Differential D20735 Diff 49444 src/applications/phortune/controller/cart/PhortuneCartUpdateController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phortune/controller/cart/PhortuneCartUpdateController.php
<?php | <?php | ||||
final class PhortuneCartUpdateController | final class PhortuneCartUpdateController | ||||
extends PhortuneCartController { | extends PhortuneCartController { | ||||
public function handleRequest(AphrontRequest $request) { | protected function shouldRequireAccountAuthority() { | ||||
$viewer = $request->getViewer(); | return false; | ||||
$id = $request->getURIData('id'); | |||||
$authority = $this->loadMerchantAuthority(); | |||||
$cart_query = id(new PhortuneCartQuery()) | |||||
->setViewer($viewer) | |||||
->withIDs(array($id)) | |||||
->needPurchases(true); | |||||
if ($authority) { | |||||
$cart_query->withMerchantPHIDs(array($authority->getPHID())); | |||||
} | } | ||||
$cart = $cart_query->executeOne(); | protected function shouldRequireMerchantAuthority() { | ||||
if (!$cart) { | return false; | ||||
return new Aphront404Response(); | |||||
} | } | ||||
protected function handleCartRequest(AphrontRequest $request) { | |||||
$viewer = $request->getViewer(); | |||||
$id = $request->getURIData('id'); | |||||
$cart = $this->getCart(); | |||||
$authority = $this->getMerchantAuthority(); | |||||
$charges = id(new PhortuneChargeQuery()) | $charges = id(new PhortuneChargeQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withCartPHIDs(array($cart->getPHID())) | ->withCartPHIDs(array($cart->getPHID())) | ||||
->needCarts(true) | ->needCarts(true) | ||||
->withStatuses( | ->withStatuses( | ||||
array( | array( | ||||
PhortuneCharge::STATUS_HOLD, | PhortuneCharge::STATUS_HOLD, | ||||
PhortuneCharge::STATUS_CHARGED, | PhortuneCharge::STATUS_CHARGED, | ||||
Show All 21 Lines | foreach ($charges as $charge) { | ||||
throw new Exception(pht('Unable to load provider for charge!')); | throw new Exception(pht('Unable to load provider for charge!')); | ||||
} | } | ||||
$provider = $provider_config->buildProvider(); | $provider = $provider_config->buildProvider(); | ||||
$provider->updateCharge($charge); | $provider->updateCharge($charge); | ||||
} | } | ||||
return id(new AphrontRedirectResponse()) | return id(new AphrontRedirectResponse()) | ||||
->setURI($cart->getDetailURI($authority)); | ->setURI($cart->getDetailURI()); | ||||
} | } | ||||
} | } |