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\Models\InvoiceData;
use Vladchornyi\Mono\MonoClient;

$mono = new MonoClient($_ENV['MONO_KEY']);

// 1. Create the invoice and send the customer to pageUrl.
$invoice = $mono->invoices()->createInvoice(new InvoiceData(
    amount: 58000,                                       // kopecks
    redirectUrl: 'https://example.com/payments/return',
    webHookUrl: 'https://example.com/webhooks/monobank'
));
header('Location: ' . $invoice['pageUrl']);

// 2. In the webhook endpoint: verify the signature, then apply the status.
$event = $mono->webhooks()->parseVerifiedPayload(
    file_get_contents('php://input'),
    $_SERVER['HTTP_X_SIGN'] ?? null
);

if ($event->isSuccessful()) {
    // mark the order paid, once per $event->deduplicationKey()
}