Angularjs Paypal在单页应用中的实现

Angularjs Paypal在单页应用中的实现,angularjs,cordova,paypal,integration,single-page-application,Angularjs,Cordova,Paypal,Integration,Single Page Application,我目前正在开发一款游戏,它将由一个基于API的后端、一个web前端(AngularJS中的单页应用程序)和几个移动设备(使用Cordova)组成。我计划通过主域名和CDN为SPA提供服务。SPA(和主页)都是静态HTML/Javascript/CSS文件,因此唯一动态的部分是api。托管静态站点的“主服务器”的域名将采用example.com的样式,api的域名将采用api.example.com 我想知道如何将Paypal整合到这个场景中。互联网似乎没有就如何将其整合到S.P.A中提供太多建议

我目前正在开发一款游戏,它将由一个基于API的后端、一个web前端(AngularJS中的单页应用程序)和几个移动设备(使用Cordova)组成。我计划通过主域名和CDN为SPA提供服务。SPA(和主页)都是静态HTML/Javascript/CSS文件,因此唯一动态的部分是api。托管静态站点的“主服务器”的域名将采用example.com的样式,api的域名将采用api.example.com

我想知道如何将Paypal整合到这个场景中。互联网似乎没有就如何将其整合到S.P.A中提供太多建议,就像这样……否则我的谷歌fu可能会关闭。谢谢你的回复


以下是我如何处理这种情况

我有一个按钮,上面写着“用贝宝支付”,点击一次,我会打开一个新窗口->
窗口。打开(“/paypalCreate”,width=“20px”,height=“20px”)
我在node.js服务器中捕获了这个get请求“/paypalCreate”,并调用create方法,如下所示

exports.create = function (req, res) {
    //Payment object
    var payment = {
       //fill details from DB
    };   

    //Passing the payment over to PayPal
    paypal.payment.create(payment, function (error, payment) {
        if (error) {
            console.log(error);
        } else {
            if (payment.payer.payment_method === 'paypal') {
                req.session.paymentId = payment.id;
                var redirectUrl;
                for (var i = 0; i < payment.links.length; i++) {
                    var link = payment.links[i];
                    if (link.method === 'REDIRECT') {
                        redirectUrl = link.href;
                    }
                }
                res.redirect(redirectUrl);
            }
        }
    });
};

This redirects user to paypal and once user confirms or cancels payment, the redirect urls are called. And in the success redirect url I capture the payment details into the databse and render a html in this opened window with the confirmation.

exports.execute = function (req, res) {
    var paymentId = req.session.paymentId;
    var payerId = req.param('PayerID');

    // 1. if this is executed, then that means the payment was successful, now store the paymentId, payerId and token into the database
    // 2. At the close of the popup window open a confirmation for the reserved listing
    var details = {"payer_id": payerId};
    paypal.payment.execute(paymentId, details, function (error, payment) {
        if (error) {
            console.log(error);
        } else {
            //res.send("Hell yeah!");
            res.render('paypalSuccess', {payerId: payerId, paymentId: paymentId});
        }
    });
};
exports.create=函数(req,res){
//支付对象
风险值支付={
//从数据库中填写详细信息
};   
//将付款转交给PayPal
paypal.payment.create(付款,函数(错误,付款){
如果(错误){
console.log(错误);
}否则{
如果(payment.payer.payment_method==='paypal'){
req.session.paymentId=payment.id;
var重定向url;
对于(变量i=0;i
一旦用户关闭处理paypal的打开窗口,原始SPA窗口将被刷新,从而从DB获得付款详细信息,在这里,您可以以任何方式处理SPA。 我知道这是一个肮脏的黑客行为,但像你一样,我找不到更好的方法。请让我知道这是否对你有用,或者你是否找到了更好的方法

干杯, 奇丹