0

I am doing payu automation refunds. In that after sending the request am
getting response as

$res =  Array (
    [status] => 0
    [msg] => Refund FAILURE - Invalid amount
    [error_code] => 105
    [mihpayid] => 569611073
   )

But if check gettype($res) its coming as string... Here am not able to get key and value pairs using

$res['status'] or $res['msg']

Its giving

A PHP Error was encountered
     Severity: Warning
     Message:  Illegal string offset 'status'
     Filename: pgrefunds/pgrefunds.php
     Line Number: 296

suggest me how can get the kay value pairs...

2
  • what if you do a var_dump($res). what do you get then? Commented May 18, 2016 at 13:58
  • I think it's an output of print_r the array you showing in $res Commented May 18, 2016 at 13:59

2 Answers 2

1

In the PayU documentation (https://developer.payubiz.in/documentation/Request-and-Response-format/110) you can read this line:

Web Service API responds back in PHP serialized string by default.

So you must unserialize the content before using it. Depends on the configuration the content can come as JSON or in "array" form (serialized). Depends on the case you must use json_decode or unserialize.

Sign up to request clarification or add additional context in comments.

1 Comment

If you do a print of $res what string do you get exacly?
0

Most likely you are getting a serialized response. You should unserialize the string.

$resArr = unserialize($res);
$resArr['status'];

EDIT

As other answer show the other option is to you json_decode()

$resArr = json_decode($res);
$resArr['status'];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.