normalize the message from stripe

This commit is contained in:
Rimian Perkins 2017-04-20 11:09:59 +10:00
parent d98ba20d0d
commit e09b852361
4 changed files with 11 additions and 16 deletions

View File

@ -7,12 +7,11 @@ module DiscourseDonations
skip_before_filter :verify_authenticity_token, only: [:create]
def create
if !email.nil? || email.empty?
response = {}
else
byebug
if email.present?
payment = DiscourseDonations::Stripe.new(secret_key, stripe_options)
response = payment.charge(email, params)
else
response = {}
end
render :json => response

View File

@ -18,6 +18,7 @@ module DiscourseDonations
description: @description,
currency: @currency
)
@charge[:message] = @charge[:outcome][:seller_message] if @charge[:outcome]
@charge
end

View File

@ -15,7 +15,6 @@ after_initialize do
header_script = '<script src="https://js.stripe.com/v3/"></script>'
discourse_donations_theme = Theme.find_or_create_by(name: 'Discourse Donations Header', hidden: false, user_id: -1)
discourse_donations_theme.set_field('common', 'head_tag', header_script)
discourse_donations_theme.save
end
Discourse::Application.routes.prepend do

View File

@ -20,16 +20,6 @@ module DiscourseDonations
email: email,
source: 'stripe-token'
).returns(customer)
::Stripe::Charge.expects(:create).with(
customer: customer.id,
amount: params[:amount],
description: stripe_options[:description],
currency: stripe_options[:currency]
)
subject.charge(email, params)
end
it 'has a message' do
::Stripe::Charge.expects(:create).with(
customer: customer.id,
amount: params[:amount],
@ -42,7 +32,13 @@ module DiscourseDonations
}
)
subject.charge(email, params)
expect(subject.message).to eq 'yay!'
end
it 'has a message' do
::Stripe::Customer.expects(:create).returns(customer)
::Stripe::Charge.expects(:create).returns({ outcome: { seller_message: 'yay!' } })
response = subject.charge(email, params)
expect(response[:message]).to eq 'yay!'
end
describe '.successful?' do