Authorize.Net Payment Gateway Integration using PHP

authorize_net-payment-gateway-integration-using-php

Authorize.Net payment gateway is one of the most used payment systems in applications for eCommerce. It supports the standard Visa, MasterCard, Discover, Google Pay, PayPal, Apple Pay, and all popular similar services. The payment gateway Authorize. Net provides a simple and effective solution for integrating an online checkout system with a smooth payment experience.

The payment gateway is the most important part of the online payment application. There are different payment gateways available to integrate the credit card payment system on the website. Like the Stripe payment gateway, 2Checkout Payment Gateway, Paypal Payment System. In this article, we will see how to make payment transactions to charge a credit card using the Authorize.Net Payment Gateway in PHP.

Steps to Integrate Authorize.Net Payment Gateway

Step-1: Create Authorize.Net sandbox account to get API Login id ad Key from here. After account creation, Sandbox is used to test the integration of the payment gateway. The following screenshot shows the generated API login Id and key.

Copy and paste the API Login ID and Transaction Key on the notepad to later use in the script.

Step-2: Create Database Table

To store the transaction details, a table needs to be created in the database.  So, copy the below MySQL query and run this query in the MySQL database.

Step-3: Create Authorize.Net API and Database Configuration (authConfig.php)

Note: Authorize.Net API Login ID and Transaction Key will be found in the API Credentials & Keys section of your Authorize.Net merchant account.

Step-4: Create Database Connection (dbconfig.php)

Step-5: Payment Checkout Form (index.php)

Before any HTML code, including the configuration file. Create an HTML form for collecting information from the customer on the user (such as e-mail and name) and card details (card number, expiration and CVC no.). After submission of the form, data is submitted to the script (payment.php) for processing the credit card payment.

Step-6: Import PHP SDK to access Authorize.Net API

For the processing of payments, we need the PHP SDK to access the Autorize.Net API. The composer must import this SDK. Make sure you install the composer on your computer and create a composer.json file and add the below script.

Then, run the following command.

After this, you will get the vendor folder. We will use this folder to the next step for the Authorize.Net payment process.

Step-7: Create (AuthorizeNetPayment.php) file to add the Request Payment Process code

Step-8: Create (payment.php) to Charge Credit Card and get Authorize.net Payment Response and Update Database

The AuthorizeNetPayment class instance is created in the below PHP code and the request for a charge credit card is created. As a result, the function returns the payment response in JSON format.

Test Card Details

To test the Authorized.Net payment API integration, use the following test credit card information.

Expiration date: 10/2020

CVV: 123

Switch Authorize.Net Payment Mode from Sandbox to Live

It’s time to go live after testing the payment flow in the sandbox environment of Authorize. Net. Switching the payment mode from the sandbox to live is very simple.

  1. Login to your Authorize.Net merchant account.
  2. Click the Account link from the top navigation menu bar.
  3. Click the Settings link in the left-side menu panel. Go to the Security Settings » General Security Settings section and click the API Credentials & Keys.
  4. In the API Credentials & Keys page,
    • You will get the API Login ID.
    • For Transaction Key, select New Transaction Key and Submit.
  5. In the authConfig.php file,
    • Replace the Sandbox API keys by the Live API credentials (Login ID and Transaction Key).
    • Set environment to PRODUCTION

Integrate Recurring Stripe Subscription Payment with PHP

How to Integrate 2Checkout Payment Gateway in PHP

How to Integrate Paypal Payment System with Paypal API in PHP and MySql

Conclusion:

The payment gateway Authorize. Net provides a simple and powerful solution for enhancing the online checkout system with a smooth payment experience. Authorize. Net offers features such as payment transactions webhooks and more for building a payment solution in our application.

Related posts