142 lines
5.5 KiB
TypeScript
Executable File
142 lines
5.5 KiB
TypeScript
Executable File
import { Body, Controller, Get, Param, Patch, Post, Query, Res } from "@nestjs/common";
|
|
import { ApiOperation, ApiTags } from "@nestjs/swagger";
|
|
import { FastifyReply } from "fastify";
|
|
|
|
import { CreateBankAccountDto } from "./DTO/create-bankaccount.dto";
|
|
import { GatewayDepositDto, TransferDepositDto } from "./DTO/deposit-wallet.dto";
|
|
import { PaymentTransactionQueryDto } from "./DTO/payment-transaction-query.dto";
|
|
import { SearchTransactionQueryDto } from "./DTO/search-transaction-query.dto";
|
|
import { UpdateBankAccountDto } from "./DTO/update-bankaccount.dto";
|
|
import { RejectDepositRequestDto } from "./DTO/update-deposit-request-status.dto";
|
|
import { VerifyParamDto, VerifyQueryDto } from "./DTO/verify-payment.dto";
|
|
import { PaymentsService } from "./providers/payments.service";
|
|
import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
|
|
import { Pagination } from "../../common/decorators/pagination.decorator";
|
|
import { PermissionsDec } from "../../common/decorators/permission.decorator";
|
|
import { UserDec } from "../../common/decorators/user.decorator";
|
|
import { PaginationDto } from "../../common/DTO/pagination.dto";
|
|
import { ParamDto } from "../../common/DTO/param.dto";
|
|
import { PermissionEnum } from "../users/enums/permission.enum";
|
|
|
|
@Controller("payments")
|
|
@ApiTags("Payments")
|
|
export class PaymentsController {
|
|
constructor(private readonly paymentsService: PaymentsService) {}
|
|
|
|
@AuthGuards()
|
|
@ApiOperation({ summary: "get all available gateways" })
|
|
@Get("gateways")
|
|
getAvailableGateways() {
|
|
return this.paymentsService.getAvailableGateways();
|
|
}
|
|
|
|
@ApiOperation({ summary: "Charge wallet ==> user route" })
|
|
@AuthGuards()
|
|
@Post("deposit/gateway")
|
|
chargeWalletWithGateway(@Body() chargeDto: GatewayDepositDto, @UserDec("id") userId: string) {
|
|
return this.paymentsService.chargeWalletWithGateway(chargeDto, userId);
|
|
}
|
|
|
|
@ApiOperation({ summary: "charge wallet with transfer ==> user route" })
|
|
@AuthGuards()
|
|
@Post("deposit/transfer")
|
|
chargeWalletWithTransfer(@Body() depositDto: TransferDepositDto, @UserDec("id") userId: string) {
|
|
return this.paymentsService.chargeWalletWithTransfer(depositDto, userId);
|
|
}
|
|
|
|
@ApiOperation({ summary: "get deposit request of users ==> admin route" })
|
|
@PermissionsDec(PermissionEnum.PAYMENTS_READ)
|
|
@AuthGuards()
|
|
@Pagination()
|
|
@Get("deposit/transfer")
|
|
getDepositRequests(@Query() queryDto: PaymentTransactionQueryDto) {
|
|
return this.paymentsService.getDepositRequests(queryDto);
|
|
}
|
|
|
|
@ApiOperation({ summary: "get deposit gateway payment ==> admin route" })
|
|
@PermissionsDec(PermissionEnum.PAYMENTS_READ)
|
|
@AuthGuards()
|
|
@Pagination()
|
|
@Get("deposit/gateway")
|
|
getDepositGatewayPayment(@Query() queryDto: PaginationDto) {
|
|
return this.paymentsService.getDepositGatewayPayment(queryDto);
|
|
}
|
|
|
|
@ApiOperation({ summary: "approve deposit request ==> admin route" })
|
|
@PermissionsDec(PermissionEnum.PAYMENTS_UPDATE)
|
|
@AuthGuards()
|
|
@Post("deposit/transfer/approve/:id")
|
|
approverDepositRequest(@Param() paramDto: ParamDto) {
|
|
return this.paymentsService.approverDepositRequest(paramDto.id);
|
|
}
|
|
|
|
@ApiOperation({ summary: "reject deposit request ==> admin route" })
|
|
@PermissionsDec(PermissionEnum.PAYMENTS_UPDATE)
|
|
@AuthGuards()
|
|
@Post("deposit/transfer/reject/:id")
|
|
rejectDepositRequest(@Param() paramDto: ParamDto, @Body() rejectDto: RejectDepositRequestDto) {
|
|
return this.paymentsService.rejectDepositRequest(paramDto.id, rejectDto);
|
|
}
|
|
|
|
@ApiOperation({ summary: "get transaction for admin" })
|
|
@PermissionsDec(PermissionEnum.PAYMENTS_READ)
|
|
@AuthGuards()
|
|
@Pagination()
|
|
@Get("transactions")
|
|
getTransaction(@Query() queryDto: SearchTransactionQueryDto) {
|
|
return this.paymentsService.getTransactions(queryDto);
|
|
}
|
|
|
|
@Get("verify/:gateway/:invoiceId")
|
|
verifyPaymentWithInvoice(
|
|
@Param() paramDto: VerifyParamDto,
|
|
@Query() queryDto: VerifyQueryDto,
|
|
@Res({ passthrough: true }) rep: FastifyReply,
|
|
) {
|
|
return this.paymentsService.verifyPayment(paramDto, queryDto, rep);
|
|
}
|
|
|
|
@Get("verify/:gateway")
|
|
verifyPaymentWithoutInvoice(
|
|
@Param() paramDto: VerifyParamDto,
|
|
@Query() queryDto: VerifyQueryDto,
|
|
@Res({ passthrough: true }) rep: FastifyReply,
|
|
) {
|
|
return this.paymentsService.verifyPayment(paramDto, queryDto, rep);
|
|
}
|
|
|
|
///------------------- bank account -----------------------------
|
|
|
|
@AuthGuards()
|
|
@PermissionsDec(PermissionEnum.PAYMENTS_CREATE, PermissionEnum.BANK_ACCOUNTS_CREATE)
|
|
@ApiOperation({ summary: "add bank account for transfer and deposit ==> admin route" })
|
|
@Post("bank-account")
|
|
addBankAccount(@Body() createDto: CreateBankAccountDto) {
|
|
return this.paymentsService.addBankAccount(createDto);
|
|
}
|
|
|
|
@AuthGuards()
|
|
@ApiOperation({ summary: "get bank account by id" })
|
|
@Get("bank-account/:id")
|
|
getBankAccountById(@Param() paramDto: ParamDto) {
|
|
return this.paymentsService.getBankAccountById(paramDto.id);
|
|
}
|
|
|
|
@AuthGuards()
|
|
@ApiOperation({ summary: "update bank account with its id" })
|
|
@PermissionsDec(PermissionEnum.PAYMENTS_UPDATE, PermissionEnum.BANK_ACCOUNTS_UPDATE)
|
|
@Patch("bank-account/:id")
|
|
updateBankAccount(@Body() updateDto: UpdateBankAccountDto, @Param() paramDto: ParamDto) {
|
|
return this.paymentsService.updateBankAccount(updateDto, paramDto.id);
|
|
}
|
|
|
|
@AuthGuards()
|
|
@ApiOperation({ summary: "get bank account" })
|
|
@Get("bank-account")
|
|
getBankAccounts(@UserDec("isAdmin") isAdmin: boolean) {
|
|
return this.paymentsService.getBankAccounts(isAdmin);
|
|
}
|
|
|
|
///------------------- Deposit transfer -----------------------------
|
|
}
|