36 lines
1021 B
JavaScript
36 lines
1021 B
JavaScript
const WalletTransactionModel = require('../models/WalletTransactionModel')
|
|
|
|
/** Deposit required at booking time, when the provider has enabled it. */
|
|
const BOOKING_DEPOSIT_RATE = 0.3
|
|
/** Platform commission taken from the deposit amount. */
|
|
const BOOKING_COMMISSION_RATE = 0.05
|
|
|
|
/** Credits the provider's booking wallet bucket (net of platform commission) and pushes a live notification if possible. */
|
|
async function creditBookingShare (io, userId, amount, referenceId, description) {
|
|
if (!userId || amount <= 0) return
|
|
await WalletTransactionModel.create({
|
|
user: userId,
|
|
bucket: 'booking',
|
|
type: 'credit',
|
|
amount,
|
|
referenceType: 'payment',
|
|
referenceId,
|
|
description
|
|
})
|
|
if (io) {
|
|
try {
|
|
io.to(`user:${String(userId)}`).emit('notification', {
|
|
type: 'booking_commission',
|
|
title: 'واریز به کیف پول',
|
|
description
|
|
})
|
|
} catch (_) {}
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
BOOKING_DEPOSIT_RATE,
|
|
BOOKING_COMMISSION_RATE,
|
|
creditBookingShare
|
|
}
|