0

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",
            });
        }
    );
});
4

1 に答える 1