[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class PhortuneProviderDisableController
   4    extends PhortuneMerchantController {
   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      $provider_config = id(new PhortunePaymentProviderConfigQuery())
  17        ->setViewer($viewer)
  18        ->withIDs(array($this->id))
  19        ->requireCapabilities(
  20          array(
  21            PhabricatorPolicyCapability::CAN_VIEW,
  22            PhabricatorPolicyCapability::CAN_EDIT,
  23          ))
  24        ->executeOne();
  25      if (!$provider_config) {
  26        return new Aphront404Response();
  27      }
  28  
  29      $merchant = $provider_config->getMerchant();
  30      $merchant_id = $merchant->getID();
  31      $cancel_uri = $this->getApplicationURI("merchant/{$merchant_id}/");
  32  
  33      $provider = $provider_config->buildProvider();
  34  
  35      if ($request->isFormPost()) {
  36        $new_status = !$provider_config->getIsEnabled();
  37  
  38        $xactions = array();
  39        $xactions[] = id(new PhortunePaymentProviderConfigTransaction())
  40          ->setTransactionType(
  41            PhortunePaymentProviderConfigTransaction::TYPE_ENABLE)
  42          ->setNewValue($new_status);
  43  
  44        $editor = id(new PhortunePaymentProviderConfigEditor())
  45          ->setActor($viewer)
  46          ->setContentSourceFromRequest($request)
  47          ->setContinueOnNoEffect(true)
  48          ->setContinueOnMissingFields(true);
  49  
  50        $editor->applyTransactions($provider_config, $xactions);
  51  
  52        return id(new AphrontRedirectResponse())->setURI($cancel_uri);
  53      }
  54  
  55      if ($provider_config->getIsEnabled()) {
  56        $title = pht('Disable Provider?');
  57        $body = pht(
  58          'If you disable this payment provider, users will no longer be able '.
  59          'to use it to make new payments.');
  60        $button = pht('Disable Provider');
  61      } else {
  62        $title = pht('Enable Provider?');
  63        $body = pht(
  64          'If you enable this payment provider, users will be able to use it to '.
  65          'make new payments.');
  66        $button = pht('Enable Provider');
  67      }
  68  
  69      return $this->newDialog()
  70        ->setTitle($title)
  71        ->appendParagraph($body)
  72        ->addSubmitButton($button)
  73        ->addCancelButton($cancel_uri);
  74    }
  75  
  76  }


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