0

Transaction initiated for payment and Got the revert form a transaction and want to display result on page ans save to my DB

    if (!($data = curl_exec($ch))) {
        return ERROR;
    }
    curl_close($ch);
    unset($ch);
    print "\n$data\n";
    $data = explode("&",$data);
    for($i=0;$i<count($data);$i++) {
        $rdata = explode("=",$data[$i]);
        $this->responses[$rdata[0]] = $rdata[1];
    }
    return $this->responses['response'];
  }

Result
response=1&responsetext=SUCCESS&authcode=123456&transactionid=2766128623&avsresponse=N&cvvresponse=M&orderid=1123400&type=sale&response_code=100 

now i want to display each items on page like Responce = 1 Responce Text = Success

1
  • I am not sure but json might help you Commented Aug 3, 2015 at 19:29

3 Answers 3

1

Do it normally as follows -

$data = "response=1&responsetext=SUCCESS&authcode=123456&transactionid=2766128623&avsresponse=N&cvvresponse=M&orderid=1123400&type=sale&response_code=100";

$data = explode("&",$data);


// use print_r if needed
//print_r($data);

foreach($data as $d) {
  echo $d .'<br/>';
}

And For Key/ Label you have to do some pregmatch trick to achieve something like -

Response Text or Response or Auth Code

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

3 Comments

getting error message Warning: Invalid argument supplied for foreach() in
I have tested the code @ WriteCodeOnline. It's working
but i am getting this on display on page response=1&responsetext=SUCCESS&authcode=123456&transactionid=2766128623&avsresponse=N&cvvresponse=M&orderid=1123400&type=sale&response_code=100 so how can i add this into variable, thanks for the support i have just started writing code so sorry to bother you for silly mistake if any
1

it is called query string. You can do

parse_str ('response=1&responsetext=SUCCESS&authcode=123456&transactionid=2766128623&avsresponse=N&cvvresponse=M&orderid=1123400&type=sale&response_code=100', $resp);
print_r($resp);

and give the result array

Array
(
    [response] => 1
    [responsetext] => SUCCESS
    [authcode] => 123456
    [transactionid] => 2766128623
    [avsresponse] => N
    [cvvresponse] => M
    [orderid] => 1123400
    [type] => sale
    [response_code] => 100
)

Or don't say the 2nd argument, and then you will give variables with names as array keys

Comments

0

you can try str_replace() for replacing '&' with ' ', and you can use ucwords() for capitalization

like this

ucwords(str_replace('&',$this->responses['response'];))

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.