Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DTPPCPSDK-2824] [DTPRP-1734] [DTPRP-1751] Limit eligible button to Paypal when new createSubscription is used #2456

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
22 changes: 14 additions & 8 deletions src/ui/buttons/buttons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function validateButtonProps(props: ButtonPropsInputs) {
}

export function Buttons(props: ButtonsProps): ElementNode {
const { onClick = noop } = props;
const { onClick = noop, isFsSubscription } = props;
const {
applePaySupport,
buyerCountry,
Expand Down Expand Up @@ -190,7 +190,6 @@ export function Buttons(props: ButtonsProps): ElementNode {
experiment,
displayOnly,
});
const multiple = fundingSources.length > 1;

if (!fundingSources.length) {
throw new ValidationError(
Expand All @@ -209,13 +208,20 @@ export function Buttons(props: ButtonsProps): ElementNode {
];
}

const isAPM = fundingSources.some((src) => {
// Set the value of the FINAL fundingSource we want to use
const finalFundingSources = isFsSubscription
? fundingSources.filter((src) => src === FUNDING.PAYPAL)
: fundingSources;

const multiple = finalFundingSources.length > 1;

const isAPM = finalFundingSources.some((src) => {
return APM_LIST.includes(src);
});

const instruments = getWalletInstruments({
wallet,
fundingSources,
fundingSources: finalFundingSources,
layout,
hasShippingCallback,
});
Expand All @@ -234,7 +240,7 @@ export function Buttons(props: ButtonsProps): ElementNode {
!fundingSource &&
!message;

const showPoweredBy = calculateShowPoweredBy(layout, fundingSources);
const showPoweredBy = calculateShowPoweredBy(layout, finalFundingSources);

return (
<div
Expand All @@ -260,7 +266,7 @@ export function Buttons(props: ButtonsProps): ElementNode {
<Message markup={messageMarkup} position={message.position} />
) : null}

{fundingSources.map((source, i) => (
{finalFundingSources.map((source, i) => (
<Button
content={content}
i={index(i)}
Expand Down Expand Up @@ -293,7 +299,7 @@ export function Buttons(props: ButtonsProps): ElementNode {

{showTagline ? (
<TagLine
fundingSource={fundingSources[0]}
fundingSource={finalFundingSources[0]}
style={style}
locale={locale}
multiple={multiple}
Expand All @@ -302,7 +308,7 @@ export function Buttons(props: ButtonsProps): ElementNode {
/>
) : null}

{fundingSources.indexOf(FUNDING.CARD) !== -1 ? (
{finalFundingSources.indexOf(FUNDING.CARD) !== -1 ? (
<div id="card-fields-container" class="card-fields-container" />
) : null}

Expand Down
202 changes: 202 additions & 0 deletions src/ui/buttons/buttons.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/* @flow */
import { describe, expect } from "vitest";

import { Buttons } from "./buttons";

/* NOTE: We want to give a "complete" fundingEligibility object since this is what determines how many buttons there will be to start with, before we try to limit the buttons */
const fundingEligibility = {
paypal: {
eligible: true,
vaultable: true,
},
paylater: {
eligible: true,
vaultable: true,
products: {
payIn3: {
eligible: false,
variant: null,
},
payIn4: {
eligible: false,
variant: null,
},
paylater: {
eligible: true,
variant: null,
},
},
},
card: {
eligible: true,
branded: false,
installments: false,
vendors: {
visa: {
eligible: true,
vaultable: true,
},
mastercard: {
eligible: true,
vaultable: true,
},
amex: {
eligible: true,
vaultable: true,
},
discover: {
eligible: true,
vaultable: true,
},
hiper: {
eligible: false,
vaultable: false,
},
elo: {
eligible: false,
vaultable: true,
},
jcb: {
eligible: false,
vaultable: true,
},
maestro: {
eligible: true,
vaultable: true,
},
diners: {
eligible: true,
vaultable: true,
},
cup: {
eligible: true,
vaultable: true,
},
},
guestEnabled: false,
},
venmo: {
eligible: false,
vaultable: false,
},
itau: {
eligible: false,
},
credit: {
eligible: false,
},
applepay: {
eligible: true,
},
sepa: {
eligible: false,
},
ideal: {
eligible: false,
},
bancontact: {
eligible: false,
},
giropay: {
eligible: false,
},
eps: {
eligible: false,
},
sofort: {
eligible: false,
},
mybank: {
eligible: false,
},
p24: {
eligible: false,
},
wechatpay: {
eligible: false,
},
payu: {
eligible: false,
},
blik: {
eligible: false,
},
trustly: {
eligible: false,
},
oxxo: {
eligible: false,
},
boleto: {
eligible: false,
},
boletobancario: {
eligible: false,
},
mercadopago: {
eligible: false,
},
multibanco: {
eligible: false,
},
satispay: {
eligible: false,
},
paidy: {
eligible: false,
},
};

describe("Smart Payment Buttons - limit button to PayPal for FSS", () => {
test("should return only 1 PayPal button if isFsSubscription=true", () => {
const mockedButtonProps = {
// isFsSubscription is the determinant of how many buttons get shown
isFsSubscription: true,
flow: "subscription_setup",
fundingEligibility,
};

// $FlowFixMe
const jsxElems = Buttons(mockedButtonProps);

const allButtonsTotalCount = jsxElems?.children.filter(
// $FlowFixMe
(elem) => elem?.component?.name === "Button"
).length;

const hasPayPalButton =
jsxElems?.children.filter(
// $FlowFixMe
(elem) => elem?.props?.fundingSource === "paypal"
).length === 1;

expect(allButtonsTotalCount).toBe(1);
expect(hasPayPalButton).toBe(true);
});

test("should return 1 or more buttons if not isFsSubscription", () => {
const mockedButtonProps = {
// isFsSubscription is the determinant of how many buttons get shown
isFsSubscription: false,
flow: "subscription_setup",
fundingEligibility,
};

// $FlowFixMe
const jsxElems = Buttons(mockedButtonProps);

const allButtonsTotalCount = jsxElems?.children.filter(
// $FlowFixMe
(elem) => elem?.component?.name === "Button"
).length;

const hasPayPalButton =
jsxElems?.children.filter(
// $FlowFixMe
(elem) => elem?.props?.fundingSource === "paypal"
).length === 1;

expect(allButtonsTotalCount).toBeGreaterThanOrEqual(1);
expect(hasPayPalButton).toBe(true);
});
});
1 change: 1 addition & 0 deletions src/ui/buttons/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ export type ButtonPropsInputs = {
message?: ButtonMessageInputs | void,
messageMarkup?: string | void,
renderedButtons: $ReadOnlyArray<$Values<typeof FUNDING>>,
isFsSubscription: boolean,
};

export const DEFAULT_STYLE = {
Expand Down
17 changes: 17 additions & 0 deletions src/zoid/buttons/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
getSDKAttribute,
getJsSdkLibrary,
wasShopperInsightsUsed,
getSDKToken,
} from "@paypal/sdk-client/src";
import {
rememberFunding,
Expand Down Expand Up @@ -613,6 +614,16 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
value: getIntent,
},

isFsSubscription: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@9zees 9zees Jan 27, 2025

Choose a reason for hiding this comment

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

@ravishekhar @imbrian What new flow should I name it as?

Do we want a way to distinguish the FSS and NGS here?
image

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to differentiate is from existing subscriptions. full_stack_subscription_setup?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do that @imbrian

Copy link
Contributor Author

@9zees 9zees Jan 27, 2025

Choose a reason for hiding this comment

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

@ravishekhar @imbrian I'm noticing that when we use flow, we have to update the config for each funding each time. I can submit this code, but wanted to check once if this is the expected behavior. Thank you.

Right now since we're only enabling the PayPal button, I'm only adding this in the PayPal config:

https://github.com/paypal/paypal-checkout-components/blob/main/src/funding/paypal/config.jsx#L21-L26

type: "boolean",
queryParam: true,
required: false,
value: ({ props }) =>
props.createSubscription &&
Boolean(getSDKToken()) &&
props.intent !== "subscription",
},

jsSdkLibrary: {
type: "string",
queryParam: true,
Expand Down Expand Up @@ -933,6 +944,12 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
value: getSDKMeta,
},

sdkToken: {
type: "string",
required: false,
value: getSDKToken,
},

/**
* Version of the SDK used in first render.
* This is passed to the `/smart/buttons` endpoint in order for the second render
Expand Down
Loading