zarinpal payment

This commit is contained in:
2026-01-18 19:30:41 +03:30
parent 6e8e4c7cf5
commit 87da6a8c10
4 changed files with 25 additions and 18 deletions
+10 -5
View File
@@ -61,12 +61,17 @@ export class Order extends BaseEntity {
@Property({ type: 'decimal', precision: 10, scale: 0 })
paidAmount!: number;
// balance!: number;
@Property({ type: 'decimal', precision: 10, scale: 0 })
get balance():number{
return this.total- this.paidAmount
}
// private _balance!: number;
@Property({ type: 'decimal', precision: 10, scale: 0 })
balance!: number;
// get balance(): number {
// return this._balance
// }
// set balance(value) {
// this._balance = this.total - this.paidAmount
// }
// @Property({ type: 'text', nullable: true })
// description?: string;
@@ -150,6 +150,7 @@ export class OrderService {
targetOrder.discount = discount
targetOrder.total = subTotal - discount
targetOrder.balance = subTotal - discount
// change status
targetOrder.status = OrderStatusEnum.INVOICED
@@ -2,6 +2,7 @@ import {
Controller, Get, Post, Body,
Param,
UseGuards,
Query,
} from '@nestjs/common';
import { PaymentService } from '../services/payments.service';
import {
@@ -41,7 +42,7 @@ export class PaymentController {
@ApiBearerAuth()
@Get('public/payments')
@ApiOperation({ summary: 'get all payments as admin' })
findAllByUser(@UserId() userId: string, @Body() dto: FindPaymentsDto) {
findAllByUser(@UserId() userId: string, @Query() dto: FindPaymentsDto) {
return this.paymentsService.findAllByUser(dto, userId);
}
@@ -122,7 +122,7 @@ export class PaymentService {
gateway: null,
order,
status: PaymentStatusEnum.Paid,
paidAt: new Date()
paidAt: new Date(),
});
// 3. Create Credit transaction record
const newCreditTransaction = this.creditRepository.create({
@@ -130,7 +130,7 @@ export class PaymentService {
amount,
type: CreditTransactionType.WITHDRAW,
balance: newBalance,
orderId: order.id
orderId: order.id,
});
em.persist([payment, newCreditTransaction]);
@@ -148,21 +148,19 @@ export class PaymentService {
const gateway = this.gatewayManager.get(requestedGateway!);
const payment = this.paymentRepository.create({
order,
amount,
method: PaymentMethodEnum.Online,
status: PaymentStatusEnum.Pending
})
const { token, paymentUrl } = await gateway.requestPayment({
amount: ctx.amount,
orderId: ctx.order.id,
});
payment.gateway = requestedGateway;
payment.token = token;
payment.status = PaymentStatusEnum.Pending;
const payment = this.paymentRepository.create({
order,
amount,
method: PaymentMethodEnum.Online,
status: PaymentStatusEnum.Pending,
gateway: requestedGateway,
token,
})
await this.em.persistAndFlush(payment);
@@ -211,6 +209,7 @@ export class PaymentService {
// TODO : use decimal js
// does need persist or not
payment.order.paidAmount += payment.amount
payment.order.balance -= payment.amount
await em.flush();
return payment;
@@ -248,6 +247,7 @@ export class PaymentService {
// TODO : use decimal js
payment.order.paidAmount += payment.amount
payment.order.balance -= payment.amount
em.persist(payment);
em.persist(payment.order);