Skip to content

Commit

Permalink
Fix pay for order with blocks API on ECE (#3760)
Browse files Browse the repository at this point in the history
* Enabling Blocks API for ECE by default

* Changelog and readme entries

* Deprecating method instead of removing it

* Deprecating the order creation method

* Deprecated the pay for order endpoint

* Fix pay for order with blocks API on ECE

* Changelog and readme entries

* Removing unused function

* Fix tests
  • Loading branch information
wjrosa authored Jan 24, 2025
1 parent 02f7e0b commit 88b5007
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 113 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*** Changelog ***

= 9.2.0 - xxxx-xx-xx =
* Fix - Fixes processing of orders through the Pay for Order page when using ECE with Blocks (Store) API.
* Add - Enables the use of Blocks API for Express Checkout Element orders by default.
* Add - Adds a new filter to allow changing the user attributed to an order when paying for it through the Order Pay page.
* Fix - Fixes an error with the fingerprint property setting when using the legacy checkout.
Expand Down
6 changes: 1 addition & 5 deletions client/express-checkout/__tests__/event-handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
normalizeLineItems,
normalizeShippingAddress,
normalizeOrderData,
normalizePayForOrderData,
} from '../utils';
import {
onConfirmHandler,
Expand Down Expand Up @@ -483,10 +482,7 @@ describe( 'Express checkout event handlers', () => {
order
);

const expectedOrderData = normalizePayForOrderData(
event,
'pm_123'
);
const expectedOrderData = normalizeOrderData( event, 'pm_123' );
expect( api.expressCheckoutECEPayForOrder ).toHaveBeenCalledWith(
123,
expectedOrderData
Expand Down
5 changes: 2 additions & 3 deletions client/express-checkout/event-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { __ } from '@wordpress/i18n';
import {
getErrorMessageFromNotice,
normalizeOrderData,
normalizePayForOrderData,
normalizeShippingAddress,
normalizeLineItems,
getExpressCheckoutData,
Expand Down Expand Up @@ -85,11 +84,11 @@ export const onConfirmHandler = async (
} else {
orderResponse = await api.expressCheckoutECEPayForOrder(
order,
normalizePayForOrderData( event, paymentMethod.id )
normalizeOrderData( event, paymentMethod.id )
);
}

if ( orderResponse.payment_result.payment_status !== 'success' ) {
if ( orderResponse.payment_result?.payment_status !== 'success' ) {
return abortPayment(
event,
getErrorMessageFromNotice(
Expand Down
87 changes: 0 additions & 87 deletions client/express-checkout/utils/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import {
normalizeLineItems,
normalizeOrderData,
normalizePayForOrderData,
normalizeShippingAddress,
} from '../normalize';

Expand Down Expand Up @@ -343,92 +342,6 @@ describe( 'Express checkout normalization', () => {
} );
} );

describe( 'normalizePayForOrderData', () => {
test( 'should normalize pay for order data with complete event and paymentMethodId', () => {
const event = {
billingDetails: {
name: 'John Doe',
email: '[email protected]',
address: {
organization: 'Some Company',
country: 'US',
line1: '123 Main St',
line2: 'Apt 4B',
city: 'New York',
state: 'NY',
postal_code: '10001',
},
phone: '(123) 456-7890',
},
shippingAddress: {
name: 'John Doe',
organization: 'Some Company',
address: {
country: 'US',
line1: '123 Main St',
line2: 'Apt 4B',
city: 'New York',
state: 'NY',
postal_code: '10001',
},
},
shippingRate: { id: 'rate_1' },
expressPaymentType: 'express',
};

expect( normalizePayForOrderData( event, 'pm_123456' ) ).toEqual( {
payment_data: [
{
key: 'payment_method',
value: 'stripe',
},
{
key: 'wc-stripe-payment-method',
value: 'pm_123456',
},
{
key: 'express_payment_type',
value: 'express',
},
{
key: 'wc-stripe-is-deferred-intent',
value: true,
},
],
payment_method: 'stripe',
} );
} );

test( 'should normalize pay for order data with empty event and empty payment method', () => {
const event = {};
const paymentMethodId = '';

expect(
normalizePayForOrderData( event, paymentMethodId )
).toEqual( {
payment_data: [
{
key: 'payment_method',
value: 'stripe',
},
{
key: 'wc-stripe-payment-method',
value: '',
},
{
key: 'express_payment_type',
value: undefined,
},
{
key: 'wc-stripe-is-deferred-intent',
value: true,
},
],
payment_method: 'stripe',
} );
} );
} );

describe( 'normalizeShippingAddress', () => {
test( 'should normalize shipping address with all fields present', () => {
const shippingAddress = {
Expand Down
18 changes: 0 additions & 18 deletions client/express-checkout/utils/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,6 @@ export const normalizeOrderData = ( event, paymentMethodId ) => {
};
};

/**
* Normalize Pay for Order data from Stripe's object to the expected format for WC (when using Blocks API).
*
* @param {Object} event Stripe's event object.
* @param {string} paymentMethodId Stripe's payment method id.
*
* @return {Object} Order object in the format WooCommerce expects.
*/
export const normalizePayForOrderData = ( event, paymentMethodId ) => {
return {
payment_method: 'stripe',
payment_data: buildBlocksAPIPaymentData(
event?.expressPaymentType,
paymentMethodId
),
};
};

/**
* Normalize shipping address information from Stripe's address object to
* the cart shipping address object shape.
Expand Down
1 change: 1 addition & 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 processing of orders through the Pay for Order page when using ECE with Blocks (Store) API.
* Add - Enables the use of Blocks API for Express Checkout Element orders by default.
* Add - Adds a new filter to allow changing the user attributed to an order when paying for it through the Order Pay page.
* Fix - Fixes an error with the fingerprint property setting when using the legacy checkout.
Expand Down

0 comments on commit 88b5007

Please sign in to comment.