Tutorial: Integrating the Authorize.Net AIM API with PHP

Working with the Authorize.Net AIM API in and of itself is very easy to do. Between the integration guide and sample code a good programmer can have a working solution in only minutes. But this code is for demonstration purposes only and isn’t suited for live production sites. A reusable concise solution is needed.

Fortunately I have taken the time to abstract the AIM API into my own class that not only simplifies the code we will need to work with that API but also makes it modular and easy to port from application to application. To begin you will need to download the AuthnetAIM class. You can find it here.

 

This code is written in PHP5. PHP4 has been officially retired by PHP and all of the major open source projects have committed to PHP5. If you aren’t programming in PHP5 yet, you should be. If your host doesn’t support PHP5 yet, find a new host.

 

To begin you will need to include the class using the require() function:

  1. require('AuthnetAIM.class.php');

As with any class/object the first thing we need to do is instantiate it. This can be done as follows:

  1. $payment = new AuthnetAIM('myapilogin', 'mYtRaNsaCTiOnKEy');

Up to three parameters are accepted in constructor with the first two being required. myapilogin is the API login for the account. mYtRaNsaCTiOnKEy is the transaction key generated in the Authorize.Net control panel.

If you have a Authorize.Net developer account you can use it with this script by setting the third parameters to TRUE to be true.

  1. $payment = new AuthnetAIM('myapilogin', 'mYtRaNsaCTiOnKEy', true);

Authorize.Net allows for a lot of information to be passed through their API. Only a few of these are actually required to process a transaction. The following snippet is the minimum amount of code required to successfully process a transaction:

  1. $payment = new AuthnetAIM('myapilogin', 'mYtRaNsaCTiOnKEy');
  2. $payment->setTransaction($creditcard, $expiration, $total);
  3. $payment->process();

First we create our Authorize.Net object and store it in a variable called $payment. We then called the setTransaction() method to set the three required pieces of information for processing a transaction: credit card number, credit card expiration date, and the total amount to be processed. If any of these pieces of information are omitted an exception will be thrown and the transaction will not be processed. Lastly we call the process() method which utilizes the Authorize.Net API to process the transaction and receive the response.

This basic code does not do AVS or CVV verification which, at the very least, means higher rates will be charged for the merchant but it also means they will be missing two important tools for reducing their exposure to fraud. To perform CVV verification we need only to add a fourth parameter to the setTransaction() method. To perform AVS we only need to provide the street address and zip code to Authorize.Net. We can do that using the setParameter() method which allows us to set predetermined parameters to be sent to the Authorize.Net API along with the transaction information (you can find all of the possible parameters in the integration guide):

  1. $payment = new AuthnetAIM('myapilogin', 'mYtRaNsaCTiOnKEy');
  2. $payment->setTransaction($creditcard, $expiration, $total, $cvv);
  3. $payment->setParameter("x_address", $business_address);
  4. $payment->setParameter("x_zip", $business_zipcode);
  5. $payment->process();

We can take it a step further and take advantage of Authorize.Net’s logging of transaction information and send over quite a bit of information through their API. Typically the complete billing address and shipping address, if necessary, are provided. Application specific user ids are also good to provide as they make matching a transaction to a user account that much easier to do.

There are other pieces of information that can be configured or provided to further customize a transaction. Two pieces of information that are a good idea to provide with each transaction is the total amount of tax charged to a sale and any invoice number associated with it. These pieces of information are required to processing business cards and since we cannot tell if a card being processed is in fact a business card it is simply a good idea to provide them with every transaction.

A parameter that can be configured programmatically is the window in which Authorize.Net will prevent a duplicate transaction from being processed. Basically this prevents a user from hitting the refresh button in their browser and processing their sale again. The x_duplicate_window parameter controls how long this window is open and is set in seconds.

