File tree Expand file tree Collapse file tree 2 files changed +47
-2
lines changed
tests/Omnipay/Common/Message Expand file tree Collapse file tree 2 files changed +47
-2
lines changed Original file line number Diff line number Diff line change @@ -308,9 +308,9 @@ protected function getCurrencies()
308
308
* @return null|Money
309
309
* @throws InvalidRequestException
310
310
*/
311
- public function getMoney ()
311
+ public function getMoney ($ amount = null )
312
312
{
313
- $ amount = $ this ->getParameter ('amount ' );
313
+ $ amount = $ amount !== null ? $ amount : $ this ->getParameter ('amount ' );
314
314
315
315
if ($ amount instanceof Money) {
316
316
return $ amount ;
@@ -430,6 +430,36 @@ public function getCurrencyNumeric()
430
430
}
431
431
}
432
432
433
+ /**
434
+ * Get the number of decimal places in the payment currency.
435
+ *
436
+ * @return integer
437
+ */
438
+ public function getCurrencyDecimalPlaces ()
439
+ {
440
+ if ($ this ->getCurrency ()) {
441
+ $ currency = new Currency ($ this ->getCurrency ());
442
+ if ($ this ->getCurrencies ()->contains ($ currency )) {
443
+ return $ this ->getCurrencies ()->subunitFor ($ currency );
444
+ }
445
+ }
446
+
447
+ return 2 ;
448
+ }
449
+
450
+ /**
451
+ * Format an amount for the payment currency.
452
+ *
453
+ * @return string
454
+ */
455
+ public function formatCurrency ($ amount )
456
+ {
457
+ $ money = $ this ->getMoney ($ amount );
458
+ $ formatter = new DecimalMoneyFormatter ($ this ->getCurrencies ());
459
+
460
+ return $ formatter ->format ($ money );
461
+ }
462
+
433
463
/**
434
464
* Get the request description.
435
465
*
Original file line number Diff line number Diff line change @@ -273,6 +273,21 @@ public function testCurrencyNumericUnkown()
273
273
$ this ->assertSame (null , $ this ->request ->getCurrencyNumeric ());
274
274
}
275
275
276
+ public function testCurrencyDecimals ()
277
+ {
278
+ $ this ->assertSame ($ this ->request , $ this ->request ->setCurrency ('JPY ' ));
279
+ $ this ->assertSame (0 , $ this ->request ->getCurrencyDecimalPlaces ());
280
+ }
281
+ public function testFormatCurrency ()
282
+ {
283
+ $ this ->assertSame ('1234.00 ' , $ this ->request ->formatCurrency (1234 ));
284
+ }
285
+ public function testFormatCurrencyNoDecimals ()
286
+ {
287
+ $ this ->request ->setCurrency ('JPY ' );
288
+ $ this ->assertSame ('1234 ' , $ this ->request ->formatCurrency (1234 ));
289
+ }
290
+
276
291
public function testDescription ()
277
292
{
278
293
$ this ->assertSame ($ this ->request , $ this ->request ->setDescription ('Cool product ' ));
You can’t perform that action at this time.
0 commit comments