fairsure-checkout-sdk 1.0.11 → 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.
|
@@ -98,7 +98,8 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
|
|
|
98
98
|
setLoading(true);
|
|
99
99
|
const payload = {
|
|
100
100
|
amount,
|
|
101
|
-
requestId,
|
|
101
|
+
reference: requestId,
|
|
102
|
+
isBill: true,
|
|
102
103
|
bankCode: selectedBank === null || selectedBank === void 0 ? void 0 : selectedBank.code,
|
|
103
104
|
};
|
|
104
105
|
try {
|
|
@@ -110,7 +111,6 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
|
|
|
110
111
|
"User-Agent": "PostmanRuntime/7.51.0",
|
|
111
112
|
},
|
|
112
113
|
});
|
|
113
|
-
console.log("USSD GENERATION RES", JSON.stringify(res.data.data, null, 2));
|
|
114
114
|
setUssdBankResponse((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data);
|
|
115
115
|
}
|
|
116
116
|
catch (error) {
|
|
@@ -120,13 +120,14 @@ 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 {
|
|
126
127
|
setLoading(true);
|
|
127
128
|
const payload = {
|
|
128
|
-
codeReference: ussdBankResponse === null || ussdBankResponse === void 0 ? void 0 : ussdBankResponse.codeRef,
|
|
129
129
|
amount: ussdBankResponse === null || ussdBankResponse === void 0 ? void 0 : ussdBankResponse.amount,
|
|
130
|
+
codeReference: ussdBankResponse === null || ussdBankResponse === void 0 ? void 0 : ussdBankResponse.codeRef,
|
|
130
131
|
};
|
|
131
132
|
const res = await axios.post("https://api.fairsurepay.com/api/pub/ussd-status", payload, {
|
|
132
133
|
headers: {
|
|
@@ -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
|
}
|
|
@@ -149,41 +151,12 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
|
|
|
149
151
|
}
|
|
150
152
|
}
|
|
151
153
|
catch (error) {
|
|
152
|
-
console.log("FETCH ERROR:", error);
|
|
153
154
|
onError === null || onError === void 0 ? void 0 : onError(error);
|
|
154
155
|
}
|
|
155
156
|
finally {
|
|
156
157
|
setLoading(false);
|
|
157
158
|
}
|
|
158
159
|
};
|
|
159
|
-
// const verifyUssd = async () => {
|
|
160
|
-
// try {
|
|
161
|
-
// setLoading(true);
|
|
162
|
-
// const payload = {
|
|
163
|
-
// codeReference: ussdBankResponse?.codeRef,
|
|
164
|
-
// amount: ussdBankResponse?.amount,
|
|
165
|
-
// };
|
|
166
|
-
// const res = await axios.post(
|
|
167
|
-
// "https://api.fairsurepay.com/api/pub/ussd-status",
|
|
168
|
-
// payload,
|
|
169
|
-
// {
|
|
170
|
-
// headers: {
|
|
171
|
-
// Accept: "application/json",
|
|
172
|
-
// "Content-Type": "application/json",
|
|
173
|
-
// publickey: "LIVE_7AXSCCY8R3HABAN14QP7",
|
|
174
|
-
// "User-Agent": "PostmanRuntime/7.51.0",
|
|
175
|
-
// },
|
|
176
|
-
// },
|
|
177
|
-
// );
|
|
178
|
-
// console.log("USSD PAYMENT RESPONSE", res);
|
|
179
|
-
// onSuccess?.(cardDetails.transactionRef);
|
|
180
|
-
// setLoading(false);
|
|
181
|
-
// } catch (error) {
|
|
182
|
-
// console.log("FETCH ERROR:", error);
|
|
183
|
-
// } finally {
|
|
184
|
-
// setLoading(false);
|
|
185
|
-
// }
|
|
186
|
-
// };
|
|
187
160
|
useEffect(() => {
|
|
188
161
|
if (selectedBank) {
|
|
189
162
|
generateUssdCode();
|
|
@@ -258,17 +231,46 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
|
|
|
258
231
|
}
|
|
259
232
|
return v;
|
|
260
233
|
};
|
|
234
|
+
const checkCardPaymentStatus = async (transactionRef, amount) => {
|
|
235
|
+
var _a, _b;
|
|
236
|
+
try {
|
|
237
|
+
const res = await axios.get(`https://api.fairsurepay.com/api/pub/verify-transaction?transaction_ref=${transactionRef}&amount=${amount}`, {
|
|
238
|
+
headers: {
|
|
239
|
+
Accept: "application/json",
|
|
240
|
+
"Content-Type": "application/json",
|
|
241
|
+
publickey: "LIVE_7AXSCCY8R3HABAN14QP7",
|
|
242
|
+
"User-Agent": "PostmanRuntime/7.36.0",
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
const result = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data;
|
|
246
|
+
const code = result === null || result === void 0 ? void 0 : result.responseCode;
|
|
247
|
+
console.log("RESULT", result);
|
|
248
|
+
if (code === "00") {
|
|
249
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transactionRef); // ✅ use the card's own ref, not transfer's
|
|
250
|
+
}
|
|
251
|
+
else if (PENDING_CODES.includes(code)) {
|
|
252
|
+
onPending === null || onPending === void 0 ? void 0 : onPending(result);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
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
|
+
}
|
|
257
|
+
return res === null || res === void 0 ? void 0 : res.data;
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
onError === null || onError === void 0 ? void 0 : onError(error);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
261
263
|
const completeCard = async (data) => {
|
|
262
264
|
var _a, _b, _c;
|
|
263
265
|
setLoading(true);
|
|
264
266
|
try {
|
|
265
267
|
const payload = {
|
|
266
|
-
customerId:
|
|
268
|
+
customerId: "08164493471_airtime_fairsurepay_com",
|
|
267
269
|
amount: String(amount),
|
|
268
270
|
transactionRef: requestId,
|
|
269
271
|
currency: "NGN",
|
|
270
|
-
|
|
271
|
-
isBill:
|
|
272
|
+
callBackUrl: "https://checkout.fairsurepay.com/",
|
|
273
|
+
isBill: true,
|
|
272
274
|
data: data,
|
|
273
275
|
deviceInformation: {
|
|
274
276
|
deviceChannel: "MOBILE",
|
|
@@ -341,16 +343,17 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
|
|
|
341
343
|
}
|
|
342
344
|
};
|
|
343
345
|
const verifyCardPayment = async () => {
|
|
344
|
-
var _a, _b
|
|
346
|
+
var _a, _b;
|
|
345
347
|
setLoading(true);
|
|
346
348
|
try {
|
|
347
349
|
const payload = {
|
|
348
350
|
transactionId: cardDetails === null || cardDetails === void 0 ? void 0 : cardDetails.transactionRef,
|
|
349
351
|
paymentId: cardDetails === null || cardDetails === void 0 ? void 0 : cardDetails.paymentId,
|
|
352
|
+
// eciFlag: "07",
|
|
350
353
|
otp: otp,
|
|
351
354
|
customerName,
|
|
352
355
|
customerPhone,
|
|
353
|
-
customerEmail,
|
|
356
|
+
customerEmail: "08164493471_airtime_fairsurepay_com",
|
|
354
357
|
};
|
|
355
358
|
const res = await axios.post("https://api.fairsurepay.com/api/pub/submit-otp", payload, {
|
|
356
359
|
headers: {
|
|
@@ -360,85 +363,18 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
|
|
|
360
363
|
"User-Agent": "PostmanRuntime/7.36.0",
|
|
361
364
|
},
|
|
362
365
|
});
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
onPending === null || onPending === void 0 ? void 0 : onPending(result);
|
|
367
|
-
}
|
|
368
|
-
else if (status.includes("success") || (result === null || result === void 0 ? void 0 : result.paid)) {
|
|
369
|
-
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(cardDetails.transactionRef);
|
|
370
|
-
}
|
|
371
|
-
else {
|
|
372
|
-
onError === null || onError === void 0 ? void 0 : onError((_d = result === null || result === void 0 ? void 0 : result.message) !== null && _d !== void 0 ? _d : "Card payment could not be verified");
|
|
373
|
-
}
|
|
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);
|
|
368
|
+
setLoading(false);
|
|
374
369
|
return res === null || res === void 0 ? void 0 : res.data;
|
|
375
370
|
}
|
|
376
371
|
catch (error) {
|
|
377
|
-
console.log("ERROR", error);
|
|
378
|
-
onError === null || onError === void 0 ? void 0 : onError(error);
|
|
379
|
-
}
|
|
380
|
-
finally {
|
|
381
372
|
setLoading(false);
|
|
373
|
+
console.log("ERROR", error);
|
|
382
374
|
}
|
|
383
375
|
};
|
|
384
|
-
// const verifyCardPayment = async () => {
|
|
385
|
-
// setLoading(true);
|
|
386
|
-
// try {
|
|
387
|
-
// const payload = {
|
|
388
|
-
// transactionId: cardDetails?.transactionRef,
|
|
389
|
-
// paymentId: cardDetails?.paymentId,
|
|
390
|
-
// // eciFlag: "07",
|
|
391
|
-
// otp: otp,
|
|
392
|
-
// customerName,
|
|
393
|
-
// customerPhone,
|
|
394
|
-
// customerEmail,
|
|
395
|
-
// };
|
|
396
|
-
// const res = await axios.post(
|
|
397
|
-
// "https://api.fairsurepay.com/api/pub/submit-otp",
|
|
398
|
-
// payload,
|
|
399
|
-
// {
|
|
400
|
-
// headers: {
|
|
401
|
-
// Accept: "application/json",
|
|
402
|
-
// "Content-Type": "application/json",
|
|
403
|
-
// publickey: "LIVE_7AXSCCY8R3HABAN14QP7",
|
|
404
|
-
// "User-Agent": "PostmanRuntime/7.36.0",
|
|
405
|
-
// },
|
|
406
|
-
// },
|
|
407
|
-
// );
|
|
408
|
-
// onSuccess?.(transferDetail.transactionReference);
|
|
409
|
-
// setLoading(false);
|
|
410
|
-
// return res?.data;
|
|
411
|
-
// } catch (error) {
|
|
412
|
-
// setLoading(false);
|
|
413
|
-
// console.log("ERROR", error);
|
|
414
|
-
// }
|
|
415
|
-
// };
|
|
416
|
-
// const verifyTransfer = async () => {
|
|
417
|
-
// setLoading(true);
|
|
418
|
-
// try {
|
|
419
|
-
// const res = await axios.get(
|
|
420
|
-
// `https://api.fairsurepay.com/api/pub/transfer-status?transactionReference=${transferDetail?.transactionReference}`,
|
|
421
|
-
// {
|
|
422
|
-
// timeout: 15000,
|
|
423
|
-
// headers: {
|
|
424
|
-
// Accept: "application/json",
|
|
425
|
-
// "Content-Type": "application/json",
|
|
426
|
-
// publickey: "LIVE_7AXSCCY8R3HABAN14QP7",
|
|
427
|
-
// "User-Agent": "PostmanRuntime/7.36.0",
|
|
428
|
-
// },
|
|
429
|
-
// },
|
|
430
|
-
// );
|
|
431
|
-
// console.log("RESPONSE", res);
|
|
432
|
-
// onSuccess?.(transferDetail.transactionReference);
|
|
433
|
-
// return res?.data;
|
|
434
|
-
// } catch (error: any) {
|
|
435
|
-
// console.log("Failed to Verify transfer", error.response?.data);
|
|
436
|
-
// } finally {
|
|
437
|
-
// setLoading(false);
|
|
438
|
-
// }
|
|
439
|
-
// };
|
|
440
376
|
const verifyTransfer = async () => {
|
|
441
|
-
var _a, _b, _c
|
|
377
|
+
var _a, _b, _c;
|
|
442
378
|
setLoading(true);
|
|
443
379
|
try {
|
|
444
380
|
const res = await axios.get(`https://api.fairsurepay.com/api/pub/transfer-status?transactionReference=${transferDetail === null || transferDetail === void 0 ? void 0 : transferDetail.transactionReference}`, {
|
|
@@ -447,24 +383,24 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
|
|
|
447
383
|
Accept: "application/json",
|
|
448
384
|
"Content-Type": "application/json",
|
|
449
385
|
publickey: "LIVE_7AXSCCY8R3HABAN14QP7",
|
|
450
|
-
"User-Agent": "PostmanRuntime/7.36.0",
|
|
451
386
|
},
|
|
452
387
|
});
|
|
453
388
|
const result = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data;
|
|
454
|
-
const
|
|
455
|
-
if (
|
|
456
|
-
onPending === null || onPending === void 0 ? void 0 : onPending(result);
|
|
457
|
-
}
|
|
458
|
-
else if (status.includes("success") || (result === null || result === void 0 ? void 0 : result.paid)) {
|
|
389
|
+
const code = result === null || result === void 0 ? void 0 : result.responseCode;
|
|
390
|
+
if (code === "00") {
|
|
459
391
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transferDetail.transactionReference);
|
|
460
392
|
}
|
|
393
|
+
else if (PENDING_CODES.includes(code)) {
|
|
394
|
+
onPending === null || onPending === void 0 ? void 0 : onPending(result);
|
|
395
|
+
}
|
|
461
396
|
else {
|
|
462
|
-
|
|
397
|
+
// includes "Z0" (Transaction not Completed) until confirmed otherwise
|
|
398
|
+
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");
|
|
463
399
|
}
|
|
464
400
|
return res === null || res === void 0 ? void 0 : res.data;
|
|
465
401
|
}
|
|
466
402
|
catch (error) {
|
|
467
|
-
console.log("Failed to Verify transfer", (
|
|
403
|
+
console.log("Failed to Verify transfer", (_c = error.response) === null || _c === void 0 ? void 0 : _c.data);
|
|
468
404
|
onError === null || onError === void 0 ? void 0 : onError(error);
|
|
469
405
|
}
|
|
470
406
|
finally {
|
package/package.json
CHANGED
|
@@ -118,7 +118,8 @@ export function usePaymentCheckout(
|
|
|
118
118
|
setLoading(true);
|
|
119
119
|
const payload = {
|
|
120
120
|
amount,
|
|
121
|
-
requestId,
|
|
121
|
+
reference: requestId,
|
|
122
|
+
isBill: true,
|
|
122
123
|
bankCode: selectedBank?.code,
|
|
123
124
|
};
|
|
124
125
|
|
|
@@ -135,11 +136,6 @@ export function usePaymentCheckout(
|
|
|
135
136
|
},
|
|
136
137
|
},
|
|
137
138
|
);
|
|
138
|
-
console.log(
|
|
139
|
-
"USSD GENERATION RES",
|
|
140
|
-
JSON.stringify(res.data.data, null, 2),
|
|
141
|
-
);
|
|
142
|
-
|
|
143
139
|
setUssdBankResponse(res?.data?.data);
|
|
144
140
|
} catch (error) {
|
|
145
141
|
console.log("FETCH ERROR:", error);
|
|
@@ -148,13 +144,16 @@ export function usePaymentCheckout(
|
|
|
148
144
|
}
|
|
149
145
|
};
|
|
150
146
|
|
|
147
|
+
const PENDING_CODES: string[] = ["01", "02", "03"];
|
|
148
|
+
|
|
151
149
|
const verifyUssd = async () => {
|
|
152
150
|
try {
|
|
153
151
|
setLoading(true);
|
|
154
152
|
const payload = {
|
|
155
|
-
codeReference: ussdBankResponse?.codeRef,
|
|
156
153
|
amount: ussdBankResponse?.amount,
|
|
154
|
+
codeReference: ussdBankResponse?.codeRef,
|
|
157
155
|
};
|
|
156
|
+
|
|
158
157
|
const res = await axios.post(
|
|
159
158
|
"https://api.fairsurepay.com/api/pub/ussd-status",
|
|
160
159
|
payload,
|
|
@@ -169,7 +168,10 @@ export function usePaymentCheckout(
|
|
|
169
168
|
);
|
|
170
169
|
|
|
171
170
|
const result = res?.data?.data;
|
|
171
|
+
|
|
172
172
|
const status = result?.message?.toLowerCase() ?? "";
|
|
173
|
+
console.log("statushhh", status);
|
|
174
|
+
|
|
173
175
|
if (status.includes("pending")) {
|
|
174
176
|
onPending?.(result);
|
|
175
177
|
} else if (status.includes("success") && result?.paid) {
|
|
@@ -178,43 +180,12 @@ export function usePaymentCheckout(
|
|
|
178
180
|
onError?.(result?.message ?? "Payment could not be verified");
|
|
179
181
|
}
|
|
180
182
|
} catch (error) {
|
|
181
|
-
console.log("FETCH ERROR:", error);
|
|
182
183
|
onError?.(error);
|
|
183
184
|
} finally {
|
|
184
185
|
setLoading(false);
|
|
185
186
|
}
|
|
186
187
|
};
|
|
187
188
|
|
|
188
|
-
// const verifyUssd = async () => {
|
|
189
|
-
// try {
|
|
190
|
-
// setLoading(true);
|
|
191
|
-
// const payload = {
|
|
192
|
-
// codeReference: ussdBankResponse?.codeRef,
|
|
193
|
-
// amount: ussdBankResponse?.amount,
|
|
194
|
-
// };
|
|
195
|
-
// const res = await axios.post(
|
|
196
|
-
// "https://api.fairsurepay.com/api/pub/ussd-status",
|
|
197
|
-
// payload,
|
|
198
|
-
// {
|
|
199
|
-
// headers: {
|
|
200
|
-
// Accept: "application/json",
|
|
201
|
-
// "Content-Type": "application/json",
|
|
202
|
-
// publickey: "LIVE_7AXSCCY8R3HABAN14QP7",
|
|
203
|
-
// "User-Agent": "PostmanRuntime/7.51.0",
|
|
204
|
-
// },
|
|
205
|
-
// },
|
|
206
|
-
// );
|
|
207
|
-
// console.log("USSD PAYMENT RESPONSE", res);
|
|
208
|
-
|
|
209
|
-
// onSuccess?.(cardDetails.transactionRef);
|
|
210
|
-
// setLoading(false);
|
|
211
|
-
// } catch (error) {
|
|
212
|
-
// console.log("FETCH ERROR:", error);
|
|
213
|
-
// } finally {
|
|
214
|
-
// setLoading(false);
|
|
215
|
-
// }
|
|
216
|
-
// };
|
|
217
|
-
|
|
218
189
|
useEffect(() => {
|
|
219
190
|
if (selectedBank) {
|
|
220
191
|
generateUssdCode();
|
|
@@ -300,16 +271,51 @@ export function usePaymentCheckout(
|
|
|
300
271
|
return v;
|
|
301
272
|
};
|
|
302
273
|
|
|
274
|
+
const checkCardPaymentStatus = async (
|
|
275
|
+
transactionRef: string,
|
|
276
|
+
amount: number,
|
|
277
|
+
) => {
|
|
278
|
+
try {
|
|
279
|
+
const res = await axios.get(
|
|
280
|
+
`https://api.fairsurepay.com/api/pub/verify-transaction?transaction_ref=${transactionRef}&amount=${amount}`,
|
|
281
|
+
{
|
|
282
|
+
headers: {
|
|
283
|
+
Accept: "application/json",
|
|
284
|
+
"Content-Type": "application/json",
|
|
285
|
+
publickey: "LIVE_7AXSCCY8R3HABAN14QP7",
|
|
286
|
+
"User-Agent": "PostmanRuntime/7.36.0",
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
);
|
|
290
|
+
const result = res?.data?.data;
|
|
291
|
+
const code = result?.responseCode;
|
|
292
|
+
console.log("RESULT", result);
|
|
293
|
+
|
|
294
|
+
if (code === "00") {
|
|
295
|
+
onSuccess?.(transactionRef); // ✅ use the card's own ref, not transfer's
|
|
296
|
+
} else if (PENDING_CODES.includes(code)) {
|
|
297
|
+
onPending?.(result);
|
|
298
|
+
} else {
|
|
299
|
+
onError?.(
|
|
300
|
+
result?.responseDescription ?? "Transfer could not be verified",
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
return res?.data;
|
|
304
|
+
} catch (error) {
|
|
305
|
+
onError?.(error);
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
|
|
303
309
|
const completeCard = async (data: string) => {
|
|
304
310
|
setLoading(true);
|
|
305
311
|
try {
|
|
306
312
|
const payload = {
|
|
307
|
-
customerId:
|
|
313
|
+
customerId: "08164493471_airtime_fairsurepay_com",
|
|
308
314
|
amount: String(amount),
|
|
309
315
|
transactionRef: requestId,
|
|
310
316
|
currency: "NGN",
|
|
311
|
-
|
|
312
|
-
isBill:
|
|
317
|
+
callBackUrl: "https://checkout.fairsurepay.com/",
|
|
318
|
+
isBill: true,
|
|
313
319
|
data: data,
|
|
314
320
|
deviceInformation: {
|
|
315
321
|
deviceChannel: "MOBILE",
|
|
@@ -323,6 +329,7 @@ export function usePaymentCheckout(
|
|
|
323
329
|
httpBrowserTimeDifference: `${-new Date().getTimezoneOffset()}`,
|
|
324
330
|
},
|
|
325
331
|
};
|
|
332
|
+
|
|
326
333
|
const res = await axios.post(
|
|
327
334
|
"https://api.fairsurepay.com/api/pub/card-payment",
|
|
328
335
|
payload,
|
|
@@ -373,6 +380,7 @@ export function usePaymentCheckout(
|
|
|
373
380
|
},
|
|
374
381
|
},
|
|
375
382
|
);
|
|
383
|
+
|
|
376
384
|
const data = await completeCard(res?.data?.data);
|
|
377
385
|
setMessage(data?.data?.message);
|
|
378
386
|
setCardDetails(data?.data);
|
|
@@ -393,10 +401,11 @@ export function usePaymentCheckout(
|
|
|
393
401
|
const payload = {
|
|
394
402
|
transactionId: cardDetails?.transactionRef,
|
|
395
403
|
paymentId: cardDetails?.paymentId,
|
|
404
|
+
// eciFlag: "07",
|
|
396
405
|
otp: otp,
|
|
397
406
|
customerName,
|
|
398
407
|
customerPhone,
|
|
399
|
-
customerEmail,
|
|
408
|
+
customerEmail: "08164493471_airtime_fairsurepay_com",
|
|
400
409
|
};
|
|
401
410
|
const res = await axios.post(
|
|
402
411
|
"https://api.fairsurepay.com/api/pub/submit-otp",
|
|
@@ -410,82 +419,15 @@ export function usePaymentCheckout(
|
|
|
410
419
|
},
|
|
411
420
|
},
|
|
412
421
|
);
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
if (status.includes("pending")) {
|
|
418
|
-
onPending?.(result);
|
|
419
|
-
} else if (status.includes("success") || result?.paid) {
|
|
420
|
-
onSuccess?.(cardDetails.transactionRef);
|
|
421
|
-
} else {
|
|
422
|
-
onError?.(result?.message ?? "Card payment could not be verified");
|
|
423
|
-
}
|
|
422
|
+
await checkCardPaymentStatus(res?.data?.data?.transactionRef, amount);
|
|
423
|
+
// onSuccess?.(transferDetail.transactionReference);
|
|
424
|
+
setLoading(false);
|
|
424
425
|
return res?.data;
|
|
425
426
|
} catch (error) {
|
|
426
|
-
console.log("ERROR", error);
|
|
427
|
-
onError?.(error);
|
|
428
|
-
} finally {
|
|
429
427
|
setLoading(false);
|
|
428
|
+
console.log("ERROR", error);
|
|
430
429
|
}
|
|
431
430
|
};
|
|
432
|
-
// const verifyCardPayment = async () => {
|
|
433
|
-
// setLoading(true);
|
|
434
|
-
// try {
|
|
435
|
-
// const payload = {
|
|
436
|
-
// transactionId: cardDetails?.transactionRef,
|
|
437
|
-
// paymentId: cardDetails?.paymentId,
|
|
438
|
-
// // eciFlag: "07",
|
|
439
|
-
// otp: otp,
|
|
440
|
-
// customerName,
|
|
441
|
-
// customerPhone,
|
|
442
|
-
// customerEmail,
|
|
443
|
-
// };
|
|
444
|
-
// const res = await axios.post(
|
|
445
|
-
// "https://api.fairsurepay.com/api/pub/submit-otp",
|
|
446
|
-
// payload,
|
|
447
|
-
// {
|
|
448
|
-
// headers: {
|
|
449
|
-
// Accept: "application/json",
|
|
450
|
-
// "Content-Type": "application/json",
|
|
451
|
-
// publickey: "LIVE_7AXSCCY8R3HABAN14QP7",
|
|
452
|
-
// "User-Agent": "PostmanRuntime/7.36.0",
|
|
453
|
-
// },
|
|
454
|
-
// },
|
|
455
|
-
// );
|
|
456
|
-
// onSuccess?.(transferDetail.transactionReference);
|
|
457
|
-
// setLoading(false);
|
|
458
|
-
// return res?.data;
|
|
459
|
-
// } catch (error) {
|
|
460
|
-
// setLoading(false);
|
|
461
|
-
// console.log("ERROR", error);
|
|
462
|
-
// }
|
|
463
|
-
// };
|
|
464
|
-
// const verifyTransfer = async () => {
|
|
465
|
-
// setLoading(true);
|
|
466
|
-
// try {
|
|
467
|
-
// const res = await axios.get(
|
|
468
|
-
// `https://api.fairsurepay.com/api/pub/transfer-status?transactionReference=${transferDetail?.transactionReference}`,
|
|
469
|
-
// {
|
|
470
|
-
// timeout: 15000,
|
|
471
|
-
// headers: {
|
|
472
|
-
// Accept: "application/json",
|
|
473
|
-
// "Content-Type": "application/json",
|
|
474
|
-
// publickey: "LIVE_7AXSCCY8R3HABAN14QP7",
|
|
475
|
-
// "User-Agent": "PostmanRuntime/7.36.0",
|
|
476
|
-
// },
|
|
477
|
-
// },
|
|
478
|
-
// );
|
|
479
|
-
// console.log("RESPONSE", res);
|
|
480
|
-
|
|
481
|
-
// onSuccess?.(transferDetail.transactionReference);
|
|
482
|
-
// return res?.data;
|
|
483
|
-
// } catch (error: any) {
|
|
484
|
-
// console.log("Failed to Verify transfer", error.response?.data);
|
|
485
|
-
// } finally {
|
|
486
|
-
// setLoading(false);
|
|
487
|
-
// }
|
|
488
|
-
// };
|
|
489
431
|
|
|
490
432
|
const verifyTransfer = async () => {
|
|
491
433
|
setLoading(true);
|
|
@@ -498,20 +440,22 @@ export function usePaymentCheckout(
|
|
|
498
440
|
Accept: "application/json",
|
|
499
441
|
"Content-Type": "application/json",
|
|
500
442
|
publickey: "LIVE_7AXSCCY8R3HABAN14QP7",
|
|
501
|
-
"User-Agent": "PostmanRuntime/7.36.0",
|
|
502
443
|
},
|
|
503
444
|
},
|
|
504
445
|
);
|
|
505
446
|
|
|
506
447
|
const result = res?.data?.data;
|
|
507
|
-
const
|
|
448
|
+
const code = result?.responseCode;
|
|
508
449
|
|
|
509
|
-
if (
|
|
510
|
-
onPending?.(result);
|
|
511
|
-
} else if (status.includes("success") || result?.paid) {
|
|
450
|
+
if (code === "00") {
|
|
512
451
|
onSuccess?.(transferDetail.transactionReference);
|
|
452
|
+
} else if (PENDING_CODES.includes(code)) {
|
|
453
|
+
onPending?.(result);
|
|
513
454
|
} else {
|
|
514
|
-
|
|
455
|
+
// includes "Z0" (Transaction not Completed) until confirmed otherwise
|
|
456
|
+
onError?.(
|
|
457
|
+
result?.responseDescription ?? "Transfer could not be verified",
|
|
458
|
+
);
|
|
515
459
|
}
|
|
516
460
|
return res?.data;
|
|
517
461
|
} catch (error: any) {
|
|
@@ -521,6 +465,7 @@ export function usePaymentCheckout(
|
|
|
521
465
|
setLoading(false);
|
|
522
466
|
}
|
|
523
467
|
};
|
|
468
|
+
|
|
524
469
|
const resetForm = () => {
|
|
525
470
|
setCardNumber("");
|
|
526
471
|
setExpiryDate("");
|