Skip to content

Commit 769aad1

Browse files
authored
[DTPPCPSDK-2824] [DTPRP-1734] [DTPRP-1751] Limit eligible button to Paypal when new createSubscription is used (#2456)
* Limit eligible button to Paypal when new createSubscription is used * Fix lint error * Fix typecheck errors * Add FSS as a flow, clean up isFsSubscription prop * Reverting code from isFsSubscription * Reverting change from isFsSubscription * Passing more properties into eligible * Temp removal of DISPLAY_ONLY and eligible * Checking intent to determine flow
1 parent e691f89 commit 769aad1

File tree

5 files changed

+214
-1
lines changed

5 files changed

+214
-1
lines changed

Diff for: src/constants/button.js

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export const BUTTON_FLOW = {
5656
PURCHASE: ("purchase": "purchase"),
5757
BILLING_SETUP: ("billing_setup": "billing_setup"),
5858
SUBSCRIPTION_SETUP: ("subscription_setup": "subscription_setup"),
59+
FULL_STACK_SUBSCRIPTION_SETUP:
60+
("full_stack_subscription_setup": "full_stack_subscription_setup"),
5961
VAULT_WITHOUT_PURCHASE: ("vault_without_purchase": "vault_without_purchase"),
6062
};
6163

Diff for: src/funding/paypal/config.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export function getPayPalConfig(): FundingSourceConfig {
2222
BUTTON_FLOW.PURCHASE,
2323
BUTTON_FLOW.BILLING_SETUP,
2424
BUTTON_FLOW.SUBSCRIPTION_SETUP,
25+
BUTTON_FLOW.FULL_STACK_SUBSCRIPTION_SETUP,
2526
BUTTON_FLOW.VAULT_WITHOUT_PURCHASE,
2627
],
2728

Diff for: src/ui/buttons/buttons.test.js

+198
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
/* @flow */
2+
import { describe, expect } from "vitest";
3+
4+
import { Buttons } from "./buttons";
5+
6+
/* 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 */
7+
const fundingEligibility = {
8+
paypal: {
9+
eligible: true,
10+
vaultable: true,
11+
},
12+
paylater: {
13+
eligible: true,
14+
vaultable: true,
15+
products: {
16+
payIn3: {
17+
eligible: false,
18+
variant: null,
19+
},
20+
payIn4: {
21+
eligible: false,
22+
variant: null,
23+
},
24+
paylater: {
25+
eligible: true,
26+
variant: null,
27+
},
28+
},
29+
},
30+
card: {
31+
eligible: true,
32+
branded: false,
33+
installments: false,
34+
vendors: {
35+
visa: {
36+
eligible: true,
37+
vaultable: true,
38+
},
39+
mastercard: {
40+
eligible: true,
41+
vaultable: true,
42+
},
43+
amex: {
44+
eligible: true,
45+
vaultable: true,
46+
},
47+
discover: {
48+
eligible: true,
49+
vaultable: true,
50+
},
51+
hiper: {
52+
eligible: false,
53+
vaultable: false,
54+
},
55+
elo: {
56+
eligible: false,
57+
vaultable: true,
58+
},
59+
jcb: {
60+
eligible: false,
61+
vaultable: true,
62+
},
63+
maestro: {
64+
eligible: true,
65+
vaultable: true,
66+
},
67+
diners: {
68+
eligible: true,
69+
vaultable: true,
70+
},
71+
cup: {
72+
eligible: true,
73+
vaultable: true,
74+
},
75+
},
76+
guestEnabled: false,
77+
},
78+
venmo: {
79+
eligible: false,
80+
vaultable: false,
81+
},
82+
itau: {
83+
eligible: false,
84+
},
85+
credit: {
86+
eligible: false,
87+
},
88+
applepay: {
89+
eligible: true,
90+
},
91+
sepa: {
92+
eligible: false,
93+
},
94+
ideal: {
95+
eligible: false,
96+
},
97+
bancontact: {
98+
eligible: false,
99+
},
100+
giropay: {
101+
eligible: false,
102+
},
103+
eps: {
104+
eligible: false,
105+
},
106+
sofort: {
107+
eligible: false,
108+
},
109+
mybank: {
110+
eligible: false,
111+
},
112+
p24: {
113+
eligible: false,
114+
},
115+
wechatpay: {
116+
eligible: false,
117+
},
118+
payu: {
119+
eligible: false,
120+
},
121+
blik: {
122+
eligible: false,
123+
},
124+
trustly: {
125+
eligible: false,
126+
},
127+
oxxo: {
128+
eligible: false,
129+
},
130+
boleto: {
131+
eligible: false,
132+
},
133+
boletobancario: {
134+
eligible: false,
135+
},
136+
mercadopago: {
137+
eligible: false,
138+
},
139+
multibanco: {
140+
eligible: false,
141+
},
142+
satispay: {
143+
eligible: false,
144+
},
145+
paidy: {
146+
eligible: false,
147+
},
148+
};
149+
150+
describe("Smart Payment Buttons - limit button to PayPal for FSS", () => {
151+
test("should return only 1 PayPal button if flow=full_stack_subscription_setup", () => {
152+
const mockedButtonProps = {
153+
flow: "full_stack_subscription_setup",
154+
fundingEligibility,
155+
};
156+
157+
// $FlowFixMe
158+
const jsxElems = Buttons(mockedButtonProps);
159+
160+
const allButtonsTotalCount = jsxElems?.children.filter(
161+
// $FlowFixMe
162+
(elem) => elem?.component?.name === "Button"
163+
).length;
164+
165+
const hasPayPalButton =
166+
jsxElems?.children.filter(
167+
// $FlowFixMe
168+
(elem) => elem?.props?.fundingSource === "paypal"
169+
).length === 1;
170+
171+
expect(allButtonsTotalCount).toBe(1);
172+
expect(hasPayPalButton).toBe(true);
173+
});
174+
175+
test("should return 1 or more buttons if flow != full_stack_subscription_setup", () => {
176+
const mockedButtonProps = {
177+
flow: "subscription_setup",
178+
fundingEligibility,
179+
};
180+
181+
// $FlowFixMe
182+
const jsxElems = Buttons(mockedButtonProps);
183+
184+
const allButtonsTotalCount = jsxElems?.children.filter(
185+
// $FlowFixMe
186+
(elem) => elem?.component?.name === "Button"
187+
).length;
188+
189+
const hasPayPalButton =
190+
jsxElems?.children.filter(
191+
// $FlowFixMe
192+
(elem) => elem?.props?.fundingSource === "paypal"
193+
).length === 1;
194+
195+
expect(allButtonsTotalCount).toBeGreaterThanOrEqual(1);
196+
expect(hasPayPalButton).toBe(true);
197+
});
198+
});

Diff for: src/zoid/buttons/component.jsx

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
wasShopperInsightsUsed,
4545
isPayPalTrustedUrl,
4646
getSDKInitTime,
47+
getSDKToken,
4748
} from "@paypal/sdk-client/src";
4849
import {
4950
rememberFunding,
@@ -1116,6 +1117,12 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
11161117
value: getSDKMeta,
11171118
},
11181119

