Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / phortune / storage / PhortunePaymentProviderConfig.php
blob985906519cd6e3785d12461ba0f217847f855a3a
1 <?php
3 final class PhortunePaymentProviderConfig extends PhortuneDAO
4 implements
5 PhabricatorPolicyInterface,
6 PhabricatorApplicationTransactionInterface {
8 protected $merchantPHID;
9 protected $providerClassKey;
10 protected $providerClass;
11 protected $isEnabled;
12 protected $metadata = array();
14 private $merchant = self::ATTACHABLE;
16 public static function initializeNewProvider(
17 PhortuneMerchant $merchant) {
18 return id(new PhortunePaymentProviderConfig())
19 ->setMerchantPHID($merchant->getPHID())
20 ->attachMerchant($merchant)
21 ->setIsEnabled(1);
24 protected function getConfiguration() {
25 return array(
26 self::CONFIG_AUX_PHID => true,
27 self::CONFIG_SERIALIZATION => array(
28 'metadata' => self::SERIALIZATION_JSON,
30 self::CONFIG_COLUMN_SCHEMA => array(
31 'providerClassKey' => 'bytes12',
32 'providerClass' => 'text128',
33 'isEnabled' => 'bool',
35 self::CONFIG_KEY_SCHEMA => array(
36 'key_merchant' => array(
37 'columns' => array('merchantPHID', 'providerClassKey'),
38 'unique' => true,
41 ) + parent::getConfiguration();
44 public function save() {
45 $this->providerClassKey = PhabricatorHash::digestForIndex(
46 $this->providerClass);
48 return parent::save();
51 public function generatePHID() {
52 return PhabricatorPHID::generateNewPHID(
53 PhortunePaymentProviderPHIDType::TYPECONST);
56 public function attachMerchant(PhortuneMerchant $merchant) {
57 $this->merchant = $merchant;
58 return $this;
61 public function getMerchant() {
62 return $this->assertAttached($this->merchant);
65 public function getMetadataValue($key, $default = null) {
66 return idx($this->metadata, $key, $default);
69 public function setMetadataValue($key, $value) {
70 $this->metadata[$key] = $value;
71 return $this;
74 public function buildProvider() {
75 return newv($this->getProviderClass(), array())
76 ->setProviderConfig($this);
79 public function getObjectName() {
80 return pht('Provider %d', $this->getID());
83 public function getURI() {
84 return urisprintf(
85 '/phortune/merchant/%d/providers/%d/',
86 $this->getMerchant()->getID(),
87 $this->getID());
91 /* -( PhabricatorPolicyInterface )----------------------------------------- */
94 public function getCapabilities() {
95 return array(
96 PhabricatorPolicyCapability::CAN_VIEW,
97 PhabricatorPolicyCapability::CAN_EDIT,
101 public function getPolicy($capability) {
102 return $this->getMerchant()->getPolicy($capability);
105 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
106 return $this->getMerchant()->hasAutomaticCapability($capability, $viewer);
109 public function describeAutomaticCapability($capability) {
110 return pht('Providers have the policies of their merchant.');
114 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
117 public function getApplicationTransactionEditor() {
118 return new PhortunePaymentProviderConfigEditor();
121 public function getApplicationTransactionTemplate() {
122 return new PhortunePaymentProviderConfigTransaction();