feat: open billing for lmz customers #538
This commit is contained in:
@@ -1,21 +1,44 @@
|
||||
<script>
|
||||
import { VARIANTS } from '$lib/components/PrimaryButton/constants';
|
||||
import PrimaryButton from '$lib/components/PrimaryButton/index.svelte';
|
||||
import { snackbar } from '$lib/components/Snackbar/store';
|
||||
import { t } from '$lib/utils/functions/translations';
|
||||
import { currentOrgPlan, isFreePlan } from '$lib/utils/store/org';
|
||||
import { Column, Grid, Row } from 'carbon-components-svelte';
|
||||
import SectionTitle from '../SectionTitle.svelte';
|
||||
|
||||
let isRedirecting = false;
|
||||
|
||||
async function onOpenBilling() {
|
||||
console.log({
|
||||
plan: $currentOrgPlan
|
||||
});
|
||||
|
||||
if ($currentOrgPlan?.customerId) {
|
||||
const url = new URL('/api/polar/portal', window.location.origin);
|
||||
url.searchParams.set('customerId', $currentOrgPlan?.customerId);
|
||||
try {
|
||||
if ($currentOrgPlan?.provider === 'polar') {
|
||||
const url = new URL('/api/polar/portal', window.location.origin);
|
||||
url.searchParams.set('customerId', $currentOrgPlan?.customerId);
|
||||
|
||||
window.open(url.toString(), '_blank');
|
||||
window.open(url.toString(), '_blank');
|
||||
}
|
||||
|
||||
if ($currentOrgPlan?.provider === 'lmz') {
|
||||
isRedirecting = true;
|
||||
const url = new URL('/api/lmz/subscription', window.location.origin);
|
||||
url.searchParams.set('subscriptionId', $currentOrgPlan?.subscriptionId);
|
||||
|
||||
const response = await fetch(url.toString());
|
||||
const result = await response.json();
|
||||
|
||||
isRedirecting = false;
|
||||
|
||||
window.open(result.customerPortal, '_blank');
|
||||
}
|
||||
} catch (error) {
|
||||
isRedirecting = false;
|
||||
|
||||
console.error(error);
|
||||
snackbar.error($t('settings.billing.error'));
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -36,7 +59,7 @@
|
||||
label={$t('settings.billing.open_billing')}
|
||||
variant={VARIANTS.CONTAINED_DARK}
|
||||
onClick={onOpenBilling}
|
||||
isDisabled={!$currentOrgPlan?.customerId}
|
||||
isLoading={isRedirecting}
|
||||
/>
|
||||
{/if}
|
||||
</Column>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { env } from '$env/dynamic/private';
|
||||
import { lemonSqueezySetup } from '@lemonsqueezy/lemonsqueezy.js';
|
||||
|
||||
export function configureLemonSqueezy() {
|
||||
return lemonSqueezySetup({
|
||||
apiKey: env.LEMON_SQUEEZY_API_KEY,
|
||||
onError: (error) => {
|
||||
throw new Error(`Lemon Squeezy API error: ${error.message}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { getAccessToken } from '$lib/utils/functions/supabase';
|
||||
import axios from 'axios';
|
||||
|
||||
interface SubscriptionData {
|
||||
productId: string;
|
||||
email: string;
|
||||
name: string;
|
||||
triggeredBy: string;
|
||||
orgId: string;
|
||||
}
|
||||
|
||||
interface SubscriptionResponse {
|
||||
success: boolean;
|
||||
checkoutURL: string;
|
||||
}
|
||||
|
||||
export async function subscribeToProduct(data: SubscriptionData): Promise<SubscriptionResponse> {
|
||||
const accessToken = await getAccessToken();
|
||||
|
||||
const response = await axios({
|
||||
method: 'POST',
|
||||
url: '/api/lmz/subscribe',
|
||||
data,
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`
|
||||
}
|
||||
});
|
||||
|
||||
return response.data;
|
||||
}
|
||||
@@ -77,6 +77,8 @@ export async function getOrganizations(userId: string, isOrgSite?: boolean, orgS
|
||||
organization_plan(
|
||||
plan_name,
|
||||
is_active,
|
||||
provider,
|
||||
subscriptionId:payload->id,
|
||||
customerId:payload->customerId
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1148,7 +1148,8 @@
|
||||
"manage": "Verwalten Sie Ihre Abrechnung",
|
||||
"active": "Sie haben keine aktive Abrechnung",
|
||||
"open_billing": "Abrechnung öffnen",
|
||||
"provider": "Wir verwenden Polar, um Ihre Abrechnung zu verwalten"
|
||||
"provider": "Wir verwenden Polar, um Ihre Abrechnung zu verwalten",
|
||||
"error": "Beim Öffnen der Abrechnung ist ein Fehler aufgetreten"
|
||||
},
|
||||
"integrations": {
|
||||
"heading": "Telegramm",
|
||||
|
||||
@@ -243,7 +243,8 @@
|
||||
"manage": "Manage your billing",
|
||||
"active": "You don't have any active billing",
|
||||
"provider": "We use Polar to help manage your billing",
|
||||
"open_billing": "Open billing"
|
||||
"open_billing": "Open billing",
|
||||
"error": "An error occurred while opening billing"
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -1148,7 +1148,8 @@
|
||||
"manage": "Gestiona tu facturación",
|
||||
"active": "No tienes ninguna facturación activa",
|
||||
"open_billing": "Facturación abierta",
|
||||
"provider": "Usamos Polar para ayudarte a gestionar tu facturación"
|
||||
"provider": "Usamos Polar para ayudarte a gestionar tu facturación",
|
||||
"error": "Se produjo un error al abrir la facturación."
|
||||
},
|
||||
"integrations": {
|
||||
"heading": "Telegrama",
|
||||
|
||||
@@ -1148,7 +1148,8 @@
|
||||
"manage": "Gérez votre facturation",
|
||||
"active": "Vous n'avez aucune facturation active",
|
||||
"open_billing": "Facturation ouverte",
|
||||
"provider": "Nous utilisons Polar pour vous aider à gérer votre facturation"
|
||||
"provider": "Nous utilisons Polar pour vous aider à gérer votre facturation",
|
||||
"error": "Une erreur s'est produite lors de l'ouverture de la facturation"
|
||||
},
|
||||
"integrations": {
|
||||
"heading": "Télégramme",
|
||||
|
||||
@@ -1148,7 +1148,8 @@
|
||||
"manage": "अपनी बिलिंग प्रबंधित करें",
|
||||
"active": "आपके पास कोई सक्रिय बिलिंग नहीं है",
|
||||
"open_billing": "बिलिंग खोलें",
|
||||
"provider": "हम आपकी बिलिंग प्रबंधित करने में सहायता के लिए पोलर का उपयोग करते हैं"
|
||||
"provider": "हम आपकी बिलिंग प्रबंधित करने में सहायता के लिए पोलर का उपयोग करते हैं",
|
||||
"error": "बिलिंग खोलते समय एक त्रुटि उत्पन्न हुई"
|
||||
},
|
||||
"integrations": {
|
||||
"heading": "तार",
|
||||
|
||||
@@ -1148,7 +1148,8 @@
|
||||
"manage": "Gerencie seu faturamento",
|
||||
"active": "Você não tem nenhum faturamento ativo",
|
||||
"open_billing": "Faturamento aberto",
|
||||
"provider": "Usamos a Polar para ajudar a gerenciar seu faturamento"
|
||||
"provider": "Usamos a Polar para ajudar a gerenciar seu faturamento",
|
||||
"error": "Ocorreu um erro ao abrir o faturamento"
|
||||
},
|
||||
"integrations": {
|
||||
"heading": "Telegrama",
|
||||
|
||||
@@ -1148,7 +1148,8 @@
|
||||
"manage": "Управляйте своим биллингом",
|
||||
"active": "У вас нет активных платежных данных.",
|
||||
"open_billing": "Открыть биллинг",
|
||||
"provider": "Мы используем Polar, чтобы управлять вашими платежами."
|
||||
"provider": "Мы используем Polar, чтобы управлять вашими платежами.",
|
||||
"error": "Произошла ошибка при открытии счета."
|
||||
},
|
||||
"integrations": {
|
||||
"heading": "Телеграмма",
|
||||
|
||||
@@ -1148,7 +1148,8 @@
|
||||
"manage": "Quản lý thanh toán của bạn",
|
||||
"active": "Bạn không có bất kỳ thanh toán nào đang hoạt động",
|
||||
"open_billing": "Thanh toán mở",
|
||||
"provider": "Chúng tôi sử dụng Polar để giúp quản lý việc thanh toán của bạn"
|
||||
"provider": "Chúng tôi sử dụng Polar để giúp quản lý việc thanh toán của bạn",
|
||||
"error": "Đã xảy ra lỗi khi mở thanh toán"
|
||||
},
|
||||
"integrations": {
|
||||
"heading": "điện tín",
|
||||
|
||||
@@ -29,6 +29,8 @@ export interface CurrentOrg {
|
||||
customization: OrgCustomization;
|
||||
theme: string;
|
||||
organization_plan: {
|
||||
provider: 'polar' | 'lmz';
|
||||
subscriptionId: string;
|
||||
customerId: string;
|
||||
plan_name: string;
|
||||
is_active: boolean;
|
||||
|
||||
Reference in New Issue
Block a user