File tree Expand file tree Collapse file tree 2 files changed +80
-0
lines changed Expand file tree Collapse file tree 2 files changed +80
-0
lines changed Original file line number Diff line number Diff line change 57
57
* * startMonth
58
58
* * startYear
59
59
* * cvv
60
+ * * tracks
60
61
* * issueNumber
61
62
* * billingTitle
62
63
* * billingName
@@ -580,6 +581,62 @@ public function setCvv($value)
580
581
return $ this ->setParameter ('cvv ' , $ value );
581
582
}
582
583
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
+
583
640
/**
584
641
* Get the card issue number.
585
642
*
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 ;
@@ -324,6 +327,26 @@ public function testCvv()
324
327
$ this ->assertEquals ('456 ' , $ this ->card ->getCvv ());
325
328
}
326
329
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
+
327
350
public function testIssueNumber ()
328
351
{
329
352
$ this ->card ->setIssueNumber ('12 ' );
You can’t perform that action at this time.
0 commit comments