From 5468cac1612b67f1ca6ba7c793168dd6ab8cdf8f Mon Sep 17 00:00:00 2001 From: Rimian Perkins Date: Tue, 7 Mar 2017 15:21:51 +1100 Subject: [PATCH] add settings for currency and hide post code --- README.md | 2 +- .../discourse_donations/charges_controller.rb | 4 +++- .../javascripts/discourse/components/stripe-card.js.es6 | 9 ++++++--- config/locales/client.de.yml | 2 ++ config/locales/server.en.yml | 2 ++ config/settings.yml | 6 ++++++ plugin.rb | 2 +- 7 files changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ba660d2..5411c9b 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Accept donations in Discourse! Integrates with [Stripe](https://stripe.com). ## Configuration -Visit `/admin/plugins` and configure your private and public keys. +Visit `/admin/plugins` and configure. ## TODO diff --git a/app/controllers/discourse_donations/charges_controller.rb b/app/controllers/discourse_donations/charges_controller.rb index 4442d59..c72b94d 100644 --- a/app/controllers/discourse_donations/charges_controller.rb +++ b/app/controllers/discourse_donations/charges_controller.rb @@ -8,6 +8,7 @@ module DiscourseDonations def create Stripe.api_key = SiteSetting.discourse_donations_secret_key + currency = SiteSetting.discourse_donations_currency customer = Stripe::Customer.create( :email => current_user.email, @@ -18,8 +19,9 @@ module DiscourseDonations :customer => customer.id, :amount => params[:amount], :description => 'Consumer Defender', - :currency => 'aud' + :currency => currency ) + render :json => charge end end diff --git a/assets/javascripts/discourse/components/stripe-card.js.es6 b/assets/javascripts/discourse/components/stripe-card.js.es6 index a4d19c2..55f6826 100644 --- a/assets/javascripts/discourse/components/stripe-card.js.es6 +++ b/assets/javascripts/discourse/components/stripe-card.js.es6 @@ -7,16 +7,19 @@ export default Ember.Component.extend({ amount: null, stripe: null, transactionInProgress: null, + settings: null, init() { this._super(); - var public_key = getRegister(this).lookup('site-settings:main').discourse_donations_public_key - this.set('stripe', Stripe(public_key)); + this.set('settings', getRegister(this).lookup('site-settings:main')); + this.set('stripe', Stripe(this.get('settings').discourse_donations_public_key)); }, card: function() { var elements = this.get('stripe').elements(); - return elements.create('card', { hidePostalCode: true }); + return elements.create('card', { + hidePostalCode: this.get('settings').discourse_donations_hide_zip_code + }); }.property('stripe'), didInsertElement() { diff --git a/config/locales/client.de.yml b/config/locales/client.de.yml index 4a65378..7a6205d 100644 --- a/config/locales/client.de.yml +++ b/config/locales/client.de.yml @@ -5,3 +5,5 @@ en: amount: Betrag card: Kreditkarte oder Bankkarte submit: Spende bezahlen + currency: Currency + hide_zip_code: Hide Zip Code diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index cc64944..a089687 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -3,3 +3,5 @@ en: discourse_donations_enabled: Enable the discourse donations plugin. discourse_donations_secret_key: Stripe Secret Key discourse_donations_public_key: Stripe Public Key + discourse_donations_currency: Curency Code + discourse_donations_hide_zip_code: Hide Zip Code diff --git a/config/settings.yml b/config/settings.yml index a4b5aa0..7c5b143 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -6,3 +6,9 @@ plugins: client: false discourse_donations_public_key: client: true + discourse_donations_currency: + client: true + default: 'USD' + discourse_donations_hide_zip_code: + default: true + client: true diff --git a/plugin.rb b/plugin.rb index a03a4ad..80042d9 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,6 +1,6 @@ # name: discourse-donations # about: Integrating Discourse with Stripe for donations -# version: 1.8.2 +# version: 1.9.0 # url: https://github.com/choiceaustralia/discourse-donations # authors: Rimian Perkins