Authorize.net provides CIM (Customer Information Manager) and AIM (Advanced Integration Method) APIs which we are used to integrate payment gateway in any application.
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.
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 disabled TLS 1.0 and TLS 1.1, 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.net.class.php file and include this PHP file using include_once function. Create an object of AuthorizeAPI class as mentioned below.
include_once('authorize.class.php'); $objAuthorizeAPI = new AuthorizeAPI(2gEh8tX1B', '69W3eRt7sd7yU5pcR');
Here 2gEh8tX1Bis an API login id and 69W3eRt7sd7yU5pcR 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.
$arrCustomerInfo = array(); $arrCustomerInfo['firstname'] = 'Krish'; $arrCustomerInfo['lastname'] = 'Johnson'; $arrCustomerInfo['company_name'] = '100Utils'; $arrCustomerInfo['ad_street'] = 'Krishna Nagar'; $arrCustomerInfo['ad_city'] = 'Mumbai'; $arrCustomerInfo['ad_state'] = 'Maharastra'; $arrCustomerInfo['ad_zip'] = '250015'; $arrCustomerInfo['ad_country'] = 'India'; $arrCustomerInfo['ph_number'] = '9856324758'; $arrCustomerInfo['em_email'] = '[email protected]'; $objAuthorizeAPI->setCustomerAddress($arrCustomerInfo);
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:
/* First: Credit card number Second: Expiration date (YYYY-MM) Third: CVV */ $objAuthorizeAPI->setCreditCardParameters('4111111111111111', '2023-10', '123'); $arrCustomerAddCCResponse = $objAuthorizeAPI->addCustomerPaymentProfile(111,'cc');
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:
{"success":"1","customerProfileId":"1501067535","customerPaymentProfileId":"1500625311","error":"","paymentFlag":"1","message":""}
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:
If we want to add another credit card / eCheck for this same customer then call addCustomerPaymentProfile function as below:
/* First: Credit card number Second: Expiration date (YYYY-MM) Third: CVV */ $objAuthorizeAPI->setCreditCardParameters(4111111111111185, '2019-12', '123'); $arrCustomerAddCCResponse = $objAuthorizeAPI->addCustomerPaymentProfile(111,'cc', true, 1501067535);
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:
/* First: Routing number Second: Account number Third: Name on account Fourth: Account type (checking, savings, or businessChecking) */ $objAuthorizeAPI->setBankParameters('071921891', '123456789', 'Prashant Jethwa', 'savings'); $arrCustomerAddeCheckResponse = $objAuthorizeAPI->addCustomerPaymentProfile(111,'eCheck',true, 1501067535);
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
/* First: Customer profile id Second: Customer payment profile id Third: Amout */ $arrChargeResponse = $objAuthorizeAPI->chargeCCeCheck(1501067535,1500625311, 50.15);
Method 2: Get credit card / eCheck Information
/* First: Customer profile id Second: Customer payment profile id */ $arrCCeCheckInfo = $objAuthorizeAPI->getCCeCheckInfo(1501067535,1500625311);
Method 3: Refund Amount From Transaction
/* First: Customer profile id Second: Customer payment profile id Third: Transaction id Fourth: Amount */ $arrRefundResponse = $objAuthorizeAPI->refundMoneyFromTransaction(1501067535,1500625311, '6547898132', 20.12);
Method 4: Get Transaction status
// First: Transaction id $arrTransactionStatus = $objAuthorizeAPI->getTransactionStatus('6547898132');
Method 5: Delete customer payment profile (Delete credit card / eCheck)
/* First: Customer profile id Second: Customer payment profile id */ $arrCPPDeleteResponse = $objAuthorizeAPI->deleteCustomerPaymentProfile(1501067535,1500625311);
Method 6: Delete customer profile (Delete customer from authorize.net account)
// First: Customer profile id $arrCPDeleteResponse = $objAuthorizeAPI->deleteCustomerProfile(1501067535);
Click on below link to download complete PHP code with working examples.
Download code to Integrate Authorize.net API with PHP
Tutorial Source:
This nice article created on code-bucket.co. I’m just sharing article to world. Thanks code-bucket.co!!