-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Fix outdated address data when using Braintree's "Pay with PayPal" button #15133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix outdated address data when using Braintree's "Pay with PayPal" button #15133
Conversation
This commit fixes the case when customer navigates back to the shipping step and change address fields.
Hi, @vovayatsyuk, I took your PR into processing, thank you for collaboration. |
Hi @vovayatsyuk, please fix failed tests. Thanks |
Done. |
@vovayatsyuk thanks. |
@magento-engcom-team give me test instance |
Hi @VladimirZaets. Thank you for your request. I'm working on Magento instance for you |
Hi @VladimirZaets, here is your Magento instance. |
…th PayPal" button #15133
Hi @vovayatsyuk. Thank you for your contribution. Please, consider porting this solution across release lines. |
Accepted Public Pull Requests: - #15482: [Forwardport] Fix outdated address data when using Braintree's "Pay with PayPal" button #15133 (by @vovayatsyuk) - #17067: Fixed invalid knockoutjs data binding for Braintree PayPal (by @joni-jones)
Interestingly enough, this change appears to cause Chrome, and perhaps other browsers, to block this Braintree Paypal payment window as a popup. I'm curious if others are noticing the same behavior. I can post the mixin I wrote to patch it and provide more details if so. |
@bassplayer7 true. My patch made to call Previously So what about your patch? How you fixed it? |
@vovayatsyuk, ultimately, I used the window hashchange to watch for the payment form coming up again. There may be a different even that can be subscribed to. This allowed me to have Braintree fully initialized when the button was clicked: initialize: function() {
this._super();
$(window).hashchange(function() {
if (window.location.hash.indexOf('payment') !== -1) {
this.reInitPayPal.call(this, function() {})
}
}.bind(this));
} This was my whole mixin: define([
'jquery',
'Magento_Braintree/js/view/payment/adapter',
'Magento_Checkout/js/model/payment/additional-validators',
'jquery/jquery.hashchange'
], function($, Braintree, additionalValidators) {
/**
* Braintree must be started synchronously. The core now starts it via a callback that is passed to Braintree.
* @see Magento_Braintree/js/view/payment/method-renderer/paypal::reInitPayPal()
*
* @link https://github.com/magento/magento2/pull/15133 (description)
*
* @type {{initialize: initialize, payWithPayPal: payWithPayPal}}
*/
var mixin = {
initialize: function() {
this._super();
$(window).hashchange(function() {
if (window.location.hash.indexOf('payment') !== -1) {
this.reInitPayPal.call(this, function() {})
}
}.bind(this));
},
payWithPayPal: function () {
if (!additionalValidators.validate()) {
return;
}
try {
Braintree.checkout.paypal.initAuthFlow();
} catch (e) {
this.messageContainer.addErrorMessage({
message: $t('Payment ' + this.getTitle() + ' can\'t be initialized.')
});
}
}
};
return function(target) {
return target.extend(mixin);
}
}) |
I see. Your solution is like to call Possible downside: when you will apply discount code, total will not updated in Braintree config. p.s. I was looking for any other method except |
@vovayatsyuk, that's a good point. I wonder if it would be feasible to use a Knockout observer for watching any changes to the payment information, and then |
Dirty and not 100% solution (popup still blocked if diff --git a/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js b/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js
index 253f3530701..80a1ed73b25 100644
--- a/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js
+++ b/app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js
@@ -53,6 +53,8 @@ define([
* {Object}
*/
clientConfig: {
+ ready: false,
+
dataCollector: {
paypal: true
},
@@ -63,6 +65,7 @@ define([
*/
onReady: function (checkout) {
Braintree.checkout = checkout;
+ this.clientConfig.ready = true;
this.additionalData['device_data'] = checkout.deviceData;
this.enableButton();
Braintree.onReady();
@@ -230,18 +233,25 @@ define([
}
this.disableButton();
+ this.clientConfig.ready = false;
this.clientConfig.paypal.amount = this.grandTotalAmount;
this.clientConfig.paypal.shippingAddressOverride = this.getShippingAddress();
if (callback) {
- this.clientConfig.onReady = wrapper.wrap(
- this.clientConfig.onReady,
- function (original, checkout) {
- this.clientConfig.onReady = original;
- original(checkout);
+ /**
+ * Do not use onReady because Braintree's popup will be blocked
+ * by the browser if called from callback.
+ *
+ * 999 - Is the the max wait time between `click` and `window.open`.
+ * When the time is longer - browser blocks popup.
+ */
+ setTimeout(function cb() {
+ if (this.clientConfig.ready) {
callback();
- }.bind(this)
- );
+ } else {
+ setTimeout(cb.bind(this), 200);
+ }
+ }.bind(this), 999);
}
Braintree.setConfig(this.clientConfig);
|
Description
This commit fixes the case when customer navigates back
to the shipping step and change address fields.
Manual testing scenarios
Contribution checklist