@directcryptopay/sdk 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -87
- package/dist/core/config.d.ts +9 -46
- package/dist/core/iframe.d.ts +16 -0
- package/dist/dcp-sdk.umd.js +1 -12811
- package/dist/dcp.d.ts +12 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +219 -2
- package/dist/types.d.ts +26 -164
- package/package.json +3 -13
- package/dist/ExchangeController-CPMQq6Q-.js +0 -217
- package/dist/HelpersUtil-DfMFC7Bf.js +0 -120
- package/dist/NavigationUtil-kj9LEOOd.js +0 -8
- package/dist/PhArrowCircleDown-lsK25DCk.js +0 -73
- package/dist/PhArrowClockwise-NeKHZ1co.js +0 -73
- package/dist/PhArrowDown-C9AkNvLs.js +0 -73
- package/dist/PhArrowLeft-RNfIQP1X.js +0 -73
- package/dist/PhArrowRight-DM1tna0G.js +0 -73
- package/dist/PhArrowSquareOut-S5XYbAZj.js +0 -73
- package/dist/PhArrowUp-DmktzOWy.js +0 -73
- package/dist/PhArrowUpRight-BkNeW_5i.js +0 -73
- package/dist/PhArrowsClockwise-CQ4pG76b.js +0 -73
- package/dist/PhArrowsDownUp-H6gxaNM6.js +0 -73
- package/dist/PhArrowsLeftRight-DZSsfMR6.js +0 -73
- package/dist/PhBank-4_9QzqIB.js +0 -73
- package/dist/PhBrowser-B-JSznId.js +0 -73
- package/dist/PhCaretDown-vV5oHMNi.js +0 -73
- package/dist/PhCaretLeft-BLo6Y_f4.js +0 -73
- package/dist/PhCaretRight-CqQN4TT3.js +0 -73
- package/dist/PhCaretUp-Df7UCAHy.js +0 -73
- package/dist/PhCheck-gtpfK4ed.js +0 -73
- package/dist/PhCircleHalf-Uq7dwDYw.js +0 -73
- package/dist/PhClock-SDCW-NmF.js +0 -73
- package/dist/PhCompass-B7hgtdx-.js +0 -73
- package/dist/PhCopy-BcnhyXCy.js +0 -73
- package/dist/PhCreditCard-BJjByVgu.js +0 -73
- package/dist/PhCurrencyDollar-B7ZXqXBy.js +0 -73
- package/dist/PhDesktop-B3VKPuJx.js +0 -73
- package/dist/PhDeviceMobile-Bnd0TYEH.js +0 -73
- package/dist/PhDotsThree-yyMWyZ-R.js +0 -73
- package/dist/PhEnvelope-67uzHbI9.js +0 -73
- package/dist/PhFunnelSimple-B-DCsloI.js +0 -73
- package/dist/PhGlobe-TMm_6qGk.js +0 -73
- package/dist/PhIdentificationCard-CePPD2xc.js +0 -73
- package/dist/PhImage-gY96WtHR.js +0 -73
- package/dist/PhInfo-DRQM_ZDP.js +0 -73
- package/dist/PhLightbulb-B0TxPfZ1.js +0 -73
- package/dist/PhMagnifyingGlass-B8si5_6W.js +0 -73
- package/dist/PhPaperPlaneRight-DVu5PLYd.js +0 -73
- package/dist/PhPlus-BfTsQnUz.js +0 -73
- package/dist/PhPower-CxYUGOWn.js +0 -73
- package/dist/PhPuzzlePiece-CQ4wh0gV.js +0 -73
- package/dist/PhQrCode-BuJ97NYJ.js +0 -73
- package/dist/PhQuestion-kJoP8Mja.js +0 -73
- package/dist/PhQuestionMark-C46ZkFpu.js +0 -73
- package/dist/PhSealCheck-Eh8jVqSN.js +0 -73
- package/dist/PhSignOut-jk97OSVt.js +0 -73
- package/dist/PhSpinner-CiYOhwMg.js +0 -73
- package/dist/PhTrash-pxerMqzd.js +0 -73
- package/dist/PhUser-BMg0VV4A.js +0 -73
- package/dist/PhVault-DYQvx5A-.js +0 -73
- package/dist/PhWarning-NLC5Mj87.js +0 -73
- package/dist/PhWarningCircle-Ch2jU9fA.js +0 -73
- package/dist/PhX-Bx4wpwm3.js +0 -73
- package/dist/SwapController-Cti0Cyxa.js +0 -457
- package/dist/ccip-CKZd2XJ7.js +0 -150
- package/dist/core/api.d.ts +0 -39
- package/dist/core/logic.d.ts +0 -2
- package/dist/core/wallet.d.ts +0 -55
- package/dist/data-capture-7D5CL385.js +0 -490
- package/dist/email-AmK0INbZ.js +0 -344
- package/dist/embedded-wallet-Pn0I_XLn.js +0 -820
- package/dist/features-x8XNprEe.js +0 -274
- package/dist/hashTypedData-B50-z0AA.js +0 -197
- package/dist/if-defined-CdZSZ6UL.js +0 -10
- package/dist/index-4ewUtPPp.js +0 -7981
- package/dist/index-51l86yqx.js +0 -276
- package/dist/index-B6K56LF_.js +0 -85
- package/dist/index-BAmv9PxJ.js +0 -257
- package/dist/index-BEswjY9r.js +0 -117
- package/dist/index-BSKRq56S.js +0 -355
- package/dist/index-BaygXQxx.js +0 -172
- package/dist/index-BcPxaHr5.js +0 -118
- package/dist/index-Bjt7nGaJ.js +0 -199
- package/dist/index-BkTSyAJb.js +0 -21991
- package/dist/index-Bmnl7l2U.js +0 -555
- package/dist/index-BvPvouSq.js +0 -56
- package/dist/index-C-6iznUO.js +0 -174
- package/dist/index-C1QEJL-2.js +0 -572
- package/dist/index-C4M5s_AM.js +0 -228
- package/dist/index-CEqcN8QP.js +0 -1175
- package/dist/index-CM3YaYca.js +0 -8189
- package/dist/index-CclBLA5r.js +0 -517
- package/dist/index-ChTxJOiF.js +0 -46
- package/dist/index-CmAv0Tzr.js +0 -86
- package/dist/index-CmvoKY4x.js +0 -125
- package/dist/index-D7PmdQ9B.js +0 -1750
- package/dist/index-D7k2Pc4e.js +0 -1083
- package/dist/index-D7lmgqUR.js +0 -153
- package/dist/index-DG_-qYze.js +0 -107
- package/dist/index-DHot9Fdb.js +0 -218
- package/dist/index-DV2LrPtU.js +0 -123
- package/dist/index-DYBaJQ2W.js +0 -65
- package/dist/index-D_8VUmn1.js +0 -41543
- package/dist/index-D_gLn3rT.js +0 -100
- package/dist/index-DqcVUSC9.js +0 -62
- package/dist/index-I7VDqINw.js +0 -128
- package/dist/index-Oz72I9VP.js +0 -209
- package/dist/index-UclsHkJ0.js +0 -118
- package/dist/index-X8zir_1j.js +0 -110
- package/dist/index-XvlWKGCu.js +0 -1281
- package/dist/index-dO97xPlt.js +0 -171
- package/dist/index-uBeF6OAB.js +0 -387
- package/dist/index-zeA_RiCV.js +0 -159
- package/dist/localBatchGatewayRequest-BUZHGdjw.js +0 -91
- package/dist/onramp-CdnBuF0r.js +0 -855
- package/dist/parseSignature-CcyTNGr4.js +0 -3304
- package/dist/pay-with-exchange-CSM6WCOV.js +0 -525
- package/dist/property-Bd8U3_QP.js +0 -618
- package/dist/receive-DooMu4Dx.js +0 -232
- package/dist/ref-CpgjXAw7.js +0 -107
- package/dist/send-3T7CyYic.js +0 -1166
- package/dist/socials-Dt-iHL17.js +0 -620
- package/dist/swaps-CjA9Es42.js +0 -1760
- package/dist/transactions-nRm9DVzn.js +0 -37
- package/dist/ui/Modal.d.ts +0 -9
- package/dist/ui/index.d.ts +0 -6
- package/dist/w3m-modal-NV25AXhM.js +0 -1706
package/dist/dcp.d.ts
CHANGED
|
@@ -2,19 +2,26 @@ import { type DCPInitConfig } from './core/config';
|
|
|
2
2
|
import type { DCPPayOptions, DCPPaymentOptions } from './types';
|
|
3
3
|
export declare class DCP {
|
|
4
4
|
private static instance;
|
|
5
|
+
private cleanup;
|
|
5
6
|
private constructor();
|
|
6
7
|
static getInstance(): DCP;
|
|
8
|
+
/**
|
|
9
|
+
* Initialize the SDK. Must be called before pay() or Payment().
|
|
10
|
+
*/
|
|
7
11
|
init(initConfig: DCPInitConfig): void;
|
|
8
12
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
13
|
+
* Open a checkout iframe for a Payment Tool (link, button, donation, etc.).
|
|
14
|
+
* The checkout page handles wallet connection, token selection, and payment.
|
|
11
15
|
*/
|
|
12
16
|
pay(options: DCPPayOptions): void;
|
|
13
17
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* Requires DCP.init() first (for WalletConnect projectId).
|
|
18
|
+
* Open a checkout iframe for an Integration with dynamic amount.
|
|
19
|
+
* Use this for programmatic payments where amount is determined at runtime.
|
|
17
20
|
*/
|
|
18
21
|
Payment(options: DCPPaymentOptions): void;
|
|
22
|
+
/**
|
|
23
|
+
* Programmatically close the checkout iframe.
|
|
24
|
+
*/
|
|
25
|
+
close(): void;
|
|
19
26
|
}
|
|
20
27
|
export declare const dcp: DCP;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { dcp as DCP } from './dcp';
|
|
2
2
|
export type { DCPInitConfig } from './core/config';
|
|
3
|
-
export type { DCPPayOptions, DCPPaymentOptions, PaymentCallbacks
|
|
3
|
+
export type { DCPPayOptions, DCPPaymentOptions, PaymentCallbacks } from './types';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,221 @@
|
|
|
1
|
-
|
|
1
|
+
var z = Object.defineProperty;
|
|
2
|
+
var D = (p, e, d) => e in p ? z(p, e, { enumerable: !0, configurable: !0, writable: !0, value: d }) : p[e] = d;
|
|
3
|
+
var g = (p, e, d) => D(p, typeof e != "symbol" ? e + "" : e, d);
|
|
4
|
+
class P {
|
|
5
|
+
constructor() {
|
|
6
|
+
g(this, "config", null);
|
|
7
|
+
}
|
|
8
|
+
init(e) {
|
|
9
|
+
this.config = {
|
|
10
|
+
checkoutUrl: (e.checkoutUrl || "https://directcryptopay.com").replace(/\/$/, "")
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
get() {
|
|
14
|
+
if (!this.config)
|
|
15
|
+
throw new Error("DirectCryptoPay: SDK not initialized. Call DCP.init() first");
|
|
16
|
+
return this.config;
|
|
17
|
+
}
|
|
18
|
+
isInitialized() {
|
|
19
|
+
return this.config !== null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const y = new P();
|
|
23
|
+
function a(p, e) {
|
|
24
|
+
let d = !1;
|
|
25
|
+
const i = document.createElement("div");
|
|
26
|
+
i.id = "dcp-checkout-overlay", Object.assign(i.style, {
|
|
27
|
+
position: "fixed",
|
|
28
|
+
inset: "0",
|
|
29
|
+
zIndex: "99999",
|
|
30
|
+
background: "rgba(0, 0, 0, 0.6)",
|
|
31
|
+
display: "flex",
|
|
32
|
+
alignItems: "center",
|
|
33
|
+
justifyContent: "center"
|
|
34
|
+
});
|
|
35
|
+
const h = document.createElement("div");
|
|
36
|
+
Object.assign(h.style, {
|
|
37
|
+
background: "white",
|
|
38
|
+
borderRadius: "16px",
|
|
39
|
+
overflow: "hidden",
|
|
40
|
+
width: "100%",
|
|
41
|
+
maxWidth: "440px",
|
|
42
|
+
maxHeight: "90vh",
|
|
43
|
+
boxShadow: "0 25px 50px -12px rgba(0, 0, 0, 0.25)",
|
|
44
|
+
position: "relative"
|
|
45
|
+
});
|
|
46
|
+
const t = document.createElement("button");
|
|
47
|
+
t.innerHTML = "×", Object.assign(t.style, {
|
|
48
|
+
position: "absolute",
|
|
49
|
+
top: "8px",
|
|
50
|
+
right: "8px",
|
|
51
|
+
zIndex: "10",
|
|
52
|
+
background: "rgba(255, 255, 255, 0.9)",
|
|
53
|
+
border: "none",
|
|
54
|
+
borderRadius: "50%",
|
|
55
|
+
width: "32px",
|
|
56
|
+
height: "32px",
|
|
57
|
+
fontSize: "20px",
|
|
58
|
+
lineHeight: "32px",
|
|
59
|
+
textAlign: "center",
|
|
60
|
+
cursor: "pointer",
|
|
61
|
+
color: "#6b7280",
|
|
62
|
+
boxShadow: "0 2px 4px rgba(0,0,0,0.1)"
|
|
63
|
+
});
|
|
64
|
+
const u = document.createElement("iframe");
|
|
65
|
+
u.src = p, Object.assign(u.style, {
|
|
66
|
+
width: "100%",
|
|
67
|
+
height: "600px",
|
|
68
|
+
border: "none",
|
|
69
|
+
display: "block"
|
|
70
|
+
}), h.appendChild(t), h.appendChild(u), i.appendChild(h);
|
|
71
|
+
const n = () => {
|
|
72
|
+
d || (d = !0, window.removeEventListener("message", w), window.removeEventListener("keydown", r), i.parentNode && i.parentNode.removeChild(i));
|
|
73
|
+
};
|
|
74
|
+
t.onclick = () => {
|
|
75
|
+
var s;
|
|
76
|
+
n(), (s = e == null ? void 0 : e.onClose) == null || s.call(e);
|
|
77
|
+
}, i.addEventListener("click", (s) => {
|
|
78
|
+
var o;
|
|
79
|
+
s.target === i && (n(), (o = e == null ? void 0 : e.onClose) == null || o.call(e));
|
|
80
|
+
});
|
|
81
|
+
const r = (s) => {
|
|
82
|
+
var o;
|
|
83
|
+
s.key === "Escape" && (n(), (o = e == null ? void 0 : e.onClose) == null || o.call(e));
|
|
84
|
+
};
|
|
85
|
+
window.addEventListener("keydown", r);
|
|
86
|
+
const w = (s) => {
|
|
87
|
+
var x, C, S, E, I, v;
|
|
88
|
+
const o = s.data;
|
|
89
|
+
if (!(!o || typeof o.type != "string") && o.type.startsWith("dcp:"))
|
|
90
|
+
switch (o.type) {
|
|
91
|
+
case "dcp:ready":
|
|
92
|
+
(x = e == null ? void 0 : e.onReady) == null || x.call(e);
|
|
93
|
+
break;
|
|
94
|
+
case "dcp:payment-submitted":
|
|
95
|
+
(C = e == null ? void 0 : e.onTxSubmitted) == null || C.call(e, o.txHash);
|
|
96
|
+
break;
|
|
97
|
+
case "dcp:payment-success":
|
|
98
|
+
(S = e == null ? void 0 : e.onSuccess) == null || S.call(e, { txHash: o.txHash, intentId: o.intentId });
|
|
99
|
+
break;
|
|
100
|
+
case "dcp:payment-error":
|
|
101
|
+
(E = e == null ? void 0 : e.onError) == null || E.call(e, o.error);
|
|
102
|
+
break;
|
|
103
|
+
case "dcp:payment-cancelled":
|
|
104
|
+
(I = e == null ? void 0 : e.onCancel) == null || I.call(e), n();
|
|
105
|
+
break;
|
|
106
|
+
case "dcp:close":
|
|
107
|
+
(v = e == null ? void 0 : e.onClose) == null || v.call(e), n();
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
return window.addEventListener("message", w), document.body.appendChild(i), n;
|
|
112
|
+
}
|
|
113
|
+
const m = class m {
|
|
114
|
+
constructor() {
|
|
115
|
+
g(this, "cleanup", null);
|
|
116
|
+
}
|
|
117
|
+
static getInstance() {
|
|
118
|
+
return m.instance || (m.instance = new m()), m.instance;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Initialize the SDK. Must be called before pay() or Payment().
|
|
122
|
+
*/
|
|
123
|
+
init(e) {
|
|
124
|
+
if (y.isInitialized()) {
|
|
125
|
+
console.warn("DirectCryptoPay: SDK already initialized");
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
y.init(e);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Open a checkout iframe for a Payment Tool (link, button, donation, etc.).
|
|
132
|
+
* The checkout page handles wallet connection, token selection, and payment.
|
|
133
|
+
*/
|
|
134
|
+
pay(e) {
|
|
135
|
+
var u;
|
|
136
|
+
if (!y.isInitialized())
|
|
137
|
+
throw new Error("DirectCryptoPay: SDK not initialized. Call DCP.init() first");
|
|
138
|
+
const { checkoutUrl: d } = y.get(), i = new URLSearchParams({ embedded: "true" });
|
|
139
|
+
e.amountUsd && i.set("amount", String(e.amountUsd));
|
|
140
|
+
const h = `${d}/pay/${e.toolId}?${i.toString()}`, t = e.callbacks;
|
|
141
|
+
(u = this.cleanup) == null || u.call(this), this.cleanup = a(h, {
|
|
142
|
+
onReady: () => {
|
|
143
|
+
var n;
|
|
144
|
+
return (n = t == null ? void 0 : t.onOpen) == null ? void 0 : n.call(t);
|
|
145
|
+
},
|
|
146
|
+
onTxSubmitted: (n) => {
|
|
147
|
+
var r;
|
|
148
|
+
return (r = t == null ? void 0 : t.onTxSubmitted) == null ? void 0 : r.call(t, n);
|
|
149
|
+
},
|
|
150
|
+
onSuccess: (n) => {
|
|
151
|
+
var r;
|
|
152
|
+
return (r = t == null ? void 0 : t.onSuccess) == null ? void 0 : r.call(t, n);
|
|
153
|
+
},
|
|
154
|
+
onError: (n) => {
|
|
155
|
+
var r;
|
|
156
|
+
return (r = t == null ? void 0 : t.onError) == null ? void 0 : r.call(t, new Error(n));
|
|
157
|
+
},
|
|
158
|
+
onClose: () => {
|
|
159
|
+
var n;
|
|
160
|
+
this.cleanup = null, (n = t == null ? void 0 : t.onClose) == null || n.call(t);
|
|
161
|
+
},
|
|
162
|
+
onCancel: () => {
|
|
163
|
+
var n;
|
|
164
|
+
this.cleanup = null, (n = t == null ? void 0 : t.onCancel) == null || n.call(t);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Open a checkout iframe for an Integration with dynamic amount.
|
|
170
|
+
* Use this for programmatic payments where amount is determined at runtime.
|
|
171
|
+
*/
|
|
172
|
+
Payment(e) {
|
|
173
|
+
var u;
|
|
174
|
+
if (!y.isInitialized())
|
|
175
|
+
throw new Error("DirectCryptoPay: SDK not initialized. Call DCP.init() first");
|
|
176
|
+
if (!e.integrationId)
|
|
177
|
+
throw new Error("DirectCryptoPay: integrationId is required");
|
|
178
|
+
const { checkoutUrl: d } = y.get(), i = new URLSearchParams({ embedded: "true" });
|
|
179
|
+
i.set("integrationId", e.integrationId), e.amount_usd && i.set("amount_usd", e.amount_usd), e.amount != null && i.set("amount", String(e.amount)), e.currency && i.set("currency", e.currency), e.chainId && i.set("chainId", String(e.chainId)), e.metadata && i.set("metadata", JSON.stringify(e.metadata));
|
|
180
|
+
const h = `${d}/pay/checkout?${i.toString()}`, t = e.callbacks;
|
|
181
|
+
(u = this.cleanup) == null || u.call(this), this.cleanup = a(h, {
|
|
182
|
+
onReady: () => {
|
|
183
|
+
var n;
|
|
184
|
+
return (n = t == null ? void 0 : t.onOpen) == null ? void 0 : n.call(t);
|
|
185
|
+
},
|
|
186
|
+
onTxSubmitted: (n) => {
|
|
187
|
+
var r;
|
|
188
|
+
return (r = t == null ? void 0 : t.onTxSubmitted) == null ? void 0 : r.call(t, n);
|
|
189
|
+
},
|
|
190
|
+
onSuccess: (n) => {
|
|
191
|
+
var r;
|
|
192
|
+
return (r = t == null ? void 0 : t.onSuccess) == null ? void 0 : r.call(t, n);
|
|
193
|
+
},
|
|
194
|
+
onError: (n) => {
|
|
195
|
+
var r;
|
|
196
|
+
return (r = t == null ? void 0 : t.onError) == null ? void 0 : r.call(t, new Error(n));
|
|
197
|
+
},
|
|
198
|
+
onClose: () => {
|
|
199
|
+
var n;
|
|
200
|
+
this.cleanup = null, (n = t == null ? void 0 : t.onClose) == null || n.call(t);
|
|
201
|
+
},
|
|
202
|
+
onCancel: () => {
|
|
203
|
+
var n;
|
|
204
|
+
this.cleanup = null, (n = t == null ? void 0 : t.onCancel) == null || n.call(t);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Programmatically close the checkout iframe.
|
|
210
|
+
*/
|
|
211
|
+
close() {
|
|
212
|
+
var e;
|
|
213
|
+
(e = this.cleanup) == null || e.call(this), this.cleanup = null;
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
g(m, "instance");
|
|
217
|
+
let f = m;
|
|
218
|
+
const U = f.getInstance();
|
|
2
219
|
export {
|
|
3
|
-
|
|
220
|
+
U as DCP
|
|
4
221
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,188 +1,50 @@
|
|
|
1
|
-
import type { Address, Hash } from 'viem';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
2
|
+
* Callbacks for payment lifecycle events.
|
|
4
3
|
*/
|
|
5
|
-
export interface PaymentIntent {
|
|
6
|
-
id: string;
|
|
7
|
-
chain_id: number;
|
|
8
|
-
recipient: Address;
|
|
9
|
-
amount_wei: string;
|
|
10
|
-
currency: string;
|
|
11
|
-
expires_at: string;
|
|
12
|
-
signature: string;
|
|
13
|
-
status: 'CREATED' | 'PENDING' | 'PAID' | 'FAILED' | 'EXPIRED' | 'LATE_CONFIRMED';
|
|
14
|
-
metadata?: Record<string, any>;
|
|
15
|
-
asset_type?: 'native' | 'erc20';
|
|
16
|
-
token_address?: Address;
|
|
17
|
-
token_decimals?: number;
|
|
18
|
-
nonce?: string;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Gas estimation result
|
|
22
|
-
*/
|
|
23
|
-
export interface GasEstimate {
|
|
24
|
-
gasLimit: bigint;
|
|
25
|
-
maxFeePerGas: bigint;
|
|
26
|
-
maxPriorityFeePerGas: bigint;
|
|
27
|
-
totalCostWei: bigint;
|
|
28
|
-
percentageOfPayment: number;
|
|
29
|
-
exceedsThreshold: boolean;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Payment status update
|
|
33
|
-
*/
|
|
34
|
-
export type PaymentStatus = {
|
|
35
|
-
type: 'fetching_tool_data';
|
|
36
|
-
} | {
|
|
37
|
-
type: 'fetching_token_balances';
|
|
38
|
-
} | {
|
|
39
|
-
type: 'awaiting_token_selection';
|
|
40
|
-
} | {
|
|
41
|
-
type: 'creating_payment_intent';
|
|
42
|
-
} | {
|
|
43
|
-
type: 'estimating_gas';
|
|
44
|
-
} | {
|
|
45
|
-
type: 'gas_estimated';
|
|
46
|
-
estimate: GasEstimate;
|
|
47
|
-
} | {
|
|
48
|
-
type: 'awaiting_wallet_connection';
|
|
49
|
-
} | {
|
|
50
|
-
type: 'wallet_connected';
|
|
51
|
-
address: Address;
|
|
52
|
-
} | {
|
|
53
|
-
type: 'awaiting_signature';
|
|
54
|
-
} | {
|
|
55
|
-
type: 'transaction_submitted';
|
|
56
|
-
txHash: Hash;
|
|
57
|
-
} | {
|
|
58
|
-
type: 'confirming';
|
|
59
|
-
txHash: Hash;
|
|
60
|
-
confirmations: number;
|
|
61
|
-
} | {
|
|
62
|
-
type: 'verifying';
|
|
63
|
-
txHash: Hash;
|
|
64
|
-
paymentId: string;
|
|
65
|
-
} | {
|
|
66
|
-
type: 'confirmed';
|
|
67
|
-
txHash: Hash;
|
|
68
|
-
paymentId?: string;
|
|
69
|
-
} | {
|
|
70
|
-
type: 'failed';
|
|
71
|
-
error: Error;
|
|
72
|
-
} | {
|
|
73
|
-
type: 'rejected';
|
|
74
|
-
} | {
|
|
75
|
-
type: 'cancelled';
|
|
76
|
-
};
|
|
77
|
-
export interface TokenConfig {
|
|
78
|
-
symbol: string;
|
|
79
|
-
name: string;
|
|
80
|
-
address: string | null;
|
|
81
|
-
decimals: number;
|
|
82
|
-
isNative: boolean;
|
|
83
|
-
}
|
|
84
|
-
export interface TokenWithBalance extends TokenConfig {
|
|
85
|
-
balance: string;
|
|
86
|
-
balanceFormatted: string;
|
|
87
|
-
hasBalance: boolean;
|
|
88
|
-
}
|
|
89
|
-
export interface ToolData {
|
|
90
|
-
id: string;
|
|
91
|
-
amount: string;
|
|
92
|
-
currency_id: string;
|
|
93
|
-
chain_id: number;
|
|
94
|
-
recipient_address: string;
|
|
95
|
-
available_tokens: TokenConfig[];
|
|
96
|
-
metadata: {
|
|
97
|
-
name: string;
|
|
98
|
-
type: string;
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
export interface BackendIntentResponse {
|
|
102
|
-
id: string;
|
|
103
|
-
amount: string;
|
|
104
|
-
currency: string;
|
|
105
|
-
chainId: number;
|
|
106
|
-
tokenAddress: Address;
|
|
107
|
-
merchantAddress: Address;
|
|
108
|
-
expiresAt: string;
|
|
109
|
-
signature: string;
|
|
110
|
-
nonce: string;
|
|
111
|
-
}
|
|
112
4
|
export interface PaymentCallbacks {
|
|
5
|
+
/** Fired when the checkout iframe opens. */
|
|
113
6
|
onOpen?: () => void;
|
|
7
|
+
/** Fired when the checkout iframe is closed (by user or programmatically). */
|
|
114
8
|
onClose?: () => void;
|
|
115
|
-
|
|
116
|
-
onTxSubmitted?: (txHash:
|
|
117
|
-
|
|
9
|
+
/** Fired when the transaction hash is available (TX sent, not yet confirmed). */
|
|
10
|
+
onTxSubmitted?: (txHash: string) => void;
|
|
11
|
+
/** Fired when the payment is confirmed on-chain. */
|
|
12
|
+
onSuccess?: (data: {
|
|
13
|
+
txHash: string;
|
|
14
|
+
intentId?: string;
|
|
15
|
+
}) => void;
|
|
16
|
+
/** Fired when the user explicitly cancels the payment. */
|
|
118
17
|
onCancel?: () => void;
|
|
18
|
+
/** Fired on payment error. */
|
|
119
19
|
onError?: (error: Error) => void;
|
|
120
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Options for DCP.pay() — tool-based payments (payment links, buttons, etc.)
|
|
23
|
+
*/
|
|
121
24
|
export interface DCPPayOptions {
|
|
25
|
+
/** The payment tool ID (from the dashboard). */
|
|
122
26
|
toolId: string;
|
|
27
|
+
/** Optional amount override in USD. */
|
|
123
28
|
amountUsd?: number;
|
|
124
|
-
|
|
125
|
-
chainId?: number;
|
|
126
|
-
metadata?: Record<string, string>;
|
|
29
|
+
/** Payment lifecycle callbacks. */
|
|
127
30
|
callbacks?: PaymentCallbacks;
|
|
128
31
|
}
|
|
129
32
|
/**
|
|
130
|
-
* Options for DCP.Payment() — integration-based payments
|
|
33
|
+
* Options for DCP.Payment() — integration-based payments with dynamic amounts.
|
|
131
34
|
*/
|
|
132
35
|
export interface DCPPaymentOptions {
|
|
36
|
+
/** The integration public ID. */
|
|
133
37
|
integrationId: string;
|
|
38
|
+
/** Amount in USD (mutually exclusive with `amount`). */
|
|
134
39
|
amount_usd?: string;
|
|
40
|
+
/** Amount in token units (mutually exclusive with `amount_usd`). */
|
|
135
41
|
amount?: string | number;
|
|
42
|
+
/** Token symbol (e.g., 'USDC'). When omitted, user picks from available tokens. */
|
|
136
43
|
currency?: string;
|
|
44
|
+
/** Chain ID override. */
|
|
137
45
|
chainId?: number;
|
|
46
|
+
/** Arbitrary metadata passed to the backend. */
|
|
138
47
|
metadata?: Record<string, any>;
|
|
48
|
+
/** Payment lifecycle callbacks. */
|
|
139
49
|
callbacks?: PaymentCallbacks;
|
|
140
50
|
}
|
|
141
|
-
/**
|
|
142
|
-
* Integration config returned from GET /public/integrations/:id
|
|
143
|
-
*/
|
|
144
|
-
export interface IntegrationConfig {
|
|
145
|
-
publicId: string;
|
|
146
|
-
name: string;
|
|
147
|
-
allowChains: number[];
|
|
148
|
-
allowTokens: string[];
|
|
149
|
-
autoConversion: boolean;
|
|
150
|
-
preferredToken: string | null;
|
|
151
|
-
chains: Record<number, {
|
|
152
|
-
name: string;
|
|
153
|
-
tokens: TokenConfig[];
|
|
154
|
-
}>;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Intent response from POST /public/integrations/:id/intent
|
|
158
|
-
*/
|
|
159
|
-
export interface IntegrationIntentResponse {
|
|
160
|
-
id?: string;
|
|
161
|
-
intent_id?: string;
|
|
162
|
-
chain_id: number;
|
|
163
|
-
recipient: Address;
|
|
164
|
-
amount_wei: string;
|
|
165
|
-
currency: string;
|
|
166
|
-
expires_at?: string;
|
|
167
|
-
signature?: string;
|
|
168
|
-
status?: string;
|
|
169
|
-
asset_type?: 'native' | 'erc20';
|
|
170
|
-
token_address?: Address;
|
|
171
|
-
token_decimals?: number;
|
|
172
|
-
metadata?: Record<string, any>;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Discriminated union for modal mode
|
|
176
|
-
*/
|
|
177
|
-
export type ModalMode = {
|
|
178
|
-
type: 'tool';
|
|
179
|
-
toolId: string;
|
|
180
|
-
} | {
|
|
181
|
-
type: 'integration';
|
|
182
|
-
integrationId: string;
|
|
183
|
-
amount_usd?: string;
|
|
184
|
-
amount?: string | number;
|
|
185
|
-
currency?: string;
|
|
186
|
-
chainId?: number;
|
|
187
|
-
metadata?: Record<string, any>;
|
|
188
|
-
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@directcryptopay/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Official SDK for DirectCryptoPay — accept crypto payments directly to your wallet. Non-custodial, multi-chain, developer-first.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/dcp-sdk.umd.js",
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
11
12
|
"import": "./dist/index.js",
|
|
12
|
-
"require": "./dist/dcp-sdk.umd.js"
|
|
13
|
-
"types": "./dist/index.d.ts"
|
|
13
|
+
"require": "./dist/dcp-sdk.umd.js"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
@@ -53,17 +53,7 @@
|
|
|
53
53
|
"typecheck": "tsc --noEmit",
|
|
54
54
|
"prepublishOnly": "npm run build"
|
|
55
55
|
},
|
|
56
|
-
"dependencies": {
|
|
57
|
-
"@reown/appkit": "1.8.14",
|
|
58
|
-
"@reown/appkit-adapter-wagmi": "1.8.14",
|
|
59
|
-
"@tanstack/react-query": "^5.62.0",
|
|
60
|
-
"@wagmi/core": "^2.22.1",
|
|
61
|
-
"preact": "^10.25.0",
|
|
62
|
-
"viem": "^2.40.3",
|
|
63
|
-
"wagmi": "^2.19.5"
|
|
64
|
-
},
|
|
65
56
|
"devDependencies": {
|
|
66
|
-
"@preact/preset-vite": "^2.9.2",
|
|
67
57
|
"typescript": "^5.7.2",
|
|
68
58
|
"vite": "^6.0.0"
|
|
69
59
|
}
|