mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 23:02:42 +01:00
Allow PhortuneTestProvider to add payment methods
Summary: Provide a bare implementation so that you can add PhortuneTestProvider as a payment method. Ref 2787. Test Plan: Added "cards" through the test provider. Reviewers: btrahan, chad Reviewed By: btrahan CC: aran Maniphest Tasks: T2787 Differential Revision: https://secure.phabricator.com/D5772
This commit is contained in:
parent
7a5f622820
commit
f30f0b30f8
5 changed files with 109 additions and 1 deletions
|
@ -2280,6 +2280,18 @@ celerity_register_resource_map(array(
|
|||
),
|
||||
'disk' => '/rsrc/js/application/phortune/behavior-stripe-payment-form.js',
|
||||
),
|
||||
'javelin-behavior-test-payment-form' =>
|
||||
array(
|
||||
'uri' => '/res/a8fe8616/rsrc/js/application/phortune/behavior-test-payment-form.js',
|
||||
'type' => 'js',
|
||||
'requires' =>
|
||||
array(
|
||||
0 => 'javelin-behavior',
|
||||
1 => 'javelin-dom',
|
||||
2 => 'phortune-credit-card-form',
|
||||
),
|
||||
'disk' => '/rsrc/js/application/phortune/behavior-test-payment-form.js',
|
||||
),
|
||||
'javelin-behavior-toggle-class' =>
|
||||
array(
|
||||
'uri' => '/res/79921b7f/rsrc/js/core/behavior-toggle-class.js',
|
||||
|
|
|
@ -25,6 +25,21 @@ final class PhabricatorPhortuneConfigOptions
|
|||
$this->newOption('phortune.balanced.secret-key', 'string', null)
|
||||
->setHidden(true)
|
||||
->setDescription(pht('Balanced secret key.')),
|
||||
$this->newOption('phortune.test.enabled', 'bool', false)
|
||||
->setBoolOptions(
|
||||
array(
|
||||
pht('Enable Test Provider'),
|
||||
pht('Disable Test Provider'),
|
||||
))
|
||||
->setSummary(pht('Enable test payment provider.'))
|
||||
->setDescription(
|
||||
pht(
|
||||
"Enable the test payment provider.\n\n".
|
||||
"NOTE: Enabling this provider gives all users infinite free ".
|
||||
"money! You should enable it **ONLY** for testing and ".
|
||||
"development."))
|
||||
->setLocked(true)
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
final class PhortuneTestPaymentProvider extends PhortunePaymentProvider {
|
||||
|
||||
public function isEnabled() {
|
||||
return true;
|
||||
return PhabricatorEnv::getEnvConfig('phortune.test.enabled');
|
||||
}
|
||||
|
||||
public function getProviderType() {
|
||||
|
@ -37,4 +37,60 @@ final class PhortuneTestPaymentProvider extends PhortunePaymentProvider {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
/* -( Adding Payment Methods )--------------------------------------------- */
|
||||
|
||||
|
||||
public function canCreatePaymentMethods() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function translateCreatePaymentMethodErrorCode($error_code) {
|
||||
return $error_code;
|
||||
}
|
||||
|
||||
|
||||
public function getCreatePaymentMethodErrorMessage($error_code) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public function validateCreatePaymentMethodToken(array $token) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function createPaymentMethodFromRequest(
|
||||
AphrontRequest $request,
|
||||
PhortunePaymentMethod $method,
|
||||
array $token) {
|
||||
|
||||
$method
|
||||
->setExpires('2050', '01')
|
||||
->setBrand('FreeMoney')
|
||||
->setLastFourDigits('9999');
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task addmethod
|
||||
*/
|
||||
public function renderCreatePaymentMethodForm(
|
||||
AphrontRequest $request,
|
||||
array $errors) {
|
||||
|
||||
$ccform = id(new PhortuneCreditCardForm())
|
||||
->setUser($request->getUser())
|
||||
->setErrors($errors);
|
||||
|
||||
Javelin::initBehavior(
|
||||
'test-payment-form',
|
||||
array(
|
||||
'formID' => $ccform->getFormID(),
|
||||
));
|
||||
|
||||
return $ccform->buildForm();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,9 @@ final class PhortunePaymentProviderTestCase extends PhabricatorTestCase {
|
|||
}
|
||||
|
||||
public function testNoPaymentProvider() {
|
||||
$env = PhabricatorEnv::beginScopedEnv();
|
||||
$env->overrideEnvConfig('phortune.test.enabled', true);
|
||||
|
||||
$method = id(new PhortunePaymentMethod())
|
||||
->setMetadataValue('type', 'hugs');
|
||||
|
||||
|
@ -26,6 +29,9 @@ final class PhortunePaymentProviderTestCase extends PhabricatorTestCase {
|
|||
}
|
||||
|
||||
public function testMultiplePaymentProviders() {
|
||||
$env = PhabricatorEnv::beginScopedEnv();
|
||||
$env->overrideEnvConfig('phortune.test.enabled', true);
|
||||
|
||||
$method = id(new PhortunePaymentMethod())
|
||||
->setMetadataValue('type', 'test.multiple');
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
/**
|
||||
* @provides javelin-behavior-test-payment-form
|
||||
* @requires javelin-behavior
|
||||
* javelin-dom
|
||||
* phortune-credit-card-form
|
||||
*/
|
||||
|
||||
JX.behavior('test-payment-form', function(config) {
|
||||
var ccform = new JX.PhortuneCreditCardForm(JX.$(config.formID), onsubmit);
|
||||
|
||||
function onsubmit(card_data) {
|
||||
onresponse();
|
||||
}
|
||||
|
||||
function onresponse() {
|
||||
ccform.submitForm([], {test: true});
|
||||
}
|
||||
|
||||
});
|
Loading…
Reference in a new issue