Summary: Ref T6881. This generates a product, purchase and invoice for users, and there's sort of some UI for them. Stuff it doesn't do yet: - Try to autobill when we have a CC; - actually tell the user they should pay it; - ask the application for anything like "how much should we charge", or tell the application anything like "the user paid". However, these work: - You can //technically// pay the invoices. - You can see the invoices you paid in the past. Test Plan: Used `bin/phriction invoice` to double-bill myself over and over again. Paid one of the invoices. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T6881 Differential Revision: https://secure.phabricator.com/D11580
118 lines
3.3 KiB
PHP
118 lines
3.3 KiB
PHP
<?php
|
|
|
|
final class PhortuneSubscriptionViewController extends PhortuneController {
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
$viewer = $this->getViewer();
|
|
|
|
$subscription = id(new PhortuneSubscriptionQuery())
|
|
->setViewer($viewer)
|
|
->withIDs(array($request->getURIData('id')))
|
|
->needTriggers(true)
|
|
->executeOne();
|
|
if (!$subscription) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
$is_merchant = (bool)$request->getURIData('merchantID');
|
|
$merchant = $subscription->getMerchant();
|
|
$account = $subscription->getAccount();
|
|
|
|
$title = pht('Subscription: %s', $subscription->getSubscriptionName());
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
->setHeader($subscription->getSubscriptionName());
|
|
|
|
$actions = id(new PhabricatorActionListView())
|
|
->setUser($viewer)
|
|
->setObjectURI($request->getRequestURI());
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
if ($is_merchant) {
|
|
$this->addMerchantCrumb($crumbs, $merchant);
|
|
} else {
|
|
$this->addAccountCrumb($crumbs, $account);
|
|
}
|
|
$crumbs->addTextCrumb(pht('Subscription %d', $subscription->getID()));
|
|
|
|
$properties = id(new PHUIPropertyListView())
|
|
->setUser($viewer)
|
|
->setActionList($actions);
|
|
|
|
$next_invoice = $subscription->getTrigger()->getNextEventPrediction();
|
|
$properties->addProperty(
|
|
pht('Next Invoice'),
|
|
phabricator_datetime($next_invoice, $viewer));
|
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
->setHeader($header)
|
|
->addPropertyList($properties);
|
|
|
|
$carts = id(new PhortuneCartQuery())
|
|
->setViewer($viewer)
|
|
->withSubscriptionPHIDs(array($subscription->getPHID()))
|
|
->needPurchases(true)
|
|
->withStatuses(
|
|
array(
|
|
PhortuneCart::STATUS_PURCHASING,
|
|
PhortuneCart::STATUS_CHARGED,
|
|
PhortuneCart::STATUS_HOLD,
|
|
PhortuneCart::STATUS_REVIEW,
|
|
PhortuneCart::STATUS_PURCHASED,
|
|
))
|
|
->execute();
|
|
|
|
$phids = array();
|
|
foreach ($carts as $cart) {
|
|
$phids[] = $cart->getPHID();
|
|
foreach ($cart->getPurchases() as $purchase) {
|
|
$phids[] = $purchase->getPHID();
|
|
}
|
|
}
|
|
$handles = $this->loadViewerHandles($phids);
|
|
|
|
$invoice_table = id(new PhortuneOrderTableView())
|
|
->setUser($viewer)
|
|
->setCarts($carts)
|
|
->setHandles($handles);
|
|
|
|
$account_id = $account->getID();
|
|
$merchant_id = $merchant->getID();
|
|
$subscription_id = $subscription->getID();
|
|
|
|
if ($is_merchant) {
|
|
$invoices_uri = $this->getApplicationURI(
|
|
"merchant/{$merchant_id}/subscription/order/{$subscription_id}/");
|
|
} else {
|
|
$invoices_uri = $this->getApplicationURI(
|
|
"{$account_id}/subscription/order/{$subscription_id}/");
|
|
}
|
|
|
|
$invoice_header = id(new PHUIHeaderView())
|
|
->setHeader(pht('Recent Invoices'))
|
|
->addActionLink(
|
|
id(new PHUIButtonView())
|
|
->setTag('a')
|
|
->setIcon(
|
|
id(new PHUIIconView())
|
|
->setIconFont('fa-list'))
|
|
->setHref($invoices_uri)
|
|
->setText(pht('View All Invoices')));
|
|
|
|
$invoice_box = id(new PHUIObjectBoxView())
|
|
->setHeader($invoice_header)
|
|
->appendChild($invoice_table);
|
|
|
|
return $this->buildApplicationPage(
|
|
array(
|
|
$crumbs,
|
|
$object_box,
|
|
$invoice_box,
|
|
),
|
|
array(
|
|
'title' => $title,
|
|
));
|
|
}
|
|
|
|
}
|