2017-08-23 6 views
0

私は今、私が開発していたアプリケーションでこれを使用しようとしているhttp://laravelcode.com/post/how-to-integrate-paypal-payment-gateway-in-laravel-54LaravelのPayPalチュートリアルでは、

のチュートリアル以下となっているが、私はそうしようとPHP/Laravelにはかなり新しいですこれらのpaypal関数を私が既に構築した自分自身のコントローラ/フォームに入れるためです。

私には、../bookings/createのフォームを持つコントローラ「BookingsController」があります。EUが送信ボタンを押すと、DBに情報が入力され、完璧に動作し、PayPalビットを実行します。 EUをPayPalのチェックアウトに連れて行きます。ここで私は元気を出しています。

マイコントローラー: -

<?php 

namespace App\Http\Controllers; 

use Illuminate\Http\Request; 
use App\Market; 
use App\Stall; 
use App\Booking; 
use Auth; 
use GuzzleHttp\Transaction; 

class BookingsController extends Controller 
{ 
    /** 
    * Display a listing of the resource. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function index() 
    { 
     // 
    } 

    /** 
    * Show the form for creating a new resource. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function create() 
    { 
     $market = Market::where('is_active', true)->orderBy('name')->pluck('name','id'); 
     $stall = Stall::pluck('name','id')->all(); 
     return view ('bookings.create', compact('market','stall')); 
    } 

    /** 
    * Store a newly created resource in storage. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @return \Illuminate\Http\Response 
    */ 
    public function store(Request $request) 
    { 
     $this->validate($request, [ 
      'name' => 'required', 
      'email' => 'email', 
      'address' => 'required', 
      'phone' => 'required', 
     ]); 

     //Uncomment the below line to test form values 
     // return $request->all(); 
     $booking = new Booking; 
     $booking->name = $request->input('name'); 
     $booking->email = $request->input('email'); 
     $booking->address = $request->input('address'); 
     $booking->phone = $request->input('phone'); 
     $booking->market_id = $request->input('market_id'); 
     $booking->stall_id = $request->input('stall_id'); 
     $booking->itemtype = $request->input('itemtype'); 
     $booking->clothesrail = $request->input('clothesrail'); 
     $booking->businessname = $request->input('businessname'); 
     $booking->insurance = $request->input('insurance'); 

     //Get the stall cost 
     //$stallPrice = Stall::pluck('cost')->where('id', '=', $booking->stall_id); 
     $stallPrice = 15; 

     //Check if the user is logged in. If so then submit the user_id 
     if (Auth::check()) 
     { 
      $booking->user_id = auth()->user()->id; 
     } 


     //return $stallPrice; 
     //$booking->save(); 

     //Redirect user based on logged in session_status 
     if (Auth::check()) 
     { 
     return redirect('/dashboard')->with('success', 'Stall Booked!'); 
     } 
     return redirect('/confirm')->with('success', 'Stall Booked!'); 
    } 

    /** 
    * Display the specified resource. 
    * 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function show($id) 
    { 
     // 
    } 

    /** 
    * Show the form for editing the specified resource. 
    * 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function edit($id) 
    { 
     $booking = Booking::find($id); 
     return view('bookings.edit')->with('booking', $booking); 
    } 

    /** 
    * Update the specified resource in storage. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function update(Request $request, $id) 
    { 
     $this->validate($request, [ 
     'name' => 'required', 
     'email' => 'email', 
     'address' => 'required', 
     'phone' => 'required', 
     ]); 

    $booking = Booking::find($id); 
    $booking->name = $request->input('name'); 
    $booking->email = $request->input('email'); 
    $booking->address = $request->input('address'); 
    $booking->phone = $request->input('phone'); 
    $booking->market_id = $request->input('market_id'); 
    $booking->stall_id = $request->input('stall_id'); 
    $booking->itemtype = $request->input('itemtype'); 
    $booking->clothesrail = $request->input('clothesrail'); 
    $booking->businessname = $request->input('businessname'); 
    $booking->insurance = $request->input('insurance'); 

    //Check if the user is logged in. If so then submit the user_id 
    if (Auth::check()) 
    { 
     $booking->user_id = auth()->user()->id; 
    } 

    $booking->save(); 

    return redirect('/admin/dashboard')->with('success', 'Booking Updated'); 
    } 

    /** 
    * Remove the specified resource from storage. 
    * 
    * @param int $id 
    * @return \Illuminate\Http\Response 
    */ 
    public function destroy($id) 
    { 
     $booking = Booking::find($id); 
     $booking->delete(); 

     return redirect('/admin/dashboard')->with('success', 'Booking Removed'); 
    } 
} 

