Reply
Member
Posts: 5
Registered: ‎01-30-2017

Migration from AIM to the Authorize.Net API

We have a PHP-based ecom system in which our client wants to implement accept.js.  We're currently using the AIM method and my understanding is that we will first need to migrate to the Authorize.Net API.  I've read through the API Reference, but looking for something that boils down the steps for migrating.  Can somebody here help?  Should I post my current code?  Sorry for newbie questions, this is my first time posting here.

 

Thanks!

Administrator
Posts: 296
Registered: ‎11-03-2016

Re: Migration from AIM to the Authorize.Net API

Hi @danjo,

 

You've got a few options here. Since your application is PHP-based, you may want to look at our PHP SDK, which can handle the heavy lifting of processing through our API. If that's not going to work for whatever reason, you could change the message format of your requests and then go step by step through your application replacing each point of communication with the AIM system with its equivalent in the API.

 

Communication with our API is done using HTTP POST, but instead of a bunch of key/value pairs like with AIM, you'll format a message body in XML or JSON format, then post that. Click the "API Endpoints" tab at the top of our API Reference to see the endpoint URLs and the Content-type to send.

 

Whether you're choosing XML or JSON formatting, samples of the correct formatting for each type of request are on the "Try it" tab in the API Reference.

 

Hopefully that gives you a rough idea of how to proceed, but if you have more specific questions, please feel free to post them here!

 

 

-Aaron

Aaron Wright
Developer Evangelist - Authorize.Net

Follow Authorize.Net developer news on Twitter!
Member
Posts: 5
Registered: ‎01-30-2017

Re: Migration from AIM to the Authorize.Net API

Thanks for getting me started in the right direction Aaron!  I've got the SDK installed and have begun looking at the sample code from the API reference section under Payment Transactions / Charge a Credit Card.  Just a few questions before I give it a whirl...

 

1:

define("AUTHORIZENET_LOG_FILE", "phplog");

- I'm assuming this will result in a log file named "phplog" eventually being created somewhere... in the current directory where the script runs or elsewhere?

 

2:

$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);

- I'm not finding where these constants are defined for me to update.  Are they actually defined somewhere (in a separate file maybe) where I can just update them or is it up to me to set them up?

 

3:

echo "Code : " . $tresponse->getMessages()[0]->getCode() . "\n";

- Lines like this one (and others) generate a syntax error in Dreamweaver, unless I remove the "[0]" part.  I'm sure this is a bit out of the realm of this forum (and I'm showing my inexperience here), but hoping you might be able to hed some light on it for me.

 

Thank you!

Member
Posts: 5
Registered: ‎01-30-2017

Re: Migration from AIM to the Authorize.Net API

