Download the PHP package squareetlabs/laravel-authorizenet without Composer
On this page you can find all versions of the php package squareetlabs/laravel-authorizenet. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download squareetlabs/laravel-authorizenet
More information about squareetlabs/laravel-authorizenet
Files in squareetlabs/laravel-authorizenet
Package laravel-authorizenet
Short Description This package allows laravel application to use authorizenet api easily.
License MIT
Informations about the package laravel-authorizenet
Laravel Authorize.Net Package
A comprehensive Laravel package for seamless integration with Authorize.Net payment gateway. This package provides an elegant, fluent interface for managing customer profiles, payment methods, transactions, subscriptions, and more.
Features
- ✅ Customer Profile Management - Create and manage customer profiles on Authorize.Net
- ✅ Payment Profile Management - Store payment methods securely without PCI compliance requirements
- ✅ Direct Card Transactions - Process one-time card payments
- ✅ Recurring Subscriptions - Create and manage subscription payments
- ✅ Transaction Management - Process charges, refunds, and query transactions
- ✅ Eloquent Models - Built-in models for local storage of payment profiles
- ✅ Type-Safe - Full PHP 8.1+ type hints and return types
- ✅ Laravel 10/11/12 Compatible - Works with modern Laravel versions
- ✅ Well-Tested - Comprehensive test coverage
Requirements
- PHP >= 8.1
- Laravel >= 10.0
- Authorize.Net account (sandbox or production)
- cURL extension enabled
Installation
Install the package via Composer:
Publish Configuration
Publish the configuration file (optional):
Run Migrations
The package requires database tables to store customer and payment profiles. Run the migrations:
This will create two tables:
user_gateway_profiles- Stores Authorize.Net customer profile IDsuser_payment_profiles- Stores payment method information
Setup User Model
Add the ANetPayments trait to your User model:
Configuration
Add your Authorize.Net credentials to your .env file:
You can obtain these credentials from your Authorize.Net Merchant Interface:
- Sandbox: https://sandbox.authorize.net
- Production: https://account.authorize.net
Navigate to Settings > Security Settings > API Credentials & Keys to find your credentials.
Basic Usage
Once configured, you can access Authorize.Net functionality through the anet() method on your User model:
Customer Profiles
Customer profiles are required before you can store payment methods. Authorize.Net uses customer profiles to securely store payment information without requiring PCI compliance on your end.
Create a Customer Profile
Get Customer Profile ID
The customer profile ID is automatically stored in your database using the UserGatewayProfile model.
Payment Profiles
Payment profiles allow you to store payment methods securely without handling sensitive card data. This is achieved through Authorize.Net's Accept.js, which sends payment data directly to Authorize.Net.
Creating a Payment Profile with Accept.js
Frontend (JavaScript):
Backend (Laravel):
Get Payment Profiles
Using Eloquent Models
You can also work directly with the Eloquent models:
Charging Payment Profiles
Once you have a payment profile, you can charge it:
Refunds
Refund a previous transaction:
Direct Card Transactions
For one-time payments without storing payment methods, you can process direct card transactions:
Card Service Methods
Subscriptions
Create and manage recurring subscription payments:
Create a Subscription
Get Subscription
Update Subscription
Cancel Subscription
Get Subscription Status
List Subscriptions
Subscription Aliases
You can use any of these methods to access the subscription service:
Transaction Management
Work with transaction responses to check status and retrieve information:
Get Transactions by Batch ID
Working with Transaction Responses
All transaction methods return a CreateTransactionResponse object. Here's how to work with it:
Eloquent Models
The package provides two Eloquent models for working with stored data:
UserGatewayProfile
Represents a customer profile stored locally:
UserPaymentProfile
Represents a payment method stored locally:
Environment Configuration
The package automatically uses the appropriate environment based on your Laravel app environment:
- Local/Testing: Uses Authorize.Net Sandbox
- Production: Uses Authorize.Net Production
You can override this by setting AUTHORIZE_NET_ENVIRONMENT in your .env file:
Error Handling
Always wrap Authorize.Net operations in try-catch blocks:
Testing
Running Package Tests
The package includes a comprehensive test suite. To run the tests:
Test Coverage
The package includes tests for:
- ✅ Unit Tests - Models, Services, and core functionality (all passing)
- ✅ Integration Tests - API interactions with Authorize.Net (require valid credentials)
- ✅ Model Tests - Eloquent models and relationships (all passing)
- ✅ Service Tests - Payment processing, subscriptions, and transactions
Test Environment Setup
For testing, you need to configure your .env file with Authorize.Net sandbox credentials:
Note: Some integration tests require valid Authorize.Net sandbox credentials and will fail if credentials are invalid or missing. This is expected behavior as these tests verify actual API connectivity.
Testing in Your Application
When testing your own application that uses this package:
Option 1: Use Authorize.Net Sandbox (Recommended)
Configure your test environment to use Authorize.Net's sandbox:
Option 2: Mock Authorize.Net Responses
Use PHPUnit's mocking capabilities to mock API responses:
Option 3: Use Feature Flags
Skip actual API calls during testing:
Test Database Setup
The package tests use an in-memory SQLite database. The package automatically creates the necessary tables during testing. Note: The package does not create a users table migration - your application should already have this table.
Test Results
Current test status:
- Total Tests: 89
- Passing: ~53 (unit tests and model tests)
- Integration Tests: Require valid Authorize.Net credentials
- Model Tests: 100% passing (10/10)
- Service Tests: Unit tests passing, integration tests require API credentials
Best Practices for Testing
- Use Sandbox Environment: Always use Authorize.Net sandbox credentials for testing
- Mock External Calls: For unit tests, mock Authorize.Net API responses
- Test Error Handling: Test both success and failure scenarios
- Isolate Tests: Each test should be independent and not rely on previous test data
- Use Test Database: Always use a separate test database, never test against production data
API Reference
ANet Class Methods
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This package is open-sourced software licensed under the MIT license.
Support
For issues and questions:
- GitHub Issues: Create an issue
- Authorize.Net Documentation: https://developer.authorize.net/
Changelog
Version 2.0.0
- ✅ Updated to Laravel 11/12 compatibility
- ✅ PHP 8.1+ required
- ✅ Modernized codebase with type hints and return types
- ✅ Reorganized services into
Services/directory - ✅ Added Eloquent models for database operations
- ✅ Improved error handling and validation
- ✅ Updated SDK to version 2.0.3
Made with ❤️ for the Laravel community
All versions of laravel-authorizenet with dependencies
ext-curl Version *
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/database Version ^10.0|^11.0|^12.0
authorizenet/authorizenet Version ^2.0.3

