logix-pay 1.0.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,716 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var stripeJs = require('@stripe/stripe-js');
5
+ var reactStripeJs = require('@stripe/react-stripe-js');
6
+
7
+ function _arrayLikeToArray(r, a) {
8
+ (null == a || a > r.length) && (a = r.length);
9
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
10
+ return n;
11
+ }
12
+ function _arrayWithHoles(r) {
13
+ if (Array.isArray(r)) return r;
14
+ }
15
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
16
+ try {
17
+ var i = n[a](c),
18
+ u = i.value;
19
+ } catch (n) {
20
+ return void e(n);
21
+ }
22
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
23
+ }
24
+ function _asyncToGenerator(n) {
25
+ return function () {
26
+ var t = this,
27
+ e = arguments;
28
+ return new Promise(function (r, o) {
29
+ var a = n.apply(t, e);
30
+ function _next(n) {
31
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
32
+ }
33
+ function _throw(n) {
34
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
35
+ }
36
+ _next(void 0);
37
+ });
38
+ };
39
+ }
40
+ function _iterableToArrayLimit(r, l) {
41
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
42
+ if (null != t) {
43
+ var e,
44
+ n,
45
+ i,
46
+ u,
47
+ a = [],
48
+ f = true,
49
+ o = false;
50
+ try {
51
+ if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
52
+ } catch (r) {
53
+ o = true, n = r;
54
+ } finally {
55
+ try {
56
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
57
+ } finally {
58
+ if (o) throw n;
59
+ }
60
+ }
61
+ return a;
62
+ }
63
+ }
64
+ function _nonIterableRest() {
65
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
66
+ }
67
+ function _regenerator() {
68
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
69
+ var e,
70
+ t,
71
+ r = "function" == typeof Symbol ? Symbol : {},
72
+ n = r.iterator || "@@iterator",
73
+ o = r.toStringTag || "@@toStringTag";
74
+ function i(r, n, o, i) {
75
+ var c = n && n.prototype instanceof Generator ? n : Generator,
76
+ u = Object.create(c.prototype);
77
+ return _regeneratorDefine(u, "_invoke", function (r, n, o) {
78
+ var i,
79
+ c,
80
+ u,
81
+ f = 0,
82
+ p = o || [],
83
+ y = false,
84
+ G = {
85
+ p: 0,
86
+ n: 0,
87
+ v: e,
88
+ a: d,
89
+ f: d.bind(e, 4),
90
+ d: function (t, r) {
91
+ return i = t, c = 0, u = e, G.n = r, a;
92
+ }
93
+ };
94
+ function d(r, n) {
95
+ for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
96
+ var o,
97
+ i = p[t],
98
+ d = G.p,
99
+ l = i[2];
100
+ r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
101
+ }
102
+ if (o || r > 1) return a;
103
+ throw y = true, n;
104
+ }
105
+ return function (o, p, l) {
106
+ if (f > 1) throw TypeError("Generator is already running");
107
+ for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
108
+ i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
109
+ try {
110
+ if (f = 2, i) {
111
+ if (c || (o = "next"), t = i[o]) {
112
+ if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
113
+ if (!t.done) return t;
114
+ u = t.value, c < 2 && (c = 0);
115
+ } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
116
+ i = e;
117
+ } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
118
+ } catch (t) {
119
+ i = e, c = 1, u = t;
120
+ } finally {
121
+ f = 1;
122
+ }
123
+ }
124
+ return {
125
+ value: t,
126
+ done: y
127
+ };
128
+ };
129
+ }(r, o, i), true), u;
130
+ }
131
+ var a = {};
132
+ function Generator() {}
133
+ function GeneratorFunction() {}
134
+ function GeneratorFunctionPrototype() {}
135
+ t = Object.getPrototypeOf;
136
+ var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
137
+ return this;
138
+ }), t),
139
+ u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
140
+ function f(e) {
141
+ return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
142
+ }
143
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
144
+ return this;
145
+ }), _regeneratorDefine(u, "toString", function () {
146
+ return "[object Generator]";
147
+ }), (_regenerator = function () {
148
+ return {
149
+ w: i,
150
+ m: f
151
+ };
152
+ })();
153
+ }
154
+ function _regeneratorDefine(e, r, n, t) {
155
+ var i = Object.defineProperty;
156
+ try {
157
+ i({}, "", {});
158
+ } catch (e) {
159
+ i = 0;
160
+ }
161
+ _regeneratorDefine = function (e, r, n, t) {
162
+ function o(r, n) {
163
+ _regeneratorDefine(e, r, function (e) {
164
+ return this._invoke(r, n, e);
165
+ });
166
+ }
167
+ r ? i ? i(e, r, {
168
+ value: n,
169
+ enumerable: !t,
170
+ configurable: !t,
171
+ writable: !t
172
+ }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
173
+ }, _regeneratorDefine(e, r, n, t);
174
+ }
175
+ function _slicedToArray(r, e) {
176
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
177
+ }
178
+ function _unsupportedIterableToArray(r, a) {
179
+ if (r) {
180
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
181
+ var t = {}.toString.call(r).slice(8, -1);
182
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
183
+ }
184
+ }
185
+
186
+ function ShiftPaymentForm(_ref) {
187
+ var amount = _ref.amount,
188
+ currency = _ref.currency,
189
+ color = _ref.color,
190
+ _ref$formwidth = _ref.formwidth,
191
+ formwidth = _ref$formwidth === void 0 ? 400 : _ref$formwidth,
192
+ _ref$formborderRadius = _ref.formborderRadius,
193
+ formborderRadius = _ref$formborderRadius === void 0 ? 20 : _ref$formborderRadius,
194
+ _ref$formbackgroundCo = _ref.formbackgroundColor,
195
+ formbackgroundColor = _ref$formbackgroundCo === void 0 ? "#fff" : _ref$formbackgroundCo,
196
+ _ref$inputpadding = _ref.inputpadding,
197
+ inputpadding = _ref$inputpadding === void 0 ? 12 : _ref$inputpadding,
198
+ baseUrl = _ref.baseUrl,
199
+ userId = _ref.userId,
200
+ successPage = _ref.successPage,
201
+ errorPage = _ref.errorPage,
202
+ description = _ref.description;
203
+ var formRef = React.useRef();
204
+ var initializedRef = React.useRef(false);
205
+ var shift4Ref = React.useRef(null);
206
+ var componentsRef = React.useRef(null);
207
+ var _useState = React.useState(false),
208
+ _useState2 = _slicedToArray(_useState, 2),
209
+ isSubmitting = _useState2[0],
210
+ setIsSubmitting = _useState2[1];
211
+ var _useState3 = React.useState(false),
212
+ _useState4 = _slicedToArray(_useState3, 2),
213
+ isReady = _useState4[0],
214
+ setIsReady = _useState4[1];
215
+ React.useEffect(function () {
216
+ if (initializedRef.current) return;
217
+ initializedRef.current = true;
218
+ var initPayment = /*#__PURE__*/function () {
219
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
220
+ var response, _yield$response$json, publicKeys, isProd, script, _t;
221
+ return _regenerator().w(function (_context) {
222
+ while (1) switch (_context.p = _context.n) {
223
+ case 0:
224
+ _context.p = 0;
225
+ _context.n = 1;
226
+ return fetch(baseUrl + userId);
227
+ case 1:
228
+ response = _context.v;
229
+ if (!response.ok) errorPage("Failed to fetch public key");
230
+ _context.n = 2;
231
+ return response.json();
232
+ case 2:
233
+ _yield$response$json = _context.v;
234
+ publicKeys = _yield$response$json.publicKeys;
235
+ isProd = _yield$response$json.isProd;
236
+ if (!publicKeys) errorPage("Public key is empty");
237
+ script = document.createElement("script");
238
+ script.src = isProd ? "https://js.shift4.com/shift4.js" : "https://js.dev.shift4.com/shift4.js";
239
+ script.async = true;
240
+ script.onload = function () {
241
+ if (!window.Shift4) return;
242
+ shift4Ref.current = window.Shift4(publicKeys);
243
+ componentsRef.current = shift4Ref.current.createComponentGroup().automount("#payment-form");
244
+ setIsReady(true);
245
+ };
246
+ script.onerror = function () {
247
+ setError("Payment provider script failed to load.");
248
+ };
249
+ document.body.appendChild(script);
250
+ _context.n = 4;
251
+ break;
252
+ case 3:
253
+ _context.p = 3;
254
+ _t = _context.v;
255
+ console.error(_t);
256
+ setError("Payment initialization failed. Please try again.");
257
+ case 4:
258
+ return _context.a(2);
259
+ }
260
+ }, _callee, null, [[0, 3]]);
261
+ }));
262
+ return function initPayment() {
263
+ return _ref2.apply(this, arguments);
264
+ };
265
+ }();
266
+ initPayment();
267
+ }, []);
268
+ var handleSubmit = /*#__PURE__*/function () {
269
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e) {
270
+ var token, request, threeDSecureToken, apiBase, response, result, _t2;
271
+ return _regenerator().w(function (_context2) {
272
+ while (1) switch (_context2.p = _context2.n) {
273
+ case 0:
274
+ e.preventDefault();
275
+ if (!isSubmitting) {
276
+ _context2.n = 1;
277
+ break;
278
+ }
279
+ return _context2.a(2);
280
+ case 1:
281
+ if (formRef.current) {
282
+ _context2.n = 2;
283
+ break;
284
+ }
285
+ return _context2.a(2);
286
+ case 2:
287
+ if (!(!shift4Ref.current || !componentsRef.current)) {
288
+ _context2.n = 3;
289
+ break;
290
+ }
291
+ errorPage("Payment form is not ready yet. Please try again.");
292
+ return _context2.a(2);
293
+ case 3:
294
+ setIsSubmitting(true);
295
+ _context2.p = 4;
296
+ _context2.n = 5;
297
+ return shift4Ref.current.createToken(componentsRef.current);
298
+ case 5:
299
+ token = _context2.v;
300
+ if (!(token !== null && token !== void 0 && token.id)) {
301
+ errorPage("Card tokenization failed. Please check your details and try again.");
302
+ }
303
+ request = {
304
+ amount: amount,
305
+ currency: currency,
306
+ card: token.id,
307
+ description: description
308
+ };
309
+ _context2.n = 6;
310
+ return shift4Ref.current.verifyThreeDSecure(request);
311
+ case 6:
312
+ threeDSecureToken = _context2.v;
313
+ if (!(threeDSecureToken !== null && threeDSecureToken !== void 0 && threeDSecureToken.id)) {
314
+ errorPage("3D Secure verification failed. Please try again.");
315
+ }
316
+ apiBase = baseUrl + "charge/" + userId;
317
+ _context2.n = 7;
318
+ return fetch("".concat(apiBase), {
319
+ method: "POST",
320
+ headers: {
321
+ "Content-Type": "application/json"
322
+ },
323
+ body: JSON.stringify({
324
+ tokenId: threeDSecureToken.id,
325
+ amount: request.amount,
326
+ currency: request.currency,
327
+ description: description
328
+ })
329
+ });
330
+ case 7:
331
+ response = _context2.v;
332
+ _context2.n = 8;
333
+ return response.json();
334
+ case 8:
335
+ result = _context2.v;
336
+ if (response.ok) {
337
+ _context2.n = 9;
338
+ break;
339
+ }
340
+ if (typeof errorPage === "function") errorPage(result);
341
+ return _context2.a(2);
342
+ case 9:
343
+ if (typeof successPage === "function") successPage(result.message);
344
+ _context2.n = 11;
345
+ break;
346
+ case 10:
347
+ _context2.p = 10;
348
+ _t2 = _context2.v;
349
+ if (typeof errorPage === "function") errorPage(_t2.message);
350
+ case 11:
351
+ _context2.p = 11;
352
+ setIsSubmitting(false);
353
+ return _context2.f(11);
354
+ case 12:
355
+ return _context2.a(2);
356
+ }
357
+ }, _callee2, null, [[4, 10, 11, 12]]);
358
+ }));
359
+ return function handleSubmit(_x) {
360
+ return _ref3.apply(this, arguments);
361
+ };
362
+ }();
363
+ return /*#__PURE__*/React.createElement("div", {
364
+ style: {
365
+ display: "flex",
366
+ justifyContent: "center",
367
+ width: "100%",
368
+ boxSizing: "border-box"
369
+ }
370
+ }, /*#__PURE__*/React.createElement("form", {
371
+ ref: formRef,
372
+ id: "payment-form",
373
+ onSubmit: handleSubmit,
374
+ method: "post",
375
+ style: {
376
+ display: "grid",
377
+ gap: "12px",
378
+ padding: "20px",
379
+ backgroundColor: formbackgroundColor,
380
+ borderRadius: formborderRadius,
381
+ width: formwidth,
382
+ boxSizing: "border-box"
383
+ }
384
+ }, /*#__PURE__*/React.createElement("div", {
385
+ style: {
386
+ display: "grid",
387
+ gap: "8px"
388
+ }
389
+ }, /*#__PURE__*/React.createElement("label", {
390
+ style: {
391
+ fontWeight: "500",
392
+ color: "#555"
393
+ }
394
+ }, "Card number"), /*#__PURE__*/React.createElement("div", {
395
+ "data-shift4": "number",
396
+ className: "form-control",
397
+ style: {
398
+ padding: inputpadding,
399
+ borderRadius: formborderRadius,
400
+ border: "1px solid #ccc",
401
+ boxShadow: "inset 0 2px 4px rgba(0,0,0,0.05)"
402
+ }
403
+ })), /*#__PURE__*/React.createElement("div", {
404
+ style: {
405
+ display: "grid",
406
+ gridTemplateColumns: "1fr 1fr",
407
+ gap: "10px",
408
+ marginTop: "5px"
409
+ }
410
+ }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", {
411
+ style: {
412
+ fontWeight: "500",
413
+ color: "#555",
414
+ marginBottom: 2
415
+ }
416
+ }, "Expiration"), /*#__PURE__*/React.createElement("div", {
417
+ "data-shift4": "expiry",
418
+ className: "form-control",
419
+ style: {
420
+ padding: inputpadding,
421
+ borderRadius: formborderRadius,
422
+ border: "1px solid #ccc",
423
+ boxShadow: "inset 0 2px 4px rgba(0,0,0,0.05)"
424
+ }
425
+ })), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", {
426
+ style: {
427
+ fontWeight: "500",
428
+ color: "#555",
429
+ marginBottom: 2
430
+ }
431
+ }, "CVC"), /*#__PURE__*/React.createElement("div", {
432
+ "data-shift4": "cvc",
433
+ className: "form-control",
434
+ style: {
435
+ padding: inputpadding,
436
+ borderRadius: formborderRadius,
437
+ border: "1px solid #ccc",
438
+ boxShadow: "inset 0 2px 4px rgba(0,0,0,0.05)"
439
+ }
440
+ }))), /*#__PURE__*/React.createElement("button", {
441
+ type: "submit",
442
+ disabled: !isReady || isSubmitting,
443
+ style: {
444
+ marginTop: "16px",
445
+ width: "100%",
446
+ padding: inputpadding + 2,
447
+ backgroundColor: color,
448
+ color: "white",
449
+ border: "none",
450
+ borderRadius: formborderRadius,
451
+ fontWeight: "600",
452
+ cursor: !isReady || isSubmitting ? "not-allowed" : "pointer",
453
+ opacity: !isReady || isSubmitting ? 0.7 : 1
454
+ }
455
+ }, isSubmitting ? "Processing..." : "Buy now")));
456
+ }
457
+
458
+ function StripePaymentForm(_ref) {
459
+ var amount = _ref.amount,
460
+ _ref$currency = _ref.currency,
461
+ currency = _ref$currency === void 0 ? "usd" : _ref$currency,
462
+ _ref$color = _ref.color,
463
+ color = _ref$color === void 0 ? "#556cd6" : _ref$color,
464
+ _ref$formWidth = _ref.formWidth,
465
+ formWidth = _ref$formWidth === void 0 ? 400 : _ref$formWidth,
466
+ _ref$formBorderRadius = _ref.formBorderRadius,
467
+ formBorderRadius = _ref$formBorderRadius === void 0 ? 20 : _ref$formBorderRadius,
468
+ _ref$formBackgroundCo = _ref.formBackgroundColor,
469
+ formBackgroundColor = _ref$formBackgroundCo === void 0 ? "#fff" : _ref$formBackgroundCo,
470
+ _ref$inputPadding = _ref.inputPadding,
471
+ inputPadding = _ref$inputPadding === void 0 ? 12 : _ref$inputPadding,
472
+ baseUrl = _ref.baseUrl,
473
+ userId = _ref.userId,
474
+ successPage = _ref.successPage,
475
+ errorPage = _ref.errorPage,
476
+ _ref$description = _ref.description,
477
+ description = _ref$description === void 0 ? "" : _ref$description;
478
+ var stripe = reactStripeJs.useStripe();
479
+ var elements = reactStripeJs.useElements();
480
+ var initializedRef = React.useRef(false);
481
+ var _useState = React.useState(null),
482
+ _useState2 = _slicedToArray(_useState, 2),
483
+ publicKey = _useState2[0],
484
+ setPublicKey = _useState2[1];
485
+ var _useState3 = React.useState(false),
486
+ _useState4 = _slicedToArray(_useState3, 2),
487
+ isSubmitting = _useState4[0],
488
+ setIsSubmitting = _useState4[1];
489
+
490
+ /** Input styling based on props */
491
+ var inputStyle = {
492
+ style: {
493
+ base: {
494
+ fontSize: "15px",
495
+ color: "#111",
496
+ "::placeholder": {
497
+ color: "#aaa"
498
+ },
499
+ padding: "".concat(inputPadding, "px"),
500
+ border: "1px solid #ccc",
501
+ borderRadius: "6px",
502
+ backgroundColor: "#fff"
503
+ },
504
+ invalid: {
505
+ color: "#ff4d4f"
506
+ }
507
+ }
508
+ };
509
+
510
+ /** Fetch Stripe public key once */
511
+ React.useEffect(function () {
512
+ if (initializedRef.current) return;
513
+ initializedRef.current = true;
514
+ var initPayment = /*#__PURE__*/function () {
515
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
516
+ var res, data, _t;
517
+ return _regenerator().w(function (_context) {
518
+ while (1) switch (_context.p = _context.n) {
519
+ case 0:
520
+ _context.p = 0;
521
+ _context.n = 1;
522
+ return fetch("".concat(baseUrl).concat(userId));
523
+ case 1:
524
+ res = _context.v;
525
+ if (!res.ok) errorPage("Failed to fetch public key");
526
+ _context.n = 2;
527
+ return res.json();
528
+ case 2:
529
+ data = _context.v;
530
+ if (!data.publicKey) errorPage("Public key not found");
531
+ setPublicKey(data.publicKey);
532
+ _context.n = 4;
533
+ break;
534
+ case 3:
535
+ _context.p = 3;
536
+ _t = _context.v;
537
+ if (errorPage) errorPage(_t.message);
538
+ case 4:
539
+ return _context.a(2);
540
+ }
541
+ }, _callee, null, [[0, 3]]);
542
+ }));
543
+ return function initPayment() {
544
+ return _ref2.apply(this, arguments);
545
+ };
546
+ }();
547
+ initPayment();
548
+ }, [baseUrl, userId, errorPage]);
549
+
550
+ /** Handle form submit */
551
+ var handleSubmit = /*#__PURE__*/function () {
552
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e) {
553
+ var card, _yield$stripe$createP, pmError, paymentMethod, res, result, _t2;
554
+ return _regenerator().w(function (_context2) {
555
+ while (1) switch (_context2.p = _context2.n) {
556
+ case 0:
557
+ e.preventDefault();
558
+ errorPage("");
559
+ if (!(!stripe || !elements)) {
560
+ _context2.n = 1;
561
+ break;
562
+ }
563
+ return _context2.a(2);
564
+ case 1:
565
+ card = elements.getElement(reactStripeJs.CardNumberElement);
566
+ if (card) {
567
+ _context2.n = 2;
568
+ break;
569
+ }
570
+ return _context2.a(2, errorPage("Card element not found"));
571
+ case 2:
572
+ _context2.n = 3;
573
+ return stripe.createPaymentMethod({
574
+ type: "card",
575
+ card: card
576
+ });
577
+ case 3:
578
+ _yield$stripe$createP = _context2.v;
579
+ pmError = _yield$stripe$createP.error;
580
+ paymentMethod = _yield$stripe$createP.paymentMethod;
581
+ if (!pmError) {
582
+ _context2.n = 4;
583
+ break;
584
+ }
585
+ if (errorPage) errorPage(pmError.message);
586
+ return _context2.a(2);
587
+ case 4:
588
+ setIsSubmitting(true);
589
+ _context2.p = 5;
590
+ _context2.n = 6;
591
+ return fetch("".concat(baseUrl, "charge/").concat(userId), {
592
+ method: "POST",
593
+ headers: {
594
+ "Content-Type": "application/json"
595
+ },
596
+ body: JSON.stringify({
597
+ tokenId: paymentMethod.id,
598
+ amount: amount,
599
+ currency: currency,
600
+ description: description
601
+ })
602
+ });
603
+ case 6:
604
+ res = _context2.v;
605
+ _context2.n = 7;
606
+ return res.json();
607
+ case 7:
608
+ result = _context2.v;
609
+ if (res.ok) {
610
+ _context2.n = 8;
611
+ break;
612
+ }
613
+ if (errorPage) errorPage(result);
614
+ return _context2.a(2);
615
+ case 8:
616
+ if (successPage) successPage(result.message);
617
+ _context2.n = 10;
618
+ break;
619
+ case 9:
620
+ _context2.p = 9;
621
+ _t2 = _context2.v;
622
+ if (errorPage) errorPage(_t2.message);
623
+ case 10:
624
+ _context2.p = 10;
625
+ setIsSubmitting(false);
626
+ return _context2.f(10);
627
+ case 11:
628
+ return _context2.a(2);
629
+ }
630
+ }, _callee2, null, [[5, 9, 10, 11]]);
631
+ }));
632
+ return function handleSubmit(_x) {
633
+ return _ref3.apply(this, arguments);
634
+ };
635
+ }();
636
+ if (!publicKey) return /*#__PURE__*/React.createElement("p", null, "Loading payment form...");
637
+ var stripePromise = stripeJs.loadStripe(publicKey);
638
+ return /*#__PURE__*/React.createElement(reactStripeJs.Elements, {
639
+ stripe: stripePromise
640
+ }, /*#__PURE__*/React.createElement("form", {
641
+ onSubmit: handleSubmit,
642
+ style: {
643
+ maxWidth: "".concat(formWidth, "px"),
644
+ margin: "30px auto",
645
+ padding: "20px",
646
+ borderRadius: "".concat(formBorderRadius, "px"),
647
+ backgroundColor: formBackgroundColor,
648
+ display: "grid",
649
+ gap: "14px",
650
+ fontFamily: "Arial, sans-serif",
651
+ boxShadow: "0 2px 6px rgba(0,0,0,0.08)"
652
+ }
653
+ }, /*#__PURE__*/React.createElement("div", {
654
+ style: {
655
+ display: "grid",
656
+ gap: "6px"
657
+ }
658
+ }, /*#__PURE__*/React.createElement("label", {
659
+ style: {
660
+ fontWeight: "500",
661
+ color: "#555"
662
+ }
663
+ }, "Card number"), /*#__PURE__*/React.createElement(reactStripeJs.CardNumberElement, {
664
+ options: inputStyle
665
+ })), /*#__PURE__*/React.createElement("div", {
666
+ style: {
667
+ display: "flex",
668
+ gap: "10px"
669
+ }
670
+ }, /*#__PURE__*/React.createElement("div", {
671
+ style: {
672
+ flex: 1,
673
+ display: "grid",
674
+ gap: "4px"
675
+ }
676
+ }, /*#__PURE__*/React.createElement("label", {
677
+ style: {
678
+ fontWeight: "500",
679
+ color: "#555"
680
+ }
681
+ }, "Expiration"), /*#__PURE__*/React.createElement(reactStripeJs.CardExpiryElement, {
682
+ options: inputStyle
683
+ })), /*#__PURE__*/React.createElement("div", {
684
+ style: {
685
+ flex: 1,
686
+ display: "grid",
687
+ gap: "4px"
688
+ }
689
+ }, /*#__PURE__*/React.createElement("label", {
690
+ style: {
691
+ fontWeight: "500",
692
+ color: "#555"
693
+ }
694
+ }, "CVC"), /*#__PURE__*/React.createElement(reactStripeJs.CardCvcElement, {
695
+ options: inputStyle
696
+ }))), /*#__PURE__*/React.createElement("button", {
697
+ type: "submit",
698
+ disabled: isSubmitting,
699
+ style: {
700
+ marginTop: "16px",
701
+ width: "100%",
702
+ padding: "".concat(inputPadding + 2, "px"),
703
+ backgroundColor: color,
704
+ color: "white",
705
+ border: "none",
706
+ borderRadius: "".concat(formBorderRadius, "px"),
707
+ fontWeight: "600",
708
+ cursor: isSubmitting ? "not-allowed" : "pointer",
709
+ opacity: isSubmitting ? 0.7 : 1
710
+ }
711
+ }, isSubmitting ? "Processing..." : "Buy now")));
712
+ }
713
+
714
+ exports.ShiftPaymentForm = ShiftPaymentForm;
715
+ exports.StripePaymentForm = StripePaymentForm;
716
+ //# sourceMappingURL=index.cjs.js.map