1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10:55 +01:00

Provide a purchase detail view in Phortune

Summary: Ref T2787. This provides a purchase detail screen (which has nothing useful on it yet) and converts a bunch of PHIDs into slightly more useful links.

Test Plan: Browsed around my account.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T2787

Differential Revision: https://secure.phabricator.com/D10284
This commit is contained in:
epriestley 2014-08-18 13:15:21 -07:00
parent 211a93529b
commit 1652e07b4d
11 changed files with 162 additions and 10 deletions

View file

@ -2507,6 +2507,7 @@ phutil_register_library_map(array(
'PhortuneProviderController' => 'applications/phortune/controller/PhortuneProviderController.php',
'PhortunePurchase' => 'applications/phortune/storage/PhortunePurchase.php',
'PhortunePurchaseQuery' => 'applications/phortune/query/PhortunePurchaseQuery.php',
'PhortunePurchaseViewController' => 'applications/phortune/controller/PhortunePurchaseViewController.php',
'PhortuneStripePaymentProvider' => 'applications/phortune/provider/PhortuneStripePaymentProvider.php',
'PhortuneTestExtraPaymentProvider' => 'applications/phortune/provider/__tests__/PhortuneTestExtraPaymentProvider.php',
'PhortuneTestPaymentProvider' => 'applications/phortune/provider/PhortuneTestPaymentProvider.php',
@ -5433,6 +5434,7 @@ phutil_register_library_map(array(
'PhabricatorPolicyInterface',
),
'PhortunePurchaseQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhortunePurchaseViewController' => 'PhortuneController',
'PhortuneStripePaymentProvider' => 'PhortunePaymentProvider',
'PhortuneTestExtraPaymentProvider' => 'PhortunePaymentProvider',
'PhortuneTestPaymentProvider' => 'PhortunePaymentProvider',

View file

@ -58,6 +58,9 @@ final class PhabricatorPhortuneApplication extends PhabricatorApplication {
'view/(?P<id>\d+)/' => 'PhortuneProductViewController',
'edit/(?:(?P<id>\d+)/)?' => 'PhortuneProductEditController',
),
'purchase/(?P<id>\d+)/' => array(
'' => 'PhortunePurchaseViewController',
),
'provider/(?P<digest>[^/]+)/(?P<action>[^/]+)/'
=> 'PhortuneProviderController',
),

View file

@ -173,20 +173,36 @@ final class PhortuneAccountViewController extends PhortuneController {
$rows = array();
$rowc = array();
foreach ($carts as $cart) {
$cart_link = phutil_tag(
'a',
array(
'href' => $this->getApplicationURI('cart/'.$cart->getID().'/'),
),
pht('Cart %d', $cart->getID()));
$rowc[] = 'highlighted';
$rows[] = array(
$cart->getPHID(),
phutil_tag('strong', array(), $cart_link),
'',
'',
);
foreach ($cart->getPurchases() as $purchase) {
$id = $purchase->getID();
$price = $purchase->getTotalPriceInCents();
$price = PhortuneCurrency::newFromUSDCents($price)->formatForDisplay();
$purchase_link = phutil_tag(
'a',
array(
'href' => $this->getApplicationURI('purchase/'.$id.'/'),
),
$purchase->getFullDisplayName());
$rowc[] = '';
$rows[] = array(
'',
$purchase->getPHID(),
$purchase_link,
$price,
);
}
@ -222,6 +238,7 @@ final class PhortuneAccountViewController extends PhortuneController {
$charges = id(new PhortuneChargeQuery())
->setViewer($viewer)
->withAccountPHIDs(array($account->getPHID()))
->needCarts(true)
->execute();
return $this->buildChargesTable($charges);

View file

@ -98,7 +98,7 @@ final class PhortuneCartCheckoutController
foreach ($methods as $method) {
$method_control->addButton(
$method->getID(),
$method->getBrand().' / '.$method->getLastFourDigits(),
$method->getFullDisplayName(),
$method->getDescription());
}
}

View file

@ -9,7 +9,7 @@ abstract class PhortuneCartController
$total = 0;
foreach ($cart->getPurchases() as $purchase) {
$rows[] = array(
pht('A Purchase'),
$purchase->getFullDisplayName(),
PhortuneCurrency::newFromUSDCents($purchase->getBasePriceInCents())
->formatForDisplay(),
$purchase->getQuantity(),

View file

@ -27,14 +27,16 @@ final class PhortuneCartViewController
$charges = id(new PhortuneChargeQuery())
->setViewer($viewer)
->withCartPHIDs(array($cart->getPHID()))
->needCarts(true)
->execute();
$charges_table = $this->buildChargesTable($charges);
$charges_table = $this->buildChargesTable($charges, false);
$account = $cart->getAccount();
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Cart'));
$this->addAccountCrumb($crumbs, $cart->getAccount());
$crumbs->addTextCrumb(pht('Cart %d', $cart->getID()));
return $this->buildApplicationPage(
array(

View file

@ -52,15 +52,25 @@ abstract class PhortuneController extends PhabricatorController {
return $account;
}
protected function buildChargesTable(array $charges) {
protected function buildChargesTable(array $charges, $show_cart = true) {
$request = $this->getRequest();
$viewer = $request->getUser();
$rows = array();
foreach ($charges as $charge) {
$cart = $charge->getCart();
$cart_id = $cart->getID();
$cart_uri = $this->getApplicationURI("cart/{$cart_id}/");
$cart_href = phutil_tag(
'a',
array(
'href' => $cart_uri,
),
pht('Cart %d', $cart_id));
$rows[] = array(
$charge->getID(),
$charge->getCartPHID(),
$cart_href,
$charge->getPaymentProviderKey(),
$charge->getPaymentMethodPHID(),
PhortuneCurrency::newFromUSDCents($charge->getAmountInCents())
@ -73,7 +83,7 @@ abstract class PhortuneController extends PhabricatorController {
$charge_table = id(new AphrontTableView($rows))
->setHeaders(
array(
pht('Charge ID'),
pht('ID'),
pht('Cart'),
pht('Provider'),
pht('Method'),
@ -84,12 +94,17 @@ abstract class PhortuneController extends PhabricatorController {
->setColumnClasses(
array(
'',
'',
'strong',
'',
'',
'wide right',
'',
'',
))
->setColumnVisibility(
array(
true,
$show_cart,
));
$header = id(new PHUIHeaderView())
@ -100,4 +115,20 @@ abstract class PhortuneController extends PhabricatorController {
->appendChild($charge_table);
}
protected function addAccountCrumb(
$crumbs,
PhortuneAccount $account,
$link = true) {
$name = pht('Account');
$href = null;
if ($link) {
$href = $this->getApplicationURI($account->getID().'/');
$crumbs->addTextCrumb($name, $href);
} else {
$crumbs->addTextCrumb($name);
}
}
}

View file

@ -0,0 +1,58 @@
<?php
final class PhortunePurchaseViewController extends PhortuneController {
private $purchaseID;
public function willProcessRequest(array $data) {
$this->purchaseID = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$account = $this->loadActiveAccount($viewer);
$purchase = id(new PhortunePurchaseQuery())
->setViewer($viewer)
->withIDs(array($this->purchaseID))
->executeOne();
if (!$purchase) {
return new Aphront404Response();
}
$cart = $purchase->getCart();
$title = pht('Purchase: %s', $purchase->getFullDisplayName());
$header = id(new PHUIHeaderView())
->setHeader($purchase->getFullDisplayName());
$crumbs = $this->buildApplicationCrumbs();
$this->addAccountCrumb($crumbs, $account);
$crumbs->addTextCrumb(
pht('Cart %d', $cart->getID()),
$this->getApplicationURI('cart/'.$cart->getID().'/'));
$crumbs->addTextCrumb(
pht('Purchase %d', $purchase->getID()),
$this->getApplicationURI('purchase/'.$purchase->getID().'/'));
$properties = id(new PHUIPropertyListView())
->setUser($viewer)
->addProperty(pht('Status'), $purchase->getStatus());
$object_box = id(new PHUIObjectBoxView())
->setHeader($header)
->addPropertyList($properties);
return $this->buildApplicationPage(
array(
$crumbs,
$object_box,
),
array(
'title' => $title,
));
}
}

View file

@ -8,6 +8,8 @@ final class PhortuneChargeQuery
private $accountPHIDs;
private $cartPHIDs;
private $needCarts;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
@ -28,6 +30,11 @@ final class PhortuneChargeQuery
return $this;
}
public function needCarts($need_carts) {
$this->needCarts = $need_carts;
return $this;
}
protected function loadPage() {
$table = new PhortuneCharge();
$conn = $table->establishConnection('r');
@ -63,6 +70,24 @@ final class PhortuneChargeQuery
return $charges;
}
protected function didFilterPage(array $charges) {
if ($this->needCarts) {
$carts = id(new PhortuneCartQuery())
->setViewer($this->getViewer())
->setParentQuery($this)
->withPHIDs(mpull($charges, 'getCartPHID'))
->execute();
$carts = mpull($carts, null, 'getPHID');
foreach ($charges as $charge) {
$cart = idx($carts, $charge->getCartPHID());
$charge->attachCart($cart);
}
}
return $charges;
}
private function buildWhereClause(AphrontDatabaseConnection $conn) {
$where = array();

View file

@ -25,6 +25,7 @@ final class PhortuneCharge extends PhortuneDAO
protected $metadata = array();
private $account = self::ATTACHABLE;
private $cart = self::ATTACHABLE;
public function getConfiguration() {
return array(
@ -63,6 +64,15 @@ final class PhortuneCharge extends PhortuneDAO
return $this;
}
public function getCart() {
return $this->assertAttached($this->cart);
}
public function attachCart(PhortuneCart $cart = null) {
$this->cart = $cart;
return $this;
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */

View file

@ -54,6 +54,10 @@ final class PhortunePurchase extends PhortuneDAO
$this->totalPriceInCents = (int)$this->totalPriceInCents;
}
public function getFullDisplayName() {
return pht('Goods and/or Services');
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */