據我所知,您只是要求使用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:'[email protected]' ,
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}})
})
})
如果不是所有上面的代碼會來自這個網址:https://github.com/jamescarr/node-shopping-cart
在eBay開發商有用的鏈接頁碼:http://go.developer.ebay.com/devzone/articles/integrating-paypal-express-checkout-your-nodejs-app