From c23833830a5f81bbd5628a02ec4ef5aec62a38bf Mon Sep 17 00:00:00 2001 From: Rimian Perkins Date: Tue, 21 Feb 2017 10:25:31 +1100 Subject: [PATCH] move the strip elements js into a component --- .../discourse/components/stripe-card.js.es6 | 29 +++++++ .../templates/components/stripe-card.hbs | 5 ++ .../discourse/templates/user/payments.hbs | 82 +------------------ 3 files changed, 36 insertions(+), 80 deletions(-) create mode 100644 assets/javascripts/discourse/components/stripe-card.js.es6 create mode 100644 assets/javascripts/discourse/templates/components/stripe-card.hbs diff --git a/assets/javascripts/discourse/components/stripe-card.js.es6 b/assets/javascripts/discourse/components/stripe-card.js.es6 new file mode 100644 index 0000000..3018383 --- /dev/null +++ b/assets/javascripts/discourse/components/stripe-card.js.es6 @@ -0,0 +1,29 @@ +export default Ember.Component.extend({ + stripe: Stripe('pk_test_b8RmhzlL8QPizJRqOrKF3JEV'), + card: function() { + var elements = this.get('stripe').elements(); + return elements.create('card', { hidePostalCode: true }); + }.property('stripe'), + + didInsertElement() { + this.get('card').mount('#stripe-card'); + }, + + actions: { + submitStripeCard() { + this.get('stripe').createToken(this.get('card')).then(function(result) { + if (result.error) { + console.log('error yo'); + } + else { + var form = document.getElementById('stripe-card'); + var hiddenInput = document.createElement('input'); + // hiddenInput.setAttribute('type', 'hidden'); + hiddenInput.setAttribute('name', 'stripeToken'); + hiddenInput.setAttribute('value', result.token.id); + form.appendChild(hiddenInput); + } + }); + } + } +}); diff --git a/assets/javascripts/discourse/templates/components/stripe-card.hbs b/assets/javascripts/discourse/templates/components/stripe-card.hbs new file mode 100644 index 0000000..5f76857 --- /dev/null +++ b/assets/javascripts/discourse/templates/components/stripe-card.hbs @@ -0,0 +1,5 @@ +
+ + diff --git a/assets/javascripts/discourse/templates/user/payments.hbs b/assets/javascripts/discourse/templates/user/payments.hbs index 2f56863..e4ea8d7 100644 --- a/assets/javascripts/discourse/templates/user/payments.hbs +++ b/assets/javascripts/discourse/templates/user/payments.hbs @@ -1,83 +1,5 @@ - - -
-
- -
+

Payments

-
- - -
- - - +{{stripe-card}}