Skip to content

Commit b1630ef

Browse files
committed
Add CreditCard birthday and gender fields
1 parent 02ba9e5 commit b1630ef

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/Omnipay/Common/CreditCard.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Omnipay\Common;
44

5+
use DateTime;
6+
use DateTimeZone;
57
use Omnipay\Common\Exception\InvalidCreditCardException;
68
use Symfony\Component\HttpFoundation\ParameterBag;
79

@@ -631,4 +633,32 @@ public function setEmail($value)
631633
{
632634
return $this->setParameter('email', $value);
633635
}
636+
637+
public function getBirthday($format = 'Y-m-d')
638+
{
639+
$value = $this->getParameter('birthday');
640+
641+
return $value ? $value->format($format) : null;
642+
}
643+
644+
public function setBirthday($value)
645+
{
646+
if ($value) {
647+
$value = new DateTime($value, new DateTimeZone('UTC'));
648+
} else {
649+
$value = null;
650+
}
651+
652+
return $this->setParameter('birthday', $value);
653+
}
654+
655+
public function getGender()
656+
{
657+
return $this->getParameter('gender');
658+
}
659+
660+
public function setGender($value)
661+
{
662+
return $this->setParameter('gender', $value);
663+
}
634664
}

tests/Omnipay/Common/CreditCardTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,4 +498,23 @@ public function testEmail()
498498
$this->card->setEmail('[email protected]');
499499
$this->assertEquals('[email protected]', $this->card->getEmail());
500500
}
501+
502+
public function testBirthday()
503+
{
504+
$this->card->setBirthday('01-02-2000');
505+
$this->assertEquals('2000-02-01', $this->card->getBirthday());
506+
$this->assertEquals('01/02/2000', $this->card->getBirthday('d/m/Y'));
507+
}
508+
509+
public function testBirthdayEmpty()
510+
{
511+
$this->card->setBirthday('');
512+
$this->assertNull($this->card->getBirthday());
513+
}
514+
515+
public function testGender()
516+
{
517+
$this->card->setGender('female');
518+
$this->assertEquals('female', $this->card->getGender());
519+
}
501520
}

0 commit comments

Comments
 (0)