I'm using Laravel, here the 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 is the 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() as $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 I return to $redirectUrl after payment approval, this is the error:
Got Http response code 404 when accessing https://api.sandbox.paypal.com/v1/payments/payment/execute . Retried 0 times.
The Routes are correct and indeed in the url bar of the browser there' the correct url but I've this error. The courius thing is that if i specify as redirectUrl something like http://www.google.com everythings work...
Here the log:
PayPal\Core\PPHttpConnection: Connecting to 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 to 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 is the 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 is the 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 to 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 to 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 is in the path, it seems that using the "payment" word in the url causing the 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... but I don't know why
Judging on your own solution, you probably had something like this in your routes file: Route::get('payment/{whatever}', function() { ... });
which would catch everything that starts with payment.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.