PHP code example of atsareva / monopay
1. Go to this page and download the library: Download atsareva/monopay 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/ */
atsareva / monopay example snippets
/** Initialize Mono client */
$client = new MonoPay\ClientMono('TOKEN');
$options = [
'amount' => 5000,
'merchantPaymInfo' => [
'reference' => '1000000021',
'destination' => 'Order #1000000021',
'basketOrder' => [
[
'name' => 'Product ABC',
'qty' => 1,
'sum' => 5000, // Amount in the smallest currency unit per product unit
'icon' => 'https://example.com/media/catalog/product/product_abc.jpg',
'unit' => 'kg',
],
],
],
'redirectUrl' => 'https://example.com/monopay/success.php',
'webHookUrl' => 'https://example.com/monopay/webhook.php',
'paymentType' => 'hold', // Options: debit | hold
];
try {
$invoice = new MonoPay\Invoice();
$invoice
->setClient($client)
->create($options);
// Save invoice ID for future reference
echo "Invoice ID: " . $invoice->getInvoiceId() . '<br/>';
echo "Invoice Payment URL: " . $invoice->getPageUrl() . '<br/>';
echo "Invoice Status: " . $invoice->getStatus() . '<br/>';
// Redirect customer to payment page
header("Location: " . $invoice->getPageUrl());
} catch (Exception $e) {
// Handle error
echo $e->getMessage();
}
try {
$invoice
->setClient($client)
->setInvoiceId('INVOICE_ID')
->updateInfo();
echo "Invoice ID: " . $invoice->getInvoiceId() . '<br/>';
echo "Invoice Status: " . $invoice->getStatus() . '<br/>';
} catch (Exception $e) {
// Handle error
echo $e->getMessage();
}
try {
$invoice
->setClient($client)
->setInvoiceId('INVOICE_ID')
->refund()
->updateInfo();
echo "Invoice Status: " . $invoice->getStatus() . '<br/>';
} catch (Exception $e) {
// Handle error
echo $e->getMessage();
}
try {
$merchant = new MonoPay\Merchant();
$merchant
->setClient($client)
->load();
echo "Merchant ID: " . $merchant->getMerchantId() . '<br/>';
echo "Merchant Name: " . $merchant->getMerchantName() . '<br/>';
echo "Public Key: " . $merchant->getPublicKey() . '<br/>';
// Load all statements from the last 4 days
$statements = $merchant->getStatement(time() - 60 * 60 * 96);
foreach ($statements as $statement) {
var_dump($statement);
}
} catch (Exception $e) {
// Handle error
echo $e->getMessage();
}