【问题标题】:Paypal is not sending notificationsPaypal 不发送通知
【发布时间】:2020-05-12 08:44:50
【问题描述】:

我正在使用 PHP REST APIv1(我相信)与 paypal 集成。

我的请求代码如下:

include '../../classes/db.connect.php';
use PayPal\Api\Amount;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;

require 'bootstrap.php';
if (empty($_POST['buy_now'])) {
  throw new Exception('This script should not be called directly, expected post data');
}
$setitem = strip_tags($_POST['item']);
$stmt=$db->prepare("SELECT * FROM shopping WHERE id = :id");
$stmt->bindParam(':id', $setitem);
$stmt->execute();
$row = $stmt->fetch();

$payer = new Payer();
$payer->setPaymentMethod('paypal');
  $currency = 'USD';
  $amountPayable = $row['price'];
  $item1 = new Item();
  $item1->setName($row['name'])
    ->setCurrency('USD')
    ->setQuantity('1')
    ->setPrice($amountPayable);

$invoiceNumber = uniqid();
$amount = new Amount();
$amount->setCurrency($currency)
  ->setTotal($amountPayable);

$itemList = new ItemList();
if (isset($item1) && isset($item2)) {
  $itemList->setItems(array($item1, $item2));
} elseif (isset($item1)) {
  $itemList->setItems(array($item1));
} elseif (isset($item2)) {
  $itemList->setItems(array($item2));
}

$transaction = new Transaction();
$transaction->setAmount($amount)
  ->setItemList($itemList)
  ->setDescription('Website '.$row['name'].' Purchase')
  ->setInvoiceNumber($invoiceNumber)
  ->setNotifyUrl("https://REDACTED/notify.php")
  ->setCustom($username);

$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($paypalConfig['return_url'])
  ->setCancelUrl($paypalConfig['cancel_url']);

$payment = new Payment();
$payment->setIntent('sale')
  ->setPayer($payer)
  ->setTransactions([$transaction])
  ->setRedirectUrls($redirectUrls);

try {
  $payment->create($apiContext);
} catch (Exception $e) {
  throw new Exception('Unable to create link for payment');
}
header('location:' . $payment->getApprovalLink());

付款顺利进行,但 paypal 不调用 notify_url。根本没有错误。用户可以付款,付款通过,用户返回setReturnUrl,但setNotifyUrl似乎被忽略了。

我在$transaction 上做了一个var_dump,notify_url 被发送到了贝宝,但贝宝没有调用它——因此我没有收到交易通知/数据库中没有任何更新。

我已经完成了我能想到的最基本的测试,以确保贝宝没有调用notify_url。文件中的php简单设置为:

include '../../classes/db.connect.php';
$stmt = $db->prepare("INSERT INTO test (info) VALUES ('1122')");
$stmt->execute();

我意识到 REST 旨在与 webhook 一起使用 - 但出于多种原因,我不想使用它们。我的理解是设置 notify_url 将允许贝宝将该 url 用作 IPN。但是我发现贝宝只是忽略了这个变量。

另外我应该提到我已经尝试过启用 IPN 并禁用 IPN 状态更新,我尝试过启用 IPN 并启用状态更新,并且我尝试过禁用 IPN。所有三种方式都有相同的结果 - 没有错误,一切正常,但贝宝没有发送或接收任何通知。

我在贝宝上的 IPN 故事页面完全是空的。

我做错了吗?误会了什么?

我找不到任何关于此的可靠信息。

【问题讨论】:

  • “我的理解是设置一个 notify_url 将允许贝宝使用该 url 作为 IPN。但是我发现贝宝只是忽略了这个变量。”你应该联系贝宝的支持来询问这个问题,因为只有他们会知道在特定情况下发生了什么。

标签: php paypal


【解决方案1】:

无论用于创建交易的方法如何,都会发送通过您的 Paypal 帐户设置的 Paypal IPN。

https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNSetup/

您可以使用 IPN 模拟器来测试您的接收代码,或者通过注册一个沙盒帐户来在那里配置 IPN 设置。

【讨论】:

  • 在事务级别配置 IPN 通常是一种更强大的集成(因为购物车/订单管理器在域更改等情况下具有直接控制权)并且它将优先于任何默认 IPN 处理程序在帐户级别设置或不设置,所以我认为这个答案不会增加太多 - 除非他无法让首选方法正常工作,否则可能作为替代解决方案。
  • 我不认为您可以使用其余 API afaik 设置通知网址。
  • notify_urltransaction 对象developer.paypal.com/docs/api/payments/v1/…
  • @PrestonPHX 这是版本 1(已弃用)而不是 2...
  • OP 说他们正在使用 v1/payments,所以我链接到了那个。 v2/checkout/orders 不允许设置 notify_url,因为 IPN 是一种非常古老且笨拙的技术。应该转而使用 v2 的 webhook。
猜你喜欢
  • 2016-06-10
  • 2015-09-27
  • 2012-06-23
  • 2013-08-17
  • 2016-10-15
  • 2013-02-25
  • 2015-08-19
  • 2021-03-27
  • 2018-11-27
相关资源
最近更新 更多