Skip to content

Commit

Permalink
Merge branch 'develop' into fix/token-retrieval-per-payment-method
Browse files Browse the repository at this point in the history
  • Loading branch information
timur27 authored Jun 21, 2024
2 parents a5aa44b + aac2f27 commit a9987ec
Show file tree
Hide file tree
Showing 37 changed files with 1,927 additions and 129 deletions.
3 changes: 3 additions & 0 deletions assets/images/icons/send-money.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: chore: copy PRB blocks to tokenized cart


4 changes: 4 additions & 0 deletions changelog/fix-8220-instant-deposit-messaging
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Clearly display available instant deposit amount on notice and button label on Payment Overview page
4 changes: 4 additions & 0 deletions changelog/fix-8718-restrict-klarna-non-domestic-transactions
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: fix

Hide payment methods with domestic transactions restrictions (Klarna, Affirm, Afterpay) when conditions are not met.
4 changes: 4 additions & 0 deletions changelog/kreykjalin-8868-ece-cart-and-checkout-page
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Add support for ECE elements on the Shortcode Cart and Checkout pages
5 changes: 5 additions & 0 deletions changelog/update-8972-save-payment-activity-preset-session
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: update
Comment: Part of Payment Activity Card. Persist selected preset date in session.


8 changes: 7 additions & 1 deletion client/checkout/blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import request from '../utils/request';
import enqueueFraudScripts from 'fraud-scripts';
import paymentRequestPaymentMethod from '../../payment-request/blocks';
import expressCheckoutElementPaymentMethod from '../../express-checkout/blocks';
import tokenizedCartPaymentRequestPaymentMethod from '../../tokenized-payment-request/blocks';

import {
PAYMENT_METHOD_NAME_CARD,
PAYMENT_METHOD_NAME_BANCONTACT,
Expand Down Expand Up @@ -154,7 +156,11 @@ if ( getUPEConfig( 'isWooPayEnabled' ) ) {
}
}

