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

时间:2014-05-16 16:17:07

标签: php rest paypal laravel paypal-sandbox

我正在使用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次。

路由是正确的,确实在浏览器的网址栏中有正确的网址,但我有这个错误。 courius的事情是,如果我指定为redirectUrl,像http://www.google.com每件事都可以......

这里是日志:

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

有什么想法吗?

--------------------的解决 ------------------- -

问题出在路径上,似乎在网址中使用“付款”字会导致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");

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

1 个答案:

答案 0 :(得分:0)

根据你自己的解决方案,你可能在你的路线文件中有这样的东西:Route::get('payment/{whatever}', function() { ... });它可以捕获从付款开始的一切。