1. Intro 2. Defining parts of the request. 3. Making a request to Judopay's Transaction API. 4. Handling the API response.
In this tutorial we will create a payment session. 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.
To create the payment session, we will be making a request to Judopay’s Transaction API.
The ‘payment session reference’ returned from the API should be stored in the backend server, where it is ready to be used when calling our Web SDK’s payment functions.
For this tutorial we will be using PHP as our server-side scripting language. You may use any server-side language you wish.
To make a request to Judopay’s Transaction API we first need to define:
Define an array of headers, which includes: content type, authorisation and the API version.
For authorisation, set this as Basic and then the base 64 encoding of your API token, colon, then your API secret.
For the API version, ensure this is set to the most recent version, which can be found in our documentation.
To check the latest API version, visit Judopay’s Transaction API reference documentation.
Define the end-point, /payment-session.
Define the Judopay API server URL, depending on the environment; where api-sandbox.judopay is for the sandbox environment, and api.judopay is for the live environment.
Add the end-point to the end of the Judopay API URL.
Define an array which includes: your judoId, the transaction amount, the transaction currency, a payment reference and a consumer reference.
Convert the format of this array to JSON.
This will be used as the request body.
Please note, all the values used here must also be used later, when calling other Web SDK functions, such as invokePayment().
If any of these values are different, it will cause an error.
Now we pull together everything we have defined, to make a POST request to Judopay’s Transaction API payment-session end-point.
If the request is successful, you should receive an object containing a reference and the reference expiry date.
If unsuccessful, you should receive an error response from the API.
Judopay’s Transaction API reference documentation also contains information on the expected responses from the API calls, along with the fields required for the request body.
If the request was successful, extract the reference value from the response object.
If the request was not successful, handle the API error accordingly.
For more information on the format of the API error responses, head to our Web SDK documentation and see the section, Web SDK error responses.
Here it describes the fields, that make up the API error response object.