set the dollar amount

This commit is contained in:
Rimian Perkins 2019-10-31 13:29:11 +11:00
parent 1074d84901
commit b0a4665bf4
3 changed files with 23 additions and 7 deletions

View File

@ -2,10 +2,16 @@ import computed from "ember-addons/ember-computed-decorators";
import { ajax } from "discourse/lib/ajax";
const Plan = Discourse.Model.extend({
@computed("amount")
amountDollars(amount) {
return parseFloat(amount / 100).toFixed(2);
},
amountDollars: Ember.computed("amount", {
get() {
return parseFloat(this.get("amount") / 100).toFixed(2);
},
set(key, value) {
const decimal = parseFloat(value) * 100;
this.set("amount", decimal);
return value;
}
}),
@computed("amountDollars", "currency", "interval")
subscriptionRate(amountDollars, currency, interval) {

View File

@ -22,7 +22,7 @@
</p>
<p>
<label for="amount">{{i18n 'discourse_patrons.admin.plans.plan.amount'}}</label>
{{input type="text" name="name" value=model.plan.amount disabled=planFieldDisabled}}
{{input type="text" name="name" value=model.plan.amountDollars disabled=planFieldDisabled}}
</p>
<p>
<label for="trial">

View File

@ -4,7 +4,7 @@ QUnit.module("discourse-patrons:model:plan");
QUnit.test("subscriptionRate", assert => {
const plan = Plan.create({
amount: 2399,
amount: "2399",
currency: 'aud',
interval: 'month'
});
@ -22,6 +22,16 @@ QUnit.test("amountDollars", assert => {
assert.equal(
plan.get("amountDollars"),
23.99,
"it returns the formatted amount"
"it returns the formatted dollar amount"
);
});
QUnit.test("amount", assert => {
const plan = Plan.create({ amountDollars: "22.12" });
assert.equal(
plan.get("amount"),
2212,
"it returns the cents amount"
);
});