From 88711f283486643ac4fc5a09091f3bd37124ca9c Mon Sep 17 00:00:00 2001 From: Francesco Date: Tue, 12 Dec 2023 00:16:07 -0800 Subject: [PATCH 1/3] fix: account currency hook return value (#7872) --- changelog/fix-account-currency-hook | 4 ++++ client/payment-methods/index.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changelog/fix-account-currency-hook diff --git a/changelog/fix-account-currency-hook b/changelog/fix-account-currency-hook new file mode 100644 index 00000000000..23d9628b19f --- /dev/null +++ b/changelog/fix-account-currency-hook @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +fix: account currency hook return value diff --git a/client/payment-methods/index.js b/client/payment-methods/index.js index 950610e6fba..7efb306b0da 100644 --- a/client/payment-methods/index.js +++ b/client/payment-methods/index.js @@ -92,7 +92,7 @@ const PaymentMethods = () => { const [ , updateSelectedPaymentMethod ] = useSelectedPaymentMethod(); - const [ stripeAccountDomesticCurrency ] = useAccountDomesticCurrency(); + const stripeAccountDomesticCurrency = useAccountDomesticCurrency(); const completeActivation = ( itemId ) => { updateSelectedPaymentMethod( itemId ); From d04bda8dfbfd2a05ac7e73e9f588c0deab8bc82a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C4=81rlis=20Janisels?= Date: Tue, 12 Dec 2023 11:12:01 +0200 Subject: [PATCH 2/3] Include discount in fees brakedown tooltip (#7787) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kārlis Janisels Co-authored-by: Vladimir Reznichenko --- .../fix-7750-include-discount-in-tooltip | 4 ++ client/utils/account-fees.tsx | 59 +++++++++++------ .../test/__snapshots__/account-fees.tsx.snap | 65 ++----------------- client/utils/test/account-fees.tsx | 29 --------- 4 files changed, 48 insertions(+), 109 deletions(-) create mode 100644 changelog/fix-7750-include-discount-in-tooltip diff --git a/changelog/fix-7750-include-discount-in-tooltip b/changelog/fix-7750-include-discount-in-tooltip new file mode 100644 index 00000000000..b600a611e92 --- /dev/null +++ b/changelog/fix-7750-include-discount-in-tooltip @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Include discount fee in fees tooltip diff --git a/client/utils/account-fees.tsx b/client/utils/account-fees.tsx index 6ba2674de6d..c2b3214c1b5 100644 --- a/client/utils/account-fees.tsx +++ b/client/utils/account-fees.tsx @@ -74,24 +74,31 @@ const getStripeFeeSectionUrl = ( country: string ): string => { ); }; -const getFeeDescriptionString = ( fee: BaseFee ): string => { +const getFeeDescriptionString = ( + fee: BaseFee, + discountBasedMultiplier: number +): string => { if ( fee.fixed_rate && fee.percentage_rate ) { return sprintf( '%1$f%% + %2$s', - formatFee( fee.percentage_rate ), - formatCurrency( fee.fixed_rate, fee.currency ) + formatFee( fee.percentage_rate * discountBasedMultiplier ), + formatCurrency( + fee.fixed_rate * discountBasedMultiplier, + fee.currency + ) ); } else if ( fee.fixed_rate ) { return sprintf( - '%2$s', - formatFee( fee.percentage_rate ), - formatCurrency( fee.fixed_rate, fee.currency ) + '%1$s', + formatCurrency( + fee.fixed_rate * discountBasedMultiplier, + fee.currency + ) ); } else if ( fee.percentage_rate ) { return sprintf( '%1$f%%', - formatFee( fee.percentage_rate ), - formatCurrency( fee.fixed_rate, fee.currency ) + formatFee( fee.percentage_rate * discountBasedMultiplier ) ); } return ''; @@ -109,19 +116,19 @@ export const formatMethodFeesTooltip = ( accountFees: FeeStructure ): JSX.Element => { if ( ! accountFees ) return <>; - const currentBaseFee = getCurrentBaseFee( accountFees ); - // If the current fee doesn't have a fixed or percentage rate, use the base fee's rate. Eg. when there is a promotional discount fee applied. Use this to calculate the total fee too. - const currentFeeWithBaseFallBack = currentBaseFee.percentage_rate - ? currentBaseFee - : accountFees.base; + + const discountAdjustedFeeRate: number = + accountFees.discount.length && accountFees.discount[ 0 ].discount + ? 1 - accountFees.discount[ 0 ].discount + : 1; const total = { percentage_rate: - currentFeeWithBaseFallBack.percentage_rate + + accountFees.base.percentage_rate + accountFees.additional.percentage_rate + accountFees.fx.percentage_rate, fixed_rate: - currentFeeWithBaseFallBack.fixed_rate + + accountFees.base.fixed_rate + accountFees.additional.fixed_rate + accountFees.fx.fixed_rate, currency: accountFees.base.currency, @@ -136,14 +143,20 @@ export const formatMethodFeesTooltip = (
Base fee
- { getFeeDescriptionString( currentFeeWithBaseFallBack ) } + { getFeeDescriptionString( + accountFees.base, + discountAdjustedFeeRate + ) }
{ hasFees( accountFees.additional ) ? (
International payment method fee
- { getFeeDescriptionString( accountFees.additional ) } + { getFeeDescriptionString( + accountFees.additional, + discountAdjustedFeeRate + ) }
) : ( @@ -152,7 +165,12 @@ export const formatMethodFeesTooltip = ( { hasFees( accountFees.fx ) ? (
Foreign exchange fee
-
{ getFeeDescriptionString( accountFees.fx ) }
+
+ { getFeeDescriptionString( + accountFees.fx, + discountAdjustedFeeRate + ) } +
) : ( '' @@ -160,7 +178,10 @@ export const formatMethodFeesTooltip = (
Total per transaction
- { getFeeDescriptionString( total ) } + { getFeeDescriptionString( + total, + discountAdjustedFeeRate + ) }
{ wcpaySettings && diff --git a/client/utils/test/__snapshots__/account-fees.tsx.snap b/client/utils/test/__snapshots__/account-fees.tsx.snap index 5ec2897e12b..5388a2b344d 100644 --- a/client/utils/test/__snapshots__/account-fees.tsx.snap +++ b/client/utils/test/__snapshots__/account-fees.tsx.snap @@ -10,7 +10,7 @@ exports[`Account fees utility functions formatMethodFeesTooltip() displays base Base fee
- 12.3% + $4.57 + 9.84% + $3.65
@@ -18,7 +18,7 @@ exports[`Account fees utility functions formatMethodFeesTooltip() displays base International payment method fee
- 1% + 0.8%
@@ -26,7 +26,7 @@ exports[`Account fees utility functions formatMethodFeesTooltip() displays base Foreign exchange fee
- 1% + 0.8%
@@ -36,7 +36,7 @@ exports[`Account fees utility functions formatMethodFeesTooltip() displays base
- 14.3% + $4.57 + 11.44% + $3.65
`; - -exports[`Account fees utility functions formatMethodFeesTooltip() displays custom fee details, when applicable 1`] = ` -
-
-
-
- Base fee -
-
- 10.1% + $4.01 -
-
-
-
- International payment method fee -
-
- 1% -
-
-
-
- Foreign exchange fee -
-
- 1% -
-
-
-
- Total per transaction -
-
- 12.1% + $4.01 -
-
-
- - - Learn more - - about WooPayments Fees in your country - -
-
-
-`; diff --git a/client/utils/test/account-fees.tsx b/client/utils/test/account-fees.tsx index 72cf891067b..c1b181ac160 100644 --- a/client/utils/test/account-fees.tsx +++ b/client/utils/test/account-fees.tsx @@ -310,35 +310,6 @@ describe( 'Account fees utility functions', () => { expect( container ).toMatchSnapshot(); } ); - it( 'displays custom fee details, when applicable', () => { - const methodFees = mockAccountFees( - { - percentage_rate: 0.123, - fixed_rate: 456.78, - currency: 'USD', - }, - [ { percentage_rate: 0.101, fixed_rate: 400.78 } ] - ); - - methodFees.additional = { - percentage_rate: 0.01, - fixed_rate: 0, - currency: 'USD', - }; - - methodFees.fx = { - percentage_rate: 0.01, - fixed_rate: 0, - currency: 'USD', - }; - - const { container } = render( - formatMethodFeesTooltip( methodFees ) - ); - - expect( container ).toMatchSnapshot(); - } ); - it( 'displays base fee, when only promo discount without percentage or fixed', () => { const methodFees = mockAccountFees( { From 3d373d68fe0f8cee425bac3aa9b0b37f9fa4f092 Mon Sep 17 00:00:00 2001 From: Jesse Pearson Date: Tue, 12 Dec 2023 07:41:22 -0400 Subject: [PATCH 3/3] Update Qualitative Feedback note to have more efficient sql query (#7825) --- changelog/fix-3693-qualitative-feedback-note | 4 ++++ ...wc-payments-notes-qualitative-feedback.php | 23 +++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 changelog/fix-3693-qualitative-feedback-note diff --git a/changelog/fix-3693-qualitative-feedback-note b/changelog/fix-3693-qualitative-feedback-note new file mode 100644 index 00000000000..8862cc0c961 --- /dev/null +++ b/changelog/fix-3693-qualitative-feedback-note @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Update Qualitative Feedback note to have more efficient sql query. diff --git a/includes/notes/class-wc-payments-notes-qualitative-feedback.php b/includes/notes/class-wc-payments-notes-qualitative-feedback.php index 266e1dd70f1..031fbd6b473 100644 --- a/includes/notes/class-wc-payments-notes-qualitative-feedback.php +++ b/includes/notes/class-wc-payments-notes-qualitative-feedback.php @@ -38,8 +38,27 @@ public static function get_note() { } // We should have at least one transaction. - $token_count = $wpdb->get_var( "select count(*) from {$wpdb->prefix}woocommerce_payment_tokens" ); - if ( 0 === (int) $token_count ) { + if ( WC_Payments_Utils::is_hpos_tables_usage_enabled() ) { + $result = $wpdb->get_var( + "SELECT EXISTS( + SELECT 1 + FROM {$wpdb->prefix}wc_orders_meta + WHERE meta_key = '_wcpay_transaction_fee' + LIMIT 1) + AS count;" + ); + } else { + $result = $wpdb->get_var( + "SELECT EXISTS( + SELECT 1 + FROM {$wpdb->postmeta} + WHERE meta_key = '_wcpay_transaction_fee' + LIMIT 1) + AS count;" + ); + } + + if ( 1 !== intval( $result ) ) { return; }