1120+
sdkToken: {
1121+
type: "string",
1122+
required: false,
1123+
value: getSDKToken,
1124+
},
1125+
11191126
/**
11201127
* Version of the SDK used in first render.
11211128
* This is passed to the `/smart/buttons` endpoint in order for the second render

Diff for: src/zoid/buttons/util.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ import {
2626
getNamespace,
2727
getPayPalDomain,
2828
getFirstRenderExperiments,
29+
getSDKToken,
30+
getIntent,
2931
} from "@paypal/sdk-client/src";
30-
import { FUNDING, FPTI_KEY } from "@paypal/sdk-constants/src";
32+
import { FUNDING, FPTI_KEY, INTENT } from "@paypal/sdk-constants/src";
3133
import { getRefinedFundingEligibility } from "@paypal/funding-components/src";
3234

3335
import type { Experiment as EligibilityExperiment } from "../../types";
@@ -84,6 +86,9 @@ export function determineFlow(
8486
} else if (props.createBillingAgreement) {
8587
return BUTTON_FLOW.BILLING_SETUP;
8688
} else if (props.createSubscription) {
89+
if (Boolean(getSDKToken()) && getIntent() !== INTENT.SUBSCRIPTION) {
90+
return BUTTON_FLOW.FULL_STACK_SUBSCRIPTION_SETUP;
91+
}
8792
return BUTTON_FLOW.SUBSCRIPTION_SETUP;
8893
} else {
8994
return BUTTON_FLOW.PURCHASE;

0 commit comments

Comments
 (0)