Create Plans
* rescue and respond to error from stripe * save plan name and id
This commit is contained in:
parent
99abd87c73
commit
6f9195a7d4
|
|
@ -12,22 +12,32 @@ module DiscoursePatrons
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
begin
|
||||||
|
|
||||||
plan = ::Stripe::Plan.create(
|
plan = ::Stripe::Plan.create(
|
||||||
amount: params[:amount],
|
amount: params[:amount],
|
||||||
interval: params[:interval],
|
interval: params[:interval],
|
||||||
product: {
|
product: { name: params[:name] },
|
||||||
name: 'Gold special',
|
|
||||||
},
|
|
||||||
currency: SiteSetting.discourse_patrons_currency,
|
currency: SiteSetting.discourse_patrons_currency,
|
||||||
id: 'gold-special',
|
id: plan_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
render json: plan
|
render_json_dump plan
|
||||||
|
|
||||||
|
rescue ::Stripe::InvalidRequestError => e
|
||||||
|
return render_json_error e.message
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
plan = ::Stripe::Plan.delete(params[:id])
|
plan = ::Stripe::Plan.delete(params[:id])
|
||||||
render json: plan
|
render json: plan
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def plan_id
|
||||||
|
params[:name].parameterize.dasherize if params[:name]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import computed from "ember-addons/ember-computed-decorators";
|
import computed from "ember-addons/ember-computed-decorators";
|
||||||
|
import DiscourseURL from "discourse/lib/url";
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
@computed("model.plans")
|
@computed("model.plans")
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
actions: {
|
actions: {
|
||||||
createPlan() {
|
createPlan() {
|
||||||
|
|
@ -5,7 +7,8 @@ export default Ember.Controller.extend({
|
||||||
.save()
|
.save()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.transitionToRoute("adminPlugins.discourse-patrons.plans");
|
this.transitionToRoute("adminPlugins.discourse-patrons.plans");
|
||||||
});
|
})
|
||||||
|
.catch(popupAjaxError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,16 @@ module DiscoursePatrons
|
||||||
::Stripe::Plan.expects(:create).with(has_entry(:amount, '102'))
|
::Stripe::Plan.expects(:create).with(has_entry(:amount, '102'))
|
||||||
post "/patrons/admin/plans.json", params: { amount: '102' }
|
post "/patrons/admin/plans.json", params: { amount: '102' }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "creates a plan with a title" do
|
||||||
|
::Stripe::Plan.expects(:create).with(has_entry(:product, name: 'Rick Astley'))
|
||||||
|
post "/patrons/admin/plans.json", params: { name: 'Rick Astley' }
|
||||||
|
end
|
||||||
|
|
||||||
|
it "creates a plan with an id" do
|
||||||
|
::Stripe::Plan.expects(:create).with(has_entry(id: 'rick-astley'))
|
||||||
|
post "/patrons/admin/plans.json", params: { name: 'Rick Astley' }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "delete" do
|
describe "delete" do
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue