cannot subscribe to a product twice

This commit is contained in:
Rimian Perkins 2019-11-28 20:11:48 +11:00
parent 1429bf116f
commit e5753095d8
3 changed files with 21 additions and 16 deletions

View File

@ -6,6 +6,7 @@ export default Discourse.Route.extend({
model(params) { model(params) {
const product_id = params["subscription-id"]; const product_id = params["subscription-id"];
const product = Product.find(product_id); const product = Product.find(product_id);
const subscription = Subscription.create(); const subscription = Subscription.create();
const plans = Plan.findAll({ product_id: product_id }).then(results => const plans = Plan.findAll({ product_id: product_id }).then(results =>
results.map(p => ({ id: p.id, name: p.subscriptionRate })) results.map(p => ({ id: p.id, name: p.subscriptionRate }))

View File

@ -9,7 +9,7 @@
{{#if currentUser}} {{#if currentUser}}
<div class="pull-right"> <div class="pull-right">
{{#link-to "patrons.subscribe.show" product.id class="btn btn-primary"}} {{#link-to "patrons.subscribe.show" product.id disabled=product.subscribed class="btn btn-primary"}}
{{i18n 'discourse_patrons.subscribe.title'}} {{i18n 'discourse_patrons.subscribe.title'}}
{{/link-to}} {{/link-to}}
</div> </div>

View File

@ -9,25 +9,29 @@
</p> </p>
</div> </div>
<div class="section-column"> <div class="section-column">
{{combo-box valueAttribute="id" content=model.plans value=model.product.plan}} {{#unless model.product.subscribed}}
{{#d-button {{combo-box valueAttribute="id" content=model.plans value=model.product.plan}}
disabled=loading
action="stripePaymentHandler"
class="btn btn-primary btn-payment btn-discourse-patrons"}}
{{i18n 'discourse_patrons.subscribe.buttons.subscribe'}}
{{/d-button}}
<hr> {{#d-button
disabled=loading
action="stripePaymentHandler"
class="btn btn-primary btn-payment btn-discourse-patrons"}}
{{i18n 'discourse_patrons.subscribe.buttons.subscribe'}}
{{/d-button}}
<h4> <hr>
{{i18n 'discourse_patrons.subscribe.card.title'}}
</h4>
{{subscribe-card cardElement=cardElement}} <h4>
{{i18n 'discourse_patrons.subscribe.card.title'}}
</h4>
{{#if loading}} {{subscribe-card cardElement=cardElement}}
{{loading-spinner}}
{{/if}} {{#if loading}}
{{loading-spinner}}
{{/if}}
{{/unless}}
</div> </div>
</div> </div>