diff --git a/assets/javascripts/discourse/components/stripe-card.js.es6 b/assets/javascripts/discourse/components/stripe-card.js.es6 index c21c62a..948c590 100644 --- a/assets/javascripts/discourse/components/stripe-card.js.es6 +++ b/assets/javascripts/discourse/components/stripe-card.js.es6 @@ -1,6 +1,7 @@ import { ajax } from 'discourse/lib/ajax'; export default Ember.Component.extend({ + result: null, stripe: Stripe('pk_test_b8RmhzlL8QPizJRqOrKF3JEV'), card: function() { @@ -9,25 +10,31 @@ export default Ember.Component.extend({ }.property('stripe'), didInsertElement() { + this._super(); this.get('card').mount('#card-element'); }, actions: { submitStripeCard() { + var self = this; + this.get('stripe').createToken(this.get('card')).then(function(result) { + + self.set('result', null); + if (result.error) { console.log('error yo'); } else { - var data = { + var params = { stripeToken: result.token.id, amount: 1234 }; - ajax('/charges', { data: data, method: 'post' }).then(data => { - console.log(data); - }).catch(() => { - console.log('error'); + ajax('/charges', { data: params, method: 'post' }).then(data => { + self.set('result', (data.status == 'succeeded' ? true : null)); + }).catch((data) => { + console.log('catch', data); }); } }); diff --git a/assets/javascripts/discourse/templates/components/stripe-card.hbs b/assets/javascripts/discourse/templates/components/stripe-card.hbs index 499d4c8..5a47186 100644 --- a/assets/javascripts/discourse/templates/components/stripe-card.hbs +++ b/assets/javascripts/discourse/templates/components/stripe-card.hbs @@ -5,4 +5,8 @@ + + {{#if result}} +