Skip to content

Commit 2b5ad5e

Browse files
committed
Merge branch 'master' of github.com:xola/authorizenet into optional-cvv
* 'master' of github.com:xola/authorizenet: CS-137 Set constants for the profile response codes CS-137 Add tests for verification of duplicate payment profile logic CS-137 Use PHP 5.3 array() syntax so tests pass CS-137 Look for duplicate payment profiles even if you reach maximum profile limit Normally if a duplicate payment profile exists, Authorize.net will return Error code E00039. But if the customer has the maximum number of payment profiles (10), then AUthorize.net will return E00042. So whenever we receive E00042 we need to check the existing payment profile list to see if there is a duplicate profile.
2 parents 35fc3a7 + d9d1156 commit 2b5ad5e

7 files changed

+78
-7
lines changed

src/Message/CIMCreateCardRequest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,17 @@ public function createPaymentProfile(CIMCreateCardResponse $createCardResponse)
205205

206206
$getProfileResponse = $this->makeGetProfileRequest($parameters);
207207

208+
// Check if there is a pre-existing profile for the given card numbers.
209+
// For these codes we should check for duplicate payment profiles
210+
$otherErrorCodes = array(
211+
CIMGetProfileResponse::ERROR_DUPLICATE_PROFILE,
212+
CIMGetProfileResponse::ERROR_MAX_PAYMENT_PROFILE_LIMIT_REACHED
213+
);
208214
if (!$createPaymentProfileResponse->isSuccessful() &&
209-
$createPaymentProfileResponse->getReasonCode() == 'E00039'
215+
in_array($createPaymentProfileResponse->getReasonCode(), $otherErrorCodes)
210216
) {
211-
// Found a duplicate payment profile existing for the same card data. Force update is turned on,
212-
// So find matching payment profile id from the customer profile and update it.
217+
// There is a possibility of a duplicate payment profile, so find matching payment profile id
218+
// from the customer profile and update it.
213219
$card = $this->getCard();
214220
$last4 = substr($card->getNumber(), -4);
215221

src/Message/CIMGetProfileResponse.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
*/
88
class CIMGetProfileResponse extends CIMCreatePaymentProfileResponse
99
{
10+
const ERROR_DUPLICATE_PROFILE = 'E00039';
11+
const ERROR_MAX_PAYMENT_PROFILE_LIMIT_REACHED = 'E00042';
12+
1013
protected $xmlRootElement = 'getCustomerProfileResponse';
1114

1215
/**

tests/CIMGatewayTest.php

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public function setUp()
2323
$this->createCardOptions = array(
2424
'email' => "kaylee@serenity.com",
2525
'card' => $this->getValidCard(),
26-
'testMode' => true
26+
'testMode' => true,
27+
'forceCardUpdate' => true
2728
);
2829

2930
$this->authorizeOptions = array(
@@ -59,6 +60,53 @@ public function testCreateCardSuccess()
5960
$this->assertSame('Successful.', $response->getMessage());
6061
}
6162

63+
public function testShouldCreateCardIfDuplicateCustomerProfileExists()
64+
{
65+
$this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt', 'CIMCreatePaymentProfileSuccess.txt',
66+
'CIMGetProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt'));
67+
68+
$response = $this->gateway->createCard($this->createCardOptions)->send();
69+
70+
$this->assertTrue($response->isSuccessful());
71+
$this->assertSame(
72+
'{"customerProfileId":"28775801","customerPaymentProfileId":"26485433"}',
73+
$response->getCardReference()
74+
);
75+
$this->assertSame('Successful.', $response->getMessage());
76+
}
77+
78+
public function testShouldUpdateExistingPaymentProfileIfDuplicateExistsAndForceCardUpdateIsSet()
79+
{
80+
// Duplicate **payment** profile
81+
$this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt', 'CIMCreatePaymentProfileFailure.txt',
82+
'CIMGetProfileSuccess.txt', 'CIMUpdatePaymentProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt'));
83+
84+
$response = $this->gateway->createCard($this->createCardOptions)->send();
85+
86+
$this->assertTrue($response->isSuccessful());
87+
$this->assertSame(
88+
'{"customerProfileId":"28775801","customerPaymentProfileId":"26485433"}',
89+
$response->getCardReference()
90+
);
91+
$this->assertSame('Successful.', $response->getMessage());
92+
}
93+
94+
public function testShouldUpdateExistingPaymentProfileIfDuplicateExistsAndMaxPaymentProfileLimitIsMet()
95+
{
96+
$this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt',
97+
'CIMCreatePaymentProfileFailureMaxProfileLimit.txt', 'CIMGetProfileSuccess.txt',
98+
'CIMUpdatePaymentProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt'));
99+
100+
$response = $this->gateway->createCard($this->createCardOptions)->send();
101+
102+
$this->assertTrue($response->isSuccessful());
103+
$this->assertSame(
104+
'{"customerProfileId":"28775801","customerPaymentProfileId":"26485433"}',
105+
$response->getCardReference()
106+
);
107+
$this->assertSame('Successful.', $response->getMessage());
108+
}
109+
62110
public function testCreateCardFailure()
63111
{
64112
$this->setMockHttpResponse('CIMCreateCardFailure.txt');

tests/Mock/CIMCreatePaymentProfileFailure.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ Access-Control-Allow-Origin: *
1111
Access-Control-Allow-Methods: GET,POST,OPTIONS
1212
Date: Thu, 18 Sep 2014 03:59:27 GMT
1313

14-
<?xml version="1.0" encoding="utf-8"?><createCustomerPaymentProfileResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"><messages><resultCode>Error</resultCode><message><code>E00039</code><text>A duplicate customer payment profile already exists.</text></message></messages><validationDirectResponse>1,1,1,(TESTMODE) This transaction has been approved.,000000,P,0,none,Test transaction for ValidateCustomerPaymentProfile.,1.00,CC,auth_only,none,,,,,,,12345,,,,email@example.com,,,,,,,,,0.00,0.00,0.00,FALSE,none,9ACE39F249AB996589D58E6FCCCFFFA3,,,,,,,,,,,,,XXXX8888,Visa,,,,,,,,,,,,,,,,</validationDirectResponse></createCustomerPaymentProfileResponse>
14+
<?xml version="1.0" encoding="utf-8"?><createCustomerPaymentProfileResponse><messages><resultCode>Error</resultCode><message><code>E00039</code><text>A duplicate customer payment profile already exists.</text></message></messages><validationDirectResponse>1,1,1,(TESTMODE) This transaction has been approved.,000000,P,0,none,Test transaction for ValidateCustomerPaymentProfile.,1.00,CC,auth_only,none,,,,,,,12345,,,,email@example.com,,,,,,,,,0.00,0.00,0.00,FALSE,none,9ACE39F249AB996589D58E6FCCCFFFA3,,,,,,,,,,,,,XXXX8888,Visa,,,,,,,,,,,,,,,,</validationDirectResponse></createCustomerPaymentProfileResponse>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
HTTP/1.1 200 OK
2+
Cache-Control: private
3+
Content-Length: 746
4+
Content-Type: text/xml;
5+
charset=utf-8
6+
Server: Microsoft-IIS/7.5
7+
X-AspNet-Version: 2.0.50727
8+
X-Powered-By: ASP.NET
9+
Access-Control-Allow-Headers: x-requested-with,cache-control,content-type,origin,method
10+
Access-Control-Allow-Origin: *
11+
Access-Control-Allow-Methods: GET,POST,OPTIONS
12+
Date: Thu, 18 Sep 2014 03:59:27 GMT
13+
14+
<?xml version="1.0" encoding="utf-8"?><createCustomerPaymentProfileResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><messages><resultCode>Error</resultCode><message><code>E00042</code><text>You cannot add more than 10 payment profiles.</text></message></messages><validationDirectResponse>1,1,1,This transaction has been approved.,03305Y,Z,9044060115,none,Test transaction for ValidateCustomerPaymentProfile.,0.00,CC,auth_only,none,John Doe,,,None provided,,,12345,,,,email@example.com,,,,,,,,,0.00,0.00,0.00,FALSE,none,C01815A69AE1AC538B4F16A4C17DD88C,,,,,,,,,,,,,XXXX1111,Visa,,,,,,,,,,,,,,,,</validationDirectResponse></createCustomerPaymentProfileResponse>

tests/Mock/CIMGetProfileSuccess.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ Access-Control-Allow-Origin: *
1111
Access-Control-Allow-Methods: GET,POST,OPTIONS
1212
Date: Thu, 18 Sep 2014 03:59:27 GMT
1313

14-
<?xml version="1.0" encoding="utf-8"?><getCustomerProfileResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><profile><email>kaylee@serenity.com</email><customerProfileId>28775801</customerProfileId><paymentProfiles><billTo><firstName /><lastName /><company /><address /><city /><state /><zip>12345</zip><country /></billTo><customerPaymentProfileId>26455656</customerPaymentProfileId><payment><creditCard><cardNumber>XXXX1111</cardNumber><expirationDate>XXXX</expirationDate></creditCard></payment></paymentProfiles><paymentProfiles><billTo><firstName /><lastName /><company /><address /><city /><state /><zip>12345</zip><country /></billTo><customerPaymentProfileId>26455709</customerPaymentProfileId><payment><creditCard><cardNumber>XXXX8888</cardNumber><expirationDate>XXXX</expirationDate></creditCard></payment></paymentProfiles></profile></getCustomerProfileResponse>
14+
<?xml version="1.0" encoding="utf-8"?><getCustomerProfileResponse><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><profile><email>kaylee@serenity.com</email><customerProfileId>28775801</customerProfileId><paymentProfiles><billTo><firstName /><lastName /><company /><address /><city /><state /><zip>12345</zip><country /></billTo><customerPaymentProfileId>26455656</customerPaymentProfileId><payment><creditCard><cardNumber>XXXX1111</cardNumber><expirationDate>XXXX</expirationDate></creditCard></payment></paymentProfiles><paymentProfiles><billTo><firstName /><lastName /><company /><address /><city /><state /><zip>12345</zip><country /></billTo><customerPaymentProfileId>26455709</customerPaymentProfileId><payment><creditCard><cardNumber>XXXX8888</cardNumber><expirationDate>XXXX</expirationDate></creditCard></payment></paymentProfiles></profile></getCustomerProfileResponse>

tests/Mock/CIMUpdatePaymentProfileSuccess.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ Access-Control-Allow-Origin: *
1111
Access-Control-Allow-Methods: GET,POST,OPTIONS
1212
Date: Thu, 18 Sep 2014 03:59:27 GMT
1313

14-
<?xml version="1.0" encoding="utf-8"?><updateCustomerPaymentProfileResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><validationDirectResponse>1,1,1,(TESTMODE) This transaction has been approved.,000000,P,0,none,Test transaction for ValidateCustomerPaymentProfile.,1.00,CC,auth_only,,,,,,,,12345,,,,kaylee@serenity.com,,,,,,,,,0.00,0.00,0.00,FALSE,none,9ACE39F249AB996589D58E6FCCCFFFA3,,,,,,,,,,,,,XXXX8888,Visa,,,,,,,,,,,,,,,,</validationDirectResponse></updateCustomerPaymentProfileResponse>
14+
<?xml version="1.0" encoding="utf-8"?><updateCustomerPaymentProfileResponse><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><validationDirectResponse>1,1,1,(TESTMODE) This transaction has been approved.,000000,P,0,none,Test transaction for ValidateCustomerPaymentProfile.,1.00,CC,auth_only,,,,,,,,12345,,,,kaylee@serenity.com,,,,,,,,,0.00,0.00,0.00,FALSE,none,9ACE39F249AB996589D58E6FCCCFFFA3,,,,,,,,,,,,,XXXX8888,Visa,,,,,,,,,,,,,,,,</validationDirectResponse></updateCustomerPaymentProfileResponse>

0 commit comments

Comments
 (0)