fairsure-checkout-sdk 1.0.12 → 1.0.13

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.
@@ -120,6 +120,7 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
120
120
  setLoading(false);
121
121
  }
122
122
  };
123
+ const PENDING_CODES = ["01", "02", "03"];
123
124
  const verifyUssd = async () => {
124
125
  var _a, _b, _c, _d;
125
126
  try {
@@ -138,6 +139,7 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
138
139
  });
139
140
  const result = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data;
140
141
  const status = (_c = (_b = result === null || result === void 0 ? void 0 : result.message) === null || _b === void 0 ? void 0 : _b.toLowerCase()) !== null && _c !== void 0 ? _c : "";
142
+ console.log("statushhh", status);
141
143
  if (status.includes("pending")) {
142
144
  onPending === null || onPending === void 0 ? void 0 : onPending(result);
143
145
  }
@@ -231,7 +233,6 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
231
233
  };
232
234
  const checkCardPaymentStatus = async (transactionRef, amount) => {
233
235
  var _a, _b;
234
- console.log("TRANSACTION REF", transactionRef, amount);
235
236
  try {
236
237
  const res = await axios.get(`https://api.fairsurepay.com/api/pub/verify-transaction?transaction_ref=${transactionRef}&amount=${amount}`, {
237
238
  headers: {
@@ -243,15 +244,14 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
243
244
  });
244
245
  const result = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data;
245
246
  const code = result === null || result === void 0 ? void 0 : result.responseCode;
246
- console.log("RESPONSE", JSON.stringify(result, null, 2));
247
+ console.log("RESULT", result);
247
248
  if (code === "00") {
248
- onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transferDetail.transactionReference);
249
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transactionRef); // ✅ use the card's own ref, not transfer's
249
250
  }
250
251
  else if (PENDING_CODES.includes(code)) {
251
252
  onPending === null || onPending === void 0 ? void 0 : onPending(result);
252
253
  }
253
254
  else {
254
- // includes "Z0" (Transaction not Completed) until confirmed otherwise
255
255
  onError === null || onError === void 0 ? void 0 : onError((_b = result === null || result === void 0 ? void 0 : result.responseDescription) !== null && _b !== void 0 ? _b : "Transfer could not be verified");
256
256
  }
257
257
  return res === null || res === void 0 ? void 0 : res.data;
@@ -343,7 +343,7 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
343
343
  }
344
344
  };
345
345
  const verifyCardPayment = async () => {
346
- var _a;
346
+ var _a, _b;
347
347
  setLoading(true);
348
348
  try {
349
349
  const payload = {
@@ -355,7 +355,6 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
355
355
  customerPhone,
356
356
  customerEmail: "08164493471_airtime_fairsurepay_com",
357
357
  };
358
- console.log("Payload:", payload);
359
358
  const res = await axios.post("https://api.fairsurepay.com/api/pub/submit-otp", payload, {
360
359
  headers: {
361
360
  Accept: "application/json",
@@ -364,9 +363,8 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
364
363
  "User-Agent": "PostmanRuntime/7.36.0",
365
364
  },
366
365
  });
367
- console.log("RESPONSEhhhhhhh", JSON.stringify((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data, null, 2));
368
- // await checkCardPaymentStatus(res?.data?.data?.transactionRef, amount);s
369
- onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transferDetail.transactionReference);
366
+ await checkCardPaymentStatus((_b = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.transactionRef, amount);
367
+ // onSuccess?.(transferDetail.transactionReference);
370
368
  setLoading(false);
371
369
  return res === null || res === void 0 ? void 0 : res.data;
372
370
  }
@@ -375,31 +373,6 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
375
373
  console.log("ERROR", error);
376
374
  }
377
375
  };
378
- // const verifyTransfer = async () => {
379
- // setLoading(true);
380
- // try {
381
- // const res = await axios.get(
382
- // `https://api.fairsurepay.com/api/pub/transfer-status?transactionReference=${transferDetail?.transactionReference}`,
383
- // {
384
- // timeout: 15000,
385
- // headers: {
386
- // Accept: "application/json",
387
- // "Content-Type": "application/json",
388
- // publickey: "LIVE_7AXSCCY8R3HABAN14QP7",
389
- // "User-Agent": "PostmanRuntime/7.36.0",
390
- // },
391
- // },
392
- // );
393
- // console.log("RESPONSE", res?.data?.data);
394
- // onSuccess?.(transferDetail.transactionReference);
395
- // return res?.data;
396
- // } catch (error: any) {
397
- // console.log("Failed to Verify transfer", error.response?.data);
398
- // } finally {
399
- // setLoading(false);
400
- // }
401
- // };
402
- const PENDING_CODES = ["00", "01", "02", "03"];
403
376
  const verifyTransfer = async () => {
404
377
  var _a, _b, _c;
405
378
  setLoading(true);
@@ -414,7 +387,6 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
414
387
  });
415
388
  const result = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data;
