Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/feat-add-apple-pay-google-pay-definitions
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

refactor: add Apple Pay and Google Pay payment definitions
33 changes: 25 additions & 8 deletions client/components/payment-method-details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import './style.scss';
import p24BankList from '../../payment-details/payment-method/p24/bank-list';
import { HoverTooltip } from '../tooltip';
import { getTransactionPaymentMethodTitle } from 'wcpay/transactions/utils/getTransactionPaymentMethodTitle';
import paymentMethodsMap from 'wcpay/payment-methods-map';

interface Payment {
type: string;
Expand Down Expand Up @@ -67,6 +68,27 @@ const formatDetails = ( payment: Payment ): ReactNode => {
}
};

const WalletIcon = ( { payment }: PaymentMethodDetailsProps ) => {
const { wallet } = payment[ payment.type ];
if ( ! wallet ) return null;

if ( ! wallet.type ) return null;

const paymentMethod = paymentMethodsMap[ wallet.type ];
if ( ! paymentMethod ) return null;

const { icon: Icon, label } = paymentMethod;

return (
<HoverTooltip
isVisible={ false }
content={ label }
className="payment-method-details__brand-tooltip"
>
<Icon />
</HoverTooltip>
);
};
interface PaymentMethodDetailsProps {
payment: Payment;
}
Expand All @@ -78,20 +100,15 @@ const PaymentMethodDetails = ( { payment }: PaymentMethodDetailsProps ) => {
return <span>&ndash;</span>;
}

let brand = payment.type;
if ( paymentMethod && paymentMethod.brand ) {
brand = paymentMethod.brand;
}
if ( paymentMethod && paymentMethod.network ) {
brand = paymentMethod.network;
}

const details = formatDetails( payment );

const accountCountry = wcpaySettings?.accountStatus?.country || 'US';
const brand =
paymentMethod?.brand || paymentMethod?.network || payment?.type;