Here is a sample transaction that sets the duplicate transaction window to three minutes, records the customer’s IP address, turns off the automatic email generated by Authorize.Net, provides an invoice number and tax amount, sends over complete billing and shipping addresses, and records the user id for this customer:

  1. $payment = new AuthnetAIM('myapilogin', 'mYtRaNsaCTiOnKEy');
  2. $payment->setTransaction($creditcard, $expiration, $total, $cvv, $invoice, $tax);
  3. $payment->setParameter("x_duplicate_window", 180);
  4. $payment->setParameter("x_cust_id", $user_id);
  5. $payment->setParameter("x_customer_ip", $_SERVER['REMOTE_ADDR']);
  6. $payment->setParameter("x_email", $email);
  7. $payment->setParameter("x_email_customer", FALSE);
  8. $payment->setParameter("x_first_name", $billing_firstname);
  9. $payment->setParameter("x_last_name", $billing_lastname);
  10. $payment->setParameter("x_address", $billing_address);
  11. $payment->setParameter("x_city", $billing_city);
  12. $payment->setParameter("x_state", $billing_state);
  13. $payment->setParameter("x_zip", $billing_zipcode);
  14. $payment->setParameter("x_phone", $billing_telephone);
  15. $payment->setParameter("x_ship_to_first_name", $shipping_firstname);
  16. $payment->setParameter("x_ship_to_last_name", $shipping_lastname);
  17. $payment->setParameter("x_ship_to_address", $shipping_address);
  18. $payment->setParameter("x_ship_to_city", $shipping_city);
  19. $payment->setParameter("x_ship_to_state", $shipping_state);
  20. $payment->setParameter("x_ship_to_zip", $shipping_zipcode);
  21. $payment->setParameter("x_description", $product);
  22. $payment->process();

The Authorize.Net API is not limited to processing sales only. All types of transactions can be performed including refunds and authorizations. To do an authorization without charging the credit card we can use the setTransactionType() method to change the transaction type to AUTH_ONLY. setTransactionType() accepts one of six possible values which are AUTH_CAPTURE, AUTH_ONLY, PRIOR_AUTH_CAPTURE, CREDIT, CAPTURE_ONLY, and VOID. AUTH_CAPTURE is the default for sale and is set automatically when you create the $payment object. Below is a sample AUTH_ONLY transaction:

  1. $payment = new AuthnetAIM('myapilogin', 'mYtRaNsaCTiOnKEy');
  2. $payment->setTransaction($creditcard, $expiration, $total, $cvv);
  3. $payment->setTransactionType("AUTH_ONLY");
  4. $payment->process();

Now that we know how to process a transaction, let’s see how we handle the results. Our AuthnetAIM class includes three methods for determining the status of the transaction. isApproved() will return true if the transaction was successful. isDeclined() will return true if the sale was declined. isError() will return true if there was some sort of error processing the transaction.

Using these three methods we can create a flow control structure to handle the response appropriately:

  1. if ($payment->isApproved())
  2. {
  3.     // Get the approval code
  4.     $approval_code  = $payment->getAuthCode();
  5.  
  6.     // Get the results of AVS
  7.     $avs_result     = $payment->getAVSResponse();
  8.  
  9.     // Get the Authorize.Net transaction ID
  10.     $transaction_id = $payment->getTransactionID();
  11.  
  12.     // Do stuff with this. Most likely store it in a database.
  13. }
  14. else if ($payment->isDeclined())
  15. {
  16.     // Get reason for the decline from the bank. This always says,
  17.     // "This credit card has been declined". Not very useful.
  18.     $reason = $payment->getResponseText();
  19.  
  20.     // Politely tell the customer their card was declined
  21.     // and to try a different form of payment
  22. }
  23. else if ($payment->isError())
  24. {
  25.     // Get the error number so we can reference the Authnet
  26.     // documentation and get an error description
  27.     $error_number  = $payment->getResponseSubcode();
  28.     $error_message = $payment->getResponseText();
  29.  
  30.     // Or just echo the message out ourselves
  31.     echo $payment->getResponseMessage();
  32.  
  33.     // Report the error to someone who can investigate it
  34.     // and hopefully fix it
  35.  
  36.     // Notify the user of the error and request they contact
  37.     // us for further assistance
  38. }

For debugging purposes the AuthnetAIM class overloads the __toString() method to display the current state of the $payment object in a clear and easy to read table. If you run the code below you will get two tables displayed on your screen, . The first will show the state of the object before the transaction is processed and the other will show it after.

  1. $payment = new AuthnetAIM('myapilogin', 'mYtRaNsaCTiOnKEy');
  2. $payment->setTransaction($creditcard, $expiration, $total, $cvv);
  3. echo $payment;
  4. $payment->process();
  5. echo $payment;

