convert amount in param

This commit is contained in:
Rimian Perkins 2019-09-12 11:49:52 +10:00
parent c636a2896a
commit ce258d3d08
2 changed files with 19 additions and 1 deletions

View File

@ -15,7 +15,7 @@ module DiscoursePatrons
begin
response = ::Stripe::PaymentIntent.create(
amount: params[:amount],
amount: param_currency_to_number,
currency: SiteSetting.discourse_patrons_currency,
payment_method_types: ['card'],
payment_method: params[:paymentMethodId],
@ -30,5 +30,11 @@ module DiscoursePatrons
render json: response
end
private
def param_currency_to_number
params[:amount].to_s.sub('.', '').to_i
end
end
end

View File

@ -24,6 +24,18 @@ module DiscoursePatrons
post :create, params: {}, format: :json
expect(response).to have_http_status(200)
end
it 'has the correct amount' do
::Stripe::PaymentIntent.expects(:create).with(has_entry(:amount, 2000))
post :create, params: { amount: '20.00' }, format: :json
expect(response).to have_http_status(200)
end
it 'has no amount' do
::Stripe::PaymentIntent.expects(:create).with(has_entry(:amount, 0))
post :create, params: {}, format: :json
expect(response).to have_http_status(200)
end
end
end
end