pay
This commit is contained in:
@@ -4,6 +4,7 @@ import { OrdersService } from './orders.service';
|
|||||||
import { AuthGuard } from '../auth/guards/auth.guard';
|
import { AuthGuard } from '../auth/guards/auth.guard';
|
||||||
import { UserId } from '../../common/decorators/user-id.decorator';
|
import { UserId } from '../../common/decorators/user-id.decorator';
|
||||||
import { RestId } from 'src/common/decorators/rest-id.decorator';
|
import { RestId } from 'src/common/decorators/rest-id.decorator';
|
||||||
|
import { AdminAuthGuard } from '../auth/guards/adminAuth.guard';
|
||||||
|
|
||||||
@ApiTags('orders')
|
@ApiTags('orders')
|
||||||
@Controller()
|
@Controller()
|
||||||
@@ -22,8 +23,16 @@ export class OrdersController {
|
|||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@Get('public/orders')
|
@Get('public/orders')
|
||||||
@ApiOperation({ summary: 'Get all orders' })
|
@ApiOperation({ summary: 'Get all orders' })
|
||||||
findAll() {
|
findAll(@RestId() restId: string) {
|
||||||
return this.ordersService.findAll();
|
return this.ordersService.findAll(restId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(AdminAuthGuard)
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@Get('admin/orders')
|
||||||
|
@ApiOperation({ summary: 'Get all orders' })
|
||||||
|
findAllAdmin(@RestId() restId: string) {
|
||||||
|
return this.ordersService.findAll(restId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(AuthGuard)
|
@UseGuards(AuthGuard)
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export class OrdersService {
|
|||||||
throw new BadRequestException('Payment method is required for checkout');
|
throw new BadRequestException('Payment method is required for checkout');
|
||||||
}
|
}
|
||||||
|
|
||||||
const { paymentUrl } = await this.paymentsService.initializePayment(order.paymentMethod.id, order.total, order.id);
|
const { paymentUrl } = await this.paymentsService.startPayment(order.id);
|
||||||
|
|
||||||
await this.cartService.clearCart(userId, restaurantId);
|
await this.cartService.clearCart(userId, restaurantId);
|
||||||
|
|
||||||
@@ -234,10 +234,10 @@ export class OrdersService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll() {
|
async findAll(restId: string) {
|
||||||
const orders = await this.em.find(
|
const orders = await this.em.find(
|
||||||
Order,
|
Order,
|
||||||
{},
|
{ restaurant: { id: restId } },
|
||||||
{ populate: ['user', 'restaurant', 'deliveryMethod', 'address', 'paymentMethod'] },
|
{ populate: ['user', 'restaurant', 'deliveryMethod', 'address', 'paymentMethod'] },
|
||||||
);
|
);
|
||||||
if (!orders) {
|
if (!orders) {
|
||||||
|
|||||||
@@ -26,14 +26,7 @@ export class PaymentsController {
|
|||||||
return this.paymentMethodService.findByRestaurant(restId);
|
return this.paymentMethodService.findByRestaurant(restId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(AuthGuard)
|
|
||||||
@ApiBearerAuth()
|
|
||||||
@Get('public/payments/methods/restaurant')
|
|
||||||
@ApiOperation({ summary: 'Get the restaurant payment methods' })
|
|
||||||
@ApiNotFoundResponse({ description: 'Restaurant payment methods not found' })
|
|
||||||
payOrder(@RestId() restId: string) {
|
|
||||||
return this.paymentMethodService.findByRestaurant(restId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// @UseGuards(AdminAuthGuard)
|
// @UseGuards(AdminAuthGuard)
|
||||||
// @ApiBearerAuth()
|
// @ApiBearerAuth()
|
||||||
|
|||||||
@@ -55,9 +55,6 @@ export class PaymentsService {
|
|||||||
|
|
||||||
// return { paymentUrl };
|
// return { paymentUrl };
|
||||||
// }
|
// }
|
||||||
asynv paymentGatewayAuthorize(amount: number, orderId: string, merchantId: string, gateway: PaymentGatewayEnum){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async startPayment(orderId: string): Promise<{ paymentUrl: string | null }> {
|
async startPayment(orderId: string): Promise<{ paymentUrl: string | null }> {
|
||||||
const { amount, method, restaurantDomain, gateway, merchantId } = await this.validateOrder(orderId);
|
const { amount, method, restaurantDomain, gateway, merchantId } = await this.validateOrder(orderId);
|
||||||
@@ -105,10 +102,10 @@ export class PaymentsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createPayment(domain: string, dto: CreatePaymentDto) {
|
async createPayment(domain: string, dto: CreatePaymentDto) {
|
||||||
const { amount, orderId, merchantId, gateway, paymentMethod } = dto;
|
const { amount, orderId, merchantId, gateway, method } = dto;
|
||||||
|
|
||||||
const { authority } = await this.paymentGatewayService.requestToGateway(
|
const { authority } = await this.paymentGatewayService.requestToGateway(
|
||||||
paymentMethod,
|
method,
|
||||||
amount,
|
amount,
|
||||||
orderId,
|
orderId,
|
||||||
merchantId,
|
merchantId,
|
||||||
|
|||||||
Reference in New Issue
Block a user