Authorize.Net Payment Gateway Integration using PHP

Authorize.Net is the most popular payment Gateway and widely used payment-enabling mechanisms in many E-commerce applications.Authorize.net payment gateway integration supports the standard Visa, MasterCard, Discover, Apple Pay, Google Pay, PayPal, and all popular similar services.
Authorize.Net provides API services with features like payment transactions, webhooks, and more. In this tutorial, I will explain to you a step-by-step process to integrate Authorize.Net Payment Gateway in PHP for accepting online payments.
Features
  • Easy integration with your web application
  • Filters to Help Fight Fraud
  • No-Hassle Subscriptions and Recurring Billing
  • No update? No extra charge
  • Easy-to-read reports
  • Invoice online for faster payments and more
Create Authorize.Net account to get API Credentials
  • Create Authorize.Net sandbox account.
  • Get Sandbox API credentials API LOGIN ID, TRANSACTION KEY and KEY.
Before started to implement the Authorize.Net Payment Gateway in PHP, look files structure:
  • authorize-net-payment-gateway-integration-in-php
    • anet-sdk-php
    • css
    • templates
    • config.php
    • DBConnection.php
    • AuthorizeNetPayment.php
    • Order.php
    • payment.php
    • index.php
Step 1: Create the database and Table
For this tutorial, you need a MySQL database with the following table:
Step 2: Authorize.Net API Configuration file named config.php
In the config.php file, constant variables of the Authorize.Net API and database settings are defined.
Step 3: Database Connection file named DBConnection.php
Step 4: Create class Request Payment Process file named AuthorizeNetPayment.php
  • Include Authorize.Net PHP SDK.
  • Charge Credit Card
  • Process Payment
Step 5: Create Payment class file named Order.php
Step 6: Create Payment Checkout Form file named index.php
Step 7: Create Payment Process file named payment.php
  • Retrieve user and card information via $_POST method
  • Create a MerchantAuthenticationType object and set API keys
  • Create a CreditCardType object and set credit card details
  • Add the payment data to a PaymentType object
  • Create OrderType object
  • Create CustomerDataType object
  • Create TransactionRequestType object
  • Charge and validate credit card for transaction
  • if API request success, the orde details inserted in database
Create files named (header.php and footer.php)
This file contains the header and footer section of the webpage. The Bootstrap library is used to provide a better UI, so, include it in the header and footer section.
header.php
footer.php