如何向用户引用 paypal webhook?

How to reference a paypal webhook to a user?

我正在尝试找出将 webhook 与 webapp 用户相关联的最佳方式。

在贝宝交易后,我收到了来自贝宝的 webhook
但它没有我可以使用的可靠参考
与应用中的用户关联。


我的解决方案是:

  1. 在 onApprove 函数上使用 javascript 代码提交带有 subscriptionID 的表单 隐藏在输入上并将其发送到服务器。
  2. 在服务器上收到 subscriptionID 后,使用进行交易的用户的 subscriptionID 字段创建 webhook 数据库条目。
  3. 当我从 paypal 收到 webhook 时,我可以通过 订阅 ID.

周围的人有更好的选择吗?
我在想是否有办法在 paypal webhook 中插入 webapp 的 userID。
会更干净。
还没有找到任何东西。

这里是paypal webhook客户端调用:

<script>
  paypal.Buttons({
      style: {
          shape: 'pill',
          color: 'gold',
          layout: 'vertical',
          label: 'subscribe'
      },
      createSubscription: function(data, actions) {
        return actions.subscription.create({
          /* Creates the subscription */
          plan_id: '************************'

        });
      },
      onApprove: function(data, actions) {
        alert(data.subscriptionID); // You can add optional success message for the subscriber here
      }
  }).render('#paypal-button-container-******************'); // Renders the PayPal button
</script>

谢谢

创建订阅时,传递唯一的 custom_id

感谢普雷斯顿。这无疑是最好的选择。我遇到了麻烦,因为我添加了一个具有随机名称的新字段以关联到应用程序的用户 ID。事实证明,您确实需要使用 custom_id 密钥才能在 webhook 调用中接收它。

最终解决方案如下:

<script>
  paypal.Buttons({
      style: {
          shape: 'pill',
          color: 'gold',
          layout: 'vertical',
          label: 'subscribe'
      },
      createSubscription: function(data, actions) {
        return actions.subscription.create({
          /* Creates the subscription */
          plan_id: '************************',
          custom_id: 'appUserID'

        });
      },
      onApprove: function(data, actions) {
        alert(data.subscriptionID); // You can add optional success message for the subscriber here
      }
  }).render('#paypal-button-container-******************'); // Renders the PayPal button
</script>

然后 custom_id 字段将在所有 webhook 调用中可用。完美!