Checkout API
How to create check-out page using IntaSend 's checkout API

How to use REST API to create a sharable payment URL

To create a checkout page, a payment checkout URL that can be shared to the client to complete payment on email or social media, simply send a post request to /api/v1/checkout/ with the payment data parameters as payload.

Code examples

Send POST request to generate a checkout URL, then redirect the user to the checkout link to securely complete payment.
Curl
Go
JavaScript
PHP
Python
1
curl --location --request POST 'https://sandbox.intasend.com/api/v1/checkout/' \
2
--header 'Content-Type: application/json' \
3
--header 'Cookie: csrftoken=RJXYBwzJ3IeqxgrNZ0iRFblmo9dOO6Sr6PiCjkrwrmu5LUYDTuNJanEbVwWveodC' \
4
--data-raw '{
5
"public_key": "<YOUR-PUBLISHABLE-API-KEY>",
6
"amount": 10,
7
"currency": "USD",
8
"email": "[email protected]",
9
"first_name": "John",
10
"last_name": "Doe",
11
"country": "US"
12
}'
Copied!
1
package main
2
3
import (
4
"fmt"
5
"strings"
6
"net/http"
7
"io/ioutil"
8
)
9
10
func main() {
11
12
url := "https://sandbox.intasend.com/api/v1/checkout/"
13
method := "POST"
14
15
payload := strings.NewReader(`{
16
"public_key": "<YOUR-PUBLISHABLE-API-KEY>",
17
"amount": 10,
18
"currency": "USD",
19
"email": "[email protected]",
20
"first_name": "John",
21
"last_name": "Doe",
22
"country": "US"
23
}`)
24
25
client := &http.Client {
26
}
27
req, err := http.NewRequest(method, url, payload)
28
29
if err != nil {
30
fmt.Println(err)
31
return
32
}
33
req.Header.Add("Content-Type", "application/json")
34
35
res, err := client.Do(req)
36
if err != nil {
37
fmt.Println(err)
38
return
39
}
40
defer res.Body.Close()
41
42
body, err := ioutil.ReadAll(res.Body)
43
if err != nil {
44
fmt.Println(err)
45
return
46
}
47
fmt.Println(string(body))
48
}
Copied!
1
var axios = require('axios');
2
var data = JSON.stringify({"public_key":"<YOUR-PUBLISHABLE-API-KEY>","amount":10,"currency":"USD","email":"[email protected]","first_name":"John","last_name":"Doe","country":"US"});
3
4
var config = {
5
method: 'post',
6
url: 'https://sandbox.intasend.com/api/v1/checkout/',
7
headers: {
8
'Content-Type': 'application/json'
9
},
10
data : data
11
};
12
13
axios(config)
14
.then(function (response) {
15
console.log(JSON.stringify(response.data));
16
})
17
.catch(function (error) {
18
console.log(error);
19
});
20
Copied!
1
<?php
2
3
$curl = curl_init();
4
5
curl_setopt_array($curl, array(
6
CURLOPT_URL => 'https://sandbox.intasend.com/api/v1/checkout/',
7
CURLOPT_RETURNTRANSFER => true,
8
CURLOPT_ENCODING => '',
9
CURLOPT_MAXREDIRS => 10,
10
CURLOPT_TIMEOUT => 0,
11
CURLOPT_FOLLOWLOCATION => true,
12
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
13
CURLOPT_CUSTOMREQUEST => 'POST',
14
CURLOPT_POSTFIELDS =>'{
15
"public_key": "<YOUR-PUBLISHABLE-API-KEY>",
16
"amount": 10,
17
"currency": "USD",
18
"email": "[email protected]",
19
"first_name": "John",
20
"last_name": "Doe",
21
"country": "US"
22
}',
23
CURLOPT_HTTPHEADER => array(
24
'Content-Type: application/json'
25
),
26
));
27
28
$response = curl_exec($curl);
29
30
curl_close($curl);
31
echo $response;
32
Copied!
1
import requests
2
3
url = "https://sandbox.intasend.com/api/v1/checkout/"
4
5
payload={
6
"public_key":"<YOUR-PUBLISHABLE-API-KEY>",
7
"amount": 10,
8
"currency": "USD",
9
"email": "[email protected]",
10
"first_name": "John",
11
"last_name": "Doe",
12
"country": "US"
13
}
14
headers = {
15
'Content-Type': 'application/json'
16
}
17
18
response = requests.request("POST", url, headers=headers, data=payload)
19
20
print(response.text)
21
Copied!

Response

The checkout request returns a JSON response with a url field. Redirect the user to the url to securely complete payment.
1
{
2
"id": "666f4283-ffb2-4633-8c30-5338a50be37d",
3
"url": "https://sandbox.intasend.com/checkout/666f4283-ffb2-4633-8c30-5338a50be37d/express/",
4
"signature": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzY29wZSI6ImV4cHJl....",
5
"first_name": "John",
6
"last_name": "Doe",
7
"phone_number": null,
8
"email": "[email protected]",
9
"country": "US",
10
"address": null,
11
"city": null,
12
"state": null,
13
"zipcode": null,
14
"api_ref": null,
15
"amount": "10.00",
16
"currency": "USD",
17
"mobile_tarrif": "BUSINESS-PAYS",
18
"card_tarrif": "BUSINESS-PAYS",
19
"created_at": "2021-08-05T10:53:08.761765+03:00",
20
"updated_at": "2021-08-05T10:53:08.761794+03:00"
21
}
Copied!

Code Example using Axios (JavaScript)

Here is a quick example of how to create a link using JavaScript. Note this can be done from any backend e.g PHP, Python, and Java

1. Install Axios

We'll use Axios to send HTTP post requests. Feel free to use any other tool that works well for you.
1
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.21.1/axios.min.js"></script>
Copied!
Send a POST request to the API environment that you'd wish to create the link. Learn more on test and live environment here.
A successful request will return an url which in this case will be our check-out URL. Share this url with the customer for them to complete payment.
1
function generateLink() {
2
// Use https://payment.intasend.com/api/v1/checkout/ for live payments
3
let url = "https://sandbox.intasend.com/api/v1/checkout/"
4
let payload = {
5
public_key: "REPLACE-WITH-YOUR-PUBLISHABLE-KEY",
6
amount: 10,
7
currency: "KES",
8
9
first_name: "John",
10
last_name: "Doe",
11
country: "US"
12
}
13
axios.post(url, payload).then((resp) => {
14
if (resp.data.url) {
15
window.open(resp.data.url, '_blank').focus();
16
}
17
}).catch((err) => alert("Problem experienced while initializing your request: " + err))
18
}
Copied!
Trigger the above function using on-click event. Here is a sample button for your reference.
1
<button onclick="generateLink()">Pay now</button>
Copied!
Last modified 2d ago