@superlogic/spree-pay 0.2.0 → 0.2.1
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/build/CryptoComTab-WWW23OV5.js +169 -0
- package/build/CryptoTab-HISSGXAC.js +838 -0
- package/build/chunk-2V675UEC.js +56 -0
- package/build/chunk-FGNS5H2Q.js +278 -0
- package/build/chunk-RQX2IOTB.js +795 -0
- package/build/index.cjs +4379 -3872
- package/build/index.css +30 -0
- package/build/index.js +1509 -3510
- package/package.json +1 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Iframe3ds
|
|
3
|
+
} from "./chunk-2V675UEC.js";
|
|
4
|
+
import {
|
|
5
|
+
InfoBanner,
|
|
6
|
+
Legal,
|
|
7
|
+
PaymentError,
|
|
8
|
+
SlapiPaymentService,
|
|
9
|
+
logger,
|
|
10
|
+
useSpreePayConfig,
|
|
11
|
+
useSpreePayEnv,
|
|
12
|
+
useSpreePayRegister,
|
|
13
|
+
useSpreePaymentMethod,
|
|
14
|
+
useStaticConfig
|
|
15
|
+
} from "./chunk-RQX2IOTB.js";
|
|
16
|
+
|
|
17
|
+
// src/components/CryptoComTab/CryptoComTab.tsx
|
|
18
|
+
import { useCallback, useEffect } from "react";
|
|
19
|
+
|
|
20
|
+
// src/hooks/payments/useCryptoComPayment.ts
|
|
21
|
+
import NiceModal from "@ebay/nice-modal-react";
|
|
22
|
+
var cryptoComLogger = logger.child("crypto-com-payment");
|
|
23
|
+
var useCryptoComPayment = () => {
|
|
24
|
+
const { selectedPaymentMethod } = useSpreePaymentMethod();
|
|
25
|
+
const { env } = useSpreePayEnv();
|
|
26
|
+
const cryptoComPayment = async (params) => {
|
|
27
|
+
if (selectedPaymentMethod.type !== "CDC" /* CDC */) {
|
|
28
|
+
throw new Error("Unsupported payment method");
|
|
29
|
+
}
|
|
30
|
+
const { hash, metadata } = params;
|
|
31
|
+
cryptoComLogger.info("Starting Crypto.com Pay payment", { hash });
|
|
32
|
+
const { data: paymentResData } = await SlapiPaymentService.createPayment({
|
|
33
|
+
hash,
|
|
34
|
+
metadata,
|
|
35
|
+
type: "CDC" /* CDC */,
|
|
36
|
+
cdc: {
|
|
37
|
+
returnUrl: `${typeof window !== "undefined" ? window.location.origin : ""}${env.redirect3dsURI}?payment_intent=success`,
|
|
38
|
+
cancelUrl: `${typeof window !== "undefined" ? window.location.origin : ""}${env.redirect3dsURI}?payment_intent=canceled`
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
cryptoComLogger.info("Payment created", {
|
|
42
|
+
paymentId: paymentResData.id,
|
|
43
|
+
status: paymentResData.status,
|
|
44
|
+
hasRedirect: Boolean(paymentResData.redirectUrl)
|
|
45
|
+
});
|
|
46
|
+
let { status } = paymentResData;
|
|
47
|
+
if (paymentResData.redirectUrl) {
|
|
48
|
+
cryptoComLogger.debug("Opening CDC payment redirect", { paymentId: paymentResData.id });
|
|
49
|
+
const paymentIntent = await NiceModal.show(Iframe3ds, { url: paymentResData.redirectUrl });
|
|
50
|
+
cryptoComLogger.info("CDC payment redirect completed", { paymentIntent });
|
|
51
|
+
if (paymentIntent === "success") {
|
|
52
|
+
cryptoComLogger.debug("Validating CDC payment", { paymentId: paymentResData.id });
|
|
53
|
+
const { data: validateData } = await SlapiPaymentService.validateCDC({ paymentId: paymentResData.id });
|
|
54
|
+
({ status } = validateData);
|
|
55
|
+
cryptoComLogger.info("CDC payment validated", { paymentId: paymentResData.id, status });
|
|
56
|
+
} else {
|
|
57
|
+
status = "FAILED" /* FAILED */;
|
|
58
|
+
cryptoComLogger.warn("CDC payment canceled or failed", { paymentIntent });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
cryptoComLogger.info("Crypto.com Pay payment completed", {
|
|
62
|
+
paymentId: paymentResData.id,
|
|
63
|
+
status,
|
|
64
|
+
txId: paymentResData.txId
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
status,
|
|
68
|
+
paymentType: "CDC" /* CDC */,
|
|
69
|
+
paymentId: paymentResData.id,
|
|
70
|
+
txId: paymentResData.txId,
|
|
71
|
+
txHash: null
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
return { cryptoComPayment };
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/components/CryptoComTab/Checkout.tsx
|
|
78
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
79
|
+
var Checkout = () => {
|
|
80
|
+
const { appProps } = useStaticConfig();
|
|
81
|
+
return /* @__PURE__ */ jsx(
|
|
82
|
+
"button",
|
|
83
|
+
{
|
|
84
|
+
onClick: appProps.onProcess,
|
|
85
|
+
disabled: appProps.isProcessing,
|
|
86
|
+
className: "flex flex-col items-center rounded-md bg-(--crypto-pay-bg) p-2 text-(--brand-primary) hover:bg-(--crypto-pay-bg-hover) disabled:cursor-not-allowed disabled:bg-(--crypto-pay-bg-hover) disabled:text-(--disabled)",
|
|
87
|
+
children: /* @__PURE__ */ jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", className: "h-7 w-[76px]", fill: "none", viewBox: "0 0 76 28", children: [
|
|
88
|
+
/* @__PURE__ */ jsx(
|
|
89
|
+
"path",
|
|
90
|
+
{
|
|
91
|
+
fill: "currentColor",
|
|
92
|
+
fillRule: "evenodd",
|
|
93
|
+
d: "M47.42 9.06c0 4.02-3.25 6.09-7.1 6.09h-4.38v6.53h-2.03V3.16h6.75c4.08 0 6.76 2.22 6.76 5.9m-2.06.08c0-2.68-1.94-4.05-4.85-4.05h-4.57v8.15h4.47c2.99 0 4.95-1.64 4.95-4.1m9.28.47c-1.57 0-2.81.43-4.05 1.01L50 8.95a11 11 0 0 1 4.86-1.14c3.63 0 5.67 1.9 5.67 5.5v8.37h-1.9v-2.06a5.8 5.8 0 0 1-4.83 2.35c-2.48 0-4.98-1.43-4.98-4.28 0-2.92 2.32-4.45 5.7-4.45 1.7 0 2.92.24 4.1.58v-.47c0-2.47-1.47-3.74-3.97-3.74m.08 5.14c1.62 0 2.94.29 3.92.58v1.32c0 2.17-2.01 3.71-4.46 3.71-1.8 0-3.36-1-3.36-2.75s1.4-2.86 3.9-2.86m12.23 11.8 1.75-4.7-6.14-13.8h2.2l4.84 11.4 4.28-11.4H76l-7.32 18.5z",
|
|
94
|
+
clipRule: "evenodd"
|
|
95
|
+
}
|
|
96
|
+
),
|
|
97
|
+
/* @__PURE__ */ jsx(
|
|
98
|
+
"path",
|
|
99
|
+
{
|
|
100
|
+
fill: "currentColor",
|
|
101
|
+
fillRule: "evenodd",
|
|
102
|
+
d: "M0 6.77V20.3l11.66 6.77 11.66-6.77V6.77L11.66 0zM1.03 19.7V7.36L11.66 1.2 22.3 7.36v12.35l-10.64 6.17z",
|
|
103
|
+
clipRule: "evenodd"
|
|
104
|
+
}
|
|
105
|
+
),
|
|
106
|
+
/* @__PURE__ */ jsx(
|
|
107
|
+
"path",
|
|
108
|
+
{
|
|
109
|
+
fill: "currentColor",
|
|
110
|
+
fillRule: "evenodd",
|
|
111
|
+
d: "M16.23 5.84H7.07L6 10.54h11.33zM8.7 17v-3.12l-2.72-1.73-3.07 2.3 4.19 7.31h1.67l1.98-1.85v-.93z",
|
|
112
|
+
clipRule: "evenodd"
|
|
113
|
+
}
|
|
114
|
+
),
|
|
115
|
+
/* @__PURE__ */ jsx(
|
|
116
|
+
"path",
|
|
117
|
+
{
|
|
118
|
+
fill: "currentColor",
|
|
119
|
+
fillRule: "evenodd",
|
|
120
|
+
d: "M14.64 11.25H8.7l1 2.62-.3 2.94h4.54l-.28-2.94z",
|
|
121
|
+
clipRule: "evenodd"
|
|
122
|
+
}
|
|
123
|
+
),
|
|
124
|
+
/* @__PURE__ */ jsx(
|
|
125
|
+
"path",
|
|
126
|
+
{
|
|
127
|
+
fill: "currentColor",
|
|
128
|
+
fillRule: "evenodd",
|
|
129
|
+
d: "m17.35 12.13-2.68 1.75V17l-2.05 1.98v.93l1.98 1.83h1.65l4.16-7.3z",
|
|
130
|
+
clipRule: "evenodd"
|
|
131
|
+
}
|
|
132
|
+
)
|
|
133
|
+
] })
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// src/components/CryptoComTab/CryptoComTab.tsx
|
|
139
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
140
|
+
var CryptoComTab = () => {
|
|
141
|
+
const { register } = useSpreePayRegister();
|
|
142
|
+
const { cryptoComPayment } = useCryptoComPayment();
|
|
143
|
+
const { spreePayConfig } = useSpreePayConfig();
|
|
144
|
+
const handlePay = useCallback(
|
|
145
|
+
async (data) => {
|
|
146
|
+
try {
|
|
147
|
+
const res = await cryptoComPayment(data);
|
|
148
|
+
if (["AUTHORIZED" /* AUTHORIZED */, "CAPTURED" /* CAPTURED */].includes(res.status)) {
|
|
149
|
+
return Promise.resolve(res);
|
|
150
|
+
}
|
|
151
|
+
return Promise.reject(new PaymentError("Crypto payment failed", res.status));
|
|
152
|
+
} catch (_) {
|
|
153
|
+
return Promise.reject(new PaymentError("Payment failed", "FAILED" /* FAILED */));
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
[cryptoComPayment]
|
|
157
|
+
);
|
|
158
|
+
useEffect(() => {
|
|
159
|
+
register(handlePay);
|
|
160
|
+
}, [register, handlePay]);
|
|
161
|
+
return /* @__PURE__ */ jsxs2("div", { className: "flex w-full flex-col gap-4 border-b border-b-(--border-component-specific-card) px-5 py-5 md:px-7 md:py-6", children: [
|
|
162
|
+
spreePayConfig?.cryptoCom.infoMessage && /* @__PURE__ */ jsx2(InfoBanner, { message: spreePayConfig.cryptoCom.infoMessage }),
|
|
163
|
+
/* @__PURE__ */ jsx2(Legal, {}),
|
|
164
|
+
/* @__PURE__ */ jsx2(Checkout, {})
|
|
165
|
+
] });
|
|
166
|
+
};
|
|
167
|
+
export {
|
|
168
|
+
CryptoComTab
|
|
169
|
+
};
|