我正在使用laravel moltin购物车包。到目前为止,我一直在关注本教程:http://jslim.net/blog/2014/09/19/integrate-paypal-sdk-into-laravel-4/
当我使用相同的代码时,代码可以正常工作,但每当我将自己的项目放在购物车上时,都会显示错误:“访问api.paypal.com/v1/payments/payment时获得Http响应代码400。”
这是我的代码,目前我已经注释掉静态项目,而不是我正在使用moltin包。链接:https://github.com/moltin/laravel-cart
public function postPayment()
{
$cart = new Cart(new Session, new Cookie);
$payer = new Payer();
$payer->setPaymentMethod('paypal');
// $item_1 = new Item();
// $item_1->setName('Item 1') // item name
// ->setCurrency('USD')
// ->setQuantity(2)
// ->setPrice('15'); // unit price
//
// $item_2 = new Item();
// $item_2->setName('Item 2')
// ->setCurrency('USD')
// ->setQuantity(4)
// ->setPrice('7');
//
// $item_3 = new Item();
// $item_3->setName('Item 3')
// ->setCurrency('USD')
// ->setQuantity(1)
// ->setPrice('21');
// add item to list
$item_list = new ItemList();
$item_list->setItems($cart->contents(true));
$amount = new Amount();
$amount->setCurrency('USD')
->setTotal($cart->total(false));
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($item_list)
->setDescription('Your transaction description');
$redirect_urls = new RedirectUrls();
$redirect_urls->setReturnUrl(URL::route('payment.status'))
->setCancelUrl(URL::route('payment.status'));
$payment = new Payment();
$payment->setIntent('Sale')
->setPayer($payer)
->setRedirectUrls($redirect_urls)
->setTransactions(array($transaction));
$payment->create($this->_api_context);
foreach($payment->getLinks() as $link) {
if($link->getRel() == 'approval_url') {
$redirect_url = $link->getHref();
break;
}
}
// add payment ID to session
Session::put('paypal_payment_id', $payment->getId());
if(isset($redirect_url)) {
// redirect to paypal
return Redirect::away($redirect_url);
}
return Redirect::route('original.route')
->with('error', 'Unknown error occurred');
}
我收到了这个错误:
stdClass Object
(
[name] => MALFORMED_REQUEST
[message] => Incoming JSON request does not map to API request
[information_link] => https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST
[debug_id] => 8df76ef7377bc
)
虽然使用静态项目但它可以工作,但为此它不起作用。有什么帮助吗?
提前致谢!! : - )