Skip to content

Commit

Permalink
Fix pay to buyer (#456)
Browse files Browse the repository at this point in the history
Now /paytobuyer can be used by admins in their communities
  • Loading branch information
Catrya authored Dec 21, 2023
1 parent a8cf035 commit 1df768d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion bot/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ const initialize = (botToken: string, options: Partial<Telegraf.Options<MainCont
await release(ctx, ctx.match[1]);
});

bot.command('paytobuyer', superAdminMiddleware, async (ctx: MainContext) => {
bot.command('paytobuyer', adminMiddleware, async (ctx: MainContext) => {
try {
const [orderId] = await validateParams(ctx, 2, '\\<_order id_\\>');
if (!orderId) return;
Expand All @@ -828,6 +828,17 @@ const initialize = (botToken: string, options: Partial<Telegraf.Options<MainCont
_id: orderId,
});
if (!order) return await messages.notActiveOrderMessage(ctx);

// We check if this is a solver, the order must be from the same community
if (!ctx.admin.admin) {
if (!order.community_id) {
return await messages.notAuthorized(ctx);
}

if (order.community_id != ctx.admin.default_community_id) {
return await messages.notAuthorized(ctx);
}
}

// We make sure the buyers invoice is not being paid
const isPending = await PendingPayment.findOne({
Expand Down

0 comments on commit 1df768d

Please sign in to comment.