php - Laravel 5 - Paypal Payment - Pass data form to controller -
i have problem store forms inputs after payment paypal. have pass data form (name, phone_ship, address_ship ecc...) function ordersave () can store data other information. doesnt work. variabile $request->get('inputs of form') doesnt exist function saveorder
argument 1 passed dixard\http\controllers\paypalcontroller::saveorder() must instance of illuminate\http\request, none given, called in c:\xampp\htdocs\2016\app\http\controllers\paypalcontroller.php on line 191 , defined
paypalcontroller.php
<?php namespace dixard\http\controllers; use illuminate\http\request; use dixard\http\requests; use dixard\http\controllers\controller; use illuminate\foundation\bus\dispatchescommands; use illuminate\routing\controller basecontroller; use illuminate\foundation\validation\validatesrequests; use paypal\rest\apicontext; use paypal\auth\oauthtokencredential; use paypal\api\amount; use paypal\api\details; use paypal\api\item; use paypal\api\itemlist; use paypal\api\payer; use paypal\api\payment; use paypal\api\redirecturls; use paypal\api\executepayment; use paypal\api\paymentexecution; use paypal\api\transaction; use dixard\order; use dixard\orderitem; class paypalcontroller extends basecontroller { private $_api_context; //conterrĂ tutte config public function __construct() { // setup paypal api context $paypal_conf = \config::get('paypal'); $this->_api_context = new apicontext(new oauthtokencredential($paypal_conf['client_id'], $paypal_conf['secret'])); $this->_api_context->setconfig($paypal_conf['settings']); } // public function postpayment(request $request) { $payer = new payer(); $payer->setpaymentmethod('paypal'); $items = array(); $subtotal = 0; $cart = \session::get('cart'); //ottenere tutta l'informazione dalla session cart $currency = 'eur'; $cell = $request->get('phone_ship'); //return $cell; // impostiamo tutte le informazioni foreach($cart $producto){ $item = new item(); $item->setname($producto->name) ->setcurrency($currency) ->setdescription($producto->extract) ->setquantity($producto->quantity) ->setprice($producto->price); $items[] = $item; $subtotal += $producto->quantity * $producto->price; } //// $item_list = new itemlist(); $item_list->setitems($items); // // $details = new details(); $details->setsubtotal($subtotal) ->setshipping(1); //// $total = $subtotal + 1; $amount = new amount(); $amount->setcurrency($currency) ->settotal($total) ->setdetails($details); // creiamo oggetto transaction e passiamo l'imposrto $transaction = new transaction(); $transaction->setamount($amount) ->setitemlist($item_list) ->setdescription('order laravel app store'); // redirect // $redirect_urls = new redirecturls(); $redirect_urls->setreturnurl(\url::route('payment.status')) ->setcancelurl(\url::route('payment.status')); // /// $payment = new payment(); $payment->setintent('sale') ->setpayer($payer) ->setredirecturls($redirect_urls) ->settransactions(array($transaction)); //controll api / try { $payment->create($this->_api_context); } catch (\paypal\exception\ppconnectionexception $ex) { if (\config::get('app.debug')) { echo "exception: " . $ex->getmessage() . php_eol; $err_data = json_decode($ex->getdata(), true); exit; } else { die('ups! error'); } } // url approval foreach($payment->getlinks() $link) { if($link->getrel() == 'approval_url') { $redirect_url = $link->gethref(); break; } } // add payment id session, // \session::put('paypal_payment_id', $payment->getid()); // // if(isset($redirect_url)) { // redirect paypal return \redirect::away($redirect_url); } // return \redirect::route('cart-show') ->with('message', 'ups! error.'); } public function getpaymentstatus() { // payment id before session clear $payment_id = \session::get('paypal_payment_id'); // clear session payment id \session::forget('paypal_payment_id'); $payerid = \input::get('payerid'); $token = \input::get('token'); if (empty($payerid) || empty($token)) { return \redirect('products') ->with('message', 'error payment'); } $payment = payment::get($payment_id, $this->_api_context); $execution = new paymentexecution(); $execution->setpayerid(\input::get('payerid')); $result = $payment->execute($execution, $this->_api_context); if ($result->getstate() == 'approved') { $this->saveorder(); // quindi richiamo metodo saveorder e salviamo tutto // completat order \session::forget('cart'); return \redirect('ordercomplete') ->with('message', 'order complete! good!'); } return \redirect('ordercomplete') ->with('message-error', 'payment cancelled'); } protected function saveorder(request $request) { $subtotal = 0; $cart = \session::get('cart'); $shipping = 1; foreach($cart $producto){ $subtotal += $producto->quantity * $producto->price; } $order = order::create([ 'subtotal' => $subtotal, 'shipping' => $shipping, 'phone_ship' => $request->get('phone_ship') , //'user_id' => \auth::user()->id ]); foreach($cart $producto){ $this->saveorderitem($producto, $order->id); } } protected function saveorderitem($producto, $order_id) { orderitem::create([ 'price' => $producto->price, 'quantity' => $producto->quantity, 'product_id' => $producto->id, 'order_id' => $order_id ]); } }
order-detail.php
<form class="login" method="post" action="{{url('payment')}}"> {{csrf_field()}} <!--<form action="checkout.html" method="post" >--> <div class="checkout-wrapper"> <div class="container"> <div class="text-alert"> <p>returning customer? <a href="#">click here login</a></p> </div><!-- /.text-alert --> <div class="row"> <div class="col-md-6"> <h2>fatturazione</h2> <fieldset id="billinfo"> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="first_name_shipping">nome <sup>*</sup></label> <input type="text" class="form-control dark" id="first_name_shipping" placeholder="nome" > </div><!-- /.form-group --> </div> <div class="col-md-6"> <div class="form-group"> <label for="last_name_shipping">cognome <sup>*</sup></label> <input type="text" class="form-control dark" id="last_name_shipping" placeholder="cognome"> </div><!-- /.form-group --> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="address_shipping">indirizzo <sup>*</sup></label> <input type="text" class="form-control dark" id="address_shipping" placeholder="via/piazza/viale" > </div><!-- /.form-group --> </div> <div class="col-md-6"> <div class="form-group"> <label for="address2_shipping">interno/scala <sup>*</sup></label> <input type="text" class="form-control dark" id="address2_shipping" placeholder="scalaa/interno:11" > </div><!-- /.form-group --> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="province_shipping">provincia<sup>*</sup></label> <input type="text" class="form-control dark" id="province_shipping" placeholder="roma,milano,ecc" > </div><!-- /.form-group --> </div> <div class="col-md-6"> <div class="form-group"> <label for="country_shipping">paese<sup>*</sup></label> <input type="text" class="form-control dark" id="country_shipping" placeholder="paese" value="" > </div><!-- /.form-group --> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="email_shipping">email<sup>*</sup></label> <input type="text" class="form-control dark" id="email_shipping" placeholder="email" value="{{auth::user()->email}}" > </div><!-- /.form-group --> </div> <div class="col-md-6"> <div class="form-group"> <label for="phone_shipping">cellulare<sup>*</sup></label> <input type="text" class="form-control dark" id="phone_ship" placeholder="telefono/cellulare" name="phone_ship" > </div><!-- /.form-group --> </div> </div> </fieldset> </form>
routes.php
//paypal routes
route::post('payment', array( 'as' => 'payment', 'uses' => 'paypalcontroller@postpayment', )); route::get('payment', array( 'as' => 'payment', 'uses' => 'paypalcontroller@getpayment', )); //route::get('auth/register', 'auth\authcontroller@getregister'); //route::post('auth/register', 'auth\authcontroller@postregister'); //paypal redirect alla nostra route route::get('payment/status', array( 'as' => 'payment.status', 'uses' => 'paypalcontroller@getpaymentstatus', )); // pagine ordine completato route::get('ordercomplete','cartcontroller@ordercomplete');
you not pass request
object. add getpaymentstatus()
:
public function getpaymentstatus(request $request) {
and use saveorder()
this:
$this->saveorder($request);
Comments
Post a Comment