The AuthnetAIM class takes advantage of exceptions which are new in PHP5. These are only generated when something isn’t configured properly. This can be anything from the API login and transaction key to setting any parameters. Errors generated by Authorize.Net do not throw exceptions. You can use the new try/catch flow control structure to handle any exceptions generated by the class:

  1. try
  2. {
  3.     $payment = new AuthnetAIM('myapilogin', 'mYtRaNsaCTiOnKEy');
  4.     $payment->setTransaction($bad_information);
  5.     $payment->process();
  6. }
  7. catch (AuthnetAIMException $e)
  8. {
  9.     echo 'There was an error processing the transaction. Here is the error message: ';
  10.     echo $e->__toString();
  11. }

Now that we know how to process a sale, handle its response, and handle potential errors, let’s put it all together in one block so we can see it working all at once with a few extras thrown in to show you most of what this class can do:

  1. require('AuthnetAIM.class.php');
  2.  
  3. try
  4. {
  5.     $user_id = 1;
  6.     $email   = 'johnny@example.com';
  7.     $product = 'A test transaction';
  8.     $business_firstname = 'John';
  9.     $business_lastname  = 'Smith';
  10.     $business_address   = '123 Main Street';
  11.     $business_city      = 'Townsville';
  12.     $business_state     = 'NJ';
  13.     $business_zipcode   = '12345';
  14.     $business_telephone = '800-555-1234';
  15.     $shipping_firstname = 'John';
  16.     $shipping_lastname  = 'Smith';
  17.     $shipping_address   = '100 Business Rd';
  18.     $shipping_city      = 'Big City';
  19.     $shipping_state     = 'NY';
  20.     $shipping_zipcode   = '10101';
  21.  
  22.     $creditcard = '4111-1111-1111-1111';
  23.     $expiration = '12-2016';
  24.     $total      = 1.00;
  25.     $cvv        = 123;
  26.     $invoice    = substr(time(), 0, 6);
  27.     $tax        = 0.00;
  28.  
  29.     $payment = new AuthnetAIM('myapilogin', 'mYtRaNsaCTiOnKEy', true);
  30.     $payment->setTransaction($creditcard, $expiration, $total, $cvv, $invoice, $tax);
  31.     $payment->setParameter("x_duplicate_window", 180);
  32.     $payment->setParameter("x_cust_id", $user_id);
  33.     $payment->setParameter("x_customer_ip", $_SERVER['REMOTE_ADDR']);
  34.     $payment->setParameter("x_email", $email);
  35.     $payment->setParameter("x_email_customer", FALSE);
  36.     $payment->setParameter("x_first_name", $business_firstname);
  37.     $payment->setParameter("x_last_name", $business_lastname);
  38.     $payment->setParameter("x_address", $business_address);
  39.     $payment->setParameter("x_city", $business_city);
  40.     $payment->setParameter("x_state", $business_state);
  41.     $payment->setParameter("x_zip", $business_zipcode);
  42.     $payment->setParameter("x_phone", $business_telephone);
  43.     $payment->setParameter("x_ship_to_first_name", $shipping_firstname);
  44.     $payment->setParameter("x_ship_to_last_name", $shipping_lastname);
  45.     $payment->setParameter("x_ship_to_address", $shipping_address);
  46.     $payment->setParameter("x_ship_to_city", $shipping_city);
  47.     $payment->setParameter("x_ship_to_state", $shipping_state);
  48.     $payment->setParameter("x_ship_to_zip", $shipping_zipcode);
  49.     $payment->setParameter("x_description", $product);
  50.     $payment->process();
  51.  
  52.     if ($payment->isApproved())
  53.     {
  54.         // Get info from Authnet to store in the database
  55.         $approval_code  = $payment->getAuthCode();
  56.         $avs_result     = $payment->getAVSResponse();
  57.         $cvv_result     = $payment->getCVVResponse();
  58.         $transaction_id = $payment->getTransactionID();
  59.  
  60.         // Do stuff with this. Most likely store it in a database.
  61.         // Direct the user to a receipt or something similiar.
  62.     }
  63.     else if ($payment->isDeclined())
  64.     {
  65.         // Get reason for the decline from the bank. This always says,
  66.         // "This credit card has been declined". Not very useful.
  67.         $reason = $payment->getResponseText();
  68.  
  69.         // Politely tell the customer their card was declined
  70.         // and to try a different form of payment.
  71.     }
  72.     else if ($payment->isError())
  73.     {
  74.         // Get the error number so we can reference the Authnet
  75.         // documentation and get an error description.
  76.         $error_number  = $payment->getResponseSubcode();
  77.         $error_message = $payment->getResponseText();
  78.  
  79.         // OR
  80.  
  81.         // Capture a detailed error message. No need to refer to the manual
  82.         // with this one as it tells you everything the manual does.
  83.         $full_error_message =  $payment->getResponseMessage();
  84.  
  85.         // We can tell what kind of error it is and handle it appropriately.
  86.         if ($payment->isConfigError())
  87.         {
  88.             // We misconfigured something on our end.
  89.         }
  90.         else if ($payment->isTempError())
  91.         {
  92.             // Some kind of temporary error on Authorize.Net's end. 
  93.             // It should work properly "soon".
  94.         }
  95.         else
  96.         {
  97.             // All other errors.
  98.         }
  99.  
  100.         // Report the error to someone who can investigate it
  101.         // and hopefully fix it
  102.  
  103.         // Notify the user of the error and request they contact
  104.         // us for further assistance
  105.     }
  106. }
  107. catch (AuthnetAIMException $e)
  108. {
  109.     echo 'There was an error processing the transaction. Here is the error message: ';
  110.     echo $e->__toString();
  111. }

