mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 06:20:56 +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:
parent
211a93529b
commit
1652e07b4d
11 changed files with 162 additions and 10 deletions
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
),
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -98,7 +98,7 @@ final class PhortuneCartCheckoutController
|
|||
foreach ($methods as $method) {
|
||||
$method_control->addButton(
|
||||
$method->getID(),
|
||||
$method->getBrand().' / '.$method->getLastFourDigits(),
|
||||
$method->getFullDisplayName(),
|
||||
$method->getDescription());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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 )----------------------------------------- */
|
||||
|
||||
|
|
|
@ -54,6 +54,10 @@ final class PhortunePurchase extends PhortuneDAO
|
|||
$this->totalPriceInCents = (int)$this->totalPriceInCents;
|
||||
}
|
||||
|
||||
public function getFullDisplayName() {
|
||||
return pht('Goods and/or Services');
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||
|
||||
|
|
Loading…
Reference in a new issue