Search code examples
meteorbalanced-payments

Cannot call method 'create' of undefined


Here is what I'm getting from the console server side.

I20140516-21:27:12.142(0)? There was an error on this page. Cannot call method 'create' of undefined

I am not finding a good reason why this method isn't defined. I have the balanced-payments-production package from Atmosphere loaded and this includes the balanced.js file and the api export to the server. Any help here is appreciated.

Here is my events.js file

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 }
        });
    }
});

Here is my Methods.js file

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);
        }
    }
});

Solution

  • I needed to run balanced.configure('APIKEYHERE'); first, then run the balanced code.