Differential D20735 Diff 49444 src/applications/phortune/controller/cart/PhortuneCartCancelController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phortune/controller/cart/PhortuneCartCancelController.php
<?php | <?php | ||||
final class PhortuneCartCancelController | final class PhortuneCartCancelController | ||||
extends PhortuneCartController { | extends PhortuneCartController { | ||||
public function handleRequest(AphrontRequest $request) { | protected function shouldRequireAccountAuthority() { | ||||
return false; | |||||
} | |||||
protected function shouldRequireMerchantAuthority() { | |||||
return false; | |||||
} | |||||
protected function handleCartRequest(AphrontRequest $request) { | |||||
$viewer = $request->getViewer(); | $viewer = $request->getViewer(); | ||||
$id = $request->getURIData('id'); | $id = $request->getURIData('id'); | ||||
$action = $request->getURIData('action'); | $action = $request->getURIData('action'); | ||||
$authority = $this->loadMerchantAuthority(); | $cart = $this->getCart(); | ||||
$authority = $this->getMerchantAuthority(); | |||||
$cart_query = id(new PhortuneCartQuery()) | |||||
->setViewer($viewer) | |||||
->withIDs(array($id)) | |||||
->needPurchases(true); | |||||
if ($authority) { | |||||
$cart_query->withMerchantPHIDs(array($authority->getPHID())); | |||||
} | |||||
$cart = $cart_query->executeOne(); | |||||
if (!$cart) { | |||||
return new Aphront404Response(); | |||||
} | |||||
switch ($action) { | switch ($action) { | ||||
case 'cancel': | case 'cancel': | ||||
// You must be able to edit the account to cancel an order. | // You must be able to edit the account to cancel an order. | ||||
PhabricatorPolicyFilter::requireCapability( | PhabricatorPolicyFilter::requireCapability( | ||||
$viewer, | $viewer, | ||||
$cart->getAccount(), | $cart->getAccount(), | ||||
PhabricatorPolicyCapability::CAN_EDIT); | PhabricatorPolicyCapability::CAN_EDIT); | ||||
$is_refund = false; | $is_refund = false; | ||||
break; | break; | ||||
case 'refund': | case 'refund': | ||||
// You must be able to control the merchant to refund an order. | // You must be able to control the merchant to refund an order. | ||||
PhabricatorPolicyFilter::requireCapability( | PhabricatorPolicyFilter::requireCapability( | ||||
$viewer, | $viewer, | ||||
$cart->getMerchant(), | $cart->getMerchant(), | ||||
PhabricatorPolicyCapability::CAN_EDIT); | PhabricatorPolicyCapability::CAN_EDIT); | ||||
$is_refund = true; | $is_refund = true; | ||||
break; | break; | ||||
default: | default: | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$cancel_uri = $cart->getDetailURI($authority); | $cancel_uri = $cart->getDetailURI(); | ||||
$merchant = $cart->getMerchant(); | $merchant = $cart->getMerchant(); | ||||
try { | try { | ||||
if ($is_refund) { | if ($is_refund) { | ||||
$title = pht('Unable to Refund Order'); | $title = pht('Unable to Refund Order'); | ||||
$cart->assertCanRefundOrder(); | $cart->assertCanRefundOrder(); | ||||
} else { | } else { | ||||
$title = pht('Unable to Cancel Order'); | $title = pht('Unable to Cancel Order'); | ||||
$cart->assertCanCancelOrder(); | $cart->assertCanCancelOrder(); | ||||
} | } | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
return $this->newDialog() | return $this->newDialog() | ||||
->setTitle($title) | ->setTitle($title) | ||||
->appendChild($ex->getMessage()) | ->appendChild($ex->getMessage()) | ||||
->addCancelButton($cancel_uri); | ->addCancelButton($cancel_uri, pht('Rats')); | ||||
} | } | ||||
$charges = id(new PhortuneChargeQuery()) | $charges = id(new PhortuneChargeQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withCartPHIDs(array($cart->getPHID())) | ->withCartPHIDs(array($cart->getPHID())) | ||||
->withStatuses( | ->withStatuses( | ||||
array( | array( | ||||
PhortuneCharge::STATUS_HOLD, | PhortuneCharge::STATUS_HOLD, | ||||
▲ Show 20 Lines • Show All 135 Lines • Show Last 20 Lines |