Skip to content

Commit 5501385

Browse files
committed
Merge pull request #83 from anushr/tracks
Support for card present transactions
2 parents dad499d + ac1ad3b commit 5501385

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

src/Omnipay/Common/CreditCard.php

Lines changed: 57 additions & 0 deletions
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
@@ -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: 23 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;
@@ -324,6 +327,26 @@ public function testCvv()
324327
$this->assertEquals('456', $this->card->getCvv());
325328
}
326329

330+
public function testTracks()
331+
{
332+
$this->card->setTracks('%B4242424242424242^SMITH/JOHN ^1520126100000000000000444000000?;4242424242424242=15201269999944401?');
333+
$this->assertSame('%B4242424242424242^SMITH/JOHN ^1520126100000000000000444000000?;4242424242424242=15201269999944401?', $this->card->getTracks());
334+
}
335+
336+
public function testShouldReturnTrack1()
337+
{
338+
$this->card->setTracks('%B4242424242424242^SMITH/JOHN ^1520126100000000000000444000000?;4242424242424242=15201269999944401?');
339+
$actual = $this->card->getTrack1();
340+
$this->assertEquals('%B4242424242424242^SMITH/JOHN ^1520126100000000000000444000000?', $actual);
341+
}
342+
343+
public function testShouldReturnTrack2()
344+
{
345+
$this->card->setTracks('%B4242424242424242^SMITH/JOHN ^1520126100000000000000444000000?;4242424242424242=15201269999944401?');
346+
$actual = $this->card->getTrack2();
347+
$this->assertEquals(';4242424242424242=15201269999944401?', $actual);
348+
}
349+
327350
public function testIssueNumber()
328351
{
329352
$this->card->setIssueNumber('12');

0 commit comments

Comments
 (0)