SourceSage Pay

SourceSage Pay

  • Docs
  • Help
  • Register

›Integration Guide

Getting Started

  • Overview
  • Get an API Key
  • Project Configuration

APIs

  • Overview
  • SourceSage Pay Session
  • SourceSage Pay Transactions

Integration Guide

  • Overview
  • 1. Initialize Session
  • 2. Trigger Payment
  • 3. Handle Response

1. Initialize Session

In this section, we will look into how a session can be initialized

1.1 Backend: Call Session API

To create a session , we will have to call the /create-session endpoint by passing the amount, currency and description of the transaction.

This process needs to happen on the backend since it needs to be authenticated using your access_token. This token can be misused if visible on the frontend, and hence needs to be restricted to the backend.

Ignoring the security aspect, you will not be allowed the make this call from the backend due to cross-origin-resource-sharing restrictions on the browser.

Below is an example of how the session can be created. The example is a nodejs express api and axios.

const app = express();
const BASE_URL = process.env.BASE_URL;
const TOKEN = process.env.SS_PAY_TOKEN;
//...

app.get("/checkout-session", async (request, response) => {
  //Your internal process of obtaining the order amount, currency etc
  const order = create_order_from_cart();

  const { data } = await axios.post(
    BASE_URL + "payments/create-session",
    {
      amount: order.amount,
      currency: order.currency,
      description: order.description,
    },
    {
      headers: {
        "X-SS-EXTERNAL-TOKEN": TOKEN,
      },
    }
  );

  //...
  return response.json({ data });
});

//...

1.2 Frontend: Create Session

Next, we will be using the api created on the backend, on our frontend, preferably the checkout page. Below is the sample code that achieves this.

  const checkout = ({reference_number, checkout_payload}) => {
    //... will be done in the next step
  };

  Axios.get(`/api/payments/checkout-session/`).then((res) => {
    checkout(res.data);
  });

In the next page, we will look into initiating the payment via hosted checkout

← Overview2. Trigger Payment →
  • 1.1 Backend: Call Session API
  • 1.2 Frontend: Create Session
SourceSage Pay
Docs
Getting StartedGuidesAPI Reference
Community
User Showcase
More
GitHub
Copyright © 2020 Sourcesage