curl --request POST \
--url https://api.sandbox.primer.io/client-session \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data '
{
"orderId": "order-abc",
"currencyCode": "GBP",
"amount": 1000,
"order": {
"lineItems": [
{
"itemId": "shoe-123",
"description": "Blue Shoe",
"amount": 100,
"quantity": 10
}
],
"countryCode": "FR"
},
"customerId": "customer-123",
"customer": {
"emailAddress": "john@primer.io"
},
"metadata": {
"productType": "Shoes"
},
"paymentMethod": {
"descriptor": "Purchase: Shoes",
"paymentMethodType": "PAYMENT_CARD",
"vaultOnSuccess": true,
"options": {
"PAYMENT_CARD": {
"networks": {
"VISA": {
"surcharge": {
"amount": 10
}
}
}
},
"GOOGLE_PAY": {
"surcharge": {
"amount": 20
}
}
}
}
}
'import requests
url = "https://api.sandbox.primer.io/client-session"
payload = {
"orderId": "order-abc",
"currencyCode": "GBP",
"amount": 1000,
"order": {
"lineItems": [
{
"itemId": "shoe-123",
"description": "Blue Shoe",
"amount": 100,
"quantity": 10
}
],
"countryCode": "FR"
},
"customerId": "customer-123",
"customer": { "emailAddress": "john@primer.io" },
"metadata": { "productType": "Shoes" },
"paymentMethod": {
"descriptor": "Purchase: Shoes",
"paymentMethodType": "PAYMENT_CARD",
"vaultOnSuccess": True,
"options": {
"PAYMENT_CARD": { "networks": { "VISA": { "surcharge": { "amount": 10 } } } },
"GOOGLE_PAY": { "surcharge": { "amount": 20 } }
}
}
}
headers = {
"X-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
orderId: 'order-abc',
currencyCode: 'GBP',
amount: 1000,
order: {
lineItems: [{itemId: 'shoe-123', description: 'Blue Shoe', amount: 100, quantity: 10}],
countryCode: 'FR'
},
customerId: 'customer-123',
customer: {emailAddress: 'john@primer.io'},
metadata: {productType: 'Shoes'},
paymentMethod: {
descriptor: 'Purchase: Shoes',
paymentMethodType: 'PAYMENT_CARD',
vaultOnSuccess: true,
options: {
PAYMENT_CARD: {networks: {VISA: {surcharge: {amount: 10}}}},
GOOGLE_PAY: {surcharge: {amount: 20}}
}
}
})
};
fetch('https://api.sandbox.primer.io/client-session', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.sandbox.primer.io/client-session",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'orderId' => 'order-abc',
'currencyCode' => 'GBP',
'amount' => 1000,
'order' => [
'lineItems' => [
[
'itemId' => 'shoe-123',
'description' => 'Blue Shoe',
'amount' => 100,
'quantity' => 10
]
],
'countryCode' => 'FR'
],
'customerId' => 'customer-123',
'customer' => [
'emailAddress' => 'john@primer.io'
],
'metadata' => [
'productType' => 'Shoes'
],
'paymentMethod' => [
'descriptor' => 'Purchase: Shoes',
'paymentMethodType' => 'PAYMENT_CARD',
'vaultOnSuccess' => true,
'options' => [
'PAYMENT_CARD' => [
'networks' => [
'VISA' => [
'surcharge' => [
'amount' => 10
]
]
]
],
'GOOGLE_PAY' => [
'surcharge' => [
'amount' => 20
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-KEY: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.sandbox.primer.io/client-session"
payload := strings.NewReader("{\n \"orderId\": \"order-abc\",\n \"currencyCode\": \"GBP\",\n \"amount\": 1000,\n \"order\": {\n \"lineItems\": [\n {\n \"itemId\": \"shoe-123\",\n \"description\": \"Blue Shoe\",\n \"amount\": 100,\n \"quantity\": 10\n }\n ],\n \"countryCode\": \"FR\"\n },\n \"customerId\": \"customer-123\",\n \"customer\": {\n \"emailAddress\": \"john@primer.io\"\n },\n \"metadata\": {\n \"productType\": \"Shoes\"\n },\n \"paymentMethod\": {\n \"descriptor\": \"Purchase: Shoes\",\n \"paymentMethodType\": \"PAYMENT_CARD\",\n \"vaultOnSuccess\": true,\n \"options\": {\n \"PAYMENT_CARD\": {\n \"networks\": {\n \"VISA\": {\n \"surcharge\": {\n \"amount\": 10\n }\n }\n }\n },\n \"GOOGLE_PAY\": {\n \"surcharge\": {\n \"amount\": 20\n }\n }\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-KEY", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.sandbox.primer.io/client-session")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"orderId\": \"order-abc\",\n \"currencyCode\": \"GBP\",\n \"amount\": 1000,\n \"order\": {\n \"lineItems\": [\n {\n \"itemId\": \"shoe-123\",\n \"description\": \"Blue Shoe\",\n \"amount\": 100,\n \"quantity\": 10\n }\n ],\n \"countryCode\": \"FR\"\n },\n \"customerId\": \"customer-123\",\n \"customer\": {\n \"emailAddress\": \"john@primer.io\"\n },\n \"metadata\": {\n \"productType\": \"Shoes\"\n },\n \"paymentMethod\": {\n \"descriptor\": \"Purchase: Shoes\",\n \"paymentMethodType\": \"PAYMENT_CARD\",\n \"vaultOnSuccess\": true,\n \"options\": {\n \"PAYMENT_CARD\": {\n \"networks\": {\n \"VISA\": {\n \"surcharge\": {\n \"amount\": 10\n }\n }\n }\n },\n \"GOOGLE_PAY\": {\n \"surcharge\": {\n \"amount\": 20\n }\n }\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sandbox.primer.io/client-session")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"orderId\": \"order-abc\",\n \"currencyCode\": \"GBP\",\n \"amount\": 1000,\n \"order\": {\n \"lineItems\": [\n {\n \"itemId\": \"shoe-123\",\n \"description\": \"Blue Shoe\",\n \"amount\": 100,\n \"quantity\": 10\n }\n ],\n \"countryCode\": \"FR\"\n },\n \"customerId\": \"customer-123\",\n \"customer\": {\n \"emailAddress\": \"john@primer.io\"\n },\n \"metadata\": {\n \"productType\": \"Shoes\"\n },\n \"paymentMethod\": {\n \"descriptor\": \"Purchase: Shoes\",\n \"paymentMethodType\": \"PAYMENT_CARD\",\n \"vaultOnSuccess\": true,\n \"options\": {\n \"PAYMENT_CARD\": {\n \"networks\": {\n \"VISA\": {\n \"surcharge\": {\n \"amount\": 10\n }\n }\n }\n },\n \"GOOGLE_PAY\": {\n \"surcharge\": {\n \"amount\": 20\n }\n }\n }\n }\n}"
response = http.request(request)
puts response.read_bodyCreate a client session
Creating a client session generates a client token: a temporary key used to initialize Universal Checkout and authenticate it against your account.
Universal Checkout automatically retrieves all the settings from the client session and the Dashboard to configure the payment methods and the checkout experience.
Note:
When creating a Client Session, please make sure to provide currencyCode, orderId, and at least one of amount or lineItems.
If any of these are not yet available, you can provide them when making the payment request.
POST /client-session does not have required fields as all fields are not always known when a client session is created.
Use PATCH /client-session to update the parameters throughout the checkout session.
Client tokens expire after 24 hours.
curl --request POST \
--url https://api.sandbox.primer.io/client-session \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data '
{
"orderId": "order-abc",
"currencyCode": "GBP",
"amount": 1000,
"order": {
"lineItems": [
{
"itemId": "shoe-123",
"description": "Blue Shoe",
"amount": 100,
"quantity": 10
}
],
"countryCode": "FR"
},
"customerId": "customer-123",
"customer": {
"emailAddress": "john@primer.io"
},
"metadata": {
"productType": "Shoes"
},
"paymentMethod": {
"descriptor": "Purchase: Shoes",
"paymentMethodType": "PAYMENT_CARD",
"vaultOnSuccess": true,
"options": {
"PAYMENT_CARD": {
"networks": {
"VISA": {
"surcharge": {
"amount": 10
}
}
}
},
"GOOGLE_PAY": {
"surcharge": {
"amount": 20
}
}
}
}
}
'import requests
url = "https://api.sandbox.primer.io/client-session"
payload = {
"orderId": "order-abc",
"currencyCode": "GBP",
"amount": 1000,
"order": {
"lineItems": [
{
"itemId": "shoe-123",
"description": "Blue Shoe",
"amount": 100,
"quantity": 10
}
],
"countryCode": "FR"
},
"customerId": "customer-123",
"customer": { "emailAddress": "john@primer.io" },
"metadata": { "productType": "Shoes" },
"paymentMethod": {
"descriptor": "Purchase: Shoes",
"paymentMethodType": "PAYMENT_CARD",
"vaultOnSuccess": True,
"options": {
"PAYMENT_CARD": { "networks": { "VISA": { "surcharge": { "amount": 10 } } } },
"GOOGLE_PAY": { "surcharge": { "amount": 20 } }
}
}
}
headers = {
"X-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
orderId: 'order-abc',
currencyCode: 'GBP',
amount: 1000,
order: {
lineItems: [{itemId: 'shoe-123', description: 'Blue Shoe', amount: 100, quantity: 10}],
countryCode: 'FR'
},
customerId: 'customer-123',
customer: {emailAddress: 'john@primer.io'},
metadata: {productType: 'Shoes'},
paymentMethod: {
descriptor: 'Purchase: Shoes',
paymentMethodType: 'PAYMENT_CARD',
vaultOnSuccess: true,
options: {
PAYMENT_CARD: {networks: {VISA: {surcharge: {amount: 10}}}},
GOOGLE_PAY: {surcharge: {amount: 20}}
}
}
})
};
fetch('https://api.sandbox.primer.io/client-session', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.sandbox.primer.io/client-session",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'orderId' => 'order-abc',
'currencyCode' => 'GBP',
'amount' => 1000,
'order' => [
'lineItems' => [
[
'itemId' => 'shoe-123',
'description' => 'Blue Shoe',
'amount' => 100,
'quantity' => 10
]
],
'countryCode' => 'FR'
],
'customerId' => 'customer-123',
'customer' => [
'emailAddress' => 'john@primer.io'
],
'metadata' => [
'productType' => 'Shoes'
],
'paymentMethod' => [
'descriptor' => 'Purchase: Shoes',
'paymentMethodType' => 'PAYMENT_CARD',
'vaultOnSuccess' => true,
'options' => [
'PAYMENT_CARD' => [
'networks' => [
'VISA' => [
'surcharge' => [
'amount' => 10
]
]
]
],
'GOOGLE_PAY' => [
'surcharge' => [
'amount' => 20
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-KEY: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.sandbox.primer.io/client-session"
payload := strings.NewReader("{\n \"orderId\": \"order-abc\",\n \"currencyCode\": \"GBP\",\n \"amount\": 1000,\n \"order\": {\n \"lineItems\": [\n {\n \"itemId\": \"shoe-123\",\n \"description\": \"Blue Shoe\",\n \"amount\": 100,\n \"quantity\": 10\n }\n ],\n \"countryCode\": \"FR\"\n },\n \"customerId\": \"customer-123\",\n \"customer\": {\n \"emailAddress\": \"john@primer.io\"\n },\n \"metadata\": {\n \"productType\": \"Shoes\"\n },\n \"paymentMethod\": {\n \"descriptor\": \"Purchase: Shoes\",\n \"paymentMethodType\": \"PAYMENT_CARD\",\n \"vaultOnSuccess\": true,\n \"options\": {\n \"PAYMENT_CARD\": {\n \"networks\": {\n \"VISA\": {\n \"surcharge\": {\n \"amount\": 10\n }\n }\n }\n },\n \"GOOGLE_PAY\": {\n \"surcharge\": {\n \"amount\": 20\n }\n }\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-KEY", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.sandbox.primer.io/client-session")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"orderId\": \"order-abc\",\n \"currencyCode\": \"GBP\",\n \"amount\": 1000,\n \"order\": {\n \"lineItems\": [\n {\n \"itemId\": \"shoe-123\",\n \"description\": \"Blue Shoe\",\n \"amount\": 100,\n \"quantity\": 10\n }\n ],\n \"countryCode\": \"FR\"\n },\n \"customerId\": \"customer-123\",\n \"customer\": {\n \"emailAddress\": \"john@primer.io\"\n },\n \"metadata\": {\n \"productType\": \"Shoes\"\n },\n \"paymentMethod\": {\n \"descriptor\": \"Purchase: Shoes\",\n \"paymentMethodType\": \"PAYMENT_CARD\",\n \"vaultOnSuccess\": true,\n \"options\": {\n \"PAYMENT_CARD\": {\n \"networks\": {\n \"VISA\": {\n \"surcharge\": {\n \"amount\": 10\n }\n }\n }\n },\n \"GOOGLE_PAY\": {\n \"surcharge\": {\n \"amount\": 20\n }\n }\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sandbox.primer.io/client-session")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"orderId\": \"order-abc\",\n \"currencyCode\": \"GBP\",\n \"amount\": 1000,\n \"order\": {\n \"lineItems\": [\n {\n \"itemId\": \"shoe-123\",\n \"description\": \"Blue Shoe\",\n \"amount\": 100,\n \"quantity\": 10\n }\n ],\n \"countryCode\": \"FR\"\n },\n \"customerId\": \"customer-123\",\n \"customer\": {\n \"emailAddress\": \"john@primer.io\"\n },\n \"metadata\": {\n \"productType\": \"Shoes\"\n },\n \"paymentMethod\": {\n \"descriptor\": \"Purchase: Shoes\",\n \"paymentMethodType\": \"PAYMENT_CARD\",\n \"vaultOnSuccess\": true,\n \"options\": {\n \"PAYMENT_CARD\": {\n \"networks\": {\n \"VISA\": {\n \"surcharge\": {\n \"amount\": 10\n }\n }\n }\n },\n \"GOOGLE_PAY\": {\n \"surcharge\": {\n \"amount\": 20\n }\n }\n }\n }\n}"
response = http.request(request)
puts response.read_bodyAuthorizations
Body
Your reference for the payment.
The 3-letter currency code in ISO 4217 format. e.g. use USD for US dollars.
The amount you would like to charge the customer, in minor units. e.g. for $7, use 700.
Some currencies, such as Japanese Yen, do not have minor units. In this case you should use the value as it is, without any formatting. For example for ¥100, use 100.
If the amount is provided on this level, it would override any amount calculated from the provided line items, shipping and other amounts.
x >= 0More information associated with the order.
Show child attributes
Show child attributes
A unique identifier for your customer.
Create a client session token with a customerId to enable the client-side SDK to retrieve and manage your customer's saved payment methods. A client session token also enables saving payment methods against this customer id.
More information associated with the customer.
Show child attributes
Show child attributes
Additional data to be used throughout the payment lifecycle.
A dictionary of key-value pairs where the values can only be strings or integers.
e.g. {"productId": 1001, "merchantId": "a13bsd62s"}
The size of metadata must not exceed 300 KB (307,200 bytes) when
serialized as JSON. Larger payloads are rejected with a
PaymentMetadataSizeExceeded error.
Enable certain options associated with the payment method.
Show child attributes
Show child attributes
Response
Successful Response
Client token used to initialize the SDK on all platforms. Its length is not fixed. Treat it as an opaque string and do not rely on a maximum length when storing it.
Expiration date & time of the client token (UTC with no timezoneinfo).
Your reference for the payment.
The 3-letter currency code in ISO 4217 format. e.g. use USD for US dollars.
The amount you would like to charge the customer, in minor units. e.g. for $7, use 700.
Some currencies, such as Japanese Yen, do not have minor units. In this case you should use the value as it is, without any formatting. For example for ¥100, use 100.
If the amount is provided on this level, it would override any amount calculated from the provided line items, shipping and other amounts.
x >= 0More information associated with the order.
Show child attributes
Show child attributes
A unique identifier for your customer.
More information associated with the customer.
Show child attributes
Show child attributes
Additional data to be used throughout the payment lifecycle.
Enable certain options associated with the payment methods.
Show child attributes
Show child attributes
Warning messages to indicate missing information that are required for payment methods, checkout modules and other features; or when third-party services are unavailable.
Show child attributes
Show child attributes