Please make sure you have created an api. If you haven’t done so, please read the post here.

This document is for AES decryption. The codes demonstrated below is for PHP.

1. Download any slowAES library that can help you encrypt our data. We are using the AES library provided by Laurent Hant. Please download the library from:
http://code.google.com/p/slowaes/

2. You need the Crypto Helper library. It is usually the case that AES libraries come with the Crypto Helper library. WE are using the Crypto Helper library from the same provider. Please download from:
http://code.google.com/p/slowaes/

3. To decrypt , we need the following keys:

- AES Vector
- AES Key

4. Below is the sample code. Please note the comments.

-Sample data being sent to your call back server after decryption is:

 

{
"Email":"customer@email.com",
"Address": "1dagQsy1b7wZrHn7kpw1GvnXZ1nsrYut8",
"Receipt": "5EF23D77C2",
"Reference: "mercahnt reference here (can be invoice number)",
"BTCAmount": 0.00025,
"FiatAmount": 2.00,
"ExchangeRate": 647.25,
"TxId": "cadb0e6591b5fb466d9f1153c8f079f86bb38c7f5f0cf36fd1ebefb739164960", "Confirmations": 0
}

-Here is the callback function that CoinPip will activate

<?php
require("aes_small.php");
require("cryptoHelpers.php");
try{
 if(isset($_POST['callback'])){
 $aes_key = "<insert your aes key here>" ;
 $aes_vector = "<insert vector aes here>" ;
 $encrypted_base64Data = $_POST['callback']; //get the base64 Data sent by CoinPip
 $aes = new AES(); //Instantiate the AES class
 $ch = new cryptoHelpers(); //instantiate the cryptoHelper class
 $cipherIn= $ch->base64_decode($encrypted_base64Data); //decode data
 $originalsize = sizeof($cipherIn) + 32; //compute original size by adding 32 to the cipherIn array
 $key = $ch->base64_decode($aes_key); //decode the key using the crypto helper
 $iv = $ch->base64_decode($aes_vector); //decode the vextor using crypto helper
 $decrypt = $aes->decrypt($cipherIn,$originalsize,2,$key,32,$iv); //decrypt with the above found information
 $json = $ch->convertByteArrayToString($decrypt); //convert array to json string

 //additional step to filter some characters that are appended by AES.
 $last_index = strripos($json,'}') + 1;
 $json = substr($json, 0, $last_index );
 $data = json_decode($json,true);

 if($data){ //data is not empty and is validated. Create your own validation logic if needed
 if($data['Confirmations'] == 0){
 //include code to get the confirmation at 0. Apply your business logic
 $file = 'doc.txt';
 file_put_contents($file, $json); //record in textfile
 } else{
 //include code to get the confirmation at final number. Apply your business logic.
 $file = 'doc.txt';
 file_put_contents($file, "confirmation done"); //record in textfile
 }
 }
 }
}catch(Exception $e){
 $file = 'doc.txt';
 file_put_contents($file, $e); //record in textfile
}
?>

- As bitcoin is running in a shared network. Checking data by confirmation is not a recommended solution.

if($data['Confirmations'] == 0) {

//include code to get the confirmation at 0. Apply your business logic
$file = 'doc.txt';
file_put_contents($file, $json); //record in textfile
}else{
//include code to get the confirmation at final number. Apply your business logic.
$file = 'doc.txt';
file_put_contents($file, "confirmation done"); //record in textfile
}

- we recommend the following algorithm. The algorithm is written in psuedocode:

#use the receipt no
$rNo = $data['Receipt']

#check if the data with the receipt no exist in database #update the record
if (data exist in database):
    #update the record
else:
    #create a new record