2017-08-23 1 views
0

Ich habe auf http://laravelcode.com/post/how-to-integrate-paypal-payment-gateway-in-laravel-54Laravel PayPal Tutorial in der realen Welt Szenario

nach dem Tutorial gewesen

Ich bin jetzt entwickle ich versuche, dies in einer eine Anwendung zu verwenden, aber ich bin ganz neu in PHP/Laravel so versuchen um diese Paypal-Funktionen in meine eigenen Controller/Formulare zu bekommen, die ich bereits gebaut habe.

Ich habe einen Controller "BookingsController", der eine Form auf ../bookings/create hat, dass, wenn die EU die Submit-Taste drückt, es die Info in die DB eingeben wird, die perfekt funktioniert, und dann die PayPal-Bits zu ausführt Nimm die EU zum PayPal-Checkout, wo ich nicht weitergekommen bin.

Mein Controller: -

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

Meine Ansicht mit der Form: -

@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:

  • Die Submit-Button ruft die "store" Methode in der Steuerung
  • Ich kann nicht den Stall Preis von der Auswahl des Benutzers in die ziehen Variable, aber ich werde später damit umgehen, wie ich das beheben kann, ich arbeite nur mit einer festen Wertvariable, um es zu arbeiten.

Antwort

1

Gerade Änderung:

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

TO

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

Hier müssen Sie your_stall_table mit Ihren tatsächlichen Stall Tabellennamen.

+0

Danke für die Befestigung! Jetzt muss ich nur noch die Zahlung abwickeln! – Luke

+0

Ohne jedes Detail, kann Ihnen nicht helfen –

+0

Siehe oben, ich benutze das Tutorial, das seinen eigenen Controller und View/Formular hat, aber ich muss mein Formular von PayPal mit der Lösung im Tutorial und die Variablen für die Verarbeitung verarbeitet werden die PayPal-Zahlung – Luke

Verwandte Themen