mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +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) {
|
public function getName(PhortuneCart $cart) {
|
||||||
return pht('Subscription');
|
return $this->getSubscription()->getCartName($cart);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function willCreateCart(
|
public function willCreateCart(
|
||||||
|
|
|
@ -2,15 +2,8 @@
|
||||||
|
|
||||||
final class PhortuneAccountViewController extends PhortuneController {
|
final class PhortuneAccountViewController extends PhortuneController {
|
||||||
|
|
||||||
private $accountID;
|
public function handleRequest(AphrontRequest $request) {
|
||||||
|
$viewer = $this->getViewer();
|
||||||
public function willProcessRequest(array $data) {
|
|
||||||
$this->accountID = $data['accountID'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function processRequest() {
|
|
||||||
$request = $this->getRequest();
|
|
||||||
$user = $request->getUser();
|
|
||||||
|
|
||||||
// TODO: Currently, you must be able to edit an account to view the detail
|
// 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
|
// page, because the account must be broadly visible so merchants can
|
||||||
|
@ -20,8 +13,8 @@ final class PhortuneAccountViewController extends PhortuneController {
|
||||||
$can_edit = true;
|
$can_edit = true;
|
||||||
|
|
||||||
$account = id(new PhortuneAccountQuery())
|
$account = id(new PhortuneAccountQuery())
|
||||||
->setViewer($user)
|
->setViewer($viewer)
|
||||||
->withIDs(array($this->accountID))
|
->withIDs(array($request->getURIData('accountID')))
|
||||||
->requireCapabilities(
|
->requireCapabilities(
|
||||||
array(
|
array(
|
||||||
PhabricatorPolicyCapability::CAN_VIEW,
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
|
@ -34,6 +27,13 @@ final class PhortuneAccountViewController extends PhortuneController {
|
||||||
|
|
||||||
$title = $account->getName();
|
$title = $account->getName();
|
||||||
|
|
||||||
|
$invoices = id(new PhortuneCartQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withAccountPHIDs(array($account->getPHID()))
|
||||||
|
->needPurchases(true)
|
||||||
|
->withInvoices(true)
|
||||||
|
->execute();
|
||||||
|
|
||||||
$crumbs = $this->buildApplicationCrumbs();
|
$crumbs = $this->buildApplicationCrumbs();
|
||||||
$this->addAccountCrumb($crumbs, $account, $link = false);
|
$this->addAccountCrumb($crumbs, $account, $link = false);
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ final class PhortuneAccountViewController extends PhortuneController {
|
||||||
$edit_uri = $this->getApplicationURI('account/edit/'.$account->getID().'/');
|
$edit_uri = $this->getApplicationURI('account/edit/'.$account->getID().'/');
|
||||||
|
|
||||||
$actions = id(new PhabricatorActionListView())
|
$actions = id(new PhabricatorActionListView())
|
||||||
->setUser($user)
|
->setUser($viewer)
|
||||||
->setObjectURI($request->getRequestURI())
|
->setObjectURI($request->getRequestURI())
|
||||||
->addAction(
|
->addAction(
|
||||||
id(new PhabricatorActionView())
|
id(new PhabricatorActionView())
|
||||||
|
@ -55,7 +55,7 @@ final class PhortuneAccountViewController extends PhortuneController {
|
||||||
|
|
||||||
$properties = id(new PHUIPropertyListView())
|
$properties = id(new PHUIPropertyListView())
|
||||||
->setObject($account)
|
->setObject($account)
|
||||||
->setUser($user);
|
->setUser($viewer);
|
||||||
|
|
||||||
$this->loadHandles($account->getMemberPHIDs());
|
$this->loadHandles($account->getMemberPHIDs());
|
||||||
|
|
||||||
|
@ -63,12 +63,29 @@ final class PhortuneAccountViewController extends PhortuneController {
|
||||||
pht('Members'),
|
pht('Members'),
|
||||||
$this->renderHandlesForPHIDs($account->getMemberPHIDs()));
|
$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);
|
$properties->setActionList($actions);
|
||||||
|
|
||||||
$payment_methods = $this->buildPaymentMethodsSection($account);
|
$invoices = $this->buildInvoicesSection($account, $invoices);
|
||||||
$purchase_history = $this->buildPurchaseHistorySection($account);
|
$purchase_history = $this->buildPurchaseHistorySection($account);
|
||||||
$charge_history = $this->buildChargeHistorySection($account);
|
$charge_history = $this->buildChargeHistorySection($account);
|
||||||
$subscriptions = $this->buildSubscriptionsSection($account);
|
$subscriptions = $this->buildSubscriptionsSection($account);
|
||||||
|
$payment_methods = $this->buildPaymentMethodsSection($account);
|
||||||
|
|
||||||
$timeline = $this->buildTransactionTimeline(
|
$timeline = $this->buildTransactionTimeline(
|
||||||
$account,
|
$account,
|
||||||
|
@ -83,10 +100,11 @@ final class PhortuneAccountViewController extends PhortuneController {
|
||||||
array(
|
array(
|
||||||
$crumbs,
|
$crumbs,
|
||||||
$object_box,
|
$object_box,
|
||||||
$payment_methods,
|
$invoices,
|
||||||
$purchase_history,
|
$purchase_history,
|
||||||
$charge_history,
|
$charge_history,
|
||||||
$subscriptions,
|
$subscriptions,
|
||||||
|
$payment_methods,
|
||||||
$timeline,
|
$timeline,
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
|
@ -165,6 +183,38 @@ final class PhortuneAccountViewController extends PhortuneController {
|
||||||
->appendChild($list);
|
->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) {
|
private function buildPurchaseHistorySection(PhortuneAccount $account) {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$viewer = $request->getUser();
|
$viewer = $request->getUser();
|
||||||
|
@ -308,4 +358,34 @@ final class PhortuneAccountViewController extends PhortuneController {
|
||||||
return $crumbs;
|
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 $merchantPHIDs;
|
||||||
private $subscriptionPHIDs;
|
private $subscriptionPHIDs;
|
||||||
private $statuses;
|
private $statuses;
|
||||||
|
private $invoices;
|
||||||
|
|
||||||
private $needPurchases;
|
private $needPurchases;
|
||||||
|
|
||||||
|
@ -42,6 +43,18 @@ final class PhortuneCartQuery
|
||||||
return $this;
|
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) {
|
public function needPurchases($need_purchases) {
|
||||||
$this->needPurchases = $need_purchases;
|
$this->needPurchases = $need_purchases;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -178,6 +191,20 @@ final class PhortuneCartQuery
|
||||||
$this->statuses);
|
$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);
|
return $this->formatWhereClause($where);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,6 +166,10 @@ final class PhortuneSubscription extends PhortuneDAO
|
||||||
return $this->getImplementation()->getName($this);
|
return $this->getImplementation()->getName($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCartName(PhortuneCart $cart) {
|
||||||
|
return $this->getImplementation()->getCartName($this, $cart);
|
||||||
|
}
|
||||||
|
|
||||||
public function getURI() {
|
public function getURI() {
|
||||||
$account_id = $this->getAccount()->getID();
|
$account_id = $this->getAccount()->getID();
|
||||||
$id = $this->getID();
|
$id = $this->getID();
|
||||||
|
|
|
@ -15,4 +15,10 @@ abstract class PhortuneSubscriptionImplementation {
|
||||||
array());
|
array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCartName(
|
||||||
|
PhortuneSubscription $subscription,
|
||||||
|
PhortuneCart $cart) {
|
||||||
|
return pht('Subscription');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ final class PhortuneOrderTableView extends AphrontView {
|
||||||
|
|
||||||
private $carts;
|
private $carts;
|
||||||
private $handles;
|
private $handles;
|
||||||
|
private $noDataString;
|
||||||
|
private $isInvoices;
|
||||||
|
|
||||||
public function setHandles(array $handles) {
|
public function setHandles(array $handles) {
|
||||||
$this->handles = $handles;
|
$this->handles = $handles;
|
||||||
|
@ -23,11 +25,31 @@ final class PhortuneOrderTableView extends AphrontView {
|
||||||
return $this->carts;
|
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() {
|
public function render() {
|
||||||
$carts = $this->getCarts();
|
$carts = $this->getCarts();
|
||||||
$handles = $this->getHandles();
|
$handles = $this->getHandles();
|
||||||
$viewer = $this->getUser();
|
$viewer = $this->getUser();
|
||||||
|
|
||||||
|
$is_invoices = $this->getIsInvoices();
|
||||||
|
|
||||||
$rows = array();
|
$rows = array();
|
||||||
$rowc = array();
|
$rowc = array();
|
||||||
foreach ($carts as $cart) {
|
foreach ($carts as $cart) {
|
||||||
|
@ -42,9 +64,16 @@ final class PhortuneOrderTableView extends AphrontView {
|
||||||
$purchase_name = '';
|
$purchase_name = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($is_invoices) {
|
||||||
|
$merchant_link = $handles[$cart->getMerchantPHID()]->renderLink();
|
||||||
|
} else {
|
||||||
|
$merchant_link = null;
|
||||||
|
}
|
||||||
|
|
||||||
$rowc[] = '';
|
$rowc[] = '';
|
||||||
$rows[] = array(
|
$rows[] = array(
|
||||||
$cart->getID(),
|
$cart->getID(),
|
||||||
|
$merchant_link,
|
||||||
phutil_tag(
|
phutil_tag(
|
||||||
'strong',
|
'strong',
|
||||||
array(),
|
array(),
|
||||||
|
@ -56,6 +85,14 @@ final class PhortuneOrderTableView extends AphrontView {
|
||||||
$cart->getTotalPriceAsCurrency()->formatForDisplay()),
|
$cart->getTotalPriceAsCurrency()->formatForDisplay()),
|
||||||
PhortuneCart::getNameForStatus($cart->getStatus()),
|
PhortuneCart::getNameForStatus($cart->getStatus()),
|
||||||
phabricator_datetime($cart->getDateModified(), $viewer),
|
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) {
|
foreach ($purchases as $purchase) {
|
||||||
$id = $purchase->getID();
|
$id = $purchase->getID();
|
||||||
|
@ -64,34 +101,56 @@ final class PhortuneOrderTableView extends AphrontView {
|
||||||
|
|
||||||
$rowc[] = '';
|
$rowc[] = '';
|
||||||
$rows[] = array(
|
$rows[] = array(
|
||||||
|
'',
|
||||||
'',
|
'',
|
||||||
$handles[$purchase->getPHID()]->renderLink(),
|
$handles[$purchase->getPHID()]->renderLink(),
|
||||||
$price,
|
$price,
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$table = id(new AphrontTableView($rows))
|
$table = id(new AphrontTableView($rows))
|
||||||
|
->setNoDataString($this->getNoDataString())
|
||||||
->setRowClasses($rowc)
|
->setRowClasses($rowc)
|
||||||
->setHeaders(
|
->setHeaders(
|
||||||
array(
|
array(
|
||||||
pht('ID'),
|
pht('ID'),
|
||||||
pht('Order'),
|
pht('Merchant'),
|
||||||
|
$is_invoices ? pht('Invoice') : pht('Order'),
|
||||||
pht('Purchase'),
|
pht('Purchase'),
|
||||||
pht('Amount'),
|
pht('Amount'),
|
||||||
pht('Status'),
|
pht('Status'),
|
||||||
pht('Updated'),
|
pht('Updated'),
|
||||||
|
pht('Invoice Date'),
|
||||||
|
null,
|
||||||
))
|
))
|
||||||
->setColumnClasses(
|
->setColumnClasses(
|
||||||
array(
|
array(
|
||||||
|
'',
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
'wide',
|
'wide',
|
||||||
'right',
|
'right',
|
||||||
'',
|
'',
|
||||||
'right',
|
'right',
|
||||||
|
'right',
|
||||||
|
'',
|
||||||
|
))
|
||||||
|
->setColumnVisibility(
|
||||||
|
array(
|
||||||
|
true,
|
||||||
|
$is_invoices,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
!$is_invoices,
|
||||||
|
!$is_invoices,
|
||||||
|
$is_invoices,
|
||||||
|
$is_invoices,
|
||||||
));
|
));
|
||||||
|
|
||||||
return $table;
|
return $table;
|
||||||
|
|
Loading…
Reference in a new issue