Skip to content

Commit 502a141

Browse files
Add compatibility to the recent Braintree api changes
1 parent 37f5cbc commit 502a141

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

Model/Checkout.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function createOrder(
156156
}
157157

158158
/**
159-
* Set billing and shipping addreess
159+
* Set billing and shipping address
160160
*/
161161
$magentoBillingAddress = $this->address->execute(
162162
$billingAddress,

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"name": "imaginationmedia/magento2-payment-request",
33
"description": "W3C Web Payments for Magento 2",
4-
"version" : "1.0.0",
4+
"version" : "1.0.1",
55
"require": {
6-
"php": ">=7.0",
76
"magento/framework": ">=102.0",
87
"magento/module-backend": ">=101.0",
8+
"magento/module-braintree": ">=100.3",
99
"magento/module-checkout": ">=100.3",
1010
"magento/module-payment": ">=100.3",
1111
"magento/module-quote" : ">=100.3",
1212
"magento/module-sales": ">=102.0",
1313
"magento/module-sales-sequence": ">=100.3",
1414
"magento/module-shipping": ">=100.3",
15-
"magento/module-braintree": ">=100.3"
15+
"php": ">=7.2"
1616
},
1717
"type": "magento2-module",
1818
"license": [

view/frontend/requirejs-config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@ var config = {
1616
'ImaginationMedia_PaymentRequest/js/sidebar': true
1717
}
1818
}
19+
},
20+
paths: {
21+
braintreeClientV2: 'https://js.braintreegateway.com/js/braintree-2.32.0.min'
1922
}
2023
};

view/frontend/web/js/checkout/payment-type/basic-card/braintree.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
*/
1111

1212
define([
13-
'https://js.braintreegateway.com/js/braintree-2.32.0.min.js',
13+
'braintreeClientV2',
1414
'mage/translate',
1515
'jquery'
16-
], function (braintree, $t, $) {
16+
], function (braintreeClient, $t, $) {
1717
'use strict';
1818

1919
return {
@@ -29,15 +29,30 @@ define([
2929
paymentResponse.complete('fail');
3030
}
3131

32-
var client = new braintree.api.Client({clientToken: w3cPaymentRequest.cardConfig.additionalInfo.clientToken});
33-
client.tokenizeCard({
32+
var customerFullName = details.billingAddress.recipient;
33+
var names = customerFullName.split(" ");
34+
var finalData = {
3435
number: details.cardNumber,
3536
cardholderName: details.cardholderName,
3637
expirationMonth: details.expiryMonth,
3738
expirationYear: details.expiryYear,
3839
cvv: details.cardSecurityCode,
39-
billingAddress: details.billingAddress
40-
}, function (err, nonce) {
40+
billingAddress: {
41+
firstName : names[0],
42+
lastName : names.slice(-1)[0],
43+
company : details.billingAddress.organization,
44+
streetAddress : Object.values(details.billingAddress.addressLine).length > 0
45+
? details.billingAddress.addressLine[0] : '',
46+
extendedAddress : Object.values(details.billingAddress.addressLine).length > 1
47+
? details.billingAddress.addressLine[1] : '',
48+
locality : details.billingAddress.city,
49+
region : details.billingAddress.region,
50+
postalCode : details.billingAddress.postalCode,
51+
countryCodeAlpha2 : details.billingAddress.country
52+
}
53+
};
54+
var client = new braintreeClient.api.Client({clientToken: w3cPaymentRequest.cardConfig.additionalInfo.clientToken});
55+
client.tokenizeCard(finalData, function (err, nonce) {
4156
if (!err) {
4257
var params = {
4358
paymentMethod: "braintree",
@@ -67,7 +82,8 @@ define([
6782
}
6883
});
6984
} else {
70-
console.log(err);
85+
console.log(err.toString());
86+
console.log(nonce);
7187
paymentResponse.complete('fail');
7288
}
7389
});

0 commit comments

Comments
 (0)