2

I was trying to get the message about the payment status(successful, Failed, Cancelled) using this script.

$status = $_POST['status'];

if $status == "success" (
?> CONGRATS! <? AND SO ON

but i was not successful. It is my first time with instamojo so i would kindly ask you guys to help me with it.

Thanks & Regards
Bhaamb

Bhaamb
  • 91
  • 1
  • 10

2 Answers2

2

Considering you're using PHP then you should be using $_GET not $_POST to get the values of query arguments.


Currently we return two query arguments with the redirection URL: payment_id and status.

Here the status argument is only for backwards compatibility and you shouldn't rely on its value to mark the payment as successful because anyone can modify its value.

The correct way is to use the payment_id and query our API to get the payment details.

A sample response may look like:

{
    "payment": {
        "payment_id": "MOJO3815000J72853518",
        "quantity": 1,
        "status": "Credit",                <---- Payment status
        "link_slug": "hello-api-inr-link",
        "link_title": "Hello API INR Link",
        "buyer_name": "A Gehani",
        "buyer_phone": "+9100000000",
        "buyer_email": "akash@instamojo.com",
        "currency": "INR",
        "unit_price": "9.00",
        "amount": "9.00",
        "fees": "0.45",
        "shipping_address": null,
        "shipping_city": null,
        "shipping_state": null,
        "shipping_zip": null,
        "shipping_country": null,
        "discount_code": null,
        "discount_amount_off": null,
        "variants": [],
        "custom_fields": null,
        "affiliate_id": "hiway",
        "affiliate_commission": "3.00",
        "created_at": "2014-12-16T13:17:27.943Z"
    },
    "success": true
}

Here if the value of payment -> status is "Credit" then the payment was successful otherwise it was not.

Again if you're using PHP then you may want to use our API wrapper: Get Details of a Payment using Payment ID


Note that the API also returns "success": true, but don't confuse it for actual payment status.

Ashwini Chaudhary
  • 244,495
  • 58
  • 464
  • 504
1

check if the status in url exists

if(isset($_GET['status']))
   $status =$_GET['status'];

now check if the status is failure or succes

if($status != 'failure')
{
   "redirect to success url"
}
else{
   "redirect to failure url"
}
Austin Rodrigues
  • 451
  • 5
  • 15
  • It's not recommended to rely on `status` query parameter: The `status` argument is only for backwards compatibility and you shouldn't rely on its value to mark the payment as successful because anyone can modify its value. If you someone is verifying and payment using this on their end then it's not the right approach, query the API using `payment_id` and get the status from there. – Ashwini Chaudhary Oct 02 '16 at 05:29