order
This commit is contained in:
@@ -35,16 +35,15 @@ export class OrdersService {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
async checkout(userId: string, restaurantId: string) {
|
async checkout(userId: string, restaurantId: string) {
|
||||||
console.log('Order created event emitted 000');
|
|
||||||
const cart = await this.cartService.findOneOrFail(userId, restaurantId);
|
const cart = await this.cartService.findOneOrFail(userId, restaurantId);
|
||||||
|
|
||||||
const { order } = await this.createOrder(userId, restaurantId, cart);
|
const { order } = await this.createOrder(userId, restaurantId, cart);
|
||||||
|
|
||||||
if (!order.paymentMethod) {
|
// if (!order.paymentMethod) {
|
||||||
throw new BadRequestException('Payment method is required for checkout');
|
// throw new BadRequestException('Payment method is required for checkout');
|
||||||
}
|
// }
|
||||||
|
|
||||||
const { paymentUrl } = await this.paymentsService.startPayment(order.id);
|
// const { paymentUrl } = await this.paymentsService.startPayment(order.id);
|
||||||
|
|
||||||
await this.cartService.clearCart(userId, restaurantId);
|
await this.cartService.clearCart(userId, restaurantId);
|
||||||
|
|
||||||
@@ -57,7 +56,7 @@ export class OrdersService {
|
|||||||
// new OrderPaymentSuccessEvent(restaurantId, order.user.id, order.id, order.total),
|
// new OrderPaymentSuccessEvent(restaurantId, order.user.id, order.id, order.total),
|
||||||
// );
|
// );
|
||||||
console.log('Order created event emitted 111');
|
console.log('Order created event emitted 111');
|
||||||
return { order, paymentUrl };
|
return { order };
|
||||||
}
|
}
|
||||||
|
|
||||||
async createOrder(userId: string, restaurantId: string, cart: Cart) {
|
async createOrder(userId: string, restaurantId: string, cart: Cart) {
|
||||||
|
|||||||
@@ -57,6 +57,19 @@ export class PaymentsController {
|
|||||||
findAllByRestaurant(@UserId() userId: string, @RestId() restId: string) {
|
findAllByRestaurant(@UserId() userId: string, @RestId() restId: string) {
|
||||||
return this.paymentsService.findAllByRestaurantId(restId, userId);
|
return this.paymentsService.findAllByRestaurantId(restId, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@Get('public/payments/pay-order/:orderId')
|
||||||
|
@ApiOperation({ summary: 'Pay for an order' })
|
||||||
|
@ApiParam({ name: 'orderId', type: 'string', description: 'Order ID' })
|
||||||
|
@ApiHeader({
|
||||||
|
name: 'X-Slug',
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
payAnOrder(@Param('orderId') orderId: string, @RestId() restId: string) {
|
||||||
|
return this.paymentsService.startPayment(orderId, restId);
|
||||||
|
}
|
||||||
// @UseGuards(AdminAuthGuard)
|
// @UseGuards(AdminAuthGuard)
|
||||||
// @ApiBearerAuth()
|
// @ApiBearerAuth()
|
||||||
// @Get('admin/payments/:id')
|
// @Get('admin/payments/:id')
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ export class PaymentsService {
|
|||||||
// return { paymentUrl };
|
// return { paymentUrl };
|
||||||
// }
|
// }
|
||||||
|
|
||||||
async startPayment(orderId: string): Promise<{ paymentUrl: string | null }> {
|
async startPayment(orderId: string, restId: string): Promise<{ paymentUrl: string | null }> {
|
||||||
const { amount, method, restaurantDomain, gateway, merchantId, user } = await this.validateOrder(orderId);
|
const { amount, method, restaurantDomain, gateway, merchantId, user } = await this.validateOrder(orderId, restId);
|
||||||
|
|
||||||
// Handle Wallet payment immediately
|
// Handle Wallet payment immediately
|
||||||
// if (method === PaymentMethodEnum.Wallet) {
|
// if (method === PaymentMethodEnum.Wallet) {
|
||||||
@@ -86,8 +86,12 @@ export class PaymentsService {
|
|||||||
return { paymentUrl };
|
return { paymentUrl };
|
||||||
}
|
}
|
||||||
|
|
||||||
private async validateOrder(orderId: string) {
|
private async validateOrder(orderId: string, restId: string) {
|
||||||
const order = await this.em.findOne(Order, { id: orderId }, { populate: ['user', 'paymentMethod'] });
|
const order = await this.em.findOne(
|
||||||
|
Order,
|
||||||
|
{ id: orderId, restaurant: { id: restId } },
|
||||||
|
{ populate: ['user', 'paymentMethod'] },
|
||||||
|
);
|
||||||
if (!order) {
|
if (!order) {
|
||||||
throw new NotFoundException('Order not found');
|
throw new NotFoundException('Order not found');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user