return (
<span className="payment-method-details">
<WalletIcon payment={ payment } />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shows the wallet icon next to the payment

Image

Unfortunately, it's not possible to show the wallet icon on the transactions list, because it's missing the wallet information.

<HoverTooltip
isVisible={ false }
content={ getTransactionPaymentMethodTitle( brand ) }
Expand Down
7 changes: 7 additions & 0 deletions client/components/payment-method-details/style.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
/** @format **/

.payment-method-details {
gap: 5px;

.payment-method__icon {
width: 28px;
width: 1.75rem;
}

.payment-method__brand {
width: 28px;
width: 1.75rem;
Expand Down
2 changes: 2 additions & 0 deletions client/constants/payment-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ enum PAYMENT_METHOD_IDS {
AFFIRM = 'affirm',
AFTERPAY_CLEARPAY = 'afterpay_clearpay',
ALIPAY = 'alipay',
APPLE_PAY = 'apple_pay',
AU_BECS_DEBIT = 'au_becs_debit',
BANCONTACT = 'bancontact',
CARD = 'card',
CARD_PRESENT = 'card_present',
EPS = 'eps',
GIROPAY = 'giropay',
GOOGLE_PAY = 'google_pay',
GRABPAY = 'grabpay',
IDEAL = 'ideal',
KLARNA = 'klarna',
Expand Down
21 changes: 5 additions & 16 deletions client/disable-confirmation-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ import PaymentDeleteIllustration from '../components/payment-delete-illustration
import WooCardIcon from 'assets/images/cards/woo-card.svg?asset';
import ConfirmationModal from '../components/confirmation-modal';
import paymentMethodsMap from 'wcpay/payment-methods-map';
import {
ApplePayIcon,
GooglePayIcon,
LinkIcon,
WooIconShort,
} from 'wcpay/payment-methods-icons';
import { LinkIcon, WooIconShort } from 'wcpay/payment-methods-icons';

const DisableConfirmationModal = ( { onClose, onConfirm } ) => {
const [ enabledMethodIds ] = useEnabledPaymentMethodIds();
Expand Down Expand Up @@ -109,20 +104,14 @@ const DisableConfirmationModal = ( { onClose, onConfirm } ) => {
<>
<li>
<PaymentMethodIcon
Icon={ GooglePayIcon }
label={ __(
'Google Pay',
'woocommerce-payments'
) }
Icon={ paymentMethodsMap.google_pay.icon }
label={ paymentMethodsMap.google_pay.label }
/>
</li>
<li>
<PaymentMethodIcon
Icon={ ApplePayIcon }
label={ __(
'Apple Pay',
'woocommerce-payments'
) }
Icon={ paymentMethodsMap.apple_pay.icon }
label={ paymentMethodsMap.apple_pay.label }
/>
</li>
</>
Expand Down
4 changes: 0 additions & 4 deletions client/express-checkout/transformers/stripe-to-wc.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ export const transformStripePaymentMethodForStoreApi = (
key: 'payment_method',
value: 'card',
},
{
key: 'payment_request_type',
value: paymentData.expressPaymentType,
},
Comment on lines -80 to -83
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deprecating the payment_request_type attribute from $_POST. It's a duplicate of express_payment_type. See PR description for background info.

{
key: 'wcpay-fraud-prevention-token',
value: window.wcpayFraudPreventionToken ?? '',
Expand Down
3 changes: 0 additions & 3 deletions client/express-checkout/utils/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ describe( 'Express checkout normalization', () => {
ship_to_different_address: 1,
terms: 1,
'wcpay-payment-method': paymentMethodId,
payment_request_type: 'express',
express_payment_type: 'express',
'wcpay-fraud-prevention-token': 'token123',
};
Expand Down Expand Up @@ -242,7 +241,6 @@ describe( 'Express checkout normalization', () => {
ship_to_different_address: 1,
terms: 1,
'wcpay-payment-method': paymentMethodId,
payment_request_type: undefined,
express_payment_type: undefined,
'wcpay-fraud-prevention-token': '',
};
Expand Down Expand Up @@ -288,7 +286,6 @@ describe( 'Express checkout normalization', () => {
ship_to_different_address: 1,
terms: 1,
'wcpay-payment-method': paymentMethodId,
payment_request_type: undefined,
express_payment_type: undefined,
'wcpay-fraud-prevention-token': '',
};
Expand Down
1 change: 0 additions & 1 deletion client/express-checkout/utils/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export const normalizeOrderData = ( event, paymentMethodId ) => {
ship_to_different_address: 1,
terms: 1,
'wcpay-payment-method': paymentMethodId,
payment_request_type: event?.expressPaymentType,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deprecating the payment_request_type attribute from $_POST. It's a duplicate of express_payment_type. See PR description for background info.

express_payment_type: event?.expressPaymentType,
'wcpay-fraud-prevention-token': fraudPreventionTokenValue,
};
Expand Down
10 changes: 0 additions & 10 deletions client/payment-methods-icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import MasterCardAsset from 'assets/images/cards/mastercard.svg?asset';
import AmexAsset from 'assets/images/cards/amex.svg?asset';
import WooAsset from 'assets/images/payment-methods/woo.svg?asset';
import WooAssetShort from 'assets/images/payment-methods/woo-short.svg?asset';
import ApplePayAsset from 'assets/images/cards/apple-pay.svg?asset';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The asset is still used in the payment method definition.

import GooglePayAsset from 'assets/images/cards/google-pay.svg?asset';
import DinersClubAsset from 'assets/images/cards/diners.svg?asset';
import DiscoverAsset from 'assets/images/cards/discover.svg?asset';
import CBAsset from 'assets/images/cards/cb.svg?asset';
Expand Down Expand Up @@ -49,10 +47,6 @@ export const AmericanExpressIcon = iconComponent(
AmexAsset,
__( 'American Express', 'woocommerce-payments' )
);
export const ApplePayIcon = iconComponent(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used anywhere anymore

ApplePayAsset,
__( 'Apple Pay', 'woocommerce-payments' )
);
export const CBIcon = iconComponent(
CBAsset,
__( 'Cartes Bancaires', 'woocommerce-payments' )
Expand All @@ -65,10 +59,6 @@ export const DiscoverIcon = iconComponent(
DiscoverAsset,
__( 'Discover', 'woocommerce-payments' )
);
export const GooglePayIcon = iconComponent(
GooglePayAsset,
__( 'Google Pay', 'woocommerce-payments' )
);
export const JCBIcon = iconComponent(
JCBAsset,
__( 'JCB', 'woocommerce-payments' )
Expand Down
51 changes: 28 additions & 23 deletions client/settings/express-checkout-settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ import SettingsLayout from '../settings-layout';
import LoadableSettingsSection from '../loadable-settings-section';
import SaveSettingsSection from '../save-settings-section';
import ErrorBoundary from '../../components/error-boundary';
import {
AmazonPayIcon,
ApplePayIcon,
GooglePayIcon,
WooIcon,
} from 'wcpay/payment-methods-icons';
import { AmazonPayIcon, WooIcon } from 'wcpay/payment-methods-icons';
import methodsConfiguration from 'wcpay/payment-methods-map';

const methods = {
woopay: {
Expand Down Expand Up @@ -76,24 +72,33 @@ const methods = {
sections: [
{
section: 'enable',
description: () => (
<>
<div className="express-checkout-settings__icons">
<div className="express-checkout-settings__icon">
<ApplePayIcon />
</div>
<div className="express-checkout-settings__icon">
<GooglePayIcon />
description: () => {
const {
icon: ApplePayIcon,
} = methodsConfiguration.apple_pay;
const {
icon: GooglePayIcon,
} = methodsConfiguration.google_pay;

return (
<>
<div className="express-checkout-settings__icons">
<div className="express-checkout-settings__icon">
<ApplePayIcon />
</div>
<div className="express-checkout-settings__icon">
<GooglePayIcon />
</div>
</div>
</div>
<p>
{ __(
'Allow your customers to collect payments via Apple Pay and Google Pay.',
'woocommerce-payments'
) }
</p>
</>
),
<p>
{ __(
'Allow your customers to collect payments via Apple Pay and Google Pay.',
'woocommerce-payments'
) }
</p>
</>
);
},
},
{
section: 'general',
Expand Down
Loading
Loading