@@ -305,17 +305,23 @@ protected function getCurrencies()
305305 }
306306
307307 /**
308+ * @param string|int|null $amount
308309 * @return null|Money
309310 * @throws InvalidRequestException
310311 */
311312 private function getMoney ($ amount = null )
312313 {
314+ $ currencyCode = $ this ->getCurrency () ?: 'USD ' ;
315+ $ currency = new Currency ($ currencyCode );
316+
313317 $ amount = $ amount !== null ? $ amount : $ this ->getParameter ('amount ' );
314318
315- if ($ amount !== null ) {
319+ if ($ amount === null ) {
320+ return null ;
321+ } elseif (is_integer ($ amount )) {
322+ $ money = new Money ($ amount , $ currency );
323+ } else {
316324 $ moneyParser = new DecimalMoneyParser ($ this ->getCurrencies ());
317- $ currencyCode = $ this ->getCurrency () ?: 'USD ' ;
318- $ currency = new Currency ($ currencyCode );
319325
320326 $ number = Number::fromString ($ amount );
321327
@@ -327,19 +333,19 @@ private function getMoney($amount = null)
327333 }
328334
329335 $ money = $ moneyParser ->parse ((string ) $ number , $ currency );
336+ }
330337
331- // Check for a negative amount.
332- if (!$ this ->negativeAmountAllowed && $ money ->isNegative ()) {
333- throw new InvalidRequestException ('A negative amount is not allowed. ' );
334- }
335-
336- // Check for a zero amount.
337- if (!$ this ->zeroAmountAllowed && $ money ->isZero ()) {
338- throw new InvalidRequestException ('A zero amount is not allowed. ' );
339- }
338+ // Check for a negative amount.
339+ if (!$ this ->negativeAmountAllowed && $ money ->isNegative ()) {
340+ throw new InvalidRequestException ('A negative amount is not allowed. ' );
341+ }
340342
341- return $ money ;
343+ // Check for a zero amount.
344+ if (!$ this ->zeroAmountAllowed && $ money ->isZero ()) {
345+ throw new InvalidRequestException ('A zero amount is not allowed. ' );
342346 }
347+
348+ return $ money ;
343349 }
344350
345351 /**
@@ -362,12 +368,12 @@ public function getAmount()
362368 /**
363369 * Sets the payment amount.
364370 *
365- * @param string $value
371+ * @param string|null $value
366372 * @return AbstractRequest Provides a fluent interface
367373 */
368374 public function setAmount ($ value )
369375 {
370- return $ this ->setParameter ('amount ' , $ value );
376+ return $ this ->setParameter ('amount ' , $ value !== null ? ( string ) $ value : null );
371377 }
372378
373379 /**
@@ -384,6 +390,17 @@ public function getAmountInteger()
384390 }
385391 }
386392
393+ /**
394+ * Sets the payment amount as integer.
395+ *
396+ * @param int $value
397+ * @return AbstractRequest Provides a fluent interface
398+ */
399+ public function setAmountInteger ($ value )
400+ {
401+ return $ this ->setParameter ('amount ' , (int ) $ value );
402+ }
403+
387404 /**
388405 * Get the payment currency code.
389406 *
@@ -446,11 +463,12 @@ public function getCurrencyDecimalPlaces()
446463 /**
447464 * Format an amount for the payment currency.
448465 *
466+ * @param string $amount
449467 * @return string
450468 */
451469 public function formatCurrency ($ amount )
452470 {
453- $ money = $ this ->getMoney ($ amount );
471+ $ money = $ this ->getMoney (( string ) $ amount );
454472 $ formatter = new DecimalMoneyFormatter ($ this ->getCurrencies ());
455473
456474 return $ formatter ->format ($ money );
0 commit comments