PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, November 11, 2022

[FIXED] How to Redirect Success or Failure Payment in Razorpay

 November 11, 2022     javascript, payment-gateway, php     No comments   

Issue

I am New to Integrate Payment Gateway.

How to Redirect a URL after Success or Failure Payments in Razorpay. I want Js Code. I thing handler function can use that redirect. How to Use them

var options = {
    "key": "rzp_test_aIfnpuWEudWnID",
    "amount": "35000", // 2000 paise = INR 20
    "name": "Vanakkam Chennai",
    "description": "I Run.. Becasue .. I Care",
    "image": "http://vanakkamchennai.com/images/about/chennai_2017.jpg",
    "callback_url": 'https://www.google.com',
    "handler": function (response){

            alert(response.razorpay_payment_id);


    },
    "prefill": {
        "name": "Harshil Mathur",
        "email": "harshil@razorpay.com"
    },
    "notes": {
        "address": "Hello World"
    },
    "theme": {
        "color": "#F37254"
    }
};

Solution

The way to redirect a user is to alter the value of location.href. Remove alert(response.razorpay_payment_id); and redirect the user based on if the payment id is defined or not:

// alert(response.razorpay_payment_id);
if (typeof response.razorpay_payment_id == 'undefined' ||  response.razorpay_payment_id < 1) {
  redirect_url = '/you-owe-money.html';
} else {
  redirect_url = '/thnx-you-paid.html';
}
location.href = redirect_url;

My example urls are humorous; replace them with your actual urls. Also, you can read more detailed information on location.href and location redirection here.



Answered By - WEBjuju
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing