One-Click Payment
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. It’s based on one of these two guides:
How it works
Autenticate the Customer
Authenticate the customer.
Show the checkout
Show the checkout.
Send the Payment
Send the payment.
1. Authenticate the customer
You will need a method to authenticate the customer against your records in order to obtain their respective registration.id
(token) associated with their account. This can be achieved by asking the customer to log in for example, however you may find other ways that are applicable to your system.
The information that you might want to store, per customer, in order to execute a One-Click payment includes:
- registration.id (token)
- account brand
- last four digits of account number
- expiry date (if applicable)
2. Show the checkout
Once you have retrieved the stored information, you should confirm with the customer how they wants to checkout. We recommend offering normal payment methods alongside your One-Click checkout page.
<!DOCTYPE HTML> <html> <head> <script> var wpwlOptions = { style: "card" } </script> <script src="https://test.como.world/v1/paymentWidgets.js?checkoutId={checkoutId}"></script> <style> body { background-color:white; width:720px; margin:auto;padding:10px;font-size:14px;} h2 { margin-top:25px;margin-bottom:10px;padding:5px;width:100%;background-color:#eee; border:1px solid #ccc;border-radius:6px;font-size: 16px;font-weight:normal; } </style> </head> <body> <h2><input type="radio" checked="checked" /> Checkout with stored payment details</h2> <table> <tr><td width="100px">Visa</td><td width="200px">xxxx-xxxx-xxxx-1234</td><td width="200px">Dec / 2018</td></tr> </table> <div><button type="submit" name="pay" class="myButton">Pay now</button></div><br /><br /> <h2><input type="radio" /> Checkout with new payment method</h2> <form action="http://localhost/pay.html"> MASTER VISA AMEX CHINAUNIONPAY </form> </body> </html>
3. Send the payment
When the customer checks out with One-Click, all you need to do is send a server-to-server request for a new payment with the respective registration.id (token) for which you want to make the payment. You can do this by sending a POST request to the/v1/registrations/{registration.id}/payments
endpoint. Try it out
https://test.como.world/v1/registrations//payments
curl https://test.como.world/v1/registrations/{id}/payments \ -d "entityId=8ac7a4c7761cdc4a01761f34e767099c" \ -d "amount=92.00" \ -d "currency=EUR" \ -d "paymentType=DB" \ -H "Authorization: Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg=="
https://test.como.world/v1/registrations//payments
public Dictionary<string, dynamic> Request() { Dictionary<string, dynamic> responseData; string data="entityId=8ac7a4c7761cdc4a01761f34e767099c" + "&amount=92.00" + "¤cy=EUR" + "&paymentType=DB"; string url = "https://test.como.world/v1/registrations/{id}/payments"; 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"];
https://test.como.world/v1/registrations//payments
import groovy.json.JsonSlurper public static String request() { def data = "entityId=8ac7a4c7761cdc4a01761f34e767099c" + "&amount=92.00" + "¤cy=EUR" + "&paymentType=DB" def url = "https://test.como.world/v1/registrations/{id}/payments".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()
https://test.como.world/v1/registrations//payments
private String request() throws IOException { URL url = new URL("https://test.como.world/v1/registrations/{id}/payments"); 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"; 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); }
https://test.como.world/v1/registrations//payments
const https = require('https'); const querystring = require('querystring'); const request = async () => { const path='/v1/registrations/{id}/payments'; const data = querystring.stringify({ 'entityId':'8ac7a4c7761cdc4a01761f34e767099c', 'amount':'92.00', 'currency':'EUR', 'paymentType':'DB' }); 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);
https://test.como.world/v1/registrations//payments
function request() { $url = "https://test.como.world/v1/registrations/{id}/payments"; $data = "entityId=8ac7a4c7761cdc4a01761f34e767099c" . "&amount=92.00" . "¤cy=EUR" . "&paymentType=DB"; $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();
https://test.como.world/v1/registrations//payments
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/registrations/{id}/payments" data = { 'entityId' : '8ac7a4c7761cdc4a01761f34e767099c', 'amount' : '92.00', 'currency' : 'EUR', 'paymentType' : 'DB' } 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);
https://test.como.world/v1/registrations//payments
require 'net/https' require 'uri' require 'json' def request() uri = URI('https://test.como.world/v1/registrations/{id}/payments') 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' }) res = http.request(req) return JSON.parse(res.body) end puts request()
https://test.como.world/v1/registrations//payments
def initialPayment : String = { val url = "https://test.como.world/v1/registrations/{id}/payments" val data = ("" + "entityId=8ac7a4c7761cdc4a01761f34e767099c" + "&amount=92.00" + "¤cy=EUR" + "&paymentType=DB" ) 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()) } }
https://test.como.world/v1/registrations//payments
Public Function Request() As Dictionary(Of String, Object) Dim url As String = "https://test.como.world/v1/registrations/{id}/payments" Dim data As String = "" + "entityId=8ac7a4c7761cdc4a01761f34e767099c" + "&amount=92.00" + "¤cy=EUR" + "&paymentType=DB" 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")
https://test.como.world/v1/registrations/8a82944a4cc25ebf014cc2c782423202/payments
Authorization | Bearer OGFjN2E0Yzc3NjFjZGM0YTAxNzYxZjM0ZTc5YjA5YTB8V0duZ0Q4WGFYRg== |
entityId=8ac7a4c7761cdc4a01761f34e767099c
amount=92.00
currency=EUR
paymentType=DB