Skip to content

Amounts ​

Every payment data amount (and every Wave Pay and Wave Pay Mini App item amount) is an Amount or a whole int. An Amount is an exact, non-negative amount kept as decimal text, so it is never rounded through a float.

php
use Laranex\PhpMyanmarPayments\Amount;

Amount::kyat(10000);       // whole amount: 10000
Amount::parse('10000.50'); // decimal, from a string
Amount::from(10000);       // an Amount as is, or an int through kyat()

A float such as 10.5 is never accepted: write decimals as Amount::parse('10.50').

Parsing ​

Amount::parse accepts only digits with an optional fractional part: 1000, 1000.50, 0.5. It rejects signs, exponents, spaces and thousands separators (-1, 1e5, 10, 1,000, 10., .5). Leading zeros of the whole part are removed (007 becomes 7); fractional digits are kept exactly as given (10.50 stays 10.50).

Amount::kyat takes an int. Negative values throw. A negative int passed as payment data is reported with the other invalid fields as The amount field must not be negative. (items.0.amount for a Wave Pay item).

They throw an InvalidPaymentDataException with an amount entry, so bad user input surfaces like any other invalid field:

php
use Laranex\PhpMyanmarPayments\Amount;
use Laranex\PhpMyanmarPayments\Exceptions\InvalidPaymentDataException;

try {
    $amount = Amount::parse($input);
} catch (InvalidPaymentDataException $e) {
    // The amount field must be a number such as 1000 or 1000.50,
    // got "1,000".
    error_log($e->errors()['amount']);
}

Methods ​

MethodReturns
Amount::kyat($n)A whole amount from an int
Amount::parse($text)A decimal amount from plain digits
Amount::from($value)$value itself when it is an Amount, else Amount::kyat($value)
$amount->toString()The amount as sent to the gateway, e.g. 1000.50; also (string) $amount
$amount->decimalPlaces()Number of fractional digits
$amount->wholePart()The digits before the decimal point
$amount->isZero()The amount equals zero
$amount->isPositive()The amount is greater than zero
$amount->equals($other)Same value, ignoring leading zeros and trailing fractional zeros (1000 equals 1000.00); takes an Amount or a string; null and text that is not plain digits are never equal
json_encode($amount)The amount as a JSON string, e.g. "1000.50"

Gateway Rules ​

Each gateway checks the amount against its official documentation when you create the payment data, before any request is sent:

GatewayDecimalsOther rules
KBZ PayUp to 2 placesGreater than 0, MMK only
Wave PayNoGreater than 0, MMK only. The total defaults to the sum of the items
Wave Pay Mini AppNoGreater than 0. The total defaults to the sum of the items
AYA Payment GatewayNoGreater than 0, MMK only
Yoma MMQRNoGreater than 0
CyberSourceAny0 or more, at most 15 characters, currencies enabled on your Secure Acceptance profile

A violation throws InvalidPaymentDataException, e.g. Wave Pay does not accept decimal amounts; the amount field must be a whole number. AYA Payment Gateway, whose documentation shows no decimal amounts, reports AYA Payment Gateway documents no decimal amounts; the amount field must be a whole number.

Storing Amounts ​

$amount->toString() is the exact text ("1000.50"), so store it in a text or DECIMAL column. Read it back with Amount::parse.

Amounts reported by gateways (PaymentCallback::$amount, PaymentStatusResult::$amount) are plain strings: the exact text the gateway sent, even when it sent a JSON number such as 1000.50. Compare them with $amount->equals($callback->amount).