From 446cc75cbcd0fbb8924bd8ea6b7931344fa65816 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Fri, 2 Feb 2018 19:49:58 +0800 Subject: [PATCH] Make donation amounts a customisable setting --- .../discourse/components/stripe-card.js.es6 | 23 ++++++++++++------- config/locales/client.en.yml | 4 ++++ config/settings.yml | 6 +++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/assets/javascripts/discourse/components/stripe-card.js.es6 b/assets/javascripts/discourse/components/stripe-card.js.es6 index 8927486..ee83b52 100644 --- a/assets/javascripts/discourse/components/stripe-card.js.es6 +++ b/assets/javascripts/discourse/components/stripe-card.js.es6 @@ -3,14 +3,6 @@ import { getRegister } from 'discourse-common/lib/get-owner'; import { default as computed } from 'ember-addons/ember-computed-decorators'; export default Ember.Component.extend({ - donateAmounts: [ - { value: 1, name: '1.00'}, - { value: 2, name: '2.00'}, - { value: 5, name: '5.00'}, - { value: 10, name: '10.00'}, - { value: 20, name: '20.00'}, - { value: 50, name: '50.00'} - ], result: [], amount: 1, stripe: null, @@ -26,6 +18,21 @@ export default Ember.Component.extend({ this.set('stripe', Stripe(this.get('settings').discourse_donations_public_key)); }, + @computed + donateAmounts() { + const setting = Discourse.SiteSettings.discourse_donations_amounts.split('|'); + if (setting.length) { + return setting.map((amount) => { + return { + value: parseInt(amount, 10), + name: `${amount}.00` + }; + }); + } else { + return []; + } + }, + @computed('stripe') card(stripe) { let elements = stripe.elements(); diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 3ffc827..975e9ba 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -15,6 +15,10 @@ en: discourse_donations_enable_transaction_fee: "Give the user the option of including the Stripe transaction fee in their donation." discourse_donations_transaction_fee_fixed: "Fixed part of Stripe transaction fee (changes per region). See Stripe's pricing for your region and Stripe's explaination of passing fees onto customers." discourse_donations_transaction_fee_percent: "Percent part of Stripe transaction fee (changes per region). See Stripe's pricing for your region and Stripe's explaination of passing fees onto customers." + discourse_donations_amounts: "Donation amounts available to user" + discourse_donations_custom_amount: "Allow custom donation amount" + errors: + discourse_donations_amount_must_be_number: "Amounts must be numbers" js: discourse_donations: diff --git a/config/settings.yml b/config/settings.yml index 340ff38..8ba2e94 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -44,3 +44,9 @@ plugins: discourse_donations_transaction_fee_percent: client: true default: 0.029 + discourse_donations_amounts: + client: true + type: list + default: '1|2|5|10|20|50' + regex: "^[0-9\\|]+$" + regex_error: "site_settings.errors.discourse_donations_amount_must_be_number"