• France
status page
Demo shops
assistance
FAQContact support
Search
Categories
Tags
docs.
France
Spain
Europe (English)
India
Homepage
Use cases
Create a payment
Create an installment payment
Create a multi-card (split) payment
Create a payment by Alias (Token)
Create a payment link
Create a recurring payment
Manage subscriptions
Manage your transactions (refund, cancel...)
Analyze your reports
API docs
Embedded Form
REST API
Hosted payment
Mobile payment
File exchange
SDD mandates by REST API
Snippets
Payment methods
Plugins
Marketplace
Guides
Merchant Back Office
Back Office Expert
Functional guides

Example file : formToken.php

This file is used to create the formToken.

  1. Request data

  2. sending data with the CURL command

  3. the call to the endpoint of the REST Web Service V4/Charge/CreatePayment

  4. the response containing the formToken


<?php include_once 'config.php'; ?>

<?php
// STEP 1 : the data request
$data = array(
    'orderId' => uniqid('order_'),
 'amount' => 250, 
 'currency' => 'EUR', 
 'customer' => array(
        'email' => 'sample@example.com',
     'reference' => uniqid('customer_'),
     'billingDetails' => array(
            'language' => 'fr',
            'title' => 'M.',
            'firstName' => 'Test',
            'lastName' => 'Krypton',
            'category' => 'PRIVATE',
            'address' => '25 rue de l\'Innovation', 
   'zipCode' => '31000',
            'city' => 'Testville',
            'phoneNumber' => '0615665555',
            'country' => 'FR'
        )
 ),
 'transactionOptions' => array(
        'cardOptions' => array(
      'retry' => 1
  )
 )
);

// STEP 3 : call the endpoint V4/Charge/CreatePayment with the json data.
$response = post(SERVER."/api-payment/V4/Charge/CreatePayment", json_encode($data));

// Check if there is errors.
if ($response['status'] != 'SUCCESS') {
    // An error occurs, throw exception
    $error = $response['answer'];
    throw new Exception('error ' . $error['errorCode'] . ': ' . $error['errorMessage'] );
}

// Everything is fine, extract the formToken
// STEP 4 : the answer with the creation of the formToken
$formToken = $response['answer']['formToken'];

function post($url, $data){


// STEP 2 : send data with curl command
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_USERAGENT, 'test');
    curl_setopt($curl, CURLOPT_USERPWD, USERNAME . ':' . PASSWORD);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 45);
    curl_setopt($curl, CURLOPT_TIMEOUT, 45);

    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);

    $raw_response = curl_exec($curl);
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

    if (!in_array($status, array(200, 401))) {
        curl_close($curl);

        throw new \Exception("Error: call to URL $url failed with unexpected status $status, response $raw_response.");
    }

    $response = json_decode($raw_response, true);
    if (!is_array($response)) {
        $error = curl_error($curl);
        $errno = curl_errno($curl);

        curl_close($curl);

        throw new \Exception("Error: call to URL $url failed, response $raw_response, curl_error $error, curl_errno $errno.");
    }

    curl_close($curl);

    return $response;
}
?>
Jobs
Legal
GDPR
25.18-1.11