reduce territory price with prorated refund for actives (#1761)

This commit is contained in:
Keyan 2024-12-23 18:50:35 -06:00 committed by GitHub
parent b4352e74b4
commit 2fc529419e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 7 deletions

View File

@ -197,7 +197,7 @@ export default function TerritoryForm ({ sub }) {
> >
<Checkbox <Checkbox
type='radio' type='radio'
label='100k sats/month' label={`${abbrNum(TERRITORY_PERIOD_COST('MONTHLY'))} sats/month`}
value='MONTHLY' value='MONTHLY'
name='billingType' name='billingType'
id='monthly-checkbox' id='monthly-checkbox'
@ -206,7 +206,7 @@ export default function TerritoryForm ({ sub }) {
/> />
<Checkbox <Checkbox
type='radio' type='radio'
label='1m sats/year' label={`${abbrNum(TERRITORY_PERIOD_COST('YEARLY'))} sats/year`}
value='YEARLY' value='YEARLY'
name='billingType' name='billingType'
id='yearly-checkbox' id='yearly-checkbox'
@ -215,7 +215,7 @@ export default function TerritoryForm ({ sub }) {
/> />
<Checkbox <Checkbox
type='radio' type='radio'
label='3m sats once' label={`${abbrNum(TERRITORY_PERIOD_COST('ONCE'))} sats once`}
value='ONCE' value='ONCE'
name='billingType' name='billingType'
id='once-checkbox' id='once-checkbox'

View File

@ -92,19 +92,19 @@ export const FREEBIE_BASE_COST_THRESHOLD = 10
// From lawyers: north korea, cuba, iran, ukraine, syria // From lawyers: north korea, cuba, iran, ukraine, syria
export const SANCTIONED_COUNTRY_CODES = ['KP', 'CU', 'IR', 'UA', 'SY'] export const SANCTIONED_COUNTRY_CODES = ['KP', 'CU', 'IR', 'UA', 'SY']
export const TERRITORY_COST_MONTHLY = 100000 export const TERRITORY_COST_MONTHLY = 50000
export const TERRITORY_COST_YEARLY = 1000000 export const TERRITORY_COST_YEARLY = 500000
export const TERRITORY_COST_ONCE = 3000000 export const TERRITORY_COST_ONCE = 3000000
export const TERRITORY_BILLING_OPTIONS = (labelPrefix) => ({ export const TERRITORY_BILLING_OPTIONS = (labelPrefix) => ({
monthly: { monthly: {
term: '+ 100k', term: '+ 50k',
label: `${labelPrefix} month`, label: `${labelPrefix} month`,
op: '+', op: '+',
modifier: cost => cost + TERRITORY_COST_MONTHLY modifier: cost => cost + TERRITORY_COST_MONTHLY
}, },
yearly: { yearly: {
term: '+ 1m', term: '+ 500k',
label: `${labelPrefix} year`, label: `${labelPrefix} year`,
op: '+', op: '+',
modifier: cost => cost + TERRITORY_COST_YEARLY modifier: cost => cost + TERRITORY_COST_YEARLY

View File

@ -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";