cryptopay-dev / cryptopay
Cryptopay API 客户端
v2.1.0
2023-07-17 11:24 UTC
Requires
- php: >=7.4
- ext-json: *
- guzzlehttp/guzzle: ^7.2
- vlucas/phpdotenv: ^5.2
Requires (Dev)
- mockery/mockery: ^1.4
- php-vcr/php-vcr: ^1.5
- phpunit/phpunit: ^9
- squizlabs/php_codesniffer: ^3.5
This package is not auto-updated.
Last update: 2024-09-24 14:34:20 UTC
README
这是 Cryptopay API 的官方 PHP 库。
Cryptopay 是一个支付网关和商务钱包,允许商家自动化接受客户加密货币支付和提现的过程,以及进行货币兑换交易,并接收交易历史和账户余额状态的数据以进行报告。
有关更多信息,请访问 Cryptopay API 文档。
目录
安装
需求
- PHP 7.4+
Composer
您可以通过 Composer 安装此库。运行以下命令
composer require cryptopay-dev/cryptopay
要使用此库,请使用 Composer 的自动加载
require_once 'vendor/autoload.php';
配置
创建 API 凭据
有关 API 凭据的更多信息,请参阅 开发者指南。
配置库
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);
使用
账户
列出账户
$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);
通过自定义 ID 检索一个渠道
$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);
币种提款
除了通过 Cryptopay 支付网关接受支付外,还可能向客户支付任何 Cryptopay 当前支持的加密货币。在 Cryptopay 中,这些支付被称为“币种提款”。请求币种提款的过程几乎与收银员进行存款的过程相同,唯一的区别是客户需要指定他想要将加密货币发送到哪个钱包的地址。
列出提款
$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);
通过自定义 ID 检索提款
$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);
发票
发票是请求加密货币支付的请求,其中包含唯一的 BTC、LTC、ETH 或 XRP 地址以及必须在有效期内支付的金额。
列出发票
$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);
通过自定义 ID 检索发票
$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' => 'user@example.com', 'starts_at' => $startsAt->format(\DateTime::ATOM) ]; $result = $cryptopay->subscriptions->create($params);
检索订阅
$subscriptionId = '64249ede-8969-4d5c-a042-806f9c3e7db3'; $result = $cryptopay->subscriptions->retrieve($subscriptionId);
通过自定义 ID 检索订阅
$customId = 'PAYMENT-123'; $result = $cryptopay->subscriptions->retrieveByCustomId($customId);
交易
列出交易
$result = $cryptopay->transactions->all([ 'reference_type' => 'Invoice' ]);
回调
所有回调都需要通过签名进行验证。
<?php // Get CallbackJson $callbackJson = file_get_contents('php://input'); // Get headers $headers = getallheaders(); $cryptopay->validateCallback($callbackJson, $headers);
如果签名错误,包验证将抛出ForbiddenException异常。否则,它将返回对象。