1.0.7 • Published 8 months ago
@ijodkor/nest-payme v1.0.7
Payme - Elektron to‘lov tizimi
NestJs ilovalar uchun Payme ETT bilan integratsiya qilish uchun kutubxona.
Payment gateway integrator package for NestJs App
O‘rnatish va sozlash (Installation and setup)
O‘rnatish (installation)
npm install @ijodkor/nest-paymeMuhit o‘zgaruvchilari (Environment variables)
PAYME_SUBSCRIPTION_API_URL=
PAYME_MERCHANT_ID=
PAYME_MERCHANT_KEY=Foydalanish (Usage)
Namuna (example)
import {HttpException, Inject, Injectable} from '@nestjs/common';
import {Cache as MCache, CACHE_MANAGER} from "@nestjs/cache-manager";
import {CardService, ReceiptService} from "payme";
import {v4 as uuidV4} from 'uuid';
import {PaymentTransactionService} from "@/modules/balance/transaction/payment-transaction.service";
import {PreparePaymentDto} from "@/modules/account/dto/payment/prepare-payment.dto";
import {PayPaymentDto} from "@/modules/account/dto/payment/pay-payment.dto";
import {ProductService} from "@/modules/account/services/product.service";
@Injectable()
export class PaymentService {
constructor(
@Inject(CACHE_MANAGER) private cacheManager: MCache,
private readonly transactionService: PaymentTransactionService,
private readonly receiptService: ReceiptService,
private readonly cardService: CardService,
) {
}
public async prepare(dto: PreparePaymentDto) {
// Create a token
const {token} = await this.cardService.create(dto);
// Get code for verifying
await this.cardService.getCode(token);
// Create new receipt (there is account contains only uuid)
const account = {};
const receipt = await this.receiptService.create(
account,
dto.amount,
{
receipt_type: 0,
items: [
{
title: "Xizmat",
price: dto.amount,
discount: 0,
count: 1,
code: "10305001001000000",
package_code: "1504169",
vat_percent: 0
}
]
}
);
// Create transaction
// ...
// Store token to cache
return {
account,
amount: receipt.amount
}
}
async pay(dto: PayPaymentDto) {
// Verify code
await this.cardService.getCode(dto.code);
// Get token from cache
const token: any = "..."
// Find transaction
const {receiptId, balanceId} = await this.transactionService.findById(dto.uuid);
// Verify card
await this.cardService.verify(token, dto.code);
// Pay by card
const receipt = await this.receiptService.pay(receiptId, token);
// Update transaction status
await this.transactionService.completed(dto.uuid);
return receipt;
}
}Registration
hidden - exclude from Swagger
// Register for feature
SubscriptionModule.forFeature({
hidden: false,
// options: {
// auth: AuthOption.BASIC_AUTH,
// params: {
// username: '12',
// password: '12',
// },
// },
})
// Registar async
SubscriptionModule.registerAsync({
hidden: false,
useFactory: () => ({
auth: AuthOption.ANY,
useFactory: () => {
return true
}
})
})Mavjud xizmatlar
- Subscribe API
Foydalanilgan manbalar (References)
- Payme Business - Elektron to‘lov tizimi