Files

30 lines
721 B
Ruby
Raw Permalink Normal View History

2017-10-18 23:32:28 +02:00
class ChargesController < ApplicationController
def new; end
def create
@amount = params[:amount]
begin
@amount = Float(@amount).round(2)
rescue
2017-12-15 23:12:43 +01:00
flash[:danger] = 'Bitte geben sie einen Betrag in CHF ein.'
2017-10-18 23:32:28 +02:00
redirect_to donation_path
return
end
@amount = (@amount * 100).to_i # Must be an integer!
2017-12-15 23:12:43 +01:00
if @amount < 1000
flash[:danger] = 'Ihre Spende muss mindestens 10.- CHF betragen.'
2017-10-18 23:32:28 +02:00
redirect_to donation_path
return
end
Stripe::Charge.create(amount: @amount, currency: 'CHF', source: params[:stripeToken], description: 'Initiativspende')
rescue Stripe::CardError => e
2017-12-18 21:04:06 +01:00
flash[:danger] = e.message
2017-10-18 23:32:28 +02:00
redirect_to donation_path
end
end