PHPackages                             cryptopay-dev/cryptopay - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. cryptopay-dev/cryptopay

ActiveLibrary[API Development](/categories/api)

cryptopay-dev/cryptopay
=======================

Cryptopay API client

v2.2.0(1y ago)21.0k—6.7%MITPHPPHP &gt;=7.4CI passing

Since Jan 21Pushed 6mo ago5 watchersCompare

[ Source](https://github.com/cryptopay-dev/cryptopay-php)[ Packagist](https://packagist.org/packages/cryptopay-dev/cryptopay)[ Docs](https://business.cryptopay.me)[ RSS](/packages/cryptopay-dev-cryptopay/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (6)Versions (6)Used By (0)

Cryptopay PHP Library
=====================

[](#cryptopay-php-library)

The official PHP library for the Cryptopay API.

Cryptopay is a payment gateway and business wallet that allows merchants to automate the processes of accepting cryptocurrency payments and payouts from their customers, as well as making currency exchange transactions and receiving data on the transaction history and account balance statuses for reporting.

For more information, please visit [Cryptopay API docs](https://developers.cryptopay.me).

Table of contents
=================

[](#table-of-contents)

- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
    - [Accounts](#accountsapi)
    - [Channels](#channelsapi)
    - [CoinWithdrawals](#coinwithdrawalsapi)
    - [Coins](#coinsapi)
    - [Customers](#customersapi)
    - [ExchangeTransfers](#exchangetransfersapi)
    - [Invoices](#invoicesapi)
    - [Rates](#ratesapi)
    - [Subscriptions](#subscriptionsapi)
    - [Transactions](#transactionsapi)
- [Callbacks](#callbacks)

Installation
============

[](#installation)

Requirements
------------

[](#requirements)

- PHP 7.4+

Composer
--------

[](#composer)

You can install the library via [Composer](https://getcomposer.org). Run the following command:

```
composer require cryptopay-dev/cryptopay

```

To use the library, use Composer's autoload:

```
require_once 'vendor/autoload.php';
```

Configuration
=============

[](#configuration)

Create API credentials
----------------------

[](#create-api-credentials)

Learn mode about API credentials at [Developers guide](https://developers.cryptopay.me/guides/api-credentials).

Configure library
-----------------

[](#configure-library)

```
require_once 'vendor/autoload.php';

use Cryptopay\Config\Config;
use Cryptopay\Cryptopay;

$config = (new Config())
    ->withApiKey('API_KEY_VALUE')
    ->withApiSecret('YOUR_SECRET_VALUE')
    ->withBaseUrl('https://business-sandbox.cryptopay.me')
    ->withCallbackSecret('YOUR_CALLBACK_SECRET_VALUE')
    ->withTimeout(10);

$cryptopay = new Cryptopay($config);
```

Example: [examples/Init.php](https://github.com/cryptopay-dev/cryptopay-php/blob/master/examples/Init.php)

Usage
=====

[](#usage)

Accounts
--------

[](#accounts)

### List accounts

[](#list-accounts)

```
$result = $cryptopay->accounts->all();
```

### List account transactions

[](#list-account-transactions)

```
$accountId = '31804390-d44e-49e9-8698-ca781e0eb806';

$result = $cryptopay->accounts->allTransactions($accountId);
```

Channels
--------

[](#channels)

A channel is a static cryptocurrency address that may be assigned to each one of your customers.

[Channels API docs](https://developers.cryptopay.me/guides/channels)

### List channels

[](#list-channels)

```
$result = $cryptopay->channels->all();
```

### Create a channel

[](#create-a-channel)

```
$params = [
  'name' => 'Channel name',
  'pay_currency' => 'BTC',
  'receiver_currency' => 'EUR'
];

$result = $cryptopay->channels->create($params);
```

### List channel payments

[](#list-channel-payments)

```
$channelId = '15d0bb11-1e9f-4295-bec5-abd9d5a906a1';

$result = $cryptopay->channels->allPayments($channelId);
```

### Retrieve a channel

[](#retrieve-a-channel)

```
$channelId = '15d0bb11-1e9f-4295-bec5-abd9d5a906a1';

$result = $cryptopay->channels->retrieve($channelId);
```

### Retrieve a channel by custom id

[](#retrieve-a-channel-by-custom-id)

```
$customId = 'CHANNEL-123';

$result = $cryptopay->channels->retrieveByCustomId($customId);
```

### Retrieve a channel payment

[](#retrieve-a-channel-payment)

```
$channelId = '15d0bb11-1e9f-4295-bec5-abd9d5a906a1';
$channelPaymentId = '704291ec-0b90-4118-89aa-0c9681c3213c';

$result = $cryptopay->channels->retrievePayment($channelId, $channelPaymentId);
```

### Update a channel

[](#update-a-channel)

```
$channelId = '15d0bb11-1e9f-4295-bec5-abd9d5a906a1';
$params = ['status' => 'disabled'];

$result = $cryptopay->channels->update($channelId, $params);
```

CoinWithdrawals
---------------

[](#coinwithdrawals)

In addition to accepting payments through the Cryptopay payment gateway, it is also possible to make payments to your customers in any of the cryptocurrency currently supported by Cryptopay. In Cryptopay, these payments are called “Coin Withdrawal”. The process of requesting coin withdrawal is almost the same for a customer in Cashier as the process of making a deposit with one exception - the customer will need to specify the address of the wallet he wants to send the cryptocurrency to.

[Coin withdrawals API docs](https://developers.cryptopay.me/guides/payouts)

### List withdrawals

[](#list-withdrawals)

```
$result = $cryptopay->coinWithdrawals->all();
```

### Commit a withdrawal

[](#commit-a-withdrawal)

```
$coinWithdrawal = $cryptopay->coinWithdrawals->create([
  'address' => '2Mz3bcjSVHG8uQJpNjmCxp24VdTjwaqmFcJ',
  'charged_amount' => '100.0',
  'charged_currency' => 'EUR',
  'received_currency' => 'BTC',
  'force_commit' => false
])->data;

$result = $cryptopay->coinWithdrawals->commit($coinWithdrawal->id);
```

### Create a withdrawal

[](#create-a-withdrawal)

[Documentation](https://developers.cryptopay.me/guides/payouts/create-a-coin-withdrawal)

```
$params = [
  'address' => '2Mz3bcjSVHG8uQJpNjmCxp24VdTjwaqmFcJ',
  'charged_amount' => '100.0',
  'charged_currency' => 'EUR',
  'received_currency' => 'BTC',
  'force_commit' => true
];

$result = $cryptopay->coinWithdrawals->create($params);
```

### List network fees

[](#list-network-fees)

```
$result = $cryptopay->coinWithdrawals->allNetworkFees();
```

### Retrieve a withdrawal

[](#retrieve-a-withdrawal)

```
$coinWithdrawalId = '3cf9d1c4-6191-4826-8cae-2c717810c7e9';

$result = $cryptopay->coinWithdrawals->retrieve($coinWithdrawalId);
```

### Retrieve a withdrawal by custom id

[](#retrieve-a-withdrawal-by-custom-id)

```
$customId = 'PAYMENT-123';

$result = $cryptopay->coinWithdrawals->retrieveByCustomId($customId);
```

Coins
-----

[](#coins)

### List supported coins

[](#list-supported-coins)

```
$result = $cryptopay->coins->all();
```

Customers
---------

[](#customers)

Customer objects allow you to reject High-Risk transactions automatically, and to track multiple transactions, that are associated with the same customer.

### List customers

[](#list-customers)

```
$result = $cryptopay->customers->all();
```

### Create a customer

[](#create-a-customer)

```
$params = [
  'id' => '56c8cb4112bc7df178ae804fa75f712b',
  'currency' => 'EUR'
];

$result = $cryptopay->customers->create($params);
```

### Retrieve a customer

[](#retrieve-a-customer)

```
$customerId = "CUSTOMER-123";

$result = $cryptopay->customers->retrieve($customerId);
```

### Update a customer

[](#update-a-customer)

```
$customerId = 'CUSTOMER-123';
$params = [
  'addresses' => [
    [
      'address' => '2N9wPGx67zdSeAbXi15qHgoZ9Hb9Uxhd2uQ',
      'currency' => 'BTC',
      'network' => 'bitcoin'
    ]
  ]
];

$result = $cryptopay->customers->update($customerId, $params);
```

ExchangeTransfers
-----------------

[](#exchangetransfers)

### Commit an exchange transfer

[](#commit-an-exchange-transfer)

```
$exchangeTransfer = $cryptopay->exchangeTransfers->create([
  'charged_currency' => 'EUR',
  'charged_amount' => '100.0',
  'received_currency' => 'BTC',
  'received_amount' => null,
  'force_commit' => false
])->data;

$result = $cryptopay->exchangeTransfers->commit($exchangeTransfer->id);
```

### Create an exchange transfer

[](#create-an-exchange-transfer)

```
$params = [
  'charged_currency' => 'EUR',
  'charged_amount' => '100.0',
  'received_currency' => 'BTC',
  'received_amount' => null,
  'force_commit' => true
];

$result = $cryptopay->exchangeTransfers->create($params);
```

### Retrieve an exchange transfer

[](#retrieve-an-exchange-transfer)

```
$exchangeTransferId = '2c090f99-7cc1-40da-9bca-7caa57b4ebfb';

$result = $cryptopay->exchangeTransfers->retrieve($exchangeTransferId);
```

Invoices
--------

[](#invoices)

An invoice is a request for a cryptocurrency payment which contains a unique BTC, LTC, ETH or XRP address and the amount that has to be paid while the invoice is valid.

[Invoices API docs](https://developers.cryptopay.me/guides/invoices)

### List invoices

[](#list-invoices)

```
$result = $cryptopay->invoices->all();
```

### Commit invoice recalculation

[](#commit-invoice-recalculation)

```
$invoiceId = '8dd53e0f-0725-48b4-b0a7-1840aa67b5bb';
$recalculation = $cryptopay->invoices->createRecalculation($invoiceId)->data;

$result = $cryptopay->invoices->commitRecalculation($invoiceId, $recalculation->id);
```

### Create an invoice

[](#create-an-invoice)

```
$params = [
  'price_amount' => '100.0',
  'price_currency' => 'EUR',
  'pay_currency' => 'BTC'
];

$result = $cryptopay->invoices->create($params);
```

### Create invoice recalculation

[](#create-invoice-recalculation)

```
$invoiceId = '29a563ad-b417-445c-b8f6-b6c806bb039b';
$params = ['force_commit' => true];

$result = $cryptopay->invoices->createRecalculation($invoiceId, $params);
```

### Create invoice refund

[](#create-invoice-refund)

```
$invoiceId = '331646a6-c8b5-430d-adfb-021d11ff6cd0';

$result = $cryptopay->invoices->createRefund($invoiceId);
```

### List invoice refunds

[](#list-invoice-refunds)

```
$invoiceId = '7e274430-e20f-4321-8748-20824287ae44';

$result = $cryptopay->invoices->allRefunds($invoiceId);
```

### Retrieve an invoice

[](#retrieve-an-invoice)

```
$invoiceId = 'c8233d57-78c8-4c36-b35e-940ae9067c78';

$result = $cryptopay->invoices->retrieve($invoiceId);
```

### Retrieve an invoice by custom\_id

[](#retrieve-an-invoice-by-custom_id)

```
$customId = 'PAYMENT-123';

$result = $cryptopay->invoices->retrieveByCustomId($customId);
```

Rates
-----

[](#rates)

### Retrieve all rates

[](#retrieve-all-rates)

```
$result = $cryptopay->rates->all();
```

### Retrieve a pair rate

[](#retrieve-a-pair-rate)

```
$result = $cryptopay->rates->retrieve('BTC', 'EUR');
```

Subscriptions
-------------

[](#subscriptions)

### List subscriptions

[](#list-subscriptions)

```
$result = $cryptopay->subscriptions->all();
```

### Cancel a subscription

[](#cancel-a-subscription)

```
$subscriptionId = '7dd7da55-2fd6-445e-8c7c-6c2c85d135d7';

$result = $cryptopay->subscriptions->cancel($subscriptionId);
```

### Create a subscription

[](#create-a-subscription)

```
$startsAt = (new \DateTime())->add(\DateInterval::createFromDateString('7 days'));
$params = [
  'name' => 'Subscription name',
  'amount' => '100.0',
  'currency' => 'EUR',
  'period' => 'month',
  'period_quantity' => 3,
  'payer_email' => 'user@example.com',
  'starts_at' => $startsAt->format(\DateTime::ATOM)
];

$result = $cryptopay->subscriptions->create($params);
```

### Retrieve a subscription

[](#retrieve-a-subscription)

```
$subscriptionId = '64249ede-8969-4d5c-a042-806f9c3e7db3';

$result = $cryptopay->subscriptions->retrieve($subscriptionId);
```

### Retrieve a subscription by custom\_id

[](#retrieve-a-subscription-by-custom_id)

```
$customId = 'PAYMENT-123';

$result = $cryptopay->subscriptions->retrieveByCustomId($customId);
```

Transactions
------------

[](#transactions)

[Transactions API docs](https://developers.cryptopay.me/guides/transactions)

### List transactions

[](#list-transactions)

```
$result = $cryptopay->transactions->all([
    'reference_type' => 'Invoice'
]);
```

Callbacks
=========

[](#callbacks)

[Documentation](https://developers.cryptopay.me/guides/api-basics/callbacks)

All callbacks needs to be validated with [signature](https://developers.cryptopay.me/guides/api-basics/authentication/signature)

```
