send the customer to the payment api

This commit is contained in:
Rimian Perkins 2019-09-14 21:00:56 +10:00
parent ad5961a4c5
commit bc8ae3449d
2 changed files with 13 additions and 3 deletions

View File

@ -32,10 +32,11 @@ module DiscoursePatrons
description: SiteSetting.discourse_patrons_payment_description, description: SiteSetting.discourse_patrons_payment_description,
receipt_email: params[:receipt_email], receipt_email: params[:receipt_email],
confirm: true, confirm: true,
customer: user_id
) )
Payment.create( Payment.create(
user_id: user_id, user_id: response[:customer],
payment_intent_id: response[:id], payment_intent_id: response[:id],
receipt_email: response[:receipt_email], receipt_email: response[:receipt_email],
url: response[:charges][:url], url: response[:charges][:url],

View File

@ -41,20 +41,23 @@ module DiscoursePatrons
end end
describe 'create' do describe 'create' do
let!(:current_user) { Fabricate(:user) }
let(:payment) do let(:payment) do
{ {
id: 'xyz-1234', id: 'xyz-1234',
charges: { url: '/v1/charges?payment_intent=xyz-1234' }, charges: { url: '/v1/charges?payment_intent=xyz-1234' },
amount: 9000, amount: 9000,
receipt_email: 'hello@example.com', receipt_email: 'hello@example.com',
currency: 'aud' currency: 'aud',
customer: current_user.id
} }
end end
before do before do
SiteSetting.stubs(:discourse_patrons_currency).returns('AUD') SiteSetting.stubs(:discourse_patrons_currency).returns('AUD')
SiteSetting.stubs(:discourse_patrons_secret_key).returns('xyz-678') SiteSetting.stubs(:discourse_patrons_secret_key).returns('xyz-678')
controller.stubs(:current_user).returns(Fabricate(:user)) controller.stubs(:current_user).returns(current_user)
end end
it 'responds ok' do it 'responds ok' do
@ -96,6 +99,12 @@ module DiscoursePatrons
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
it 'has the customer id' do
::Stripe::PaymentIntent.expects(:create).with(has_entry(:customer, current_user.id)).returns(payment)
post :create, params: {}, format: :json
expect(response).to have_http_status(200)
end
it 'has a receipt email' do it 'has a receipt email' do
::Stripe::PaymentIntent.expects(:create).with(has_entry(:receipt_email, 'hello@example.com')).returns(payment) ::Stripe::PaymentIntent.expects(:create).with(has_entry(:receipt_email, 'hello@example.com')).returns(payment)
post :create, params: { receipt_email: 'hello@example.com' }, format: :json post :create, params: { receipt_email: 'hello@example.com' }, format: :json