Redirect to PayUMoney in Laravel using Curl
P粉877114798
P粉877114798 2023-07-22 20:17:03
0
1
538

I want to redirect from my PHP server to PayUMoney payment gateway using Curl.

I am using Laravel framework but I don't want to use HTML/Blade methods to trigger the payment gateway.


$posted = array();

$posted['key'] = $MERCHANT_KEY;
$posted['hash'] = $hash;
$posted['txnid'] = $txnid;
$posted['firstname'] = $firstname;
$posted['email'] = $email;
$posted['phone'] = $phone;
$posted['amount'] = $amount;
$posted['productinfo'] = $productinfo;
$posted['surl'] = $surl;
$posted['furl'] = $furl;
                
ini_set('display_errors', 1);

$c = curl_init();

$url = "https://test.payu.in/_payment";
curl_setopt_array($c, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => 0,
    CURLOPT_FOLLOWLOCATION => 1,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $posted,
));
$response = curl_exec($c);

But this code shows the output as below, so it cannot be completely redirected to the payment gateway (https://i.stack.imgur.com/WmDFS.png).

P粉877114798
P粉877114798

reply all(1)
P粉020085599
$posted = array(
        'key' => $MERCHANT_KEY,
        'hash' => $hash,
        'txnid' => $txnid,
        'firstname' => $firstname,
        'email' => $email,
        'phone' => $phone,
        'amount' => $amount,
        'productinfo' => $productinfo,
        'surl' => $surl,
        'furl' => $furl,
    );



$url = "https://test.payu.in/_payment";
$c = curl_init();
curl_setopt_array($c, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => false,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => http_build_query($posted),
    CURLOPT_HEADER => false,
));
curl_setopt($c, CURLOPT_VERBOSE, true);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);

$response = curl_exec($c);
curl_close($c);

Redirect the page to PayUmoney payment gateway.

return Redirect::away($url)->withInput($request->input());

Or you can use:

header("Location: $url");
exit;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template