full app
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user