mirror of
https://github.com/discourse/discourse-subscriptions.git
synced 2025-07-09 07:33:28 +00:00
stripe service can create subscriptions
This commit is contained in:
parent
f99aed364b
commit
9d2cd86f54
@ -23,6 +23,18 @@ module DiscourseDonations
|
|||||||
@charge
|
@charge
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def subscribe(email, opts)
|
||||||
|
customer = ::Stripe::Customer.create(
|
||||||
|
email: email,
|
||||||
|
source: opts[:stripeToken]
|
||||||
|
)
|
||||||
|
@subscription = ::Stripe::Subscription.create(
|
||||||
|
customer: customer.id,
|
||||||
|
plan: opts[:plan]
|
||||||
|
)
|
||||||
|
@subscription
|
||||||
|
end
|
||||||
|
|
||||||
def successful?
|
def successful?
|
||||||
@charge[:paid]
|
@charge[:paid]
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,6 @@ module DiscourseDonations
|
|||||||
before { SiteSetting.stubs(:discourse_donations_secret_key).returns('secret-key-yo') }
|
before { SiteSetting.stubs(:discourse_donations_secret_key).returns('secret-key-yo') }
|
||||||
|
|
||||||
let(:stripe_options) { { description: 'hi there', currency: 'AUD' } }
|
let(:stripe_options) { { description: 'hi there', currency: 'AUD' } }
|
||||||
let(:params) { { email: email, stripeToken: 'stripe-token', amount: '1234', other: 'redundant param' } }
|
|
||||||
let(:email) { 'ray-zintoast@example.com' }
|
let(:email) { 'ray-zintoast@example.com' }
|
||||||
let(:customer) { stub(id: 1) }
|
let(:customer) { stub(id: 1) }
|
||||||
let!(:subject) { described_class.new('secret-key-yo', stripe_options) }
|
let!(:subject) { described_class.new('secret-key-yo', stripe_options) }
|
||||||
@ -15,6 +14,25 @@ module DiscourseDonations
|
|||||||
expect(::Stripe.api_key).to eq 'secret-key-yo'
|
expect(::Stripe.api_key).to eq 'secret-key-yo'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'subscribe' do
|
||||||
|
let(:params) { { email: email, stripeToken: 'stripe-token', plan: 'subscription-plan-1234', other: 'redundant param' } }
|
||||||
|
|
||||||
|
it 'creates a customer and a subscription' do
|
||||||
|
::Stripe::Customer.expects(:create).with(
|
||||||
|
email: email,
|
||||||
|
source: 'stripe-token'
|
||||||
|
).returns(customer)
|
||||||
|
::Stripe::Subscription.expects(:create).with(
|
||||||
|
customer: customer.id,
|
||||||
|
plan: params[:plan]
|
||||||
|
)
|
||||||
|
subject.subscribe(email, params)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'charge' do
|
||||||
|
let(:params) { { email: email, stripeToken: 'stripe-token', amount: '1234', other: 'redundant param' } }
|
||||||
|
|
||||||
it 'creates a customer and charges them an amount' do
|
it 'creates a customer and charges them an amount' do
|
||||||
::Stripe::Customer.expects(:create).with(
|
::Stripe::Customer.expects(:create).with(
|
||||||
email: email,
|
email: email,
|
||||||
@ -33,8 +51,10 @@ module DiscourseDonations
|
|||||||
)
|
)
|
||||||
subject.charge(email, params)
|
subject.charge(email, params)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '.successful?' do
|
describe '.successful?' do
|
||||||
|
let(:params) { { email: email, stripeToken: 'stripe-token', amount: '1234', other: 'redundant param' } }
|
||||||
let(:charge_options) { { customer: customer.id, amount: params[:amount], description: stripe_options[:description], currency: stripe_options[:currency] } }
|
let(:charge_options) { { customer: customer.id, amount: params[:amount], description: stripe_options[:description], currency: stripe_options[:currency] } }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user