簡體   English   中英

Paypal PHP REST API-結帳時未顯示付款值

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

我對PayPal API和REST請求/響應非常陌生。 因此,我一直在嘗試與在線示例(主要來自GitHub)一起關注如何使用PayPal的REST Api處理付款。

但是,我遇到了一個問題。 當我單擊生成的鏈接時,我已成功重定向到PayPal的站點。 但是,在結帳頁面上,沒有任何指示購買金額的信息。 可能是什么問題? 謝謝!

在此處輸入圖片說明

<?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;
?>

您必須在付款中添加項目清單:
http://paypal.github.io/PayPal-PHP-SDK/sample/doc/payments/OrderCreateUsingPayPal.html

您還可以通過將&useraction=commit附加到批准網址來更改操作:
PayPal Rest API是否具有等效的經典useraction

希望這會有所幫助

$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