diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index cc77dc6..5a647b4 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -31,7 +31,7 @@ module DiscoursePatrons @subscription = ::Stripe::Subscription.create( customer: params[:customer], items: [ { plan: params[:plan] } ], - metadata: { username_lower: current_user.username_lower }, + metadata: metadata_user, ) group = plan_group(plan) @@ -53,6 +53,10 @@ module DiscoursePatrons private + def metadata_user + { user_id: current_user.id, username: current_user.username_lower } + end + def plan_group(plan) Group.find_by_name(plan[:metadata][:group_name]) end diff --git a/assets/javascripts/discourse/models/admin-subscription.js.es6 b/assets/javascripts/discourse/models/admin-subscription.js.es6 index 9ef13f7..0c39e84 100644 --- a/assets/javascripts/discourse/models/admin-subscription.js.es6 +++ b/assets/javascripts/discourse/models/admin-subscription.js.es6 @@ -1,6 +1,20 @@ +import EmberObject from "@ember/object"; +import computed from "ember-addons/ember-computed-decorators"; import { ajax } from "discourse/lib/ajax"; -const AdminSubscription = Discourse.Model.extend({}); +const AdminSubscription = Discourse.Model.extend({ + @computed("metadata") + user(metadata) { + console.log(metadata); + if (metadata.user_id && metadata.username) { + return EmberObject.create({ + id: metadata.user_id, + username: metadata.username + }); + } + return false; + } +}); AdminSubscription.reopenClass({ find() { diff --git a/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-subscriptions.hbs b/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-subscriptions.hbs index 498ee4e..c06fd52 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-subscriptions.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-discourse-patrons-subscriptions.hbs @@ -2,6 +2,7 @@ + @@ -10,6 +11,13 @@ {{#each model as |subscription|}} + diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index ad40492..376acc9 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -123,6 +123,7 @@ en: subscriptions: title: Subscriptions subscription: + user: User subscription_id: Subscription ID customer: Customer plan: Plan diff --git a/spec/requests/subscriptions_controller_spec.rb b/spec/requests/subscriptions_controller_spec.rb index 31aba73..4429210 100644 --- a/spec/requests/subscriptions_controller_spec.rb +++ b/spec/requests/subscriptions_controller_spec.rb @@ -25,7 +25,7 @@ module DiscoursePatrons ::Stripe::Subscription.expects(:create).with( customer: 'cus_1234', items: [ plan: 'plan_1234' ], - metadata: { username_lower: user.username_lower }, + metadata: { user_id: user.id, username: user.username_lower }, ) post "/patrons/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' } end
{{i18n 'discourse_patrons.admin.subscriptions.subscription.user'}} {{i18n 'discourse_patrons.admin.subscriptions.subscription.customer'}} {{i18n 'discourse_patrons.admin.subscriptions.subscription.plan'}} {{i18n 'discourse_patrons.admin.subscriptions.subscription.status'}}
+ {{#if subscription.user}} + {{#link-to 'adminUser' subscription.user}} + {{subscription.user.username}} + {{/link-to}} + {{/if}} + {{subscription.customer}} {{subscription.plan.id}} {{subscription.status}}