Authnetjson
Library that abstracts Authorize.Net's JSON APIs. This includes the Advanced Integration Method (AIM), Automated Recurring Billing (ARB), Customer Information Manager (CIM), Transaction Reporting, Simple Integration Method (SIM), and Webhooks.
Install / Use
/learn @stymiee/AuthnetjsonREADME
AuthnetJSON
Library that abstracts Authorize.Net's JSON APIs.
Requirements
- PHP 7.2+ (Support for PHP 7.2.0 - 8.*)
- cURL PHP Extension
- JSON PHP Extension
- An Authorize.Net account
Support for PHP versions less than 7.2 has been removed from the master branch. There is a PHP 5.6 compatible branch available for development and releases for 5.6 may continue to be made as long as it is feasible to do so.
Installation
Simply add a dependency on stymiee/authnetjson to your project's composer.json file if you use Composer
to manage the dependencies of your project.
Here is a minimal example of a composer.json file that just defines a dependency on AuthnetJSON:
{
"require": {
"stymiee/authnetjson": "~4.1"
}
}
Basic Usage
Using this library usually consists of three steps:
- Initiate the library with the login credentials for your Authorize.Net account
- Make the API call passing any required parameters as an array
- Check for the results and use them appropriately
NOTE: If you are viewing any of the examples in a browser you will need to fill your Authorize.Net credentials in config.inc.php before usage
Simple usage:
$request = AuthnetApiFactory::getJsonApiHandler(AUTHNET_LOGIN, AUTHNET_TRANSKEY);
$response = $request->getTransactionDetailsRequest([
'transId' => '2162566217'
]);
if ($response->isSuccessful()) {
echo $response->transaction->transactionStatus;
}
The format of the array to be passed during the API call follows the structure outlined in Authorize.Net's Integration Guide.
Using the Authorize.Net Development Server
Authorize.Net provides a development environment for developers to test their integration against. To use this endpoint
(as opposed to their production endpoint) set the optional third parameter of AuthnetApiFactory::getJsonApiHandler() to be 1 or use the built in class constant AuthnetApiFactory::USE_DEVELOPMENT_SERVER:
$json = AuthnetApiFactory::getJsonApiHandler(AUTHNET_LOGIN, AUTHNET_TRANSKEY,
AuthnetApiFactory::USE_DEVELOPMENT_SERVER);
Usage Examples
To help make how this library is used easier to understand example API calls are provided in the example directory.
Examples for all of the current APIs calls are represented. You may need to make adjustments to get some to work as
they may be dependent on valid values created from other API calls (i.e. a void will not work without a valid
transaction ID).
Authorize and Capture (Basic)
$request = AuthnetApiFactory::getJsonApiHandler(AUTHNET_LOGIN, AUTHNET_TRANSKEY);
$response = $request->createTransactionRequest([
'refId' => rand(1000000, 100000000),
'transactionRequest' => [
'transactionType' => 'authCaptureTransaction',
'amount' => 5,
'payment' => [
'creditCard' => [
'cardNumber' => '4111111111111111',
'expirationDate' => '122026',
'cardCode' => '999',
]
]
]
]);
if ($response->isSuccessful()) {
echo $response->transactionResponse->authCode;
}
Authorize and Capture (Full)
$request = AuthnetApiFactory::getJsonApiHandler(AUTHNET_LOGIN, AUTHNET_TRANSKEY);
$response = $request->createTransactionRequest([
'refId' => rand(1000000, 100000000),
'transactionRequest' => [
'transactionType' => 'authCaptureTransaction',
'amount' => 5,
'payment' => [
'creditCard' => [
'cardNumber' => '4111111111111111',
'expirationDate' => '122026',
'cardCode' => '999',
],
],
'order' => [
'invoiceNumber' => '1324567890',
'description' => 'this is a test transaction',
],
'lineItems' => [
'lineItem' => [
0 => [
'itemId' => '1',
'name' => 'vase',
'description' => 'Cannes logo',
'quantity' => '18',
'unitPrice' => '45.00'
],
1 => [
'itemId' => '2',
'name' => 'desk',
'description' => 'Big Desk',
'quantity' => '10',
'unitPrice' => '85.00'
]
]
],
'tax' => [
'amount' => '4.26',
'name' => 'level2 tax name',
'description' => 'level2 tax',
],
'duty' => [
'amount' => '8.55',
'name' => 'duty name',
'description' => 'duty description',
],
'shipping' => [
'amount' => '4.26',
'name' => 'level2 tax name',
'description' => 'level2 tax',
],
'poNumber' => '456654',
'customer' => [
'id' => '18',
'email' => 'someone@blackhole.tv',
],
'billTo' => [
'firstName' => 'Ellen',
'lastName' => 'Johnson',
'company' => 'Souveniropolis',
'address' => '14 Main Street',
'city' => 'Pecan Springs',
'state' => 'TX',
'zip' => '44628',
'country' => 'USA',
],
'shipTo' => [
'firstName' => 'China',
'lastName' => 'Bayles',
'company' => 'Thyme for Tea',
'address' => '12 Main Street',
'city' => 'Pecan Springs',
'state' => 'TX',
'zip' => '44628',
'country' => 'USA',
],
'customerIP' => '192.168.1.1',
'transactionSettings' => [
'setting' => [
0 => [
'settingName' =>'allowPartialAuth',
'settingValue' => 'false'
],
1 => [
'settingName' => 'duplicateWindow',
'settingValue' => '0'
],
2 => [
'settingName' => 'emailCustomer',
'settingValue' => 'false'
],
3 => [
'settingName' => 'recurringBilling',
'settingValue' => 'false'
],
4 => [
'settingName' => 'testRequest',
'settingValue' => 'false'
]
]
],
'userFields' => [
'userField' => [
0 => [
'name' => 'MerchantDefinedFieldName1',
'value' => 'MerchantDefinedFieldValue1',
],
1 => [
'name' => 'favorite_color',
'value' => 'blue',
],
],
],
],
]);
if ($response->isSuccessful()) {
echo $response->transactionResponse->authCode;
}
Create a Customer Profile
$request = AuthnetApiFactory::getJsonApiHandler(AUTHNET_LOGIN, AUTHNET_TRANSKEY);
$response = $request->createCustomerProfileRequest([
'profile' => [
'merchantCustomerId' => '12345',
'email' => 'user@example.com',
'paymentProfiles' => [
'billTo' => [
'firstName' => 'John',
'lastName' => 'Smith',
'address' => '123 Main Street',
'city' => 'Townsville',
'state' => 'NJ',
'zip' => '12345',
'phoneNumber' => '800-555-1234'
],
'payment' => [
'creditCard' => [
'cardNumber' => '4111111111111111',
'expirationDate' => '2026-08',
],
],
],
'shipToList' => [
'firstName' => 'John',
'lastName' => 'Smith',
'address' => '123 Main Street',
'city' => 'Townsville',
'state' => 'NJ',
'zip' => '12345',
'phoneNumber' => '800-555-1234'
],
],
'validationMode' => 'liveMode'
]);
if ($response->isSuccessful()) {
echo $response->customerProfileId;
}
Create a Recurring Subscription
$request = AuthnetApiFactory::getJsonApiHandler(AUTHNET_LOGIN, AUTHNET_TRANSKEY);
$response = $request->ARBCreateSubscriptionRequest([
'refId' => 'Sample',
'subscription' => [
'name' => 'Sample subscription',
'paymentSchedule' => [
'interval' => [
'length' => '1',
'unit' => 'months'
],
'startDate' => '2020-04-18',
'totalOccurrences' => '12',
'trialOccurrences' => '1'
],
'amount' => '10
Related Skills
node-connect
344.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
99.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
344.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
344.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。



