0.0.5 • Published 3 years ago

nest-payment v0.0.5

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
3 years ago

Nest Payment

Payfort implementation for NestJs.

Installation

NPM

$ npm install nest-payment --save

Yarn

$ yarn add nest-payment

Getting Started

Let's register the PaymentModule in app.module.ts

import { Module } from '@nestjs/common';
import { PaymentModule } from 'nest-payment';

@Module({
    imports: [
        PaymentModule.register(options)
    ]
})
export class AppModule {}

Or with Async

import { Module } from '@nestjs/common';
import { PaymentModule } from 'nest-payment';

@Module({
    imports: [
        PaymentModule.forRootAsync({
            useFactory: (configService: ConfigService) => configService.payment,
            // or use an async method
            // useFactory: async (configService: ConfigService) => configService.payment,
            inject: [ConfigService],
        }),
    ],
})
export class AppModule {}    

Options

const options = {
    baseUrl: 'https://example.com/v0',
    tokenUrl: 'https://example.com/v0/oauth/token',
    authorization: {
        grant_type: 'client_credentials',
        username: 'username',
        password: 'pasword'
    }
}

Models

The package contains some models to help for bills generation.

Bill, Service, PaymentMethod

import {PaymentService, Bill, Serivce, PaymentMethod} from 'nest-payment';

// ..

export class InvoiceService {

    constructor(private readonly paymentService: PaymentService) {
    }

    private readonly serviceCode = '00000000-0000-0000-0000-000000000000'

    async createBill(applicationReference: string) {
        const bill = new Bill(applicationReference);
        bill.addCustomerAttribute('email', 'john@example.com')


        const service = new Serivce(this.serviceCode);
        bill.addService(bill)

        const paymentMethod = new PaymentMethod('CreditCard');
        bill.addPaymentMethod(paymentMethod);

        this.paymentService.generateBill(bill, false)
    }
}