Skip to content

Commit 61aba9f

Browse files
authored
Merge pull request #690 from paypal/feature/DTPPCPSDK-3708-add-jsdoc-comments-to-types
feat: add jsdoc comments to v6 public interface types
2 parents fcb1179 + 87cea48 commit 61aba9f

File tree

5 files changed

+279
-0
lines changed

5 files changed

+279
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@paypal/paypal-js": patch
3+
---
4+
5+
feat: add jsdoc comments to v6 public interface types

packages/paypal-js/types/v6/components/paypal-legacy-billing-agreements.d.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import {
77
PresentationModeOptionsForPaymentHandler,
88
} from "./base-component";
99

10+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
11+
import { PayPalPaymentsInstance } from "./paypal-payments.d";
12+
1013
export type OnApproveDataBillingAgreements = {
1114
billingToken: string;
1215
payerId?: string;
@@ -40,9 +43,68 @@ export type PayPalLegacyBillingAgreementsSession = Omit<
4043
) => Promise<void>;
4144
};
4245

46+
/**
47+
* Interface for PayPal legacy billing agreement functionality.
48+
*
49+
* @deprecated This interface provides legacy billing agreement methods that should not be used for new implementations.
50+
* Use the newer vault setup token approach with {@link PayPalPaymentsInstance.createPayPalSavePaymentSession} instead.
51+
*
52+
* @interface PayPalLegacyBillingInstance
53+
* @description Provides methods for creating billing agreements without requiring an immediate purchase.
54+
* This legacy interface allows merchants to set up recurring payment agreements with customers
55+
* that can be used for future transactions.
56+
*
57+
* @example
58+
* ```typescript
59+
* // Legacy billing agreement setup (deprecated)
60+
* const billingAgreementWithoutPurchaseSession = sdkInstance.createPayPalBillingAgreementWithoutPurchase({
61+
* billingToken: 'your-billing-token',
62+
* onApprove: (data) => {
63+
* console.log('Billing agreement approved:', data);
64+
* },
65+
* onCancel: () => {
66+
* console.log('Billing agreement canceled');
67+
* },
68+
* onError: (data) => {
69+
* console.error('Billing agreement error:', data);
70+
* }
71+
* });
72+
*
73+
* // Start the billing agreement flow
74+
* await billingAgreementWithoutPurchaseSession.start({
75+
* mode: 'popup'
76+
* });
77+
* ```
78+
*
79+
* @see {@link PayPalPaymentsInstance.createPayPalSavePaymentSession} For the recommended modern approach
80+
*/
4381
export interface PayPalLegacyBillingInstance {
4482
/**
83+
* Creates a PayPal billing agreement session without requiring an immediate purchase.
84+
* This legacy method allows merchants to set up recurring payment agreements with customers
85+
* that can be used for future transactions.
86+
*
4587
* @deprecated This method is legacy and should not be used for new implementations.
88+
* Use the newer vault setup token approach with {@link PayPalPaymentsInstance.createPayPalSavePaymentSession} instead.
89+
*
90+
* @param {PayPalLegacyBillingAgreementsSessionOptions} paymentSessionOptions - Configuration options for the billing agreement session
91+
* @returns {PayPalLegacyBillingAgreementsSession} - A session object that can be used to start the billing agreement flow
92+
*
93+
* @example
94+
* ```typescript
95+
* const billingSession = sdkInstance.createPayPalBillingAgreementWithoutPurchase({
96+
* billingToken: 'your-billing-token',
97+
* onApprove: (data) => {
98+
* console.log('Billing agreement approved:', data);
99+
* },
100+
* onCancel: () => {
101+
* console.log('Billing agreement canceled');
102+
* },
103+
* onError: (data) => {
104+
* console.error('Billing agreement error:', data);
105+
* }
106+
* });
107+
* ```
46108
*/
47109
createPayPalBillingAgreementWithoutPurchase: (
48110
paymentSessionOptions: PayPalLegacyBillingAgreementsSessionOptions,

packages/paypal-js/types/v6/components/paypal-payments.d.ts

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,143 @@ export type PayLaterOneTimePaymentSessionOptions =
121121
export type PayPalCreditOneTimePaymentSessionOptions =
122122
PayPalOneTimePaymentSessionOptions;
123123

124+
/**
125+
* PayPal Payments Instance interface for creating and managing different types of PayPal payment sessions.
126+
*
127+
* This interface provides methods to create various PayPal payment flows including:
128+
* - One-time payments with standard PayPal
129+
* - Save payment methods for future use (vaulting)
130+
* - PayPal Pay Later financing options
131+
* - PayPal Credit transactions
132+
*
133+
* Each method returns a payment session object that can be used to initiate the corresponding
134+
* payment flow with different presentation modes (popup, modal, redirect, etc.).
135+
*
136+
* @interface PayPalPaymentsInstance
137+
*
138+
* @example
139+
* ```typescript
140+
* // Create a one-time payment session
141+
* const paypalCheckout = sdkInstance.createPayPalOneTimePaymentSession({
142+
* onApprove: (data) => console.log('Payment approved:', data),
143+
* onCancel: () => console.log('Payment canceled'),
144+
* onError: (data) => console.error('Payment error:', data)
145+
* });
146+
*
147+
* // Start the payment flow
148+
* await paypalCheckout.start({ mode: 'auto' });
149+
* ```
150+
*/
124151
export interface PayPalPaymentsInstance {
152+
/**
153+
* Creates a PayPal one-time payment session for processing single payments through PayPal.
154+
* This method allows you to configure callback functions to handle different stages
155+
* of the PayPal checkout process, including payment approval, shipping address changes,
156+
* shipping option changes, cancelation, and errors.
157+
*
158+
* @param {PayPalOneTimePaymentSessionOptions} paymentSessionOptions - Configuration options for the PayPal payment session
159+
* @returns {OneTimePaymentSession} - A session object that can be used to start the payment flow
160+
*
161+
* @example
162+
* ```typescript
163+
* const paypalSession = sdkInstance.createPayPalOneTimePaymentSession({
164+
* onApprove: (data) => {
165+
* console.log('PayPal payment approved:', data);
166+
* },
167+
* onShippingAddressChange: (data) => {
168+
* console.log('Shipping address changed:', data);
169+
* },
170+
* onShippingOptionsChange: (data) => {
171+
* console.log('Shipping options changed:', data);
172+
* },
173+
* onCancel: () => {
174+
* console.log('PayPal payment canceled');
175+
* },
176+
* onError: (data) => {
177+
* console.error('PayPal payment error:', data);
178+
* }
179+
* });
180+
* ```
181+
*/
125182
createPayPalOneTimePaymentSession: (
126183
paymentSessionOptions: PayPalOneTimePaymentSessionOptions,
127184
) => OneTimePaymentSession;
185+
/**
186+
* Creates a PayPal save payment session for storing payment methods for future use.
187+
* This method allows you to set up vault payment sessions where customers can save
188+
* their PayPal payment method for future transactions without re-entering details.
189+
*
190+
* @param {SavePaymentSessionOptions} paymentSessionOptions - Configuration options for the save payment session
191+
* @returns {SavePaymentSession} - A session object that can be used to start the vault setup flow
192+
*
193+
* @example
194+
* ```typescript
195+
* const savePaymentSession = sdkInstance.createPayPalSavePaymentSession({
196+
* vaultSetupToken: 'your-vault-setup-token',
197+
* onApprove: (data) => {
198+
* console.log('Payment method saved:', data);
199+
* },
200+
* onCancel: () => {
201+
* console.log('Save payment canceled');
202+
* },
203+
* onError: (data) => {
204+
* console.error('Save payment error:', data);
205+
* }
206+
* });
207+
* ```
208+
*/
128209
createPayPalSavePaymentSession: (
129210
paymentSessionOptions: SavePaymentSessionOptions,
130211
) => SavePaymentSession;
212+
/**
213+
* Creates a PayPal Pay Later one-time payment session for buy now, pay later transactions.
214+
* This method enables customers to make purchases and pay for them over time through
215+
* PayPal's Pay Later financing options. Available in supported countries.
216+
*
217+
* @param {PayLaterOneTimePaymentSessionOptions} paymentSessionOptions - Configuration options for the Pay Later payment session
218+
* @returns {OneTimePaymentSession} - A session object that can be used to start the Pay Later flow
219+
*
220+
* @example
221+
* ```typescript
222+
* const payLaterSession = sdkInstance.createPayLaterOneTimePaymentSession({
223+
* onApprove: (data) => {
224+
* console.log('Pay Later payment approved:', data);
225+
* },
226+
* onCancel: () => {
227+
* console.log('Pay Later payment canceled');
228+
* },
229+
* onError: (data) => {
230+
* console.error('Pay Later payment error:', data);
231+
* }
232+
* });
233+
* ```
234+
*/
131235
createPayLaterOneTimePaymentSession: (
132236
paymentSessionOptions: PayLaterOneTimePaymentSessionOptions,
133237
) => OneTimePaymentSession;
238+
/**
239+
* Creates a PayPal Credit one-time payment session for credit-based transactions.
240+
* This method enables customers to make purchases using PayPal Credit, allowing them
241+
* to pay over time with financing options. Available in supported countries.
242+
*
243+
* @param {PayPalCreditOneTimePaymentSessionOptions} paymentSessionOptions - Configuration options for the PayPal Credit payment session
244+
* @returns {OneTimePaymentSession} - A session object that can be used to start the PayPal Credit flow
245+
*
246+
* @example
247+
* ```typescript
248+
* const creditSession = sdkInstance.createPayPalCreditOneTimePaymentSession({
249+
* onApprove: (data) => {
250+
* console.log('PayPal Credit payment approved:', data);
251+
* },
252+
* onCancel: () => {
253+
* console.log('PayPal Credit payment canceled');
254+
* },
255+
* onError: (data) => {
256+
* console.error('PayPal Credit payment error:', data);
257+
* }
258+
* });
259+
* ```
260+
*/
134261
createPayPalCreditOneTimePaymentSession: (
135262
paymentSessionOptions: PayPalCreditOneTimePaymentSessionOptions,
136263
) => OneTimePaymentSession;

packages/paypal-js/types/v6/components/venmo-payments.d.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,40 @@ export type VenmoOneTimePaymentSession = Omit<BasePaymentSession, "start"> & {
2626
) => Promise<void>;
2727
};
2828

29+
/**
30+
* Interface for managing Venmo payment operations within the PayPal SDK.
31+
* This interface provides methods for creating and managing Venmo payment sessions,
32+
* allowing merchants to integrate Venmo as a payment method in their applications.
33+
*
34+
* The {@link VenmoPaymentsInstance} enables seamless integration with Venmo's payment flow,
35+
* providing a secure and user-friendly way to process payments through the Venmo platform.
36+
*
37+
* @interface VenmoPaymentsInstance
38+
*/
2939
export interface VenmoPaymentsInstance {
40+
/**
41+
* Creates a Venmo one-time payment session for processing payments through Venmo.
42+
* This method allows you to configure callback functions to handle different stages
43+
* of the Venmo checkout process, including payment approval, cancelation, and errors.
44+
*
45+
* @param {VenmoOneTimePaymentSessionOptions} paymentSessionOptions - Configuration options for the Venmo payment session
46+
* @returns {VenmoOneTimePaymentSession} - A session object that can be used to start the payment flow
47+
*
48+
* @example
49+
* ```typescript
50+
* const venmoSession = sdkInstance.createVenmoOneTimePaymentSession({
51+
* onApprove: (data) => {
52+
* console.log('Venmo payment approved:', data);
53+
* },
54+
* onCancel: () => {
55+
* console.log('Venmo payment canceled');
56+
* },
57+
* onError: (data) => {
58+
* console.error('Venmo payment error:', data);
59+
* }
60+
* });
61+
* ```
62+
*/
3063
createVenmoOneTimePaymentSession: (
3164
paymentSessionOptions: VenmoOneTimePaymentSessionOptions,
3265
) => VenmoOneTimePaymentSession;

packages/paypal-js/types/v6/index.d.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ import {
77
} from "./components/find-eligible-methods";
88

99
export interface PayPalV6Namespace {
10+
/**
11+
* Creates an SDK instance, which is the first step in an SDK integration. This instance serves as the base layer for all SDK components.
12+
*
13+
* This is an asynchronous method that initializes the PayPal SDK with the provided
14+
* client token and components.
15+
*
16+
* @param {CreateInstanceOptions} createInstanceOptions - Configuration options for creating the SDK instance
17+
* @returns {Promise<SdkInstance<Components[]>>} - A promise that resolves to an SDK instance with methods based on the specified components
18+
*
19+
* @example
20+
* ```typescript
21+
* const sdkInstance = await window.paypal.createInstance({
22+
* clientToken: "your-client-token",
23+
* components: ["paypal-payments"],
24+
* locale: "en-US",
25+
* pageType: "checkout"
26+
* });
27+
* ```
28+
*/
1029
createInstance: <T extends readonly [Components, ...Components[]]>(
1130
createInstanceOptions: CreateInstanceOptions<T>,
1231
) => Promise<SdkInstance<T>>;
@@ -81,9 +100,42 @@ export type SdkInstance<T extends readonly [Components, ...Components[]]> =
81100
: unknown);
82101

83102
export interface BaseInstance {
103+
/**
104+
* Checks eligibility for specific payment methods.
105+
*
106+
* This method verifies buyer and merchant eligibility by interacting with PayPal's
107+
* public API to determine whether payment methods (such as PayPal or Venmo) can be used.
108+
* Use this to conditionally render the appropriate payment buttons on your site.
109+
*
110+
* @param {FindEligibleMethodsOptions} findEligibleMethodsOptions - Options for checking payment method eligibility
111+
* @returns {Promise<EligiblePaymentMethodsOutput>} - A promise that resolves to payment methods eligibility information
112+
*
113+
* @example
114+
* ```typescript
115+
* const paymentMethods = await sdkInstance.findEligibleMethods();
116+
* const isPayPalEligible = paymentMethods.isEligible("paypal");
117+
* if (isPayPalEligible) {
118+
* // Render PayPal button
119+
* }
120+
* ```
121+
*/
84122
findEligibleMethods: (
85123
findEligibleMethodsOptions: FindEligibleMethodsOptions,
86124
) => Promise<EligiblePaymentMethodsOutput>;
125+
/**
126+
* Updates the locale for the SDK instance.
127+
*
128+
* This method allows you to dynamically change the locale of the SDK instance
129+
* after it has been initialized. The locale should be specified using a BCP-47 code.
130+
*
131+
* @param {string} locale - The new locale to set, specified as a BCP-47 code (e.g., "en-US", "es-ES")
132+
* @returns {void}
133+
*
134+
* @example
135+
* ```typescript
136+
* sdkInstance.updateLocale("es-ES");
137+
* ```
138+
*/
87139
updateLocale: (locale: string) => void;
88140
}
89141

0 commit comments

Comments
 (0)