Author

Topic: Blockchain API Simple PHP Problem - .03 bitcoin reward (Read 1859 times)

newbie
Activity: 7
Merit: 0
Hi,
i had alot of problems with this Bitcoin API too, specialy the callback URL
after 2 nights of Headaches,i finaly found the problem :p
this is a DEMO, who is interesting to integrate this LOVELY API on his website he can "Check before Buy" here is the link : http://ex-currency.com/btc/index.php
Payment Sent/Recieved/Confirmed IMMEDIATLY
the price of curiosity is 1 USD
legendary
Activity: 1260
Merit: 1168
This message was too old and has been purged
member
Activity: 66
Merit: 10
I'm just curious, did this problem get solved and was the bounty paid?
hero member
Activity: 525
Merit: 531
legendary
Activity: 1260
Merit: 1168
This message was too old and has been purged
sr. member
Activity: 434
Merit: 250
Edit: Also, why are you using cURL here? Seems needless?

I'm confused at the cURL too, perhaps it's supposed to be sending a second notification via a web URL too but that line or two to setup the cURL correctly is missing?.. The code sends the mail() and then passes the same data to cURL straight after.

and $ch isn't even set anywhere....
full member
Activity: 120
Merit: 100
If its sending once every hour without confirmations=1 then i'm guessing the script is being automated to run once an hour and the email will only be sent when it is told to run AND 'confirmations' is exactly 1, so if its 0 or 2 or more, nothing is be sent. A shitty fix would be to set if confirmations > 0 && < 7. It would work most of the time, except occasionally people will get 2 emails or none if a load of blocks are solved faster or slower than usual. The only proper way to do it is use a database and record when you send the email.
newbie
Activity: 50
Merit: 0
Edit: Also, why are you using cURL here? Seems needless?

I'm confused at the cURL too, perhaps it's supposed to be sending a second notification via a web URL too but that line or two to setup the cURL correctly is missing?.. The code sends the mail() and then passes the same data to cURL straight after.
sr. member
Activity: 434
Merit: 250
What I'd do, is store transactions in a database table. Check the tx hash of the transaction hitting the callback, if it doesn't exist in the database insert it and send the email. If it DOES exist in the database, just either ignore it, or update it with a different confirmation count.

Edit: Also, why are you using cURL here? Seems needless?
member
Activity: 94
Merit: 10
is there simple code for that? I have no idea how to do it. willing to pay more if its more work..I thought this would be a simple fix
hero member
Activity: 525
Merit: 531
store somewhere (session or database) if you already sent the mail.

Elbandi
member
Activity: 94
Merit: 10
edit: thanks for the advice all but I was looking for the actual code. Just hired someone on fiverr to write it. the curl and other extraneous code was from previous attempts.


Hey all. I don't know much about php but have been trying to get this api script working. This is the callback script which is supposed to send two letters after bitcoin has been sent with one confirmation: one to me and one to the customer. I am having a hard time getting this to send an email after just one confirmation. If I take this part out: "if ($_GET['confirmations'] == 1)" then it will send me emails every hour with different confirmation amounts. But if I put this qualifier in it sends me nothing. I am guessing that maybe when the script is kicks in the number of confirmations might be over 1 already? How do I solve this to get the script to send just one email after one confirmation? First person to reply with fix and their wallet address gets reward.



/**
 * Callback endpoint for the Blockchain Receive API.
 *
 * Notifies the administrator when a watched address has a new transaction.
 */

if ($_GET['confirmations'] < 1) {
  die('Waiting for 1 notification.');
}



$to = '[email protected]';
$subject = 'New transaction through Blockchain API';

$message = 'There is a new transaction detected by the Blockchain API.' . "\r\n\r\n";
$message .= 'Amount:           ' . sprintf('%02.8f', ($_GET['value'] / 100000000)) . ' BTC'. "\r\n";
$message .= 'Address:          ' . $_GET['input_address'] . "\r\n";
$message .= 'Confirmations:    ' . $_GET['confirmations'] . "\r\n";
$message .= 'Track:            http://blockchain.info/tx/' . $_GET['transaction_hash'] . "\r\n";
$message .= 'Customer\'s email: ' . $_GET['email'] . "\r\n";
$headers = 'From: "Blockchain API endpoint" <[email protected]>';

$fields = array(
  'to' => $to,
  'subject' => $subject,
  'message' => $message,
  'headers' => $headers,
);

$postvars = http_build_query($fields);

if ($_GET['confirmations'] == 1) {
   mail($to, $subject, $message, $headers);
}


curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);

$res = curl_exec($ch);

if ($res == 'ok') {
  echo '*ok*';
}
else {
  echo 'Mail not sent!';
  echo $res;
}

if (isset($_GET['email'])) {
  $to = $_GET['email'];
  $subject = 'Payment Verification';
  $message = 'This is an automatic notification that I have received a payment for your order.' . "\r\n\r\n";
  $message .= 'Your item should arrive in the mail within a week.';
  $headers = 'From: "Marley" <[email protected]>';
 
  $fields = array(
    'to' => $to,
    'subject' => $subject,
    'message' => $message,
    'headers' => $headers,
  );

  $postvars = http_build_query($fields);

if ($_GET['confirmations'] == 1) {
   mail($to, $subject, $message, $headers);
}


  curl_setopt($ch, CURLOPT_POST, TRUE);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($ch, CURLOPT_HEADER, FALSE);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);

  $res = curl_exec($ch);
}
Jump to: