1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-04-04 08:28:22 +02: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', 'PhortuneProviderController' => 'applications/phortune/controller/PhortuneProviderController.php',
'PhortunePurchase' => 'applications/phortune/storage/PhortunePurchase.php', 'PhortunePurchase' => 'applications/phortune/storage/PhortunePurchase.php',
'PhortunePurchaseQuery' => 'applications/phortune/query/PhortunePurchaseQuery.php', 'PhortunePurchaseQuery' => 'applications/phortune/query/PhortunePurchaseQuery.php',
'PhortunePurchaseViewController' => 'applications/phortune/controller/PhortunePurchaseViewController.php',
'PhortuneStripePaymentProvider' => 'applications/phortune/provider/PhortuneStripePaymentProvider.php', 'PhortuneStripePaymentProvider' => 'applications/phortune/provider/PhortuneStripePaymentProvider.php',
'PhortuneTestExtraPaymentProvider' => 'applications/phortune/provider/__tests__/PhortuneTestExtraPaymentProvider.php', 'PhortuneTestExtraPaymentProvider' => 'applications/phortune/provider/__tests__/PhortuneTestExtraPaymentProvider.php',
'PhortuneTestPaymentProvider' => 'applications/phortune/provider/PhortuneTestPaymentProvider.php', 'PhortuneTestPaymentProvider' => 'applications/phortune/provider/PhortuneTestPaymentProvider.php',
@ -5433,6 +5434,7 @@ phutil_register_library_map(array(
'PhabricatorPolicyInterface', 'PhabricatorPolicyInterface',
), ),
'PhortunePurchaseQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhortunePurchaseQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhortunePurchaseViewController' => 'PhortuneController',
'PhortuneStripePaymentProvider' => 'PhortunePaymentProvider', 'PhortuneStripePaymentProvider' => 'PhortunePaymentProvider',
'PhortuneTestExtraPaymentProvider' => 'PhortunePaymentProvider', 'PhortuneTestExtraPaymentProvider' => 'PhortunePaymentProvider',
'PhortuneTestPaymentProvider' => 'PhortunePaymentProvider', 'PhortuneTestPaymentProvider' => 'PhortunePaymentProvider',

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -52,15 +52,25 @@ abstract class PhortuneController extends PhabricatorController {
return $account; return $account;
} }
protected function buildChargesTable(array $charges) { protected function buildChargesTable(array $charges, $show_cart = true) {
$request = $this->getRequest(); $request = $this->getRequest();
$viewer = $request->getUser(); $viewer = $request->getUser();
$rows = array(); $rows = array();
foreach ($charges as $charge) { 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( $rows[] = array(
$charge->getID(), $charge->getID(),
$charge->getCartPHID(), $cart_href,
$charge->getPaymentProviderKey(), $charge->getPaymentProviderKey(),
$charge->getPaymentMethodPHID(), $charge->getPaymentMethodPHID(),
PhortuneCurrency::newFromUSDCents($charge->getAmountInCents()) PhortuneCurrency::newFromUSDCents($charge->getAmountInCents())
@ -73,7 +83,7 @@ abstract class PhortuneController extends PhabricatorController {
$charge_table = id(new AphrontTableView($rows)) $charge_table = id(new AphrontTableView($rows))
->setHeaders( ->setHeaders(
array( array(
pht('Charge ID'), pht('ID'),
pht('Cart'), pht('Cart'),
pht('Provider'), pht('Provider'),
pht('Method'), pht('Method'),
@ -84,12 +94,17 @@ abstract class PhortuneController extends PhabricatorController {
->setColumnClasses( ->setColumnClasses(
array( array(
'', '',
'', 'strong',
'', '',
'', '',
'wide right', 'wide right',
'', '',
'', '',
))
->setColumnVisibility(
array(
true,
$show_cart,
)); ));
$header = id(new PHUIHeaderView()) $header = id(new PHUIHeaderView())
@ -100,4 +115,20 @@ abstract class PhortuneController extends PhabricatorController {
->appendChild($charge_table); ->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 $accountPHIDs;
private $cartPHIDs; private $cartPHIDs;
private $needCarts;
public function withIDs(array $ids) { public function withIDs(array $ids) {
$this->ids = $ids; $this->ids = $ids;
return $this; return $this;
@ -28,6 +30,11 @@ final class PhortuneChargeQuery
return $this; return $this;
} }
public function needCarts($need_carts) {
$this->needCarts = $need_carts;
return $this;
}
protected function loadPage() { protected function loadPage() {
$table = new PhortuneCharge(); $table = new PhortuneCharge();
$conn = $table->establishConnection('r'); $conn = $table->establishConnection('r');
@ -63,6 +70,24 @@ final class PhortuneChargeQuery
return $charges; 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) { private function buildWhereClause(AphrontDatabaseConnection $conn) {
$where = array(); $where = array();

View file

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

View file

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