Create a Channel

First of all, let’s create a channel for our customer:

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

Let’s go over the parameters we used in the request above:

  • pay_currency - is a cryptocurrency in which the customer will make a payment (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.

  • receiver_currency - the currency to which incoming cryptocurrency transactions will be converted and in which the merchant will be credited to the balance account (in our case it is EUR)

  • name - any channel name

  • custom_id - we recommend indicating a certain reference by which you associate your customer with the created channel. It is important to note that all channel payments of this channel will be inherited by the parent channel - for example, 631044494

You will receive the channel’s address and a link to its hosted page, which can be integrated into your website:

{
  "customer_id": "e7bb04fb-7f33-4729-819e-05a92761b492",
  "id": "50eb5775-f77e-4c64-870b-dc93624b5967",
  "name": "channel name",
  "description": "channel description",
  "receiver_currency": "EUR",
  "pay_currency": "BTC",
  "address": "2N9uVK2MDFNgBVqPnvCTV66Dinx3cp5J7S4",
  "network": "bitcoin",
  "project_id": "25632c89-7f40-4693-8ed0-99bf5f79d3a6",
  "custom_id": "631044494",
  "uri": "bitcoin:2N9uVK2MDFNgBVqPnvCTV66Dinx3cp5J7S4",
  "hosted_page_url": "https://business-hosted.cryptopay.me/channels/50eb5775-f77e-4c64-870b-dc93624b5967"
}

To create a channel payment, we need to send a BTC transaction to the Bitcoin address of our newly created channel 2N9uVK2MDFNgBVqPnvCTV66Dinx3cp5J7S4. In order to send the transaction, please login to your test account and press the "Send" button, which is located on your Bitcoin account:

In the pop-up window, enter the address and amount of the transaction, and complete the process.

You can also automate the process of sending transactions using this endpoint so that you do not have to create payments manually.

Once the payment is sent, we will create a Channel Payment transaction in your account and send the callbacks to the Callback URL. We also recommend you using this endpoint to check the channel payment status before depositing funds to your customer's balance, as delivery of the callbacks is not guaranteed.

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

{
  "type": "ChannelPayment",
  "event": "completed",
  "data": {
    "id": "284d4b79-fea6-46ce-bc2f-0f9cbed6367e",
    "txid": "09723bf75253f3d2bf2f150fd8b5da5bc3026b95f1fe50b1f5f76f43d67a2e30",
    "address": "2N9uVK2MDFNgBVqPnvCTV66Dinx3cp5J7S4",
    "network": "bitcoin",
    "paid_amount": "0.02",
    "paid_currency": "BTC",
    "received_amount": "97.26",
    "received_currency": "EUR",
    "fee": "0.99",
    "fee_currency": "EUR",
    "exchange": {
      "pair": "BTCEUR",
      "rate": "4912.8021"
    },
    "status": "completed",
    "channel_id": "50eb5775-f77e-4c64-870b-dc93624b5967",
    "custom_id": "631044494",
    "risk": {
      "score": 0,
      "level": "low",
      "resource_name": "Bitstamp",
      "resource_category": "Exchange"
    },
    "hosted_page_url": "https://business-hosted.cryptopay.me/channels/50eb5775-f77e-4c64-870b-dc93624b5967",
    "created_at": "2019-05-02T11:00:01+00:00"
  }
}

It is important to note that paid_amount == received_amount + fee. It means that the full amount of the payment made by the customer consists of the received_amount and the fee, where the received_amount is the amount of the merchant balance credited to Cryptopay and the fee is the amount of the processing fee charged by Cryptopay.

Last updated