Невозможно вызвать метод «создать» неопределенного

Вот что я получаю со стороны консольного сервера.

I20140516-21:27:12.142(0)? На этой странице произошла ошибка. Невозможно вызвать метод «создать» неопределенного

Я не нахожу веской причины, почему этот метод не определен. У меня загружен пакет Balanced-Payments-Production от Atmosphere, который включает в себя файл 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);
        }
    }
});

person JoshJoe    schedule 16.05.2014    source источник
comment
Что такое balanced.marketplace.customers.create? Я не вижу ссылки на него в функции getCustomer   -  person gabrielhpugliese    schedule 17.05.2014
comment
balance.marketplace.customer.create — это метод, который можно вызывать как часть сбалансированного API. «сбалансированный» должен (я полагаю) быть доступным для вызова из любого места на стороне сервера.   -  person JoshJoe    schedule 17.05.2014
comment
к вашему сведению: сбалансированный использует обещания, поэтому ваша строка создания должна выглядеть примерно так: balanced.marketplace.customers.create(req).then(callback) также см.: stackoverflow.com/questions/22276269/   -  person Matthew FL    schedule 17.05.2014
comment
Я не думаю, что смогу использовать .then в метеоре, так как он работает синхронно. См. эту статью. stackoverflow.com/questions/19876609/ Я думаю, что Stripe должен быть похож тем, что он тоже использует промисы.   -  person JoshJoe    schedule 18.05.2014
comment
Я отформатировал другую функцию так же, как в упомянутой выше статье stackoverflow, и я получаю еще одну ошибку. [TypeError: Object [object Promise] has no method 'apply']   -  person JoshJoe    schedule 18.05.2014


Ответы (1)


Мне нужно было запустить balance.configure('APIKEYHERE'); сначала, затем запустите сбалансированный код.

person JoshJoe    schedule 21.05.2014