@Thawani node docs
This Documentation is to make the development process easier for you

Thawani-node

Thawani node is a nodejs client for Thawani API this document is didicated for the pure purpose of migration of the plugin before the version 1.1.0

if you have the early version before 1.1.0 the the class initialization will be this way The documentation of the previous version prior to version 1.1.0 is here

const api = new ThawaniClient(
  "your_secret_key",
  "your_publishable_key",
  "dev|prod"
);

and now it's like this

const api = new ThawaniClient({
  secretKey: 'your_app_secret_key', 
  publishableKey : 'your_app_publishable_key',
  dev : true // false to set it for production 
});

and this change can break your code or application

Initialize

Before we start

Take a look in the developer docs so you have a better about the idea and the payload of each endpoint & you may not need this package if you are aiming to use only 1 or 2 end-points

  • Note : This plugin just helps you to get the the integration fast
    • The package does not provide any helper function for formatting the payload

    • The package does not validate your payload

Initialize

const api = new ThawaniClient({
  secretKey: 'your_app_secret_key', 
  publishableKey : 'your_app_publishable_key',
  dev : true, // false to set it for production 
  filter: { // optional 
      skip: 1, 
      limit:10
  }
});
  • secretKey - required the secret key provided by Thawani
  • publishableKey - require the publishable key provided by Thawani
  • dev - required if this value set to true then the API will call the development end-points
  • filter - optional by default the filter object has two keys skip and limit and they represent the page number and the result in each page
    • skip - optional page number default set to 1
    • limit - optional number of result in each page default is 10 and the max is 50.

sessions

Sessions API are responsible of creating the payment and redirecting the user to Thawani checkout page

note all the function are promised based.

Create new session

 await api.session.create(payload);

Redirect to pay

const redirectFullURL = api.redirect(session_id);

get the session by id

 await  api.sesssion.getSessionByID(session_id); // return a promise

get all the sessions

await api.session.findAll();

or you can pass filter object same as the class construct

await api.session.findAll({
    skip :2, 
    limit: 20
});

Find session by reference

await api.session.findSessionByReference(session_number); 

Find session by receipt number

await api.session.findSessionByReceipt(receipt_number); 

Customer End-point

The customer endpoint allow you to create a customer token in order for saving the customer credit card in Thawani servers and skipping the payment method when purchasing again

all the endpoints returns a promise

Create customer

You can pass any thing is unique to the customer his email or phone number

await api.customer.create(customer_id)

Find Customer

By passing the customer token

await api.customer.find(customer_token); 

Find all customers

await api.customer.findAll(); 

or by passing a filter

await api.customer.findAll({
    skip:1, 
    limit:30
}); 

Remove customer

await api.customer.remove(customer_token); 

payments

Payments endpoint shows the card type the customer uses

Find a payment

await api.payment.find(customer_token)

Remove a payment

await api.payment.remove(card_token)

Payment Transaction

Get the payment transaction details

Find payment transaction

await api.paymentTransaction.find(payment_id); 

Find All payments transactions

await api.paymentTransaction.findAll();

Or by passing a filter as a parameter

await api.paymentTransaction.findAll({
    skip:1, 
    limit:12
});

Refund API

Refund APi for getting refund to the client directly before the amount transferred to your account

Create a refund

await api.refund.create(payload);

Find a refund

await api.refund.find();

Find all refunds

await api.refund.findAll();

or by passing a filter

await api.refund.findAll({
    skip:2,
    limit:12
});

Payment Intent

This endpoint to create a quick payments

Create a payment

await api.paymentIntent.create(payload); 

Confirm a payment

await api.paymentIntent.confirm(paymentIntent_id); 

Cancel a payment

await api.paymentIntent.create(paymentIntent_id); 

Find a payment

await api.paymentIntent.find(paymentIntent_id); 

Find payment by reference

await api.paymentIntent.findByReference(reference_id); 

Find all

await api.paymentIntent.findAll(); 

or by passing a filter as parameter

await api.paymentIntent.findAll({
    skip:2,
    limit:10
}); 
Crafted with 🔨 Nuxtjs & tailwindcss