feat: migrate from lemonsqueezy to polar (#535)
* feat: move from lemonsqueezy to polar * update lock * add migration files * test with demo product id
This commit is contained in:
@@ -77,7 +77,7 @@ export async function getOrganizations(userId: string, isOrgSite?: boolean, orgS
|
||||
organization_plan(
|
||||
plan_name,
|
||||
is_active,
|
||||
subscriptionId:lmz_data->id
|
||||
subscriptionId:payload->id
|
||||
)
|
||||
)
|
||||
`
|
||||
@@ -255,11 +255,27 @@ export async function getCurrentOrg(siteName: string, justGet = false, isCustomD
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateOrgPlan(params: {
|
||||
supabase: typeof supabase;
|
||||
subscriptionId: string;
|
||||
data: OrganizationPlan['payload'];
|
||||
}) {
|
||||
return await params.supabase
|
||||
.from('organization_plan')
|
||||
.update({
|
||||
payload: params.data
|
||||
})
|
||||
.match({
|
||||
subscription_id: params.subscriptionId
|
||||
});
|
||||
}
|
||||
|
||||
export async function createOrgPlan(params: {
|
||||
orgId: string;
|
||||
planName: string;
|
||||
triggeredBy: number;
|
||||
data: OrganizationPlan['lmz_data'];
|
||||
orgId: OrganizationPlan['org_id'];
|
||||
planName: OrganizationPlan['plan_name'];
|
||||
subscriptionId: OrganizationPlan['subscription_id'];
|
||||
triggeredBy: OrganizationPlan['triggered_by'];
|
||||
data: OrganizationPlan['payload'];
|
||||
supabase: typeof supabase;
|
||||
}) {
|
||||
return await params.supabase.from('organization_plan').insert({
|
||||
@@ -268,19 +284,24 @@ export async function createOrgPlan(params: {
|
||||
triggered_by: params.triggeredBy,
|
||||
plan_name: params.planName,
|
||||
is_active: true,
|
||||
lmz_data: params.data
|
||||
payload: params.data,
|
||||
subscription_id: params.subscriptionId,
|
||||
provider: 'polar'
|
||||
});
|
||||
}
|
||||
|
||||
export async function cancelOrgPlan(params: { orgId: string; planName: string }) {
|
||||
export async function cancelOrgPlan(params: {
|
||||
subscriptionId: string;
|
||||
data: OrganizationPlan['payload'];
|
||||
}) {
|
||||
return await supabase
|
||||
.from('organization_plan')
|
||||
.update({
|
||||
is_active: false,
|
||||
deactivated_at: new Date().toDateString()
|
||||
deactivated_at: new Date().toDateString(),
|
||||
payload: params.data
|
||||
})
|
||||
.match({
|
||||
plan_name: params.planName,
|
||||
org_id: params.orgId
|
||||
subscription_id: params.subscriptionId
|
||||
});
|
||||
}
|
||||
|
||||
@@ -136,10 +136,13 @@ export interface OrganizationPlan {
|
||||
activated_at: string;
|
||||
deactivated_at: string;
|
||||
org_id: string;
|
||||
subscription_id: string;
|
||||
triggered_by: number;
|
||||
plan_name: string;
|
||||
is_active: boolean;
|
||||
updated_at: string;
|
||||
lmz_data: unknown;
|
||||
payload: unknown;
|
||||
provider: string;
|
||||
}
|
||||
|
||||
export interface Profile {
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
interface BillingAddress {
|
||||
line1: string | null;
|
||||
line2: string | null;
|
||||
postalCode: string | null;
|
||||
city: string | null;
|
||||
state: string | null;
|
||||
country: string;
|
||||
}
|
||||
|
||||
interface Customer {
|
||||
createdAt: string;
|
||||
modifiedAt: string | null;
|
||||
id: string;
|
||||
metadata: Record<string, any>;
|
||||
email: string;
|
||||
emailVerified: boolean;
|
||||
name: string;
|
||||
billingAddress: BillingAddress;
|
||||
taxId: string | null;
|
||||
organizationId: string;
|
||||
avatarUrl: string;
|
||||
}
|
||||
|
||||
interface User {
|
||||
id: string;
|
||||
email: string;
|
||||
publicName: string;
|
||||
avatarUrl: string | null;
|
||||
githubUsername: string | null;
|
||||
}
|
||||
|
||||
interface Price {
|
||||
createdAt: string;
|
||||
modifiedAt: string | null;
|
||||
id: string;
|
||||
amountType: string;
|
||||
isArchived: boolean;
|
||||
productId: string;
|
||||
priceCurrency: string;
|
||||
priceAmount: number;
|
||||
type: string;
|
||||
recurringInterval: string;
|
||||
}
|
||||
|
||||
interface Media {
|
||||
id: string;
|
||||
organizationId: string;
|
||||
name: string;
|
||||
path: string;
|
||||
mimeType: string;
|
||||
size: number;
|
||||
storageVersion: string;
|
||||
checksumEtag: string;
|
||||
checksumSha256Base64: string;
|
||||
checksumSha256Hex: string;
|
||||
lastModifiedAt: string;
|
||||
version: string | null;
|
||||
service: string;
|
||||
isUploaded: boolean;
|
||||
createdAt: string;
|
||||
sizeReadable: string;
|
||||
publicUrl: string;
|
||||
}
|
||||
|
||||
interface Product {
|
||||
createdAt: string;
|
||||
modifiedAt: string;
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
isRecurring: boolean;
|
||||
isArchived: boolean;
|
||||
organizationId: string;
|
||||
metadata: Record<string, any>;
|
||||
prices: Price[];
|
||||
benefits: any[];
|
||||
medias: Media[];
|
||||
attachedCustomFields: any[];
|
||||
}
|
||||
|
||||
interface SubscriptionData {
|
||||
createdAt: string;
|
||||
modifiedAt: string | null;
|
||||
id: string;
|
||||
amount: number;
|
||||
currency: string;
|
||||
recurringInterval: string;
|
||||
status: string;
|
||||
currentPeriodStart: string;
|
||||
currentPeriodEnd: string;
|
||||
cancelAtPeriodEnd: boolean;
|
||||
canceledAt: string | null;
|
||||
startedAt: string;
|
||||
endsAt: string | null;
|
||||
endedAt: string | null;
|
||||
customerId: string;
|
||||
productId: string;
|
||||
priceId: string;
|
||||
discountId: string | null;
|
||||
checkoutId: string;
|
||||
customerCancellationReason: string | null;
|
||||
customerCancellationComment: string | null;
|
||||
metadata: {
|
||||
orgId: string;
|
||||
orgSlug: string;
|
||||
triggeredBy: string;
|
||||
};
|
||||
customFieldData: Record<string, any>;
|
||||
customer: Customer;
|
||||
userId: string;
|
||||
user: User;
|
||||
product: Product;
|
||||
price: Price;
|
||||
discount: any | null;
|
||||
}
|
||||
|
||||
export interface PolarWebhookPayload {
|
||||
type: string;
|
||||
data: SubscriptionData;
|
||||
}
|
||||
Reference in New Issue
Block a user