Bitcoin Forum
May 09, 2024, 09:28:12 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Implementing code to receive bitcoin payments  (Read 860 times)
monbux (OP)
Legendary
*
Offline Offline

Activity: 1736
Merit: 1029



View Profile WWW
November 06, 2016, 06:43:31 PM
 #1

Working on a project right now and I want to have a pay with bitcoin button where the user pays a bitcoin amount pegged to a set dollar value, with a uniquely generated bitcoin address for each purchase.  We want to make it so that the instant the payment is visible on the blockchain, the order will go through.

How do we go about implementing this kind of code (Using javascript and firebase), and how do we make the order go through once the payment is accepted?  Will blockchain API help for all of this?
Kind of new to web development and this kind of stuff, so any help is greatly appreciated!

Want it to pop up like this:



Note to mods: Also posted here: https://bitcointalk.org/index.php?topic=1672715.0
Please let me know where it belongs.
1715290092
Hero Member
*
Offline Offline

Posts: 1715290092

View Profile Personal Message (Offline)

Ignore
1715290092
Reply with quote  #2

1715290092
Report to moderator
You get merit points when someone likes your post enough to give you some. And for every 2 merit points you receive, you can send 1 merit point to someone else!
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715290092
Hero Member
*
Offline Offline

Posts: 1715290092

View Profile Personal Message (Offline)

Ignore
1715290092
Reply with quote  #2

1715290092
Report to moderator
yomumn
Newbie
*
Offline Offline

Activity: 26
Merit: 0


View Profile
November 06, 2016, 10:22:55 PM
 #2

Hey @monbux!

In your PHP code you need something like this:

Code:
$secret = 'ZzsMLGKe162CfA5EcG6j';

$my_xpub = '{YOUR XPUB ADDRESS}';
$my_api_key = '{YOUR API KEY}';

$my_callback_url = 'https://mystore.com?invoice_id=058921123&secret='.$secret;

$root_url = 'https://api.blockchain.info/v2/receive';

$parameters = 'xpub=' .$my_xpub. '&callback=' .urlencode($my_callback_url). '&key=' .$my_api_key;

$response = file_get_contents($root_url . '?' . $parameters);

$object = json_decode($response);

echo 'Send Payment To : ' . $object->address;

And

Code:
$real_secret = 'ZzsMLGKe162CfA5EcG6j';
$invoice_id = $_GET['invoice_id']; //invoice_id is passed back to the callback URL
$transaction_hash = $_GET['transaction_hash'];
$value_in_satoshi = $_GET['value'];
$value_in_btc = $value_in_satoshi / 100000000;

//Commented out to test, uncomment when live
if ($_GET['test'] == true) {
    return;
}

try {
  //create or open the database
  $database = new SQLiteDatabase('db.sqlite', 0666, $error);
} catch(Exception $e) {
  die($error);
}

//Add the invoice to the database
$stmt = $db->prepare("replace INTO invoice_payments (invoice_id, transaction_hash, value) values(?, ?, ?)");
$stmt->bind_param("isd", $invoice_id, $transaction_hash, $value_in_btc);

if($stmt->execute()) {
   echo "*ok*";
}

Instead of:
Code:
echo 'Send Payment To : ' . $object->address;

Delete that, and inside your <body> (or whatever you want to show the button), you should add:

Code:
<b>Bitcoin Payment</b></br>Please send Exactly <?php echo $value_in_btc?> to</br><?php echo $object->address?>

You can read more here: https://blockchain.info/pt/api/api_receive

Hope i was helpful. If you have more questions just message me or post here.

EDIT: This isn't enough for what you want. But i can't help more without details though.
Chris!
Legendary
*
Offline Offline

Activity: 1382
Merit: 1122



View Profile
November 06, 2016, 10:32:17 PM
 #3

I'm definitely not an expert here (far from it) but this sounds a lot like what achow101 has developed here. It's a tipping address that generates a new one after each tip is sent.
yomumn
Newbie
*
Offline Offline

Activity: 26
Merit: 0


View Profile
November 06, 2016, 10:37:59 PM
 #4

I'm definitely not an expert here (far from it) but this sounds a lot like what achow101 has developed here. It's a tipping address that generates a new one after each tip is sent.

Well i think it's a little different because on "Bitcoin Tipping Addresses" you need to enter a list up to 1000 addresses. It will basically pick a random address from the one of the list after a tip/address gets balance.

@monbux wants to generate some kind of "invoice" that generates a unique address (with json-rpc connected to the wallet), and it gives the amount of BTC that user needs to pay. Once the address gets the amount of BTC, the invoice will switch to "paid" on Database and it will redirect to content or something (depends of what is the invoice for).

I think it's this..
bitaps
Member
**
Offline Offline

Activity: 148
Merit: 45

https://bitaps.com/


View Profile WWW
November 07, 2016, 12:19:14 PM
 #5

Try to use easy API https://bitaps.com/api/#Create_payment_address

Just change parametrs and copy past PHP code.
It's free without any registration keys or delaying.

If need support - I can help you!

cloverme
Legendary
*
Offline Offline

Activity: 1512
Merit: 1057


SpacePirate.io


View Profile WWW
November 07, 2016, 02:17:22 PM
 #6

Working on a project right now and I want to have a pay with bitcoin button where the user pays a bitcoin amount pegged to a set dollar value, with a uniquely generated bitcoin address for each purchase.  We want to make it so that the instant the payment is visible on the blockchain, the order will go through.

How do we go about implementing this kind of code (Using javascript and firebase), and how do we make the order go through once the payment is accepted?  Will blockchain API help for all of this?
Kind of new to web development and this kind of stuff, so any help is greatly appreciated!

Want it to pop up like this:

Note to mods: Also posted here: https://bitcointalk.org/index.php?topic=1672715.0
Please let me know where it belongs.

I've done this in PHP, but not JS or Firebase. In short, you're probably better off getting a developer to code it for you. I don't recommend using blockchain.info or another wallet service, they often get DDoS'd causing a disruption and some API limits. You're better off running a node and doing your code through it and there's no limitations.

Basic process:
Generate new address from wallet
Calculate fiat/usd/etc to BTC
Store address, btc amount, usd amount, order number, customer data in database
Display address, qrcode, and btc amount requested
Have a backend process check addresses in the database that are unconfirmed
Once the address is funded with the amount, run the action that you want to for a successful transaction
Save the bitcoin tx into the database once you get the number of confirmations you want.
Notify the customer by email, etc that the amount was received
Update your admin panel for any transaction data
bitaps
Member
**
Offline Offline

Activity: 148
Merit: 45

https://bitaps.com/


View Profile WWW
November 07, 2016, 02:21:15 PM
 #7

If you still need to use API - you can use it unlimited.
Welcome!

monbux (OP)
Legendary
*
Offline Offline

Activity: 1736
Merit: 1029



View Profile WWW
November 09, 2016, 12:37:15 AM
 #8

Thanks so much for the responses!!  Will work with all the advice once workload decreases, but the information here is seriously helpful.
Probably will have more questions though, so keeping this thread open.

Thanks again everyone!
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!