From f0483a1c2aef9a84539b72696dd65225c1b43376 Mon Sep 17 00:00:00 2001 From: Maria Chin Date: Tue, 5 Nov 2024 14:05:28 -0800 Subject: [PATCH] Add validation for SDK token when createSubscription is being passed (#2450) * Add component support for a new createSubscription callback to the CardFields component * Add validation for SDK token --- src/zoid/card-fields/component.jsx | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/zoid/card-fields/component.jsx b/src/zoid/card-fields/component.jsx index 40a33828e..62b418a01 100644 --- a/src/zoid/card-fields/component.jsx +++ b/src/zoid/card-fields/component.jsx @@ -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"; @@ -111,6 +111,7 @@ type CardFieldsProps = {| hcfSessionID: string, partnerAttributionID: string, merchantID: $ReadOnlyArray, + sdkToken?: string, installments?: {| onInstallmentsRequested: () => | InstallmentsConfiguration @@ -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; + }, }, }), @@ -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; + }, }, }),