Bitcoin Forum

Bitcoin => Project Development => Topic started by: Zz on January 08, 2017, 12:37:53 PM



Title: Simple donation system in PHP
Post by: Zz on January 08, 2017, 12:37:53 PM
I want to write a donation system with the simplest form of PHP programming language.
The first step is to generate a bitcoin address.
I will generate the QR code for this bitcoin address and put it on the site.
The screen I imagine is as follows:
https://i.imgur.com/cr3k3On.png
I'm investigating an this matter.
There are also ready services for this matters, but I want to code myself.
how to list bitcoin transactions in PHP
I need suggestions.

thanks in advance


Title: Re: Simple donation system in PHP
Post by: Moritz30 on January 08, 2017, 01:31:41 PM
I want to write a donation system with the simplest form of PHP programming language.
The first step is to generate a bitcoin address.
I will generate the QR code for this bitcoin address and put it on the site.
The screen I imagine is as follows:
https://i.imgur.com/cr3k3On.png
I'm investigating an this matter.
There are also ready services for this matters, but I want to code myself.
how to list bitcoin transactions in PHP
I need suggestions.

thanks in advance

You could use a coinbase wallet users send donations to and use the Coinbase API (http://"https://developers.coinbase.com/") to get the transactions.


Title: Re: Simple donation system in PHP
Post by: OmegaStarScream on January 08, 2017, 05:05:41 PM
Since you are not looking to generate a unique address for each user then you should simply put an address that fits you and then gather transactions that gets sent to it with the balance , I suggest using the blocktrail API here : https://www.blocktrail.com/api/docs and you could use the sample given and explained here : http://bitcoin.stackexchange.com/questions/34300/how-to-get-the-list-of-transactions-that-has-gone-into-an-address-with-the-amoun


Title: Re: Simple donation system in PHP
Post by: coinableS on January 08, 2017, 05:09:55 PM
There's really no need for PHP, you could do it client-side with javascript and websocket. In fact I just did a blog post for blockchain.info on how to do this. https://blog.blockchain.com/2017/01/04/intro-to-bitcoin-development/

However if you really want PHP it's easy enough, but new donations won't show up LIVE unless you use something like websocket or AJAX.

Code:
<?php
$address 
"YOUR_BTC_ADDRESS";

$qrurl "http://chart.googleapis.com/chart?chs=125x125&cht=qr&chl=".$address;
$qrcode "<img src='".$qrurl."'>";
//this is just an image created using google charts API

//get JSON data on address using blockchain.info free public API
$url "https://blockchain.info/address/".$address."?format=json";
$json json_decode(file_get_contents($url), true);

?>

<html>
<body>
Bitcoin Donations Accepted
<br>
<?php echo $qrcode?>
<br>
<table>
<tr>
   <td>Received From</td>
   <td>Amount</td>
</tr>
<?php
//loop through the last 4 received donations
for($i=0;$i<5;$i++){
   
$outputs count($json["txs"][$i]["out"]);
   
//loop through each output of the tx
   
for($ii=0;$ii<$outputs;$ii++){
      
//check if output addy matches our donation addy
      
$outaddy $json["txs"][$i]["out"][$ii]["addr"];
      
$value $json["txs"][$i]["out"][$ii]["value"];
      
$value $value 100000000;
      if(
$outaddy == $address){
          echo 
"<tr><td>".$json['txs'][$i]['inputs'][0]['prev_out']['addr']."</td><td>".$value."BTC</td></tr>";
      }
   }
}
?>

</table>
</body>
</html>


Example output:
https://i.imgur.com/6wohQ5a.jpg


Title: Re: Simple donation system in PHP
Post by: AikFrank on January 10, 2017, 06:14:30 PM
Yes its possible with PHP. I have done this with PHP, very simple and straight forward.

Hit me up for learning cost ;D


Title: Re: Simple donation system in PHP
Post by: Zz on January 11, 2017, 08:17:50 AM
There's really no need for PHP, you could do it client-side with javascript and websocket. In fact I just did a blog post for blockchain.info on how to do this. https://blog.blockchain.com/2017/01/04/intro-to-bitcoin-development/

However if you really want PHP it's easy enough, but new donations won't show up LIVE unless you use something like websocket or AJAX.


The information you gave me solved my problem.
thank you so much I'm very happy :)

https://i.imgur.com/wZeGSA8.png


I will continue to work to resolve this issue in php language.