我正在使用
https://github.com/paypal/rest-api-sdk-php
$amountDetails = new Details(); $amountDetails->setSubtotal('7.41'); $amountDetails->setTax('0.03'); $amountDetails->setShipping('0.03'); $amount = new Amount(); $amount->setCurrency('USD'); $amount->setTotal('7.47'); $amount->setDetails($amountDetails); $transaction = new Transaction(); $transaction->setAmount($amount); $transaction->setDescription('This is the payment transaction description.'); $RedirectUrls = new RedirectUrls(); $RedirectUrls ->setReturnUrl('http://localhost/mrSurvey/public/#/pricing'); $RedirectUrls ->setCancelUrl('http://localhost/mrSurvey/public/#/pricing'); $payment = new Payment(); $payment->setIntent('sale'); $payment->setPayer($payer); $payment->setTransactions(array($transaction)); $payment->setRedirectUrls($RedirectUrls);
所有我能看到的是描述,但我想看项目编号和小计,我缺少什么?
更新:
所以我读到我需要添加一些东西:所以我做了这样的事情:
$item = new Item(); $item->setQuantity('1'); $item->setName('benny'); $item->setPrice('7.41'); $item->setCurrency('USD'); $item->setSku('blah'); $items = new ItemList(); $items->addItem(array($item));
…
$transaction->setItemList($items);
…
$payment = new Payment(); $payment->setIntent('sale'); $payment->setPayer($payer); $payment->setTransactions(array($transaction)); $payment->setRedirectUrls($RedirectUrls); $response = $payment->create($apiContext)->toarray(); return Response::json($response);
从您获得的更新中可以看出您的正确轨道.但是看起来你也有一些问题,那就是陈述的问题
try{ //your code here } catch(PayPal\Exception\PayPalConnectionException $e) { //This will show error from paypal $e->getData() }
我的猜测因为我得到了类似的错误是你没有正确添加你的物品(税,运费,小计等等)等等.试试这个样本@ https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/payments/ExecutePayment.php并让它首先工作,然后修改样本中的代码,以满足您的需求.
请注意,您有项目描述和交易描述
//run x through loop with ++ $x = 0; //for item $items[$x] = new Item(); $items->setName($item_name) ->setDescription($item_description) ->setCurrency($currency) ->setQuantity($item_quantity) ->setTax($item_tax) ->setPrice($item_price) ->setSku($item_sku); $itemList = new ItemList(); $itemList->setItems($items); //for transaction $transaction = new Transaction(); $transaction ->setAmount($amount) ->setItemList($itemList) ->setDescription($payment_description) ->setInvoiceNumber($invoice_number); function getTotals($quantity,$tax,$price){ $tax = $tax * $quantity; $subtotal = $price * $quantity; $total = $tax + $subtotal; } total = getTotal($item_quantity,$item_tax,$item_price);