在Laravel 5.6中集成PayUMoney

时间:2018-11-21 17:16:27

标签: laravel-5 payment-gateway payumoney

我正在尝试将PayUMoney集成到Laravel 5.6中。根据PayUMoney重定向结帐文档,需要填写表格并将其提交到“ https://sandboxsecure.payu.in/_payment”(使用沙箱网址进行测试)。 提交具有必填字段的html表单后,成功将我重定向到了支付网关页面,并且工作正常。但是我想在我的Laravel控制器中实现它。我做了以下事情:

我的路线是:

    Route::get('book/placeOrder', ['uses' => 'BooksController@placeOrder', 'as' => 'placeOrder']);
Route::get('payumoney/surl', ['uses' => 'BooksController@surl', 'as' => 'payumoneysurl']);
    Route::get('payumoney/furl', ['uses' => 'BooksController@furl', 'as' => 'payumoneyfurl']);

BooksController中的placeOrder函数:

public function sendCurlPostRequest(){
    //code to add order and order details go here

    $salt = "[my merchant salt]";
    $hash_string = '';
    $hash_string .= "[hash string as per the payumoney checkout document]";
    $hash_string .= $salt;
    $hash = strtolower(hash('sha512', $hash_string));

    $data1 = [
        'key' => "[merchant key]",
        'hash' => $hash,
        'txnid' => "or1234txn",
        'amount' => "10",
        'firstname' => "[sample customer name]",
        'email' => "[sample email]",
        'phone' => "[sample phone number]",
        'productinfo' => "book",
        'surl' =>  "[route to success page]",
        'furl' => "[route to failure page]",
        'service_provider' => "payu_paisa",
    ];

    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://sandboxsecure.payu.in/_payment",
        CURLOPT_RETURNTRANSFER => false,
        CURLOPT_FOLLOWLOCATION => 1,
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => $data1,
    ));

    $response = curl_exec($curl);

    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
        echo "cURL Error #:" . $err;
    } else {
        //print_r(json_decode($response));
        //print_r($response);
    }

}

单击购物车页面中的结帐按钮时,我确实被重定向到PayUMoney页面,但该页面未完全加载。仅出现页面的html标题,并且出现页面加载器。由于该页面未加载,因此加载器就是我所能看到的全部内容。

您能帮我在Laravel控制器方法中实现PayUMoney支付网关(最好没有任何第三方插件)的正确方法吗?

请向我指出必要的解决方案...

谢谢

1 个答案:

答案 0 :(得分:0)

我本人只是为客户开始使用PayU-您是否考虑过使用官方SDK?

https://github.com/PayU-EMEA/openpayu_php

或非官方

https://github.com/tzsk/payu