order
This commit is contained in:
@@ -57,6 +57,19 @@ export class PaymentsController {
|
||||
findAllByRestaurant(@UserId() userId: string, @RestId() restId: string) {
|
||||
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)
|
||||
// @ApiBearerAuth()
|
||||
// @Get('admin/payments/:id')
|
||||
|
||||
@@ -57,8 +57,8 @@ export class PaymentsService {
|
||||
// return { paymentUrl };
|
||||
// }
|
||||
|
||||
async startPayment(orderId: string): Promise<{ paymentUrl: string | null }> {
|
||||
const { amount, method, restaurantDomain, gateway, merchantId, user } = await this.validateOrder(orderId);
|
||||
async startPayment(orderId: string, restId: string): Promise<{ paymentUrl: string | null }> {
|
||||
const { amount, method, restaurantDomain, gateway, merchantId, user } = await this.validateOrder(orderId, restId);
|
||||
|
||||
// Handle Wallet payment immediately
|
||||
// if (method === PaymentMethodEnum.Wallet) {
|
||||
@@ -86,8 +86,12 @@ export class PaymentsService {
|
||||
return { paymentUrl };
|
||||
}
|
||||
|
||||
private async validateOrder(orderId: string) {
|
||||
const order = await this.em.findOne(Order, { id: orderId }, { populate: ['user', 'paymentMethod'] });
|
||||
private async validateOrder(orderId: string, restId: string) {
|
||||
const order = await this.em.findOne(
|
||||
Order,
|
||||
{ id: orderId, restaurant: { id: restId } },
|
||||
{ populate: ['user', 'paymentMethod'] },
|
||||
);
|
||||
if (!order) {
|
||||
throw new NotFoundException('Order not found');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user