The next code snippets require above curl_request function and the variables secretPhrase, server and shop
It shows undelivered Items. Currently it does not deliver the Item when run. You need to get rid of the // before $json_delivery and var_dump($json_delivery) to enable and show Delivery of an Item.
Modify the variables to place your text in the delivery, a download link or whatever.
<?php
//get undelivered items
$getItems = file_get_contents($server.'?requestType=getDGSPendingPurchases&seller='.$shop);
$obj = json_decode($getItems);
$json_purchases = $obj->{'purchases'};
echo '<h1>Undelivered Items</h1>';
var_dump($json_purchases);
echo '<h2>Example access</h2>';
$amount_purchases = count($json_purchases);
for($x=0;$x<$amount_purchases;$x++) {
echo 'Buyer: '.htmlspecialchars($json_purchases[$x]->buyerRS);
echo '<br>';
echo 'Quantity: '.htmlspecialchars($json_purchases[$x]->quantity);
echo '<br>';
echo 'Purchase: '.htmlspecialchars($json_purchases[$x]->purchase).' this is the product ID';
$undelivered_array[$x] = $json_purchases[$x]->purchase;
}
//purchase Delivery
function purchaseDelivery ($purchase,$goodsToEncrypt, $deadline, $feeNQT, $secretPhrase, $server) {
// URL is again our before defined Serverurl
$url = $server;
$data = array(
'requestType' => 'dgsDelivery',
'purchase' => urlencode($purchase),
'goodsToEncrypt' => urlencode($goodsToEncrypt),
'feeNQT' => urlencode($feeNQT),
'deadline' => urlencode($deadline),
'secretPhrase' => urlencode($secretPhrase)
);
//Do the curl function defined at the beginning
$json = curl_request($url, $data);
return $json;
}
//Undelivered Items
if(!empty($undelivered_array)) {
$amount_undelivered = count($undelivered_array);
//Loop through the undelivered Items and make the purchase delivery. You should delay it, or save the different purchase deliverys in a database to prevent double spending.
//To make it automatic, you can use a Cron
//Be safe with POST requests that contain your secretPassphrase
//You should delay any purchase delivery after the purchase. The more time you delay it after the purchase, the more secure the purchase will be.
for($x=0;$x<$amount_undelivered;$x++) {
echo '<h2>Delivery of: '.htmlspecialchars($json_purchases[$x]->purchase).'</h2>';
$purchase = $json_purchases[$x]->purchase;
$goodsToEncrypt = 'Here you can put the Info to be seen encrypted by the NXT user';
$feeNQT = 100000000;
$deadline = 1000;
//$json_delivery = purchaseDelivery($purchase,$goodsToEncrypt, $deadline, $feeNQT, $secretPhrase, $server);
//var_dump($json_delivery);
}
}
?>