From 984b264c832ef0b846c3a7dc7c7c5ed8648170d5 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Tue, 17 Feb 2026 16:28:48 +0330 Subject: [PATCH] add: paymnet in toman --- src/modules/bills/bills.service.ts | 5 ++++- src/modules/payments/constants/index.ts | 3 +++ src/modules/payments/gateways/zarinpal.gateway.ts | 4 ++-- src/modules/payments/services/payments.service.ts | 1 + 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/modules/bills/bills.service.ts b/src/modules/bills/bills.service.ts index b41f56e..dfe2a9b 100644 --- a/src/modules/bills/bills.service.ts +++ b/src/modules/bills/bills.service.ts @@ -49,7 +49,10 @@ export class BillsService { const companyMap = new Map(companies.map((c) => [c.id, c])); for (const value of values) { - const subtotal = new Decimal(waterRate).mul(value.waterUsage); + const waterCost = new Decimal(waterRate).mul(value.waterUsage); + const sewageCost = waterCost.mul(waterCost); + const subtotal = waterCost.add(sewageCost); + const tax = subtotal.mul(0.1); const totalPrice = subtotal.add(tax); const company = companyMap.get(value.companyId); diff --git a/src/modules/payments/constants/index.ts b/src/modules/payments/constants/index.ts index 3c109c8..e1d8fea 100755 --- a/src/modules/payments/constants/index.ts +++ b/src/modules/payments/constants/index.ts @@ -1,6 +1,9 @@ export const ZARINPAL_CONFIG = "ZARINPAL_CONFIG"; //=============================================== +/** Payment currency: IRR = Iranian Rial, IRT = Iran Toman (1 Toman = 10 Rials) */ +export const PAYMENT_CURRENCY = "IRT" as const; + export const PAYMENT = Object.freeze({ QUEUE_NAME: "payment", START: "payment_start", diff --git a/src/modules/payments/gateways/zarinpal.gateway.ts b/src/modules/payments/gateways/zarinpal.gateway.ts index 2f75823..1ecc30d 100755 --- a/src/modules/payments/gateways/zarinpal.gateway.ts +++ b/src/modules/payments/gateways/zarinpal.gateway.ts @@ -5,7 +5,7 @@ import { catchError, firstValueFrom } from "rxjs"; import { PaymentMessage } from "../../../common/enums/message.enum"; import { IZarinpalConfig } from "../../../configs/zarinpal.config"; -import { ZARINPAL_CONFIG } from "../constants"; +import { PAYMENT_CURRENCY, ZARINPAL_CONFIG } from "../constants"; import { GatewayEnum } from "../enums/gateway.enum"; import { IPaymentGateway, @@ -36,7 +36,7 @@ export class ZarinpalGateway implements IPaymentGateway { amount: processParams.amount, callback_url: `${this.config.callBackUrl}/${GatewayEnum.ZARINPAL}`, description: processParams.description, - currency: "IRT", + currency: PAYMENT_CURRENCY, // IRT = Iranian Rial metadata: { email: processParams.email, mobile: processParams.mobile }, }; diff --git a/src/modules/payments/services/payments.service.ts b/src/modules/payments/services/payments.service.ts index 58431f2..424900c 100644 --- a/src/modules/payments/services/payments.service.ts +++ b/src/modules/payments/services/payments.service.ts @@ -57,6 +57,7 @@ export class PaymentsService { if (invoice.company.user.id !== user.id) throw new BadRequestException(InvoiceMessage.NOT_FOUND_BY_ID_OR_NOT_BELONG_TO_USER); + // Amount is in IRT (Iranian Toman) const gatewayData = await this.processPayment(paymentGateway.name, { amount: new Decimal(invoice.totalPrice).toNumber(), description: PaymentMessage.CHECKOUT_INVOICE_MESSAGE.replace("[invoiceNumber]", invoice.numericId.toString()),