Welcome Guest, Not a member yet? Register   Sign In
Authorize.Net (net\authorize\api) Helper
#1

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.
Reply
#2

Here is a (very) brief overview of what I did to implement the basic charge CC sample code located here:
https://github.com/AuthorizeNet/sample-c...t-card.php

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.
https://github.com/AuthorizeNet/sdk-php/.../README.md



/core
- 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>";



/libraries
- 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:
// LIVE or TEST
if ($vANETMode == 'TEST') {
// TEST URL
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
} else {
// LIVE URL
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment:TongueRODUCTION);
}
return $response;



/controllers
// Back in your controller, create your logic (using rest of the SDK sample code) in:
- start with loading the library:
$this->load->library('authorize_net');

- 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!
Donovan
Reply




Theme © iAndrew 2016 - Forum software by © MyBB