如何在laravel中编辑控制器以将用户重定向到页面

时间:2018-05-12 07:15:41

标签: php laravel laravel-5 laravel-5.2 paytm

我使用用户制作的为paytm( anand siddharth package )创建了与我的网站的paytm集成。
我的ordercontroller位于以下位置:



<?php


namespace App\Http\Controllers;


use PaytmWallet;
use Illuminate\Http\Request;
use App\EventRegistration;


class OrderController extends Controller
{


    /**
     * Redirect the user to the Payment Gateway.
     *
     * @return Response
     */
    public function register()
    {
        return view('payment');
    }


    /**
     * Redirect the user to the Payment Gateway.
     *
     * @return Response
     */
    public function order(Request $request)
    {


        $this->validate($request, [
            'name' => 'required',
            'mobile_no' => 'required',
            'email' => 'required',
        ]);


        $input = $request->all();
        $input['order_id'] = $request->mobile_no.rand(1,100);
        $input['fee'] = 50;


        EventRegistration::create($input);


        $payment = PaytmWallet::with('receive');
        $payment->prepare([
          'order' => $input['order_id'],
          'user' => 'your paytm user',
          'mobile_number' => 'your paytm number',
          'email' => 'your paytm email',
          'amount' => $input['fee'],
          'callback_url' => url('api/payment/status')
        ]);
        return $payment->receive();
    }


    /**
     * Obtain the payment information.
     *
     * @return Object
     */
    public function paymentCallback()
    {
        $transaction = PaytmWallet::with('receive');


        $response = $transaction->response();
        $order_id = $transaction->getOrderId();


        if($transaction->isSuccessful()){
          EventRegistration::where('order_id',$order_id)->update(['status'=>2, 'transaction_id'=>$transaction->getTransactionId()]);


          dd('Payment Successfully Paid.');
        }else if($transaction->isFailed()){
          EventRegistration::where('order_id',$order_id)->update(['status'=>1, 'transaction_id'=>$transaction->getTransactionId()]);
          dd('Payment Failed.');
        }
    }
}
&#13;
&#13;
&#13;

我知道回拨网址是在付款完成后重定向。但是如何编辑此ordercontroller以便重定向到paytm商家页面以使用户付款?

1 个答案:

答案 0 :(得分:0)

我发现了这个,它看起来像你一直关注的教程:

http://itsolutionstuff.com/post/paytm-payment-gateway-integration-example-in-laravel-5example.html

如果是这种情况,那么只需将浏览器导航到http://yoursite.com/event-registration即可显示教程最后提到的 register.php 文件(实际上是付款视图) 。请注意,此文件包含POST HTML表单,在提交时会将用户发送到http://yoursite.com/payment,这将启动OrderController@order方法。

修改

参考问题的标题 - 如果您想从Controller内部将用户重定向到另一个路由,请在此处查看文档:

https://laravel.com/docs/5.6/redirects

简而言之,使用return redirect('route/path')即可实现此目标。