Create an invoice

Let's create an invoice and then pay for it:

curl -X POST \
https://business-sandbox.cryptopay.me/api/invoices \
-H 'Authorization: HMAC ***' \
-H 'Content-Type: application/json' \
-H 'Date: Tue, 19 Mar 2019 10:11:40 GMT' \
-d '{"price_amount":"100", "price_currency":"EUR", "pay_currency":"BTC", "network":"bitcoin", "custom_id":"209584732"}'

Let us go through the parameters we used in our request above:

  • price_amount - the payment amount

  • price_currency - the currency of payment, i.e. the currency into which the cryptocurrency received at the address of the invoice will be converted and in which the merchant will be credited to the balance, in our case it is EUR

  • pay_currency - the cryptocurrency in which the payment is to be made, in our case it is BTC

  • network - the blockchain in which the address is going to be created. The list of available networks can be found here.

  • custom_id - we recommend you to specify a certain reference by which you associate your customer with the payment, e.g. 209584732

You will receive the invoice address, the amount of cryptocurrency to be sent to the invoice address and a link to the invoice's hosted page, which can be built into your website and other details:

{
  "id": "cc75b958-5780-4b34-a33a-cf63b349fbab",
  "custom_id": "209584732",
  "status": "new",
  "status_context": null,
  "address": "3Gtvf2EVxN8XJ4DHriRt9q9LkdVCpQZEeSd",
  "network": "bitcoin",
  "uri": "bitcoin:3Gtvf2EVxN8XJ4DHriRt9q9LkdVCpQZEeSd?amount=0.010268",
  "price_amount": "100.0",
  "price_currency": "EUR",
  "pay_amount": "0.010268",
  "pay_currency": "BTC",
  "fee": "1.0",
  "fee_currency": "EUR",
  "paid_amount": "0.0",
  "exchange": {
    "pair": "BTCEUR",
    "rate": "4905.9838",
    "fee": "0.0",
    "fee_currency": "EUR"
  },
  "transactions": [],
  "name": "invoice name",
  "description": "invoice description",
  "metadata": {
    "foo": "bar"
  },
  "success_redirect_url": null,
  "hosted_page_url": "https://hosted-business.cryptopay.me/invoices/cc75b958-5780-4b34-a33a-cf63b349fbab",
  "created_at": "2019-05-02T13:56:56+00:00",
  "expires_at": "2019-05-02T14:06:56+00:00"
}

Tips for Making Invoice Payments

To pay for the invoice, it’s required to send a cryptocurrency transaction to the invoice cryptocurrency address - in this tutorial it is 3Gtvf2EVxN8XJ4DHriRt9q9LkdVCpQZEeSd. To do so, log in to your sandbox account and press the "Send" button, which is located on your cryptocurrency wallet balance:

In the pop-up window, enter the address (address from the received response) and the transaction amount (pay_amount from the received response), and complete the process. You can also automate this process with this endpoint so that you do not have to create payments manually.

Once the payment is made, we will send the callbacks to the Callback URL.

We recommend that you check invoice statuses via GET /api/invoices/:idusing this endpoint as the delivery of the callbacks is not guaranteed.

Below is an example of a callback for the final status completed of the payment:

{
  "type": "Invoice",
  "event": "status_changed",
  "data": {
    "id": "cc75b958-5780-4b34-a33a-cf63b349fbab",
    "status": "completed",
    "status_context": null,
    "address": "2NG8f2EVxN8XJ4DHriRt9q9LkdVCpQZ2UGB",
    "network": "bitcoin",  
    "price_amount": "100.0",
    "price_currency": "EUR",
    "pay_amount": "0.02038328",
    "pay_currency": "BTC",
    "paid_amount": "0.02038328",
    "exchange": {
      "pair": "BTCEUR",
      "rate": "4905.9838"
    },
    "transactions": [
      {
        "txid": "502e6de0c3b1d129974c55e6cd127fd548e4501ff8e8d9330ea9a30a83dbd16e",
        "risk": {
          "score": 3.1,
          "level": "low",
          "resource_name": "Bitstamp",
          "resource_category": "Exchange"
        }
      }
    ],
    "name": "invoice name",
    "description": "invoice description",
    "metadata": {
      "foo": "bar"
    },
    "success_redirect_url": null,
    "hosted_page_url": "https://hosted-business.cryptopay.me/invoices/cc75b958-5780-4b34-a33a-cf63b349fbab",
    "custom_id": "209584732",
    "created_at": "2019-05-02T13:56:56+00:00",
    "expires_at": "2019-05-02T14:06:56+00:00"
  }
}

It is important to note that cash from the payment is only credited to the merchant balance when the payment status is updated to completed. The price_amount field for a payment with the status completed indicates the full amount of this processed payment.

Last updated