4 * @task addmethod Adding Payment Methods
6 abstract class PhortunePaymentProvider
extends Phobject
{
8 private $providerConfig;
10 public function setProviderConfig(
11 PhortunePaymentProviderConfig
$provider_config) {
12 $this->providerConfig
= $provider_config;
16 public function getProviderConfig() {
17 return $this->providerConfig
;
21 * Return a short name which identifies this provider.
23 abstract public function getName();
26 /* -( Configuring Providers )---------------------------------------------- */
30 * Return a human-readable provider name for use on the merchant workflow
31 * where a merchant owner adds providers.
33 abstract public function getConfigureName();
37 * Return a human-readable provider description for use on the merchant
38 * workflow where a merchant owner adds providers.
40 abstract public function getConfigureDescription();
42 abstract public function getConfigureInstructions();
44 abstract public function getConfigureProvidesDescription();
46 abstract public function getAllConfigurableProperties();
48 abstract public function getAllConfigurableSecretProperties();
50 * Read a dictionary of properties from the provider's configuration for
51 * use when editing the provider.
53 public function readEditFormValuesFromProviderConfig() {
54 $properties = $this->getAllConfigurableProperties();
55 $config = $this->getProviderConfig();
57 $secrets = $this->getAllConfigurableSecretProperties();
58 $secrets = array_fuse($secrets);
61 foreach ($properties as $property) {
62 $map[$property] = $config->getMetadataValue($property);
63 if (isset($secrets[$property])) {
64 $map[$property] = $this->renderConfigurationSecret($map[$property]);
73 * Read a dictionary of properties from a request for use when editing the
76 public function readEditFormValuesFromRequest(AphrontRequest
$request) {
77 $properties = $this->getAllConfigurableProperties();
80 foreach ($properties as $property) {
81 $map[$property] = $request->getStr($property);
88 abstract public function processEditForm(
89 AphrontRequest
$request,
92 abstract public function extendEditForm(
93 AphrontRequest
$request,
94 AphrontFormView
$form,
98 protected function renderConfigurationSecret($value) {
100 return str_repeat('*', strlen($value));
105 public function isConfigurationSecret($value) {
106 return preg_match('/^\*+\z/', trim($value));
109 abstract public function canRunConfigurationTest();
111 public function runConfigurationTest() {
112 throw new PhutilMethodNotImplementedException();
116 /* -( Selecting Providers )------------------------------------------------ */
119 public static function getAllProviders() {
120 return id(new PhutilClassMapQuery())
121 ->setAncestorClass(__CLASS__
)
125 public function isEnabled() {
126 return $this->getProviderConfig()->getIsEnabled();
129 abstract public function isAcceptingLivePayments();
130 abstract public function getPaymentMethodDescription();
131 abstract public function getPaymentMethodIcon();
132 abstract public function getPaymentMethodProviderDescription();
134 final public function applyCharge(
135 PhortunePaymentMethod
$payment_method,
136 PhortuneCharge
$charge) {
137 $this->executeCharge($payment_method, $charge);
140 final public function refundCharge(
141 PhortuneCharge
$charge,
142 PhortuneCharge
$refund) {
143 $this->executeRefund($charge, $refund);
146 abstract protected function executeCharge(
147 PhortunePaymentMethod
$payment_method,
148 PhortuneCharge
$charge);
150 abstract protected function executeRefund(
151 PhortuneCharge
$charge,
152 PhortuneCharge
$refund);
154 abstract public function updateCharge(PhortuneCharge
$charge);
157 /* -( Adding Payment Methods )--------------------------------------------- */
163 public function canCreatePaymentMethods() {
171 public function translateCreatePaymentMethodErrorCode($error_code) {
172 throw new PhutilMethodNotImplementedException();
179 public function getCreatePaymentMethodErrorMessage($error_code) {
180 throw new PhutilMethodNotImplementedException();
187 public function validateCreatePaymentMethodToken(array $token) {
188 throw new PhutilMethodNotImplementedException();
195 public function createPaymentMethodFromRequest(
196 AphrontRequest
$request,
197 PhortunePaymentMethod
$method,
199 throw new PhutilMethodNotImplementedException();
206 public function renderCreatePaymentMethodForm(
207 AphrontRequest
$request,
209 throw new PhutilMethodNotImplementedException();
212 public function getDefaultPaymentMethodDisplayName(
213 PhortunePaymentMethod
$method) {
214 throw new PhutilMethodNotImplementedException();
218 /* -( One-Time Payments )-------------------------------------------------- */
221 public function canProcessOneTimePayments() {
225 public function renderOneTimePaymentButton(
226 PhortuneAccount
$account,
228 PhabricatorUser
$user) {
230 require_celerity_resource('phortune-css');
232 $description = $this->getPaymentMethodProviderDescription();
233 $details = $this->getPaymentMethodDescription();
235 $icon = id(new PHUIIconView())
236 ->setSpriteSheet(PHUIIconView
::SPRITE_LOGIN
)
237 ->setSpriteIcon($this->getPaymentMethodIcon());
239 $button = id(new PHUIButtonView())
240 ->setSize(PHUIButtonView
::BIG
)
241 ->setColor(PHUIButtonView
::GREY
)
243 ->setText($description)
244 ->setSubtext($details);
246 // NOTE: We generate a local URI to make sure the form picks up CSRF tokens.
247 $uri = $this->getControllerURI(
250 'cartID' => $cart->getID(),
254 return phabricator_form(
264 /* -( Controllers )-------------------------------------------------------- */
267 final public function getControllerURI(
269 array $params = array(),
272 $id = $this->getProviderConfig()->getID();
273 $app = PhabricatorApplication
::getByClass('PhabricatorPhortuneApplication');
274 $path = $app->getBaseURI().'provider/'.$id.'/'.$action.'/';
276 $uri = new PhutilURI($path, $params);
281 return PhabricatorEnv
::getURI((string)$uri);
285 public function canRespondToControllerAction($action) {
289 public function processControllerRequest(
290 PhortuneProviderActionController
$controller,
291 AphrontRequest
$request) {
292 throw new PhutilMethodNotImplementedException();