Javascript 使用paypal node sdk向计费协议添加自定义字段

Javascript 使用paypal node sdk向计费协议添加自定义字段,javascript,node.js,paypal,paypal-ipn,Javascript,Node.js,Paypal,Paypal Ipn,我正在尝试向计费协议添加自定义字段,以便在我收到IPN POST呼叫时知道哪些用户正在启动或停止订阅 const billingAgreementAttributes = { "name": "TEST Web App", "description": "TEST WEB APP.", "start_date": null, "plan": { "id": "" }, "custom": "string" "payer":

我正在尝试向计费协议添加自定义字段,以便在我收到IPN POST呼叫时知道哪些用户正在启动或停止订阅

const billingAgreementAttributes = {
    "name": "TEST Web App",
    "description": "TEST WEB APP.",
    "start_date": null,
    "plan": {
        "id": ""
    },
    "custom": "string"
    "payer": {
        "payment_method": "paypal",
    },

};
    api.post('/create', authCheck, (req, res) => {
    const body = req.body
    const type = body.type // default basic
    const user = body.user



    let isoDate = new Date();
    isoDate.setSeconds(isoDate.getSeconds() + 120);
    isoDate.toISOString().slice(0, 19) + 'Z';


    let agreement = billingAgreementAttributes

    agreement.plan.id = type ? basic : unlimited 
    agreement.start_date = isoDate


    // Use activated billing plan to create agreement
    paypal.billingAgreement.create(agreement, function (error, billingAgreement) {
        if (error) {
            console.error(JSON.stringify(error));
            res.json(error)
        } else {
            console.log("Create Billing Agreement Response");
            //console.log(billingAgreement);
            for (var index = 0; index < billingAgreement.links.length; index++) {
                if (billingAgreement.links[index].rel === 'approval_url') {
                    var approval_url = billingAgreement.links[index].href;
                    console.log("For approving subscription via Paypal, first redirect user to");
                    console.log(approval_url);
                    res.json({ approval_url })

                    // See billing_agreements/execute.js to see example for executing agreement 
                    // after you have payment token
                }
            }
        }
    });
})

如果在执行协议时尝试将其添加到数据参数中,则不会在任何地方返回。因此,当前如果用户要启动或停止订阅,我不知道是哪个用户做的。

我不确定您使用的订阅API和计费协议的版本,但SDK不支持最新版本,并且不支持
自定义
参数

当用户通过您的站点/应用程序创建订阅/计费协议ID时,您必须在创建时将订阅/计费协议ID与用户关联。此用户关联的订阅/计费协议id应保留在您自己的数据库中。然后,可以查找该id上的任何后续事件,并与用户进行匹配(尽管您确实希望将用户视为文件中具有活动订阅/BA id的对象)

api.post('/execute', authCheck, (req, res) => {
    const token = req.body
    console.log(token)
    paypal.billingAgreement.execute(token.token, {"custom": "foobar"}, function (error, billingAgreement) {
        if (error) {
            console.error(JSON.stringify(error));
            res.json(error)
        } else {
            res.json(billingAgreement)
            console.log(JSON.stringify(billingAgreement));
            console.log('Billing Agreement Created Successfully');
        }
    });
})