From c90d4b2f8e497da2bb7b7cf699c98c0ceaa17665 Mon Sep 17 00:00:00 2001 From: Rimian Perkins Date: Fri, 13 Sep 2019 14:34:06 +1000 Subject: [PATCH] fix params --- app/controllers/patrons_controller.rb | 4 ++-- app/models/payment.rb | 4 ++++ .../discourse/components/donation-form.js.es6 | 4 ++-- .../20190913010928_create_payments_table.rb | 17 +++++++++++++++++ plugin.rb | 1 - .../patrons_controller_spec.rb | 15 ++++++++++++++- 6 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 app/models/payment.rb create mode 100644 db/migrate/20190913010928_create_payments_table.rb diff --git a/app/controllers/patrons_controller.rb b/app/controllers/patrons_controller.rb index a45e3cd..181f5ab 100644 --- a/app/controllers/patrons_controller.rb +++ b/app/controllers/patrons_controller.rb @@ -23,9 +23,9 @@ module DiscoursePatrons amount: param_currency_to_number, currency: SiteSetting.discourse_patrons_currency, payment_method_types: ['card'], - payment_method: params[:paymentMethodId], + payment_method: params[:payment_method_id], description: SiteSetting.discourse_patrons_payment_description, - receipt_email: params[:receiptEmail], + receipt_email: params[:receipt_email], confirm: true, ) diff --git a/app/models/payment.rb b/app/models/payment.rb new file mode 100644 index 0000000..d0e90dd --- /dev/null +++ b/app/models/payment.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class Payment < ActiveRecord::Base +end diff --git a/assets/javascripts/discourse/components/donation-form.js.es6 b/assets/javascripts/discourse/components/donation-form.js.es6 index 0ed310f..8f93513 100644 --- a/assets/javascripts/discourse/components/donation-form.js.es6 +++ b/assets/javascripts/discourse/components/donation-form.js.es6 @@ -33,9 +33,9 @@ export default Ember.Component.extend({ confirmStripeCard() { const data = { - paymentMethodId: this.confirmation.id, + payment_method_id: this.confirmation.id, amount: this.amount, - receiptEmail: this.receiptEmail + receipt_email: this.receiptEmail }; this.stripePaymentHandler(data).then(paymentIntent => { diff --git a/db/migrate/20190913010928_create_payments_table.rb b/db/migrate/20190913010928_create_payments_table.rb new file mode 100644 index 0000000..7b8154a --- /dev/null +++ b/db/migrate/20190913010928_create_payments_table.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class CreatePaymentsTable < ActiveRecord::Migration[5.2] + def change + def change + create_table :payments do |t| + t.integer :payment_intent_id, null: false + t.string :receipt_email, null: false + t.string :url, null: false + t.integer :amount, null: false + t.timestamps + end + + add_index :payments, [:payment_intent_id], unique: true + end + end +end diff --git a/plugin.rb b/plugin.rb index a08eca0..056fa86 100644 --- a/plugin.rb +++ b/plugin.rb @@ -32,7 +32,6 @@ after_initialize do "../app/models/payment", ].each { |path| require File.expand_path(path, __FILE__) } - Discourse::Application.routes.append do mount ::DiscoursePatrons::Engine, at: 'patrons' end diff --git a/spec/controllers/discourse_patrons/patrons_controller_spec.rb b/spec/controllers/discourse_patrons/patrons_controller_spec.rb index 2ab8ec8..965cd0b 100644 --- a/spec/controllers/discourse_patrons/patrons_controller_spec.rb +++ b/spec/controllers/discourse_patrons/patrons_controller_spec.rb @@ -39,6 +39,13 @@ module DiscoursePatrons expect(response).to have_http_status(200) end + xit 'creates a payment' do + ::Stripe::PaymentIntent.expects(:create) + expect { + post :create, params: { receipt_email: 'hello@example.com', amount: '20.00' }, format: :json + }.to change { Payment.count } + end + it 'has the correct amount' do ::Stripe::PaymentIntent.expects(:create).with(has_entry(:amount, 2000)) post :create, params: { amount: '20.00' }, format: :json @@ -59,7 +66,13 @@ module DiscoursePatrons it 'has a receipt email' do ::Stripe::PaymentIntent.expects(:create).with(has_entry(:receipt_email, 'hello@example.com')) - post :create, params: { receiptEmail: 'hello@example.com' }, format: :json + post :create, params: { receipt_email: 'hello@example.com' }, format: :json + expect(response).to have_http_status(200) + end + + it 'has a payment method' do + ::Stripe::PaymentIntent.expects(:create).with(has_entry(:payment_method, 'xyz-1234')) + post :create, params: { payment_method_id: 'xyz-1234' }, format: :json expect(response).to have_http_status(200) end