feat(paypal-js): add v6 Local Payment Methods (LPM) types#992
feat(paypal-js): add v6 Local Payment Methods (LPM) types#992Mathanjeevika wants to merge 3 commits into
Conversation
Adds LPMPaymentsInstance and the LPMComponents union to the v6 SDK types, and wires LPM component names into SdkInstance/Components/ CreateInstanceOptions so createInstance surfaces LPM methods. Split out of PR paypal#926 per review (paypal-js portion). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 51755ca The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| await loadCoreSdkScript({} as any); |
There was a problem hiding this comment.
Does this need to be added? Same with the as any below. I don't think we need to cast this in our tests.
|
|
||
| export interface LoadCoreSdkScriptOptions extends CoreSdkScriptDataAttributes { | ||
| environment: "production" | "sandbox"; | ||
| environment?: "production" | "sandbox"; |
There was a problem hiding this comment.
This is accidentally reverting a prior change.
| environment?: "production" | "sandbox"; | |
| environment: "production" | "sandbox"; |
| | "ovo-payments" | ||
| | "paysera-payments" | ||
| | "skrill-payments" | ||
| | "thailandbanks-payments" |
There was a problem hiding this comment.
slightly different component name, which is odd b/c other component names do not have the hyphen indonesiabanks-payment for example.
| | "thailandbanks-payments" | |
| | "thailand-banks-payments" |
| export type LPMOneTimePaymentSessionPromise = Promise<{ | ||
| orderId: string; | ||
| phone?: { countryCode: string; nationalNumber: string }; | ||
| billingAddress?: { | ||
| addressLine1: string; | ||
| addressLine2?: string; | ||
| adminArea1: string; | ||
| adminArea2?: string; | ||
| postalCode: string; | ||
| countryCode: string; | ||
| }; | ||
| taxInfo?: { taxId: string; taxIdType: string }; | ||
| expiryDate?: string; | ||
| }>; |
There was a problem hiding this comment.
Can we re-use the types that are defined above? Maybe this type LPMSessionFields could be re-used more broadly?
export type LPMOneTimePaymentSessionPromise = Promise<{
orderId: string;
phone?: LPMSessionFieldPhone;
billingAddress?: LPMSessionFieldBillingAddress;
taxInfo?: LPMSessionFieldTaxInfo;
expiryDate?: string;
}>;
| | "createLithuaniaBanksOneTimePaymentSession" | ||
| | "createJeniuspayOneTimePaymentSession"; | ||
|
|
||
| export type LPMPaymentsInstance = { |
There was a problem hiding this comment.
Can you add a JS Doc comment that is in line with the other instance interfaces/types? VenmoPaymentsInstance is a good example.
| options: LPMStartOptions, | ||
| paymentSessionPromise?: LPMOneTimePaymentSessionPromise, | ||
| ) => Promise<void>; | ||
| createPaymentFields: (options: { type: string; value?: string }) => HTMLElement; |
There was a problem hiding this comment.
I see createPaymentFields option typed more tightly internally. Is there a reason to leave the style key off of the options here? Also should the type be more tightly typed to the actual values "email" | "name" | "tax_id" | "tax_id_type" ?
- Replace 'as any' casts with '@ts-expect-error' in index.test.ts - Make 'environment' required again in LoadCoreSdkScriptOptions - Reuse LPMSessionField* types in LPMOneTimePaymentSessionPromise - Rename 'thailandbanks-payments' -> 'thailand-banks-payments' - Add JSDoc comment for LPMPaymentsInstance - Tighten createPaymentFields: narrow type union, add style key Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| * Extends the presentation-mode options with optional merchant-collected | ||
| * session fields (phone, billingAddress, taxInfo, etc.) required by some LPMs. | ||
| */ | ||
| export type LPMStartOptions = LPMPresentationModeOptions & LPMSessionFields; |
There was a problem hiding this comment.
Why are the LPM session fields being added to the LPMStartOptions? Looking at the internal code, the first argument for .start is options and can include either presentationMode or fullPageOverlay, why is options being expanded to include these other properties?
| phone?: LPMSessionFieldPhone; | ||
| billingAddress?: LPMSessionFieldBillingAddress; | ||
| taxInfo?: LPMSessionFieldTaxInfo; | ||
| expiryDate?: string; |
There was a problem hiding this comment.
Looking more closely at the internal code it looks like expiryDate is shaped like this
expiryDate: {expiry_date: string} <-- this is the shape of ExpiryDate type
| billingAddress?: LPMSessionFieldBillingAddress; | ||
| taxInfo?: LPMSessionFieldTaxInfo; | ||
| expiryDate?: string; | ||
| }>; |
There was a problem hiding this comment.
It looks like this is also missing date of birth and number of installments fields, shouldn't we just re-use LPMSessionFields here?
Summary
LPMComponents,LPMSessionMethodName,LPMOneTimePaymentSession, and related types inpackages/paypal-js/types/v6/components/lpm-payments.d.ts.packages/paypal-js/types/v6/index.d.ts.Context
This is PR 1 of 3 split out from #926 per review feedback requesting the original monolithic PR be broken up. This PR contains only the
paypal-jstype declarations, with no runtime code changes. It's a foundational dependency for the React wrapper split out in a follow-up PR.Test plan
npm run typecheckpassespackages/paypal-js/src/v6/index.test.tsupdated and passing.changeset/lpm-paypal-js-types.md)