pesepay
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

Installation

npm install pesepay

Getting Started

Import the library into your project/application

const { Pesepay } = require('pesepay')

Create an instance of the Pesepay class using your integration key and encryption key as supplied by Pesepay.

const pesepay = new Pesepay("INTEGRATION KEY", "ENCRYPTION KEY");

Set return and result urls

pesepay.resultUrl = 'https://example.com/result'
pesepay.returnUrl = 'https://example.com/return'

Make seamless payment

Create the payment

NB: Customer email or number should be provided
const payment = pesepay.createPayment('CURRECNCY_CODE', 'PAYMENT_METHOD_CODE', 'CUSTOMER_EMAIL(OPTIONAL)', 'CUSTOMER_PHONE_NUMBER(OPTIONAL)', 'CUSTOMER_NAME(OPTIONAL)')

Create an object of the required fields (if any)

const requiredFields = {'requiredFieldName': 'requiredFieldValue'}

Send of the payment

pesepay.makeSeamlessPayment(payment, 'PAYMENT_REASON', AMOUNT, requiredFields).then(response => {
    if (response.success) {
        // Save the reference number and/or poll url (used to check the status of a transaction)
        const referenceNumber = response.referenceNumber;
        const pollUrl = response.pollUrl

    } else {
        // Get Error Message  
        const message = res.message;
    }
});

Make redirect payment

Create a transaction

const transaction = pesepay.createTransaction(amount, 'CURRENCY_CODE', 'PAYMENT_REASON')

Initiate the transaction

pesepay.initiateTransaction(transaction).then(response => {
    if (response.success) {
        // Save the reference number and/or poll url (used to check the status of a transaction)
        const referenceNumber = response.referenceNumber;
        const pollUrl = response.pollUrl

        // Get the redirect url and redirect user to complete transaction 
        const redirectUrl = response.redirectUrl

    } else {
        // Get Error Message  
        const message = res.message;
    }
});

Check Payment Status

Method 1: Check using reference number

pesepay.checkPayment(referenceNumber).then(response => {
    if (response.success) {
        if (response.paid) {
            // Payment was successful
        }
    } else {
        // Get Error Message  
        const message = res.message;
    }
});

Method 2: Check using poll url

pesepay.pollTransaction(pollUrl).then(response => {
    if (response.success) {
        if (response.paid) {
            // Payment was successful
        }
    } else {
        // Get Error Message  
        const message = res.message;
    }
});

Readme

Keywords

none

Package Sidebar

Install

npm i pesepay

Weekly Downloads

3

Version

1.0.3

License

MIT

Unpacked Size

43.1 kB

Total Files

42

Last publish

Collaborators

  • codevirtus