0

我正在使用适用于 PHP 的 paypal REST SDK,使用laravel 包装器,这给了我一个 400 错误(据我所知,输入错误)我主要从以下示例中复制:在此处输入链接描述但我收到 400 错误送回。我不知道我做错了什么:这是代码。

    $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;
    }
4

3 回答 3

2

API 返回带有 HTTP 400 响应的验证错误的详细描述,您应该能够检查异常对象以确定返回的内容。

在这种情况下,您的商品总金额似乎与交易的总付款金额不匹配,但 API 错误消息应该会明确告诉您

于 2013-11-01T06:24:52.047 回答
0

Change this

$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("7.50");

Thats it

于 2013-12-09T16:37:21.660 回答
0

错误是我有一个值为“0”的 returnURL 和 CancelURL,因为我试图用 +(Javascript 习惯)连接到字符串,但baseUrl()由于 Laravel 的路由,返回一个无效的地址。

查看 PayPal.log 很有帮助

于 2013-11-01T15:43:04.520 回答