DEV: fix linter issues
This commit is contained in:
parent
ff981f76e8
commit
bf7079928e
|
@ -1,7 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module StripeDiscourseSubscriptions
|
||||
class PricingtableController < ::ApplicationController
|
||||
def index
|
||||
head 200
|
||||
end
|
||||
class PricingtableController < ::ApplicationController
|
||||
def index
|
||||
head 200
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,35 +1,37 @@
|
|||
import Controller from "@ember/controller";
|
||||
import Ember from 'ember';
|
||||
import Ember from "ember";
|
||||
import { htmlSafe } from "@ember/template";
|
||||
import I18n from "I18n";
|
||||
|
||||
export default Controller.extend({
|
||||
init() {
|
||||
// Perform any initialization logic here
|
||||
this._super(...arguments);
|
||||
// Additional custom initialization code
|
||||
if(this.currentUser){
|
||||
this.currentUser.checkEmail().then((r)=>this.set('email',this.currentUser.email))
|
||||
}
|
||||
|
||||
},
|
||||
pricingTable: Ember.computed('email', function() {
|
||||
try{
|
||||
const pricing_table_info = JSON.parse(this.siteSettings.discourse_subscriptions_pricing_table)
|
||||
if(this.currentUser){
|
||||
return`<stripe-pricing-table
|
||||
init() {
|
||||
// Perform any initialization logic here
|
||||
this._super(...arguments);
|
||||
// Additional custom initialization code
|
||||
if (this.currentUser) {
|
||||
this.currentUser
|
||||
.checkEmail()
|
||||
.then(() => this.set("email", this.currentUser.email));
|
||||
}
|
||||
},
|
||||
pricingTable: Ember.computed("email", function () {
|
||||
try {
|
||||
const pricing_table_info = JSON.parse(
|
||||
this.siteSettings.discourse_subscriptions_pricing_table
|
||||
);
|
||||
if (this.currentUser) {
|
||||
return htmlSafe(`<stripe-pricing-table
|
||||
pricing-table-id="${pricing_table_info.pricingTableId}"
|
||||
publishable-key="${pricing_table_info.publishableKey}"
|
||||
customer-email="${this.email}"></stripe-pricing-table>`;
|
||||
} else {
|
||||
return`<stripe-pricing-table
|
||||
customer-email="${this.email}"></stripe-pricing-table>`);
|
||||
} else {
|
||||
return htmlSafe(`<stripe-pricing-table
|
||||
pricing-table-id="${pricing_table_info.pricingTableId}"
|
||||
publishable-key="${pricing_table_info.publishableKey}"
|
||||
></stripe-pricing-table>`;
|
||||
}
|
||||
|
||||
|
||||
} catch(error){
|
||||
return I18n.t("discourse_subscriptions.subscribe.no_products")
|
||||
}
|
||||
}),
|
||||
></stripe-pricing-table>`);
|
||||
}
|
||||
} catch (error) {
|
||||
return I18n.t("discourse_subscriptions.subscribe.no_products");
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
|
|
@ -23,29 +23,35 @@ export default {
|
|||
href: `/u/${user.username}/billing/subscriptions`,
|
||||
content: "Billing",
|
||||
});
|
||||
|
||||
if(user.admin){
|
||||
api.modifyClassStatic('model:site-setting', {
|
||||
pluginId: 'discourse-subscriptions',
|
||||
update(key, value, opts = {}) {
|
||||
if(key ==="discourse_subscriptions_pricing_table"){
|
||||
const inputString = value;
|
||||
// Extract pricing-table-id
|
||||
const pricingTableIdRegex = /pricing-table-id="([^"]+)"/;
|
||||
const pricingTableIdMatch = inputString.match(pricingTableIdRegex);
|
||||
const pricingTableId = pricingTableIdMatch ? pricingTableIdMatch[1] : null;
|
||||
|
||||
// Extract publishable-key
|
||||
const publishableKeyRegex = /publishable-key="([^"]+)"/;
|
||||
const publishableKeyMatch = inputString.match(publishableKeyRegex);
|
||||
const publishableKey = publishableKeyMatch ? publishableKeyMatch[1] : null;
|
||||
if(pricingTableId && publishableKey){
|
||||
value = JSON.stringify({pricingTableId,publishableKey})
|
||||
}
|
||||
|
||||
if (user.admin) {
|
||||
api.modifyClassStatic("model:site-setting", {
|
||||
pluginId: "discourse-subscriptions",
|
||||
update(key, value, opts = {}) {
|
||||
if (key === "discourse_subscriptions_pricing_table") {
|
||||
const inputString = value;
|
||||
// Extract pricing-table-id
|
||||
const pricingTableIdRegex = /pricing-table-id="([^"]+)"/;
|
||||
const pricingTableIdMatch =
|
||||
inputString.match(pricingTableIdRegex);
|
||||
const pricingTableId = pricingTableIdMatch
|
||||
? pricingTableIdMatch[1]
|
||||
: null;
|
||||
|
||||
// Extract publishable-key
|
||||
const publishableKeyRegex = /publishable-key="([^"]+)"/;
|
||||
const publishableKeyMatch =
|
||||
inputString.match(publishableKeyRegex);
|
||||
const publishableKey = publishableKeyMatch
|
||||
? publishableKeyMatch[1]
|
||||
: null;
|
||||
if (pricingTableId && publishableKey) {
|
||||
value = JSON.stringify({ pricingTableId, publishableKey });
|
||||
}
|
||||
this._super(key, value, opts);
|
||||
}
|
||||
});
|
||||
this._super(key, value, opts);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
export default function () {
|
||||
this.route("subscriptions")
|
||||
this.route("subscriptions");
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
<div class="container">
|
||||
{{{pricingTable}}}
|
||||
{{pricingTable}}
|
||||
</div>
|
10
plugin.rb
10
plugin.rb
|
@ -70,16 +70,16 @@ after_initialize do
|
|||
|
||||
module ::StripeDiscourseSubscriptions
|
||||
class Engine < ::Rails::Engine
|
||||
engine_name 'stripe-discourse-subscriptions'
|
||||
engine_name "stripe-discourse-subscriptions"
|
||||
isolate_namespace StripeDiscourseSubscriptions
|
||||
end
|
||||
end
|
||||
StripeDiscourseSubscriptions::Engine.routes.draw do
|
||||
get "/" => "pricingtable#index"
|
||||
end
|
||||
StripeDiscourseSubscriptions::Engine.routes.draw { get "/" => "pricingtable#index" }
|
||||
require_relative "app/controllers/discourse_subscriptions/pricingtable_controller.rb"
|
||||
|
||||
Discourse::Application.routes.append { mount ::StripeDiscourseSubscriptions::Engine, at: "subscriptions" }
|
||||
Discourse::Application.routes.append do
|
||||
mount ::StripeDiscourseSubscriptions::Engine, at: "subscriptions"
|
||||
end
|
||||
|
||||
::Stripe.set_app_info(
|
||||
"Discourse Subscriptions",
|
||||
|
|
Loading…
Reference in New Issue