PHP code example of vladchornyi / mono

1. Go to this page and download the library: Download vladchornyi/mono 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/ */

    

vladchornyi / mono example snippets


use Vladchornyi\Mono\MonoClient;
use Vladchornyi\Mono\Models\InvoiceData;

$apiKey = 'ВАШ_API_КЛЮЧ';
$monoClient = new MonoClient($apiKey);

try {
    $pubKey = $monoClient->pubkey()->get();
    echo "Public Key: " . $pubKey;
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

$redirectUrl = 'https://test.com?payment=success';
$webHookUrl = 'https://test.com/mono/callback';
$params = ['saveCard' => true];

$invoiceData = new InvoiceData(150, $redirectUrl, $webHookUrl, $params);

try {
    $invoice = $monoClient->invoices()->createInvoice($invoiceData);
    $invoiceId = $invoice['invoiceId'] ?? false;
    if($invoiceId !== false) {
        echo "Invoice Created: " . $invoiceId;
    }
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

$invoiceId = 'ВАШ_INVOICE_ID';

try {
    $invoiceStatus = $monoClient->invoices()->getInvoiceStatus($invoiceId);
    $status = $invoice['status'] ?? false;
    if($status !== false) {
        echo "Invoice Status: " . $status;
    }
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

$fromTime = 1609459200; // початок періоду в форматі Unix timestamp
$toTime = 1612137600; // кінець періоду в форматі Unix timestamp

try {
    $statement = $monoClient->statements()->getStatement($fromTime, $toTime);
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

try {
    // Ваш код тут
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}