Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Blockchain by (12.7k points)

Callback:

<?php 

$id =""; 

$pw = "";

$secret = "f8fe526080ec3366eddbb498c6df4e1a"; //md5 hash a unui cuvant 

$address = "1MBF4cGmVac3r561YYRcamqJKN269yk7aD";

if($_GET['secret'] != $secret){ 

echo "Invalid"; 

return; 

if($_GET['mainaddress'] != $address){ 

echo "Invalid"; 

return; 

if (!isset($_GET['btc'])){ 

echo "Invalid"; 

return; 

if (!isset($_GET['value'])){ 

echo "Invalid"; 

return; 

$price = $_GET['btc']; 

$value= $_GET['value'] / 10000000;

if ($price >= $value){ 

$email = "[email protected]"; 

$subject = "Payment Received"; 

$body = "Payment received for invoice #". $_GET['invoice'] . "\r\n" . "Price: " . $price . " BTC" . "\r\n"; 

$headers = "From: GoBets <[email protected]>". "\r\n"; 

$headers .= "Content-type: text/html\r\n"; 

$mail = mail($email, $subject, $body, $headers);

}else{ 

$mail2 = mail($email, "rekt","hdhdhd",$headers); 

}

if($mail){ 

echo "*ok*"; // return code pentru blockchain 

}

if ($mail2){ 

echo "*ok*"; 

?> 

The way im creating an address and setting the callback url:

<?php

session_start();

$secret = "f8fe526080ec3366eddbb498c6df4e1a";   //md5 hash a unui cuvant

$address = "1MBF4cGmVac3r561YYRcamqJKN269yk7aD";  

if ($_GET['test'] == true) {

      echo 'Ignoring Test Callback';

      return;

   }

if(isset($_GET['key'])) {

if ($_GET['key'] == "p1"){

$price_in_usd = 1;

} elseif($_GET['key'] =="p2"){

$price_in_usd = 4.5;

} elseif($_GET['key'] =="p3"){

$price_in_usd = 8;

} elseif($_GET['key'] =="p4"){

$price_in_usd = 15;

}elseif($_GET['key'] == "test"){

$price_in_usd = 0.3;

}else{

echo "Invalid param. Please contact an administrator or try again later";

}

if ($price_in_usd <> ""){

$price_in_btc = file_get_contents("https://blockchain.info/tobtc?currency=USD&value=" . $price_in_usd);

$invoice = $_SESSION['s_ID'] . "-" . rand();

$callback = "http://gobets.pw/purchase/callback.php?invoice=".$invoice."&secret=".$secret."&mainaddress=".$address ."&btc=" . $price_in_btc;

$result = json_decode(file_get_contents("https://blockchain.info/api/receive?method=create&address=".$address."&callback=" .urlencode($callback)), true);

$qrcode = "https://blockchain.info/qr?data=bitcoin:". $result["input_address"]. "?amount=" . $price_in_btc;

echo '<div align="center">';

echo '<img src="'.$qrcode.'"' . 'height="125" width="125"/>' . "</br>";

echo "Invoice #: " . $invoice . "<br>";

echo "Please send <b>" . $price_in_btc ."</b> BTC to <b>".  $result["input_address"] . "</b></br>";

echo "</div>";

}

} else {

    echo "Something went wrong!";

}

?>

Nothing is happening when I'm sending money to the generated address except blockchain sending that amount back to my main address. What am I doing wrong?

1 Answer

0 votes
by (29.5k points)
edited by

The problem is in the callback.php script.:

if ($price >= $value)
which basically means:

if
price to be paid > price paid then payment is succesful
which was wrong, changed it to:

if ($value >= $price)
and now it should work.

There is a lot more to learn than this. Enroll now in Blockchain Online Course to learn more.

Related questions

Browse Categories

...