diff --git a/src/Message/AIMAuthorizeRequest.php b/src/Message/AIMAuthorizeRequest.php index d4e77687..ba370888 100644 --- a/src/Message/AIMAuthorizeRequest.php +++ b/src/Message/AIMAuthorizeRequest.php @@ -19,7 +19,6 @@ public function getData() $this->addPayment($data); $this->addSolutionId($data); $this->addDescription($data); - $this->addCustomerIP($data); $this->addBillingData($data); $this->addRetail($data); $this->addTransactionSettings($data); @@ -59,14 +58,6 @@ protected function addDescription(\SimpleXMLElement $data) } } - protected function addCustomerIP(\SimpleXMLElement $data) - { - $ip = $this->getClientIp(); - if (!empty($ip)) { - $data->transactionRequest->customerIP = $ip; - } - } - protected function addRetail(\SimpleXMLElement $data) { if ($this->isCardPresent()) { diff --git a/src/Message/CIMAuthorizeRequest.php b/src/Message/CIMAuthorizeRequest.php index 51abd84a..dc8d9252 100644 --- a/src/Message/CIMAuthorizeRequest.php +++ b/src/Message/CIMAuthorizeRequest.php @@ -30,7 +30,6 @@ protected function addPayment(\SimpleXMLElement $data) return $data; } - } protected function addBillingData(\SimpleXMLElement $data) @@ -38,8 +37,17 @@ protected function addBillingData(\SimpleXMLElement $data) if ($this->isCardPresent()) { return parent::addBillingData($data); } else { - // Do nothing since billing information is already part of the customer profile + // Billing information is already part of the customer profile, so just add the IP address + $this->addCustomerIP($data); return $data; } } + + protected function addCustomerIP(\SimpleXMLElement $data) + { + $ip = $this->getClientIp(); + if (!empty($ip)) { + $data->transactionRequest->customerIP = $ip; + } + } } diff --git a/tests/CIMGatewayIntegrationTest.php b/tests/CIMGatewayIntegrationTest.php index 59bf1049..817a3d8f 100644 --- a/tests/CIMGatewayIntegrationTest.php +++ b/tests/CIMGatewayIntegrationTest.php @@ -67,24 +67,25 @@ public function testCustomerAndPaymentProfile() { // Create a customer profile with the specified email (email is the identifier) $email = uniqid('', true) . '@example.com'; - $cardRef = $this->createCard(array('email' => $email)); + $this->createCard(array('email' => $email)); // Create a new card in an existing customer profile + $card = $this->getValidCard(); $params = array( - 'card' => $this->getValidCard(), + 'card' => $card, 'name' => 'Kaywinnet Lee Frye', 'email' => $email, ); - $params['card']['number'] = '4007000000027'; $request = $this->gateway->createCard($params); $request->setDeveloperMode(true); $response = $request->send(); $this->assertTrue($response->isSuccessful(), 'Should be successful as we have created a payment profile'); $this->assertNotNull($response->getCardReference(), 'Card reference should be returned'); + $cardRef = $response->getCardReference(); // Create a card with same number in an existing customer profile (should fail) $params = array( - 'card' => $this->getValidCard(), + 'card' => $card, 'name' => 'Kaywinnet Lee Frye', 'email' => $email, ); @@ -96,7 +97,7 @@ public function testCustomerAndPaymentProfile() // Create a card with the same number in an existing customer profile with auto-update enabled $params = array( - 'card' => $this->getValidCard(), + 'card' => $card, 'name' => 'Kaywinnet Lee Frye', 'email' => $email, 'forceCardUpdate' => true diff --git a/tests/Message/AIMAuthorizeRequestTest.php b/tests/Message/AIMAuthorizeRequestTest.php index 2bc0b80a..66931691 100644 --- a/tests/Message/AIMAuthorizeRequestTest.php +++ b/tests/Message/AIMAuthorizeRequestTest.php @@ -28,12 +28,12 @@ public function testGetData() $data = $this->request->getData(); $this->assertEquals('authOnlyTransaction', $data->transactionRequest->transactionType); - $this->assertEquals('10.0.0.1', $data->transactionRequest->customerIP); $this->assertEquals('cust-id', $data->transactionRequest->customer->id); $setting = $data->transactionRequest->transactionSettings->setting[0]; $this->assertEquals('testRequest', $setting->settingName); $this->assertEquals('false', $setting->settingValue); + $this->assertObjectNotHasAttribute('customerIP', $data->transactionRequest, 'should only set IP in shipTo'); $this->assertObjectNotHasAttribute('trackData', $data->transactionRequest->payment); $this->assertObjectNotHasAttribute('retail', $data->transactionRequest); } diff --git a/tests/Message/AIMPurchaseRequestTest.php b/tests/Message/AIMPurchaseRequestTest.php index 77ec02bd..4f5f860a 100644 --- a/tests/Message/AIMPurchaseRequestTest.php +++ b/tests/Message/AIMPurchaseRequestTest.php @@ -28,12 +28,12 @@ public function testGetData() $data = $this->request->getData(); $this->assertEquals('authCaptureTransaction', $data->transactionRequest->transactionType); - $this->assertEquals('10.0.0.1', $data->transactionRequest->customerIP); $this->assertEquals('cust-id', $data->transactionRequest->customer->id); $this->assertEquals('AAA100302', $data->transactionRequest->solution->id); $setting = $data->transactionRequest->transactionSettings->setting[0]; $this->assertEquals('testRequest', $setting->settingName); $this->assertEquals('false', $setting->settingValue); + $this->assertObjectNotHasAttribute('customerIP', $data->transactionRequest); } } diff --git a/tests/Message/CIMAuthorizeRequestTest.php b/tests/Message/CIMAuthorizeRequestTest.php index 136c57be..969ad2d9 100644 --- a/tests/Message/CIMAuthorizeRequestTest.php +++ b/tests/Message/CIMAuthorizeRequestTest.php @@ -16,7 +16,8 @@ public function setUp() array( 'cardReference' => '{"customerProfileId":"28972085","customerPaymentProfileId":"26317841","customerShippingAddressId":"27057151"}', 'amount' => '12.00', - 'description' => 'Test authorize transaction' + 'description' => 'Test authorize transaction', + 'clientIp' => '10.0.0.1' ) ); } @@ -26,6 +27,7 @@ public function testGetData() $data = $this->request->getData(); $this->assertEquals('12.00', $data->transactionRequest->amount); + $this->assertEquals('10.0.0.1', $data->transactionRequest->customerIP); $this->assertEquals('28972085', $data->transactionRequest->profile->customerProfileId); $this->assertEquals('26317841', $data->transactionRequest->profile->paymentProfile->paymentProfileId); $this->assertEquals('27057151', $data->transactionRequest->profile->shippingProfileId); @@ -38,12 +40,14 @@ public function testShouldUseTrackDataIfCardPresent() $card['tracks'] = '%B4242424242424242^SMITH/JOHN ^2511126100000000000000444000000?;4242424242424242=25111269999944401?'; $this->request->initialize(array( 'card' => $card, - 'amount' => 21.00 + 'amount' => 21.00, + 'clientIp' => '10.0.0.1' )); $data = $this->request->getData(); $this->assertObjectNotHasAttribute('profile', $data->transactionRequest); + $this->assertObjectNotHasAttribute('customerIP', $data->transactionRequest, 'should not set IP for card present'); $this->assertObjectHasAttribute('trackData', $data->transactionRequest->payment); } }