diff --git a/src/Message/CIMGetProfileResponse.php b/src/Message/CIMGetProfileResponse.php index b7e03be8..ff644fc0 100644 --- a/src/Message/CIMGetProfileResponse.php +++ b/src/Message/CIMGetProfileResponse.php @@ -26,6 +26,11 @@ public function getMatchingPaymentProfileId($last4) return null; } + // Handle quirkiness with XML -> JSON conversion + if (!array_key_exists(0, $this->data['profile']['paymentProfiles'])) { + $this->data['profile']['paymentProfiles'] = [$this->data['profile']['paymentProfiles']]; + } + foreach ($this->data['profile']['paymentProfiles'] as $paymentProfile) { // For every payment profile check if the last4 matches the last4 of the card in request. $cardLast4 = substr($paymentProfile['payment']['creditCard']['cardNumber'], -4); diff --git a/tests/CIMGatewayTest.php b/tests/CIMGatewayTest.php index 5c6e1a21..9e8fb78f 100644 --- a/tests/CIMGatewayTest.php +++ b/tests/CIMGatewayTest.php @@ -118,7 +118,7 @@ public function testCreateCardFromOpaqueDataSuccess() public function testShouldCreateCardIfDuplicateCustomerProfileExists() { $this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt', 'CIMCreatePaymentProfileSuccess.txt', - 'CIMGetProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt')); + 'CIMGetMultipleProfilesSuccess.txt', 'CIMGetPaymentProfileSuccess.txt')); $response = $this->gateway->createCard($this->createCardOptions)->send(); @@ -133,7 +133,7 @@ public function testShouldCreateCardIfDuplicateCustomerProfileExists() public function testShouldCreateCardFromOpaqueDataIfDuplicateCustomerProfileExists() { $this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt', 'CIMCreatePaymentProfileSuccess.txt', - 'CIMGetProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt')); + 'CIMGetMultipleProfilesSuccess.txt', 'CIMGetPaymentProfileSuccess.txt')); $response = $this->gateway->createCard($this->createCardFromOpaqueDataOptions)->send(); @@ -149,7 +149,7 @@ public function testShouldUpdateExistingPaymentProfileIfDuplicateExistsAndForceC { // Duplicate **payment** profile $this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt', 'CIMCreatePaymentProfileFailure.txt', - 'CIMGetProfileSuccess.txt', 'CIMUpdatePaymentProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt')); + 'CIMGetMultipleProfilesSuccess.txt', 'CIMUpdatePaymentProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt')); $response = $this->gateway->createCard($this->createCardOptions)->send(); @@ -165,7 +165,7 @@ public function testDoesntUpdateExistingPaymentProfileFromOpaqueData() { // Duplicate **payment** profile $this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt', 'CIMCreatePaymentProfileFailure.txt', - 'CIMGetProfileSuccess.txt', 'CIMUpdatePaymentProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt')); + 'CIMGetMultipleProfilesSuccess.txt', 'CIMUpdatePaymentProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt')); $response = $this->gateway->createCard($this->createCardFromOpaqueDataOptions)->send(); @@ -175,7 +175,7 @@ public function testDoesntUpdateExistingPaymentProfileFromOpaqueData() public function testShouldUpdateExistingPaymentProfileIfDuplicateExistsAndMaxPaymentProfileLimitIsMet() { $this->setMockHttpResponse(array('CIMCreateCardFailureWithDuplicate.txt', - 'CIMCreatePaymentProfileFailureMaxProfileLimit.txt', 'CIMGetProfileSuccess.txt', + 'CIMCreatePaymentProfileFailureMaxProfileLimit.txt', 'CIMGetMultipleProfilesSuccess.txt', 'CIMUpdatePaymentProfileSuccess.txt', 'CIMGetPaymentProfileSuccess.txt')); $response = $this->gateway->createCard($this->createCardOptions)->send(); diff --git a/tests/Message/CIMGetProfileResponseTest.php b/tests/Message/CIMGetProfileResponseTest.php index d339c9ce..912c7d0b 100644 --- a/tests/Message/CIMGetProfileResponseTest.php +++ b/tests/Message/CIMGetProfileResponseTest.php @@ -2,7 +2,6 @@ namespace Omnipay\AuthorizeNet\Message; -use Omnipay\Common\Exception\InvalidResponseException; use Omnipay\Tests\TestCase; class CIMGetProfileResponseTest extends TestCase @@ -15,13 +14,22 @@ public function testConstructEmpty() new CIMGetProfileResponse($this->getMockRequest(), ''); } - public function testGetMatchingPaymentProfileId() + public function testGetMultipleMatchingPaymentProfileId() { - $httpResponse = $this->getMockHttpResponse('CIMGetProfileSuccess.txt'); + $httpResponse = $this->getMockHttpResponse('CIMGetMultipleProfilesSuccess.txt'); $response = new CIMGetProfileResponse($this->getMockRequest(), $httpResponse->getBody()); $this->assertEquals('26455656', $response->getMatchingPaymentProfileId('1111')); $this->assertEquals('26455709', $response->getMatchingPaymentProfileId('8888')); $this->assertNull($response->getMatchingPaymentProfileId('8889')); } + + public function testGetSingleMatchingPaymentProfileId() + { + $httpResponse = $this->getMockHttpResponse('CIMGetSingleProfileSuccess.txt'); + $response = new CIMGetProfileResponse($this->getMockRequest(), $httpResponse->getBody()); + + $this->assertEquals('26455656', $response->getMatchingPaymentProfileId('1111')); + $this->assertNull($response->getMatchingPaymentProfileId('8889')); + } } diff --git a/tests/Mock/CIMGetProfileSuccess.txt b/tests/Mock/CIMGetMultipleProfilesSuccess.txt similarity index 100% rename from tests/Mock/CIMGetProfileSuccess.txt rename to tests/Mock/CIMGetMultipleProfilesSuccess.txt diff --git a/tests/Mock/CIMGetSingleProfileSuccess.txt b/tests/Mock/CIMGetSingleProfileSuccess.txt new file mode 100644 index 00000000..3beb50c0 --- /dev/null +++ b/tests/Mock/CIMGetSingleProfileSuccess.txt @@ -0,0 +1,13 @@ +HTTP/1.1 200 OK +Cache-Control: private +Content-Length: 746 +Content-Type: text/xml; charset=utf-8 +Server: Microsoft-IIS/7.5 +X-AspNet-Version: 2.0.50727 +X-Powered-By: ASP.NET +Access-Control-Allow-Headers: x-requested-with,cache-control,content-type,origin,method +Access-Control-Allow-Origin: * +Access-Control-Allow-Methods: GET,POST,OPTIONS +Date: Thu, 18 Sep 2014 03:59:27 GMT + +OkI00001Successful.kaylee@serenity.com28775801
1234526455656XXXX1111XXXX