我正在使用适用于 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;
}