How to Integrate Instamojo Payment Gateway in Python using Flask

This article is a very important article. I mean in this How to Integrate Instamojo Payment Gateway in Python using Flask we are going to know very clearly about this. We hope you like this article. Please comment if you liked this article.

How to Integrate Instamojo Payment Gateway in Python using Flask

How to Integrate Instamojo Payment Gateway in Python using Flask

 install a dependency using the following command

pip install instamojo-wrapper
from flask import Flask, render_template, request,redirect
from instamojo_wrapper import Instamojo

API_KEY = "####yourapikey####"

AUTH_TOKEN = "####yourauthtoken####"

api = Instamojo(api_key=API_KEY,auth_token=AUTH_TOKEN,endpoint='https://test.instamojo.com/api/1.1/')

app = Flask(__name__)

@app.route('/')
def home():
   return render_template('home.html')

@app.route('/success')
def success():
    return render_template('success.html')

@app.route('/pay',methods=['POST','GET'])
def pay():
    if request.method == 'POST':
        name = request.form.get('name')
        purpose = request.form.get('purpose')
        email = request.form.get('email')
        amount = request.form.get('amount')
        
        response = api.payment_request_create(
        amount=amount,
        purpose=purpose,
        buyer_name=name,
        send_email=True,
        email=email,
        redirect_url="http://localhost:5000/success"
        )
        
        return redirect(response['payment_request']['longurl'])
    
    else:
        
        return redirect('/')

    
if __name__ == '__main__':
   app.run(debug=True)

Read also:- Deploy Python Flask App on Heroku

home.html

<!DOCTYPE html>
<html>
  <head>
    <title>Instamojo Payment Integration in Python</title>
    <link
      rel="stylesheet"
      href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
    />
  </head>
  <body>
    <div class="container">
      <h1 class="text-center">Instamojo Payment</h1>
      <form action="/pay" method="POST">
        <div class="form-group">
          <input
            type="text"
            class="form-control"
            required
            name="name"
            id=""
            placeholder="name"
          />
        </div>
        <div class="form-group">
            <input
              type="text"
              class="form-control"
              required
              name="purpose"
              id=""
              placeholder="purpose"
            />
          </div>
        <div class="form-group">
          <input
            type="email"
            class="form-control"
            required
            name="email"
            id=""
            placeholder="email"
          />
        </div>
        <div class="form-group">
            <input
              type="number"
              class="form-control"
              required
              name="amount"
              id=""
              placeholder="amount"
            />
          </div>
        <div class="form-group">
            <button class="btn btn-danger btn-block">
                Create Payment Link
            </button>
        </div>
      </form>
    </div>
  </body>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</html>

success.html

<!DOCTYPE html>
<html>
  <head>
    <title>Instamojo Payment Gateway in Python</title>
    <link
      rel="stylesheet"
      href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
    />
  </head>
  <body>
      <div class="container">
          <h1 class="text-center">
              Your Payment is successful
          </h1>
          <p>Please check your confirmation email</p>
      </div>
</body>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</html>

Final Words

How to Integrate Instamojo Payment Gateway in Python using Flask We have clearly identified the information you need through the article. If in doubt please let us know your doubts via the comment box Thank you.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment