php – Paypal项目描述与其余api sdk
发布时间:2020-12-13 17:54:20 所属栏目:PHP教程 来源:网络整理
导读:我正在使用 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
|
我正在使用
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);
现在上面的代码给了我400错误…因为添加了项目的东西,任何线索?
从您获得的更新中可以看出您的正确轨道.但是看起来你也有一些问题,那就是陈述的问题
尝试将您的代码添加到catch并从paypal回显消息 try{
//your code here
}
catch(PayPalExceptionPayPalConnectionException $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);
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
