【发布时间】:2014-05-16 21:32:23
【问题描述】:
这是我从控制台服务器端得到的。
I20140516-21:27:12.142(0)?此页面出现错误。无法调用未定义的“创建”方法
我找不到未定义此方法的充分理由。我从 Atmosphere 加载了 balance-payments-production 包,其中包括 balance.js 文件和到服务器的 api 导出。任何帮助在这里表示赞赏。
这是我的 events.js 文件
Template.CheckFormSubmit.events({
'submit form': function (e, tmpl) {
e.preventDefault();
var recurringStatus = $(e.target).find('[name=is_recurring]').is(':checked');
var checkForm = {
name: $(e.target).find('[name=name]').val(),
account_number: $(e.target).find('[name=account_number]').val(),
routing_number: $(e.target).find('[name=routing_number]').val(),
recurring: { is_recurring: recurringStatus },
created_at: new Date
}
checkForm._id = Donations.insert(checkForm);
Meteor.call("addCustomer", checkForm, function(error, result) {
console.log(error);
console.log(result);
// Successful tokenization
if(result.status_code === 201 && result.href) {
// Send to your backend
jQuery.post(responseTarget, {
uri: result.href
}, function(r) {
// Check your backend result
if(r.status === 201) {
// Your successful logic here from backend
} else {
// Your failure logic here from backend
}
});
} else {
// Failed to tokenize, your error logic here
}
// Debuging, just displays the tokenization result in a pretty div
$('#response .panel-body pre').html(JSON.stringify(result, false, 4));
$('#response').slideDown(300);
});
var form = tmpl.find('form');
//form.reset();
//Will need to add route to receipt page here.
//Something like this maybe - Router.go('receiptPage', checkForm);
},
'click [name=is_recurring]': function (e, tmpl) {
var id = this._id;
console.log($id);
var isRecuring = tmpl.find('input').checked;
Donations.update({_id: id}, {
$set: { 'recurring.is_recurring': true }
});
}
});
这是我的 Methods.js 文件
function getCustomer(req, callback) {
try {
balanced.marketplace.customers.create(req, callback);
console.log(req.links.customers.bank_accounts);
}
catch (error){
var error = "There was an error on this page. " + error.message;
console.log(error);
}
}
var wrappedGetCustomer = Meteor._wrapAsync(getCustomer);
Meteor.methods({
addCustomer: function(formData) {
try {
console.log(formData);
return wrappedGetCustomer(formData);
}
catch (error) {
var error = "There was an error on this page." + error.message;
console.log(error);
}
}
});
【问题讨论】:
-
什么是
balanced.marketplace.customers.create?我在函数getCustomer中看不到它的任何引用 -
balanced.marketplace.customer.create 是一种可以作为平衡 API 的一部分调用的方法。 'balanced' 应该(我相信)可以从服务器端的任何地方调用。
-
仅供参考:balanced 使用 Promise,因此您的 create 行应类似于
balanced.marketplace.customers.create(req).then(callback),另请参阅:stackoverflow.com/questions/22276269/… -
我认为我不能在流星中使用 .then,因为它是同步运行的。见这篇文章。 stackoverflow.com/questions/19876609/… 我认为 Stripe 一定是相似的,它也使用了 Promise。
-
我以与上面引用的 stackoverflow 文章相同的方式格式化了另一个函数,但我遇到了另一个错误。
[TypeError: Object [object Promise] has no method 'apply']