Skip to content

Commit 2e9fcd1

Browse files
committed
Fix bug where validating currency returns true after setting to null
Previously, if you set the currency field to null and then called `validate` on the currency field, the validation would pass because `strtoupper(null) === ''`, but `validate` looks for null values. Now `strtoupper` is not called when the currency field is set to null, so validation will fail.
1 parent e4054bc commit 2e9fcd1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Omnipay/Common/Message/AbstractRequest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,10 @@ public function getCurrency()
399399
*/
400400
public function setCurrency($value)
401401
{
402-
return $this->setParameter('currency', strtoupper($value));
402+
if ($value !== null) {
403+
$value = strtoupper($value);
404+
}
405+
return $this->setParameter('currency', $value);
403406
}
404407

405408
/**

tests/Omnipay/Common/Message/AbstractRequestTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,12 @@ public function testCurrencyLowercase()
284284
$this->assertSame('USD', $this->request->getCurrency());
285285
}
286286

287+
public function testCurrencyNull()
288+
{
289+
$this->assertSame($this->request, $this->request->setCurrency(null));
290+
$this->assertNull($this->request->getCurrency());
291+
}
292+
287293
public function testCurrencyNumeric()
288294
{
289295
$this->assertSame($this->request, $this->request->setCurrency('USD'));

0 commit comments

Comments
 (0)