2013-11-15 45 views
0

我有一個簡單的網絡應用程序使用nodejs有一些產品。我已經使用angularjs設置了自己的購物車,並且我想要最簡單的方法來實現PayPal付款。在過去的兩週裏,我一直在爲paypal的長文檔打破我的頭腦。貝寶快遞結帳nodejs應用程序

我在開發者頁面看到了一個示例curl調用,並使用nodejs中的restler包實現了它。它返回的捲曲調用相同的令牌(所以我想它的工作原理)。我想知道如何使我的應用程序與它工作。

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調用來完成這個任務?我只想讓我的客戶支付,然後把錢拿到銀行。暫時沒有退款或任何其他流程,請幫助我。

回答

0

據我所知,您只是要求使用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