Creating Orders

To process payments through N-Genius, your server must first authenticate with our identity service and then create an order with the payment gateway. This flow is common across SDK, API, and plugin integrations.

To create orders through the N-Genius platform, your merchant server must authenticate and communicate with the N-Genius API. This process is essential for both mobile and web integrations.

📘

This guide is backend-focused and applies to all platforms.

If you're using the Android or iOS SDK, your app will send order details to your server, which then handles authentication and order creation.

The flow diagram demonstrates the steps taken to create an order from web or mobile devices.

Create Order Flow

Step 1: Authenticate and Create a Session

Before creating an order, your server must authenticate using credentials provided during onboarding.

Required Credentials

KeyDescription
API_KEYGenerated in the admin portal
IDENTITY_API_URLAuth endpoint:
UAT: https://api-gateway.sandbox.ngenius-payments.com/identity/auth/access-token
Production: https://api-gateway.ngenius-payments.com/identity/auth/access-token
GATEWAY_API_URLOrder endpoint:
UAT: - https://api-gateway.sandbox.ngenius-payments.com/transactions/outlets/XXXX/orders
Production - https://api-gateway.ngenius-payments.com/transactions/outlets/XXXX/orders
REALMUAT: ni
Production: networkinternational

Sample Authentication Function (Node.js)

const axios = require('axios');

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

    return { access_token: data.access_token };
  } catch (error) {
    console.error('Authentication failed:', error);
    return { error };
  }
}

📘

Prefer PHP? View our PHP Merchant Server implementation on GitHub (link it to the repo)

Step 2: Create an Order

Once authenticated, use the bearer token to create an order.

Required Endpoint

📘

Replace XXXX with your outletid.

Sample orderRequest object

{
  "action": "SALE",
  "amount": {
    "currencyCode": "AED",
    "value": 1000
  },
  "merchantAttributes": {
    "redirectUrl": "https://yourdomain.com/callback",
    "cancelUrl": "https://yourdomain.com/cancel"
  }
}

Sample Order Creation Function (Node.js)

async 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'
      }
    });

    return orderData;
  } catch (error) {
    console.error('Order creation failed:', error);
    return {
      error,
      message: 'An error occurred while creating the order',
    };
  }
}

Step 3: Handle Payment Status Callbacks

Once a payment is completed or canceled, the N-Genius platform sends a webhook (callback) to your server with the transaction result.

To learn how to set up and handle these callbacks securely, see our Consuming Webhooks guide.

This ensures your system stays up to date with payment statuses and can trigger the next steps in your business logic.

Additional Resources