From 8ec59ce47820dc426115fd4e352d8ec29a0177a0 Mon Sep 17 00:00:00 2001 From: Nicolas Klier Date: Mon, 28 Dec 2020 15:01:30 +0100 Subject: [PATCH] Add 'Invoice protocol' --- Invoice-protocol.md | 61 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Invoice-protocol.md diff --git a/Invoice-protocol.md b/Invoice-protocol.md new file mode 100644 index 0000000..08180b0 --- /dev/null +++ b/Invoice-protocol.md @@ -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[...]` + +## \ No newline at end of file