Bitcoin Forum
May 25, 2024, 12:44:55 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Blockchain API Simple PHP Problem - .03 bitcoin reward  (Read 1853 times)
cosmicboy (OP)
Member
**
Offline Offline

Activity: 94
Merit: 10


View Profile
March 27, 2014, 04:00:23 PM
Last edit: March 28, 2014, 08:33:32 PM by cosmicboy
 #1

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.


<?php

/**
 * 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 = 'marley4567@gmail.com';
$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" <noreply@noreply.com>';

$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" <marley4567@gmail.com>';
 
  $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);
}
elbandi
Hero Member
*****
Offline Offline

Activity: 525
Merit: 529


View Profile
March 27, 2014, 05:22:11 PM
 #2

store somewhere (session or database) if you already sent the mail.

Elbandi
cosmicboy (OP)
Member
**
Offline Offline

Activity: 94
Merit: 10


View Profile
March 27, 2014, 07:17:35 PM
 #3

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
leckey
Sr. Member
****
Offline Offline

Activity: 434
Merit: 250


View Profile
March 27, 2014, 08:47:57 PM
 #4

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?

gwlloyd
Newbie
*
Offline Offline

Activity: 50
Merit: 0


View Profile
March 28, 2014, 03:33:17 AM
 #5

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.
solomon
Full Member
***
Offline Offline

Activity: 120
Merit: 100



View Profile
March 28, 2014, 04:21:10 AM
 #6

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.

bitcoin price ticker | bits.so
leckey
Sr. Member
****
Offline Offline

Activity: 434
Merit: 250


View Profile
March 28, 2014, 11:24:57 AM
 #7

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....

Evil-Knievel
Legendary
*
Offline Offline

Activity: 1260
Merit: 1168



View Profile
March 28, 2014, 11:55:44 AM
Last edit: April 17, 2016, 10:05:04 PM by Evil-Knievel
 #8

This message was too old and has been purged
elbandi
Hero Member
*****
Offline Offline

Activity: 525
Merit: 529


View Profile
March 28, 2014, 01:01:49 PM
 #9

Use this small adjustment :-)



 Grin
jimbursch
Member
**
Offline Offline

Activity: 66
Merit: 10


View Profile WWW
March 31, 2014, 04:42:17 PM
 #10

I'm just curious, did this problem get solved and was the bounty paid?

MyMindshare -- a commercial messaging system -- check it out at  *Link Removed*
Evil-Knievel
Legendary
*
Offline Offline

Activity: 1260
Merit: 1168



View Profile
March 31, 2014, 10:30:56 PM
Last edit: April 17, 2016, 09:59:51 PM by Evil-Knievel
 #11

This message was too old and has been purged
ExchangeCurrency
Newbie
*
Offline Offline

Activity: 7
Merit: 0


View Profile
October 24, 2014, 04:35:16 AM
 #12

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
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!