0
目前我有用戶單擊提交,然後發生點擊事件,其中創建一個標記並調用一個方法。我試圖做的是收費後得到一個回調,說明它是否成功。如果成功,它將運行router.go到確認頁面。如果不成功,則會讓用戶知道該卡已被拒絕。以上所有我可以編碼,除了不停的修補,我似乎無法弄清楚如何將消息傳回給事件。流星:異步回調問題
這裏是我的服務器端方法:
Meteor.methods({
'chargeCard': function(token,amount,email) {
var Stripe = StripeAPI('where the key info guys');
// get a sync version of our API async func
var stripeCustomersCreateSync=Meteor.wrapAsync(Stripe.customers.create,Stripe.customers);
// call the sync version of our API func with the parameters from the method call
var result=stripeCustomersCreateSync({
description: 'Woot! A new customer!',
card: token,
email: email
}, function(error,result) {
if(error) {
return error;
}
return 'Success';
});
return result;
}
});
和我的客戶端的方法:
Stripe.card.createToken({
number: $('#cc-number').val(),
cvc: $('#card-cvc').val(),
exp_month: expM,
exp_year: expY,
name: $('#fn').val(),
address_zip: $('#postCode').val()
}, stripeResponseHandler);
}
function stripeResponseHandler(status, response) {
var $form = $('form');
if (response.error) {
// Show the errors on the form
$form.find('.validation').text(response.error.message);
return false;
} else {
var token = response.id;
var amount = 15000;
var Payid = $('#pid').text();
var userEmail = Leaguemembers.findOne({_id: Payid}).Email;
Meteor.call('chargeCard', token, amount,userEmail, function (error, result) {
console.log(error,result); alert(result); alert(error);
}
);
}
};
任何幫助將不勝感激。
編輯:
我回到後臺,我能看穿的console.log所產生的誤差,但仍是無法將它傳遞迴進行呼叫,其中顯示這些錯誤給用戶或將它們傳遞給確認頁面。我似乎得到的所有東西都是未定義的。
我做你的變化,但問題是,它沒有通過錯誤。我擺弄了一下,終於得到它返回,但它返回這個奇怪的消息:對象{_bitField:1,_promise0:對象} – DimlyAware 2015-04-04 21:47:19
這就是錯誤或成功味精? – Ethaan 2015-04-04 21:56:06
兩者...我成功通過刪除功能(錯誤,收費)來接收成功消息。用函數反向工作來解決錯誤。 – DimlyAware 2015-04-04 22:05:35