From 35ac1bc3c328270d5f3ac6b2c829b9306268dbb2 Mon Sep 17 00:00:00 2001 From: Rimian Perkins Date: Thu, 2 Feb 2017 11:49:22 +1100 Subject: [PATCH] Transaction works. Still need to tidy up response --- README.md | 6 +++++ app/controllers/choice/choice_controller.rb | 22 +++++++++++-------- .../user-profile-primary/stripe.hbs | 1 - plugin.rb | 4 ++-- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index d194931..12f8179 100644 --- a/README.md +++ b/README.md @@ -1 +1,7 @@ # CHOICE Discourse + +Enables stripe payments from discourse. + +# Configuration + +You can either set your environment vars in docker or save them in a yaml. diff --git a/app/controllers/choice/choice_controller.rb b/app/controllers/choice/choice_controller.rb index 7969c73..3dcecc3 100644 --- a/app/controllers/choice/choice_controller.rb +++ b/app/controllers/choice/choice_controller.rb @@ -1,6 +1,12 @@ module Choice class ChoiceController < Choice::ApplicationController def create + badge = Badge.find_by_name('Consumer Defender') + + if badge.nil? + head 422 and return + end + customer = Stripe::Customer.create( :email => params[:stripeEmail], :source => params[:stripeToken] @@ -8,20 +14,18 @@ module Choice charge = Stripe::Charge.create( :customer => customer.id, - :amount => params[:amount], + :amount => 1000, :description => 'Consumer Defender', :currency => 'aud' ) - BadgeGranter.grant(consumer_defender_badge, current_user) + BadgeGranter.grant(badge, current_user) - head :created - end - - private - - def consumer_defender_badge - Badge.find_by_name('Consumer Defender') + respond_to do |format| + format.html + format.js + format.json { render :json => { status: 'OK' } } + end end end end diff --git a/assets/javascripts/discourse/templates/connectors/user-profile-primary/stripe.hbs b/assets/javascripts/discourse/templates/connectors/user-profile-primary/stripe.hbs index 91c523a..b71e57c 100644 --- a/assets/javascripts/discourse/templates/connectors/user-profile-primary/stripe.hbs +++ b/assets/javascripts/discourse/templates/connectors/user-profile-primary/stripe.hbs @@ -12,7 +12,6 @@ data-currency="aud" data-label="Become a Consumer Defender" data-email="{{model.email}}" - data-amount="1000" > diff --git a/plugin.rb b/plugin.rb index 5d97ee6..35a292d 100644 --- a/plugin.rb +++ b/plugin.rb @@ -6,8 +6,8 @@ gem 'stripe', '1.58.0' Rails.configuration.stripe = { - :publishable_key => ENV['STRIPE_PUBLISHABLE_KEY'], - :secret_key => ENV['STRIPE_SECRET_KEY'] + :publishable_key => ENV['STRIPE_PUBLISHABLE_KEY'] || Rails.application.config_for(:stripe)['publishable_key'], + :secret_key => ENV['STRIPE_SECRET_KEY'] || Rails.application.config_for(:stripe)['secret_key'] } Stripe.api_key = Rails.configuration.stripe[:secret_key]