@alphawebai/medusa-custom-payments-react 0.1.0-rc.49 → 0.1.0-rc.50
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/dist/{chunk-XCUOIQ2U.mjs → chunk-IXQEWGRG.mjs} +67 -26
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/payment-surface.d.mts +2 -2
- package/dist/payment-surface.d.ts +2 -2
- package/dist/payment-surface.js +81 -37
- package/dist/payment-surface.mjs +1 -1
- package/dist/paypal.d.mts +2 -2
- package/dist/paypal.d.ts +2 -2
- package/dist/paypal.js +71 -27
- package/dist/paypal.mjs +1 -1
- package/dist/{types-CzSrJFo2.d.mts → types-Dufdvsa0.d.mts} +2 -0
- package/dist/{types-CzSrJFo2.d.ts → types-Dufdvsa0.d.ts} +2 -0
- package/package.json +1 -1
|
@@ -1,16 +1,56 @@
|
|
|
1
1
|
// src/prism/PrismClickTimePayPalButton.tsx
|
|
2
|
+
import { PayPalProvider } from "@paypal/react-paypal-js/sdk-v6";
|
|
3
|
+
import { useRef as useRef2, useState } from "react";
|
|
4
|
+
|
|
5
|
+
// src/prism/PayPalOneTimePaymentButton.tsx
|
|
2
6
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
7
|
+
usePayPal,
|
|
8
|
+
usePayPalOneTimePaymentSession
|
|
5
9
|
} from "@paypal/react-paypal-js/sdk-v6";
|
|
6
|
-
import {
|
|
10
|
+
import { createElement, useEffect, useRef } from "react";
|
|
11
|
+
function PayPalOneTimePaymentButton({
|
|
12
|
+
type = "pay",
|
|
13
|
+
disabled = false,
|
|
14
|
+
onStartError,
|
|
15
|
+
...hookProps
|
|
16
|
+
}) {
|
|
17
|
+
const errorNotifications = useRef(0);
|
|
18
|
+
const { error, isPending, handleClick } = usePayPalOneTimePaymentSession({
|
|
19
|
+
...hookProps,
|
|
20
|
+
onError: (error2) => {
|
|
21
|
+
errorNotifications.current += 1;
|
|
22
|
+
hookProps.onError?.(error2);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const { isHydrated } = usePayPal();
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (error) console.error(error);
|
|
28
|
+
}, [error]);
|
|
29
|
+
return isHydrated ? createElement("paypal-button", {
|
|
30
|
+
type,
|
|
31
|
+
disabled: disabled || isPending || error !== null ? true : void 0,
|
|
32
|
+
onClick: async () => {
|
|
33
|
+
if (disabled || isPending || error !== null) return;
|
|
34
|
+
const notificationsBeforeStart = errorNotifications.current;
|
|
35
|
+
try {
|
|
36
|
+
await handleClick();
|
|
37
|
+
} catch (error2) {
|
|
38
|
+
if (errorNotifications.current === notificationsBeforeStart) {
|
|
39
|
+
onStartError(error2);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}) : createElement("div", null);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/prism/PrismClickTimePayPalButton.tsx
|
|
7
47
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
48
|
function safeError(value) {
|
|
9
49
|
return value instanceof Error ? value : new Error("PayPal could not complete payment approval.");
|
|
10
50
|
}
|
|
11
51
|
function ClickTimePayPalButton(props) {
|
|
12
|
-
const submittingRef =
|
|
13
|
-
const createdOrderIdRef =
|
|
52
|
+
const submittingRef = useRef2(false);
|
|
53
|
+
const createdOrderIdRef = useRef2(null);
|
|
14
54
|
const [submitting, setSubmittingState] = useState(false);
|
|
15
55
|
const [message, setMessage] = useState(null);
|
|
16
56
|
function setSubmitting(next) {
|
|
@@ -18,6 +58,12 @@ function ClickTimePayPalButton(props) {
|
|
|
18
58
|
setSubmittingState(next);
|
|
19
59
|
props.onSubmittingChange?.(next);
|
|
20
60
|
}
|
|
61
|
+
function handleError(error) {
|
|
62
|
+
const normalized = safeError(error);
|
|
63
|
+
setSubmitting(false);
|
|
64
|
+
setMessage(normalized.message);
|
|
65
|
+
props.onError(normalized);
|
|
66
|
+
}
|
|
21
67
|
return /* @__PURE__ */ jsxs("div", { "aria-busy": submitting, className: props.classNames?.container, children: [
|
|
22
68
|
/* @__PURE__ */ jsx(
|
|
23
69
|
PayPalOneTimePaymentButton,
|
|
@@ -77,15 +123,11 @@ function ClickTimePayPalButton(props) {
|
|
|
77
123
|
orderId: createdOrderIdRef.current
|
|
78
124
|
});
|
|
79
125
|
},
|
|
80
|
-
onError:
|
|
81
|
-
|
|
82
|
-
setSubmitting(false);
|
|
83
|
-
setMessage(normalized.message);
|
|
84
|
-
props.onError(normalized);
|
|
85
|
-
}
|
|
126
|
+
onError: handleError,
|
|
127
|
+
onStartError: handleError
|
|
86
128
|
}
|
|
87
129
|
),
|
|
88
|
-
message ? /* @__PURE__ */ jsx("p", { role: "alert", "aria-live": "assertive", className: props.classNames?.error, children: message }) : null,
|
|
130
|
+
message && props.errorPresentation !== "external" ? /* @__PURE__ */ jsx("p", { role: "alert", "aria-live": "assertive", className: props.classNames?.error, children: message }) : null,
|
|
89
131
|
/* @__PURE__ */ jsx(
|
|
90
132
|
"span",
|
|
91
133
|
{
|
|
@@ -122,17 +164,14 @@ function PrismClickTimePayPalButton(props) {
|
|
|
122
164
|
}
|
|
123
165
|
|
|
124
166
|
// src/prism/PrismPayPalPaymentButton.tsx
|
|
125
|
-
import {
|
|
126
|
-
|
|
127
|
-
PayPalProvider as PayPalProvider2
|
|
128
|
-
} from "@paypal/react-paypal-js/sdk-v6";
|
|
129
|
-
import { useRef as useRef2, useState as useState2 } from "react";
|
|
167
|
+
import { PayPalProvider as PayPalProvider2 } from "@paypal/react-paypal-js/sdk-v6";
|
|
168
|
+
import { useRef as useRef3, useState as useState2 } from "react";
|
|
130
169
|
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
131
170
|
function safeError2(value) {
|
|
132
171
|
return value instanceof Error ? value : new Error("PayPal could not complete payment approval.");
|
|
133
172
|
}
|
|
134
173
|
function PayPalButton(props) {
|
|
135
|
-
const submittingRef =
|
|
174
|
+
const submittingRef = useRef3(false);
|
|
136
175
|
const [submitting, setSubmittingState] = useState2(false);
|
|
137
176
|
const [message, setMessage] = useState2(null);
|
|
138
177
|
function setSubmitting(next) {
|
|
@@ -140,6 +179,12 @@ function PayPalButton(props) {
|
|
|
140
179
|
setSubmittingState(next);
|
|
141
180
|
props.onSubmittingChange?.(next);
|
|
142
181
|
}
|
|
182
|
+
function handleError(error) {
|
|
183
|
+
const normalized = safeError2(error);
|
|
184
|
+
setSubmitting(false);
|
|
185
|
+
setMessage(normalized.message);
|
|
186
|
+
props.onError(normalized);
|
|
187
|
+
}
|
|
143
188
|
return /* @__PURE__ */ jsxs2(
|
|
144
189
|
"div",
|
|
145
190
|
{
|
|
@@ -147,7 +192,7 @@ function PayPalButton(props) {
|
|
|
147
192
|
className: props.classNames?.container,
|
|
148
193
|
children: [
|
|
149
194
|
/* @__PURE__ */ jsx2(
|
|
150
|
-
|
|
195
|
+
PayPalOneTimePaymentButton,
|
|
151
196
|
{
|
|
152
197
|
type: "pay",
|
|
153
198
|
className: props.classNames?.button,
|
|
@@ -191,15 +236,11 @@ function PayPalButton(props) {
|
|
|
191
236
|
orderId: props.session.orderId
|
|
192
237
|
});
|
|
193
238
|
},
|
|
194
|
-
onError:
|
|
195
|
-
|
|
196
|
-
setSubmitting(false);
|
|
197
|
-
setMessage(normalized.message);
|
|
198
|
-
props.onError(normalized);
|
|
199
|
-
}
|
|
239
|
+
onError: handleError,
|
|
240
|
+
onStartError: handleError
|
|
200
241
|
}
|
|
201
242
|
),
|
|
202
|
-
message ? /* @__PURE__ */ jsx2("p", { role: "alert", "aria-live": "assertive", className: props.classNames?.error, children: message }) : null,
|
|
243
|
+
message && props.errorPresentation !== "external" ? /* @__PURE__ */ jsx2("p", { role: "alert", "aria-live": "assertive", className: props.classNames?.error, children: message }) : null,
|
|
203
244
|
/* @__PURE__ */ jsx2(
|
|
204
245
|
"span",
|
|
205
246
|
{
|
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 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-
|
|
2
|
+
import { P as PrismDeferredPaymentElementProps, a as PrismPaymentElementProps } from './types-Dufdvsa0.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-Dufdvsa0.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 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-
|
|
2
|
+
import { P as PrismDeferredPaymentElementProps, a as PrismPaymentElementProps } from './types-Dufdvsa0.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-Dufdvsa0.js';
|
|
4
4
|
import '@stripe/stripe-js';
|
|
5
5
|
|
|
6
6
|
declare function PrismDeferredPaymentElement(props: PrismDeferredPaymentElementProps): react.JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { e as PrismDeferredPaymentSurfaceProps, p as PrismPaymentSurfaceProps } from './types-
|
|
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-
|
|
2
|
+
import { e as PrismDeferredPaymentSurfaceProps, p as PrismPaymentSurfaceProps } from './types-Dufdvsa0.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-Dufdvsa0.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, p as PrismPaymentSurfaceProps } from './types-
|
|
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-
|
|
2
|
+
import { e as PrismDeferredPaymentSurfaceProps, p as PrismPaymentSurfaceProps } from './types-Dufdvsa0.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-Dufdvsa0.js';
|
|
4
4
|
import '@stripe/stripe-js';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/payment-surface.js
CHANGED
|
@@ -26,25 +26,71 @@ __export(payment_surface_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(payment_surface_exports);
|
|
27
27
|
|
|
28
28
|
// src/prism/PrismClickTimePayPalButton.tsx
|
|
29
|
+
var import_sdk_v62 = require("@paypal/react-paypal-js/sdk-v6");
|
|
30
|
+
var import_react2 = require("react");
|
|
31
|
+
|
|
32
|
+
// src/prism/PayPalOneTimePaymentButton.tsx
|
|
29
33
|
var import_sdk_v6 = require("@paypal/react-paypal-js/sdk-v6");
|
|
30
34
|
var import_react = require("react");
|
|
35
|
+
function PayPalOneTimePaymentButton({
|
|
36
|
+
type = "pay",
|
|
37
|
+
disabled = false,
|
|
38
|
+
onStartError,
|
|
39
|
+
...hookProps
|
|
40
|
+
}) {
|
|
41
|
+
const errorNotifications = (0, import_react.useRef)(0);
|
|
42
|
+
const { error, isPending, handleClick } = (0, import_sdk_v6.usePayPalOneTimePaymentSession)({
|
|
43
|
+
...hookProps,
|
|
44
|
+
onError: (error2) => {
|
|
45
|
+
errorNotifications.current += 1;
|
|
46
|
+
hookProps.onError?.(error2);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
const { isHydrated } = (0, import_sdk_v6.usePayPal)();
|
|
50
|
+
(0, import_react.useEffect)(() => {
|
|
51
|
+
if (error) console.error(error);
|
|
52
|
+
}, [error]);
|
|
53
|
+
return isHydrated ? (0, import_react.createElement)("paypal-button", {
|
|
54
|
+
type,
|
|
55
|
+
disabled: disabled || isPending || error !== null ? true : void 0,
|
|
56
|
+
onClick: async () => {
|
|
57
|
+
if (disabled || isPending || error !== null) return;
|
|
58
|
+
const notificationsBeforeStart = errorNotifications.current;
|
|
59
|
+
try {
|
|
60
|
+
await handleClick();
|
|
61
|
+
} catch (error2) {
|
|
62
|
+
if (errorNotifications.current === notificationsBeforeStart) {
|
|
63
|
+
onStartError(error2);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}) : (0, import_react.createElement)("div", null);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/prism/PrismClickTimePayPalButton.tsx
|
|
31
71
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
32
72
|
function safeError(value) {
|
|
33
73
|
return value instanceof Error ? value : new Error("PayPal could not complete payment approval.");
|
|
34
74
|
}
|
|
35
75
|
function ClickTimePayPalButton(props) {
|
|
36
|
-
const submittingRef = (0,
|
|
37
|
-
const createdOrderIdRef = (0,
|
|
38
|
-
const [submitting, setSubmittingState] = (0,
|
|
39
|
-
const [message, setMessage] = (0,
|
|
76
|
+
const submittingRef = (0, import_react2.useRef)(false);
|
|
77
|
+
const createdOrderIdRef = (0, import_react2.useRef)(null);
|
|
78
|
+
const [submitting, setSubmittingState] = (0, import_react2.useState)(false);
|
|
79
|
+
const [message, setMessage] = (0, import_react2.useState)(null);
|
|
40
80
|
function setSubmitting(next) {
|
|
41
81
|
submittingRef.current = next;
|
|
42
82
|
setSubmittingState(next);
|
|
43
83
|
props.onSubmittingChange?.(next);
|
|
44
84
|
}
|
|
85
|
+
function handleError(error) {
|
|
86
|
+
const normalized = safeError(error);
|
|
87
|
+
setSubmitting(false);
|
|
88
|
+
setMessage(normalized.message);
|
|
89
|
+
props.onError(normalized);
|
|
90
|
+
}
|
|
45
91
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { "aria-busy": submitting, className: props.classNames?.container, children: [
|
|
46
92
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
47
|
-
|
|
93
|
+
PayPalOneTimePaymentButton,
|
|
48
94
|
{
|
|
49
95
|
type: "pay",
|
|
50
96
|
className: props.classNames?.button,
|
|
@@ -101,15 +147,11 @@ function ClickTimePayPalButton(props) {
|
|
|
101
147
|
orderId: createdOrderIdRef.current
|
|
102
148
|
});
|
|
103
149
|
},
|
|
104
|
-
onError:
|
|
105
|
-
|
|
106
|
-
setSubmitting(false);
|
|
107
|
-
setMessage(normalized.message);
|
|
108
|
-
props.onError(normalized);
|
|
109
|
-
}
|
|
150
|
+
onError: handleError,
|
|
151
|
+
onStartError: handleError
|
|
110
152
|
}
|
|
111
153
|
),
|
|
112
|
-
message ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { role: "alert", "aria-live": "assertive", className: props.classNames?.error, children: message }) : null,
|
|
154
|
+
message && props.errorPresentation !== "external" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { role: "alert", "aria-live": "assertive", className: props.classNames?.error, children: message }) : null,
|
|
113
155
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
114
156
|
"span",
|
|
115
157
|
{
|
|
@@ -133,7 +175,7 @@ function PrismClickTimePayPalButton(props) {
|
|
|
133
175
|
throw new Error("Prism PayPal checkout context is invalid.");
|
|
134
176
|
}
|
|
135
177
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
136
|
-
|
|
178
|
+
import_sdk_v62.PayPalProvider,
|
|
137
179
|
{
|
|
138
180
|
clientId: props.context.clientId,
|
|
139
181
|
environment: props.context.environment,
|
|
@@ -148,7 +190,7 @@ function PrismClickTimePayPalButton(props) {
|
|
|
148
190
|
// src/prism/PrismDeferredPaymentElement.tsx
|
|
149
191
|
var import_react_stripe_js = require("@stripe/react-stripe-js");
|
|
150
192
|
var import_stripe_js = require("@stripe/stripe-js");
|
|
151
|
-
var
|
|
193
|
+
var import_react3 = require("react");
|
|
152
194
|
|
|
153
195
|
// src/prism/outcome.ts
|
|
154
196
|
function normalizeStripePaymentIntent(paymentIntent) {
|
|
@@ -277,9 +319,9 @@ async function dispatchOutcome(outcome, callbacks) {
|
|
|
277
319
|
function DeferredPaymentElementForm(props) {
|
|
278
320
|
const stripe = (0, import_react_stripe_js.useStripe)();
|
|
279
321
|
const elements = (0, import_react_stripe_js.useElements)();
|
|
280
|
-
const [ready, setReady] = (0,
|
|
281
|
-
const [submitting, setSubmitting] = (0,
|
|
282
|
-
const [message, setMessage] = (0,
|
|
322
|
+
const [ready, setReady] = (0, import_react3.useState)(false);
|
|
323
|
+
const [submitting, setSubmitting] = (0, import_react3.useState)(false);
|
|
324
|
+
const [message, setMessage] = (0, import_react3.useState)(null);
|
|
283
325
|
const callbacks = {
|
|
284
326
|
onAuthorized: props.onAuthorized,
|
|
285
327
|
onPending: props.onPending,
|
|
@@ -432,7 +474,7 @@ function deferredStripeElementsContract(props) {
|
|
|
432
474
|
}
|
|
433
475
|
function PrismDeferredPaymentElement(props) {
|
|
434
476
|
const validationError = props.connector !== "stripe" || props.context.connector !== "stripe" ? "Unsupported Prism payment connector." : props.context.providerId !== "pp_hyperswitch-prism_stripe" || !/^pk_(test|live)_/.test(props.context.publishableKey) || !Number.isSafeInteger(props.amountMinor) || props.amountMinor <= 0 || !/^[a-z]{3}$/.test(props.currency) ? "Prism Stripe checkout context is invalid." : null;
|
|
435
|
-
const stripe = (0,
|
|
477
|
+
const stripe = (0, import_react3.useMemo)(
|
|
436
478
|
() => validationError ? null : stripePromise(props.context.publishableKey),
|
|
437
479
|
[props.context.publishableKey, validationError]
|
|
438
480
|
);
|
|
@@ -451,21 +493,27 @@ function PrismDeferredPaymentSurface(props) {
|
|
|
451
493
|
}
|
|
452
494
|
|
|
453
495
|
// src/prism/PrismPayPalPaymentButton.tsx
|
|
454
|
-
var
|
|
455
|
-
var
|
|
496
|
+
var import_sdk_v63 = require("@paypal/react-paypal-js/sdk-v6");
|
|
497
|
+
var import_react4 = require("react");
|
|
456
498
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
457
499
|
function safeError2(value) {
|
|
458
500
|
return value instanceof Error ? value : new Error("PayPal could not complete payment approval.");
|
|
459
501
|
}
|
|
460
502
|
function PayPalButton(props) {
|
|
461
|
-
const submittingRef = (0,
|
|
462
|
-
const [submitting, setSubmittingState] = (0,
|
|
463
|
-
const [message, setMessage] = (0,
|
|
503
|
+
const submittingRef = (0, import_react4.useRef)(false);
|
|
504
|
+
const [submitting, setSubmittingState] = (0, import_react4.useState)(false);
|
|
505
|
+
const [message, setMessage] = (0, import_react4.useState)(null);
|
|
464
506
|
function setSubmitting(next) {
|
|
465
507
|
submittingRef.current = next;
|
|
466
508
|
setSubmittingState(next);
|
|
467
509
|
props.onSubmittingChange?.(next);
|
|
468
510
|
}
|
|
511
|
+
function handleError(error) {
|
|
512
|
+
const normalized = safeError2(error);
|
|
513
|
+
setSubmitting(false);
|
|
514
|
+
setMessage(normalized.message);
|
|
515
|
+
props.onError(normalized);
|
|
516
|
+
}
|
|
469
517
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
470
518
|
"div",
|
|
471
519
|
{
|
|
@@ -473,7 +521,7 @@ function PayPalButton(props) {
|
|
|
473
521
|
className: props.classNames?.container,
|
|
474
522
|
children: [
|
|
475
523
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
476
|
-
|
|
524
|
+
PayPalOneTimePaymentButton,
|
|
477
525
|
{
|
|
478
526
|
type: "pay",
|
|
479
527
|
className: props.classNames?.button,
|
|
@@ -517,15 +565,11 @@ function PayPalButton(props) {
|
|
|
517
565
|
orderId: props.session.orderId
|
|
518
566
|
});
|
|
519
567
|
},
|
|
520
|
-
onError:
|
|
521
|
-
|
|
522
|
-
setSubmitting(false);
|
|
523
|
-
setMessage(normalized.message);
|
|
524
|
-
props.onError(normalized);
|
|
525
|
-
}
|
|
568
|
+
onError: handleError,
|
|
569
|
+
onStartError: handleError
|
|
526
570
|
}
|
|
527
571
|
),
|
|
528
|
-
message ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { role: "alert", "aria-live": "assertive", className: props.classNames?.error, children: message }) : null,
|
|
572
|
+
message && props.errorPresentation !== "external" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { role: "alert", "aria-live": "assertive", className: props.classNames?.error, children: message }) : null,
|
|
529
573
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
530
574
|
"span",
|
|
531
575
|
{
|
|
@@ -551,7 +595,7 @@ function PrismPayPalPaymentButton(props) {
|
|
|
551
595
|
throw new Error("Prism PayPal payment session is invalid.");
|
|
552
596
|
}
|
|
553
597
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
554
|
-
|
|
598
|
+
import_sdk_v63.PayPalProvider,
|
|
555
599
|
{
|
|
556
600
|
clientId: props.session.clientId,
|
|
557
601
|
environment: props.session.environment,
|
|
@@ -566,7 +610,7 @@ function PrismPayPalPaymentButton(props) {
|
|
|
566
610
|
// src/prism/PrismPaymentElement.tsx
|
|
567
611
|
var import_react_stripe_js2 = require("@stripe/react-stripe-js");
|
|
568
612
|
var import_stripe_js2 = require("@stripe/stripe-js");
|
|
569
|
-
var
|
|
613
|
+
var import_react5 = require("react");
|
|
570
614
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
571
615
|
var stripeByPublishableKey2 = /* @__PURE__ */ new Map();
|
|
572
616
|
function stripePromise2(publishableKey) {
|
|
@@ -618,9 +662,9 @@ async function dispatchOutcome2(outcome, callbacks) {
|
|
|
618
662
|
function PaymentElementForm(props) {
|
|
619
663
|
const stripe = (0, import_react_stripe_js2.useStripe)();
|
|
620
664
|
const elements = (0, import_react_stripe_js2.useElements)();
|
|
621
|
-
const [ready, setReady] = (0,
|
|
622
|
-
const [submitting, setSubmitting] = (0,
|
|
623
|
-
const [message, setMessage] = (0,
|
|
665
|
+
const [ready, setReady] = (0, import_react5.useState)(false);
|
|
666
|
+
const [submitting, setSubmitting] = (0, import_react5.useState)(false);
|
|
667
|
+
const [message, setMessage] = (0, import_react5.useState)(null);
|
|
624
668
|
const callbacks = {
|
|
625
669
|
onAuthorized: props.onAuthorized,
|
|
626
670
|
onPending: props.onPending,
|
|
@@ -738,7 +782,7 @@ function PaymentElementForm(props) {
|
|
|
738
782
|
}
|
|
739
783
|
function PrismPaymentElement(props) {
|
|
740
784
|
const validationError = props.connector !== "stripe" || props.session.connector !== "stripe" ? "Unsupported Prism payment connector." : props.session.providerId !== "pp_hyperswitch-prism_stripe" || !props.session.clientSecret.startsWith("pi_") || !props.session.clientSecret.includes("_secret_") || !/^pk_(test|live)_/.test(props.session.publishableKey) ? "Prism Stripe payment session is invalid." : null;
|
|
741
|
-
const stripe = (0,
|
|
785
|
+
const stripe = (0, import_react5.useMemo)(
|
|
742
786
|
() => validationError ? null : stripePromise2(props.session.publishableKey),
|
|
743
787
|
[props.session.publishableKey, validationError]
|
|
744
788
|
);
|
package/dist/payment-surface.mjs
CHANGED
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, q as PrismPreparedPayPalPaymentSession } from './types-
|
|
2
|
+
import { c as PrismClickTimePayPalButtonProps, j as PrismPayPalPaymentButtonProps } from './types-Dufdvsa0.mjs';
|
|
3
|
+
export { d as PrismClickTimePayPalOrder, g as PrismPayPalApprovalOutcome, h as PrismPayPalCheckoutProviderContext, i as PrismPayPalPaymentButtonClassNames, q as PrismPreparedPayPalPaymentSession } from './types-Dufdvsa0.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, q as PrismPreparedPayPalPaymentSession } from './types-
|
|
2
|
+
import { c as PrismClickTimePayPalButtonProps, j as PrismPayPalPaymentButtonProps } from './types-Dufdvsa0.js';
|
|
3
|
+
export { d as PrismClickTimePayPalOrder, g as PrismPayPalApprovalOutcome, h as PrismPayPalCheckoutProviderContext, i as PrismPayPalPaymentButtonClassNames, q as PrismPreparedPayPalPaymentSession } from './types-Dufdvsa0.js';
|
|
4
4
|
import '@stripe/stripe-js';
|
|
5
5
|
|
|
6
6
|
declare function PrismClickTimePayPalButton(props: PrismClickTimePayPalButtonProps): react.JSX.Element;
|
package/dist/paypal.js
CHANGED
|
@@ -26,25 +26,71 @@ __export(paypal_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(paypal_exports);
|
|
27
27
|
|
|
28
28
|
// src/prism/PrismClickTimePayPalButton.tsx
|
|
29
|
+
var import_sdk_v62 = require("@paypal/react-paypal-js/sdk-v6");
|
|
30
|
+
var import_react2 = require("react");
|
|
31
|
+
|
|
32
|
+
// src/prism/PayPalOneTimePaymentButton.tsx
|
|
29
33
|
var import_sdk_v6 = require("@paypal/react-paypal-js/sdk-v6");
|
|
30
34
|
var import_react = require("react");
|
|
35
|
+
function PayPalOneTimePaymentButton({
|
|
36
|
+
type = "pay",
|
|
37
|
+
disabled = false,
|
|
38
|
+
onStartError,
|
|
39
|
+
...hookProps
|
|
40
|
+
}) {
|
|
41
|
+
const errorNotifications = (0, import_react.useRef)(0);
|
|
42
|
+
const { error, isPending, handleClick } = (0, import_sdk_v6.usePayPalOneTimePaymentSession)({
|
|
43
|
+
...hookProps,
|
|
44
|
+
onError: (error2) => {
|
|
45
|
+
errorNotifications.current += 1;
|
|
46
|
+
hookProps.onError?.(error2);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
const { isHydrated } = (0, import_sdk_v6.usePayPal)();
|
|
50
|
+
(0, import_react.useEffect)(() => {
|
|
51
|
+
if (error) console.error(error);
|
|
52
|
+
}, [error]);
|
|
53
|
+
return isHydrated ? (0, import_react.createElement)("paypal-button", {
|
|
54
|
+
type,
|
|
55
|
+
disabled: disabled || isPending || error !== null ? true : void 0,
|
|
56
|
+
onClick: async () => {
|
|
57
|
+
if (disabled || isPending || error !== null) return;
|
|
58
|
+
const notificationsBeforeStart = errorNotifications.current;
|
|
59
|
+
try {
|
|
60
|
+
await handleClick();
|
|
61
|
+
} catch (error2) {
|
|
62
|
+
if (errorNotifications.current === notificationsBeforeStart) {
|
|
63
|
+
onStartError(error2);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}) : (0, import_react.createElement)("div", null);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/prism/PrismClickTimePayPalButton.tsx
|
|
31
71
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
32
72
|
function safeError(value) {
|
|
33
73
|
return value instanceof Error ? value : new Error("PayPal could not complete payment approval.");
|
|
34
74
|
}
|
|
35
75
|
function ClickTimePayPalButton(props) {
|
|
36
|
-
const submittingRef = (0,
|
|
37
|
-
const createdOrderIdRef = (0,
|
|
38
|
-
const [submitting, setSubmittingState] = (0,
|
|
39
|
-
const [message, setMessage] = (0,
|
|
76
|
+
const submittingRef = (0, import_react2.useRef)(false);
|
|
77
|
+
const createdOrderIdRef = (0, import_react2.useRef)(null);
|
|
78
|
+
const [submitting, setSubmittingState] = (0, import_react2.useState)(false);
|
|
79
|
+
const [message, setMessage] = (0, import_react2.useState)(null);
|
|
40
80
|
function setSubmitting(next) {
|
|
41
81
|
submittingRef.current = next;
|
|
42
82
|
setSubmittingState(next);
|
|
43
83
|
props.onSubmittingChange?.(next);
|
|
44
84
|
}
|
|
85
|
+
function handleError(error) {
|
|
86
|
+
const normalized = safeError(error);
|
|
87
|
+
setSubmitting(false);
|
|
88
|
+
setMessage(normalized.message);
|
|
89
|
+
props.onError(normalized);
|
|
90
|
+
}
|
|
45
91
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { "aria-busy": submitting, className: props.classNames?.container, children: [
|
|
46
92
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
47
|
-
|
|
93
|
+
PayPalOneTimePaymentButton,
|
|
48
94
|
{
|
|
49
95
|
type: "pay",
|
|
50
96
|
className: props.classNames?.button,
|
|
@@ -101,15 +147,11 @@ function ClickTimePayPalButton(props) {
|
|
|
101
147
|
orderId: createdOrderIdRef.current
|
|
102
148
|
});
|
|
103
149
|
},
|
|
104
|
-
onError:
|
|
105
|
-
|
|
106
|
-
setSubmitting(false);
|
|
107
|
-
setMessage(normalized.message);
|
|
108
|
-
props.onError(normalized);
|
|
109
|
-
}
|
|
150
|
+
onError: handleError,
|
|
151
|
+
onStartError: handleError
|
|
110
152
|
}
|
|
111
153
|
),
|
|
112
|
-
message ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { role: "alert", "aria-live": "assertive", className: props.classNames?.error, children: message }) : null,
|
|
154
|
+
message && props.errorPresentation !== "external" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { role: "alert", "aria-live": "assertive", className: props.classNames?.error, children: message }) : null,
|
|
113
155
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
114
156
|
"span",
|
|
115
157
|
{
|
|
@@ -133,7 +175,7 @@ function PrismClickTimePayPalButton(props) {
|
|
|
133
175
|
throw new Error("Prism PayPal checkout context is invalid.");
|
|
134
176
|
}
|
|
135
177
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
136
|
-
|
|
178
|
+
import_sdk_v62.PayPalProvider,
|
|
137
179
|
{
|
|
138
180
|
clientId: props.context.clientId,
|
|
139
181
|
environment: props.context.environment,
|
|
@@ -146,21 +188,27 @@ function PrismClickTimePayPalButton(props) {
|
|
|
146
188
|
}
|
|
147
189
|
|
|
148
190
|
// src/prism/PrismPayPalPaymentButton.tsx
|
|
149
|
-
var
|
|
150
|
-
var
|
|
191
|
+
var import_sdk_v63 = require("@paypal/react-paypal-js/sdk-v6");
|
|
192
|
+
var import_react3 = require("react");
|
|
151
193
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
152
194
|
function safeError2(value) {
|
|
153
195
|
return value instanceof Error ? value : new Error("PayPal could not complete payment approval.");
|
|
154
196
|
}
|
|
155
197
|
function PayPalButton(props) {
|
|
156
|
-
const submittingRef = (0,
|
|
157
|
-
const [submitting, setSubmittingState] = (0,
|
|
158
|
-
const [message, setMessage] = (0,
|
|
198
|
+
const submittingRef = (0, import_react3.useRef)(false);
|
|
199
|
+
const [submitting, setSubmittingState] = (0, import_react3.useState)(false);
|
|
200
|
+
const [message, setMessage] = (0, import_react3.useState)(null);
|
|
159
201
|
function setSubmitting(next) {
|
|
160
202
|
submittingRef.current = next;
|
|
161
203
|
setSubmittingState(next);
|
|
162
204
|
props.onSubmittingChange?.(next);
|
|
163
205
|
}
|
|
206
|
+
function handleError(error) {
|
|
207
|
+
const normalized = safeError2(error);
|
|
208
|
+
setSubmitting(false);
|
|
209
|
+
setMessage(normalized.message);
|
|
210
|
+
props.onError(normalized);
|
|
211
|
+
}
|
|
164
212
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
165
213
|
"div",
|
|
166
214
|
{
|
|
@@ -168,7 +216,7 @@ function PayPalButton(props) {
|
|
|
168
216
|
className: props.classNames?.container,
|
|
169
217
|
children: [
|
|
170
218
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
171
|
-
|
|
219
|
+
PayPalOneTimePaymentButton,
|
|
172
220
|
{
|
|
173
221
|
type: "pay",
|
|
174
222
|
className: props.classNames?.button,
|
|
@@ -212,15 +260,11 @@ function PayPalButton(props) {
|
|
|
212
260
|
orderId: props.session.orderId
|
|
213
261
|
});
|
|
214
262
|
},
|
|
215
|
-
onError:
|
|
216
|
-
|
|
217
|
-
setSubmitting(false);
|
|
218
|
-
setMessage(normalized.message);
|
|
219
|
-
props.onError(normalized);
|
|
220
|
-
}
|
|
263
|
+
onError: handleError,
|
|
264
|
+
onStartError: handleError
|
|
221
265
|
}
|
|
222
266
|
),
|
|
223
|
-
message ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { role: "alert", "aria-live": "assertive", className: props.classNames?.error, children: message }) : null,
|
|
267
|
+
message && props.errorPresentation !== "external" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { role: "alert", "aria-live": "assertive", className: props.classNames?.error, children: message }) : null,
|
|
224
268
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
225
269
|
"span",
|
|
226
270
|
{
|
|
@@ -246,7 +290,7 @@ function PrismPayPalPaymentButton(props) {
|
|
|
246
290
|
throw new Error("Prism PayPal payment session is invalid.");
|
|
247
291
|
}
|
|
248
292
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
249
|
-
|
|
293
|
+
import_sdk_v63.PayPalProvider,
|
|
250
294
|
{
|
|
251
295
|
clientId: props.session.clientId,
|
|
252
296
|
environment: props.session.environment,
|
package/dist/paypal.mjs
CHANGED
|
@@ -97,6 +97,7 @@ interface PrismPayPalPaymentButtonProps {
|
|
|
97
97
|
connector: "paypal";
|
|
98
98
|
intent: "checkout";
|
|
99
99
|
classNames?: PrismPayPalPaymentButtonClassNames;
|
|
100
|
+
errorPresentation?: "inline" | "external";
|
|
100
101
|
disabled?: boolean;
|
|
101
102
|
onSubmittingChange?: (submitting: boolean) => void;
|
|
102
103
|
onProviderApproved: (outcome: PrismPayPalApprovalOutcome) => void | Promise<void>;
|
|
@@ -157,6 +158,7 @@ interface PrismClickTimePayPalButtonProps {
|
|
|
157
158
|
intent: "checkout";
|
|
158
159
|
onCreateOrder: () => Promise<PrismClickTimePayPalOrder>;
|
|
159
160
|
classNames?: PrismPayPalPaymentButtonClassNames;
|
|
161
|
+
errorPresentation?: "inline" | "external";
|
|
160
162
|
disabled?: boolean;
|
|
161
163
|
onSubmittingChange?: (submitting: boolean) => void;
|
|
162
164
|
onProviderApproved: (outcome: PrismPayPalApprovalOutcome) => void | Promise<void>;
|
|
@@ -97,6 +97,7 @@ interface PrismPayPalPaymentButtonProps {
|
|
|
97
97
|
connector: "paypal";
|
|
98
98
|
intent: "checkout";
|
|
99
99
|
classNames?: PrismPayPalPaymentButtonClassNames;
|
|
100
|
+
errorPresentation?: "inline" | "external";
|
|
100
101
|
disabled?: boolean;
|
|
101
102
|
onSubmittingChange?: (submitting: boolean) => void;
|
|
102
103
|
onProviderApproved: (outcome: PrismPayPalApprovalOutcome) => void | Promise<void>;
|
|
@@ -157,6 +158,7 @@ interface PrismClickTimePayPalButtonProps {
|
|
|
157
158
|
intent: "checkout";
|
|
158
159
|
onCreateOrder: () => Promise<PrismClickTimePayPalOrder>;
|
|
159
160
|
classNames?: PrismPayPalPaymentButtonClassNames;
|
|
161
|
+
errorPresentation?: "inline" | "external";
|
|
160
162
|
disabled?: boolean;
|
|
161
163
|
onSubmittingChange?: (submitting: boolean) => void;
|
|
162
164
|
onProviderApproved: (outcome: PrismPayPalApprovalOutcome) => void | Promise<void>;
|
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.50",
|
|
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",
|