@alphawebai/medusa-custom-payments-react 0.1.0-rc.39 → 0.1.0-rc.41
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/README.md +5 -0
- package/dist/{chunk-XCUOIQ2U.mjs → chunk-AVZIQKZV.mjs} +16 -4
- package/dist/{chunk-CNZSWNL2.mjs → chunk-FMPWH5MM.mjs} +55 -7
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +55 -7
- package/dist/index.mjs +1 -1
- package/dist/payment-surface.d.mts +2 -2
- package/dist/payment-surface.d.ts +2 -2
- package/dist/payment-surface.js +71 -11
- package/dist/payment-surface.mjs +2 -2
- package/dist/paypal.d.mts +2 -2
- package/dist/paypal.d.ts +2 -2
- package/dist/paypal.js +16 -4
- package/dist/paypal.mjs +1 -1
- package/dist/{types-CHvHlDN6.d.mts → types-BNNA0H0d.d.mts} +12 -2
- package/dist/{types-CHvHlDN6.d.ts → types-BNNA0H0d.d.ts} +12 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,3 +52,8 @@ For redirect-based payment methods, the host must recognize the returned
|
|
|
52
52
|
payment session before rendering this component again, stop rendering Elements,
|
|
53
53
|
and resume its server-authoritative checkout completion contract. Do not mount
|
|
54
54
|
this component with a PaymentIntent that may already be terminal.
|
|
55
|
+
|
|
56
|
+
Deferred Stripe consumers that own a page-level error surface can set
|
|
57
|
+
`errorPresentation="external"`. The `onError` callback then identifies whether
|
|
58
|
+
Stripe already presented the error (`presentation: "provider"`) or the host must
|
|
59
|
+
present it (`presentation: "host"`), so the same message is never rendered twice.
|
|
@@ -38,7 +38,7 @@ function ClickTimePayPalButton(props) {
|
|
|
38
38
|
return { orderId };
|
|
39
39
|
},
|
|
40
40
|
savePayment: props.context.savePayment,
|
|
41
|
-
commit: true,
|
|
41
|
+
commit: props.context.commit ?? true,
|
|
42
42
|
presentationMode: "auto",
|
|
43
43
|
onApprove: async (data) => {
|
|
44
44
|
if (submittingRef.current) return;
|
|
@@ -115,7 +115,13 @@ function PrismClickTimePayPalButton(props) {
|
|
|
115
115
|
environment: props.context.environment,
|
|
116
116
|
components: ["paypal-payments"],
|
|
117
117
|
pageType: "checkout",
|
|
118
|
-
children: /* @__PURE__ */ jsx(
|
|
118
|
+
children: /* @__PURE__ */ jsx(
|
|
119
|
+
ClickTimePayPalButton,
|
|
120
|
+
{
|
|
121
|
+
...props
|
|
122
|
+
},
|
|
123
|
+
`${props.context.commit ?? true}:${props.context.savePayment}`
|
|
124
|
+
)
|
|
119
125
|
},
|
|
120
126
|
`${props.context.environment}:${props.context.clientId}`
|
|
121
127
|
);
|
|
@@ -154,7 +160,7 @@ function PayPalButton(props) {
|
|
|
154
160
|
disabled: props.disabled || submitting,
|
|
155
161
|
orderId: props.session.orderId,
|
|
156
162
|
savePayment: props.session.savePayment,
|
|
157
|
-
commit: true,
|
|
163
|
+
commit: props.session.commit ?? true,
|
|
158
164
|
presentationMode: "auto",
|
|
159
165
|
onApprove: async (data) => {
|
|
160
166
|
if (submittingRef.current) return;
|
|
@@ -231,7 +237,13 @@ function PrismPayPalPaymentButton(props) {
|
|
|
231
237
|
environment: props.session.environment,
|
|
232
238
|
components: ["paypal-payments"],
|
|
233
239
|
pageType: "checkout",
|
|
234
|
-
children: /* @__PURE__ */ jsx2(
|
|
240
|
+
children: /* @__PURE__ */ jsx2(
|
|
241
|
+
PayPalButton,
|
|
242
|
+
{
|
|
243
|
+
...props
|
|
244
|
+
},
|
|
245
|
+
`${props.session.orderId}:${props.session.commit ?? true}:${props.session.savePayment}`
|
|
246
|
+
)
|
|
235
247
|
},
|
|
236
248
|
`${props.session.environment}:${props.session.clientId}`
|
|
237
249
|
);
|
|
@@ -47,6 +47,38 @@ function normalizeStripePaymentIntent(paymentIntent) {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
// src/prism/stripe-error-presentation.ts
|
|
51
|
+
var paymentElementErrorCodes = /* @__PURE__ */ new Set([
|
|
52
|
+
"card_declined",
|
|
53
|
+
"card_velocity_exceeded",
|
|
54
|
+
"expired_card",
|
|
55
|
+
"fraudulent",
|
|
56
|
+
"generic_decline",
|
|
57
|
+
"incorrect_cvc",
|
|
58
|
+
"incorrect_number",
|
|
59
|
+
"incorrect_zip",
|
|
60
|
+
"insufficient_funds",
|
|
61
|
+
"invalid_cvc",
|
|
62
|
+
"invalid_expiry_month",
|
|
63
|
+
"invalid_expiry_year",
|
|
64
|
+
"live_mode_test_card",
|
|
65
|
+
"lost_card",
|
|
66
|
+
"processing_error",
|
|
67
|
+
"stolen_card",
|
|
68
|
+
"test_mode_live_card"
|
|
69
|
+
]);
|
|
70
|
+
function stripeErrorContext(phase, error) {
|
|
71
|
+
const paymentElementOwnsMessage = error.type === "validation_error" || error.code !== void 0 && paymentElementErrorCodes.has(error.code) || error.decline_code !== void 0 && paymentElementErrorCodes.has(error.decline_code);
|
|
72
|
+
return {
|
|
73
|
+
connector: "stripe",
|
|
74
|
+
phase,
|
|
75
|
+
presentation: paymentElementOwnsMessage ? "provider" : "host"
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function hostErrorContext(phase) {
|
|
79
|
+
return { connector: "stripe", phase, presentation: "host" };
|
|
80
|
+
}
|
|
81
|
+
|
|
50
82
|
// src/prism/PrismDeferredPaymentElement.tsx
|
|
51
83
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
52
84
|
var stripeByPublishableKey = /* @__PURE__ */ new Map();
|
|
@@ -113,21 +145,34 @@ function DeferredPaymentElementForm(props) {
|
|
|
113
145
|
onPending: props.onPending,
|
|
114
146
|
onRequiresAction: props.onRequiresAction
|
|
115
147
|
};
|
|
148
|
+
function reportError(error, context) {
|
|
149
|
+
setMessage(
|
|
150
|
+
context.presentation === "host" && props.errorPresentation !== "external" ? error.message : null
|
|
151
|
+
);
|
|
152
|
+
props.onError(error, context);
|
|
153
|
+
}
|
|
116
154
|
async function submit(event) {
|
|
117
155
|
event.preventDefault();
|
|
118
156
|
if (!stripe || !elements || submitting || props.disabled) return;
|
|
119
157
|
setSubmitting(true);
|
|
120
158
|
props.onSubmittingChange?.(true);
|
|
121
159
|
setMessage(null);
|
|
160
|
+
let phase = "details";
|
|
122
161
|
try {
|
|
123
162
|
const submitted = await elements.submit();
|
|
124
163
|
if (submitted.error) {
|
|
125
|
-
|
|
126
|
-
|
|
164
|
+
reportError(
|
|
165
|
+
new Error(
|
|
166
|
+
submitted.error.message ?? "Payment details are incomplete."
|
|
167
|
+
),
|
|
168
|
+
stripeErrorContext("details", submitted.error)
|
|
127
169
|
);
|
|
170
|
+
return;
|
|
128
171
|
}
|
|
172
|
+
phase = "prepare";
|
|
129
173
|
const prepared = await props.onPrepare();
|
|
130
174
|
const clientSecret = assertPreparedClientSecret(prepared?.clientSecret);
|
|
175
|
+
phase = "confirm";
|
|
131
176
|
const result = await stripe.confirmPayment({
|
|
132
177
|
elements,
|
|
133
178
|
clientSecret,
|
|
@@ -142,19 +187,23 @@ function DeferredPaymentElementForm(props) {
|
|
|
142
187
|
redirect: "if_required"
|
|
143
188
|
});
|
|
144
189
|
if (result.error) {
|
|
145
|
-
|
|
190
|
+
reportError(
|
|
191
|
+
new Error(result.error.message ?? "Stripe could not confirm payment."),
|
|
192
|
+
stripeErrorContext("confirm", result.error)
|
|
193
|
+
);
|
|
194
|
+
return;
|
|
146
195
|
}
|
|
147
196
|
if (!result.paymentIntent) {
|
|
148
197
|
throw new Error("Stripe did not return a payment result.");
|
|
149
198
|
}
|
|
199
|
+
phase = "outcome";
|
|
150
200
|
await dispatchOutcome(
|
|
151
201
|
normalizeStripePaymentIntent(result.paymentIntent),
|
|
152
202
|
callbacks
|
|
153
203
|
);
|
|
154
204
|
} catch (error) {
|
|
155
205
|
const safeError = error instanceof Error ? error : new Error("Payment could not be completed.");
|
|
156
|
-
|
|
157
|
-
props.onError(safeError);
|
|
206
|
+
reportError(safeError, hostErrorContext(phase));
|
|
158
207
|
} finally {
|
|
159
208
|
setSubmitting(false);
|
|
160
209
|
props.onSubmittingChange?.(false);
|
|
@@ -174,8 +223,7 @@ function DeferredPaymentElementForm(props) {
|
|
|
174
223
|
onReady: () => setReady(true),
|
|
175
224
|
onLoadError: (event) => {
|
|
176
225
|
const error = new Error(event.error.message);
|
|
177
|
-
|
|
178
|
-
props.onError(error);
|
|
226
|
+
reportError(error, hostErrorContext("load"));
|
|
179
227
|
}
|
|
180
228
|
}
|
|
181
229
|
),
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { P as PrismDeferredPaymentElementProps, a as PrismPaymentElementProps } from './types-
|
|
3
|
-
export { b as PrismCheckoutProviderContext, c as PrismClickTimePayPalButtonProps, d as PrismClickTimePayPalOrder, e as PrismDeferredPaymentSurfaceProps, f as PrismDeferredStripePreparedPayment, g as PrismPayPalApprovalOutcome, h as PrismPayPalCheckoutProviderContext, i as PrismPayPalPaymentButtonClassNames, j as PrismPayPalPaymentButtonProps, k as PrismPaymentBillingDetails, l as
|
|
2
|
+
import { P as PrismDeferredPaymentElementProps, a as PrismPaymentElementProps } from './types-BNNA0H0d.mjs';
|
|
3
|
+
export { b as PrismCheckoutProviderContext, c as PrismClickTimePayPalButtonProps, d as PrismClickTimePayPalOrder, e as PrismDeferredPaymentSurfaceProps, f as PrismDeferredStripePreparedPayment, g as PrismPayPalApprovalOutcome, h as PrismPayPalCheckoutProviderContext, i as PrismPayPalPaymentButtonClassNames, j as PrismPayPalPaymentButtonProps, k as PrismPaymentBillingDetails, l as PrismPaymentErrorContext, m as PrismPaymentErrorPhase, n as PrismPaymentErrorPresentation, o as PrismPaymentOutcome, p as PrismPaymentSurfaceProps, q as PrismPreparedPayPalPaymentSession, r as PrismPreparedPaymentSession, s as PrismPreparedStripePaymentSession, t as PrismStripeCheckoutProviderContext, u as PrismStripeDisplayPolicy, S as StripeSupportedTermMethod } from './types-BNNA0H0d.mjs';
|
|
4
4
|
import '@stripe/stripe-js';
|
|
5
5
|
|
|
6
6
|
declare function PrismDeferredPaymentElement(props: PrismDeferredPaymentElementProps): react.JSX.Element;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { P as PrismDeferredPaymentElementProps, a as PrismPaymentElementProps } from './types-
|
|
3
|
-
export { b as PrismCheckoutProviderContext, c as PrismClickTimePayPalButtonProps, d as PrismClickTimePayPalOrder, e as PrismDeferredPaymentSurfaceProps, f as PrismDeferredStripePreparedPayment, g as PrismPayPalApprovalOutcome, h as PrismPayPalCheckoutProviderContext, i as PrismPayPalPaymentButtonClassNames, j as PrismPayPalPaymentButtonProps, k as PrismPaymentBillingDetails, l as
|
|
2
|
+
import { P as PrismDeferredPaymentElementProps, a as PrismPaymentElementProps } from './types-BNNA0H0d.js';
|
|
3
|
+
export { b as PrismCheckoutProviderContext, c as PrismClickTimePayPalButtonProps, d as PrismClickTimePayPalOrder, e as PrismDeferredPaymentSurfaceProps, f as PrismDeferredStripePreparedPayment, g as PrismPayPalApprovalOutcome, h as PrismPayPalCheckoutProviderContext, i as PrismPayPalPaymentButtonClassNames, j as PrismPayPalPaymentButtonProps, k as PrismPaymentBillingDetails, l as PrismPaymentErrorContext, m as PrismPaymentErrorPhase, n as PrismPaymentErrorPresentation, o as PrismPaymentOutcome, p as PrismPaymentSurfaceProps, q as PrismPreparedPayPalPaymentSession, r as PrismPreparedPaymentSession, s as PrismPreparedStripePaymentSession, t as PrismStripeCheckoutProviderContext, u as PrismStripeDisplayPolicy, S as StripeSupportedTermMethod } from './types-BNNA0H0d.js';
|
|
4
4
|
import '@stripe/stripe-js';
|
|
5
5
|
|
|
6
6
|
declare function PrismDeferredPaymentElement(props: PrismDeferredPaymentElementProps): react.JSX.Element;
|
package/dist/index.js
CHANGED
|
@@ -67,6 +67,38 @@ function normalizeStripePaymentIntent(paymentIntent) {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
// src/prism/stripe-error-presentation.ts
|
|
71
|
+
var paymentElementErrorCodes = /* @__PURE__ */ new Set([
|
|
72
|
+
"card_declined",
|
|
73
|
+
"card_velocity_exceeded",
|
|
74
|
+
"expired_card",
|
|
75
|
+
"fraudulent",
|
|
76
|
+
"generic_decline",
|
|
77
|
+
"incorrect_cvc",
|
|
78
|
+
"incorrect_number",
|
|
79
|
+
"incorrect_zip",
|
|
80
|
+
"insufficient_funds",
|
|
81
|
+
"invalid_cvc",
|
|
82
|
+
"invalid_expiry_month",
|
|
83
|
+
"invalid_expiry_year",
|
|
84
|
+
"live_mode_test_card",
|
|
85
|
+
"lost_card",
|
|
86
|
+
"processing_error",
|
|
87
|
+
"stolen_card",
|
|
88
|
+
"test_mode_live_card"
|
|
89
|
+
]);
|
|
90
|
+
function stripeErrorContext(phase, error) {
|
|
91
|
+
const paymentElementOwnsMessage = error.type === "validation_error" || error.code !== void 0 && paymentElementErrorCodes.has(error.code) || error.decline_code !== void 0 && paymentElementErrorCodes.has(error.decline_code);
|
|
92
|
+
return {
|
|
93
|
+
connector: "stripe",
|
|
94
|
+
phase,
|
|
95
|
+
presentation: paymentElementOwnsMessage ? "provider" : "host"
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function hostErrorContext(phase) {
|
|
99
|
+
return { connector: "stripe", phase, presentation: "host" };
|
|
100
|
+
}
|
|
101
|
+
|
|
70
102
|
// src/prism/PrismDeferredPaymentElement.tsx
|
|
71
103
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
72
104
|
var stripeByPublishableKey = /* @__PURE__ */ new Map();
|
|
@@ -133,21 +165,34 @@ function DeferredPaymentElementForm(props) {
|
|
|
133
165
|
onPending: props.onPending,
|
|
134
166
|
onRequiresAction: props.onRequiresAction
|
|
135
167
|
};
|
|
168
|
+
function reportError(error, context) {
|
|
169
|
+
setMessage(
|
|
170
|
+
context.presentation === "host" && props.errorPresentation !== "external" ? error.message : null
|
|
171
|
+
);
|
|
172
|
+
props.onError(error, context);
|
|
173
|
+
}
|
|
136
174
|
async function submit(event) {
|
|
137
175
|
event.preventDefault();
|
|
138
176
|
if (!stripe || !elements || submitting || props.disabled) return;
|
|
139
177
|
setSubmitting(true);
|
|
140
178
|
props.onSubmittingChange?.(true);
|
|
141
179
|
setMessage(null);
|
|
180
|
+
let phase = "details";
|
|
142
181
|
try {
|
|
143
182
|
const submitted = await elements.submit();
|
|
144
183
|
if (submitted.error) {
|
|
145
|
-
|
|
146
|
-
|
|
184
|
+
reportError(
|
|
185
|
+
new Error(
|
|
186
|
+
submitted.error.message ?? "Payment details are incomplete."
|
|
187
|
+
),
|
|
188
|
+
stripeErrorContext("details", submitted.error)
|
|
147
189
|
);
|
|
190
|
+
return;
|
|
148
191
|
}
|
|
192
|
+
phase = "prepare";
|
|
149
193
|
const prepared = await props.onPrepare();
|
|
150
194
|
const clientSecret = assertPreparedClientSecret(prepared?.clientSecret);
|
|
195
|
+
phase = "confirm";
|
|
151
196
|
const result = await stripe.confirmPayment({
|
|
152
197
|
elements,
|
|
153
198
|
clientSecret,
|
|
@@ -162,19 +207,23 @@ function DeferredPaymentElementForm(props) {
|
|
|
162
207
|
redirect: "if_required"
|
|
163
208
|
});
|
|
164
209
|
if (result.error) {
|
|
165
|
-
|
|
210
|
+
reportError(
|
|
211
|
+
new Error(result.error.message ?? "Stripe could not confirm payment."),
|
|
212
|
+
stripeErrorContext("confirm", result.error)
|
|
213
|
+
);
|
|
214
|
+
return;
|
|
166
215
|
}
|
|
167
216
|
if (!result.paymentIntent) {
|
|
168
217
|
throw new Error("Stripe did not return a payment result.");
|
|
169
218
|
}
|
|
219
|
+
phase = "outcome";
|
|
170
220
|
await dispatchOutcome(
|
|
171
221
|
normalizeStripePaymentIntent(result.paymentIntent),
|
|
172
222
|
callbacks
|
|
173
223
|
);
|
|
174
224
|
} catch (error) {
|
|
175
225
|
const safeError = error instanceof Error ? error : new Error("Payment could not be completed.");
|
|
176
|
-
|
|
177
|
-
props.onError(safeError);
|
|
226
|
+
reportError(safeError, hostErrorContext(phase));
|
|
178
227
|
} finally {
|
|
179
228
|
setSubmitting(false);
|
|
180
229
|
props.onSubmittingChange?.(false);
|
|
@@ -194,8 +243,7 @@ function DeferredPaymentElementForm(props) {
|
|
|
194
243
|
onReady: () => setReady(true),
|
|
195
244
|
onLoadError: (event) => {
|
|
196
245
|
const error = new Error(event.error.message);
|
|
197
|
-
|
|
198
|
-
props.onError(error);
|
|
246
|
+
reportError(error, hostErrorContext("load"));
|
|
199
247
|
}
|
|
200
248
|
}
|
|
201
249
|
),
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { e as PrismDeferredPaymentSurfaceProps,
|
|
3
|
-
export { b as PrismCheckoutProviderContext, h as PrismPayPalCheckoutProviderContext,
|
|
2
|
+
import { e as PrismDeferredPaymentSurfaceProps, p as PrismPaymentSurfaceProps } from './types-BNNA0H0d.mjs';
|
|
3
|
+
export { b as PrismCheckoutProviderContext, h as PrismPayPalCheckoutProviderContext, l as PrismPaymentErrorContext, m as PrismPaymentErrorPhase, n as PrismPaymentErrorPresentation, r as PrismPreparedPaymentSession, t as PrismStripeCheckoutProviderContext } from './types-BNNA0H0d.mjs';
|
|
4
4
|
import '@stripe/stripe-js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { e as PrismDeferredPaymentSurfaceProps,
|
|
3
|
-
export { b as PrismCheckoutProviderContext, h as PrismPayPalCheckoutProviderContext,
|
|
2
|
+
import { e as PrismDeferredPaymentSurfaceProps, p as PrismPaymentSurfaceProps } from './types-BNNA0H0d.js';
|
|
3
|
+
export { b as PrismCheckoutProviderContext, h as PrismPayPalCheckoutProviderContext, l as PrismPaymentErrorContext, m as PrismPaymentErrorPhase, n as PrismPaymentErrorPresentation, r as PrismPreparedPaymentSession, t as PrismStripeCheckoutProviderContext } from './types-BNNA0H0d.js';
|
|
4
4
|
import '@stripe/stripe-js';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/payment-surface.js
CHANGED
|
@@ -62,7 +62,7 @@ function ClickTimePayPalButton(props) {
|
|
|
62
62
|
return { orderId };
|
|
63
63
|
},
|
|
64
64
|
savePayment: props.context.savePayment,
|
|
65
|
-
commit: true,
|
|
65
|
+
commit: props.context.commit ?? true,
|
|
66
66
|
presentationMode: "auto",
|
|
67
67
|
onApprove: async (data) => {
|
|
68
68
|
if (submittingRef.current) return;
|
|
@@ -139,7 +139,13 @@ function PrismClickTimePayPalButton(props) {
|
|
|
139
139
|
environment: props.context.environment,
|
|
140
140
|
components: ["paypal-payments"],
|
|
141
141
|
pageType: "checkout",
|
|
142
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
142
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
143
|
+
ClickTimePayPalButton,
|
|
144
|
+
{
|
|
145
|
+
...props
|
|
146
|
+
},
|
|
147
|
+
`${props.context.commit ?? true}:${props.context.savePayment}`
|
|
148
|
+
)
|
|
143
149
|
},
|
|
144
150
|
`${props.context.environment}:${props.context.clientId}`
|
|
145
151
|
);
|
|
@@ -187,6 +193,38 @@ function normalizeStripePaymentIntent(paymentIntent) {
|
|
|
187
193
|
}
|
|
188
194
|
}
|
|
189
195
|
|
|
196
|
+
// src/prism/stripe-error-presentation.ts
|
|
197
|
+
var paymentElementErrorCodes = /* @__PURE__ */ new Set([
|
|
198
|
+
"card_declined",
|
|
199
|
+
"card_velocity_exceeded",
|
|
200
|
+
"expired_card",
|
|
201
|
+
"fraudulent",
|
|
202
|
+
"generic_decline",
|
|
203
|
+
"incorrect_cvc",
|
|
204
|
+
"incorrect_number",
|
|
205
|
+
"incorrect_zip",
|
|
206
|
+
"insufficient_funds",
|
|
207
|
+
"invalid_cvc",
|
|
208
|
+
"invalid_expiry_month",
|
|
209
|
+
"invalid_expiry_year",
|
|
210
|
+
"live_mode_test_card",
|
|
211
|
+
"lost_card",
|
|
212
|
+
"processing_error",
|
|
213
|
+
"stolen_card",
|
|
214
|
+
"test_mode_live_card"
|
|
215
|
+
]);
|
|
216
|
+
function stripeErrorContext(phase, error) {
|
|
217
|
+
const paymentElementOwnsMessage = error.type === "validation_error" || error.code !== void 0 && paymentElementErrorCodes.has(error.code) || error.decline_code !== void 0 && paymentElementErrorCodes.has(error.decline_code);
|
|
218
|
+
return {
|
|
219
|
+
connector: "stripe",
|
|
220
|
+
phase,
|
|
221
|
+
presentation: paymentElementOwnsMessage ? "provider" : "host"
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
function hostErrorContext(phase) {
|
|
225
|
+
return { connector: "stripe", phase, presentation: "host" };
|
|
226
|
+
}
|
|
227
|
+
|
|
190
228
|
// src/prism/PrismDeferredPaymentElement.tsx
|
|
191
229
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
192
230
|
var stripeByPublishableKey = /* @__PURE__ */ new Map();
|
|
@@ -253,21 +291,34 @@ function DeferredPaymentElementForm(props) {
|
|
|
253
291
|
onPending: props.onPending,
|
|
254
292
|
onRequiresAction: props.onRequiresAction
|
|
255
293
|
};
|
|
294
|
+
function reportError(error, context) {
|
|
295
|
+
setMessage(
|
|
296
|
+
context.presentation === "host" && props.errorPresentation !== "external" ? error.message : null
|
|
297
|
+
);
|
|
298
|
+
props.onError(error, context);
|
|
299
|
+
}
|
|
256
300
|
async function submit(event) {
|
|
257
301
|
event.preventDefault();
|
|
258
302
|
if (!stripe || !elements || submitting || props.disabled) return;
|
|
259
303
|
setSubmitting(true);
|
|
260
304
|
props.onSubmittingChange?.(true);
|
|
261
305
|
setMessage(null);
|
|
306
|
+
let phase = "details";
|
|
262
307
|
try {
|
|
263
308
|
const submitted = await elements.submit();
|
|
264
309
|
if (submitted.error) {
|
|
265
|
-
|
|
266
|
-
|
|
310
|
+
reportError(
|
|
311
|
+
new Error(
|
|
312
|
+
submitted.error.message ?? "Payment details are incomplete."
|
|
313
|
+
),
|
|
314
|
+
stripeErrorContext("details", submitted.error)
|
|
267
315
|
);
|
|
316
|
+
return;
|
|
268
317
|
}
|
|
318
|
+
phase = "prepare";
|
|
269
319
|
const prepared = await props.onPrepare();
|
|
270
320
|
const clientSecret = assertPreparedClientSecret(prepared?.clientSecret);
|
|
321
|
+
phase = "confirm";
|
|
271
322
|
const result = await stripe.confirmPayment({
|
|
272
323
|
elements,
|
|
273
324
|
clientSecret,
|
|
@@ -282,19 +333,23 @@ function DeferredPaymentElementForm(props) {
|
|
|
282
333
|
redirect: "if_required"
|
|
283
334
|
});
|
|
284
335
|
if (result.error) {
|
|
285
|
-
|
|
336
|
+
reportError(
|
|
337
|
+
new Error(result.error.message ?? "Stripe could not confirm payment."),
|
|
338
|
+
stripeErrorContext("confirm", result.error)
|
|
339
|
+
);
|
|
340
|
+
return;
|
|
286
341
|
}
|
|
287
342
|
if (!result.paymentIntent) {
|
|
288
343
|
throw new Error("Stripe did not return a payment result.");
|
|
289
344
|
}
|
|
345
|
+
phase = "outcome";
|
|
290
346
|
await dispatchOutcome(
|
|
291
347
|
normalizeStripePaymentIntent(result.paymentIntent),
|
|
292
348
|
callbacks
|
|
293
349
|
);
|
|
294
350
|
} catch (error) {
|
|
295
351
|
const safeError3 = error instanceof Error ? error : new Error("Payment could not be completed.");
|
|
296
|
-
|
|
297
|
-
props.onError(safeError3);
|
|
352
|
+
reportError(safeError3, hostErrorContext(phase));
|
|
298
353
|
} finally {
|
|
299
354
|
setSubmitting(false);
|
|
300
355
|
props.onSubmittingChange?.(false);
|
|
@@ -314,8 +369,7 @@ function DeferredPaymentElementForm(props) {
|
|
|
314
369
|
onReady: () => setReady(true),
|
|
315
370
|
onLoadError: (event) => {
|
|
316
371
|
const error = new Error(event.error.message);
|
|
317
|
-
|
|
318
|
-
props.onError(error);
|
|
372
|
+
reportError(error, hostErrorContext("load"));
|
|
319
373
|
}
|
|
320
374
|
}
|
|
321
375
|
),
|
|
@@ -423,7 +477,7 @@ function PayPalButton(props) {
|
|
|
423
477
|
disabled: props.disabled || submitting,
|
|
424
478
|
orderId: props.session.orderId,
|
|
425
479
|
savePayment: props.session.savePayment,
|
|
426
|
-
commit: true,
|
|
480
|
+
commit: props.session.commit ?? true,
|
|
427
481
|
presentationMode: "auto",
|
|
428
482
|
onApprove: async (data) => {
|
|
429
483
|
if (submittingRef.current) return;
|
|
@@ -500,7 +554,13 @@ function PrismPayPalPaymentButton(props) {
|
|
|
500
554
|
environment: props.session.environment,
|
|
501
555
|
components: ["paypal-payments"],
|
|
502
556
|
pageType: "checkout",
|
|
503
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
557
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
558
|
+
PayPalButton,
|
|
559
|
+
{
|
|
560
|
+
...props
|
|
561
|
+
},
|
|
562
|
+
`${props.session.orderId}:${props.session.commit ?? true}:${props.session.savePayment}`
|
|
563
|
+
)
|
|
504
564
|
},
|
|
505
565
|
`${props.session.environment}:${props.session.clientId}`
|
|
506
566
|
);
|
package/dist/payment-surface.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PrismDeferredPaymentElement,
|
|
3
3
|
PrismPaymentElement
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-FMPWH5MM.mjs";
|
|
5
5
|
import {
|
|
6
6
|
PrismClickTimePayPalButton,
|
|
7
7
|
PrismPayPalPaymentButton
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-AVZIQKZV.mjs";
|
|
9
9
|
|
|
10
10
|
// src/prism/PrismDeferredPaymentSurface.tsx
|
|
11
11
|
import { jsx } from "react/jsx-runtime";
|
package/dist/paypal.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { c as PrismClickTimePayPalButtonProps, j as PrismPayPalPaymentButtonProps } from './types-
|
|
3
|
-
export { d as PrismClickTimePayPalOrder, g as PrismPayPalApprovalOutcome, h as PrismPayPalCheckoutProviderContext, i as PrismPayPalPaymentButtonClassNames,
|
|
2
|
+
import { c as PrismClickTimePayPalButtonProps, j as PrismPayPalPaymentButtonProps } from './types-BNNA0H0d.mjs';
|
|
3
|
+
export { d as PrismClickTimePayPalOrder, g as PrismPayPalApprovalOutcome, h as PrismPayPalCheckoutProviderContext, i as PrismPayPalPaymentButtonClassNames, q as PrismPreparedPayPalPaymentSession } from './types-BNNA0H0d.mjs';
|
|
4
4
|
import '@stripe/stripe-js';
|
|
5
5
|
|
|
6
6
|
declare function PrismClickTimePayPalButton(props: PrismClickTimePayPalButtonProps): react.JSX.Element;
|
package/dist/paypal.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { c as PrismClickTimePayPalButtonProps, j as PrismPayPalPaymentButtonProps } from './types-
|
|
3
|
-
export { d as PrismClickTimePayPalOrder, g as PrismPayPalApprovalOutcome, h as PrismPayPalCheckoutProviderContext, i as PrismPayPalPaymentButtonClassNames,
|
|
2
|
+
import { c as PrismClickTimePayPalButtonProps, j as PrismPayPalPaymentButtonProps } from './types-BNNA0H0d.js';
|
|
3
|
+
export { d as PrismClickTimePayPalOrder, g as PrismPayPalApprovalOutcome, h as PrismPayPalCheckoutProviderContext, i as PrismPayPalPaymentButtonClassNames, q as PrismPreparedPayPalPaymentSession } from './types-BNNA0H0d.js';
|
|
4
4
|
import '@stripe/stripe-js';
|
|
5
5
|
|
|
6
6
|
declare function PrismClickTimePayPalButton(props: PrismClickTimePayPalButtonProps): react.JSX.Element;
|
package/dist/paypal.js
CHANGED
|
@@ -62,7 +62,7 @@ function ClickTimePayPalButton(props) {
|
|
|
62
62
|
return { orderId };
|
|
63
63
|
},
|
|
64
64
|
savePayment: props.context.savePayment,
|
|
65
|
-
commit: true,
|
|
65
|
+
commit: props.context.commit ?? true,
|
|
66
66
|
presentationMode: "auto",
|
|
67
67
|
onApprove: async (data) => {
|
|
68
68
|
if (submittingRef.current) return;
|
|
@@ -139,7 +139,13 @@ function PrismClickTimePayPalButton(props) {
|
|
|
139
139
|
environment: props.context.environment,
|
|
140
140
|
components: ["paypal-payments"],
|
|
141
141
|
pageType: "checkout",
|
|
142
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
142
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
143
|
+
ClickTimePayPalButton,
|
|
144
|
+
{
|
|
145
|
+
...props
|
|
146
|
+
},
|
|
147
|
+
`${props.context.commit ?? true}:${props.context.savePayment}`
|
|
148
|
+
)
|
|
143
149
|
},
|
|
144
150
|
`${props.context.environment}:${props.context.clientId}`
|
|
145
151
|
);
|
|
@@ -175,7 +181,7 @@ function PayPalButton(props) {
|
|
|
175
181
|
disabled: props.disabled || submitting,
|
|
176
182
|
orderId: props.session.orderId,
|
|
177
183
|
savePayment: props.session.savePayment,
|
|
178
|
-
commit: true,
|
|
184
|
+
commit: props.session.commit ?? true,
|
|
179
185
|
presentationMode: "auto",
|
|
180
186
|
onApprove: async (data) => {
|
|
181
187
|
if (submittingRef.current) return;
|
|
@@ -252,7 +258,13 @@ function PrismPayPalPaymentButton(props) {
|
|
|
252
258
|
environment: props.session.environment,
|
|
253
259
|
components: ["paypal-payments"],
|
|
254
260
|
pageType: "checkout",
|
|
255
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
261
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
262
|
+
PayPalButton,
|
|
263
|
+
{
|
|
264
|
+
...props
|
|
265
|
+
},
|
|
266
|
+
`${props.session.orderId}:${props.session.commit ?? true}:${props.session.savePayment}`
|
|
267
|
+
)
|
|
256
268
|
},
|
|
257
269
|
`${props.session.environment}:${props.session.clientId}`
|
|
258
270
|
);
|
package/dist/paypal.mjs
CHANGED
|
@@ -18,6 +18,7 @@ interface PrismPreparedPayPalPaymentSession extends PrismPreparedPaymentSessionB
|
|
|
18
18
|
clientId: string;
|
|
19
19
|
environment: "sandbox" | "production";
|
|
20
20
|
savePayment: boolean;
|
|
21
|
+
commit?: boolean;
|
|
21
22
|
}
|
|
22
23
|
type PrismPreparedPaymentSession = PrismPreparedStripePaymentSession | PrismPreparedPayPalPaymentSession;
|
|
23
24
|
interface PrismPaymentBillingDetails {
|
|
@@ -51,6 +52,13 @@ interface PrismPaymentElementClassNames {
|
|
|
51
52
|
submitButton?: string;
|
|
52
53
|
status?: string;
|
|
53
54
|
}
|
|
55
|
+
type PrismPaymentErrorPresentation = "provider" | "host";
|
|
56
|
+
type PrismPaymentErrorPhase = "load" | "details" | "prepare" | "confirm" | "outcome";
|
|
57
|
+
interface PrismPaymentErrorContext {
|
|
58
|
+
connector: "stripe";
|
|
59
|
+
phase: PrismPaymentErrorPhase;
|
|
60
|
+
presentation: PrismPaymentErrorPresentation;
|
|
61
|
+
}
|
|
54
62
|
interface PrismPaymentOutcome {
|
|
55
63
|
connector: "stripe";
|
|
56
64
|
paymentIntentId: string;
|
|
@@ -111,6 +119,7 @@ interface PrismPayPalCheckoutProviderContext {
|
|
|
111
119
|
clientId: string;
|
|
112
120
|
environment: "sandbox" | "production";
|
|
113
121
|
savePayment: boolean;
|
|
122
|
+
commit?: boolean;
|
|
114
123
|
}
|
|
115
124
|
type PrismCheckoutProviderContext = PrismStripeCheckoutProviderContext | PrismPayPalCheckoutProviderContext;
|
|
116
125
|
interface PrismDeferredStripePreparedPayment {
|
|
@@ -130,13 +139,14 @@ interface PrismDeferredPaymentElementProps {
|
|
|
130
139
|
displayPolicy?: "if_required" | PrismStripeDisplayPolicy;
|
|
131
140
|
appearance?: StripeElementsOptions["appearance"];
|
|
132
141
|
classNames?: PrismPaymentElementClassNames;
|
|
142
|
+
errorPresentation?: "inline" | "external";
|
|
133
143
|
submitLabel?: string;
|
|
134
144
|
disabled?: boolean;
|
|
135
145
|
onSubmittingChange?: (submitting: boolean) => void;
|
|
136
146
|
onAuthorized: (outcome: PrismPaymentOutcome) => void | Promise<void>;
|
|
137
147
|
onPending: (outcome: PrismPaymentOutcome) => void | Promise<void>;
|
|
138
148
|
onRequiresAction: (outcome: PrismPaymentOutcome) => void | Promise<void>;
|
|
139
|
-
onError: (error: Error) => void;
|
|
149
|
+
onError: (error: Error, context: PrismPaymentErrorContext) => void;
|
|
140
150
|
}
|
|
141
151
|
interface PrismClickTimePayPalOrder {
|
|
142
152
|
orderId: string;
|
|
@@ -158,4 +168,4 @@ interface PrismClickTimePayPalButtonProps {
|
|
|
158
168
|
}
|
|
159
169
|
type PrismDeferredPaymentSurfaceProps = PrismDeferredPaymentElementProps | PrismClickTimePayPalButtonProps;
|
|
160
170
|
|
|
161
|
-
export type { PrismDeferredPaymentElementProps as P, StripeSupportedTermMethod as S, PrismPaymentElementProps as a, PrismCheckoutProviderContext as b, PrismClickTimePayPalButtonProps as c, PrismClickTimePayPalOrder as d, PrismDeferredPaymentSurfaceProps as e, PrismDeferredStripePreparedPayment as f, PrismPayPalApprovalOutcome as g, PrismPayPalCheckoutProviderContext as h, PrismPayPalPaymentButtonClassNames as i, PrismPayPalPaymentButtonProps as j, PrismPaymentBillingDetails as k,
|
|
171
|
+
export type { PrismDeferredPaymentElementProps as P, StripeSupportedTermMethod as S, PrismPaymentElementProps as a, PrismCheckoutProviderContext as b, PrismClickTimePayPalButtonProps as c, PrismClickTimePayPalOrder as d, PrismDeferredPaymentSurfaceProps as e, PrismDeferredStripePreparedPayment as f, PrismPayPalApprovalOutcome as g, PrismPayPalCheckoutProviderContext as h, PrismPayPalPaymentButtonClassNames as i, PrismPayPalPaymentButtonProps as j, PrismPaymentBillingDetails as k, PrismPaymentErrorContext as l, PrismPaymentErrorPhase as m, PrismPaymentErrorPresentation as n, PrismPaymentOutcome as o, PrismPaymentSurfaceProps as p, PrismPreparedPayPalPaymentSession as q, PrismPreparedPaymentSession as r, PrismPreparedStripePaymentSession as s, PrismStripeCheckoutProviderContext as t, PrismStripeDisplayPolicy as u };
|
|
@@ -18,6 +18,7 @@ interface PrismPreparedPayPalPaymentSession extends PrismPreparedPaymentSessionB
|
|
|
18
18
|
clientId: string;
|
|
19
19
|
environment: "sandbox" | "production";
|
|
20
20
|
savePayment: boolean;
|
|
21
|
+
commit?: boolean;
|
|
21
22
|
}
|
|
22
23
|
type PrismPreparedPaymentSession = PrismPreparedStripePaymentSession | PrismPreparedPayPalPaymentSession;
|
|
23
24
|
interface PrismPaymentBillingDetails {
|
|
@@ -51,6 +52,13 @@ interface PrismPaymentElementClassNames {
|
|
|
51
52
|
submitButton?: string;
|
|
52
53
|
status?: string;
|
|
53
54
|
}
|
|
55
|
+
type PrismPaymentErrorPresentation = "provider" | "host";
|
|
56
|
+
type PrismPaymentErrorPhase = "load" | "details" | "prepare" | "confirm" | "outcome";
|
|
57
|
+
interface PrismPaymentErrorContext {
|
|
58
|
+
connector: "stripe";
|
|
59
|
+
phase: PrismPaymentErrorPhase;
|
|
60
|
+
presentation: PrismPaymentErrorPresentation;
|
|
61
|
+
}
|
|
54
62
|
interface PrismPaymentOutcome {
|
|
55
63
|
connector: "stripe";
|
|
56
64
|
paymentIntentId: string;
|
|
@@ -111,6 +119,7 @@ interface PrismPayPalCheckoutProviderContext {
|
|
|
111
119
|
clientId: string;
|
|
112
120
|
environment: "sandbox" | "production";
|
|
113
121
|
savePayment: boolean;
|
|
122
|
+
commit?: boolean;
|
|
114
123
|
}
|
|
115
124
|
type PrismCheckoutProviderContext = PrismStripeCheckoutProviderContext | PrismPayPalCheckoutProviderContext;
|
|
116
125
|
interface PrismDeferredStripePreparedPayment {
|
|
@@ -130,13 +139,14 @@ interface PrismDeferredPaymentElementProps {
|
|
|
130
139
|
displayPolicy?: "if_required" | PrismStripeDisplayPolicy;
|
|
131
140
|
appearance?: StripeElementsOptions["appearance"];
|
|
132
141
|
classNames?: PrismPaymentElementClassNames;
|
|
142
|
+
errorPresentation?: "inline" | "external";
|
|
133
143
|
submitLabel?: string;
|
|
134
144
|
disabled?: boolean;
|
|
135
145
|
onSubmittingChange?: (submitting: boolean) => void;
|
|
136
146
|
onAuthorized: (outcome: PrismPaymentOutcome) => void | Promise<void>;
|
|
137
147
|
onPending: (outcome: PrismPaymentOutcome) => void | Promise<void>;
|
|
138
148
|
onRequiresAction: (outcome: PrismPaymentOutcome) => void | Promise<void>;
|
|
139
|
-
onError: (error: Error) => void;
|
|
149
|
+
onError: (error: Error, context: PrismPaymentErrorContext) => void;
|
|
140
150
|
}
|
|
141
151
|
interface PrismClickTimePayPalOrder {
|
|
142
152
|
orderId: string;
|
|
@@ -158,4 +168,4 @@ interface PrismClickTimePayPalButtonProps {
|
|
|
158
168
|
}
|
|
159
169
|
type PrismDeferredPaymentSurfaceProps = PrismDeferredPaymentElementProps | PrismClickTimePayPalButtonProps;
|
|
160
170
|
|
|
161
|
-
export type { PrismDeferredPaymentElementProps as P, StripeSupportedTermMethod as S, PrismPaymentElementProps as a, PrismCheckoutProviderContext as b, PrismClickTimePayPalButtonProps as c, PrismClickTimePayPalOrder as d, PrismDeferredPaymentSurfaceProps as e, PrismDeferredStripePreparedPayment as f, PrismPayPalApprovalOutcome as g, PrismPayPalCheckoutProviderContext as h, PrismPayPalPaymentButtonClassNames as i, PrismPayPalPaymentButtonProps as j, PrismPaymentBillingDetails as k,
|
|
171
|
+
export type { PrismDeferredPaymentElementProps as P, StripeSupportedTermMethod as S, PrismPaymentElementProps as a, PrismCheckoutProviderContext as b, PrismClickTimePayPalButtonProps as c, PrismClickTimePayPalOrder as d, PrismDeferredPaymentSurfaceProps as e, PrismDeferredStripePreparedPayment as f, PrismPayPalApprovalOutcome as g, PrismPayPalCheckoutProviderContext as h, PrismPayPalPaymentButtonClassNames as i, PrismPayPalPaymentButtonProps as j, PrismPaymentBillingDetails as k, PrismPaymentErrorContext as l, PrismPaymentErrorPhase as m, PrismPaymentErrorPresentation as n, PrismPaymentOutcome as o, PrismPaymentSurfaceProps as p, PrismPreparedPayPalPaymentSession as q, PrismPreparedPaymentSession as r, PrismPreparedStripePaymentSession as s, PrismStripeCheckoutProviderContext as t, PrismStripeDisplayPolicy as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alphawebai/medusa-custom-payments-react",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.41",
|
|
4
4
|
"description": "AlphaWeb-owned Prism Stripe and PayPal checkout surfaces for Medusa storefronts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|