Skip to content

Commit 8f2cdd5

Browse files
author
Cristian Partica
committed
MAGETWO-39052: Incorporate CR from MPI team into Braintree module
- fix client side validation for credit card form in one-page checkout
1 parent c545681 commit 8f2cdd5

File tree

2 files changed

+231
-160
lines changed
  • app/code/Magento/Braintree/view/frontend/web

2 files changed

+231
-160
lines changed

app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/cc-form.js

Lines changed: 75 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,43 @@ define(
66
[
77
'ko',
88
'Magento_Payment/js/view/payment/cc-form',
9+
'Magento_Checkout/js/action/set-payment-information',
910
'Magento_Checkout/js/model/quote',
1011
'braintree',
1112
'underscore',
1213
'jquery',
1314
'Magento_Ui/js/model/messageList',
1415
'mage/translate'
1516
],
16-
function (ko, Component, quote, braintreeClientSDK, _, $, messageList, $t) {
17+
function (ko, Component, setPaymentInformationAction, quote, braintreeClientSDK, _, $, messageList, $t) {
1718
'use strict';
1819
var configBraintree= window.checkoutConfig.payment.braintree;
1920
return Component.extend({
21+
22+
placeOrderHandler: null,
23+
validateHandler: null,
24+
setPlaceOrderHandler: function(handler) {
25+
this.placeOrderHandler = handler;
26+
},
27+
setValidateHandler: function(handler) {
28+
this.validateHandler = handler;
29+
},
30+
isShowLegend: function() {
31+
return true;
32+
},
33+
getSource: function () {
34+
return window.checkoutConfig.payment.iframe.source[this.getCode()];
35+
},
36+
getControllerName: function() {
37+
return window.checkoutConfig.payment.iframe.controllerName[this.getCode()];
38+
},
39+
getPlaceOrderUrl: function() {
40+
return window.checkoutConfig.payment.iframe.placeOrderUrl[this.getCode()];
41+
},
42+
43+
isActive: function() {
44+
return true;
45+
},
2046
defaults: {
2147
template: 'Magento_Braintree/payment/cc-form',
2248
isCcFormShown: true,
@@ -79,60 +105,64 @@ define(
79105
* Prepare and process payment information
80106
*/
81107
preparePayment: function () {
82-
var self = this,
83-
cardInfo = null;
84-
85-
messageList.clear();
86-
this.quoteBaseGrandTotals = quote.totals().base_grand_total;
108+
if (this.validateHandler()) {
109+
var self = this,
110+
cardInfo = null;
87111

88-
this.isPaymentProcessing = $.Deferred();
89-
$.when(this.isPaymentProcessing).done(
90-
function () {
91-
self.placeOrder();
92-
}
93-
).fail(
94-
function (result) {
95-
self.handleError(result);
96-
}
97-
);
112+
messageList.clear();
113+
this.quoteBaseGrandTotals = quote.totals().base_grand_total;
98114

99-
this.getFraudAdditionalData();
115+
this.isPaymentProcessing = $.Deferred();
116+
$.when(this.isPaymentProcessing).done(
100117

101-
if (this.selectedCardToken()) {
102-
if (self.show3dSecure) {
103-
self.verify3DSWithToken();
104-
} else {
105-
this.isPaymentProcessing.resolve();
106-
}
118+
function () {
119+
self.placeOrder();
120+
}
121+
).fail(
122+
function (result) {
123+
self.handleError(result);
124+
}
125+
);
107126

108-
return;
109-
}
127+
this.getFraudAdditionalData();
110128

111-
cardInfo = {
112-
number: this.creditCardNumber(),
113-
expirationMonth: this.creditCardExpMonth(),
114-
expirationYear: this.creditCardExpYear(),
115-
cvv: this.creditCardVerificationNumber()
116-
};
117-
this.braintreeClient.tokenizeCard(cardInfo, function (error, nonce) {
118-
if (error) {
119-
this.isPaymentProcessing.reject(error);
129+
if (this.selectedCardToken()) {
130+
if (self.show3dSecure) {
131+
self.verify3DSWithToken();
132+
} else {
133+
this.isPaymentProcessing.resolve();
134+
}
120135

121136
return;
122137
}
123138

124-
self.paymentMethodNonce(nonce);
139+
cardInfo = {
140+
number: this.creditCardNumber(),
141+
expirationMonth: this.creditCardExpMonth(),
142+
expirationYear: this.creditCardExpYear(),
143+
cvv: this.creditCardVerificationNumber()
144+
};
145+
this.braintreeClient.tokenizeCard(cardInfo, function (error, nonce) {
146+
if (error) {
147+
this.isPaymentProcessing.reject(error);
125148

126-
if (self.show3dSecure) {
127-
self.verify3DS();
128-
} else {
129-
self.isPaymentProcessing.resolve();
130-
}
131-
});
149+
return;
150+
}
151+
152+
self.paymentMethodNonce(nonce);
153+
154+
if (self.show3dSecure) {
155+
self.verify3DS();
156+
} else {
157+
self.isPaymentProcessing.resolve();
158+
}
159+
});
160+
}
132161
},
133162
/**
134163
* @override
135164
*/
165+
136166
getData: function () {
137167
return {
138168
'method': this.item.method,
@@ -148,6 +178,7 @@ define(
148178
}
149179
};
150180
},
181+
151182
/**
152183
* Display error message on the top of the page and reset payment method nonce.
153184
* @param {*} error - error message
@@ -278,6 +309,9 @@ define(
278309
}
279310
return availableTypes;
280311
},
312+
context: function() {
313+
return this;
314+
},
281315
/**
282316
* Get fraud control token.
283317
*/

0 commit comments

Comments
 (0)