logix-payment-shift4 1.1.0 → 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 CHANGED
@@ -193,7 +193,10 @@ function PaymentForm(_ref) {
193
193
  formbackgroundColor = _ref$formbackgroundCo === void 0 ? "#fff" : _ref$formbackgroundCo,
194
194
  _ref$inputpadding = _ref.inputpadding,
195
195
  inputpadding = _ref$inputpadding === void 0 ? 12 : _ref$inputpadding,
196
- apiUrl = _ref.apiUrl;
196
+ baseUrl = _ref.baseUrl,
197
+ userId = _ref.userId,
198
+ successPage = _ref.successPage,
199
+ errorPage = _ref.errorPage;
197
200
  var formRef = React.useRef();
198
201
  var initializedRef = React.useRef(false); // yalnız bir dəfə mount üçün
199
202
  var shift4Ref = React.useRef(null);
@@ -227,7 +230,7 @@ function PaymentForm(_ref) {
227
230
  case 0:
228
231
  _context.p = 0;
229
232
  _context.n = 1;
230
- return fetch(apiUrl);
233
+ return fetch(baseUrl + userId);
231
234
  case 1:
232
235
  response = _context.v;
233
236
  if (response.ok) {
@@ -283,7 +286,7 @@ function PaymentForm(_ref) {
283
286
  }, []);
284
287
  var handleSubmit = /*#__PURE__*/function () {
285
288
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e) {
286
- var _result$charge, token, request, threeDSecureToken, apiBase, response, result, _t2;
289
+ var token, request, threeDSecureToken, apiBase, response, result, _t2;
287
290
  return _regenerator().w(function (_context2) {
288
291
  while (1) switch (_context2.p = _context2.n) {
289
292
  case 0:
@@ -336,9 +339,9 @@ function PaymentForm(_ref) {
336
339
  }
337
340
  throw new Error("3D Secure verification failed. Please try again.");
338
341
  case 8:
339
- apiBase = process.env.REACT_APP_API_BASE || "http://localhost:4242";
342
+ apiBase = baseUrl + "charge/" + userId;
340
343
  _context2.n = 9;
341
- return fetch("".concat(apiBase, "/charge"), {
344
+ return fetch("".concat(apiBase), {
342
345
  method: "POST",
343
346
  headers: {
344
347
  "Content-Type": "application/json"
@@ -359,15 +362,16 @@ function PaymentForm(_ref) {
359
362
  _context2.n = 11;
360
363
  break;
361
364
  }
362
- throw new Error((result === null || result === void 0 ? void 0 : result.error) || "Payment failed. Please try again.");
365
+ window.location.href = "".concat(errorPage, "?message=").concat(encodeURIComponent(result.message));
366
+ return _context2.a(2);
363
367
  case 11:
364
- setSuccess("Payment approved. Charge ID: ".concat((result === null || result === void 0 || (_result$charge = result.charge) === null || _result$charge === void 0 ? void 0 : _result$charge.id) || "unknown"));
368
+ window.location.href = "".concat(successPage, "?message=").concat(encodeURIComponent(result.message));
365
369
  _context2.n = 13;
366
370
  break;
367
371
  case 12:
368
372
  _context2.p = 12;
369
373
  _t2 = _context2.v;
370
- setError((_t2 === null || _t2 === void 0 ? void 0 : _t2.message) || "Payment failed. Please try again.");
374
+ window.location.href = "".concat(errorPage, "?message=").concat(encodeURIComponent(_t2.message));
371
375
  case 13:
372
376
  _context2.p = 13;
373
377
  setIsSubmitting(false);
package/dist/index.esm.js CHANGED
@@ -191,7 +191,10 @@ function PaymentForm(_ref) {
191
191
  formbackgroundColor = _ref$formbackgroundCo === void 0 ? "#fff" : _ref$formbackgroundCo,
192
192
  _ref$inputpadding = _ref.inputpadding,
193
193
  inputpadding = _ref$inputpadding === void 0 ? 12 : _ref$inputpadding,
194
- apiUrl = _ref.apiUrl;
194
+ baseUrl = _ref.baseUrl,
195
+ userId = _ref.userId,
196
+ successPage = _ref.successPage,
197
+ errorPage = _ref.errorPage;
195
198
  var formRef = useRef();
196
199
  var initializedRef = useRef(false); // yalnız bir dəfə mount üçün
197
200
  var shift4Ref = useRef(null);
@@ -225,7 +228,7 @@ function PaymentForm(_ref) {
225
228
  case 0:
226
229
  _context.p = 0;
227
230
  _context.n = 1;
228
- return fetch(apiUrl);
231
+ return fetch(baseUrl + userId);
229
232
  case 1:
230
233
  response = _context.v;
231
234
  if (response.ok) {
@@ -281,7 +284,7 @@ function PaymentForm(_ref) {
281
284
  }, []);
282
285
  var handleSubmit = /*#__PURE__*/function () {
283
286
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e) {
284
- var _result$charge, token, request, threeDSecureToken, apiBase, response, result, _t2;
287
+ var token, request, threeDSecureToken, apiBase, response, result, _t2;
285
288
  return _regenerator().w(function (_context2) {
286
289
  while (1) switch (_context2.p = _context2.n) {
287
290
  case 0:
@@ -334,9 +337,9 @@ function PaymentForm(_ref) {
334
337
  }
335
338
  throw new Error("3D Secure verification failed. Please try again.");
336
339
  case 8:
337
- apiBase = process.env.REACT_APP_API_BASE || "http://localhost:4242";
340
+ apiBase = baseUrl + "charge/" + userId;
338
341
  _context2.n = 9;
339
- return fetch("".concat(apiBase, "/charge"), {
342
+ return fetch("".concat(apiBase), {
340
343
  method: "POST",
341
344
  headers: {
342
345
  "Content-Type": "application/json"
@@ -357,15 +360,16 @@ function PaymentForm(_ref) {
357
360
  _context2.n = 11;
358
361
  break;
359
362
  }
360
- throw new Error((result === null || result === void 0 ? void 0 : result.error) || "Payment failed. Please try again.");
363
+ window.location.href = "".concat(errorPage, "?message=").concat(encodeURIComponent(result.message));
364
+ return _context2.a(2);
361
365
  case 11:
362
- setSuccess("Payment approved. Charge ID: ".concat((result === null || result === void 0 || (_result$charge = result.charge) === null || _result$charge === void 0 ? void 0 : _result$charge.id) || "unknown"));
366
+ window.location.href = "".concat(successPage, "?message=").concat(encodeURIComponent(result.message));
363
367
  _context2.n = 13;
364
368
  break;
365
369
  case 12:
366
370
  _context2.p = 12;
367
371
  _t2 = _context2.v;
368
- setError((_t2 === null || _t2 === void 0 ? void 0 : _t2.message) || "Payment failed. Please try again.");
372
+ window.location.href = "".concat(errorPage, "?message=").concat(encodeURIComponent(_t2.message));
369
373
  case 13:
370
374
  _context2.p = 13;
371
375
  setIsSubmitting(false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "logix-payment-shift4",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.esm.js",
6
6
  "description": "A React component library for integrating Shift4 payments with Logix applications.",
@@ -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,apiUrl}) {
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,54 +9,54 @@ 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
- useEffect(() => {
17
- if (initializedRef.current) return;
18
- initializedRef.current = true;
16
+ useEffect(() => {
17
+ if (initializedRef.current) return;
18
+ initializedRef.current = true;
19
19
 
20
- const initPayment = async () => {
21
- try {
22
- // 🔹 1. Public key-ni backend-dən çəkirik
23
- const response = await fetch(apiUrl);
24
- if (!response.ok) throw new Error("Failed to fetch public key");
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
- const { publicKeys} = await response.json();
27
- if (!publicKeys) throw new Error("Public key is empty");
26
+ const { publicKeys } = await response.json();
27
+ if (!publicKeys) throw new Error("Public key is empty");
28
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;
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
33
 
34
- script.onload = () => {
35
- if (!window.Shift4) return;
34
+ script.onload = () => {
35
+ if (!window.Shift4) return;
36
36
 
37
- // 🔹 3. Dinamik key ilə init
38
- shift4Ref.current = window.Shift4(publicKeys);
37
+ // 🔹 3. Dinamik key ilə init
38
+ shift4Ref.current = window.Shift4(publicKeys);
39
39
 
40
- componentsRef.current = shift4Ref.current
41
- .createComponentGroup()
42
- .automount("#payment-form");
40
+ componentsRef.current = shift4Ref.current
41
+ .createComponentGroup()
42
+ .automount("#payment-form");
43
43
 
44
- setIsReady(true);
45
- };
44
+ setIsReady(true);
45
+ };
46
46
 
47
- script.onerror = () => {
48
- setError("Payment provider script failed to load.");
49
- };
47
+ script.onerror = () => {
48
+ setError("Payment provider script failed to load.");
49
+ };
50
50
 
51
- document.body.appendChild(script);
52
- } catch (err) {
53
- console.error(err);
54
- setError("Payment initialization failed. Please try again.");
55
- }
56
- };
51
+ document.body.appendChild(script);
52
+ } catch (err) {
53
+ console.error(err);
54
+ setError("Payment initialization failed. Please try again.");
55
+ }
56
+ };
57
57
 
58
- initPayment();
59
- }, []);
58
+ initPayment();
59
+ }, []);
60
60
 
61
61
 
62
62
  const handleSubmit = async (e) => {
@@ -91,8 +91,8 @@ console.log(success);
91
91
  throw new Error("3D Secure verification failed. Please try again.");
92
92
  }
93
93
 
94
- const apiBase = process.env.REACT_APP_API_BASE || "http://localhost:4242";
95
- const response = await fetch(`${apiBase}/charge`, {
94
+ const apiBase = baseUrl + "charge/" + userId;
95
+ const response = await fetch(`${apiBase}`, {
96
96
  method: "POST",
97
97
  headers: {
98
98
  "Content-Type": "application/json",
@@ -103,22 +103,23 @@ console.log(success);
103
103
  currency: request.currency,
104
104
  }),
105
105
  });
106
-
107
106
  const result = await response.json();
108
107
  if (!response.ok) {
109
- throw new Error(result?.error || "Payment failed. Please try again.");
108
+ window.location.href = `${errorPage}?message=${encodeURIComponent(result.message)}`;
109
+ return;
110
110
  }
111
111
 
112
- setSuccess(`Payment approved. Charge ID: ${result?.charge?.id || "unknown"}`);
112
+ window.location.href = `${successPage}?message=${encodeURIComponent(result.message)}`;
113
+
113
114
  } catch (err) {
114
- setError(err?.message || "Payment failed. Please try again.");
115
+ window.location.href = `${errorPage}?message=${encodeURIComponent(err.message)}`;
115
116
  } finally {
116
117
  setIsSubmitting(false);
117
118
  }
118
119
  };
119
120
 
120
121
  return (
121
- <div
122
+ <div
122
123
  style={{
123
124
  display: "flex",
124
125
  justifyContent: "center",
@@ -137,11 +138,11 @@ console.log(success);
137
138
  padding: "20px",
138
139
  backgroundColor: formbackgroundColor,
139
140
  borderRadius: formborderRadius,
140
- width: formwidth,
141
+ width: formwidth,
141
142
  boxSizing: "border-box"
142
143
  }}
143
144
  >
144
-
145
+
145
146
 
146
147
  {/* Card Number */}
147
148
  <div style={{ display: "grid", gap: "8px" }}>
@@ -161,7 +162,7 @@ console.log(success);
161
162
  {/* Expiration + CVC */}
162
163
  <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "10px", marginTop: "5px" }}>
163
164
  <div>
164
- <label style={{ fontWeight: "500", color: "#555",marginBottom:2 }}>Expiration</label>
165
+ <label style={{ fontWeight: "500", color: "#555", marginBottom: 2 }}>Expiration</label>
165
166
  <div
166
167
  data-shift4="expiry"
167
168
  className="form-control"
@@ -174,7 +175,7 @@ console.log(success);
174
175
  />
175
176
  </div>
176
177
  <div>
177
- <label style={{ fontWeight: "500", color: "#555",marginBottom:2 }}>CVC</label>
178
+ <label style={{ fontWeight: "500", color: "#555", marginBottom: 2 }}>CVC</label>
178
179
  <div
179
180
  data-shift4="cvc"
180
181
  className="form-control"
@@ -195,7 +196,7 @@ console.log(success);
195
196
  style={{
196
197
  marginTop: "16px",
197
198
  width: "100%",
198
- padding: inputpadding+2,
199
+ padding: inputpadding + 2,
199
200
  backgroundColor: color,
200
201
  color: "white",
201
202
  border: "none",