Update README.md

This commit is contained in:
Jeff Vandrew Jr 2019-03-11 16:35:41 -04:00 committed by GitHub
parent ad264e3c0f
commit 0f8f4f112d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,9 +11,20 @@ pip3 install btcpay-python
```
This library is fully backward compatibile with the prior unofficial library; no code changes are needed.
## Pairing to your server:
To connect your website with your BTCPay server, you must first pair your application to BTCPay. To do this you will need to generate a Access token as follows:
1. On your BTCPay server, browse to Stores > Store settings > Access tokens > Create new token
2. Fill in the form:
Label: <anything that will help you remember what this pairing is used for>
Public key: leave blank
Facade: 'merchant'
3. Click save and then copy the 7 digit pairing code from the success page
After you have the access token, you are ready to use the client library to create a client object.
## The "easy method" to create a new BTCPay client
* On BTCPay server > shop > access tokens > create new token, copy pairing code.
* Then use that code in the below Python code:
Use the pairing code obtained above as follows:
```python
from btcpay import BTCPayClient
@ -22,17 +33,7 @@ client = BTCPayClient.create_client(host='https://btcpay.example.com', code=<pai
## Uses for the client object you just created above
### Get rates
```python
client.get_rates()
```
### Create specific rate
```python
client.get_rate('USD')
```
You'll probably only ever need the `create_invoice` and `get_invoice` methods, but the client object also has other methods, such as those for getting and setting custom rate information.
### Create invoice
See bitpay api documentation: https://bitpay.com/api#resource-Invoices
@ -40,18 +41,29 @@ See bitpay api documentation: https://bitpay.com/api#resource-Invoices
client.create_invoice({"price": 20, "currency": "USD"})
```
### Get invoice
```python
client.get_invoice(<invoice-id>)
```
### Get rates
```python
client.get_rates()
```
### Create specific rate
```python
client.get_rate('USD')
```
## Storing the client object for later
You do not need to store any tokens or private keys. Simply `pickle` the client object and save it to your persistent storage method (Redis, SQLAlchemy, Mongo, etc). Do not use `shelve` for storage. Pull it from persistent storage later, unpickle it, and perform any of the methods above on it which you may need. You must save the object to persistent storage if you wish for the pairing to persist beyond being stored in memory.
You do not need to store any tokens or private keys. Simply `pickle` the client object and save it to your persistent storage method (Redis, SQLAlchemy, MongoDB, etc). Do not use `shelve` or a file for storage, as concurrent access could corrupt the static file. Pull the client object from persistent storage later, unpickle it, and perform any of the methods above on it which you may need. You must save the object to persistent storage if you wish for the pairing to persist beyond the limited time your code is in memory.
## Creating a client the manual way (not necessary if you used the 'easy' method above)
If you prefer to create the client object manually (as was the only way in the prior unofficial library), you can do so as follows. This is unnecessary for most developers and is preserved primarily to maintain backward compatibility with both the prior unofficial library and also compatibility with Bitpay.
* Generate and save private key:
```python
import btcpay.crypto