Skip to content

Support Venmo vault without purchase with a feature flag #2403

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

Merged
merged 11 commits into from
Jun 12, 2024
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
"readmeFilename": "README.md",
"devDependencies": {
"@bunchtogether/vite-plugin-flow": "^1.0.2",
"@krakenjs/grumbler-scripts": "^8.1.5",
"@krakenjs/eslint-config-grumbler": "8.1.3",
"@krakenjs/grumbler-scripts": "^8.1.5",
"@krakenjs/sync-browser-mocks": "^3.0.0",
"@percy/cli": "1.28.5",
"@percy/playwright": "^1.0.4",
Expand Down Expand Up @@ -114,7 +114,7 @@
"@paypal/common-components": "^1.0.35",
"@paypal/connect-loader-component": "1.1.1",
"@paypal/funding-components": "^1.0.31",
"@paypal/sdk-client": "^4.0.184",
"@paypal/sdk-client": "^4.0.191",
"@paypal/sdk-constants": "^1.0.146",
"@paypal/sdk-logos": "^2.2.6"
},
Expand Down
10 changes: 10 additions & 0 deletions src/funding/card/config.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { describe, test, expect } from "vitest";
import { FUNDING, COMPONENTS } from "@paypal/sdk-constants/src";

import { BUTTON_FLOW } from "../../constants";

import { getCardConfig } from "./config";

