普通网友 2018-05-12 07:15
浏览 56

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

I have created paytm integration with my website using a user made package for paytm(anand siddharth package).
my ordercontroller is below:

<?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.');
        }
    }
}

i know the call back url is for redirecting after the payment is done. but how do i edit this ordercontroller in order to get redirected to paytm merchant page to make the user do the payment?

</div>
  • 写回答

1条回答 默认 最新

  • duanjiani6826 2018-05-12 07:50
    关注

    I found this and it looks like the tutorial you have been following to get this far:

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

    If this is the case, then simply navigating your browser to http://yoursite.com/event-registration would display the register.php file (which is actually the payment view) mentioned at the very end of the tutorial. Note that this file contains a POST HTML Form, which when submitted sends the User to http://yoursite.com/payment which will initiate the OrderController@order method.

    Edit

    Referring to the title of the question - if you want to redirect a user to another Route, from inside a Controller, then check out the docs here:

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

    In short, using return redirect('route/path') will achieve this.

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测