Skip to content

Commit 9d3fc2d

Browse files
wjrosadaledupreez
andauthored
Fix WeChat display on the block checkout with the Optimized Checkout (#4261)
* Fix WeChat display on the block checkout with Smart Checkout * Toggle setup future usage value depending on the saving checkbox * Disable some methods on the classic checkout due lack of update method for SPE * Checking for existing subscription in cart * Changelog and readme entries * Readme and changelog updates --------- Co-authored-by: daledupreez <[email protected]>
1 parent b76ebd3 commit 9d3fc2d

File tree

5 files changed

+37
-13
lines changed

5 files changed

+37
-13
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Changelog ***
22

33
= 9.5.0 - xxxx-xx-xx =
4+
* Fix - Fixes the availability of WeChat Pay when the Optimized Checkout is enabled on the block checkout. Removes it from the classic/shortcode checkout to avoid issues.
45
* Dev - Renames all references to "Smart Checkout" and "Single Payment Element" (and "SPE") to "Optimized Checkout" (and "OC"), following the feature rebranding.
56
* Tweak - Updates the "Smart Checkout" setting name to "Optimized Checkout", and the description accordingly.
67
* Fix - Checks for the existence of the WC_Stripe_Feature_Flags class before including it during extension initialization.

client/blocks/upe/upe-deferred-intent-creation/payment-elements.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,19 @@ const PaymentElements = ( {
152152
),
153153
},
154154
};
155-
}
156155

157-
// If the cart contains a subscription or the payment method supports saving, we need to use off_session setup so Stripe can display appropriate terms and conditions.
158-
if (
159-
getBlocksConfiguration()?.cartContainsSubscription ||
160-
props.showSaveOption
161-
) {
162-
options = {
163-
...options,
164-
...{
165-
setupFutureUsage: 'off_session',
166-
},
167-
};
156+
// If the cart contains a subscription or the payment method supports saving, we need to use off_session setup so Stripe can display appropriate terms and conditions.
157+
if (
158+
getBlocksConfiguration()?.cartContainsSubscription ||
159+
props.showSaveOption
160+
) {
161+
options = {
162+
...options,
163+
...{
164+
setupFutureUsage: 'off_session',
165+
},
166+
};
167+
}
168168
}
169169
} else {
170170
options = {

client/blocks/upe/upe-deferred-intent-creation/payment-processor.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,26 @@ const PaymentProcessor = ( {
336336
// Apply single payment element styles if the selected payment method is card and SPE is enabled.
337337
if ( getBlocksConfiguration()?.isOCEnabled ) {
338338
applyStyles();
339+
340+
// Maybe change the value of `setupFutureUsage` depending on the saving payment method checkbox state.
341+
const savingPaymentMethodCheckbox = document.querySelector(
342+
'.wc-block-components-payment-methods__save-card-info input[type=checkbox]'
343+
);
344+
savingPaymentMethodCheckbox.addEventListener(
345+
'change',
346+
function () {
347+
elements.update( {
348+
setupFutureUsage:
349+
getBlocksConfiguration()
350+
?.cartContainsSubscription ||
351+
savingPaymentMethodCheckbox?.checked
352+
? 'off_session'
353+
: null,
354+
} );
355+
}
356+
);
339357
}
340-
}, [ selectedPaymentMethodType ] );
358+
}, [ selectedPaymentMethodType, elements ] );
341359

342360
usePaymentCompleteHandler(
343361
api,

client/classic/upe/payment-processing.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ async function createStripePaymentElement( api, paymentMethodType ) {
148148
...options,
149149
paymentMethodConfiguration: getStripeServerData()
150150
?.paymentMethodConfigurationParentId,
151+
// There's no way to update this option in the classic checkout dynamically (for SPE).
152+
// So, we cannot update this based on the value of the saving payment method checkbox.
153+
// Setting this value to `off_session` to avoid issues with methods that do not work with this option (i.e. WeChat Pay, BNPLs)
154+
setupFutureUsage: 'off_session',
151155
};
152156
} else {
153157
options = {

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
111111
== Changelog ==
112112

113113
= 9.5.0 - xxxx-xx-xx =
114+
* Fix - Fixes the availability of WeChat Pay when the Optimized Checkout is enabled on the block checkout. Removes it from the classic/shortcode checkout to avoid issues.
114115
* Dev - Renames all references to "Smart Checkout" and "Single Payment Element" (and "SPE") to "Optimized Checkout" (and "OC"), following the feature rebranding.
115116
* Tweak - Updates the "Smart Checkout" setting name to "Optimized Checkout", and the description accordingly.
116117
* Fix - Checks for the existence of the WC_Stripe_Feature_Flags class before including it during extension initialization.

0 commit comments

Comments
 (0)