How to Integrate 2Checkout Payment Gateway in PHP

If you have ecommerce website and you want to accept payment via credit card or debit card from your website then 2Checkout Payment Gateway is the easy solution. In this article, i will show you an easy way to integrate 2Checkout Payment Gateway in web application or ecommerce website.

The 2Checkout Payment API allows you to accept payment via credit cards or debit card on your website. With 2Checkout Gateway, your website user or customer can make payment through their credit or debit card.

If you are a Web Developer and want to integrate 2Checkout Payment Gateway, 2Checkout PHP library helps you to connect the Payment API and process the credit or debit card payment. Now i will explain you step by step process to integrate 2Checkout payment gateway in PHP for accept payment online with credit or debit card.

How to create 2Checkout Sandbox Account:

2Checkout sandbox account provide a testing environment to test 2Checkout integration process. Before make 2Checkout payment gateway live or production mode, you need to test the gateway integration in sandbox environment. you need to follow the below steps to generate 2Checkout payment Gateway API Keys in Sandbox Account. We will use this API Keys to test the credit or debit card payment process with 2Checkout Gateway API.

Step-1: Login or Signup (if you don’t have account) into your 2Checkout Sandbox account.

Step-2: After Login you will get an API tab in top bar Menu, Click on API Menu.

Step-3: Go to API Page and generate API Keys. In Key Generation section, you will get Publishable Key and Private Key. Copy both keys and save it in your notepad for later use in the script.

Now First we need to create a Database Table to store order transaction details.

Following Sql query will create “order_transaction” table with some basic field in mysql database

To connect our database we need to create Database Configuration file (dbconfig.php).
dbconfig.php file will contain database host ($host ), username ($dbuser ), password ($dbpass) and database name ($dbname) mysql server credentials.

Create 2Checkout Payment Form (index.php)

You need to create payment form that allow buyer to submit their details like email, name on card, card number, expiration month and year, and CVC.