[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * A payment method is a credit card; it is associated with an account and 5 * charges can be made against it. 6 */ 7 final class PhortunePaymentMethod extends PhortuneDAO 8 implements PhabricatorPolicyInterface { 9 10 const STATUS_ACTIVE = 'payment:active'; 11 const STATUS_DISABLED = 'payment:disabled'; 12 13 protected $name = ''; 14 protected $status; 15 protected $accountPHID; 16 protected $authorPHID; 17 protected $merchantPHID; 18 protected $providerPHID; 19 protected $expires; 20 protected $metadata = array(); 21 protected $brand; 22 protected $lastFourDigits; 23 24 private $account = self::ATTACHABLE; 25 private $merchant = self::ATTACHABLE; 26 private $providerConfig = self::ATTACHABLE; 27 28 public function getConfiguration() { 29 return array( 30 self::CONFIG_AUX_PHID => true, 31 self::CONFIG_SERIALIZATION => array( 32 'metadata' => self::SERIALIZATION_JSON, 33 ), 34 self::CONFIG_COLUMN_SCHEMA => array( 35 'name' => 'text255', 36 'status' => 'text64', 37 'brand' => 'text64', 38 'expires' => 'text16', 39 'lastFourDigits' => 'text16', 40 ), 41 self::CONFIG_KEY_SCHEMA => array( 42 'key_account' => array( 43 'columns' => array('accountPHID', 'status'), 44 ), 45 'key_merchant' => array( 46 'columns' => array('merchantPHID', 'accountPHID'), 47 ), 48 ), 49 ) + parent::getConfiguration(); 50 } 51 52 public function generatePHID() { 53 return PhabricatorPHID::generateNewPHID( 54 PhortunePaymentMethodPHIDType::TYPECONST); 55 } 56 57 public function attachAccount(PhortuneAccount $account) { 58 $this->account = $account; 59 return $this; 60 } 61 62 public function getAccount() { 63 return $this->assertAttached($this->account); 64 } 65 66 public function attachMerchant(PhortuneMerchant $merchant) { 67 $this->merchant = $merchant; 68 return $this; 69 } 70 71 public function getMerchant() { 72 return $this->assertAttached($this->merchant); 73 } 74 75 public function attachProviderConfig(PhortunePaymentProviderConfig $config) { 76 $this->providerConfig = $config; 77 return $this; 78 } 79 80 public function getProviderConfig() { 81 return $this->assertAttached($this->providerConfig); 82 } 83 84 public function getDescription() { 85 $provider = $this->buildPaymentProvider(); 86 return $provider->getPaymentMethodProviderDescription(); 87 } 88 89 public function getMetadataValue($key, $default = null) { 90 return idx($this->getMetadata(), $key, $default); 91 } 92 93 public function setMetadataValue($key, $value) { 94 $this->metadata[$key] = $value; 95 return $this; 96 } 97 98 public function buildPaymentProvider() { 99 return $this->getProviderConfig()->buildProvider(); 100 } 101 102 public function getDisplayName() { 103 if (strlen($this->name)) { 104 return $this->name; 105 } 106 107 $provider = $this->buildPaymentProvider(); 108 return $provider->getDefaultPaymentMethodDisplayName($this); 109 } 110 111 public function getFullDisplayName() { 112 return pht('%s (%s)', $this->getDisplayName(), $this->getSummary()); 113 } 114 115 public function getSummary() { 116 return pht('%s %s', $this->getBrand(), $this->getLastFourDigits()); 117 } 118 119 public function setExpires($year, $month) { 120 $this->expires = $year.'-'.$month; 121 return $this; 122 } 123 124 public function getDisplayExpires() { 125 list($year, $month) = explode('-', $this->getExpires()); 126 $month = sprintf('%02d', $month); 127 $year = substr($year, -2); 128 return $month.'/'.$year; 129 } 130 131 132 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 133 134 135 public function getCapabilities() { 136 return array( 137 PhabricatorPolicyCapability::CAN_VIEW, 138 PhabricatorPolicyCapability::CAN_EDIT, 139 ); 140 } 141 142 public function getPolicy($capability) { 143 return $this->getAccount()->getPolicy($capability); 144 } 145 146 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 147 return $this->getAccount()->hasAutomaticCapability( 148 $capability, 149 $viewer); 150 } 151 152 public function describeAutomaticCapability($capability) { 153 return pht( 154 'Members of an account can always view and edit its payment methods.'); 155 } 156 157 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |