程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了paypal checkout v2 - 捕获订单 Nodejs大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决paypal checkout v2 - 捕获订单 Nodejs?

开发过程中遇到paypal checkout v2 - 捕获订单 Nodejs的问题如何解决?下面主要结合日常开发的经验,给出你关于paypal checkout v2 - 捕获订单 Nodejs的解决方法建议,希望对你解决paypal checkout v2 - 捕获订单 Nodejs有所启发或帮助;

我一直在尝试在我正在开发的网站上实施 PayPal。我可以创建一个订单并将用户重定向到 PayPal 页面进行付款,但是一旦用户确认付款并重定向到成功页面,该页面就会持续加载,直到我收到内部服务器错误并且控制台中没有任何内容。不知道出了什么问题,因为我从文档中做了所有的事情。

这是我的代码:

var dotenv = require('dotenv');
var express = require('express');
var router = express.Router({ mergeParams: true });
var async = require('async');


const paypal = require('@paypal/checkout-server-sdk');

// CreaTing an environment
let clIEntID = 'SECRET1';
let clIEntSecret =
    'SECRET2';
// This sample uses SandBoxEnvironment. In production,use liveEnvironment
let environment = new paypal.core.SandBoxEnvironment(clIEntID,clIEntSecret);
let clIEnt = new paypal.core.PayPalhttpClIEnt(environment);

router.post('/donate',(req,res) => {
    var SELEctedamount = req.body.options;

    let request = new paypal.orders.ordersCreaterequest();
    request.requestbody({
        intent: 'CAPTURE',application_context: {
            return_url: 'https://localhost:3000/success',cancel_url: 'https://localhost:3000/cancel',brand_name: 'Example site',user_action: 'CONTinUE',},purchase_units: [
            {
                reference_ID: 'ws_123',description: 'sample product',amount: {
                    currency_code: 'USD',value: SELEctedamount,],});

    // Call API with your clIEnt and get a response for your call
    let createOrder = async function () {
        let response = await clIEnt.execute(request);
        
        for (let i = 0; i < response.result.links.length; i++) {
            if (response.result.links[i].rel === 'approve') {
                res.redirect(response.result.links[i].href);
            }
        }
    };
    createOrder();
    console.log('CreaTing Order...');
    
});

router.get('/success',res) =>{
    
    let captureOrder =  async function(orderID) {
    request = new paypal.orders.ordersCapturerequest(orderID);
    request.requestbody({});
    // Call API with your clIEnt and get a response for your call
    let response = await clIEnt.execute(request);
    console.log(`Response: ${JsON.Stringify(responsE)}`);
    // If call returns body in response,you can get the deserialized version from the result attribute of the response.
    console.log(`Capture: ${JsON.Stringify(response.result)}`);
}
        
});

module.exports = router;

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的paypal checkout v2 - 捕获订单 Nodejs全部内容,希望文章能够帮你解决paypal checkout v2 - 捕获订单 Nodejs所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。