1. Go to this page and download the library: Download usukhbayar/qpay-php 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/ */
usukhbayar / qpay-php example snippets
use QPay\Config;
use QPay\QPayClient;
use QPay\Models\CreateSimpleInvoiceRequest;
use QPay\Exceptions\QPayException;
// Configure from environment variables
$config = Config::fromEnv();
$client = new QPayClient($config);
// Or configure manually
$config = new Config(
baseUrl: 'https://merchant.qpay.mn',
username: 'YOUR_USERNAME',
password: 'YOUR_PASSWORD',
invoiceCode: 'YOUR_INVOICE_CODE',
callbackUrl: 'https://yoursite.com/callback',
);
$client = new QPayClient($config);
// Create an invoice (token is obtained automatically)
try {
$invoice = $client->createSimpleInvoice(new CreateSimpleInvoiceRequest(
invoiceCode: $config->invoiceCode,
senderInvoiceNo: 'ORDER-001',
invoiceReceiverCode: 'terminal',
invoiceDescription: 'Payment for Order #001',
amount: 10000.0,
callbackUrl: $config->callbackUrl,
));
echo $invoice->invoiceId; // Invoice ID
echo $invoice->qPayShortUrl; // Payment link
echo $invoice->qrImage; // QR code image (base64)
} catch (QPayException $e) {
echo "Error: {$e->errorCode} - {$e->errorMessage}";
}
// All 5 variables must be set, otherwise InvalidArgumentException is thrown
$config = Config::fromEnv();
use GuzzleHttp\Client as HttpClient;
$http = new HttpClient([
'timeout' => 60,
'proxy' => 'tcp://localhost:8080',
]);
$client = new QPayClient($config, $http);
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.