fix subscribe request
This commit is contained in:
parent
7edb0fe39b
commit
2a985ae554
|
@ -38,7 +38,9 @@ module DiscoursePatrons
|
|||
group.add(current_user)
|
||||
end
|
||||
|
||||
DiscoursePatrons::Customer.create(user_id: current_user.id, customer_id: params[:customer])
|
||||
unless DiscoursePatrons::Customer.exists?(user_id: current_user.id)
|
||||
DiscoursePatrons::Customer.create(user_id: current_user.id, customer_id: params[:customer])
|
||||
end
|
||||
|
||||
render_json_dump @subscription
|
||||
|
||||
|
|
|
@ -13,8 +13,9 @@ export default Discourse.Route.extend({
|
|||
};
|
||||
|
||||
const plans = Plan.findAll().then(results =>
|
||||
results.map(p => planSelectText(p))
|
||||
results.map(p => ({ id: p.id, name: planSelectText(p) }))
|
||||
);
|
||||
|
||||
const subscription = Subscription.create();
|
||||
|
||||
return Ember.RSVP.hash({ plans, subscription });
|
||||
|
|
|
@ -20,4 +20,5 @@ DiscoursePatrons::Engine.routes.draw do
|
|||
resources :subscriptions, only: [:index, :create]
|
||||
|
||||
get '/' => 'patrons#index'
|
||||
get '/subscribe' => 'patrons#index'
|
||||
end
|
||||
|
|
|
@ -51,6 +51,15 @@ module DiscoursePatrons
|
|||
post "/patrons/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' }
|
||||
}.to change { DiscoursePatrons::Customer.count }
|
||||
end
|
||||
|
||||
it "does not create a customer id one existeth" do
|
||||
::Stripe::Plan.expects(:retrieve).returns(metadata: {})
|
||||
::Stripe::Subscription.expects(:create).returns(status: 'active')
|
||||
DiscoursePatrons::Customer.create(user_id: user.id, customer_id: 'cus_1234')
|
||||
|
||||
DiscoursePatrons::Customer.expects(:create).never
|
||||
post "/patrons/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' }
|
||||
end
|
||||
end
|
||||
|
||||
describe "user groups" do
|
||||
|
|
Loading…
Reference in New Issue