据我了解,您只是需要一种使用 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