How to Integrate authorize.net API with php

Basically, authorize.net is providing CIM (Customer Information Manager) and AIM (Advanced Integration Method) APIs which we can use in our application to integrate payment gateway. In this tutorial, we will learn how to Integrate Authorize.net API with PHP.

Before going ahead let’s check different between CIM and AIM.

What is CIM in authorize.net?

CIM is the easiest way to implement ongoing subscriptions or multiple charges without redirecting to a page on Authorize.net. We can use CIM to tokenize and store customer’s sensitive payment information on authorize.net’s secure server. By below image, we can easily understand the functionality of CIM.

How to Integrate authorize.net API with php

What is AIM in authorize.net?

AIM is recommended if you are just processing just a single charge. You can not create any subscription or charge a customer multiple times.

Minimum Requirements to integrate authorize.net CIM / AIM API

  • The merchant’s website must have server-side scripting or CGI capabilities such as ASP Classic, C#, Cold Fusion, Java, Perl, PHP, or VB.Net
  • The merchant must be able to securely store payment gateway account data, such as their API Login ID or Transaction Key.
  • The merchant’s website must use HTTPS.
  • The merchant must have a valid SSL or TLS certificate and their website must be capable of initiating both client and server side connections.

Note: Authorize.Net plans to disable TLS 1.0 and TLS 1.1 on Sandbox (April 30, 2017) and Production (Sept 18, 2017). So it is recommended to use TLS 1.2.

Steps to Integrate Authorize.net API with PHP

Step 1: Download authorize.net class file

Download authorize.class.php file and include this PHP file using include_once function. Create an object of AuthorizeAPI class as mentioned below.

Here 7mMJ5tx5M is an API login id and 37U3eM9qR7Td5qEg is a transaction key. Pass third parameter as ‘liveMode’ for a production environment.

Step 2: Set customer’s information

After creating an object of AuthorizeAPI class, Call setCustomerAddress to set customer’s information like the first name, last name, company name, address, phone number and email address.

Step 3: Add Customer Payment Profile (Add credit card / eCheck)

To add credit card / eCheck (customer payment profile) in authorize.net call setCreditCardParameters and addCustomerPaymentProfile methods as mention below:

Here 111 is customer id (Unique id) and cc is a parameter which will indicate that we are adding a credit card.

Authorize.net will give a response like below:

Store customer profile id and customer payment profile id in a table for future reference.

After successfully adding a credit card, we can see customer profile and payment profile in authorize.net account which will look like below:

How to Integrate authorize.net API with php

If we want to add another credit card / eCheck for this same customer then call addCustomerPaymentProfile function as below:

Here we are passing the third parameter as true because this customer is already added once in authorize.net account and we want to add another credit card. Pass customer profile id as a fourth parameter so API will add a new credit card for this customer only.

To add eCheck in authorize.net, call a method as below:

Here we are passing the second parameter as eCheck to indicate that we are adding eCheck.

That’s it, by above three steps we can add credit card / eCheck details in Authorize.net which are basic steps to Integrate Authorize.net API with PHP.

Some of the useful methods which I created in authorize.class.php file are as below:

Method 1: Charge customer’s credit card / eCheck

Method 2: Get credit card / eCheck Information

Method 3: Refund Amount From Transaction

Method 4: Get Transaction status

Method 5: Delete customer payment profile (Delete credit card / eCheck)

Method 6: Delete customer profile (Delete customer from authorize.net account)

Click on below link to download complete PHP code with working examples.

Download code to Integrate Authorize.net API with PHP

You can also read Authorize.net CIM document for more information.

Comment if you need any help in payment gateway integration. Happy to help 🙂

You may also like:

Sharing is caring!