diff --git a/.travis.yml b/.travis.yml index d2d2b29..cd68d09 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ env: dist: trusty -cache: bundler +cache: bundler --path $TRAVIS_BUILD_DIR/discourse/vendor addons: postgresql: 9.5 @@ -29,7 +29,7 @@ before_install: install: - touch config/stripe.yml - - git clone https://github.com/choiceaustralia/discourse-payments.git plugins/discourse-payments --depth=1 + - git clone $TRAVIS_BUILD_DIR plugins/discourse-donations --depth 50 --branch $TRAVIS_BRANCH before_script: - gem install bundler @@ -37,4 +37,4 @@ before_script: - bundle exec rake db:create db:migrate script: - - "bundle exec rake plugin:spec[discourse-payments] && bundle exec rake qunit:test['200000']" + - "bundle exec rake plugin:spec[discourse-donations] && bundle exec rake qunit:test['200000']" diff --git a/README.md b/README.md index c0a4414..eb4615a 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,25 @@ -# Discourse Payments +# Discourse Donations -[![Build Status](https://travis-ci.org/choiceaustralia/discourse-payments.svg?branch=master)](https://travis-ci.org/choiceaustralia/discourse-payments) +[![Build Status](https://travis-ci.org/choiceaustralia/discourse-donations.svg?branch=master)](https://travis-ci.org/choiceaustralia/discourse-donations) -Enables stripe payments from discourse. +Accept donations in Discourse! Integrates with [Stripe](https://stripe.com). ## Configuration -You can either set your environment vars in docker or save them in a yaml. - -In your `app.yml`: - -``` - STRIPE_SECRET_KEY: 'sk_test_key' - STRIPE_PUBLISHABLE_KEY: 'pk_test_key' -``` +Visit `/admin/plugins` and configure your private and public keys. ## TODO -* Remove hard coded key and use settings. * Add a plugin outlet for custom user fields. * Some tests * Handle fails from stripe * A button in the user's profile page. -**In your app.yml** - -``` -STRIPE_SECRET_KEY: 'my_secret_key' -STRIPE_PUBLISHABLE_KEY: 'my_publishable_key' -``` - ## Testing -To run the rails specs, install the plugin and run `bundle exec rake plugin:spec[discourse-payments]` in the discourse root directory. +To run the rails specs, install the plugin and run `bundle exec rake plugin:spec[discourse-donations]` in the discourse root directory. -To run qunit tests: `MODULE='Acceptance: Discourse Payments' rake qunit:test[20000]`. +To run qunit tests: `MODULE='Acceptance: Discourse Donations' bundle exec rake qunit:test[20000]`. **Note:** diff --git a/app/controllers/discourse_payments/charges_controller.rb b/app/controllers/discourse_donations/charges_controller.rb similarity index 85% rename from app/controllers/discourse_payments/charges_controller.rb rename to app/controllers/discourse_donations/charges_controller.rb index 4bf4d85..4442d59 100644 --- a/app/controllers/discourse_payments/charges_controller.rb +++ b/app/controllers/discourse_donations/charges_controller.rb @@ -1,12 +1,14 @@ require_dependency 'discourse' -module DiscoursePayments +module DiscourseDonations class ChargesController < ActionController::Base include CurrentUser skip_before_filter :verify_authenticity_token, only: [:create] def create + Stripe.api_key = SiteSetting.discourse_donations_secret_key + customer = Stripe::Customer.create( :email => current_user.email, :source => params[:stripeToken] diff --git a/app/controllers/discourse_payments/payments_controller.rb b/app/controllers/discourse_donations/payments_controller.rb similarity index 85% rename from app/controllers/discourse_payments/payments_controller.rb rename to app/controllers/discourse_donations/payments_controller.rb index 9dd2621..e4a6c27 100644 --- a/app/controllers/discourse_payments/payments_controller.rb +++ b/app/controllers/discourse_donations/payments_controller.rb @@ -1,4 +1,4 @@ -module DiscoursePayments +module DiscourseDonations class PaymentsController < ApplicationController def index render json: {} diff --git a/app/helpers/discourse_payments/application_helper.rb b/app/helpers/discourse_donations/application_helper.rb similarity index 59% rename from app/helpers/discourse_payments/application_helper.rb rename to app/helpers/discourse_donations/application_helper.rb index 012d848..9009142 100644 --- a/app/helpers/discourse_payments/application_helper.rb +++ b/app/helpers/discourse_donations/application_helper.rb @@ -1,5 +1,5 @@ -module DiscoursePayments +module DiscourseDonations module ApplicationHelper end end diff --git a/assets/javascripts/discourse/components/stripe-card.js.es6 b/assets/javascripts/discourse/components/stripe-card.js.es6 index b8f5a6d..4514e2e 100644 --- a/assets/javascripts/discourse/components/stripe-card.js.es6 +++ b/assets/javascripts/discourse/components/stripe-card.js.es6 @@ -1,10 +1,17 @@ import { ajax } from 'discourse/lib/ajax'; +import { getRegister } from 'discourse-common/lib/get-owner'; export default Ember.Component.extend({ + donateAmounts: [1, 5, 10, 25], result: null, - paymentAmounts: [5, 10], amount: null, - stripe: Stripe('pk_test_b8RmhzlL8QPizJRqOrKF3JEV'), + stripe: null, + + init() { + this._super(); + var public_key = getRegister(this).lookup('site-settings:main').discourse_donations_public_key + this.set('stripe', Stripe(public_key)); + }, card: function() { var elements = this.get('stripe').elements(); diff --git a/assets/javascripts/discourse/templates/components/stripe-card.hbs b/assets/javascripts/discourse/templates/components/stripe-card.hbs index 15b111f..5983439 100644 --- a/assets/javascripts/discourse/templates/components/stripe-card.hbs +++ b/assets/javascripts/discourse/templates/components/stripe-card.hbs @@ -1,22 +1,22 @@
- +
- {{combo-box valueAttribute="value" content=paymentAmounts value=amount}} + {{combo-box valueAttribute="value" content=donateAmounts value=amount}}
- +
- + {{#if result}} - {{i18n 'discourse_payments.success'}} + {{i18n 'discourse_donations.success'}} {{/if}}
diff --git a/assets/javascripts/discourse/templates/connectors/user-profile-primary/link.hbs b/assets/javascripts/discourse/templates/connectors/user-profile-primary/link.hbs index 6c4e8b2..6fb4ef1 100644 --- a/assets/javascripts/discourse/templates/connectors/user-profile-primary/link.hbs +++ b/assets/javascripts/discourse/templates/connectors/user-profile-primary/link.hbs @@ -1,4 +1,5 @@ - -
- Payments page -
+{{#if siteSettings.discourse_donations_enabled}} +
+ Donate +
+{{/if}} diff --git a/assets/javascripts/discourse/templates/user/payments.hbs b/assets/javascripts/discourse/templates/user/payments.hbs index bca741e..ce01d90 100644 --- a/assets/javascripts/discourse/templates/user/payments.hbs +++ b/assets/javascripts/discourse/templates/user/payments.hbs @@ -1,9 +1,10 @@ -{{#d-section pageClass="user-payments" class="user-content user-payments"}} + +{{#d-section pageClass="user-donations" class="user-content user-donations"}}
diff --git a/config/locales/client.de.yml b/config/locales/client.de.yml index 48de9f9..79ea61b 100644 --- a/config/locales/client.de.yml +++ b/config/locales/client.de.yml @@ -1,8 +1,8 @@ en: js: - discourse_payments: - title: Donate - amount: Amount - card: Credit or debit card - success: Payment Successful! - submit: Make Payment + discourse_donations: + title: Spenden + amount: Betrag + card: Kreditkarte oder Bankkarte + success: Bezahlung erfolgreich ! + submit: Spende bezahlen diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 48de9f9..23708ec 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1,6 +1,6 @@ en: js: - discourse_payments: + discourse_donations: title: Donate amount: Amount card: Credit or debit card diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml new file mode 100644 index 0000000..cc64944 --- /dev/null +++ b/config/locales/server.en.yml @@ -0,0 +1,5 @@ +en: + site_settings: + discourse_donations_enabled: Enable the discourse donations plugin. + discourse_donations_secret_key: Stripe Secret Key + discourse_donations_public_key: Stripe Public Key diff --git a/config/routes.rb b/config/routes.rb index cf8481a..519853a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,4 @@ -DiscoursePayments::Engine.routes.draw do +DiscourseDonations::Engine.routes.draw do resources :charges, only: [:create] get 'users/:username/payments' => 'payments#show' end diff --git a/config/settings.yml b/config/settings.yml new file mode 100644 index 0000000..a4b5aa0 --- /dev/null +++ b/config/settings.yml @@ -0,0 +1,8 @@ +plugins: + discourse_donations_enabled: + default: true + client: true + discourse_donations_secret_key: + client: false + discourse_donations_public_key: + client: true diff --git a/config/stripe.rb b/config/stripe.rb deleted file mode 100644 index bee5482..0000000 --- a/config/stripe.rb +++ /dev/null @@ -1,14 +0,0 @@ - -if File.exist?('config/stripe.yml') - Rails.configuration.stripe = { - :publishable_key => Rails.application.config_for(:stripe)['publishable_key'], - :secret_key => Rails.application.config_for(:stripe)['secret_key'] - } -else - Rails.configuration.stripe = { - :publishable_key => ENV['STRIPE_PUBLISHABLE_KEY'], - :secret_key => ENV['STRIPE_SECRET_KEY'] - } -end - -Stripe.api_key = Rails.configuration.stripe[:secret_key] diff --git a/lib/discourse_donations/engine.rb b/lib/discourse_donations/engine.rb new file mode 100644 index 0000000..d92e065 --- /dev/null +++ b/lib/discourse_donations/engine.rb @@ -0,0 +1,6 @@ +module ::DiscourseDonations + class Engine < ::Rails::Engine + engine_name 'discourse-donations' + isolate_namespace DiscourseDonations + end +end diff --git a/lib/discourse_payments/engine.rb b/lib/discourse_payments/engine.rb deleted file mode 100644 index 2770737..0000000 --- a/lib/discourse_payments/engine.rb +++ /dev/null @@ -1,6 +0,0 @@ -module ::DiscoursePayments - class Engine < ::Rails::Engine - engine_name 'discourse-payments' - isolate_namespace DiscoursePayments - end -end diff --git a/plugin.rb b/plugin.rb index df456df..bb5c5ce 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,28 +1,29 @@ -# name: discourse-payments -# about: Integrating Discourse with Stripe -# version: 1.5.0 -# url: https://github.com/choiceaustralia/discourse-payments +# name: discourse-donations +# about: Integrating Discourse with Stripe for donations +# version: 1.6.8 +# url: https://github.com/choiceaustralia/discourse-donations # authors: Rimian Perkins gem 'stripe', '2.0.1' -load File.expand_path('../lib/discourse_payments/engine.rb', __FILE__) -load File.expand_path('../config/stripe.rb', __FILE__) +load File.expand_path('../lib/discourse_donations/engine.rb', __FILE__) + +enabled_site_setting :discourse_donations_enabled after_initialize do header_script = '' - discourse_payments_customization = SiteCustomization.find_or_create_by({ - name: 'Discourse Payments Header', + discourse_donations_customization = SiteCustomization.find_or_create_by({ + name: 'Discourse Donations Header', header: header_script, mobile_header: header_script, enabled: true, user_id: -1 }) - SiteCustomization.where(name: discourse_payments_customization.name).where.not(id: discourse_payments_customization.id).delete_all + SiteCustomization.where(name: discourse_donations_customization.name).where.not(id: discourse_donations_customization.id).delete_all end Discourse::Application.routes.prepend do - mount ::DiscoursePayments::Engine, at: '/' + mount ::DiscourseDonations::Engine, at: '/' end diff --git a/spec/controllers/discourse_payments/charges_controller_spec.rb b/spec/controllers/discourse_donations/charges_controller_spec.rb similarity index 75% rename from spec/controllers/discourse_payments/charges_controller_spec.rb rename to spec/controllers/discourse_donations/charges_controller_spec.rb index ca9b7fa..eef34d2 100644 --- a/spec/controllers/discourse_payments/charges_controller_spec.rb +++ b/spec/controllers/discourse_donations/charges_controller_spec.rb @@ -1,8 +1,8 @@ require 'rails_helper' -module DiscoursePayments +module DiscourseDonations RSpec.describe ChargesController, type: :controller do - routes { DiscoursePayments::Engine.routes } + routes { DiscourseDonations::Engine.routes } # it 'responds with ok' do skip 'need to get fixtures' diff --git a/spec/controllers/discourse_payments/payments_controller_spec.rb b/spec/controllers/discourse_donations/payments_controller_spec.rb similarity index 55% rename from spec/controllers/discourse_payments/payments_controller_spec.rb rename to spec/controllers/discourse_donations/payments_controller_spec.rb index 6a369dc..0922802 100644 --- a/spec/controllers/discourse_payments/payments_controller_spec.rb +++ b/spec/controllers/discourse_donations/payments_controller_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' -module DiscoursePayments +module DiscourseDonations RSpec.describe PaymentsController, type: :controller do - routes { DiscoursePayments::Engine.routes } + routes { DiscourseDonations::Engine.routes } end end diff --git a/test/javascripts/acceptance/discourse-donations-test.es6 b/test/javascripts/acceptance/discourse-donations-test.es6 new file mode 100644 index 0000000..17ed0e4 --- /dev/null +++ b/test/javascripts/acceptance/discourse-donations-test.es6 @@ -0,0 +1,10 @@ +import { acceptance } from 'helpers/qunit-helpers'; +acceptance('Discourse Donations', { loggedIn: true }); + +test('Donations Link Exists', () => { + visit('/users/eviltrout'); + + andThen(() => { + ok(exists('.discourse-donations > a'), 'Link exists on profile page'); + }); +}); diff --git a/test/javascripts/acceptance/discourse-payments-test.js.es6 b/test/javascripts/acceptance/discourse-payments-test.js.es6 deleted file mode 100644 index a8beabb..0000000 --- a/test/javascripts/acceptance/discourse-payments-test.js.es6 +++ /dev/null @@ -1,10 +0,0 @@ -import { acceptance } from 'helpers/qunit-helpers'; -acceptance('Discourse Payments', { loggedIn: true }); - -test('Payments Link Exists', () => { - visit('/users/eviltrout'); - - andThen(() => { - ok(exists('.discourse-payments > a'), 'Link exists on profile page'); - }); -});