Paypal 无法使用沙箱处理付款

时间:2021-07-28 13:39:29

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

现在我必须集成贝宝付款,并且在使用沙盒帐户时遇到问题。

因此,我使用我的 Nodejs 服务器准备 PayPal 付款,然后重定向用户(使用沙箱)以完成该过程,但是当我单击付款或继续时,我看到此消息:

<块引用>

我们无法使用您的 PayPal 帐户处理您的付款,地址为 这次。请返回商家并尝试使用不同的 付款方式。

我的网址中有:

<块引用>

genericError?code=UEFZTUVOVF9ERU5JRUQ%3D

这是我的服务器代码:

app.get('/pay', (req,res)=>{
    console.log('payement');
    var create_payment_json = {
        "intent": "sale",
        "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": "100",
                    "currency": "USD",
                    "quantity": 1
                }]
            },
            "amount": {
                "currency": "USD",
                "total": "100"
            },
            "description": "This is the payment description."
        }]
    };
    
    
    paypal.payment.create(create_payment_json, function (error, payment) {
        if (error) {
            throw error;
        } else {
            console.log("Create Payment Response");
            console.log(payment);
            for (var index = 0; index < payment.links.length; index++) {
                //Redirect user to this endpoint for redirect url
                if (payment.links[index].rel === 'approval_url') {
                    res.redirect(payment.links[index].href);
                }
            }
        }
    });
});

U can here see the payment page.

1 个答案:

答案 0 :(得分:0)

为什么要使用已弃用的 v1/payments API 或 PayPal-Node-SDK?不要那样做。使用当前的 v2/checkout/orders 或 Checkout-NodeJS-SDK。

在您的服务器上创建两条路由,一条用于“创建订单”,另一条用于“捕获订单”,documented here。这些路由应该只返回 JSON 数据(没有 HTML 或文本)。后者应该(成功时)在返回之前将付款详细信息存储在您的数据库中(特别是 purchase_units[0].payments.captures[0].id,PayPal 交易 ID)

将这两条路线与以下审批流程配对:https://developer.paypal.com/demo/checkout/#/pattern/server


至于您的一般错误问题,请尝试creating a new sandbox Business account 用于其他国家/地区,例如美国进行沙盒测试。然后为该新沙箱帐户 create a REST App,并使用该应用的沙箱客户端 ID 和密码。