形でマイビュー: -

@extends('layouts.app') 

@section('content') 
<div class="row"> 
    <div class="col-md-8 col-md-offset-2"> 
     <div class="panel panel-default"> 
      <div class="panel-heading">Book a Stall</div> 
      <div class="alert alert-info" role="alert">Clothes Rails are not provided. You will need to provide this yourself.</div> 

      <div class="panel-body"> 
       {!!Form::open(['action' => '[email protected]','method' => 'POST'])!!} 

       @if (Auth::check()) 
       {{Form::bsText('name',Auth::user()->name)}} 
       {{Form::bsText('email',Auth::user()->email)}} 
       {{Form::bsText('address',Auth::user()->address)}} 
       {{Form::bsText('phone',Auth::user()->phone)}} 
       @else 
       {{Form::bsText('name','',['placeholder' => 'Name'])}} 
       {{Form::bsText('email','',['placeholder' => 'Email'])}} 
       {{Form::bsText('address','',['placeholder' => 'Address'])}} 
       {{Form::bsText('phone','',['placeholder' => 'Phone'])}} 
       @endif 

       <div class="form-group"> 
        {!! Form::label('market_id', 'Date:') !!} 
        {!! Form::select('market_id', $market , null, ['class'=>'form-control'])!!} 
       </div> 
       <div class="form-group"> 
        {!! Form::label('stall_id', 'Type of stall:') !!} 
        {!! Form::select('stall_id', $stall , null, ['id' => 'stall_id', 'class'=>'form-control'])!!} 
       </div> 
       {{Form::bsText('itemtype','',['placeholder' => 'Type of items to sell'])}} 
       <div class="form-group"> 
        {!! Form::label('clothesrail', 'Clothes Rail?:') !!} 
        {!! Form::label('clothesrail', 'Yes') !!} 
        {!! Form::radio('clothesrail', 1, ['class'=>'form-control'])!!} 
        {!! Form::label('clothesrail', 'No') !!} 
        {!! Form::radio('clothesrail', 0, ['class'=>'form-control'])!!} 
       </div> 

       <div class="form-group"> 
        {!! Form::label('businessname', 'Business Name:') !!} 
        {!! Form::text('businessname', null, ['id' => 'businessname', 'class'=>'form-control hidden'])!!} 
       </div> 

       <div class="form-group"> 
        {!! Form::label('insurance', 'Public Liability Insurance??:') !!} 
        {!! Form::label('insurance', 'Yes') !!} 
        {!! Form::radio('insurance', 1, ['id' => 'insurance', 'class'=>'form-control'])!!} 
        {!! Form::label('insurance', 'No') !!} 
        {!! Form::radio('insurance', 0, ['id' => 'insurance', 'class'=>'form-control'])!!} 
       </div> 
       {{Form::bsSubmit('Submit')}} 
       {!! Form::close() !!} 
      </div> 
     </div> 
    </div> 
</div> 
@endsection 

NOTES:

  • 送信ボタンをコントローラ
  • に "ストア" メソッドを呼び出します
  • ユーザーからの選択を取り消すストールプライスを取得できません。私はそれを修正することができますが、固定値の変数を使って作業しています。

答えて

1

だけ変更:ここ

$stallPrice = DB::table('your_stall_table')->find($booking->stall_id)->cost; 

TO

$stallPrice = Stall::pluck('cost')->where('id', '=', $booking->stall_id); 

を、あなたは、実際のストールテーブル名とyour_stall_tableする必要があります。

+0

これを修正していただきありがとうございます。今私はちょうど支払を処理するためにそれを取得する必要があります! – Luke

+0

詳細を知らないと、 –

+0

上記を参照してください、私はそれ自身のコントロールとビュー/フォームを持っているチュートリアルを使用していますが、私はPayPalでチュートリアルのソリューションを使って処理され、 PayPalの支払い – Luke

関連する問題