diff --git a/app/controllers/discourse_donations/charges_controller.rb b/app/controllers/discourse_donations/charges_controller.rb index 753844b..c6e6962 100644 --- a/app/controllers/discourse_donations/charges_controller.rb +++ b/app/controllers/discourse_donations/charges_controller.rb @@ -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 diff --git a/app/services/discourse_donations/stripe.rb b/app/services/discourse_donations/stripe.rb index 3cf82bf..a8e4fa4 100644 --- a/app/services/discourse_donations/stripe.rb +++ b/app/services/discourse_donations/stripe.rb @@ -18,6 +18,7 @@ module DiscourseDonations description: @description, currency: @currency ) + @charge[:message] = @charge[:outcome][:seller_message] if @charge[:outcome] @charge end diff --git a/plugin.rb b/plugin.rb index 8cd7b4a..d8fdf77 100644 --- a/plugin.rb +++ b/plugin.rb @@ -15,7 +15,6 @@ after_initialize do header_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 diff --git a/spec/services/discourse_donations/stripe_spec.rb b/spec/services/discourse_donations/stripe_spec.rb index 32913b5..cc7f30c 100644 --- a/spec/services/discourse_donations/stripe_spec.rb +++ b/spec/services/discourse_donations/stripe_spec.rb @@ -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