Closed timbowhite closed 8 years ago
+1
Thanks a ton, @timbowhite! I think what you've written is a great candidate for a pull request to the guide for this plugin. What do you think?
@martindale sounds good, but may want to get some feedback on it from other users.
The client.as('pos')
part of this writeup saved me. I was stuck implementing this module for a long time. Thanks so much for this write up @timbowhite. The README right now is not good. Instead of having all these API docs in the README they should just put a simple example like this to generate an invoice. Cause what do most websites do with BitPay when integrating a module like this? Generate invoices. I don't care about different facades, streaming, etc... just show me an example of how to generate a damn invoice with no prior knowledge of bitauth and node-bitpay-client.
@timbowhite just pinging you again, as per the above comment – might be a great opportunity to submit a full-on pull request!
This was great, thanks. Please add this to the README docs.
@martindale all due respect, but bitpay is a for profit company, and I think it's a bit much asking your customers to perform the task of updating the docs for this clunky module. It shouldn't be hard for a bitpay employee to spend 15 minutes copy/pasting the key parts of the content above into the README.md. All due respect.
@timbowhite, I'm sure @martindale's request was not about making customers do our work, but to allow those who have written code, patches, documentation, etc.. to get commit credit for their work. I personally hate it when I write up a patch or PR only to have it copied by the maintainer. It discourages me from wanting to contribute.
But, if you aren't concerned about that and we have your permission to use your content above under the MIT license, we would be more than happy to add it ourselves.
PS/Edit: I would like to personally thank you for the documentation comment you wrote up as well. It was very thorough and well thought out!
But, if you aren't concerned about that and we have your permission to use your content above under the MIT license, we would be more than happy to add it ourselves.
Not concerned with credit, full permission is granted on content under MIT, etc (see 2nd sentence of my original post)... I'm really just interested in making it as easy as possible for merchants using node.js to accept Bitcoin. Cheers.
After an afternoon of struggling with this thing and its documentation, I'm going to share how I was able to create a basic invoice. Bitpay: please update and improve the docs, feel free to use any of this.
Install and Setup Bitpay Module (*nix platform)
NOTE: the bitpay module automatically creates a
.bitpay
directory in your home directory that contains your public & private key, and config file. If you want that stuff stored elsewhere (and you probably do, especially if your app runs as a different user), do this first:Then install the bitpay module. Note that we're also installing the bitauth module (it's required later on for decrypting your private key when making requests).
Set up your client's private key:
Next set the environment. Bitpay's test platform is used by default, so if you want to use the regular production platform (ie. bitpay.com and not test.bitpay.com), do this:
Next you have to pair up your client's private key with your bitpay account. This is done by requesting a pairing code:
This will spit out a bunch of output. At the end of it will be a URL:
Visit this URL in your browser and hit the approve button. Afterwards, you can test creating a basic invoice from the command line like this:
If it worked, you'll see some JSON outputted regarding the newly created invoice. If you get an error like this:
It's probably because you specified the "Merchant" facade (option 2) when generating your pairing code. For invoices, you want the "Point of Sale" facade (option 1).
Usage in Node.js
Here's how you can create a basic invoice:
Arguments for creating invoices can be viewed here: https://bitpay.com/api#resource-Invoices
Also, the current README and examples bundled in this module conflict, but the examples are more accurate, so it's best to use them as a starting point.
Hope this helps someone else.