Wednesday, 26 June 2013

CURL PHP MyGate Payment gateway

I am trying to post some details to mygate payment gateway. If i use a normal form and post to the url, it generates a token id for that specific session and internally redirects the page to the details capturing page.

As i am using curl to do so, i get a success message but i am unable to get the required page.

Is it possible to load the same page in a new tab using curl, I suspect that would help me in some way.

Any other solution would also be appreciated.

Code i have tried is:

 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$ch = curl_init();
 
 //set the url, number of POST vars, POST data
 curl_setopt($ch,CURLOPT_URL, $url);
 curl_setopt($ch,CURLOPT_POST, count($fields));
 curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
 
 curl_setopt($ch, CURLOPT_VERBOSE, true);
 curl_setopt($ch, CURLOPT_SSLVERSION, 3);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER,0);
 
 //turning off the server and peer verification(TrustManager Concept).
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2);      
 
 
 $result = curl_exec($ch);
 
 if(!$result)
 {
     echo curl_error($ch);
 }
 else
 {
     echo $result;
 }
 
 //close connection
 curl_close($ch);

2 comments :

  1. Since its redirecting to a page on success, You can get the location of the redirected url.

    You can get the redirect URL by setting some curl options.

    ?
    1
    2
    3
    4
    5
    6
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $a = curl_exec($ch);
    if(preg_match('#Location: (.*)#', $a, $r))
    $l = trim($r[1]);


    $l would be the redirect location. You can get the url and redirect your page to the location.

    $r will contain an array with location url.

    ReplyDelete
  2. learn more from www.drtuts.com

    ReplyDelete