From ff981f76e8360cc9819c5b21595fe61db4fffe75 Mon Sep 17 00:00:00 2001 From: spirobel Date: Sun, 9 Jul 2023 05:18:10 +0800 Subject: [PATCH] DEV: Remove the old product / pricing table display routes --- .../discourse/controllers/subscribe-index.js | 10 - .../discourse/controllers/subscribe-show.js | 195 ------------------ .../discourse/controllers/subscribe.js | 3 - .../discourse/templates/subscribe.hbs | 11 - .../discourse/templates/subscribe/index.hbs | 5 - .../discourse/templates/subscribe/show.hbs | 126 ----------- 6 files changed, 350 deletions(-) delete mode 100644 assets/javascripts/discourse/controllers/subscribe-index.js delete mode 100644 assets/javascripts/discourse/controllers/subscribe-show.js delete mode 100644 assets/javascripts/discourse/controllers/subscribe.js delete mode 100644 assets/javascripts/discourse/templates/subscribe.hbs delete mode 100644 assets/javascripts/discourse/templates/subscribe/index.hbs delete mode 100644 assets/javascripts/discourse/templates/subscribe/show.hbs diff --git a/assets/javascripts/discourse/controllers/subscribe-index.js b/assets/javascripts/discourse/controllers/subscribe-index.js deleted file mode 100644 index 6a5d820..0000000 --- a/assets/javascripts/discourse/controllers/subscribe-index.js +++ /dev/null @@ -1,10 +0,0 @@ -import Controller from "@ember/controller"; -import User from "discourse/models/user"; -import discourseComputed from "discourse-common/utils/decorators"; - -export default Controller.extend({ - @discourseComputed() - isLoggedIn() { - return User.current(); - }, -}); diff --git a/assets/javascripts/discourse/controllers/subscribe-show.js b/assets/javascripts/discourse/controllers/subscribe-show.js deleted file mode 100644 index ef688e1..0000000 --- a/assets/javascripts/discourse/controllers/subscribe-show.js +++ /dev/null @@ -1,195 +0,0 @@ -/* global Stripe */ -import Controller from "@ember/controller"; -import { not } from "@ember/object/computed"; -import { inject as service } from "@ember/service"; -import discourseComputed from "discourse-common/utils/decorators"; -import I18n from "I18n"; -import Subscription from "discourse/plugins/discourse-subscriptions/discourse/models/subscription"; -import Transaction from "discourse/plugins/discourse-subscriptions/discourse/models/transaction"; - -export default Controller.extend({ - dialog: service(), - router: service(), - selectedPlan: null, - promoCode: null, - cardholderName: null, - cardholderAddress: { - line1: null, - city: null, - state: null, - country: null, - postalCode: null, - }, - isAnonymous: not("currentUser"), - isCountryUS: false, - isCountryCA: false, - - init() { - this._super(...arguments); - this.set( - "stripe", - Stripe(this.siteSettings.discourse_subscriptions_public_key) - ); - const elements = this.get("stripe").elements(); - - this.set("cardElement", elements.create("card", { hidePostalCode: true })); - - this.set("isCountryUS", this.cardholderAddress.country === "US"); - this.set("isCountryCA", this.cardholderAddress.country === "CA"); - }, - - alert(path) { - this.dialog.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"), { - name: this.cardholderName, // Recommended by Stripe - address_line1: this.cardholderAddress.line1 ?? "", - address_city: this.cardholderAddress.city ?? "", - address_state: this.cardholderAddress.state ?? "", - address_zip: this.cardholderAddress.postalCode ?? "", - address_country: this.cardholderAddress.country, // Recommended by Stripe - }) - .then((result) => { - if (result.error) { - this.set("loading", false); - return result; - } else { - const subscription = Subscription.create({ - source: result.token.id, - plan: plan.get("id"), - promo: this.promoCode, - cardholderName: this.cardholderName, - cardholderAddress: this.cardholderAddress, - }); - - return subscription.save(); - } - }); - }, - - handleAuthentication(plan, transaction) { - return this.stripe - .confirmCardPayment(transaction.payment_intent.client_secret) - .then((result) => { - if ( - result.paymentIntent && - result.paymentIntent.status === "succeeded" - ) { - return result; - } else { - this.set("loading", false); - this.dialog.alert(result.error.message || result.error); - return result; - } - }); - }, - - _advanceSuccessfulTransaction(plan) { - this.alert("plans.success"); - this.set("loading", false); - - this.router.transitionTo( - plan.type === "recurring" - ? "user.billing.subscriptions" - : "user.billing.payments", - this.currentUser.username.toLowerCase() - ); - }, - - actions: { - changeCountry(country) { - this.set("cardholderAddress.country", country); - this.set("isCountryUS", country === "US"); - this.set("isCountryCA", country === "CA"); - }, - - changeState(stateOrProvince) { - this.set("cardholderAddress.state", stateOrProvince); - }, - - stripePaymentHandler() { - this.set("loading", true); - const plan = this.get("model.plans") - .filterBy("id", this.selectedPlan) - .get("firstObject"); - const cardholderAddress = this.cardholderAddress; - const cardholderName = this.cardholderName; - - if (!plan) { - this.alert("plans.validate.payment_options.required"); - this.set("loading", false); - return; - } - - if (!cardholderName) { - this.alert("subscribe.invalid_cardholder_name"); - this.set("loading", false); - return; - } - - if (!cardholderAddress.country) { - this.alert("subscribe.invalid_cardholder_country"); - this.set("loading", false); - return; - } - - if (cardholderAddress.country === "US" && !cardholderAddress.state) { - this.alert("subscribe.invalid_cardholder_state"); - this.set("loading", false); - return; - } - - if (cardholderAddress.country === "CA" && !cardholderAddress.state) { - this.alert("subscribe.invalid_cardholder_province"); - this.set("loading", false); - return; - } - - let transaction = this.createSubscription(plan); - - transaction - .then((result) => { - if (result.error) { - this.dialog.alert(result.error.message || result.error); - } else if ( - result.status === "incomplete" || - result.status === "open" - ) { - const transactionId = result.id; - const planId = this.selectedPlan; - this.handleAuthentication(plan, result).then( - (authenticationResult) => { - if (authenticationResult && !authenticationResult.error) { - return Transaction.finalize(transactionId, planId).then( - () => { - this._advanceSuccessfulTransaction(plan); - } - ); - } - } - ); - } else { - this._advanceSuccessfulTransaction(plan); - } - }) - .catch((result) => { - this.dialog.alert( - result.jqXHR.responseJSON.errors[0] || result.errorThrown - ); - this.set("loading", false); - }); - }, - }, -}); diff --git a/assets/javascripts/discourse/controllers/subscribe.js b/assets/javascripts/discourse/controllers/subscribe.js deleted file mode 100644 index fa4ba1e..0000000 --- a/assets/javascripts/discourse/controllers/subscribe.js +++ /dev/null @@ -1,3 +0,0 @@ -import Controller from "@ember/controller"; - -export default Controller.extend({}); diff --git a/assets/javascripts/discourse/templates/subscribe.hbs b/assets/javascripts/discourse/templates/subscribe.hbs deleted file mode 100644 index 41e5f13..0000000 --- a/assets/javascripts/discourse/templates/subscribe.hbs +++ /dev/null @@ -1,11 +0,0 @@ -
-
-

- {{i18n "discourse_subscriptions.subscribe.title"}} -

-
- -
- - {{outlet}} -
\ No newline at end of file diff --git a/assets/javascripts/discourse/templates/subscribe/index.hbs b/assets/javascripts/discourse/templates/subscribe/index.hbs deleted file mode 100644 index a149651..0000000 --- a/assets/javascripts/discourse/templates/subscribe/index.hbs +++ /dev/null @@ -1,5 +0,0 @@ -{{#unless isLoggedIn}} - -{{/unless}} - - \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/subscribe/show.hbs b/assets/javascripts/discourse/templates/subscribe/show.hbs deleted file mode 100644 index fa1981b..0000000 --- a/assets/javascripts/discourse/templates/subscribe/show.hbs +++ /dev/null @@ -1,126 +0,0 @@ -
-
-

- {{model.product.name}} -

- -
- -

- {{html-safe model.product.description}} -

-
- -
- {{#if canPurchase}} -

- {{i18n "discourse_subscriptions.subscribe.card.title"}} -

- -
- - - -
- - - - {{#if loading}} - {{loading-spinner}} - {{else if isAnonymous}} - - {{else}} - -
- - -
- -
- - {{#if isCountryUS}} - - {{else if isCountryCA}} - - {{else}} - - {{/if}} -
- - - - - {{/if}} - {{else}} -

{{i18n "discourse_subscriptions.subscribe.already_purchased"}}

- - - {{i18n "discourse_subscriptions.subscribe.go_to_billing"}} - - {{/if}} -
-
\ No newline at end of file