const getEligibility = ({
Expand Down Expand Up @@ -43,6 +45,7 @@ describe("card eligibility", () => {
fundingEligibility: getEligibility({ eligible: false }),
// $FlowIssue
wallet: getWallet(),
flow: BUTTON_FLOW.PURCHASE,
})
).toEqual(false);
});
Expand All @@ -54,6 +57,7 @@ describe("card eligibility", () => {
fundingSource: FUNDING.PAYPAL,
fundingEligibility: getEligibility({ branded: true }),
wallet: getWallet(),
flow: BUTTON_FLOW.PURCHASE,
})
).toEqual(true);
});
Expand All @@ -65,6 +69,7 @@ describe("card eligibility", () => {
fundingSource: FUNDING.CARD,
fundingEligibility: getEligibility(),
wallet: getWallet(),
flow: BUTTON_FLOW.PURCHASE,
})
).toEqual(true);
});
Expand All @@ -77,6 +82,7 @@ describe("card eligibility", () => {
fundingSource: FUNDING.PAYPAL,
fundingEligibility: getEligibility(),
wallet: getWallet(),
flow: BUTTON_FLOW.PURCHASE,
})
).toEqual(false);
});
Expand All @@ -91,6 +97,7 @@ describe("card eligibility", () => {
wallet: getWallet({
card: ["some instrument"],
}),
flow: BUTTON_FLOW.PURCHASE,
})
).toEqual(false);
});
Expand All @@ -104,6 +111,7 @@ describe("card eligibility", () => {
wallet: getWallet({
card: ["some instrument"],
}),
flow: BUTTON_FLOW.PURCHASE,
})
).toEqual(true);
});
Expand All @@ -115,6 +123,7 @@ describe("card eligibility", () => {
fundingSource: FUNDING.PAYPAL,
fundingEligibility: getEligibility(),
wallet: getWallet(),
flow: BUTTON_FLOW.PURCHASE,
})
).toEqual(false);
});
Expand All @@ -126,6 +135,7 @@ describe("card eligibility", () => {
fundingSource: FUNDING.PAYPAL,
fundingEligibility: getEligibility(),
wallet: getWallet(),
flow: BUTTON_FLOW.PURCHASE,
})
).toEqual(true);
});
Expand Down
1 change: 1 addition & 0 deletions src/funding/common.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export type FundingSourceConfig = {|
eligible?: ({|
components: $ReadOnlyArray<$Values<typeof COMPONENTS>>,
experiment?: ?Experiment,
flow: $Values<typeof BUTTON_FLOW>,
enableFunding?: $ReadOnlyArray<?$Values<typeof FUNDING>>,
fundingEligibility: FundingEligibilityType,
fundingSource: ?$Values<typeof FUNDING>,
Expand Down
1 change: 1 addition & 0 deletions src/funding/funding.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export function isFundingEligible(
enableFunding,
components,
experiment,
flow,
fundingSource,
fundingEligibility,
layout,
Expand Down
13 changes: 11 additions & 2 deletions src/funding/venmo/config.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "@paypal/sdk-logos/src";
import { DISPLAY_ONLY_VALUES, PLATFORM } from "@paypal/sdk-constants/src";

import { BUTTON_COLOR, BUTTON_LAYOUT } from "../../constants";
import { BUTTON_COLOR, BUTTON_LAYOUT, BUTTON_FLOW } from "../../constants";
import { DEFAULT_FUNDING_CONFIG, type FundingSourceConfig } from "../common";

import { WalletLabel, Label } from "./template";
Expand All @@ -17,9 +17,11 @@ export function getVenmoConfig(): FundingSourceConfig {
return {
...DEFAULT_FUNDING_CONFIG,

flows: [BUTTON_FLOW.PURCHASE, BUTTON_FLOW.VAULT_WITHOUT_PURCHASE],

layouts: [BUTTON_LAYOUT.HORIZONTAL, BUTTON_LAYOUT.VERTICAL],

eligible: ({ experiment, shippingChange, displayOnly }) => {
eligible: ({ experiment, shippingChange, displayOnly, flow }) => {
if (experiment && experiment.enableVenmo === false) {
return false;
}
Expand All @@ -39,6 +41,13 @@ export function getVenmoConfig(): FundingSourceConfig {
return false;
}

if (
flow === BUTTON_FLOW.VAULT_WITHOUT_PURCHASE &&
experiment?.venmoVaultWithoutPurchase !== true
) {
return false;
}

return true;
},

Expand Down
24 changes: 24 additions & 0 deletions src/funding/venmo/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import { describe, expect } from "vitest";

import { BUTTON_FLOW } from "../../constants";

import { getVenmoConfig } from "./config";

describe("Venmo eligibility", () => {
Expand All @@ -10,6 +12,7 @@ describe("Venmo eligibility", () => {
components: ["buttons"],
fundingEligibility: {},
wallet: expect.any,
flow: BUTTON_FLOW.PURCHASE,
};
const venmoConfig = getVenmoConfig();

Expand Down Expand Up @@ -46,4 +49,25 @@ describe("Venmo eligibility", () => {

expect(isVenmoEligible).toEqual(true);
});

test("should not be eligible if flow is VAULT_WITHOUT_PURCHASE and venmoVaultWithoutPurchase is false", () => {
const isVenmoEligible = venmoConfig.eligible?.({
...baseEligibilityProps,
flow: BUTTON_FLOW.VAULT_WITHOUT_PURCHASE,
});

expect(isVenmoEligible).toEqual(false);
});

test("should be eligible if flow is VAULT_WITHOUT_PURCHASE and venmoVaultWithoutPurchase is true", () => {
const isVenmoEligible = venmoConfig.eligible?.({
...baseEligibilityProps,
flow: BUTTON_FLOW.VAULT_WITHOUT_PURCHASE,
experiment: {
venmoVaultWithoutPurchase: true,
},
});

expect(isVenmoEligible).toEqual(true);
});
});
2 changes: 2 additions & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export type Experiment = {|
enableVenmo?: boolean,
disablePaylater?: boolean,
venmoWebEnabled?: boolean,
// first render experiments
venmoVaultWithoutPurchase?: boolean,
|};

export type Requires = {|
Expand Down
12 changes: 7 additions & 5 deletions src/zoid/buttons/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
getVersion,
getDisableSetCookie,
getExperimentation,
getFirstRenderExperiments,
getSDKAttribute,
getJsSdkLibrary,
} from "@paypal/sdk-client/src";
Expand Down Expand Up @@ -472,12 +473,13 @@ export const getButtonsComponent: () => ButtonsComponent = memoize(() => {
experiment: {
type: "object",
queryParam: true,
value: () => {
const experiments = getButtonExperiments();
return experiments;
},
value: () => ({
...getButtonExperiments(),
...getFirstRenderExperiments(),
}),
},

// TODO first-render-experiment-cleanup
// verify if this is needed/used now that were putting the first render experiments in experiment param above
experimentation: {
type: "object",
queryParam: true,
Expand Down
Loading