69 lines
3.0 KiB
Markdown
69 lines
3.0 KiB
Markdown
## <a name="BTCPAY_PRIVATE_KEY"></a>Setting up the BTCPAY_PRIVATE_KEY
|
|
|
|
Generate a private key and the accompanying bitpay SIN for the btcpay API client.
|
|
|
|
I used this code as an example: https://github.com/bitpay/bitpay-python/blob/master/bitpay/key_utils.py#L6
|
|
|
|
```
|
|
$ pipenv run python ./readme/generate_btcpay_keys.py
|
|
```
|
|
|
|
It should output something looking like this:
|
|
|
|
```
|
|
-----BEGIN EC PRIVATE KEY-----
|
|
EXAMPLEIArx/EXAMPLEKH23EXAMPLEsYXEXAMPLE5qdEXAMPLEcFHoAcEXAMPLEK
|
|
oUQDQgAEnWs47PT8+ihhzyvXX6/yYMAWWODluRTR2Ix6ZY7Z+MV7v0W1maJzqeqq
|
|
NQ+cpBvPDbyrDk9+Uf/sEaRCma094g==
|
|
-----END EC PRIVATE KEY-----
|
|
|
|
|
|
EXAMPLEwzAEXAMPLEEXAMPLEURD7EXAMPLE
|
|
```
|
|
|
|
In order to register the key with the btcpay server, you have to first generate a pairing token using the btcpay server interface.
|
|
This requires your btcpay server account to have access to the capsul store. Ask Cass about this.
|
|
|
|
Navigate to `Manage store: Access Tokens` at: `https://btcpay.cyberia.club/stores/<store-id>/Tokens`
|
|
|
|
![](readme/btcpay_sin_pairing.jpg)
|
|
|
|
|
|
Finally, send an http request to the btcpay server to complete the pairing:
|
|
|
|
```
|
|
curl -H "Content-Type: application/json" https://btcpay.cyberia.club/tokens -d "{'id': 'EXAMPLEwzAEXAMPLEEXAMPLEURD7EXAMPLE', 'pairingCode': 'XXXXXXX'}"
|
|
```
|
|
|
|
It should respond with a token:
|
|
|
|
```
|
|
{"data":[{"policies":[],"pairingCode":"XXXXXXX","pairingExpiration":1589473817597,"dateCreated":1589472917597,"facade":"merchant","token":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","label":"capsulflask"}]}
|
|
```
|
|
|
|
And you should see the token in the btcpay server UI:
|
|
|
|
![](readme/paired.jpg)
|
|
|
|
Now simply set your `BTCPAY_PRIVATE_KEY` variable in `.env`
|
|
|
|
NOTE: make sure to use single quotes and replace the new lines with \n.
|
|
|
|
```
|
|
BTCPAY_PRIVATE_KEY='-----BEGIN EC PRIVATE KEY-----\nEXAMPLEIArx/EXAMPLEKH23EXAMPLEsYXEXAMPLE5qdEXAMPLEcFHoAcEXAMPLEK\noUQDQgAEnWs47PT8+ihhzyvXX6/yYMAWWODluRTR2Ix6ZY7Z+MV7v0W1maJzqeqq\nNQ+cpBvPDbyrDk9+Uf/sEaRCma094g==\n-----END EC PRIVATE KEY-----'
|
|
```
|
|
|
|
-----
|
|
|
|
## <a name="testing"></a>testing cryptocurrency payments
|
|
|
|
I used litecoin to test cryptocurrency payments, because its the simplest & lowest fee cryptocurrency that BTCPay server supports. You can download the easy-to-use litecoin SPV wallet `electrum-ltc` from [github.com/pooler/electrum-ltc](https://github.com/pooler/electrum-ltc) or [electrum-ltc.org](https://electrum-ltc.org/), set up a wallet, and then either purchase some litecoin from an exchange, or [ask Forest for some litecoin](https://sequentialread.com/capsul-rollin-onwards-with-a-web-application/#sqr-comment-container) to use for testing.
|
|
|
|
|
|
## <a name="0_conf_diagram"></a>sequence diagram explaining how BTC payment process works (how we accept 0-confirmation transactions 😀)
|
|
|
|
![btcpayment_process](readme/btcpayment_process.png)
|
|
|
|
This diagram was created with https://app.diagrams.net/.
|
|
To edit it, download the <a download href="readme/btcpayment_process.drawio">diagram file</a> and edit it with the https://app.diagrams.net/ web application, or you may run the application from [source](https://github.com/jgraph/drawio) if you wish.
|