laravel - Calling the controller i'm in : not found -
i'm trying implement paypal api
namespace app\http\controllers; use paypal; use redirect; class paypalpaymentcontroller extends controller{ private $_apicontext; public function __construct() { $this->_apicontext = paypal::apicontext( config('services.paypal.client_id'), config('services.paypal.secret')); $this->_apicontext->setconfig(array( 'mode' => 'sandbox', 'service.endpoint' => 'https://api.sandbox.paypal.com', 'http.connectiontimeout' => 30, 'log.logenabled' => true, 'log.filename' => storage_path('logs/paypal.log'), 'log.loglevel' => 'fine' )); } public function getcheckout() { $payer = paypal::payer(); $payer->setpaymentmethod('paypal'); $amount = paypal:: amount(); $amount->setcurrency('eur'); $amount->settotal(500); // simple way, // can alternatively describe in order separately; // reference paypal php rest sdk details. $transaction = paypal::transaction(); $transaction->setamount($amount); $transaction->setdescription('altaro vm backup'); $redirecturls = paypal:: redirecturls(); $redirecturls->setreturnurl(action('paypalpaymentcontroller@getdone')); $redirecturls->setcancelurl(action('paypalpaymentcontroller@getcancel')); $payment = paypal::payment(); $payment->setintent('sale'); $payment->setpayer($payer); $payment->setredirecturls($redirecturls); $payment->settransactions(array($transaction)); $response = $payment->create($this->_apicontext); $redirecturl = $response->links[1]->href; return redirect::to( $redirecturl ); } public function getdone(request $request) { $id = $request->get('paymentid'); $token = $request->get('token'); $payer_id = $request->get('payerid'); $payment = paypal::getbyid($id, $this->_apicontext); $paymentexecution = paypal::paymentexecution(); $paymentexecution->setpayerid($payer_id); $executepayment = $payment->execute($paymentexecution, $this->_apicontext); // clear shopping cart, write database, send notifications, etc. // thank user purchase return "merci pour votre achat"; } public function getcancel() { // curse , humiliate user cancelling sacred payment (yours) return "erreur"; } }
as can see in controller i'm trying call other function of controller i'm in :
$redirecturls->setreturnurl(action('paypalpaymentcontroller@getdone')); $redirecturls->setcancelurl(action('paypalpaymentcontroller@getcancel'));
but have following error :
invalidargumentexception in urlgenerator.php line 602: action app\http\controllers\paypalpaymentcontroller@getdone not defined.
i don't understand how possible... checked multiple times spelling, everything's correct here.
any thoughts ?
edit:
i tried :
$redirecturls->setreturnurl(route('paypal.done')); $redirecturls->setcancelurl(route('paypal.cancel'));
with these routes:
route::get('done', [ 'as' => 'paypal.done', 'uses' => 'paypalpaymentcontroller@getdone' ]); route::get('cancel', [ 'as' => 'paypal.cancel', 'uses' => 'paypalpaymentcontroller@getcancel' ]);
it works !
i think have define route methods, otherwise url cannot build , returns error.
Comments
Post a Comment