If you would like to learn more about how this class was written, be sure to read Integrate the Authorize.Net Payment Gateway with PHP. That article covers how to create a basic class that does everything we cover in this article and is a good primer for abstracting APIs with your own classes.

UPDATE 2009-09-16: I’ve updated this code a bit and have altered the tutorial to better reflect this. I’ve also, obviously, provided the newer code for download and changed the license to be LGPL from GPL.

UPDATE 2009-12-18: Apparently Godaddy.com got rid of their stupid proxy server so there’s no need to account for it. I’ve removed it from the code. I’ve also optimized handling connection errors and make exceptions thrown more informative.

103 thoughts on “Tutorial: Integrating the Authorize.Net AIM API with PHP

  1. Thanks for this descriptive solution. I have one problem I need to create the subscription based on the transaction id which send back by AIM method.

    is this possible

    Thanks

  2. This is perfect, thank you. Two questions… 1) how is this different than your article on merchant-account-services.org? and 2) what information do I have to provide when using this on my own e-commerce site?

  3. The article actually shows someone how to write the class and explains Authnet’s API in detail. This is different as this blog post is a tutorial in how to use that class the article is about. It’s aimed at users who aren’t either interested or capable of learning advanced APIs or programming and just want a solution that works.

    To use this with your own ecommerce site all you have to do is have your own Authorize.Net payment gateway. That will give you an API login and transaction key. All you need to do is then put them into the class (you can see where at the top of the file) and the script should work for you.

  4. HI. thanks for your Tutorial ..I am just finding this kind of article…..I need intergrade Authorize in my e-commence website…..And this my first time to intergade Authorize….it is very detailed…I will have a try later…

  5. hi.. thanks a lot for your information.. i want one help from you. actually i php4, so can you please mail me PHP4 compatibility code.

  6. hi, can any one help me getting done with SIM integration. I have used the sample code for integrating, but it gives me error..saying “(99) This transaction cannot be accepted.”. Please help me in getting this done .Thanks in advance..
    Neethi

  7. So in order to actually process a transaction you would just need fields and a post for the variables here?

  8. Not exactly sure what you mean. But to use this code you need:

    1) a form to capture the payment information (credit card number, expiration date, etc.)

    2) to validate all of the data and make sure it is correct before you use this code to communicate with Authorize.Net

    3) an Authorize.Net account to handle the payment processing (a test account will work fine)

  9. I have it all working fine on one site. I want to launch a similar but slightly different site, same charges, account info, bank account, etc. Can I use the same API setup I have on anther site?

  10. Hey John,

    It looks like there are a few inconsistencies in the (otherwise good) code:

    1. You use AuthnetException in your code, but AuthnetAIMException is what you define at the top of your code.

    2. Line 156, if (empty($this->params[‘x_amount’])) is invalid if x_amount is 0.00 (if you’re trying to force an error for testing) – you may want to use isset or change the error message to explain a little better.

    3. This is just a feature request (which I’m going to implement myself if I end up using this), but it’d be nice if you could pass the credentials into the object during __construct rather than defining them within the library.

    Hope this helps!

  11. Chris,

    Thanks for taking the time to review my code!

    1) Thanks for pointing that out. I’ve updated the class to reflect that.

    2) Basically what does is catch an invalid amount before the transaction is attempted. A zero dollar amount is not a valid amount top charge a card so the transaction will automatically. By catching it here at this point we save the merchant money as no transaction is processed so no transaction fee is charged by Authnet.

    3) That is definitely an option to take. Especially if you’re in a situation where you may want to use multiple Authnet accounts for one service (I’ve seen it happen). It basically boils down to a tomato, tomáto situation.

  12. it seems $payment->isError is always called with response codes null. when testing this code with authorize.net, is ssl required?

    if not, what else could be the possible problem? i’ve tried with valid cc numbers and always get the same results.

    rob

  13. If you’re getting a null return value then it should definitely be flagged by $payment->isError as null is not an acceptable response. SSL is always required even when using an Authnet test account. This error should go away once you switch to a secure connection.

  14. hi john,

    are you sure you need ssl for testing? after doing further research, forum posts suggest that ssl isn’t required for authorize.net gateway in “test mode”.

    nonetheless, i setup ssl to troubleshooot, it seems the null response is still present. is there anyway to debug further to see why this is happening?

  15. Hey John,

    My pleasure – thanks for providing this library to the community!

    One more thing…

    It looks like the prepareParameters function can be removed – instead of using it and the rtrim() of ‘&’, you can just use the http_build_query function to do the same thing.

    So POSTFIELDS in process() would look like:

    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($this->params));

    and then you can get rid of prepareParameters() and $this->fields alltogether!

    Just a little optimization. 🙂 Overall this code is very helpful though – thanks!

  16. update: you can test against authorize.net without having an SSL certificate. you need to specify curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); (which you have, but this is for when you use godaddy’s proxies only)

    hopefully that helps others

  17. Chris,

    I gotta tell ya, PHP is just full of goodies! Looks like this function was added in PHP 5 and it looks darn useful. Based on what I saw in the PHP manual you are correct and that function would do exactly what prepareParameters() and $this->fields accomplish. Great catch!

    Rob,

    Thanks for pointing out that you can test over an insecure connection. Hopefully that will help others when they’re integrating this script into their sites. Although I should point out test mode and an Authorize.Net test account are two different things. All Authorize.Net accounts can operate in test mode but a test account must be applied for at Authorize.Net and requires a separate login and password. Their test account does require an SSL account to function normally AFAIK.

  18. “echo $e->__toString();” should be just “echo $e;”

    php will execute the internal method __toString().
    I think calling any method starting with “_” is considered a bad OOP if it is outside of the class itself.

    Slavi

  19. Just wanted to drop a quick line and say thanks for sharing this code! It’s been a big help!

  20. John,

    Thanks a lot! I wanted to learn a bit about this and your class seems to be most helpful.

  21. Thanks for this code!! Everything works great until I try to pass “x_line_item” into the class. I receive a “Error Number: 1 …. error_message: Line item 1 is invalid” error whenever I try to include x_line_item, regardless of whether I hard-code a static line item or build the line item list dynamically. I’m almost positive I have the value formatted properly. Is your class set up to accommodate x_line_item? Thanks again for the great resource!!

  22. John,

    Great class – saved me a bunch of time. If I wanted to redirect with a header(“Location….”) to a different page upon approval and / or rejection, I have tried to add this to the if() statement and it tells me that headers have already been sent and it points to an error in the class itself causing this. Could it be the response from authnet that is causing the problem? Would I need to redirect in the class itself?

    Thanks,
    Charles

  23. For some reason when using this code my emails look like name%40whatever.com and my addresses use similar characters rather than correct spaces. Authorize.net says it has something to do with url encoding. Any ideas?

  24. I have an Authorized.net account and I have my log in and now I have a question.

    I have always been able to use the code successfully whenever there is ONE PRICE and allowed people to make multiple purchases of the same price. NOW, I have a situation where I have to create $25.00 for adults & $15.00 for kids AND I want them to have the options to purchase multiples of each ticket ticket price.

    Any ideas on how to use our Authorize.net account to do this?

  25. Thank you, this is a great class and a great tutorial. I had a valid response from my AuthNet developer sandbox account in minutes, just like you said.

    Curious though about the response array. I got 69 elements, but pages 28 to 32 of the AIM guide only go up to 40. Any idea what the rest are? Truth to tell, except for the last one they were all blank ([68] was FALSE) Got the same results with id & key from a live account, but also in test mode.

    Also, wondering why you hard-coded testmode, id & key into the class. Was it for security, to get folks up and running more quickly, or some completely other reason?

    Made a little extension so I could set those 3 at runtime, and added a few other functions, seemed to make the code a little more re-usable.

    Take care!

    Carl

  26. Hi,
    You said in the beginning of the article – the code is not suited for live production environments. If I dont care about reusability/conciseness, is it production-ready?
    What changes do u suggest to make it production ready?

    Thanks
    Jo

  27. Jo,

    I meant the Authorize.Net sample code is not production ready. It’s just sample code designed to help developers understand how their API works so they can more easily write their own production ready code.

    My code is production ready. 🙂

  28. Hello sir,

    i like to brief the problem..

    this was the curl i am using to execute for test server of authorize.net

    https://test.authorize.net/gateway/transact.dll

    i get the output “could not connect”, I have used this statement for failure of curl execution.

    so is that the test url is wrong given by authorize.net or some settings problem in authorize.net account. i have tried keeping enabled testmode and also tried disabling testmode, but i get the same response,

    $request = curl_init();

    curl_setopt($request, CURLOPT_URL, $post_url);

    curl_setopt($request, CURLOPT_HEADER, 0);

    curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);

    curl_setopt($request, CURLOPT_POSTFIELDS, $post_string);

    curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE);

    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

    curl_setopt($request, CURLOPT_TIMEOUT, 30);

    $post_response = curl_exec($request) or die(‘could not connect’);

    curl_close ($request);

    Is that we need ssl for test account to get connected with authorize.net server

    I am waiting for your reply sir.

  29. I’m getting the same as Avijit.

    Incomming Parameters
    Response Code 3
    Response Subcode 2
    Response Reason Code 13
    Response Reason Text The merchant login ID or password is invalid or the account is inactive.

    I tried both logins for :Card Not Present, and Card Present.

    Any ideas? I’m going to troll around and see if i find any thing.

  30. The Response Reason Text says it all. You’re using an invalid login and/or password. If you set const TEST = true then you have to have a developer account. If you don’t you will get this error. You will also get this error on a live account with the wrong credentials.

  31. Yep that was half the problem with me, so I set it to TEST = true and use the login for “Card Not Present” and it worked perfectly. Thanks for all the work you put into your making your AuthnetAIM class and writing this tutorial.

    p.s. you should sell this bit of code to Authorize.net I’m sure it would cut down on the amount of tech support calls they get and cut down on the miles of documentation they have on there site.

  32. hii thanks for this amazing class, but needed one more help from you can you please pass on the developer/demo credentials for authorize.net, i have applied for but they say it takes 48 hours. and i can’t wait trying this….

    thanks once again

  33. Hi Sir
    I set it to TEST = true and use the login for “Card Not Present” but throw the same error
    Response Reason Code 13
    Response Reason Text The merchant login ID or password is invalid or the account is inactive.
    plz help me how to solve this problem
    Thanks
    Avijit

  34. Hi All,

    Johnny, it’s so great of you to publish all this! But, unfortunately, it’s not working for me :(.

    Am not used to working with classes, and can’t even get off the ground. The
    try
    {
    statement gave me an immediate error: Parse error: syntax error, unexpected ‘{‘

    When I took the “try” and parentheses out, I got another parse error:
    Parse error: syntax error, unexpected T_CONST,…
    This error occurs at the top of the Authnet.AIM.class.php in the
    const LOGIN =
    statement.

    What could be going on? Do I need to define something somewhere??? Or is it a server/hosting setting?

    Thanks much for any help or ideas!!

    Judi

  35. Judi,

    Sounds like you’re running PHP4 and not 5. This means the code just won’t work for you. If you’re not familiar with the differences between PHP 4 and 5 and objects you’ll find altering the code to work for you difficult at best. See if your host offers PHP 5. If they don’t I recommend switching to one that does as PHP 4 is dead.

    John

  36. Ahhhhhhhhhhhh…..

    That explains it. You’d think these large hosting companies (this is 1&1) would be up to date, wouldn’t you?

    Thanks,
    Judi

  37. hello johnny,
    i have tried a lot with the code
    ————————————————–
    require(‘AuthnetAIM.class.php’);

    try
    {
    $payment = new AuthnetAIM(‘myapilogin’, ‘mYtRaNsaCTiOnKEy’, true, true);
    $payment->setTransaction($creditcard, $expiration, $total, $cvv, $invoice, $tax);
    $payment->setParameter(“x_duplicate_window”, 180);
    $payment->setParameter(“x_cust_id”, $user_id);
    $payment->setParameter(“x_customer_ip”, $_SERVER[‘REMOTE_ADDR’]);
    $payment->setParameter(“x_email”, $email);
    $payment->setParameter(“x_email_customer”, FALSE);
    $payment->setParameter(“x_first_name”, $business_firstname);
    $payment->setParameter(“x_last_name”, $business_lastname);
    $payment->setParameter(“x_address”, $business_address);
    $payment->setParameter(“x_city”, $business_city);
    $payment->setParameter(“x_state”, $business_state);
    $payment->setParameter(“x_zip”, $business_zipcode);
    $payment->setParameter(“x_phone”, $business_telephone);
    $payment->setParameter(“x_ship_to_first_name”, $shipping_firstname);
    $payment->setParameter(“x_ship_to_last_name”, $shipping_lastname);
    $payment->setParameter(“x_ship_to_address”, $shipping_address);
    $payment->setParameter(“x_ship_to_city”, $shipping_city);
    $payment->setParameter(“x_ship_to_state”, $shipping_state);
    $payment->setParameter(“x_ship_to_zip”, $shipping_zipcode);
    $payment->setParameter(“x_description”, $product);
    $payment->process();

    if ($payment->isApproved())
    {
    // Get info from Authnet to store in the database
    $approval_code = $payment->getAuthCode();
    $avs_result = $payment->getAVSResponse();
    $transaction_id = $payment->getTransactionID();

    // Do stuff with this. Most likely store it in a database.
    }
    else if ($payment->isDeclined())
    {
    // Get reason for the decline from the bank. This always says,
    // “This credit card has been declined”. Not very useful.
    $reason = $payment->getResponseText();

    // Politely tell the customer their card was declined
    // and to try a different form of payment
    }
    else if ($payment->isError())
    {
    // Get the error number so we can reference the Authnet
    // documentation and get an error description
    $error_number = $payment->getResponseSubcode();
    $error_message = $payment->getResponseText();

    // Report the error to someone who can investigate it
    // and hopefully fix it

    // Notify the user of the error and request they contact
    // us for further assistance
    }
    }
    catch (AuthnetAIMException $e)
    {
    echo ‘There was an error processing the transaction. Here is the error message: ‘;
    echo $e->__toString();
    }

    ————————————————————–

    but not connecting to the authorized.net ,

    what extra to do for that ,
    please help me , i have to complete my clients site within 2 days , and only remained this billing section ,
    i do’nt want demo , i want to use it in live site, i have mearchent account also in authorized.net,

    is ssl ertification is necessary for this?

    please help me!!!

    thanks

  38. It is possible to have a form and all the files ready configured, in a way I only need to updated my authorize.net info?
    I’m a bit lost don’t really know what to do first here, all I need is a simple form for my customers to make payments and type the invoice number and amount they wish to pay.
    thanks

  39. Hey there… Im a flash guy… and trying to build a shopping cart… I am getting everything right other than the x_line_item. I need to send an Array to PHP POST and use the line itemization of the email system… for some reason, I can only get 1 item through per transaction, even though I am sending an array!

    When using this format SENDING POST VARS to php, DOES WORK:
    var the_line_items:Array = new Array(‘item1Fish Tank1138.95Y&’);

    When using this format SENDING POST VARS to php, doesnt work:
    var the_line_items:Array = new Array(‘item1Fish Tank1138.95Y&’,’item2Red Corals 1Spikey Red Corals on a bed of sea salt19.99Y&’,’item3Fish Tank PumpWhite pump with nails on the side121.99Y&’);

  40. Hi, love the concept and need this but it’s not charging and I’m not getting responses codes. I’m not on a godaddy account nor do I want it to test. so the line is $payment = new AuthnetAIM($loginname, $transactionkey, false, false);

    I did get messages when the parameters were empty but nothing else. Any quick words of wisdom.

Leave a Reply

Your email address will not be published. Required fields are marked *