Nucleus Web Technologies
  • Office Shoranur Road, Thrissur
  • Email[email protected]
  • Phone +91-8330862370
  • Contact Us
Nucleus Web Technologies
  • Home
  • Services
    • Graphic Design
      • Branding
      • Marketing Collaterals
      • UI/UX Design
    • Web Development
      • Web Development
      • E-Commerce Website
      • Mobile App Development
      • Website design
    • Digital Marketing
      • Search Engine Optimization
      • Google Marketing
      • Social Media Marketing
      • Email Marketing
    • Content Writing
      • Corporate Communication
      • Internal Communications
    • Online Software
      • Custom made online Software
  • Solutions
    • Domain Registration & Hosting
    • Website Design & Development
    • Search engine optimization (seo)
    • E-Commerce websites
  • Articles
    • Articles
    • Portfolio
    • FAQ
  • About Us
    • Profile
    • Business Partners
    • Jobs
  • Products
  • contact

Article Details

  • Home
  • Article
  • integrate Instamojo payment gateway with CodeIgniter 3
Thumb

integrate Instamojo payment gateway with CodeIgniter 3

To integrate Instamojo payment gateway with CodeIgniter 3, you can follow these steps:

Step 1: Install CodeIgniter 3
If you haven't already installed CodeIgniter 3, you can download it from the official website and set up your project.

Step 2: Get Instamojo API Credentials
Sign up for an Instamojo account and get your API credentials, including the API key and auth token. You'll need these credentials to communicate with Instamojo's API.

Step 3: Create a Controller
Create a controller in CodeIgniter to handle payment requests and responses. For example, you can create a controller named "Payment" using the following command in your terminal:

```bash
php index.php tools/make_controller Payment
```

Step 4: Configure Payment Gateway Settings
In your CodeIgniter project, open the `config.php` file located in `application/config` and set the `base_url` to your project's URL.

Step 5: Create Payment Form
Create a view file where users can fill in payment details and submit the payment request. For example, create a view file named `payment_form.php` in your `application/views` folder.

```php
<!-- application/views/payment_form.php -->
<form method="post" action="<?= base_url('payment/process_payment') ?>">
  <input type="text" name="amount" placeholder="Amount">
  <input type="text" name="name" placeholder="Name">
  <input type="email" name="email" placeholder="Email">
  <button type="submit">Pay Now</button>
</form>
```

Step 6: Process Payment Request
In the `Payment` controller, process the payment request and redirect the user to Instamojo's payment page. Install the Instamojo PHP SDK using composer or manually download and include it in your project.

```bash
composer require instamojo/instamojo-php
```

Now, in your `Payment` controller:

```php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

require APPPATH . 'libraries/Instamojo.php';

class Payment extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
    }

    public function index() {
        $this->load->view('payment_form');
    }

    public function process_payment() {
        $api_key = 'YOUR_INSTAMOJO_API_KEY';
        $auth_token = 'YOUR_INSTAMOJO_AUTH_TOKEN';
        $api = new Instamojo\Instamojo($api_key, $auth_token, 'https://www.instamojo.com/api/1.1/');

        $data = array(
            'purpose' => 'Payment for Order', // Purpose of the payment
            'amount' => $this->input->post('amount'), // Amount to be paid
            'buyer_name' => $this->input->post('name'), // Buyer's name
            'email' => $this->input->post('email'), // Buyer's email
            'send_email' => true,
            'redirect_url' => base_url('payment/payment_success'),
            'webhook' => base_url('payment/webhook'), // Webhook URL for handling payment updates
        );

        try {
            $response = $api->paymentRequestCreate($data);
            $payment_url = $response['longurl'];
            redirect($payment_url);
        } catch (Exception $e) {
            echo 'Error: ' . $e->getMessage();
        }
    }

    public function payment_success() {
        // Handle successful payment here
        echo 'Payment Successful';
    }

    public function webhook() {
        // Handle webhook data here
    }
}
```

Remember to replace `'YOUR_INSTAMOJO_API_KEY'` and `'YOUR_INSTAMOJO_AUTH_TOKEN'` with your actual API credentials obtained from your Instamojo account.

Step 7: Handling Payment Response
Create methods in the `Payment` controller to handle successful and failed payment responses. The `process_payment` method redirects the user to Instamojo's payment page, and after successful payment, the user will be redirected back to the `payment_success` method. In this method, you can handle the successful payment completion.

In the Instamojo dashboard, you can also set a webhook URL that Instamojo will use to send payment updates. Implement the `webhook` method to handle these updates.

Conclusion

This CodeIgniter 3 code demonstrates how to integrate the Instamojo payment gateway into your web application. Users can enter payment details in the form, and upon submitting, they will be redirected to the Instamojo payment page for secure payment processing. After successful payment, the user will be redirected back to the website, and you can handle the payment completion in the `payment_success` method. Additionally, you can implement the `webhook` method to handle payment updates from Instamojo, ensuring a seamless payment experience for your users.

  • 22 Jul, 2023

Latest Articles

  • Integrating PhonePe as a payment gateway in CodeIgniter 3 involves following steps
    Integrating PhonePe as a payment gateway in CodeIgniter 3 involves following steps
    22 Jul, 2023
  • Advice on Selecting the Correct Technology Stack for a Web Development Project
    Advice on Selecting the Correct Technology Stack for a Web Development Project
    29 Nov, 2022
  • What makes branding so crucial?
    What makes branding so crucial?
    27 Oct, 2022
  • What sets static websites apart from dynamic ones?
    What sets static websites apart from dynamic ones?
    25 Oct, 2022
  • Which Should You Choose: An In-House Team or Outsourcing?
    Which Should You Choose: An In-House Team or Outsourcing?
    20 Oct, 2022
  • Ideas on Communication for Start-ups
    Ideas on Communication for Start-ups
    17 Oct, 2022
  • Do you prefer a customized or templated website?
    Do you prefer a customized or templated website?
    13 Oct, 2022
  • Is conventional marketing being displaced by digital marketing?
    Is conventional marketing being displaced by digital marketing?
    11 Nov, 2021
  • Tips for Writing SEO Content
    Tips for Writing SEO Content
    11 Nov, 2021
  • Various Kinds of Web Development
    Various Kinds of Web Development
    30 Oct, 2021

Portfolio

  • Inspire Solution
  • Trentrix
  • Griantek
  • CADD Centre Thrissur
  • DreamZone Thrissur
  • Galaxy Educational Services
  • Shalom Institute of Mental Health and Research
  • Travel Designer

By understanding your business, Nucleus Web Technologies create a website design tailored to the needs of your site and allow you to tackle the team. Our people design the right website that fulfils your desire to achieve the right brand identity and identity.

  • Tweet
SiteLock

Recent Posts

  • integrate Instamojo payment gateway with CodeIgniter 3
    Jul 22, 2023
  • Integrating PhonePe as a payment gateway in CodeIgniter 3 involves following steps
    Jul 22, 2023

Quick Links

Home
Graphic Design
Web Development
Digital Marketing
Content Writing
Online Software
Contact

© Copyright © 2006-2026. All Rights Reserved by Nucleus WT

  • Terms & Conditions
  • Privacy Policy
  • Refund Policy
  • Support