@superlogic/spree-pay 0.1.8 → 0.1.10
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 +3 -2
- package/build/index.cjs +46 -28
- package/build/index.d.cts +10 -5
- package/build/index.d.ts +10 -5
- package/build/index.js +49 -31
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ npm i @superlogic/spree-pay
|
|
|
14
14
|
import { useState } from 'react';
|
|
15
15
|
|
|
16
16
|
import { SpreePay, SpreePayProvider, useSpreePay } from '@superlogic/spree-pay';
|
|
17
|
+
import '@superlogic/spree-pay/styles.css';
|
|
17
18
|
|
|
18
19
|
const spreeEnv = {
|
|
19
20
|
tenantId: 'moca' // Keep moca for crypto payments on BASE network
|
|
@@ -31,7 +32,7 @@ function Checkout() {
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
function CheckoutContent() {
|
|
34
|
-
const { process } = useSpreePay(); // Access payment process function (must be inside provider)
|
|
35
|
+
const { process, selectedPaymentMethod, isProcessing } = useSpreePay(); // Access payment process function and processing state (must be inside provider)
|
|
35
36
|
const [status, setStatus] = useState<'idle' | 'processing' | 'success' | 'error'>('idle');
|
|
36
37
|
|
|
37
38
|
async function handleProcess() {
|
|
@@ -48,7 +49,7 @@ function CheckoutContent() {
|
|
|
48
49
|
|
|
49
50
|
return (
|
|
50
51
|
<div style={{ maxWidth: 540 }}>
|
|
51
|
-
<SpreePay amount={99} onProcess={handleProcess} />
|
|
52
|
+
<SpreePay isLoading={status === 'processing'} amount={99} onProcess={handleProcess} />
|
|
52
53
|
{status === 'success' && <p>Payment successful! Thank you for your order.</p>}
|
|
53
54
|
{status === 'error' && <p>Payment failed. Please try again.</p>}
|
|
54
55
|
</div>
|
package/build/index.cjs
CHANGED
|
@@ -316,7 +316,8 @@ function Dialog({ ...props }) {
|
|
|
316
316
|
}
|
|
317
317
|
function DialogPortal({ ...props }) {
|
|
318
318
|
const container = usePortalContainer();
|
|
319
|
-
|
|
319
|
+
const safeContainer = container && document.body.contains(container) ? container : void 0;
|
|
320
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(DialogPrimitive.Portal, { container: safeContainer, "data-slot": "dialog-portal", ...props });
|
|
320
321
|
}
|
|
321
322
|
function DialogOverlay({ className, ...props }) {
|
|
322
323
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
@@ -527,14 +528,14 @@ var SlapiPaymentService = {
|
|
|
527
528
|
// return coin.balance > outAmountNumber;
|
|
528
529
|
// },
|
|
529
530
|
createPayment: (params) => {
|
|
530
|
-
const { type, hash } = params;
|
|
531
|
+
const { type, hash, metadata, capture = false } = params;
|
|
531
532
|
let reqParams;
|
|
532
533
|
if (type === "CRYPTO" /* CRYPTO */) {
|
|
533
534
|
reqParams = { type, hash, crypto: params.crypto };
|
|
534
535
|
} else {
|
|
535
536
|
reqParams = { type, hash, card: params.card };
|
|
536
537
|
}
|
|
537
|
-
return slapiApi.post("/v1/payments", { ...reqParams, capture
|
|
538
|
+
return slapiApi.post("/v1/payments", { ...reqParams, capture, metadata }).then((data) => ({ data }));
|
|
538
539
|
},
|
|
539
540
|
baseVerify: ({ id, txHash }) => {
|
|
540
541
|
return slapiApi.post(`/v1/base-transactions/transactions/${id}/verify`, { txHash });
|
|
@@ -561,7 +562,13 @@ var SlapiPaymentService = {
|
|
|
561
562
|
};
|
|
562
563
|
|
|
563
564
|
// src/services/cardPayment.ts
|
|
564
|
-
var cardPayment = async ({
|
|
565
|
+
var cardPayment = async ({
|
|
566
|
+
card,
|
|
567
|
+
hash,
|
|
568
|
+
redirect3dsURI,
|
|
569
|
+
metadata,
|
|
570
|
+
capture
|
|
571
|
+
}) => {
|
|
565
572
|
let cardId = card.id;
|
|
566
573
|
if ("token" in card) {
|
|
567
574
|
const { data: cardResData } = await SlapiPaymentService.addCard({ hash, source: card.token });
|
|
@@ -570,6 +577,8 @@ var cardPayment = async ({ card, hash, redirect3dsURI }) => {
|
|
|
570
577
|
const { data: paymentResData } = await SlapiPaymentService.createPayment({
|
|
571
578
|
hash,
|
|
572
579
|
type: "CREDIT_CARD" /* CREDIT_CARD */,
|
|
580
|
+
metadata,
|
|
581
|
+
capture,
|
|
573
582
|
card: { cardId, returnUrl: `${window.location.origin}${redirect3dsURI}` }
|
|
574
583
|
});
|
|
575
584
|
if (paymentResData.redirectUrl) {
|
|
@@ -577,13 +586,18 @@ var cardPayment = async ({ card, hash, redirect3dsURI }) => {
|
|
|
577
586
|
if (paymentIntent) {
|
|
578
587
|
const { data: validateData } = await SlapiPaymentService.validate3DS({ paymentId: paymentResData.id });
|
|
579
588
|
return {
|
|
580
|
-
status: validateData.status
|
|
589
|
+
status: validateData.status,
|
|
590
|
+
paymentId: paymentResData.id,
|
|
591
|
+
txId: paymentResData.txId,
|
|
592
|
+
txHash: null
|
|
581
593
|
};
|
|
582
594
|
}
|
|
583
595
|
}
|
|
584
596
|
return {
|
|
585
597
|
status: paymentResData.status,
|
|
586
|
-
paymentId: paymentResData.id
|
|
598
|
+
paymentId: paymentResData.id,
|
|
599
|
+
txId: paymentResData.txId,
|
|
600
|
+
txHash: null
|
|
587
601
|
};
|
|
588
602
|
};
|
|
589
603
|
|
|
@@ -996,8 +1010,8 @@ var CreditCardTab = () => {
|
|
|
996
1010
|
try {
|
|
997
1011
|
if (selectedPaymentMethod.type === "CREDIT_CARD" /* CREDIT_CARD */ && selectedPaymentMethod.method) {
|
|
998
1012
|
const res = await cardPayment({
|
|
1013
|
+
...data,
|
|
999
1014
|
card: selectedPaymentMethod.method,
|
|
1000
|
-
hash: data.hash,
|
|
1001
1015
|
redirect3dsURI: env.redirect3dsURI
|
|
1002
1016
|
});
|
|
1003
1017
|
if (["AUTHORIZED" /* AUTHORIZED */, "CAPTURED" /* CAPTURED */].includes(res.status)) {
|
|
@@ -1157,7 +1171,7 @@ var useCryptoPayment = () => {
|
|
|
1157
1171
|
const { data: walletClient } = (0, import_wagmi.useWalletClient)();
|
|
1158
1172
|
const config2 = (0, import_wagmi.useConfig)();
|
|
1159
1173
|
const { selectedPaymentMethod } = useSpreePaymentMethod();
|
|
1160
|
-
const cryptoPayment = async (
|
|
1174
|
+
const cryptoPayment = async (params) => {
|
|
1161
1175
|
if (!walletClient) {
|
|
1162
1176
|
throw new Error("Wallet not connected");
|
|
1163
1177
|
}
|
|
@@ -1191,8 +1205,8 @@ var useCryptoPayment = () => {
|
|
|
1191
1205
|
}
|
|
1192
1206
|
}
|
|
1193
1207
|
const paymentRes = await SlapiPaymentService.createPayment({
|
|
1208
|
+
...params,
|
|
1194
1209
|
type: "CRYPTO" /* CRYPTO */,
|
|
1195
|
-
hash,
|
|
1196
1210
|
crypto: {
|
|
1197
1211
|
token: TOKEN,
|
|
1198
1212
|
publicKey: walletClient.account.address,
|
|
@@ -1210,7 +1224,8 @@ var useCryptoPayment = () => {
|
|
|
1210
1224
|
const res = await SlapiPaymentService.baseVerify({ id: paymentRes.data.txId, txHash });
|
|
1211
1225
|
return {
|
|
1212
1226
|
txHash,
|
|
1213
|
-
paymentId: paymentRes.data.
|
|
1227
|
+
paymentId: paymentRes.data.id,
|
|
1228
|
+
txId: paymentRes.data.txId,
|
|
1214
1229
|
status: res.verified ? "AUTHORIZED" /* AUTHORIZED */ : "FAILED" /* FAILED */
|
|
1215
1230
|
};
|
|
1216
1231
|
};
|
|
@@ -1589,7 +1604,7 @@ var Crypto = () => {
|
|
|
1589
1604
|
const handlePay = (0, import_react8.useCallback)(
|
|
1590
1605
|
async (data) => {
|
|
1591
1606
|
try {
|
|
1592
|
-
const res = await cryptoPayment(
|
|
1607
|
+
const res = await cryptoPayment(data);
|
|
1593
1608
|
if (["AUTHORIZED" /* AUTHORIZED */, "CAPTURED" /* CAPTURED */].includes(res.status)) {
|
|
1594
1609
|
return Promise.resolve(res);
|
|
1595
1610
|
}
|
|
@@ -1846,7 +1861,7 @@ var envConfig = {
|
|
|
1846
1861
|
var SpreePay = ({ className, ...rest }) => {
|
|
1847
1862
|
const rootRef = (0, import_react10.useRef)(null);
|
|
1848
1863
|
const [portalEl, setPortalEl] = (0, import_react10.useState)(null);
|
|
1849
|
-
(0, import_react10.
|
|
1864
|
+
(0, import_react10.useLayoutEffect)(() => {
|
|
1850
1865
|
if (!rootRef.current) return;
|
|
1851
1866
|
const el = rootRef.current.querySelector(":scope > .sl-spreepay__portal");
|
|
1852
1867
|
setPortalEl(el ?? null);
|
|
@@ -1855,11 +1870,11 @@ var SpreePay = ({ className, ...rest }) => {
|
|
|
1855
1870
|
const environment = env?.environment || "dev";
|
|
1856
1871
|
const tenantId = env?.tenantId || "bookit";
|
|
1857
1872
|
const { isChecking, accessToken, error } = useKeycloakSSO({
|
|
1858
|
-
realm:
|
|
1873
|
+
realm: tenantId,
|
|
1859
1874
|
url: envConfig[environment][tenantId].keyklockUrl,
|
|
1860
1875
|
clientId: envConfig[environment][tenantId].keyklockClientId,
|
|
1861
|
-
ssoPageURI: env
|
|
1862
|
-
enabled: !env
|
|
1876
|
+
ssoPageURI: env?.ssoPageURI,
|
|
1877
|
+
enabled: !env?.accessToken
|
|
1863
1878
|
});
|
|
1864
1879
|
const slapiFetcher = (0, import_react10.useMemo)(() => {
|
|
1865
1880
|
if (accessToken || env.accessToken) {
|
|
@@ -1870,18 +1885,17 @@ var SpreePay = ({ className, ...rest }) => {
|
|
|
1870
1885
|
});
|
|
1871
1886
|
}
|
|
1872
1887
|
}, [env.accessToken, environment, tenantId, accessToken]);
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
"
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
1884
|
-
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
1888
|
+
const getContent = () => {
|
|
1889
|
+
if (isChecking) {
|
|
1890
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("p", { className: "w-full text-center text-sm", children: "Loading..." });
|
|
1891
|
+
}
|
|
1892
|
+
if (error) {
|
|
1893
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("p", { className: "w-full text-center text-sm", children: [
|
|
1894
|
+
"Error: ",
|
|
1895
|
+
error.message
|
|
1896
|
+
] });
|
|
1897
|
+
}
|
|
1898
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
1885
1899
|
import_swr4.SWRConfig,
|
|
1886
1900
|
{
|
|
1887
1901
|
value: {
|
|
@@ -1892,7 +1906,11 @@ var SpreePay = ({ className, ...rest }) => {
|
|
|
1892
1906
|
},
|
|
1893
1907
|
children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(PortalContainerProvider, { container: portalEl, children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_nice_modal_react6.default.Provider, { children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(SpreePayContent, { ...rest }) }) })
|
|
1894
1908
|
}
|
|
1895
|
-
)
|
|
1909
|
+
);
|
|
1910
|
+
};
|
|
1911
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { ref: rootRef, className: cn("sl-spreepay", className), children: [
|
|
1912
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: "sl-spreepay__portal" }),
|
|
1913
|
+
getContent()
|
|
1896
1914
|
] });
|
|
1897
1915
|
};
|
|
1898
1916
|
|
package/build/index.d.cts
CHANGED
|
@@ -93,9 +93,16 @@ declare const enum SlapiPaymentStatus {
|
|
|
93
93
|
}
|
|
94
94
|
type PaymentMethodResult = {
|
|
95
95
|
status: SlapiPaymentStatus;
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
paymentId: string;
|
|
97
|
+
txHash: string | null;
|
|
98
|
+
txId: string | null;
|
|
98
99
|
};
|
|
100
|
+
type ProcessFnParams = {
|
|
101
|
+
hash: string;
|
|
102
|
+
capture?: boolean;
|
|
103
|
+
metadata?: Record<string, unknown>;
|
|
104
|
+
};
|
|
105
|
+
type ProcessFn = (data: ProcessFnParams) => Promise<PaymentMethodResult>;
|
|
99
106
|
|
|
100
107
|
type SpreePayProviderProps = {
|
|
101
108
|
children: ReactNode;
|
|
@@ -103,9 +110,7 @@ type SpreePayProviderProps = {
|
|
|
103
110
|
};
|
|
104
111
|
declare const SpreePayProvider: FC<SpreePayProviderProps>;
|
|
105
112
|
declare const useSpreePay: () => {
|
|
106
|
-
process:
|
|
107
|
-
hash: string;
|
|
108
|
-
}) => Promise<PaymentMethodResult>;
|
|
113
|
+
process: ProcessFn;
|
|
109
114
|
isProcessing: boolean;
|
|
110
115
|
enabled: boolean;
|
|
111
116
|
selectedPaymentMethod: SelectedPaymentMethod;
|
package/build/index.d.ts
CHANGED
|
@@ -93,9 +93,16 @@ declare const enum SlapiPaymentStatus {
|
|
|
93
93
|
}
|
|
94
94
|
type PaymentMethodResult = {
|
|
95
95
|
status: SlapiPaymentStatus;
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
paymentId: string;
|
|
97
|
+
txHash: string | null;
|
|
98
|
+
txId: string | null;
|
|
98
99
|
};
|
|
100
|
+
type ProcessFnParams = {
|
|
101
|
+
hash: string;
|
|
102
|
+
capture?: boolean;
|
|
103
|
+
metadata?: Record<string, unknown>;
|
|
104
|
+
};
|
|
105
|
+
type ProcessFn = (data: ProcessFnParams) => Promise<PaymentMethodResult>;
|
|
99
106
|
|
|
100
107
|
type SpreePayProviderProps = {
|
|
101
108
|
children: ReactNode;
|
|
@@ -103,9 +110,7 @@ type SpreePayProviderProps = {
|
|
|
103
110
|
};
|
|
104
111
|
declare const SpreePayProvider: FC<SpreePayProviderProps>;
|
|
105
112
|
declare const useSpreePay: () => {
|
|
106
|
-
process:
|
|
107
|
-
hash: string;
|
|
108
|
-
}) => Promise<PaymentMethodResult>;
|
|
113
|
+
process: ProcessFn;
|
|
109
114
|
isProcessing: boolean;
|
|
110
115
|
enabled: boolean;
|
|
111
116
|
selectedPaymentMethod: SelectedPaymentMethod;
|
package/build/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/SpreePay.tsx
|
|
2
|
-
import {
|
|
2
|
+
import { useLayoutEffect, useMemo as useMemo2, useRef as useRef3, useState as useState7 } from "react";
|
|
3
3
|
import NiceModal6 from "@ebay/nice-modal-react";
|
|
4
4
|
import { SWRConfig } from "swr";
|
|
5
5
|
|
|
@@ -277,7 +277,8 @@ function Dialog({ ...props }) {
|
|
|
277
277
|
}
|
|
278
278
|
function DialogPortal({ ...props }) {
|
|
279
279
|
const container = usePortalContainer();
|
|
280
|
-
|
|
280
|
+
const safeContainer = container && document.body.contains(container) ? container : void 0;
|
|
281
|
+
return /* @__PURE__ */ jsx5(DialogPrimitive.Portal, { container: safeContainer, "data-slot": "dialog-portal", ...props });
|
|
281
282
|
}
|
|
282
283
|
function DialogOverlay({ className, ...props }) {
|
|
283
284
|
return /* @__PURE__ */ jsx5(
|
|
@@ -488,14 +489,14 @@ var SlapiPaymentService = {
|
|
|
488
489
|
// return coin.balance > outAmountNumber;
|
|
489
490
|
// },
|
|
490
491
|
createPayment: (params) => {
|
|
491
|
-
const { type, hash } = params;
|
|
492
|
+
const { type, hash, metadata, capture = false } = params;
|
|
492
493
|
let reqParams;
|
|
493
494
|
if (type === "CRYPTO" /* CRYPTO */) {
|
|
494
495
|
reqParams = { type, hash, crypto: params.crypto };
|
|
495
496
|
} else {
|
|
496
497
|
reqParams = { type, hash, card: params.card };
|
|
497
498
|
}
|
|
498
|
-
return slapiApi.post("/v1/payments", { ...reqParams, capture
|
|
499
|
+
return slapiApi.post("/v1/payments", { ...reqParams, capture, metadata }).then((data) => ({ data }));
|
|
499
500
|
},
|
|
500
501
|
baseVerify: ({ id, txHash }) => {
|
|
501
502
|
return slapiApi.post(`/v1/base-transactions/transactions/${id}/verify`, { txHash });
|
|
@@ -522,7 +523,13 @@ var SlapiPaymentService = {
|
|
|
522
523
|
};
|
|
523
524
|
|
|
524
525
|
// src/services/cardPayment.ts
|
|
525
|
-
var cardPayment = async ({
|
|
526
|
+
var cardPayment = async ({
|
|
527
|
+
card,
|
|
528
|
+
hash,
|
|
529
|
+
redirect3dsURI,
|
|
530
|
+
metadata,
|
|
531
|
+
capture
|
|
532
|
+
}) => {
|
|
526
533
|
let cardId = card.id;
|
|
527
534
|
if ("token" in card) {
|
|
528
535
|
const { data: cardResData } = await SlapiPaymentService.addCard({ hash, source: card.token });
|
|
@@ -531,6 +538,8 @@ var cardPayment = async ({ card, hash, redirect3dsURI }) => {
|
|
|
531
538
|
const { data: paymentResData } = await SlapiPaymentService.createPayment({
|
|
532
539
|
hash,
|
|
533
540
|
type: "CREDIT_CARD" /* CREDIT_CARD */,
|
|
541
|
+
metadata,
|
|
542
|
+
capture,
|
|
534
543
|
card: { cardId, returnUrl: `${window.location.origin}${redirect3dsURI}` }
|
|
535
544
|
});
|
|
536
545
|
if (paymentResData.redirectUrl) {
|
|
@@ -538,13 +547,18 @@ var cardPayment = async ({ card, hash, redirect3dsURI }) => {
|
|
|
538
547
|
if (paymentIntent) {
|
|
539
548
|
const { data: validateData } = await SlapiPaymentService.validate3DS({ paymentId: paymentResData.id });
|
|
540
549
|
return {
|
|
541
|
-
status: validateData.status
|
|
550
|
+
status: validateData.status,
|
|
551
|
+
paymentId: paymentResData.id,
|
|
552
|
+
txId: paymentResData.txId,
|
|
553
|
+
txHash: null
|
|
542
554
|
};
|
|
543
555
|
}
|
|
544
556
|
}
|
|
545
557
|
return {
|
|
546
558
|
status: paymentResData.status,
|
|
547
|
-
paymentId: paymentResData.id
|
|
559
|
+
paymentId: paymentResData.id,
|
|
560
|
+
txId: paymentResData.txId,
|
|
561
|
+
txHash: null
|
|
548
562
|
};
|
|
549
563
|
};
|
|
550
564
|
|
|
@@ -957,8 +971,8 @@ var CreditCardTab = () => {
|
|
|
957
971
|
try {
|
|
958
972
|
if (selectedPaymentMethod.type === "CREDIT_CARD" /* CREDIT_CARD */ && selectedPaymentMethod.method) {
|
|
959
973
|
const res = await cardPayment({
|
|
974
|
+
...data,
|
|
960
975
|
card: selectedPaymentMethod.method,
|
|
961
|
-
hash: data.hash,
|
|
962
976
|
redirect3dsURI: env.redirect3dsURI
|
|
963
977
|
});
|
|
964
978
|
if (["AUTHORIZED" /* AUTHORIZED */, "CAPTURED" /* CAPTURED */].includes(res.status)) {
|
|
@@ -1118,7 +1132,7 @@ var useCryptoPayment = () => {
|
|
|
1118
1132
|
const { data: walletClient } = useWalletClient();
|
|
1119
1133
|
const config2 = useConfig2();
|
|
1120
1134
|
const { selectedPaymentMethod } = useSpreePaymentMethod();
|
|
1121
|
-
const cryptoPayment = async (
|
|
1135
|
+
const cryptoPayment = async (params) => {
|
|
1122
1136
|
if (!walletClient) {
|
|
1123
1137
|
throw new Error("Wallet not connected");
|
|
1124
1138
|
}
|
|
@@ -1152,8 +1166,8 @@ var useCryptoPayment = () => {
|
|
|
1152
1166
|
}
|
|
1153
1167
|
}
|
|
1154
1168
|
const paymentRes = await SlapiPaymentService.createPayment({
|
|
1169
|
+
...params,
|
|
1155
1170
|
type: "CRYPTO" /* CRYPTO */,
|
|
1156
|
-
hash,
|
|
1157
1171
|
crypto: {
|
|
1158
1172
|
token: TOKEN,
|
|
1159
1173
|
publicKey: walletClient.account.address,
|
|
@@ -1171,7 +1185,8 @@ var useCryptoPayment = () => {
|
|
|
1171
1185
|
const res = await SlapiPaymentService.baseVerify({ id: paymentRes.data.txId, txHash });
|
|
1172
1186
|
return {
|
|
1173
1187
|
txHash,
|
|
1174
|
-
paymentId: paymentRes.data.
|
|
1188
|
+
paymentId: paymentRes.data.id,
|
|
1189
|
+
txId: paymentRes.data.txId,
|
|
1175
1190
|
status: res.verified ? "AUTHORIZED" /* AUTHORIZED */ : "FAILED" /* FAILED */
|
|
1176
1191
|
};
|
|
1177
1192
|
};
|
|
@@ -1550,7 +1565,7 @@ var Crypto = () => {
|
|
|
1550
1565
|
const handlePay = useCallback3(
|
|
1551
1566
|
async (data) => {
|
|
1552
1567
|
try {
|
|
1553
|
-
const res = await cryptoPayment(
|
|
1568
|
+
const res = await cryptoPayment(data);
|
|
1554
1569
|
if (["AUTHORIZED" /* AUTHORIZED */, "CAPTURED" /* CAPTURED */].includes(res.status)) {
|
|
1555
1570
|
return Promise.resolve(res);
|
|
1556
1571
|
}
|
|
@@ -1807,7 +1822,7 @@ var envConfig = {
|
|
|
1807
1822
|
var SpreePay = ({ className, ...rest }) => {
|
|
1808
1823
|
const rootRef = useRef3(null);
|
|
1809
1824
|
const [portalEl, setPortalEl] = useState7(null);
|
|
1810
|
-
|
|
1825
|
+
useLayoutEffect(() => {
|
|
1811
1826
|
if (!rootRef.current) return;
|
|
1812
1827
|
const el = rootRef.current.querySelector(":scope > .sl-spreepay__portal");
|
|
1813
1828
|
setPortalEl(el ?? null);
|
|
@@ -1816,11 +1831,11 @@ var SpreePay = ({ className, ...rest }) => {
|
|
|
1816
1831
|
const environment = env?.environment || "dev";
|
|
1817
1832
|
const tenantId = env?.tenantId || "bookit";
|
|
1818
1833
|
const { isChecking, accessToken, error } = useKeycloakSSO({
|
|
1819
|
-
realm:
|
|
1834
|
+
realm: tenantId,
|
|
1820
1835
|
url: envConfig[environment][tenantId].keyklockUrl,
|
|
1821
1836
|
clientId: envConfig[environment][tenantId].keyklockClientId,
|
|
1822
|
-
ssoPageURI: env
|
|
1823
|
-
enabled: !env
|
|
1837
|
+
ssoPageURI: env?.ssoPageURI,
|
|
1838
|
+
enabled: !env?.accessToken
|
|
1824
1839
|
});
|
|
1825
1840
|
const slapiFetcher = useMemo2(() => {
|
|
1826
1841
|
if (accessToken || env.accessToken) {
|
|
@@ -1831,18 +1846,17 @@ var SpreePay = ({ className, ...rest }) => {
|
|
|
1831
1846
|
});
|
|
1832
1847
|
}
|
|
1833
1848
|
}, [env.accessToken, environment, tenantId, accessToken]);
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
"
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
/* @__PURE__ */ jsx28(
|
|
1845
|
-
/* @__PURE__ */ jsx28(
|
|
1849
|
+
const getContent = () => {
|
|
1850
|
+
if (isChecking) {
|
|
1851
|
+
return /* @__PURE__ */ jsx28("p", { className: "w-full text-center text-sm", children: "Loading..." });
|
|
1852
|
+
}
|
|
1853
|
+
if (error) {
|
|
1854
|
+
return /* @__PURE__ */ jsxs22("p", { className: "w-full text-center text-sm", children: [
|
|
1855
|
+
"Error: ",
|
|
1856
|
+
error.message
|
|
1857
|
+
] });
|
|
1858
|
+
}
|
|
1859
|
+
return /* @__PURE__ */ jsx28(
|
|
1846
1860
|
SWRConfig,
|
|
1847
1861
|
{
|
|
1848
1862
|
value: {
|
|
@@ -1853,14 +1867,18 @@ var SpreePay = ({ className, ...rest }) => {
|
|
|
1853
1867
|
},
|
|
1854
1868
|
children: /* @__PURE__ */ jsx28(PortalContainerProvider, { container: portalEl, children: /* @__PURE__ */ jsx28(NiceModal6.Provider, { children: /* @__PURE__ */ jsx28(SpreePayContent, { ...rest }) }) })
|
|
1855
1869
|
}
|
|
1856
|
-
)
|
|
1870
|
+
);
|
|
1871
|
+
};
|
|
1872
|
+
return /* @__PURE__ */ jsxs22("div", { ref: rootRef, className: cn("sl-spreepay", className), children: [
|
|
1873
|
+
/* @__PURE__ */ jsx28("div", { className: "sl-spreepay__portal" }),
|
|
1874
|
+
getContent()
|
|
1857
1875
|
] });
|
|
1858
1876
|
};
|
|
1859
1877
|
|
|
1860
1878
|
// src/hooks/useCapture3DS.ts
|
|
1861
|
-
import { useEffect as
|
|
1879
|
+
import { useEffect as useEffect6 } from "react";
|
|
1862
1880
|
var useCapture3DS = (searchParams) => {
|
|
1863
|
-
|
|
1881
|
+
useEffect6(() => {
|
|
1864
1882
|
if (window?.parent && searchParams?.paymentIntent) {
|
|
1865
1883
|
window.parent.SP_EVENT_BUS?.emit("paymentIntent", { paymentIntent: searchParams.paymentIntent });
|
|
1866
1884
|
}
|