Skip to content

Commit

Permalink
Add validation for SDK token when createSubscription is being passed (#…
Browse files Browse the repository at this point in the history
…2450)

* Add component support for a new createSubscription callback to the CardFields component

* Add validation for SDK token
  • Loading branch information
9zees authored Nov 5, 2024
1 parent e4bb4c2 commit f0483a1
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/zoid/card-fields/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
type FundingEligibilityType,
} from "@paypal/sdk-constants/src";

import { getSessionID } from "../../lib";
import { getSessionID, ValidationError } from "../../lib";

import { CardPrerender } from "./prerender";

Expand Down Expand Up @@ -111,6 +111,7 @@ type CardFieldsProps = {|
hcfSessionID: string,
partnerAttributionID: string,
merchantID: $ReadOnlyArray<string>,
sdkToken?: string,
installments?: {|
onInstallmentsRequested: () =>
| InstallmentsConfiguration
Expand Down Expand Up @@ -251,7 +252,17 @@ export const getCardFieldsComponent: () => CardFieldsComponent = memoize(
createSubscription: {
type: "function",
required: false,
value: ({ props }) => props.parent.props.createSubscription,
value: ({ props }) => {
if (
props.parent.props.createSubscription &&
!props.parent.props.sdkToken
) {
throw new ValidationError(
`SDK Token must be passed in for createSubscription`
);
}
return props.parent.props.createSubscription;
},
},
}),

Expand Down Expand Up @@ -587,6 +598,14 @@ export const getCardFieldsComponent: () => CardFieldsComponent = memoize(
createSubscription: {
type: "function",
required: false,
value: ({ props }) => {
if (props.createSubscription && !props.sdkToken) {
throw new ValidationError(
`SDK Token must be passed in for createSubscription`
);
}
return props.createSubscription;
},
},
}),

Expand Down

0 comments on commit f0483a1

Please sign in to comment.