Skip to content

Commit 1c2c341

Browse files
authored
Merge pull request #130 from anush/xml_array
Handle XML to JSON array conversion issue when a single payment profile is present
2 parents 1fe6f4e + 9145e44 commit 1c2c341

File tree

5 files changed

+34
-8
lines changed

5 files changed

+34
-8
lines changed

src/Message/CIMGetProfileResponse.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public function getMatchingPaymentProfileId($last4)
2626
return null;
2727
}
2828

29+
// Handle quirkiness with XML -> JSON conversion
30+
if (!array_key_exists(0, $this->data['profile']['paymentProfiles'])) {
31+
$this->data['profile']['paymentProfiles'] = [$this->data['profile']['paymentProfiles']];
32+
}
33+
2934
foreach ($this->data['profile']['paymentProfiles'] as $paymentProfile) {
3035
// For every payment profile check if the last4 matches the last4 of the card in request.
3136
$cardLast4 = substr($paymentProfile['payment']['creditCard']['cardNumber'], -4);

tests/CIMGatewayTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function testCreateCardFromOpaqueDataSuccess()
118118
public function testShouldCreateCardIfDuplicateCustomerProfileExists()
119119
{
120120
$this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt', 'CIMCreatePaymentProfileSuccess.txt',
121-
'CIMGetProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt'));
121+
'CIMGetMultipleProfilesSuccess.txt', 'CIMGetPaymentProfileSuccess.txt'));
122122

123123
$response = $this->gateway->createCard($this->createCardOptions)->send();
124124

@@ -133,7 +133,7 @@ public function testShouldCreateCardIfDuplicateCustomerProfileExists()
133133
public function testShouldCreateCardFromOpaqueDataIfDuplicateCustomerProfileExists()
134134
{
135135
$this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt', 'CIMCreatePaymentProfileSuccess.txt',
136-
'CIMGetProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt'));
136+
'CIMGetMultipleProfilesSuccess.txt', 'CIMGetPaymentProfileSuccess.txt'));
137137

138138
$response = $this->gateway->createCard($this->createCardFromOpaqueDataOptions)->send();
139139

@@ -149,7 +149,7 @@ public function testShouldUpdateExistingPaymentProfileIfDuplicateExistsAndForceC
149149
{
150150
// Duplicate **payment** profile
151151
$this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt', 'CIMCreatePaymentProfileFailure.txt',
152-
'CIMGetProfileSuccess.txt', 'CIMUpdatePaymentProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt'));
152+
'CIMGetMultipleProfilesSuccess.txt', 'CIMUpdatePaymentProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt'));
153153

154154
$response = $this->gateway->createCard($this->createCardOptions)->send();
155155

@@ -165,7 +165,7 @@ public function testDoesntUpdateExistingPaymentProfileFromOpaqueData()
165165
{
166166
// Duplicate **payment** profile
167167
$this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt', 'CIMCreatePaymentProfileFailure.txt',
168-
'CIMGetProfileSuccess.txt', 'CIMUpdatePaymentProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt'));
168+
'CIMGetMultipleProfilesSuccess.txt', 'CIMUpdatePaymentProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt'));
169169

170170
$response = $this->gateway->createCard($this->createCardFromOpaqueDataOptions)->send();
171171

@@ -175,7 +175,7 @@ public function testDoesntUpdateExistingPaymentProfileFromOpaqueData()
175175
public function testShouldUpdateExistingPaymentProfileIfDuplicateExistsAndMaxPaymentProfileLimitIsMet()
176176
{
177177
$this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt',
178-
'CIMCreatePaymentProfileFailureMaxProfileLimit.txt', 'CIMGetProfileSuccess.txt',
178+
'CIMCreatePaymentProfileFailureMaxProfileLimit.txt', 'CIMGetMultipleProfilesSuccess.txt',
179179
'CIMUpdatePaymentProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt'));
180180

181181
$response = $this->gateway->createCard($this->createCardOptions)->send();

tests/Message/CIMGetProfileResponseTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Omnipay\AuthorizeNet\Message;
44

5-
use Omnipay\Common\Exception\InvalidResponseException;
65
use Omnipay\Tests\TestCase;
76

87
class CIMGetProfileResponseTest extends TestCase
@@ -15,13 +14,22 @@ public function testConstructEmpty()
1514
new CIMGetProfileResponse($this->getMockRequest(), '');
1615
}
1716

18-
public function testGetMatchingPaymentProfileId()
17+
public function testGetMultipleMatchingPaymentProfileId()
1918
{
20-
$httpResponse = $this->getMockHttpResponse('CIMGetProfileSuccess.txt');
19+
$httpResponse = $this->getMockHttpResponse('CIMGetMultipleProfilesSuccess.txt');
2120
$response = new CIMGetProfileResponse($this->getMockRequest(), $httpResponse->getBody());
2221

2322
$this->assertEquals('26455656', $response->getMatchingPaymentProfileId('1111'));
2423
$this->assertEquals('26455709', $response->getMatchingPaymentProfileId('8888'));
2524
$this->assertNull($response->getMatchingPaymentProfileId('8889'));
2625
}
26+
27+
public function testGetSingleMatchingPaymentProfileId()
28+
{
29+
$httpResponse = $this->getMockHttpResponse('CIMGetSingleProfileSuccess.txt');
30+
$response = new CIMGetProfileResponse($this->getMockRequest(), $httpResponse->getBody());
31+
32+
$this->assertEquals('26455656', $response->getMatchingPaymentProfileId('1111'));
33+
$this->assertNull($response->getMatchingPaymentProfileId('8889'));
34+
}
2735
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
HTTP/1.1 200 OK
2+
Cache-Control: private
3+
Content-Length: 746
4+
Content-Type: text/xml; charset=utf-8
5+
Server: Microsoft-IIS/7.5
6+
X-AspNet-Version: 2.0.50727
7+
X-Powered-By: ASP.NET
8+
Access-Control-Allow-Headers: x-requested-with,cache-control,content-type,origin,method
9+
Access-Control-Allow-Origin: *
10+
Access-Control-Allow-Methods: GET,POST,OPTIONS
11+
Date: Thu, 18 Sep 2014 03:59:27 GMT
12+
13+
<?xml version="1.0" encoding="utf-8"?><getCustomerProfileResponse><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><profile><email>[email protected]</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></profile></getCustomerProfileResponse>

0 commit comments

Comments
 (0)