Tech Arise

2Checkout Payment Gateway Integration in Codeigniter

2Checkout Payment Gateway API allows you to accept payment credit cards or debit card on your web application. 2Checkout PHP library helps to connect the Payment API, create a charge against credit card or debit card and payment process. In this article, I will explain you step by step process to integrate 2Checkout Payment Gateway in PHP to accept online payment.
Follow some basic Steps 2Checkout payment gateway
Step-1: Create a 2Checkout account and get API keys
Publishable Key and Private Key
Before started to implement the 2Checkout Payment Gateway Integration in Codeigniter, look files structure:
Step-2: Create MySQL Database and Table
1- product table
2- orders table
Open application/config/autoload.php file and add/update code like as bellow:
Step-3: Define constants
Update file named constants.php inside “application/config/” folder.
Open application/config/database.php file and add constants like as bellow:
Download 2Checkout PHP library
The 2Checkout PHP library is used to process the card transaction using Payment API. All the library files copy and paste application/third_party folder.
Step-4: Create file (TwoCheckoutApi)
Create a file named TwoCheckoutApi.php inside “application/libraries” folder.
Step-5: Create a controller file
Create a controller file named TwoCheckoutPayment.php inside “application/controllers” folder.
Step 6: Create a model file
Create a model file named Payment_model.php” inside “application/models” folder.
Open application/config/routes.php file and add code like as bellow:
Step-7: 2Checkout Token and Validate Card with 2Checkout.js:
Step-8: The following JavaScript code is used to generate token with 2Checkout library.
Step 9: Create a view(header)
Create a view file named header.php inside “application/views/templates” folder
This view contains the header section of the webpage. The Bootstrap library is used to provide a better UI, so, include it in the header section.
Step 10: Create a view(footer)
Create a view file named footer.php inside “application/views/templates” folder.
This view contains the footer section of the webpage.
Step 11: Create a view(index)
Create a view file named index.php inside “application/views/2checkout” folder.
Step 12: Create a view(checkout)
Create a view file named checkout.php inside “application/views/2checkout” folder.
Step 13: Create a view(success)
Create a view file named success.php inside “application/views/2checkout” folder.

Exit mobile version