phabloraylan/coinpayments-php-sdk

为CoinPayments.net v1 API提供的PHP封装。

1.0.1 2019-09-03 00:00 UTC

This package is auto-updated.

Last update: 2024-09-04 08:12:48 UTC


README

#Coinpayments PHP SDK

用于连接到https://www.coinpayments.net的库

未来将添加更多功能。

安装

通过composer

composer require phabloraylan/coinpayments-php

使用

将autoload包含到您的项目中,例如

require_once __DIR__ . '/vendor/autoload.php';

创建一个简单的交易

/** Scenario: Create a simple transaction. **/

// Create a new API wrapper instance
$private_key= "";
$public_key = "";
$cps_api = new \Coinpayments\CoinpaymentsAPI($private_key, $public_key, 'json');

// Make call to API to create the transaction
try {

    $fields = [
        'amount' => 100.00,
        'currency1' => 'BRL',
        'currency2' => 'LTCT',
        'buyer_email' => 'phabloraylan@gmail.com'
    ];
    $transaction_response = $cps_api->CreateCustomTransaction($fields);
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
    exit();
}

if ($transaction_response['error'] == 'ok') {
    // Success!
    $output = 'Transaction created with ID: ' . $transaction_response['result']['txn_id'] . '<br>';
    $output .= 'Amount for buyer to send: ' . $transaction_response['result']['amount'] . '<br>';
    $output .= 'Address for buyer to send to: ' . $transaction_response['result']['address'] . '<br>';
    $output .= 'Seller can view status here: ' . $transaction_response['result']['status_url'];

} else {
    // Something went wrong!
    $output = 'Error: ' . $transaction_response['error'];
}

// Output the response of the API call
echo $output;