Welcome to our support center

Developers

Creating Products

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)
  • Product APIs

Overview

The CreateProducts API is used to make new products to be avaliable for customers to purchase. After a product has been made it may then be used with the payments page, where the the Product ID is required. Alternatively this can be used with the many available Shopping Carts.

Parameters

The createProduct API takes the following parameters:

  • merchant_id - The merchant ID that can be found within the merchant console. (Compulsory)
  • api_key - The API Key associated with the merchant ID.
    This is used to authorise and identify the caller of the request. (Compulsory)
  • prod_name- Product name (Compulsory)
  • prod_rrp- Product recommended sale price (Compulsory)
  • prod_quantity- Product quantity (Compulsory)
  • prod_sale_price- Product sale price in New Zealand Dollars (Compulsory)
  • prod_minimum_purchase- The minimum number of products that need to be purchased to get it at this price.
    The default number usually chosen will be one. (Compulsory)
  • prod_description- Product subscription (Optional)
  • prod_sale_price_aud- Product sale price in AUD (Optional)
  • prod_sale_price_cad- Product sale price in CAD (Optional)
  • prod_sale_price_cny- Product sale price in CNY (Optional)
  • prod_sale_price_eur- Product sale price in EUR (Optional)
  • prod_sale_price_gbp- Product sale price in GBP (Optional)
  • prod_sale_price_hkd- Product sale price in HKD (Optional)
  • prod_sale_price_jpy- Product sale price in JPY (Optional)
  • prod_sale_price_sgd- Product sale price in SGD (Optional)
  • prod_sale_price_zar- Product sale price in ZAR (Optional)
  • prod_sale_price_krw- Product sale price in KRW (Optional)
  • prod_sale_price_usd- Product sale price in USD (Optional)
  • prod_accepted_url- A URL to redirect to after a customer has made a successful payment (Optional)
  • prod_declined_url- A URL to redirect to after a customer has made a unsuccessful payment (Optional)

Example Request

Example createProduct API call:

https://api.cybercompay.com/createProduct.php?api_key=ida8463534kawhdi347d39h078dt3383&merchant_id=123E59334B8338&prod_name=10.50&prod_rrp=Magazine&prod_quantity=2&prod_sale_price=prod_sale_price&prod_minimum_purchase=1


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:

If the API call was successful, it will return a response in JSON format. This response includes the product_id from the CyberCom Pay system.

{"response_code":200,"message":"OK","data":{"product_id":"B24C66DC3DC54"}}


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',
    'prod_name' => '10.50',
    'prod_rrp' => 'Magazine',
    'prod_quantity' => '2',
    'prod_sale_price' => '10.50',
    'prod_minimum_purchase' => '1'
);

//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));