@ijodkor/nest-payme
Version:
NestJs ilovalar uchun Payme ETT bilan integratsiya qilish uchun kutubxona.
41 lines (35 loc) • 1.19 kB
text/typescript
import { BadRequestException, Body, Controller, HttpException, Post, UseGuards, } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { CardCreateDto } from "../dto/card-create.dto";
import { CardVerifyDto } from "../dto/card-verify.dto";
import { CardService } from "./card.service";
import { RouteGuard } from "../../support/guards/route.guard";
('payment')
('payment/payme')
(RouteGuard)
export class CardController {
constructor(private readonly cardService: CardService) {}
('card/create')
async cardCreate(() dto: CardCreateDto) {
try {
const card = await this.cardService.create(dto);
const { token } = card;
const response = await this.cardService.getCode(token);
if (!response.result.sent) {
throw new BadRequestException("Not sent");
}
return { token }
} catch (e: any) {
throw new HttpException(e.message, 400)
}
}
('card/verify')
async cardVerify(() dto: CardVerifyDto) {
try {
const { result } = await this.cardService.verify(dto.token, dto.code)
return result;
} catch (e) {
return 0;
}
}
}