@sikka/aps 0.0.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.
@@ -0,0 +1,1863 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/react/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ APSProvider: () => APSProvider,
24
+ ErrorDisplay: () => ErrorDisplay,
25
+ HostedCheckoutButton: () => HostedCheckoutButton,
26
+ PaymentStatus: () => PaymentStatus,
27
+ TokenizationForm: () => TokenizationForm,
28
+ useAPS: () => useAPS,
29
+ useCheckout: () => useCheckout,
30
+ usePayment: () => usePayment
31
+ });
32
+ module.exports = __toCommonJS(index_exports);
33
+
34
+ // src/react/APSProvider.tsx
35
+ var import_react = require("react");
36
+ var import_jsx_runtime = require("react/jsx-runtime");
37
+ var APSContext = (0, import_react.createContext)(void 0);
38
+ var APSProvider = ({ client, children }) => {
39
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(APSContext.Provider, { value: { client }, children });
40
+ };
41
+ function useAPSContext() {
42
+ const context = (0, import_react.useContext)(APSContext);
43
+ if (context === void 0) {
44
+ throw new Error(
45
+ "useAPS must be used within an APSProvider. Make sure to wrap your app with <APSProvider client={aps}>...</APSProvider>"
46
+ );
47
+ }
48
+ return context;
49
+ }
50
+
51
+ // src/react/useAPS.ts
52
+ function useAPS() {
53
+ const { client } = useAPSContext();
54
+ return client;
55
+ }
56
+
57
+ // src/react/useCheckout.ts
58
+ var import_react2 = require("react");
59
+ function useCheckout() {
60
+ const aps = useAPS();
61
+ const [state, setState] = (0, import_react2.useState)({
62
+ checkout: null,
63
+ isLoading: false,
64
+ error: null
65
+ });
66
+ const isMountedRef = (0, import_react2.useRef)(true);
67
+ const createCheckout = (0, import_react2.useCallback)(async (options) => {
68
+ setState((prev) => ({ ...prev, isLoading: true, error: null }));
69
+ try {
70
+ const checkout = await aps.hostedCheckout.create(options);
71
+ if (isMountedRef.current) {
72
+ setState({
73
+ checkout,
74
+ isLoading: false,
75
+ error: null
76
+ });
77
+ }
78
+ return checkout;
79
+ } catch (err) {
80
+ const error = err instanceof Error ? err : new Error(String(err));
81
+ if (isMountedRef.current) {
82
+ setState((prev) => ({
83
+ ...prev,
84
+ isLoading: false,
85
+ error
86
+ }));
87
+ }
88
+ throw error;
89
+ }
90
+ }, [aps]);
91
+ const redirectToCheckout = (0, import_react2.useCallback)(() => {
92
+ const { checkout } = state;
93
+ if (!checkout?.redirectForm) {
94
+ throw new Error(
95
+ "No checkout session available. Call createCheckout() first."
96
+ );
97
+ }
98
+ const { url, method, params } = checkout.redirectForm;
99
+ const form = document.createElement("form");
100
+ form.method = method;
101
+ form.action = url;
102
+ Object.entries(params).forEach(([key, value]) => {
103
+ const input = document.createElement("input");
104
+ input.type = "hidden";
105
+ input.name = key;
106
+ input.value = value;
107
+ form.appendChild(input);
108
+ });
109
+ document.body.appendChild(form);
110
+ form.submit();
111
+ }, [state]);
112
+ const reset = (0, import_react2.useCallback)(() => {
113
+ setState({
114
+ checkout: null,
115
+ isLoading: false,
116
+ error: null
117
+ });
118
+ }, []);
119
+ return {
120
+ ...state,
121
+ createCheckout,
122
+ redirectToCheckout,
123
+ reset
124
+ };
125
+ }
126
+
127
+ // src/react/usePayment.ts
128
+ var import_react3 = require("react");
129
+ function usePayment() {
130
+ const aps = useAPS();
131
+ const [state, setState] = (0, import_react3.useState)({
132
+ payment: null,
133
+ status: null,
134
+ isLoading: false,
135
+ error: null
136
+ });
137
+ const isMountedRef = (0, import_react3.useRef)(true);
138
+ const createPaymentLink = (0, import_react3.useCallback)(async (options) => {
139
+ setState((prev) => ({ ...prev, isLoading: true, error: null }));
140
+ try {
141
+ const payment = await aps.paymentLinks.create(options);
142
+ if (isMountedRef.current) {
143
+ setState({
144
+ payment,
145
+ status: "pending",
146
+ isLoading: false,
147
+ error: null
148
+ });
149
+ }
150
+ return payment;
151
+ } catch (err) {
152
+ const error = err instanceof Error ? err : new Error(String(err));
153
+ if (isMountedRef.current) {
154
+ setState((prev) => ({
155
+ ...prev,
156
+ isLoading: false,
157
+ error
158
+ }));
159
+ }
160
+ throw error;
161
+ }
162
+ }, [aps]);
163
+ const createCustomPayment = (0, import_react3.useCallback)(async (options) => {
164
+ setState((prev) => ({ ...prev, isLoading: true, error: null }));
165
+ try {
166
+ const payment = await aps.customPaymentPage.charge(options);
167
+ if (isMountedRef.current) {
168
+ setState({
169
+ payment,
170
+ status: payment.status,
171
+ isLoading: false,
172
+ error: null
173
+ });
174
+ }
175
+ return payment;
176
+ } catch (err) {
177
+ const error = err instanceof Error ? err : new Error(String(err));
178
+ if (isMountedRef.current) {
179
+ setState((prev) => ({
180
+ ...prev,
181
+ isLoading: false,
182
+ error
183
+ }));
184
+ }
185
+ throw error;
186
+ }
187
+ }, [aps]);
188
+ const checkStatus = (0, import_react3.useCallback)(async (options) => {
189
+ setState((prev) => ({ ...prev, isLoading: true, error: null }));
190
+ try {
191
+ const result = await aps.payments.query(options);
192
+ const status = result.status;
193
+ if (isMountedRef.current) {
194
+ setState((prev) => ({
195
+ ...prev,
196
+ status,
197
+ isLoading: false,
198
+ error: null
199
+ }));
200
+ }
201
+ return status;
202
+ } catch (err) {
203
+ const error = err instanceof Error ? err : new Error(String(err));
204
+ if (isMountedRef.current) {
205
+ setState((prev) => ({
206
+ ...prev,
207
+ isLoading: false,
208
+ error
209
+ }));
210
+ }
211
+ throw error;
212
+ }
213
+ }, [aps]);
214
+ const confirmPayment = (0, import_react3.useCallback)(async (options) => {
215
+ const {
216
+ transactionId,
217
+ pollInterval = 2e3,
218
+ maxAttempts = 30
219
+ } = options;
220
+ setState((prev) => ({ ...prev, isLoading: true, error: null }));
221
+ try {
222
+ let attempts = 0;
223
+ let finalStatus = "pending";
224
+ while (attempts < maxAttempts) {
225
+ const status = await checkStatus({ transactionId });
226
+ finalStatus = status;
227
+ if (["captured", "failed", "voided", "refunded", "cancelled"].includes(status)) {
228
+ break;
229
+ }
230
+ await new Promise((resolve) => setTimeout(resolve, pollInterval));
231
+ attempts++;
232
+ }
233
+ if (isMountedRef.current) {
234
+ setState((prev) => ({
235
+ ...prev,
236
+ status: finalStatus,
237
+ isLoading: false,
238
+ error: null
239
+ }));
240
+ }
241
+ return finalStatus;
242
+ } catch (err) {
243
+ const error = err instanceof Error ? err : new Error(String(err));
244
+ if (isMountedRef.current) {
245
+ setState((prev) => ({
246
+ ...prev,
247
+ isLoading: false,
248
+ error
249
+ }));
250
+ }
251
+ throw error;
252
+ }
253
+ }, [checkStatus]);
254
+ const capture = (0, import_react3.useCallback)(async (transactionId, amount) => {
255
+ setState((prev) => ({ ...prev, isLoading: true, error: null }));
256
+ try {
257
+ await aps.payments.capture({ transactionId, amount });
258
+ if (isMountedRef.current) {
259
+ setState((prev) => ({
260
+ ...prev,
261
+ status: "captured",
262
+ isLoading: false,
263
+ error: null
264
+ }));
265
+ }
266
+ } catch (err) {
267
+ const error = err instanceof Error ? err : new Error(String(err));
268
+ if (isMountedRef.current) {
269
+ setState((prev) => ({
270
+ ...prev,
271
+ isLoading: false,
272
+ error
273
+ }));
274
+ }
275
+ throw error;
276
+ }
277
+ }, [aps]);
278
+ const refund = (0, import_react3.useCallback)(async (transactionId, amount, reason) => {
279
+ setState((prev) => ({ ...prev, isLoading: true, error: null }));
280
+ try {
281
+ await aps.payments.refund({ transactionId, amount, reason });
282
+ if (isMountedRef.current) {
283
+ setState((prev) => ({
284
+ ...prev,
285
+ status: "refunded",
286
+ isLoading: false,
287
+ error: null
288
+ }));
289
+ }
290
+ } catch (err) {
291
+ const error = err instanceof Error ? err : new Error(String(err));
292
+ if (isMountedRef.current) {
293
+ setState((prev) => ({
294
+ ...prev,
295
+ isLoading: false,
296
+ error
297
+ }));
298
+ }
299
+ throw error;
300
+ }
301
+ }, [aps]);
302
+ const voidPayment = (0, import_react3.useCallback)(async (transactionId, reason) => {
303
+ setState((prev) => ({ ...prev, isLoading: true, error: null }));
304
+ try {
305
+ await aps.payments.void({ transactionId, reason });
306
+ if (isMountedRef.current) {
307
+ setState((prev) => ({
308
+ ...prev,
309
+ status: "voided",
310
+ isLoading: false,
311
+ error: null
312
+ }));
313
+ }
314
+ } catch (err) {
315
+ const error = err instanceof Error ? err : new Error(String(err));
316
+ if (isMountedRef.current) {
317
+ setState((prev) => ({
318
+ ...prev,
319
+ isLoading: false,
320
+ error
321
+ }));
322
+ }
323
+ throw error;
324
+ }
325
+ }, [aps]);
326
+ const reset = (0, import_react3.useCallback)(() => {
327
+ setState({
328
+ payment: null,
329
+ status: null,
330
+ isLoading: false,
331
+ error: null
332
+ });
333
+ }, []);
334
+ return {
335
+ ...state,
336
+ createPaymentLink,
337
+ createCustomPayment,
338
+ confirmPayment,
339
+ checkStatus,
340
+ capture,
341
+ refund,
342
+ void: voidPayment,
343
+ reset
344
+ };
345
+ }
346
+
347
+ // src/react/TokenizationForm.tsx
348
+ var import_react4 = require("react");
349
+ var import_jsx_runtime2 = require("react/jsx-runtime");
350
+ function detectCardBrand(cardNumber) {
351
+ const number = cardNumber.replace(/\D/g, "");
352
+ if (/^4/.test(number)) return "visa";
353
+ if (/^5[1-5]/.test(number)) return "mastercard";
354
+ if (/^3[47]/.test(number)) return "amex";
355
+ if (/^6(?:011|5)/.test(number)) return "discover";
356
+ if (/^(?:2131|1800|35)/.test(number)) return "jcb";
357
+ if (/^9792/.test(number)) return "troy";
358
+ if (/^50/.test(number) || /^4571/.test(number)) return "mada";
359
+ return "unknown";
360
+ }
361
+ var DefaultIcons = {
362
+ visa: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { viewBox: "0 0 48 48", className: "w-8 h-8", children: [
363
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { fill: "#1A1F71", rx: "4", width: "48", height: "48" }),
364
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
365
+ "path",
366
+ {
367
+ fill: "#fff",
368
+ d: "M19.5 30h-3l1.9-11.5h3L19.5 30zm11.4 0h-2.7l-1.7-8.2c-.2-.9-.4-1.7-.5-2.6-.1 0-.2.1-.3.2-.6.8-1.3 1.6-1.9 2.4L22.5 30h-3l3.1-11.5h2.8l.4 2.1c.7-1 1.5-2 2.3-2.9.9-1.2 2-1.7 3.4-1.7.5 0 1 0 1.5.1l-2.1 13.9zm6.6-11.3c-.8-.3-2.6-.7-4.6-.7-5.1 0-8.7 2.7-8.7 6.5 0 2.9 2.6 4.5 4.6 5.5 2 .9 2.7 1.6 2.7 2.4 0 1.3-1.6 1.9-3 1.9-2 0-3.1-.3-4.8-1l-.7-.3-.7 4.3c1.2.5 3.4 1 5.7 1 5.4 0 8.9-2.7 8.9-6.8 0-2.3-1.4-4-4.4-5.5-1.8-.9-2.9-1.6-2.9-2.5 0-.8.9-1.7 2.8-1.7 1.6 0 2.8.3 3.7.7l.4.2.7-4.2z"
369
+ }
370
+ )
371
+ ] }),
372
+ mastercard: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { viewBox: "0 0 48 48", className: "w-8 h-8", children: [
373
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { fill: "#000", rx: "4", width: "48", height: "48" }),
374
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { fill: "#EB001B", cx: "18", cy: "24", r: "10" }),
375
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { fill: "#F79E1B", cx: "30", cy: "24", r: "10", opacity: "0.8" })
376
+ ] }),
377
+ amex: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { viewBox: "0 0 48 48", className: "w-8 h-8", children: [
378
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { fill: "#006FCF", rx: "4", width: "48", height: "48" }),
379
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
380
+ "path",
381
+ {
382
+ fill: "#fff",
383
+ d: "M10 18h28v12H10V18zm2 2v8h24v-8H12z"
384
+ }
385
+ )
386
+ ] }),
387
+ mada: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { viewBox: "0 0 48 48", className: "w-8 h-8", children: [
388
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { fill: "#006C35", rx: "4", width: "48", height: "48" }),
389
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
390
+ "path",
391
+ {
392
+ fill: "#fff",
393
+ d: "M12 20h24v8H12v-8zm2 2v4h20v-4H14z"
394
+ }
395
+ )
396
+ ] }),
397
+ unknown: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { viewBox: "0 0 48 48", className: "w-8 h-8", children: [
398
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { fill: "#666", rx: "4", width: "48", height: "48" }),
399
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { fill: "#999", x: "10", y: "18", width: "28", height: "12", rx: "2" })
400
+ ] })
401
+ };
402
+ var defaultStyles = {
403
+ container: {
404
+ maxWidth: "480px",
405
+ margin: "0 auto"
406
+ },
407
+ form: {
408
+ display: "flex",
409
+ flexDirection: "column",
410
+ gap: "16px"
411
+ },
412
+ inputGroup: {
413
+ display: "flex",
414
+ flexDirection: "column",
415
+ gap: "4px"
416
+ },
417
+ label: {
418
+ fontSize: "14px",
419
+ fontWeight: "500",
420
+ color: "#374151"
421
+ },
422
+ input: {
423
+ padding: "12px 16px",
424
+ fontSize: "16px",
425
+ border: "1px solid #D1D5DB",
426
+ borderRadius: "8px",
427
+ outline: "none",
428
+ transition: "border-color 0.2s"
429
+ },
430
+ inputError: {
431
+ borderColor: "#EF4444"
432
+ },
433
+ row: {
434
+ display: "grid",
435
+ gridTemplateColumns: "1fr 1fr",
436
+ gap: "12px"
437
+ },
438
+ button: {
439
+ padding: "14px 24px",
440
+ fontSize: "16px",
441
+ fontWeight: "600",
442
+ color: "#fff",
443
+ backgroundColor: "#7C3AED",
444
+ border: "none",
445
+ borderRadius: "8px",
446
+ cursor: "pointer",
447
+ transition: "background-color 0.2s"
448
+ },
449
+ buttonDisabled: {
450
+ backgroundColor: "#A78BFA",
451
+ cursor: "not-allowed"
452
+ },
453
+ securityNotice: {
454
+ padding: "12px",
455
+ backgroundColor: "#D1FAE5",
456
+ borderRadius: "8px",
457
+ fontSize: "13px",
458
+ color: "#065F46"
459
+ }
460
+ };
461
+ var TokenizationForm = ({
462
+ actionUrl,
463
+ formParams,
464
+ customerEmail = "",
465
+ onSuccess: _onSuccess,
466
+ // Success is handled via returnUrl redirect
467
+ onError,
468
+ styles = {},
469
+ icons = {},
470
+ labels = {},
471
+ placeholders = {},
472
+ disableFormatting = false,
473
+ showCardIcons = true,
474
+ showSecurityNotice = true,
475
+ className = {}
476
+ }) => {
477
+ const [cardNumber, setCardNumber] = (0, import_react4.useState)("");
478
+ const [expiryDate, setExpiryDate] = (0, import_react4.useState)("");
479
+ const [cvv, setCvv] = (0, import_react4.useState)("");
480
+ const [cardHolderName, setCardHolderName] = (0, import_react4.useState)("");
481
+ const [email, setEmail] = (0, import_react4.useState)(customerEmail);
482
+ const [loading, setLoading] = (0, import_react4.useState)(false);
483
+ const [errors, setErrors] = (0, import_react4.useState)({});
484
+ const [cardBrand, setCardBrand] = (0, import_react4.useState)("unknown");
485
+ const mergedStyles = {
486
+ ...defaultStyles,
487
+ ...styles
488
+ };
489
+ const mergedIcons = {
490
+ ...DefaultIcons,
491
+ ...icons
492
+ };
493
+ const mergedLabels = {
494
+ cardNumber: "Card Number",
495
+ cardHolder: "Card Holder Name",
496
+ customerEmail: "Customer Email",
497
+ expiryDate: "Expiry Date",
498
+ cvv: "CVV",
499
+ submitButton: "Secure Payment",
500
+ processing: "Processing...",
501
+ ...labels
502
+ };
503
+ const mergedPlaceholders = {
504
+ cardNumber: "1234 5678 9012 3456",
505
+ cardHolder: "John Doe",
506
+ customerEmail: "customer@example.com",
507
+ expiryDate: "MM/YY",
508
+ cvv: "123",
509
+ ...placeholders
510
+ };
511
+ const formatCardNumber = (value) => {
512
+ if (disableFormatting) return value;
513
+ const v = value.replace(/\s+/g, "").replace(/[^0-9]/gi, "");
514
+ const matches = v.match(/\d{4,16}/g);
515
+ const match = matches && matches[0] || "";
516
+ const parts = [];
517
+ for (let i = 0, len = match.length; i < len; i += 4) {
518
+ parts.push(match.substring(i, i + 4));
519
+ }
520
+ if (parts.length) {
521
+ return parts.join(" ");
522
+ }
523
+ return value;
524
+ };
525
+ const formatExpiryDate = (value) => {
526
+ if (disableFormatting) return value;
527
+ const v = value.replace(/\s+/g, "").replace(/[^0-9]/gi, "");
528
+ if (v.length >= 2) {
529
+ return v.substring(0, 2) + "/" + v.substring(2, 4);
530
+ }
531
+ return v;
532
+ };
533
+ const validateForm = () => {
534
+ const newErrors = {};
535
+ if (!cardNumber || cardNumber.replace(/\s/g, "").length < 13) {
536
+ newErrors.cardNumber = "Invalid card number";
537
+ }
538
+ if (!expiryDate || expiryDate.length !== 5) {
539
+ newErrors.expiryDate = "Invalid expiry date";
540
+ }
541
+ if (!cvv || cvv.length < 3) {
542
+ newErrors.cvv = "Invalid CVV";
543
+ }
544
+ if (!cardHolderName || cardHolderName.length < 2) {
545
+ newErrors.cardHolder = "Card holder name is required";
546
+ }
547
+ if (email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
548
+ newErrors.email = "Invalid email address";
549
+ }
550
+ setErrors(newErrors);
551
+ return Object.keys(newErrors).length === 0;
552
+ };
553
+ const handleSubmit = (e) => {
554
+ e.preventDefault();
555
+ if (!validateForm()) {
556
+ onError?.("Please fill in all required fields correctly");
557
+ return;
558
+ }
559
+ setLoading(true);
560
+ const form = document.createElement("form");
561
+ form.method = "POST";
562
+ form.action = actionUrl;
563
+ form.style.display = "none";
564
+ Object.entries(formParams).forEach(([key, value]) => {
565
+ const input = document.createElement("input");
566
+ input.type = "hidden";
567
+ input.name = key;
568
+ input.value = value;
569
+ form.appendChild(input);
570
+ });
571
+ const addHiddenInput = (name, value) => {
572
+ const input = document.createElement("input");
573
+ input.type = "hidden";
574
+ input.name = name;
575
+ input.value = value;
576
+ form.appendChild(input);
577
+ };
578
+ const cleanCardNumber = cardNumber.replace(/\s/g, "");
579
+ const cleanExpiryDate = expiryDate.replace("/", "");
580
+ addHiddenInput("card_number", cleanCardNumber);
581
+ addHiddenInput("expiry_date", cleanExpiryDate);
582
+ addHiddenInput("card_security_code", cvv);
583
+ addHiddenInput("card_holder_name", cardHolderName);
584
+ document.body.appendChild(form);
585
+ form.submit();
586
+ setLoading(false);
587
+ };
588
+ const handleCardNumberChange = (e) => {
589
+ const formatted = formatCardNumber(e.target.value);
590
+ setCardNumber(formatted);
591
+ setCardBrand(detectCardBrand(formatted));
592
+ if (errors.cardNumber) {
593
+ setErrors({ ...errors, cardNumber: "" });
594
+ }
595
+ };
596
+ const handleExpiryDateChange = (e) => {
597
+ const formatted = formatExpiryDate(e.target.value);
598
+ setExpiryDate(formatted);
599
+ if (errors.expiryDate) {
600
+ setErrors({ ...errors, expiryDate: "" });
601
+ }
602
+ };
603
+ const handleCvvChange = (e) => {
604
+ const value = e.target.value.replace(/\D/g, "").substring(0, 4);
605
+ setCvv(value);
606
+ if (errors.cvv) {
607
+ setErrors({ ...errors, cvv: "" });
608
+ }
609
+ };
610
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: mergedStyles.container, className: className.container || "", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("form", { onSubmit: handleSubmit, style: mergedStyles.form, className: className.form || "", children: [
611
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: mergedStyles.inputGroup, className: className.inputGroup || "", children: [
612
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { style: mergedStyles.label, className: className.label || "", children: mergedLabels.cardNumber }),
613
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { position: "relative" }, children: [
614
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
615
+ "input",
616
+ {
617
+ type: "text",
618
+ value: cardNumber,
619
+ onChange: handleCardNumberChange,
620
+ placeholder: mergedPlaceholders.cardNumber,
621
+ maxLength: 19,
622
+ required: true,
623
+ style: {
624
+ ...mergedStyles.input,
625
+ ...errors.cardNumber ? mergedStyles.inputError : {},
626
+ paddingRight: showCardIcons ? "60px" : "16px"
627
+ },
628
+ className: className.input || ""
629
+ }
630
+ ),
631
+ showCardIcons && cardBrand !== "unknown" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
632
+ "div",
633
+ {
634
+ style: {
635
+ position: "absolute",
636
+ right: "12px",
637
+ top: "50%",
638
+ transform: "translateY(-50%)"
639
+ },
640
+ children: mergedIcons[cardBrand]
641
+ }
642
+ )
643
+ ] }),
644
+ errors.cardNumber && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { color: "#EF4444", fontSize: "12px" }, children: errors.cardNumber })
645
+ ] }),
646
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: mergedStyles.inputGroup, className: className.inputGroup || "", children: [
647
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { style: mergedStyles.label, className: className.label || "", children: mergedLabels.cardHolder }),
648
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
649
+ "input",
650
+ {
651
+ type: "text",
652
+ value: cardHolderName,
653
+ onChange: (e) => {
654
+ setCardHolderName(e.target.value);
655
+ if (errors.cardHolder) {
656
+ setErrors({ ...errors, cardHolder: "" });
657
+ }
658
+ },
659
+ placeholder: mergedPlaceholders.cardHolder,
660
+ required: true,
661
+ style: {
662
+ ...mergedStyles.input,
663
+ ...errors.cardHolder ? mergedStyles.inputError : {}
664
+ },
665
+ className: className.input || ""
666
+ }
667
+ ),
668
+ errors.cardHolder && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { color: "#EF4444", fontSize: "12px" }, children: errors.cardHolder })
669
+ ] }),
670
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: mergedStyles.inputGroup, className: className.inputGroup || "", children: [
671
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { style: mergedStyles.label, className: className.label || "", children: mergedLabels.customerEmail }),
672
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
673
+ "input",
674
+ {
675
+ type: "email",
676
+ value: email,
677
+ onChange: (e) => {
678
+ setEmail(e.target.value);
679
+ if (errors.email) {
680
+ setErrors({ ...errors, email: "" });
681
+ }
682
+ },
683
+ placeholder: mergedPlaceholders.customerEmail,
684
+ style: {
685
+ ...mergedStyles.input,
686
+ ...errors.email ? mergedStyles.inputError : {}
687
+ },
688
+ className: className.input || ""
689
+ }
690
+ ),
691
+ errors.email && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { color: "#EF4444", fontSize: "12px" }, children: errors.email }),
692
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { fontSize: "12px", color: "#6B7280" }, children: "Used to associate the saved card with the customer" })
693
+ ] }),
694
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: mergedStyles.row, children: [
695
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: mergedStyles.inputGroup, className: className.inputGroup || "", children: [
696
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { style: mergedStyles.label, className: className.label || "", children: mergedLabels.expiryDate }),
697
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
698
+ "input",
699
+ {
700
+ type: "text",
701
+ value: expiryDate,
702
+ onChange: handleExpiryDateChange,
703
+ placeholder: mergedPlaceholders.expiryDate,
704
+ maxLength: 5,
705
+ required: true,
706
+ style: {
707
+ ...mergedStyles.input,
708
+ ...errors.expiryDate ? mergedStyles.inputError : {}
709
+ },
710
+ className: className.input || ""
711
+ }
712
+ ),
713
+ errors.expiryDate && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { color: "#EF4444", fontSize: "12px" }, children: errors.expiryDate })
714
+ ] }),
715
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: mergedStyles.inputGroup, className: className.inputGroup || "", children: [
716
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { style: mergedStyles.label, className: className.label || "", children: mergedLabels.cvv }),
717
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
718
+ "input",
719
+ {
720
+ type: "text",
721
+ value: cvv,
722
+ onChange: handleCvvChange,
723
+ placeholder: mergedPlaceholders.cvv,
724
+ maxLength: 4,
725
+ required: true,
726
+ style: {
727
+ ...mergedStyles.input,
728
+ ...errors.cvv ? mergedStyles.inputError : {}
729
+ },
730
+ className: className.input || ""
731
+ }
732
+ ),
733
+ errors.cvv && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { color: "#EF4444", fontSize: "12px" }, children: errors.cvv })
734
+ ] })
735
+ ] }),
736
+ showSecurityNotice && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: mergedStyles.securityNotice, children: "\u{1F512} Your card details are securely processed by Amazon Payment Services. We never store your card information." }),
737
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
738
+ "button",
739
+ {
740
+ type: "submit",
741
+ disabled: loading,
742
+ style: {
743
+ ...mergedStyles.button,
744
+ ...loading ? mergedStyles.buttonDisabled : {}
745
+ },
746
+ className: className.button || "",
747
+ children: loading ? mergedLabels.processing : mergedLabels.submitButton
748
+ }
749
+ )
750
+ ] }) });
751
+ };
752
+
753
+ // src/constants.ts
754
+ var ResponseCodes = {
755
+ // Success Codes
756
+ /** Transaction successful */
757
+ SUCCESS: "00000",
758
+ /** Payment link created successfully */
759
+ PAYMENT_LINK_SUCCESS: "48000",
760
+ /** Recurring payment successful */
761
+ RECURRING_SUCCESS: "14000",
762
+ // Authentication & Security
763
+ /** 3D Secure authentication failed */
764
+ AUTHENTICATION_FAILED: "10030",
765
+ /** 3D Secure not enrolled */
766
+ NOT_ENROLLED_3DS: "10031",
767
+ /** Signature mismatch */
768
+ SIGNATURE_MISMATCH: "00008",
769
+ /** Invalid access code */
770
+ INVALID_ACCESS_CODE: "00009",
771
+ /** Invalid merchant identifier */
772
+ INVALID_MERCHANT_ID: "00010",
773
+ // Card Errors
774
+ /** Card expired */
775
+ CARD_EXPIRED: "10035",
776
+ /** Invalid card number */
777
+ INVALID_CARD_NUMBER: "10036",
778
+ /** Invalid CVV */
779
+ INVALID_CVV: "10037",
780
+ /** Card not supported */
781
+ CARD_NOT_SUPPORTED: "10038",
782
+ /** Lost card */
783
+ LOST_CARD: "10039",
784
+ /** Stolen card */
785
+ STOLEN_CARD: "10040",
786
+ /** Restricted card */
787
+ RESTRICTED_CARD: "10041",
788
+ /** Card blocked */
789
+ CARD_BLOCKED: "10042",
790
+ /** Invalid expiry date */
791
+ INVALID_EXPIRY: "10043",
792
+ // Transaction Errors
793
+ /** Transaction declined */
794
+ DECLINED: "14001",
795
+ /** Insufficient funds */
796
+ INSUFFICIENT_FUNDS: "14002",
797
+ /** Transaction limit exceeded */
798
+ LIMIT_EXCEEDED: "14003",
799
+ /** Invalid transaction */
800
+ INVALID_TRANSACTION: "14004",
801
+ /** Duplicate transaction */
802
+ DUPLICATE_TRANSACTION: "14005",
803
+ /** Transaction not allowed */
804
+ TRANSACTION_NOT_ALLOWED: "14006",
805
+ /** Transaction expired */
806
+ TRANSACTION_EXPIRED: "14007",
807
+ /** Transaction already captured */
808
+ ALREADY_CAPTURED: "14008",
809
+ /** Transaction already voided */
810
+ ALREADY_VOIDED: "14009",
811
+ /** Transaction already refunded */
812
+ ALREADY_REFUNDED: "14010",
813
+ // Amount Errors
814
+ /** Invalid amount */
815
+ INVALID_AMOUNT: "15001",
816
+ /** Amount too small */
817
+ AMOUNT_TOO_SMALL: "15002",
818
+ /** Amount too large */
819
+ AMOUNT_TOO_LARGE: "15003",
820
+ /** Currency not supported */
821
+ CURRENCY_NOT_SUPPORTED: "15004",
822
+ // Parameter Errors
823
+ /** Missing parameter */
824
+ MISSING_PARAMETER: "00001",
825
+ /** Invalid parameter format */
826
+ INVALID_PARAMETER: "00002",
827
+ /** Invalid command */
828
+ INVALID_COMMAND: "00003",
829
+ /** Invalid language */
830
+ INVALID_LANGUAGE: "00004",
831
+ /** Invalid currency */
832
+ INVALID_CURRENCY: "00005",
833
+ /** Invalid return URL */
834
+ INVALID_RETURN_URL: "00006",
835
+ /** Invalid customer email */
836
+ INVALID_EMAIL: "00007",
837
+ /** Parameter value not allowed */
838
+ PARAMETER_VALUE_NOT_ALLOWED: "00033",
839
+ // Tokenization Errors
840
+ /** Token not found */
841
+ TOKEN_NOT_FOUND: "16001",
842
+ /** Token expired */
843
+ TOKEN_EXPIRED: "16002",
844
+ /** Token already used */
845
+ TOKEN_ALREADY_USED: "16003",
846
+ /** Invalid token */
847
+ INVALID_TOKEN: "16004",
848
+ // System Errors
849
+ /** System error */
850
+ SYSTEM_ERROR: "90001",
851
+ /** Service unavailable */
852
+ SERVICE_UNAVAILABLE: "90002",
853
+ /** Timeout */
854
+ TIMEOUT: "90003",
855
+ /** Database error */
856
+ DATABASE_ERROR: "90004",
857
+ /** Internal error */
858
+ INTERNAL_ERROR: "90005"
859
+ };
860
+ var ErrorCategories = {
861
+ /** Success - no error */
862
+ SUCCESS: "success",
863
+ /** Card-related errors (expired, invalid, blocked) */
864
+ CARD_ERROR: "card_error",
865
+ /** Authentication errors (3DS, signature) */
866
+ AUTHENTICATION_ERROR: "authentication_error",
867
+ /** Transaction errors (declined, insufficient funds) */
868
+ TRANSACTION_ERROR: "transaction_error",
869
+ /** Amount/currency errors */
870
+ AMOUNT_ERROR: "amount_error",
871
+ /** Parameter validation errors */
872
+ VALIDATION_ERROR: "validation_error",
873
+ /** Tokenization errors */
874
+ TOKEN_ERROR: "token_error",
875
+ /** System/technical errors */
876
+ SYSTEM_ERROR: "system_error",
877
+ /** Errors that can be retried */
878
+ RETRYABLE: "retryable",
879
+ /** Errors that should not be retried */
880
+ NON_RETRYABLE: "non_retryable"
881
+ };
882
+ var ERROR_CODE_TO_CATEGORY = {
883
+ [ResponseCodes.SUCCESS]: ErrorCategories.SUCCESS,
884
+ [ResponseCodes.PAYMENT_LINK_SUCCESS]: ErrorCategories.SUCCESS,
885
+ [ResponseCodes.RECURRING_SUCCESS]: ErrorCategories.SUCCESS,
886
+ // Card errors
887
+ [ResponseCodes.CARD_EXPIRED]: ErrorCategories.CARD_ERROR,
888
+ [ResponseCodes.INVALID_CARD_NUMBER]: ErrorCategories.CARD_ERROR,
889
+ [ResponseCodes.INVALID_CVV]: ErrorCategories.CARD_ERROR,
890
+ [ResponseCodes.CARD_NOT_SUPPORTED]: ErrorCategories.CARD_ERROR,
891
+ [ResponseCodes.LOST_CARD]: ErrorCategories.CARD_ERROR,
892
+ [ResponseCodes.STOLEN_CARD]: ErrorCategories.CARD_ERROR,
893
+ [ResponseCodes.RESTRICTED_CARD]: ErrorCategories.CARD_ERROR,
894
+ [ResponseCodes.CARD_BLOCKED]: ErrorCategories.CARD_ERROR,
895
+ [ResponseCodes.INVALID_EXPIRY]: ErrorCategories.CARD_ERROR,
896
+ // Authentication errors
897
+ [ResponseCodes.AUTHENTICATION_FAILED]: ErrorCategories.AUTHENTICATION_ERROR,
898
+ [ResponseCodes.NOT_ENROLLED_3DS]: ErrorCategories.AUTHENTICATION_ERROR,
899
+ [ResponseCodes.SIGNATURE_MISMATCH]: ErrorCategories.AUTHENTICATION_ERROR,
900
+ [ResponseCodes.INVALID_ACCESS_CODE]: ErrorCategories.AUTHENTICATION_ERROR,
901
+ [ResponseCodes.INVALID_MERCHANT_ID]: ErrorCategories.AUTHENTICATION_ERROR,
902
+ // Transaction errors
903
+ [ResponseCodes.DECLINED]: ErrorCategories.TRANSACTION_ERROR,
904
+ [ResponseCodes.INSUFFICIENT_FUNDS]: ErrorCategories.TRANSACTION_ERROR,
905
+ [ResponseCodes.LIMIT_EXCEEDED]: ErrorCategories.TRANSACTION_ERROR,
906
+ [ResponseCodes.INVALID_TRANSACTION]: ErrorCategories.TRANSACTION_ERROR,
907
+ [ResponseCodes.DUPLICATE_TRANSACTION]: ErrorCategories.TRANSACTION_ERROR,
908
+ [ResponseCodes.TRANSACTION_NOT_ALLOWED]: ErrorCategories.TRANSACTION_ERROR,
909
+ [ResponseCodes.TRANSACTION_EXPIRED]: ErrorCategories.TRANSACTION_ERROR,
910
+ [ResponseCodes.ALREADY_CAPTURED]: ErrorCategories.TRANSACTION_ERROR,
911
+ [ResponseCodes.ALREADY_VOIDED]: ErrorCategories.TRANSACTION_ERROR,
912
+ [ResponseCodes.ALREADY_REFUNDED]: ErrorCategories.TRANSACTION_ERROR,
913
+ // Amount errors
914
+ [ResponseCodes.INVALID_AMOUNT]: ErrorCategories.AMOUNT_ERROR,
915
+ [ResponseCodes.AMOUNT_TOO_SMALL]: ErrorCategories.AMOUNT_ERROR,
916
+ [ResponseCodes.AMOUNT_TOO_LARGE]: ErrorCategories.AMOUNT_ERROR,
917
+ [ResponseCodes.CURRENCY_NOT_SUPPORTED]: ErrorCategories.AMOUNT_ERROR,
918
+ // Validation errors
919
+ [ResponseCodes.MISSING_PARAMETER]: ErrorCategories.VALIDATION_ERROR,
920
+ [ResponseCodes.INVALID_PARAMETER]: ErrorCategories.VALIDATION_ERROR,
921
+ [ResponseCodes.INVALID_COMMAND]: ErrorCategories.VALIDATION_ERROR,
922
+ [ResponseCodes.INVALID_LANGUAGE]: ErrorCategories.VALIDATION_ERROR,
923
+ [ResponseCodes.INVALID_CURRENCY]: ErrorCategories.VALIDATION_ERROR,
924
+ [ResponseCodes.INVALID_RETURN_URL]: ErrorCategories.VALIDATION_ERROR,
925
+ [ResponseCodes.INVALID_EMAIL]: ErrorCategories.VALIDATION_ERROR,
926
+ [ResponseCodes.PARAMETER_VALUE_NOT_ALLOWED]: ErrorCategories.VALIDATION_ERROR,
927
+ // Token errors
928
+ [ResponseCodes.TOKEN_NOT_FOUND]: ErrorCategories.TOKEN_ERROR,
929
+ [ResponseCodes.TOKEN_EXPIRED]: ErrorCategories.TOKEN_ERROR,
930
+ [ResponseCodes.TOKEN_ALREADY_USED]: ErrorCategories.TOKEN_ERROR,
931
+ [ResponseCodes.INVALID_TOKEN]: ErrorCategories.TOKEN_ERROR,
932
+ // System errors
933
+ [ResponseCodes.SYSTEM_ERROR]: ErrorCategories.SYSTEM_ERROR,
934
+ [ResponseCodes.SERVICE_UNAVAILABLE]: ErrorCategories.SYSTEM_ERROR,
935
+ [ResponseCodes.TIMEOUT]: ErrorCategories.SYSTEM_ERROR,
936
+ [ResponseCodes.DATABASE_ERROR]: ErrorCategories.SYSTEM_ERROR,
937
+ [ResponseCodes.INTERNAL_ERROR]: ErrorCategories.SYSTEM_ERROR
938
+ };
939
+ var RETRYABLE_CODES = [
940
+ ResponseCodes.TIMEOUT,
941
+ ResponseCodes.SERVICE_UNAVAILABLE,
942
+ ResponseCodes.SYSTEM_ERROR,
943
+ ResponseCodes.INTERNAL_ERROR,
944
+ ResponseCodes.DATABASE_ERROR
945
+ ];
946
+ function categorizeError(code) {
947
+ return ERROR_CODE_TO_CATEGORY[code] || ErrorCategories.SYSTEM_ERROR;
948
+ }
949
+ function isRetryableError(code) {
950
+ return RETRYABLE_CODES.includes(code);
951
+ }
952
+
953
+ // src/errors.ts
954
+ var ERROR_DETAILS_MAP = {
955
+ // Success codes
956
+ [ResponseCodes.SUCCESS]: {
957
+ message: "Transaction completed successfully.",
958
+ action: "No action needed. Proceed with order fulfillment.",
959
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html"
960
+ },
961
+ [ResponseCodes.PAYMENT_LINK_SUCCESS]: {
962
+ message: "Payment link created successfully.",
963
+ action: "Share the payment link with your customer via email, SMS, or any channel.",
964
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html"
965
+ },
966
+ [ResponseCodes.RECURRING_SUCCESS]: {
967
+ message: "Recurring payment processed successfully.",
968
+ action: "Payment has been charged. Update subscription status in your system.",
969
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html"
970
+ },
971
+ // Authentication & Security
972
+ [ResponseCodes.AUTHENTICATION_FAILED]: {
973
+ message: "3D Secure authentication failed. The customer could not verify their identity.",
974
+ action: "Ask the customer to check their 3D Secure password or use a different card. Some banks require SMS verification - ensure customer has network coverage.",
975
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#_3d_secure",
976
+ httpStatus: 402
977
+ },
978
+ [ResponseCodes.NOT_ENROLLED_3DS]: {
979
+ message: "Card is not enrolled in 3D Secure.",
980
+ action: "The card does not support 3D Secure. You can proceed without 3DS or ask customer to use a different card.",
981
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#_3d_secure"
982
+ },
983
+ [ResponseCodes.SIGNATURE_MISMATCH]: {
984
+ message: "Request signature is invalid.",
985
+ action: "Check that your request_secret is correct and that parameters are being signed in the correct order. Use the SDK's built-in signing methods.",
986
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#signature_calculation",
987
+ httpStatus: 401
988
+ },
989
+ [ResponseCodes.INVALID_ACCESS_CODE]: {
990
+ message: "Invalid access code.",
991
+ action: "Verify your APS_ACCESS_CODE environment variable matches the value in your APS dashboard under Integration Settings.",
992
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#credentials",
993
+ httpStatus: 401
994
+ },
995
+ [ResponseCodes.INVALID_MERCHANT_ID]: {
996
+ message: "Invalid merchant identifier.",
997
+ action: "Verify your APS_MERCHANT_ID environment variable matches your APS dashboard. Ensure you're using the correct environment (sandbox vs production).",
998
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#credentials",
999
+ httpStatus: 401
1000
+ },
1001
+ // Card Errors
1002
+ [ResponseCodes.CARD_EXPIRED]: {
1003
+ message: "The card has expired.",
1004
+ action: "Ask the customer to check the expiry date on their card and enter it correctly, or use a different card.",
1005
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#card_errors",
1006
+ httpStatus: 402
1007
+ },
1008
+ [ResponseCodes.INVALID_CARD_NUMBER]: {
1009
+ message: "The card number is invalid.",
1010
+ action: "Ask the customer to check their card number and try again. Ensure no spaces or dashes are included.",
1011
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#card_errors",
1012
+ httpStatus: 402
1013
+ },
1014
+ [ResponseCodes.INVALID_CVV]: {
1015
+ message: "The CVV code is invalid.",
1016
+ action: "Ask the customer to check the CVV on the back of their card (3 digits for Visa/MC, 4 for Amex) and enter it correctly.",
1017
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#card_errors",
1018
+ httpStatus: 402
1019
+ },
1020
+ [ResponseCodes.CARD_NOT_SUPPORTED]: {
1021
+ message: "This card type is not supported.",
1022
+ action: "The customer is using a card type not accepted by your merchant account. Ask them to use Visa, Mastercard, or MADA.",
1023
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#payment_methods",
1024
+ httpStatus: 402
1025
+ },
1026
+ [ResponseCodes.LOST_CARD]: {
1027
+ message: "The card has been reported lost.",
1028
+ action: "Do not retry. Ask the customer to use a different card and contact their bank.",
1029
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#card_errors",
1030
+ httpStatus: 402
1031
+ },
1032
+ [ResponseCodes.STOLEN_CARD]: {
1033
+ message: "The card has been reported stolen.",
1034
+ action: "Do not retry. Ask the customer to use a different card and contact their bank immediately.",
1035
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#card_errors",
1036
+ httpStatus: 402
1037
+ },
1038
+ [ResponseCodes.RESTRICTED_CARD]: {
1039
+ message: "The card has restrictions that prevent this transaction.",
1040
+ action: "The card may be restricted for online or international use. Ask the customer to contact their bank or use a different card.",
1041
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#card_errors",
1042
+ httpStatus: 402
1043
+ },
1044
+ [ResponseCodes.CARD_BLOCKED]: {
1045
+ message: "The card has been blocked by the issuing bank.",
1046
+ action: "Ask the customer to contact their bank to unblock the card or use a different card.",
1047
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#card_errors",
1048
+ httpStatus: 402
1049
+ },
1050
+ [ResponseCodes.INVALID_EXPIRY]: {
1051
+ message: "The expiry date is invalid.",
1052
+ action: "Ask the customer to check the expiry date format (MM/YY) and ensure the card has not expired.",
1053
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#card_errors",
1054
+ httpStatus: 402
1055
+ },
1056
+ // Transaction Errors
1057
+ [ResponseCodes.DECLINED]: {
1058
+ message: "The transaction was declined by the issuing bank.",
1059
+ action: "Ask the customer to contact their bank or use a different card. The bank does not provide specific reasons for declines.",
1060
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#declined_transactions",
1061
+ httpStatus: 402
1062
+ },
1063
+ [ResponseCodes.INSUFFICIENT_FUNDS]: {
1064
+ message: "The card has insufficient funds.",
1065
+ action: "Ask the customer to use a different card or payment method, or reduce the transaction amount.",
1066
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#transaction_errors",
1067
+ httpStatus: 402
1068
+ },
1069
+ [ResponseCodes.LIMIT_EXCEEDED]: {
1070
+ message: "The transaction amount exceeds the card limit.",
1071
+ action: "The transaction may exceed the customer's daily limit or card limit. Ask them to contact their bank or use a different card.",
1072
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#transaction_errors",
1073
+ httpStatus: 402
1074
+ },
1075
+ [ResponseCodes.INVALID_TRANSACTION]: {
1076
+ message: "The transaction is invalid.",
1077
+ action: "Check that all required parameters are provided correctly. Ensure the amount is valid and currency is supported.",
1078
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#transaction_errors",
1079
+ httpStatus: 400
1080
+ },
1081
+ [ResponseCodes.DUPLICATE_TRANSACTION]: {
1082
+ message: "A duplicate transaction was detected.",
1083
+ action: "This transaction appears to be a duplicate. Use a unique merchant_reference for each transaction.",
1084
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#idempotency",
1085
+ httpStatus: 409
1086
+ },
1087
+ [ResponseCodes.TRANSACTION_NOT_ALLOWED]: {
1088
+ message: "This transaction type is not allowed for this merchant.",
1089
+ action: "Your merchant account may not be configured for this transaction type. Contact APS support to enable the required service.",
1090
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#merchant_setup",
1091
+ httpStatus: 403
1092
+ },
1093
+ [ResponseCodes.TRANSACTION_EXPIRED]: {
1094
+ message: "The transaction has expired.",
1095
+ action: "The authorization window has expired. Create a new transaction.",
1096
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#transaction_lifecycle",
1097
+ httpStatus: 410
1098
+ },
1099
+ [ResponseCodes.ALREADY_CAPTURED]: {
1100
+ message: "The transaction has already been captured.",
1101
+ action: "This transaction was already captured. Check your records or query the transaction status.",
1102
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#capture",
1103
+ httpStatus: 409
1104
+ },
1105
+ [ResponseCodes.ALREADY_VOIDED]: {
1106
+ message: "The transaction has already been voided.",
1107
+ action: "This transaction was already voided. No further action can be taken on it.",
1108
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#void",
1109
+ httpStatus: 409
1110
+ },
1111
+ [ResponseCodes.ALREADY_REFUNDED]: {
1112
+ message: "The transaction has already been refunded.",
1113
+ action: "This transaction was already refunded. Check the refund status for details.",
1114
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#refund",
1115
+ httpStatus: 409
1116
+ },
1117
+ // Amount Errors
1118
+ [ResponseCodes.INVALID_AMOUNT]: {
1119
+ message: "The transaction amount is invalid.",
1120
+ action: "Ensure the amount is a positive number in the smallest currency unit (e.g., cents, fils). Amount should not contain decimals.",
1121
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#amount_format",
1122
+ httpStatus: 400
1123
+ },
1124
+ [ResponseCodes.AMOUNT_TOO_SMALL]: {
1125
+ message: "The transaction amount is below the minimum allowed.",
1126
+ action: "The amount is below the minimum transaction limit. Increase the amount or contact APS for limit adjustments.",
1127
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#amount_limits",
1128
+ httpStatus: 400
1129
+ },
1130
+ [ResponseCodes.AMOUNT_TOO_LARGE]: {
1131
+ message: "The transaction amount exceeds the maximum allowed.",
1132
+ action: "The amount exceeds your merchant transaction limit. Contact APS support to increase your limit.",
1133
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#amount_limits",
1134
+ httpStatus: 400
1135
+ },
1136
+ [ResponseCodes.CURRENCY_NOT_SUPPORTED]: {
1137
+ message: "The currency is not supported.",
1138
+ action: "Use a supported currency (SAR, AED, USD, EUR, etc.). Check APS documentation for the full list.",
1139
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#currencies",
1140
+ httpStatus: 400
1141
+ },
1142
+ // Parameter Errors
1143
+ [ResponseCodes.MISSING_PARAMETER]: {
1144
+ message: "A required parameter is missing.",
1145
+ action: "Check that all required parameters are provided. Common missing fields: merchant_reference, amount, currency, customer_email.",
1146
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#required_parameters",
1147
+ httpStatus: 400
1148
+ },
1149
+ [ResponseCodes.INVALID_PARAMETER]: {
1150
+ message: "A parameter has an invalid format or value.",
1151
+ action: "Check parameter formats: emails must be valid, amounts must be numeric, dates must be in correct format.",
1152
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#parameter_formats",
1153
+ httpStatus: 400
1154
+ },
1155
+ [ResponseCodes.INVALID_COMMAND]: {
1156
+ message: "The command is invalid or not recognized.",
1157
+ action: "Use a valid command: PURCHASE, AUTHORIZATION, CAPTURE, REFUND, VOID, TOKENIZATION, etc.",
1158
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#commands",
1159
+ httpStatus: 400
1160
+ },
1161
+ [ResponseCodes.INVALID_LANGUAGE]: {
1162
+ message: "The language code is invalid.",
1163
+ action: 'Use "en" for English or "ar" for Arabic.',
1164
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#language_codes",
1165
+ httpStatus: 400
1166
+ },
1167
+ [ResponseCodes.INVALID_CURRENCY]: {
1168
+ message: "The currency code is invalid.",
1169
+ action: "Use a valid 3-letter ISO currency code (SAR, AED, USD, EUR, etc.).",
1170
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#currencies",
1171
+ httpStatus: 400
1172
+ },
1173
+ [ResponseCodes.INVALID_RETURN_URL]: {
1174
+ message: "The return URL is invalid.",
1175
+ action: "Ensure the return_url is a valid HTTPS URL and properly URL-encoded if needed.",
1176
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#return_url",
1177
+ httpStatus: 400
1178
+ },
1179
+ [ResponseCodes.INVALID_EMAIL]: {
1180
+ message: "The customer email is invalid.",
1181
+ action: "Ensure the customer_email is a valid email format (e.g., customer@example.com).",
1182
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#customer_email",
1183
+ httpStatus: 400
1184
+ },
1185
+ [ResponseCodes.PARAMETER_VALUE_NOT_ALLOWED]: {
1186
+ message: "A parameter value is not allowed for your merchant account.",
1187
+ action: "This error often occurs when trying to use tokenization (remember_me) but your merchant account does not have tokenization enabled. Contact APS support to enable tokenization, or set tokenize: false. Other causes: using a payment method not enabled for your account, or an invalid parameter value.",
1188
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#merchant_setup",
1189
+ httpStatus: 400
1190
+ },
1191
+ // Tokenization Errors
1192
+ [ResponseCodes.TOKEN_NOT_FOUND]: {
1193
+ message: "The card token was not found.",
1194
+ action: "The token may have been deleted or never created. Ask the customer to re-enter their card details.",
1195
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#tokenization",
1196
+ httpStatus: 404
1197
+ },
1198
+ [ResponseCodes.TOKEN_EXPIRED]: {
1199
+ message: "The card token has expired.",
1200
+ action: "Tokens expire after a period of inactivity. Ask the customer to re-enter their card details.",
1201
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#token_expiry",
1202
+ httpStatus: 410
1203
+ },
1204
+ [ResponseCodes.TOKEN_ALREADY_USED]: {
1205
+ message: "The token has already been used.",
1206
+ action: "Each token can only be used once for security. Create a new token for this transaction.",
1207
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#token_usage",
1208
+ httpStatus: 409
1209
+ },
1210
+ [ResponseCodes.INVALID_TOKEN]: {
1211
+ message: "The token is invalid.",
1212
+ action: "Check that the token was properly generated and is being passed correctly.",
1213
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#tokenization",
1214
+ httpStatus: 400
1215
+ },
1216
+ // System Errors
1217
+ [ResponseCodes.SYSTEM_ERROR]: {
1218
+ message: "A system error occurred.",
1219
+ action: "This is a temporary issue on APS side. Wait a moment and retry the transaction.",
1220
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#system_errors",
1221
+ httpStatus: 500
1222
+ },
1223
+ [ResponseCodes.SERVICE_UNAVAILABLE]: {
1224
+ message: "The service is temporarily unavailable.",
1225
+ action: "APS is experiencing high load or maintenance. Wait a moment and retry.",
1226
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#system_errors",
1227
+ httpStatus: 503
1228
+ },
1229
+ [ResponseCodes.TIMEOUT]: {
1230
+ message: "The request timed out.",
1231
+ action: "The request took too long to complete. Check your network connection and retry.",
1232
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#timeouts",
1233
+ httpStatus: 504
1234
+ },
1235
+ [ResponseCodes.DATABASE_ERROR]: {
1236
+ message: "A database error occurred.",
1237
+ action: "Temporary database issue. Wait a moment and retry the transaction.",
1238
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#system_errors",
1239
+ httpStatus: 500
1240
+ },
1241
+ [ResponseCodes.INTERNAL_ERROR]: {
1242
+ message: "An internal error occurred.",
1243
+ action: "Unexpected error on APS side. Contact APS support if this persists.",
1244
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#support",
1245
+ httpStatus: 500
1246
+ }
1247
+ };
1248
+ function getErrorDetails(code) {
1249
+ const details = ERROR_DETAILS_MAP[code];
1250
+ const category = categorizeError(code);
1251
+ const retryable = isRetryableError(code);
1252
+ if (details) {
1253
+ return {
1254
+ code,
1255
+ message: details.message,
1256
+ action: details.action,
1257
+ category,
1258
+ retryable,
1259
+ documentation: details.documentation,
1260
+ httpStatus: details.httpStatus
1261
+ };
1262
+ }
1263
+ return {
1264
+ code,
1265
+ message: `An unknown error occurred (code: ${code}).`,
1266
+ action: "Contact APS support with this error code for assistance.",
1267
+ category: ErrorCategories.SYSTEM_ERROR,
1268
+ retryable: false,
1269
+ documentation: "https://paymentservices.amazon.com/docs/EN/index.html#support",
1270
+ httpStatus: 500
1271
+ };
1272
+ }
1273
+ function isRetryableError2(code) {
1274
+ return isRetryableError(code);
1275
+ }
1276
+
1277
+ // src/react/ErrorDisplay.tsx
1278
+ var import_jsx_runtime3 = require("react/jsx-runtime");
1279
+ var defaultStyles2 = {
1280
+ container: {
1281
+ padding: "16px",
1282
+ borderRadius: "8px",
1283
+ border: "1px solid #EF4444",
1284
+ backgroundColor: "#FEF2F2",
1285
+ color: "#991B1B"
1286
+ },
1287
+ header: {
1288
+ display: "flex",
1289
+ alignItems: "center",
1290
+ gap: "8px",
1291
+ marginBottom: "12px"
1292
+ },
1293
+ title: {
1294
+ fontWeight: "600",
1295
+ fontSize: "16px",
1296
+ color: "#DC2626"
1297
+ },
1298
+ code: {
1299
+ fontSize: "12px",
1300
+ padding: "2px 8px",
1301
+ backgroundColor: "#FEE2E2",
1302
+ borderRadius: "4px",
1303
+ fontFamily: "monospace"
1304
+ },
1305
+ message: {
1306
+ fontSize: "14px",
1307
+ marginBottom: "8px",
1308
+ lineHeight: "1.5"
1309
+ },
1310
+ action: {
1311
+ fontSize: "13px",
1312
+ color: "#7F1D1D",
1313
+ marginBottom: "12px",
1314
+ padding: "8px",
1315
+ backgroundColor: "#FEE2E2",
1316
+ borderRadius: "4px"
1317
+ },
1318
+ actions: {
1319
+ display: "flex",
1320
+ gap: "8px",
1321
+ marginTop: "12px"
1322
+ },
1323
+ button: {
1324
+ padding: "8px 16px",
1325
+ borderRadius: "6px",
1326
+ fontSize: "14px",
1327
+ fontWeight: "500",
1328
+ cursor: "pointer",
1329
+ border: "none",
1330
+ transition: "opacity 0.2s"
1331
+ },
1332
+ buttonRetry: {
1333
+ backgroundColor: "#DC2626",
1334
+ color: "#fff"
1335
+ },
1336
+ buttonDismiss: {
1337
+ backgroundColor: "transparent",
1338
+ color: "#7F1D1D",
1339
+ border: "1px solid #EF4444"
1340
+ },
1341
+ documentation: {
1342
+ fontSize: "12px",
1343
+ marginTop: "12px",
1344
+ color: "#991B1B"
1345
+ }
1346
+ };
1347
+ var ErrorDisplay = ({
1348
+ error,
1349
+ onRetry,
1350
+ onDismiss,
1351
+ title: customTitle,
1352
+ showDocumentation = true,
1353
+ styles: customStyles = {},
1354
+ className = ""
1355
+ }) => {
1356
+ const styles = {
1357
+ container: { ...defaultStyles2.container, ...customStyles.container },
1358
+ header: { ...defaultStyles2.header, ...customStyles.header },
1359
+ title: { ...defaultStyles2.title, ...customStyles.title },
1360
+ code: { ...defaultStyles2.code, ...customStyles.code },
1361
+ message: { ...defaultStyles2.message, ...customStyles.message },
1362
+ action: { ...defaultStyles2.action, ...customStyles.action },
1363
+ actions: { ...defaultStyles2.actions, ...customStyles.actions },
1364
+ button: { ...defaultStyles2.button, ...customStyles.button },
1365
+ buttonRetry: { ...defaultStyles2.buttonRetry, ...customStyles.buttonRetry },
1366
+ buttonDismiss: { ...defaultStyles2.buttonDismiss, ...customStyles.buttonDismiss },
1367
+ documentation: { ...defaultStyles2.documentation, ...customStyles.documentation }
1368
+ };
1369
+ let errorCode;
1370
+ let errorMessage;
1371
+ let errorDetails = null;
1372
+ let canRetry = false;
1373
+ if (typeof error === "string") {
1374
+ errorMessage = error;
1375
+ } else if (error instanceof Error) {
1376
+ errorMessage = error.message;
1377
+ if ("code" in error) {
1378
+ errorCode = error.code;
1379
+ errorDetails = getErrorDetails(errorCode);
1380
+ canRetry = isRetryableError2(errorCode);
1381
+ }
1382
+ } else {
1383
+ errorMessage = "An unknown error occurred";
1384
+ }
1385
+ const title = customTitle || errorDetails?.category.toUpperCase() || "Error";
1386
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.container, className, role: "alert", children: [
1387
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.header, children: [
1388
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1389
+ "svg",
1390
+ {
1391
+ width: "20",
1392
+ height: "20",
1393
+ viewBox: "0 0 20 20",
1394
+ fill: "none",
1395
+ style: { flexShrink: 0 },
1396
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1397
+ "path",
1398
+ {
1399
+ d: "M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",
1400
+ fill: "#DC2626"
1401
+ }
1402
+ )
1403
+ }
1404
+ ),
1405
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: styles.title, children: title }),
1406
+ errorCode && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: styles.code, children: errorCode })
1407
+ ] }),
1408
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.message, children: errorDetails?.message || errorMessage }),
1409
+ errorDetails?.action && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.action, children: [
1410
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("strong", { children: "Suggested action:" }),
1411
+ " ",
1412
+ errorDetails.action
1413
+ ] }),
1414
+ (onRetry || onDismiss) && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.actions, children: [
1415
+ onRetry && canRetry && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1416
+ "button",
1417
+ {
1418
+ onClick: onRetry,
1419
+ style: { ...styles.button, ...styles.buttonRetry },
1420
+ type: "button",
1421
+ children: "Try Again"
1422
+ }
1423
+ ),
1424
+ onDismiss && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1425
+ "button",
1426
+ {
1427
+ onClick: onDismiss,
1428
+ style: { ...styles.button, ...styles.buttonDismiss },
1429
+ type: "button",
1430
+ children: "Dismiss"
1431
+ }
1432
+ )
1433
+ ] }),
1434
+ showDocumentation && errorDetails?.documentation && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.documentation, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1435
+ "a",
1436
+ {
1437
+ href: errorDetails.documentation,
1438
+ target: "_blank",
1439
+ rel: "noopener noreferrer",
1440
+ style: { color: "#991B1B", textDecoration: "underline" },
1441
+ children: "Learn more about this error \u2192"
1442
+ }
1443
+ ) })
1444
+ ] });
1445
+ };
1446
+
1447
+ // src/react/PaymentStatus.tsx
1448
+ var import_jsx_runtime4 = require("react/jsx-runtime");
1449
+ function getStatusConfig(status) {
1450
+ switch (status.toLowerCase()) {
1451
+ case "captured":
1452
+ case "success":
1453
+ return {
1454
+ icon: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1455
+ "path",
1456
+ {
1457
+ d: "M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z",
1458
+ stroke: "currentColor",
1459
+ strokeWidth: "2",
1460
+ strokeLinecap: "round",
1461
+ strokeLinejoin: "round"
1462
+ }
1463
+ ) }),
1464
+ title: "Payment Successful",
1465
+ color: "#059669",
1466
+ bgColor: "#D1FAE5",
1467
+ borderColor: "#10B981"
1468
+ };
1469
+ case "authorized":
1470
+ return {
1471
+ icon: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1472
+ "path",
1473
+ {
1474
+ d: "M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z",
1475
+ stroke: "currentColor",
1476
+ strokeWidth: "2",
1477
+ strokeLinecap: "round",
1478
+ strokeLinejoin: "round"
1479
+ }
1480
+ ) }),
1481
+ title: "Payment Authorized",
1482
+ color: "#0891B2",
1483
+ bgColor: "#CFFAFE",
1484
+ borderColor: "#06B6D4"
1485
+ };
1486
+ case "pending":
1487
+ case "3ds":
1488
+ return {
1489
+ icon: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1490
+ "path",
1491
+ {
1492
+ d: "M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z",
1493
+ stroke: "currentColor",
1494
+ strokeWidth: "2",
1495
+ strokeLinecap: "round",
1496
+ strokeLinejoin: "round"
1497
+ }
1498
+ ) }),
1499
+ title: "Payment Pending",
1500
+ color: "#D97706",
1501
+ bgColor: "#FEF3C7",
1502
+ borderColor: "#F59E0B"
1503
+ };
1504
+ case "failed":
1505
+ case "declined":
1506
+ return {
1507
+ icon: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1508
+ "path",
1509
+ {
1510
+ d: "M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z",
1511
+ stroke: "currentColor",
1512
+ strokeWidth: "2",
1513
+ strokeLinecap: "round",
1514
+ strokeLinejoin: "round"
1515
+ }
1516
+ ) }),
1517
+ title: "Payment Failed",
1518
+ color: "#DC2626",
1519
+ bgColor: "#FEE2E2",
1520
+ borderColor: "#EF4444"
1521
+ };
1522
+ case "voided":
1523
+ return {
1524
+ icon: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1525
+ "path",
1526
+ {
1527
+ d: "M6 18L18 6M6 6l12 12",
1528
+ stroke: "currentColor",
1529
+ strokeWidth: "2",
1530
+ strokeLinecap: "round",
1531
+ strokeLinejoin: "round"
1532
+ }
1533
+ ) }),
1534
+ title: "Payment Voided",
1535
+ color: "#6B7280",
1536
+ bgColor: "#F3F4F6",
1537
+ borderColor: "#9CA3AF"
1538
+ };
1539
+ case "refunded":
1540
+ return {
1541
+ icon: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1542
+ "path",
1543
+ {
1544
+ d: "M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6",
1545
+ stroke: "currentColor",
1546
+ strokeWidth: "2",
1547
+ strokeLinecap: "round",
1548
+ strokeLinejoin: "round"
1549
+ }
1550
+ ) }),
1551
+ title: "Payment Refunded",
1552
+ color: "#7C3AED",
1553
+ bgColor: "#EDE9FE",
1554
+ borderColor: "#8B5CF6"
1555
+ };
1556
+ case "cancelled":
1557
+ return {
1558
+ icon: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1559
+ "path",
1560
+ {
1561
+ d: "M6 18L18 6M6 6l12 12",
1562
+ stroke: "currentColor",
1563
+ strokeWidth: "2",
1564
+ strokeLinecap: "round",
1565
+ strokeLinejoin: "round"
1566
+ }
1567
+ ) }),
1568
+ title: "Payment Cancelled",
1569
+ color: "#6B7280",
1570
+ bgColor: "#F3F4F6",
1571
+ borderColor: "#9CA3AF"
1572
+ };
1573
+ default:
1574
+ return {
1575
+ icon: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1576
+ "path",
1577
+ {
1578
+ d: "M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z",
1579
+ stroke: "currentColor",
1580
+ strokeWidth: "2",
1581
+ strokeLinecap: "round",
1582
+ strokeLinejoin: "round"
1583
+ }
1584
+ ) }),
1585
+ title: "Unknown Status",
1586
+ color: "#6B7280",
1587
+ bgColor: "#F3F4F6",
1588
+ borderColor: "#9CA3AF"
1589
+ };
1590
+ }
1591
+ }
1592
+ function formatAmount(amount, currency) {
1593
+ const majorUnits = amount / 100;
1594
+ const formatter = new Intl.NumberFormat("en-US", {
1595
+ style: "currency",
1596
+ currency
1597
+ });
1598
+ return formatter.format(majorUnits);
1599
+ }
1600
+ function getSizeStyles(size) {
1601
+ switch (size) {
1602
+ case "small":
1603
+ return { padding: "12px", iconSize: 20, fontSize: "14px" };
1604
+ case "large":
1605
+ return { padding: "24px", iconSize: 32, fontSize: "18px" };
1606
+ default:
1607
+ return { padding: "16px", iconSize: 24, fontSize: "16px" };
1608
+ }
1609
+ }
1610
+ var PaymentStatus = ({
1611
+ status,
1612
+ amount,
1613
+ currency = "USD",
1614
+ transactionId,
1615
+ paymentMethod,
1616
+ title: customTitle,
1617
+ showAmount = true,
1618
+ showTransactionId = true,
1619
+ styles: customStyles = {},
1620
+ className = "",
1621
+ size = "medium"
1622
+ }) => {
1623
+ const config = getStatusConfig(status);
1624
+ const sizeStyles = getSizeStyles(size);
1625
+ const displayTitle = customTitle || config.title;
1626
+ const styles = {
1627
+ container: {
1628
+ padding: sizeStyles.padding,
1629
+ borderRadius: "8px",
1630
+ border: `1px solid ${config.borderColor}`,
1631
+ backgroundColor: config.bgColor,
1632
+ color: config.color,
1633
+ ...customStyles.container
1634
+ },
1635
+ icon: {
1636
+ flexShrink: 0,
1637
+ ...customStyles.icon
1638
+ },
1639
+ content: {
1640
+ flex: 1,
1641
+ ...customStyles.content
1642
+ },
1643
+ title: {
1644
+ fontWeight: "600",
1645
+ fontSize: sizeStyles.fontSize,
1646
+ marginBottom: "4px",
1647
+ ...customStyles.title
1648
+ },
1649
+ amount: {
1650
+ fontSize: "24px",
1651
+ fontWeight: "700",
1652
+ marginTop: "8px",
1653
+ ...customStyles.amount
1654
+ },
1655
+ details: {
1656
+ marginTop: "12px",
1657
+ paddingTop: "12px",
1658
+ borderTop: `1px solid ${config.borderColor}`,
1659
+ ...customStyles.details
1660
+ },
1661
+ detail: {
1662
+ display: "flex",
1663
+ justifyContent: "space-between",
1664
+ marginBottom: "4px",
1665
+ ...customStyles.detail
1666
+ },
1667
+ detailLabel: {
1668
+ fontSize: "14px",
1669
+ opacity: 0.8,
1670
+ ...customStyles.detailLabel
1671
+ },
1672
+ detailValue: {
1673
+ fontSize: "14px",
1674
+ fontWeight: "500",
1675
+ fontFamily: "monospace",
1676
+ ...customStyles.detailValue
1677
+ }
1678
+ };
1679
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: styles.container, className, role: "status", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "flex", alignItems: "flex-start", gap: "12px" }, children: [
1680
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { ...styles.icon, width: sizeStyles.iconSize, height: sizeStyles.iconSize }, children: config.icon }),
1681
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: styles.content, children: [
1682
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: styles.title, children: displayTitle }),
1683
+ showAmount && amount !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: styles.amount, children: formatAmount(amount, currency) }),
1684
+ (showTransactionId || paymentMethod) && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: styles.details, children: [
1685
+ showTransactionId && transactionId && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: styles.detail, children: [
1686
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: styles.detailLabel, children: "Transaction ID:" }),
1687
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: styles.detailValue, children: transactionId })
1688
+ ] }),
1689
+ paymentMethod && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: styles.detail, children: [
1690
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: styles.detailLabel, children: "Payment Method:" }),
1691
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: styles.detailValue, children: paymentMethod.toUpperCase() })
1692
+ ] }),
1693
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: styles.detail, children: [
1694
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: styles.detailLabel, children: "Status:" }),
1695
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: styles.detailValue, children: status.toUpperCase() })
1696
+ ] })
1697
+ ] })
1698
+ ] })
1699
+ ] }) });
1700
+ };
1701
+
1702
+ // src/react/HostedCheckoutButton.tsx
1703
+ var import_react5 = require("react");
1704
+ var import_jsx_runtime5 = require("react/jsx-runtime");
1705
+ var defaultStyles3 = {
1706
+ button: {
1707
+ padding: "14px 28px",
1708
+ fontSize: "16px",
1709
+ fontWeight: "600",
1710
+ color: "#fff",
1711
+ backgroundColor: "#7C3AED",
1712
+ border: "none",
1713
+ borderRadius: "8px",
1714
+ cursor: "pointer",
1715
+ transition: "all 0.2s",
1716
+ display: "inline-flex",
1717
+ alignItems: "center",
1718
+ justifyContent: "center",
1719
+ gap: "8px",
1720
+ minWidth: "200px"
1721
+ },
1722
+ buttonDisabled: {
1723
+ backgroundColor: "#A78BFA",
1724
+ cursor: "not-allowed",
1725
+ opacity: 0.7
1726
+ },
1727
+ buttonLoading: {
1728
+ cursor: "wait",
1729
+ opacity: 0.8
1730
+ },
1731
+ errorContainer: {
1732
+ marginTop: "16px"
1733
+ }
1734
+ };
1735
+ var LoadingSpinner = () => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1736
+ "svg",
1737
+ {
1738
+ width: "20",
1739
+ height: "20",
1740
+ viewBox: "0 0 24 24",
1741
+ fill: "none",
1742
+ style: { animation: "spin 1s linear infinite" },
1743
+ children: [
1744
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("style", { children: `
1745
+ @keyframes spin {
1746
+ from { transform: rotate(0deg); }
1747
+ to { transform: rotate(360deg); }
1748
+ }
1749
+ ` }),
1750
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1751
+ "circle",
1752
+ {
1753
+ cx: "12",
1754
+ cy: "12",
1755
+ r: "10",
1756
+ stroke: "currentColor",
1757
+ strokeWidth: "3",
1758
+ strokeLinecap: "round",
1759
+ strokeDasharray: "31.42",
1760
+ strokeDashoffset: "10",
1761
+ opacity: "0.25"
1762
+ }
1763
+ ),
1764
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1765
+ "path",
1766
+ {
1767
+ d: "M12 2a10 10 0 0 1 10 10",
1768
+ stroke: "currentColor",
1769
+ strokeWidth: "3",
1770
+ strokeLinecap: "round"
1771
+ }
1772
+ )
1773
+ ]
1774
+ }
1775
+ );
1776
+ var HostedCheckoutButton = ({
1777
+ order,
1778
+ returnUrl,
1779
+ allowedPaymentMethods,
1780
+ hideShipping = false,
1781
+ children,
1782
+ onCheckoutCreated,
1783
+ onError,
1784
+ styles: customStyles = {},
1785
+ className = "",
1786
+ disabled = false,
1787
+ showError = true,
1788
+ loadingComponent
1789
+ }) => {
1790
+ const { createCheckout, redirectToCheckout, isLoading, error, reset } = useCheckout();
1791
+ const [isRedirecting, setIsRedirecting] = (0, import_react5.useState)(false);
1792
+ const styles = {
1793
+ button: { ...defaultStyles3.button, ...customStyles.button },
1794
+ buttonDisabled: { ...defaultStyles3.buttonDisabled, ...customStyles.buttonDisabled },
1795
+ buttonLoading: { ...defaultStyles3.buttonLoading, ...customStyles.buttonLoading },
1796
+ errorContainer: { ...defaultStyles3.errorContainer, ...customStyles.errorContainer }
1797
+ };
1798
+ const handleClick = async () => {
1799
+ if (isLoading || isRedirecting) return;
1800
+ reset();
1801
+ try {
1802
+ const options = {
1803
+ order,
1804
+ successUrl: returnUrl,
1805
+ failureUrl: returnUrl,
1806
+ cancelUrl: returnUrl,
1807
+ allowedPaymentMethods,
1808
+ hideShipping
1809
+ };
1810
+ const checkout = await createCheckout(options);
1811
+ onCheckoutCreated?.(checkout);
1812
+ setIsRedirecting(true);
1813
+ await new Promise((resolve) => setTimeout(resolve, 500));
1814
+ redirectToCheckout();
1815
+ } catch (err) {
1816
+ const error2 = err instanceof Error ? err : new Error(String(err));
1817
+ onError?.(error2);
1818
+ } finally {
1819
+ setIsRedirecting(false);
1820
+ }
1821
+ };
1822
+ const isDisabled = disabled || isLoading || isRedirecting;
1823
+ const buttonStyle = {
1824
+ ...styles.button,
1825
+ ...isDisabled ? styles.buttonDisabled : {},
1826
+ ...isLoading || isRedirecting ? styles.buttonLoading : {}
1827
+ };
1828
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
1829
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1830
+ "button",
1831
+ {
1832
+ onClick: handleClick,
1833
+ disabled: isDisabled,
1834
+ style: buttonStyle,
1835
+ className,
1836
+ type: "button",
1837
+ children: isLoading || isRedirecting ? loadingComponent || /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
1838
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(LoadingSpinner, {}),
1839
+ isRedirecting ? "Redirecting..." : "Processing..."
1840
+ ] }) : children
1841
+ }
1842
+ ),
1843
+ showError && error && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles.errorContainer, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1844
+ ErrorDisplay,
1845
+ {
1846
+ error,
1847
+ onDismiss: reset,
1848
+ onRetry: handleClick
1849
+ }
1850
+ ) })
1851
+ ] });
1852
+ };
1853
+ // Annotate the CommonJS export names for ESM import in node:
1854
+ 0 && (module.exports = {
1855
+ APSProvider,
1856
+ ErrorDisplay,
1857
+ HostedCheckoutButton,
1858
+ PaymentStatus,
1859
+ TokenizationForm,
1860
+ useAPS,
1861
+ useCheckout,
1862
+ usePayment
1863
+ });