班级金额未找到贝宝

时间:2018-05-08 10:18:40

标签: php paypal sdk

我刚刚开始使用PayPal Sdk在我的网站上创建付款。 所以我按照他在Paypal官方GitHub上说的那样安装了Sdk: PayPal SDK Github

一切顺利,我设置了所有代码,但是当我运行脚本时,我收到了这个错误: Fatal error: Class 'Paypal\Api\Amount' not found in C:\wamp64\www\UGraphics\payment.php on line 33

这是我的源代码:



<?php
require("/includes/db.php");

$q = $db->prepare("SELECT * FROM products ORDER BY RAND() LIMIT 0,1");
$q->execute();

$product = $q->fetch(PDO::FETCH_OBJ);

require("PayPal-PHP-SDK/autoload.php");
$ids = require("/includes/paypal.php");

$apiContext = new PayPal\Rest\ApiContext(
	new \PayPal\Auth\OAuthTokenCredential(
		$ids["id"],
		$ids["secret"]
	)
);

$list = new \PayPal\Api\ItemList();

$item = (new \PayPal\Api\Item())
	->setName($product->name)
	->setPrice($product->price)
	->setCurrency('EUR')
	->setQuantity(1);

$details = (new \PayPal\Api\Details())
	->setSubTotal($item->price);

$list->addItem($item);

$amount = (new \Paypal\Api\Amount())
	->setTotal($item->price)
	->setCurrency("EUR")
	->setDetails($details);

$transaction = (new \Paypal\Api\Transaction())
	->setItemList($list)
	->setDescription($product->product_desc)
	->setAmount($amount)
	->setCustom($product->product_id);

$payment = (new \PayPal\Api\Payment())
	->setIntent("sale");

$redirect_urls = (new \PayPal\Api\RedirectUrls())
	->setReturnUrl("http://localhost:8000/pay.php")
	->setReturnUrl("http://localhost:8000/index.php");

$payment->setRedirectUrls($redirect_urls);
$payment->setTransaction([$transaction]);
$payment->setPayer((new PayPal\Api\Payer())->setPaymentMethod("paypal"));

echo $payment->getApprovalLink();
&#13;
&#13;
&#13;

你能帮我解决一下这个错误吗?

1 个答案:

答案 0 :(得分:0)

$amount = (new \PayPal\Api\Amount())

new \ Pay P al \ Api \ Amount()

需要使用大写字母&#34; P&#34;在命名空间中:)