Paypal php Rest API, "Got Http response code 404" error on redirect -
i'm using laravel, here code:
create payment method
public function create() { $payer = paypalpayment::payer(); $payer->setpayment_method("paypal"); $amount = paypalpayment:: amount(); $amount->setcurrency("usd"); $amount->settotal("1.00"); $transaction = paypalpayment:: transaction(); $transaction->setamount($amount); $transaction->setdescription("this payment description."); $redirecturls = paypalpayment::redirecturls(); $redirecturls->setreturnurl("http://mysite/prova/public/payment/execute") ->setcancelurl("http://mysite/prova/public/payment/problema"); $payment = paypalpayment:: payment(); $payment->setintent("sale"); $payment->setpayer($payer); $payment->setredirecturls($redirecturls); $payment->settransactions(array($transaction)); try { $payment->create($this->_apicontext); } catch (paypal\exception\ppconnectionexception $ex) { echo "exception: " . $ex->getmessage() . php_eol; echo "<pre>"; var_dump($ex->getdata()); echo "</pre>"; exit(1); } foreach($payment->getlinks() $link) { if($link->getrel() == 'approval_url') { $redirecturl = $link->gethref(); break; } } $_session['paymentid'] = $payment->getid(); if(isset($redirecturl)) { header("location: $redirecturl"); exit; } } public function execute() { $input = input::all(); echo "<pre>"; print_r($input); echo "</pre>"; }
whe return $redirecturl after payment approval, error:
got http response code 404 when accessing https://api.sandbox.paypal.com/v1/payments/payment/execute. retried 0 times.
the routes correct , indeed in url bar of browser there' correct url i've error. courius thing if specify redirecturl http://www.google.com everythings work...
here log:
paypal\core\pphttpconnection: connecting https://api.sandbox.paypal.com/v1/oauth2/token paypal\core\pphttpconnection: payload grant_type=client_credentials paypal\core\pphttpconnection: adding header user-agent: paypalsdk/rest-sdk-php 0.6.0 (lang=php;v=5.3.3;bit=64;os=linux_2.6.32-358.2.1.el6.x86_64;machine=x86_64;openssl=1.0.1e-fips;curl=7.19.7) paypal\core\pphttpconnection: adding header authorization: basic qwrvemloqmxyyknanfntofnnqxczzjblshdkaxhsx0p4nkfwtvfveudgtufqx0nny2jrym5uwxbdqmy4okvidmlkukm3c2lkyxvazja3mnbitxp1z1j3vhlxagv3butksfhmafkzm0zuwdf4wwc0uwpqbgzor1hdvw== paypal\core\pphttpconnection: adding header accept: */* paypal\core\pphttpconnection: connecting https://api.sandbox.paypal.com/v1/payments/payment paypal\core\pphttpconnection: payload {"intent":"sale","payer":{"payment_method":"paypal"},"redirect_urls":{"return_url":"http:\/\/mysite\/prova\/public\/payment\/execute","cancel_url":"http:\/\/mysite\/prova\/public\/payment\/problema"},"transactions":[{"amount":{"currency":"usd","total":"1.00"},"description":"this payment description."}]} paypal\core\pphttpconnection: adding header content-type: application/json paypal\core\pphttpconnection: adding header user-agent: paypalsdk/rest-sdk-php 0.6.0 (lang=php;v=5.3.3;bit=64;os=linux_2.6.32-358.2.1.el6.x86_64;machine=x86_64;openssl=1.0.1e-fips;curl=7.19.7) paypal\core\pphttpconnection: adding header authorization: bearer a015cdyok5ggt4rob9n-inbly1ojo4tjvjev-eomddvykbc paypal\core\pphttpconnection: adding header paypal-request-id: 160110728012881140025562311630 paypal\transport\pprestcall: {"id":"pay-969088725c646431rkn3djay","create_time":"2014-05-16t15:53:39z","update_time":"2014-05-16t15:53:39z","state":"created","intent":"sale","payer":{"payment_method":"paypal","payer_info":{"shipping_address":{}}},"transactions":[{"amount":{"total":"1.00","currency":"usd","details":{"subtotal":"1.00"}},"description":"this payment description."}],"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/pay-969088725c646431rkn3djay","rel":"self","method":"get"},{"href":"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=ec-77w22205rv5104528","rel":"approval_url","method":"redirect"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/pay-969088725c646431rkn3djay/execute","rel":"execute","method":"post"}]} paypal\core\pphttpconnection: connecting https://api.sandbox.paypal.com/v1/oauth2/token paypal\core\pphttpconnection: payload grant_type=client_credentials paypal\core\pphttpconnection: adding header user-agent: paypalsdk/rest-sdk-php 0.6.0 (lang=php;v=5.3.3;bit=64;os=linux_2.6.32-358.2.1.el6.x86_64;machine=x86_64;openssl=1.0.1e-fips;curl=7.19.7) paypal\core\pphttpconnection: adding header authorization: basic qwrvemloqmxyyknanfntofnnqxczzjblshdkaxhsx0p4nkfwtvfveudgtufqx0nny2jrym5uwxbdqmy4okvidmlkukm3c2lkyxvazja3mnbitxp1z1j3vhlxagv3butksfhmafkzm0zuwdf4wwc0uwpqbgzor1hdvw== paypal\core\pphttpconnection: adding header accept: */* paypal\core\pphttpconnection: connecting https://api.sandbox.paypal.com/v1/payments/payment/execute paypal\core\pphttpconnection: payload paypal\core\pphttpconnection: adding header content-type: application/json paypal\core\pphttpconnection: adding header user-agent: paypalsdk/rest-sdk-php 0.6.0 (lang=php;v=5.3.3;bit=64;os=linux_2.6.32-358.2.1.el6.x86_64;machine=x86_64;openssl=1.0.1e-fips;curl=7.19.7) paypal\core\pphttpconnection: adding header authorization: bearer a015td4q1ta1duz2e2vh-3ngnxcfybb3k6hryjs6oztdbii
any ideas?
--------------------solved--------------------
the problem in path, seems using "payment" word in url causing 404 error.
changing
$redirecturls->setreturnurl("http://mysite/prova/public/payment/execute") ->setcancelurl("http://mysite/prova/public/payment/problema");
in
$redirecturls->setreturnurl("http://mysite/prova/public/pagamento/execute") ->setcancelurl("http://mysite/prova/public/pagamento/problema");
problem solved... don't know why
judging on own solution, had in routes file: route::get('payment/{whatever}', function() { ... });
catch starts payment.
Comments
Post a Comment