我正在使用paypal REST SDK for PHP,使用laravel wrapper给出了400错误(我理解的错误输入)我大部分都是从enter link description here找到的示例中复制的我收到了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;
}
答案 0 :(得分:2)
API使用HTTP 400响应返回validation errors的详细说明,您应该能够检查异常对象以确定返回的内容。
在这种情况下,您的商品总额看起来与交易的总体付款金额不符,但API错误消息应该告诉您确定
答案 1 :(得分:0)
错误是我有一个returnURL和CancelURL值为'0',因为我试图连接到带有+(Javascript习惯)的字符串,但由于Laravel的路由,baseUrl()
返回一个无效的地址。
查看PayPal.log
很有帮助答案 2 :(得分:0)
更改此
$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");
多数民众赞成