Skip to content

Commit 2e6194d

Browse files
committed
Check for valid card object
1 parent dad499d commit 2e6194d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Omnipay/Common/Message/AbstractRequest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,13 @@ public function validate()
222222
*/
223223
public function getCard()
224224
{
225-
return $this->getParameter('card');
225+
$card = $this->getParameter('card');
226+
227+
if (!$card instanceof CreditCard) {
228+
return new CreditCard();
229+
}
230+
231+
return $card;
226232
}
227233

228234
/**

tests/Omnipay/Common/Message/AbstractRequestTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ public function testCard()
6363
$this->assertSame($card, $this->request->getCard());
6464
}
6565

66+
public function testGetCard()
67+
{
68+
$this->assertInstanceOf('\Omnipay\Common\CreditCard', $this->request->getCard());
69+
}
70+
6671
public function testSetCardWithArray()
6772
{
6873
// passing array should create CreditCard object

0 commit comments

Comments
 (0)