WePay Meteor 无法获取 Credit_card_id
WePay Meteor can't get the Credit_card_id
在 Meteor Server 文件夹中,我有这个 main.js 文件。
在 main.js 文件中,我添加了这段代码,
saveCC(data){
var cc = "";
...
wp.call('/credit_card/create',
{
'client_id': some_id,
'cc_number': data.ccn,
'cvv': data.cvv,
'expiration_month': data.em,
'expiration_year': data.ey,
'user_name': data.name,
'email': data.eadd,
'address': {
'country': 'US',
'postal_code': data.postal,
}
},
function(response) {
if(response.error){
throw new Meteor.Error("WePay-Form",response.error_description);
}
cc = response.credit_card_id;
}
);
return "succesful";
}
我能得到response.credit_card_id。但是它只在wp.call里面。这个 wp.call 函数在 Meteor.methods 里面。我怎样才能得到 credit_card_id?我怎样才能 return 出错?
更具体地说,问题是,当用户调用 saveCC 时,return "successful" 消息甚至 wp.call 还没有完成。所以我没有得到 Meteor.error。还有一个错误,是关于Meteor.error的,只允许在Meteor.methods里面,不能在wp.call里面。 cc 也没有用信用卡更新。
当你的 meteor 方法运行时,这就是它所做的,非常快:
- 定义了一个名为 "cc"
的变量
- 进行异步调用
- returns
稍后,您的异步调用 returns,但没关系,因为您的方法早已退出。这有意义吗?
您需要的是一种机制,通过该机制您的方法在异步调用 returns 之前不会退出。你可以为此使用 Futures,它看起来像这样:
let Future = Npm.require('fibers/future');
Meteor.methods({
'foo': function() {
let future = new Future();
wp.call('/credit_card/create',
{
'client_id': some_id,
'cc_number': data.ccn,
'cvv': data.cvv,
'expiration_month': data.em,
'expiration_year': data.ey,
'user_name': data.name,
'email': data.eadd,
'address': {
'country': 'US',
'postal_code': data.postal,
}
},
function(response) {
if(response.error){
future.throw(new Meteor.Error("WePay-Form",response.error_description));
}
cc = response.credit_card_id;
future.return(cc);
}
);
return future.wait();
}
});
在 Meteor Server 文件夹中,我有这个 main.js 文件。 在 main.js 文件中,我添加了这段代码,
saveCC(data){
var cc = "";
...
wp.call('/credit_card/create',
{
'client_id': some_id,
'cc_number': data.ccn,
'cvv': data.cvv,
'expiration_month': data.em,
'expiration_year': data.ey,
'user_name': data.name,
'email': data.eadd,
'address': {
'country': 'US',
'postal_code': data.postal,
}
},
function(response) {
if(response.error){
throw new Meteor.Error("WePay-Form",response.error_description);
}
cc = response.credit_card_id;
}
);
return "succesful";
}
我能得到response.credit_card_id。但是它只在wp.call里面。这个 wp.call 函数在 Meteor.methods 里面。我怎样才能得到 credit_card_id?我怎样才能 return 出错?
更具体地说,问题是,当用户调用 saveCC 时,return "successful" 消息甚至 wp.call 还没有完成。所以我没有得到 Meteor.error。还有一个错误,是关于Meteor.error的,只允许在Meteor.methods里面,不能在wp.call里面。 cc 也没有用信用卡更新。
当你的 meteor 方法运行时,这就是它所做的,非常快:
- 定义了一个名为 "cc" 的变量
- 进行异步调用
- returns
稍后,您的异步调用 returns,但没关系,因为您的方法早已退出。这有意义吗?
您需要的是一种机制,通过该机制您的方法在异步调用 returns 之前不会退出。你可以为此使用 Futures,它看起来像这样:
let Future = Npm.require('fibers/future');
Meteor.methods({
'foo': function() {
let future = new Future();
wp.call('/credit_card/create',
{
'client_id': some_id,
'cc_number': data.ccn,
'cvv': data.cvv,
'expiration_month': data.em,
'expiration_year': data.ey,
'user_name': data.name,
'email': data.eadd,
'address': {
'country': 'US',
'postal_code': data.postal,
}
},
function(response) {
if(response.error){
future.throw(new Meteor.Error("WePay-Form",response.error_description));
}
cc = response.credit_card_id;
future.return(cc);
}
);
return future.wait();
}
});