简体   繁体   English

Paypal PHP REST API-结帐时未显示付款值

[英]Paypal PHP REST API - No Payment Value Shown At Checkout

I am very new to the PayPal API and REST request/responses. 我对PayPal API和REST请求/响应非常陌生。 As such, I have been trying to follow along with online samples (mostly from GitHub) about how to use PayPal's REST Api to process payments. 因此,我一直在尝试与在线示例(主要来自GitHub)一起关注如何使用PayPal的REST Api处理付款。

However, I have encountered a problem. 但是,我遇到了一个问题。 When I click on the link that is generated, I am successfully redirected to PayPal's site. 当我单击生成的链接时,我已成功重定向到PayPal的站点。 However, at the checkout page, there is nothing that indicates the amount of the purchase. 但是,在结帐页面上,没有任何指示购买金额的信息。 What might the issue be? 可能是什么问题? Thanks! 谢谢!

在此处输入图片说明

<?php
require __DIR__ . '/bootstrap.php';

use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;

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

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

$transaction = new Transaction();
$transaction->setAmount($amount)->setDescription("Purchase from Leisurely Diversion")->setInvoiceNumber(uniqid());

$redirectURLs = new RedirectUrls();
$redirectURLs->setReturnUrl("http://localhost/leisurelydiversion/confirmation.php")->setCancelUrl("http://localhost/leisurelydiversion/confirmation.php");

$payment = new Payment();
$payment->setIntent("sale")->setPayer($payer)->setTransactions(array($transaction))->setRedirectUrls($redirectURLs);

try {
$payment->create($apiContext);
} catch(Exception $e) {
echo "<h2> Error Sending Payment! $e</h2>";
}

$url = $payment->getApprovalLink();
echo $url;
?>

You have to add an item list to the payment: 您必须在付款中添加项目清单:
http://paypal.github.io/PayPal-PHP-SDK/sample/doc/payments/OrderCreateUsingPayPal.html http://paypal.github.io/PayPal-PHP-SDK/sample/doc/payments/OrderCreateUsingPayPal.html

You can also change the action by appending &useraction=commit to the approval url: 您还可以通过将&useraction=commit附加到批准网址来更改操作:
Does PayPal Rest API have the classic useraction equivalent PayPal Rest API是否具有等效的经典useraction

Hope this will help 希望这会有所帮助

$item = new Item();
$item->setSku('Product Id');
$item->setName('Product Name');
$item->setPrice('5.55');
$item->setCurrency('USD');
$item->setQuantity(1);

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

$transaction = new Transaction();
$transaction->setItemList($itemList);
$transaction->setAmount($amount);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM