PHP code example of financialplugins / omnipay-coinpayments

1. Go to this page and download the library: Download financialplugins/omnipay-coinpayments library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

financialplugins / omnipay-coinpayments example snippets


$gateway = Omnipay::create('Coinpayments');
   
$gateway->initialize([
    'merchant_id'   => '...',
    'public_key'    => '...',
    'private_key'   => '...',
    'secret_key'    => '...'
);

$response = $gateway->fetchAccountInfo()->send();

if ($response->isSuccessful()) {
    $data = $response->getData();
} else {
    $errorMessage = $response->getMessage();
}

$response = $gateway->fetchBalance()->send();

if ($response->isSuccessful()) {
    $data = $response->getData();
} else {
    $errorMessage = $response->getMessage();
}

$response = $gateway->fetchCurrencies()->send();

if ($response->isSuccessful()) {
    $data = $response->getData();
} else {
    $errorMessage = $response->getMessage();
}

$response = $gateway
    ->fetchTransaction(['transactionReference' => '...'])
    ->send();

if ($response->isSuccessful()) {
    $data = $response->getData();
} else {
    $errorMessage = $response->getMessage();
}

$response = $gateway
    ->fetchWithdrawal(['withdrawalReference' => '...'])
    ->send();

if ($response->isSuccessful()) {
    $data = $response->getData();
} else {
    $errorMessage = $response->getMessage();
}

$response = $gateway
    ->createTransaction([
        'amount'            => '100',
        'currency'          => 'USD',
        'payment_currency'  => 'BTC',
        'description'       => 'Payment description',
        'client_email'      => '[email protected]',
        'notify_url'        => 'https://yourwebsite/webhook'
    ])
    ->send();

if ($response->isRedirect()) {
    $data = $response->getData();

    EXAMPLE RESPONSE:
    {
      "amount":"1.00000000",
      "address":"ZZZ",
      "dest_tag":"YYY",
      "txn_id":"XXX",
      "confirms_needed":"10",
      "timeout":9000,
      "checkout_url":"https:\/\/www.coinpayments.net\/index.php?cmd=checkout&id=XXX&key=ZZZ"
      "status_url":"https:\/\/www.coinpayments.net\/index.php?cmd=status&id=XXX&key=ZZZ"
      "qrcode_url":"https:\/\/www.coinpayments.net\/qrgen.php?id=XXX&key=ZZZ"
    }

} else {
    $errorMessage = $response->getMessage();
}

$response = $gateway
    ->createWithdrawal([
        'amount'            => '100',
        'currency'          => 'USD',
        'payment_currency'  => 'BTC',
        'description'       => 'Payment description',
        'address'           => 'XXXXXXXXXX',
        'auto_confirm'      => 0,
        'notify_url'        => 'https://yourwebsite/webhook'
    ])
    ->send();

if ($response->isSuccessful()) {
    $data = $response->getData();

    EXAMPLE RESPONSE:
    {
       "error":"ok",
       "result":{
          "id":"hex string",
          "status":0,
          "amount":1.00,
       }
    }

} else {
    $errorMessage = $response->getMessage();
}