【问题标题】:How to make Paypal Payouts on a Node.Js environment如何在 Node.Js 环境中进行 Paypal 支付
【发布时间】:2021-06-21 13:47:54
【问题描述】:

我正在尝试在 Node.Js 环境中执行 PayPal Payout,但我似乎无法理解它。

能否请您帮我正确设置参数,也许我应该在哪里重新组织代码,并最终开始朝着正确的方向前进?

提前谢谢大家。

var PAYPAL_API = "https://api-m.sandbox.paypal.com";

app.post("/my-api/execute-payment/", function (req, res) {
    // 2. Get the payment ID and the payer ID from the request body.
    var paymentID = req.body.paymentID;
    var payerID = req.body.payerID;

    let requestBody = {
        "sender_batch_header": {
            "sender_batch_id": "Payouts_2018_100007",
            "email_subject": "You have a payout!",
            "email_message": "You have received a payout! Thanks for using our service!",
        },
        "items": [
            {
                "recipient_type": "EMAIL",
                "amount": {
                    "value": "9.87",
                    "currency": "USD",
                },
                "note": "Thanks for your patronage!",
                "sender_item_id": "201403140001",
                "receiver": "rev_buyer@personal.example.com",
                "alternate_notification_method": {
                    "phone": {
                        "country_code": "91",
                        "national_number": "9999988888",
                    },
                },
                "notification_language": "fr-FR",
            },
            {
                "recipient_type": "PAYPAL_ID",
                "amount": {
                    "value": "5.32",
                    "currency": "USD",
                },
                "note": "Thanks for your patronage!",
                "sender_item_id": "201403140003",
                "receiver": "xXXXXXX-50mQSYBJpg_OWguVkwYYYYYYY-ZAFupw-aaaaa-nnnnnnn",
            },
        ],
    };

    request.post(
        PAYPAL_API + "/v1/payments/payouts",
        {
            auth: {
                user: CLIENT,
                pass: SECRET,
            },
            requestBody,
            json: true,
        },
        function (err, response) {
            if (err) {
                console.error(err);
                return res.sendStatus(500);
            }
            // 4. Return a success response to the client
            res.json({
                status: "success",
            });
        }
    );
});

【问题讨论】:

    标签: node.js paypal payout


    【解决方案1】:

    你试过Payouts-NodeJS-SDK吗?


    上述自定义代码的主要问题是您不是先请求 OAuth 2.0 access_token,然后再使用 access_token 进行 REST API 调用。

    查看文档:https://developer.paypal.com/docs/api/overview/#get-an-access-token

    SDK 为您抽象了这一步。

    【讨论】:

      猜你喜欢
      • 2022-10-24
      • 2019-04-28
      • 2020-10-13
      • 2014-11-01
      • 2017-11-24
      • 2013-02-27
      • 2013-04-25
      • 2014-11-22
      • 2012-05-24
      相关资源
      最近更新 更多