Checkout with inai APIs

Supporting payments through inai's APIs is just 3 steps

Goal

If you're a developer you can use inai's APIs to develop your own checkout flow. This document explains how.

Outline

We want our APIs to be easy and simple to understand. If you disagree, please share your feedback at the Discussions page. We welcome your feedback and constantly look to improve.

At the highest level, the following sequence diagram details what happens during a payment.

This sequence diagram shows what happens during an online payment.

"you" refers to you, the reader of this guide, integrating with inai to easily accept payments.  There are two parts, your frontend and your backend.

"Payment Provider" is the service who accepts your payments.  Typical examples are Stripe, PayPal, Mollie, or Razorpay.

This sequence diagram was generated using PlantUML.This sequence diagram shows what happens during an online payment.

"you" refers to you, the reader of this guide, integrating with inai to easily accept payments.  There are two parts, your frontend and your backend.

"Payment Provider" is the service who accepts your payments.  Typical examples are Stripe, PayPal, Mollie, or Razorpay.

This sequence diagram was generated using PlantUML.

This sequence diagram shows what happens during an online payment.

"you" refers to you, the reader of this guide, integrating with inai to easily accept payments. There are two parts, your frontend and your backend.

"Payment Provider" is the service who accepts your payments. Typical examples are Stripe, PayPal, Mollie, or Razorpay.

This sequence diagram was generated using PlantUML.

As is evident from the above sequence diagram, you make 3 calls to inai. These are:

Steps

  1. Create an order
  2. Show your customer their available payment methods
  3. Send your customer's payment details to inai

Let's look at each in turn.

1. Create an order

The order specifies the most basic elements of your customer's order. In the simplest case this is the amount and currency you're charging your customer. A purchase of $31.41 will be sent as { "order": { "currency": "USD", "amount": "31.41", "customer": {"email": "[email protected]"} } }.

curl -XPOST                                                        \
        --header 'Authorization: Basic Base64(username:password)'  \
        --header 'Content-Type: application/json'                  \
        --header 'Accept: application/json'                        \
        --compressed                                               \
        https://api.inai.io/v1/orders                              \
        -d '{
              "amount": "31.41", 
              "currency": "USD",
              "customer": {
                "email": "[email protected]"
              }
            }'
from base64 import b64encode
import requests

username, password = 'up' # take these from your dashboard
url = "https://api.inai.io/v1/orders"
authz = b64encode(bytes(f'{username}:{password}', 'us-ascii'))
headers = {
    "Accept": "application/json",
    "Content-Type": "application/json",
    "Authorization": authz
}
payload = {
    "amount": "31.41",
    "currency": "USD",
    "customer": {"email": "[email protected]"}
}
response = requests.request(
        "POST", url, 
        json-payload, headers=headers)
print(response.text)

Once your order is created, the inai API responds with an order_id. Once you have an order_id you are ready for the next step: showing your customer their available payment options.

2. Show your customer their available payment methods

With the order_id from step 1, call inai's payment options. This is a simple GET call as illustrated by the code snippet shown below.

ORDER_ID=... # populate from step 1
curl --request GET                                                     \
     --url "https://api.inai.io/v1/orders/${ORDER_ID}/payment-options" \
     --header 'Accept: application/json'
import requests
order_id = ... ## fill from step 1
url = f"https://api.inai.io/v1/orders/{order_id}/payment-options"
headers = {"Accept": "application/json"}
response = requests.request("GET", url, headers=headers)
print(response.text)
require 'uri'
require 'net/http'
require 'openssl'

order_id = ... ## fill from step 1
url = URI("https://api.inai.io/v1/orders/#{order_id}/payment-options")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["Accept"] = 'application/json'

response = http.request(request)
puts response.read_body

The response lists available payment options. These options are determined by the configurations you've made on inai's dashboard. A sample response is as shown below.

{
  "options": [
    { "rail": "credit_card" }
  ]
}

Show the available payment options to your customer so they may choose how to complete their transaction. Once they have chosen and entered their payment details, there's only one thing left to do: send your customer's payment details to inai. This is discussed in the following section that has the rather obvious name:

3. Send your customer's payment details to inai

At this point you will have displayed the modes of payment available to your customer and are invited to pay with mode of choice. Once you accept their payment details, submit these details to inai via our Payments API. For instance, for a card transaction, your customer will have provided their card number, expiration date, name as on the card. The details can be submitted as shown below.

curl --request POST                            \
     --url https://api.inai.io/v1/payments     \
     --header 'Accept: application/json'       \
     --header 'Content-Type: application/json' \
     --data '{
               "details": {
                 "card": {
                   "holder_name": "John Doe",
                   "number": "5105105105105100",
                   "exp_month": 5,
                   "exp_year": 2030,
                   "cvc": "314"
                 },
                 "currency": "USD",
                 "amount": "31.41"
               },
               "rail": "card",
               "order_id": "00decade-c0da-feed-c0ffeedec0de"
             }'

That's it! inai will complete the transaction with your configured Payment Provider. The response will contain the result of your transaction which you can show your customer.

You can also get an aggregated view of your past transactions in inai's Transactions page.