Paypal REST PHP SDK给我一个400错误(laravel库) [英] Paypal REST PHP SDK giving me a 400 error (laravel library)

查看:218
本文介绍了Paypal REST PHP SDK给我一个400错误(laravel库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Paypal REST SDK for PHP,使用 laravel包装器这给了我400错误(我所理解的错误输入),我主要是从以下示例中复制的:

I'm using the paypal REST SDK for PHP, using the laravel wrapper which gives me a 400 error (bad input from what I understand) I mostly copied from the example found at: enter link description here Yet I'm getting a 400 error sent back. I can't figure out what I'm doing wrong: here's the code.

    $payer = Paypalpayment::Payer();
    $payer->setPayment_method("paypal");

    $item1 = Paypalpayment::Item();
    $item1->setName('Lavender 6 oz')
        ->setCurrency('USD')
        ->setQuantity(1)
        ->setPrice('7.50');

    $itemList = Paypalpayment::ItemLIst();
    $itemList->setItems(array($item1));


    $amount = Paypalpayment::Amount();
    $amount->setCurrency("USD")
        ->setTotal("20.00");


    $transaction = Paypalpayment::Transaction();
    $transaction->setAmount($amount)
        ->setItemList($itemList)
        ->setDescription("Buying from ButterflyOils.com");

    $redirectUrls = Paypalpayment::RedirectUrls();
    $baseUrl = Paypalpayment::getBaseUrl();
    $redirectUrls->setReturnUrl($baseUrl +  "/ExecutePayment.php?success=true&message='PayPal+Worked!'")
        ->setCancelUrl($baseUrl + "/ExecutePayment.php?success=false&message='PayPal+Cancel'");

    $payment = Paypalpayment:: Payment();
    $payment->setIntent("sale");
    $payment->setPayer($payer);
    $payment->setRedirectUrls($redirectUrls);
    $payment->setTransactions(array($transaction));

    try {
        $payment->create($this->_apiContext);
    } catch (\PPConnectionException $ex) {
        return "Exception: " . $ex->getMessage() . PHP_EOL;
        var_dump($ex->getData());
        exit(1);
    }

    foreach($payment->getLinks() as $link) {
        if($link->getRel() == 'approval_url') {
            $redirectUrl = $link->getHref();
            break;
        }
    }

    // yeah I know this is a bad idea
    $_SESSION['paymentId'] = $payment->getId();
    if(isset($redirectUrl)) {
        header("Location: $redirectUrl");
        exit;
    }

推荐答案

错误是我有一个returnURL和CancelURL,其值为'0',因为我试图将其连接为带有+(JavaScript习惯)的字符串,但是由于Laravel的路由,baseUrl()返回的地址无效.

The Error was I had a returnURL and CancelURL with a value of '0' because I was trying to concatenate to strings with a + (Javascript habit) but also the baseUrl() returns an invalid address due to Laravel's routing.

查看PayPal.log很有帮助

It was helpful to look at the PayPal.log

这篇关于Paypal REST PHP SDK给我一个400错误(laravel库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