File tree Expand file tree Collapse file tree 2 files changed +53
-2
lines changed Expand file tree Collapse file tree 2 files changed +53
-2
lines changed Original file line number Diff line number Diff line change @@ -555,6 +555,40 @@ public function getTracks()
555
555
return $ this ->getParameter ('tracks ' );
556
556
}
557
557
558
+ /**
559
+ * Get raw data for track 1 on the credit card magnetic strip.
560
+ *
561
+ * @return string
562
+ */
563
+ public function getTrack1 ()
564
+ {
565
+ $ track1 = null ;
566
+ if ($ tracks = $ this ->getTracks ()) {
567
+ $ pattern = '/\%B\d{1,19}\^.{2,26}\^\d{4}\d*\?/ ' ;
568
+ if (preg_match ($ pattern , $ tracks , $ matches ) === 1 ) {
569
+ $ track1 = $ matches [0 ];
570
+ }
571
+ }
572
+ return $ track1 ;
573
+ }
574
+
575
+ /**
576
+ * Get raw data for track 2 on the credit card magnetic strip.
577
+ *
578
+ * @return string
579
+ */
580
+ public function getTrack2 ()
581
+ {
582
+ $ track2 = null ;
583
+ if ($ tracks = $ this ->getTracks ()) {
584
+ $ pattern = '/;\d{1,19}=\d{4}\d*\?/ ' ;
585
+ if (preg_match ($ pattern , $ tracks , $ matches ) === 1 ) {
586
+ $ track2 = $ matches [0 ];
587
+ }
588
+ }
589
+ return $ track2 ;
590
+ }
591
+
558
592
/**
559
593
* Sets raw data from all tracks on the credit card magnetic strip. Used by gateways that support card-present
560
594
* transactions.
Original file line number Diff line number Diff line change 6
6
7
7
class CreditCardTest extends TestCase
8
8
{
9
+ /** @var CreditCard */
10
+ private $ card ;
11
+
9
12
public function setUp ()
10
13
{
11
14
$ this ->card = new CreditCard ;
@@ -311,8 +314,22 @@ public function testCvv()
311
314
312
315
public function testTracks ()
313
316
{
314
- $ this ->card ->setTracks ('%25B4242424242424242%5ETESTLAST%2FTESTFIRST%5E1505201425400714000000%3F%3B4242424242424242%3D150520142547140130%3F ' );
315
- $ this ->assertSame ('%25B4242424242424242%5ETESTLAST%2FTESTFIRST%5E1505201425400714000000%3F%3B4242424242424242%3D150520142547140130%3F ' , $ this ->card ->getTracks ());
317
+ $ this ->card ->setTracks ('%B4242424242424242^SMITH/JOHN ^1520126100000000000000444000000?;4242424242424242=15201269999944401? ' );
318
+ $ this ->assertSame ('%B4242424242424242^SMITH/JOHN ^1520126100000000000000444000000?;4242424242424242=15201269999944401? ' , $ this ->card ->getTracks ());
319
+ }
320
+
321
+ public function testShouldReturnTrack1 ()
322
+ {
323
+ $ this ->card ->setTracks ('%B4242424242424242^SMITH/JOHN ^1520126100000000000000444000000?;4242424242424242=15201269999944401? ' );
324
+ $ actual = $ this ->card ->getTrack1 ();
325
+ $ this ->assertEquals ('%B4242424242424242^SMITH/JOHN ^1520126100000000000000444000000? ' , $ actual );
326
+ }
327
+
328
+ public function testShouldReturnTrack2 ()
329
+ {
330
+ $ this ->card ->setTracks ('%B4242424242424242^SMITH/JOHN ^1520126100000000000000444000000?;4242424242424242=15201269999944401? ' );
331
+ $ actual = $ this ->card ->getTrack2 ();
332
+ $ this ->assertEquals (';4242424242424242=15201269999944401? ' , $ actual );
316
333
}
317
334
318
335
public function testIssueNumber ()
You can’t perform that action at this time.
0 commit comments