Skip to content

Commit

Permalink
reduce territory price with prorated refund for actives
Browse files Browse the repository at this point in the history
  • Loading branch information
huumn committed Dec 24, 2024
1 parent b4352e7 commit 6cf1e36
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
6 changes: 3 additions & 3 deletions components/territory-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export default function TerritoryForm ({ sub }) {
>
<Checkbox
type='radio'
label='100k sats/month'
label={`${abbrNum(TERRITORY_PERIOD_COST('MONTHLY'))} sats/month`}
value='MONTHLY'
name='billingType'
id='monthly-checkbox'
Expand All @@ -206,7 +206,7 @@ export default function TerritoryForm ({ sub }) {
/>
<Checkbox
type='radio'
label='1m sats/year'
label={`${abbrNum(TERRITORY_PERIOD_COST('YEARLY'))} sats/year`}
value='YEARLY'
name='billingType'
id='yearly-checkbox'
Expand All @@ -215,7 +215,7 @@ export default function TerritoryForm ({ sub }) {
/>
<Checkbox
type='radio'
label='3m sats once'
label={`${abbrNum(TERRITORY_PERIOD_COST('ONCE'))} sats once`}
value='ONCE'
name='billingType'
id='once-checkbox'
Expand Down
8 changes: 4 additions & 4 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,19 @@ export const FREEBIE_BASE_COST_THRESHOLD = 10
// From lawyers: north korea, cuba, iran, ukraine, syria
export const SANCTIONED_COUNTRY_CODES = ['KP', 'CU', 'IR', 'UA', 'SY']

export const TERRITORY_COST_MONTHLY = 100000
export const TERRITORY_COST_YEARLY = 1000000
export const TERRITORY_COST_MONTHLY = 50000
export const TERRITORY_COST_YEARLY = 500000
export const TERRITORY_COST_ONCE = 3000000

export const TERRITORY_BILLING_OPTIONS = (labelPrefix) => ({
monthly: {
term: '+ 100k',
term: '+ 50k',
label: `${labelPrefix} month`,
op: '+',
modifier: cost => cost + TERRITORY_COST_MONTHLY
},
yearly: {
term: '+ 1m',
term: '+ 500k',
label: `${labelPrefix} year`,
op: '+',
modifier: cost => cost + TERRITORY_COST_YEARLY
Expand Down
16 changes: 16 additions & 0 deletions prisma/migrations/20241223204948_territory_refund/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- refund users who have active territories and paid the old, higher price
-- for the rest of their billing period once the switchover is complete

WITH active_territories AS (
SELECT *,
"billingCost" *
EXTRACT(epoch FROM "billPaidUntil" - now()) / EXTRACT(epoch FROM "billPaidUntil" - "billedLastAt") *
0.5 AS refund_sats
FROM "Sub"
WHERE "status" = 'ACTIVE'
AND "billingType" IN ('MONTHLY', 'YEARLY')
)
UPDATE users
SET msats = msats + refund_sats*1000
FROM active_territories
WHERE users.id = active_territories."userId";

0 comments on commit 6cf1e36

Please sign in to comment.