fairsure-checkout-sdk 1.0.9 → 1.0.11
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/components/PaystackCheckout.d.ts +3 -1
- package/dist/components/PaystackCheckout.js +5 -1
- package/dist/components/USSDPayment.js +0 -1
- package/dist/components/usePaymentCheckout.d.ts +1 -1
- package/dist/components/usePaymentCheckout.js +129 -10
- package/dist/context/CheckoutProvider.js +1 -1
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
- package/src/components/PaystackCheckout.tsx +10 -0
- package/src/components/USSDPayment.tsx +0 -2
- package/src/components/usePaymentCheckout.ts +133 -8
- package/src/context/CheckoutProvider.tsx +2 -0
- package/src/types.ts +2 -0
|
@@ -8,6 +8,8 @@ type CheckoutProps = {
|
|
|
8
8
|
merchantName?: string;
|
|
9
9
|
onClose: () => void;
|
|
10
10
|
onSuccess?: (reference: string) => void;
|
|
11
|
+
onPending?: (result: any) => void;
|
|
12
|
+
onError?: (error: any) => void;
|
|
11
13
|
};
|
|
12
|
-
export default function Checkout({ requestId, customerEmail, customerName, customerPhone, amount, merchantName, onClose, onSuccess, }: CheckoutProps): import("react").JSX.Element;
|
|
14
|
+
export default function Checkout({ requestId, customerEmail, customerName, customerPhone, amount, merchantName, onClose, onSuccess, onPending, onError, }: CheckoutProps): import("react").JSX.Element;
|
|
13
15
|
export {};
|
|
@@ -10,10 +10,14 @@ const paymentMethods = [
|
|
|
10
10
|
{ id: "transfer", name: "Transfer", icon: "business-outline" },
|
|
11
11
|
{ id: "ussd", name: "USSD", icon: "phone-portrait-outline" },
|
|
12
12
|
];
|
|
13
|
-
export default function Checkout({ requestId, customerEmail, customerName, customerPhone, amount, merchantName = "Merchant", onClose, onSuccess, }) {
|
|
13
|
+
export default function Checkout({ requestId, customerEmail, customerName, customerPhone, amount, merchantName = "Merchant", onClose, onSuccess, onPending, onError, }) {
|
|
14
14
|
const checkout = usePaymentCheckout(amount, requestId, customerEmail, customerName, customerPhone, (reference) => {
|
|
15
15
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(reference);
|
|
16
16
|
handleClose();
|
|
17
|
+
}, (result) => {
|
|
18
|
+
onPending === null || onPending === void 0 ? void 0 : onPending(result);
|
|
19
|
+
}, (error) => {
|
|
20
|
+
onError === null || onError === void 0 ? void 0 : onError(error);
|
|
17
21
|
});
|
|
18
22
|
const handleClose = () => {
|
|
19
23
|
checkout.resetForm();
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Ionicons } from "@expo/vector-icons";
|
|
2
2
|
import { ActivityIndicator, ScrollView, StyleSheet, Text, TouchableOpacity, View, } from "react-native";
|
|
3
3
|
export default function USSDPayment({ selectedBank, setSelectedBank, showBankDropdown, ussString, setShowBankDropdown, ussdBanks, loading, copied, handleCopy, }) {
|
|
4
|
-
// console.log("USSSSSS", ussdBanks);
|
|
5
4
|
return (<View>
|
|
6
5
|
<View style={styles.inputGroup}>
|
|
7
6
|
<Text style={styles.inputLabel}>Select Your Bank</Text>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function usePaymentCheckout(amount: number, requestId: string, customerEmail: string, customerName: string, customerPhone: string, onSuccess?: (reference: string) => void): {
|
|
1
|
+
export declare function usePaymentCheckout(amount: number, requestId: string, customerEmail: string, customerName: string, customerPhone: string, onSuccess?: (reference: string) => void, onPending?: (result: any) => void, onError?: (error: any) => void): {
|
|
2
2
|
selectedMethod: string;
|
|
3
3
|
cardNumber: string;
|
|
4
4
|
expiryDate: string;
|
|
@@ -3,7 +3,7 @@ import * as Clipboard from "expo-clipboard";
|
|
|
3
3
|
import { useEffect, useState } from "react";
|
|
4
4
|
import { Dimensions, Platform } from "react-native";
|
|
5
5
|
const { width, height } = Dimensions.get("window");
|
|
6
|
-
export function usePaymentCheckout(amount, requestId, customerEmail, customerName, customerPhone, onSuccess) {
|
|
6
|
+
export function usePaymentCheckout(amount, requestId, customerEmail, customerName, customerPhone, onSuccess, onPending, onError) {
|
|
7
7
|
const [selectedMethod, setSelectedMethod] = useState("card");
|
|
8
8
|
const [cardNumber, setCardNumber] = useState("");
|
|
9
9
|
const [expiryDate, setExpiryDate] = useState("");
|
|
@@ -110,6 +110,7 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
|
|
|
110
110
|
"User-Agent": "PostmanRuntime/7.51.0",
|
|
111
111
|
},
|
|
112
112
|
});
|
|
113
|
+
console.log("USSD GENERATION RES", JSON.stringify(res.data.data, null, 2));
|
|
113
114
|
setUssdBankResponse((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data);
|
|
114
115
|
}
|
|
115
116
|
catch (error) {
|
|
@@ -120,6 +121,7 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
|
|
|
120
121
|
}
|
|
121
122
|
};
|
|
122
123
|
const verifyUssd = async () => {
|
|
124
|
+
var _a, _b, _c, _d;
|
|
123
125
|
try {
|
|
124
126
|
setLoading(true);
|
|
125
127
|
const payload = {
|
|
@@ -134,16 +136,54 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
|
|
|
134
136
|
"User-Agent": "PostmanRuntime/7.51.0",
|
|
135
137
|
},
|
|
136
138
|
});
|
|
137
|
-
|
|
138
|
-
|
|
139
|
+
const result = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data;
|
|
140
|
+
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 : "";
|
|
141
|
+
if (status.includes("pending")) {
|
|
142
|
+
onPending === null || onPending === void 0 ? void 0 : onPending(result);
|
|
143
|
+
}
|
|
144
|
+
else if (status.includes("success") && (result === null || result === void 0 ? void 0 : result.paid)) {
|
|
145
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(result.transactionRef);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
onError === null || onError === void 0 ? void 0 : onError((_d = result === null || result === void 0 ? void 0 : result.message) !== null && _d !== void 0 ? _d : "Payment could not be verified");
|
|
149
|
+
}
|
|
139
150
|
}
|
|
140
151
|
catch (error) {
|
|
141
152
|
console.log("FETCH ERROR:", error);
|
|
153
|
+
onError === null || onError === void 0 ? void 0 : onError(error);
|
|
142
154
|
}
|
|
143
155
|
finally {
|
|
144
156
|
setLoading(false);
|
|
145
157
|
}
|
|
146
158
|
};
|
|
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
|
+
// };
|
|
147
187
|
useEffect(() => {
|
|
148
188
|
if (selectedBank) {
|
|
149
189
|
generateUssdCode();
|
|
@@ -301,12 +341,12 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
|
|
|
301
341
|
}
|
|
302
342
|
};
|
|
303
343
|
const verifyCardPayment = async () => {
|
|
344
|
+
var _a, _b, _c, _d;
|
|
304
345
|
setLoading(true);
|
|
305
346
|
try {
|
|
306
347
|
const payload = {
|
|
307
348
|
transactionId: cardDetails === null || cardDetails === void 0 ? void 0 : cardDetails.transactionRef,
|
|
308
349
|
paymentId: cardDetails === null || cardDetails === void 0 ? void 0 : cardDetails.paymentId,
|
|
309
|
-
// eciFlag: "07",
|
|
310
350
|
otp: otp,
|
|
311
351
|
customerName,
|
|
312
352
|
customerPhone,
|
|
@@ -320,17 +360,85 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
|
|
|
320
360
|
"User-Agent": "PostmanRuntime/7.36.0",
|
|
321
361
|
},
|
|
322
362
|
});
|
|
323
|
-
|
|
324
|
-
|
|
363
|
+
const result = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data;
|
|
364
|
+
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 : "";
|
|
365
|
+
if (status.includes("pending")) {
|
|
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
|
+
}
|
|
325
374
|
return res === null || res === void 0 ? void 0 : res.data;
|
|
326
375
|
}
|
|
327
376
|
catch (error) {
|
|
328
|
-
setLoading(false);
|
|
329
377
|
console.log("ERROR", error);
|
|
378
|
+
onError === null || onError === void 0 ? void 0 : onError(error);
|
|
379
|
+
}
|
|
380
|
+
finally {
|
|
381
|
+
setLoading(false);
|
|
330
382
|
}
|
|
331
383
|
};
|
|
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
|
+
// };
|
|
332
440
|
const verifyTransfer = async () => {
|
|
333
|
-
var _a;
|
|
441
|
+
var _a, _b, _c, _d, _e;
|
|
334
442
|
setLoading(true);
|
|
335
443
|
try {
|
|
336
444
|
const res = await axios.get(`https://api.fairsurepay.com/api/pub/transfer-status?transactionReference=${transferDetail === null || transferDetail === void 0 ? void 0 : transferDetail.transactionReference}`, {
|
|
@@ -342,11 +450,22 @@ export function usePaymentCheckout(amount, requestId, customerEmail, customerNam
|
|
|
342
450
|
"User-Agent": "PostmanRuntime/7.36.0",
|
|
343
451
|
},
|
|
344
452
|
});
|
|
345
|
-
|
|
453
|
+
const result = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data;
|
|
454
|
+
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 : "";
|
|
455
|
+
if (status.includes("pending")) {
|
|
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)) {
|
|
459
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(transferDetail.transactionReference);
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
onError === null || onError === void 0 ? void 0 : onError((_d = result === null || result === void 0 ? void 0 : result.message) !== null && _d !== void 0 ? _d : "Transfer could not be verified");
|
|
463
|
+
}
|
|
346
464
|
return res === null || res === void 0 ? void 0 : res.data;
|
|
347
465
|
}
|
|
348
466
|
catch (error) {
|
|
349
|
-
console.log("Failed to Verify transfer", (
|
|
467
|
+
console.log("Failed to Verify transfer", (_e = error.response) === null || _e === void 0 ? void 0 : _e.data);
|
|
468
|
+
onError === null || onError === void 0 ? void 0 : onError(error);
|
|
350
469
|
}
|
|
351
470
|
finally {
|
|
352
471
|
setLoading(false);
|
|
@@ -10,7 +10,7 @@ export function CheckoutProvider({ children }) {
|
|
|
10
10
|
return (<CheckoutContext.Provider value={{ openCheckout }}>
|
|
11
11
|
{children}
|
|
12
12
|
|
|
13
|
-
{config && (<Checkout amount={config.amount} merchantName={config.merchantName} onSuccess={config.onSuccess} onClose={closeCheckout} requestId={config.requestId} customerEmail={config.customerEmail} customerName={config.customerName} customerPhone={config.customerPhone}/>)}
|
|
13
|
+
{config && (<Checkout amount={config.amount} merchantName={config.merchantName} onSuccess={config.onSuccess} onPending={config.onPending} onError={config.onError} onClose={closeCheckout} requestId={config.requestId} customerEmail={config.customerEmail} customerName={config.customerName} customerPhone={config.customerPhone}/>)}
|
|
14
14
|
</CheckoutContext.Provider>);
|
|
15
15
|
}
|
|
16
16
|
export const useCheckoutContext = () => useContext(CheckoutContext);
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -24,6 +24,8 @@ type CheckoutProps = {
|
|
|
24
24
|
merchantName?: string;
|
|
25
25
|
onClose: () => void;
|
|
26
26
|
onSuccess?: (reference: string) => void;
|
|
27
|
+
onPending?: (result: any) => void;
|
|
28
|
+
onError?: (error: any) => void;
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
const paymentMethods = [
|
|
@@ -41,6 +43,8 @@ export default function Checkout({
|
|
|
41
43
|
merchantName = "Merchant",
|
|
42
44
|
onClose,
|
|
43
45
|
onSuccess,
|
|
46
|
+
onPending,
|
|
47
|
+
onError,
|
|
44
48
|
}: CheckoutProps) {
|
|
45
49
|
const checkout = usePaymentCheckout(
|
|
46
50
|
amount,
|
|
@@ -52,6 +56,12 @@ export default function Checkout({
|
|
|
52
56
|
onSuccess?.(reference);
|
|
53
57
|
handleClose();
|
|
54
58
|
},
|
|
59
|
+
(result) => {
|
|
60
|
+
onPending?.(result);
|
|
61
|
+
},
|
|
62
|
+
(error) => {
|
|
63
|
+
onError?.(error);
|
|
64
|
+
},
|
|
55
65
|
);
|
|
56
66
|
|
|
57
67
|
const handleClose = () => {
|
|
@@ -12,6 +12,8 @@ export function usePaymentCheckout(
|
|
|
12
12
|
customerName: string,
|
|
13
13
|
customerPhone: string,
|
|
14
14
|
onSuccess?: (reference: string) => void,
|
|
15
|
+
onPending?: (result: any) => void,
|
|
16
|
+
onError?: (error: any) => void,
|
|
15
17
|
) {
|
|
16
18
|
const [selectedMethod, setSelectedMethod] = useState("card");
|
|
17
19
|
const [cardNumber, setCardNumber] = useState("");
|
|
@@ -133,6 +135,11 @@ export function usePaymentCheckout(
|
|
|
133
135
|
},
|
|
134
136
|
},
|
|
135
137
|
);
|
|
138
|
+
console.log(
|
|
139
|
+
"USSD GENERATION RES",
|
|
140
|
+
JSON.stringify(res.data.data, null, 2),
|
|
141
|
+
);
|
|
142
|
+
|
|
136
143
|
setUssdBankResponse(res?.data?.data);
|
|
137
144
|
} catch (error) {
|
|
138
145
|
console.log("FETCH ERROR:", error);
|
|
@@ -160,15 +167,54 @@ export function usePaymentCheckout(
|
|
|
160
167
|
},
|
|
161
168
|
},
|
|
162
169
|
);
|
|
163
|
-
|
|
164
|
-
|
|
170
|
+
|
|
171
|
+
const result = res?.data?.data;
|
|
172
|
+
const status = result?.message?.toLowerCase() ?? "";
|
|
173
|
+
if (status.includes("pending")) {
|
|
174
|
+
onPending?.(result);
|
|
175
|
+
} else if (status.includes("success") && result?.paid) {
|
|
176
|
+
onSuccess?.(result.transactionRef);
|
|
177
|
+
} else {
|
|
178
|
+
onError?.(result?.message ?? "Payment could not be verified");
|
|
179
|
+
}
|
|
165
180
|
} catch (error) {
|
|
166
181
|
console.log("FETCH ERROR:", error);
|
|
182
|
+
onError?.(error);
|
|
167
183
|
} finally {
|
|
168
184
|
setLoading(false);
|
|
169
185
|
}
|
|
170
186
|
};
|
|
171
187
|
|
|
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
|
+
|
|
172
218
|
useEffect(() => {
|
|
173
219
|
if (selectedBank) {
|
|
174
220
|
generateUssdCode();
|
|
@@ -340,13 +386,13 @@ export function usePaymentCheckout(
|
|
|
340
386
|
setLoading(false);
|
|
341
387
|
}
|
|
342
388
|
};
|
|
389
|
+
|
|
343
390
|
const verifyCardPayment = async () => {
|
|
344
391
|
setLoading(true);
|
|
345
392
|
try {
|
|
346
393
|
const payload = {
|
|
347
394
|
transactionId: cardDetails?.transactionRef,
|
|
348
395
|
paymentId: cardDetails?.paymentId,
|
|
349
|
-
// eciFlag: "07",
|
|
350
396
|
otp: otp,
|
|
351
397
|
customerName,
|
|
352
398
|
customerPhone,
|
|
@@ -364,14 +410,83 @@ export function usePaymentCheckout(
|
|
|
364
410
|
},
|
|
365
411
|
},
|
|
366
412
|
);
|
|
367
|
-
|
|
368
|
-
|
|
413
|
+
|
|
414
|
+
const result = res?.data?.data;
|
|
415
|
+
const status = result?.message?.toLowerCase() ?? "";
|
|
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
|
+
}
|
|
369
424
|
return res?.data;
|
|
370
425
|
} catch (error) {
|
|
371
|
-
setLoading(false);
|
|
372
426
|
console.log("ERROR", error);
|
|
427
|
+
onError?.(error);
|
|
428
|
+
} finally {
|
|
429
|
+
setLoading(false);
|
|
373
430
|
}
|
|
374
431
|
};
|
|
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
|
+
|
|
375
490
|
const verifyTransfer = async () => {
|
|
376
491
|
setLoading(true);
|
|
377
492
|
try {
|
|
@@ -387,15 +502,25 @@ export function usePaymentCheckout(
|
|
|
387
502
|
},
|
|
388
503
|
},
|
|
389
504
|
);
|
|
390
|
-
|
|
505
|
+
|
|
506
|
+
const result = res?.data?.data;
|
|
507
|
+
const status = result?.message?.toLowerCase() ?? "";
|
|
508
|
+
|
|
509
|
+
if (status.includes("pending")) {
|
|
510
|
+
onPending?.(result);
|
|
511
|
+
} else if (status.includes("success") || result?.paid) {
|
|
512
|
+
onSuccess?.(transferDetail.transactionReference);
|
|
513
|
+
} else {
|
|
514
|
+
onError?.(result?.message ?? "Transfer could not be verified");
|
|
515
|
+
}
|
|
391
516
|
return res?.data;
|
|
392
517
|
} catch (error: any) {
|
|
393
518
|
console.log("Failed to Verify transfer", error.response?.data);
|
|
519
|
+
onError?.(error);
|
|
394
520
|
} finally {
|
|
395
521
|
setLoading(false);
|
|
396
522
|
}
|
|
397
523
|
};
|
|
398
|
-
|
|
399
524
|
const resetForm = () => {
|
|
400
525
|
setCardNumber("");
|
|
401
526
|
setExpiryDate("");
|
|
@@ -23,6 +23,8 @@ export function CheckoutProvider({ children }: { children: React.ReactNode }) {
|
|
|
23
23
|
amount={config.amount}
|
|
24
24
|
merchantName={config.merchantName}
|
|
25
25
|
onSuccess={config.onSuccess}
|
|
26
|
+
onPending={config.onPending}
|
|
27
|
+
onError={config.onError}
|
|
26
28
|
onClose={closeCheckout}
|
|
27
29
|
requestId={config.requestId}
|
|
28
30
|
customerEmail={config.customerEmail}
|
package/src/types.ts
CHANGED