1.0.7 • Published 8 months ago

@ijodkor/nest-payme v1.0.7

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

Payme - Elektron tolov tizimi

NestJs ilovalar uchun Payme ETT bilan integratsiya qilish uchun kutubxona.

Payment gateway integrator package for NestJs App

Ornatish va sozlash (Installation and setup)

Ornatish (installation)

npm install @ijodkor/nest-payme

Muhit ozgaruvchilari (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)

Links

1.0.7

8 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago