@easypayment/medusa-paypal-ui 1.1.0 → 1.2.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 +97 -25
- package/README.md +781 -759
- package/dist/index.cjs +366 -170
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +74 -2
- package/dist/index.d.ts +74 -2
- package/dist/index.mjs +352 -170
- package/dist/index.mjs.map +1 -1
- package/dist/order.cjs +14 -3
- package/dist/order.cjs.map +1 -1
- package/dist/order.d.cts +13 -4
- package/dist/order.d.ts +13 -4
- package/dist/order.mjs +13 -4
- package/dist/order.mjs.map +1 -1
- package/package.json +76 -65
- package/src/adapters/MedusaNextPayPalAdapter.tsx +34 -5
- package/src/client/http.ts +63 -11
- package/src/client/paypal.ts +27 -1
- package/src/client/types.ts +10 -0
- package/src/components/PayPalAdvancedCard.tsx +138 -24
- package/src/components/PayPalPaymentSection.tsx +95 -202
- package/src/components/PayPalSmartButtons.tsx +136 -7
- package/src/constants.ts +22 -0
- package/src/hooks/usePayPalPaymentMethods.ts +15 -1
- package/src/index.ts +5 -0
- package/src/order.ts +7 -10
- package/src/utils/captured-state.ts +44 -0
- package/src/utils/next-errors.ts +5 -1
- package/src/utils/processing-overlay.ts +12 -0
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,16 @@ type PayPalConfig = {
|
|
|
22
22
|
disable_buttons?: string[];
|
|
23
23
|
};
|
|
24
24
|
type PayPalSettingsResponse = {
|
|
25
|
+
/**
|
|
26
|
+
* What `GET /store/paypal/settings` actually returns: the configured
|
|
27
|
+
* payment action and whether advanced card fields are enabled.
|
|
28
|
+
*/
|
|
29
|
+
paymentAction?: "capture" | "authorize";
|
|
30
|
+
advancedCardEnabled?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated The settings endpoint has never returned a `data` envelope —
|
|
33
|
+
* kept only so existing (already-null-safe) consumer code keeps compiling.
|
|
34
|
+
*/
|
|
25
35
|
data?: {
|
|
26
36
|
api_details?: {
|
|
27
37
|
currency_code?: string;
|
|
@@ -35,8 +45,27 @@ type PayPalSettingsResponse = {
|
|
|
35
45
|
type HttpOptions = {
|
|
36
46
|
baseUrl: string;
|
|
37
47
|
publishableApiKey?: string;
|
|
48
|
+
/**
|
|
49
|
+
* `credentials` mode for every request. Defaults to "include" (the
|
|
50
|
+
* historical behavior, required when the backend sits behind cookie-based
|
|
51
|
+
* gateways like Cloudflare Access). Set to "omit" or "same-origin" when the
|
|
52
|
+
* backend answers with `Access-Control-Allow-Origin: *` — browsers reject
|
|
53
|
+
* credentialed requests against a wildcard CORS origin outright.
|
|
54
|
+
*/
|
|
55
|
+
credentials?: RequestCredentials;
|
|
38
56
|
};
|
|
39
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Fresh idempotency key per create-order ATTEMPT (i.e. per buyer click).
|
|
60
|
+
*
|
|
61
|
+
* The backend derives the PayPal-Request-Id from this header. It must be
|
|
62
|
+
* unique per attempt: PayPal replays the cached response for a reused request
|
|
63
|
+
* id, so a key stable across cart changes would hand back the ORIGINAL order —
|
|
64
|
+
* at the original total — after the buyer edits the cart, charging a stale
|
|
65
|
+
* amount. Reuse/dedup of an unchanged order is handled server-side by the
|
|
66
|
+
* stored-order staleness check, not by this key.
|
|
67
|
+
*/
|
|
68
|
+
declare function generateIdempotencyKey(): string;
|
|
40
69
|
declare function markPaymentComplete(baseUrl: string, cartId: string, publishableApiKey?: string): Promise<Record<string, unknown>>;
|
|
41
70
|
declare function createPayPalStoreApi(opts: HttpOptions): {
|
|
42
71
|
getConfig(cartId?: string, signal?: AbortSignal): Promise<PayPalConfig>;
|
|
@@ -103,9 +132,18 @@ type MedusaNextPayPalAdapterProps = {
|
|
|
103
132
|
};
|
|
104
133
|
declare function MedusaNextPayPalAdapter(props: MedusaNextPayPalAdapterProps): React.JSX.Element | null;
|
|
105
134
|
|
|
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
|
+
*/
|
|
106
142
|
declare const PAYPAL_WALLET_PROVIDER_ID: "pp_paypal_paypal";
|
|
107
143
|
declare const PAYPAL_CARD_PROVIDER_ID: "pp_paypal_card_paypal_card";
|
|
108
|
-
|
|
144
|
+
/** True when the provider id belongs to this PayPal plugin. */
|
|
145
|
+
declare function isPayPalProviderId(providerId?: string | null): boolean;
|
|
146
|
+
|
|
109
147
|
type PayPalPaymentSectionProps = {
|
|
110
148
|
cartId: string;
|
|
111
149
|
selectedProviderId: string | null | undefined;
|
|
@@ -116,6 +154,14 @@ type PayPalPaymentSectionProps = {
|
|
|
116
154
|
onError?: (message: string) => void;
|
|
117
155
|
onPaid?: (result: unknown) => void;
|
|
118
156
|
};
|
|
157
|
+
/**
|
|
158
|
+
* Drop-in PayPal payment section for a Medusa checkout.
|
|
159
|
+
*
|
|
160
|
+
* A thin wrapper over {@link MedusaNextPayPalAdapter} (they previously carried
|
|
161
|
+
* two ~90%-identical render paths that had to be edited in lockstep): this
|
|
162
|
+
* component pins the default provider ids and adds the `sessionLoading` gate
|
|
163
|
+
* shown while the storefront is still creating the payment session.
|
|
164
|
+
*/
|
|
119
165
|
declare function PayPalPaymentSection({ cartId, selectedProviderId, baseUrl, publishableApiKey, sessionLoading, onSuccess, onError, onPaid, }: PayPalPaymentSectionProps): React.JSX.Element | null;
|
|
120
166
|
|
|
121
167
|
type Args = {
|
|
@@ -130,10 +176,36 @@ type Result = {
|
|
|
130
176
|
cardEnabled: boolean;
|
|
131
177
|
cardTitle: string;
|
|
132
178
|
loading: boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Non-null when the config fetch failed and the returned flags are the
|
|
181
|
+
* optimistic defaults rather than the merchant's real settings. Storefronts
|
|
182
|
+
* can use this to hide or annotate the PayPal options instead of advertising
|
|
183
|
+
* methods that will fail once selected.
|
|
184
|
+
*/
|
|
185
|
+
error: string | null;
|
|
133
186
|
};
|
|
134
187
|
declare function usePayPalPaymentMethods({ baseUrl, publishableApiKey, cartId, enabled, }: Args): Result;
|
|
135
188
|
|
|
136
189
|
declare function showProcessingOverlay(): void;
|
|
137
190
|
declare function hideProcessingOverlay(): void;
|
|
138
191
|
|
|
139
|
-
|
|
192
|
+
/**
|
|
193
|
+
* Per-cart "money was captured" flag, persisted in sessionStorage.
|
|
194
|
+
*
|
|
195
|
+
* The in-memory `capturedRef` protects a buyer within one page lifetime, but a
|
|
196
|
+
* reload/crash between the capture and the order finalization loses it — the
|
|
197
|
+
* buyer would then see fresh payment buttons for a cart whose money is already
|
|
198
|
+
* taken. Persisting the flag lets the components restore the finalize-only
|
|
199
|
+
* Retry path after a reload instead of offering a second payment.
|
|
200
|
+
*
|
|
201
|
+
* sessionStorage is deliberately chosen over localStorage: it is scoped to the
|
|
202
|
+
* tab/session, so an abandoned flag can't leak into a future visit after the
|
|
203
|
+
* cart id is reused, and it needs no expiry logic. Every access is guarded —
|
|
204
|
+
* private browsing modes and storage-blocking settings throw on access, and a
|
|
205
|
+
* storage failure must never break the payment flow.
|
|
206
|
+
*/
|
|
207
|
+
declare function markCartCaptured(cartId: string): void;
|
|
208
|
+
declare function wasCartCaptured(cartId: string): boolean;
|
|
209
|
+
declare function clearCartCaptured(cartId: string): void;
|
|
210
|
+
|
|
211
|
+
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 };
|