This guide covers integrating Authorize.Net with CoCart Preview API. Requires CoCart v4.6+ and a configured Authorize.Net payment gateway.
Overview
Authorize.Net integration with CoCart uses Accept.js for secure tokenization of payment data. This ensures sensitive card information never touches your server while providing PCI DSS compliance and fraud protection.Prerequisites
Before implementing Authorize.Net checkout, ensure you have:- Authorize.Net payment gateway configured in WooCommerce
- Accept.js library loaded in your frontend
- A valid cart with items added
- Customer billing address information
- API Login ID and Public Client Key from Authorize.Net
Integration Flow
1
Load Accept.js Library
Initialize Accept.js with your store’s public client key
2
Collect Payment Details
Securely collect card information from customers using form validation
3
Tokenize Payment Data
Use Accept.js to create secure payment nonce tokens
4
Complete Checkout
Submit checkout with payment nonce to CoCart for processing
Step 1: Load Accept.js Library
Include the Accept.js library in your checkout page:Step 2: Initialize Accept.js
Set up Accept.js with your store’s configuration:- JavaScript
- HTML
Step 3: HTML Structure
Create a checkout form with secure payment fields:Step 4: Initialize Accept.js and Handle Form
Set up Accept.js with payment processing:Step 5: Tokenize Payment Data with Accept.js
Use Accept.js to securely tokenize the payment information:Step 6: Process Checkout
Submit the checkout with tokenized payment data:Complete Integration Example
Here’s a complete working implementation:Error Handling
Handle common Authorize.Net error scenarios:Testing
For development and testing with Authorize.Net:Test Card Numbers
- Visa:
4007000000027 - MasterCard:
5424000000000015 - American Express:
374200000000004 - Discover:
6011000000000012
Test Scenarios
- Declined transaction: Use amount
$0.01 - Error transaction: Use amount
$0.02 - Held transaction: Use amount
$0.03
Troubleshooting
Common Issues
Accept.js Library Not Loading
Accept.js Library Not Loading
Problem: Accept.js is undefined or not loading.Solution: Verify script is loaded correctly:Common causes:
- Wrong URL (production vs sandbox)
- Script blocked by ad blocker or firewall
- CORS or Content Security Policy issues
- Network timeout loading external script
Tokenization Fails with Error Messages
Tokenization Fails with Error Messages
Problem: Getting errors when calling Accept.dispatchData().Solution: Handle Accept.js error responses:Verification checklist:
- Card number is valid (use Luhn algorithm)
- Expiration date is in future (MM/YYYY format)
- CVV is 3-4 digits
- Client key and API login ID are correct
- All required fields are provided
Invalid Client Key or API Login ID
Invalid Client Key or API Login ID
Problem: Authentication errors when tokenizing.Solution: Verify credentials match your environment:Steps to verify:
- Log into Authorize.Net Merchant Interface
- Go to Account → Settings → API Credentials & Keys
- For sandbox: use test API credentials
- For production: use live API credentials
- Ensure WooCommerce Authorize.Net settings match
- Client key format: starts with numbers and letters
- API Login ID: alphanumeric string
Opaque Data Not Being Accepted
Opaque Data Not Being Accepted
Problem: Backend rejects the opaque data token.Solution: Ensure proper data format:Common mistakes:
- Only sending dataValue without dataDescriptor
- Trying to reuse an expired token (tokens expire quickly)
- Sending raw card data instead of opaque data
- Wrong payment_method ID (must be ‘authorizenet’)
Transaction Declined with Reason Codes
Transaction Declined with Reason Codes
Problem: Transactions are being declined.Solution: Handle specific decline codes:Testing declines:
- Use test amounts (0.02, $0.03) in sandbox
- Check AVS settings in Authorize.Net dashboard
- Verify CVV verification is properly configured
- Review fraud detection rules
Sandbox vs Production Configuration
Sandbox vs Production Configuration
Problem: Works in sandbox but fails in production.Solution: Verify environment configuration:Pre-launch checklist:
- Switch Accept.js URL from jstest to js
- Update API Login ID to production credentials
- Update Public Client Key to production key
- Update WooCommerce settings to production mode
- Test with real card (small amount)
- Verify SSL certificate is valid
- Enable production transaction mode
- Configure webhooks for production
- Set up email notifications
Payment Method Not Recognized
Payment Method Not Recognized
Problem: Backend returns “payment method not available” error.Solution: Verify payment method configuration:Checklist:
- Payment method ID is ‘authorizenet’ (check WooCommerce gateway settings)
- Authorize.Net gateway is enabled in WooCommerce → Settings → Payments
- Gateway is properly configured with valid credentials
- Currency is supported by Authorize.Net
- Account is active and in good standing
Form Validation Not Working
Form Validation Not Working
Problem: Unable to validate card input before tokenization.Solution: Implement client-side validation:
Checkout Completes But Order Not Created
Checkout Completes But Order Not Created
Problem: Payment authorized but WooCommerce order fails.Solution: Debug the checkout submission:Debug checklist:
- Check browser console for errors
- Review server PHP error logs
- Check WooCommerce → Status → Logs
- Verify Authorize.Net transaction in merchant interface
- Ensure cart is not empty
- Validate all required billing fields are provided
CORS or Content Security Policy Errors
CORS or Content Security Policy Errors
Problem: Browser blocks Accept.js or API calls.Solution: Configure CSP headers properly:Or in server configuration:Also check:
- Firewall not blocking authorize.net domains
- No ad blockers interfering with payment scripts
- HTTPS is properly configured (Accept.js requires HTTPS)
Debug Mode
Enable detailed logging for troubleshooting:Getting Help
If issues persist:- Authorize.Net Documentation: Accept.js Integration Guide
- Authorize.Net Support: Contact through merchant interface
- Developer Forums: Authorize.Net Community
- WooCommerce Logs: Check WooCommerce → Status → Logs
- Transaction Details: Review in Authorize.Net Merchant Interface
Best Practices
Security
- Always use Accept.js for tokenization
- Never store raw card data
- Use HTTPS for all requests
- Implement proper form validation
- Clear sensitive data after processing
User Experience
- Format card numbers with spaces
- Auto-advance between form fields
- Show real-time validation errors
- Provide clear error messages
- Handle declined cards gracefully
Compliance
- Follow PCI DSS guidelines
- Use Accept.js for PCI compliance
- Implement proper error handling
- Log transactions for auditing
- Test with various card types
Performance
- Load Accept.js asynchronously
- Cache payment contexts
- Implement proper timeouts
- Handle network failures
- Monitor transaction success rates
Advanced Features
Customer Information Manager (CIM)
For storing customer payment methods:Recurring Billing
For subscription payments:Always test your Authorize.Net integration thoroughly using the sandbox environment before going live. Ensure your webhook endpoints are configured to handle transaction notifications and updates.