# Crypto Payments using API

XGateway enables direct deposits without the necessity to use the Checkout page or pre-create an invoice. This simplified process, known as [Channels](https://docs.xgateway.tech/payment-flows#channel), has two key differences:

1. The exchange rates are not fixed.
2. No UI is provided by XGateway.

### Creating an Channel

In order to create a channel, you need to make a `POST` request to the corresponding API endpoint.&#x20;

## Returns a previously created or brand-new address with a link to a QR code.

> Create a channel for the customer for a specified currency.\
> \
> Access to this endpoint requires a valid API key. The API key is sent in the \`x-api-key\` header on requests.

```json
{"openapi":"3.0.0","info":{"title":"x-gateway-external-api","version":"0.0.1"},"servers":[{"url":"https://api.xgateway.tech/api/v2"}],"security":[{"api_key":[]}],"components":{"securitySchemes":{"api_key":{"in":"header","name":"x-api-key","type":"apiKey"}},"schemas":{"AppSuccessResponse_IAddressResponse_":{"description":"The AppSuccessResponse object contains general information about the success execution.","properties":{"success":{"type":"boolean","default":true},"data":{"$ref":"#/components/schemas/IAddressResponse"}},"required":["success","data"],"type":"object","additionalProperties":false},"IAddressResponse":{"properties":{"address":{"type":"string"},"qrCodeURL":{"type":"string"},"qrCode":{"type":"string"}},"required":["address"],"type":"object","additionalProperties":false},"AppErrorResponse":{"description":"The AppErrorResponse object contains general information about the error message.","properties":{"success":{"type":"boolean","default":false},"errors":{"items":{"$ref":"#/components/schemas/IAppError"},"type":"array"}},"required":["success","errors"],"type":"object","additionalProperties":false},"IAppError":{"description":"The IAppError interface represents an application error message.","properties":{"code":{"anyOf":[{"$ref":"#/components/schemas/AppClientErrorResponseCode"},{"$ref":"#/components/schemas/AppServerErrorResponseCode"}]},"message":{"type":"string"}},"required":["code","message"],"type":"object","additionalProperties":false},"AppClientErrorResponseCode":{"type":"string","enum":["bad_request","db_violation","unauthorized","payment_required","forbidden","not_found","method_not_allowed","not_acceptable","proxy_authentication_required","request_timeout","conflict","db_unique_violation","gone","length_required","precondition_failed","payload_too_large","uri_too_long","unsupported_media_type","range_not_satisfiable","expectation_failed","misdirected_request","unprocessable_content","db_non_null_violation","locked","failed_dependency","upgrade_required","precondition_required","too_many_requests","request_header_fields_too_large","unavailable_for_legal_reasons"],"nullable":false,"description":"The AppClientErrorResponseCode object contains all client error response codes."},"AppServerErrorResponseCode":{"type":"string","enum":["internal_server_error","not_implemented","bad_gateway","service_unavailable","gateway_timeout","http_version_not_supported","variant_also_negotiates","insufficient_storage","loop_detected","not_extended","network_authentication_required"],"nullable":false,"description":"The AppServerErrorResponseCode object contains all server error response codes."},"AppAuthenticationErrorResponse":{"description":"The AppAuthenticationErrorResponse object contains general information about the authentication\nerror.","properties":{"success":{"type":"boolean","default":false},"errors":{"items":{"$ref":"#/components/schemas/IAppError"},"type":"array","default":[{"code":"unauthorized","message":"You do not have permission to access this resource."}]}},"required":["success","errors"],"type":"object","additionalProperties":false},"AppValidationErrorResponse":{"description":"The AppValidationErrorResponse object contains general information about the validation error.","properties":{"success":{"type":"boolean","default":false},"errors":{"items":{},"type":"array"}},"required":["success","errors"],"type":"object","additionalProperties":false},"CreateAddressInput":{"properties":{"currency":{"$ref":"#/components/schemas/SupportedCryptoCurrency"},"customerId":{"type":"string"},"applicationId":{"type":"string"}},"required":["currency","customerId"],"type":"object","additionalProperties":false},"SupportedCryptoCurrency":{"type":"string","enum":["BNB","bUSDT","BTC","ETH","eUSDC","eUSDT","FTN","POL","pUSDC","SOL","sUSDT","TRX","tUSDC","tUSDT","wpUSDC","wpUSDT"],"description":"Represents supported crypto currencies in the payment processing system.\n\nCurrencies:\n- `BNB` - Binance Coin\n- `bUSDT` - Tether (pegged to USD), issued on BNB Smart Chain network (BEP20 token)\n- `BTC` - Bitcoin\n- `ETH` - Ether\n- `eUSDC` - USD Coin (pegged to USD), issued on Ethereum network (ERC20 token)\n- `eUSDT` - Tether (pegged to USD), issued on Ethereum network (ERC20 token)\n- `FTN` - Fasttoken\n- `POL` - POL\n- `pUSDC` - USD Coin (pegged to USD), issued on Polygon network (ERC20 token)\n- `SOL` - SOL\n- `sUSDT` - Tether (pegged to USD), issued on Solana network (SPL token)\n- `TRX` - Tronix (native coin), issued on Tron network\n- `tUSDC` - USD Coin (pegged to USD), issued on Tron network (TRC20 token)\n- `tUSDT` - Tether (pegged to USD), issued on Tron network (TRC20 token)\n- `wpUSDC` - wrapped USD Coin (pegged to USD), issued on Polygon network (ERC20 token)\n- `wpUSDT` - wrapped Tether (pegged to USD), issued on Polygon network (ERC20 token)."}}},"paths":{"/channels":{"post":{"operationId":"CreateWallet","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"anyOf":[{"$ref":"#/components/schemas/AppSuccessResponse_IAddressResponse_"},{"$ref":"#/components/schemas/AppErrorResponse"}]}}}},"201":{"description":"Created","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AppSuccessResponse_IAddressResponse_"}}}},"400":{"description":"Database violation","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AppErrorResponse"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AppAuthenticationErrorResponse"}}}},"422":{"description":"Unprocessable content","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AppValidationErrorResponse"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AppErrorResponse"}}}}},"description":"Create a channel for the customer for a specified currency.\n\nAccess to this endpoint requires a valid API key. The API key is sent in the `x-api-key` header on requests.","summary":"Returns a previously created or brand-new address with a link to a QR code.","tags":["Channels"],"parameters":[],"requestBody":{"description":"- Contains currency and customer id.\n\n__Params__:\n- __currency__ - The currency.\n- __customerId__ - The customer ID in the external system.","required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateAddressInput","description":"- Contains currency and customer id.\n\n__Params__:\n- __currency__ - The currency.\n- __customerId__ - The customer ID in the external system."}}}}}}}}
```

In case of a successful response, the `data` property contains the address that you can display to your customer. You can also use the `qrCodeURL` property to display the address in an easy-to-use format.&#x20;

By default, the payment gateway links the created wallet to a customer forever. The created wallet can be used across all EVM compatible chains.&#x20;

Remember to authorise the request with your key using `x-api-key` header.

### Processing a callback

When a customer makes a deposit using a cryptocurrency, XGateway detects the transaction and sends a deposit callback to the merchant. Below is an example of such a callback. For detailed information, please visit[ this page](https://docs.xgateway.tech/miscellaneous/how-to-process-the-callback/transaction-callback-for-deposit-and-withdraw).

<details>

<summary>Callback example</summary>

```json
{
   "callbackType":"transaction",
   "amount":"200",
   "applicationId":null,
   "currency":"USDT",
   "customerId":"000394",
   "hash":"...",
   "id":"7e71d132-d80d-4140-8e60-9c89d0bd9eed",
   "invoiceId":"184e9933-1526-...-fe567091b5bd",
   "network":"tron",
   "orderId":null,
   "status":"confirmed",
   "transactionHash":"0x58f6",
   "type":"deposit",
   "info":{
      "exchangeRate":"1.03759",
      "referenceAmount":"207.52",
      "referenceCurrency":"USD",
      "referenceExchangeRate":"1.000065",
      "transactionAmount":"207.51518",
      "transactionCurrency":"tUSDT"
   },
   "fees":{
      "processing":"7.263031",
      "technical":null
   },
   "eur":"200.12",
   "usd":"207.52"
}
```

</details>

{% hint style="warning" %}
Callbacks for Withdraw requests will be sent to the same URL. Make sure to properly filter callbacks by type.
{% endhint %}

### Confirming a transaction

{% hint style="danger" %}
Due to security risks, merchants *must* use our [API endpoint](https://docs.xgateway.tech/miscellaneous/deposit-data-confirmation) to request transaction details. XGateway is not liable for issues caused by relying only on callback data.
{% endhint %}

To confirm the callback is valid, please use the [API endpoint](https://docs.xgateway.tech/miscellaneous/deposit-data-confirmation).

### Testing Crypto Payments on Demo environment

You can test direct crypto deposits in the[ Demo environment](https://docs.xgateway.tech/miscellaneous/environments).&#x20;

#### Testing with transaction simulation

The Demo Environment provides and [API](https://docs.xgateway.tech/miscellaneous/deposit-and-withdrawal-simulation) to simulate a deposit.

#### Testing with real transactions

The way to test the integration is to deposit native token on a test network. Proceed with the integration up to the point where the customer wallet is generated and returned to you. Make sure that deposits of ETH are enabled for your profile.

Use faucets, like [this](https://www.alchemy.com/faucets) one, to get some ETH on Sepolia test network.&#x20;

Send a portion of this ETH to the wallet, assigned to your customer.&#x20;

Wait for the system to send you a callback about a successful deposit.&#x20;
