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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user