4msar / coingate-php
PHP CoinGate 库,{MSAR 添加的定制方法}
3.0.1
2018-05-04 12:03 UTC
Requires
- ext-curl: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: 4.8.*
This package is auto-updated.
Last update: 2024-09-29 04:48:47 UTC
README
CoinGate API 的 PHP 库。
您可以在https://coingate.com注册 CoinGate 账户用于生产,以及在https://sandbox.coingate.com进行测试(沙盒)。
请注意,对于沙盒,您必须在https://sandbox.coingate.com上生成单独的 API 凭据。在https://coingate.com上生成的 API 凭据在沙盒模式下将不会工作。
Composer
您可以通过 Composer 安装库。在您的终端中运行以下命令
composer require 4msar/coingate-php
手动安装
下载最新版本并包含 init.php
文件。
require_once('/path/to/coingate-php/init.php');
入门
CoinGate PHP 库的使用。
设置 CoinGate 库
设置默认认证
use CoinGate\CoinGate; \CoinGate\CoinGate::config(array( 'environment' => 'sandbox', // sandbox OR live 'auth_token' => 'YOUR_AUTH_TOKEN', 'curlopt_ssl_verifypeer' => TRUE // default is false )); // $order = \CoinGate\Merchant\Order::find(7294);
单独设置认证
use CoinGate\CoinGate; # \CoinGate\Merchant\Order::find($orderId, $options = array(), $authentication = array()) $order = \CoinGate\Merchant\Order::find(1087999, array(), array( 'environment' => 'sandbox', // sandbox OR live 'auth_token' => 'YOUR_AUTH_TOKEN'));
创建商户订单
https://developer.coingate.com/docs/create-order
use CoinGate\CoinGate; $post_params = array( 'order_id' => 'YOUR-CUSTOM-ORDER-ID-115', 'price_amount' => 1050.99, 'price_currency' => 'USD', 'receive_currency' => 'EUR', 'callback_url' => 'https://example.com/payments/callback?token=6tCENGUYI62ojkuzDPX7Jg', 'cancel_url' => 'https://example.com/cart', 'success_url' => 'https://example.com/account/orders', 'title' => 'Order #112', 'description' => 'Apple Iphone 6' ); $order = \CoinGate\Merchant\Order::create($post_params); if ($order) { echo $order->status; print_r($order); } else { # Order Is Not Valid }
获取商户所有订单
use CoinGate\CoinGate; try { $order = \CoinGate\Merchant\Order::get_all(); if ($order) { var_dump($order); } else { echo 'Order not found'; } } catch (Exception $e) { echo $e->getMessage(); // BadCredentials Not found App by Access-Key }
获取商户订单
https://developer.coingate.com/docs/get-order
use CoinGate\CoinGate; try { $order = \CoinGate\Merchant\Order::find(7294); if ($order) { var_dump($order); } else { echo 'Order not found'; } } catch (Exception $e) { echo $e->getMessage(); // BadCredentials Not found App by Access-Key }
测试 API 凭据
$testConnection = \CoinGate\CoinGate::testConnection(array( 'environment' => 'sandbox', 'auth_token' => 'YOUR_AUTH_TOKEN' )); if ($testConnection !== true) { echo $testConnection; // CoinGate\BadCredentials: BadCredentials Not found App by Access-Key }
这是从 coingate 克隆的仓库,但添加了一些额外功能。
例如 get_all() 等。