Skip to content

Commit

Permalink
Merge branch 'develop' into fix/user-source-from-order
Browse files Browse the repository at this point in the history
  • Loading branch information
wjrosa authored Jan 22, 2025
2 parents 69ea9b9 + fbcb1cd commit 9f9b9bc
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 27 deletions.
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
*** Changelog ***

= 9.2.0 - xxxx-xx-xx =
* Fix - Fixes an error with the fingerprint property setting when using the legacy checkout.
* Fix - Fixes order attribution data for the Express Checkout Element when using the Blocks API to process.
* Tweak - Process ECE orders using the Blocks API.
* Fix - Fixes incorrect error message for card failures due insufficient funds on the shortcode checkout page (legacy).
* Fix - Fixes deprecation warnings related to nullable method parameters when using PHP 8.4, and increases the minimum PHP version Code Sniffer considers to 7.4.
* Fix - Adds support for the Reunion country when checking out using the new checkout experience.
* Add - Support zero-amount refunds.
* Fix - A potential fix to prevent duplicate charges.
* Fix - Improve product page caching when Express Payment buttons are not enabled.
* Fix - Error when changing subscription payment method to a 3D Secure card while using a custom checkout endpoint.

= 9.1.1 - 2025-01-10 =
* Fix - Fixes the webhook order retrieval by intent charges. The processed event is an object, not an array.
Expand Down
27 changes: 6 additions & 21 deletions client/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getExpressCheckoutAjaxURL,
getRequiredFieldDataFromCheckoutForm,
} from 'wcstripe/express-checkout/utils';
import { getStripeServerData } from 'wcstripe/stripe-utils';
import { PAYMENT_METHOD_CASHAPP } from 'wcstripe/stripe-utils/constants';

/**
Expand Down Expand Up @@ -309,28 +310,12 @@ export default class WCStripeAPI {
const clientSecret = partials[ 3 ];
const nonce = partials[ 4 ];

const orderPayIndex = redirectUrl.indexOf( 'order-pay' );
const isOrderPage = orderPayIndex > -1;
const isChangingPayment =
isOrderPage &&
document.querySelectorAll( '#wc-stripe-change-payment-method' )
.length > 0;
const isChangingPayment = getStripeServerData()?.isChangingPayment;

// If we're on the Pay for Order page, get the order ID
// directly from the URL instead of relying on the hash.
// The checkout URL does not contain the string 'order-pay'.
// The Pay for Order page contains the string 'order-pay' and
// can have these formats:
// Plain permalinks:
// /?page_id=7&order-pay=189&pay_for_order=true&key=wc_order_key
// Non-plain permalinks:
// /checkout/order-pay/189/
// Match for consecutive digits after the string 'order-pay' to get the order ID.
const orderIdPartials =
isOrderPage &&
redirectUrl.substring( orderPayIndex ).match( /\d+/ );
if ( orderIdPartials ) {
orderId = orderIdPartials[ 0 ];
// directly from the server data instead of relying on the hash.
if ( isChangingPayment ) {
orderId = getStripeServerData().orderId;
}

// After processing the intent, trigger the appropriate AJAX action.
Expand Down Expand Up @@ -385,7 +370,7 @@ export default class WCStripeAPI {

return {
request,
isOrderPage,
isChangingPayment,
};
}

Expand Down
1 change: 1 addition & 0 deletions includes/admin/class-wc-stripe-settings-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public function admin_scripts( $hook_suffix ) {
'time' => time(),
'i18n_out_of_sync' => $message,
'is_upe_checkout_enabled' => WC_Stripe_Feature_Flags::is_upe_checkout_enabled(),
'is_ach_enabled' => WC_Stripe_Feature_Flags::is_ach_lpm_enabled(),
'stripe_oauth_url' => $oauth_url,
'stripe_test_oauth_url' => $test_oauth_url,
'show_customization_notice' => get_option( 'wc_stripe_show_customization_notice', 'yes' ) === 'yes' ? true : false,
Expand Down
14 changes: 13 additions & 1 deletion includes/class-wc-stripe-feature-flags.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@

class WC_Stripe_Feature_Flags {
const UPE_CHECKOUT_FEATURE_ATTRIBUTE_NAME = 'upe_checkout_experience_enabled';
const ECE_FEATURE_FLAG_NAME = '_wcstripe_feature_ece';
const ECE_FEATURE_FLAG_NAME = '_wcstripe_feature_ece';

const LPM_ACH_FEATURE_FLAG_NAME = '_wcstripe_feature_lpm_ach';

/**
* Checks whether ACH LPM (Local Payment Method) feature flag is enabled.
* ACH LPM is a feature that allows merchants to enable/disable the ACH payment method.
*
* @return bool
*/
public static function is_ach_lpm_enabled() {
return 'yes' === get_option( self::LPM_ACH_FEATURE_FLAG_NAME, 'no' );
}

