This commit is contained in:
payacom
2026-09-24 21:00:07 +03:30
parent 1954b2661d
commit 7f0ddfde70
113 changed files with 570 additions and 5049 deletions

View File

@@ -193,7 +193,7 @@ const requestWithdrawal = async (req, res, next) => {
const initiateWalletCharge = async (req, res, next) => {
try {
const { amount } = req.body
const { amount, platform } = req.body
const chargeAmount = Number(amount)
if (!Number.isFinite(chargeAmount) || chargeAmount <= 0) {
return walletError(res, 422, 'مبلغ نامعتبر است')
@@ -204,13 +204,14 @@ const initiateWalletCharge = async (req, res, next) => {
return walletError(res, 500, 'آدرس بازگشت پرداخت تنظیم نشده است')
}
const platformSuffix = platform ? `&platform=${encodeURIComponent(platform)}` : ''
const response = await axios.post(
'https://api.zarinpal.com/pg/v4/payment/request.json',
{
merchant_id: MERCHANT_ID,
amount: toRial(chargeAmount),
description: 'شارژ کیف پول مدستاگرام',
callback_url: `${callbackBase}/wallet/charge/callback?userId=${req.user._id}&amount=${chargeAmount}`
callback_url: `${callbackBase}/wallet/charge/callback?userId=${req.user._id}&amount=${chargeAmount}${platformSuffix}`
},
{ headers: { 'Content-Type': 'application/json' } }
)
@@ -228,9 +229,14 @@ const initiateWalletCharge = async (req, res, next) => {
}
const handleWalletChargeCallback = async (req, res) => {
const { Authority, Status, userId, amount } = req.query
const failRedirect = `${process.env.APP_SITE}/settings/wallet?charge=failed`
const successRedirect = `${process.env.APP_SITE}/settings/wallet?charge=success`
const { Authority, Status, userId, amount, platform } = req.query
const isAndroid = platform === 'android'
const failRedirect = isAndroid
? 'modstagram://FailedPay?type=wallet'
: `${process.env.APP_SITE}/settings/wallet?charge=failed`
const successRedirect = isAndroid
? 'modstagram://SuccessPay?type=wallet'
: `${process.env.APP_SITE}/settings/wallet?charge=success`
try {
if (Status !== 'OK') return res.redirect(failRedirect)