3 final class PhortunePaymentProviderConfig
extends PhortuneDAO
5 PhabricatorPolicyInterface
,
6 PhabricatorApplicationTransactionInterface
{
8 protected $merchantPHID;
9 protected $providerClassKey;
10 protected $providerClass;
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)
24 protected function getConfiguration() {
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'),
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;
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;
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() {
85 '/phortune/merchant/%d/providers/%d/',
86 $this->getMerchant()->getID(),
91 /* -( PhabricatorPolicyInterface )----------------------------------------- */
94 public function getCapabilities() {
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();