• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Authorize.Net (net\authorize\api) Helper

Hello CI patrons.

I am just starting an integration for the latest Authorize.Net PHP SDK. 
I couldn't find an example for the newer net\authorize\api method, so I thought I'd start the thread here.

I am planning on this structure:
- Custom library for most of the code in 'libraries'. 
- core -> MY_Controller to store some constants.

The idea is to be able to load the library in the controller as well as call the function there.

Comments welcome if there is a better idea... otherwise, I'll post some code or questions when I have them.

Here is a (very) brief overview of what I did to implement the basic charge CC sample code located here:

This should be a good compass to use in addition to AuthNet's instructions.

First, init your AuthNet sandbox, etc as the README suggests on github.

- I happen to put my constants in a MY_Contoller.php file.
$this->site_constants['ANET_mode'] = "TEST";
// AuthNet Test (Sandbox)
$this->site_constants['MERCHANT_LOGIN_ID'] = "<yourid>";
$this->site_constants['MERCHANT_TRANSACTION_KEY'] = "<yourkey>";

- create an Authorize_net.php php class file
- Note: **special trick** include the autoload.php and 'use' operators / URL's at the very top of the file *before* define!!.. ie:
require 'vendor/autoload.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE", "phplog");

^ very top!! ;-)

// create your method in this class.. ie.:
public function fAuthNetPurchase($vPayAmount, $vPayWebOrdID = 0, $vPayCC, $vPayExpire, $vPayCVV, $vPayZip, $vPayFName, $vPayLName, $vPayPhone, $vPayEmail, $vPayDescription)

- <most of sample code continues here... all the way to:>

// Create the controller and get the response
$controller = new AnetController\CreateTransactionController($request);

- I then created a switch using the constants above to switch between live and sandbox:
if ($vANETMode == 'TEST') {
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
} else {
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment:TongueRODUCTION);
return $response;

// Back in your controller, create your logic (using rest of the SDK sample code) in:
- start with loading the library:

- call to the method:
$data['vPayResponse'] = $this->authorize_net->fAuthNetPurchase($vPayAmount, $vPayWebOrdID, $vPayCC, $vPayExpire, $vPayCVV, $vPayZip, $vPayFName, $vPayLName, $vPayCleanPhone, $vPayEmail, $vOrdDescription);

You can then reference the rest of SDK sample code to create your response parse logic and to formulate error reporting.

Works great!

If you need help or you need a developer.. shoot me a PM.

Good luck!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.