【问题标题】:How do I send shipping info to Paypal via Node.js with paypal-rest-sdk module?如何通过带有 paypal-rest-sdk 模块的 Node.js 将运输信息发送到 Paypal?
【发布时间】:2018-05-24 07:28:24
【问题描述】:

我想知道如何将发货信息发送到 Paypal,以便当用户被重定向到 Paypal 进行付款时,用户不必再次填写发货信息。用户已经填写了运输信息,数据存储在我的数据库中。问题是存储在数据库中的运输信息很可能与下订单的人的地址不同。用户很可能会使用另一个送货地址,而不是他们自己的。现在我可以通过这种方式正常操作,但我在想:如果我在 Paypal 的记录中没有存储正确的送货地址,客户很容易说我从未运送过他们的产品并要求退款。在这一点上,我只会在我的数据库中存储地址的跟踪号,而不是在 Paypal 的记录中,从而使我很容易受到这类 paypal 诈骗的攻击。如果我错了任何人,请纠正我。

以下是 Paypals 示例,说明在订购过程中向他们发送了哪些数据: https://github.com/paypal/PayPal-node-SDK/blob/master/samples/order/create.js

var create_payment_json = {
    "intent": "order",
    "payer": {
        "payment_method": "paypal"
    },
    "redirect_urls": {
        "return_url": "http://return.url",
        "cancel_url": "http://cancel.url"
    },
    "transactions": [{
        "item_list": {
            "items": [{
                "name": "item",
                "sku": "item",
                "price": "1.00",
                "currency": "USD",
                "quantity": 1
            }]
        },
        "amount": {
            "currency": "USD",
            "total": "1.00"
        },
        "description": "This is the payment description."
    }]
};

我添加了一个运输对象,请参见下面的示例。

    var create_payment_json = {
      "intent": "sale",
      "payer": {
          "payment_method": "paypal"
      },
      "redirect_urls": {
          "return_url": "https://website.com/thankyou",
          "cancel_url": "https://website.com"
      },
      "transactions": [{
          "item_list": {
              "items": [{
                  "name": name,
                  "sku": "item",
                  "price": total_price,
                  "currency": "USD",
                  "quantity": 1
              }]
          },
          "shipping_address": {
            "recipient_name":recipient_name,
            "line1":line_1,
            "city": city,
            "state":state,
            "postal_code":zipcode,
            "country_code":"US"
          },
          "amount": {
              "currency": "USD",
              "total": total_price
          },
          "description": description
      }]
      };

但我收到此错误:

"response": {
    "name":"MALFORMED REQUEST",
    "message":"Incoming JSON request",
    "information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST",
    "debug_id":"cb2ecc213218b",
    "httpStatusCode":400
},
"httpStatusCode":400
}

我不只是在装运物品。在成功的 Paypal 付款时,PayPal 返回一个包含送货地址对象的交易对象。我完全按照我看到的方式复制了它,假设我可以将运输信息发送到 Paypal。

在创建 Paypal 订单时,如何通过 REST API / node.js 将运输信息发送到 Paypal。请记住,当您在任何商店结账并登录 Paypal 时,收货地址将自动成为您在 Paypal 中设置的收货地址。如何通过 API 更改它?如果不能,商店通常如何处理这些情况?例如,给朋友买礼物。感谢您的宝贵时间,非常感谢您的帮助。

【问题讨论】:

    标签: node.js paypal paypal-sandbox paypal-rest-sdk


    【解决方案1】:

    你有正确的方法。 shipping_address 对象属于item_list 内,紧邻items 数组。

    这里有一个例子:

    var create_payment_json = {
      "intent": "sale",
      "payer": {
          "payment_method": "paypal"
      },
      "redirect_urls": {
          "return_url": "https://website.com/thankyou",
          "cancel_url": "https://website.com"
      },
      "transactions": [{
          "item_list": {
              "shipping_address": {
                  "recipient_name":recipient_name,
                  "line1":line_1,
                  "city": city,
                  "state":state,
                  "postal_code":zipcode,
                  "country_code":"US"
              },
              "items": [{
                  "name": name,
                  "sku": "item",
                  "price": total_price,
                  "currency": "USD",
                  "quantity": 1
              }]
          },
          "amount": {
              "currency": "USD",
              "total": total_price
          },
          "description": description
      }]
      };
    

    【讨论】:

    • Uwe Wiemer 如何从我的交易中完全删除运费?
    猜你喜欢
    • 2013-10-14
    • 2023-03-17
    • 2013-08-15
    • 2012-05-03
    • 2014-11-19
    • 2016-08-11
    • 2023-03-17
    • 2015-10-07
    • 2013-08-24
    相关资源
    最近更新 更多