|
|
|
@@ -7,25 +7,32 @@ import usersService from "../../../services/UsersService";
|
|
|
|
|
import { tableReload } from "../../../store/TableReloads";
|
|
|
|
|
import LoadingSpinner from "../../Spinners/LoadingSpinner";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function ThePaymentText({ value, type }) {
|
|
|
|
|
const cardDetails = value;
|
|
|
|
|
value.description =
|
|
|
|
|
type === "new"
|
|
|
|
|
? cardDetails.cardNum[0] === "4"
|
|
|
|
|
? "Visa"
|
|
|
|
|
: cardDetails.cardNum[0] == "5"
|
|
|
|
|
? "Master"
|
|
|
|
|
: "ATM"
|
|
|
|
|
: value.description;
|
|
|
|
|
value.digits = type === "new" ? cardDetails.cardNum.slice(-4) : value.digits;
|
|
|
|
|
const { cardNum } = value;
|
|
|
|
|
let description = value.description;
|
|
|
|
|
let digits = value.digits;
|
|
|
|
|
|
|
|
|
|
if (type === "new") {
|
|
|
|
|
const firstDigit = cardNum[0];
|
|
|
|
|
if (firstDigit === "4") {
|
|
|
|
|
description = "Visa";
|
|
|
|
|
} else if (firstDigit === "5") {
|
|
|
|
|
description = "Master";
|
|
|
|
|
} else {
|
|
|
|
|
description = "ATM";
|
|
|
|
|
}
|
|
|
|
|
digits = cardNum.slice(-4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="my-2 flex items-center gap-5">
|
|
|
|
|
<div className="card-details flex items-center gap-3">
|
|
|
|
|
<h1 className="text-xl font-bold text-dark-gray dark:text-white tracking-tighter my-1 space-x-1">
|
|
|
|
|
{value.description} Card
|
|
|
|
|
<h1 className="text-xl font-normal text-dark-gray dark:text-white tracking-tighter my-1 space-x-1">
|
|
|
|
|
{description} Card
|
|
|
|
|
</h1>
|
|
|
|
|
<p className="text-base font-bold text-dark-gray dark:text-white tracking-wide">
|
|
|
|
|
Bank **************{value.digits}
|
|
|
|
|
<p className="text-xl font-normal text-dark-gray dark:text-white tracking-wide">
|
|
|
|
|
Bank **************{digits}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
@@ -41,7 +48,7 @@ function AmountSection({ currency, amount, country }) {
|
|
|
|
|
<h1 className="text-xl font-bold text-dark-gray dark:text-white tracking-tighter my-1">
|
|
|
|
|
Amount({currency})
|
|
|
|
|
</h1>
|
|
|
|
|
<span className="text-xl font-bold text-dark-gray dark:text-white tracking-tighter my-1">
|
|
|
|
|
<span className="text-xl font-normal text-dark-gray dark:text-white tracking-tighter my-1">
|
|
|
|
|
{formattedAmount}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
@@ -59,7 +66,7 @@ function TransactionFeeSection({ currency, fee, country }) {
|
|
|
|
|
<h1 className="text-xl font-bold text-dark-gray dark:text-white tracking-tighter my-1">
|
|
|
|
|
Transaction Fee
|
|
|
|
|
</h1>
|
|
|
|
|
<span className="text-xl font-bold text-dark-gray dark:text-white tracking-tighter my-1">
|
|
|
|
|
<span className="text-xl font-normal text-dark-gray dark:text-white tracking-tighter my-1">
|
|
|
|
|
{formattedFee}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
@@ -78,7 +85,7 @@ function TotalSection({ currency, amount, fee, country }) {
|
|
|
|
|
<h1 className="text-xl font-bold text-dark-gray dark:text-white tracking-tighter my-1">
|
|
|
|
|
Total
|
|
|
|
|
</h1>
|
|
|
|
|
<span className="text-xl font-bold text-dark-gray dark:text-white tracking-tighter my-1">
|
|
|
|
|
<span className="text-xl font-normal text-dark-gray dark:text-white tracking-tighter my-1">
|
|
|
|
|
{formattedTotal}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
@@ -127,7 +134,7 @@ function ConfirmAddFund({
|
|
|
|
|
logo: "https://www.wrenchboard.com/assets/images/wrench-500-500-icon.png",
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
//debugger;
|
|
|
|
|
|
|
|
|
|
const fwConfig = {
|
|
|
|
|
...config,
|
|
|
|
|
text: "Proceed",
|
|
|
|
@@ -188,27 +195,40 @@ function ConfirmAddFund({
|
|
|
|
|
|
|
|
|
|
const debouncedSuccessPayment = debounce(onSuccessPayment, 5000);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handles the process of making a payment using a previously saved card.
|
|
|
|
|
* Updates the state to show a loader while the payment is being processed,
|
|
|
|
|
* sends a request to the server to make the payment, and updates the state with the response.
|
|
|
|
|
* If the payment is successful, it also dispatches an action to reload the wallet table.
|
|
|
|
|
*/
|
|
|
|
|
const handlePrevCard = async () => {
|
|
|
|
|
const { amount, credit_reference, currency } = __confirmData;
|
|
|
|
|
const { card_uid } = __confirmCardDetails;
|
|
|
|
|
|
|
|
|
|
const reqData = {
|
|
|
|
|
amount: amount * 100,
|
|
|
|
|
card_uid,
|
|
|
|
|
credit_reference,
|
|
|
|
|
currency,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// Show loader while the payment is being processed
|
|
|
|
|
setConfirmCredit((prev) => ({
|
|
|
|
|
...prev,
|
|
|
|
|
show: {
|
|
|
|
|
acceptConfirm: { loader: true },
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
// Extract necessary data from confirmCredit and confirmCardDetails objects
|
|
|
|
|
const { amount, credit_reference, currency } = __confirmData;
|
|
|
|
|
const { card_uid } = __confirmCardDetails;
|
|
|
|
|
|
|
|
|
|
// Create request data object with required parameters for making the payment
|
|
|
|
|
const reqData = {
|
|
|
|
|
amount: amount * 100,
|
|
|
|
|
card_uid,
|
|
|
|
|
credit_reference,
|
|
|
|
|
currency,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Send request to server to make the payment using getPaidPrevCard method of usersService
|
|
|
|
|
const res = await apiURL.getPaidPrevCard(reqData);
|
|
|
|
|
const _response = res.data;
|
|
|
|
|
if (res.data.internal_return < 0) {
|
|
|
|
|
|
|
|
|
|
// If internal_return value in the response is less than 0, hide the loader and return
|
|
|
|
|
if (_response.internal_return < 0) {
|
|
|
|
|
setConfirmCredit((prev) => ({
|
|
|
|
|
...prev,
|
|
|
|
|
show: {
|
|
|
|
@@ -218,6 +238,7 @@ function ConfirmAddFund({
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update state to show the acceptConfirm state and the response data
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
setConfirmCredit((prev) => ({
|
|
|
|
|
...prev,
|
|
|
|
@@ -227,9 +248,11 @@ function ConfirmAddFund({
|
|
|
|
|
},
|
|
|
|
|
data: _response,
|
|
|
|
|
}));
|
|
|
|
|
// Dispatch an action to reload the wallet table
|
|
|
|
|
dispatch(tableReload({ type: "WALLETTABLE" }));
|
|
|
|
|
}, 1500);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
// Handle error and hide the loader
|
|
|
|
|
setConfirmCredit((prev) => ({
|
|
|
|
|
...prev,
|
|
|
|
|
show: {
|
|
|
|
@@ -240,45 +263,44 @@ function ConfirmAddFund({
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handles the payment process when a new card is used.
|
|
|
|
|
* @async
|
|
|
|
|
*/
|
|
|
|
|
const handleNewCard = async () => {
|
|
|
|
|
const { amount, credit_reference, uid } = __confirmData;
|
|
|
|
|
const { address, cardNum, cvv, expirationMonth, expirationYear } =
|
|
|
|
|
__confirmCardDetails;
|
|
|
|
|
|
|
|
|
|
const reqData = {
|
|
|
|
|
amount: amount * 100,
|
|
|
|
|
cardnumber: cardNum.replace(/\s/g, ""),
|
|
|
|
|
credit_reference,
|
|
|
|
|
cvc: cvv,
|
|
|
|
|
description: address,
|
|
|
|
|
exp_month: expirationMonth,
|
|
|
|
|
exp_year: expirationYear,
|
|
|
|
|
paymenttype: 100,
|
|
|
|
|
uid,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// Extract necessary data from __confirmData and __confirmCardDetails
|
|
|
|
|
const { amount, credit_reference, uid } = __confirmData;
|
|
|
|
|
const { address, cardNum, cvv, expirationMonth, expirationYear } = __confirmCardDetails;
|
|
|
|
|
|
|
|
|
|
// Set loading state to indicate payment is being processed
|
|
|
|
|
setConfirmCredit((prev) => ({
|
|
|
|
|
...prev,
|
|
|
|
|
show: {
|
|
|
|
|
acceptConfirm: { loader: true },
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
// Prepare request data
|
|
|
|
|
const reqData = {
|
|
|
|
|
amount: amount * 100,
|
|
|
|
|
cardnumber: cardNum.replace(/\s/g, ""),
|
|
|
|
|
credit_reference,
|
|
|
|
|
cvc: cvv,
|
|
|
|
|
description: address,
|
|
|
|
|
exp_month: expirationMonth,
|
|
|
|
|
exp_year: expirationYear,
|
|
|
|
|
paymenttype: 100,
|
|
|
|
|
uid,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Send request to server to process payment
|
|
|
|
|
const res = await apiURL.getPaidNewCard(reqData);
|
|
|
|
|
const _response = res.data;
|
|
|
|
|
if (res.data.internal_return < 0) {
|
|
|
|
|
setConfirmCredit((prev) => ({
|
|
|
|
|
...prev,
|
|
|
|
|
show: {
|
|
|
|
|
awaitConfirm: { loader: false, state: false },
|
|
|
|
|
acceptConfirm: { loader: false, state: true },
|
|
|
|
|
},
|
|
|
|
|
data: _response,
|
|
|
|
|
}));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
// Handle response from server
|
|
|
|
|
if (res.data.internal_return < 0) {
|
|
|
|
|
// Payment could not be completed
|
|
|
|
|
setConfirmCredit((prev) => ({
|
|
|
|
|
...prev,
|
|
|
|
|
show: {
|
|
|
|
@@ -287,9 +309,23 @@ function ConfirmAddFund({
|
|
|
|
|
},
|
|
|
|
|
data: _response,
|
|
|
|
|
}));
|
|
|
|
|
dispatch(tableReload({ type: "WALLETTABLE" }));
|
|
|
|
|
}, 1500);
|
|
|
|
|
} else {
|
|
|
|
|
// Payment was successful
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
setConfirmCredit((prev) => ({
|
|
|
|
|
...prev,
|
|
|
|
|
show: {
|
|
|
|
|
awaitConfirm: { loader: false, state: false },
|
|
|
|
|
acceptConfirm: { loader: false, state: true },
|
|
|
|
|
},
|
|
|
|
|
data: _response,
|
|
|
|
|
}));
|
|
|
|
|
console.log("Show meeeeeeeeee");
|
|
|
|
|
dispatch(tableReload({ type: "WALLETTABLE" }));
|
|
|
|
|
}, 1500);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
// Handle error during payment process
|
|
|
|
|
setConfirmCredit((prev) => ({
|
|
|
|
|
...prev,
|
|
|
|
|
show: {
|
|
|
|
@@ -362,7 +398,7 @@ function ConfirmAddFund({
|
|
|
|
|
<h1 className="text-xl font-bold text-dark-gray dark:text-white tracking-tighter my-1">
|
|
|
|
|
Reference No
|
|
|
|
|
</h1>
|
|
|
|
|
<span className="text-xl font-bold text-dark-gray dark:text-white tracking-tighter my-1">
|
|
|
|
|
<span className="text-xl font-normal text-dark-gray dark:text-white tracking-tighter my-1">
|
|
|
|
|
{__confirmData?.credit_reference}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|