PHP code example of mortogo321 / laravel-thai-promptpay
1. Go to this page and download the library: Download mortogo321/laravel-thai-promptpay 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/ */
mortogo321 / laravel-thai-promptpay example snippets
use Mortogo321\LaravelThaiPromptPay\Facades\PromptPay;
// Generate QR code with phone number
$qrCode = PromptPay::generateQRCode('0812345678');
// Generate QR code with fixed amount
$qrCode = PromptPay::generateQRCode('0812345678', 100.50);
// Generate QR code with National ID
$qrCode = PromptPay::generateQRCode('1234567890123', 250.00);
// Generate QR code with custom size (default: 300px)
$qrCode = PromptPay::generateQRCode('0812345678', 100.00, 400);
// Generate payload string only
$payload = PromptPay::generatePayload('0812345678', 100.00);
// Generate QR code as binary PNG
$binary = PromptPay::generateQRCodeBinary('0812345678', 100.00);
use Mortogo321\LaravelThaiPromptPay\PromptPayQR;
class PaymentController extends Controller
{
public function generateQR(PromptPayQR $promptpay)
{
$qrCode = $promptpay->generateQRCode('0812345678', 150.00);
return view('payment', compact('qrCode'));
}
}
use Mortogo321\LaravelThaiPromptPay\PromptPayQR;
$qr = new PromptPayQR();
// Validate without generating QR
$result = $qr->validate('0812345678');
// Returns: ['valid' => true, 'type' => 'mobile', 'formatted' => '0066812345678', 'error' => null]
$result = $qr->validate('invalid');
// Returns: ['valid' => false, 'type' => null, 'formatted' => null, 'error' => 'Invalid PromptPay ID format...']
$qr->validateAmount(100.50); // ['valid' => true, 'error' => null]
$qr->validateAmount(-50); // ['valid' => false, 'error' => 'Amount cannot be negative']
$qr->validateAmount(9999999999); // ['valid' => false, 'error' => 'Amount exceeds maximum...']
$qr->validateAmount(100.123); // ['valid' => false, 'error' => 'Amount must have at most 2 decimal places']