ห้องสมุด Coingate PHP ให้การเข้าถึง Coingate API ที่สะดวกจากแอปพลิเคชันที่เขียนในภาษา PHP
PHP 7.3.0 และใหม่กว่า
คุณสามารถติดตั้งไลบรารีผ่านนักแต่งเพลง เรียกใช้คำสั่งต่อไปนี้:
composer require coingate/coingate-php หากคุณไม่ต้องการใช้นักแต่งเพลงคุณสามารถดาวน์โหลดรุ่นล่าสุดได้ จากนั้นใช้ไลบรารีให้รวมไฟล์ init.php
require_once ( ' /path/to/coingate-php/init.php ' );ห้องสมุดต้องการส่วนขยายต่อไปนี้เพื่อทำงานอย่างถูกต้อง:
curl แม้ว่าคุณจะสามารถใช้ไคลเอนต์ที่ไม่ใช่ม้วนของคุณเองได้หากคุณต้องการjsonหากคุณใช้นักแต่งเพลงการพึ่งพาเหล่านี้ควรได้รับการจัดการโดยอัตโนมัติ หากคุณติดตั้งด้วยตนเองคุณจะต้องแน่ใจว่ามีส่วนขยายเหล่านี้พร้อมใช้งาน
คุณสามารถสมัครใช้งานบัญชี Coingate ได้ที่ https://coingate.com สำหรับการผลิตและ https://sandbox.coingate.com สำหรับการทดสอบ (Sandbox)
โปรดทราบว่าสำหรับ Sandbox คุณต้องสร้างข้อมูลรับรอง API แยกต่างหากใน https://sandbox.coingate.com ข้อมูลรับรอง API ที่สร้างขึ้นบน https://coingate.com จะไม่ทำงานสำหรับโหมด Sandbox
การใช้ห้องสมุด Coingate PHP ดูเหมือนว่า:
$ client = new CoinGate Client ( ' YOUR_API_TOKEN ' ); ในการสั่งซื้อโหมด Sandbox คุณต้องตั้งค่าพารามิเตอร์ที่สองเป็น 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 และ Redirect Shopper ไปยังใบแจ้งหนี้ (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, ฯลฯ ) แสดงการชำระเงิน _address และ pay_amount สำหรับนักช้อปหรือเปลี่ยนเส้นทางไปยัง Payment_url สามารถใช้กับใบแจ้งหนี้ฉลากสีขาว
$ checkout = $ client -> order -> checkout ( 7294 , [
' pay_currency ' => ' BTC '
]);หลังจากสร้างคำสั่งซื้อคุณจะได้รับรหัสคำสั่งซื้อ ID นี้จะถูกใช้สำหรับการขอคำสั่งซื้อ
$ order = $ client -> order -> get ( 7294 );การดึงข้อมูลของคำสั่งซื้อทั้งหมด
$ orders = $ client -> order -> list ([
' created_at ' => [
' from ' => ' 2022-01-25 '
]
]);อัตราแลกเปลี่ยนปัจจุบันสำหรับสองสกุลเงิน Fiat หรือ crypto จุดสิ้นสุดนี้เป็นสาธารณะไม่จำเป็นต้องมีการตรวจสอบสิทธิ์
$ client -> getExchangeRate ( ' BTC ' , ' EUR ' );อัตราแลกเปลี่ยน coingate ปัจจุบันสำหรับพ่อค้าและผู้ค้า จุดสิ้นสุดนี้เป็นสาธารณะไม่จำเป็นต้องมีการตรวจสอบสิทธิ์
$ client -> listExchangeRates ();จุดสิ้นสุดการตรวจสุขภาพสำหรับ Coingate API จุดสิ้นสุดนี้เป็นสาธารณะไม่จำเป็นต้องมีการตรวจสอบสิทธิ์
$ client -> ping ();รับที่อยู่ IP ของเซิร์ฟเวอร์ Coingate
$ 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 ' ); ในการสั่งซื้อเพื่อทดสอบการเชื่อมต่อ API ในโหมด Sandbox คุณต้องตั้งค่าพารามิเตอร์ที่สองเป็น true
$ result = CoinGate Client:: testConnection ( ' YOUR_API_TOKEN ' , true );คุณกำลังเขียนปลั๊กอินที่รวม Coingate และฝังไลบรารีของเราหรือไม่? จากนั้นโปรดใช้ฟังก์ชั่น setappinfo เพื่อระบุปลั๊กอินของคุณ ตัวอย่างเช่น:
CoinGate Client:: setAppInfo ( " MyAwesomePlugin " , " 1.0.0 " );ควรเรียกใช้วิธีหนึ่งครั้งก่อนที่คำขอใด ๆ จะถูกส่งไปยัง API พารามิเตอร์ที่สองเป็นตัวเลือก