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 -[](https://travis-ci.org/choiceaustralia/discourse-payments) +[](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 @@