[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/phortune/storage/ -> PhortunePaymentProviderConfig.php (source)

   1  <?php
   2  
   3  final class PhortunePaymentProviderConfig extends PhortuneDAO
   4    implements PhabricatorPolicyInterface {
   5  
   6    protected $merchantPHID;
   7    protected $providerClassKey;
   8    protected $providerClass;
   9    protected $isEnabled;
  10    protected $metadata = array();
  11  
  12    private $merchant = self::ATTACHABLE;
  13  
  14    public static function initializeNewProvider(
  15      PhortuneMerchant $merchant) {
  16      return id(new PhortunePaymentProviderConfig())
  17        ->setMerchantPHID($merchant->getPHID())
  18        ->setIsEnabled(1);
  19    }
  20  
  21    public function getConfiguration() {
  22      return array(
  23        self::CONFIG_AUX_PHID => true,
  24        self::CONFIG_SERIALIZATION => array(
  25          'metadata' => self::SERIALIZATION_JSON,
  26        ),
  27        self::CONFIG_COLUMN_SCHEMA => array(
  28          'providerClassKey' => 'bytes12',
  29          'providerClass' => 'text128',
  30          'isEnabled' => 'bool',
  31        ),
  32        self::CONFIG_KEY_SCHEMA => array(
  33          'key_merchant' => array(
  34            'columns' => array('merchantPHID', 'providerClassKey'),
  35            'unique' => true,
  36          ),
  37        ),
  38      ) + parent::getConfiguration();
  39    }
  40  
  41    public function save() {
  42      $this->providerClassKey = PhabricatorHash::digestForIndex(
  43        $this->providerClass);
  44  
  45      return parent::save();
  46    }
  47  
  48    public function generatePHID() {
  49      return PhabricatorPHID::generateNewPHID(
  50        PhortunePaymentProviderPHIDType::TYPECONST);
  51    }
  52  
  53    public function attachMerchant(PhortuneMerchant $merchant) {
  54      $this->merchant = $merchant;
  55      return $this;
  56    }
  57  
  58    public function getMerchant() {
  59      return $this->assertAttached($this->merchant);
  60    }
  61  
  62    public function getMetadataValue($key, $default = null) {
  63      return idx($this->metadata, $key, $default);
  64    }
  65  
  66    public function setMetadataValue($key, $value) {
  67      $this->metadata[$key] = $value;
  68      return $this;
  69    }
  70  
  71    public function buildProvider() {
  72      return newv($this->getProviderClass(), array())
  73        ->setProviderConfig($this);
  74    }
  75  
  76  
  77  /* -(  PhabricatorPolicyInterface  )----------------------------------------- */
  78  
  79  
  80    public function getCapabilities() {
  81      return array(
  82        PhabricatorPolicyCapability::CAN_VIEW,
  83        PhabricatorPolicyCapability::CAN_EDIT,
  84      );
  85    }
  86  
  87    public function getPolicy($capability) {
  88      return $this->getMerchant()->getPolicy($capability);
  89    }
  90  
  91    public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
  92      return $this->getMerchant()->hasAutomaticCapability($capability, $viewer);
  93    }
  94  
  95    public function describeAutomaticCapability($capability) {
  96      return pht('Providers have the policies of their merchant.');
  97    }
  98  
  99  }


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