Skip to content

Commit 7e11d77

Browse files
committed
For PR thephpleague#36 - validate card number only if card not present.
1 parent 3137918 commit 7e11d77

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

src/AIMGateway.php

+17-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@
1414
*/
1515
class AIMGateway extends AbstractGateway
1616
{
17+
/**
18+
* The device type collecting credit card data.
19+
*/
20+
const DEVICE_TYPE_UNKNOWN = 1;
21+
const DEVICE_TYPE_UNATTENDED_TERMINAL = 2;
22+
const DEVICE_TYPE_SELF_SERVICE_TERMINAL = 3;
23+
const DEVICE_TYPE_ELECTRONIC_CASH_REGISTER = 4;
24+
const DEVICE_TYPE_PC_TERMINAL = 5;
25+
const DEVICE_TYPE_AIRPAY = 6;
26+
const DEVICE_TYPE_WIRELESS_POS = 7;
27+
const DEVICE_TYPE_WEBSITE = 8;
28+
const DEVICE_TYPE_DIAL_TERMINAL = 9;
29+
const DEVICE_TYPE_VIRTUAL_TERMINAL = 10;
30+
1731
public function getName()
1832
{
1933
return 'Authorize.Net AIM';
@@ -29,7 +43,7 @@ public function getDefaultParameters()
2943
'hashSecret' => '',
3044
'liveEndpoint' => 'https://api2.authorize.net/xml/v1/request.api',
3145
'developerEndpoint' => 'https://apitest.authorize.net/xml/v1/request.api',
32-
'deviceType' => 1 // Device used to make the transaction. Required for card present. "1" = Unknown.
46+
'deviceType' => static::DEVICE_TYPE_UNKNOWN
3347
);
3448
}
3549

@@ -115,8 +129,8 @@ public function getDeviceType()
115129
}
116130

117131
/**
118-
* Sets the type of device used to collect the credit card data. A device type is required for card present
119-
* transactions.
132+
* Sets the type of device used to collect the credit card data.
133+
* A device type is required for card present transactions.
120134
*
121135
* 1 = Unknown
122136
* 2 = Unattended Terminal

src/Message/AIMAuthorizeRequest.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ protected function addPayment(\SimpleXMLElement $data)
3737
return;
3838
}
3939

40+
// The CreditCard object must be present.
4041
$this->validate('card');
42+
4143
/** @var CreditCard $card */
4244
$card = $this->getCard();
43-
$card->validate();
45+
4446
if ($card->getTracks()) {
4547
// Card present
4648
if ($track1 = $card->getTrack1()) {
@@ -49,7 +51,11 @@ protected function addPayment(\SimpleXMLElement $data)
4951
$data->transactionRequest->payment->trackData->track2 = $track2;
5052
}
5153
} else {
52-
// Card not present
54+
// Card not present.
55+
56+
// Validate sufficient card details have been supplied.
57+
$card->validate();
58+
5359
$data->transactionRequest->payment->creditCard->cardNumber = $card->getNumber();
5460
$data->transactionRequest->payment->creditCard->expirationDate = $card->getExpiryDate('my');
5561
$data->transactionRequest->payment->creditCard->cardCode = $card->getCvv();

tests/Message/AIMAuthorizeRequestTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ public function testGetDataCardPresentTrack1()
9696
{
9797
$card = $this->getValidCard();
9898
$card['tracks'] = '%B4242424242424242^SMITH/JOHN ^2511126100000000000000444000000?;4242424242424242=25111269999944401?';
99+
100+
// If sending tracks, then the card number and expiry date are not required.
101+
unset($card['number']);
102+
unset($card['expiryMonth']);
103+
unset($card['expiryYear']);
104+
unset($card['cvv']);
105+
99106
$this->request->initialize(array(
100107
'amount' => '12.12',
101108
'card' => $card,

0 commit comments

Comments
 (0)