Skip to content

Commit d1e7f10

Browse files
committed
CS-137 Add tests for verification of duplicate payment profile logic
1 parent 4d5c93a commit d1e7f10

File tree

5 files changed

+66
-4
lines changed

5 files changed

+66
-4
lines changed

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)