|
2 | 2 |
|
3 | 3 | namespace Omnipay\Stripe\Message; |
4 | 4 |
|
| 5 | +use Omnipay\Common\CreditCard; |
5 | 6 | use Omnipay\Common\ItemBag; |
6 | 7 | use Omnipay\Tests\TestCase; |
7 | 8 |
|
@@ -107,6 +108,48 @@ public function testDataWithCard() |
107 | 108 | $this->assertSame($card['number'], $data['source']['number']); |
108 | 109 | } |
109 | 110 |
|
| 111 | + public function testDataWithTracks() |
| 112 | + { |
| 113 | + $cardData = $this->getValidCard(); |
| 114 | + $tracks = "%25B4242424242424242%5ETESTLAST%2FTESTFIRST%5E1505201425400714000000%3F"; |
| 115 | + $cardData['tracks'] = $tracks; |
| 116 | + unset($cardData['cvv']); |
| 117 | + unset($cardData['billingPostcode']); |
| 118 | + $this->request->setCard(new CreditCard($cardData)); |
| 119 | + $data = $this->request->getData(); |
| 120 | + |
| 121 | + $this->assertSame($tracks, $data['source']['swipe_data']); |
| 122 | + $this->assertCount(2, $data['source'], "Swipe data should be present. All other fields are not required"); |
| 123 | + |
| 124 | + // If there is any mismatch between the track data and the parsed data, Stripe rejects the transaction, so it's |
| 125 | + // best to suppress fields that is already present in the track data. |
| 126 | + $this->assertArrayNotHasKey('number', $data, 'Should not send card number for card present charge'); |
| 127 | + $this->assertArrayNotHasKey('exp_month', $data, 'Should not send expiry month for card present charge'); |
| 128 | + $this->assertArrayNotHasKey('exp_year', $data, 'Should not send expiry year for card present charge'); |
| 129 | + $this->assertArrayNotHasKey('name', $data, 'Should not send name for card present charge'); |
| 130 | + |
| 131 | + // Billing address is not accepted for card present transactions. |
| 132 | + $this->assertArrayNotHasKey('address_line1', $data, 'Should not send billing address for card present charge'); |
| 133 | + $this->assertArrayNotHasKey('address_line2', $data, 'Should not send billing address for card present charge'); |
| 134 | + $this->assertArrayNotHasKey('address_city', $data, 'Should not send billing address for card present charge'); |
| 135 | + $this->assertArrayNotHasKey('address_state', $data, 'Should not send billing address for card present charge'); |
| 136 | + |
| 137 | + } |
| 138 | + |
| 139 | + public function testDataWithTracksAndZipCVVManuallyEntered() |
| 140 | + { |
| 141 | + $cardData = $this->getValidCard(); |
| 142 | + $tracks = "%25B4242424242424242%5ETESTLAST%2FTESTFIRST%5E1505201425400714000000%3F"; |
| 143 | + $cardData['tracks'] = $tracks; |
| 144 | + $this->request->setCard(new CreditCard($cardData)); |
| 145 | + $data = $this->request->getData(); |
| 146 | + |
| 147 | + $this->assertSame($tracks, $data['source']['swipe_data']); |
| 148 | + $this->assertSame($cardData['cvv'], $data['source']['cvc']); |
| 149 | + $this->assertSame($cardData['billingPostcode'], $data['source']['address_zip']); |
| 150 | + $this->assertCount(4, $data['source'], "Swipe data, cvv and zip code should be present"); |
| 151 | + } |
| 152 | + |
110 | 153 | public function testSendSuccess() |
111 | 154 | { |
112 | 155 | $this->setMockHttpResponse('PurchaseSuccess.txt'); |
|
0 commit comments