Skip to content

Commit e8087e1

Browse files
annemirasolwjrosadaledupreez
authored
ECE: add support for extensions data (#4394)
* Add extensions data to POSTed order data * Add js tests * Add changelog and readme entries * Update changelog.txt Co-authored-by: daledupreez <[email protected]> * Update readme.txt Co-authored-by: daledupreez <[email protected]> * Guard against undefined method --------- Co-authored-by: Wesley Rosa <[email protected]> Co-authored-by: daledupreez <[email protected]>
1 parent 1822a5c commit e8087e1

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
* Fix - Show correct price in express checkout for zero decimal currencies
6060
* Fix - Fixes a possible fatal error with Multibanco purchases when generating the email instructions.
6161
* Fix - Fix buggy unsaved changes warning in settings page
62+
* Update - Include extension data from block checkout when submitting an express checkout order
6263
* Fix - Use the platform's payment method configuration id constant when rendering the Optimized Checkout
6364
* Dev - Add Klarna e2e tests
6465
* Update - Improve checks in voucher purchase flow

client/express-checkout/utils/__tests__/normalize.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ describe( 'Express checkout normalization', () => {
148148

149149
select.mockImplementation( () => {
150150
return {
151+
getExtensionData: () => {
152+
return {};
153+
},
151154
getAdditionalFields: () => {
152155
return {};
153156
},
@@ -280,6 +283,9 @@ describe( 'Express checkout normalization', () => {
280283
};
281284
select.mockImplementation( () => {
282285
return {
286+
getExtensionData: () => {
287+
return {};
288+
},
283289
getAdditionalFields: () => {
284290
return additionalFields;
285291
},
@@ -299,13 +305,44 @@ describe( 'Express checkout normalization', () => {
299305
);
300306
} );
301307

308+
test( 'should include extension data in the normalized order data', () => {
309+
const extensionData = {
310+
'my-plugin': 'test',
311+
};
312+
select.mockImplementation( () => {
313+
return {
314+
getExtensionData: () => {
315+
return extensionData;
316+
},
317+
getAdditionalFields: () => {
318+
return {};
319+
},
320+
getCustomerData: () => {
321+
return {};
322+
},
323+
};
324+
} );
325+
326+
const expectedNormalizedDataWithAdditionalFields = {
327+
...expectedNormalizedData,
328+
extensions: extensionData,
329+
};
330+
331+
expect( normalizeOrderData( { event, paymentMethodId } ) ).toEqual(
332+
expectedNormalizedDataWithAdditionalFields
333+
);
334+
} );
335+
302336
test( 'should include additional customer (address) fields in the normalized order data', () => {
303337
const additionalCustomerData = {
304338
custom_address_field1: 'test1',
305339
custom_address_field2: 'test2',
306340
};
307341
select.mockImplementation( () => {
308342
return {
343+
getExtensionData: () => {
344+
return {};
345+
},
309346
getAdditionalFields: () => {
310347
return {};
311348
},

client/express-checkout/utils/normalize.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const normalizeOrderData = ( {
4949
} ),
5050
extensions: applyFilters(
5151
'wcstripe.express-checkout.cart-place-order-extension-data',
52-
{}
52+
getExtensionDataFromStore()
5353
),
5454
additional_fields: getAdditionalFieldsData(),
5555
};
@@ -288,6 +288,25 @@ const getAdditionalFieldsDataFromStore = () => {
288288
return store.getAdditionalFields() || {};
289289
};
290290

291+
/**
292+
* Get extension data from the checkout store.
293+
*
294+
* @return {Object} The extension data.
295+
*/
296+
const getExtensionDataFromStore = () => {
297+
const checkoutStore = window.wc?.wcBlocksData?.checkoutStore;
298+
if ( ! checkoutStore ) {
299+
return {};
300+
}
301+
302+
const store = select( checkoutStore );
303+
if ( ! store ) {
304+
return {};
305+
}
306+
307+
return store?.getExtensionData() || {};
308+
};
309+
291310
/**
292311
* Build the custom fields object with empty values.
293312
*

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
163163
* Fix - Fix payment processing for $0 subscription with recurring coupon
164164
* Dev - Add e2e tests to cover Affirm purchase flow
165165
* Fix - Add safety check when checking error object
166+
* Update - Include extension data from block checkout when submitting an express checkout order
166167

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

0 commit comments

Comments
 (0)