update payment

This commit is contained in:
2024-11-03 20:28:14 +07:00
parent e8c0e0d312
commit bc2eda7490
10 changed files with 208 additions and 14 deletions

View File

@@ -32,4 +32,18 @@ export class PayosController {
async ping() {
return this.payosService.ping()
}
// test create payment url
@Post('create-payment-url')
@ApiOperation({ summary: 'Test create payment url' })
async createPaymentURL(@Body() body: any) {
return this.payosService.createPaymentURL(body)
}
// get payment status
@Get('get-payment-status/:orderId')
@ApiOperation({ summary: 'Get payment status' })
async getPaymentStatus(@Param('orderId') orderId: string | number) {
return this.payosService.getPaymentStatus(orderId)
}
}

View File

@@ -1,9 +1,24 @@
import { Module } from '@nestjs/common'
import { PayosController } from './payos.controller'
import { PayosService } from './payos.service'
import { HttpModule } from '@nestjs/axios'
import PayOS from '@payos/node'
@Module({
providers: [PayosService],
imports: [HttpModule],
providers: [
PayosService,
{
provide: 'PayOS',
useFactory: () => {
return new PayOS(
process.env.PAYOS_CLIENT_ID ?? '',
process.env.PAYOS_API_KEY ?? '',
process.env.PAYOS_CHECKSUM_KEY ?? '',
)
},
},
],
controllers: [PayosController],
exports: [PayosService],
})

View File

@@ -1,10 +1,19 @@
import { Injectable, Logger } from '@nestjs/common'
import { Inject, Injectable, Logger } from '@nestjs/common'
import { PrismaService } from '../Prisma/prisma.service'
import PayOS from '@payos/node'
import type {
CheckoutRequestType,
CheckoutResponseDataType,
} from '@payos/node/lib/type'
export type CreatePaymentBody = CheckoutRequestType
export type CreatePaymentResponse = CheckoutResponseDataType
@Injectable()
export class PayosService {
constructor(private readonly prisma: PrismaService) {}
constructor(
private readonly prisma: PrismaService,
@Inject('PayOS') private readonly payos: PayOS,
) {}
async ping() {
return 'pong'
@@ -16,7 +25,15 @@ export class PayosService {
}
async createPaymentURL(body: any) {
return body
return await this.payos.createPaymentLink(body)
}
async createPayment(body: CreatePaymentBody): Promise<CreatePaymentResponse> {
return await this.payos.createPaymentLink(body)
}
async getPaymentStatus(orderId: string | number) {
return await this.payos.getPaymentLinkInformation(orderId)
}
async cancelPaymentURL(body: any) {