0

There seem to be something like this but in the opposite. This is closest but I'm not storing anything.

I am only using stripe for a charge in my other post/answer:

Client:

I am grabbing the value, with jQuery, from an input field:

<input type="text" id="amount" name="amount"/>
var amount = $("#amount").val() *100; // the js client

Server:

To charge the card, you would have something like:

amount: 7000, // I want to remove the static value

I need something like this:

amount: amount

I am still learning js and I thought jquery would work but I guess not. I've tried passing amount into the isServer function but that does not work. Any alternatives?

I have also tried to use var amount = document.getElementById('#amount'); But document is not defined.

Edit:

if (Meteor.isServer) {
  Meteor.methods({
    'chargeCard': function(stripeToken, amount) {
      check(stripeToken, Object);
      var stripe = Meteor.npmRequire('stripe')('sk_test_rand');

      stripe.customers.create({
        email: 'a@aol.com'
      }).then(function() {
        return stripe.charges.create({
          amount: amount,
          currency: 'gbp',
          source: stripeToken.id
        });
      }).then(function(err, charge) {
        // New charge created on a new customer
        console.log(err, charge);
      }, function(err) {
        // Deal with an error
        console.log('Card not charge')
      });
    }
  });
}
Community
  • 1
  • 1
Sylar
  • 11,422
  • 25
  • 93
  • 166
  • any particular errors? Could you please give full jquery code where you are calling isServer function. It will be great if you could also mention the server side code. – Gagan Jaura Sep 22 '15 at 06:10
  • @Sylar http://docs.meteor.com/#/full/meteor_methods `meteor methods` –  Sep 22 '15 at 06:14
  • I have edited the post. @MarkUretsky I'll have a read. Thanks. – Sylar Sep 22 '15 at 06:23
  • 1
    @Sylar do you have a meteor call at the client? `Meteor.call('chargeCard', token, amount, function(err, res) { }` –  Sep 22 '15 at 06:32
  • @MarkUretsky No. But just added amount to the cal()l and it worked. You can add that as the answer and ill accept it. Thanks!! – Sylar Sep 22 '15 at 06:39
  • @Sylar glad it helped! :) I did thanks. –  Sep 22 '15 at 06:45

1 Answers1

0

To call a meteor method on the server from the client you need to use meteor.call:

Meteor.call('chargeCard', token, amount, function (err, res) {
  if (err) {
    console.log(err);
    return;
  }
  // success
  // if you return anything from the server you can find it with res
  console.log(res);
});