Skip to content

Commit 874b99d

Browse files
committed
Add refund operation
1 parent e5488ef commit 874b99d

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/billing/cloudpayments.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,29 @@ export default class CloudPaymentsWebhooks {
496496
*/
497497
if (data.cloudPayments?.recurrent?.startDate) {
498498
this.handleSendingToTelegramError(telegram.sendMessage(`✅ [Billing / Pay] Recurrent payments activated for «${workspace.name}». 1 RUB charged`, TelegramBotURLs.Money));
499+
499500
await cloudPaymentsApi.cancelPayment(body.TransactionId);
501+
502+
const member = await this.getMember(data.userId, workspace);
503+
const plan = await this.getPlan(req, planId);
504+
505+
/**
506+
* Create business operation about refund
507+
*/
508+
await req.context.factories.businessOperationsFactory.create<PayloadOfWorkspacePlanPurchase>({
509+
transactionId: body.TransactionId.toString(),
510+
type: BusinessOperationType.CardLinkRefund,
511+
status: BusinessOperationStatus.Confirmed,
512+
payload: {
513+
workspaceId: workspace._id,
514+
amount: +body.Amount * PENNY_MULTIPLIER * -1,
515+
currency: body.Currency,
516+
userId: member._id,
517+
tariffPlanId: plan._id,
518+
},
519+
dtCreated: new Date(),
520+
});
521+
500522
this.handleSendingToTelegramError(telegram.sendMessage(`✅ [Billing / Pay] Recurrent payments activated for «${workspace.name}». 1 RUB returned`, TelegramBotURLs.Money));
501523
} else {
502524
/**

0 commit comments

Comments
 (0)