File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
tests/Omnipay/Common/Message Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -318,6 +318,8 @@ private function getMoney($amount = null)
318
318
319
319
if ($ amount === null ) {
320
320
return null ;
321
+ } elseif ($ amount instanceof Money) {
322
+ $ money = $ amount ;
321
323
} elseif (is_integer ($ amount )) {
322
324
$ money = new Money ($ amount , $ currency );
323
325
} else {
@@ -401,6 +403,21 @@ public function setAmountInteger($value)
401
403
return $ this ->setParameter ('amount ' , (int ) $ value );
402
404
}
403
405
406
+ /**
407
+ * Sets the payment amount as integer.
408
+ *
409
+ * @param Money $value
410
+ * @return $this
411
+ */
412
+ public function setMoney (Money $ value )
413
+ {
414
+ $ currency = $ value ->getCurrency ()->getCode ();
415
+
416
+ $ this ->setCurrency ($ currency );
417
+
418
+ return $ this ->setParameter ('amount ' , $ value );
419
+ }
420
+
404
421
/**
405
422
* Get the payment currency code.
406
423
*
Original file line number Diff line number Diff line change 3
3
namespace Omnipay \Common \Message ;
4
4
5
5
use Mockery as m ;
6
+ use Money \Currency ;
7
+ use Money \Money ;
6
8
use Omnipay \Common \CreditCard ;
7
9
use Omnipay \Common \ItemBag ;
8
10
use Omnipay \Tests \TestCase ;
@@ -247,6 +249,18 @@ public function testAmountNegativeFloatThrowsException()
247
249
$ this ->request ->getAmount ();
248
250
}
249
251
252
+ public function testMoney ()
253
+ {
254
+ $ money = new Money (12345 , new Currency ('EUR ' ));
255
+ $ this ->assertSame ($ this ->request , $ this ->request ->setMoney ($ money ));
256
+
257
+ $ this ->request ->validate ('amount ' , 'currency ' );
258
+
259
+ $ this ->assertSame ('123.45 ' , $ this ->request ->getAmount ());
260
+ $ this ->assertSame (12345 , $ this ->request ->getAmountInteger ());
261
+ $ this ->assertSame ('EUR ' , $ this ->request ->getCurrency ());
262
+ }
263
+
250
264
public function testCurrency ()
251
265
{
252
266
$ this ->assertSame ($ this ->request , $ this ->request ->setCurrency ('USD ' ));
You can’t perform that action at this time.
0 commit comments