@easypayment/medusa-paypal-ui 1.2.8 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +82 -0
- package/LICENSE +21 -1
- package/README.md +8 -2
- package/dist/index.cjs +605 -676
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +101 -28
- package/dist/index.d.ts +101 -28
- package/dist/index.mjs +601 -676
- package/dist/index.mjs.map +1 -1
- package/dist/order.cjs +11 -8
- package/dist/order.cjs.map +1 -1
- package/dist/order.d.cts +1 -1
- package/dist/order.d.ts +1 -1
- package/dist/order.mjs +10 -8
- package/dist/order.mjs.map +1 -1
- package/package.json +43 -4
- package/src/adapters/MedusaNextPayPalAdapter.tsx +48 -10
- package/src/client/config-cache.ts +96 -0
- package/src/client/http.ts +24 -5
- package/src/client/paypal.ts +28 -6
- package/src/components/PayPalAdvancedCard.tsx +88 -214
- package/src/components/PayPalPaymentSection.tsx +17 -6
- package/src/components/PayPalProvider.tsx +4 -1
- package/src/components/PayPalSmartButtons.tsx +92 -224
- package/src/components/internal/ui.tsx +221 -0
- package/src/hooks/usePayPalConfig.ts +43 -32
- package/src/hooks/usePayPalPaymentMethods.ts +59 -54
- package/src/index.ts +4 -0
- package/src/order.ts +16 -8
- package/src/utils/processing-overlay.ts +25 -21
package/dist/index.d.cts
CHANGED
|
@@ -53,6 +53,34 @@ type HttpOptions = {
|
|
|
53
53
|
* credentialed requests against a wildcard CORS origin outright.
|
|
54
54
|
*/
|
|
55
55
|
credentials?: RequestCredentials;
|
|
56
|
+
/**
|
|
57
|
+
* Per-request timeout in milliseconds. Covers the full request including
|
|
58
|
+
* reading the body. Defaults to 30 000. A caller-supplied AbortSignal
|
|
59
|
+
* composes with (never replaces) this timeout.
|
|
60
|
+
*/
|
|
61
|
+
timeoutMs?: number;
|
|
62
|
+
};
|
|
63
|
+
type RequestOptions = {
|
|
64
|
+
/**
|
|
65
|
+
* Number of extra attempts on transient failures (network error, timeout,
|
|
66
|
+
* HTTP 429/5xx). Only use for idempotent calls — the PayPal capture/complete
|
|
67
|
+
* endpoints are idempotent server-side, so a retried request after a network
|
|
68
|
+
* blip re-uses the existing result instead of duplicating work. Default 0.
|
|
69
|
+
*/
|
|
70
|
+
retries?: number;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Error thrown for HTTP-level failures (non-2xx responses and malformed
|
|
74
|
+
* response bodies). `status` carries the HTTP status code so callers can
|
|
75
|
+
* branch on it (e.g. 403 → "PayPal is disabled") instead of matching
|
|
76
|
+
* localized/backend-authored message text.
|
|
77
|
+
*/
|
|
78
|
+
declare class HttpError extends Error {
|
|
79
|
+
status: number;
|
|
80
|
+
constructor(message: string, status: number);
|
|
81
|
+
}
|
|
82
|
+
declare function createHttpClient(opts: HttpOptions): {
|
|
83
|
+
request: <T>(path: string, init?: RequestInit, reqOpts?: RequestOptions) => Promise<T>;
|
|
56
84
|
};
|
|
57
85
|
|
|
58
86
|
/**
|
|
@@ -66,26 +94,64 @@ type HttpOptions = {
|
|
|
66
94
|
* stored-order staleness check, not by this key.
|
|
67
95
|
*/
|
|
68
96
|
declare function generateIdempotencyKey(): string;
|
|
69
|
-
|
|
97
|
+
type MarkPaymentCompleteOptions = {
|
|
98
|
+
publishableApiKey?: string;
|
|
99
|
+
credentials?: RequestCredentials;
|
|
100
|
+
timeoutMs?: number;
|
|
101
|
+
signal?: AbortSignal;
|
|
102
|
+
};
|
|
103
|
+
declare function markPaymentComplete(baseUrl: string, cartId: string,
|
|
104
|
+
/** Publishable API key string (legacy signature) or an options object. */
|
|
105
|
+
options?: string | MarkPaymentCompleteOptions): Promise<Record<string, unknown>>;
|
|
70
106
|
declare function createPayPalStoreApi(opts: HttpOptions): {
|
|
71
107
|
getConfig(cartId?: string, signal?: AbortSignal): Promise<PayPalConfig>;
|
|
72
|
-
getSettings(): Promise<PayPalSettingsResponse>;
|
|
73
|
-
createOrder(cartId: string, isCardPayment?: boolean): Promise<{
|
|
108
|
+
getSettings(signal?: AbortSignal): Promise<PayPalSettingsResponse>;
|
|
109
|
+
createOrder(cartId: string, isCardPayment?: boolean, signal?: AbortSignal): Promise<{
|
|
74
110
|
id: string;
|
|
75
111
|
}>;
|
|
76
|
-
captureOrder(cartId: string, orderId: string): Promise<Record<string, unknown>>;
|
|
112
|
+
captureOrder(cartId: string, orderId: string, signal?: AbortSignal): Promise<Record<string, unknown>>;
|
|
77
113
|
};
|
|
78
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Drop cached configs — all of them, or only the entries for one cart.
|
|
117
|
+
* Call after anything that changes what the config endpoint would return
|
|
118
|
+
* (region/currency switch, plugin settings change).
|
|
119
|
+
*/
|
|
120
|
+
declare function invalidatePayPalConfigCache(cartId?: string): void;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Provider ids registered by `@easypayment/medusa-payment-paypal`.
|
|
124
|
+
*
|
|
125
|
+
* Single source of truth — `PayPalPaymentSection`, `MedusaNextPayPalAdapter`,
|
|
126
|
+
* and the server-safe `order` entrypoint all re-export from here so the ids
|
|
127
|
+
* can never drift between entrypoints.
|
|
128
|
+
*/
|
|
129
|
+
declare const PAYPAL_WALLET_PROVIDER_ID: "pp_paypal_paypal";
|
|
130
|
+
declare const PAYPAL_CARD_PROVIDER_ID: "pp_paypal_card_paypal_card";
|
|
131
|
+
declare const PAYPAL_PROVIDER_IDS: readonly ["pp_paypal_paypal", "pp_paypal_card_paypal_card"];
|
|
132
|
+
type PayPalProviderId = (typeof PAYPAL_PROVIDER_IDS)[number];
|
|
133
|
+
/** True when the provider id belongs to this PayPal plugin. */
|
|
134
|
+
declare function isPayPalProviderId(providerId?: string | null): providerId is PayPalProviderId;
|
|
135
|
+
|
|
79
136
|
type Args$1 = {
|
|
80
137
|
baseUrl: string;
|
|
81
138
|
publishableApiKey?: string;
|
|
82
139
|
cartId?: string;
|
|
140
|
+
/**
|
|
141
|
+
* The cart's current currency code (e.g. "usd"). Optional, but recommended:
|
|
142
|
+
* when provided it becomes part of the cache key, so a region/currency
|
|
143
|
+
* switch on the same cart refetches the config instead of serving a stale
|
|
144
|
+
* one for up to 5 minutes.
|
|
145
|
+
*/
|
|
146
|
+
currencyCode?: string;
|
|
147
|
+
credentials?: RequestCredentials;
|
|
83
148
|
enabled?: boolean;
|
|
84
149
|
};
|
|
85
|
-
declare function usePayPalConfig({ baseUrl, publishableApiKey, cartId, enabled, }: Args$1): {
|
|
150
|
+
declare function usePayPalConfig({ baseUrl, publishableApiKey, cartId, currencyCode, credentials, enabled, }: Args$1): {
|
|
86
151
|
config: PayPalConfig | null;
|
|
87
152
|
loading: boolean;
|
|
88
153
|
error: string | null;
|
|
154
|
+
retry: () => void;
|
|
89
155
|
};
|
|
90
156
|
|
|
91
157
|
declare function PayPalProvider(props: {
|
|
@@ -102,18 +168,22 @@ declare function PayPalCurrencyNotice({ config }: {
|
|
|
102
168
|
declare function PayPalSmartButtons(props: {
|
|
103
169
|
baseUrl: string;
|
|
104
170
|
publishableApiKey?: string;
|
|
171
|
+
/** Forwarded to every API call — see `HttpOptions.credentials`. */
|
|
172
|
+
credentials?: RequestCredentials;
|
|
105
173
|
cartId: string;
|
|
106
174
|
config: PayPalConfig;
|
|
107
|
-
onPaid?: (result: Record<string, unknown>) => void
|
|
175
|
+
onPaid?: (result: Record<string, unknown>) => void | Promise<void>;
|
|
108
176
|
onError?: (message: string) => void;
|
|
109
177
|
}): React.JSX.Element | null;
|
|
110
178
|
|
|
111
179
|
declare function PayPalAdvancedCard(props: {
|
|
112
180
|
baseUrl: string;
|
|
113
181
|
publishableApiKey?: string;
|
|
182
|
+
/** Forwarded to every API call — see `HttpOptions.credentials`. */
|
|
183
|
+
credentials?: RequestCredentials;
|
|
114
184
|
cartId: string;
|
|
115
185
|
config: PayPalConfig;
|
|
116
|
-
onPaid?: (result: Record<string, unknown>) => void
|
|
186
|
+
onPaid?: (result: Record<string, unknown>) => void | Promise<void>;
|
|
117
187
|
onError?: (message: string) => void;
|
|
118
188
|
}): React.JSX.Element | null;
|
|
119
189
|
|
|
@@ -122,39 +192,39 @@ type MedusaNextPayPalAdapterProps = {
|
|
|
122
192
|
selectedProviderId: string | null | undefined;
|
|
123
193
|
baseUrl: string;
|
|
124
194
|
publishableApiKey?: string;
|
|
195
|
+
/** Forwarded to every API call — see `HttpOptions.credentials`. */
|
|
196
|
+
credentials?: RequestCredentials;
|
|
197
|
+
/**
|
|
198
|
+
* The cart's currency code (e.g. "usd"). Recommended: busts the config
|
|
199
|
+
* cache when the buyer switches region/currency on the same cart.
|
|
200
|
+
*/
|
|
201
|
+
currencyCode?: string;
|
|
125
202
|
providerIds?: {
|
|
126
203
|
paypal?: string;
|
|
127
204
|
paypalCard?: string;
|
|
128
205
|
};
|
|
129
|
-
onSuccess?: (cartId: string) => void
|
|
206
|
+
onSuccess?: (cartId: string) => void | Promise<void>;
|
|
130
207
|
onError?: (message: string) => void;
|
|
131
|
-
onPaid?: (result: unknown) => void
|
|
208
|
+
onPaid?: (result: unknown) => void | Promise<void>;
|
|
132
209
|
};
|
|
133
210
|
declare function MedusaNextPayPalAdapter(props: MedusaNextPayPalAdapterProps): React.JSX.Element | null;
|
|
134
211
|
|
|
135
|
-
/**
|
|
136
|
-
* Provider ids registered by `@easypayment/medusa-payment-paypal`.
|
|
137
|
-
*
|
|
138
|
-
* Single source of truth — `PayPalPaymentSection`, `MedusaNextPayPalAdapter`,
|
|
139
|
-
* and the server-safe `order` entrypoint all re-export from here so the ids
|
|
140
|
-
* can never drift between entrypoints.
|
|
141
|
-
*/
|
|
142
|
-
declare const PAYPAL_WALLET_PROVIDER_ID: "pp_paypal_paypal";
|
|
143
|
-
declare const PAYPAL_CARD_PROVIDER_ID: "pp_paypal_card_paypal_card";
|
|
144
|
-
declare const PAYPAL_PROVIDER_IDS: readonly ["pp_paypal_paypal", "pp_paypal_card_paypal_card"];
|
|
145
|
-
type PayPalProviderId = (typeof PAYPAL_PROVIDER_IDS)[number];
|
|
146
|
-
/** True when the provider id belongs to this PayPal plugin. */
|
|
147
|
-
declare function isPayPalProviderId(providerId?: string | null): providerId is PayPalProviderId;
|
|
148
|
-
|
|
149
212
|
type PayPalPaymentSectionProps = {
|
|
150
213
|
cartId: string;
|
|
151
214
|
selectedProviderId: string | null | undefined;
|
|
152
215
|
baseUrl: string;
|
|
153
216
|
publishableApiKey?: string;
|
|
217
|
+
/** Forwarded to every API call — see `HttpOptions.credentials`. */
|
|
218
|
+
credentials?: RequestCredentials;
|
|
219
|
+
/**
|
|
220
|
+
* The cart's currency code (e.g. "usd"). Recommended: busts the config
|
|
221
|
+
* cache when the buyer switches region/currency on the same cart.
|
|
222
|
+
*/
|
|
223
|
+
currencyCode?: string;
|
|
154
224
|
sessionLoading?: boolean;
|
|
155
|
-
onSuccess?: (cartId: string) => void
|
|
225
|
+
onSuccess?: (cartId: string) => void | Promise<void>;
|
|
156
226
|
onError?: (message: string) => void;
|
|
157
|
-
onPaid?: (result: unknown) => void
|
|
227
|
+
onPaid?: (result: unknown) => void | Promise<void>;
|
|
158
228
|
};
|
|
159
229
|
/**
|
|
160
230
|
* Drop-in PayPal payment section for a Medusa checkout.
|
|
@@ -164,12 +234,15 @@ type PayPalPaymentSectionProps = {
|
|
|
164
234
|
* component pins the default provider ids and adds the `sessionLoading` gate
|
|
165
235
|
* shown while the storefront is still creating the payment session.
|
|
166
236
|
*/
|
|
167
|
-
declare function PayPalPaymentSection({ cartId, selectedProviderId, baseUrl, publishableApiKey, sessionLoading, onSuccess, onError, onPaid, }: PayPalPaymentSectionProps): React.JSX.Element | null;
|
|
237
|
+
declare function PayPalPaymentSection({ cartId, selectedProviderId, baseUrl, publishableApiKey, credentials, currencyCode, sessionLoading, onSuccess, onError, onPaid, }: PayPalPaymentSectionProps): React.JSX.Element | null;
|
|
168
238
|
|
|
169
239
|
type Args = {
|
|
170
240
|
baseUrl: string;
|
|
171
241
|
publishableApiKey?: string;
|
|
172
242
|
cartId?: string;
|
|
243
|
+
/** See `usePayPalConfig` — include to bust the cache on currency switches. */
|
|
244
|
+
currencyCode?: string;
|
|
245
|
+
credentials?: RequestCredentials;
|
|
173
246
|
enabled?: boolean;
|
|
174
247
|
};
|
|
175
248
|
type Result = {
|
|
@@ -186,7 +259,7 @@ type Result = {
|
|
|
186
259
|
*/
|
|
187
260
|
error: string | null;
|
|
188
261
|
};
|
|
189
|
-
declare function usePayPalPaymentMethods({ baseUrl, publishableApiKey, cartId, enabled, }: Args): Result;
|
|
262
|
+
declare function usePayPalPaymentMethods({ baseUrl, publishableApiKey, cartId, currencyCode, credentials, enabled, }: Args): Result;
|
|
190
263
|
|
|
191
264
|
declare function showProcessingOverlay(): void;
|
|
192
265
|
declare function hideProcessingOverlay(): void;
|
|
@@ -210,4 +283,4 @@ declare function markCartCaptured(cartId: string): void;
|
|
|
210
283
|
declare function wasCartCaptured(cartId: string): boolean;
|
|
211
284
|
declare function clearCartCaptured(cartId: string): void;
|
|
212
285
|
|
|
213
|
-
export { MedusaNextPayPalAdapter, type MedusaNextPayPalAdapterProps, PAYPAL_CARD_PROVIDER_ID, PAYPAL_WALLET_PROVIDER_ID, PayPalAdvancedCard, type PayPalConfig, PayPalCurrencyNotice, PayPalPaymentSection, type PayPalPaymentSectionProps, PayPalProvider, type PayPalSettingsResponse, PayPalSmartButtons, clearCartCaptured, createPayPalStoreApi, generateIdempotencyKey, hideProcessingOverlay, isPayPalProviderId, markCartCaptured, markPaymentComplete, showProcessingOverlay, usePayPalConfig, usePayPalPaymentMethods, wasCartCaptured };
|
|
286
|
+
export { HttpError, type HttpOptions, type MarkPaymentCompleteOptions, MedusaNextPayPalAdapter, type MedusaNextPayPalAdapterProps, PAYPAL_CARD_PROVIDER_ID, PAYPAL_PROVIDER_IDS, PAYPAL_WALLET_PROVIDER_ID, PayPalAdvancedCard, type PayPalConfig, PayPalCurrencyNotice, PayPalPaymentSection, type PayPalPaymentSectionProps, PayPalProvider, type PayPalProviderId, type PayPalSettingsResponse, PayPalSmartButtons, type RequestOptions, clearCartCaptured, createHttpClient, createPayPalStoreApi, generateIdempotencyKey, hideProcessingOverlay, invalidatePayPalConfigCache, isPayPalProviderId, markCartCaptured, markPaymentComplete, showProcessingOverlay, usePayPalConfig, usePayPalPaymentMethods, wasCartCaptured };
|
package/dist/index.d.ts
CHANGED
|
@@ -53,6 +53,34 @@ type HttpOptions = {
|
|
|
53
53
|
* credentialed requests against a wildcard CORS origin outright.
|
|
54
54
|
*/
|
|
55
55
|
credentials?: RequestCredentials;
|
|
56
|
+
/**
|
|
57
|
+
* Per-request timeout in milliseconds. Covers the full request including
|
|
58
|
+
* reading the body. Defaults to 30 000. A caller-supplied AbortSignal
|
|
59
|
+
* composes with (never replaces) this timeout.
|
|
60
|
+
*/
|
|
61
|
+
timeoutMs?: number;
|
|
62
|
+
};
|
|
63
|
+
type RequestOptions = {
|
|
64
|
+
/**
|
|
65
|
+
* Number of extra attempts on transient failures (network error, timeout,
|
|
66
|
+
* HTTP 429/5xx). Only use for idempotent calls — the PayPal capture/complete
|
|
67
|
+
* endpoints are idempotent server-side, so a retried request after a network
|
|
68
|
+
* blip re-uses the existing result instead of duplicating work. Default 0.
|
|
69
|
+
*/
|
|
70
|
+
retries?: number;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Error thrown for HTTP-level failures (non-2xx responses and malformed
|
|
74
|
+
* response bodies). `status` carries the HTTP status code so callers can
|
|
75
|
+
* branch on it (e.g. 403 → "PayPal is disabled") instead of matching
|
|
76
|
+
* localized/backend-authored message text.
|
|
77
|
+
*/
|
|
78
|
+
declare class HttpError extends Error {
|
|
79
|
+
status: number;
|
|
80
|
+
constructor(message: string, status: number);
|
|
81
|
+
}
|
|
82
|
+
declare function createHttpClient(opts: HttpOptions): {
|
|
83
|
+
request: <T>(path: string, init?: RequestInit, reqOpts?: RequestOptions) => Promise<T>;
|
|
56
84
|
};
|
|
57
85
|
|
|
58
86
|
/**
|
|
@@ -66,26 +94,64 @@ type HttpOptions = {
|
|
|
66
94
|
* stored-order staleness check, not by this key.
|
|
67
95
|
*/
|
|
68
96
|
declare function generateIdempotencyKey(): string;
|
|
69
|
-
|
|
97
|
+
type MarkPaymentCompleteOptions = {
|
|
98
|
+
publishableApiKey?: string;
|
|
99
|
+
credentials?: RequestCredentials;
|
|
100
|
+
timeoutMs?: number;
|
|
101
|
+
signal?: AbortSignal;
|
|
102
|
+
};
|
|
103
|
+
declare function markPaymentComplete(baseUrl: string, cartId: string,
|
|
104
|
+
/** Publishable API key string (legacy signature) or an options object. */
|
|
105
|
+
options?: string | MarkPaymentCompleteOptions): Promise<Record<string, unknown>>;
|
|
70
106
|
declare function createPayPalStoreApi(opts: HttpOptions): {
|
|
71
107
|
getConfig(cartId?: string, signal?: AbortSignal): Promise<PayPalConfig>;
|
|
72
|
-
getSettings(): Promise<PayPalSettingsResponse>;
|
|
73
|
-
createOrder(cartId: string, isCardPayment?: boolean): Promise<{
|
|
108
|
+
getSettings(signal?: AbortSignal): Promise<PayPalSettingsResponse>;
|
|
109
|
+
createOrder(cartId: string, isCardPayment?: boolean, signal?: AbortSignal): Promise<{
|
|
74
110
|
id: string;
|
|
75
111
|
}>;
|
|
76
|
-
captureOrder(cartId: string, orderId: string): Promise<Record<string, unknown>>;
|
|
112
|
+
captureOrder(cartId: string, orderId: string, signal?: AbortSignal): Promise<Record<string, unknown>>;
|
|
77
113
|
};
|
|
78
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Drop cached configs — all of them, or only the entries for one cart.
|
|
117
|
+
* Call after anything that changes what the config endpoint would return
|
|
118
|
+
* (region/currency switch, plugin settings change).
|
|
119
|
+
*/
|
|
120
|
+
declare function invalidatePayPalConfigCache(cartId?: string): void;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Provider ids registered by `@easypayment/medusa-payment-paypal`.
|
|
124
|
+
*
|
|
125
|
+
* Single source of truth — `PayPalPaymentSection`, `MedusaNextPayPalAdapter`,
|
|
126
|
+
* and the server-safe `order` entrypoint all re-export from here so the ids
|
|
127
|
+
* can never drift between entrypoints.
|
|
128
|
+
*/
|
|
129
|
+
declare const PAYPAL_WALLET_PROVIDER_ID: "pp_paypal_paypal";
|
|
130
|
+
declare const PAYPAL_CARD_PROVIDER_ID: "pp_paypal_card_paypal_card";
|
|
131
|
+
declare const PAYPAL_PROVIDER_IDS: readonly ["pp_paypal_paypal", "pp_paypal_card_paypal_card"];
|
|
132
|
+
type PayPalProviderId = (typeof PAYPAL_PROVIDER_IDS)[number];
|
|
133
|
+
/** True when the provider id belongs to this PayPal plugin. */
|
|
134
|
+
declare function isPayPalProviderId(providerId?: string | null): providerId is PayPalProviderId;
|
|
135
|
+
|
|
79
136
|
type Args$1 = {
|
|
80
137
|
baseUrl: string;
|
|
81
138
|
publishableApiKey?: string;
|
|
82
139
|
cartId?: string;
|
|
140
|
+
/**
|
|
141
|
+
* The cart's current currency code (e.g. "usd"). Optional, but recommended:
|
|
142
|
+
* when provided it becomes part of the cache key, so a region/currency
|
|
143
|
+
* switch on the same cart refetches the config instead of serving a stale
|
|
144
|
+
* one for up to 5 minutes.
|
|
145
|
+
*/
|
|
146
|
+
currencyCode?: string;
|
|
147
|
+
credentials?: RequestCredentials;
|
|
83
148
|
enabled?: boolean;
|
|
84
149
|
};
|
|
85
|
-
declare function usePayPalConfig({ baseUrl, publishableApiKey, cartId, enabled, }: Args$1): {
|
|
150
|
+
declare function usePayPalConfig({ baseUrl, publishableApiKey, cartId, currencyCode, credentials, enabled, }: Args$1): {
|
|
86
151
|
config: PayPalConfig | null;
|
|
87
152
|
loading: boolean;
|
|
88
153
|
error: string | null;
|
|
154
|
+
retry: () => void;
|
|
89
155
|
};
|
|
90
156
|
|
|
91
157
|
declare function PayPalProvider(props: {
|
|
@@ -102,18 +168,22 @@ declare function PayPalCurrencyNotice({ config }: {
|
|
|
102
168
|
declare function PayPalSmartButtons(props: {
|
|
103
169
|
baseUrl: string;
|
|
104
170
|
publishableApiKey?: string;
|
|
171
|
+
/** Forwarded to every API call — see `HttpOptions.credentials`. */
|
|
172
|
+
credentials?: RequestCredentials;
|
|
105
173
|
cartId: string;
|
|
106
174
|
config: PayPalConfig;
|
|
107
|
-
onPaid?: (result: Record<string, unknown>) => void
|
|
175
|
+
onPaid?: (result: Record<string, unknown>) => void | Promise<void>;
|
|
108
176
|
onError?: (message: string) => void;
|
|
109
177
|
}): React.JSX.Element | null;
|
|
110
178
|
|
|
111
179
|
declare function PayPalAdvancedCard(props: {
|
|
112
180
|
baseUrl: string;
|
|
113
181
|
publishableApiKey?: string;
|
|
182
|
+
/** Forwarded to every API call — see `HttpOptions.credentials`. */
|
|
183
|
+
credentials?: RequestCredentials;
|
|
114
184
|
cartId: string;
|
|
115
185
|
config: PayPalConfig;
|
|
116
|
-
onPaid?: (result: Record<string, unknown>) => void
|
|
186
|
+
onPaid?: (result: Record<string, unknown>) => void | Promise<void>;
|
|
117
187
|
onError?: (message: string) => void;
|
|
118
188
|
}): React.JSX.Element | null;
|
|
119
189
|
|
|
@@ -122,39 +192,39 @@ type MedusaNextPayPalAdapterProps = {
|
|
|
122
192
|
selectedProviderId: string | null | undefined;
|
|
123
193
|
baseUrl: string;
|
|
124
194
|
publishableApiKey?: string;
|
|
195
|
+
/** Forwarded to every API call — see `HttpOptions.credentials`. */
|
|
196
|
+
credentials?: RequestCredentials;
|
|
197
|
+
/**
|
|
198
|
+
* The cart's currency code (e.g. "usd"). Recommended: busts the config
|
|
199
|
+
* cache when the buyer switches region/currency on the same cart.
|
|
200
|
+
*/
|
|
201
|
+
currencyCode?: string;
|
|
125
202
|
providerIds?: {
|
|
126
203
|
paypal?: string;
|
|
127
204
|
paypalCard?: string;
|
|
128
205
|
};
|
|
129
|
-
onSuccess?: (cartId: string) => void
|
|
206
|
+
onSuccess?: (cartId: string) => void | Promise<void>;
|
|
130
207
|
onError?: (message: string) => void;
|
|
131
|
-
onPaid?: (result: unknown) => void
|
|
208
|
+
onPaid?: (result: unknown) => void | Promise<void>;
|
|
132
209
|
};
|
|
133
210
|
declare function MedusaNextPayPalAdapter(props: MedusaNextPayPalAdapterProps): React.JSX.Element | null;
|
|
134
211
|
|
|
135
|
-
/**
|
|
136
|
-
* Provider ids registered by `@easypayment/medusa-payment-paypal`.
|
|
137
|
-
*
|
|
138
|
-
* Single source of truth — `PayPalPaymentSection`, `MedusaNextPayPalAdapter`,
|
|
139
|
-
* and the server-safe `order` entrypoint all re-export from here so the ids
|
|
140
|
-
* can never drift between entrypoints.
|
|
141
|
-
*/
|
|
142
|
-
declare const PAYPAL_WALLET_PROVIDER_ID: "pp_paypal_paypal";
|
|
143
|
-
declare const PAYPAL_CARD_PROVIDER_ID: "pp_paypal_card_paypal_card";
|
|
144
|
-
declare const PAYPAL_PROVIDER_IDS: readonly ["pp_paypal_paypal", "pp_paypal_card_paypal_card"];
|
|
145
|
-
type PayPalProviderId = (typeof PAYPAL_PROVIDER_IDS)[number];
|
|
146
|
-
/** True when the provider id belongs to this PayPal plugin. */
|
|
147
|
-
declare function isPayPalProviderId(providerId?: string | null): providerId is PayPalProviderId;
|
|
148
|
-
|
|
149
212
|
type PayPalPaymentSectionProps = {
|
|
150
213
|
cartId: string;
|
|
151
214
|
selectedProviderId: string | null | undefined;
|
|
152
215
|
baseUrl: string;
|
|
153
216
|
publishableApiKey?: string;
|
|
217
|
+
/** Forwarded to every API call — see `HttpOptions.credentials`. */
|
|
218
|
+
credentials?: RequestCredentials;
|
|
219
|
+
/**
|
|
220
|
+
* The cart's currency code (e.g. "usd"). Recommended: busts the config
|
|
221
|
+
* cache when the buyer switches region/currency on the same cart.
|
|
222
|
+
*/
|
|
223
|
+
currencyCode?: string;
|
|
154
224
|
sessionLoading?: boolean;
|
|
155
|
-
onSuccess?: (cartId: string) => void
|
|
225
|
+
onSuccess?: (cartId: string) => void | Promise<void>;
|
|
156
226
|
onError?: (message: string) => void;
|
|
157
|
-
onPaid?: (result: unknown) => void
|
|
227
|
+
onPaid?: (result: unknown) => void | Promise<void>;
|
|
158
228
|
};
|
|
159
229
|
/**
|
|
160
230
|
* Drop-in PayPal payment section for a Medusa checkout.
|
|
@@ -164,12 +234,15 @@ type PayPalPaymentSectionProps = {
|
|
|
164
234
|
* component pins the default provider ids and adds the `sessionLoading` gate
|
|
165
235
|
* shown while the storefront is still creating the payment session.
|
|
166
236
|
*/
|
|
167
|
-
declare function PayPalPaymentSection({ cartId, selectedProviderId, baseUrl, publishableApiKey, sessionLoading, onSuccess, onError, onPaid, }: PayPalPaymentSectionProps): React.JSX.Element | null;
|
|
237
|
+
declare function PayPalPaymentSection({ cartId, selectedProviderId, baseUrl, publishableApiKey, credentials, currencyCode, sessionLoading, onSuccess, onError, onPaid, }: PayPalPaymentSectionProps): React.JSX.Element | null;
|
|
168
238
|
|
|
169
239
|
type Args = {
|
|
170
240
|
baseUrl: string;
|
|
171
241
|
publishableApiKey?: string;
|
|
172
242
|
cartId?: string;
|
|
243
|
+
/** See `usePayPalConfig` — include to bust the cache on currency switches. */
|
|
244
|
+
currencyCode?: string;
|
|
245
|
+
credentials?: RequestCredentials;
|
|
173
246
|
enabled?: boolean;
|
|
174
247
|
};
|
|
175
248
|
type Result = {
|
|
@@ -186,7 +259,7 @@ type Result = {
|
|
|
186
259
|
*/
|
|
187
260
|
error: string | null;
|
|
188
261
|
};
|
|
189
|
-
declare function usePayPalPaymentMethods({ baseUrl, publishableApiKey, cartId, enabled, }: Args): Result;
|
|
262
|
+
declare function usePayPalPaymentMethods({ baseUrl, publishableApiKey, cartId, currencyCode, credentials, enabled, }: Args): Result;
|
|
190
263
|
|
|
191
264
|
declare function showProcessingOverlay(): void;
|
|
192
265
|
declare function hideProcessingOverlay(): void;
|
|
@@ -210,4 +283,4 @@ declare function markCartCaptured(cartId: string): void;
|
|
|
210
283
|
declare function wasCartCaptured(cartId: string): boolean;
|
|
211
284
|
declare function clearCartCaptured(cartId: string): void;
|
|
212
285
|
|
|
213
|
-
export { MedusaNextPayPalAdapter, type MedusaNextPayPalAdapterProps, PAYPAL_CARD_PROVIDER_ID, PAYPAL_WALLET_PROVIDER_ID, PayPalAdvancedCard, type PayPalConfig, PayPalCurrencyNotice, PayPalPaymentSection, type PayPalPaymentSectionProps, PayPalProvider, type PayPalSettingsResponse, PayPalSmartButtons, clearCartCaptured, createPayPalStoreApi, generateIdempotencyKey, hideProcessingOverlay, isPayPalProviderId, markCartCaptured, markPaymentComplete, showProcessingOverlay, usePayPalConfig, usePayPalPaymentMethods, wasCartCaptured };
|
|
286
|
+
export { HttpError, type HttpOptions, type MarkPaymentCompleteOptions, MedusaNextPayPalAdapter, type MedusaNextPayPalAdapterProps, PAYPAL_CARD_PROVIDER_ID, PAYPAL_PROVIDER_IDS, PAYPAL_WALLET_PROVIDER_ID, PayPalAdvancedCard, type PayPalConfig, PayPalCurrencyNotice, PayPalPaymentSection, type PayPalPaymentSectionProps, PayPalProvider, type PayPalProviderId, type PayPalSettingsResponse, PayPalSmartButtons, type RequestOptions, clearCartCaptured, createHttpClient, createPayPalStoreApi, generateIdempotencyKey, hideProcessingOverlay, invalidatePayPalConfigCache, isPayPalProviderId, markCartCaptured, markPaymentComplete, showProcessingOverlay, usePayPalConfig, usePayPalPaymentMethods, wasCartCaptured };
|