Skip to content

Commit adfd19b

Browse files
committed
Merge pull request thephpleague#10 from anushr/optional-cvv
XOL-2776 Make CVV optional
2 parents d9d1156 + 2b5ad5e commit adfd19b

File tree

4 files changed

+65
-27
lines changed

4 files changed

+65
-27
lines changed

composer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@
2424
"homepage": "https://github.com/thephpleague/omnipay-authorizenet/contributors"
2525
}
2626
],
27+
"repositories": [
28+
{
29+
"type": "vcs",
30+
"url": "https://github.com/xola/omnipay-common"
31+
}
32+
],
2733
"autoload": {
2834
"psr-4": { "Omnipay\\AuthorizeNet\\" : "src/" }
2935
},
3036
"require": {
31-
"omnipay/common": "~2.0"
37+
"omnipay/common": "~2.4.2"
3238
},
3339
"require-dev": {
3440
"omnipay/tests": "~2.0"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Omnipay\AuthorizeNet\Message;
4+
5+
abstract class CIMAbstractCustomerProfileRequest extends CIMAbstractRequest
6+
{
7+
const VALIDATION_MODE_TEST = 'testMode';
8+
const VALIDATION_MODE_LIVE = 'liveMode';
9+
const VALIDATION_MODE_NONE = 'none';
10+
11+
public function setValidationMode($value)
12+
{
13+
return $this->setParameter('validationMode', $value);
14+
}
15+
16+
public function getValidationMode()
17+
{
18+
$validationMode = $this->getParameter('validationMode');
19+
if ($validationMode !== self::VALIDATION_MODE_NONE) {
20+
$validationMode = $this->getDeveloperMode() ? self::VALIDATION_MODE_TEST : self::VALIDATION_MODE_LIVE;
21+
}
22+
return $validationMode;
23+
}
24+
}

src/Message/CIMCreateCardRequest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* Create Credit Card Request.
99
*/
10-
class CIMCreateCardRequest extends CIMAbstractRequest
10+
class CIMCreateCardRequest extends CIMAbstractCustomerProfileRequest
1111
{
1212
protected $xmlRootElement = 'createCustomerProfileRequest';
1313

@@ -103,7 +103,11 @@ protected function addBillingData(\SimpleXMLElement $data)
103103
$req = $data->addChild('payment');
104104
$req->creditCard->cardNumber = $card->getNumber();
105105
$req->creditCard->expirationDate = $card->getExpiryDate('Y-m');
106-
$req->creditCard->cardCode = $card->getCvv();
106+
if ($card->getCvv()) {
107+
$req->creditCard->cardCode = $card->getCvv();
108+
} else {
109+
$this->setValidationMode(self::VALIDATION_MODE_NONE);
110+
}
107111
}
108112
}
109113

@@ -145,8 +149,7 @@ protected function addShippingData(\SimpleXMLElement $data)
145149

146150
protected function addTestModeSetting(\SimpleXMLElement $data)
147151
{
148-
// Test mode setting
149-
$data->validationMode = $this->getDeveloperMode() ? 'testMode' : 'liveMode';
152+
$data->validationMode = $this->getValidationMode();
150153
}
151154

152155
public function sendData($data)

tests/Message/CIMCreateCardRequestTest.php

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,55 @@ class CIMCreateCardRequestTest extends TestCase
88
{
99
/** @var CIMCreateCardRequest */
1010
protected $request;
11+
private $params;
1112

1213
public function setUp()
1314
{
1415
$this->request = new CIMCreateCardRequest($this->getHttpClient(), $this->getHttpRequest());
15-
$this->request->initialize(
16-
array(
17-
'email' => "kaylee@serenity.com",
18-
'card' => $this->getValidCard(),
19-
'developerMode' => true
20-
)
16+
$this->params = array(
17+
'email' => "kaylee@serenity.com",
18+
'card' => $this->getValidCard(),
19+
'developerMode' => true
2120
);
21+
$this->request->initialize($this->params);
2222
}
2323

2424
public function testGetData()
2525
{
2626
$data = $this->request->getData();
27-
$card = $this->getValidCard();
27+
$card = $this->params['card'];
2828
$this->assertEquals('12345', $data->profile->paymentProfiles->billTo->zip);
2929
$this->assertEquals($card['number'], $data->profile->paymentProfiles->payment->creditCard->cardNumber);
3030
$this->assertEquals('testMode', $data->validationMode);
3131
}
3232

3333
public function testGetDataShouldHaveCustomBillTo()
3434
{
35-
$card = $this->getValidCard();
36-
unset($card['billingAddress1']);
37-
unset($card['billingAddress2']);
38-
unset($card['billingCity']);
39-
$this->request->initialize(
40-
array(
41-
'email' => "kaylee@serenity.com",
42-
'card' => $card,
43-
'developerMode' => true,
44-
'forceCardUpdate' => true,
45-
'defaultBillTo' => array(
46-
'address' => '1234 Test Street',
47-
'city' => 'Blacksburg'
48-
)
49-
)
35+
unset($this->params['card']['billingAddress1']);
36+
unset($this->params['card']['billingAddress2']);
37+
unset($this->params['card']['billingCity']);
38+
$this->params['forceCardUpdate'] = true;
39+
$this->params['defaultBillTo'] = array(
40+
'address' => '1234 Test Street',
41+
'city' => 'Blacksburg'
5042
);
43+
$this->request->initialize($this->params);
5144

5245
$data = $this->request->getData();
46+
5347
$this->assertEquals('12345', $data->profile->paymentProfiles->billTo->zip);
5448
$this->assertEquals('1234 Test Street', $data->profile->paymentProfiles->billTo->address);
5549
$this->assertEquals('Blacksburg', $data->profile->paymentProfiles->billTo->city);
5650
}
51+
52+
public function testGetDataShouldSetValidationModeToNoneIfNoCvvProvided()
53+
{
54+
unset($this->params['card']['cvv']);
55+
$this->request->initialize($this->params);
56+
57+
$data = $this->request->getData();
58+
59+
$this->assertFalse(isset($data->profile->paymentProfiles->payment->creditCard->cardCode));
60+
$this->assertEquals(CIMCreatePaymentProfileRequest::VALIDATION_MODE_NONE, $this->request->getValidationMode());
61+
}
5762
}

0 commit comments

Comments
 (0)