Skip to content

Commit

Permalink
Add compatibility to the recent Braintree api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-imaginemage committed Jun 24, 2020
1 parent 37f5cbc commit 502a141
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Model/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function createOrder(
}

/**
* Set billing and shipping addreess
* Set billing and shipping address
*/
$magentoBillingAddress = $this->address->execute(
$billingAddress,
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"name": "imaginationmedia/magento2-payment-request",
"description": "W3C Web Payments for Magento 2",
"version" : "1.0.0",
"version" : "1.0.1",
"require": {
"php": ">=7.0",
"magento/framework": ">=102.0",
"magento/module-backend": ">=101.0",
"magento/module-braintree": ">=100.3",
"magento/module-checkout": ">=100.3",
"magento/module-payment": ">=100.3",
"magento/module-quote" : ">=100.3",
"magento/module-sales": ">=102.0",
"magento/module-sales-sequence": ">=100.3",
"magento/module-shipping": ">=100.3",
"magento/module-braintree": ">=100.3"
"php": ">=7.2"
},
"type": "magento2-module",
"license": [
Expand Down
3 changes: 3 additions & 0 deletions view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ var config = {
'ImaginationMedia_PaymentRequest/js/sidebar': true
}
}
},
paths: {
braintreeClientV2: 'https://js.braintreegateway.com/js/braintree-2.32.0.min'
}
};
30 changes: 23 additions & 7 deletions view/frontend/web/js/checkout/payment-type/basic-card/braintree.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
*/

define([
'https://js.braintreegateway.com/js/braintree-2.32.0.min.js',
'braintreeClientV2',
'mage/translate',
'jquery'
], function (braintree, $t, $) {
], function (braintreeClient, $t, $) {
'use strict';

return {
Expand All @@ -29,15 +29,30 @@ define([
paymentResponse.complete('fail');
}

var client = new braintree.api.Client({clientToken: w3cPaymentRequest.cardConfig.additionalInfo.clientToken});
client.tokenizeCard({
var customerFullName = details.billingAddress.recipient;
var names = customerFullName.split(" ");
var finalData = {
number: details.cardNumber,
cardholderName: details.cardholderName,
expirationMonth: details.expiryMonth,
expirationYear: details.expiryYear,
cvv: details.cardSecurityCode,
billingAddress: details.billingAddress
}, function (err, nonce) {
billingAddress: {
firstName : names[0],
lastName : names.slice(-1)[0],
company : details.billingAddress.organization,
streetAddress : Object.values(details.billingAddress.addressLine).length > 0
? details.billingAddress.addressLine[0] : '',
extendedAddress : Object.values(details.billingAddress.addressLine).length > 1
? details.billingAddress.addressLine[1] : '',
locality : details.billingAddress.city,
region : details.billingAddress.region,
postalCode : details.billingAddress.postalCode,
countryCodeAlpha2 : details.billingAddress.country
}
};
var client = new braintreeClient.api.Client({clientToken: w3cPaymentRequest.cardConfig.additionalInfo.clientToken});
client.tokenizeCard(finalData, function (err, nonce) {
if (!err) {
var params = {
paymentMethod: "braintree",
Expand Down Expand Up @@ -67,7 +82,8 @@ define([
}
});
} else {
console.log(err);
console.log(err.toString());
console.log(nonce);
paymentResponse.complete('fail');
}
});
Expand Down

0 comments on commit 502a141

Please sign in to comment.