416
389
  const code = result === null || result === void 0 ? void 0 : result.responseCode;
417
- console.log("RESPONSE", JSON.stringify(result, null, 2));
418
390
  if (code === "00") {
419
391
  onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transferDetail.transactionReference);
420
392
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fairsure-checkout-sdk",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -144,6 +144,8 @@ export function usePaymentCheckout(
144
144
  }
145
145
  };
146
146
 
147
+ const PENDING_CODES: string[] = ["01", "02", "03"];
148
+
147
149
  const verifyUssd = async () => {
148
150
  try {
149
151
  setLoading(true);
@@ -168,6 +170,8 @@ export function usePaymentCheckout(
168
170
  const result = res?.data?.data;
169
171
 
170
172
  const status = result?.message?.toLowerCase() ?? "";
173
+ console.log("statushhh", status);
174
+
171
175
  if (status.includes("pending")) {
172
176
  onPending?.(result);
173
177
  } else if (status.includes("success") && result?.paid) {
@@ -271,8 +275,6 @@ export function usePaymentCheckout(
271
275
  transactionRef: string,
272
276
  amount: number,
273
277
  ) => {
274
- console.log("TRANSACTION REF", transactionRef, amount);
275
-
276
278
  try {
277
279
  const res = await axios.get(
278
280
  `https://api.fairsurepay.com/api/pub/verify-transaction?transaction_ref=${transactionRef}&amount=${amount}`,
@@ -287,15 +289,13 @@ export function usePaymentCheckout(
287
289
  );
288
290
  const result = res?.data?.data;
289
291
  const code = result?.responseCode;
290
-
291
- console.log("RESPONSE", JSON.stringify(result, null, 2));
292
+ console.log("RESULT", result);
292
293
 
293
294
  if (code === "00") {
294
- onSuccess?.(transferDetail.transactionReference);
295
+ onSuccess?.(transactionRef); // ✅ use the card's own ref, not transfer's
295
296
  } else if (PENDING_CODES.includes(code)) {
296
297
  onPending?.(result);
297
298
  } else {
298
- // includes "Z0" (Transaction not Completed) until confirmed otherwise
299
299
  onError?.(
300
300
  result?.responseDescription ?? "Transfer could not be verified",
301
301
  );
@@ -407,8 +407,6 @@ export function usePaymentCheckout(
407
407
  customerPhone,
408
408
  customerEmail: "08164493471_airtime_fairsurepay_com",
409
409
  };
410
- console.log("Payload:", payload);
411
-
412
410
  const res = await axios.post(
413
411
  "https://api.fairsurepay.com/api/pub/submit-otp",
414
412
  payload,
@@ -421,10 +419,8 @@ export function usePaymentCheckout(
421
419
  },
422
420
  },
423
421
  );
424
-
425
- console.log("RESPONSEhhhhhhh", JSON.stringify(res?.data?.data, null, 2));
426
- // await checkCardPaymentStatus(res?.data?.data?.transactionRef, amount);s
427
- onSuccess?.(transferDetail.transactionReference);
422
+ await checkCardPaymentStatus(res?.data?.data?.transactionRef, amount);
423
+ // onSuccess?.(transferDetail.transactionReference);
428
424
  setLoading(false);
429
425
  return res?.data;
430
426
  } catch (error) {
@@ -433,34 +429,6 @@ export function usePaymentCheckout(
433
429
  }
434
430
  };
435
431
 
436
- // const verifyTransfer = async () => {
437
- // setLoading(true);
438
- // try {
439
- // const res = await axios.get(
440
- // `https://api.fairsurepay.com/api/pub/transfer-status?transactionReference=${transferDetail?.transactionReference}`,
441
- // {
442
- // timeout: 15000,
443
- // headers: {
444
- // Accept: "application/json",
445
- // "Content-Type": "application/json",
446
- // publickey: "LIVE_7AXSCCY8R3HABAN14QP7",
447
- // "User-Agent": "PostmanRuntime/7.36.0",
448
- // },
449
- // },
450
- // );
451
- // console.log("RESPONSE", res?.data?.data);
452
-
453
- // onSuccess?.(transferDetail.transactionReference);
454
-
455
- // return res?.data;
456
- // } catch (error: any) {
457
- // console.log("Failed to Verify transfer", error.response?.data);
458
- // } finally {
459
- // setLoading(false);
460
- // }
461
- // };
462
-
463
- const PENDING_CODES: string[] = ["00", "01", "02", "03"];
464
432
  const verifyTransfer = async () => {
465
433
  setLoading(true);
466
434
  try {
@@ -479,8 +447,6 @@ export function usePaymentCheckout(
479
447
  const result = res?.data?.data;
480
448
  const code = result?.responseCode;
481
449
 
482
- console.log("RESPONSE", JSON.stringify(result, null, 2));
483
-
484
450
  if (code === "00") {
485
451
  onSuccess?.(transferDetail.transactionReference);
486
452
  } else if (PENDING_CODES.includes(code)) {