diff --git a/packages/paypal-js/types/v6/index.d.ts b/packages/paypal-js/types/v6/index.d.ts index ed4e09c1..cb08928d 100644 --- a/packages/paypal-js/types/v6/index.d.ts +++ b/packages/paypal-js/types/v6/index.d.ts @@ -47,9 +47,8 @@ export type PageTypes = | "product-listing" | "search-results"; -export type CreateInstanceOptions = { +type BaseCreateInstanceOptions = { clientMetadataId?: string; - clientToken: string; components: T; locale?: string; pageType?: PageTypes; @@ -58,6 +57,18 @@ export type CreateInstanceOptions = { testBuyerCountry?: string; }; +export type CreateInstanceOptions = + | (BaseCreateInstanceOptions & { + clientId?: never; + merchantId?: never; + clientToken: string; + }) + | (BaseCreateInstanceOptions & { + clientId: string; + merchantId?: string | string[]; + clientToken?: never; + }); + /** * Dynamically typed SDK instance based on the components array provided to createInstance. * diff --git a/packages/paypal-js/types/v6/tests/paypal-payments.test.ts b/packages/paypal-js/types/v6/tests/paypal-payments.test.ts index 3e44a4bc..de5a13c2 100644 --- a/packages/paypal-js/types/v6/tests/paypal-payments.test.ts +++ b/packages/paypal-js/types/v6/tests/paypal-payments.test.ts @@ -22,11 +22,32 @@ async function main() { throw new Error("PayPal v6 namespace missing version property"); } + // option 1 - auth with clientToken const sdkInstance = await paypal.createInstance({ clientToken: "fakeValue", components: ["paypal-payments"], }); + // option 2 - auth with clientId only + const sdkInstance2 = await paypal.createInstance({ + clientId: "fakeValue", + components: ["paypal-payments"], + }); + + // option 3 - auth with clientId and single merchantId + const sdkInstance3 = await paypal.createInstance({ + clientId: "fakeValue", + merchantId: "fakeValue", + components: ["paypal-payments"], + }); + + // option 4 - auth with clientId and many merchantIds + const sdkInstance4 = await paypal.createInstance({ + clientId: "fakeValue", + merchantId: ["fakeValue", "fakeValue2", "fakeValue3"], + components: ["paypal-payments"], + }); + const paymentMethods = await sdkInstance.findEligibleMethods({ currencyCode: "USD", });