Author

Topic: Implementing code to receive bitcoin payments (Read 862 times)

legendary
Activity: 1736
Merit: 1029
November 08, 2016, 07:37:15 PM
#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!
member
Activity: 148
Merit: 45
https://bitaps.com/
November 07, 2016, 09:21:15 AM
#7
If you still need to use API - you can use it unlimited.
Welcome!
legendary
Activity: 1512
Merit: 1057
SpacePirate.io
November 07, 2016, 09:17:22 AM
#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://bitcointalksearch.org/topic/--1672715
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
member
Activity: 148
Merit: 45
https://bitaps.com/
November 07, 2016, 07:19:14 AM
#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!
newbie
Activity: 26
Merit: 0
November 06, 2016, 05: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..
legendary
Activity: 1382
Merit: 1122
November 06, 2016, 05: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.
newbie
Activity: 26
Merit: 0
November 06, 2016, 05: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 (or whatever you want to show the button), you should add:

Code:
Bitcoin Payment
Please send Exactly echo $value_in_btc?> to
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.
legendary
Activity: 1736
Merit: 1029
November 06, 2016, 01: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://bitcointalksearch.org/topic/--1672715
Please let me know where it belongs.
Jump to: