2017 © Pedro Peláez
 

library authorizenet

Official PHP SDK for Authorize.Net

image

authorizenet/authorizenet

Official PHP SDK for Authorize.Net

  • Monday, July 2, 2018
  • by authorizenet
  • Repository
  • 65 Watchers
  • 255 Stars
  • 1,050,292 Installations
  • PHP
  • 29 Dependents
  • 1 Suggesters
  • 229 Forks
  • 19 Open issues
  • 27 Versions
  • 13 % Grown

The README.md

Authorize.Net PHP SDK

Authorize.net PHP CI Packagist Stable Version, (*1)

Requirements

  • PHP 5.6 to 8.x.x
  • cURL PHP Extension
  • JSON PHP Extension
  • An Authorize.Net account (see Registration & Configuration section below)
  • TLS 1.2 capable versions of libcurl and OpenSSL (or its equivalent)

Migrating from older versions

Since August 2018, the Authorize.Net API has been reorganized to be more merchant focused. Authorize.Net AIM, ARB, CIM, Transaction Reporting, and SIM classes have been deprecated in favor of net\authorize\api. To see the full list of mapping of new features corresponding to the deprecated features, see MIGRATING.md., (*2)

Contribution

TLS 1.2

The Authorize.Net APIs only support connections using the TLS 1.2 security protocol. Make sure to upgrade all required components to support TLS 1.2. Keep these components up to date to mitigate the risk of new security flaws., (*3)

To test whether your current installation is capable of communicating to our servers using TLS 1.2, run the following PHP code and examine the output for the TLS version:, (*4)

<?php
    $ch = curl_init('https://apitest.authorize.net/xml/v1/request.api');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    $data = curl_exec($ch);
    curl_close($ch);

If curl is unable to connect to our URL (as given in the previous sample), it's likely that your system is not able to connect using TLS 1.2, or does not have a supported cipher installed. To verify what TLS version your connection does support, run the following PHP code:, (*5)

<?php 
$ch = curl_init('https://www.howsmyssl.com/a/check');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);

$json = json_decode($data);
echo "Connection uses " . $json->tls_version ."\n";

Installation

Composer

We recommend using Composer. (Note: we never recommend you override the new secure-http default setting). Update your composer.json file as per the example below and then run for this specific release composer update., (*6)

{
  "require": {
  "php": ">=5.6",
  "authorizenet/authorizenet": "2.0.3"
  }
}

After installation through Composer, don't forget to require its autoloader in your script or bootstrap file:, (*7)

require 'vendor/autoload.php';

Custom SPL Autoloader

Alternatively, we provide a custom SPL autoloader for you to reference from within your PHP file:, (*8)

require 'path/to/anet_php_sdk/autoload.php';

This autoloader still requires the vendor directory and all of its dependencies to exist. However, this is a possible solution for cases where composer can't be run on a given system. You can run composer locally or on another system to build the directory, then copy the vendor directory to the desired system., (*9)

Registration & Configuration

Use of this SDK and the Authorize.Net APIs requires having an account on the Authorize.Net system. You can find these details in the Settings section. If you don't currently have a production Authorize.Net account, sign up for a sandbox account., (*10)

Authentication

To authenticate with the Authorize.Net API, use your account's API Login ID and Transaction Key. If you don't have these credentials, obtain them from the Merchant Interface. For production accounts, the Merchant Interface is located at (https://account.authorize.net/), and for sandbox accounts, at (https://sandbox.authorize.net)., (*11)

After you have your credentials, load them into the appropriate variables in your code. The below sample code shows how to set the credentials as part of the API request., (*12)

To set your API credentials for an API request:

..., (*13)

use net\authorize\api\contract\v1 as AnetAPI;

..., (*14)

$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName("YOURLOGIN");
$merchantAuthentication->setTransactionKey("YOURKEY");

..., (*15)

$request = new AnetAPI\CreateTransactionRequest();
$request->setMerchantAuthentication($merchantAuthentication);

..., (*16)

You should never include your Login ID and Transaction Key directly in a PHP file that's in a publically accessible portion of your website. A better practice would be to define these in a constants file, and then reference those constants in the appropriate place in your code., (*17)

Switching between the sandbox environment and the production environment

Authorize.Net maintains a complete sandbox environment for testing and development purposes. The sandbox environment is an exact replica of our production environment, with simulated transaction authorization and settlement. By default, this SDK is configured to use the sandbox environment. To switch to the production environment, replace the environment constant in the execute method. For example:, (*18)

// For PRODUCTION use
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);

API credentials are different for each environment, so be sure to switch to the appropriate credentials when switching environments., (*19)

SDK Usage Examples and Sample Code

To get started using this SDK, it's highly recommended to download our sample code repository: * Authorize.Net PHP Sample Code Repository (on GitHub), (*20)

In that respository, we have comprehensive sample code for all common uses of our API:, (*21)

Additionally, you can find details and examples of how our API is structured in our API Reference Guide: * Developer Center API Reference, (*22)

The API Reference Guide provides examples of what information is needed for a particular request and how that information would be formatted. Using those examples, you can easily determine what methods would be necessary to include that information in a request using this SDK., (*23)

Building & Testing the SDK

