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)
318318
319319 if ($ amount === null ) {
320320 return null ;
321+ } elseif ($ amount instanceof Money) {
322+ $ money = $ amount ;
321323 } elseif (is_integer ($ amount )) {
322324 $ money = new Money ($ amount , $ currency );
323325 } else {
@@ -401,6 +403,21 @@ public function setAmountInteger($value)
401403 return $ this ->setParameter ('amount ' , (int ) $ value );
402404 }
403405
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+
404421 /**
405422 * Get the payment currency code.
406423 *
Original file line number Diff line number Diff line change 33namespace Omnipay \Common \Message ;
44
55use Mockery as m ;
6+ use Money \Currency ;
7+ use Money \Money ;
68use Omnipay \Common \CreditCard ;
79use Omnipay \Common \ItemBag ;
810use Omnipay \Tests \TestCase ;
@@ -247,6 +249,18 @@ public function testAmountNegativeFloatThrowsException()
247249 $ this ->request ->getAmount ();
248250 }
249251
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+
250264 public function testCurrency ()
251265 {
252266 $ this ->assertSame ($ this ->request , $ this ->request ->setCurrency ('USD ' ));
You can’t perform that action at this time.
0 commit comments