mirror of
https://github.com/pockethost/pockethost.git
synced 2025-11-24 06:25:48 +00:00
enh: add new product SKUs to LS hook
This commit is contained in:
parent
286ff5f93e
commit
f7bc130c54
@ -14,13 +14,13 @@ type LemonSqueezyDebugContext = PartialDeep<{
|
||||
product_id: number
|
||||
product_name: string
|
||||
variant_id: number
|
||||
variant_name: string
|
||||
first_order_item: {
|
||||
product_id: number
|
||||
product_name: string
|
||||
variant_id: number
|
||||
}
|
||||
first_subscription_item: {
|
||||
subscription_id: number
|
||||
variant_name: string
|
||||
quantity: number
|
||||
}
|
||||
}
|
||||
type: string
|
||||
@ -37,8 +37,9 @@ type LemonSqueezyDebugContext = PartialDeep<{
|
||||
user_id: string
|
||||
product_id: number
|
||||
variant_id: number
|
||||
subscription_id: number
|
||||
product_name: string
|
||||
quantity: number
|
||||
variant_name: string
|
||||
}>
|
||||
|
||||
export const HandleLemonSqueezySale = (c: echo.Context) => {
|
||||
@ -111,23 +112,37 @@ export const HandleLemonSqueezySale = (c: echo.Context) => {
|
||||
context.data?.data?.attributes?.first_order_item?.product_name ||
|
||||
context.data?.data?.attributes?.product_name ||
|
||||
''
|
||||
log(`product name ok`, context.product_name)
|
||||
|
||||
context.variant_id =
|
||||
context.data?.data?.attributes?.first_order_item?.variant_id ||
|
||||
context.data?.data?.attributes?.variant_id ||
|
||||
0
|
||||
|
||||
if (!context.variant_id) {
|
||||
throw new Error(`No variant ID`)
|
||||
} else {
|
||||
log(`variant ID ok`, context.variant_id)
|
||||
}
|
||||
|
||||
context.variant_name =
|
||||
context.data?.data?.attributes?.first_order_item?.variant_name ||
|
||||
context.data?.data?.attributes?.variant_name ||
|
||||
''
|
||||
log(`variant name ok`, context.variant_name)
|
||||
|
||||
context.quantity =
|
||||
context.data?.data?.attributes?.first_order_item?.quantity || 0
|
||||
log(`quantity ok`, context.quantity)
|
||||
|
||||
const FLOUNDER_ANNUAL_PV_ID = `367781-200790`
|
||||
const FLOUNDER_LIFETIME_PV_ID = `306534-441845`
|
||||
const PRO_MONTHLY_PV_ID = `159790-200788`
|
||||
const PRO_ANNUAL_PV_ID = `159791-200789`
|
||||
const FOUNDER_ANNUAL_PV_ID = `159792-200790`
|
||||
const PAYWALL_INSTANCE_MONTHLY_PV_ID = `424532-651625`
|
||||
const PAYWALL_PRO_MONTHLY_PV_ID = `424532-651629`
|
||||
const PAYWALL_PRO_ANNUAL_PV_ID = `424532-651634`
|
||||
const PAYWALL_FLOUNDER_PV_ID = `424532-651627`
|
||||
|
||||
const pv_id = `${context.product_id}-${context.variant_id}`
|
||||
|
||||
@ -138,16 +153,15 @@ export const HandleLemonSqueezySale = (c: echo.Context) => {
|
||||
PRO_MONTHLY_PV_ID,
|
||||
PRO_ANNUAL_PV_ID,
|
||||
FOUNDER_ANNUAL_PV_ID,
|
||||
PAYWALL_INSTANCE_MONTHLY_PV_ID,
|
||||
PAYWALL_PRO_MONTHLY_PV_ID,
|
||||
PAYWALL_PRO_ANNUAL_PV_ID,
|
||||
PAYWALL_FLOUNDER_PV_ID,
|
||||
].includes(pv_id)
|
||||
) {
|
||||
throw new Error(`Product and variant not found: ${pv_id}`)
|
||||
}
|
||||
|
||||
context.subscription_id =
|
||||
context.data?.data?.attributes?.first_subscription_item
|
||||
?.subscription_id || 0
|
||||
log(`subscription ID`, context.subscription_id)
|
||||
|
||||
const userRec = (() => {
|
||||
try {
|
||||
return dao.findFirstRecordByData('users', 'id', context.user_id)
|
||||
@ -206,6 +220,30 @@ export const HandleLemonSqueezySale = (c: echo.Context) => {
|
||||
userRec.set(`subscription`, `flounder`)
|
||||
userRec.set(`subscription_interval`, `year`)
|
||||
},
|
||||
// Paywall instance
|
||||
[PAYWALL_INSTANCE_MONTHLY_PV_ID]: () => {
|
||||
userRec.set(`subscription`, `premium`)
|
||||
userRec.set(`subscription_interval`, `month`)
|
||||
userRec.set(`subscription_quantity`, context.quantity)
|
||||
},
|
||||
// Paywall pro monthly
|
||||
[PAYWALL_PRO_MONTHLY_PV_ID]: () => {
|
||||
userRec.set(`subscription`, `premium`)
|
||||
userRec.set(`subscription_interval`, `month`)
|
||||
userRec.set(`subscription_quantity`, 250)
|
||||
},
|
||||
// Paywall pro annual
|
||||
[PAYWALL_PRO_ANNUAL_PV_ID]: () => {
|
||||
userRec.set(`subscription`, `premium`)
|
||||
userRec.set(`subscription_interval`, `year`)
|
||||
userRec.set(`subscription_quantity`, 250)
|
||||
},
|
||||
// Paywall flounder
|
||||
[PAYWALL_FLOUNDER_PV_ID]: () => {
|
||||
userRec.set(`subscription`, `flounder`)
|
||||
userRec.set(`subscription_interval`, `life`)
|
||||
userRec.set(`subscription_quantity`, 250)
|
||||
},
|
||||
} as const
|
||||
|
||||
const product_handler =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user