merge updates with settings

This commit is contained in:
Rimian Perkins 2017-02-28 13:52:13 +11:00
commit dc36487eec
22 changed files with 88 additions and 92 deletions

View File

@ -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']"

View File

@ -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:**

View File

@ -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]

View File

@ -1,4 +1,4 @@
module DiscoursePayments
module DiscourseDonations
class PaymentsController < ApplicationController
def index
render json: {}

View File

@ -1,5 +1,5 @@
module DiscoursePayments
module DiscourseDonations
module ApplicationHelper
end
end

View File

@ -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();

View File

@ -1,22 +1,22 @@
<form id="payment-form" class="form-horizontal">
<div class="control-group" style="width: 550px;">
<label class="control-label" for="card-element">{{i18n 'discourse_payments.amount'}}</label>
<label class="control-label" for="card-element">{{i18n 'discourse_donations.amount'}}</label>
<div class="controls controls-dropdown">
{{combo-box valueAttribute="value" content=paymentAmounts value=amount}}
{{combo-box valueAttribute="value" content=donateAmounts value=amount}}
</div>
</div>
<div class="control-group" style="width: 550px;">
<label class="control-label" for="card-element">{{i18n 'discourse_payments.card'}}</label>
<label class="control-label" for="card-element">{{i18n 'discourse_donations.card'}}</label>
<div id="card-element" class="controls"></div>
</div>
<div class="control-group save-button">
<div class="controls">
<button {{action "submitStripeCard"}} class="btn btn-primary">{{i18n 'discourse_payments.submit'}}</button>
<button {{action "submitStripeCard"}} class="btn btn-primary">{{i18n 'discourse_donations.submit'}}</button>
{{#if result}}
<span>{{i18n 'discourse_payments.success'}}</span>
<span>{{i18n 'discourse_donations.success'}}</span>
{{/if}}
</div>
</div>

View File

@ -1,4 +1,5 @@
<div class="discourse-payments">
<a href="/users/{{model.username}}/payments">Payments page</a>
</div>
{{#if siteSettings.discourse_donations_enabled}}
<div class="discourse-donations">
<a href="/users/{{model.username}}/payments">Donate</a>
</div>
{{/if}}

View File

@ -1,9 +1,10 @@
{{#d-section pageClass="user-payments" class="user-content user-payments"}}
{{#d-section pageClass="user-donations" class="user-content user-donations"}}
<div class="user-table">
<div class="wrapper">
<section class="user-navigation">
<ul class="action-list nav-stacked">
<li class="no-glyph">{{i18n 'discourse_payments.title'}}</li>
<li class="no-glyph">{{i18n 'discourse_donations.title'}}</li>
</ul>
</section>
<section class="user-right">

View File

@ -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

View File

@ -1,6 +1,6 @@
en:
js:
discourse_payments:
discourse_donations:
title: Donate
amount: Amount
card: Credit or debit card

View File

@ -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

View File

@ -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

8
config/settings.yml Normal file
View File

@ -0,0 +1,8 @@
plugins:
discourse_donations_enabled:
default: true
client: true
discourse_donations_secret_key:
client: false
discourse_donations_public_key:
client: true

View File

@ -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]

View File

@ -0,0 +1,6 @@
module ::DiscourseDonations
class Engine < ::Rails::Engine
engine_name 'discourse-donations'
isolate_namespace DiscourseDonations
end
end

View File

@ -1,6 +0,0 @@
module ::DiscoursePayments
class Engine < ::Rails::Engine
engine_name 'discourse-payments'
isolate_namespace DiscoursePayments
end
end

View File

@ -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 = '<script src="https://js.stripe.com/v3/"></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

View File

@ -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'

View File

@ -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

View File

@ -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');
});
});

View File

@ -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');
});
});