Integration tests for the AuthorizeNet SDK are in the tests directory. These tests are mainly for SDK development. However, you can also browse through them to find more usage examples for the various APIs., (*24)

  • Run composer update --dev to load the PHPUnit test library.
  • Copy the phpunit.xml.dist file to phpunit.xml and enter your merchant credentials in the constant fields.
  • Run vendor/bin/phpunit to run the test suite.

You'll probably want to disable emails on your sandbox account., (*25)

Testing Guide

For additional help in testing your own code, Authorize.Net maintains a comprehensive testing guide that includes test credit card numbers to use and special triggers to generate certain responses from the sandbox environment., (*26)

Logging

The SDK generates a log with masking for sensitive data like credit card, expiration dates. The provided levels for logging are debug, info, warn, error. Add use \net\authorize\util\LogFactory;. Logger can be initialized using $logger = LogFactory::getLog(get_class($this)); The default log file phplog gets generated in the current folder. The subsequent logs are appended to the same file, unless the execution folder is changed, and a new log file is generated., (*27)

Usage Examples

  • Logging a string message $logger->debug("Sending 'XML' Request type");
  • Logging xml strings $logger->debug($xmlRequest);
  • Logging using formatting $logger->debugFormat("Integer: %d, Float: %f, Xml-Request: %s\n", array(100, 1.29f, $xmlRequest));

Customizing Sensitive Tags

A local copy of AuthorizedNetSensitiveTagsConfig.json gets generated when code invoking the logger first gets executed. The local file can later be edited by developer to re-configure what is masked and what is visible. (Do not edit the JSON in the SDK). - For each element of the sensitiveTags array, - tagName field corresponds to the name of the property in object, or xml-tag that should be hidden entirely ( XXXX shown if no replacement specified ) or masked (e.g. showing the last 4 digits of credit card number). - pattern[Note] and replacement[Note] can be left "", if the default is to be used (as defined in Log.php). pattern gives the regex to identify, while replacement defines the visible part. - disableMask can be set to true to allow the log to fully display that property in an object, or tag in a xml string. - sensitiveStringRegexes[Note] has list of credit-card regexes. So if credit-card number is not already masked, it would get entirely masked. - Take care of non-ascii characters (refer manual) while defining the regex, e.g. use "pattern": "(\\p{N}+)(\\p{N}{4})" instead of "pattern": "(\\d+)(\\d{4})". Also note \\ escape sequence is used., (*28)

Note: For any regex, no starting or ending '/' or any other delimiter should be defined. The '/' delimiter and unicode flag is added in the code., (*29)

### Transaction Hash Upgrade Authorize.Net is phasing out the MD5 based transHash element in favor of the SHA-512 based transHashSHA2. The setting in the Merchant Interface which controlled the MD5 Hash option is no longer available, and the transHash element will stop returning values at a later date to be determined. For information on how to use transHashSHA2, see the [Transaction Hash Upgrade Guide] (https://developer.authorize.net/support/hash_upgrade/)., (*30)

License

This repository is distributed under a proprietary license. See the provided LICENSE.txt file., (*31)

The Versions

02/07 2018

dev-master

9999999-dev http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

14/06 2018

dev-future

dev-future http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

14/06 2018

1.9.7

1.9.7.0 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

24/03 2018

1.9.6

1.9.6.0 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

21/02 2018

1.9.5

1.9.5.0 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

17/11 2017

1.9.4

1.9.4.0 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

18/07 2017

dev-nodependency

dev-nodependency http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

  • ext-curl *
  • ext-json *
  • php >=5.5

 

The Development Requires

payment authorize.net ecommerce authorizenet

25/04 2017

1.9.3

1.9.3.0 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

03/12 2016

1.9.2

1.9.2.0 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

24/11 2016

1.9.1

1.9.1.0 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

12/08 2016

1.9.0

1.9.0.0 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

15/06 2016

1.8.9

1.8.9.0 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

18/03 2016

1.8.8

1.8.8.0 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

23/02 2016

1.8.7

1.8.7.0 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

20/11 2015

1.8.6.2

1.8.6.2 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

15/09 2015

1.8.5.1

1.8.5.1 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

05/08 2015

1.8.5

1.8.5.0 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

18/06 2015

1.8.4.1

1.8.4.1 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

01/06 2015

1.8.4

1.8.4.0 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

28/05 2015

1.8.3.3

1.8.3.3 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

08/05 2015

dev-ideas

dev-ideas http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

08/05 2015

1.8.3.2

1.8.3.2 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

02/04 2015

1.8.3.1

1.8.3.1 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

19/12 2014

1.8.3

1.8.3.0 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

 

The Development Requires

payment authorize.net ecommerce authorizenet

06/08 2014

1.8.2

1.8.2.0 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

  • ext-curl *
  • ext-json *
  • ext-simplexml *
  • php ~5.3

 

The Development Requires

payment authorize.net ecommerce authorizenet

04/06 2014

1.8.1

1.8.1.0 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

proprietary

The Requires

  • ext-curl *
  • ext-json *
  • ext-simplexml *
  • php ~5.3

 

The Development Requires

payment authorize.net ecommerce authorizenet

29/03 2014

1.8.0

1.8.0.0 http://developer.authorize.net

Official PHP SDK for Authorize.Net

  Sources   Download

The Requires

  • ext-curl *
  • php >=5.2.0

 

payment authorize.net ecommerce authorizenet