I'm trying to get a payment gateway up in my Meteor application. I'm getting the redirect url using a request.post
but I'm not able to callback.
我正试图在我的Meteor应用程序中启用支付网关。我正在使用request.post获取重定向url,但我无法回调。
The function returns some data prematurely but it does not return any data from inside the request.post
callback function to the callback function in the client from where I'm calling this from.
该函数过早地返回一些数据,但是它不会将request.post回调函数内部的任何数据返回到客户端的回调函数,我从这里调用它。
** I also tried future
, but it gives me a future.result
not found error
**我也尝试过未来,但它给了我一个future.result not found错误
pay: function(id)
{
var pay_cart = scart.findOne({ _id: id } );
var pay_user = Meteor.users.findOne({ _id: pay_cart.user_id } );
var user_name = pay_user.profile.name;
var user_email = pay_user.services[Object.keys(pay_user.services)[0]].email;
var amount = pay_cart.totalPrice.toString();
var purpose = 'Trn #'+id;
purpose = purpose.toString();
var headers = { 'X-Api-Key': 'key-value', 'X-Auth-Token': 'token-value'}
var payload = {
purpose: purpose,
amount: amount,
phone: '',
buyer_name: user_name,
redirect_url: 'http://www.example.com/redirect/'}
request.post('https://www.instamojo.com/api/1.1/payment-requests/', {form: payload, headers: headers}, function(error, response, body) {
if(!error && response.statusCode == 201) {
body = JSON.parse(body);
console.log(body.longurl);
//I'm trying to return this longurl
return body.longurl;
}
});
}
1 个解决方案
#1
0
The Problem is that Meteor doesn't wait until your post request is done. But Meteor does support the new await/async syntax and there is a request-promise package, so the post request returns a promise instead of passing a callback.
问题是Meteor不会等到你的帖子请求完成。但Meteor确实支持新的await / async语法,并且有一个request-promise包,因此post请求返回一个promise,而不是传递一个回调。
#1
0
The Problem is that Meteor doesn't wait until your post request is done. But Meteor does support the new await/async syntax and there is a request-promise package, so the post request returns a promise instead of passing a callback.
问题是Meteor不会等到你的帖子请求完成。但Meteor确实支持新的await / async语法,并且有一个request-promise包,因此post请求返回一个promise,而不是传递一个回调。