zarinpal payment
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user