Skip to content

Commit

Permalink
move result codes from the response object to the configs so that the…
Browse files Browse the repository at this point in the history
…y can be translated if necessary
  • Loading branch information
Brian Anderson committed Nov 5, 2015
1 parent 86d29f8 commit e65e23d
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 58 deletions.
19 changes: 19 additions & 0 deletions src/Credibility/LaravelCybersource/Configs/ServerConfigs.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class ServerConfigs {
protected $password;
/* @var array */
protected $reports;
/* @var array */
protected $resultCodes;

/**
* Optionally build the configs object with array of configs
Expand Down Expand Up @@ -51,6 +53,7 @@ public function setConfigs(array $configs = [])
$this->setUsername(isset($configs['username']) ? $configs['username'] : null);
$this->setPassword(isset($configs['password']) ? $configs['password'] : null);
$this->setReports(isset($configs['reports']) ? $configs['reports'] : null);
$this->setResultCodes(isset($configs['result_codes']) ? $configs['result_codes'] : null);
}

/**
Expand Down Expand Up @@ -260,4 +263,20 @@ public function setReports($reports)
{
$this->reports = $reports;
}

/**
* @return array
*/
public function getResultCodes()
{
return $this->resultCodes;
}

/**
* @param array $resultCodes
*/
public function setResultCodes($resultCodes)
{
$this->resultCodes = $resultCodes;
}
}
2 changes: 1 addition & 1 deletion src/Credibility/LaravelCybersource/Cybersource.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public function createNewRequest($merchantReferenceNumber = null)
public function sendRequest($request)
{
$rawResponse = $this->requester->send($request);
$csResponse = new CybersourceResponse($rawResponse);
$csResponse = new CybersourceResponse($rawResponse, $this->configs->getResultCodes());
$csResponse->setRequest($request);

return $csResponse;
Expand Down
50 changes: 6 additions & 44 deletions src/Credibility/LaravelCybersource/models/CybersourceResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,24 @@ class CybersourceResponse {

private $request;

private $resultCodes = array(
'100' => 'Successful transaction.',
'101' => 'The request is missing one or more required fields.',
'102' => 'One or more fields in the request contains invalid data.',
'104' => 'The access key and transaction uuid fields for this authorization request matches the access_key and transaction_uuid of another authorization request that you sent within the past 15 minutes.',
'110' => 'Only a partial amount was approved.',
'150' => 'Error: General system failure.',
'151' => 'Error: The request was received but there was a server timeout.',
'152' => 'Error: The request was received, but a service did not finish running in time.',
'200' => 'The authorization request was approved by the issuing bank but declined by CyberSource because it did not pass the Address Verification Service (AVS) check.',
'201' => 'The issuing bank has questions about the request.',
'202' => 'Expired card.',
'203' => 'General decline of the card.',
'204' => 'Insufficient funds in the account.',
'205' => 'Stolen or lost card.',
'207' => 'Issuing bank unavailable.',
'208' => 'Inactive card or card not authorized for card-not-present transactions.',
'209' => 'American Express Card Identification Digits (CID) did not match.',
'210' => 'The card has reached the credit limit.',
'211' => 'Invalid CVN.',
'221' => 'The customer matched an entry on the processor\'s negative file.',
'222' => 'Account frozen.',
'230' => 'The authorization request was approved by the issuing bank but declined by CyberSource because it did not pass the CVN check.',
'231' => 'Invalid credit card number.',
'232' => 'The card type is not accepted by the payment processor.',
'233' => 'General decline by the processor.',
'234' => 'There is a problem with your CyberSource merchant configuration.',
'235' => 'The requested amount exceeds the originally authorized amount.',
'236' => 'Processor failure.',
'237' => 'The authorization has already been reversed.',
'238' => 'The authorization has already been captured.',
'239' => 'The requested transaction amount must match the previous transaction amount.',
'240' => 'The card type sent is invalid or does not correlate with the credit card number.',
'241' => 'The request ID is invalid.',
'242' => 'You requested a capture, but there is no corresponding, unused authorization record.',
'243' => 'The transaction has already been settled or reversed.',
'246' => 'The capture or credit is not voidable because the capture or credit information has laready been submitted to your processor. Or, you requested a void for a type of transaction that cannot be voided.',
'247' => 'You requested a credit for a capture that was previously voided.',
'250' => 'Error: The request was received, but there was a timeout at the payment processor.',
'475' => 'The cardholder is enrolled for payer authentication.',
'476' => 'Payer authentication could not be authenticated.',
'520' => 'The authorization request was approved by the issuing bank but declined by CyberSource based on your Smart Authorization settings.',
);
/** @var array */
private $resultCodes;

/**
* Response object constructor method
*
* @param $response Array|CybersourceSoapModel [required]
* @param $resultCodes Array [required]
* @throws \Credibility\LaravelCybersource\Exceptions\CybersourceException
*/
public function __construct($response)
public function __construct($response, $resultCodes)
{
if ($response instanceof CybersourceSOAPModel) {
$response = $response->toArray();
}

$this->resultCodes = $resultCodes;

$this->reasonCode = $this->getReasonCode($response);

if(is_null($this->reasonCode)) {
Expand Down
47 changes: 47 additions & 0 deletions src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,53 @@
'username' => '',
'password' => '',

/**
* Translated result codes to be returned
* as part of the CybersourceResponse
*/
'result_codes' => [
'100' => 'Successful transaction.',
'101' => 'The request is missing one or more required fields.',
'102' => 'One or more fields in the request contains invalid data.',
'104' => 'The access key and transaction uuid fields for this authorization request matches the access_key and transaction_uuid of another authorization request that you sent within the past 15 minutes.',
'110' => 'Only a partial amount was approved.',
'150' => 'Error: General system failure.',
'151' => 'Error: The request was received but there was a server timeout.',
'152' => 'Error: The request was received, but a service did not finish running in time.',
'200' => 'The authorization request was approved by the issuing bank but declined by CyberSource because it did not pass the Address Verification Service (AVS) check.',
'201' => 'The issuing bank has questions about the request.',
'202' => 'Expired card.',
'203' => 'General decline of the card.',
'204' => 'Insufficient funds in the account.',
'205' => 'Stolen or lost card.',
'207' => 'Issuing bank unavailable.',
'208' => 'Inactive card or card not authorized for card-not-present transactions.',
'209' => 'American Express Card Identification Digits (CID) did not match.',
'210' => 'The card has reached the credit limit.',
'211' => 'Invalid CVN.',
'221' => 'The customer matched an entry on the processor\'s negative file.',
'222' => 'Account frozen.',
'230' => 'The authorization request was approved by the issuing bank but declined by CyberSource because it did not pass the CVN check.',
'231' => 'Invalid credit card number.',
'232' => 'The card type is not accepted by the payment processor.',
'233' => 'General decline by the processor.',
'234' => 'There is a problem with your CyberSource merchant configuration.',
'235' => 'The requested amount exceeds the originally authorized amount.',
'236' => 'Processor failure.',
'237' => 'The authorization has already been reversed.',
'238' => 'The authorization has already been captured.',
'239' => 'The requested transaction amount must match the previous transaction amount.',
'240' => 'The card type sent is invalid or does not correlate with the credit card number.',
'241' => 'The request ID is invalid.',
'242' => 'You requested a capture, but there is no corresponding, unused authorization record.',
'243' => 'The transaction has already been settled or reversed.',
'246' => 'The capture or credit is not voidable because the capture or credit information has laready been submitted to your processor. Or, you requested a void for a type of transaction that cannot be voided.',
'247' => 'You requested a credit for a capture that was previously voided.',
'250' => 'Error: The request was received, but there was a timeout at the payment processor.',
'475' => 'The cardholder is enrolled for payer authentication.',
'476' => 'Payer authentication could not be authenticated.',
'520' => 'The authorization request was approved by the issuing bank but declined by CyberSource based on your Smart Authorization settings.',
],

);

23 changes: 10 additions & 13 deletions tests/CybersourceResponseTest.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<?php namespace LaravelCybersource;

use Credibility\LaravelCybersource\Cybersource;
use Credibility\LaravelCybersource\Exceptions\CybersourceException as CybersourceException;
use Credibility\LaravelCybersource\models\CybersourceResponse;
use Credibility\LaravelCybersource\models\CybersourceSOAPModel;
use LaravelCybersource\TestCase;
use \Mockery as m;

class CybersourceResponseTest extends TestCase {

public function testResponseDoesNotBreak()
{
$model = $this->createModel(101, 'REJECT');
$responseObj = new CybersourceResponse($model);
$responseObj = new CybersourceResponse($model, $this->configs->getResultCodes());

$this->assertFalse($responseObj->isValid());
$this->assertNotEmpty($responseObj->getDetails());
Expand All @@ -21,7 +18,7 @@ public function testResponseDoesNotBreak()
public function testConstructionSetsValidity()
{
$model = $this->createModel(100, 'ACCEPT');
$responseObj = new CybersourceResponse($model);
$responseObj = new CybersourceResponse($model, $this->configs->getResultCodes());

$this->assertTrue($responseObj->isValid());
}
Expand All @@ -31,7 +28,7 @@ public function testConstructionAcceptsArray()
$model = $this->createModel(100, 'ACCEPT');
$array = $model->toArray();

$responseObj = new CybersourceResponse($array);
$responseObj = new CybersourceResponse($array, $this->configs->getResultCodes());

$this->assertTrue($responseObj->isValid());
}
Expand All @@ -40,26 +37,26 @@ public function testEmptyCodeThrowsError()
{
$this->setExpectedException('Credibility\LaravelCybersource\Exceptions\CybersourceException', 'Response Code Not Provided');
$model = $this->createModel(null, null);
$responseObj = new CybersourceResponse($model);
$responseObj = new CybersourceResponse($model, $this->configs->getResultCodes());
}

public function testEmptyDecisionThrowsError()
{
$this->setExpectedException('Credibility\LaravelCybersource\Exceptions\CybersourceException', 'Decision Not Provided');
$model = $this->createModel(100, null);
$responseObj = new CybersourceResponse($model);
$responseObj = new CybersourceResponse($model, $this->configs->getResultCodes());
}

public function testInvalidCodeThrowsError()
{
$this->setExpectedException('Credibility\LaravelCybersource\Exceptions\CybersourceException', 'Invalid Response Code Provided');
$model = $this->createModel(0, 'ACCEPT');
$responseObj = new CybersourceResponse($model);
$responseObj = new CybersourceResponse($model, $this->configs->getResultCodes());
}

public function testErrorIsSet() {
$model = $this->createModel(102, 'REJECT');
$responseObj = new CybersourceResponse($model);
$responseObj = new CybersourceResponse($model, $this->configs->getResultCodes());

$error = $responseObj->error();

Expand All @@ -68,7 +65,7 @@ public function testErrorIsSet() {

public function testErrorIsNotSet() {
$model = $this->createModel(100, 'ACCEPT');
$responseObj = new CybersourceResponse($model);
$responseObj = new CybersourceResponse($model, $this->configs->getResultCodes());

$this->assertFalse($responseObj->error());
}
Expand All @@ -78,7 +75,7 @@ public function testSetRequestWithArray()
$array = array('value' => 'test', 'other-value' => 'other-test');
$model = $this->createModel(100, 'ACCEPT');

$responseObj = new CybersourceResponse($model);
$responseObj = new CybersourceResponse($model, $this->configs->getResultCodes());
$responseObj->setRequest($array);

$returnedArray = $responseObj->getRequestData();
Expand All @@ -95,7 +92,7 @@ public function testSetRequestWithSOAPModel()
);

$model = $this->createModel('100', 'ACCEPT');
$responseObj = new CybersourceResponse($model);
$responseObj = new CybersourceResponse($model, $this->configs->getResultCodes());
$responseObj->setRequest($requestObj);
$requestArray = $responseObj->getRequestData();

Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

use \Mockery as m;
use Credibility\LaravelCybersource\Configs\Factory as ConfigsFactory;
use Credibility\LaravelCybersource\Configs\ServerConfigs;

class TestCase extends \PHPUnit_Framework_TestCase {

protected $environment = 'testing';
protected $merchantId = 'test-merchant-id';
protected $merchantRefCode = 'test-merchant-code';
/** @var ServerConfigs */
protected $configs;

public function setUp()
Expand Down

0 comments on commit e65e23d

Please sign in to comment.