From b1630efda8f2229fe8190c22b47e0ae0ecd6fe1f Mon Sep 17 00:00:00 2001 From: Adrian Macneil Date: Sun, 8 Dec 2013 18:04:13 +1100 Subject: [PATCH] Add CreditCard birthday and gender fields --- src/Omnipay/Common/CreditCard.php | 30 +++++++++++++++++++++++++ tests/Omnipay/Common/CreditCardTest.php | 19 ++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/Omnipay/Common/CreditCard.php b/src/Omnipay/Common/CreditCard.php index 27e2088f..10b84fd4 100644 --- a/src/Omnipay/Common/CreditCard.php +++ b/src/Omnipay/Common/CreditCard.php @@ -2,6 +2,8 @@ namespace Omnipay\Common; +use DateTime; +use DateTimeZone; use Omnipay\Common\Exception\InvalidCreditCardException; use Symfony\Component\HttpFoundation\ParameterBag; @@ -631,4 +633,32 @@ public function setEmail($value) { return $this->setParameter('email', $value); } + + public function getBirthday($format = 'Y-m-d') + { + $value = $this->getParameter('birthday'); + + return $value ? $value->format($format) : null; + } + + public function setBirthday($value) + { + if ($value) { + $value = new DateTime($value, new DateTimeZone('UTC')); + } else { + $value = null; + } + + return $this->setParameter('birthday', $value); + } + + public function getGender() + { + return $this->getParameter('gender'); + } + + public function setGender($value) + { + return $this->setParameter('gender', $value); + } } diff --git a/tests/Omnipay/Common/CreditCardTest.php b/tests/Omnipay/Common/CreditCardTest.php index 26f6d760..f8e52c19 100644 --- a/tests/Omnipay/Common/CreditCardTest.php +++ b/tests/Omnipay/Common/CreditCardTest.php @@ -498,4 +498,23 @@ public function testEmail() $this->card->setEmail('adrian@example.com'); $this->assertEquals('adrian@example.com', $this->card->getEmail()); } + + public function testBirthday() + { + $this->card->setBirthday('01-02-2000'); + $this->assertEquals('2000-02-01', $this->card->getBirthday()); + $this->assertEquals('01/02/2000', $this->card->getBirthday('d/m/Y')); + } + + public function testBirthdayEmpty() + { + $this->card->setBirthday(''); + $this->assertNull($this->card->getBirthday()); + } + + public function testGender() + { + $this->card->setGender('female'); + $this->assertEquals('female', $this->card->getGender()); + } }