Working with Meteor and Async balanced-payments functions -


i'm using balanced-payments , version 1.1 of balanced.js within meteor.

i'm trying create new customer using balanced.marketplace.customers.create(formdata);

here checkformsubmitevents.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("balancedcardcreate", checkform, function(error, result) {                 console.log(result);                 // successful tokenization             if(result.status_code === 201 && result.href) {                 // send backend                 jquery.post(responsetarget, {                     uri: result.href                 }, function(r) {                     // check backend result                     if(r.status === 201) {                         // successful logic here backend                     } else {                         // failure logic here backend                     }                 });             } else {                 // failed tokenize, error logic here             }              // debuging, displays tokenization result in pretty div             $('#response .panel-body pre').html(json.stringify(result, false, 4));             $('#response').slidedown(300);             });       } }); 

here methods.js file

var wrappeddelayedfunction = async.wrap(balanced.marketplace.customers.create);  meteor.methods({     balancedcardcreate: function (formdata) {         console.log(formdata);         var response =  wrappeddelayedfunction(formdata);         console.log(response);         return response;         } }); 

i nothing when submit form, except on server console see log of form data.

i'm sure i'm not calling of these async functions correctly. hard part me here balanced function async, don't know if fit same mold of examples i've seen.

i've tried follow example code. http://meteorhacks.com/improved-async-utilities-in-meteor-npm.html

is there specific change needs done in regard working balanced here? have tips working async functions or see specific code i've done wrong?

thanks

the npm utilities async.wrap same thing undocumented meteor function meteor._wrapasync, in takes asynchronous function last argument function(err, result) {} , turns synchronous function takes same arguments, either returns result or throws error instead of using callback. function yields in fiber until asynchronous callback returns, other code in event loop can run.

one pitfall need make sure function wrap called correct context. if balanced.marketplace.customers.create prototype method expects this set something, not set unless bind yourself, using function.bind or of other various library polyfills.

for more information, see https://stackoverflow.com/a/21542356/586086.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -