Skip to content

Commit 9284e7d

Browse files
committed
Add AbstractRequest::formatCurrency() method
1 parent 5ff842e commit 9284e7d

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/Omnipay/Common/Message/AbstractRequest.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,7 @@ public function getAmount()
172172
);
173173
}
174174

175-
return number_format(
176-
$amount,
177-
$this->getCurrencyDecimalPlaces(),
178-
'.',
179-
''
180-
);
175+
return $this->formatCurrency($amount);
181176
}
182177
}
183178

@@ -222,6 +217,16 @@ private function getCurrencyDecimalFactor()
222217
return pow(10, $this->getCurrencyDecimalPlaces());
223218
}
224219

220+
public function formatCurrency($amount)
221+
{
222+
return number_format(
223+
$amount,
224+
$this->getCurrencyDecimalPlaces(),
225+
'.',
226+
''
227+
);
228+
}
229+
225230
public function getDescription()
226231
{
227232
return $this->getParameter('description');

tests/Omnipay/Common/Message/AbstractRequestTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ public function testCurrencyDecimals()
140140
$this->assertSame(0, $this->request->getCurrencyDecimalPlaces());
141141
}
142142

143+
public function testFormatCurrency()
144+
{
145+
$this->assertSame('1234.00', $this->request->formatCurrency(1234));
146+
}
147+
148+
public function testFormatCurrencyNoDecimals()
149+
{
150+
$this->request->setCurrency('JPY');
151+
$this->assertSame('1234', $this->request->formatCurrency(1234));
152+
}
153+
143154
public function testDescription()
144155
{
145156
$this->assertSame($this->request, $this->request->setDescription('Cool product'));

0 commit comments

Comments
 (0)