@meith/plugin-dues 0.34.0 → 0.35.1
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/package.json +3 -3
- package/src/definition.tsx +1 -1
- package/src/entitlement.ts +15 -10
- package/src/store.ts +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meith/plugin-dues",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.1",
|
|
4
4
|
"description": "Membership dues for a Meith board: Stripe-backed subscriptions as a contained plugin.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@meith/plugin-kit": "^0.
|
|
24
|
-
"@meith/theme-kit": "^0.
|
|
23
|
+
"@meith/plugin-kit": "^0.35.1",
|
|
24
|
+
"@meith/theme-kit": "^0.35.1"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": "^19.2.0"
|
package/src/definition.tsx
CHANGED
|
@@ -57,7 +57,7 @@ export function createDues(input: DuesConfigInput = {}): PluginDefinition {
|
|
|
57
57
|
return definePlugin({
|
|
58
58
|
key: 'dues',
|
|
59
59
|
name: 'Dues',
|
|
60
|
-
version: '0.
|
|
60
|
+
version: '0.35.1',
|
|
61
61
|
description: en['dues.definition.description'].replace(
|
|
62
62
|
'{label}',
|
|
63
63
|
staticConfig.label.toLowerCase(),
|
package/src/entitlement.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
type OrderRow,
|
|
17
17
|
orderByPaymentIntent,
|
|
18
18
|
orderBySessionId,
|
|
19
|
+
orderHasCharge,
|
|
19
20
|
type PlanRow,
|
|
20
21
|
planRowByKey,
|
|
21
22
|
releaseCodeReservation,
|
|
@@ -106,6 +107,8 @@ export async function settlePaidOrder(
|
|
|
106
107
|
stripeSubscriptionId: info.subscriptionId,
|
|
107
108
|
lastOrderId: order.id,
|
|
108
109
|
})
|
|
110
|
+
} else if (existing.lastOrderId === order.id) {
|
|
111
|
+
membership = existing
|
|
109
112
|
} else {
|
|
110
113
|
await extendMembership(deps.data, existing.id, {
|
|
111
114
|
currentPeriodEnd: periodEnd,
|
|
@@ -141,16 +144,18 @@ export async function settlePaidOrder(
|
|
|
141
144
|
...(order.discountMinor > 0 ? [`code took ${order.discountMinor} off`] : []),
|
|
142
145
|
]
|
|
143
146
|
|
|
144
|
-
await
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
147
|
+
if (!(await orderHasCharge(deps.data, order.id))) {
|
|
148
|
+
await insertLedger(deps.data, {
|
|
149
|
+
kind: 'charge',
|
|
150
|
+
userId: order.buyerUserId,
|
|
151
|
+
membershipId: membership.id,
|
|
152
|
+
orderId: order.id,
|
|
153
|
+
amountMinor: order.amountMinor,
|
|
154
|
+
currency: order.currency,
|
|
155
|
+
stripeRef: info.paymentIntentId ?? info.subscriptionId,
|
|
156
|
+
note: notes.length === 0 ? null : notes.join('; '),
|
|
157
|
+
})
|
|
158
|
+
}
|
|
154
159
|
|
|
155
160
|
await settleOrder(deps.data, order.id, {
|
|
156
161
|
status: 'paid',
|
package/src/store.ts
CHANGED
|
@@ -594,6 +594,15 @@ export async function insertLedger(data: PluginData, entry: NewLedgerEntry): Pro
|
|
|
594
594
|
)
|
|
595
595
|
}
|
|
596
596
|
|
|
597
|
+
export async function orderHasCharge(data: PluginData, orderId: number): Promise<boolean> {
|
|
598
|
+
const row = await data.one(
|
|
599
|
+
`select 1 as found from plugin_dues_ledger
|
|
600
|
+
where order_id = $1 and kind = 'charge' limit 1`,
|
|
601
|
+
[orderId],
|
|
602
|
+
)
|
|
603
|
+
return row !== null
|
|
604
|
+
}
|
|
605
|
+
|
|
597
606
|
export async function recentLedger(data: PluginData, limit = 50): Promise<readonly LedgerRow[]> {
|
|
598
607
|
const rows = await data.query(
|
|
599
608
|
`select * from plugin_dues_ledger order by occurred_at desc limit $1`,
|