Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/paypal-js/types/v6/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ export type PageTypes =
| "product-listing"
| "search-results";

export type CreateInstanceOptions<T extends readonly Components[]> = {
type BaseCreateInstanceOptions<T extends readonly Components[]> = {
clientMetadataId?: string;
clientToken: string;
components: T;
locale?: string;
pageType?: PageTypes;
Expand All @@ -58,6 +57,18 @@ export type CreateInstanceOptions<T extends readonly Components[]> = {
testBuyerCountry?: string;
};

export type CreateInstanceOptions<T extends readonly Components[]> =
| (BaseCreateInstanceOptions<T> & {
clientId?: never;
merchantId?: never;
clientToken: string;
})
| (BaseCreateInstanceOptions<T> & {
clientId: string;
merchantId?: string | string[];
clientToken?: never;
});

/**
* Dynamically typed SDK instance based on the components array provided to createInstance.
*
Expand Down
21 changes: 21 additions & 0 deletions packages/paypal-js/types/v6/tests/paypal-payments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
Expand Down
Loading