Receiving a meteorite call to receive return payments from the strip

I worked with Meteor and the strip package to try and make a client. So, first I have client-side code that calls a method on the server, so when I click on it I have client.js:

Meteor.call('usersignup', function (error, result) {
    console.log (result);
});

So this calls the method on server.js:

var Future = Npm.require('fibers/future');
var stripe = StripeAPI('my key'); // secret stripe API key

Meteor.methods({

    usersignup: function(cusEmail){
        var fut = new Future();

        stripe.customers.create(
            { email: cusEmail },
            function(err, customer) {
                if (err) {
                    console.log(err);
                    fut.ret;
                }
                fut.ret(customer);
            }
            );
        return fut.wait();
    },

    userfail: function(cusid){
        var fut = new Future();

        stripe.customers.retrieve(cusid, function(err, result) {
            if(err){
                    console.log(err);
                    fut.ret;
                }
                fut.ret(err, result);
            });
        return fut.wait();
    }

});

Now it works and creates the client when I enter the stripe.com toolbar, but I try to get the response returned to the client, at least the client ID, and print it in the console. Here I can not make it work. It will write undefined when I do console.log (result). Any ideas?

EDIT: , , , , . :

'click #signupsubmit': function (event) {
    console.log("hello");
    var whatis = getVal(); // function gets value of forms and returns object
    var testid;
    var cusid = Meteor.call('usersignup', whatis.email, function (error, result) {
        if (error) {
            console.log(err.message);
            return;
        }
        console.log(result);
        console.log("meteor call");
        testid = result;
        return (result);
    });
    console.log("outside call");
    console.log(testid);
    console.log(cusid);
    },
});

, console.log, , meteor.call . Console.log testid cusid undefined, console.log "meteor call" meteor.call. , ? :

  • ""
  • " "
  • test id undefined
  • cusid undefined
  • " "
  • ""
+5
2

, API- Fibers. . , ( )

- , , :

var stripe = StripeAPI('mykeygoeshere');  // secret stripe API key
var Future = Npm.require('fibers/future');

var fut = new Future();

stripe.customers.create(
    { email: 'hello@example.org' },
    function(err, customer) {
        if (err) {
            console.log(err.message);
            fut.ret;
        }
        fut.ret("customer id", customer.id);
    }
);
return fut.wait();

Future, , .

Fibers/Futures Synchronous Callbacks, , :

+9

- . Meteor Meteor.wrapAsync() :

var stripe = StripeAPI("key");    
Meteor.methods({

    yourMethod: function(callArg) {

        var charge = Meteor.wrapAsync(stripe.charges.create, stripe.charges);
        charge({
            amount: amount,
            currency: "usd",
            //I passed the stripe token in callArg
            card: callArg.stripeToken,
        }, function(err, charge) {
            if (err && err.type === 'StripeCardError') {
              // The card has been declined
              throw new Meteor.Error("stripe-charge-error", err.message);
            }

            //Insert your 'on success' code here

        });
    }
});

: : Meteor.wrapAsync

+1

All Articles