Bitcoin Forum
May 27, 2019, 12:51:07 AM *
News: Latest Bitcoin Core release: 0.18.0 [Torrent] (New!)
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [1 BTC bounty] Update blockchain.info API receive code  (Read 1876 times)
OpenYourEyes
Full Member
***
Offline Offline

Activity: 238
Merit: 100



View Profile
March 15, 2013, 05:52:10 AM
Last edit: March 20, 2013, 04:46:03 PM by OpenYourEyes
 #1

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.

takemybitcoins.com: Spend a few seconds entering a merchants email address to encourage them to accept Bitcoin
PGP key | Bitmessage: BM-GuCA7CkQ8ojXSFGrREpMDuWgv495FUX7
1558918267
Hero Member
*
Offline Offline

Posts: 1558918267

View Profile Personal Message (Offline)

Ignore
1558918267
Reply with quote  #2

1558918267
Report to moderator
1558918267
Hero Member
*
Offline Offline

Posts: 1558918267

View Profile Personal Message (Offline)

Ignore
1558918267
Reply with quote  #2

1558918267
Report to moderator
GET 25 FREE SPINS AT REGISTRATION
GET 100% BONUS ON FIRST DEPOSIT
PLAY NOW
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1558918267
Hero Member
*
Offline Offline

Posts: 1558918267

View Profile Personal Message (Offline)

Ignore
1558918267
Reply with quote  #2

1558918267
Report to moderator
rme
Hero Member
*****
Offline Offline

Activity: 742
Merit: 500



View Profile
.
March 15, 2013, 06:42:14 AM
Last edit: December 21, 2016, 08:52:39 PM by rme
 #2

.
kadoban
Newbie
*
Offline Offline

Activity: 16
Merit: 0


View Profile WWW
March 18, 2013, 12:01:55 PM
 #3

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

Activity: 238
Merit: 100



View Profile
March 18, 2013, 03:50:35 PM
 #4

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.

takemybitcoins.com: Spend a few seconds entering a merchants email address to encourage them to accept Bitcoin
PGP key | Bitmessage: BM-GuCA7CkQ8ojXSFGrREpMDuWgv495FUX7
kadoban
Newbie
*
Offline Offline

Activity: 16
Merit: 0


View Profile WWW
March 18, 2013, 04:48:49 PM
 #5

Sure, sounds like a plan.  If you give any extra info, could you post it here as well?
OpenYourEyes
Full Member
***
Offline Offline

Activity: 238
Merit: 100



View Profile
March 18, 2013, 04:58:05 PM
 #6

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.

takemybitcoins.com: Spend a few seconds entering a merchants email address to encourage them to accept Bitcoin
PGP key | Bitmessage: BM-GuCA7CkQ8ojXSFGrREpMDuWgv495FUX7
Ditto
Sr. Member
****
Offline Offline

Activity: 330
Merit: 250


View Profile
March 19, 2013, 07:38:20 AM
 #7

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

Activity: 330
Merit: 250


View Profile
March 19, 2013, 01:14:38 PM
 #8

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

Activity: 238
Merit: 100



View Profile
March 19, 2013, 05:47:09 PM
Last edit: March 19, 2013, 06:17:43 PM by OpenYourEyes
 #9

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?

takemybitcoins.com: Spend a few seconds entering a merchants email address to encourage them to accept Bitcoin
PGP key | Bitmessage: BM-GuCA7CkQ8ojXSFGrREpMDuWgv495FUX7
kadoban
Newbie
*
Offline Offline

Activity: 16
Merit: 0


View Profile WWW
March 19, 2013, 06:53:40 PM
 #10

Well, looks like Ditto mostly took care of what I was planning on.  I'll let him finish it up.
Ditto
Sr. Member
****
Offline Offline

Activity: 330
Merit: 250


View Profile
March 20, 2013, 02:27:34 AM
 #11

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

Activity: 238
Merit: 100



View Profile
March 20, 2013, 04:52:22 PM
Last edit: March 20, 2013, 05:06:03 PM by OpenYourEyes
 #12

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.

takemybitcoins.com: Spend a few seconds entering a merchants email address to encourage them to accept Bitcoin
PGP key | Bitmessage: BM-GuCA7CkQ8ojXSFGrREpMDuWgv495FUX7
Cyrus
Ninja
Administrator
Legendary
*
Offline Offline

Activity: 2254
Merit: 1118



View Profile
May 26, 2013, 07:08:06 PM
 #13

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?

Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!