【问题标题】:Paypal express checkout for nodejs application用于 nodejs 应用程序的 Paypal 快速结帐
【发布时间】:2013-11-29 09:55:47
【问题描述】:

我有一个使用 nodejs 的简单网络应用程序,其中包含一些产品。我已经使用 angularjs 设置了自己的购物车,我想要最简单的方式来实现 paypal 支付。在过去的两周里,我一直在为贝宝的长文档而烦恼。

我在开发者页面中看到了一个示例 curl 调用,并使用 nodejs 中的 restler 包实现了它。它返回与 curl 调用相同的令牌(所以我猜它有效)。我想知道如何让我的应用程序使用它。

var restler = require('restler');
restler.get('https://api-3t.sandbox.paypal.com/nvp?USER=PLEASEDONTPUTYOURUSERNAMEHERE&PWD=PLEASEDONTPUTENCRYPTEDPASSWORDSHERE&SIGNATURE=PLEASEDONTPUTYOURINFORMATIONHEREf&METHOD=SetExpressCheckout&VERSION=78&PAYMENTREQUEST_0_PAYMENTACTION=SALE&PAYMENTREQUEST_0_AMT=19&PAYMENTREQUEST_0_CURRENCYCODE=USD&cancelUrl=http://www.yourdomain.com/cancel.html&returnUrl=http://www.yourdomain.com/success.html')
.on('complete',function(data){console.log(data);})

非常感谢您对此的帮助。我也对任何其他方式持开放态度,但由于我不喜欢长文档,所以我很难理解。有没有更简单的 api 调用来完成这项工作?我只想让我的客户付款,然后把钱拿到银行。目前没有退款或任何其他流程。请帮帮我。

【问题讨论】:

    标签: php node.js angularjs curl paypal


    【解决方案1】:

    据我了解,您只是需要一种使用 PayPal 接收付款的方法。

    我不太喜欢使用支付网关,但是当我这样做时,我更喜欢使用外部库来帮助我,就像你一样,我更喜欢更短的文档。我的大部分工作都是使用 Ruby,但前一段时间我正在使用 Express 制作一个简单的电子商务应用程序,最终在 Padrino 中完成。

    以下几乎是我旧笔记的复制粘贴,希望这些信息不会过时并且可以使用。

    1:图书馆:

    您需要获取paynode 库。它支持 PayPal 和其他一些支付网关。我相信这些信息必须在package.json

    { "name" : "my-shopping-cart"
      // Other information
     ,"dependencies":
        { 
          "paynode": "0.3.6",
          // other libraries
        }
    }
    

    我猜是npm install

    2:配置

    var payflow = require('paynode').use('payflow') 
    var client  = payflow.createClient({ 
      level:payflow.levels.sandbox , 
      user:'username@example.com' , 
      password:'1279778545' , 
      signature: 'AiPC9BjkCyDFQXbSkoZcgqH3hpacA0hAtGdCbvZOkLhMJ8t2a.QoecEJ' 
    })
    

    3:获取信息:

    获取服务器的信息,可能是通过 HTTP 发布(我不确定如何完成,因为我仍在开始学习客户端 MV* 框架)。

    products = null;
    total = 0;
    
    /* Update values */
    
    // products = getAllProducts()
    // total = getTotal()
    
    $.ajax({
      type: "POST",
      url:  'http://my-web-site.com/pay',
      data: { products: products, total:total },
      success: success,
      dataType: dataType
    });
    

    4:部分路线(付费,确认最重要)

    app.post('/pay', function(req, res){
      // Store information
      // Calculate sums or any similar information 
    
      request.returnurl = 'http://my-web-site.com/confirm'
      request.cancelurl = 'http://my-web-site.com/cancel'
    
      // make request and handle response
      client.setExpressCheckout(request).on('success', function(response){
        tokenStore.store(req.sessionHash, response.token)
        res.redirect('https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='+response.token)
      }).on('failure', function(response){
        res.render('start.haml', {locals:{
          error:response.errors[0].longmessage
          }
        })
      })
    })
    
    
    app.get('/confirm', function(req, res){
      // Necessary fetching - ex: user
      client.getExpressCheckoutDetails({token:req.param('token')})
        .on('success', function(response){
          // Save the order
          // orders.save(req.sessionHash, response)
          res.render('confirm.haml', {
            locals:{
              paypalResponse:response,
              orderTotal:response.paymentrequest[0].amt
            }
          })     
        })
        .on('failure', function(response){
          res.render('error.haml', {locals:{error:response.errors[0].longmessage}})
        })
    })
    

    以上大部分(如果不是全部)代码都来自此 URL:https://github.com/jamescarr/node-shopping-cart

    eBay 开发者页面上的有用链接:http://go.developer.ebay.com/devzone/articles/integrating-paypal-express-checkout-your-nodejs-app

    【讨论】:

      猜你喜欢
      • 2014-08-30
      • 1970-01-01
      • 2014-12-07
      • 2013-03-05
      • 2017-11-22
      • 2017-09-11
      • 2011-08-10
      • 2011-06-16
      • 2016-07-10
      相关资源
      最近更新 更多