1.0.2 • Published 8 months ago

@ks-libs/fort v1.0.2

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

Payfort Library for Next JS, Remix and Node JS Frameworks

A Node client library wrapper the Payfort API

Prerequisite

Your need to create a Payfort Account, if you don't have one already, to get your integration staging and production key.

Installation

npm install @fm/payfort --save

Usage

Import and initialize the library:

const { Payfort } = require('@fm/payfort')
this.payFort = new Payfort({
      'accessCode',
      'merchantIdentifier',
      'passphrase',
      mode: 'sandbox',
    });

this.payFort.payWithCreditCard(dto).then(response => console.log(response)).catch(error => console.log(error))

Import and initialize the library using ES module with async/await:

import { Payfort } from '@fm/payfort'
this.payFort = new Payfort({
      'accessCode',
      'merchantIdentifier',
      'passphrase',
      mode: 'sandbox',
    });

this.payFort.payWithCreditCard(dto).then(response => console.log(response)).catch(error => console.log(error))

Tokenization

import {
  CardTokenizationDto,
  Tokenization,
} from '@fm/payfort';

async tokenizeCard(dto: CardTokenizationDto) {
    try {
      const tokenInstance = new Tokenization({ passphrase, mode: 'sandbox' });
      const token = await tokenInstance.handleCardTokenization(dto);
      return token;
    } catch (error: any) {
      throw new Error(error?.message, 500);
    }
  }

Pay with Tokenized Card

import {
  Payfort,
  CardPaymentDto
} from '@fm/payfort';

async payWithTokenizedCard(dto: CardPaymentDto) {
    import { Payfort } from '@fm/payfort'
    this.payFort = new Payfort({
      'accessCode',
      'merchantIdentifier',
      'passphrase',
      mode: 'sandbox',
    });
    try {
      return await this.payFort.payWithTokenizedCard(dto);
    } catch (error: any) {
      throw new Error(error?.message, 500);
    }
  }

Generate STC Pay OTP

import { Payfort, CardPaymentDto } from '@fm/payfort';
import { Payfort } from '@ks-libs/fort'

this.payFort = new Payfort({
      'accessCode',
      'merchantIdentifier',
      'passphrase',
      mode: 'sandbox',
    });
  async generateOtp(dto: GenerateOtpDto) {
    try {
      return await this.payFort.generateStcPayOtp(dto);
    } catch (error: any) {
      throw new HttpException(error?.message, 500);
    }
  }

Pay with STC Pay

import {
  Payfort,
  CardPaymentDto
} from '@fm/payfort';
import { Payfort } from '@fm/payfort'

this.payFort = new Payfort({
      'accessCode',
      'merchantIdentifier',
      'passphrase',
      mode: 'sandbox',
    });
 async payWithStc(dto: StcPayPurchaseDto) {
    try {
      return await this.payFort.makeStcPay(dto);
    } catch (error: any) {
      throw new HttpException(error?.message, 500);
    }
  }

Issues

Kindly open an issue if you discover any bug or have problems using this library.

License

This repository is made available under the MIT license. Kindly read the LICENSE file for more information.

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

9 months ago