Datatrans Payments APIs Developers Manual in PHP

Datatrans Payments APIs Developer's Manual in PHP 5 minutes read

If this is your first time working with this payment gateway then you are in the right place. This post will show you how to implement the payment flows into your web application and all the parameters used in the curl and web samples will be described as follows.

Getting Started

Read the section below to learn about the various payment options available by Datatrans. Their payment flows is split into three categories: Customer-Initiated Payments, Vendor-Initiated Payments, After The Purchase. In this post we will explain every step and show how to use the API endpoints.

  • Integrations
  • Payment Methods
  • Create a test account
  • Customer Initiated Payments
  • Initialize a transaction
  • After the payment


These are the options Datatrans offers to integrate their payment system. We will talk more about the fourth option and explain every single step. You must first create a transaction before using the Redirect or Lightbox integrations.

Redirect & Lightbox

Redirect to the payment page of Datatrans or display their lightbox as an overlay on a page.

Mobile SDK

Use native payment elements for your iOS or Android mobile application.

Secure Fields

More complicated way, but you can use your own design for your payment system.

API Endpoints

Use their API endpoints to process specific payment actions. For production, remove the .sandbox part.

Payment methods

They offer a big list of payment methods. Click here if you want to find test payment details and learn about the specifics of each payment method.

Credit & Debit Cards

They support all international card brands: MasterCard, Visa, American Express, UnionPay, Diners, Discover, JCB, Maestro, etc.

Apple Pay

Apple Pay only works with transactions done with Safari. Any Apple Pay transaction is processed as a card transaction. 


Twint is a Swiss direct debit payment method that is usually used as a prepaid wallet but it can be linked to a bank account as well.

Google Pay

Google Pay is the payment method of Google. and it works with any browser. Any Google Pay transaction is processed as a card transaction.


PayPal is a payment service that allows users to deposit money in their account or connect it to a credit card or bank account.

Amazon Pay

Customers log in to their Amazon account and choose one of the payment options available.

Create a test account

As per usual, you are going to need a test account. You can create one here. Remember your details because to be able to log in again, you are going to need the Login, Username, and Password. For the sake of this tutorial, change the merchant at the top right corner to web. If you want to create a mobile application then change the merchant to mobile sdk. Under UPP Administration (Security) you will find your username (merchantId) and password. These are crucial because without them you won’t be able to initiate payments.

Customer Initiated Payments

They have three integrations available: Redirect, Lightbox, Secure Fields. For the first two, you need to send the request to initialize a transactionId to the init endpoint. For the Secure Fields integration, you need to send the request to initialize a transactionId to their secureFieldsInit endpoint.

  • Redirect
  • Lightbox
  • Secure Fields

For the Redirect integration you just need to redirect the user to this endpoint:

For the Lightbox integration you need to include this JavaScript library (of course, in the footer):

<script src="">

After the init request is made you will receive a transactionId, use it like this:

payButton.onclick = function() {
          transactionId: "transactionId"

For the Secure Fields integration, include this JavaScript library (of course in the footer):

<script src="">

Once you have the transactionId, it’s time to show our payment form. Use custom styles to design it your way.

Initialize a transaction

We mentioned two ways to retrieve a transactionId. The first one is using the init endpoint, and the second one is using the secureFieldsInit

For the purpose of this post, we will create a class where all of the necessary endpoints are used and we will explain how to use them. Don’t forget to include the JavaScript libraries as well.

After the payment

To check the status of a transaction and to settle, cancel, or refund it, use the transactionId. Remember, if you are done with coding and you want to receive payment, just remove the .sandbox from the endpoint. Create a base64 encoded value containing the merchantId and password and apply it with your requests in the authorization header.

Important links

Was this article helpful?

Add comment