[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhortuneCartViewController 4 extends PhortuneCartController { 5 6 private $id; 7 8 public function willProcessRequest(array $data) { 9 $this->id = $data['id']; 10 } 11 12 public function processRequest() { 13 $request = $this->getRequest(); 14 $viewer = $request->getUser(); 15 16 $cart = id(new PhortuneCartQuery()) 17 ->setViewer($viewer) 18 ->withIDs(array($this->id)) 19 ->needPurchases(true) 20 ->executeOne(); 21 if (!$cart) { 22 return new Aphront404Response(); 23 } 24 25 $can_admin = PhabricatorPolicyFilter::hasCapability( 26 $viewer, 27 $cart->getMerchant(), 28 PhabricatorPolicyCapability::CAN_EDIT); 29 30 $cart_table = $this->buildCartContentTable($cart); 31 32 $can_edit = PhabricatorPolicyFilter::hasCapability( 33 $viewer, 34 $cart, 35 PhabricatorPolicyCapability::CAN_EDIT); 36 37 $errors = array(); 38 $error_view = null; 39 $resume_uri = null; 40 switch ($cart->getStatus()) { 41 case PhortuneCart::STATUS_PURCHASING: 42 if ($can_edit) { 43 $resume_uri = $cart->getMetadataValue('provider.checkoutURI'); 44 if ($resume_uri) { 45 $errors[] = pht( 46 'The checkout process has been started, but not yet completed. '. 47 'You can continue checking out by clicking %s, or cancel the '. 48 'order, or contact the merchant for assistance.', 49 phutil_tag('strong', array(), pht('Continue Checkout'))); 50 } else { 51 $errors[] = pht( 52 'The checkout process has been started, but an error occurred. '. 53 'You can cancel the order or contact the merchant for '. 54 'assistance.'); 55 } 56 } 57 break; 58 case PhortuneCart::STATUS_CHARGED: 59 if ($can_edit) { 60 $errors[] = pht( 61 'You have been charged, but processing could not be completed. '. 62 'You can cancel your order, or contact the merchant for '. 63 'assistance.'); 64 } 65 break; 66 case PhortuneCart::STATUS_HOLD: 67 if ($can_edit) { 68 $errors[] = pht( 69 'Payment for this order is on hold. You can click %s to check '. 70 'for updates, cancel the order, or contact the merchant for '. 71 'assistance.', 72 phutil_tag('strong', array(), pht('Update Status'))); 73 } 74 break; 75 case PhortuneCart::STATUS_REVIEW: 76 if ($can_admin) { 77 $errors[] = pht( 78 'This order has been flagged for manual review. Review the order '. 79 'and choose %s to accept it or %s to reject it.', 80 phutil_tag('strong', array(), pht('Accept Order')), 81 phutil_tag('strong', array(), pht('Refund Order'))); 82 } else if ($can_edit) { 83 $errors[] = pht( 84 'This order requires manual processing and will complete once '. 85 'the merchant accepts it.'); 86 } 87 break; 88 case PhortuneCart::STATUS_PURCHASED: 89 $error_view = id(new AphrontErrorView()) 90 ->setSeverity(AphrontErrorView::SEVERITY_NOTICE) 91 ->appendChild(pht('This purchase has been completed.')); 92 93 break; 94 } 95 96 $properties = $this->buildPropertyListView($cart); 97 $actions = $this->buildActionListView( 98 $cart, 99 $can_edit, 100 $can_admin, 101 $resume_uri); 102 $properties->setActionList($actions); 103 104 $header = id(new PHUIHeaderView()) 105 ->setUser($viewer) 106 ->setHeader(pht('Order Detail')); 107 108 if ($cart->getStatus() == PhortuneCart::STATUS_PURCHASED) { 109 $done_uri = $cart->getDoneURI(); 110 if ($done_uri) { 111 $header->addActionLink( 112 id(new PHUIButtonView()) 113 ->setTag('a') 114 ->setHref($done_uri) 115 ->setIcon(id(new PHUIIconView()) 116 ->setIconFont('fa-check-square green')) 117 ->setText($cart->getDoneActionName())); 118 } 119 } 120 121 $cart_box = id(new PHUIObjectBoxView()) 122 ->setHeader($header) 123 ->appendChild($properties) 124 ->appendChild($cart_table); 125 126 if ($errors) { 127 $cart_box->setFormErrors($errors); 128 } else if ($error_view) { 129 $cart_box->setErrorView($error_view); 130 } 131 132 $charges = id(new PhortuneChargeQuery()) 133 ->setViewer($viewer) 134 ->withCartPHIDs(array($cart->getPHID())) 135 ->needCarts(true) 136 ->execute(); 137 138 $phids = array(); 139 foreach ($charges as $charge) { 140 $phids[] = $charge->getProviderPHID(); 141 $phids[] = $charge->getCartPHID(); 142 $phids[] = $charge->getMerchantPHID(); 143 $phids[] = $charge->getPaymentMethodPHID(); 144 } 145 $handles = $this->loadViewerHandles($phids); 146 147 $charges_table = id(new PhortuneChargeTableView()) 148 ->setUser($viewer) 149 ->setHandles($handles) 150 ->setCharges($charges) 151 ->setShowOrder(false); 152 153 $charges = id(new PHUIObjectBoxView()) 154 ->setHeaderText(pht('Charges')) 155 ->appendChild($charges_table); 156 157 $account = $cart->getAccount(); 158 159 $crumbs = $this->buildApplicationCrumbs(); 160 $this->addAccountCrumb($crumbs, $cart->getAccount()); 161 $crumbs->addTextCrumb(pht('Cart %d', $cart->getID())); 162 $crumbs->setActionList($actions); 163 164 $xactions = id(new PhortuneCartTransactionQuery()) 165 ->setViewer($viewer) 166 ->withObjectPHIDs(array($cart->getPHID())) 167 ->execute(); 168 169 $xaction_view = id(new PhabricatorApplicationTransactionView()) 170 ->setUser($viewer) 171 ->setObjectPHID($cart->getPHID()) 172 ->setTransactions($xactions) 173 ->setShouldTerminate(true); 174 175 return $this->buildApplicationPage( 176 array( 177 $crumbs, 178 $cart_box, 179 $charges, 180 $xaction_view, 181 ), 182 array( 183 'title' => pht('Cart'), 184 )); 185 186 } 187 188 private function buildPropertyListView(PhortuneCart $cart) { 189 190 $viewer = $this->getRequest()->getUser(); 191 192 $view = id(new PHUIPropertyListView()) 193 ->setUser($viewer) 194 ->setObject($cart); 195 196 $handles = $this->loadViewerHandles( 197 array( 198 $cart->getAccountPHID(), 199 $cart->getAuthorPHID(), 200 $cart->getMerchantPHID(), 201 )); 202 203 $view->addProperty( 204 pht('Order Name'), 205 $cart->getName()); 206 $view->addProperty( 207 pht('Account'), 208 $handles[$cart->getAccountPHID()]->renderLink()); 209 $view->addProperty( 210 pht('Authorized By'), 211 $handles[$cart->getAuthorPHID()]->renderLink()); 212 $view->addProperty( 213 pht('Merchant'), 214 $handles[$cart->getMerchantPHID()]->renderLink()); 215 $view->addProperty( 216 pht('Status'), 217 PhortuneCart::getNameForStatus($cart->getStatus())); 218 $view->addProperty( 219 pht('Updated'), 220 phabricator_datetime($cart->getDateModified(), $viewer)); 221 222 return $view; 223 } 224 225 private function buildActionListView( 226 PhortuneCart $cart, 227 $can_edit, 228 $can_admin, 229 $resume_uri) { 230 231 $viewer = $this->getRequest()->getUser(); 232 $id = $cart->getID(); 233 234 $view = id(new PhabricatorActionListView()) 235 ->setUser($viewer) 236 ->setObject($cart); 237 238 $can_cancel = ($can_edit && $cart->canCancelOrder()); 239 240 $cancel_uri = $this->getApplicationURI("cart/{$id}/cancel/"); 241 $refund_uri = $this->getApplicationURI("cart/{$id}/refund/"); 242 $update_uri = $this->getApplicationURI("cart/{$id}/update/"); 243 $accept_uri = $this->getApplicationURI("cart/{$id}/accept/"); 244 245 $view->addAction( 246 id(new PhabricatorActionView()) 247 ->setName(pht('Cancel Order')) 248 ->setIcon('fa-times') 249 ->setDisabled(!$can_cancel) 250 ->setWorkflow(true) 251 ->setHref($cancel_uri)); 252 253 if ($can_admin) { 254 if ($cart->getStatus() == PhortuneCart::STATUS_REVIEW) { 255 $view->addAction( 256 id(new PhabricatorActionView()) 257 ->setName(pht('Accept Order')) 258 ->setIcon('fa-check') 259 ->setWorkflow(true) 260 ->setHref($accept_uri)); 261 } 262 263 $view->addAction( 264 id(new PhabricatorActionView()) 265 ->setName(pht('Refund Order')) 266 ->setIcon('fa-reply') 267 ->setWorkflow(true) 268 ->setHref($refund_uri)); 269 } 270 271 $view->addAction( 272 id(new PhabricatorActionView()) 273 ->setName(pht('Update Status')) 274 ->setIcon('fa-refresh') 275 ->setHref($update_uri)); 276 277 if ($can_edit && $resume_uri) { 278 $view->addAction( 279 id(new PhabricatorActionView()) 280 ->setName(pht('Continue Checkout')) 281 ->setIcon('fa-shopping-cart') 282 ->setHref($resume_uri)); 283 } 284 285 return $view; 286 } 287 288 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |