Skip to content

Commit faf6d59

Browse files
committed
MAGETWO-99867: Braintree - 3D Secure 2.0 Support for 2.3
1 parent 1e58f70 commit faf6d59

File tree

2 files changed

+46
-54
lines changed

2 files changed

+46
-54
lines changed

app/code/Magento/Braintree/view/frontend/requirejs-config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
var config = {
77
map: {
88
'*': {
9-
braintreeClient: 'https://js.braintreegateway.com/web/3.44.1/js/client.min.js',
10-
braintreeHostedFields: 'https://js.braintreegateway.com/web/3.44.1/js/hosted-fields.min.js',
11-
braintreePayPal: 'https://js.braintreegateway.com/web/3.44.1/js/paypal-checkout.min.js',
12-
braintree3DSecure: 'https://js.braintreegateway.com/web/3.44.1/js/three-d-secure.min.js',
13-
braintreeDataCollector: 'https://js.braintreegateway.com/web/3.44.1/js/data-collector.min.js'
9+
braintreeClient: 'https://js.braintreegateway.com/web/3.46.0-beta-3ds.8/js/client.min.js',
10+
braintreeHostedFields: 'https://js.braintreegateway.com/web/3.46.0-beta-3ds.8/js/hosted-fields.min.js',
11+
braintreePayPal: 'https://js.braintreegateway.com/web/3.46.0-beta-3ds.8/js/paypal-checkout.min.js',
12+
braintree3DSecure: 'https://js.braintreegateway.com/web/3.46.0-beta-3ds.8/js/three-d-secure.min.js',
13+
braintreeDataCollector: 'https://js.braintreegateway.com/web/3.46.0-beta-3ds.8/js/data-collector.min.js'
1414
}
1515
},
1616
paths: {

app/code/Magento/Braintree/view/frontend/web/js/view/payment/3d-secure.js

Lines changed: 41 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ define([
4141
braintreeAdapter.getApiClient()
4242
.then(function (clientInstance) {
4343
return braintree3DSecure.create({
44+
version: 2, // Will use 3DS 2 whenever possible
4445
client: clientInstance
4546
});
4647
})
@@ -49,6 +50,7 @@ define([
4950
promise.resolve(self.threeDSecureInstance);
5051
})
5152
.catch(function (err) {
53+
fullScreenLoader.stopLoader();
5254
promise.reject(err);
5355
});
5456

@@ -84,28 +86,52 @@ define([
8486
var self = this,
8587
totalAmount = quote.totals()['base_grand_total'],
8688
billingAddress = quote.billingAddress(),
89+
shippingAddress = quote.shippingAddress(),
8790
options = {
8891
amount: totalAmount,
8992
nonce: context.paymentPayload.nonce,
90-
91-
/**
92-
* Adds iframe to page
93-
* @param {Object} err
94-
* @param {Object} iframe
95-
*/
96-
addFrame: function (err, iframe) {
97-
self.createModal($(iframe));
98-
fullScreenLoader.stopLoader();
99-
self.modal.openModal();
93+
billingAddress: {
94+
givenName: billingAddress.firstname,
95+
surname: billingAddress.lastname,
96+
phoneNumber: billingAddress.telephone,
97+
streetAddress: billingAddress.street[0],
98+
extendedAddress: billingAddress.street[1],
99+
locality: billingAddress.city,
100+
region: billingAddress.regionCode,
101+
postalCode: billingAddress.postcode,
102+
countryCodeAlpha2: billingAddress.countryId
100103
},
101104

102105
/**
103-
* Removes iframe from page
106+
* Will be called after receiving ThreeDSecure response, before completing the flow.
107+
*
108+
* @param {Object} data - ThreeDSecure data to consume before continuing
109+
* @param {Function} next - callback to continue flow
104110
*/
105-
removeFrame: function () {
106-
self.modal.closeModal();
111+
onLookupComplete: function (data, next) {
112+
next();
113+
}
114+
};
115+
116+
if (context.paymentPayload.details) {
117+
options.bin = context.paymentPayload.details.bin;
118+
}
119+
120+
if (shippingAddress) {
121+
options.additionalInformation = {
122+
shippingGivenName: shippingAddress.firstname,
123+
shippingSurname: shippingAddress.lastname,
124+
shippingPhone: shippingAddress.telephone,
125+
shippingAddress: {
126+
streetAddress: shippingAddress.street[0],
127+
extendedAddress: shippingAddress.street[1],
128+
locality: shippingAddress.city,
129+
region: shippingAddress.regionCode,
130+
postalCode: shippingAddress.postcode,
131+
countryCodeAlpha2: shippingAddress.countryId
107132
}
108133
};
134+
}
109135

110136
if (!this.isAmountAvailable(totalAmount) || !this.isCountryAvailable(billingAddress.countryId)) {
111137
self.state.resolve();
@@ -118,6 +144,7 @@ define([
118144
.then(function () {
119145
self.threeDSecureInstance.verifyCard(options, function (err, payload) {
120146
if (err) {
147+
fullScreenLoader.stopLoader();
121148
self.state.reject(err.message);
122149

123150
return;
@@ -129,6 +156,7 @@ define([
129156
context.paymentPayload.nonce = payload.nonce;
130157
self.state.resolve();
131158
} else {
159+
fullScreenLoader.stopLoader();
132160
self.state.reject($t('Please try again with another form of payment.'));
133161
}
134162
});
@@ -141,42 +169,6 @@ define([
141169
return self.state.promise();
142170
},
143171

144-
/**
145-
* Creates modal window
146-
*
147-
* @param {Object} $context
148-
* @private
149-
*/
150-
createModal: function ($context) {
151-
var self = this,
152-
options = {
153-
clickableOverlay: false,
154-
buttons: [],
155-
modalCloseBtnHandler: self.cancelFlow.bind(self),
156-
keyEventHandlers: {
157-
escapeKey: self.cancelFlow.bind(self)
158-
}
159-
};
160-
161-
// adjust iframe styles
162-
$context.attr('width', '100%');
163-
self.modal = Modal(options, $context);
164-
},
165-
166-
/**
167-
* Cancels 3D Secure flow
168-
*
169-
* @private
170-
*/
171-
cancelFlow: function () {
172-
var self = this;
173-
174-
self.threeDSecureInstance.cancelVerifyCard(function () {
175-
self.modal.closeModal();
176-
self.state.reject();
177-
});
178-
},
179-
180172
/**
181173
* Checks minimal amount for 3D Secure activation
182174
*

0 commit comments

Comments
 (0)