2019-12-12 18:41:14 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
module DiscourseSubscriptions
|
|
|
|
RSpec.describe PaymentsController do
|
|
|
|
context "not authenticated" do
|
|
|
|
it "does not create a payment intent" do
|
|
|
|
::Stripe::PaymentIntent.expects(:create).never
|
2019-12-12 19:54:32 -05:00
|
|
|
|
|
|
|
post "/s/payments.json", params: {
|
|
|
|
payment_method: 'pm_123',
|
|
|
|
amount: 999,
|
|
|
|
currency: 'gdp'
|
|
|
|
}
|
2019-12-12 18:41:14 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "authenticated" do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "create" do
|
|
|
|
it "creates a payment intent" do
|
2019-12-16 18:03:00 -05:00
|
|
|
::Stripe::Customer.expects(:create).with(
|
|
|
|
email: user.email
|
|
|
|
).returns(id: 'cus_87653')
|
|
|
|
|
2019-12-12 18:41:14 -05:00
|
|
|
::Stripe::PaymentIntent.expects(:create).with(
|
|
|
|
payment_method_types: ['card'],
|
|
|
|
payment_method: 'pm_123',
|
|
|
|
amount: '999',
|
|
|
|
currency: 'gdp',
|
2019-12-16 18:03:00 -05:00
|
|
|
confirm: true,
|
|
|
|
customer: 'cus_87653'
|
2019-12-12 18:41:14 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
post "/s/payments.json", params: {
|
|
|
|
payment_method: 'pm_123',
|
|
|
|
amount: 999,
|
|
|
|
currency: 'gdp'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|