66 abstract class AbstractRequest
implements RequestInterface
133 if (
null !== $this->response) {
134 throw new RuntimeException(
'Request cannot be modified after it has been sent!');
154 if (
null !== $this->response) {
155 throw new RuntimeException(
'Request cannot be modified after it has been sent!');
158 return $this->traitSetParameter($key, $value);
198 public function setCard($value)
200 if ($value && !$value instanceof
CreditCard) {
254 if ($this->currencies ===
null) {
255 $this->currencies =
new ISOCurrencies();
266 private function getMoney($amount =
null)
269 $currency =
new Currency($currencyCode);
271 $amount = $amount !==
null ? $amount : $this->
getParameter(
'amount');
273 if ($amount ===
null) {
275 } elseif ($amount instanceof
Money) {
277 } elseif (is_integer($amount)) {
278 $money =
new Money($amount, $currency);
280 $moneyParser =
new DecimalMoneyParser($this->
getCurrencies());
285 $decimal_count = strlen($number->getFractionalPart());
287 if ($decimal_count > $subunit) {
288 throw new InvalidRequestException(
'Amount precision is too high for currency.');
291 $money = $moneyParser->parse((
string) $number, $currency);
295 if (!$this->negativeAmountAllowed && $money->isNegative()) {
296 throw new InvalidRequestException(
'A negative amount is not allowed.');
300 if (!$this->zeroAmountAllowed && $money->isZero()) {
301 throw new InvalidRequestException(
'A zero amount is not allowed.');
315 $money = $this->getMoney();
317 if ($money !==
null) {
318 $moneyFormatter =
new DecimalMoneyFormatter($this->
getCurrencies());
320 return $moneyFormatter->format($money);
332 return $this->
setParameter(
'amount', $value !==
null ? (
string) $value :
null);
342 $money = $this->getMoney();
344 if ($money !==
null) {
345 return (
int) $money->getAmount();
393 if ($value !==
null) {
394 $value = strtoupper($value);
413 return (
string) $this->
getCurrencies()->numericCodeFor($currency);
442 $money = $this->getMoney((
string) $amount);
445 return $formatter->format($money);
513 return $this->
setParameter(
'transactionReference', $value);
534 if ($items && !$items instanceof ItemBag) {
535 $items =
new ItemBag($items);
684 public function send()
698 if (
null === $this->response) {
699 throw new RuntimeException(
'You must call send() before accessing the Response!');