Skip to content

Commit

Permalink
Merge branch 'develop' into fix/prevent-unnecessary-session-sets
Browse files Browse the repository at this point in the history
  • Loading branch information
malithsen authored Jan 20, 2025
2 parents ff156cf + 69c9a9b commit 0c4869c
Show file tree
Hide file tree
Showing 19 changed files with 1,108 additions and 21 deletions.
7 changes: 6 additions & 1 deletion assets/js/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -885,10 +885,15 @@ jQuery( function($ ) {
message = wc_stripe_params.invalid_request_error;
}

if ( wc_stripe_params.hasOwnProperty(result.error.code) ) {
if ( wc_stripe_params.hasOwnProperty( result.error.code ) ) {
message = wc_stripe_params[ result.error.code ];
}

// Correctly sets the insufficient funds message.
if ( 'card_declined' === result.error.code && 'insufficient_funds' === result.error?.decline_code ) {
message = wc_stripe_params.insufficient_funds;
}

wc_stripe_form.reset();
$( '.woocommerce-NoticeGroup-checkout' ).remove();
console.log( result.error.message ); // Leave for troubleshooting.
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
*** Changelog ***

= 9.2.0 - xxxx-xx-xx =
* 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.
Expand Down Expand Up @@ -49,6 +52,7 @@
* Update - Migrate payment request settings data to express checkout settings data.
* Update - Make the new Stripe Express Checkout Element enabled by default in all accounts.
* Fix - Duplicate emails when enabling the gateway.
* Fix - Prevent empty settings screen when cancelling changes to the payment methods display order.

= 9.0.0 - 2024-12-12 =
* Fix - Fix 404 that happens when using ECE and 3D Secure auth is triggered.
Expand Down
44 changes: 44 additions & 0 deletions client/api/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* global Stripe */
import { __ } from '@wordpress/i18n';
import apiFetch from '@wordpress/api-fetch';
import {
getExpressCheckoutData,
getExpressCheckoutAjaxURL,
Expand Down Expand Up @@ -539,6 +540,49 @@ export default class WCStripeAPI {
} );
}

/**
* Creates order based on Express Checkout ECE payment method.
*
* @param {Object} paymentData Order data.
* @return {Promise} Promise for the request to the server.
*/
expressCheckoutECECreateOrderForBlocksAPI( paymentData ) {
return this.postToBlocksAPI( '/wc/store/v1/checkout', {
...getRequiredFieldDataFromCheckoutForm( paymentData ),
} );
}

/**
* Pays for an order based on the Express Checkout payment method.
*
* @param {number} order The order ID.
* @param {Object} paymentData Order data.
* @return {Promise} Promise for the request to the server.
*/
expressCheckoutECEPayForOrderForBlocksAPI( order, paymentData ) {
return this.postToBlocksAPI( `/wc/store/v1/checkout/${ order }`, {
...paymentData,
} );
}

/**
* Posts data to the Blocks API.
*
* @param {string} path The path to post to.
* @param {Object} data The data to post.
* @return {Promise} The promise for the request to the server.
*/
postToBlocksAPI( path, data ) {
return apiFetch( {
method: 'POST',
path,
headers: {
Nonce: getExpressCheckoutData( 'nonce' )?.wc_store_api,
},
data,
} );
}

/**
* Add product to cart from product page.
*
Expand Down
14 changes: 13 additions & 1 deletion client/blocks/express-checkout/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
onClickHandler,
onCompletePaymentHandler,
onConfirmHandler,
onConfirmHandlerForBlocksAPI,
} from 'wcstripe/express-checkout/event-handler';
import {
displayExpressCheckoutNotice,
Expand All @@ -15,6 +16,7 @@ import {
getExpressCheckoutData,
normalizeLineItems,
} from 'wcstripe/express-checkout/utils';
import 'wcstripe/express-checkout/compatibility/wc-order-attribution';

export const useExpressCheckout = ( {
api,
Expand Down Expand Up @@ -116,7 +118,17 @@ export const useExpressCheckout = ( {
);

const onConfirm = async ( event ) => {
await onConfirmHandler(
if ( getExpressCheckoutData( 'use_blocks_api' ) ) {
return await onConfirmHandlerForBlocksAPI(
api,
stripe,
elements,
completePayment,
abortPayment,
event
);
}
return await onConfirmHandler(
api,
stripe,
elements,
Expand Down
14 changes: 13 additions & 1 deletion client/entrypoints/express-checkout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import {
onClickHandler,
onCompletePaymentHandler,
onConfirmHandler,
onConfirmHandlerForBlocksAPI,
onReadyHandler,
shippingAddressChangeHandler,
shippingRateChangeHandler,
} from 'wcstripe/express-checkout/event-handler';
import { getStripeServerData } from 'wcstripe/stripe-utils';
import { getAddToCartVariationParams } from 'wcstripe/utils';
import 'wcstripe/express-checkout/compatibility/wc-order-attribution';
import './styles.scss';

jQuery( function ( $ ) {
Expand Down Expand Up @@ -233,7 +235,17 @@ jQuery( function ( $ ) {

eceButton.on( 'confirm', async ( event ) => {
const order = options.order ? options.order : 0;

if ( getExpressCheckoutData( 'use_blocks_api' ) ) {
return await onConfirmHandlerForBlocksAPI(
api,
api.getStripe(),
elements,
wcStripeECE.completePayment,
wcStripeECE.abortPayment,
event,
order
);
}
return await onConfirmHandler(
api,
api.getStripe(),
Expand Down
Loading

0 comments on commit 0c4869c

Please sign in to comment.