Skip to content

Commit fb3978f

Browse files
committed
chore: update paypal components
1 parent 362d993 commit fb3978f

18 files changed

Lines changed: 108 additions & 75 deletions

packages/lib/src/components/PayPal/Paypal.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,8 @@ describe('Paypal', () => {
478478
describe('constructor', () => {
479479
test('should create the SDK loader and PayPal service and initialize it when usePayPalV6 is set', () => {
480480
new Paypal(core, {
481-
usePayPalV6: { vault: true, nonce: 'test-nonce' },
481+
usePayPalV6: { vault: true, nonce: 'test-nonce', countryCode: 'US' },
482482
configuration: { merchantId: 'merchant-1' },
483-
countryCode: 'US',
484483
amount: { value: 1000, currency: 'USD' }
485484
});
486485

packages/lib/src/components/PayPal/PaypalCredit.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class PaypalCreditElement extends BasePaypalElement<BasePayPalConfiguration> {
1414
protected override elementName: string = 'PayPalCredit';
1515

1616
public override get icon(): string {
17-
return this.resources.getImage()('paypal');
17+
return this.resources.getImage()(TxVariants.paypal);
1818
}
1919

2020
protected override componentToRender(): h.JSX.Element | null {

packages/lib/src/components/PayPal/PaypalPaylater.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class PaypalPaylaterElement extends BasePaypalElement<PayPalPayLaterConfiguratio
1515
protected override elementName: string = 'PayPalPaylater';
1616

1717
public override get icon(): string {
18-
return this.resources.getImage()('paypal');
18+
return this.resources.getImage()(TxVariants.paypal);
1919
}
2020

2121
protected override get paypalComponents(): PayPalComponents {
@@ -38,6 +38,7 @@ class PaypalPaylaterElement extends BasePaypalElement<PayPalPayLaterConfiguratio
3838
commit={this.props.commit}
3939
presentationModeOptions={this.props.presentationModeOptions}
4040
hidePayPalMessaging={this.props.hidePayPalMessaging}
41+
messagingContentOptions={this.props.messagingContentOptions}
4142
countryCode={this.props.countryCode}
4243
onSubmit={this.handleSubmit}
4344
onApprove={this.handleOnApprove}

packages/lib/src/components/PayPal/components/PayPalButton.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { h } from 'preact';
2+
import { useMemo } from 'preact/hooks';
23

3-
import type { PayPalButtonStyle } from '../types';
4-
import type { PayPalComponentV6Props } from './types';
4+
import type { PayPalButtonStyle, PayPalComponentV6Props } from './types';
55
import { usePayPalSessionOptions } from '../hooks/usePayPalSessionOptions';
66
import { useCreateOrder } from '../hooks/useCreateOrder';
77
import { useCreateVaultSetupToken } from '../hooks/useCreateVaultSetupToken';
88
import { useAmount } from '../../../core/Context/AmountProvider';
99
import { usePayPalOneTimeSession } from '../hooks/usePayPalOneTimeSession';
1010
import { usePayPalSaveSession } from '../hooks/usePayPalSaveSession';
1111
import { usePayPalButtonEligibility } from '../hooks/usePayPalButtonEligibility';
12-
import { useMemo } from 'preact/hooks';
1312

1413
export const PayPalButton = ({
1514
paypalService,

packages/lib/src/components/PayPal/components/PayPalMessaging.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@ import { useMemo, useEffect, useRef } from 'preact/hooks';
33

44
import { PayPalService } from '../services/PayPalService';
55
import { useAmount } from '../../../core/Context/AmountProvider';
6+
import { useCoreContext } from '../../../core/Context/CoreProvider';
7+
import type { PayPalFetchContentOptions, PayPalMessageElement } from '../paypal-js-types';
68

79
export const PayPalMessaging = ({
810
paypalService,
9-
countryCode
11+
countryCode,
12+
messagingContentOptions
1013
}: Readonly<{
1114
paypalService: PayPalService;
1215
countryCode?: string;
16+
messagingContentOptions?: Pick<PayPalFetchContentOptions, 'logoType' | 'logoPosition' | 'textColor'>;
1317
}>) => {
1418
const payPalSDKInstance = useMemo(() => paypalService.getInstance(), [paypalService]);
15-
const messageElementRef = useRef<HTMLElement | null>(null);
19+
const messageElementRef = useRef<PayPalMessageElement | null>(null);
1620
const { amount } = useAmount();
21+
const { i18n } = useCoreContext();
1722

1823
useEffect(() => {
1924
const fetchMessageContent = async (): Promise<void> => {
@@ -22,13 +27,18 @@ export const PayPalMessaging = ({
2227
currencyCode: amount.currency
2328
});
2429

30+
const amountString = i18n.amount(amount.value, amount.currency, {
31+
style: 'decimal',
32+
minimumFractionDigits: 0,
33+
signDisplay: 'never'
34+
});
35+
2536
await messagesInstance.fetchContent({
26-
textColor: 'BLACK',
27-
logoPosition: 'LEFT',
28-
logoType: 'TEXT',
29-
amount: String(amount.value / 100),
37+
textColor: messagingContentOptions?.textColor ?? 'BLACK',
38+
logoPosition: messagingContentOptions?.logoPosition ?? 'LEFT',
39+
logoType: messagingContentOptions?.logoType ?? 'TEXT',
40+
amount: amountString,
3041
onReady: content => {
31-
// @ts-ignore - messageElement is guaranteed to be a PayPalMessageElement
3242
messageElementRef.current?.setContent(content);
3343
}
3444
});

packages/lib/src/components/PayPal/components/PaypalPaylaterComponent.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import { PayPalPayLaterButton } from './PayPalPayLaterButton';
66
import { PayPalProcessingSpinner } from './PayPalProcessingSpinner';
77
import { PayPalSpinner } from './PayPalSpinner';
88
import { PayPalComponentV6Props } from './types';
9+
import { PayPalFetchContentOptions } from '../paypal-js-types';
910

1011
export const PayPalPaylaterComponent = ({
1112
paypalService,
1213
commit = true,
1314
presentationModeOptions,
1415
hidePayPalMessaging,
16+
messagingContentOptions,
1517
countryCode,
1618
onSubmit,
1719
onApprove,
@@ -24,6 +26,7 @@ export const PayPalPaylaterComponent = ({
2426
Omit<PayPalComponentV6Props, 'style' | 'vault'> & {
2527
hidePayPalMessaging?: boolean;
2628
countryCode?: string;
29+
messagingContentOptions?: Pick<PayPalFetchContentOptions, 'logoType' | 'logoPosition' | 'textColor'>;
2730
}
2831
>) => {
2932
const { status, handleOnApprove } = usePayPalStatus({
@@ -50,7 +53,9 @@ export const PayPalPaylaterComponent = ({
5053

5154
return (
5255
<div className="adyen-checkout__paypal" data-testid="paypal-paylater-component">
53-
{!hidePayPalMessaging && <PayPalMessaging paypalService={paypalService} countryCode={countryCode} />}
56+
{!hidePayPalMessaging && (
57+
<PayPalMessaging paypalService={paypalService} countryCode={countryCode} messagingContentOptions={messagingContentOptions} />
58+
)}
5459
<PayPalPayLaterButton
5560
paypalService={paypalService}
5661
presentationModeOptions={presentationModeOptions}

packages/lib/src/components/PayPal/components/VenmoButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { useMemo } from 'preact/hooks';
21
import { h } from 'preact';
2+
import { useMemo } from 'preact/hooks';
33

4-
import type { PayPalVenmoButtonStyle } from '../types';
4+
import type { PayPalVenmoButtonStyle } from './types';
55
import type { PayPalComponentV6Props } from './types';
66
import { usePayPalSessionOptions } from '../hooks/usePayPalSessionOptions';
77
import { useCreateOrder } from '../hooks/useCreateOrder';

packages/lib/src/components/PayPal/components/VenmoComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { h } from 'preact';
22

3-
import { PayPalVenmoButtonStyle } from '../../types';
3+
import { PayPalVenmoButtonStyle } from './types';
44
import { usePayPalStatus } from '../hooks/usePayPalStatus';
55
import { PayPalProcessingSpinner } from './PayPalProcessingSpinner';
66
import { PayPalSpinner } from './PayPalSpinner';

packages/lib/src/components/PayPal/components/types.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import type {
66
PayPalOnApproveData,
77
PayPalOnShippingAddressChangeData,
88
PayPalOnShippingOptionsChangeData,
9+
PayPalPresentationModeOptionsForAuto,
10+
PayPalPresentationModeOptionsForModal,
11+
PayPalPresentationModeOptionsForPaymentHandler,
12+
PayPalPresentationModeOptionsForPopup,
13+
PayPalPresentationModeOptionsForRedirect,
914
PayPalV6OnApproveData,
1015
PayPalV6OnShippingAddressChangeData,
1116
PayPalV6OnShippingOptionsChangeData
@@ -53,3 +58,44 @@ export type PayPalComponentV6Props = Pick<
5358
onError: (error: Error) => void;
5459
setComponentRef: (ref: ComponentMethodsRef) => void;
5560
};
61+
62+
/**
63+
* @internal
64+
*/
65+
export type PayPalButtonType = 'pay' | 'checkout' | 'buynow' | 'subscribe';
66+
67+
/**
68+
* @internal
69+
*/
70+
export type PayPalButtonClass = 'paypal-gold' | 'paypal-blue' | 'paypal-white' | 'paypal-black';
71+
72+
/**
73+
* @internal
74+
*/
75+
export type VenmoButtonClass = 'venmo-blue' | 'venmo-black';
76+
77+
/**
78+
* @internal
79+
*/
80+
export type PayPalButtonStyle = {
81+
type?: PayPalButtonType;
82+
class?: PayPalButtonClass;
83+
};
84+
85+
/**
86+
* @internal
87+
*/
88+
export type PayPalVenmoButtonStyle = {
89+
type?: PayPalButtonType;
90+
class?: VenmoButtonClass;
91+
};
92+
93+
/**
94+
* @internal
95+
*/
96+
export type PayPalPresentationModeOptions =
97+
| PayPalPresentationModeOptionsForPopup
98+
| PayPalPresentationModeOptionsForModal
99+
| PayPalPresentationModeOptionsForRedirect
100+
| PayPalPresentationModeOptionsForPaymentHandler
101+
| PayPalPresentationModeOptionsForAuto;

packages/lib/src/components/PayPal/hooks/usePayPalOneTimeSession.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { renderHook } from '@testing-library/preact-hooks';
22
import { usePayPalOneTimeSession } from './usePayPalOneTimeSession';
33
import type { PayPalOneTimePaymentSession } from '../paypal-js-types';
4-
import type { PayPalPresentationModeOptions } from '../types';
4+
import type { PayPalPresentationModeOptions } from '../components/types';
55

66
describe('usePayPalOneTimeSession', () => {
77
const presentationModeOptions: PayPalPresentationModeOptions = { presentationMode: 'auto' };

0 commit comments

Comments
 (0)