Skip to content

Commit

Permalink
Add CreditCard birthday and gender fields
Browse files Browse the repository at this point in the history
  • Loading branch information
amacneil committed Dec 8, 2013
1 parent 02ba9e5 commit b1630ef
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/Omnipay/Common/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Omnipay\Common;

use DateTime;
use DateTimeZone;
use Omnipay\Common\Exception\InvalidCreditCardException;
use Symfony\Component\HttpFoundation\ParameterBag;

Expand Down Expand Up @@ -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);
}
}
19 changes: 19 additions & 0 deletions tests/Omnipay/Common/CreditCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,4 +498,23 @@ public function testEmail()
$this->card->setEmail('[email protected]');
$this->assertEquals('[email protected]', $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());
}
}

0 comments on commit b1630ef

Please sign in to comment.