From b17e778f0f10b420f4442412b905e7af1b522ae8 Mon Sep 17 00:00:00 2001 From: frosso Date: Thu, 6 Jun 2024 11:31:58 +0200 Subject: [PATCH 1/2] fix: itemized totals & pending amount on tokenized cart --- .../fix-pending-amount-missing-itemized-totals | 4 ++++ .../transformers/wc-to-stripe.js | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 changelog/fix-pending-amount-missing-itemized-totals diff --git a/changelog/fix-pending-amount-missing-itemized-totals b/changelog/fix-pending-amount-missing-itemized-totals new file mode 100644 index 00000000000..e863c29b2e5 --- /dev/null +++ b/changelog/fix-pending-amount-missing-itemized-totals @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +fix: itemized totals & pending amount on tokenized cart diff --git a/client/tokenized-payment-request/transformers/wc-to-stripe.js b/client/tokenized-payment-request/transformers/wc-to-stripe.js index 1d04026e7f5..099b5fb4ca6 100644 --- a/client/tokenized-payment-request/transformers/wc-to-stripe.js +++ b/client/tokenized-payment-request/transformers/wc-to-stripe.js @@ -13,26 +13,28 @@ import { __ } from '@wordpress/i18n'; export const transformCartDataForDisplayItems = ( cartData ) => { const displayItems = cartData.items.map( ( item ) => ( { amount: parseInt( item.prices.price, 10 ), - // TODO: should we also add variation attributes? + // TODO: should we also add variation attributes to the description? label: [ item.name, item.quantity > 1 && ` (x${ item.quantity })` ] .filter( Boolean ) .join( '' ), - pending: true, } ) ); - if ( cartData.totals.total_tax ) { + const taxAmount = parseInt( cartData.totals.total_tax || '0', 10 ); + if ( taxAmount ) { displayItems.push( { - amount: parseInt( cartData.totals.total_tax, 10 ), + amount: taxAmount, label: __( 'Tax', 'woocommerce-payments' ), - pending: true, } ); } - if ( cartData.totals.total_shipping ) { + const shippingAmount = parseInt( + cartData.totals.total_shipping || '0', + 10 + ); + if ( shippingAmount ) { displayItems.push( { - amount: parseInt( cartData.totals.total_shipping, 10 ), + amount: shippingAmount, label: __( 'Shipping', 'woocommerce-payments' ), - pending: true, } ); } From 5daa87878ce35caf1f74d95a72129f5dcb584a51 Mon Sep 17 00:00:00 2001 From: frosso Date: Thu, 6 Jun 2024 11:40:16 +0200 Subject: [PATCH 2/2] remove TODO --- .../transformers/wc-to-stripe.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/client/tokenized-payment-request/transformers/wc-to-stripe.js b/client/tokenized-payment-request/transformers/wc-to-stripe.js index 099b5fb4ca6..a2e841b66b6 100644 --- a/client/tokenized-payment-request/transformers/wc-to-stripe.js +++ b/client/tokenized-payment-request/transformers/wc-to-stripe.js @@ -13,10 +13,19 @@ import { __ } from '@wordpress/i18n'; export const transformCartDataForDisplayItems = ( cartData ) => { const displayItems = cartData.items.map( ( item ) => ( { amount: parseInt( item.prices.price, 10 ), - // TODO: should we also add variation attributes to the description? - label: [ item.name, item.quantity > 1 && ` (x${ item.quantity })` ] + label: [ + item.name, + item.quantity > 1 && `(x${ item.quantity })`, + item.variation && + item.variation + .map( + ( variation ) => + `${ variation.attribute }: ${ variation.value }` + ) + .join( ', ' ), + ] .filter( Boolean ) - .join( '' ), + .join( ' ' ), } ) ); const taxAmount = parseInt( cartData.totals.total_tax || '0', 10 );