Creating a Payment Session

This tutorial is for your back-end server.

In this tutorial, we will cover creating a payment session, by calling the Judopay Transaction API. The purpose of the payment session is to verify the identity of the cardholder, to prevent fraudulent transactions and refunds.

The payment session reference is used when calling our Web SDK’s payment functions from your client side.


Full Tutorial

In this tutorial, we will be using PHP as our server-side scripting language. You may use any server-side language you wish, as we have a REST API (which responds with JSON).


We have created video chapters from the full tutorial, to help you easily re-watch different parts of the tutorial. We have included an overview and example code snippets for each section below:

When using the code snippets, ensure to replace any field values with your own values.


1. Intro.

Payment Flow:



2. Defining parts of the request.

To make a request to Judopay’s Transaction API we first need to define:

  • The request headers

  • The environment server URL

  • The request endpoint

  • The request body

Ensure that the data used here, is also used later when calling Web SDK functions from your client side. For example judoId, API Token / Secret, yourConsumerReference.


// Base64 Encode your API token and secret for the API Auth Header
$userEncode = base64_encode($yourAPIToken.":".$yourAPISecret);

// Setting the Headers
$headers = array(
  'Authorization: Basic '.$userEncode,
  'API-Version: 6.18' //ensure to set this to the latest version

//Setting the endpoint

//Setting the API server url with the endpoint 
$environment = "".$endpoint; // is for the live environment

// Setting the data for the request's payload
        'judoId' => "yourJudoID", //Unique merchant/location ID supplied by Judopay
        'amount' => 1.00,
        'currency' => "GBP",
        'yourPaymentReference' => "yourPaymentReference", //Unique reference for this payment
        'yourConsumerReference' => "yourConsumerReference" //Unique reference to anonymously identify your customer

// Convert the data array to JSON


3. Making a request to Judopay's Transaction API

Pulling together everything we have defined, to make a POST request to Judopay’s Transaction API payment session endpoint.



//Making a POST request to Judopay's API
$ch = curl_init($environment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS,$requestPayload);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);


4. Handling the API response.

For a successful response, the payment session reference value should be stored in your backend server. This value should be passed to your client side when it is calling Web SDK functions (where the reference value is passed as a parameter).



// Decode the JSON reply
$obj = json_decode($response);

//Check if response contains the reference
   $reference = $obj->reference; //store value so it can be accessed later (when calling WebSDK functions)
   echo $reference;

//Handle the API error
else {
   $errorMessage = $obj->message;
echo $errorMessage;