date format and product description
This commit is contained in:
parent
86c77a7395
commit
e3ac6f7dac
|
@ -73,10 +73,13 @@ module DiscoursePatrons
|
||||||
private
|
private
|
||||||
|
|
||||||
def product_params
|
def product_params
|
||||||
|
params.permit!
|
||||||
|
|
||||||
{
|
{
|
||||||
name: params[:name],
|
name: params[:name],
|
||||||
active: params[:active],
|
active: params[:active],
|
||||||
statement_descriptor: params[:statement_descriptor]
|
statement_descriptor: params[:statement_descriptor],
|
||||||
|
metadata: { description: params.dig(:metadata, :description) }
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { registerUnbound } from "discourse-common/lib/helpers";
|
||||||
|
import { autoUpdatingRelativeAge } from "discourse/lib/formatter";
|
||||||
|
|
||||||
|
registerUnbound("format-unix-date", function(timestamp) {
|
||||||
|
if (timestamp) {
|
||||||
|
const date = new Date(moment.unix(timestamp).format());
|
||||||
|
|
||||||
|
return new Handlebars.SafeString(
|
||||||
|
autoUpdatingRelativeAge(date, {
|
||||||
|
format: "medium",
|
||||||
|
title: true,
|
||||||
|
leaveAgo: true
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
|
@ -10,11 +10,6 @@ const AdminPlan = Plan.extend({
|
||||||
intervals: ["day", "week", "month", "year"],
|
intervals: ["day", "week", "month", "year"],
|
||||||
metadata: {},
|
metadata: {},
|
||||||
|
|
||||||
@computed("created")
|
|
||||||
createdFormatted(created) {
|
|
||||||
return moment.unix(created).format();
|
|
||||||
},
|
|
||||||
|
|
||||||
@computed("trial_period_days")
|
@computed("trial_period_days")
|
||||||
parseTrialPeriodDays(trial_period_days) {
|
parseTrialPeriodDays(trial_period_days) {
|
||||||
if (trial_period_days) {
|
if (trial_period_days) {
|
||||||
|
|
|
@ -1,15 +1,9 @@
|
||||||
import computed from "ember-addons/ember-computed-decorators";
|
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
|
|
||||||
const AdminProduct = Discourse.Model.extend({
|
const AdminProduct = Discourse.Model.extend({
|
||||||
isNew: false,
|
isNew: false,
|
||||||
metadata: {},
|
metadata: {},
|
||||||
|
|
||||||
@computed("created")
|
|
||||||
createdFormatted(created) {
|
|
||||||
return moment.unix(created).format();
|
|
||||||
},
|
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
return ajax(`/patrons/admin/products/${this.id}`, { method: "delete" });
|
return ajax(`/patrons/admin/products/${this.id}`, { method: "delete" });
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
import computed from "ember-addons/ember-computed-decorators";
|
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
|
|
||||||
const AdminSubscription = Discourse.Model.extend({
|
const AdminSubscription = Discourse.Model.extend({});
|
||||||
@computed("created")
|
|
||||||
createdFormatted(created) {
|
|
||||||
return moment.unix(created).format();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
AdminSubscription.reopenClass({
|
AdminSubscription.reopenClass({
|
||||||
find() {
|
find() {
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
import computed from "ember-addons/ember-computed-decorators";
|
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
|
|
||||||
const Invoice = Discourse.Model.extend({
|
const Invoice = Discourse.Model.extend({});
|
||||||
@computed("created")
|
|
||||||
createdFormatted(created) {
|
|
||||||
return moment.unix(created).format();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Invoice.reopenClass({
|
Invoice.reopenClass({
|
||||||
findAll() {
|
findAll() {
|
||||||
|
|
|
@ -17,8 +17,6 @@ const Plan = Discourse.Model.extend({
|
||||||
subscriptionRate(amountDollars, currency, interval) {
|
subscriptionRate(amountDollars, currency, interval) {
|
||||||
return `$${amountDollars} ${currency.toUpperCase()} / ${interval}`;
|
return `$${amountDollars} ${currency.toUpperCase()} / ${interval}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Plan.reopenClass({
|
Plan.reopenClass({
|
||||||
|
|
|
@ -3,11 +3,6 @@ import { ajax } from "discourse/lib/ajax";
|
||||||
import Plan from "discourse/plugins/discourse-patrons/discourse/models/plan";
|
import Plan from "discourse/plugins/discourse-patrons/discourse/models/plan";
|
||||||
|
|
||||||
const Subscription = Discourse.Model.extend({
|
const Subscription = Discourse.Model.extend({
|
||||||
@computed("created")
|
|
||||||
createdFormatted(created) {
|
|
||||||
return moment.unix(created).format();
|
|
||||||
},
|
|
||||||
|
|
||||||
@computed("status")
|
@computed("status")
|
||||||
canceled(status) {
|
canceled(status) {
|
||||||
return status === "canceled";
|
return status === "canceled";
|
||||||
|
|
|
@ -11,13 +11,15 @@
|
||||||
<thead>
|
<thead>
|
||||||
<th>{{i18n 'discourse_patrons.admin.products.product.name'}}</th>
|
<th>{{i18n 'discourse_patrons.admin.products.product.name'}}</th>
|
||||||
<th>{{i18n 'discourse_patrons.admin.products.product.created_at'}}</th>
|
<th>{{i18n 'discourse_patrons.admin.products.product.created_at'}}</th>
|
||||||
|
<th>{{i18n 'discourse_patrons.admin.products.product.updated_at'}}</th>
|
||||||
<th class="td-right">{{i18n 'discourse_patrons.admin.products.product.active'}}</th>
|
<th class="td-right">{{i18n 'discourse_patrons.admin.products.product.active'}}</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</thead>
|
</thead>
|
||||||
{{#each model as |product|}}
|
{{#each model as |product|}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{product.name}}</td>
|
<td>{{product.name}}</td>
|
||||||
<td>{{format-date product.createdFormatted}}</td>
|
<td>{{format-unix-date product.created}}</td>
|
||||||
|
<td>{{format-unix-date product.updated}}</td>
|
||||||
<td class="td-right">{{product.active}}</td>
|
<td class="td-right">{{product.active}}</td>
|
||||||
<td class="td-right">
|
<td class="td-right">
|
||||||
{{#link-to "adminPlugins.discourse-patrons.products.show" product.id class="btn no-text btn-icon"}}
|
{{#link-to "adminPlugins.discourse-patrons.products.show" product.id class="btn no-text btn-icon"}}
|
||||||
|
|
|
@ -5,6 +5,15 @@
|
||||||
<label for="name">{{i18n 'discourse_patrons.admin.products.product.name'}}</label>
|
<label for="name">{{i18n 'discourse_patrons.admin.products.product.name'}}</label>
|
||||||
{{input type="text" name="name" value=model.product.name}}
|
{{input type="text" name="name" value=model.product.name}}
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
<label for="description">
|
||||||
|
{{i18n 'discourse_patrons.admin.products.product.description'}}
|
||||||
|
</label>
|
||||||
|
{{textarea name="description" value=model.product.metadata.description class="discourse-patrons-admin-textarea"}}
|
||||||
|
<div class="control-instructions">
|
||||||
|
{{i18n 'discourse_patrons.admin.products.product.description_help'}}
|
||||||
|
</div>
|
||||||
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label for="statement_descriptor">
|
<label for="statement_descriptor">
|
||||||
{{i18n 'discourse_patrons.admin.products.product.statement_descriptor'}}
|
{{i18n 'discourse_patrons.admin.products.product.statement_descriptor'}}
|
||||||
|
@ -42,7 +51,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{plan.nickname}}</td>
|
<td>{{plan.nickname}}</td>
|
||||||
<td>{{plan.interval}}</td>
|
<td>{{plan.interval}}</td>
|
||||||
<td>{{format-date plan.createdFormatted}}</td>
|
<td>{{format-unix-date plan.created}}</td>
|
||||||
<td>{{plan.metadata.group_name}}</td>
|
<td>{{plan.metadata.group_name}}</td>
|
||||||
<td>{{plan.active}}</td>
|
<td>{{plan.active}}</td>
|
||||||
<td class="td-right">{{format-currency plan.currency plan.amountDollars}}</td>
|
<td class="td-right">{{format-currency plan.currency plan.amountDollars}}</td>
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<td>{{subscription.customer}}</td>
|
<td>{{subscription.customer}}</td>
|
||||||
<td>{{subscription.plan.id}}</td>
|
<td>{{subscription.plan.id}}</td>
|
||||||
<td>{{subscription.status}}</td>
|
<td>{{subscription.status}}</td>
|
||||||
<td class="td-right">{{format-date subscription.createdFormatted}}</td>
|
<td class="td-right">{{format-unix-date subscription.created}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{invoice.amount_paid}}</td>
|
<td>{{invoice.amount_paid}}</td>
|
||||||
<td>{{invoice.number}}</td>
|
<td>{{invoice.number}}</td>
|
||||||
<td>{{format-date invoice.createdFormatted}}</td>
|
<td>{{format-unix-date invoice.created}}</td>
|
||||||
<td class="td-right">
|
<td class="td-right">
|
||||||
<a href="{{invoice.invoice_pdf}}" class="btn btn-icon">
|
<a href="{{invoice.invoice_pdf}}" class="btn btn-icon">
|
||||||
{{d-icon "download"}}
|
{{d-icon "download"}}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{invoice.amount_paid}}</td>
|
<td>{{invoice.amount_paid}}</td>
|
||||||
<td>{{invoice.number}}</td>
|
<td>{{invoice.number}}</td>
|
||||||
<td>{{format-date invoice.createdFormatted}}</td>
|
<td>{{format-unix-date invoice.created}}</td>
|
||||||
<td class="td-right">
|
<td class="td-right">
|
||||||
<a href="{{invoice.invoice_pdf}}" class="btn btn-icon">
|
<a href="{{invoice.invoice_pdf}}" class="btn btn-icon">
|
||||||
{{d-icon "download"}}
|
{{d-icon "download"}}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<td>{{subscription.id}}</td>
|
<td>{{subscription.id}}</td>
|
||||||
<td>{{subscription.plan.subscriptionRate}}</td>
|
<td>{{subscription.plan.subscriptionRate}}</td>
|
||||||
<td>{{subscription.status}}</td>
|
<td>{{subscription.status}}</td>
|
||||||
<td>{{format-date subscription.createdFormatted}}</td>
|
<td>{{format-unix-date subscription.created}}</td>
|
||||||
<td class="td-right">{{d-button disabled=subscription.canceled label="cancel" action=(route-action "cancelSubscription" subscription) icon="times"}}</td>
|
<td class="td-right">{{d-button disabled=subscription.canceled label="cancel" action=(route-action "cancelSubscription" subscription) icon="times"}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
|
@ -33,6 +33,10 @@ table.discourse-patrons-user-table {
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.discourse-patrons-admin-textarea {
|
||||||
|
width: 80%;
|
||||||
|
}
|
||||||
|
|
||||||
#stripe-elements {
|
#stripe-elements {
|
||||||
border: 1px $primary-low-mid solid;
|
border: 1px $primary-low-mid solid;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
|
|
|
@ -91,8 +91,11 @@ en:
|
||||||
statement_descriptor: Statement Descriptor
|
statement_descriptor: Statement Descriptor
|
||||||
statement_descriptor_help: Extra information about a product which will appear on your customer’s credit card statement.
|
statement_descriptor_help: Extra information about a product which will appear on your customer’s credit card statement.
|
||||||
plan_help: Create a pricing plan to subscribe customers to this product
|
plan_help: Create a pricing plan to subscribe customers to this product
|
||||||
|
description: Description
|
||||||
|
description_help: This describes your subscription product.
|
||||||
active: Active
|
active: Active
|
||||||
created_at: Created
|
created_at: Created
|
||||||
|
updated_at: Updated
|
||||||
product_help: Before cutomers can subscribe to your site, you need to create at least one product and an associated plan.
|
product_help: Before cutomers can subscribe to your site, you need to create at least one product and an associated plan.
|
||||||
plans:
|
plans:
|
||||||
title: Pricing Plans
|
title: Pricing Plans
|
||||||
|
|
|
@ -78,6 +78,11 @@ module DiscoursePatrons
|
||||||
::Stripe::Product.expects(:create).with(has_key(:statement_descriptor)).never
|
::Stripe::Product.expects(:create).with(has_key(:statement_descriptor)).never
|
||||||
post "/patrons/admin/products.json", params: { statement_descriptor: '' }
|
post "/patrons/admin/products.json", params: { statement_descriptor: '' }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'has a description' do
|
||||||
|
::Stripe::Product.expects(:create).with(has_entry(metadata: { description: 'Oi, I think he just said bless be all the bignoses!' }))
|
||||||
|
post "/patrons/admin/products.json", params: { metadata: { description: 'Oi, I think he just said bless be all the bignoses!' }}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'show' do
|
describe 'show' do
|
||||||
|
|
|
@ -11,13 +11,13 @@ module DiscoursePatrons
|
||||||
end
|
end
|
||||||
|
|
||||||
it "orders and serialises the plans" do
|
it "orders and serialises the plans" do
|
||||||
::Stripe::Plan.expects(:list).returns({
|
::Stripe::Plan.expects(:list).returns(
|
||||||
data: [
|
data: [
|
||||||
{ id: 'plan_id123', amount: 1220, currency: 'aud', interval: 'year', metadata: {} },
|
{ id: 'plan_id123', amount: 1220, currency: 'aud', interval: 'year', metadata: {} },
|
||||||
{ id: 'plan_id234', amount: 1399, currency: 'usd', interval: 'year', metadata: {} },
|
{ id: 'plan_id234', amount: 1399, currency: 'usd', interval: 'year', metadata: {} },
|
||||||
{ id: 'plan_id678', amount: 1000, currency: 'aud', interval: 'week', metadata: {} }
|
{ id: 'plan_id678', amount: 1000, currency: 'aud', interval: 'week', metadata: {} }
|
||||||
]
|
]
|
||||||
})
|
)
|
||||||
|
|
||||||
get "/patrons/plans.json"
|
get "/patrons/plans.json"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue