mirror of
https://github.com/discourse/discourse-subscriptions.git
synced 2025-03-06 17:49:24 +00:00
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]
|
skip_before_filter :verify_authenticity_token, only: [:create]
|
||||||
|
|
||||||
def create
|
def create
|
||||||
Stripe.api_key = SiteSetting.discourse_donations_secret_key
|
if email.nil?
|
||||||
currency = SiteSetting.discourse_donations_currency
|
response = {
|
||||||
|
|
||||||
customer = Stripe::Customer.create(
|
}
|
||||||
:email => params[:email] || current_user.email,
|
else
|
||||||
:source => params[:stripeToken]
|
Stripe.api_key = SiteSetting.discourse_donations_secret_key
|
||||||
)
|
currency = SiteSetting.discourse_donations_currency
|
||||||
|
|
||||||
charge = Stripe::Charge.create(
|
customer = Stripe::Customer.create(
|
||||||
:customer => customer.id,
|
:email => email,
|
||||||
:amount => params[:amount],
|
:source => params[:stripeToken]
|
||||||
:description => SiteSetting.discourse_donations_description,
|
)
|
||||||
:currency => currency
|
|
||||||
)
|
|
||||||
|
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -14,6 +14,11 @@ module DiscourseDonations
|
|||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
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
|
it 'responds ok for logged in user' do
|
||||||
current_user = log_in(:coding_horror)
|
current_user = log_in(:coding_horror)
|
||||||
post :create
|
post :create
|
||||||
|
Loading…
x
Reference in New Issue
Block a user