One-Click Checkout
This guide allows you to achieve a significant speedup of the checkout process by re-using the data a customer entered for a previous transaction/registration. It’s based on one of these two guides:After the customer account details are stored, as part of the initial transaction/registration, you will need to keep a record of the associated registration IDs (token) that you can then use in step 1 below.
How it works
1. Prepare the checkout
NOTE: For demonstration purposes we have created a registration, which will be used in your one-click checkout, with id(s): 8ac7a4a07be8aec9017be8f0c7a714fa,8ac7a49f7be8a4a6017be8f0ca2d45cb. Following the guides above, you may add additional registrations options to the checkout.
First perform a server-to-server POST request to prepare the checkout, this should include the registration IDs of the customer as shown below.
The registration IDs should be sent in the
registrations[n].id
parameter, where n is a sequence number from zero, incrementing for each of the customer’s registration IDs. The Standing Instruction parameters should be sent as standingInstruction.source
as CIT
, standingInstruction.mode
as REPEATED
and standingInstruction.type
as UNSCHEDULED
. For example, if the customer has two accounts on file, you would send registrations[0].id = {first registration.id}
and registrations[1].id = {second registration.id}
. curl
c#
groovy
java
node.js
php
python
ruby
scala
vb.net
playground
curl
curl https://test.como.world/v1/checkouts \ -d "entityId=8ac7a4c7761cdc4a01761f34e767099c" \ -d "amount=92.00" \ -d "currency=EUR" \ -d "paymentType=DB" \ -d "registrations[0].id=8ac7a4a07c2bb473017c2dd65fad6653" \ -d "registrations[1].id=8ac7a4a07c2bb473017c2dd660f86666" \ -d "standingInstruction.source=CIT" \ -d "standingInstruction.mode=REPEATED" \ -d "standingInstruction.type=UNSCHEDULED" \ -H "Authorization: Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg=="
c#
public Dictionary<string, dynamic> Request() { Dictionary<string, dynamic> responseData; string data="entityId=8ac7a4c7761cdc4a01761f34e767099c" + "&amount=92.00" + "¤cy=EUR" + "&paymentType=DB" + "®istrations[0].id=8ac7a4a07c2bb473017c2dd65fad6653" + "®istrations[1].id=8ac7a4a07c2bb473017c2dd660f86666" + "&standingInstruction.source=CIT" + "&standingInstruction.mode=REPEATED" + "&standingInstruction.type=UNSCHEDULED"; string url = "https://test.como.world/v1/checkouts"; byte[] buffer = Encoding.ASCII.GetBytes(data); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = "POST"; request.Headers["Authorization"] = "Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg=="; request.ContentType = "application/x-www-form-urlencoded"; Stream PostData = request.GetRequestStream(); PostData.Write(buffer, 0, buffer.Length); PostData.Close(); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); var s = new JavaScriptSerializer(); responseData = s.Deserialize<Dictionary<string, dynamic>>(reader.ReadToEnd()); reader.Close(); dataStream.Close(); } return responseData; } responseData = Request()["result"]["description"];
groovy
import groovy.json.JsonSlurper public static String request() { def data = "entityId=8ac7a4c7761cdc4a01761f34e767099c" + "&amount=92.00" + "¤cy=EUR" + "&paymentType=DB" + "®istrations[0].id=8ac7a4a07c2bb473017c2dd65fad6653" + "®istrations[1].id=8ac7a4a07c2bb473017c2dd660f86666" + "&standingInstruction.source=CIT" + "&standingInstruction.mode=REPEATED" + "&standingInstruction.type=UNSCHEDULED" def url = "https://test.como.world/v1/checkouts".toURL() def connection = url.openConnection() connection.setRequestMethod("POST") connection.setRequestProperty("Authorization","Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg==") connection.doOutput = true connection.outputStream << data def json = new JsonSlurper().parseText(connection.inputStream.text) json } println request()
java
private String request() throws IOException { URL url = new URL("https://test.como.world/v1/checkouts"); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Authorization", "Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg=="); conn.setDoInput(true); conn.setDoOutput(true); String data = "" + "entityId=8ac7a4c7761cdc4a01761f34e767099c" + "&amount=92.00" + "¤cy=EUR" + "&paymentType=DB" + "®istrations[0].id=8ac7a4a07c2bb473017c2dd65fad6653" + "®istrations[1].id=8ac7a4a07c2bb473017c2dd660f86666" + "&standingInstruction.source=CIT" + "&standingInstruction.mode=REPEATED" + "&standingInstruction.type=UNSCHEDULED"; DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); wr.writeBytes(data); wr.flush(); wr.close(); int responseCode = conn.getResponseCode(); InputStream is; if (responseCode >= 400) is = conn.getErrorStream(); else is = conn.getInputStream(); return IOUtils.toString(is); }
node.js
const https = require('https'); const querystring = require('querystring'); const request = async () => { const path='/v1/checkouts'; const data = querystring.stringify({ 'entityId':'8ac7a4c7761cdc4a01761f34e767099c', 'amount':'92.00', 'currency':'EUR', 'paymentType':'DB', 'registrations[0].id':'8ac7a4a07c2bb473017c2dd65fad6653', 'registrations[1].id':'8ac7a4a07c2bb473017c2dd660f86666', 'standingInstruction.source':'CIT', 'standingInstruction.mode':'REPEATED', 'standingInstruction.type':'UNSCHEDULED' }); const options = { port: 443, host: 'test.como.world', path: path, method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': data.length, 'Authorization':'Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg==' } }; return new Promise((resolve, reject) => { const postRequest = https.request(options, function(res) { const buf = []; res.on('data', chunk => { buf.push(Buffer.from(chunk)); }); res.on('end', () => { const jsonString = Buffer.concat(buf).toString('utf8'); try { resolve(JSON.parse(jsonString)); } catch (error) { reject(error); } }); }); postRequest.on('error', reject); postRequest.write(data); postRequest.end(); }); }; request().then(console.log).catch(console.error);
php
function request() { $url = "https://test.como.world/v1/checkouts"; $data = "entityId=8ac7a4c7761cdc4a01761f34e767099c" . "&amount=92.00" . "¤cy=EUR" . "&paymentType=DB" . "®istrations[0].id=8ac7a4a07c2bb473017c2dd65fad6653" . "®istrations[1].id=8ac7a4a07c2bb473017c2dd660f86666" . "&standingInstruction.source=CIT" . "&standingInstruction.mode=REPEATED" . "&standingInstruction.type=UNSCHEDULED"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization:Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg==')); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// this should be set to true in production curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $responseData = curl_exec($ch); if(curl_errno($ch)) { return curl_error($ch); } curl_close($ch); return $responseData; } $responseData = request();
python
try: from urllib.parse import urlencode from urllib.request import build_opener, Request, HTTPHandler from urllib.error import HTTPError, URLError except ImportError: from urllib import urlencode from urllib2 import build_opener, Request, HTTPHandler, HTTPError, URLError import json def request(): url = "https://test.como.world/v1/checkouts" data = { 'entityId' : '8ac7a4c7761cdc4a01761f34e767099c', 'amount' : '92.00', 'currency' : 'EUR', 'paymentType' : 'DB', 'registrations[0].id' : '8ac7a4a07c2bb473017c2dd65fad6653', 'registrations[1].id' : '8ac7a4a07c2bb473017c2dd660f86666', 'standingInstruction.source' : 'CIT', 'standingInstruction.mode' : 'REPEATED', 'standingInstruction.type' : 'UNSCHEDULED' } try: opener = build_opener(HTTPHandler) request = Request(url, data=urlencode(data).encode('utf-8')) request.add_header('Authorization', 'Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg==') request.get_method = lambda: 'POST' response = opener.open(request) return json.loads(response.read()); except HTTPError as e: return json.loads(e.read()); except URLError as e: return e.reason; responseData = request(); print(responseData);
ruby
require 'net/https' require 'uri' require 'json' def request() uri = URI('https://test.como.world/v1/checkouts') http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true req = Net::HTTP::Post.new(uri.path) req.set_form_data({ 'entityId' => '8ac7a4c7761cdc4a01761f34e767099c', 'amount' => '92.00', 'currency' => 'EUR', 'paymentType' => 'DB', 'registrations[0].id' => '8ac7a4a07c2bb473017c2dd65fad6653', 'registrations[1].id' => '8ac7a4a07c2bb473017c2dd660f86666', 'standingInstruction.source' => 'CIT', 'standingInstruction.mode' => 'REPEATED', 'standingInstruction.type' => 'UNSCHEDULED' }) res = http.request(req) return JSON.parse(res.body) end puts request()
scala
def initialPayment : String = { val url = "https://test.como.world/v1/checkouts" val data = ("" + "entityId=8ac7a4c7761cdc4a01761f34e767099c" + "&amount=92.00" + "¤cy=EUR" + "&paymentType=DB" + "®istrations[0].id=8ac7a4a07c2bb473017c2dd65fad6653" + "®istrations[1].id=8ac7a4a07c2bb473017c2dd660f86666" + "&standingInstruction.source=CIT" + "&standingInstruction.mode=REPEATED" + "&standingInstruction.type=UNSCHEDULED" ) val conn = new URL(url).openConnection() conn match { case secureConn: HttpsURLConnection => secureConn.setRequestMethod("POST") case _ => throw new ClassCastException } conn.setDoInput(true) conn.setDoOutput(true) IOUtils.write(data, conn.getOutputStream()) conn.setRequestProperty("Authorization", "Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg==") conn.connect() if (conn.getResponseCode() >= 400) { return IOUtils.toString(conn.getErrorStream()) } else { return IOUtils.toString(conn.getInputStream()) } }
vb.net
Public Function Request() As Dictionary(Of String, Object) Dim url As String = "https://test.como.world/v1/checkouts" Dim data As String = "" + "entityId=8ac7a4c7761cdc4a01761f34e767099c" + "&amount=92.00" + "¤cy=EUR" + "&paymentType=DB" + "®istrations[0].id=8ac7a4a07c2bb473017c2dd65fad6653" + "®istrations[1].id=8ac7a4a07c2bb473017c2dd660f86666" + "&standingInstruction.source=CIT" + "&standingInstruction.mode=REPEATED" + "&standingInstruction.type=UNSCHEDULED" Dim req As WebRequest = WebRequest.Create(url) req.Method = "POST" req.Headers.Add("Authorization", "Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg==") req.ContentType = "application/x-www-form-urlencoded" Dim byteArray As Byte() = Encoding.UTF8.GetBytes(data) req.ContentLength = byteArray.Length Dim dataStream As Stream = req.GetRequestStream() dataStream.Write(byteArray, 0, byteArray.Length) dataStream.Close() Dim res As WebResponse = req.GetResponse() Dim resStream = res.GetResponseStream() Dim reader As New StreamReader(resStream) Dim response As String = reader.ReadToEnd() reader.Close() resStream.Close() res.Close() Dim jss As New System.Web.Script.Serialization.JavaScriptSerializer() Dim dict As Dictionary(Of String, Object) = jss.Deserialize(Of Dictionary(Of String, Object))(response) Return dict End Function responseData = Request()("result")("description")
playground
Authorization | Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg== |
entityId=8ac7a4c7761cdc4a01761f34e767099c
amount=92.00
currency=EUR
paymentType=DB
registrations[0].id=8ac7a4a07c2bb473017c2dd65fad6653
registrations[1].id=8ac7a4a07c2bb473017c2dd660f86666
standingInstruction.source=CIT
standingInstruction.mode=REPEATED
standingInstruction.type=UNSCHEDULED
2. Create the payment form
Then, to show the payment form you just need to add the following lines of HTML/Javascript to your page and populating the following variables- The checkout’s
id
that you got in the response from step 1
<script src="https://test.como.world/v1/paymentWidgets.js?checkoutId={checkoutId}"></script>
The
shopperResultUrl
, which is the page on your site where the customer should be redirected to after the payment is processed and the brands that will be available. <form action="{shopperResultUrl}" class="paymentWidgets">VISA MASTER AMEX</form>
When COPYandPAY builds up the payment form it automatically fetches the registrations data from the server and displays the pre-filled widgets to the shopper.
Todo Java Script
3. Get the payment status
As usual, once the payment has been processed, the customer is redirected to yourshopperResultUrl
along with a GET parameter resourcePath
.
IMPORTANT: The baseUrl must end in a “/”, e.g. “https://test.como.world/”.
Then, to get the status of the payment, you should make a GET request to the baseUrl + resourcePath
, including your authentication parameters.
Example for a resourcePath: resourcePath=/v1/checkouts/{checkoutId}/payment
curl
c#
groovy
java
node.js
php
python
ruby
scala
vb.net
playground
curl
https://test.como.world/v1/checkouts//payment
curl -G https://test.como.world/v1/checkouts/{id}/payment \ -d "entityId=8ac7a4c7761cdc4a01761f34e767099c" \ -H "Authorization: Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg=="
c#
https://test.como.world/v1/checkouts//payment
public Dictionary<string, dynamic> Request() { Dictionary<string, dynamic> responseData; string data="entityId=8ac7a4c7761cdc4a01761f34e767099c"; string url = "https://test.como.world/v1/checkouts/{id}/payment?" + data; HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = "GET"; request.Headers["Authorization"] = "Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg=="; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); var s = new JavaScriptSerializer(); responseData = s.Deserialize<Dictionary<string, dynamic>>(reader.ReadToEnd()); reader.Close(); dataStream.Close(); } return responseData; } responseData = Request()["result"]["description"];
groovy
https://test.como.world/v1/checkouts//payment
import groovy.json.JsonSlurper public static String request() { def data = "entityId=8ac7a4c7761cdc4a01761f34e767099c" def url = ("https://test.como.world/v1/checkouts/{id}/payment?" + data).toURL() def connection = url.openConnection() connection.setRequestMethod("GET") connection.setRequestProperty("Authorization","Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg==") def json = new JsonSlurper().parseText(connection.inputStream.text) json } println request()
java
https://test.como.world/v1/checkouts//payment
private String request() throws IOException { URL url = new URL("https://test.como.world/v1/checkouts/{id}/payment "&entityId=8ac7a4c7761cdc4a01761f34e767099c"); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Authorization", "Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg=="); int responseCode = conn.getResponseCode(); InputStream is; if (responseCode >= 400) is = conn.getErrorStream(); else is = conn.getInputStream(); return IOUtils.toString(is); }
node.js
https://test.como.world/v1/checkouts//payment
const https = require('https'); const querystring = require('querystring'); const request = async () => { var path='/v1/checkouts/{id}/payment'; path += '?entityId=8ac7a4c7761cdc4a01761f34e767099c'; const options = { port: 443, host: 'test.como.world', path: path, method: 'GET', headers: { 'Authorization':'Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg==' } }; return new Promise((resolve, reject) => { const postRequest = https.request(options, function(res) { const buf = []; res.on('data', chunk => { buf.push(Buffer.from(chunk)); }); res.on('end', () => { const jsonString = Buffer.concat(buf).toString('utf8'); try { resolve(JSON.parse(jsonString)); } catch (error) { reject(error); } }); }); postRequest.on('error', reject); postRequest.end(); }); }; request().then(console.log).catch(console.error);
php
https://test.como.world/v1/checkouts//payment
function request() { $url = "https://test.como.world/v1/checkouts/{id}/payment"; $url .= "?entityId=8ac7a4c7761cdc4a01761f34e767099c"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization:Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg==')); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// this should be set to true in production curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $responseData = curl_exec($ch); if(curl_errno($ch)) { return curl_error($ch); } curl_close($ch); return $responseData; } $responseData = request();
python
https://test.como.world/v1/checkouts//payment
try: from urllib.parse import urlencode from urllib.request import build_opener, Request, HTTPHandler from urllib.error import HTTPError, URLError except ImportError: from urllib import urlencode from urllib2 import build_opener, Request, HTTPHandler, HTTPError, URLError import json def request(): url = "https://test.como.world/v1/checkouts/{id}/payment" url += '?entityId=8ac7a4c7761cdc4a01761f34e767099c' try: opener = build_opener(HTTPHandler) request = Request(url, data=b'') request.add_header('Authorization', 'Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg==') request.get_method = lambda: 'GET' response = opener.open(request) return json.loads(response.read()); except HTTPError as e: return json.loads(e.read()); except URLError as e: return e.reason; responseData = request(); print(responseData);
ruby
https://test.como.world/v1/checkouts//payment
require 'net/https' require 'uri' require 'json' def request() path = ("?entityId=8ac7a4c7761cdc4a01761f34e767099c") uri = URI.parse('https://test.como.world/v1/checkouts/{id}/payment' + path) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true req = Net::HTTP::Get.new(uri) req['Authorization'] = 'Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg==' res = http.request(req) return JSON.parse(res.body) end puts request()
scala
https://test.como.world/v1/checkouts//payment
def initialPayment : String = { val url = "https://test.como.world/v1/checkouts/{id}/payment" url +="?entityId=8ac7a4c7761cdc4a01761f34e767099c" val conn = new URL(url).openConnection() conn match { case secureConn: HttpsURLConnection => secureConn.setRequestMethod("GET") case _ => throw new ClassCastException } conn.setRequestProperty("Authorization", "Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg==") conn.connect() if (conn.getResponseCode() >= 400) { return IOUtils.toString(conn.getErrorStream()) } else { return IOUtils.toString(conn.getInputStream()) } }
vb.net
https://test.como.world/v1/checkouts//payment
Public Function Request() As Dictionary(Of String, Object) Dim url As String = "https://test.como.world/v1/checkouts/{id}/payment" + "?entityId=8ac7a4c7761cdc4a01761f34e767099c" Dim req As WebRequest = WebRequest.Create(url) req.Method = "GET" req.Headers.Add("Authorization", "Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg==") req.ContentType = "application/x-www-form-urlencoded" Dim res As WebResponse = req.GetResponse() Dim resStream = res.GetResponseStream() Dim reader As New StreamReader(resStream) Dim response As String = reader.ReadToEnd() reader.Close() resStream.Close() res.Close() Dim jss As New System.Web.Script.Serialization.JavaScriptSerializer() Dim dict As Dictionary(Of String, Object) = jss.Deserialize(Of Dictionary(Of String, Object))(response) Return dict End Function responseData = Request()("result")("description")
playground
https://test.como.world/v1/checkouts/8a82944a4cc25ebf014cc2c782423202/payment
Authorization | Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg== |
entityId=8ac7a4c7761cdc4a01761f34e767099c
We recommend that you verify the following fields from the Payment Status response, by comparing the returned values with expected:
- ID(s)
- Amount
- Currency
- Brand
- Type