Skip to content

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.

php
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.

InputResult
44
4.24.2
'4.22'4.22
'4.20'4.20
'5,000.50'5000.50
'0.01'0.01
'0500'500
nullstatic code, no amount

Rejected Values

InputReason
'4.222'More than two decimal places
'.50'A digit is required before the point
'4.'A digit is required after the point
0The amount must be positive
-4.22Negative 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:

php
// 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:

php
RaastQr::make()->amount(number_format($order->total_paisa / 100, 2, '.', ''));

Checking an Amount First

php
$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