if ( getUPEConfig( 'isExpressCheckoutElementEnabled' ) ) {
if ( getUPEConfig( 'isTokenizedCartPrbEnabled' ) ) {
registerExpressPaymentMethod(
tokenizedCartPaymentRequestPaymentMethod( api )
);
} else if ( getUPEConfig( 'isExpressCheckoutElementEnabled' ) ) {
registerExpressPaymentMethod( expressCheckoutElementPaymentMethod( api ) );
} else {
registerExpressPaymentMethod( paymentRequestPaymentMethod( api ) );
Expand Down
115 changes: 107 additions & 8 deletions client/components/account-balances/index.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,63 @@
/**
* External dependencies
*/
import * as React from 'react';
import React, { useState } from 'react';
import { useDispatch } from '@wordpress/data';
import { Flex } from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import interpolateComponents from '@automattic/interpolate-components';
import { Link } from '@woocommerce/components';

/**
* Internal dependencies
*/
import { useAllDepositsOverviews } from 'wcpay/data';
import { useSelectedCurrency } from 'wcpay/overview/hooks';
import type * as AccountOverview from 'wcpay/types/account-overview';
import BalanceBlock from './balance-block';
import HelpOutlineIcon from 'gridicons/dist/help-outline';
import InlineNotice from '../inline-notice';
import InstantDepositButton from 'deposits/instant-deposits';
import SendMoneyIcon from 'assets/images/icons/send-money.svg?asset';
import {
TotalBalanceTooltip,
AvailableBalanceTooltip,
} from './balance-tooltip';
import { fundLabelStrings } from './strings';
import InstantDepositButton from 'deposits/instant-deposits';
import type * as AccountOverview from 'wcpay/types/account-overview';
import { ClickTooltip } from '../tooltip';
import { formatCurrency } from 'wcpay/utils/currency';
import { useAllDepositsOverviews } from 'wcpay/data';
import { useSelectedCurrency } from 'wcpay/overview/hooks';
import './style.scss';

const useInstantDepositNoticeState = () => {
const { updateOptions } = useDispatch( 'wc/admin/options' );
const [ isDismissed, setIsDismissed ] = useState(
wcpaySettings.isInstantDepositNoticeDismissed
);

const setInstantDepositNoticeDismissed = () => {
setIsDismissed( true );
wcpaySettings.isInstantDepositNoticeDismissed = true;
updateOptions( { wcpay_instant_deposit_notice_dismissed: true } );
};

return {
isInstantDepositNoticeDismissed: isDismissed,
handleDismissInstantDepositNotice: setInstantDepositNoticeDismissed,
};
};

/**
* Renders account balances for the selected currency.
*/
const AccountBalances: React.FC = () => {
const { overviews, isLoading } = useAllDepositsOverviews();
const { selectedCurrency } = useSelectedCurrency();

const {
isInstantDepositNoticeDismissed,
handleDismissInstantDepositNotice,
} = useInstantDepositNoticeState();

if ( ! isLoading && overviews.currencies.length === 0 ) {
return null;
}
Expand Down Expand Up @@ -108,10 +140,77 @@ const AccountBalances: React.FC = () => {
<Flex
gap={ 0 }
className="wcpay-account-balances__instant-deposit"
direction="column"
align="start"
>
<InstantDepositButton
instantBalance={ selectedOverview.instantBalance }
/>
{ ! isInstantDepositNoticeDismissed && (
<InlineNotice
className="wcpay-account-balances__instant-deposit-notice"
icon={ <img src={ SendMoneyIcon } alt="" /> }
isDismissible={ true }
onRemove={ () =>
handleDismissInstantDepositNotice()
}
>
{ sprintf(
__(
/* translators: %$1$s: Available instant deposit amount, %2$s: Instant deposit fee percentage */
/* 'Instantly deposit %1$s and get funds in your bank account in 30 mins for a %2$s%% fee.' */
'Get %1$s via instant deposit. Funds are typically in your bank account within 30 mins. Fee: %2$s%%.',
'woocommerce-payments'
),
formatCurrency(
selectedOverview.instantBalance.amount,
selectedOverview.instantBalance.currency
),
selectedOverview.instantBalance
.fee_percentage
) }
</InlineNotice>
) }

<Flex justify="flex-start">
<InstantDepositButton
instantBalance={
selectedOverview.instantBalance
}
/>
{ isInstantDepositNoticeDismissed && ( // Show the tooltip only when the notice is dismissed.
<ClickTooltip
buttonIcon={ <HelpOutlineIcon /> }
buttonLabel={ __(
'Learn more about instant deposit',
'woocommerce-payments'
) }
content={
/* 'With instant deposit you can receive requested funds in your bank account within 30 mins for a 1.5% fee. Learn more' */

interpolateComponents( {
mixedString: sprintf(
__(
/* translators: %s: Instant deposit fee percentage */
'With {{strong}}instant deposit{{/strong}} you can receive requested funds in your bank account within 30 mins for a %s%% fee. {{learnMoreLink}}Learn more{{/learnMoreLink}}',
'woocommerce-payments'
),
selectedOverview.instantBalance
.fee_percentage
),
components: {
strong: <strong />,
learnMoreLink: (
<Link
href="https://woocommerce.com/document/woopayments/deposits/instant-deposits/"
target="_blank"
rel="noreferrer"
type="external"
/>
),
},
} )
}
/>
) }
</Flex>
</Flex>
) }
</>
Expand Down
9 changes: 5 additions & 4 deletions client/components/account-balances/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
font-size: 12px;
line-height: 16px;
color: $gray-600;
display: flex;
align-items: center;
margin-top: 0;
}

&__amount {
Expand All @@ -22,10 +25,8 @@
}
}

