Expressjs中的Paypal REST SDK集成未在沙盒中显示交易

问题描述

我已经在我的Expressjs应用程序中集成了Paypal REST SDK。我正在将其与Angular应用程序连接。

这是我编写的代码:

router.post('/buy',( req,res ) => {
    const amt = req.body.quantity*req.body.price

    /**
     * Paypal payment json to be passed
     */
    const payment_json = {
        "intent": "sale","payer": {
            "payment_method": "paypal"
        },"redirect_urls": {
            "return_url": "https://localhost:4200/success","cancel_url": "https://localhost:4200/err"
        },"transactions": [{
            "amount": {
                "total": '' + Math.round((amt)*100)/100,"currency": "CAD","details": {
                    "subtotal": '' + Math.round((amt)*100)/100,"tax": "0.00","shipping": "0.00"
                }
            },"description": "This is payment description.","item_list": { 
                "items":[
                    {
                        "quantity": req.body.quantity,"name": "collection","price": '' + req.body.price,"sku": req.body.collid,"currency":"CAD"
                    }
                ]
            }
        }]
    }

    /**
     * Paypal payment object created
     */
    paypal.paypal.payment.create(payment_json,function (error,payment) {
        if (error) {
            res.status(500).send({message: error})
        } else {
            console.log('payment:',payment)
            for(let i=0; i<payment.links.length; i++) {
                if(payment.links[i].rel === 'approval_url') {
                    res.json({forwardLink: payment.links[i].href});
                }
            }
        }
    });
}); 

在进行交易时,它正在完成成功的交易并使我进入https://localhost:4200/success页。但是我看不到sandbox帐户中的交易。没有钱扣除,因此没有交易显示。

我在做什么错了?

解决方法

您正在使用的旧版v1 SDK已弃用。而且您缺少必需的“执行” API步骤,该步骤必须在批准后发生,并被重定向到return_url。


您应该使用Checkout-NodeJS-SDK切换到当前的v2集成。您需要的API调用是“设置交易”,然后在批准“捕获交易”之后,记录在这里:https://developer.paypal.com/docs/checkout/reference/server-integration/

用于批准的最佳Web流在这里:https://developer.paypal.com/demo/checkout/#/pattern/server,因为它不涉及重定向,并且使您的网站保持在后台

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...