kempo-payments 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/admin/nav.global.html +2 -2
- package/kempo-config.json +15 -0
- package/package.json +1 -1
- package/public/components/PaymentsWidget.js +67 -0
package/README.md
CHANGED
|
@@ -398,3 +398,7 @@ account is a suite nobody runs.
|
|
|
398
398
|
## License
|
|
399
399
|
|
|
400
400
|
MIT
|
|
401
|
+
|
|
402
|
+
## Dashboard widget
|
|
403
|
+
|
|
404
|
+
Adds a **Payments** widget to the kempo admin dashboard showing money captured and refunded per currency, the payment count and any disputes, with a **View payments** button. It is declared in `widgets` in `kempo-config.json` and registered when the extension is installed or updated; people only see it if they hold its permission, and can hide, reorder or resize it from the dashboard's Customize dialog. Needs a kempo with the dashboard (see kempo's `docs/dashboard.md`); on an older kempo the entry is ignored.
|
package/admin/nav.global.html
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
<content id="kempo-payments-nav" name="Payments" owner="kempo-payments" enabled="true" locked="true" location="admin-nav-extensions" priority="
|
|
2
|
-
<k-aside-item icon="credit_card" href="/admin/extension/kempo-payments/" no-expand>Payments</k-aside-item>
|
|
1
|
+
<content id="kempo-payments-nav" name="Payments" owner="kempo-payments" enabled="true" locked="true" location="admin-nav-extensions" priority="50">
|
|
2
|
+
<k-aside-item icon="credit_card" group="Commerce" href="/admin/extension/kempo-payments/" no-expand>Payments</k-aside-item>
|
|
3
3
|
</content>
|
package/kempo-config.json
CHANGED
|
@@ -3,6 +3,21 @@
|
|
|
3
3
|
"git": "https://github.com/dustinpoissant/kempo-payments",
|
|
4
4
|
"public-scope": "payments",
|
|
5
5
|
"schema": "./server/db/schema.js",
|
|
6
|
+
"widgets": [
|
|
7
|
+
{
|
|
8
|
+
"key": "summary",
|
|
9
|
+
"title": "Payments",
|
|
10
|
+
"description": "Money captured and refunded, and how many payments there have been.",
|
|
11
|
+
"icon": "credit_card",
|
|
12
|
+
"element": "k-pay-widget",
|
|
13
|
+
"module": "/payments/components/PaymentsWidget.js",
|
|
14
|
+
"defaultWidth": 2,
|
|
15
|
+
"defaultHeight": 1,
|
|
16
|
+
"minWidth": 1,
|
|
17
|
+
"permission": "payments:view",
|
|
18
|
+
"priority": 80
|
|
19
|
+
}
|
|
20
|
+
],
|
|
6
21
|
"permissions": [
|
|
7
22
|
{ "name": "payments:view", "description": "See payments, what they were for, and what happened to them" },
|
|
8
23
|
{ "name": "payments:create", "description": "Take a payment — start a new charge over the API" },
|
package/package.json
CHANGED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import DashboardWidget from '/kempo/components/DashboardWidget.js';
|
|
2
|
+
import { html, nothing } from '/kempo-ui/lit-all.min.js';
|
|
3
|
+
import { getSummary } from '/payments/sdk.js';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
Amounts are whole numbers of the currency's smallest unit, so they are divided by what that currency
|
|
7
|
+
uses (100 for dollars, 1 for yen) before display.
|
|
8
|
+
*/
|
|
9
|
+
const money = (amount, currency) => {
|
|
10
|
+
const format = new Intl.NumberFormat(undefined, { style: 'currency', currency: currency.toUpperCase() });
|
|
11
|
+
return format.format(amount / 10 ** format.resolvedOptions().maximumFractionDigits);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
Captured and refunded money per currency, how many payments there are, and any open disputes.
|
|
16
|
+
*/
|
|
17
|
+
export default class PaymentsWidget extends DashboardWidget {
|
|
18
|
+
static properties = {
|
|
19
|
+
...DashboardWidget.properties,
|
|
20
|
+
currencies: { state: true },
|
|
21
|
+
disputed: { state: true }
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
constructor(){
|
|
25
|
+
super();
|
|
26
|
+
this.currencies = [];
|
|
27
|
+
this.disputed = 0;
|
|
28
|
+
this.cta = { label: 'View payments', icon: 'credit_card', href: '/admin/extension/kempo-payments/' };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/*
|
|
32
|
+
Public Methods
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
load = async () => {
|
|
36
|
+
const { byStatus, disputed } = await this.unwrap(getSummary());
|
|
37
|
+
const totals = {};
|
|
38
|
+
byStatus.forEach(({ currency, count, captured, refunded }) => {
|
|
39
|
+
const entry = totals[currency] ??= { currency, count: 0, captured: 0, refunded: 0 };
|
|
40
|
+
entry.count += count;
|
|
41
|
+
entry.captured += captured;
|
|
42
|
+
entry.refunded += refunded;
|
|
43
|
+
});
|
|
44
|
+
this.currencies = Object.values(totals);
|
|
45
|
+
this.disputed = disputed;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/*
|
|
49
|
+
Rendering
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
renderContent(){
|
|
53
|
+
if(!this.currencies.length) return html`<p class="tc-muted">No payments yet.</p>`;
|
|
54
|
+
return html`
|
|
55
|
+
${this.currencies.map(({ currency, count, captured, refunded }) => html`
|
|
56
|
+
<div class="d-f mb">
|
|
57
|
+
<div class="flex"><div class="h2 m0">${money(captured, currency)}</div><div class="small tc-muted">Captured (${currency.toUpperCase()})</div></div>
|
|
58
|
+
<div class="flex"><div class="h2 m0">${money(refunded, currency)}</div><div class="small tc-muted">Refunded</div></div>
|
|
59
|
+
<div class="flex"><div class="h2 m0">${count}</div><div class="small tc-muted">Payments</div></div>
|
|
60
|
+
</div>
|
|
61
|
+
`)}
|
|
62
|
+
${this.disputed ? html`<p class="tc-danger" role="alert">${this.disputed} disputed</p>` : nothing}
|
|
63
|
+
`;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
customElements.define('k-pay-widget', PaymentsWidget);
|