【问题标题】:How to edit controller in laravel to redirect user to a page如何在 laravel 中编辑控制器以将用户重定向到页面
【发布时间】:2018-05-12 07:15:40
【问题描述】:

我使用用户为 paytm 制作的 packageanand 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.');
        }
    }
}

我知道回调 url 用于在付款完成后进行重定向。但是我如何编辑这个 ordercontroller 以重定向到 paytm 商家页面以使用户进行付款?

【问题讨论】:

  • 你试过return redirect('http://payment_page') 吗?
  • 我的意思是正在使用 paytm 支付网关。我已经按照他们所说的完成了 evrythng,但是当我点击提交按钮时,它说“将您重定向到商家页面”,但它会将我重定向到 localhost/payment/api /地位。 paytm 为我们提供了回调 url 之类的信息。你知道在哪里放置回调 url

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


【解决方案1】:

我找到了这个,它看起来就像你一直遵循的教程:

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 方法。

编辑

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

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

简而言之,使用return redirect('route/path') 就可以实现这一点。

【讨论】:

  • 我的意思是正在使用 paytm 支付网关。我已经按照他们所说的完成了 evrythng,但是当我点击提交按钮时,它说“将您重定向到商家页面”,但它会将我重定向到 localhost/payment/api /地位。 paytm 为我们提供了诸如回调 url 之类的信息。你知道在哪里放置回调 url
  • order() 方法中你有这行:'callback_url' =&gt; url('api/payment/status')
  • 但是是支付完成后重定向用户吗?
  • 该行在付款后将用户重定向到Route::post('payment/status', 'OrderController@paymentCallback'); 路由。它调用paymentCallback() 方法。查看上面写着if($transaction-&gt;isSuccessful() 的位置并将dd('Payment Successfully Paid.'); 替换为return redirect('path/to/go/to')
  • ok 这样 'callback_url' => url('api/payment/status') 用于在付款后重定向用户。但是我怎样才能将用户发送到商家页面。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-06-15
  • 2010-09-07
  • 1970-01-01
  • 2012-10-10
  • 2017-10-08
  • 2019-10-28
  • 1970-01-01
相关资源
最近更新 更多