1. Go to this page and download the library: Download coinpay/php-integration 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/ */
coinpay / php-integration example snippets
use Coinpay\Finance\CoinPayGateway;
use Coinpay\Finance\Exceptions\CoinPayException;
$gateway = new CoinPayGateway('###COINPAY_API_KEY###');
try {
$response = $gateway->createPayment(
1.0, // The amount to be paid (in Dollar - $).
'https://your-callback.url', // The URL the user will be redirected to after payment.
'ref123', // A unique reference ID for tracking the transaction.
'[email protected]', // The identity of the payer (email or phone number).
'Alimo', // Full name of the payer.
'Test Payment', // Description of the payment (e.g. "Payment for order #123").
'1234567890' // National identification code of the payer.
);
echo "Payment URL: " . $response->url . PHP_EOL; // Redirect the user to this URL
echo "Transaction ID: " . $response->transactionId . PHP_EOL; // Store this ID if you need it later
} catch (CoinPayException $e) {
// $e->getHttpStatusCode() — HTTP status code, or 0 if the request never got a response
// $e->getResponseBody() — decoded (array) or raw (string) response body, if any
// $e->isNetworkError() — true for connection/timeout failures rather than API rejections
echo "Error: " . $e->getMessage() . PHP_EOL;
}