Add 'Invoice protocol'
61
Invoice-protocol.md
Normal file
61
Invoice-protocol.md
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
# Invoice protocol
|
||||||
|
## Rules
|
||||||
|
1. If a payment was made, but the funds were not sufficient, the funds will be sent back.
|
||||||
|
2. If a payment was made, but it was not in time, it will be sent back.
|
||||||
|
3. If a payment was made, the expiration timer will be paused.
|
||||||
|
## Creation
|
||||||
|
### 1. Submit a invoice request
|
||||||
|
The first step is to tell LibrePay that you want to create a new invoice by submitting all necessary details.
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```json
|
||||||
|
POST /invoice/
|
||||||
|
{
|
||||||
|
"successUrl": "http://localhost/complete",
|
||||||
|
"cancelUrl": "http://localhost/cancel",
|
||||||
|
"currency": "usd",
|
||||||
|
"cart": [
|
||||||
|
{
|
||||||
|
"price": 0.1,
|
||||||
|
"name": "Raspberry Pi 4 - 8GB RAM",
|
||||||
|
"image": "https://www.avxperten.dk/billeder/raspberry-pi-4-model-b-2gb-usb-c-side.jpg",
|
||||||
|
"quantity": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
With that, LibrePay knows where to redirct after finishing or cancelling of the payment and how much everything will cost.
|
||||||
|
|
||||||
|
LibrePay will **respond** with all currently activated crypto currencies and there corresponding price:
|
||||||
|
```json
|
||||||
|
Response 200 OK
|
||||||
|
{
|
||||||
|
"methods": [
|
||||||
|
{ "coin:": "BTC", "price": 0.00037000 },
|
||||||
|
{ "coin": "XMR", "price": 0.0606816 },
|
||||||
|
{ "coin": "ETH", "price": 0.0137751 }
|
||||||
|
],
|
||||||
|
"selector": "YjcTCvruxPwdiNMkfmPuKkXEfPpOvahreyVVrlqqzDjqRgWwybsWTurkXWowOZZurSujSVozXRvKxxVqixFldifMZKFlJRjgUAJyoMOVrxsvxiBPwhtaeMuugfthoXer",
|
||||||
|
"expireDate": 1609162829
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Since the price for each crypto currency has been set, the user will receive a fixed time in which the payment has to be made.
|
||||||
|
|
||||||
|
### 2. Choose a payment method
|
||||||
|
Now you know what crypto currencies are supported and how much you'll have to pay. All you have to do now is to **choose one of them.**
|
||||||
|
```json
|
||||||
|
POST /invoice/YjcTCvruxPwdiNMk[...]/setmethod
|
||||||
|
{
|
||||||
|
"method": "BTC"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
LibrePay acknowledged this choice and will now await payments on a specific addresss.
|
||||||
|
```json
|
||||||
|
Response 200 OK
|
||||||
|
{
|
||||||
|
"receiveAddress": "1QFrbboisCYgeBdowGAuCTK3r2YnZuApYd"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
You can also get this address by calling `GET /invoice/YjcTCvruxPwdiNMk[...]`
|
||||||
|
|
||||||
|
##
|
||||||
Reference in New Issue
Block a user