shift-payment-form 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.
- package/README.md +41 -0
- package/dist/index.cjs.js +461 -0
- package/dist/index.esm.js +459 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# 💳 PaymentForm (Shift4 React Payment Component)
|
|
2
|
+
|
|
3
|
+
PaymentForm is a **React component** built to accept **secure card payments** using **Shift4**.
|
|
4
|
+
It is **SPA-friendly** and handles payment results via **callback functions** instead of forced redirects.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## ✨ Features
|
|
9
|
+
|
|
10
|
+
- 🔐 Secure card tokenization (Shift4)
|
|
11
|
+
- 🛡️ 3D Secure support
|
|
12
|
+
- ⚡ Callback-based success & error handling
|
|
13
|
+
- 🎨 Fully customizable UI
|
|
14
|
+
- 📦 Library-ready component
|
|
15
|
+
- 🚀 Works with React Router / Next.js
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## 📦 Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm i logix-payment-shift4
|
|
23
|
+
|
|
24
|
+
import PaymentForm from "logix-payment-shift4";
|
|
25
|
+
|
|
26
|
+
<PaymentForm
|
|
27
|
+
amount={1000}
|
|
28
|
+
currency="USD"
|
|
29
|
+
color="#0d6efd"
|
|
30
|
+
baseUrl="https://api.example.com/payment/"
|
|
31
|
+
userId="user-123"
|
|
32
|
+
description="Premium subscription"
|
|
33
|
+
|
|
34
|
+
successPage={(message) => {
|
|
35
|
+
console.log("Payment successful:", message);
|
|
36
|
+
}}
|
|
37
|
+
|
|
38
|
+
errorPage={(error) => {
|
|
39
|
+
console.error("Payment failed:", error);
|
|
40
|
+
}}
|
|
41
|
+
/>
|
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
|
|
5
|
+
function _arrayLikeToArray(r, a) {
|
|
6
|
+
(null == a || a > r.length) && (a = r.length);
|
|
7
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
8
|
+
return n;
|
|
9
|
+
}
|
|
10
|
+
function _arrayWithHoles(r) {
|
|
11
|
+
if (Array.isArray(r)) return r;
|
|
12
|
+
}
|
|
13
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
14
|
+
try {
|
|
15
|
+
var i = n[a](c),
|
|
16
|
+
u = i.value;
|
|
17
|
+
} catch (n) {
|
|
18
|
+
return void e(n);
|
|
19
|
+
}
|
|
20
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
21
|
+
}
|
|
22
|
+
function _asyncToGenerator(n) {
|
|
23
|
+
return function () {
|
|
24
|
+
var t = this,
|
|
25
|
+
e = arguments;
|
|
26
|
+
return new Promise(function (r, o) {
|
|
27
|
+
var a = n.apply(t, e);
|
|
28
|
+
function _next(n) {
|
|
29
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
30
|
+
}
|
|
31
|
+
function _throw(n) {
|
|
32
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
33
|
+
}
|
|
34
|
+
_next(void 0);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function _iterableToArrayLimit(r, l) {
|
|
39
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
40
|
+
if (null != t) {
|
|
41
|
+
var e,
|
|
42
|
+
n,
|
|
43
|
+
i,
|
|
44
|
+
u,
|
|
45
|
+
a = [],
|
|
46
|
+
f = true,
|
|
47
|
+
o = false;
|
|
48
|
+
try {
|
|
49
|
+
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);
|
|
50
|
+
} catch (r) {
|
|
51
|
+
o = true, n = r;
|
|
52
|
+
} finally {
|
|
53
|
+
try {
|
|
54
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
55
|
+
} finally {
|
|
56
|
+
if (o) throw n;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return a;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function _nonIterableRest() {
|
|
63
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
64
|
+
}
|
|
65
|
+
function _regenerator() {
|
|
66
|
+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
67
|
+
var e,
|
|
68
|
+
t,
|
|
69
|
+
r = "function" == typeof Symbol ? Symbol : {},
|
|
70
|
+
n = r.iterator || "@@iterator",
|
|
71
|
+
o = r.toStringTag || "@@toStringTag";
|
|
72
|
+
function i(r, n, o, i) {
|
|
73
|
+
var c = n && n.prototype instanceof Generator ? n : Generator,
|
|
74
|
+
u = Object.create(c.prototype);
|
|
75
|
+
return _regeneratorDefine(u, "_invoke", function (r, n, o) {
|
|
76
|
+
var i,
|
|
77
|
+
c,
|
|
78
|
+
u,
|
|
79
|
+
f = 0,
|
|
80
|
+
p = o || [],
|
|
81
|
+
y = false,
|
|
82
|
+
G = {
|
|
83
|
+
p: 0,
|
|
84
|
+
n: 0,
|
|
85
|
+
v: e,
|
|
86
|
+
a: d,
|
|
87
|
+
f: d.bind(e, 4),
|
|
88
|
+
d: function (t, r) {
|
|
89
|
+
return i = t, c = 0, u = e, G.n = r, a;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
function d(r, n) {
|
|
93
|
+
for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
|
|
94
|
+
var o,
|
|
95
|
+
i = p[t],
|
|
96
|
+
d = G.p,
|
|
97
|
+
l = i[2];
|
|
98
|
+
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));
|
|
99
|
+
}
|
|
100
|
+
if (o || r > 1) return a;
|
|
101
|
+
throw y = true, n;
|
|
102
|
+
}
|
|
103
|
+
return function (o, p, l) {
|
|
104
|
+
if (f > 1) throw TypeError("Generator is already running");
|
|
105
|
+
for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
|
|
106
|
+
i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
|
|
107
|
+
try {
|
|
108
|
+
if (f = 2, i) {
|
|
109
|
+
if (c || (o = "next"), t = i[o]) {
|
|
110
|
+
if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
|
|
111
|
+
if (!t.done) return t;
|
|
112
|
+
u = t.value, c < 2 && (c = 0);
|
|
113
|
+
} else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
|
|
114
|
+
i = e;
|
|
115
|
+
} else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
|
|
116
|
+
} catch (t) {
|
|
117
|
+
i = e, c = 1, u = t;
|
|
118
|
+
} finally {
|
|
119
|
+
f = 1;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
value: t,
|
|
124
|
+
done: y
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
}(r, o, i), true), u;
|
|
128
|
+
}
|
|
129
|
+
var a = {};
|
|
130
|
+
function Generator() {}
|
|
131
|
+
function GeneratorFunction() {}
|
|
132
|
+
function GeneratorFunctionPrototype() {}
|
|
133
|
+
t = Object.getPrototypeOf;
|
|
134
|
+
var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
|
|
135
|
+
return this;
|
|
136
|
+
}), t),
|
|
137
|
+
u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
|
|
138
|
+
function f(e) {
|
|
139
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
|
|
140
|
+
}
|
|
141
|
+
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 () {
|
|
142
|
+
return this;
|
|
143
|
+
}), _regeneratorDefine(u, "toString", function () {
|
|
144
|
+
return "[object Generator]";
|
|
145
|
+
}), (_regenerator = function () {
|
|
146
|
+
return {
|
|
147
|
+
w: i,
|
|
148
|
+
m: f
|
|
149
|
+
};
|
|
150
|
+
})();
|
|
151
|
+
}
|
|
152
|
+
function _regeneratorDefine(e, r, n, t) {
|
|
153
|
+
var i = Object.defineProperty;
|
|
154
|
+
try {
|
|
155
|
+
i({}, "", {});
|
|
156
|
+
} catch (e) {
|
|
157
|
+
i = 0;
|
|
158
|
+
}
|
|
159
|
+
_regeneratorDefine = function (e, r, n, t) {
|
|
160
|
+
function o(r, n) {
|
|
161
|
+
_regeneratorDefine(e, r, function (e) {
|
|
162
|
+
return this._invoke(r, n, e);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
r ? i ? i(e, r, {
|
|
166
|
+
value: n,
|
|
167
|
+
enumerable: !t,
|
|
168
|
+
configurable: !t,
|
|
169
|
+
writable: !t
|
|
170
|
+
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
171
|
+
}, _regeneratorDefine(e, r, n, t);
|
|
172
|
+
}
|
|
173
|
+
function _slicedToArray(r, e) {
|
|
174
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
175
|
+
}
|
|
176
|
+
function _unsupportedIterableToArray(r, a) {
|
|
177
|
+
if (r) {
|
|
178
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
179
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
180
|
+
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;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function PaymentForm(_ref) {
|
|
185
|
+
var amount = _ref.amount,
|
|
186
|
+
currency = _ref.currency,
|
|
187
|
+
color = _ref.color,
|
|
188
|
+
_ref$formwidth = _ref.formwidth,
|
|
189
|
+
formwidth = _ref$formwidth === void 0 ? 400 : _ref$formwidth,
|
|
190
|
+
_ref$formborderRadius = _ref.formborderRadius,
|
|
191
|
+
formborderRadius = _ref$formborderRadius === void 0 ? 20 : _ref$formborderRadius,
|
|
192
|
+
_ref$formbackgroundCo = _ref.formbackgroundColor,
|
|
193
|
+
formbackgroundColor = _ref$formbackgroundCo === void 0 ? "#fff" : _ref$formbackgroundCo,
|
|
194
|
+
_ref$inputpadding = _ref.inputpadding,
|
|
195
|
+
inputpadding = _ref$inputpadding === void 0 ? 12 : _ref$inputpadding,
|
|
196
|
+
baseUrl = _ref.baseUrl,
|
|
197
|
+
userId = _ref.userId,
|
|
198
|
+
successPage = _ref.successPage,
|
|
199
|
+
errorPage = _ref.errorPage,
|
|
200
|
+
description = _ref.description;
|
|
201
|
+
var formRef = React.useRef();
|
|
202
|
+
var initializedRef = React.useRef(false);
|
|
203
|
+
var shift4Ref = React.useRef(null);
|
|
204
|
+
var componentsRef = React.useRef(null);
|
|
205
|
+
var _useState = React.useState(false),
|
|
206
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
207
|
+
isSubmitting = _useState2[0],
|
|
208
|
+
setIsSubmitting = _useState2[1];
|
|
209
|
+
var _useState3 = React.useState(false),
|
|
210
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
211
|
+
isStart = _useState4[0],
|
|
212
|
+
setIsStart = _useState4[1];
|
|
213
|
+
var _useState5 = React.useState(false),
|
|
214
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
215
|
+
isReady = _useState6[0],
|
|
216
|
+
setIsReady = _useState6[1];
|
|
217
|
+
React.useEffect(function () {
|
|
218
|
+
if (initializedRef.current) return;
|
|
219
|
+
initializedRef.current = true;
|
|
220
|
+
var initPayment = /*#__PURE__*/function () {
|
|
221
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
222
|
+
var response, _yield$response$json, publicKeys, isProd, script, _t;
|
|
223
|
+
return _regenerator().w(function (_context) {
|
|
224
|
+
while (1) switch (_context.p = _context.n) {
|
|
225
|
+
case 0:
|
|
226
|
+
_context.p = 0;
|
|
227
|
+
_context.n = 1;
|
|
228
|
+
return fetch(baseUrl + userId);
|
|
229
|
+
case 1:
|
|
230
|
+
response = _context.v;
|
|
231
|
+
if (!response.ok) errorPage("Failed to fetch public key");
|
|
232
|
+
_context.n = 2;
|
|
233
|
+
return response.json();
|
|
234
|
+
case 2:
|
|
235
|
+
_yield$response$json = _context.v;
|
|
236
|
+
publicKeys = _yield$response$json.publicKeys;
|
|
237
|
+
isProd = _yield$response$json.isProd;
|
|
238
|
+
if (!publicKeys) errorPage("Public key is empty");
|
|
239
|
+
script = document.createElement("script");
|
|
240
|
+
script.src = isProd ? "https://js.shift4.com/shift4.js" : "https://js.dev.shift4.com/shift4.js";
|
|
241
|
+
script.async = true;
|
|
242
|
+
script.onload = function () {
|
|
243
|
+
if (!window.Shift4) return;
|
|
244
|
+
shift4Ref.current = window.Shift4(publicKeys);
|
|
245
|
+
componentsRef.current = shift4Ref.current.createComponentGroup().automount("#payment-form");
|
|
246
|
+
setIsReady(true);
|
|
247
|
+
};
|
|
248
|
+
script.onerror = function () {
|
|
249
|
+
setError("Payment provider script failed to load.");
|
|
250
|
+
};
|
|
251
|
+
document.body.appendChild(script);
|
|
252
|
+
_context.n = 4;
|
|
253
|
+
break;
|
|
254
|
+
case 3:
|
|
255
|
+
_context.p = 3;
|
|
256
|
+
_t = _context.v;
|
|
257
|
+
console.error(_t);
|
|
258
|
+
setError("Payment initialization failed. Please try again.");
|
|
259
|
+
case 4:
|
|
260
|
+
return _context.a(2);
|
|
261
|
+
}
|
|
262
|
+
}, _callee, null, [[0, 3]]);
|
|
263
|
+
}));
|
|
264
|
+
return function initPayment() {
|
|
265
|
+
return _ref2.apply(this, arguments);
|
|
266
|
+
};
|
|
267
|
+
}();
|
|
268
|
+
initPayment();
|
|
269
|
+
}, [isStart]);
|
|
270
|
+
var handleSubmit = /*#__PURE__*/function () {
|
|
271
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e) {
|
|
272
|
+
var token, request, threeDSecureToken, apiBase, response, result, _t2;
|
|
273
|
+
return _regenerator().w(function (_context2) {
|
|
274
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
275
|
+
case 0:
|
|
276
|
+
e.preventDefault();
|
|
277
|
+
if (!isSubmitting) {
|
|
278
|
+
_context2.n = 1;
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
return _context2.a(2);
|
|
282
|
+
case 1:
|
|
283
|
+
if (formRef.current) {
|
|
284
|
+
_context2.n = 2;
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
return _context2.a(2);
|
|
288
|
+
case 2:
|
|
289
|
+
if (!(!shift4Ref.current || !componentsRef.current)) {
|
|
290
|
+
_context2.n = 3;
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
errorPage("Payment form is not ready yet. Please try again.");
|
|
294
|
+
return _context2.a(2);
|
|
295
|
+
case 3:
|
|
296
|
+
setIsSubmitting(true);
|
|
297
|
+
_context2.p = 4;
|
|
298
|
+
_context2.n = 5;
|
|
299
|
+
return shift4Ref.current.createToken(componentsRef.current);
|
|
300
|
+
case 5:
|
|
301
|
+
token = _context2.v;
|
|
302
|
+
if (!(token !== null && token !== void 0 && token.id)) {
|
|
303
|
+
errorPage("Card tokenization failed. Please check your details and try again.");
|
|
304
|
+
}
|
|
305
|
+
request = {
|
|
306
|
+
amount: amount,
|
|
307
|
+
currency: currency,
|
|
308
|
+
card: token.id,
|
|
309
|
+
description: description
|
|
310
|
+
};
|
|
311
|
+
_context2.n = 6;
|
|
312
|
+
return shift4Ref.current.verifyThreeDSecure(request);
|
|
313
|
+
case 6:
|
|
314
|
+
threeDSecureToken = _context2.v;
|
|
315
|
+
if (!(threeDSecureToken !== null && threeDSecureToken !== void 0 && threeDSecureToken.id)) {
|
|
316
|
+
errorPage("3D Secure verification failed. Please try again.");
|
|
317
|
+
}
|
|
318
|
+
apiBase = baseUrl + "charge/" + userId;
|
|
319
|
+
_context2.n = 7;
|
|
320
|
+
return fetch("".concat(apiBase), {
|
|
321
|
+
method: "POST",
|
|
322
|
+
headers: {
|
|
323
|
+
"Content-Type": "application/json"
|
|
324
|
+
},
|
|
325
|
+
body: JSON.stringify({
|
|
326
|
+
tokenId: threeDSecureToken.id,
|
|
327
|
+
amount: request.amount,
|
|
328
|
+
currency: request.currency,
|
|
329
|
+
description: description
|
|
330
|
+
})
|
|
331
|
+
});
|
|
332
|
+
case 7:
|
|
333
|
+
response = _context2.v;
|
|
334
|
+
_context2.n = 8;
|
|
335
|
+
return response.json();
|
|
336
|
+
case 8:
|
|
337
|
+
result = _context2.v;
|
|
338
|
+
if (response.ok) {
|
|
339
|
+
_context2.n = 9;
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
if (typeof errorPage === "function") errorPage(result);
|
|
343
|
+
return _context2.a(2);
|
|
344
|
+
case 9:
|
|
345
|
+
if (typeof successPage === "function") successPage(result.message);
|
|
346
|
+
_context2.n = 11;
|
|
347
|
+
break;
|
|
348
|
+
case 10:
|
|
349
|
+
_context2.p = 10;
|
|
350
|
+
_t2 = _context2.v;
|
|
351
|
+
if (typeof errorPage === "function") errorPage(_t2.message);
|
|
352
|
+
case 11:
|
|
353
|
+
_context2.p = 11;
|
|
354
|
+
setIsSubmitting(false);
|
|
355
|
+
setIsStart(!isStart);
|
|
356
|
+
return _context2.f(11);
|
|
357
|
+
case 12:
|
|
358
|
+
return _context2.a(2);
|
|
359
|
+
}
|
|
360
|
+
}, _callee2, null, [[4, 10, 11, 12]]);
|
|
361
|
+
}));
|
|
362
|
+
return function handleSubmit(_x) {
|
|
363
|
+
return _ref3.apply(this, arguments);
|
|
364
|
+
};
|
|
365
|
+
}();
|
|
366
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
367
|
+
style: {
|
|
368
|
+
display: "flex",
|
|
369
|
+
justifyContent: "center",
|
|
370
|
+
width: "100%",
|
|
371
|
+
boxSizing: "border-box"
|
|
372
|
+
}
|
|
373
|
+
}, /*#__PURE__*/React.createElement("form", {
|
|
374
|
+
ref: formRef,
|
|
375
|
+
id: "payment-form",
|
|
376
|
+
onSubmit: handleSubmit,
|
|
377
|
+
method: "post",
|
|
378
|
+
style: {
|
|
379
|
+
display: "grid",
|
|
380
|
+
gap: "12px",
|
|
381
|
+
padding: "20px",
|
|
382
|
+
backgroundColor: formbackgroundColor,
|
|
383
|
+
borderRadius: formborderRadius,
|
|
384
|
+
width: formwidth,
|
|
385
|
+
boxSizing: "border-box"
|
|
386
|
+
}
|
|
387
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
388
|
+
style: {
|
|
389
|
+
display: "grid",
|
|
390
|
+
gap: "8px"
|
|
391
|
+
}
|
|
392
|
+
}, /*#__PURE__*/React.createElement("label", {
|
|
393
|
+
style: {
|
|
394
|
+
fontWeight: "500",
|
|
395
|
+
color: "#555"
|
|
396
|
+
}
|
|
397
|
+
}, "Card number"), /*#__PURE__*/React.createElement("div", {
|
|
398
|
+
"data-shift4": "number",
|
|
399
|
+
className: "form-control",
|
|
400
|
+
style: {
|
|
401
|
+
padding: inputpadding,
|
|
402
|
+
borderRadius: formborderRadius,
|
|
403
|
+
border: "1px solid #ccc",
|
|
404
|
+
boxShadow: "inset 0 2px 4px rgba(0,0,0,0.05)"
|
|
405
|
+
}
|
|
406
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
407
|
+
style: {
|
|
408
|
+
display: "grid",
|
|
409
|
+
gridTemplateColumns: "1fr 1fr",
|
|
410
|
+
gap: "10px",
|
|
411
|
+
marginTop: "5px"
|
|
412
|
+
}
|
|
413
|
+
}, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", {
|
|
414
|
+
style: {
|
|
415
|
+
fontWeight: "500",
|
|
416
|
+
color: "#555",
|
|
417
|
+
marginBottom: 2
|
|
418
|
+
}
|
|
419
|
+
}, "Expiration"), /*#__PURE__*/React.createElement("div", {
|
|
420
|
+
"data-shift4": "expiry",
|
|
421
|
+
className: "form-control",
|
|
422
|
+
style: {
|
|
423
|
+
padding: inputpadding,
|
|
424
|
+
borderRadius: formborderRadius,
|
|
425
|
+
border: "1px solid #ccc",
|
|
426
|
+
boxShadow: "inset 0 2px 4px rgba(0,0,0,0.05)"
|
|
427
|
+
}
|
|
428
|
+
})), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", {
|
|
429
|
+
style: {
|
|
430
|
+
fontWeight: "500",
|
|
431
|
+
color: "#555",
|
|
432
|
+
marginBottom: 2
|
|
433
|
+
}
|
|
434
|
+
}, "CVC"), /*#__PURE__*/React.createElement("div", {
|
|
435
|
+
"data-shift4": "cvc",
|
|
436
|
+
className: "form-control",
|
|
437
|
+
style: {
|
|
438
|
+
padding: inputpadding,
|
|
439
|
+
borderRadius: formborderRadius,
|
|
440
|
+
border: "1px solid #ccc",
|
|
441
|
+
boxShadow: "inset 0 2px 4px rgba(0,0,0,0.05)"
|
|
442
|
+
}
|
|
443
|
+
}))), /*#__PURE__*/React.createElement("button", {
|
|
444
|
+
type: "submit",
|
|
445
|
+
disabled: !isReady || isSubmitting,
|
|
446
|
+
style: {
|
|
447
|
+
marginTop: "16px",
|
|
448
|
+
width: "100%",
|
|
449
|
+
padding: inputpadding + 2,
|
|
450
|
+
backgroundColor: color,
|
|
451
|
+
color: "white",
|
|
452
|
+
border: "none",
|
|
453
|
+
borderRadius: formborderRadius,
|
|
454
|
+
fontWeight: "600",
|
|
455
|
+
cursor: !isReady || isSubmitting ? "not-allowed" : "pointer",
|
|
456
|
+
opacity: !isReady || isSubmitting ? 0.7 : 1
|
|
457
|
+
}
|
|
458
|
+
}, isSubmitting ? "Processing..." : "Buy now")));
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
exports.PaymentForm = PaymentForm;
|
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import React, { useRef, useState, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
function _arrayLikeToArray(r, a) {
|
|
4
|
+
(null == a || a > r.length) && (a = r.length);
|
|
5
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
6
|
+
return n;
|
|
7
|
+
}
|
|
8
|
+
function _arrayWithHoles(r) {
|
|
9
|
+
if (Array.isArray(r)) return r;
|
|
10
|
+
}
|
|
11
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
12
|
+
try {
|
|
13
|
+
var i = n[a](c),
|
|
14
|
+
u = i.value;
|
|
15
|
+
} catch (n) {
|
|
16
|
+
return void e(n);
|
|
17
|
+
}
|
|
18
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
19
|
+
}
|
|
20
|
+
function _asyncToGenerator(n) {
|
|
21
|
+
return function () {
|
|
22
|
+
var t = this,
|
|
23
|
+
e = arguments;
|
|
24
|
+
return new Promise(function (r, o) {
|
|
25
|
+
var a = n.apply(t, e);
|
|
26
|
+
function _next(n) {
|
|
27
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
28
|
+
}
|
|
29
|
+
function _throw(n) {
|
|
30
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
31
|
+
}
|
|
32
|
+
_next(void 0);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function _iterableToArrayLimit(r, l) {
|
|
37
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
38
|
+
if (null != t) {
|
|
39
|
+
var e,
|
|
40
|
+
n,
|
|
41
|
+
i,
|
|
42
|
+
u,
|
|
43
|
+
a = [],
|
|
44
|
+
f = true,
|
|
45
|
+
o = false;
|
|
46
|
+
try {
|
|
47
|
+
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);
|
|
48
|
+
} catch (r) {
|
|
49
|
+
o = true, n = r;
|
|
50
|
+
} finally {
|
|
51
|
+
try {
|
|
52
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
53
|
+
} finally {
|
|
54
|
+
if (o) throw n;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return a;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function _nonIterableRest() {
|
|
61
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
62
|
+
}
|
|
63
|
+
function _regenerator() {
|
|
64
|
+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
65
|
+
var e,
|
|
66
|
+
t,
|
|
67
|
+
r = "function" == typeof Symbol ? Symbol : {},
|
|
68
|
+
n = r.iterator || "@@iterator",
|
|
69
|
+
o = r.toStringTag || "@@toStringTag";
|
|
70
|
+
function i(r, n, o, i) {
|
|
71
|
+
var c = n && n.prototype instanceof Generator ? n : Generator,
|
|
72
|
+
u = Object.create(c.prototype);
|
|
73
|
+
return _regeneratorDefine(u, "_invoke", function (r, n, o) {
|
|
74
|
+
var i,
|
|
75
|
+
c,
|
|
76
|
+
u,
|
|
77
|
+
f = 0,
|
|
78
|
+
p = o || [],
|
|
79
|
+
y = false,
|
|
80
|
+
G = {
|
|
81
|
+
p: 0,
|
|
82
|
+
n: 0,
|
|
83
|
+
v: e,
|
|
84
|
+
a: d,
|
|
85
|
+
f: d.bind(e, 4),
|
|
86
|
+
d: function (t, r) {
|
|
87
|
+
return i = t, c = 0, u = e, G.n = r, a;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
function d(r, n) {
|
|
91
|
+
for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
|
|
92
|
+
var o,
|
|
93
|
+
i = p[t],
|
|
94
|
+
d = G.p,
|
|
95
|
+
l = i[2];
|
|
96
|
+
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));
|
|
97
|
+
}
|
|
98
|
+
if (o || r > 1) return a;
|
|
99
|
+
throw y = true, n;
|
|
100
|
+
}
|
|
101
|
+
return function (o, p, l) {
|
|
102
|
+
if (f > 1) throw TypeError("Generator is already running");
|
|
103
|
+
for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
|
|
104
|
+
i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
|
|
105
|
+
try {
|
|
106
|
+
if (f = 2, i) {
|
|
107
|
+
if (c || (o = "next"), t = i[o]) {
|
|
108
|
+
if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
|
|
109
|
+
if (!t.done) return t;
|
|
110
|
+
u = t.value, c < 2 && (c = 0);
|
|
111
|
+
} else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
|
|
112
|
+
i = e;
|
|
113
|
+
} else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
|
|
114
|
+
} catch (t) {
|
|
115
|
+
i = e, c = 1, u = t;
|
|
116
|
+
} finally {
|
|
117
|
+
f = 1;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
value: t,
|
|
122
|
+
done: y
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
}(r, o, i), true), u;
|
|
126
|
+
}
|
|
127
|
+
var a = {};
|
|
128
|
+
function Generator() {}
|
|
129
|
+
function GeneratorFunction() {}
|
|
130
|
+
function GeneratorFunctionPrototype() {}
|
|
131
|
+
t = Object.getPrototypeOf;
|
|
132
|
+
var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
|
|
133
|
+
return this;
|
|
134
|
+
}), t),
|
|
135
|
+
u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
|
|
136
|
+
function f(e) {
|
|
137
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
|
|
138
|
+
}
|
|
139
|
+
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 () {
|
|
140
|
+
return this;
|
|
141
|
+
}), _regeneratorDefine(u, "toString", function () {
|
|
142
|
+
return "[object Generator]";
|
|
143
|
+
}), (_regenerator = function () {
|
|
144
|
+
return {
|
|
145
|
+
w: i,
|
|
146
|
+
m: f
|
|
147
|
+
};
|
|
148
|
+
})();
|
|
149
|
+
}
|
|
150
|
+
function _regeneratorDefine(e, r, n, t) {
|
|
151
|
+
var i = Object.defineProperty;
|
|
152
|
+
try {
|
|
153
|
+
i({}, "", {});
|
|
154
|
+
} catch (e) {
|
|
155
|
+
i = 0;
|
|
156
|
+
}
|
|
157
|
+
_regeneratorDefine = function (e, r, n, t) {
|
|
158
|
+
function o(r, n) {
|
|
159
|
+
_regeneratorDefine(e, r, function (e) {
|
|
160
|
+
return this._invoke(r, n, e);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
r ? i ? i(e, r, {
|
|
164
|
+
value: n,
|
|
165
|
+
enumerable: !t,
|
|
166
|
+
configurable: !t,
|
|
167
|
+
writable: !t
|
|
168
|
+
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
169
|
+
}, _regeneratorDefine(e, r, n, t);
|
|
170
|
+
}
|
|
171
|
+
function _slicedToArray(r, e) {
|
|
172
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
173
|
+
}
|
|
174
|
+
function _unsupportedIterableToArray(r, a) {
|
|
175
|
+
if (r) {
|
|
176
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
177
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
178
|
+
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;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function PaymentForm(_ref) {
|
|
183
|
+
var amount = _ref.amount,
|
|
184
|
+
currency = _ref.currency,
|
|
185
|
+
color = _ref.color,
|
|
186
|
+
_ref$formwidth = _ref.formwidth,
|
|
187
|
+
formwidth = _ref$formwidth === void 0 ? 400 : _ref$formwidth,
|
|
188
|
+
_ref$formborderRadius = _ref.formborderRadius,
|
|
189
|
+
formborderRadius = _ref$formborderRadius === void 0 ? 20 : _ref$formborderRadius,
|
|
190
|
+
_ref$formbackgroundCo = _ref.formbackgroundColor,
|
|
191
|
+
formbackgroundColor = _ref$formbackgroundCo === void 0 ? "#fff" : _ref$formbackgroundCo,
|
|
192
|
+
_ref$inputpadding = _ref.inputpadding,
|
|
193
|
+
inputpadding = _ref$inputpadding === void 0 ? 12 : _ref$inputpadding,
|
|
194
|
+
baseUrl = _ref.baseUrl,
|
|
195
|
+
userId = _ref.userId,
|
|
196
|
+
successPage = _ref.successPage,
|
|
197
|
+
errorPage = _ref.errorPage,
|
|
198
|
+
description = _ref.description;
|
|
199
|
+
var formRef = useRef();
|
|
200
|
+
var initializedRef = useRef(false);
|
|
201
|
+
var shift4Ref = useRef(null);
|
|
202
|
+
var componentsRef = useRef(null);
|
|
203
|
+
var _useState = useState(false),
|
|
204
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
205
|
+
isSubmitting = _useState2[0],
|
|
206
|
+
setIsSubmitting = _useState2[1];
|
|
207
|
+
var _useState3 = useState(false),
|
|
208
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
209
|
+
isStart = _useState4[0],
|
|
210
|
+
setIsStart = _useState4[1];
|
|
211
|
+
var _useState5 = useState(false),
|
|
212
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
213
|
+
isReady = _useState6[0],
|
|
214
|
+
setIsReady = _useState6[1];
|
|
215
|
+
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
|
+
}, [isStart]);
|
|
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
|
+
setIsStart(!isStart);
|
|
354
|
+
return _context2.f(11);
|
|
355
|
+
case 12:
|
|
356
|
+
return _context2.a(2);
|
|
357
|
+
}
|
|
358
|
+
}, _callee2, null, [[4, 10, 11, 12]]);
|
|
359
|
+
}));
|
|
360
|
+
return function handleSubmit(_x) {
|
|
361
|
+
return _ref3.apply(this, arguments);
|
|
362
|
+
};
|
|
363
|
+
}();
|
|
364
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
365
|
+
style: {
|
|
366
|
+
display: "flex",
|
|
367
|
+
justifyContent: "center",
|
|
368
|
+
width: "100%",
|
|
369
|
+
boxSizing: "border-box"
|
|
370
|
+
}
|
|
371
|
+
}, /*#__PURE__*/React.createElement("form", {
|
|
372
|
+
ref: formRef,
|
|
373
|
+
id: "payment-form",
|
|
374
|
+
onSubmit: handleSubmit,
|
|
375
|
+
method: "post",
|
|
376
|
+
style: {
|
|
377
|
+
display: "grid",
|
|
378
|
+
gap: "12px",
|
|
379
|
+
padding: "20px",
|
|
380
|
+
backgroundColor: formbackgroundColor,
|
|
381
|
+
borderRadius: formborderRadius,
|
|
382
|
+
width: formwidth,
|
|
383
|
+
boxSizing: "border-box"
|
|
384
|
+
}
|
|
385
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
386
|
+
style: {
|
|
387
|
+
display: "grid",
|
|
388
|
+
gap: "8px"
|
|
389
|
+
}
|
|
390
|
+
}, /*#__PURE__*/React.createElement("label", {
|
|
391
|
+
style: {
|
|
392
|
+
fontWeight: "500",
|
|
393
|
+
color: "#555"
|
|
394
|
+
}
|
|
395
|
+
}, "Card number"), /*#__PURE__*/React.createElement("div", {
|
|
396
|
+
"data-shift4": "number",
|
|
397
|
+
className: "form-control",
|
|
398
|
+
style: {
|
|
399
|
+
padding: inputpadding,
|
|
400
|
+
borderRadius: formborderRadius,
|
|
401
|
+
border: "1px solid #ccc",
|
|
402
|
+
boxShadow: "inset 0 2px 4px rgba(0,0,0,0.05)"
|
|
403
|
+
}
|
|
404
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
405
|
+
style: {
|
|
406
|
+
display: "grid",
|
|
407
|
+
gridTemplateColumns: "1fr 1fr",
|
|
408
|
+
gap: "10px",
|
|
409
|
+
marginTop: "5px"
|
|
410
|
+
}
|
|
411
|
+
}, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", {
|
|
412
|
+
style: {
|
|
413
|
+
fontWeight: "500",
|
|
414
|
+
color: "#555",
|
|
415
|
+
marginBottom: 2
|
|
416
|
+
}
|
|
417
|
+
}, "Expiration"), /*#__PURE__*/React.createElement("div", {
|
|
418
|
+
"data-shift4": "expiry",
|
|
419
|
+
className: "form-control",
|
|
420
|
+
style: {
|
|
421
|
+
padding: inputpadding,
|
|
422
|
+
borderRadius: formborderRadius,
|
|
423
|
+
border: "1px solid #ccc",
|
|
424
|
+
boxShadow: "inset 0 2px 4px rgba(0,0,0,0.05)"
|
|
425
|
+
}
|
|
426
|
+
})), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("label", {
|
|
427
|
+
style: {
|
|
428
|
+
fontWeight: "500",
|
|
429
|
+
color: "#555",
|
|
430
|
+
marginBottom: 2
|
|
431
|
+
}
|
|
432
|
+
}, "CVC"), /*#__PURE__*/React.createElement("div", {
|
|
433
|
+
"data-shift4": "cvc",
|
|
434
|
+
className: "form-control",
|
|
435
|
+
style: {
|
|
436
|
+
padding: inputpadding,
|
|
437
|
+
borderRadius: formborderRadius,
|
|
438
|
+
border: "1px solid #ccc",
|
|
439
|
+
boxShadow: "inset 0 2px 4px rgba(0,0,0,0.05)"
|
|
440
|
+
}
|
|
441
|
+
}))), /*#__PURE__*/React.createElement("button", {
|
|
442
|
+
type: "submit",
|
|
443
|
+
disabled: !isReady || isSubmitting,
|
|
444
|
+
style: {
|
|
445
|
+
marginTop: "16px",
|
|
446
|
+
width: "100%",
|
|
447
|
+
padding: inputpadding + 2,
|
|
448
|
+
backgroundColor: color,
|
|
449
|
+
color: "white",
|
|
450
|
+
border: "none",
|
|
451
|
+
borderRadius: formborderRadius,
|
|
452
|
+
fontWeight: "600",
|
|
453
|
+
cursor: !isReady || isSubmitting ? "not-allowed" : "pointer",
|
|
454
|
+
opacity: !isReady || isSubmitting ? 0.7 : 1
|
|
455
|
+
}
|
|
456
|
+
}, isSubmitting ? "Processing..." : "Buy now")));
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export { PaymentForm };
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "shift-payment-form",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A React component library for integrating Shift4 payments with Logix applications.",
|
|
5
|
+
"author": "Yusif Atababayev",
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
|
|
8
|
+
"type": "module",
|
|
9
|
+
|
|
10
|
+
"main": "dist/index.cjs.js",
|
|
11
|
+
"module": "dist/index.esm.js",
|
|
12
|
+
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "rollup -c"
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
"keywords": [
|
|
23
|
+
"react",
|
|
24
|
+
"payment",
|
|
25
|
+
"shift4",
|
|
26
|
+
"checkout",
|
|
27
|
+
"3d-secure",
|
|
28
|
+
"react-component",
|
|
29
|
+
"payment-gateway"
|
|
30
|
+
],
|
|
31
|
+
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"react": ">=18",
|
|
34
|
+
"react-dom": ">=18"
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@babel/core": "^7.28.5",
|
|
39
|
+
"@babel/preset-env": "^7.28.5",
|
|
40
|
+
"@babel/preset-react": "^7.28.5",
|
|
41
|
+
"@rollup/plugin-babel": "^6.1.0",
|
|
42
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
43
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
44
|
+
"rollup": "^4.55.1"
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
}
|