PHP examples

All PHP examples use cURL to communicate with the CURO Payments API.
PHP supports libcurl, which allows you to connect and communicate with many different types of servers and protocols. You are free to use any other library for HTTPS communication, or you can connect directly using sockets.


📘

Note

The RESTful API supports the following response/request formats:

  • XML
  • JSON
  • HTML
  • serialized PHP data

iDEAL directory request

This example is intended to demonstrate how to retrieve the available iDEAL issuers/directory information.

<?php

// Sample iDEAL Issuer Directory request using CURO Protocol and REST API
// Your API authentication info
$merchant = 'demo';
$apiKey = 'averylongkeyyouwillreceivefromyouraccountmanager';

$apiUrl = 'https://secure.curopayments.net/rest/v1/curo/'; // Real
$apiUrl = 'https://secure-staging.curopayments.net/rest/v1/curo/'; // Test

// create a new cURL resource
$curl = curl_init();
// set URL and other appropriate options
curl_setopt($curl, CURLOPT_URL, $apiUrl . '/ideal/issuers/');
curl_setopt($curl, CURLOPT_HEADER, false);
// set HTTP Basic Authentication
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $merchant . ':' . $apiKey);
// we want JSON response
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Accept: application/json']);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
// get server response
$response = curl_exec($curl);
// close cURL resource, and free up system resources
curl_close($curl);

// Create associative array of the response
$directory = @json_decode($response, true);

// Dump response for this demo
print_r($directory);

iDEAL payment request

The example below demonstrates how to create an iDEAL payment request using the CURO protocol and the REST API.

<?php

// Sample iDEAL Payment request using CURO Protocol and REST API
// Your API authentication info
$merchant = 'demo';
$apiKey = 'averylongkeyyouwillreceivefromyouraccountmanager';

$apiUrl = 'https://secure.curopayments.net/rest/v1/curo/'; // Real
$apiUrl = 'https://secure-staging.curopayments.net/rest/v1/curo/'; // Test

// Debug flag
$debug = true;

// NB: for test transactions you need test-issuers with different ids!
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<payment>
    <site_id>123</site_id>
    <currency_id>EUR</currency_id>
    <amount>100</amount>
    <reference>Reference 1</reference>
    <description>Description 1</description>
    <url_success>http://www.example.com/ok.html</url_success>
    <url_pending>http://www.example.com/pending.html</url_pending>
    <url_failure>http://www.example.com/wrong.html</url_failure>
    <url_callback>http://www.example.com/callback.html</url_callback>
    <issuer_id>RABONL2U</issuer_id>
    <country_id>NL</country_id>
    <language_id>nl</language_id>
    <ip>192.168.0.1</ip>
    <consumer>
        <firstname>John</firstname>
        <lastname>Doe</lastname>
        <email>[email protected]</email>
        <address>nowhereroad 12</address>
        <city>NonVille</city>
        <zipcode>12345</zipcode>
        <country_id>NL</country_id>
        <phone>0612345678</phone>
        <dob>10-07-1970</dob>
        <gender>m</gender>
    </consumer>
    <cartitems>
        <item>
            <quantity>1</quantity>
            <sku>hamer_01</sku>
            <name>Hamer</name>
            <price>1.50</price>
            <vat>21</vat>
            <vat_inc>1</vat_inc>
            <type>1</type>
        </item>
        <item>
            <quantity>1</quantity>
            <sku>Discount</sku>
            <name>Discount total</name>
            <price>-0.50</price>
            <vat>21</vat>
            <vat_inc>1</vat_inc>
            <type>4</type>
        </item>
    </cartitems>
</payment>
';

// create a new cURL resource
$curl = curl_init();
// set URL and other appropriate options
curl_setopt($curl, CURLOPT_URL, $apiUrl . 'ideal/payment/');
curl_setopt($curl, CURLOPT_HEADER, false);
// set HTTP Basic Authentication
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $merchant . ':' . $apiKey);
// send and receive XML
curl_setopt($curl, CURLOPT_HTTPHEADER, [
    'Accept: application/xml',
    'Content-Type: application/xml',
]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
// get server response
$response = curl_exec($curl);
$curlInfo = curl_getinfo($curl);
$errorCode = curl_errno($curl);
$errorMessage = curl_error($curl);
// close cURL resource, and free up system resources
curl_close($curl);

// print response for debug
if ($debug) {
    echo "error: $errorCode $errorMessage\r\n";
    echo "cURL information:\n" .
        print_r($curlInfo, true) .
        "\nPost data:\n" .
        print_r($xml, true) .
        "\nResponse:\n" .
        substr($response, 0, 500) . (strlen($response) > 500 ? '...' : '');
}

try {
    $xmlResponse = simplexml_load_string($response);
    if ($debug) {
        echo "XML = " . print_r($xmlResponse, true) . "\r\n";
    }

    // Check the http response to make sure the request was successfull
    if ($curlInfo['http_code'] >= 200 && $curlInfo['http_code'] < 300) {
        if (
            !empty($xmlResponse->payment->transaction_id)
            && !empty($xmlResponse->payment->url)
        ) {
            // Store the transaction_id as reference in our own system
            $transactionId = $xmlResponse->payment->transaction;

            // Redirect user to the bank to complete the payment
            $header = "Location: {$xmlResponse->payment->url}";
            if ($debug) {
                echo "Header( $header )\r\n";
            } else {
                header($header);
            }
            echo "<a href='{$xmlResponse->url}'>Click here to continue</a>\r\n";
            exit();
            /**
            EXIT when the transaction was finished the user will be redirected to the given return_url
            **/
        }
    } else {
        // Something went wrong, you problably don't want to show the error to the user!
        echo "Error {$xmlResponse->error->message}";
    }
} catch (Exception $e) {
    // Bad XML? we should mail ourselves some details
    echo "Transaction problem, please try again later.";

Did this page help you?