Skip to content

Commit f30f0b3

Browse files
author
epriestley
committed
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
1 parent 7a5f622 commit f30f0b3

File tree

5 files changed

+109
-1
lines changed

5 files changed

+109
-1
lines changed

src/__celerity_resource_map__.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,6 +2280,18 @@
22802280
),
22812281
'disk' => '/rsrc/js/application/phortune/behavior-stripe-payment-form.js',
22822282
),
2283+
'javelin-behavior-test-payment-form' =>
2284+
array(
2285+
'uri' => '/res/a8fe8616/rsrc/js/application/phortune/behavior-test-payment-form.js',
2286+
'type' => 'js',
2287+
'requires' =>
2288+
array(
2289+
0 => 'javelin-behavior',
2290+
1 => 'javelin-dom',
2291+
2 => 'phortune-credit-card-form',
2292+
),
2293+
'disk' => '/rsrc/js/application/phortune/behavior-test-payment-form.js',
2294+
),
22832295
'javelin-behavior-toggle-class' =>
22842296
array(
22852297
'uri' => '/res/79921b7f/rsrc/js/core/behavior-toggle-class.js',

src/applications/phortune/option/PhabricatorPhortuneConfigOptions.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ public function getOptions() {
2525
$this->newOption('phortune.balanced.secret-key', 'string', null)
2626
->setHidden(true)
2727
->setDescription(pht('Balanced secret key.')),
28+
$this->newOption('phortune.test.enabled', 'bool', false)
29+
->setBoolOptions(
30+
array(
31+
pht('Enable Test Provider'),
32+
pht('Disable Test Provider'),
33+
))
34+
->setSummary(pht('Enable test payment provider.'))
35+
->setDescription(
36+
pht(
37+
"Enable the test payment provider.\n\n".
38+
"NOTE: Enabling this provider gives all users infinite free ".
39+
"money! You should enable it **ONLY** for testing and ".
40+
"development."))
41+
->setLocked(true)
42+
2843
);
2944
}
3045

src/applications/phortune/provider/PhortuneTestPaymentProvider.php

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
final class PhortuneTestPaymentProvider extends PhortunePaymentProvider {
44

55
public function isEnabled() {
6-
return true;
6+
return PhabricatorEnv::getEnvConfig('phortune.test.enabled');
77
}
88

99
public function getProviderType() {
@@ -37,4 +37,60 @@ protected function executeCharge(
3737
return;
3838
}
3939

40+
41+
/* -( Adding Payment Methods )--------------------------------------------- */
42+
43+
44+
public function canCreatePaymentMethods() {
45+
return true;
46+
}
47+
48+
49+
public function translateCreatePaymentMethodErrorCode($error_code) {
50+
return $error_code;
51+
}
52+
53+
54+
public function getCreatePaymentMethodErrorMessage($error_code) {
55+
return null;
56+
}
57+
58+
59+
public function validateCreatePaymentMethodToken(array $token) {
60+
return true;
61+
}
62+
63+
64+
public function createPaymentMethodFromRequest(
65+
AphrontRequest $request,
66+
PhortunePaymentMethod $method,
67+
array $token) {
68+
69+
$method
70+
->setExpires('2050', '01')
71+
->setBrand('FreeMoney')
72+
->setLastFourDigits('9999');
73+
74+
}
75+
76+
77+
/**
78+
* @task addmethod
79+
*/
80+
public function renderCreatePaymentMethodForm(
81+
AphrontRequest $request,
82+
array $errors) {
83+
84+
$ccform = id(new PhortuneCreditCardForm())
85+
->setUser($request->getUser())
86+
->setErrors($errors);
87+
88+
Javelin::initBehavior(
89+
'test-payment-form',
90+
array(
91+
'formID' => $ccform->getFormID(),
92+
));
93+
94+
return $ccform->buildForm();
95+
}
4096
}

src/applications/phortune/provider/__tests__/PhortunePaymentProviderTestCase.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ public function getPhabricatorTestCaseConfiguration() {
99
}
1010

1111
public function testNoPaymentProvider() {
12+
$env = PhabricatorEnv::beginScopedEnv();
13+
$env->overrideEnvConfig('phortune.test.enabled', true);
14+
1215
$method = id(new PhortunePaymentMethod())
1316
->setMetadataValue('type', 'hugs');
1417

@@ -26,6 +29,9 @@ public function testNoPaymentProvider() {
2629
}
2730

2831
public function testMultiplePaymentProviders() {
32+
$env = PhabricatorEnv::beginScopedEnv();
33+
$env->overrideEnvConfig('phortune.test.enabled', true);
34+
2935
$method = id(new PhortunePaymentMethod())
3036
->setMetadataValue('type', 'test.multiple');
3137

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @provides javelin-behavior-test-payment-form
3+
* @requires javelin-behavior
4+
* javelin-dom
5+
* phortune-credit-card-form
6+
*/
7+
8+
JX.behavior('test-payment-form', function(config) {
9+
var ccform = new JX.PhortuneCreditCardForm(JX.$(config.formID), onsubmit);
10+
11+
function onsubmit(card_data) {
12+
onresponse();
13+
}
14+
15+
function onresponse() {
16+
ccform.submitForm([], {test: true});
17+
}
18+
19+
});

0 commit comments

Comments
 (0)