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之前,應調用該方法一次。第二個參數是可選的。