Welcome to our support center


Fetching Contracts


This section expects prior knowledge and understanding from the sections indicated below. Please note that these areas are essential to obtaining a successful response and notifying your server upon completion.

  • API Overview
  • API Key and Merchant ID
  • Subscription & Contract APIs


The fetchContract API allows the server to get all contracts that meet a specified criteria. This call is capable of searching for both subscriptions and the templates in which created them.

Please note that the search_by and keyword parameters may be passed multiples times, however the server expects to have square brackets after the parameters to symbolise an array.


If you omit the 'search_by' and 'keyword' parameters, the API will return every subscription in your account, both templates and active types. In order to filter these results, you can pass the API the filtering parameters with corresponding values.

The fetchContract API takes the following parameters:

  • merchant_id - The merchant ID that can be found within the merchant console. (Compulsory)
  • apikey - The API Key associated with the merchant ID.
    This is used to authorise and identify the caller of the request. (Compulsory)
  • search_by - The field you want to search by
  • keyword - The keyword to search by

Pass into 'search_by' parameter:

  • contract_id - The id of the contract you want to fetch
  • contact_id - The id of the person (contact) you want to search for
  • status - The status of the contract you want to search for (active, inactive, suspended)
  • start - The start date of the contract you want to search for (in Y-m-d format)
  • end - The end date of the contract you want to search for (in Y-m-d format)
  • currency - The currency of the subscription you want to search for (To view supported currencies click here)
  • type - The type of contract you want to search for (template or subscription)

Example Request

The following API call shows how all templates and active subscriptions may be retrieved:


By passing the search and keyword parameters we can limit the records returned. An example can be seen below, where the type = 'subscription' and the status = 'active':



If the API call was successful, it will return the subscription data in JSON format.

For information on the API response format and possible response codes, please see API Response Format
         "ct_description":"Includes monthly subscription of the 52 page magazine for 12 months.",
         "ct_name":"Magazine Subscription",
         "ct_tnc":"sample conditions",

A active subscription contract will have the following parameters:

  • ct_contid - The contact_id of the subscriber
  • ct_currency - The currency the subscription is in
  • ct_date - The date the subscription was created
  • ct_description - Description of the subscription
  • ct_duration - How long the subscription lasts (in JSON format)
  • ct_frequency - How often the recurring payment is made (in JSON format)
  • ct_start - The start date of the subscription (timestamp)
  • ct_end - The end date of the subscription (timestamp)
  • ct_status - The status of the contract (active, inactive, suspended)
  • ct_total_amount - The the recurring amount being charged
  • ct_type - The type of contract (template or subscription)
  • ct_last_charge_date - The date the subscriber was last charged (timestamp)
  • ct_last_successful_payment_date - The date the subscriber was last sucessfully charged (timestamp)
  • ct_next_charge_date - The next charge date (timestamp)

Test Code

Below is an example code that will work against a test section of the server. Although this is intended to simulate server behaviour, characteristics and responses are not always the same.

Please note that no transactions will be sent online and the server will not store any information from these requests. For more information on this, please see Testing Without An Account

 * Function used to make POST requests to the server using SSL.
 * @param type $url The API URL that we want to send the request to.
 * @param type $data POST data that will be sent to the server.
 * @return false Returns the HTML response as a String. If an error has occured null will be returned. 
function post_to_url($url, $data) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    $html = curl_exec($ch);
    if (curl_errno($ch) !== 0) {
        return false;
    return $html;

//The POST data that will be sent to the server.
$postData = array(
    'apikey' => 'ida8463534kawhdi347d39h078dt3383',
    'merchant_id' => '123E59334B8338',
    'search_by[]' => 'type',
    'search_by[]' => 'status',
    'keyword[]' => 'subscription',
    'keyword[]' => 'active'

//Make the request to the server
$result = post_to_url("https://merchant.cybercompay.com/examples/fetchContracts.php", $postData);

//If we have encountered an error display something back to the customer.
if ($result === false) {
    echo 'We have encountered an error!';

//Print the results.