Skip to content

Commit 80e33f1

Browse files
authored
Merge pull request #1683 from CodeNow/SAN-4839-refresh-cc-information
Fix bug where payment method wouldn't refresh until after page load
2 parents 3780ee6 + 2268ca4 commit 80e33f1

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

client/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormController.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ require('app')
66
function ChangePaymentFormController(
77
$rootScope,
88
currentOrg,
9+
errs,
910
fetchPaymentMethod,
11+
fetchPlan,
12+
fetchWhitelists,
1013
loading,
1114
savePaymentMethod,
12-
stripe,
13-
fetchPlan
15+
stripe
1416
) {
1517
var CPFC = this;
1618
CPFC.currentOrg = currentOrg;
@@ -44,6 +46,9 @@ function ChangePaymentFormController(
4446
.then(function (res) {
4547
return savePaymentMethod(res.id);
4648
})
49+
.then(function () {
50+
return fetchWhitelists();
51+
})
4752
.then(function () {
4853
// Not doing an angular timeout because we don't care about the digest.
4954
// We want to wait for this form to no longer be visible before we clear it and cause error outlines to show.
@@ -60,6 +65,9 @@ function ChangePaymentFormController(
6065
} else {
6166
CPFC.error = messageConversion[err.type];
6267
}
68+
if (!CPFC.error) {
69+
errs.handler(err);
70+
}
6371
})
6472
.finally(function () {
6573
loading('savePayment', false);

test/unit/directives/modals/settingsModal/forms/billingForm/changePaymentForm/changePaymentFormController.unit.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('ChangePaymentFormController'.bold.underline.blue, function () {
1414
var savePaymentMethodStub;
1515
var mockCurrentOrg;
1616
var mockFetchPlan;
17+
var mockFetchWhitelists;
1718

1819
beforeEach(function () {
1920
mockCurrentOrg = {
@@ -35,6 +36,10 @@ describe('ChangePaymentFormController'.bold.underline.blue, function () {
3536
mockFetchPlan = sinon.stub().returns($q.when({}));
3637
return mockFetchPlan;
3738
});
39+
$provide.factory('fetchWhitelists', function ($q) {
40+
mockFetchWhitelists = sinon.stub().returns($q.when([]));
41+
return mockFetchWhitelists;
42+
});
3843
$provide.factory('fetchPaymentMethod', function ($q) {
3944
fetchPaymentMethodStub = sinon.stub().returns($q.when({}));
4045
fetchPaymentMethodStub.cache = {
@@ -89,7 +94,6 @@ describe('ChangePaymentFormController'.bold.underline.blue, function () {
8994
sinon.assert.calledWith(loadingStub, 'savePayment', true);
9095
sinon.assert.calledWith(loadingStub, 'savePayment', false);
9196
sinon.assert.calledWith(loadingStub.reset, 'savePayment');
92-
9397
sinon.assert.calledOnce(savePaymentMethodStub);
9498
sinon.assert.calledWith(savePaymentMethodStub, 123);
9599
sinon.assert.calledOnce(fetchPaymentMethodStub.cache.clear);

0 commit comments

Comments
 (0)