Bitcoin Forum
May 30, 2024, 09:20:53 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Integrate Bitcoin payment into my node app. Where to start?  (Read 901 times)
chovy (OP)
Newbie
*
Offline Offline

Activity: 51
Merit: 0


View Profile WWW
July 27, 2014, 02:58:13 AM
 #1

I'm trying to get a high level overview of what I need to do in order to integrate bitcoin payment in my web app.

I do not want to use a third party payment process like coinbase or bitpay, as that goes against the spirit of p2p currency.

Here is the basic idea:

* user clicks "pay now" button
* backend generates a new address in a wallet I control for user to send payment to
* user then sends payment to that address
* client pings backend waiting for confirmation payment was received at that unique address and in correct amount
* invoice is then marked as "paid" and tagged with transaction id.


So I know I have to have bitcoind running, I already have a full node running, and I'm aware that I can make json-rpc calls to bitcoind.

But how do I generate a new address for each invoice? Its my understanding bitcoind does not have a wallet.

I'm developing this app in node.js, so if I can leverage some npm modules to make things easier, even better.

I dont' need anything fancy, just a random payment address in a wallet I control and confirmation that payment was received.

I can do the long polling and client side stuff no problem.

I like to learn from examples, so if anybody can point to some code on Github that does something similar, even if its not javascript, I can probably figure it out. I haven't found anything besides bitpay/coinbase integration in Google.
kingama
Member
**
Offline Offline

Activity: 94
Merit: 10


View Profile
July 27, 2014, 06:53:25 AM
 #2

Bitcoind certainly does have a wallet. You can even pre-generate the addresses by the hundreds or thousands to less the load when a new customer appears. Use listtransactions and watch that payments have as many confirmations as you want before moving your payment process status along.

Also be sure to track incoming payments by txid and address together as transactions can have multiple outputs. That should help you in the future in case a customer gets tricky with their payments.

I don't know anything about node but since you're developing this yourself, I think there's value in using few modules and publishing your code (if you so choose).
chovy (OP)
Newbie
*
Offline Offline

Activity: 51
Merit: 0


View Profile WWW
July 27, 2014, 07:02:19 PM
 #3

How do I track incoming payments by txid if they haven't made a payment yet?

How do I generate a new address? I don't think I need to worry about large quantities at this point, since I don't expect very many transactions in the beginning.

I'm assuming listtransactions can take an address as an argument?

If I get something basic working, I will definitely release as an NPM module.

kingama
Member
**
Offline Offline

Activity: 94
Merit: 10


View Profile
July 27, 2014, 08:05:04 PM
 #4

How do I track incoming payments by txid if they haven't made a payment yet?
I'm assuming you'll have some sort of invoice id so you can attach a payment address to that invoice record to start. Then once a payment comes in and has enough confirmations you can create a record in a payments_received table and that should use address-txid as the primary key.

Quote
How do I generate a new address? I don't think I need to worry about large quantities at this point, since I don't expect very many transactions in the beginning.
just call the json-rpc command 'getnewaddress'. From the command line it'd just be "bitcoind getnewaddress".

Quote
I'm assuming listtransactions can take an address as an argument?

listtransactions doesn't actually take addresses as an argument. What you can do though is tell it to show the last 500 transactions and if volume is low as you assume, then you'll never miss one. I've used this method on several sites and it works.

for example: bitcoind listtransactions "*" 500

Quote
If I get something basic working, I will definitely release as an NPM module.

Good to know. Good luck!
chovy (OP)
Newbie
*
Offline Offline

Activity: 51
Merit: 0


View Profile WWW
July 27, 2014, 08:14:06 PM
 #5

ok, now how about wallets?

I may have two different apps on the same server, is it possible to create a wallet for 'app1' and one for 'app2' where I can call `getnewaddress` on the appropriate wallet?
kingama
Member
**
Offline Offline

Activity: 94
Merit: 10


View Profile
July 27, 2014, 11:28:07 PM
 #6

In this case I would recommend you use one bitcoind and have one payment processing script that calls listtransactions for both of the apps. Otherwise, you'll want to have another VM running another instance of bitcoind.
chovy (OP)
Newbie
*
Offline Offline

Activity: 51
Merit: 0


View Profile WWW
July 28, 2014, 02:27:23 AM
 #7

In this case I would recommend you use one bitcoind and have one payment processing script that calls listtransactions for both of the apps. Otherwise, you'll want to have another VM running another instance of bitcoind.

Is there anyway to differentiate app1 payments from app2 payments? I take it I can only have one wallet.
kingama
Member
**
Offline Offline

Activity: 94
Merit: 10


View Profile
July 28, 2014, 03:13:36 AM
 #8

You could create a table of addresses with some marked for app1 and some app2. Or as you're reading the output of listtransactions you can try to match against open invoices for both apps. If you need more separation, you'll want to go the multiple VM route.
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!