@@ -305,17 +305,23 @@ protected function getCurrencies()
305
305
}
306
306
307
307
/**
308
+ * @param string|int|null $amount
308
309
* @return null|Money
309
310
* @throws InvalidRequestException
310
311
*/
311
312
private function getMoney ($ amount = null )
312
313
{
314
+ $ currencyCode = $ this ->getCurrency () ?: 'USD ' ;
315
+ $ currency = new Currency ($ currencyCode );
316
+
313
317
$ amount = $ amount !== null ? $ amount : $ this ->getParameter ('amount ' );
314
318
315
- if ($ amount !== null ) {
319
+ if ($ amount === null ) {
320
+ return null ;
321
+ } elseif (is_integer ($ amount )) {
322
+ $ money = new Money ($ amount , $ currency );
323
+ } else {
316
324
$ moneyParser = new DecimalMoneyParser ($ this ->getCurrencies ());
317
- $ currencyCode = $ this ->getCurrency () ?: 'USD ' ;
318
- $ currency = new Currency ($ currencyCode );
319
325
320
326
$ number = Number::fromString ($ amount );
321
327
@@ -327,19 +333,19 @@ private function getMoney($amount = null)
327
333
}
328
334
329
335
$ money = $ moneyParser ->parse ((string ) $ number , $ currency );
336
+ }
330
337
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
+ }
340
342
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. ' );
342
346
}
347
+
348
+ return $ money ;
343
349
}
344
350
345
351
/**
@@ -362,12 +368,12 @@ public function getAmount()
362
368
/**
363
369
* Sets the payment amount.
364
370
*
365
- * @param string $value
371
+ * @param string|null $value
366
372
* @return AbstractRequest Provides a fluent interface
367
373
*/
368
374
public function setAmount ($ value )
369
375
{
370
- return $ this ->setParameter ('amount ' , $ value );
376
+ return $ this ->setParameter ('amount ' , $ value !== null ? ( string ) $ value : null );
371
377
}
372
378
373
379
/**
@@ -384,6 +390,17 @@ public function getAmountInteger()
384
390
}
385
391
}
386
392
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
+
387
404
/**
388
405
* Get the payment currency code.
389
406
*
@@ -446,11 +463,12 @@ public function getCurrencyDecimalPlaces()
446
463
/**
447
464
* Format an amount for the payment currency.
448
465
*
466
+ * @param string $amount
449
467
* @return string
450
468
*/
451
469
public function formatCurrency ($ amount )
452
470
{
453
- $ money = $ this ->getMoney ($ amount );
471
+ $ money = $ this ->getMoney (( string ) $ amount );
454
472
$ formatter = new DecimalMoneyFormatter ($ this ->getCurrencies ());
455
473
456
474
return $ formatter ->format ($ money );
0 commit comments