Paypal PHP SDK - 结账预览时不显示价格

时间:2016-11-09 14:49:42

标签: php api paypal sdk

我在沙盒模式下使用以下代码:

$payer = new Payer();
$payer->setPaymentMethod('paypal');


$amount = new Amount();
$amount->setCurrency('USD')
        ->setTotal(10);

$transaction = new Transaction();
$transaction->setAmount($amount)
    ->setDescription('Bezahl einfach eh')
    ->setInvoiceNumber(uniqid());

$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl('http://www.bla.com?pay=yes')
    ->setCancelUrl('http://www.bla.com?pay=no');


$payment = new Payment();
$payment->setIntent('sale')
    ->setPayer($payer)
    ->setRedirectUrls($redirectUrls)
    ->setTransactions([$transaction]);

但它在结帐预览中没有显示10美元,所以我添加了:

$payer = new Payer();
$payer->setPaymentMethod('paypal');

// added ==>
$item1 = new Item();
$item1->setName('One week premium member')
    ->setCurrency('USD')
    ->setPrice(10);


$itemList = new ItemList();
$itemList->setItems(array($item1));

$details = new Details();
$details->setSubtotal(10);
// <== added


$amount = new Amount();
$amount->setCurrency('USD')
        ->setTotal(10);

$transaction = new Transaction();
$transaction->setAmount($amount)
    ->setItemList($itemList)  // <== added
    ->setDescription('Bezahl einfach eh')
    ->setInvoiceNumber(uniqid());

但现在我得到了以下错误:

exception 'PayPal\Exception\PayPalConnectionException' with message 'Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment.' in 

我该怎么做?

忽略:我需要在问题上添加一些文字才能发布..顺便说一句,对不起我的坏英语

0 个答案:

没有答案