coingate/coingate-php
Composer 安装命令:
composer require coingate/coingate-php
包简介
CoinGate library for PHP
README 文档
README
The CoinGate PHP library provides convenient access to the CoinGate API from applications written in the PHP language.
Requirements
PHP 7.3.0 and later.
Composer
You can install library via Composer. Run the following command:
composer require coingate/coingate-php
Manual Installation
If you do not wish to use Composer, you can download the latest release. Then, to use the library, include the init.php file.
require_once('/path/to/coingate-php/init.php');
Dependencies
The library require the following extensions in order to work properly:
If you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that these extensions are available.
Getting Started
You can sign up for a CoinGate account at https://coingate.com for production and https://sandbox.coingate.com for testing (sandbox).
Please note, that for Sandbox you must generate separate API credentials on https://sandbox.coingate.com. API credentials generated on https://coingate.com will not work for Sandbox mode.
Usage of CoinGate PHP library looks like:
$client = new \CoinGate\Client('YOUR_API_TOKEN');
In order, to use sandbox mode, you need to set second parameter to true.
$client = new \CoinGate\Client('YOUR_API_TOKEN', true);
If you plan to use Public API endpoints only, authentication is not required.
$client = new CoinGate\Client(); // if needed you can set configuration parameters later $client->setApiKey('YOUR_API_TOKEN'); $client->setEnvironment('sandbox');
Full documentation of the CoinGate API can be found here
Example
An example of an app using this library can be found here
Payment Gateway API
Create Order
Create order at CoinGate and redirect shopper to invoice (payment_url).
$params = [ 'order_id' => 'YOUR-CUSTOM-ORDER-ID-115', 'price_amount' => 1050.99, 'price_currency' => 'USD', 'receive_currency' => 'EUR', 'callback_url' => 'https://example.com/payments?token=6tCENGUYI62ojkuzDPX7Jg', 'cancel_url' => 'https://example.com/cart', 'success_url' => 'https://example.com/account/orders', 'title' => 'Order #112', 'description' => 'Apple Iphone 13' ]; try { $order = $client->order->create($params); } catch (\CoinGate\Exception\ApiErrorException $e) { // something went wrong... // var_dump($e->getErrorDetails()); } echo $order->id;
Checkout
Placing created order with pre-selected payment currency (BTC, LTC, ETH, etc). Display payment_address and pay_amount for shopper or redirect to payment_url. Can be used to white-label invoices.
$checkout = $client->order->checkout(7294, [ 'pay_currency' => 'BTC' ]);
Get Order
After creating an order, you will get an ORDER ID. This ID will be used for GET ORDER requests.
$order = $client->order->get(7294);
List Orders
Retrieving information of all placed orders.
$orders = $client->order->list([ 'created_at' => [ 'from' => '2022-01-25' ] ]);
Public API
Get Exchange Rate
Current exchange rate for any two currencies, fiat or crypto. This endpoint is public, authentication is not required.
$client->getExchangeRate('BTC', 'EUR');
List Exchange Rates
Current CoinGate exchange rates for Merchants and Traders. This endpoint is public, authentication is not required.
$client->listExchangeRates();
Ping
A health check endpoint for CoinGate API. This endpoint is public, authentication is not required.
$client->ping();
IP Addresses
Get IP addresses of CoinGate servers
$client->getIPAddresses();
Currencies
$client->getCurrencies(); // Crypto + Native + Merchant Pay $client->getCheckoutCurrencies(); // get Merchant Pay currencies only $client->getMerchantPayCurrencies(); // get Merchant Receive currencies only $client->getMerchantPayoutCurrencies();
Platforms
$client->getPlatforms();
Custom Request Timeout
To modify request timeouts (connect or total, in seconds) you'll need to tell the API client to use a CurlClient other than its default. You'll set the timeouts in that CurlClient.
// set up your tweaked Curl client $curl = new \CoinGate\HttpClient\CurlClient(); $curl->setTimeout(10); $curl->setConnectTimeout(5); // tell CoinGate Library to use the tweaked Curl client \CoinGate\Client::setHttpClient($curl); // use the CoinGate API client as you normally would
Test API Connection
$result = \CoinGate\Client::testConnection('YOUR_API_TOKEN');
In order, to test API connection on sandbox mode, you need to set second parameter to true.
$result = \CoinGate\Client::testConnection('YOUR_API_TOKEN', true);
Attention plugin developers
Are you writing a plugin that integrates CoinGate and embeds our library? Then please use the setAppInfo function to identify your plugin. For example:
\CoinGate\Client::setAppInfo("MyAwesomePlugin", "1.0.0");
The method should be called once, before any request is sent to the API. The second parameter is optional.
coingate/coingate-php 适用场景与选型建议
coingate/coingate-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 515.81k 次下载、GitHub Stars 达 57, 最近一次更新时间为 2016 年 03 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payment」 「gateway」 「merchant」 「bitcoin」 「litecoin」 「altcoin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 coingate/coingate-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 coingate/coingate-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 coingate/coingate-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Payyo Gateway for the Omnipay payment processing library
PaySimple driver for the Omnipay payment processing library
Yandex.Kassa driver for Omnipay payment processing library
Some pre-defined rules for validation in Omnipay payment processing library.
BluePay gateway for the Omnipay payment processing library
统计信息
- 总下载量: 515.81k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 58
- 点击次数: 20
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-03-24