Update: I went ahead and gave it a whirl... partial success!  I set up a sample app running through our server and processing transactions through to a sandbox account I created (sandbox mode on the SDK points to https://apitest.authorize.net).  However, when I switch it to production mode (https://api2.authorize.net) with the id and transaction key that we’re currently using in our production (AIM-based) system, I get response code 35… “An error occured during processing. Call Merchant Service Provider.”.  Should I be able to use our current AIM-based production credentials with the API?

 

Thanks!

Administrator
Posts: 296
Registered: ‎11-03-2016

Re: Migration from AIM to the Authorize.Net API

Well, that's not good...

 

The same credentials that you use for AIM should absolutely work with the new API. I wonder if there's some account misconfiguration that's not causing any problems with your AIM setup, but somehow bubbles up in this new scenario?

 

The only suggestion I can give off the top of my head is to double check and make sure it's really the right api login id and transaction key. Check the phplog file to see the request, and make sure that they right key was going out with the request.

-Aaron

Aaron Wright
Developer Evangelist - Authorize.Net

Follow Authorize.Net developer news on Twitter!
Member
Posts: 5
Registered: ‎01-30-2017

Re: Migration from AIM to the Authorize.Net API

I contacted Client Services to see if they could find any additional details on why it's being rejected, but no luck.  They did say that they're seeing the rejected transaction coming through on their end as well, which indicates that the login credentials are good, but no additional info on what's causing the error.  I'm wondering if it might be that the production account requires more details on the transaction than the sandbox account (cardholder's bill-to info... name, address, etc.).  I'm looking through the sample code for the API/SDK, but not finding how to include that info.  Can you point me in the right direction for how to do that?

 

Thanks!

Administrator
Posts: 296
Registered: ‎11-03-2016

Re: Migration from AIM to the Authorize.Net API

It would be really good to find out exactly why the transactions are being rejected, which could save you a bunch of work down the road. However, if you just want to send more information with the transactions and see if that changes anything, I can hopefully get you started.

 

Generally in the PHP SDK, you're creating objects and then calling methods on those objects to add information. All of the information you're sending with the transaction is ultimately included in a TransactionRequestType object, and that object has a "setBillTo" method you can use for setting the address (the address information having previously been added to a CustomerAddressType).

-Aaron

Aaron Wright
Developer Evangelist - Authorize.Net

Follow Authorize.Net developer news on Twitter!
Administrator
Posts: 296
Registered: ‎11-03-2016

Re: Migration from AIM to the Authorize.Net API

I noticed that our sample PHP code doesn't show adding the address in the charge a card and authorize a card samples. I just sent a request to fix that, but in the mean time, here's the updated code from the charge-credit-card.php sample. Adding other things besides address is done the same way, where you create an object of the right type you want, call the methods to add the information you want to the object, then add the object to your transaction request.

 

<?php
  require 'vendor/autoload.php';

  use net\authorize\api\contract\v1 as AnetAPI;
  use net\authorize\api\controller as AnetController;

  define("AUTHORIZENET_LOG_FILE", "phplog");

  function chargeCreditCard($amount){
    // Common setup for API credentials
    $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
    $merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
    $merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
    $refId = 'ref' . time();

    // Create the payment data for a credit card
    $creditCard = new AnetAPI\CreditCardType();
    $creditCard->setCardNumber("4111111111111111");
    $creditCard->setExpirationDate("1226");
    $creditCard->setCardCode("123");
    $paymentOne = new AnetAPI\PaymentType();
    $paymentOne->setCreditCard($creditCard);

    $order = new AnetAPI\OrderType();
    $order->setDescription("New Item");

    // Set the customer's Bill To address
    $customerAddress = new AnetAPI\CustomerAddressType();
    $customerAddress->setFirstName("Ellen");
    $customerAddress->setLastName("Johnson");
    $customerAddress->setCompany("Souveniropolis");
    $customerAddress->setAddress("14 Main Street");
    $customerAddress->setCity("Pecan Springs");
    $customerAddress->setState("TX");
    $customerAddress->setZip("44628");
    $customerAddress->setCountry("USA");

    // Create a TransactionRequestType object
    $transactionRequestType = new AnetAPI\TransactionRequestType();
    $transactionRequestType->setTransactionType( "authCaptureTransaction"); 
    $transactionRequestType->setAmount($amount);
    $transactionRequestType->setOrder($order);
    $transactionRequestType->setPayment($paymentOne);
    $transactionRequestType->setBillTo($customerAddress);

    $request = new AnetAPI\CreateTransactionRequest();
    $request->setMerchantAuthentication($merchantAuthentication);
    $request->setRefId( $refId);
    $request->setTransactionRequest( $transactionRequestType);

    $controller = new AnetController\CreateTransactionController($request);
    $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
    

    if ($response != null)
    {
      if($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK)
      {
        $tresponse = $response->getTransactionResponse();
        
        if ($tresponse != null && $tresponse->getMessages() != null)   
        {
          echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n";
          echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
          echo "Charge Credit Card TRANS ID  : " . $tresponse->getTransId() . "\n";
          echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n"; 
          echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n";
        }
        else
        {
          echo "Transaction Failed \n";
          if($tresponse->getErrors() != null)
          {
            echo " Error code  : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
            echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";            
          }
        }
      }
      else
      {
        echo "Transaction Failed \n";
        $tresponse = $response->getTransactionResponse();
        
        if($tresponse != null && $tresponse->getErrors() != null)
        {
          echo " Error code  : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
          echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";                      
        }
        else
        {
          echo " Error code  : " . $response->getMessages()->getMessage()[0]->getCode() . "\n";
          echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n";
        }
      }      
    }
    else
    {
      echo  "No response returned \n";
    }

    return $response;
  }
  if(!defined('DONT_RUN_SAMPLES'))
      chargeCreditCard(\SampleCode\Constants::SAMPLE_AMOUNT);
?>
-Aaron

Aaron Wright
Developer Evangelist - Authorize.Net

Follow Authorize.Net developer news on Twitter!
Highlighted
Member
Posts: 5
Registered: ‎01-30-2017

Re: Migration from AIM to the Authorize.Net API

Thanks a bunch for that!  I'm still getting the same generic error after adding the address info, but I would have eventually needed it anyway.  I've sent an email to the Developer Support.  Client Services thought that they might have some other thoughts and/or might be able to elevate the issue to get more eyes on it.  I will let you know how that pans out, but if you come up with anything else I might want to try from a code perspective, certainly let me know.

 

Thanks again!