171 lines
6.1 KiB
TypeScript
171 lines
6.1 KiB
TypeScript
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common';
|
|
import { PaymentsService } from '../services/payments.service';
|
|
import {
|
|
ApiTags,
|
|
ApiOperation,
|
|
ApiNotFoundResponse,
|
|
ApiBody,
|
|
ApiParam,
|
|
ApiBearerAuth,
|
|
ApiHeader,
|
|
} from '@nestjs/swagger';
|
|
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
|
import { PaymentMethodService } from '../services/payment-method.service';
|
|
import { CreatePaymentMethodDto } from '../dto/create-payment-method.dto';
|
|
import { UpdatePaymentMethodDto } from '../dto/update-payment-method.dto';
|
|
import { VerifyPaymentDto } from '../dto/verify-payment.dto';
|
|
import { RestId, UserId } from 'src/common/decorators';
|
|
import { AuthGuard } from 'src/modules/auth/guards/auth.guard';
|
|
|
|
@ApiTags('payments')
|
|
@Controller()
|
|
export class PaymentsController {
|
|
constructor(
|
|
private readonly paymentsService: PaymentsService,
|
|
private readonly paymentMethodService: PaymentMethodService,
|
|
) {}
|
|
|
|
@UseGuards(AuthGuard)
|
|
@ApiBearerAuth()
|
|
@Get('public/payments/methods/restaurant')
|
|
@ApiOperation({ summary: 'Get the restaurant payment methods' })
|
|
@ApiHeader({
|
|
name: 'X-Slug',
|
|
required: true,
|
|
schema: {
|
|
type: 'string',
|
|
default: 'zhivan',
|
|
},
|
|
})
|
|
@ApiNotFoundResponse({ description: 'Restaurant payment methods not found' })
|
|
getTheRestaurantPaymentMethods(@RestId() restId: string) {
|
|
return this.paymentMethodService.findByRestaurant(restId);
|
|
}
|
|
|
|
@UseGuards(AuthGuard)
|
|
@ApiBearerAuth()
|
|
@Get('public/payments')
|
|
@ApiOperation({ summary: 'Get all the restaurant payments for user' })
|
|
@ApiHeader({
|
|
name: 'X-Slug',
|
|
required: true,
|
|
schema: {
|
|
type: 'string',
|
|
default: 'zhivan',
|
|
},
|
|
})
|
|
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')
|
|
// @ApiOperation({ summary: 'Get a payment by ID' })
|
|
// @ApiParam({ name: 'id', type: 'number', description: 'Payment ID' })
|
|
// @ApiOkResponse({ description: 'Payment found' })
|
|
// @ApiNotFoundResponse({ description: 'Payment not found' })
|
|
// findOnePayment(@Param('id') id: string) {
|
|
// return this.paymentsService.findById(+id);
|
|
// }
|
|
// @UseGuards(AdminAuthGuard)
|
|
// @ApiBearerAuth()
|
|
// @Patch('admin/payments/:id')
|
|
// @ApiOperation({ summary: 'Update a payment' })
|
|
// @ApiParam({ name: 'id', type: 'number', description: 'Payment ID' })
|
|
// @ApiBody({ type: UpdatePaymentDto })
|
|
// @ApiOkResponse({ description: 'Payment updated successfully' })
|
|
// @ApiNotFoundResponse({ description: 'Payment not found' })
|
|
// updatePayment(@Param('id') id: string, @Body() updatePaymentDto: UpdatePaymentDto) {
|
|
// return this.paymentsService.update(+id, updatePaymentDto);
|
|
// }
|
|
|
|
// @UseGuards(AdminAuthGuard)
|
|
// @ApiBearerAuth()
|
|
// @Delete('admin/payments/:id')
|
|
// @ApiOperation({ summary: 'Delete a payment' })
|
|
// @ApiParam({ name: 'id', type: 'number', description: 'Payment ID' })
|
|
// @ApiOkResponse({ description: 'Payment deleted successfully' })
|
|
// @ApiNotFoundResponse({ description: 'Payment not found' })
|
|
// removePayment(@Param('id') id: string) {
|
|
// return this.paymentsService.remove(+id);
|
|
// }
|
|
|
|
/** payment methods */
|
|
@UseGuards(AdminAuthGuard)
|
|
@ApiBearerAuth()
|
|
@Get('admin/payments/methods')
|
|
@ApiOperation({ summary: 'Get restaurant all payment methods' })
|
|
findByRestaurant(@RestId() restId: string) {
|
|
return this.paymentMethodService.findByRestaurant(restId);
|
|
}
|
|
|
|
@UseGuards(AdminAuthGuard)
|
|
@ApiBearerAuth()
|
|
@Post('admin/payments/methods')
|
|
@ApiOperation({ summary: 'Create a new restaurant payment method' })
|
|
@ApiBody({ type: CreatePaymentMethodDto })
|
|
createRestaurantPaymentMethod(@RestId() restId: string, @Body() createPaymentMethodDto: CreatePaymentMethodDto) {
|
|
return this.paymentMethodService.create(restId, createPaymentMethodDto);
|
|
}
|
|
|
|
@UseGuards(AdminAuthGuard)
|
|
@ApiBearerAuth()
|
|
@Get('admin/payments/methods/:paymentMethodId')
|
|
@ApiOperation({ summary: 'Get restaurant payment method by ID' })
|
|
@ApiParam({ name: 'paymentMethodId', type: 'string', description: 'Payment method ID' })
|
|
findOneRestaurantPaymentMethod(@Param('paymentMethodId') paymentMethodId: string) {
|
|
return this.paymentMethodService.findOne(paymentMethodId);
|
|
}
|
|
|
|
@UseGuards(AdminAuthGuard)
|
|
@ApiBearerAuth()
|
|
@Patch('admin/payments/methods/:paymentMethodId')
|
|
@ApiOperation({ summary: 'Update a restaurant payment method' })
|
|
@ApiParam({ name: 'paymentMethodId', type: 'string', description: 'Payment method ID' })
|
|
@ApiBody({ type: UpdatePaymentMethodDto })
|
|
updateRestaurantPaymentMethod(
|
|
@Param('paymentMethodId') paymentMethodId: string,
|
|
@Body() updatePaymentMethodDto: UpdatePaymentMethodDto,
|
|
) {
|
|
return this.paymentMethodService.update(paymentMethodId, updatePaymentMethodDto);
|
|
}
|
|
|
|
@UseGuards(AdminAuthGuard)
|
|
@ApiBearerAuth()
|
|
@Delete('admin/payments/methods/:paymentMethodId')
|
|
@ApiOperation({ summary: 'Delete a restaurant payment method' })
|
|
@ApiParam({ name: 'paymentMethodId', type: 'string', description: 'Payment method ID' })
|
|
removeRestaurantPaymentMethod(@Param('paymentMethodId') paymentMethodId: string) {
|
|
return this.paymentMethodService.remove(paymentMethodId);
|
|
}
|
|
|
|
@Post('public/payments/verify')
|
|
@ApiOperation({ summary: 'Verify a payment' })
|
|
@ApiHeader({
|
|
name: 'X-Slug',
|
|
required: true,
|
|
schema: {
|
|
type: 'string',
|
|
default: 'zhivan',
|
|
},
|
|
})
|
|
@ApiBody({ type: VerifyPaymentDto })
|
|
@ApiNotFoundResponse({ description: 'Payment not found' })
|
|
verifyPayment(@Body() verifyPaymentDto: VerifyPaymentDto) {
|
|
return this.paymentsService.verifyPayment(verifyPaymentDto.authority, verifyPaymentDto.orderId);
|
|
}
|
|
}
|