logix-payment-shift4 1.1.0 → 1.1.2

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,11 @@ 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,
200
+ description = _ref.description;
197
201
  var formRef = React.useRef();
198
202
  var initializedRef = React.useRef(false); // yalnız bir dəfə mount üçün
199
203
  var shift4Ref = React.useRef(null);
@@ -227,7 +231,7 @@ function PaymentForm(_ref) {
227
231
  case 0:
228
232
  _context.p = 0;
229
233
  _context.n = 1;
230
- return fetch(apiUrl);
234
+ return fetch(baseUrl + userId);
231
235
  case 1:
232
236
  response = _context.v;
233
237
  if (response.ok) {
@@ -283,7 +287,7 @@ function PaymentForm(_ref) {
283
287
  }, []);
284
288
  var handleSubmit = /*#__PURE__*/function () {
285
289
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e) {
286
- var _result$charge, token, request, threeDSecureToken, apiBase, response, result, _t2;
290
+ var token, request, threeDSecureToken, apiBase, response, result, _t2;
287
291
  return _regenerator().w(function (_context2) {
288
292
  while (1) switch (_context2.p = _context2.n) {
289
293
  case 0:
@@ -324,7 +328,8 @@ function PaymentForm(_ref) {
324
328
  request = {
325
329
  amount: amount,
326
330
  currency: currency,
327
- card: token.id
331
+ card: token.id,
332
+ description: description
328
333
  };
329
334
  _context2.n = 7;
330
335
  return shift4Ref.current.verifyThreeDSecure(request);
@@ -336,9 +341,9 @@ function PaymentForm(_ref) {
336
341
  }
337
342
  throw new Error("3D Secure verification failed. Please try again.");
338
343
  case 8:
339
- apiBase = process.env.REACT_APP_API_BASE || "http://localhost:4242";
344
+ apiBase = baseUrl + "charge/" + userId;
340
345
  _context2.n = 9;
341
- return fetch("".concat(apiBase, "/charge"), {
346
+ return fetch("".concat(apiBase), {
342
347
  method: "POST",
343
348
  headers: {
344
349
  "Content-Type": "application/json"
@@ -346,7 +351,8 @@ function PaymentForm(_ref) {
346
351
  body: JSON.stringify({
347
352
  tokenId: threeDSecureToken.id,
348
353
  amount: request.amount,
349
- currency: request.currency
354
+ currency: request.currency,
355
+ description: description
350
356
  })
351
357
  });
352
358
  case 9:
@@ -359,15 +365,16 @@ function PaymentForm(_ref) {
359
365
  _context2.n = 11;
360
366
  break;
361
367
  }
362
- throw new Error((result === null || result === void 0 ? void 0 : result.error) || "Payment failed. Please try again.");
368
+ window.location.href = "".concat(errorPage, "?message=").concat(encodeURIComponent(result.message));
369
+ return _context2.a(2);
363
370
  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"));
371
+ window.location.href = "".concat(successPage, "?message=").concat(encodeURIComponent(result.message));
365
372
  _context2.n = 13;
366
373
  break;
367
374
  case 12:
368
375
  _context2.p = 12;
369
376
  _t2 = _context2.v;
370
- setError((_t2 === null || _t2 === void 0 ? void 0 : _t2.message) || "Payment failed. Please try again.");
377
+ window.location.href = "".concat(errorPage, "?message=").concat(encodeURIComponent(_t2.message));
371
378
  case 13:
372
379
  _context2.p = 13;
373
380
  setIsSubmitting(false);
package/dist/index.esm.js CHANGED
@@ -191,7 +191,11 @@ 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,
198
+ description = _ref.description;
195
199
  var formRef = useRef();
196
200
  var initializedRef = useRef(false); // yalnız bir dəfə mount üçün
197
201
  var shift4Ref = useRef(null);
@@ -225,7 +229,7 @@ function PaymentForm(_ref) {
225
229
  case 0:
226
230
  _context.p = 0;
227
231
  _context.n = 1;
228
- return fetch(apiUrl);
232
+ return fetch(baseUrl + userId);
229
233
  case 1:
230
234
  response = _context.v;
231
235
  if (response.ok) {
@@ -281,7 +285,7 @@ function PaymentForm(_ref) {
281
285
  }, []);
282
286
  var handleSubmit = /*#__PURE__*/function () {
283
287
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e) {
284
- var _result$charge, token, request, threeDSecureToken, apiBase, response, result, _t2;
288
+ var token, request, threeDSecureToken, apiBase, response, result, _t2;
285
289
  return _regenerator().w(function (_context2) {
286
290
  while (1) switch (_context2.p = _context2.n) {
287
291
  case 0:
@@ -322,7 +326,8 @@ function PaymentForm(_ref) {
322
326
  request = {
323
327
  amount: amount,
324
328
  currency: currency,
325
- card: token.id
329
+ card: token.id,
330
+ description: description
326
331
  };
327
332
  _context2.n = 7;
328
333
  return shift4Ref.current.verifyThreeDSecure(request);
@@ -334,9 +339,9 @@ function PaymentForm(_ref) {
334
339
  }
335
340
  throw new Error("3D Secure verification failed. Please try again.");
336
341
  case 8:
337
- apiBase = process.env.REACT_APP_API_BASE || "http://localhost:4242";
342
+ apiBase = baseUrl + "charge/" + userId;
338
343
  _context2.n = 9;
339
- return fetch("".concat(apiBase, "/charge"), {
344
+ return fetch("".concat(apiBase), {
340
345
  method: "POST",
341
346
  headers: {
342
347
  "Content-Type": "application/json"
@@ -344,7 +349,8 @@ function PaymentForm(_ref) {
344
349
  body: JSON.stringify({
345
350
  tokenId: threeDSecureToken.id,
346
351
  amount: request.amount,
347
- currency: request.currency
352
+ currency: request.currency,
353
+ description: description
348
354
  })
349
355
  });
350
356
  case 9:
@@ -357,15 +363,16 @@ function PaymentForm(_ref) {
357
363
  _context2.n = 11;
358
364
  break;
359
365
  }
360
- throw new Error((result === null || result === void 0 ? void 0 : result.error) || "Payment failed. Please try again.");
366
+ window.location.href = "".concat(errorPage, "?message=").concat(encodeURIComponent(result.message));
367
+ return _context2.a(2);
361
368
  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"));
369
+ window.location.href = "".concat(successPage, "?message=").concat(encodeURIComponent(result.message));
363
370
  _context2.n = 13;
364
371
  break;
365
372
  case 12:
366
373
  _context2.p = 12;
367
374
  _t2 = _context2.v;
368
- setError((_t2 === null || _t2 === void 0 ? void 0 : _t2.message) || "Payment failed. Please try again.");
375
+ window.location.href = "".concat(errorPage, "?message=").concat(encodeURIComponent(_t2.message));
369
376
  case 13:
370
377
  _context2.p = 13;
371
378
  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.2",
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,description }) {
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) => {
@@ -84,6 +84,7 @@ console.log(success);
84
84
  amount: amount,
85
85
  currency: currency,
86
86
  card: token.id,
87
+ description
87
88
  };
88
89
 
89
90
  const threeDSecureToken = await shift4Ref.current.verifyThreeDSecure(request);
@@ -91,8 +92,8 @@ console.log(success);
91
92
  throw new Error("3D Secure verification failed. Please try again.");
92
93
  }
93
94
 
94
- const apiBase = process.env.REACT_APP_API_BASE || "http://localhost:4242";
95
- const response = await fetch(`${apiBase}/charge`, {
95
+ const apiBase = baseUrl + "charge/" + userId;
96
+ const response = await fetch(`${apiBase}`, {
96
97
  method: "POST",
97
98
  headers: {
98
99
  "Content-Type": "application/json",
@@ -101,24 +102,26 @@ console.log(success);
101
102
  tokenId: threeDSecureToken.id,
102
103
  amount: request.amount,
103
104
  currency: request.currency,
105
+ description
104
106
  }),
105
107
  });
106
-
107
108
  const result = await response.json();
108
109
  if (!response.ok) {
109
- throw new Error(result?.error || "Payment failed. Please try again.");
110
+ window.location.href = `${errorPage}?message=${encodeURIComponent(result.message)}`;
111
+ return;
110
112
  }
111
113
 
112
- setSuccess(`Payment approved. Charge ID: ${result?.charge?.id || "unknown"}`);
114
+ window.location.href = `${successPage}?message=${encodeURIComponent(result.message)}`;
115
+
113
116
  } catch (err) {
114
- setError(err?.message || "Payment failed. Please try again.");
117
+ window.location.href = `${errorPage}?message=${encodeURIComponent(err.message)}`;
115
118
  } finally {
116
119
  setIsSubmitting(false);
117
120
  }
118
121
  };
119
122
 
120
123
  return (
121
- <div
124
+ <div
122
125
  style={{
123
126
  display: "flex",
124
127
  justifyContent: "center",
@@ -137,11 +140,11 @@ console.log(success);
137
140
  padding: "20px",
138
141
  backgroundColor: formbackgroundColor,
139
142
  borderRadius: formborderRadius,
140
- width: formwidth,
143
+ width: formwidth,
141
144
  boxSizing: "border-box"
142
145
  }}
143
146
  >
144
-
147
+
145
148
 
146
149
  {/* Card Number */}
147
150
  <div style={{ display: "grid", gap: "8px" }}>
@@ -161,7 +164,7 @@ console.log(success);
161
164
  {/* Expiration + CVC */}
162
165
  <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "10px", marginTop: "5px" }}>
163
166
  <div>
164
- <label style={{ fontWeight: "500", color: "#555",marginBottom:2 }}>Expiration</label>
167
+ <label style={{ fontWeight: "500", color: "#555", marginBottom: 2 }}>Expiration</label>
165
168
  <div
166
169
  data-shift4="expiry"
167
170
  className="form-control"
@@ -174,7 +177,7 @@ console.log(success);
174
177
  />
175
178
  </div>
176
179
  <div>
177
- <label style={{ fontWeight: "500", color: "#555",marginBottom:2 }}>CVC</label>
180
+ <label style={{ fontWeight: "500", color: "#555", marginBottom: 2 }}>CVC</label>
178
181
  <div
179
182
  data-shift4="cvc"
180
183
  className="form-control"
@@ -195,7 +198,7 @@ console.log(success);
195
198
  style={{
196
199
  marginTop: "16px",
197
200
  width: "100%",
198
- padding: inputpadding+2,
201
+ padding: inputpadding + 2,
199
202
  backgroundColor: color,
200
203
  color: "white",
201
204
  border: "none",