【问题标题】:Get the billing address associated to PayPal获取与 PayPal 关联的帐单地址
【发布时间】:2021-09-04 16:40:06
【问题描述】:

我在 React 中添加了 PayPal 按钮,我希望能够从 PayPal 获取账单地址

React.useEffect(() => {
    window.paypal
      .Buttons({
        createOrder: (data, actions, err) => {
          return actions.order.create({
            intent: 'CAPTURE',
            purchase_units: [
              {
                amount: {
                  currency_code: 'GBP',
                  value: Math.ceil(total * 0.72411175 * 100) / 100,
                },
              },
            ],
          })
        },
        onApprove: async (data, actions) => {
          const order = await actions.order.capture()
          //console.log(order)
        },
        onError: (err) => {
          console.log(err)
        },
      })
      .render(paypal.current)
  }, []) // eslint-disable-line

但这只返回一个包含 ID、姓名和电子邮件的对象,我希望能够获取地址、电话号码和邮政编码。 我该怎么做?

【问题讨论】:

    标签: javascript reactjs paypal payment-gateway


    【解决方案1】:

    响应中会有一个收货地址。使用以下命令将其放大为格式化的 JSON:

            onApprove: function(data, actions) {
                return actions.order.capture().then(function(details) {
                    console.log(details);
                    console.log(JSON.stringify( JSON.parse(details) ,null,2) );
                    //This is where you should show a success message or redirect.
                    //If you need to anything that touches a server database, use a server-side create and capture instead of the client-side actions.order.create() / .capture()
                });
            }
    

    根据设计,帐单信息在 PayPal 中是保密的,而不是共享的。

    【讨论】:

    • 这是可行的,但由于某种原因我无法将这些数据存储到我的数据库中
    • 我不知道你做错了什么,但正如那里的评论所说,你不应该尝试将这些数据存储到数据库中。这些是客户端调用。如果您需要进行数据库写入,则创建和捕获的调用应该来自您的服务器。见developer.paypal.com/docs/business/checkout/…
    猜你喜欢
    • 2014-04-01
    • 1970-01-01
    • 2010-12-22
    • 2011-04-08
    • 2017-09-27
    • 2015-01-18
    • 2013-06-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多