Creating Orders

In order to create orders, you need authentication credentials provided to you by the onboarding team. If you have not received the credentials, contact the onboarding team for more info.

A sample merchant server written in nodejs, demonstrating the order creation process can be found in our github repo here

Step 1. Authenticate and create session

In order to create an order, you need to authenticate using the credentials provided and create a secure session.

Credentials Required to create an order

1.API_KEY - Generate an api key in the admin portal

2.IDENTITY_API_URL:
UAT (Test environment) - https://api-gateway.sandbox.ngenius-payments.com/identity/auth/access-token

Production - https://api-gateway.ngenius-payments.com/identity/auth/access-token


3.GATEWAY_API_URL:
UAT (Test environment) - https://api-gateway.sandbox.ngenius-payments.com/transactions/outlets/XXXX/orders

Production - https://api-gateway.ngenius-payments.com/transactions/outlets/XXXX/orders

Note: In the above 2 urls, replace XXXX with your outletId


4.Realm
UAT (Test environment) - ni
Production - networkinternational

The following snippet is an example function implementing the authentication process.

/* 
  IDENTITY_API_URL: URL for udentity service
  API_KEY: API key generated in the merchant portal
  REALM: Realm of the tenant provided by the onboarding team
*/

const axios = require('axios');

function authneticate() {
  try {

    const { data } = await axios({
      method: 'post',
      url: IDENTITY_API_URL,
      headers: {
        'Content-Type': 'application/vnd.ni-identity.v1+json',
        'Authorization': `Basic ${API_KEY}`
      },
      data: {
        grant_type: 'client_credentials',
        realm: REALM,
      }
    });

    const { access_token } = data;
    return { access_token };
  } catch (error) {
    return { error }
  }
}

Step 2. Create Order

After procuring the bearer token, create an order for the requested order object which is received from your mobile app.

The following code snippet is an example function that implements the order creation process

/*  
  GATEWAY_API_URL: URL for payment gateway provided to you by the onboarding team
  access_token: access_token received from the previous step
  orderRequest: orderRequest object sent by the app with the order details.
*/

function createOrder(access_token, orderRequest) {
  try {
    const { data: orderData } = await axios.post(GATEWAY_API_URL, {
      ...orderRequest
    }, {
      headers: {
        'Authorization': `Bearer ${access_token}`,
        'Content-Type': 'application/vnd.ni-payment.v2+json',
        'Accept': 'application/vnd.ni-payment.v2+json'
      },
    },
    );

    res
      .status(200)
      .send(orderData)

  } catch (error) {
    console.error(error);
    res
      .status(400)
      .send({
        error,
        message: 'An error occured',
      });
  }
}

For more info on the fields supported by orderRequest, check out our Create an order