Setting the Amount
An amount turns a static code into a dynamic one. The payer's banking app fills the figure in automatically, so there's nothing to type and nothing to mistype.
RaastQr::iban($iban)->amount('2500')->toPng();Accepted Values
Amounts must be positive, use at most two decimal places, and stay within ten characters once normalised. Thousands separators are accepted and stripped.
| Input | Result |
|---|---|
4 | 4 |
4.2 | 4.2 |
'4.22' | 4.22 |
'4.20' | 4.20 |
'5,000.50' | 5000.50 |
'0.01' | 0.01 |
'0500' | 500 |
null | static code, no amount |
Rejected Values
| Input | Reason |
|---|---|
'4.222' | More than two decimal places |
'.50' | A digit is required before the point |
'4.' | A digit is required after the point |
0 | The amount must be positive |
-4.22 | Negative amounts are not accepted |
'Rs 500' | Currency text and symbols are not accepted |
'12345678901' | Longer than ten characters |
With two decimal places, the largest accepted amount is 9999999.99. Whole numbers can use more digits as long as the normalised string stays within ten characters.
Pass Money as a String
Floats and money don't mix
0.1 + 0.2 in PHP is 0.30000000000000004. Float noise is exactly the kind of thing that turns a working amount into a rejected one, or worse, a subtly wrong one.
Use a string, an integer, or the output of a decimal library:
// Good
RaastQr::make()->amount('2500.50');
RaastQr::make()->amount((string) $order->total);
RaastQr::make()->amount(bcadd($subtotal, $tax, 2));
// Risky
RaastQr::make()->amount($subtotal + $tax);If you store money as integer paisa — which you should — convert explicitly:
RaastQr::make()->amount(number_format($order->total_paisa / 100, 2, '.', ''));Checking an Amount First
$normalized = RaastQr::normalizeAmount($request->amount);
if ($normalized === null) {
return back()->withErrors(['amount' => 'That amount cannot be encoded.']);
}It returns the normalised string, an empty string when the amount was omitted, or null when it's invalid.
Amounts and Expiry
Adding an amount automatically adds an expiry of the next calendar day. See Setting the Expiry for why, and how to change it.
Made with ❤️ from Pakistan