.wcpay-account-balances__balances__item__title {
display: flex;
align-items: center;
margin-top: 0;
.wcpay-account-balances__instant-deposit-notice .components-notice__content {
margin-right: 0;
}

.wcpay-account-balances__instant-deposit {
Expand Down
2 changes: 1 addition & 1 deletion client/components/account-balances/test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ describe( 'AccountBalances', () => {
render( <AccountBalances /> );

screen.getByRole( 'button', {
name: 'Deposit available funds',
name: 'Get $300.00 now',
} );
} );

Expand Down
8 changes: 5 additions & 3 deletions client/components/payment-activity/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ export const usePaymentActivityDateRangePresets = (): {
},
};

const defaultPreset =
sessionStorage.getItem( 'selectedPresetName' ) ?? 'last_7_days';
const defaultDateRange = {
preset_name: 'last_7_days',
date_start: dateRangePresets.last_7_days.start.format(
preset_name: defaultPreset,
date_start: dateRangePresets[ defaultPreset ].start.format(
'YYYY-MM-DD\\THH:mm:ss'
),
date_end: dateRangePresets.last_7_days.end.format(
date_end: dateRangePresets[ defaultPreset ].end.format(
'YYYY-MM-DD\\THH:mm:ss'
),
};
Expand Down
4 changes: 4 additions & 0 deletions client/components/payment-activity/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ const PaymentActivity: React.FC = () => {
.clone()
.format( 'YYYY-MM-DD\\THH:mm:ss' );
const { key: presetName } = selectedItem;
sessionStorage.setItem(
'selectedPresetName',
selectedItem.key
);
recordEvent(
'wcpay_overview_payment_activity_period_change',
{
Expand Down
15 changes: 13 additions & 2 deletions client/deposits/instant-deposits/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
*/
import React from 'react';
import { Button } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import './style.scss';
import { formatCurrency } from 'wcpay/utils/currency';
import InstantDepositModal from './modal';
import { useInstantDeposit } from 'wcpay/data';
import type * as AccountOverview from 'wcpay/types/account-overview';
Expand Down Expand Up @@ -49,7 +50,17 @@ const InstantDepositButton: React.FC< InstantDepositButtonProps > = ( {
disabled={ buttonDisabled }
onClick={ () => setModalOpen( true ) }
>
{ __( 'Deposit available funds', 'woocommerce-payments' ) }
{ sprintf(
__(
/* translators: %s: Available instant deposit amount */
'Get %s now',
'woocommerce-payments'
),
formatCurrency(
instantBalance.amount,
instantBalance.currency
)
) }
</Button>
{ ( isModalOpen || inProgress ) && (
<InstantDepositModal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,7 @@ exports[`Instant deposit button and modal button renders correctly with balance
class="components-button is-primary"
type="button"
>
Deposit available funds
</button>
</div>
`;

exports[`Instant deposit button and modal button renders correctly with zero balance 1`] = `
<div>
<button
class="components-button is-primary"
disabled=""
type="button"
>
Deposit available funds
Get $123.45 now
</button>
</div>
`;
Expand Down
19 changes: 3 additions & 16 deletions client/deposits/instant-deposits/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ const mockInstantBalance = {
currency: 'USD',
} as AccountOverview.InstantBalance;

const mockZeroInstantBalance = {
amount: 0,
fee: 0,
net: 0,
fee_percentage: 1.5,
currency: 'USD',
} as AccountOverview.InstantBalance;

declare const global: {
wcpaySettings: {
zeroDecimalCurrencies: string[];
Expand Down Expand Up @@ -70,13 +62,6 @@ describe( 'Instant deposit button and modal', () => {
};
} );

test( 'button renders correctly with zero balance', () => {
const { container } = render(
<InstantDepositButton instantBalance={ mockZeroInstantBalance } />
);
expect( container ).toMatchSnapshot();
} );

test( 'button renders correctly with balance', () => {
const { container } = render(
<InstantDepositButton instantBalance={ mockInstantBalance } />
Expand All @@ -92,7 +77,9 @@ describe( 'Instant deposit button and modal', () => {
screen.queryByRole( 'dialog', { name: /instant deposit/i } )
).not.toBeInTheDocument();
fireEvent.click(
screen.getByRole( 'button', { name: /Deposit available funds/i } )
screen.getByRole( 'button', {
name: /Get \$123\.45 now/i,
} )
);
const modal = screen.queryByRole( 'dialog', {
name: /instant deposit/i,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const useExpressCheckout = ( {
};

const abortPayment = ( onConfirmEvent, message ) => {
onConfirmEvent.paymentFailed( 'fail' );
onConfirmEvent.paymentFailed( { reason: 'fail' } );
setExpressPaymentError( message );
};

Expand Down
Loading

0 comments on commit a9987ec

Please sign in to comment.