diff --git a/Gemfile b/Gemfile index 5c47891..872327f 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,10 @@ gem 'coffee-rails', '~> 4.1.0' # gem 'therubyracer', platforms: :ruby # Integrate Paperclip into Mongoid. -gem "mongoid-paperclip" +gem 'mongoid-paperclip' + +# Stripe integration +gem 'stripe' # To extend paperclip with locales gem 'paperclip-i18n' diff --git a/Gemfile.lock b/Gemfile.lock index bcf10ca..0e548cc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -109,6 +109,8 @@ GEM activesupport (>= 3.0.0) faker (1.8.4) i18n (~> 0.5) + faraday (0.13.1) + multipart-post (>= 1.2, < 3) ffi (1.9.18) font-awesome-rails (4.7.0.2) railties (>= 3.2, < 5.2) @@ -185,6 +187,7 @@ GEM mongoid (>= 4) mongoid-compatibility multi_json (1.12.2) + multipart-post (2.0.0) nested_form (0.3.2) nokogiri (1.8.1) mini_portile2 (~> 2.3.0) @@ -329,6 +332,8 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) stackprof (0.2.10) + stripe (3.6.0) + faraday (~> 0.10) temple (0.8.0) thor (0.20.0) thread_safe (0.3.6) @@ -389,6 +394,7 @@ DEPENDENCIES slim slim-rails stackprof + stripe uglifier (>= 1.3.0) web-console (~> 2.0) diff --git a/app/assets/javascripts/charges.coffee b/app/assets/javascripts/charges.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/charges.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/charges.scss b/app/assets/stylesheets/charges.scss new file mode 100644 index 0000000..3ef2d76 --- /dev/null +++ b/app/assets/stylesheets/charges.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the charges controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/donations.sass b/app/assets/stylesheets/donations.sass index f79dbca..e17e70d 100644 --- a/app/assets/stylesheets/donations.sass +++ b/app/assets/stylesheets/donations.sass @@ -9,3 +9,9 @@ text-align: right padding: 1em display: inline-block + +.donatebox + font-size: 24px + margin: 15px + width: 80px + height: 80px \ No newline at end of file diff --git a/app/controllers/charges_controller.rb b/app/controllers/charges_controller.rb new file mode 100644 index 0000000..459d1c1 --- /dev/null +++ b/app/controllers/charges_controller.rb @@ -0,0 +1,29 @@ +class ChargesController < ApplicationController + def new; end + + def create + @amount = params[:amount] + + begin + @amount = Float(@amount).round(2) + rescue + flash[:error] = 'Bitte geben sie einen Betrag in CHF ein.' + redirect_to donation_path + return + end + + @amount = (@amount * 100).to_i # Must be an integer! + + if @amount < 500 + flash[:error] = 'Ihre Spende muss mindestens 5.- CHF betragen.' + redirect_to donation_path + return + end + + Stripe::Charge.create(amount: @amount, currency: 'CHF', source: params[:stripeToken], description: 'Initiativspende') + + rescue Stripe::CardError => e + flash[:error] = e.message + redirect_to donation_path + end +end diff --git a/app/helpers/charges_helper.rb b/app/helpers/charges_helper.rb new file mode 100644 index 0000000..414ee90 --- /dev/null +++ b/app/helpers/charges_helper.rb @@ -0,0 +1,2 @@ +module ChargesHelper +end diff --git a/app/views/charges/create.html.slim b/app/views/charges/create.html.slim new file mode 100644 index 0000000..c7153b2 --- /dev/null +++ b/app/views/charges/create.html.slim @@ -0,0 +1,3 @@ +h1 = title 'Vielen Dank für Ihre Spende' +p Auch dank Ihrer Hilfe können wir uns aktiv für die Interessen der Cannabis-Konsumenten einsetzen. + diff --git a/app/views/pages/donation.de.slim b/app/views/pages/donation.de.slim index 1124bb6..a7c6bc7 100644 --- a/app/views/pages/donation.de.slim +++ b/app/views/pages/donation.de.slim @@ -1,12 +1,19 @@ h1 = title 'Deine Spende zählt - Verein Legalize it!' -p - dl.dl-horizontal - dt Postkonto: - dd 87-091354-3, Verein Legalize it!, Postfach 2159, 8031 Zürich - dt IBAN: - dd CH02 0900 0000 8709 1354 3 - dt Zahlungszweck: - dd Spende Initiative + +script src="https://checkout.stripe.com/checkout.js" +javascript: + var handler = StripeCheckout.configure({ + key: "#{Rails.configuration.stripe[:publishable_key]}", + locale: '#{I18n.locale}', + image: '#{image_url("ch420_logo.png")}', + name: 'Verein Legalize it!', + currency: 'CHF', + description: 'Initiativspende', + token: function(token) { + $('input#stripeToken').val(token.id); + $('form').submit(); + } + }); h2 Spendenbarometer b Aktueller Stand: 62'000 CHF @@ -32,31 +39,96 @@ b Aktueller Stand: 62'000 CHF p Detailliertere Informationen, wie dieses Geld eingesetzt wird, findest du unter «Wie macht man eine Volksinitiative?» +h2 Via Kreditkarte online speden += form_tag charges_path do + = hidden_field_tag(:stripeToken) + #error_explanation.text-danger + = flash[:error] if flash[:error].present? + .row + .col-xs12.col-md-5 + button.donatebox.btn.btn-success onclick="donate(20)" 20 .- + button.donatebox.btn.btn-success onclick="donate(50)" 50 .- + button.donatebox.btn.btn-success onclick="donate(100)" 100 .- + button.donatebox.btn.btn-success onclick="donate(200)" 200 .- + .col-xs12.col-md-6 + .form-group + strong oder einen eigenen Betrag + .form-group + .input-group + .input-group-addon CHF + = text_field_tag(:amount, 50 , class: 'form-control') + + .form-group + button#donateButton.btn.btn-success Spenden übermitteln + + + +h2 Mit Bitcoin und Bitcoin Cash spenden .row - .col-md-7.col-xs-12 - = link_to asset_path('Einzahlungsschein_Spende_Initiative.pdf') do - = image_tag('Einzahlungsschein_Spende_Initiative.jpg', class:'img-responsive pagelogo', alt: 'Einzahlungsschein Spende initiative') - .col-md-5.col-xs-12 + .col-md-6.col-xs-12 p = image_tag '1LaYbTiCjhrUhxrQ9D5BQUfxPmRqJ7Q3gG.png', alt: 'Bitcoin Adresse: 1LaYbTiCjhrUhxrQ9D5BQUfxPmRqJ7Q3gG', width: '150', class: 'pull-right' div | Gerne nehmen wir auch Spenden via Bitcoin unter folgender Adresse entgegen: br strong 1LaYbTiCjhrUhxrQ9D5BQUfxPmRqJ7Q3gG - .clearfix - hr + .col-md-6.col-xs-12 p - = image_tag '1LVGcneFcYqCkhDFNsnhWb6x7cCHHxakg9.png', alt: 'Bitcoin Cash Adresse: 1LVGcneFcYqCkhDFNsnhWb6x7cCHHxakg9', width: '150', class: 'pull-left' + = image_tag '1LVGcneFcYqCkhDFNsnhWb6x7cCHHxakg9.png', alt: 'Bitcoin Cash Adresse: 1LVGcneFcYqCkhDFNsnhWb6x7cCHHxakg9', width: '150', class: 'pull-right' div | Oder Bitcoin Cash unter folgender Adresse: br strong 1LVGcneFcYqCkhDFNsnhWb6x7cCHHxakg9 -h2 Warum kann ich nicht auch online oder per Kreditkarte spenden? -p Wir haben mehrere Versuche unternommen, dies mittels verschiedener (zahlbaren) Payment-Service-Providern zu ermöglichen, sind jedoch immer wieder gescheitert. Die Gründe dafür sind vielfältig: Zum einen bieten viele solche Dienstleister ihren Service gar nicht für Vereine an, zum anderen ist das Schweizer Vereinsrecht relativ liberal. Ein zentrales Register für Vereine wie in anderen Ländern üblich, gibt es nicht. Einzig ein Handelsregistereintrag könnte ein wenig Klarheit schaffen. Dies ist jedoch zu kostspielig und würde momentan zu viel Zeit in Anspruch nehmen. Selbst wenn wir einen solchen hätten, wäre es nicht sicher, dass Dienste wie beispielsweise PayPal uns akzeptieren würden. -p Eine andere schwierigere Hürde ist unser Umfeld. Wir haben, genau wie in Amerika, die Schwierigkeit, dass unser Themenbereich Cannabis ist. Da der Umgang mit Cannabis illegal ist, scheinen die Banken der Logik verfallen zu sein, dass alles was mit Cannabis zu tun hat, auch illegal sei, notabene auch das Ändern des illegalen Status. Viele Finanzdienstleister wie etwa Stripe.com lehnen daher jegliche Zusammenarbeit kategorisch ab. +.clearfix -p Somit bleibt nur zum guten alten Einzahlungsschein zu greifen beziehungsweise die richtigen Zahlenkombinationen beim E-Banking an den richtigen Stellen einzufügen. +h2 Per Überweisung spenden +.row + .col-md-7.col-xs-12 + dl.dl-horizontal + dt Postkonto: + dd 87-091354-3, Verein Legalize it!, Postfach 2159, 8031 Zürich + dt IBAN: + dd CH02 0900 0000 8709 1354 3 + dt Zahlungszweck: + dd Spende Initiative + .col-md-5.col-xs-12 + = link_to asset_path('Einzahlungsschein_Spende_Initiative.pdf') do + = image_tag('Einzahlungsschein_Spende_Initiative.jpg', class:'img-responsive', alt: 'Einzahlungsschein Spende initiative') + + p b Wir würden uns freuen, wenn ihr das macht und uns finanziell unter die Arme greift. p Danke, dein Verein Legalize it! + +javascript: + $('.donatebox').on('click', function(e) { + e.preventDefault(); + }); + + function donate(amount) { + $('#amount').val(amount); + $('#donateButton').click(); + } + + $('#donateButton').on('click', function(e) { + e.preventDefault(); + + $('#error_explanation').html(''); + + var amount = $('input#amount').val(); + amount = parseFloat(amount); + + if (isNaN(amount)) { + $('#error_explanation').html('

Bitte geben sie einen Betrag in CHF ein.

'); + } + else if (amount < 5.00) { + $('#error_explanation').html('

Ihre Spende muss mindestens 5.- CHF betragen.

'); + } + else { + amount = amount * 100; // Needs to be an integer! + handler.open({ + amount: Math.round(amount) + }) + } + }); \ No newline at end of file diff --git a/config/initializers/stripe.rb b/config/initializers/stripe.rb new file mode 100644 index 0000000..83267be --- /dev/null +++ b/config/initializers/stripe.rb @@ -0,0 +1,5 @@ +Rails.configuration.stripe = { + :publishable_key => ENV['PUBLISHABLE_KEY'], + :secret_key => ENV['SECRET_KEY'] +} +Stripe.api_key = Rails.configuration.stripe[:secret_key] \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 6285301..5281711 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -28,6 +28,7 @@ Rails.application.routes.draw do resources :supporters, only: [:new, :create] resource :publicity get '/thanks', to: 'pages#thanks', as: :thanks + resources :charges end mount RailsAdmin::Engine => '/admin', as: 'rails_admin'