Coingate PHPライブラリは、PHP言語で記述されたアプリケーションからCoingate APIへの便利なアクセスを提供します。
PHP 7.3.0以降。
Composerを介してライブラリをインストールできます。次のコマンドを実行します。
composer require coingate/coingate-phpComposerを使用したくない場合は、最新リリースをダウンロードできます。次に、ライブラリを使用するには、 init.phpファイルを含めます。
require_once ( ' /path/to/coingate-php/init.php ' );ライブラリは、適切に動作するために次の拡張機能を必要とします。
curl 、あなたが望むならあなた自身の非カールクライアントを使用することはできますがjsonComposerを使用する場合、これらの依存関係は自動的に処理する必要があります。手動でインストールする場合は、これらの拡張機能が利用可能であることを確認する必要があります。
https://coingate.comでCoingateアカウントにサインアップして、テスト(Sandbox)のためにhttps://sandbox.coingate.comにサインアップできます。
Sandboxの場合、https://sandbox.coing.comで個別のAPI資格情報を生成する必要があることに注意してください。 https://coingate.comで生成されたAPI資格情報は、Sandboxモードでは機能しません。
Coingate PHPライブラリの使用法は次のように見えます:
$ client = new CoinGate Client ( ' YOUR_API_TOKEN ' );順番に、サンドボックスモードを使用するには、2番目のパラメーターを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など)で作成された注文を配置します。 ShopperまたはRedirectにPayment_AddressとPay_Amountを表示します。ホワイトラベルの請求書に使用できます。
$ 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 '
]
]);2つの通貨、フィアットまたは暗号の現在の為替レート。このエンドポイントは公開されており、認証は必要ありません。
$ 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クライアントにデフォルト以外のCurlClientを使用するように指示する必要があります。その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 $ result = CoinGate Client:: testConnection ( ' YOUR_API_TOKEN ' ); SandboxモードでAPI接続をテストするには、2番目のパラメーターをtrueに設定する必要があります。
$ result = CoinGate Client:: testConnection ( ' YOUR_API_TOKEN ' , true );Coingateを統合し、ライブラリを埋め込むプラグインを書いていますか?次に、Setappinfo関数を使用してプラグインを識別してください。例えば:
CoinGate Client:: setAppInfo ( " MyAwesomePlugin " , " 1.0.0 " );リクエストがAPIに送信される前に、メソッドを1回呼び出す必要があります。 2番目のパラメーターはオプションです。