2017-01-30 21:28:41 -05:00
|
|
|
module Choice
|
|
|
|
class ChoiceController < Choice::ApplicationController
|
2017-01-30 22:21:27 -05:00
|
|
|
def create
|
2017-02-01 19:49:22 -05:00
|
|
|
badge = Badge.find_by_name('Consumer Defender')
|
|
|
|
|
|
|
|
if badge.nil?
|
|
|
|
head 422 and return
|
|
|
|
end
|
|
|
|
|
2017-01-31 21:35:18 -05:00
|
|
|
customer = Stripe::Customer.create(
|
|
|
|
:email => params[:stripeEmail],
|
|
|
|
:source => params[:stripeToken]
|
|
|
|
)
|
|
|
|
|
|
|
|
charge = Stripe::Charge.create(
|
|
|
|
:customer => customer.id,
|
2017-02-01 19:49:22 -05:00
|
|
|
:amount => 1000,
|
2017-01-31 21:35:18 -05:00
|
|
|
:description => 'Consumer Defender',
|
|
|
|
:currency => 'aud'
|
|
|
|
)
|
|
|
|
|
2017-02-01 19:49:22 -05:00
|
|
|
BadgeGranter.grant(badge, current_user)
|
2017-01-31 21:35:18 -05:00
|
|
|
|
2017-02-01 21:11:10 -05:00
|
|
|
render :json => { status: 'OK' }
|
2017-01-30 21:28:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|