Skip to content

Commit

Permalink
Merge branch 'develop' into tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
Timur Karimov committed Dec 12, 2023
2 parents 05ab147 + 3d373d6 commit a4f086a
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 112 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-3693-qualitative-feedback-note
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Update Qualitative Feedback note to have more efficient sql query.
4 changes: 4 additions & 0 deletions changelog/fix-7750-include-discount-in-tooltip
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Include discount fee in fees tooltip
4 changes: 4 additions & 0 deletions changelog/fix-account-currency-hook
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

fix: account currency hook return value
2 changes: 1 addition & 1 deletion client/payment-methods/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const PaymentMethods = () => {

const [ , updateSelectedPaymentMethod ] = useSelectedPaymentMethod();

const [ stripeAccountDomesticCurrency ] = useAccountDomesticCurrency();
const stripeAccountDomesticCurrency = useAccountDomesticCurrency();

const completeActivation = ( itemId ) => {
updateSelectedPaymentMethod( itemId );
Expand Down
59 changes: 40 additions & 19 deletions client/utils/account-fees.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
Expand All @@ -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,
Expand All @@ -136,14 +143,20 @@ export const formatMethodFeesTooltip = (
<div>
<div>Base fee</div>
<div>
{ getFeeDescriptionString( currentFeeWithBaseFallBack ) }
{ getFeeDescriptionString(
accountFees.base,
discountAdjustedFeeRate
) }
</div>
</div>
{ hasFees( accountFees.additional ) ? (
<div>
<div>International payment method fee</div>
<div>
{ getFeeDescriptionString( accountFees.additional ) }
{ getFeeDescriptionString(
accountFees.additional,
discountAdjustedFeeRate
) }
</div>
</div>
) : (
Expand All @@ -152,15 +165,23 @@ export const formatMethodFeesTooltip = (
{ hasFees( accountFees.fx ) ? (
<div>
<div>Foreign exchange fee</div>
<div>{ getFeeDescriptionString( accountFees.fx ) }</div>
<div>
{ getFeeDescriptionString(
accountFees.fx,
discountAdjustedFeeRate
) }
</div>
</div>
) : (
''
) }
<div>
<div>Total per transaction</div>
<div className={ 'wcpay-fees-tooltip__bold' }>
{ getFeeDescriptionString( total ) }
{ getFeeDescriptionString(
total,
discountAdjustedFeeRate
) }
</div>
</div>
{ wcpaySettings &&
Expand Down
65 changes: 4 additions & 61 deletions client/utils/test/__snapshots__/account-fees.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ exports[`Account fees utility functions formatMethodFeesTooltip() displays base
Base fee
</div>
<div>
12.3% + $4.57
9.84% + $3.65
</div>
</div>
<div>
<div>
International payment method fee
</div>
<div>
1%
0.8%
</div>
</div>
<div>
<div>
Foreign exchange fee
</div>
<div>
1%
0.8%
</div>
</div>
<div>
Expand All @@ -36,7 +36,7 @@ exports[`Account fees utility functions formatMethodFeesTooltip() displays base
<div
class="wcpay-fees-tooltip__bold"
>
14.3% + $4.57
11.44% + $3.65
</div>
</div>
<div
Expand Down Expand Up @@ -113,60 +113,3 @@ exports[`Account fees utility functions formatMethodFeesTooltip() displays base
</div>
</div>
`;

exports[`Account fees utility functions formatMethodFeesTooltip() displays custom fee details, when applicable 1`] = `
<div>
<div
class="wcpay-fees-tooltip"
>
<div>
<div>
Base fee
</div>
<div>
10.1% + $4.01
</div>
</div>
<div>
<div>
International payment method fee
</div>
<div>
1%
</div>
</div>
<div>
<div>
Foreign exchange fee
</div>
<div>
1%
</div>
</div>
<div>
<div>
Total per transaction
</div>
<div
class="wcpay-fees-tooltip__bold"
>
12.1% + $4.01
</div>
</div>
<div
class="wcpay-fees-tooltip__hint-text"
>
<span>
<a
href="https://woo.com/document/woopayments/fees-and-debits/fees/#united-states"
rel="noreferrer"
target="_blank"
>
Learn more
</a>
about WooPayments Fees in your country
</span>
</div>
</div>
</div>
`;
29 changes: 0 additions & 29 deletions client/utils/test/account-fees.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down
23 changes: 21 additions & 2 deletions includes/notes/class-wc-payments-notes-qualitative-feedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit a4f086a

Please sign in to comment.