diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index f56df25..b6d3f07 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -21,6 +21,8 @@ module DiscoursePatrons group.add(current_user) end + DiscoursePatrons::Customer.create(user_id: current_user.id, customer_id: params[:customer]) + render_json_dump @subscription rescue ::Stripe::InvalidRequestError => e diff --git a/assets/javascripts/discourse/discourse-patrons-user-route-map.js.es6 b/assets/javascripts/discourse/discourse-patrons-user-route-map.js.es6 index 3024a30..f94ffbb 100644 --- a/assets/javascripts/discourse/discourse-patrons-user-route-map.js.es6 +++ b/assets/javascripts/discourse/discourse-patrons-user-route-map.js.es6 @@ -3,5 +3,6 @@ export default { path: "users/:username", map() { this.route("billing"); + this.route("subscriptions"); } }; diff --git a/assets/javascripts/discourse/routes/user-subscriptions.js.es6 b/assets/javascripts/discourse/routes/user-subscriptions.js.es6 new file mode 100644 index 0000000..e69de29 diff --git a/assets/javascripts/discourse/templates/user/billing.hbs b/assets/javascripts/discourse/templates/user/billing.hbs index d1ea854..e73da42 100644 --- a/assets/javascripts/discourse/templates/user/billing.hbs +++ b/assets/javascripts/discourse/templates/user/billing.hbs @@ -2,6 +2,13 @@

{{i18n 'discourse_patrons.user.billing.title'}}

{{#if model}} +

+ {{#link-to 'user.subscriptions' class="btn btn-primary"}} + {{d-icon "credit-card"}} + {{i18n 'discourse_patrons.user.subscriptions.title'}} + {{/link-to}} +

+ diff --git a/assets/javascripts/discourse/templates/user/subscriptions.hbs b/assets/javascripts/discourse/templates/user/subscriptions.hbs new file mode 100644 index 0000000..843ddd4 --- /dev/null +++ b/assets/javascripts/discourse/templates/user/subscriptions.hbs @@ -0,0 +1,2 @@ + +

{{i18n 'discourse_patrons.user.subscriptions.title'}}

diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 64edaaa..3acaad3 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -21,6 +21,8 @@ en: subscribe: Subscribe billing: Billing user: + subscriptions: + title: Subscriptions billing_help: We couldn't find a customer identifier in our system. billing: title: Billing diff --git a/spec/requests/subscriptions_controller_spec.rb b/spec/requests/subscriptions_controller_spec.rb index b3d87b8..b6e028f 100644 --- a/spec/requests/subscriptions_controller_spec.rb +++ b/spec/requests/subscriptions_controller_spec.rb @@ -20,6 +20,15 @@ module DiscoursePatrons ) post "/patrons/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' } end + + it "creates a customer" do + ::Stripe::Plan.expects(:retrieve).returns(metadata: {}) + ::Stripe::Subscription.expects(:create).returns(status: 'active') + + expect { + post "/patrons/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' } + }.to change { DiscoursePatrons::Customer.count } + end end describe "user groups" do
{{i18n 'discourse_patrons.user.billing.invoices.amount'}}