Differential D20740 Diff 49453 src/applications/phortune/controller/cart/PhortuneCartViewController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phortune/controller/cart/PhortuneCartViewController.php
<?php | <?php | ||||
final class PhortuneCartViewController | final class PhortuneCartViewController | ||||
extends PhortuneCartController { | extends PhortuneCartController { | ||||
private $action = null; | |||||
protected function shouldRequireAccountAuthority() { | protected function shouldRequireAccountAuthority() { | ||||
return false; | return false; | ||||
} | } | ||||
protected function shouldRequireMerchantAuthority() { | protected function shouldRequireMerchantAuthority() { | ||||
return false; | return false; | ||||
} | } | ||||
protected function handleCartRequest(AphrontRequest $request) { | protected function handleCartRequest(AphrontRequest $request) { | ||||
$viewer = $request->getViewer(); | $viewer = $request->getViewer(); | ||||
$cart = $this->getCart(); | $order = $this->getCart(); | ||||
$authority = $this->getMerchantAuthority(); | $authority = $this->getMerchantAuthority(); | ||||
$can_edit = $this->hasAccountAuthority(); | $can_edit = $this->hasAccountAuthority(); | ||||
$this->action = $request->getURIData('action'); | $is_printable = ($request->getURIData('action') === 'print'); | ||||
$cart_table = $this->buildCartContentTable($cart); | |||||
$errors = array(); | |||||
$error_view = null; | |||||
$resume_uri = null; | $resume_uri = null; | ||||
switch ($cart->getStatus()) { | if ($order->getStatus() === PhortuneCart::STATUS_PURCHASING) { | ||||
case PhortuneCart::STATUS_READY: | |||||
if ($cart->getIsInvoice()) { | |||||
$error_view = id(new PHUIInfoView()) | |||||
->setSeverity(PHUIInfoView::SEVERITY_NOTICE) | |||||
->appendChild(pht('This invoice is ready for payment.')); | |||||
} | |||||
break; | |||||
case PhortuneCart::STATUS_PURCHASING: | |||||
if ($can_edit) { | |||||
$resume_uri = $cart->getMetadataValue('provider.checkoutURI'); | |||||
if ($resume_uri) { | |||||
$errors[] = pht( | |||||
'The checkout process has been started, but not yet completed. '. | |||||
'You can continue checking out by clicking %s, or cancel the '. | |||||
'order, or contact the merchant for assistance.', | |||||
phutil_tag('strong', array(), pht('Continue Checkout'))); | |||||
} else { | |||||
$errors[] = pht( | |||||
'The checkout process has been started, but an error occurred. '. | |||||
'You can cancel the order or contact the merchant for '. | |||||
'assistance.'); | |||||
} | |||||
} | |||||
break; | |||||
case PhortuneCart::STATUS_CHARGED: | |||||
if ($can_edit) { | if ($can_edit) { | ||||
$errors[] = pht( | $resume_uri = $order->getMetadataValue('provider.checkoutURI'); | ||||
'You have been charged, but processing could not be completed. '. | |||||
'You can cancel your order, or contact the merchant for '. | |||||
'assistance.'); | |||||
} | } | ||||
break; | |||||
case PhortuneCart::STATUS_HOLD: | |||||
if ($can_edit) { | |||||
$errors[] = pht( | |||||
'Payment for this order is on hold. You can click %s to check '. | |||||
'for updates, cancel the order, or contact the merchant for '. | |||||
'assistance.', | |||||
phutil_tag('strong', array(), pht('Update Status'))); | |||||
} | } | ||||
break; | |||||
case PhortuneCart::STATUS_REVIEW: | |||||
if ($authority) { | |||||
$errors[] = pht( | |||||
'This order has been flagged for manual review. Review the order '. | |||||
'and choose %s to accept it or %s to reject it.', | |||||
phutil_tag('strong', array(), pht('Accept Order')), | |||||
phutil_tag('strong', array(), pht('Refund Order'))); | |||||
} else if ($can_edit) { | |||||
$errors[] = pht( | |||||
'This order requires manual processing and will complete once '. | |||||
'the merchant accepts it.'); | |||||
} | |||||
break; | |||||
case PhortuneCart::STATUS_PURCHASED: | |||||
$error_view = id(new PHUIInfoView()) | |||||
->setSeverity(PHUIInfoView::SEVERITY_SUCCESS) | |||||
->appendChild(pht('This purchase has been completed.')); | |||||
break; | |||||
} | |||||
if ($errors) { | |||||
$error_view = id(new PHUIInfoView()) | |||||
->setSeverity(PHUIInfoView::SEVERITY_WARNING) | |||||
->appendChild($errors); | |||||
} | |||||
$details = $this->buildDetailsView($cart); | |||||
$curtain = $this->buildCurtainView( | |||||
$cart, | |||||
$can_edit, | |||||
$authority, | |||||
$resume_uri); | |||||
$header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->setHeader($cart->getName()) | ->setHeader($order->getName()) | ||||
->setHeaderIcon('fa-shopping-bag'); | ->setHeaderIcon('fa-shopping-bag'); | ||||
if ($cart->getStatus() == PhortuneCart::STATUS_PURCHASED) { | if ($order->getStatus() == PhortuneCart::STATUS_PURCHASED) { | ||||
$done_uri = $cart->getDoneURI(); | $done_uri = $order->getDoneURI(); | ||||
if ($done_uri) { | if ($done_uri) { | ||||
$header->addActionLink( | $header->addActionLink( | ||||
id(new PHUIButtonView()) | id(new PHUIButtonView()) | ||||
->setTag('a') | ->setTag('a') | ||||
->setHref($done_uri) | ->setHref($done_uri) | ||||
->setIcon('fa-check-square green') | ->setIcon('fa-check-square green') | ||||
->setText($cart->getDoneActionName())); | ->setText($order->getDoneActionName())); | ||||
} | } | ||||
} | } | ||||
$cart_box = id(new PHUIObjectBoxView()) | $order_view = id(new PhortuneOrderSummaryView()) | ||||
->setHeaderText(pht('Cart Items')) | ->setViewer($viewer) | ||||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ->setOrder($order) | ||||
->setTable($cart_table); | ->setResumeURI($resume_uri) | ||||
->setPrintable($is_printable); | |||||
$description = $this->renderCartDescription($cart); | $crumbs = null; | ||||
$curtain = null; | |||||
$charges = id(new PhortuneChargeQuery()) | $main = array(); | ||||
->setViewer($viewer) | $tail = array(); | ||||
->withCartPHIDs(array($cart->getPHID())) | |||||
->needCarts(true) | |||||
->execute(); | |||||
$charges_table = id(new PhortuneChargeTableView()) | require_celerity_resource('phortune-invoice-css'); | ||||
->setUser($viewer) | |||||
->setCharges($charges) | |||||
->setShowOrder(false); | |||||
$charges = id(new PHUIObjectBoxView()) | if ($is_printable) { | ||||
->setHeaderText(pht('Charges')) | $body_class = 'phortune-invoice-view'; | ||||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | |||||
->setTable($charges_table); | |||||
$account = $cart->getAccount(); | $tail[] = $order_view; | ||||
} else { | |||||
$body_class = 'phortune-cart-page'; | |||||
$curtain = $this->buildCurtainView( | |||||
$order, | |||||
$can_edit, | |||||
$authority, | |||||
$resume_uri); | |||||
$account = $order->getAccount(); | |||||
$crumbs = $this->buildApplicationCrumbs() | $crumbs = $this->buildApplicationCrumbs() | ||||
->addTextCrumb($account->getName(), $account->getURI()) | ->addTextCrumb($account->getName(), $account->getURI()) | ||||
->addTextCrumb(pht('Orders'), $account->getOrdersURI()) | ->addTextCrumb(pht('Orders'), $account->getOrdersURI()) | ||||
->addTextCrumb(pht('Cart %d', $cart->getID())) | ->addTextCrumb($order->getObjectName()) | ||||
->setBorder(true); | ->setBorder(true); | ||||
require_celerity_resource('phortune-css'); | $timeline = $this->buildTransactionTimeline($order) | ||||
if (!$this->action) { | |||||
$class = 'phortune-cart-page'; | |||||
$timeline = $this->buildTransactionTimeline( | |||||
$cart, | |||||
new PhortuneCartTransactionQuery()); | |||||
$timeline | |||||
->setShouldTerminate(true); | ->setShouldTerminate(true); | ||||
$view = id(new PHUITwoColumnView()) | $main[] = $order_view; | ||||
->setHeader($header) | $main[] = $timeline; | ||||
->setCurtain($curtain) | } | ||||
->setMainColumn(array( | |||||
$error_view, | |||||
$details, | |||||
$cart_box, | |||||
$description, | |||||
$charges, | |||||
$timeline, | |||||
)); | |||||
} else { | $column_view = id(new PHUITwoColumnView()) | ||||
$class = 'phortune-invoice-view'; | ->setMainColumn($main) | ||||
$crumbs = null; | ->setFooter($tail); | ||||
$merchant_phid = $cart->getMerchantPHID(); | |||||
$buyer_phid = $cart->getAuthorPHID(); | if ($curtain) { | ||||
$merchant = id(new PhortuneMerchantQuery()) | $column_view->setCurtain($curtain); | ||||
->setViewer($viewer) | |||||
->withPHIDs(array($merchant_phid)) | |||||
->needProfileImage(true) | |||||
->executeOne(); | |||||
$buyer = id(new PhabricatorPeopleQuery()) | |||||
->setViewer($viewer) | |||||
->withPHIDs(array($buyer_phid)) | |||||
->needProfileImage(true) | |||||
->executeOne(); | |||||
$merchant_contact = new PHUIRemarkupView( | |||||
$viewer, | |||||
$merchant->getContactInfo()); | |||||
$account_name = $account->getBillingName(); | |||||
if (!strlen($account_name)) { | |||||
$account_name = $buyer->getRealName(); | |||||
} | |||||
$account_contact = $account->getBillingAddress(); | |||||
if (strlen($account_contact)) { | |||||
$account_contact = new PHUIRemarkupView( | |||||
$viewer, | |||||
$account_contact); | |||||
} | |||||
$view = id(new PhortuneInvoiceView()) | |||||
->setMerchantName($merchant->getName()) | |||||
->setMerchantLogo($merchant->getProfileImageURI()) | |||||
->setMerchantContact($merchant_contact) | |||||
->setMerchantFooter($merchant->getInvoiceFooter()) | |||||
->setAccountName($account_name) | |||||
->setAccountContact($account_contact) | |||||
->setStatus($error_view) | |||||
->setContent( | |||||
array( | |||||
$details, | |||||
$cart_box, | |||||
$charges, | |||||
)); | |||||
} | } | ||||
$page = $this->newPage() | $page = $this->newPage() | ||||
->setTitle(pht('Cart %d', $cart->getID())) | ->addClass($body_class) | ||||
->addClass($class) | ->setTitle( | ||||
->appendChild($view); | array( | ||||
$order->getObjectName(), | |||||
$order->getName(), | |||||
)) | |||||
->appendChild($column_view); | |||||
if ($crumbs) { | if ($crumbs) { | ||||
$page->setCrumbs($crumbs); | $page->setCrumbs($crumbs); | ||||
} | } | ||||
return $page; | return $page; | ||||
} | } | ||||
private function buildDetailsView(PhortuneCart $cart) { | |||||
$viewer = $this->getViewer(); | |||||
$view = id(new PHUIPropertyListView()) | |||||
->setUser($viewer) | |||||
->setObject($cart); | |||||
$handles = $this->loadViewerHandles( | |||||
array( | |||||
$cart->getAccountPHID(), | |||||
$cart->getAuthorPHID(), | |||||
$cart->getMerchantPHID(), | |||||
)); | |||||
if ($this->action == 'print') { | |||||
$view->addProperty(pht('Order Name'), $cart->getName()); | |||||
} | |||||
$view->addProperty( | |||||
pht('Account'), | |||||
$handles[$cart->getAccountPHID()]->renderLink()); | |||||
$view->addProperty( | |||||
pht('Authorized By'), | |||||
$handles[$cart->getAuthorPHID()]->renderLink()); | |||||
$view->addProperty( | |||||
pht('Merchant'), | |||||
$handles[$cart->getMerchantPHID()]->renderLink()); | |||||
$view->addProperty( | |||||
pht('Status'), | |||||
PhortuneCart::getNameForStatus($cart->getStatus())); | |||||
$view->addProperty( | |||||
pht('Updated'), | |||||
phabricator_datetime($cart->getDateModified(), $viewer)); | |||||
return id(new PHUIObjectBoxView()) | |||||
->setHeaderText(pht('Details')) | |||||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | |||||
->appendChild($view); | |||||
} | |||||
private function buildCurtainView( | private function buildCurtainView( | ||||
PhortuneCart $cart, | PhortuneCart $cart, | ||||
$can_edit, | $can_edit, | ||||
$authority, | $authority, | ||||
$resume_uri) { | $resume_uri) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$id = $cart->getID(); | $id = $cart->getID(); | ||||
Show All 11 Lines | private function buildCurtainView( | ||||
$cancel_uri = $this->getApplicationURI("cart/{$id}/cancel/"); | $cancel_uri = $this->getApplicationURI("cart/{$id}/cancel/"); | ||||
$refund_uri = $this->getApplicationURI("cart/{$id}/refund/"); | $refund_uri = $this->getApplicationURI("cart/{$id}/refund/"); | ||||
$update_uri = $this->getApplicationURI("cart/{$id}/update/"); | $update_uri = $this->getApplicationURI("cart/{$id}/update/"); | ||||
$accept_uri = $this->getApplicationURI("cart/{$id}/accept/"); | $accept_uri = $this->getApplicationURI("cart/{$id}/accept/"); | ||||
$print_uri = $this->getApplicationURI("cart/{$id}/print/"); | $print_uri = $this->getApplicationURI("cart/{$id}/print/"); | ||||
$checkout_uri = $cart->getCheckoutURI(); | $checkout_uri = $cart->getCheckoutURI(); | ||||
$void_uri = $this->getApplicationURI("cart/{$id}/void/"); | $void_uri = $this->getApplicationURI("cart/{$id}/void/"); | ||||
$curtain->addAction( | |||||
id(new PhabricatorActionView()) | |||||
->setName(pht('Printable Version')) | |||||
->setHref($print_uri) | |||||
->setOpenInNewWindow(true) | |||||
->setIcon('fa-print')); | |||||
$curtain->addAction( | |||||
id(new PhabricatorActionView()) | |||||
->setType(PhabricatorActionView::TYPE_DIVIDER)); | |||||
$curtain->addAction( | $curtain->addAction( | ||||
id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
->setName(pht('Pay Now')) | ->setName(pht('Pay Now')) | ||||
->setIcon('fa-credit-card') | ->setIcon('fa-credit-card') | ||||
->setDisabled(!$can_checkout) | ->setDisabled(!$can_checkout) | ||||
->setWorkflow(!$can_checkout) | ->setWorkflow(!$can_checkout) | ||||
->setHref($checkout_uri)); | ->setHref($checkout_uri)); | ||||
Show All 14 Lines | private function buildCurtainView( | ||||
if ($can_edit && $resume_uri) { | if ($can_edit && $resume_uri) { | ||||
$curtain->addAction( | $curtain->addAction( | ||||
id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
->setName(pht('Continue Checkout')) | ->setName(pht('Continue Checkout')) | ||||
->setIcon('fa-shopping-bag') | ->setIcon('fa-shopping-bag') | ||||
->setHref($resume_uri)); | ->setHref($resume_uri)); | ||||
} | } | ||||
$curtain->addAction( | |||||
id(new PhabricatorActionView()) | |||||
->setName(pht('Printable Version')) | |||||
->setHref($print_uri) | |||||
->setOpenInNewWindow(true) | |||||
->setIcon('fa-print')); | |||||
if ($authority) { | if ($authority) { | ||||
$curtain->addAction( | $curtain->addAction( | ||||
id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
->setType(PhabricatorActionView::TYPE_DIVIDER)); | ->setType(PhabricatorActionView::TYPE_DIVIDER)); | ||||
$curtain->addAction( | $curtain->addAction( | ||||
id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
->setName(pht('Accept Order')) | ->setName(pht('Accept Order')) | ||||
Show All 26 Lines |