Developers
...
Developer Hub
Developer Tutorials
Creating a Payment Session Tutorial
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 tutorial payment session diagram 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 define parts of the request // base64 encode your api token and secret for the api auth header $userencode = base64 encode($yourapitoken " " $yourapisecret); // setting the headers $headers = array( 'content type\ application/json', 'authorization basic ' $userencode, 'api version 6 18' //ensure to set this to the latest version ); //setting the endpoint $endpoint="/paymentsession"; //setting the api server url with the endpoint $environment = "https //api sandbox karatepay com" $endpoint; //api judopay com is for the live environment // setting the data for the request's payload $data=array( '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 $requestpayload=json encode($data); 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 post request example //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) handle the response // decode the json reply $obj = json decode($response); //check if response contains the reference if(isset($obj >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; resources web sdk docid 40dwe6lbub7vdkza1qydc handling a transaction tutorial docid\ wc705scaxt4snkefgxqr7 judopay transaction api documentation