/**
* Checks whether Stripe ECE (Express Checkout Element) feature flag is enabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ public static function instance() {
* @return void
*/
public function set_session() {
if ( ! $this->express_checkout_helper->is_product() || ( isset( WC()->session ) && WC()->session->has_session() ) ) {
// Don't set session cookies on product pages to allow for caching when payment request
// buttons are disabled. But keep cookies if there is already an active WC session in place.
if (
! ( $this->express_checkout_helper->is_product() && $this->express_checkout_helper->should_show_express_checkout_button() )
|| ( isset( WC()->session ) && WC()->session->has_session() )
) {
return;
}

Expand Down
7 changes: 6 additions & 1 deletion includes/payment-methods/class-wc-stripe-payment-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,12 @@ public static function instance() {
* @return void
*/
public function set_session() {
if ( ! $this->is_product() || ( isset( WC()->session ) && WC()->session->has_session() ) ) {
// Don't set session cookies on product pages to allow for caching when payment request
// buttons are disabled. But keep cookies if there is already an active WC session in place.
if (
! ( $this->is_product() && $this->should_show_payment_request_button() )
|| ( isset( WC()->session ) && WC()->session->has_session() )
) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ public function javascript_params() {
// ECE feature flag
$stripe_params['isECEEnabled'] = WC_Stripe_Feature_Flags::is_stripe_ece_enabled();

// ACH LPM Feature flag.
$stripe_params['is_ach_enabled'] = WC_Stripe_Feature_Flags::is_ach_lpm_enabled();

$cart_total = ( WC()->cart ? WC()->cart->get_total( '' ) : 0 );
$currency = get_woocommerce_currency();

Expand All @@ -423,6 +426,8 @@ public function javascript_params() {
$order_id = absint( get_query_var( 'order-pay' ) );
$order = wc_get_order( $order_id );

$stripe_params['orderId'] = $order_id;

// Make billing country available for subscriptions as well, so country-restricted payment methods can be shown.
if ( is_a( $order, 'WC_Order' ) ) {
$stripe_params['customerData'] = [ 'billing_country' => $order->get_billing_country() ];
Expand All @@ -440,7 +445,6 @@ public function javascript_params() {
return $stripe_params;
}

$stripe_params['orderId'] = $order_id;
$stripe_params['isOrderPay'] = true;

// Additional params for order pay page, when the order was successfully loaded.
Expand Down
8 changes: 6 additions & 2 deletions includes/payment-tokens/class-wc-stripe-payment-tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,11 @@ public function woocommerce_get_customer_payment_tokens_legacy( $tokens, $custom
$token->set_last4( $source->card->last4 );
$token->set_expiry_month( $source->card->exp_month );
$token->set_expiry_year( $source->card->exp_year );
if ( isset( $source->card->fingerprint ) ) {
$token->set_fingerprint( $source->card->fingerprint );
}
}

$token->set_fingerprint( $source->fingerprint );
$token->set_user_id( $customer_id );
$token->save();
$tokens[ $token->get_id() ] = $token;
Expand Down Expand Up @@ -221,7 +223,9 @@ public function woocommerce_get_customer_payment_tokens_legacy( $tokens, $custom
$token->set_gateway_id( WC_Gateway_Stripe_Sepa::ID );
$token->set_last4( $source->sepa_debit->last4 );
$token->set_user_id( $customer_id );
$token->set_fingerprint( $source->fingerprint );
if ( isset( $source->sepa_debit->fingerprint ) ) {
$token->set_fingerprint( $source->sepa_debit->fingerprint );
}
$token->save();
$tokens[ $token->get_id() ] = $token;
} else {
Expand Down
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
== Changelog ==

= 9.2.0 - xxxx-xx-xx =
* Fix - Fixes an error with the fingerprint property setting when using the legacy checkout.
* Fix - Fixes order attribution data for the Express Checkout Element when using the Blocks API to process.
* Tweak - Process ECE orders using the Blocks API.
* Fix - Fixes incorrect error message for card failures due insufficient funds on the shortcode checkout page (legacy).
Expand All @@ -119,5 +120,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
* Add - Support zero-amount refunds.
* Fix - A potential fix to prevent duplicate charges.
* Fix - Prevent empty settings screen when cancelling changes to the payment methods display order.
* Fix - Improve product page caching when Express Payment buttons are not enabled.
* Fix - Error when changing subscription payment method to a 3D Secure card while using a custom checkout endpoint.

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

0 comments on commit 9f9b9bc

Please sign in to comment.