Skip to content

Commit d77461f

Browse files
authored
Miscellaneous tasks on ECE (#3551)
* replace visible instances of 'source' with 'payment method' in the subscription edit page * pass locale to ece * fix js error * filter 'cart_needs_shipping_address' for subscriptions * fix test * add changelog
1 parent eb0f1f8 commit d77461f

File tree

9 files changed

+44
-10
lines changed

9 files changed

+44
-10
lines changed

changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* Tweak - Remove the subscription order notes added each time a source wasn't migrated.
2323
* Tweak - Update ECE default button type.
2424
* Fix - Fix position of ECE button on shortcode cart page.
25+
* Fix - Call ECE specific 'paymentFailed' function only when payment request fails.
26+
* Fix - Fix issue in purchasing subscriptions when the store has no shipping options.
2527

2628
= 8.8.2 - 2024-11-07 =
2729
* Fix - Prevent marking renewal orders as processing/completed multiple times due to handling the Stripe webhook in parallel.

client/blocks/express-checkout/express-checkout-container.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import React from 'react';
22
import { Elements } from '@stripe/react-stripe-js';
33
import ExpressCheckoutComponent from './express-checkout-component';
4-
import { getPaymentMethodTypesForExpressMethod } from 'wcstripe/express-checkout/utils';
4+
import {
5+
getExpressCheckoutButtonAppearance,
6+
getExpressCheckoutData,
7+
getPaymentMethodTypesForExpressMethod,
8+
} from 'wcstripe/express-checkout/utils';
59

610
export const ExpressCheckoutContainer = ( props ) => {
711
const { stripe, billing, expressPaymentMethod } = props;
@@ -13,6 +17,8 @@ export const ExpressCheckoutContainer = ( props ) => {
1317
paymentMethodTypes: getPaymentMethodTypesForExpressMethod(
1418
expressPaymentMethod
1519
),
20+
appearance: getExpressCheckoutButtonAppearance(),
21+
locale: getExpressCheckoutData( 'stripe' )?.locale ?? 'en',
1622
};
1723

1824
return (

client/blocks/express-checkout/hooks.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ export const useExpressCheckout = ( {
3939
window.location = redirectUrl;
4040
};
4141

42-
const abortPayment = ( onConfirmEvent, message ) => {
43-
onConfirmEvent.paymentFailed( { reason: 'fail' } );
42+
const abortPayment = ( onConfirmEvent, message, isOrderError = false ) => {
43+
if ( ! isOrderError ) {
44+
onConfirmEvent.paymentFailed( { reason: 'fail' } );
45+
}
4446
setExpressPaymentError( message );
4547
onAbortPaymentHandler( onConfirmEvent, message );
4648
};

client/entrypoints/express-checkout/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ jQuery( function ( $ ) {
132132
currency: options.currency,
133133
paymentMethodCreation: 'manual',
134134
appearance: getExpressCheckoutButtonAppearance(),
135+
locale: getExpressCheckoutData( 'stripe' )?.locale ?? 'en',
135136
paymentMethodTypes: getExpressPaymentMethodTypes(),
136137
} );
137138

@@ -289,6 +290,7 @@ jQuery( function ( $ ) {
289290
currency: getExpressCheckoutData( 'checkout' )
290291
.currency_code,
291292
appearance: getExpressCheckoutButtonAppearance(),
293+
locale: getExpressCheckoutData( 'stripe' )?.locale ?? 'en',
292294
displayItems,
293295
order,
294296
} );
@@ -466,9 +468,12 @@ jQuery( function ( $ ) {
466468
*
467469
* @param {PaymentResponse} payment Payment response instance.
468470
* @param {string} message Error message to display.
471+
* @param {boolean} isOrderError Whether the error is related to the order creation.
469472
*/
470-
abortPayment: ( payment, message ) => {
471-
payment.paymentFailed( { reason: 'fail' } );
473+
abortPayment: ( payment, message, isOrderError = false ) => {
474+
if ( ! isOrderError ) {
475+
payment.paymentFailed( { reason: 'fail' } );
476+
}
472477
onAbortPaymentHandler( payment, message );
473478

474479
displayExpressCheckoutNotice( message, 'error' );

client/express-checkout/__tests__/event-handler.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ describe( 'Express checkout event handlers', () => {
340340
);
341341
expect( abortPayment ).toHaveBeenCalledWith(
342342
event,
343-
'Order creation error'
343+
'Order creation error',
344+
true
344345
);
345346
expect( completePayment ).not.toHaveBeenCalled();
346347
} );
@@ -467,7 +468,8 @@ describe( 'Express checkout event handlers', () => {
467468
);
468469
expect( abortPayment ).toHaveBeenCalledWith(
469470
event,
470-
'Order creation error'
471+
'Order creation error',
472+
true
471473
);
472474
expect( completePayment ).not.toHaveBeenCalled();
473475
} );

client/express-checkout/event-handler.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ export const onConfirmHandler = async (
9292
if ( orderResponse.result !== 'success' ) {
9393
return abortPayment(
9494
event,
95-
getErrorMessageFromNotice( orderResponse.messages )
95+
getErrorMessageFromNotice( orderResponse.messages ),
96+
true
9697
);
9798
}
9899

includes/compat/trait-wc-stripe-subscriptions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ public function add_subscription_payment_meta( $payment_meta, $subscription ) {
682682
],
683683
'_stripe_source_id' => [
684684
'value' => $source_id,
685-
'label' => 'Stripe Source ID',
685+
'label' => 'Stripe Payment Method ID',
686686
],
687687
],
688688
];
@@ -720,7 +720,7 @@ public function validate_subscription_payment_meta( $payment_method_id, $payment
720720
&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'pm_' )
721721
)
722722
) {
723-
throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_", "pm_", or "card_".', 'woocommerce-gateway-stripe' ) );
723+
throw new Exception( __( 'Invalid payment method ID. A valid "Stripe Payment Method ID" must begin with "src_", "pm_", or "card_".', 'woocommerce-gateway-stripe' ) );
724724
}
725725
}
726726
}

includes/payment-methods/class-wc-stripe-express-checkout-element.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public function init() {
9999
add_action( 'woocommerce_checkout_order_processed', [ $this, 'add_order_meta' ], 10, 2 );
100100
add_filter( 'woocommerce_login_redirect', [ $this, 'get_login_redirect_url' ], 10, 3 );
101101
add_filter( 'woocommerce_registration_redirect', [ $this, 'get_login_redirect_url' ], 10, 3 );
102+
add_filter( 'woocommerce_cart_needs_shipping_address', [ $this, 'filter_cart_needs_shipping_address' ], 11, 1 );
102103

103104
add_action( 'before_woocommerce_pay_form', [ $this, 'localize_pay_for_order_page_scripts' ] );
104105
}
@@ -415,4 +416,17 @@ public function display_express_checkout_button_separator_html() {
415416
<p id="wc-stripe-express-checkout-button-separator" style="margin-top:1.5em;text-align:center;display:none;">&mdash; <?php esc_html_e( 'OR', 'woocommerce-gateway-stripe' ); ?> &mdash;</p>
416417
<?php
417418
}
419+
420+
/**
421+
* Determine whether to filter the cart needs shipping address.
422+
*
423+
* @param boolean $needs_shipping_address Whether the cart needs a shipping address.
424+
*/
425+
public function filter_cart_needs_shipping_address( $needs_shipping_address ) {
426+
if ( $this->express_checkout_helper->has_subscription_product() && wc_get_shipping_method_count( true, true ) === 0 ) {
427+
return false;
428+
}
429+
430+
return $needs_shipping_address;
431+
}
418432
}

readme.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
132132
* Tweak - Remove the subscription order notes added each time a source wasn't migrated.
133133
* Tweak - Update ECE default button type.
134134
* Fix - Fix position of ECE button on shortcode cart page.
135+
* Fix - Call ECE specific 'paymentFailed' function only when payment request fails.
136+
* Fix - Fix issue in purchasing subscriptions when the store has no shipping options.
135137

136138
[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

0 commit comments

Comments
 (0)