1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-13 09:06:14 +01:00
phorge-phorge/src/applications/phortune/provider/PhortunePaymentProvider.php
epriestley 9c43029277 Genericize "Add Payment Method" form
Summary:
Ref T2787. For payment methods that allow you to add a billable method (i.e., a credit card), move all the logic into the provider. In particular:

  - Providers may (Stripe, Balanced) or may not (Paypal, MtGox) allow you to add rebillable payment methods. Providers which don't allow rebillable methods will appear at checkout instead and we'll just invoice you every month if you don't use a rebillable method.
  - Providers which permit creation of rebillable methods handle their own data entry, since this will be per-provider.
  - "Add Payment Method" now prompts you to choose a provider. This is super ugly and barely-usable for the moment. When there's only one choice, we'll auto-select it in the future.

Test Plan: Added new Stripe payment methods; hit all the Stripe errors.

Reviewers: btrahan, chad

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2787

Differential Revision: https://secure.phabricator.com/D5756
2013-04-25 09:46:32 -07:00

115 lines
2.8 KiB
PHP

<?php
/**
* @task addmethod Adding Payment Methods
*/
abstract class PhortunePaymentProvider {
/* -( Selecting Providers )------------------------------------------------ */
public static function getAllProviders() {
$objects = id(new PhutilSymbolLoader())
->setAncestorClass('PhortunePaymentProvider')
->loadObjects();
return mpull($objects, null, 'getProviderKey');
}
public static function getEnabledProviders() {
$providers = self::getAllProviders();
foreach ($providers as $key => $provider) {
if (!$provider->isEnabled()) {
unset($providers[$key]);
}
}
return $providers;
}
public static function getProvidersForAddPaymentMethod() {
$providers = self::getEnabledProviders();
foreach ($providers as $key => $provider) {
if (!$provider->canCreatePaymentMethods()) {
unset($providers[$key]);
}
}
return $providers;
}
abstract public function isEnabled();
final public function getProviderKey() {
return $this->getProviderType().'@'.$this->getProviderDomain();
}
/**
* Return a short string which uniquely identifies this provider's protocol
* type, like "stripe", "paypal", or "balanced".
*/
abstract public function getProviderType();
/**
* Return a short string which uniquely identifies the domain for this
* provider, like "stripe.com" or "google.com".
*
* This is distinct from the provider type so that protocols are not bound
* to a single domain. This is probably not relevant for payments, but this
* assumption burned us pretty hard with authentication and it's easy enough
* to avoid.
*/
abstract public function getProviderDomain();
abstract public function getPaymentMethodDescription();
abstract public function getPaymentMethodIcon();
abstract public function getPaymentMethodProviderDescription();
/**
* Determine of a provider can handle a payment method.
*
* @return bool True if this provider can apply charges to the payment
* method.
*/
abstract public function canHandlePaymentMethod(
PhortunePaymentMethod $method);
abstract protected function executeCharge(
PhortunePaymentMethod $payment_method,
PhortuneCharge $charge);
/* -( Adding Payment Methods )--------------------------------------------- */
/**
* @task addmethod
*/
public function canCreatePaymentMethods() {
return false;
}
/**
* @task addmethod
*/
public function createPaymentMethodFromRequest(
AphrontRequest $request,
PhortunePaymentMethod $method) {
throw new PhortuneNotImplementedException($this);
}
/**
* @task addmethod
*/
public function renderCreatePaymentMethodForm(
AphrontRequest $request,
array $errors) {
throw new PhortuneNotImplementedException($this);
}
}