Skip to content

Commit e20e9f0

Browse files
committed
2 parents 2e6194d + 56c1d49 commit e20e9f0

File tree

4 files changed

+97
-1
lines changed

4 files changed

+97
-1
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"gateways": [
4242
"AuthorizeNet_AIM",
4343
"AuthorizeNet_SIM",
44+
"Buckaroo_CreditCard",
4445
"Buckaroo_Ideal",
4546
"Buckaroo_PayPal",
4647
"CardSave",

src/Omnipay/Common/CreditCard.php

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
* * startMonth
5858
* * startYear
5959
* * cvv
60+
* * tracks
6061
* * issueNumber
6162
* * billingTitle
6263
* * billingName
@@ -118,7 +119,7 @@ class CreditCard
118119
*/
119120
protected $supported_cards = array(
120121
self::BRAND_VISA => '/^4\d{12}(\d{3})?$/',
121-
self::BRAND_MASTERCARD => '/^(5[1-5]\d{4}|677189)\d{10}$/',
122+
self::BRAND_MASTERCARD => '/^(5[1-5]\d{4}|677189)\d{10}$|^(222[1-9]|2[3-6]\d{2}|27[0-1]\d|2720)\d{12}$/',
122123
self::BRAND_DISCOVER => '/^(6011|65\d{2}|64[4-9]\d)\d{12}|(62\d{14})$/',
123124
self::BRAND_AMEX => '/^3[47]\d{13}$/',
124125
self::BRAND_DINERS_CLUB => '/^3(0[0-5]|[68]\d)\d{11}$/',
@@ -580,6 +581,62 @@ public function setCvv($value)
580581
return $this->setParameter('cvv', $value);
581582
}
582583

584+
/**
585+
* Get raw data for all tracks on the credit card magnetic strip.
586+
*
587+
* @return string
588+
*/
589+
public function getTracks()
590+
{
591+
return $this->getParameter('tracks');
592+
}
593+
594+
/**
595+
* Get raw data for track 1 on the credit card magnetic strip.
596+
*
597+
* @return string
598+
*/
599+
public function getTrack1()
600+
{
601+
$track1 = null;
602+
if ($tracks = $this->getTracks()) {
603+
$pattern = '/\%B\d{1,19}\^.{2,26}\^\d{4}\d*\?/';
604+
if (preg_match($pattern, $tracks, $matches) === 1) {
605+
$track1 = $matches[0];
606+
}
607+
}
608+
return $track1;
609+
}
610+
611+
/**
612+
* Get raw data for track 2 on the credit card magnetic strip.
613+
*
614+
* @return string
615+
*/
616+
public function getTrack2()
617+
{
618+
$track2 = null;
619+
if ($tracks = $this->getTracks()) {
620+
$pattern = '/;\d{1,19}=\d{4}\d*\?/';
621+
if (preg_match($pattern, $tracks, $matches) === 1) {
622+
$track2 = $matches[0];
623+
}
624+
}
625+
return $track2;
626+
}
627+
628+
/**
629+
* Sets raw data from all tracks on the credit card magnetic strip. Used by gateways that support card-present
630+
* transactions.
631+
*
632+
* @param $value
633+
* @return CreditCard
634+
*/
635+
public function setTracks($value)
636+
{
637+
return $this->setParameter('tracks', $value);
638+
}
639+
583640
/**
584641
* Get the card issue number.
585642
*

tests/Omnipay/Common/CreditCardTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
class CreditCardTest extends TestCase
88
{
9+
/** @var CreditCard */
10+
private $card;
11+
912
public function setUp()
1013
{
1114
$this->card = new CreditCard;
@@ -124,6 +127,13 @@ public function testCustomBrandWorks()
124127
$this->assertEquals('omniexpress', $this->card->getBrand());
125128
}
126129

130+
public function testCustomBrandAddedTwiceReturnsFalse()
131+
{
132+
$this->assertTrue($this->card->addSupportedBrand('omniexpress', '/^9\d{12}(\d{3})?$/'));
133+
$this->assertArrayHasKey('omniexpress', $this->card->getSupportedBrands());
134+
$this->assertFalse($this->card->addSupportedBrand('omniexpress', '/^9\d{12}(\d{3})?$/'));
135+
}
136+
127137
public function testTitle()
128138
{
129139
$this->card->setTitle('Mr.');
@@ -230,6 +240,8 @@ public function testGetBrandMasterCard()
230240
{
231241
$card = new CreditCard(array('number' => '5555555555554444'));
232242
$this->assertSame(CreditCard::BRAND_MASTERCARD, $card->getBrand());
243+
$card = new CreditCard(array('number' => '2221000010000015'));
244+
$this->assertSame(CreditCard::BRAND_MASTERCARD, $card->getBrand());
233245
}
234246

235247
public function testGetBrandAmex()
@@ -324,6 +336,26 @@ public function testCvv()
324336
$this->assertEquals('456', $this->card->getCvv());
325337
}
326338

339+
public function testTracks()
340+
{
341+
$this->card->setTracks('%B4242424242424242^SMITH/JOHN ^1520126100000000000000444000000?;4242424242424242=15201269999944401?');
342+
$this->assertSame('%B4242424242424242^SMITH/JOHN ^1520126100000000000000444000000?;4242424242424242=15201269999944401?', $this->card->getTracks());
343+
}
344+
345+
public function testShouldReturnTrack1()
346+
{
347+
$this->card->setTracks('%B4242424242424242^SMITH/JOHN ^1520126100000000000000444000000?;4242424242424242=15201269999944401?');
348+
$actual = $this->card->getTrack1();
349+
$this->assertEquals('%B4242424242424242^SMITH/JOHN ^1520126100000000000000444000000?', $actual);
350+
}
351+
352+
public function testShouldReturnTrack2()
353+
{
354+
$this->card->setTracks('%B4242424242424242^SMITH/JOHN ^1520126100000000000000444000000?;4242424242424242=15201269999944401?');
355+
$actual = $this->card->getTrack2();
356+
$this->assertEquals(';4242424242424242=15201269999944401?', $actual);
357+
}
358+
327359
public function testIssueNumber()
328360
{
329361
$this->card->setIssueNumber('12');

tests/Omnipay/Common/Message/AbstractResponseTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ public function testGetRedirectResponseInvalidMethod()
9090

9191
$this->response->getRedirectResponse();
9292
}
93+
94+
public function testGetTransactionIdNull()
95+
{
96+
$this->response = m::mock('\Omnipay\Common\Message\AbstractResponseTest_MockRedirectResponse')->makePartial();
97+
$this->assertNull($this->response->getTransactionId());
98+
}
9399
}
94100

95101
class AbstractResponseTest_MockRedirectResponse extends AbstractResponse implements RedirectResponseInterface

0 commit comments

Comments
 (0)