Welcome to our support center

Developers

Verify Transaction

Prerequistes

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
  • Live Payment Notification (LPN)

Overview

The Verify Transaction API is used to check the status of a particular transaction. This may be used to verify responses or to confirm a transaction has been sucessfully created. It is recommended to utilise this as a security feature to ensure the callback containing the response is correct and has not been tampered with.

Parameters

The API takes the following parameters as either GET or POST data:

  • merchant_id - The merchant ID that can be found within the merchant console. (Compulsory)
  • api_key - Your The API Key associated with the merchant ID. This is used to authorise and identify the caller of the request. (Compulsory)
  • transaction_id - The transaction_id you want to check, as supplied via the LPN or from any other API (Optional)
  • identifier_id - The identifier_id you want to check, as supplied when creating Transaction Identifier's (Optional)

Example Request

Example verifyTransaction API call:

https://api.cybercompay.com/verifyTransaction.php?api_key=ida8463534kawhdi347d39h078dt3383&merchant_id=123E59334B8338&transaction_id=XXXX


Responses

If the API call was successful, it will return a response in JSON format.

For information on the API response format and possible response codes, please see API Response Format

API response example:

{"response_code":200,"message":"OK","data":{"transaction_id":"XXXX","status":"declined","transaction_approved":"no"}}

API response data fields:

  • transaction_id - A unique identifier for this completed transaction (note: this is a NOT the same as identifier_id)
  • status - This will always be either "accepted" or "declined"
  • transaction_approved - This will always be either "yes" or "no"


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

<?php
/**
 * 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) {
        curl_close($ch);
        return false;
    }
    curl_close($ch);
    return $html;
}

//The POST data that will be sent to the server.
$postData = array(
    'api_key' => 'ida8463534kawhdi347d39h078dt3383',
    'merchant_id' => '123E59334B8338',
    'transaction_id' => 'B28A2038J8E89'
);

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

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

//Print the results.
print_r(json_decode($result));