diff --git a/assets/javascripts/discourse/controllers/s-subscribe-show.js.es6 b/assets/javascripts/discourse/controllers/s-subscribe-show.js.es6 index c492876..065df34 100644 --- a/assets/javascripts/discourse/controllers/s-subscribe-show.js.es6 +++ b/assets/javascripts/discourse/controllers/s-subscribe-show.js.es6 @@ -15,6 +15,20 @@ export default Ember.Controller.extend({ actions: { stripePaymentHandler() { this.set("loading", true); + const plan = this.get("model.plans") + .filterBy("selected") + .get("firstObject"); + + if (!plan) { + bootbox.alert( + I18n.t( + "discourse_subscriptions.transactions.payment.validate.plan.required" + ) + ); + + this.set("loading", false); + return; + } this.stripe.createToken(this.get("cardElement")).then(result => { if (result.error) { @@ -31,11 +45,10 @@ export default Ember.Controller.extend({ }).then(customer => { const subscription = this.get("model.subscription"); - subscription.set("customer", customer.id); - - if (subscription.get("plan") === undefined) { - subscription.set("plan", this.get("model.plans.firstObject.id")); - } + subscription.setProperties({ + customer: customer.id, + plan: plan.get("id") + }); subscription .save() diff --git a/assets/javascripts/discourse/templates/components/payment-options.hbs b/assets/javascripts/discourse/templates/components/payment-options.hbs index bbcd1e4..8003a41 100644 --- a/assets/javascripts/discourse/templates/components/payment-options.hbs +++ b/assets/javascripts/discourse/templates/components/payment-options.hbs @@ -1,14 +1,16 @@ - + --}}
-

Select subscription period

+

+ {{i18n "discourse_subscriptions.plans.select"}} +

{{#each plans as |plan|}} diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 7107b7c..5eaf70d 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -21,11 +21,16 @@ en: transactions: payment: success: Your payment was successful + validate: + plan: + required: Please select a subscription plan. navigation: subscriptions: Subscriptions subscribe: Subscribe billing: Billing plans: + select: Select subscription period + purchase: Purchase a subscription interval: adverb: week: Weekly