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,
receipt_email: params[:receipt_email],
confirm: true,
customer: user_id
)
Payment.create(
user_id: user_id,
user_id: response[:customer],
payment_intent_id: response[:id],
receipt_email: response[:receipt_email],
url: response[:charges][:url],

View File

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