Coingate PHP库可以从使用PHP语言编写的应用程序中方便地访问Coingate API。
PHP 7.3.0及以后。
您可以通过作曲家安装库。运行以下命令:
composer require coingate/coingate-php如果您不想使用作曲家,则可以下载最新版本。然后,要使用库,请包括init.php文件。
require_once ( ' /path/to/coingate-php/init.php ' );图书馆需要以下扩展名才能正常工作:
curl ,尽管您可以使用自己的非折扣客户端json如果您使用作曲家,则应自动处理这些依赖项。如果您手动安装,则需要确保这些扩展名可用。
您可以在https://coingate.com上注册一个Coingate帐户进行生产,以及https://sandbox.coingate.com进行测试(Sandbox)。
请注意,对于沙箱,您必须在https://sandbox.coingate.com上生成单独的API凭据。在https://coingate.com上生成的API凭证将不适用于沙盒模式。
使用Coingate PHP库的使用看起来像:
$ client = new CoinGate Client ( ' YOUR_API_TOKEN ' );为了使用沙盒模式,您需要将第二个参数设置为true 。
$ client = new CoinGate Client ( ' YOUR_API_TOKEN ' , true );如果您计划仅使用公共API端点,则不需要身份验证。
$ client = new CoinGate Client ();
// if needed you can set configuration parameters later
$ client -> setApiKey ( ' YOUR_API_TOKEN ' );
$ client -> setEnvironment ( ' sandbox ' );可以在此处找到Coingate API的完整文档
可以在此处找到使用此库的应用程序的示例
在Coingate和重定向购物者中创建订单以发票(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 ;使用预先选择的支付货币(BTC,LTC,ETH等)放置创建订单。显示pealdion_address和pay_amount的购物者或重定向到payment_url。可用于白色标签发票。
$ checkout = $ client -> order -> checkout ( 7294 , [
' pay_currency ' => ' BTC '
]);创建订单后,您将获得订单ID。此ID将用于获取订单请求。
$ order = $ client -> order -> get ( 7294 );检索所有下订单的信息。
$ orders = $ client -> order -> list ([
' created_at ' => [
' from ' => ' 2022-01-25 '
]
]);任何两种货币的当前汇率,即法定或加密货币。此终点是公开的,不需要身份验证。
$ client -> getExchangeRate ( ' BTC ' , ' EUR ' );当前的商人和商人的汇率。此终点是公开的,不需要身份验证。
$ client -> listExchangeRates ();Coingate API的健康检查端点。此终点是公开的,不需要身份验证。
$ client -> ping ();获取Coingate服务器的IP地址
$ client -> getIPAddresses (); $ client -> getCurrencies ();
// Crypto + Native + Merchant Pay
$ client -> getCheckoutCurrencies ();
// get Merchant Pay currencies only
$ client -> getMerchantPayCurrencies ();
// get Merchant Receive currencies only
$ client -> getMerchantPayoutCurrencies (); $ client -> getPlatforms ();要修改请求超时(连接或总计,以秒为单位),您需要告诉API客户端以外的其他curlclclient。您将在该卷发夹中设置超时。
// 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 $ result = CoinGate Client:: testConnection ( ' YOUR_API_TOKEN ' );为了在沙盒模式下测试API连接,您需要将第二个参数设置为true 。
$ result = CoinGate Client:: testConnection ( ' YOUR_API_TOKEN ' , true );您是否正在编写一个集成了涂层并嵌入我们库的插件?然后,请使用setappinfo函数来识别您的插件。例如:
CoinGate Client:: setAppInfo ( " MyAwesomePlugin " , " 1.0.0 " );在将任何请求发送到API之前,应调用该方法一次。第二个参数是可选的。