0.1.3 • Published 5 years ago

@coderscolony/payment-router-node-client v0.1.3

Weekly downloads
3
License
MIT
Repository
-
Last release
5 years ago

Getting Started With Payment Router NodeJS Client

Installation

npm install --save @coderscolony/payment-router-node-client

Example Usage

Payment List

const { Client } = require('@coderscolony/payment-router-node-client');

const client = new Client({
  app_id: process.env.PAYMENT_ROUTER_CLIENT_APP_ID,
  app_secret: process.env.PAYMENT_ROUTER_CLIENT_APP_SECRET,
  server_url: process.env.PAYMENT_ROUTER_CLIENT_SERVER_URL,
});

(async()=>{
  const payment_list = await client.paymentList();
  console.log({ payment_list })
})()

Create Submit Form

const { Client } = require('@coderscolony/payment-router-node-client');

const client = new Client({
  app_id: process.env.PAYMENT_ROUTER_CLIENT_APP_ID,
  app_secret: process.env.PAYMENT_ROUTER_CLIENT_APP_SECRET,
  server_url: process.env.PAYMENT_ROUTER_CLIENT_SERVER_URL,
});

const form = client.createSubmitForm({
  bill_no: "XYZABC",
  bill_reff: "123039303",
  bill_date: "2018-07-06 14:26:31",
  bill_expired: "2020-07-06 16:26:31",
  bill_desc: "Test Payment",
  bill_currency: "IDR",
  bill_gross: 81000,
  bill_tax: 0,
  bill_miscfee: 0,
  bill_total: 81000,
  cust_no: "123",
  cust_name: "John Doe",
  phone: "+6281234567890",
  email: "john.doe@example.com",
  pay_type: "122",
  billing_address: "Jl. Raya No. 123",
  billing_address_city: "Kota Jakarta Pusat",
  billing_address_region: "Kota Jakarta Pusat",
  billing_address_state: "Kota Jakarta Pusat",
  billing_address_poscode: "10160",
  billing_address_country_code: "ID",
  payment_reff: "John Doe",
  receiver_name_for_shipping: "Jl. Raya No. 123",
  shipping_address: "Kota Jakarta Pusat",
  shipping_address_city: "Kota Jakarta Pusat",
  shipping_address_region: "Kota Jakarta Pusat",
  shipping_address_state: "12345",
  shipping_address_poscode: "",
  return_url: "http://www.example.com/booking/finish/XYZABC",
  items: [
    {
      product: "Test item",
      qty: 1,
      amount: 81000,
      tenor: 0,
      product_type: "tour",
      product_url: "http://www.example.com/product/tour/XYZABC",
    },
  ],
});

console.log({ form })

Handle notification

const express = require('express');
const { Client, PaymentStatus } = require('@coderscolony/payment-router-node-client');

const app = express();

app.post('/payment/notification', async(req, res) => {
  try {
    const response = await client.getNotificationFromRequest(req.body);

    if(response.status === PaymentStatus.SUCCESS){
      // add your paid listener
    }else{
      // add your failed listener
    }

  } catch (error) {
    console.log(`Payment Notification Error: ${error}`)
  }
});

const main = async()=>{

  app.listen(3000);
}

main();