public function getAmount()
{
$amount = $this->getParameter('amount');
if ($amount !== null) {
// Don't allow integers for currencies that support decimals.
// This is for legacy reasons - upgrades from v0.9
if ($this->getCurrencyDecimalPlaces() > 0) {
if (is_int($amount) || is_string($amount) && false === strpos((string) $amount, '.')) {
throw new InvalidRequestException('Please specify amount as a string or float, ' . 'with decimal places (e.g. \'10.00\' to represent $10.00).');
}
}
$amount = $this->toFloat($amount);
// Check for a negative amount.
if (!$this->negativeAmountAllowed && $amount < 0) {
throw new InvalidRequestException('A negative amount is not allowed.');
}
// Check for a zero amount.
if (!$this->zeroAmountAllowed && $amount === 0.0) {
throw new InvalidRequestException('A zero amount is not allowed.');
}
// Check for rounding that may occur if too many significant decimal digits are supplied.
$decimal_count = strlen(substr(strrchr(sprintf('%.8g', $amount), '.'), 1));
if ($decimal_count > $this->getCurrencyDecimalPlaces()) {
throw new InvalidRequestException('Amount precision is too high for currency.');
}
return $this->formatCurrency($amount);
}
}