Create an invoice
Let's create an invoice and then pay for it:
1
curl -X POST \
2
https://business-sandbox.cryptopay.me/api/invoices \
3
-H 'Authorization: HMAC ***' \
4
-H 'Content-Type: application/json' \
5
-H 'Date: Tue, 19 Mar 2019 10:11:40 GMT' \
6
-d '{"price_amount":"100", "price_currency":"EUR", "pay_currency":"BTC", "custom_id":"209584732"}'
Copied!
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
  • 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:
1
{
2
"id": "cc75b958-5780-4b34-a33a-cf63b349fbab",
3
"custom_id": "209584732",
4
"status": "new",
5
"status_context": null,
6
"address": "3Gtvf2EVxN8XJ4DHriRt9q9LkdVCpQZEeSd",
7
"uri": "bitcoin:3Gtvf2EVxN8XJ4DHriRt9q9LkdVCpQZEeSd?amount=0.010268",
8
"price_amount": "100.0",
9
"price_currency": "EUR",
10
"pay_amount": "0.010268",
11
"pay_currency": "BTC",
12
"fee": "1.0",
13
"fee_currency": "EUR",
14
"paid_amount": "0.0",
15
"exchange": {
16
"pair": "BTCEUR",
17
"rate": "4905.9838",
18
"fee": "0.0",
19
"fee_currency": "EUR"
20
},
21
"transactions": [],
22
"name": "invoice name",
23
"description": "invoice description",
24
"metadata": {
25
"foo": "bar"
26
},
27
"success_redirect_url": null,
28
"hosted_page_url": "https://hosted-business.cryptopay.me/invoices/cc75b958-5780-4b34-a33a-cf63b349fbab",
29
"created_at": "2019-05-02T13:56:56+00:00",
30
"expires_at": "2019-05-02T14:06:56+00:00"
31
}
Copied!

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:
1
{
2
"type": "Invoice",
3
"event": "status_changed",
4
"data": {
5
"id": "cc75b958-5780-4b34-a33a-cf63b349fbab",
6
"status": "completed",
7
"status_context": null,
8
"address": "2NG8f2EVxN8XJ4DHriRt9q9LkdVCpQZ2UGB",
9
"price_amount": "100.0",
10
"price_currency": "EUR",
11
"pay_amount": "0.02038328",
12
"pay_currency": "BTC",
13
"paid_amount": "0.02038328",
14
"exchange": {
15
"pair": "BTCEUR",
16
"rate": "4905.9838"
17
},
18
"transactions": [{
19
"txid": "502e6de0c3b1d129974c55e6cd127fd548e4501ff8e8d9330ea9a30a83dbd16e",
20
"risk": {
21
"score": 3.1,
22
"level": "low",
23
"resource_name": "Bitstamp",
24
"resource_category": "Exchange"
25
}
26
}],
27
"name": "invoice name",
28
"description": "invoice description",
29
"metadata": {
30
"foo": "bar"
31
},
32
"success_redirect_url": null,
33
"hosted_page_url": "https://hosted-business.cryptopay.me/invoices/cc75b958-5780-4b34-a33a-cf63b349fbab",
34
"custom_id": "209584732",
35
"created_at": "2019-05-02T13:56:56+00:00",
36
"expires_at": "2019-05-02T14:06:56+00:00"
37
}
38
}
Copied!
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 modified 7mo ago