Skip to content

Commit 35fc3a7

Browse files
committed
Do not validate card if no cvv provided
1 parent a0de700 commit 35fc3a7

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

src/Message/CIMCreateCardRequest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ protected function addBillingData(\SimpleXMLElement $data)
105105
$req->creditCard->expirationDate = $card->getExpiryDate('Y-m');
106106
if ($card->getCvv()) {
107107
$req->creditCard->cardCode = $card->getCvv();
108+
} else {
109+
$this->setValidationMode(self::VALIDATION_MODE_NONE);
108110
}
109111
}
110112
}

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)