Skip to content

Commit d61ff0d

Browse files
authored
Merge pull request #189 from magento-sparta/MAGETWO-55354
[Support] Portdown MAGETWO-54721 down to M2.1.x branch
2 parents a2520af + 18e69a1 commit d61ff0d

File tree

4 files changed

+24
-39
lines changed

4 files changed

+24
-39
lines changed

app/code/Magento/Braintree/Model/Ui/ConfigProvider.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public function getConfig()
7979
'payment' => [
8080
self::CODE => [
8181
'isActive' => $this->config->isActive(),
82-
'isSingleUse' => !$isPayPalActive,
8382
'clientToken' => $this->getClientToken(),
8483
'ccTypesMapper' => $this->config->getCctypesMapper(),
8584
'sdkUrl' => $this->config->getSdkUrl(),

app/code/Magento/Braintree/Test/Unit/Model/Ui/ConfigProviderTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ public function getConfigDataProvider()
154154
'payment' => [
155155
ConfigProvider::CODE => [
156156
'isActive' => true,
157-
'isSingleUse' => false,
158157
'clientToken' => self::CLIENT_TOKEN,
159158
'ccTypesMapper' => ['visa' => 'VI', 'american-express' => 'AE'],
160159
'sdkUrl' => self::SDK_URL,

app/code/Magento/Braintree/view/frontend/web/js/view/payment/braintree.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,19 @@
77
define(
88
[
99
'uiComponent',
10-
'uiRegistry',
11-
'Magento_Braintree/js/view/payment/adapter',
1210
'Magento_Checkout/js/model/payment/renderer-list'
1311
],
1412
function (
1513
Component,
16-
Registry,
17-
Braintree,
1814
rendererList
1915
) {
2016
'use strict';
2117

2218
var config = window.checkoutConfig.payment,
2319
braintreeType = 'braintree',
24-
payPalType = 'braintree_paypal',
25-
path = 'checkout.steps.billing-step.payment.payments-list.',
26-
components = [];
20+
payPalType = 'braintree_paypal';
2721

2822
if (config[braintreeType].isActive) {
29-
components.push(path + braintreeType);
3023
rendererList.push(
3124
{
3225
type: braintreeType,
@@ -44,13 +37,6 @@ define(
4437
);
4538
}
4639

47-
// setup Braintree SDK with merged configuration from all related components
48-
if (components.length) {
49-
Registry.get(components, function () {
50-
Braintree.setup();
51-
});
52-
}
53-
5440
/** Add view logic here if needed */
5541
return Component.extend({});
5642
}

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

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,22 @@ define(
6161
this.beforePlaceOrder(response);
6262
},
6363

64+
/**
65+
* Device data initialization
66+
*
67+
* @param {Object} checkout
68+
*/
69+
onReady: function (checkout) {
70+
braintree.checkout = checkout;
71+
},
72+
6473
/**
6574
* Triggers on any Braintree error
75+
* @param {Object} response
6676
*/
67-
onError: function () {
68-
this.paymentMethodNonce = null;
77+
onError: function (response) {
78+
braintree.showError($t('Payment ' + this.getTitle() + ' can\'t be initialized'));
79+
throw response.message;
6980
},
7081

7182
/**
@@ -90,7 +101,7 @@ define(
90101
this._super()
91102
.observe(['active']);
92103
this.validatorManager.initialize();
93-
this.initBraintree();
104+
this.initClientConfig();
94105

95106
return this;
96107
},
@@ -122,11 +133,11 @@ define(
122133
* @param {Boolean} isActive
123134
*/
124135
onActiveChange: function (isActive) {
125-
if (!isActive || this.isSingleUse()) {
136+
if (!isActive) {
126137
return;
127138
}
128139

129-
this.reInitBraintree();
140+
this.initBraintree();
130141
},
131142

132143
/**
@@ -146,17 +157,9 @@ define(
146157
},
147158

148159
/**
149-
* Create Braintree configuration
160+
* Init Braintree configuration
150161
*/
151162
initBraintree: function () {
152-
this.initClientConfig();
153-
braintree.config = _.extend(braintree.config, this.clientConfig);
154-
},
155-
156-
/**
157-
* Re-init Braintree configuration
158-
*/
159-
reInitBraintree: function () {
160163
var intervalId = setInterval(function () {
161164
// stop loader when frame will be loaded
162165
if ($('#braintree-hosted-field-number').length) {
@@ -165,6 +168,12 @@ define(
165168
}
166169
}, 500);
167170

171+
if (braintree.checkout) {
172+
braintree.checkout.teardown(function () {
173+
braintree.checkout = null;
174+
});
175+
}
176+
168177
fullScreenLoader.startLoader();
169178
braintree.setConfig(this.clientConfig);
170179
braintree.setup();
@@ -309,14 +318,6 @@ define(
309318
});
310319

311320
return false;
312-
},
313-
314-
/**
315-
* Check if Braintree configured without PayPal
316-
* @returns {Boolean}
317-
*/
318-
isSingleUse: function () {
319-
return window.checkoutConfig.payment[this.getCode()].isSingleUse;
320321
}
321322
});
322323
}

0 commit comments

Comments
 (0)