mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-20 05:42:40 +01:00
Show invoices on account information page
Summary: Ref T6881. This is basically just some UX. Right now, if we invoice you, you can //technically// pay it but since we don't tell you about it and don't show it in the UI you'd have to guess the ID by manipulating the URI. We should probably be at least a little more aggressive about billing. In the common case when we generate a cart/order, we don't show it to the user or merchant in Phortune until the user takes a payment action (basically, Phortune doesn't recognize the cart until you actually check out with it). In the current use case in Fund (and other reasonable use cases) an un-acted-upon cart hasn't been ordered yet, and is just a place for the application to store state as it hands off the workflow to Phortune. Even if we had a real "Shop for physical goods" app, I think the same rule would apply -- the application itself would probably track and show your current cart, but it wouldn't make sense to put it into your order history in Phortune until you actually buy it. Since invoices from subscriptions are essentially identical to not-yet-ordered-carts, that mean they also did not show up in the UI (although I think this is also desirable). This change carves out a place for them: - Add an "invoices" section with unpaid invoices. - The UI shows that you have unpaid invoices. - Invoices have a slightly different rendering, inclduing an alluring "Pay Now" button. Some considerations: - One thing I'm vaguely thinking about is the possibilty that users may be able to invoice one another directly, eventually. For example, we might invoice a contracting client. - Considering this, I thought about making these carts have a special status like `STATUS_DUE`, which replaces `STATUS_READY`, or a flag like `isInvoice`. - However, this approach was pretty involved and made the //billing// logic more complicated, so I backed off. The ultimate approach here puts more of the complexity into the display logic, which feels better to me. - We might need an `isInvoice` flag eventually, but `subscriptionPHID` is a reasonable stand-in for now. - The OrderTable serving double duty for rendering subscriptions feels a little muddy, but I think splitting it into two highly-redundant classes would be worse. Test Plan: {F279348} {F279349} Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T6881 Differential Revision: https://secure.phabricator.com/D11593
This commit is contained in:
parent
0c601be2b6
commit
07d640d2b6
6 changed files with 193 additions and 17 deletions
|
@ -25,7 +25,7 @@ final class PhortuneSubscriptionCart
|
|||
}
|
||||
|
||||
public function getName(PhortuneCart $cart) {
|
||||
return pht('Subscription');
|
||||
return $this->getSubscription()->getCartName($cart);
|
||||
}
|
||||
|
||||
public function willCreateCart(
|
||||
|
|
|
@ -2,15 +2,8 @@
|
|||
|
||||
final class PhortuneAccountViewController extends PhortuneController {
|
||||
|
||||
private $accountID;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->accountID = $data['accountID'];
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
// TODO: Currently, you must be able to edit an account to view the detail
|
||||
// page, because the account must be broadly visible so merchants can
|
||||
|
@ -20,8 +13,8 @@ final class PhortuneAccountViewController extends PhortuneController {
|
|||
$can_edit = true;
|
||||
|
||||
$account = id(new PhortuneAccountQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($this->accountID))
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($request->getURIData('accountID')))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
|
@ -34,6 +27,13 @@ final class PhortuneAccountViewController extends PhortuneController {
|
|||
|
||||
$title = $account->getName();
|
||||
|
||||
$invoices = id(new PhortuneCartQuery())
|
||||
->setViewer($viewer)
|
||||
->withAccountPHIDs(array($account->getPHID()))
|
||||
->needPurchases(true)
|
||||
->withInvoices(true)
|
||||
->execute();
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
$this->addAccountCrumb($crumbs, $account, $link = false);
|
||||
|
||||
|
@ -43,7 +43,7 @@ final class PhortuneAccountViewController extends PhortuneController {
|
|||
$edit_uri = $this->getApplicationURI('account/edit/'.$account->getID().'/');
|
||||
|
||||
$actions = id(new PhabricatorActionListView())
|
||||
->setUser($user)
|
||||
->setUser($viewer)
|
||||
->setObjectURI($request->getRequestURI())
|
||||
->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
|
@ -55,7 +55,7 @@ final class PhortuneAccountViewController extends PhortuneController {
|
|||
|
||||
$properties = id(new PHUIPropertyListView())
|
||||
->setObject($account)
|
||||
->setUser($user);
|
||||
->setUser($viewer);
|
||||
|
||||
$this->loadHandles($account->getMemberPHIDs());
|
||||
|
||||
|
@ -63,12 +63,29 @@ final class PhortuneAccountViewController extends PhortuneController {
|
|||
pht('Members'),
|
||||
$this->renderHandlesForPHIDs($account->getMemberPHIDs()));
|
||||
|
||||
$status_items = $this->getStatusItemsForAccount($account, $invoices);
|
||||
$status_view = new PHUIStatusListView();
|
||||
foreach ($status_items as $item) {
|
||||
$status_view->addItem(
|
||||
id(new PHUIStatusItemView())
|
||||
->setIcon(
|
||||
idx($item, 'icon'),
|
||||
idx($item, 'color'),
|
||||
idx($item, 'label'))
|
||||
->setTarget(idx($item, 'target'))
|
||||
->setNote(idx($item, 'note')));
|
||||
}
|
||||
$properties->addProperty(
|
||||
pht('Status'),
|
||||
$status_view);
|
||||
|
||||
$properties->setActionList($actions);
|
||||
|
||||
$payment_methods = $this->buildPaymentMethodsSection($account);
|
||||
$invoices = $this->buildInvoicesSection($account, $invoices);
|
||||
$purchase_history = $this->buildPurchaseHistorySection($account);
|
||||
$charge_history = $this->buildChargeHistorySection($account);
|
||||
$subscriptions = $this->buildSubscriptionsSection($account);
|
||||
$payment_methods = $this->buildPaymentMethodsSection($account);
|
||||
|
||||
$timeline = $this->buildTransactionTimeline(
|
||||
$account,
|
||||
|
@ -83,10 +100,11 @@ final class PhortuneAccountViewController extends PhortuneController {
|
|||
array(
|
||||
$crumbs,
|
||||
$object_box,
|
||||
$payment_methods,
|
||||
$invoices,
|
||||
$purchase_history,
|
||||
$charge_history,
|
||||
$subscriptions,
|
||||
$payment_methods,
|
||||
$timeline,
|
||||
),
|
||||
array(
|
||||
|
@ -165,6 +183,38 @@ final class PhortuneAccountViewController extends PhortuneController {
|
|||
->appendChild($list);
|
||||
}
|
||||
|
||||
private function buildInvoicesSection(
|
||||
PhortuneAccount $account,
|
||||
array $carts) {
|
||||
|
||||
$request = $this->getRequest();
|
||||
$viewer = $request->getUser();
|
||||
|
||||
$phids = array();
|
||||
foreach ($carts as $cart) {
|
||||
$phids[] = $cart->getPHID();
|
||||
$phids[] = $cart->getMerchantPHID();
|
||||
foreach ($cart->getPurchases() as $purchase) {
|
||||
$phids[] = $purchase->getPHID();
|
||||
}
|
||||
}
|
||||
$handles = $this->loadViewerHandles($phids);
|
||||
|
||||
$table = id(new PhortuneOrderTableView())
|
||||
->setNoDataString(pht('You have no unpaid invoices.'))
|
||||
->setIsInvoices(true)
|
||||
->setUser($viewer)
|
||||
->setCarts($carts)
|
||||
->setHandles($handles);
|
||||
|
||||
$header = id(new PHUIHeaderView())
|
||||
->setHeader(pht('Invoices Due'));
|
||||
|
||||
return id(new PHUIObjectBoxView())
|
||||
->setHeader($header)
|
||||
->appendChild($table);
|
||||
}
|
||||
|
||||
private function buildPurchaseHistorySection(PhortuneAccount $account) {
|
||||
$request = $this->getRequest();
|
||||
$viewer = $request->getUser();
|
||||
|
@ -308,4 +358,34 @@ final class PhortuneAccountViewController extends PhortuneController {
|
|||
return $crumbs;
|
||||
}
|
||||
|
||||
private function getStatusItemsForAccount(
|
||||
PhortuneAccount $account,
|
||||
array $invoices) {
|
||||
|
||||
assert_instances_of($invoices, 'PhortuneCart');
|
||||
|
||||
$items = array();
|
||||
|
||||
if ($invoices) {
|
||||
$items[] = array(
|
||||
'icon' => PHUIStatusItemView::ICON_WARNING,
|
||||
'color' => 'yellow',
|
||||
'target' => pht('Invoices'),
|
||||
'note' => pht('You have %d unpaid invoice(s).', count($invoices)),
|
||||
);
|
||||
} else {
|
||||
$items[] = array(
|
||||
'icon' => PHUIStatusItemView::ICON_ACCEPT,
|
||||
'color' => 'green',
|
||||
'target' => pht('Invoices'),
|
||||
'note' => pht('This account has no unpaid invoices.'),
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: If a payment method has expired or is expiring soon, we should
|
||||
// add a status check for it.
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ final class PhortuneCartQuery
|
|||
private $merchantPHIDs;
|
||||
private $subscriptionPHIDs;
|
||||
private $statuses;
|
||||
private $invoices;
|
||||
|
||||
private $needPurchases;
|
||||
|
||||
|
@ -42,6 +43,18 @@ final class PhortuneCartQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Include or exclude carts which represent invoices with payments due.
|
||||
*
|
||||
* @param bool `true` to select invoices; `false` to exclude invoices.
|
||||
* @return this
|
||||
*/
|
||||
public function withInvoices($invoices) {
|
||||
$this->invoices = $invoices;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function needPurchases($need_purchases) {
|
||||
$this->needPurchases = $need_purchases;
|
||||
return $this;
|
||||
|
@ -178,6 +191,20 @@ final class PhortuneCartQuery
|
|||
$this->statuses);
|
||||
}
|
||||
|
||||
if ($this->invoices !== null) {
|
||||
if ($this->invoices) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'cart.status = %s AND cart.subscriptionPHID IS NOT NULL',
|
||||
PhortuneCart::STATUS_READY);
|
||||
} else {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'cart.status != %s OR cart.subscriptionPHID IS NULL',
|
||||
PhortuneCart::STATUS_READY);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
|
|
|
@ -166,6 +166,10 @@ final class PhortuneSubscription extends PhortuneDAO
|
|||
return $this->getImplementation()->getName($this);
|
||||
}
|
||||
|
||||
public function getCartName(PhortuneCart $cart) {
|
||||
return $this->getImplementation()->getCartName($this, $cart);
|
||||
}
|
||||
|
||||
public function getURI() {
|
||||
$account_id = $this->getAccount()->getID();
|
||||
$id = $this->getID();
|
||||
|
|
|
@ -15,4 +15,10 @@ abstract class PhortuneSubscriptionImplementation {
|
|||
array());
|
||||
}
|
||||
|
||||
public function getCartName(
|
||||
PhortuneSubscription $subscription,
|
||||
PhortuneCart $cart) {
|
||||
return pht('Subscription');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ final class PhortuneOrderTableView extends AphrontView {
|
|||
|
||||
private $carts;
|
||||
private $handles;
|
||||
private $noDataString;
|
||||
private $isInvoices;
|
||||
|
||||
public function setHandles(array $handles) {
|
||||
$this->handles = $handles;
|
||||
|
@ -23,11 +25,31 @@ final class PhortuneOrderTableView extends AphrontView {
|
|||
return $this->carts;
|
||||
}
|
||||
|
||||
public function setIsInvoices($is_invoices) {
|
||||
$this->isInvoices = $is_invoices;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIsInvoices() {
|
||||
return $this->isInvoices;
|
||||
}
|
||||
|
||||
public function setNoDataString($no_data_string) {
|
||||
$this->noDataString = $no_data_string;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNoDataString() {
|
||||
return $this->noDataString;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
$carts = $this->getCarts();
|
||||
$handles = $this->getHandles();
|
||||
$viewer = $this->getUser();
|
||||
|
||||
$is_invoices = $this->getIsInvoices();
|
||||
|
||||
$rows = array();
|
||||
$rowc = array();
|
||||
foreach ($carts as $cart) {
|
||||
|
@ -42,9 +64,16 @@ final class PhortuneOrderTableView extends AphrontView {
|
|||
$purchase_name = '';
|
||||
}
|
||||
|
||||
if ($is_invoices) {
|
||||
$merchant_link = $handles[$cart->getMerchantPHID()]->renderLink();
|
||||
} else {
|
||||
$merchant_link = null;
|
||||
}
|
||||
|
||||
$rowc[] = '';
|
||||
$rows[] = array(
|
||||
$cart->getID(),
|
||||
$merchant_link,
|
||||
phutil_tag(
|
||||
'strong',
|
||||
array(),
|
||||
|
@ -56,6 +85,14 @@ final class PhortuneOrderTableView extends AphrontView {
|
|||
$cart->getTotalPriceAsCurrency()->formatForDisplay()),
|
||||
PhortuneCart::getNameForStatus($cart->getStatus()),
|
||||
phabricator_datetime($cart->getDateModified(), $viewer),
|
||||
phabricator_datetime($cart->getDateCreated(), $viewer),
|
||||
phutil_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => $cart->getCheckoutURI(),
|
||||
'class' => 'small green button',
|
||||
),
|
||||
pht('Pay Now')),
|
||||
);
|
||||
foreach ($purchases as $purchase) {
|
||||
$id = $purchase->getID();
|
||||
|
@ -64,34 +101,56 @@ final class PhortuneOrderTableView extends AphrontView {
|
|||
|
||||
$rowc[] = '';
|
||||
$rows[] = array(
|
||||
'',
|
||||
'',
|
||||
$handles[$purchase->getPHID()]->renderLink(),
|
||||
$price,
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$table = id(new AphrontTableView($rows))
|
||||
->setNoDataString($this->getNoDataString())
|
||||
->setRowClasses($rowc)
|
||||
->setHeaders(
|
||||
array(
|
||||
pht('ID'),
|
||||
pht('Order'),
|
||||
pht('Merchant'),
|
||||
$is_invoices ? pht('Invoice') : pht('Order'),
|
||||
pht('Purchase'),
|
||||
pht('Amount'),
|
||||
pht('Status'),
|
||||
pht('Updated'),
|
||||
pht('Invoice Date'),
|
||||
null,
|
||||
))
|
||||
->setColumnClasses(
|
||||
array(
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'wide',
|
||||
'right',
|
||||
'',
|
||||
'right',
|
||||
'right',
|
||||
'',
|
||||
))
|
||||
->setColumnVisibility(
|
||||
array(
|
||||
true,
|
||||
$is_invoices,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
!$is_invoices,
|
||||
!$is_invoices,
|
||||
$is_invoices,
|
||||
$is_invoices,
|
||||
));
|
||||
|
||||
return $table;
|
||||
|
|
Loading…
Reference in a new issue