Jump to content
  • Sign in to follow this  

    API


    dinox

    To receive notice of purchases made on the forum, you need to visit https://en.opencartforum.com/clients/info/ and add your Callback URL and Secret Key.

    Set your server so that it receives data from our API. You can test if it's working in the personal data section on our site using the Test Query button.


    Example:

    <?php 
    $key = "************"; // This is your secret key, as set on in the section https://en.opencartforum.com/clients/info/ . There you can also set the Callback URL
    
    
    function hmac($key, $data)
    {
    	$b = 64; // byte length for md5
    	if (strlen($key) > $b) {
    		$key = pack("H*", md5($key));
    	}
    	$key    = str_pad($key, $b, chr(0x00));
    	$ipad   = str_pad('', $b, chr(0x36));
    	$opad   = str_pad('', $b, chr(0x5c));
    	$k_ipad = $key ^ $ipad;
    	$k_opad = $key ^ $opad;
    	return md5($k_opad . pack("H*", md5($k_ipad . $data)));
    }
    
    $json = file_get_contents('php://input'); 
    
    $res = json_decode($json);
    
    
    
    $response     = strlen($res->order_id) . $res->order_id . strlen($res->date_added) . $res->date_added;
    $hash         = hmac($key, $response);
    
    if ($res->order_status == "request") {
    
    
    if ($hash == $res->hash) {
    	$result = array('success' => 'Ok');
    	echo json_encode($result);
    } else {
    	$result = array('error' => 'Bad hash');
    	echo json_encode($result);
    }
    } elseif ($res->order_status == "success" && $hash == $res->hash) {
    	$result = array('success' => 'Received');
    	echo json_encode($result);
    	
    	// This result from our API contains all the information regarding the transaction which you can use in order to track your sales and generate licensing keys for sold extensions as necessary. 
    	
    	$marketplace = $res->marketplace; //Marketplace ID -  en.opencartforum.com
    	$order_status = $res->order_status; //Order status
    	$username = $res->username; //Customer name
    	$email = $res->email; // Customer email
    	$date_added = $res->date_added; //Purchase date
    	$order_id = $res->order_id;  //\IPS\Request::i()->LMI_PAYMENT_NO, //invoice
    	$extension_id = $res->extension_id;  //Extension ID 
    	$member_id = $res->member_id; //Customer ID
    	$domain =  $res->domain, //domain (optional)
    	$test_domain = $res->test_domain, //test domain (optional)
    	$extension = $res->extension; //Extension name
    	$total = $res->total; //Transaction amount excluding markeplace commission
    
    	
    } else {
    	$result = array('error' => 'Bad request');
    	echo json_encode($result);
    }
    /*
    $log_file = $_SERVER['DOCUMENT_ROOT'].'/purchase.txt';
    
    $f = fopen($log_file, 'w+');
    fwrite($f, serialize($res)."\n");
    
    fclose($f);
    */
    ?>

    For more security, you can restrict the received data by IP. Our API's IP is 46.4.115.34

     

    Edited by dinox

    Sign in to follow this  


    User Feedback

    Recommended Comments

    There are no comments to display.


×