update payment

This commit is contained in:
2025-12-02 11:11:36 +03:30
parent 1165167619
commit 2e9a1dc7dc
12 changed files with 250 additions and 61 deletions
+12 -9
View File
@@ -12,15 +12,17 @@ import { OrderStatus } from './interface/order-status';
import { PaymentStatus } from '../payments/interface/payment-status';
import { Cart } from '../cart/interfaces/cart.interface';
import { RestaurantPaymentMethodRepository } from '../payments/repositories/restaurant-payment-method.repository';
import { PaymentGatewayService } from '../payments/services/payment-gateway.service';
// import { PaymentGatewayService } from '../payments/services/payment-gateway.service.tss';
import { PaymentsService } from '../payments/services/payments.service';
@Injectable()
export class OrdersService {
constructor(
private readonly em: EntityManager,
private readonly cartService: CartService,
private readonly paymentsService: PaymentsService,
private readonly RestaurantPaymentMethodRepository: RestaurantPaymentMethodRepository,
private readonly paymentGatewayService: PaymentGatewayService,
// private readonly paymentGatewayService: PaymentGatewayService,
) {}
async create(userId: string, restaurantId: string) {
@@ -76,24 +78,25 @@ export class OrdersService {
// Flush all changes
await em.flush();
let paymentUrl: string | null = null;
// Check if payment method is online and redirect to payment gateway
if (validationResult.paymentMethod.paymentMethod.isOnline) {
const paymentRedirect = this.paymentGatewayService.generateRedirectUrl(order, validationResult.paymentMethod);
const result = await this.paymentsService.initializePayment(
validationResult.paymentMethod.id,
order.total,
order.id,
);
// await this.cartService.clearCart(userId, restaurantId);
// Return order with redirect URL for online payment
return {
order,
redirectUrl: paymentRedirect.redirectUrl,
};
paymentUrl = result.paymentUrl;
} else {
// await this.cartService.clearCart(userId, restaurantId);
// For offline payment methods (cash on delivery, etc.), order is created and pending
// Payment status will be updated when payment is confirmed
// TODO: Implement offline payment confirmation flow if needed
}
return { order };
return { order, paymentUrl };
});
}