PHP code example of cryptopay-dev / cryptopay
1. Go to this page and download the library: Download cryptopay-dev/cryptopay library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cryptopay-dev / cryptopay example snippets
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);
$result = $cryptopay->accounts->all();
$accountId = '31804390-d44e-49e9-8698-ca781e0eb806';
$result = $cryptopay->accounts->allTransactions($accountId);
$result = $cryptopay->channels->all();
$params = [
'name' => 'Channel name',
'pay_currency' => 'BTC',
'receiver_currency' => 'EUR'
];
$result = $cryptopay->channels->create($params);
$channelId = '15d0bb11-1e9f-4295-bec5-abd9d5a906a1';
$result = $cryptopay->channels->allPayments($channelId);
$channelId = '15d0bb11-1e9f-4295-bec5-abd9d5a906a1';
$result = $cryptopay->channels->retrieve($channelId);
$customId = 'CHANNEL-123';
$result = $cryptopay->channels->retrieveByCustomId($customId);
$channelId = '15d0bb11-1e9f-4295-bec5-abd9d5a906a1';
$channelPaymentId = '704291ec-0b90-4118-89aa-0c9681c3213c';
$result = $cryptopay->channels->retrievePayment($channelId, $channelPaymentId);
$channelId = '15d0bb11-1e9f-4295-bec5-abd9d5a906a1';
$params = ['status' => 'disabled'];
$result = $cryptopay->channels->update($channelId, $params);
$result = $cryptopay->coinWithdrawals->all();
$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);
$params = [
'address' => '2Mz3bcjSVHG8uQJpNjmCxp24VdTjwaqmFcJ',
'charged_amount' => '100.0',
'charged_currency' => 'EUR',
'received_currency' => 'BTC',
'force_commit' => true
];
$result = $cryptopay->coinWithdrawals->create($params);
$result = $cryptopay->coinWithdrawals->allNetworkFees();
$coinWithdrawalId = '3cf9d1c4-6191-4826-8cae-2c717810c7e9';
$result = $cryptopay->coinWithdrawals->retrieve($coinWithdrawalId);
$customId = 'PAYMENT-123';
$result = $cryptopay->coinWithdrawals->retrieveByCustomId($customId);
$result = $cryptopay->coins->all();
$result = $cryptopay->customers->all();
$params = [
'id' => '56c8cb4112bc7df178ae804fa75f712b',
'currency' => 'EUR'
];
$result = $cryptopay->customers->create($params);
$customerId = "CUSTOMER-123";
$result = $cryptopay->customers->retrieve($customerId);
$customerId = 'CUSTOMER-123';
$params = [
'addresses' => [
[
'address' => '2N9wPGx67zdSeAbXi15qHgoZ9Hb9Uxhd2uQ',
'currency' => 'BTC',
'network' => 'bitcoin'
]
]
];
$result = $cryptopay->customers->update($customerId, $params);
$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);
$params = [
'charged_currency' => 'EUR',
'charged_amount' => '100.0',
'received_currency' => 'BTC',
'received_amount' => null,
'force_commit' => true
];
$result = $cryptopay->exchangeTransfers->create($params);
$exchangeTransferId = '2c090f99-7cc1-40da-9bca-7caa57b4ebfb';
$result = $cryptopay->exchangeTransfers->retrieve($exchangeTransferId);
$result = $cryptopay->invoices->all();
$invoiceId = '8dd53e0f-0725-48b4-b0a7-1840aa67b5bb';
$recalculation = $cryptopay->invoices->createRecalculation($invoiceId)->data;
$result = $cryptopay->invoices->commitRecalculation($invoiceId, $recalculation->id);
$params = [
'price_amount' => '100.0',
'price_currency' => 'EUR',
'pay_currency' => 'BTC'
];
$result = $cryptopay->invoices->create($params);
$invoiceId = '29a563ad-b417-445c-b8f6-b6c806bb039b';
$params = ['force_commit' => true];
$result = $cryptopay->invoices->createRecalculation($invoiceId, $params);
$invoiceId = '331646a6-c8b5-430d-adfb-021d11ff6cd0';
$params = ['address' => '0xf3532c1fd002665ec54d46a50787e0c69c76cd44'];
$result = $cryptopay->invoices->createRefund($invoiceId, $params);
$invoiceId = '7e274430-e20f-4321-8748-20824287ae44';
$result = $cryptopay->invoices->allRefunds($invoiceId);
$invoiceId = 'c8233d57-78c8-4c36-b35e-940ae9067c78';
$result = $cryptopay->invoices->retrieve($invoiceId);
$customId = 'PAYMENT-123';
$result = $cryptopay->invoices->retrieveByCustomId($customId);
$result = $cryptopay->rates->all();
$result = $cryptopay->rates->retrieve('BTC', 'EUR');
$params = [
'address' => '2N9wPGx67zdSeAbXi15qHgoZ9Hb9Uxhd2uQ',
'currency' => 'BTC',
'type' => 'source_of_funds'
];
$result = $cryptopay->risks->score($params);
$result = $cryptopay->subscriptions->all();
$subscriptionId = '7dd7da55-2fd6-445e-8c7c-6c2c85d135d7';
$result = $cryptopay->subscriptions->cancel($subscriptionId);
$startsAt = (new \DateTime())->add(\DateInterval::createFromDateString('7 days'));
$params = [
'name' => 'Subscription name',
'amount' => '100.0',
'currency' => 'EUR',
'period' => 'month',
'period_quantity' => 3,
'payer_email' => '[email protected] ',
'starts_at' => $startsAt->format(\DateTime::ATOM)
];
$result = $cryptopay->subscriptions->create($params);
$subscriptionId = '64249ede-8969-4d5c-a042-806f9c3e7db3';
$result = $cryptopay->subscriptions->retrieve($subscriptionId);
$customId = 'PAYMENT-123';
$result = $cryptopay->subscriptions->retrieveByCustomId($customId);
$result = $cryptopay->transactions->all([
'reference_type' => 'Invoice'
]);
// Get CallbackJson
$callbackJson = file_get_contents('php://input');
// Get headers
$headers = getallheaders();
$cryptopay->validateCallback($callbackJson, $headers);