addes stripe

This commit is contained in:
2017-10-18 23:32:28 +02:00
parent e44d5935f2
commit c5b7b79b7b
11 changed files with 153 additions and 20 deletions
+29
View File
@@ -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