[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/phortune/controller/ -> PhortuneCartUpdateController.php (source)

   1  <?php
   2  
   3  final class PhortuneCartUpdateController
   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      $charges = id(new PhortuneChargeQuery())
  26        ->setViewer($viewer)
  27        ->withCartPHIDs(array($cart->getPHID()))
  28        ->needCarts(true)
  29        ->withStatuses(
  30          array(
  31            PhortuneCharge::STATUS_HOLD,
  32            PhortuneCharge::STATUS_CHARGED,
  33          ))
  34        ->execute();
  35  
  36      if ($charges) {
  37        $providers = id(new PhortunePaymentProviderConfigQuery())
  38          ->setViewer($viewer)
  39          ->withPHIDs(mpull($charges, 'getProviderPHID'))
  40          ->execute();
  41        $providers = mpull($providers, null, 'getPHID');
  42      } else {
  43        $providers = array();
  44      }
  45  
  46      foreach ($charges as $charge) {
  47        if ($charge->isRefund()) {
  48          // Don't update refunds.
  49          continue;
  50        }
  51  
  52        $provider_config = idx($providers, $charge->getProviderPHID());
  53        if (!$provider_config) {
  54          throw new Exception(pht('Unable to load provider for charge!'));
  55        }
  56  
  57        $provider = $provider_config->buildProvider();
  58        $provider->updateCharge($charge);
  59      }
  60  
  61      return id(new AphrontRedirectResponse())
  62        ->setURI($cart->getDetailURI());
  63    }
  64  
  65  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1