logix-payment-shift4 1.0.9 → 1.1.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.
- package/dist/index.cjs.js +102 -49
- package/dist/index.esm.js +102 -49
- package/package.json +1 -1
- package/src/PaymentForm.jsx +53 -27
package/dist/index.cjs.js
CHANGED
|
@@ -192,7 +192,11 @@ function PaymentForm(_ref) {
|
|
|
192
192
|
_ref$formbackgroundCo = _ref.formbackgroundColor,
|
|
193
193
|
formbackgroundColor = _ref$formbackgroundCo === void 0 ? "#fff" : _ref$formbackgroundCo,
|
|
194
194
|
_ref$inputpadding = _ref.inputpadding,
|
|
195
|
-
inputpadding = _ref$inputpadding === void 0 ? 12 : _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;
|
|
196
200
|
var formRef = React.useRef();
|
|
197
201
|
var initializedRef = React.useRef(false); // yalnız bir dəfə mount üçün
|
|
198
202
|
var shift4Ref = React.useRef(null);
|
|
@@ -218,56 +222,104 @@ function PaymentForm(_ref) {
|
|
|
218
222
|
React.useEffect(function () {
|
|
219
223
|
if (initializedRef.current) return;
|
|
220
224
|
initializedRef.current = true;
|
|
221
|
-
var
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
225
|
+
var initPayment = /*#__PURE__*/function () {
|
|
226
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
227
|
+
var response, _yield$response$json, publicKeys, script, _t;
|
|
228
|
+
return _regenerator().w(function (_context) {
|
|
229
|
+
while (1) switch (_context.p = _context.n) {
|
|
230
|
+
case 0:
|
|
231
|
+
_context.p = 0;
|
|
232
|
+
_context.n = 1;
|
|
233
|
+
return fetch(baseUrl + userId);
|
|
234
|
+
case 1:
|
|
235
|
+
response = _context.v;
|
|
236
|
+
if (response.ok) {
|
|
237
|
+
_context.n = 2;
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
throw new Error("Failed to fetch public key");
|
|
241
|
+
case 2:
|
|
242
|
+
_context.n = 3;
|
|
243
|
+
return response.json();
|
|
244
|
+
case 3:
|
|
245
|
+
_yield$response$json = _context.v;
|
|
246
|
+
publicKeys = _yield$response$json.publicKeys;
|
|
247
|
+
if (publicKeys) {
|
|
248
|
+
_context.n = 4;
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
throw new Error("Public key is empty");
|
|
252
|
+
case 4:
|
|
253
|
+
// 🔹 2. Shift4 script-i yükləyirik
|
|
254
|
+
script = document.createElement("script");
|
|
255
|
+
script.src = "https://js.dev.shift4.com/shift4.js";
|
|
256
|
+
script.async = true;
|
|
257
|
+
script.onload = function () {
|
|
258
|
+
if (!window.Shift4) return;
|
|
259
|
+
|
|
260
|
+
// 🔹 3. Dinamik key ilə init
|
|
261
|
+
shift4Ref.current = window.Shift4(publicKeys);
|
|
262
|
+
componentsRef.current = shift4Ref.current.createComponentGroup().automount("#payment-form");
|
|
263
|
+
setIsReady(true);
|
|
264
|
+
};
|
|
265
|
+
script.onerror = function () {
|
|
266
|
+
setError("Payment provider script failed to load.");
|
|
267
|
+
};
|
|
268
|
+
document.body.appendChild(script);
|
|
269
|
+
_context.n = 6;
|
|
270
|
+
break;
|
|
271
|
+
case 5:
|
|
272
|
+
_context.p = 5;
|
|
273
|
+
_t = _context.v;
|
|
274
|
+
console.error(_t);
|
|
275
|
+
setError("Payment initialization failed. Please try again.");
|
|
276
|
+
case 6:
|
|
277
|
+
return _context.a(2);
|
|
278
|
+
}
|
|
279
|
+
}, _callee, null, [[0, 5]]);
|
|
280
|
+
}));
|
|
281
|
+
return function initPayment() {
|
|
282
|
+
return _ref2.apply(this, arguments);
|
|
283
|
+
};
|
|
284
|
+
}();
|
|
285
|
+
initPayment();
|
|
234
286
|
}, []);
|
|
235
287
|
var handleSubmit = /*#__PURE__*/function () {
|
|
236
|
-
var
|
|
237
|
-
var
|
|
238
|
-
return _regenerator().w(function (
|
|
239
|
-
while (1) switch (
|
|
288
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e) {
|
|
289
|
+
var token, request, threeDSecureToken, apiBase, response, result, _t2;
|
|
290
|
+
return _regenerator().w(function (_context2) {
|
|
291
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
240
292
|
case 0:
|
|
241
293
|
e.preventDefault();
|
|
242
294
|
if (!isSubmitting) {
|
|
243
|
-
|
|
295
|
+
_context2.n = 1;
|
|
244
296
|
break;
|
|
245
297
|
}
|
|
246
|
-
return
|
|
298
|
+
return _context2.a(2);
|
|
247
299
|
case 1:
|
|
248
300
|
if (formRef.current) {
|
|
249
|
-
|
|
301
|
+
_context2.n = 2;
|
|
250
302
|
break;
|
|
251
303
|
}
|
|
252
|
-
return
|
|
304
|
+
return _context2.a(2);
|
|
253
305
|
case 2:
|
|
254
306
|
if (!(!shift4Ref.current || !componentsRef.current)) {
|
|
255
|
-
|
|
307
|
+
_context2.n = 3;
|
|
256
308
|
break;
|
|
257
309
|
}
|
|
258
310
|
setError("Payment form is not ready yet. Please try again.");
|
|
259
|
-
return
|
|
311
|
+
return _context2.a(2);
|
|
260
312
|
case 3:
|
|
261
313
|
setError("");
|
|
262
314
|
setSuccess("");
|
|
263
315
|
setIsSubmitting(true);
|
|
264
|
-
|
|
265
|
-
|
|
316
|
+
_context2.p = 4;
|
|
317
|
+
_context2.n = 5;
|
|
266
318
|
return shift4Ref.current.createToken(componentsRef.current);
|
|
267
319
|
case 5:
|
|
268
|
-
token =
|
|
320
|
+
token = _context2.v;
|
|
269
321
|
if (token !== null && token !== void 0 && token.id) {
|
|
270
|
-
|
|
322
|
+
_context2.n = 6;
|
|
271
323
|
break;
|
|
272
324
|
}
|
|
273
325
|
throw new Error("Card tokenization failed. Please check your details and try again.");
|
|
@@ -277,19 +329,19 @@ function PaymentForm(_ref) {
|
|
|
277
329
|
currency: currency,
|
|
278
330
|
card: token.id
|
|
279
331
|
};
|
|
280
|
-
|
|
332
|
+
_context2.n = 7;
|
|
281
333
|
return shift4Ref.current.verifyThreeDSecure(request);
|
|
282
334
|
case 7:
|
|
283
|
-
threeDSecureToken =
|
|
335
|
+
threeDSecureToken = _context2.v;
|
|
284
336
|
if (threeDSecureToken !== null && threeDSecureToken !== void 0 && threeDSecureToken.id) {
|
|
285
|
-
|
|
337
|
+
_context2.n = 8;
|
|
286
338
|
break;
|
|
287
339
|
}
|
|
288
340
|
throw new Error("3D Secure verification failed. Please try again.");
|
|
289
341
|
case 8:
|
|
290
|
-
apiBase =
|
|
291
|
-
|
|
292
|
-
return fetch("".concat(apiBase
|
|
342
|
+
apiBase = baseUrl + "charge/" + userId;
|
|
343
|
+
_context2.n = 9;
|
|
344
|
+
return fetch("".concat(apiBase), {
|
|
293
345
|
method: "POST",
|
|
294
346
|
headers: {
|
|
295
347
|
"Content-Type": "application/json"
|
|
@@ -301,35 +353,36 @@ function PaymentForm(_ref) {
|
|
|
301
353
|
})
|
|
302
354
|
});
|
|
303
355
|
case 9:
|
|
304
|
-
response =
|
|
305
|
-
|
|
356
|
+
response = _context2.v;
|
|
357
|
+
_context2.n = 10;
|
|
306
358
|
return response.json();
|
|
307
359
|
case 10:
|
|
308
|
-
result =
|
|
360
|
+
result = _context2.v;
|
|
309
361
|
if (response.ok) {
|
|
310
|
-
|
|
362
|
+
_context2.n = 11;
|
|
311
363
|
break;
|
|
312
364
|
}
|
|
313
|
-
|
|
365
|
+
window.location.href = "".concat(errorPage, "?message=").concat(encodeURIComponent(result.message));
|
|
366
|
+
return _context2.a(2);
|
|
314
367
|
case 11:
|
|
315
|
-
|
|
316
|
-
|
|
368
|
+
window.location.href = "".concat(successPage, "?message=").concat(encodeURIComponent(result.message));
|
|
369
|
+
_context2.n = 13;
|
|
317
370
|
break;
|
|
318
371
|
case 12:
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
372
|
+
_context2.p = 12;
|
|
373
|
+
_t2 = _context2.v;
|
|
374
|
+
window.location.href = "".concat(errorPage, "?message=").concat(encodeURIComponent(_t2.message));
|
|
322
375
|
case 13:
|
|
323
|
-
|
|
376
|
+
_context2.p = 13;
|
|
324
377
|
setIsSubmitting(false);
|
|
325
|
-
return
|
|
378
|
+
return _context2.f(13);
|
|
326
379
|
case 14:
|
|
327
|
-
return
|
|
380
|
+
return _context2.a(2);
|
|
328
381
|
}
|
|
329
|
-
},
|
|
382
|
+
}, _callee2, null, [[4, 12, 13, 14]]);
|
|
330
383
|
}));
|
|
331
384
|
return function handleSubmit(_x) {
|
|
332
|
-
return
|
|
385
|
+
return _ref3.apply(this, arguments);
|
|
333
386
|
};
|
|
334
387
|
}();
|
|
335
388
|
return /*#__PURE__*/React.createElement("div", {
|
package/dist/index.esm.js
CHANGED
|
@@ -190,7 +190,11 @@ function PaymentForm(_ref) {
|
|
|
190
190
|
_ref$formbackgroundCo = _ref.formbackgroundColor,
|
|
191
191
|
formbackgroundColor = _ref$formbackgroundCo === void 0 ? "#fff" : _ref$formbackgroundCo,
|
|
192
192
|
_ref$inputpadding = _ref.inputpadding,
|
|
193
|
-
inputpadding = _ref$inputpadding === void 0 ? 12 : _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;
|
|
194
198
|
var formRef = useRef();
|
|
195
199
|
var initializedRef = useRef(false); // yalnız bir dəfə mount üçün
|
|
196
200
|
var shift4Ref = useRef(null);
|
|
@@ -216,56 +220,104 @@ function PaymentForm(_ref) {
|
|
|
216
220
|
useEffect(function () {
|
|
217
221
|
if (initializedRef.current) return;
|
|
218
222
|
initializedRef.current = true;
|
|
219
|
-
var
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
223
|
+
var initPayment = /*#__PURE__*/function () {
|
|
224
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
225
|
+
var response, _yield$response$json, publicKeys, script, _t;
|
|
226
|
+
return _regenerator().w(function (_context) {
|
|
227
|
+
while (1) switch (_context.p = _context.n) {
|
|
228
|
+
case 0:
|
|
229
|
+
_context.p = 0;
|
|
230
|
+
_context.n = 1;
|
|
231
|
+
return fetch(baseUrl + userId);
|
|
232
|
+
case 1:
|
|
233
|
+
response = _context.v;
|
|
234
|
+
if (response.ok) {
|
|
235
|
+
_context.n = 2;
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
throw new Error("Failed to fetch public key");
|
|
239
|
+
case 2:
|
|
240
|
+
_context.n = 3;
|
|
241
|
+
return response.json();
|
|
242
|
+
case 3:
|
|
243
|
+
_yield$response$json = _context.v;
|
|
244
|
+
publicKeys = _yield$response$json.publicKeys;
|
|
245
|
+
if (publicKeys) {
|
|
246
|
+
_context.n = 4;
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
throw new Error("Public key is empty");
|
|
250
|
+
case 4:
|
|
251
|
+
// 🔹 2. Shift4 script-i yükləyirik
|
|
252
|
+
script = document.createElement("script");
|
|
253
|
+
script.src = "https://js.dev.shift4.com/shift4.js";
|
|
254
|
+
script.async = true;
|
|
255
|
+
script.onload = function () {
|
|
256
|
+
if (!window.Shift4) return;
|
|
257
|
+
|
|
258
|
+
// 🔹 3. Dinamik key ilə init
|
|
259
|
+
shift4Ref.current = window.Shift4(publicKeys);
|
|
260
|
+
componentsRef.current = shift4Ref.current.createComponentGroup().automount("#payment-form");
|
|
261
|
+
setIsReady(true);
|
|
262
|
+
};
|
|
263
|
+
script.onerror = function () {
|
|
264
|
+
setError("Payment provider script failed to load.");
|
|
265
|
+
};
|
|
266
|
+
document.body.appendChild(script);
|
|
267
|
+
_context.n = 6;
|
|
268
|
+
break;
|
|
269
|
+
case 5:
|
|
270
|
+
_context.p = 5;
|
|
271
|
+
_t = _context.v;
|
|
272
|
+
console.error(_t);
|
|
273
|
+
setError("Payment initialization failed. Please try again.");
|
|
274
|
+
case 6:
|
|
275
|
+
return _context.a(2);
|
|
276
|
+
}
|
|
277
|
+
}, _callee, null, [[0, 5]]);
|
|
278
|
+
}));
|
|
279
|
+
return function initPayment() {
|
|
280
|
+
return _ref2.apply(this, arguments);
|
|
281
|
+
};
|
|
282
|
+
}();
|
|
283
|
+
initPayment();
|
|
232
284
|
}, []);
|
|
233
285
|
var handleSubmit = /*#__PURE__*/function () {
|
|
234
|
-
var
|
|
235
|
-
var
|
|
236
|
-
return _regenerator().w(function (
|
|
237
|
-
while (1) switch (
|
|
286
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e) {
|
|
287
|
+
var token, request, threeDSecureToken, apiBase, response, result, _t2;
|
|
288
|
+
return _regenerator().w(function (_context2) {
|
|
289
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
238
290
|
case 0:
|
|
239
291
|
e.preventDefault();
|
|
240
292
|
if (!isSubmitting) {
|
|
241
|
-
|
|
293
|
+
_context2.n = 1;
|
|
242
294
|
break;
|
|
243
295
|
}
|
|
244
|
-
return
|
|
296
|
+
return _context2.a(2);
|
|
245
297
|
case 1:
|
|
246
298
|
if (formRef.current) {
|
|
247
|
-
|
|
299
|
+
_context2.n = 2;
|
|
248
300
|
break;
|
|
249
301
|
}
|
|
250
|
-
return
|
|
302
|
+
return _context2.a(2);
|
|
251
303
|
case 2:
|
|
252
304
|
if (!(!shift4Ref.current || !componentsRef.current)) {
|
|
253
|
-
|
|
305
|
+
_context2.n = 3;
|
|
254
306
|
break;
|
|
255
307
|
}
|
|
256
308
|
setError("Payment form is not ready yet. Please try again.");
|
|
257
|
-
return
|
|
309
|
+
return _context2.a(2);
|
|
258
310
|
case 3:
|
|
259
311
|
setError("");
|
|
260
312
|
setSuccess("");
|
|
261
313
|
setIsSubmitting(true);
|
|
262
|
-
|
|
263
|
-
|
|
314
|
+
_context2.p = 4;
|
|
315
|
+
_context2.n = 5;
|
|
264
316
|
return shift4Ref.current.createToken(componentsRef.current);
|
|
265
317
|
case 5:
|
|
266
|
-
token =
|
|
318
|
+
token = _context2.v;
|
|
267
319
|
if (token !== null && token !== void 0 && token.id) {
|
|
268
|
-
|
|
320
|
+
_context2.n = 6;
|
|
269
321
|
break;
|
|
270
322
|
}
|
|
271
323
|
throw new Error("Card tokenization failed. Please check your details and try again.");
|
|
@@ -275,19 +327,19 @@ function PaymentForm(_ref) {
|
|
|
275
327
|
currency: currency,
|
|
276
328
|
card: token.id
|
|
277
329
|
};
|
|
278
|
-
|
|
330
|
+
_context2.n = 7;
|
|
279
331
|
return shift4Ref.current.verifyThreeDSecure(request);
|
|
280
332
|
case 7:
|
|
281
|
-
threeDSecureToken =
|
|
333
|
+
threeDSecureToken = _context2.v;
|
|
282
334
|
if (threeDSecureToken !== null && threeDSecureToken !== void 0 && threeDSecureToken.id) {
|
|
283
|
-
|
|
335
|
+
_context2.n = 8;
|
|
284
336
|
break;
|
|
285
337
|
}
|
|
286
338
|
throw new Error("3D Secure verification failed. Please try again.");
|
|
287
339
|
case 8:
|
|
288
|
-
apiBase =
|
|
289
|
-
|
|
290
|
-
return fetch("".concat(apiBase
|
|
340
|
+
apiBase = baseUrl + "charge/" + userId;
|
|
341
|
+
_context2.n = 9;
|
|
342
|
+
return fetch("".concat(apiBase), {
|
|
291
343
|
method: "POST",
|
|
292
344
|
headers: {
|
|
293
345
|
"Content-Type": "application/json"
|
|
@@ -299,35 +351,36 @@ function PaymentForm(_ref) {
|
|
|
299
351
|
})
|
|
300
352
|
});
|
|
301
353
|
case 9:
|
|
302
|
-
response =
|
|
303
|
-
|
|
354
|
+
response = _context2.v;
|
|
355
|
+
_context2.n = 10;
|
|
304
356
|
return response.json();
|
|
305
357
|
case 10:
|
|
306
|
-
result =
|
|
358
|
+
result = _context2.v;
|
|
307
359
|
if (response.ok) {
|
|
308
|
-
|
|
360
|
+
_context2.n = 11;
|
|
309
361
|
break;
|
|
310
362
|
}
|
|
311
|
-
|
|
363
|
+
window.location.href = "".concat(errorPage, "?message=").concat(encodeURIComponent(result.message));
|
|
364
|
+
return _context2.a(2);
|
|
312
365
|
case 11:
|
|
313
|
-
|
|
314
|
-
|
|
366
|
+
window.location.href = "".concat(successPage, "?message=").concat(encodeURIComponent(result.message));
|
|
367
|
+
_context2.n = 13;
|
|
315
368
|
break;
|
|
316
369
|
case 12:
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
370
|
+
_context2.p = 12;
|
|
371
|
+
_t2 = _context2.v;
|
|
372
|
+
window.location.href = "".concat(errorPage, "?message=").concat(encodeURIComponent(_t2.message));
|
|
320
373
|
case 13:
|
|
321
|
-
|
|
374
|
+
_context2.p = 13;
|
|
322
375
|
setIsSubmitting(false);
|
|
323
|
-
return
|
|
376
|
+
return _context2.f(13);
|
|
324
377
|
case 14:
|
|
325
|
-
return
|
|
378
|
+
return _context2.a(2);
|
|
326
379
|
}
|
|
327
|
-
},
|
|
380
|
+
}, _callee2, null, [[4, 12, 13, 14]]);
|
|
328
381
|
}));
|
|
329
382
|
return function handleSubmit(_x) {
|
|
330
|
-
return
|
|
383
|
+
return _ref3.apply(this, arguments);
|
|
331
384
|
};
|
|
332
385
|
}();
|
|
333
386
|
return /*#__PURE__*/React.createElement("div", {
|
package/package.json
CHANGED
package/src/PaymentForm.jsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useEffect, useRef, useState } from "react";
|
|
2
2
|
|
|
3
|
-
export default function PaymentForm({amount,currency,color,formwidth=400,formborderRadius=20,formbackgroundColor="#fff",inputpadding=12}) {
|
|
3
|
+
export default function PaymentForm({ amount, currency, color, formwidth = 400, formborderRadius = 20, formbackgroundColor = "#fff", inputpadding = 12, baseUrl, userId, successPage, errorPage }) {
|
|
4
4
|
const formRef = useRef();
|
|
5
5
|
const initializedRef = useRef(false); // yalnız bir dəfə mount üçün
|
|
6
6
|
const shift4Ref = useRef(null);
|
|
@@ -9,31 +9,56 @@ export default function PaymentForm({amount,currency,color,formwidth=400,formbor
|
|
|
9
9
|
const [success, setSuccess] = useState("");
|
|
10
10
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11
11
|
const [isReady, setIsReady] = useState(false);
|
|
12
|
-
console.log(error);
|
|
13
|
-
console.log(success);
|
|
12
|
+
console.log(error);
|
|
13
|
+
console.log(success);
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
useEffect(() => {
|
|
17
17
|
if (initializedRef.current) return;
|
|
18
18
|
initializedRef.current = true;
|
|
19
19
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const initPayment = async () => {
|
|
21
|
+
try {
|
|
22
|
+
// 🔹 1. Public key-ni backend-dən çəkirik
|
|
23
|
+
const response = await fetch(baseUrl + userId);
|
|
24
|
+
if (!response.ok) throw new Error("Failed to fetch public key");
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
const { publicKeys } = await response.json();
|
|
27
|
+
if (!publicKeys) throw new Error("Public key is empty");
|
|
28
|
+
|
|
29
|
+
// 🔹 2. Shift4 script-i yükləyirik
|
|
30
|
+
const script = document.createElement("script");
|
|
31
|
+
script.src = "https://js.dev.shift4.com/shift4.js";
|
|
32
|
+
script.async = true;
|
|
33
|
+
|
|
34
|
+
script.onload = () => {
|
|
35
|
+
if (!window.Shift4) return;
|
|
36
|
+
|
|
37
|
+
// 🔹 3. Dinamik key ilə init
|
|
38
|
+
shift4Ref.current = window.Shift4(publicKeys);
|
|
39
|
+
|
|
40
|
+
componentsRef.current = shift4Ref.current
|
|
41
|
+
.createComponentGroup()
|
|
42
|
+
.automount("#payment-form");
|
|
43
|
+
|
|
44
|
+
setIsReady(true);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
script.onerror = () => {
|
|
48
|
+
setError("Payment provider script failed to load.");
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
document.body.appendChild(script);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
console.error(err);
|
|
54
|
+
setError("Payment initialization failed. Please try again.");
|
|
55
|
+
}
|
|
32
56
|
};
|
|
33
57
|
|
|
34
|
-
|
|
58
|
+
initPayment();
|
|
35
59
|
}, []);
|
|
36
60
|
|
|
61
|
+
|
|
37
62
|
const handleSubmit = async (e) => {
|
|
38
63
|
e.preventDefault();
|
|
39
64
|
|
|
@@ -66,8 +91,8 @@ console.log(success);
|
|
|
66
91
|
throw new Error("3D Secure verification failed. Please try again.");
|
|
67
92
|
}
|
|
68
93
|
|
|
69
|
-
const apiBase =
|
|
70
|
-
const response = await fetch(`${apiBase}
|
|
94
|
+
const apiBase = baseUrl + "charge/" + userId;
|
|
95
|
+
const response = await fetch(`${apiBase}`, {
|
|
71
96
|
method: "POST",
|
|
72
97
|
headers: {
|
|
73
98
|
"Content-Type": "application/json",
|
|
@@ -78,22 +103,23 @@ console.log(success);
|
|
|
78
103
|
currency: request.currency,
|
|
79
104
|
}),
|
|
80
105
|
});
|
|
81
|
-
|
|
82
106
|
const result = await response.json();
|
|
83
107
|
if (!response.ok) {
|
|
84
|
-
|
|
108
|
+
window.location.href = `${errorPage}?message=${encodeURIComponent(result.message)}`;
|
|
109
|
+
return;
|
|
85
110
|
}
|
|
86
111
|
|
|
87
|
-
|
|
112
|
+
window.location.href = `${successPage}?message=${encodeURIComponent(result.message)}`;
|
|
113
|
+
|
|
88
114
|
} catch (err) {
|
|
89
|
-
|
|
115
|
+
window.location.href = `${errorPage}?message=${encodeURIComponent(err.message)}`;
|
|
90
116
|
} finally {
|
|
91
117
|
setIsSubmitting(false);
|
|
92
118
|
}
|
|
93
119
|
};
|
|
94
120
|
|
|
95
121
|
return (
|
|
96
|
-
|
|
122
|
+
<div
|
|
97
123
|
style={{
|
|
98
124
|
display: "flex",
|
|
99
125
|
justifyContent: "center",
|
|
@@ -112,11 +138,11 @@ console.log(success);
|
|
|
112
138
|
padding: "20px",
|
|
113
139
|
backgroundColor: formbackgroundColor,
|
|
114
140
|
borderRadius: formborderRadius,
|
|
115
|
-
width: formwidth,
|
|
141
|
+
width: formwidth,
|
|
116
142
|
boxSizing: "border-box"
|
|
117
143
|
}}
|
|
118
144
|
>
|
|
119
|
-
|
|
145
|
+
|
|
120
146
|
|
|
121
147
|
{/* Card Number */}
|
|
122
148
|
<div style={{ display: "grid", gap: "8px" }}>
|
|
@@ -136,7 +162,7 @@ console.log(success);
|
|
|
136
162
|
{/* Expiration + CVC */}
|
|
137
163
|
<div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "10px", marginTop: "5px" }}>
|
|
138
164
|
<div>
|
|
139
|
-
<label style={{ fontWeight: "500", color: "#555",marginBottom:2 }}>Expiration</label>
|
|
165
|
+
<label style={{ fontWeight: "500", color: "#555", marginBottom: 2 }}>Expiration</label>
|
|
140
166
|
<div
|
|
141
167
|
data-shift4="expiry"
|
|
142
168
|
className="form-control"
|
|
@@ -149,7 +175,7 @@ console.log(success);
|
|
|
149
175
|
/>
|
|
150
176
|
</div>
|
|
151
177
|
<div>
|
|
152
|
-
<label style={{ fontWeight: "500", color: "#555",marginBottom:2 }}>CVC</label>
|
|
178
|
+
<label style={{ fontWeight: "500", color: "#555", marginBottom: 2 }}>CVC</label>
|
|
153
179
|
<div
|
|
154
180
|
data-shift4="cvc"
|
|
155
181
|
className="form-control"
|
|
@@ -170,7 +196,7 @@ console.log(success);
|
|
|
170
196
|
style={{
|
|
171
197
|
marginTop: "16px",
|
|
172
198
|
width: "100%",
|
|
173
|
-
padding: inputpadding+2,
|
|
199
|
+
padding: inputpadding + 2,
|
|
174
200
|
backgroundColor: color,
|
|
175
201
|
color: "white",
|
|
176
202
|
border: "none",
|