affiliate payment
This commit is contained in:
parent
545c49b8c2
commit
5ee536700a
@ -1,5 +1,12 @@
|
||||
import axios from "axios";
|
||||
import { AffiliateModel } from "./AffiliateModel.js";
|
||||
|
||||
import Razorpay from "razorpay";
|
||||
const razorpay = new Razorpay({
|
||||
key_id: process.env.RAZERPAY_KEY_ID,
|
||||
key_secret: process.env.RAZERPAY_SECRET_KEY,
|
||||
});
|
||||
|
||||
// -----------------------------AFFILIATE & COUPONS ARE HARDLY BINDED DATA--------------------------------------------------------
|
||||
//Create Affiliate
|
||||
export const createAffiliate = async (req, res) => {
|
||||
@ -289,3 +296,126 @@ export const affiliatePayHistory = async (req, res) => {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Affiliate PayOut
|
||||
export const affiliatPayOut = async (req, res) => {
|
||||
const {
|
||||
amountToPay,
|
||||
nameAsBank,
|
||||
accountNo,
|
||||
ifsc,
|
||||
bankName,
|
||||
branchName,
|
||||
affiliateDiscountAmt,
|
||||
} = req.body;
|
||||
|
||||
if (!amountToPay)
|
||||
return res.status(400).json({ message: "amountToPay is not empty!" });
|
||||
if (!nameAsBank)
|
||||
return res
|
||||
.status(404)
|
||||
.json({ message: "please Enter Your name As Bank PassBook!" });
|
||||
if (!accountNo)
|
||||
return res.status(404).json({ message: "please Enter accountNo!" });
|
||||
if (!nameAsBank)
|
||||
return res.status(404).json({ message: "please Enter nameAsBank!" });
|
||||
if (!ifsc)
|
||||
return res.status(404).json({ message: "please provide Bank ifsc!" });
|
||||
if (!bankName)
|
||||
return res.status(404).json({ message: "please provide Bank Name!" });
|
||||
if (!branchName)
|
||||
return res
|
||||
.status(404)
|
||||
.json({ message: "please provide Bank branch Name!" });
|
||||
|
||||
const amount = 50000; // Amount in paise (50000 paise = Rs 500)
|
||||
const currency = "INR";
|
||||
const accountNumber = "XXXXXXXXXXXX";
|
||||
const accountHolderName = "John Doe";
|
||||
const IFSCCode = "XXXXXXX";
|
||||
// 068105500883
|
||||
// ICIC0000681
|
||||
// const options = {
|
||||
// // account_number: Number(accountNo),
|
||||
// // fund_account_id: "fund_account_id", // Get this from Razorpay Dashboard
|
||||
// // amount,
|
||||
// // currency: "INR",
|
||||
// // mode: "IMPS",
|
||||
// // purpose: "payout",
|
||||
// // recipient_contact: "+91XXXXXXXXXX", // Recipient contact number
|
||||
// // recipient_email: "recipient@example.com", // Recipient email address
|
||||
// // description: "Payout to Bank Account",
|
||||
|
||||
// account_number: "7878780080316316",
|
||||
// fund_account_id: "fa_00000000000001",
|
||||
// amount: 100,
|
||||
// currency: "INR",
|
||||
// mode: "IMPS",
|
||||
// purpose: "refund",
|
||||
// queue_if_low_balance: true,
|
||||
// // reference_id: "Acme Transaction ID 12345",
|
||||
// // narration: "Acme Corp Fund Transfer",
|
||||
// notes: {
|
||||
// account_holder_name: accountHolderName,
|
||||
// ifsc_code: IFSCCode,
|
||||
// },
|
||||
// };
|
||||
|
||||
const options = {
|
||||
method: "post",
|
||||
url: "https://api.razorpay.com/v1/payouts",
|
||||
auth: {
|
||||
username: process.env.RAZERPAY_KEY_ID,
|
||||
password: process.env.RAZERPAY_SECRET_KEY,
|
||||
},
|
||||
data: {
|
||||
account_number: accountNumber,
|
||||
amount,
|
||||
currency: "INR",
|
||||
mode: "IMPS", // Specify the mode of transfer (IMPS/NEFT/RTGS)
|
||||
purpose: "payout", // Purpose of the payout
|
||||
recipient_contact: "+91XXXXXXXXXX", // Recipient's contact number
|
||||
recipient_email: "recipient@example.com", // Recipient's email address
|
||||
notes: {
|
||||
account_holder_name: "pawan",
|
||||
ifsc_code: IFSCCode,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
try {
|
||||
// const saveData = await AffiliateModel.findById(req.params.id).sort({
|
||||
// updatedAt: -1,
|
||||
// });
|
||||
// const resObj = {
|
||||
// affiliate_pay_history: saveData.affiliate_pay_history,
|
||||
// name: saveData.name,
|
||||
|
||||
const response = await axios(options);
|
||||
// res.json(response.data);
|
||||
// console.log(razorpay.payouts);
|
||||
// razorpay.payouts.create(options, function (err, payout) {
|
||||
// if (err) {
|
||||
// console.error(err);
|
||||
// res.status(500).send("Server Error");
|
||||
// } else {
|
||||
// res.json(payout);
|
||||
// }
|
||||
// });
|
||||
// const payout = await razorpay.payouts.create(options);
|
||||
|
||||
// console.log("payout", payout);
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
response,
|
||||
message: "lllllll",
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
message: error?.response?.data?.message
|
||||
? error?.response?.data?.message
|
||||
: "Error Payout",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -1,5 +1,6 @@
|
||||
import express from "express";
|
||||
import {
|
||||
affiliatPayOut,
|
||||
affiliatePayHistory,
|
||||
createAffiliate,
|
||||
editAffiliate,
|
||||
@ -66,4 +67,11 @@ router.get(
|
||||
affiliatePayHistory
|
||||
);
|
||||
|
||||
//pay affiliat Amount by razorpay
|
||||
router.post(
|
||||
"/payout",
|
||||
isAuthenticatedUser,
|
||||
authorizeRoles("admin", "Employee"),
|
||||
affiliatPayOut
|
||||
);
|
||||
export default router;
|
||||
|
Loading…
Reference in New Issue
Block a user