Author

Topic: [1 BTC bounty] Update blockchain.info API receive code (Read 1988 times)

administrator
Activity: 3962
Merit: 3184
Hopefully this helps other users too:

Here's the order page
The callback page
SQL to create DB

Unknown Paste ID!

I guess they expired. Could you upload them again?
full member
Activity: 238
Merit: 100
Ah, ok.

rme provided some fully working code yesterday which pretty much hits all the requirements I need.

Hopefully this helps other users too:

Here's the order page
The callback page
SQL to create DB

rme's public BTC address if you find the code useful also: 1R2sWeVhFitB8zVbkrmdSoXzaQRsw6cfh

I've sent rme 1.7BTC as it does everything I need, and is clearly commented. Transaction
It's not a lot, ditto, but I've also sent you 0.3BTC for your effort. Transaction

Thanks to all who looked.
Hopefully the code can be improved upon by others, and ideally the blockchain.info API receive page be updated just to make it a bit more clear.
sr. member
Activity: 330
Merit: 250
Thanks Ditto, been trying this for about an hour, still no luck.

On the 'order' page, you're trying to insert the GET value of refund_addr, but it has not been assigned any value, and I can't see where it would obtain one: blockchain.info doesn't give back this value, and it is being inserted into the DB before any blockchain.info code has been called.

$stmt = $db->prepare("INSERT INTO invoices VALUES(null, :refund_addr, 0)");
$stmt->execute(array(':refund_addr' => $_GET['refund_addr']));

Edit:
Having a problem with blockchain.info

It is taking them hours to forwarded funds back to me, even though the transaction I sent to the address generated had more than 6 confirmations, I didn't get the transaction forwaded back to my receiving address until 4.5 hours after.
Is that normal?
I should have made it clearer. $_GET['refund_addr'] is passed in through the URL from a form, in order to have an address on file in case a refund needs to be given (for example, if a user sends you funds from a Mtgox wallet you can't refund the coins to the address you received them from)

Take a look at the updated order page for an example - https://gist.github.com/anonymous/74c1d02f1c13bf085b61
newbie
Activity: 16
Merit: 0
Well, looks like Ditto mostly took care of what I was planning on.  I'll let him finish it up.
full member
Activity: 238
Merit: 100
Thanks Ditto, been trying this for about an hour, still no luck.

On the 'order' page, you're trying to insert the GET value of refund_addr, but it has not been assigned any value, and I can't see where it would obtain one: blockchain.info doesn't give back this value, and it is being inserted into the DB before any blockchain.info code has been called.

$stmt = $db->prepare("INSERT INTO invoices VALUES(null, :refund_addr, 0)");
$stmt->execute(array(':refund_addr' => $_GET['refund_addr']));

Edit:
Having a problem with blockchain.info

It is taking them hours to forwarded funds back to me, even though the transaction I sent to the address generated had more than 6 confirmations, I didn't get the transaction forwaded back to my receiving address until 4.5 hours after.
Is that normal?
sr. member
Activity: 330
Merit: 250
I just took blockchain.info 's example code and modified it a bit to create a row in an "invoices" table which is marked unpaid at first. When the callback page is called, the corresponding invoice in the table is updated to show that it is paid once  the transaction reaches 3 confirmations.

Order page - https://gist.github.com/anonymous/266b166175d059b3d723
Callback page - https://gist.github.com/anonymous/b943bd2bef536b22bd46
SQL for table - https://gist.github.com/anonymous/5b1fba87793750a9c230
sr. member
Activity: 330
Merit: 250
Seems easy enough. I'll write up a script and send it to you in a few hours - I would do it now but I don't have access to my PC atm.
full member
Activity: 238
Merit: 100
Ideally I'd like to not have the code tied to a specific need, i.e mine, as I would like the code to be easily able adaptable by any one who wishes to implement the API; however, what I am after is giving access to a service once the payment is complete.

So, when the user has registered/signed in, they click a 'buy now' button/link; a new DB record is added into an 'unpaid' table with the invoice ID & username; the user is then presented with the payment address; (optional) once the transaction has been noticed the page updates to confirm a payment has been seen; then after 2 confirms, (optional) the page updates saying the payment has been accepted, and then a new record is added to a paid database.

Thanks.
newbie
Activity: 16
Merit: 0
Sure, sounds like a plan.  If you give any extra info, could you post it here as well?
full member
Activity: 238
Merit: 100
It would be great to see more code by other users.

Hopefully then this thread could be a reference for other users who also wish to implement and use the API.

rme, has messaged me asking for more details about the service, but if you are both able to provide working code, and it is ok with you both, I'll be happy to split the pot and send you both 1BTC.

Thanks for taking a look.
newbie
Activity: 16
Merit: 0
Hope I'm not stepping on your toes, rme, but I got interested and starting working on this.  I should have something to show this evening.

Let me know if you've already taken care of it or something like that, OpenYourEyes.
rme
hero member
Activity: 756
Merit: 504
full member
Activity: 238
Merit: 100
Bounty over, but feel free to add improvements so others can easily get to grips with the API.

I know it's not a large bounty, but I'm not the richest of Bitcoin folk.

I tried many months ago to use the API blockchain.info provide to receive payments and update a MySql database accordingly, however I didn't have much luck. (https://blockchain.info/api/api_receive)

I've been trying again today, and I'm still non the wiser: I don't know whether it's due to poor documentation, buggy example code, or I just suck at coding (most likely).
I know they're alternative services out there (like BitPay, and OpenCart), but I'd rather have as much control over the system as possible, not pay any fees, and it seems a little overkill for just 1 item (well, service) I'm selling.

I found this git repo. (https://github.com/blockchain/receive_payment_php_demo) which is something similar to what I'm after, but it's still not all there in that it lacks a bit of documentation, and seems out of date.

So I'll pay 1BTC if someone can provide working/updated demo PHP code that fulfils the requirements below:

  • I have just 1 item that I will be selling, I need code that generates an invoice ID for the transaction, sends this off to blockchain.info and assigns a BTC address for the user to send to, and then stores this in an "unpaid" database table.
  • Have the page update when a payment is noticed
  • When the exact amount has been paid, and the number of confirmations equals, say, 3 it updates the database to confirm it has been paid
  • A little bit of commenting, or documentation to go along with the code.

If I deem it as super, duper coding then I'll bump the bounty to 2BTC, and if there is more than one entry, I'll pick the one the works the best for me.

It's 6am so I'm off to rest my little stressed head.
Thanks.
Jump to: