NestJS module for integrating Payme payment system into your NestJS applications.
npm install payme-integration
- Full Payme Merchant API implementation
- Built-in authentication guard
- MongoDB integration
- TypeScript support
- Error handling
- Transaction state management
- Create PaymeStrategy:
import { Injectable } from '@nestjs/common'
import { InjectModel } from '@nestjs/mongoose'
import { Model, Types } from 'mongoose'
import {
IPaymeStrategy,
Order,
OrderStatus,
PaymeTransaction,
} from 'payme-integration'
import {
Donation,
DonationDocument,
PaymentProvider,
} from 'src/models/donation.schema'
@Injectable()
export class PaymeStrategy implements IPaymeStrategy {
constructor(
@InjectModel(Donation.name)
private readonly donationModel: Model<DonationDocument>,
) {}
async getOrderByAccount(account: { user_id: string }): Promise<Order | null> {
const donation = await this.donationModel.findOne({
user: account.user_id,
status: OrderStatus.ReadyForPayment,
})
if (donation) {
return {
id: donation.user.toString(),
status: donation.status,
amount: donation.amount,
}
}
return null
}
async successPayment(transaction: PaymeTransaction): Promise<void> {
const account = transaction.account as {
user_id: string
}
await this.donationModel.findOneAndUpdate(
{
user: new Types.ObjectId(account.user_id),
status: OrderStatus.ReadyForPayment,
},
{
status: transaction.status,
paid_time: new Date(transaction.create_time),
payment_provider: PaymentProvider.PAYME,
},
)
}
}
- Configure Module:
import { Module } from '@nestjs/common';
import { PaymeModule } from '@globalmove/payme-integration';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { MongooseModule } from '@nestjs/mongoose';
@Module({
imports: [
ConfigModule.forRoot(),
MongooseModule.forRoot('mongodb://localhost/your-db'),
MongooseModule.forFeature([
{ name: YourModel.name, schema: YourModelSchema },
]),
PaymeModule.forRootAsync({
paymeStrategy: PaymeStrategy,
imports: [
ConfigModule,
MongooseModule.forFeature([
{ name: YourModel.name, schema: YourModelSchema },
]),
],
inject: [ConfigService],
useFactory: async (configService: ConfigService) => ({
username: configService.get('PAYME_LOGIN'),
password: configService.get('PAYME_PASSWORD'),
}),
isGlobal: true,
}),
],
})
export class AppModule {}
PAYME_LOGIN=Paycom
PAYME_PASSWORD=YOUR_MERCHANT_KEY
- CheckPerformTransaction
- CreateTransaction
- PerformTransaction
- CancelTransaction
- CheckTransaction
- GetStatement
enum TransactionState {
STATE_NEW = 1,
STATE_IN_PROGRESS = 2,
STATE_DONE = 3,
STATE_CANCELLED = 4,
STATE_POST_CANCELLED = 5
}
Globalmove
MIT