使用 Product_Id 的贝宝结账

Paypal Checkout with a Product_Id

我目前正在使用来自 Paypal 的 Smart Checkout Button 购买客户。

我也在监听 Webhook 通知。

一切正常,但我的问题是我有多种用户可以购买的产品。所以我需要在我的 Webhook 中获取有关该产品的信息。

有什么方法可以像在 Stripe 中那样在 Paypal 中创建产品,或者将一些额外的值(如产品 ID)添加到结帐中,以便我知道用户购买了哪种产品。

我尝试使用下面的“item”等字段,但无法在我的 webhook 中访问它们。

  var button = paypal.Buttons({
    fundingSource: fundingSource,
    createOrder: function(data, actions) {
  // This function sets up the details of the transaction, including the amount and line item details.
  return actions.order.create({
    purchase_units: [{
      amount: {
        currency_code: 'EUR',
        value: '0.69'
      },
      item:"product_id12345"
    }]
  });
}
  });

像“item”这样的无效字段将被简单地忽略,因此根据 Orders V2 API 规范,您需要格式正确的项目数组和定价明细。您可以在 purchase_units here

中找到一个长示例

您的服务器没有理由等待可靠的异步 webhook 收到成功交易和其中的项目信息的通知。相反,切换到强大的服务器集成。这是要使用的 front-end UI:https://developer.paypal.com/demo/checkout/#/pattern/server

您的服务器需要两条路线,一条用于 'Set Up Transaction',一条用于 'Capture Transaction',记录在此处:https://developer.paypal.com/docs/checkout/reference/server-integration/

您的服务器需要的所有 product/cart 信息都可以在对它的提取调用中传达,并且在它对 PayPal 的订单 API 调用中(在项目数组和所需的金额细分参数中,您可以一旦你让其他一切正常工作,立即添加)。这比等待 webhook 要好得多。