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