2017-10-10 82 views
0

我想用PayU制作支付应用程序,但不知道如何将JSON数据发送到PayU服务器。我如何能做到这一点?请帮助我或给我一些建议。我应该通过的信息(从下面body: {...})POST到https://secure.snd.payu.com/api/v2_1/orders使用快递和角度发送JSON数据到另一个服务器(PayU)

数据我应该发送到PayU(body: {...}

userFactory.paypalPayment = function(payment) { 
    return $http({ 
    method: 'POST', 
    url: "/paynow", 
    headers: { 
     'Content-Type': 'application/json' 
    }, 
    body: { 
     "notifyUrl": "https://your.eshop.com/notify", 
     "customerIp": "127.0.0.1", 
     "merchantPosId": "145227", 
     "description": "Toyota", 
     "currencyCode": "USD", 
     "totalAmount": "12", 
     "products":{  
      "name": "Wireless mouse", 
      "unitPrice": "15000",  
      "quantity": "1" 
     }, 
    } 
    }); 
} 

return userFactory 

app.js(ExpressJS)

router.post('/paynow', function(req, res){ 
    res.setHeader('Content-type', 'application/json; charset=utf-8'); 
    res.setHeader('Access-Control-Allow-Origin', '*'); 
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE'); 
    res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With, content-type'); 
    res.setHeader('Access-Control-Allow-Credentials', 'true'); 

    res.json({ success: true}) 
}) 

控制器

app.payment = function(payment){ 
    User.paypalPayment().then(function(data){ 
     console.log(data.data) 
     if(data.data.success) { 
      $window.location = 'https://secure.snd.payu.com/api/v2_1/orders' 
     } else { 
      console.log('Wrong way') 
     } 
    })  
} 

回答

1

为了使HTTP请求到另一个r服务器,您可以使用request module(或request-promise-native,如果您更愿意承诺)。代码可能看起来像这样:

router.post('/paynow', function(req, res){ 
    // your code here 
    request({ 
     method: 'POST', 
     json: { body: req.body }, 
     uri: 'https://secure.snd.payu.com/api/v2_1/orders', 
     headers: { "Content-Type": "application/json" }, 
     (err, response, body) => { 
      // Callback - you can check response.statusCode here or get body of the response. 
      // Now you can send response to user. 
     } 
    }); 
}); 
+0

非常感谢您的提示,我分析了npm请求我解决了这个问题。再次感谢! –

相关问题