【问题标题】:paypal-sdk - Sorry, we can’t complete your purchase at this timepaypal-sdk - 抱歉,我们目前无法完成您的购买
【发布时间】:2018-05-06 00:20:42
【问题描述】:

我试图使用 PayPal SDK 实现结帐,但不幸的是我无法让它正常运行。它仅在我的购物车中只有一件看起来很奇怪的物品时才有效。 我很确定我的配置有问题,但是在线文档非常稀缺,所以这是我的代码

$payer = new Payer();
$details = new Details();
$amount = new Amount();
$transaction = new Transaction();
$payment = new Payment();
$redirectUrls = new RedirectUrls();

// Payer
$payer -> setPaymentMethod("paypal");

$total = 0;

foreach ($cart as $item => $quantity) {
   //this loop just aggregates the total for the purchase

    $total += $quantity * $price;
}

// Details
$details -> setShipping("0.00")
    -> setTax("0.00")
    -> setSubtotal($total);

// Amount
$amount -> setCurrency("USD")
    -> setTotal($total)
    -> setDetails($details);

// Transaction
$transaction
    -> setAmount($amount)
    -> setDescription("Analysis & Development");

// Payment
$payment -> setIntent("sale")
    -> setPayer($payer)
    -> setTransactions([$transaction]);

// Redirect URLs
$redirectUrls -> setReturnUrl($base_url."php/pay.php?approved=true")
    -> setCancelUrl($base_url."php/pay.php?approved=false");

$payment->setRedirectUrls($redirectUrls);

try {

    $payment->create($api);

    // code to save transaction temporarily omitted

} catch (Exception $e) {
    header("Location: ../checkout.php?error=".$e->getMessage());
    die();
}

foreach ($payment->getLinks() as $link) {
    if($link->getRel() == "approval_url")
        $redirectUrl = $link -> getHref();
}

header("location: ".$redirectUrl);

当我进入沙盒时,我收到“抱歉,我们目前无法完成您的购买”,并带有一个返回我的网站的按钮

【问题讨论】:

  • 你能记录下 JSOn 请求响应吗?
  • @RahulDighe 请问我该怎么做?
  • 你可以通过单步执行这个语句进行调试 $payment->create($api);在某些时候,必须生成 JSON。另外,您的代码在哪里添加类似这样的项目 - paypal.github.io/PayPal-PHP-SDK/sample/doc/payments/…

标签: php paypal checkout


【解决方案1】:

vb理论,

您没有初始化“$price”变量。请您检查并初始化它。如果问题仍然存在,请联系 PayPal 技术团队以获得更好、更快速的帮助:

https://www.paypal-techsupport.com

【讨论】:

    猜你喜欢
    • 2018-05-23
    • 2020-05-15
    • 2016-12-04
    • 2020-09-01
    • 2014-10-12
    • 2015-07-18
    • 2017-02-08
    • 2017-12-07
    • 1970-01-01
    相关资源
    最近更新 更多