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:
Justin DiRose
2021-01-31 14:17:44 -06:00
committed by GitHub
parent 3f8fca3246
commit 072b558d40
11 changed files with 80 additions and 33 deletions
@@ -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) {