FEATURE: Give option to repurchase products multiple times (#46)
Feature requested here: https://meta.discourse.org/t/subscriptions-allow-users-to-purchase-one-time-products-multiple-times/173732/ There may be cases where a site admin wants to allow the repurchasing of a product. This implements the functionality by adding a repurchaseable toggle in the admin screen when creating a product. This saves an attribute to the Stripe product metadata. When a user has already purchased an item with this toggle enabled, they will be able to purchase it again when browsing to `/s`.
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
import Component from "@ember/component";
|
||||
|
||||
export default Component.extend({
|
||||
classNames: ["product"],
|
||||
});
|
||||
@@ -3,6 +3,7 @@ import Subscription from "discourse/plugins/discourse-subscriptions/discourse/mo
|
||||
import Transaction from "discourse/plugins/discourse-subscriptions/discourse/models/transaction";
|
||||
import I18n from "I18n";
|
||||
import { not } from "@ember/object/computed";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
|
||||
export default Controller.extend({
|
||||
selectedPlan: null,
|
||||
@@ -24,6 +25,15 @@ export default Controller.extend({
|
||||
bootbox.alert(I18n.t(`discourse_subscriptions.${path}`));
|
||||
},
|
||||
|
||||
@discourseComputed("model.product.repurchaseable", "model.product.subscribed")
|
||||
canPurchase(repurchaseable, subscribed) {
|
||||
if (!repurchaseable && subscribed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
createSubscription(plan) {
|
||||
return this.stripe.createToken(this.get("cardElement")).then((result) => {
|
||||
if (result.error) {
|
||||
|
||||
+7
@@ -23,6 +23,13 @@
|
||||
{{i18n 'discourse_subscriptions.admin.products.product.statement_descriptor_help'}}
|
||||
</div>
|
||||
</p>
|
||||
<p>
|
||||
<label for="repurchaseable">{{i18n 'discourse_subscriptions.admin.products.product.repurchaseable'}}</label>
|
||||
{{input type="checkbox" name="repurchaseable" checked=model.product.metadata.repurchaseable}}
|
||||
<div class="control-instructions">
|
||||
{{i18n 'discourse_subscriptions.admin.products.product.repurchase_help'}}
|
||||
</div>
|
||||
</p>
|
||||
<p>
|
||||
<label for="active">{{i18n 'discourse_subscriptions.admin.products.product.active'}}</label>
|
||||
{{input type="checkbox" name="active" checked=model.product.active}}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<h2>{{product.name}}</h2>
|
||||
|
||||
<p class="product-description">
|
||||
{{html-safe product.description}}
|
||||
</p>
|
||||
|
||||
{{#if isLoggedIn}}
|
||||
<div class="product-purchase">
|
||||
{{#if product.repurchaseable}}
|
||||
{{#if product.subscribed}}
|
||||
<span class="purchased">✓ {{i18n 'discourse_subscriptions.subscribe.purchased'}}</span>
|
||||
{{#link-to "user.billing.subscriptions" currentUser.username class="billing-link"}}
|
||||
{{i18n 'discourse_subscriptions.subscribe.go_to_billing'}}
|
||||
{{/link-to}}
|
||||
{{/if}}
|
||||
{{#link-to "s.show" product.id class="btn btn-primary"}}
|
||||
{{i18n 'discourse_subscriptions.subscribe.title'}}
|
||||
{{/link-to}}
|
||||
{{else}}
|
||||
{{#if product.subscribed}}
|
||||
<span class="purchased">✓ {{i18n 'discourse_subscriptions.subscribe.purchased'}}</span>
|
||||
{{#link-to "user.billing.subscriptions" currentUser.username class="billing-link"}}
|
||||
{{i18n 'discourse_subscriptions.subscribe.go_to_billing'}}
|
||||
{{/link-to}}
|
||||
{{else}}
|
||||
{{#link-to "s.show" product.id disabled=product.subscribed class="btn btn-primary"}}
|
||||
{{i18n 'discourse_subscriptions.subscribe.title'}}
|
||||
{{/link-to}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</div>
|
||||
{{/if}}
|
||||
@@ -2,28 +2,6 @@
|
||||
<p>{{i18n 'discourse_subscriptions.subscribe.no_products'}}</p>
|
||||
{{else}}
|
||||
{{#each products as |product|}}
|
||||
<div class="product">
|
||||
<h2>{{product.name}}</h2>
|
||||
|
||||
<p class="product-description">
|
||||
{{html-safe product.description}}
|
||||
</p>
|
||||
|
||||
{{#if isLoggedIn}}
|
||||
<div class="product-purchase">
|
||||
{{#if product.subscribed}}
|
||||
<span class="purchased">✓ {{i18n 'discourse_subscriptions.subscribe.purchased'}}</span>
|
||||
{{#link-to "user.billing.subscriptions" currentUser.username class="billing-link"}}
|
||||
{{i18n 'discourse_subscriptions.subscribe.go_to_billing'}}
|
||||
{{/link-to}}
|
||||
{{else}}
|
||||
{{#link-to "s.show" product.id disabled=product.subscribed class="btn btn-primary"}}
|
||||
{{i18n 'discourse_subscriptions.subscribe.title'}}
|
||||
{{/link-to}}
|
||||
{{/if}}
|
||||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{product-item product=product isLoggedIn=isLoggedIn}}
|
||||
{{/each}}
|
||||
|
||||
{{/if}}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
</p>
|
||||
</div>
|
||||
<div class="section-column">
|
||||
{{#unless model.product.subscribed}}
|
||||
{{#if canPurchase}}
|
||||
<h2>
|
||||
{{i18n 'discourse_subscriptions.subscribe.card.title'}}
|
||||
</h2>
|
||||
@@ -45,6 +45,6 @@
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
{{/unless}}
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user