respond with empty json if email does not exist
This commit is contained in:
parent
7754513b49
commit
391171d560
|
@ -7,22 +7,34 @@ module DiscourseDonations
|
|||
skip_before_filter :verify_authenticity_token, only: [:create]
|
||||
|
||||
def create
|
||||
Stripe.api_key = SiteSetting.discourse_donations_secret_key
|
||||
currency = SiteSetting.discourse_donations_currency
|
||||
if email.nil?
|
||||
response = {
|
||||
|
||||
customer = Stripe::Customer.create(
|
||||
:email => params[:email] || current_user.email,
|
||||
:source => params[:stripeToken]
|
||||
)
|
||||
}
|
||||
else
|
||||
Stripe.api_key = SiteSetting.discourse_donations_secret_key
|
||||
currency = SiteSetting.discourse_donations_currency
|
||||
|
||||
charge = Stripe::Charge.create(
|
||||
:customer => customer.id,
|
||||
:amount => params[:amount],
|
||||
:description => SiteSetting.discourse_donations_description,
|
||||
:currency => currency
|
||||
)
|
||||
customer = Stripe::Customer.create(
|
||||
:email => email,
|
||||
:source => params[:stripeToken]
|
||||
)
|
||||
|
||||
render :json => charge
|
||||
response = Stripe::Charge.create(
|
||||
:customer => customer.id,
|
||||
:amount => params[:amount],
|
||||
:description => SiteSetting.discourse_donations_description,
|
||||
:currency => currency
|
||||
)
|
||||
end
|
||||
|
||||
render :json => response
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def email
|
||||
params[:email] || current_user.try(:email)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,6 +14,11 @@ module DiscourseDonations
|
|||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'responds ok when the email is empty' do
|
||||
post :create, { }
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'responds ok for logged in user' do
|
||||
current_user = log_in(:coding_horror)
|
||||
post :create
|
||||
|
|
Loading…
Reference in New Issue