diff --git a/app/controllers/choice/choice_controller.rb b/app/controllers/choice/choice_controller.rb index 646725a..bd9ae2d 100644 --- a/app/controllers/choice/choice_controller.rb +++ b/app/controllers/choice/choice_controller.rb @@ -1,7 +1,30 @@ module Choice class ChoiceController < Choice::ApplicationController def create - head 200 + @badge = consumer_defender_badge + @user = @discourse_api.client.user + + customer = Stripe::Customer.create( + :email => params[:stripeEmail], + :source => params[:stripeToken] + ) + + charge = Stripe::Charge.create( + :customer => customer.id, + :amount => params[:amount], + :description => 'Consumer Defender', + :currency => 'aud' + ) + + + + head :created + end + + private + + def consumer_defender_badge + Discourse.badges['badges'].select { |b| b['name'] == 'Consumer Defender' }.first end end end diff --git a/plugin.rb b/plugin.rb index 4c14b9b..5d97ee6 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,10 +1,17 @@ # name: choice-plugin -# about: Integrating CHOICE with Discourse -# version: 0.0.2 +# about: Integrating Discourse with Stripe +# version: 0.0.3 # authors: Rimian Perkins gem 'stripe', '1.58.0' +Rails.configuration.stripe = { + :publishable_key => ENV['STRIPE_PUBLISHABLE_KEY'], + :secret_key => ENV['STRIPE_SECRET_KEY'] +} + +Stripe.api_key = Rails.configuration.stripe[:secret_key] + module ::Choice class Engine < ::Rails::Engine engine_name 'choice'