1

i am using Authorize.net PHP SDK in our website for credit card payments. currently i am sending customer bill to information like customer firstname, lastname, address, zip, city, state, country and email. i need to send customer ip address also. please suggest the solution. a part of current codes look like this :

public function authorize_card($data) {
  // Create the payment data for a credit card
  $creditCard = new AnetAPI\CreditCardType();
  $creditCard->setCardNumber($data['card_no']);
  $creditCard->setExpirationDate($data['card_exp']);
  $creditCard->setCardCode($data['card_cvc']);
  
  $paymentCreditCard = new AnetAPI\PaymentType();
  $paymentCreditCard->setCreditCard($creditCard);
  
  //create a transaction
  $transactionRequestType = new AnetAPI\TransactionRequestType();
  $transactionRequestType->setTransactionType("authCaptureTransaction"); 
  $transactionRequestType->setAmount($data['amount']);
  $transactionRequestType->setPayment($paymentCreditCard);
  
  
  $billto = new AnetAPI\CustomerAddressType();
  $billto->setFirstName($data['bill_fname']);
  $billto->setLastName($data['bill_lname']);
  $billto->setAddress($data['bill_address']);
  $billto->setCity($data['bill_city']);
  $billto->setState($data['bill_state']);
  $billto->setZip($data['bill_zip']);
  $billto->setCountry($data['bill_country']);
  
  $bill_response = $transactionRequestType->setBillTo($billto);

  $request = new AnetAPI\CreateTransactionRequest();
  $request->setMerchantAuthentication($this->auth);
  $request->setRefId($this->refId);
  $request->setTransactionRequest($transactionRequestType);
  $controller = new AnetController\CreateTransactionController($request);
  $response = $controller->executeWithApiResponse($this->api_mode);
 
  if ($response != null) {
   $tresponse = $response->getTransactionResponse();
   
   if ($tresponse != null && ($tresponse->getResponseCode() == 1 ||      $tresponse->getResponseCode() == 253)) {
    $response_array = array();
    $response_array['auth_code'] = $tresponse->getAuthCode();
    $response_array['auth_transaction_id'] = $tresponse->getTransId();
    return $response_array;
   } else {
    $errors = $tresponse->geterrors();
    
    if (is_array($errors) && !empty($errors)) {
     return $errors[0]->geterrorText();
    } else {
     $message = $response->getMessages()->getMessage();
     return $message[0]->getText();
    }
   }
   
  } else {
   return "Charge Credit card Null response returned";
  }
}
Naveen Saroye
  • 109
  • 1
  • 15
  • Good luck getting a sensible IP address, or even being allowed to do this in some locales. This is probably a duplicate: https://stackoverflow.com/q/3003145/1531971 –  Dec 05 '18 at 18:24
  • the link you posted is for getting customer ip address in php. my question is about setting customer ip address in authorizeNet php sdk to send it as customer info. – Naveen Saroye Dec 05 '18 at 20:57
  • https://community.developer.authorize.net/t5/Integration-and-Testing/Does-Authorize-net-pass-on-Customer-IP-Address/td-p/65050 (It appears you are supposed to ask your web app for this.) –  Dec 05 '18 at 21:04
  • actually they are not that supportive. – Naveen Saroye Jan 14 '19 at 17:43

1 Answers1

2

actually i have figured it out. there is a method given in autorizeNet php sdk to set customer ip address. method is setCustomerIP() which need to be used with TransactionRequestType class. the final codes would look like this:

public function authorize_card($data) {
  // Create the payment data for a credit card
  $creditCard = new AnetAPI\CreditCardType();
  $creditCard->setCardNumber($data['card_no']);
  $creditCard->setExpirationDate($data['card_exp']);
  $creditCard->setCardCode($data['card_cvc']);
  
  $paymentCreditCard = new AnetAPI\PaymentType();
  $paymentCreditCard->setCreditCard($creditCard);
  
  //create a transaction
  $transactionRequestType = new AnetAPI\TransactionRequestType();
  $transactionRequestType->setTransactionType("authCaptureTransaction"); 
  $transactionRequestType->setAmount($data['amount']);
  $transactionRequestType->setPayment($paymentCreditCard);
    
    //Setting customer ip address
    $transactionRequestType->setCustomerIP($data['ip']);
  
  
  $billto = new AnetAPI\CustomerAddressType();
  $billto->setFirstName($data['bill_fname']);
  $billto->setLastName($data['bill_lname']);
  $billto->setAddress($data['bill_address']);
  $billto->setCity($data['bill_city']);
  $billto->setState($data['bill_state']);
  $billto->setZip($data['bill_zip']);
  $billto->setCountry($data['bill_country']);
  
  $bill_response = $transactionRequestType->setBillTo($billto);

  $request = new AnetAPI\CreateTransactionRequest();
  $request->setMerchantAuthentication($this->auth);
  $request->setRefId($this->refId);
  $request->setTransactionRequest($transactionRequestType);
  $controller = new AnetController\CreateTransactionController($request);
  $response = $controller->executeWithApiResponse($this->api_mode);
 
  if ($response != null) {
   $tresponse = $response->getTransactionResponse();
   
   if ($tresponse != null && ($tresponse->getResponseCode() == 1 || $tresponse->getResponseCode() == 253)) {
    $response_array = array();
    $response_array['auth_code'] = $tresponse->getAuthCode();
    $response_array['auth_transaction_id'] = $tresponse->getTransId();
    return $response_array;
   } else {
    $errors = $tresponse->geterrors();
    
    if (is_array($errors) && !empty($errors)) {
     return $errors[0]->geterrorText();
    } else {
     $message = $response->getMessages()->getMessage();
     return $message[0]->getText();
    }
   }
   
  } else {
   return "Charge Credit card Null response returned";
  }
}
Naveen Saroye
  • 109
  • 1
  • 15