Skip to content

Commit f5d451f

Browse files
authored
v7.0.8 - display amount with 2 decimals (#35)
1 parent bb88e11 commit f5d451f

File tree

8 files changed

+39
-16
lines changed

8 files changed

+39
-16
lines changed

demo/index.html

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
const plans = {
108108
"41": {
109109
"token": "Acbdcdcadsfdasf.1234alphanumeric.3foobarXyZ",
110-
"amount": 10,
110+
"amount": 10.3,
111111
"start_date": "2024-05-22 00:00:00",
112112
"is_test": true,
113113
"btdata": {
@@ -133,7 +133,7 @@
133133
},
134134
"23764": {
135135
"token": "Acbdcdcadsfdasf.1234alphanumeric.3foobar",
136-
"amount": 5,
136+
"amount": 2.5,
137137
"start_date": "2022-12-09 00:00:00",
138138
"is_test": true,
139139
"btdata": {
@@ -183,11 +183,30 @@
183183
const plansArray = Object.keys(plans).map((key) => new MonthlyPlan(plans[key]));
184184

185185
const receiptsData = [
186+
new Receipt({
187+
currency: 'USD',
188+
total_amount: 1,
189+
net_amount: 1,
190+
fee_amount: 0,
191+
fee_covered: false,
192+
date: (new Date('2019-01-22 14:26:34')).toLocaleString('US-EN', {
193+
year: 'numeric',
194+
month: 'short',
195+
day: 'numeric',
196+
}),
197+
donor: 'John Doe',
198+
paymentMethod: 'Credit Card',
199+
status: 'Completed',
200+
id: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJtYWlsc3luYyIsImlhdCI6MTczNzk3MTgyNy45MDY1NDksIm5iZiI6MTczNzk3MTc2Ny45MDY1NDksImV4cCI6MTczNzk3MjQyNy45MDY1NDksImtleSI6IjEwOTY4MjEiLCJ1c2VyIjoiQGlzYS1hdC10aGUtYXJjaGl2ZSJ9.pMbayUlFgRhm3wDoJG1IPoltliTHDq0xH2W369JtdQA',
201+
token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJtYWlsc3luYyIsImlhdCI6MTczNzk3MTgyNy45MDY1NDksIm5iZiI6MTczNzk3MTc2Ny45MDY1NDksImV4cCI6MTczNzk3MjQyNy45MDY1NDksImtleSI6IjEwOTY4MjEiLCJ1c2VyIjoiQGlzYS1hdC10aGUtYXJjaGl2ZSJ9.pMbayUlFgRhm3wDoJG1IPoltliTHDq0xH2W369JtdQA',
202+
is_test: false,
203+
}),
186204
new Receipt({
187205
currency: 'USD',
188206
net_amount: 9999.99,
189207
total_amount: 9999.99,
190208
fee_amount: 0,
209+
fee_covered: false,
191210
date: (new Date('2019-01-22 14:26:34')).toLocaleString('US-EN', {
192211
year: 'numeric',
193212
month: 'short',
@@ -205,6 +224,7 @@
205224
net_amount: 100,
206225
total_amount: 105.86,
207226
fee_amount: 5.86,
227+
fee_covered: true,
208228
date: (new Date('2022-09-22 14:26:34')).toLocaleString('US-EN', {
209229
year: 'numeric',
210230
month: 'short',

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@internetarchive/donation-monthly-portal",
3-
"version": "7.0.5",
3+
"version": "7.0.8",
44
"description": "The Internet Archive Monthly Portal",
55
"license": "AGPL-3.0-only",
66
"main": "dist/index.js",

src/form-sections/amount.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class MGCEditPlanAmount extends LitElement {
6666
this.currentlyEditing = true;
6767
this.clearStatusMessaging();
6868
}}
69-
><span>USD $${this.plan?.amount}</span>
69+
><span>USD $${this.plan?.amountFormatted}</span>
7070
</ia-mgc-form-section-info>`
7171
: nothing}
7272
${this.currentlyEditing ? this.editAmountForm : nothing}
@@ -258,7 +258,7 @@ export class MGCEditPlanAmount extends LitElement {
258258
id="edit-plan-amount"
259259
@submit=${(e: Event) => this.handleSubmit(e)}
260260
>
261-
<p>Current donation amount: $${this.plan?.amount}</p>
261+
<p>Current donation amount: $${this.plan?.amountFormatted}</p>
262262
<div>
263263
$
264264
<input

src/models/plan.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ export class MonthlyPlan {
6262
return this.plan.amount;
6363
}
6464

65+
get amountFormatted(): string {
66+
return this.plan.amount.toFixed(2);
67+
}
68+
6569
setAmount(newAmount: number) {
6670
this.plan.oldAmount = this.plan.amount;
6771
this.plan.amount = newAmount;

src/models/receipt.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ export type AReceipt = {
33
net_amount: number;
44
total_amount: number;
55
fee_amount: number;
6-
receive_date?: Date;
6+
fee_covered: boolean;
7+
receive_date: Date;
78
date: string;
89
isTest: boolean;
910
token: string;
10-
id?: string;
1111
};
12+
1213
export class Receipt {
1314
receipt: AReceipt;
1415

@@ -17,7 +18,7 @@ export class Receipt {
1718
}
1819

1920
get amountFormatted(): string {
20-
const value = this.receipt.total_amount ?? this.receipt.net_amount;
21+
const value = this.receipt.total_amount.toFixed(2);
2122
const currencyType = this.receipt.currency ?? 'CURR not found';
2223
if (value) {
2324
return `${currencyType} ${this.currencySymbol}${value}`;
@@ -26,11 +27,7 @@ export class Receipt {
2627
}
2728

2829
get amount(): string {
29-
return (
30-
`${this.receipt.total_amount}` ??
31-
`${this.receipt.net_amount}` ??
32-
"no amount found, can't find total_amount or net_amount"
33-
);
30+
return this.receipt.total_amount.toFixed(2);
3431
}
3532

3633
get isTest(): boolean {

src/plans.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class IauxMgcPlans extends LitElement {
3535
<h3>Amount</h3>
3636
<p>
3737
${plan.currency}
38-
${plan.currencySymbol}${plan.amount}/month
38+
${plan.currencySymbol}${plan.amountFormatted}/month
3939
</p>
4040
${plan.isTest
4141
? html`<p class="is-test">(Test payment)</p>`

test/receipt-email-request-flow.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ describe('Receipts: When requesting an email', () => {
3030
}),
3131
isTest: false,
3232
token: 'foo-token-3',
33+
fee_covered: true,
34+
receive_date: new Date('2023-12-23 14:26:34'),
3335
}),
3436
]}
3537
></ia-monthly-giving-circle>`

0 commit comments

Comments
 (0)