[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @task addmethod Adding Payment Methods 5 */ 6 abstract class PhortunePaymentProvider { 7 8 private $providerConfig; 9 10 public function setProviderConfig( 11 PhortunePaymentProviderConfig $provider_config) { 12 $this->providerConfig = $provider_config; 13 return $this; 14 } 15 16 public function getProviderConfig() { 17 return $this->providerConfig; 18 } 19 20 /** 21 * Return a short name which identifies this provider. 22 */ 23 abstract public function getName(); 24 25 26 /* -( Configuring Providers )---------------------------------------------- */ 27 28 29 /** 30 * Return a human-readable provider name for use on the merchant workflow 31 * where a merchant owner adds providers. 32 */ 33 abstract public function getConfigureName(); 34 35 36 /** 37 * Return a human-readable provider description for use on the merchant 38 * workflow where a merchant owner adds providers. 39 */ 40 abstract public function getConfigureDescription(); 41 42 abstract public function getConfigureInstructions(); 43 44 abstract public function getConfigureProvidesDescription(); 45 46 abstract public function getAllConfigurableProperties(); 47 48 abstract public function getAllConfigurableSecretProperties(); 49 /** 50 * Read a dictionary of properties from the provider's configuration for 51 * use when editing the provider. 52 */ 53 public function readEditFormValuesFromProviderConfig() { 54 $properties = $this->getAllConfigurableProperties(); 55 $config = $this->getProviderConfig(); 56 57 $secrets = $this->getAllConfigurableSecretProperties(); 58 $secrets = array_fuse($secrets); 59 60 $map = array(); 61 foreach ($properties as $property) { 62 $map[$property] = $config->getMetadataValue($property); 63 if (isset($secrets[$property])) { 64 $map[$property] = $this->renderConfigurationSecret($map[$property]); 65 } 66 } 67 68 return $map; 69 } 70 71 72 /** 73 * Read a dictionary of properties from a request for use when editing the 74 * provider. 75 */ 76 public function readEditFormValuesFromRequest(AphrontRequest $request) { 77 $properties = $this->getAllConfigurableProperties(); 78 79 $map = array(); 80 foreach ($properties as $property) { 81 $map[$property] = $request->getStr($property); 82 } 83 84 return $map; 85 } 86 87 88 abstract public function processEditForm( 89 AphrontRequest $request, 90 array $values); 91 92 abstract public function extendEditForm( 93 AphrontRequest $request, 94 AphrontFormView $form, 95 array $values, 96 array $issues); 97 98 protected function renderConfigurationSecret($value) { 99 if (strlen($value)) { 100 return str_repeat('*', strlen($value)); 101 } 102 return ''; 103 } 104 105 public function isConfigurationSecret($value) { 106 return preg_match('/^\*+\z/', trim($value)); 107 } 108 109 abstract public function canRunConfigurationTest(); 110 111 public function runConfigurationTest() { 112 throw new PhortuneNotImplementedException($this); 113 } 114 115 116 /* -( Selecting Providers )------------------------------------------------ */ 117 118 119 public static function getAllProviders() { 120 return id(new PhutilSymbolLoader()) 121 ->setAncestorClass('PhortunePaymentProvider') 122 ->loadObjects(); 123 } 124 125 public function isEnabled() { 126 return $this->getProviderConfig()->getIsEnabled(); 127 } 128 129 abstract public function isAcceptingLivePayments(); 130 abstract public function getPaymentMethodDescription(); 131 abstract public function getPaymentMethodIcon(); 132 abstract public function getPaymentMethodProviderDescription(); 133 134 final public function applyCharge( 135 PhortunePaymentMethod $payment_method, 136 PhortuneCharge $charge) { 137 $this->executeCharge($payment_method, $charge); 138 } 139 140 final public function refundCharge( 141 PhortuneCharge $charge, 142 PhortuneCharge $refund) { 143 $this->executeRefund($charge, $refund); 144 } 145 146 abstract protected function executeCharge( 147 PhortunePaymentMethod $payment_method, 148 PhortuneCharge $charge); 149 150 abstract protected function executeRefund( 151 PhortuneCharge $charge, 152 PhortuneCharge $refund); 153 154 abstract public function updateCharge(PhortuneCharge $charge); 155 156 157 /* -( Adding Payment Methods )--------------------------------------------- */ 158 159 160 /** 161 * @task addmethod 162 */ 163 public function canCreatePaymentMethods() { 164 return false; 165 } 166 167 168 /** 169 * @task addmethod 170 */ 171 public function translateCreatePaymentMethodErrorCode($error_code) { 172 throw new PhortuneNotImplementedException($this); 173 } 174 175 176 /** 177 * @task addmethod 178 */ 179 public function getCreatePaymentMethodErrorMessage($error_code) { 180 throw new PhortuneNotImplementedException($this); 181 } 182 183 184 /** 185 * @task addmethod 186 */ 187 public function validateCreatePaymentMethodToken(array $token) { 188 throw new PhortuneNotImplementedException($this); 189 } 190 191 192 /** 193 * @task addmethod 194 */ 195 public function createPaymentMethodFromRequest( 196 AphrontRequest $request, 197 PhortunePaymentMethod $method, 198 array $token) { 199 throw new PhortuneNotImplementedException($this); 200 } 201 202 203 /** 204 * @task addmethod 205 */ 206 public function renderCreatePaymentMethodForm( 207 AphrontRequest $request, 208 array $errors) { 209 throw new PhortuneNotImplementedException($this); 210 } 211 212 public function getDefaultPaymentMethodDisplayName( 213 PhortunePaymentMethod $method) { 214 throw new PhortuneNotImplementedException($this); 215 } 216 217 218 /* -( One-Time Payments )-------------------------------------------------- */ 219 220 221 public function canProcessOneTimePayments() { 222 return false; 223 } 224 225 public function renderOneTimePaymentButton( 226 PhortuneAccount $account, 227 PhortuneCart $cart, 228 PhabricatorUser $user) { 229 230 require_celerity_resource('phortune-css'); 231 232 $description = $this->getPaymentMethodProviderDescription(); 233 $details = $this->getPaymentMethodDescription(); 234 235 $icon = id(new PHUIIconView()) 236 ->setSpriteSheet(PHUIIconView::SPRITE_LOGIN) 237 ->setSpriteIcon($this->getPaymentMethodIcon()); 238 239 $button = id(new PHUIButtonView()) 240 ->setSize(PHUIButtonView::BIG) 241 ->setColor(PHUIButtonView::GREY) 242 ->setIcon($icon) 243 ->setText($description) 244 ->setSubtext($details); 245 246 // NOTE: We generate a local URI to make sure the form picks up CSRF tokens. 247 $uri = $this->getControllerURI( 248 'checkout', 249 array( 250 'cartID' => $cart->getID(), 251 ), 252 $local = true); 253 254 return phabricator_form( 255 $user, 256 array( 257 'action' => $uri, 258 'method' => 'POST', 259 ), 260 $button); 261 } 262 263 264 /* -( Controllers )-------------------------------------------------------- */ 265 266 267 final public function getControllerURI( 268 $action, 269 array $params = array(), 270 $local = false) { 271 272 $id = $this->getProviderConfig()->getID(); 273 $app = PhabricatorApplication::getByClass('PhabricatorPhortuneApplication'); 274 $path = $app->getBaseURI().'provider/'.$id.'/'.$action.'/'; 275 276 $uri = new PhutilURI($path); 277 $uri->setQueryParams($params); 278 279 if ($local) { 280 return $uri; 281 } else { 282 return PhabricatorEnv::getURI((string)$uri); 283 } 284 } 285 286 public function canRespondToControllerAction($action) { 287 return false; 288 } 289 290 public function processControllerRequest( 291 PhortuneProviderActionController $controller, 292 AphrontRequest $request) { 293 throw new PhortuneNotImplementedException($this); 294 } 295 296 }
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 |