Skip to content

Commit 00fc67e

Browse files
authored
Paypal: Add prop for blocking paypal button (#3597)
* feat(paypal): add prop for blocking paypal button * feat(paypal): add changeset for block paypal button prop
1 parent 011439b commit 00fc67e

5 files changed

Lines changed: 24 additions & 2 deletions

File tree

.changeset/heavy-falcons-tickle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@adyen/adyen-web': minor
3+
---
4+
5+
Add prop to enable blocking paypal button

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ describe('PaypalButtons', () => {
6565
expect(renderedButtons).toEqual(['paypal', 'credit', 'pay-later', 'venmo']);
6666
});
6767

68+
test('should not call paypalRef.Buttons().render for blocked paypal button', () => {
69+
jest.clearAllMocks();
70+
const buttonPropsMock = mock<PayPalButtonsProps>({
71+
paypalRef: paypalRefMock
72+
});
73+
renderWithCoreProvider(<PaypalButtons {...buttonPropsMock} blockPayPalButton />);
74+
// eslint-disable-next-line testing-library/render-result-naming-convention
75+
const renderedButtons = getRenderedButtons(paypalRenderMock.mock.calls);
76+
expect(renderedButtons).toEqual(['credit', 'pay-later', 'venmo']);
77+
});
78+
6879
test('should not call paypalRef.Buttons().render for blocked paypal credit button', () => {
6980
jest.clearAllMocks();
7081
const buttonPropsMock = mock<PayPalButtonsProps>({

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ export default function PaypalButtons({
5454
useEffect(() => {
5555
const { PAYPAL, CREDIT, PAYLATER, VENMO } = paypalRef.FUNDING;
5656

57-
createButton(PAYPAL, paypalButtonRef);
58-
57+
if (!props.blockPayPalButton) createButton(PAYPAL, paypalButtonRef);
5958
if (!props.blockPayPalCreditButton) createButton(CREDIT, creditButtonRef);
6059
if (!props.blockPayPalPayLaterButton) createButton(PAYLATER, payLaterButtonRef);
6160
if (!props.blockPayPalVenmoButton) createButton(VENMO, venmoButtonRef);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const defaultProps: Partial<PayPalConfiguration> = {
99
style: {
1010
height: 50 // The height of the buttons is set to 50px to align with the default size of our Pay buttons.
1111
},
12+
blockPayPalButton: false,
1213
blockPayPalCreditButton: false,
1314
blockPayPalPayLaterButton: false,
1415
blockPayPalVenmoButton: false

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ export interface PayPalConfiguration extends UIElementProps {
2929
*/
3030
expressPage?: 'cart' | 'minicart' | 'pdp' | 'checkout';
3131

32+
/**
33+
* Set to true to force the UI to not render PayPal button
34+
* @default false
35+
*/
36+
blockPayPalButton?: boolean;
37+
3238
/**
3339
* Set to true to force the UI to not render PayPal Credit button
3440
* @default false

0 commit comments

Comments
 (0)