繁体   English   中英

Paypal php Rest API,重定向时出现“ Got Http响应代码404”错误

[英]Paypal php Rest API, “Got Http response code 404” error on redirect

我正在使用Laravel,代码如下:

创建付款方式

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>";
}

付款批准后我返回到$ redirectUrl,这是错误:

访问https://api.sandbox.paypal.com/v1/payments/payment/execute时,获得了Http响应代码404。 重试0次。

路线是正确的,确实在浏览器的网址栏中有正确的网址,但我有此错误。 令人毛骨悚然的事情是,如果我将http://www.google.com之类的东西指定为redirectUrl,则一切正常。

这里的日志:

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

有任何想法吗?

--------------------已解决 --------------------

问题出在路径上,似乎在URL中使用“支付”一词会导致404错误。

改变中

$redirectUrls->setReturnUrl("http://mysite/prova/public/payment/execute")
            ->setCancelUrl("http://mysite/prova/public/payment/problema");

$redirectUrls->setReturnUrl("http://mysite/prova/public/pagamento/execute")
            ->setCancelUrl("http://mysite/prova/public/pagamento/problema");

问题解决了...但是我不知道为什么

从您自己的解决方案来看,您的路由文件中可能包含以下内容: Route::get('payment/{whatever}', function() { ... }); 这将捕获从付款开始的所有信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM