Skip to content

Commit

Permalink
Merge pull request #10 from anushr/optional-cvv
Browse files Browse the repository at this point in the history
XOL-2776 Make CVV optional
  • Loading branch information
rushi committed Mar 3, 2016
2 parents d9d1156 + 2b5ad5e commit adfd19b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 27 deletions.
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@
"homepage": "https://github.com/thephpleague/omnipay-authorizenet/contributors"
}
],
"repositories": [
{
"type": "vcs",
"url": "https://github.com/xola/omnipay-common"
}
],
"autoload": {
"psr-4": { "Omnipay\\AuthorizeNet\\" : "src/" }
},
"require": {
"omnipay/common": "~2.0"
"omnipay/common": "~2.4.2"
},
"require-dev": {
"omnipay/tests": "~2.0"
Expand Down
24 changes: 24 additions & 0 deletions src/Message/CIMAbstractCustomerProfileRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Omnipay\AuthorizeNet\Message;

abstract class CIMAbstractCustomerProfileRequest extends CIMAbstractRequest
{
const VALIDATION_MODE_TEST = 'testMode';
const VALIDATION_MODE_LIVE = 'liveMode';
const VALIDATION_MODE_NONE = 'none';

public function setValidationMode($value)
{
return $this->setParameter('validationMode', $value);
}

public function getValidationMode()
{
$validationMode = $this->getParameter('validationMode');
if ($validationMode !== self::VALIDATION_MODE_NONE) {
$validationMode = $this->getDeveloperMode() ? self::VALIDATION_MODE_TEST : self::VALIDATION_MODE_LIVE;
}
return $validationMode;
}
}
11 changes: 7 additions & 4 deletions src/Message/CIMCreateCardRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Create Credit Card Request.
*/
class CIMCreateCardRequest extends CIMAbstractRequest
class CIMCreateCardRequest extends CIMAbstractCustomerProfileRequest
{
protected $xmlRootElement = 'createCustomerProfileRequest';

Expand Down Expand Up @@ -103,7 +103,11 @@ protected function addBillingData(\SimpleXMLElement $data)
$req = $data->addChild('payment');
$req->creditCard->cardNumber = $card->getNumber();
$req->creditCard->expirationDate = $card->getExpiryDate('Y-m');
$req->creditCard->cardCode = $card->getCvv();
if ($card->getCvv()) {
$req->creditCard->cardCode = $card->getCvv();
} else {
$this->setValidationMode(self::VALIDATION_MODE_NONE);
}
}
}

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

protected function addTestModeSetting(\SimpleXMLElement $data)
{
// Test mode setting
$data->validationMode = $this->getDeveloperMode() ? 'testMode' : 'liveMode';
$data->validationMode = $this->getValidationMode();
}

public function sendData($data)
Expand Down
49 changes: 27 additions & 22 deletions tests/Message/CIMCreateCardRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,55 @@ class CIMCreateCardRequestTest extends TestCase
{
/** @var CIMCreateCardRequest */
protected $request;
private $params;

public function setUp()
{
$this->request = new CIMCreateCardRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'email' => "[email protected]",
'card' => $this->getValidCard(),
'developerMode' => true
)
$this->params = array(
'email' => "[email protected]",
'card' => $this->getValidCard(),
'developerMode' => true
);
$this->request->initialize($this->params);
}

public function testGetData()
{
$data = $this->request->getData();
$card = $this->getValidCard();
$card = $this->params['card'];
$this->assertEquals('12345', $data->profile->paymentProfiles->billTo->zip);
$this->assertEquals($card['number'], $data->profile->paymentProfiles->payment->creditCard->cardNumber);
$this->assertEquals('testMode', $data->validationMode);
}

public function testGetDataShouldHaveCustomBillTo()
{
$card = $this->getValidCard();
unset($card['billingAddress1']);
unset($card['billingAddress2']);
unset($card['billingCity']);
$this->request->initialize(
array(
'email' => "[email protected]",
'card' => $card,
'developerMode' => true,
'forceCardUpdate' => true,
'defaultBillTo' => array(
'address' => '1234 Test Street',
'city' => 'Blacksburg'
)
)
unset($this->params['card']['billingAddress1']);
unset($this->params['card']['billingAddress2']);
unset($this->params['card']['billingCity']);
$this->params['forceCardUpdate'] = true;
$this->params['defaultBillTo'] = array(
'address' => '1234 Test Street',
'city' => 'Blacksburg'
);
$this->request->initialize($this->params);

$data = $this->request->getData();

$this->assertEquals('12345', $data->profile->paymentProfiles->billTo->zip);
$this->assertEquals('1234 Test Street', $data->profile->paymentProfiles->billTo->address);
$this->assertEquals('Blacksburg', $data->profile->paymentProfiles->billTo->city);
}

public function testGetDataShouldSetValidationModeToNoneIfNoCvvProvided()
{
unset($this->params['card']['cvv']);
$this->request->initialize($this->params);

$data = $this->request->getData();

$this->assertFalse(isset($data->profile->paymentProfiles->payment->creditCard->cardCode));
$this->assertEquals(CIMCreatePaymentProfileRequest::VALIDATION_MODE_NONE, $this->request->getValidationMode());
}
}

0 comments on commit adfd19b

Please sign in to comment.