Clone
2
Invoice protocol
Nicolas Klier edited this page 2020-12-28 16:38:48 +01:00

Invoice protocol

Rules

  1. If a payment was made, but the funds sent were not sufficient, the funds will be sent back.
  2. If a payment was made, but the funds sent were too much, the rest will be sent back.
  3. If a payment was made, but it was not in time, it will be sent back.
  4. If a payment was made, the expiration timer will be paused.

Note: If a payment is sent back, the fee will be subtracted from the transcation.

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:

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:

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.

POST /invoice/YjcTCvruxPwdiNMk[...]/setmethod
{
    "method": "BTC"
}

LibrePay acknowledged this choice and will now await payments on a specific addresss.

Response 200 OK
{
    "receiveAddress": "1QFrbboisCYgeBdowGAuCTK3r2YnZuApYd"
}

You can also get this address by calling GET /invoice/YjcTCvruxPwdiNMk[...]