Stripe set up help


#1

This sends data to stripe, it is reflected in the logs, but stripe redirects to /charge and I don’t have a route set to that url and there are 0 successful charges in the stripe dashboard

server/methods

'chargeCard': function (stripeToken) {
    check(stripeToken, String);
    var Stripe = StripeAPI('sk_test_xxxxxxxxxxxxxxxxxxxx');
    Stripe.charges.create({
      source: stripeToken,
      amount: Session.get('stripe-cart-total'), // this is equivalent to $50
      currency: 'usd',
      receipt_email: Meteor.user().emails[0].address,
    }, function (err, charge) {
      console.log(err, charge);
    });
  },

The html button

              <form action="/charge" method="POST">
                    <script
                        src="https://checkout.stripe.com/checkout.js"
                        class="stripe-button"
                        data-key="pk_test_xxxxxxxxxxxxx"
                        data-amount="{{stripeCartTotal}}"
                        data-name="test"
                        data-description="Checking out the test"
                        data-image="/img/favicon.png"
                        data-zip-code=true
                        data-billing-address=true
                        data-shipping-address=true
                        data-locale="auto"></script>
                </form>

client/init.js

Meteor.startup(function () {
  Stripe.setPublishableKey('pk_test_xxxxxxxxxxx');
  const handler = StripeCheckout.configure({
    key: 'pk_test_xxxxxxxxxxxx',
    token: function (token) {}
  });
});

#2

Take a look at this article: https://themeteorchef.com/recipes/building-a-saas-with-meteor-stripe-part-1/

It might help clear things up.


#3

What I ended up doing

Template.foo.onCreated(() => {
  const template = Template.instance();
  template.checkout = StripeCheckout.configure({
    key: Meteor.settings.public.stripe,
    image: '/img/favicon.png',
    locale: 'auto',
    billingAddress: true,
    shippingAddress: true,
    token(token) {
      charge = {
        amount: Session.get('cart-total'),
        currency: 'usd',
        source: token.id,
        description: description,
        receipt_email: token.email,
      };
      Meteor.call('processPayment', charge, (error, response) => {
        if (error) {
          Bert.alert(error.reason, 'danger');
        } else {
          Bert.alert('Card accepted', 'success');
        }
      });
    },
  });
});
Template.foo.events
  'click #stripe-checkout-button'(event, templateInstance) {
    templateInstance.checkout.open({
      name: 'BarbaraLee',
      description: description,
      amount: Session.get('cart-total'),
    });
    console.log(Session.get('cart-total'));
  },
});

server/methods.js

Meteor.methods({
  'chargeCard': function (stripeToken) {
    check(stripeToken, String);
    var Stripe = StripeAPI('sk_test_xxx');
    Stripe.charges.create({
      source: stripeToken,
      amount: Session.get('stripe-cart-total'), 
      currency: 'usd',
      receipt_email: Meteor.user().emails[0].address,
    }, function (err, charge) {
      console.log(err, charge);
    });
  },
});