Transaction works. Still need to tidy up response
This commit is contained in:
parent
39a53c8cd3
commit
35ac1bc3c3
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
data-currency="aud"
|
||||
data-label="Become a Consumer Defender"
|
||||
data-email="{{model.email}}"
|
||||
data-amount="1000"
|
||||
>
|
||||
</script>
|
||||
</form>
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue