fix params

This commit is contained in:
Rimian Perkins 2019-09-13 14:34:06 +10:00
parent 4287e8aa5d
commit c90d4b2f8e
6 changed files with 39 additions and 6 deletions

View File

@ -23,9 +23,9 @@ module DiscoursePatrons
amount: param_currency_to_number, amount: param_currency_to_number,
currency: SiteSetting.discourse_patrons_currency, currency: SiteSetting.discourse_patrons_currency,
payment_method_types: ['card'], payment_method_types: ['card'],
payment_method: params[:paymentMethodId], payment_method: params[:payment_method_id],
description: SiteSetting.discourse_patrons_payment_description, description: SiteSetting.discourse_patrons_payment_description,
receipt_email: params[:receiptEmail], receipt_email: params[:receipt_email],
confirm: true, confirm: true,
) )

4
app/models/payment.rb Normal file
View File

@ -0,0 +1,4 @@
# frozen_string_literal: true
class Payment < ActiveRecord::Base
end

View File

@ -33,9 +33,9 @@ export default Ember.Component.extend({
confirmStripeCard() { confirmStripeCard() {
const data = { const data = {
paymentMethodId: this.confirmation.id, payment_method_id: this.confirmation.id,
amount: this.amount, amount: this.amount,
receiptEmail: this.receiptEmail receipt_email: this.receiptEmail
}; };
this.stripePaymentHandler(data).then(paymentIntent => { this.stripePaymentHandler(data).then(paymentIntent => {

View File

@ -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

View File

@ -32,7 +32,6 @@ after_initialize do
"../app/models/payment", "../app/models/payment",
].each { |path| require File.expand_path(path, __FILE__) } ].each { |path| require File.expand_path(path, __FILE__) }
Discourse::Application.routes.append do Discourse::Application.routes.append do
mount ::DiscoursePatrons::Engine, at: 'patrons' mount ::DiscoursePatrons::Engine, at: 'patrons'
end end

View File

@ -39,6 +39,13 @@ module DiscoursePatrons
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end 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 it 'has the correct amount' do
::Stripe::PaymentIntent.expects(:create).with(has_entry(:amount, 2000)) ::Stripe::PaymentIntent.expects(:create).with(has_entry(:amount, 2000))
post :create, params: { amount: '20.00' }, format: :json post :create, params: { amount: '20.00' }, format: :json
@ -59,7 +66,13 @@ module DiscoursePatrons
it 'has a receipt email' do it 'has a receipt email' do
::Stripe::PaymentIntent.expects(:create).with(has_entry(:receipt_email, 'hello@example.com')) ::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) expect(response).to have_http_status(200)
end end