stablezact-pay 0.66.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.
@@ -0,0 +1,302 @@
1
+ import { B as Buffer$1 } from "./index-DYkC2Bui.js";
2
+ import React from "react";
3
+ import { createRoot } from "react-dom/client";
4
+ import { C as CoinleyPayment } from "./CoinleyPayment-BA2ym_mw.js";
5
+ const global = globalThis || void 0 || self;
6
+ (function initBufferPolyfill() {
7
+ const BufferClass = Buffer$1;
8
+ if (typeof globalThis !== "undefined") {
9
+ globalThis.Buffer = BufferClass;
10
+ }
11
+ if (typeof window !== "undefined") {
12
+ window.Buffer = BufferClass;
13
+ }
14
+ if (typeof global !== "undefined") {
15
+ global.Buffer = BufferClass;
16
+ }
17
+ if (typeof self !== "undefined") {
18
+ self.Buffer = BufferClass;
19
+ }
20
+ })();
21
+ class CoinleyVanilla {
22
+ /**
23
+ * Initialize Coinley payment SDK
24
+ * @param {Object} config - SDK configuration
25
+ * @param {string} [config.publicKey] - Merchant public key (recommended - starts with 'pk_')
26
+ * @param {string} [config.apiKey] - Merchant API key (legacy, used with apiSecret)
27
+ * @param {string} [config.apiSecret] - Merchant API secret (legacy, used with apiKey)
28
+ * @param {string} config.apiUrl - API base URL (required)
29
+ * @param {string} [config.theme='light'] - UI theme ('light' or 'dark')
30
+ * @param {boolean} [config.debug=false] - Enable debug logging
31
+ */
32
+ constructor(config = {}) {
33
+ if (!config.publicKey && !config.apiKey) {
34
+ throw new Error("CoinleyVanilla: publicKey or apiKey is required");
35
+ }
36
+ if (!config.publicKey && !config.apiSecret) {
37
+ throw new Error("CoinleyVanilla: apiSecret is required when using apiKey");
38
+ }
39
+ if (!config.apiUrl) {
40
+ throw new Error("CoinleyVanilla: apiUrl is required");
41
+ }
42
+ this.config = {
43
+ publicKey: config.publicKey || null,
44
+ apiKey: config.apiKey || null,
45
+ apiSecret: config.apiSecret || null,
46
+ apiUrl: config.apiUrl.replace(/\/$/, ""),
47
+ // Remove trailing slash
48
+ theme: config.theme || "light",
49
+ debug: config.debug || false,
50
+ ...config
51
+ };
52
+ this.isOpen = false;
53
+ this.root = null;
54
+ this.container = null;
55
+ this.callbacks = {};
56
+ this.currentPayment = null;
57
+ if (this.config.debug) ;
58
+ }
59
+ /**
60
+ * Open payment modal
61
+ * @param {Object} paymentConfig - Payment configuration
62
+ * @param {number} paymentConfig.amount - Payment amount (required)
63
+ * @param {string} paymentConfig.customerEmail - Customer email (required)
64
+ * @param {string} [paymentConfig.merchantName] - Merchant display name
65
+ * @param {string} [paymentConfig.callbackUrl] - Webhook callback URL
66
+ * @param {Object} paymentConfig.merchantWalletAddresses - Network-specific wallet addresses
67
+ * @param {string} [paymentConfig.preferredNetwork] - Default network to select
68
+ * @param {string} [paymentConfig.preferredCurrency] - Default token to select
69
+ * @param {Object} [paymentConfig.metadata] - Custom metadata to attach
70
+ * @param {Object} callbacks - Event callbacks
71
+ * @param {Function} callbacks.onSuccess - Called when payment succeeds (paymentId, txHash, details)
72
+ * @param {Function} callbacks.onError - Called when payment fails (error)
73
+ * @param {Function} callbacks.onClose - Called when modal closes
74
+ */
75
+ open(paymentConfig, callbacks = {}) {
76
+ if (this.isOpen) {
77
+ return;
78
+ }
79
+ try {
80
+ this._validatePaymentConfig(paymentConfig);
81
+ this.callbacks = callbacks;
82
+ this.currentPayment = paymentConfig;
83
+ this._createContainer();
84
+ this.root = createRoot(this.container);
85
+ this.isOpen = true;
86
+ this.root.render(
87
+ React.createElement(CoinleyPayment, {
88
+ publicKey: this.config.publicKey,
89
+ apiKey: this.config.apiKey,
90
+ apiSecret: this.config.apiSecret,
91
+ apiUrl: this.config.apiUrl,
92
+ isOpen: true,
93
+ theme: this.config.theme,
94
+ config: {
95
+ amount: paymentConfig.amount,
96
+ customerEmail: paymentConfig.customerEmail,
97
+ merchantName: paymentConfig.merchantName || "Merchant",
98
+ callbackUrl: paymentConfig.callbackUrl || this._getDefaultCallbackUrl(),
99
+ merchantWalletAddresses: paymentConfig.merchantWalletAddresses || {},
100
+ preferredNetwork: paymentConfig.preferredNetwork,
101
+ preferredCurrency: paymentConfig.preferredCurrency,
102
+ metadata: {
103
+ ...paymentConfig.metadata,
104
+ source: "vanilla-sdk",
105
+ sdkVersion: "2.0.0",
106
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
107
+ }
108
+ },
109
+ onSuccess: this._handleSuccess.bind(this),
110
+ onError: this._handleError.bind(this),
111
+ onClose: this._handleClose.bind(this)
112
+ })
113
+ );
114
+ if (this.config.debug) {
115
+ }
116
+ } catch (error) {
117
+ if (callbacks.onError) {
118
+ callbacks.onError(error.message || "Failed to open payment modal");
119
+ }
120
+ }
121
+ }
122
+ /**
123
+ * Close payment modal programmatically
124
+ */
125
+ close() {
126
+ if (!this.isOpen) {
127
+ return;
128
+ }
129
+ this._cleanup();
130
+ if (this.config.debug) ;
131
+ }
132
+ /**
133
+ * Check if payment modal is currently open
134
+ * @returns {boolean}
135
+ */
136
+ isPaymentOpen() {
137
+ return this.isOpen;
138
+ }
139
+ /**
140
+ * Update SDK configuration
141
+ * @param {Object} newConfig - Configuration updates
142
+ */
143
+ updateConfig(newConfig) {
144
+ this.config = { ...this.config, ...newConfig };
145
+ if (this.config.debug) ;
146
+ }
147
+ /**
148
+ * Get current configuration (read-only)
149
+ * @returns {Object}
150
+ */
151
+ getConfig() {
152
+ return { ...this.config };
153
+ }
154
+ /**
155
+ * Get current payment details
156
+ * @returns {Object|null}
157
+ */
158
+ getCurrentPayment() {
159
+ return this.currentPayment ? { ...this.currentPayment } : null;
160
+ }
161
+ // ==================== PRIVATE METHODS ====================
162
+ /**
163
+ * Validate payment configuration
164
+ * @private
165
+ */
166
+ _validatePaymentConfig(config) {
167
+ if (!config) {
168
+ throw new Error("Payment configuration is required");
169
+ }
170
+ if (!config.amount || typeof config.amount !== "number" || config.amount <= 0) {
171
+ throw new Error("Valid amount (number > 0) is required");
172
+ }
173
+ if (!config.customerEmail || typeof config.customerEmail !== "string") {
174
+ throw new Error("Customer email is required");
175
+ }
176
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
177
+ if (!emailRegex.test(config.customerEmail)) {
178
+ throw new Error("Invalid email format");
179
+ }
180
+ if (config.merchantWalletAddresses) {
181
+ if (typeof config.merchantWalletAddresses !== "object") {
182
+ throw new Error("merchantWalletAddresses must be an object");
183
+ }
184
+ Object.keys(config.merchantWalletAddresses).length;
185
+ }
186
+ }
187
+ /**
188
+ * Create DOM container for payment modal
189
+ * @private
190
+ */
191
+ _createContainer() {
192
+ if (this.container) {
193
+ return;
194
+ }
195
+ this.container = document.createElement("div");
196
+ this.container.id = "coinley-payment-container";
197
+ this.container.style.cssText = `
198
+ position: fixed;
199
+ top: 0;
200
+ left: 0;
201
+ right: 0;
202
+ bottom: 0;
203
+ z-index: 999999;
204
+ `;
205
+ document.body.appendChild(this.container);
206
+ }
207
+ /**
208
+ * Get default callback URL
209
+ * @private
210
+ */
211
+ _getDefaultCallbackUrl() {
212
+ if (typeof window !== "undefined") {
213
+ return `${window.location.origin}/api/webhooks/coinley`;
214
+ }
215
+ return "";
216
+ }
217
+ /**
218
+ * Handle successful payment
219
+ * @private
220
+ */
221
+ _handleSuccess(paymentId, transactionHash, paymentDetails) {
222
+ if (this.config.debug) ;
223
+ if (this.callbacks.onSuccess) {
224
+ this.callbacks.onSuccess(paymentId, transactionHash, paymentDetails);
225
+ }
226
+ }
227
+ /**
228
+ * Handle payment error
229
+ * @private
230
+ */
231
+ _handleError(error) {
232
+ if (this.config.debug) ;
233
+ if (this.callbacks.onError) {
234
+ this.callbacks.onError(error);
235
+ }
236
+ }
237
+ /**
238
+ * Handle modal close
239
+ * @private
240
+ */
241
+ _handleClose() {
242
+ this._cleanup();
243
+ if (this.callbacks.onClose) {
244
+ this.callbacks.onClose();
245
+ }
246
+ }
247
+ /**
248
+ * Cleanup resources
249
+ * @private
250
+ */
251
+ _cleanup() {
252
+ this.isOpen = false;
253
+ if (this.root) {
254
+ try {
255
+ this.root.unmount();
256
+ } catch (error) {
257
+ }
258
+ this.root = null;
259
+ }
260
+ if (this.container && this.container.parentNode) {
261
+ this.container.parentNode.removeChild(this.container);
262
+ this.container = null;
263
+ }
264
+ this.currentPayment = null;
265
+ }
266
+ }
267
+ if (typeof window !== "undefined") {
268
+ window.CoinleyVanilla = CoinleyVanilla;
269
+ if (document.readyState === "loading") {
270
+ document.addEventListener("DOMContentLoaded", autoInitialize);
271
+ } else {
272
+ autoInitialize();
273
+ }
274
+ }
275
+ function autoInitialize() {
276
+ const scripts = document.querySelectorAll('script[src*="coinley-vanilla"]');
277
+ scripts.forEach((script) => {
278
+ const publicKey = script.getAttribute("data-public-key");
279
+ const apiKey = script.getAttribute("data-api-key");
280
+ const apiSecret = script.getAttribute("data-api-secret");
281
+ const apiUrl = script.getAttribute("data-api-url");
282
+ const theme = script.getAttribute("data-theme") || "light";
283
+ const debug = script.hasAttribute("data-debug");
284
+ if ((publicKey || apiKey && apiSecret) && apiUrl) {
285
+ try {
286
+ window.coinley = new CoinleyVanilla({
287
+ publicKey,
288
+ apiKey,
289
+ apiSecret,
290
+ apiUrl,
291
+ theme,
292
+ debug
293
+ });
294
+ } catch (error) {
295
+ }
296
+ }
297
+ });
298
+ }
299
+ export {
300
+ CoinleyVanilla as default
301
+ };
302
+ //# sourceMappingURL=index-BTn5xw-W.js.map