BryanShaw

Connecting Authorize.Net’s Payment Gateway to PrestaShop Using Advanced Integration Method

by ‎07-23-2012 02:15 PM - edited ‎07-23-2012 02:59 PM (12,000 Views)

Authorize.Net prides itself on our flexible APIs and the many ways in which they can be used to create your own payment system. From time to time, we like to invite guest bloggers to talk about their real-world solutions. This way, you can see working examples of the many ways that our solutions can be implemented. We hope these perspectives will help you as you determine how best to approach designing your own solutions and applications.


Today’s post is by PrestaShop, a leading open-source e-commerce solution powering more than 115,000 stores worldwide. PrestaShop uses Authorize.Net’s Advanced Integration Method (AIM) to ensure easy online selling and is the winner of the Packt Publishing 2010 and 2011 award for Best Open-source Business Application. Whether you decide to create your own solution or to use a ready-to-go offering like PrestaShop, we hope this post will provide some good information and stimulate some ideas.  


If you’re interested in blogging about your solution, please email Michelle at michelle@authorize.net.


 

Hi everyone, my name is Bryan Shaw, and I work in the communications department at PrestaShop. Today I want to briefly share with you sample code for how PrestaShop integrates with Authorize.Net.

 

In order for PrestaShop’s free Authorize.Net module to be successful, developers had to utilize the Advanced Integration Method (AIM).

 

AIM is best described as a customizable payment processing solution that gives merchants control over all steps in processing transactions online.

 

AIM transactions are secured through a 128-bit Secure Sockets Layer (SSL) connection between any PrestaShop store and the Authorize.Net Payment Gateway. This level of security ensures all sensitive information is transferred and stored safely, securely and in accordance with the Payment Card Industry’s (PCI) Data Security Standard.

 

In order to integrate the Authorize.Net Payment Gateway to the PrestaShop store, our developers had to natively rewrite the source code.

 

The following is a sample of the code necessary to execute Authorize.Net’s basic payment processing solutions via PrestaShop:

 

<?php

 

class authorizeNetAIM() extends PaymentModule

{

}

 

/* Forge the parameters */

 

// Authorize.Net credentials

$authorizeAIMParams['x_login'] = 'YOUR_SANDBOX_LOGIN_ID';

$authorizeAIMParams['x_tran_key'] = 'YOUR_SANDBOX_TRANSACTION_KEY';

 

// Card data

$authorizeAIMParams['x_card_num'] = ''; // Card Number

$authorizeAIMParams['x_card_code'] = ''; //CCV

$authorizeAIMParams['x_exp_date'] = ''; // Expiration date

 

// Customer infos

$authorizeAIMParams['x_address'] = '';

$authorizeAIMParams['x_zip'] = '';

$authorizeAIMParams['x_first_name'] = '';

$authorizeAIMParams['x_last_name'] = '';

 

// Order data

$authorizeAIMParams['x_invoice_num'] = (int)time(); // Lets generate an unique invoice number

$authorizeAIMParams['x_amount'] = 200; // $200

 

// Make sure we are in test mode

$authorizeAIMParams['x_test_request'] = 1;

 

 

/* Do the CURL request to Authorize.net */

$request = curl_init('https://test.authorize.net/gateway/transact.dll');

curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($request, CURLOPT_POSTFIELDS, http_build_query($authorizeAIMParams));

curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE);

$postResponse = curl_exec($request);

curl_close($request);

 

$response = explode('|', $postResponse);

 

// Init the objects

$authorizeaim = new authorizeAIM();

$cart = new Cart((int)$response[7]);

$customer = new Customer((int)$cart->id_customer);

$message = $response[3];

$amount = (float)$response[9];

 

switch ($response[0]) // Response Code

{

            case 1: // Payment accepted

                        $state = Configuration::get('PS_OS_PAYMENT');

                        break ;

            case 4: // Hold for review

                        $state = Configuration::get('PS_OS_ERROR'); // Can put any custom Order State here

                        break ;

            default: // Error

                        $state = Configuration::get('PS_OS_ERROR');

}

 

$authorizeaim->validateOrder((int)$cart->id, $state, $amount,

            'Payment with Authorize.net', $message, NULL, NULL, false, $customer->secure_key);

 

Note: This is a non-working code provided to offer a conceptualized example of how to execute basic payment processing solutions using Authorize.Net’s AIM module in your PrestaShop store.

 

The source code provided above also employs basic security features such as Card Code Verification (CCV), Address Verification, as well as ‘hold for review’ options.

 

The CCV filter simply allows merchants to compare the card code submitted with the card code on file with the bank. If necessary, the merchant can choose to hold a payment for review for security reasons.

 

The Address Verification Service (AVS) Filter allows merchants to verify a customer’s billing address with the billing address on file with the bank.  Again, this filter grants merchants the option to hold payment processing should security concerns arise.

 

The most recent version of the free Authorize.Net module is available with PrestaShop’s newest v1.4.8 software, now available for download.

You can learn more about PrestaShop by visiting their website. There, you can also download and install the free Authorize.Net module to your store. 

 

Comments
by awahab on ‎09-08-2014 03:08 AM

Hi,

 

Currently i am using authorize.net module in prestashop 1.6 but i am facing one problem, how to charged unsettled transaction to using preasthop module and also transcation id will not return or save in the our database. Can you have any solution regarding this issue.

 

Regards,

Awahab

About the Author
  • Authorize.Net Developer Community Manager
Announcements
Labels