Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/lib/sdk/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,16 @@ export class Billing {
organizationId: string,
name: string,
billingPlan: string,
paymentMethodId: string
paymentMethodId: string,
billingAddressId: string
): Promise<Organization> {
const path = `/organizations`;
const params = {
organizationId,
name,
billingPlan,
paymentMethodId
paymentMethodId,
billingAddressId
};
const uri = new URL(this.client.config.endpoint + path);
return await this.client.call(
Expand Down Expand Up @@ -331,13 +333,15 @@ export class Billing {
async updatePlan(
organizationId: string,
billingPlan: string,
paymentMethodId: string
paymentMethodId: string,
billingAddressId: string
): Promise<Organization> {
const path = `/organizations/${organizationId}/plan`;
const params = {
organizationId,
billingPlan,
paymentMethodId
paymentMethodId,
billingAddressId
};
const uri = new URL(this.client.config.endpoint + path);
return await this.client.call(
Expand Down
1 change: 1 addition & 0 deletions src/lib/stores/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ export async function checkForFreeOrgOverflow(orgs: Models.TeamList<Record<strin
importance: 10
});
}
activeHeaderAlert.set(headerAlert.get());
}

export async function checkForPostReleaseProModal(orgs: Models.TeamList<Record<string, unknown>>) {
Expand Down
41 changes: 4 additions & 37 deletions src/routes/console/changeOrganizationTierCloud.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
await sdk.forConsole.billing.updatePlan(
$organization.$id,
$changeOrganizationTier.billingPlan,
$changeOrganizationTier.paymentMethodId
$changeOrganizationTier.paymentMethodId,
$changeOrganizationTier.billingAddressId
);
feedback.submitFeedback(
'downgrade',
Expand Down Expand Up @@ -78,35 +79,10 @@
const org = await sdk.forConsole.billing.updatePlan(
$organization.$id,
$changeOrganizationTier.billingPlan,
$changeOrganizationTier.paymentMethodId
$changeOrganizationTier.paymentMethodId,
$changeOrganizationTier.billingAddressId
);

//Add billing address
if ($changeOrganizationTier.billingAddressId) {
await sdk.forConsole.billing.setBillingAddress(
org.$id,
$changeOrganizationTier.billingAddressId
);
} else if (
$changeOrganizationTier.billingAddress &&
$changeOrganizationTier.billingAddress.streetAddress
) {
const response = await sdk.forConsole.billing.createAddress(
$changeOrganizationTier.billingAddress.country,
$changeOrganizationTier.billingAddress.streetAddress,
$changeOrganizationTier.billingAddress.city,
$changeOrganizationTier.billingAddress.state,
$changeOrganizationTier.billingAddress.postalCode
? $changeOrganizationTier.billingAddress.postalCode
: undefined,
$changeOrganizationTier.billingAddress.addressLine2
? $changeOrganizationTier.billingAddress.addressLine2
: undefined
);

await sdk.forConsole.billing.setBillingAddress(org.$id, response.$id);
}

//Add coupon
if ($changeOrganizationTier.couponCode) {
await sdk.forConsole.billing.addCredit(
Expand Down Expand Up @@ -193,15 +169,6 @@
paymentMethodId: null,
collaborators: [],
billingAddressId: null,
billingAddress: {
$id: null,
streetAddress: null,
addressLine2: null,
city: null,
state: null,
postalCode: null,
country: null
},
taxId: null,
feedbackMessage: null
};
Expand Down
37 changes: 2 additions & 35 deletions src/routes/console/createOrganizationCloud.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,9 @@
$createOrganization.id ?? ID.unique(),
$createOrganization.name,
$createOrganization.billingPlan,
$createOrganization.paymentMethodId
$createOrganization.paymentMethodId,
$createOrganization.billingAddressId
);
//Add billing address
if ($createOrganization.billingAddressId) {
await sdk.forConsole.billing.setBillingAddress(
org.$id,
$createOrganization.billingAddressId
);
} else if (
$createOrganization.billingAddress &&
$createOrganization.billingAddress.streetAddress
) {
const response = await sdk.forConsole.billing.createAddress(
$createOrganization.billingAddress.country,
$createOrganization.billingAddress.streetAddress,
$createOrganization.billingAddress.city,
$createOrganization.billingAddress.state,
$createOrganization.billingAddress.postalCode
? $createOrganization.billingAddress.postalCode
: undefined,
$createOrganization.billingAddress.addressLine2
? $createOrganization.billingAddress.addressLine2
: undefined
);

await sdk.forConsole.billing.setBillingAddress(org.$id, response.$id);
}

//Add budget
if ($createOrganization?.billingBudget) {
Expand Down Expand Up @@ -121,15 +97,6 @@
paymentMethodId: null,
collaborators: [],
billingAddressId: null,
billingAddress: {
$id: null,
streetAddress: null,
addressLine2: null,
city: null,
state: null,
postalCode: null,
country: null
},
taxId: null
};
});
Expand Down
1 change: 1 addition & 0 deletions src/routes/console/onboarding/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
ID.unique(),
'Personal Projects',
'tier-0',
null,
null
);
} else return await sdk.forConsole.teams.create(ID.unique(), 'Personal Projects');
Expand Down
40 changes: 32 additions & 8 deletions src/routes/console/wizard/cloudOrganization/addressDetails.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,38 @@
}
];
let addressList: AddressesList;
let country: string;
let streetAddress: string;
let city: string;
let state: string;
let postalCode: string;
let addressLine2: string;

async function handleAddress() {
if (!$createOrganization.billingAddressId) {
try {
const response = await sdk.forConsole.billing.createAddress(
country,
streetAddress,
city,
state,
postalCode ? postalCode : undefined,
addressLine2 ? addressLine2 : undefined
);
$createOrganization.billingAddressId = response.$id;
} catch (error) {
throw new Error(error.message);
}
}
}

onMount(async () => {
addressList = await sdk.forConsole.billing.listAddresses();
$createOrganization.billingAddressId = addressList.billingAddresses?.[0]?.$id ?? null;
const countryList = await sdk.forProject.locale.listCountries();
const locale = await sdk.forProject.locale.get();
if (locale?.countryCode) {
$createOrganization.billingAddress.country = locale.countryCode;
country = locale.countryCode;
}
options = countryList.countries.map((country) => {
return {
Expand All @@ -32,7 +56,7 @@
});
</script>

<WizardStep>
<WizardStep beforeSubmit={handleAddress}>
<svelte:fragment slot="title">Billing address</svelte:fragment>
<svelte:fragment slot="subtitle">Add a billing address for your organization.</svelte:fragment>

Expand Down Expand Up @@ -70,25 +94,25 @@
placeholder="Enter tax ID"
optionalText="(optional)" />
<InputSelect
bind:value={$createOrganization.billingAddress.country}
bind:value={country}
{options}
label="Country or region"
placeholder="Select country or region"
id="country"
required />
<InputText
bind:value={$createOrganization.billingAddress.streetAddress}
bind:value={streetAddress}
id="address"
label="Street address"
placeholder="Enter street address"
required />
<InputText
bind:value={$createOrganization.billingAddress.addressLine2}
bind:value={addressLine2}
id="address2"
label="Address line 2"
placeholder="Unit number, floor, etc." />
<InputText
bind:value={$createOrganization.billingAddress.city}
bind:value={city}
id="city"
label="City or suburb"
placeholder="Enter your city"
Expand All @@ -97,15 +121,15 @@
<InputText
isMultiple
fullWidth
bind:value={$createOrganization.billingAddress.state}
bind:value={state}
id="state"
label="State"
placeholder="Enter your state"
required />
<InputText
isMultiple
fullWidth
bind:value={$createOrganization.billingAddress.postalCode}
bind:value={postalCode}
id="zip"
label="Postal code"
placeholder="Enter postal code" />
Expand Down
11 changes: 0 additions & 11 deletions src/routes/console/wizard/cloudOrganization/store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { WizardStepsType } from '$lib/layout/wizard.svelte';
import type { Address } from '$lib/sdk/billing';
import type { Tier } from '$lib/stores/billing';
import { writable } from 'svelte/store';

Expand All @@ -12,7 +11,6 @@ export const createOrganization = writable<{
billingPlan: Tier;
paymentMethodId: string;
billingAddressId: string;
billingAddress?: Address;
collaborators?: string[];
billingBudget?: number;
taxId?: string;
Expand All @@ -23,14 +21,5 @@ export const createOrganization = writable<{
paymentMethodId: null,
collaborators: [],
billingAddressId: null,
billingAddress: {
$id: null,
streetAddress: null,
addressLine2: null,
city: null,
state: null,
postalCode: null,
country: null
},
taxId: null
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,30 @@
}
];
let addressList: AddressesList;
let country: string;
let streetAddress: string;
let city: string;
let state: string;
let postalCode: string;
let addressLine2: string;

async function handleAddress() {
if (!$changeOrganizationTier.billingAddressId) {
try {
const response = await sdk.forConsole.billing.createAddress(
country,
streetAddress,
city,
state,
postalCode ? postalCode : undefined,
addressLine2 ? addressLine2 : undefined
);
$changeOrganizationTier.billingAddressId = response.$id;
} catch (error) {
throw new Error(error.message);
}
}
}

onMount(async () => {
addressList = await sdk.forConsole.billing.listAddresses();
Expand All @@ -23,7 +47,7 @@
: addressList.billingAddresses?.[0]?.$id ?? null;
const locale = await sdk.forProject.locale.get();
if (locale?.countryCode && !$changeOrganizationTier.billingAddressId) {
$changeOrganizationTier.billingAddress.country = locale.countryCode;
country = locale.countryCode;
}
const countryList = await sdk.forProject.locale.listCountries();
options = countryList.countries.map((country) => {
Expand All @@ -35,7 +59,7 @@
});
</script>

<WizardStep>
<WizardStep beforeSubmit={handleAddress}>
<svelte:fragment slot="title">Billing address</svelte:fragment>
<svelte:fragment slot="subtitle">Add a billing address for your organization.</svelte:fragment>

Expand Down Expand Up @@ -73,25 +97,25 @@
placeholder="Enter tax ID"
optionalText="(optional)" />
<InputSelect
bind:value={$changeOrganizationTier.billingAddress.country}
bind:value={country}
{options}
label="Country or region"
placeholder="Select country or region"
id="country"
required />
<InputText
bind:value={$changeOrganizationTier.billingAddress.streetAddress}
bind:value={streetAddress}
id="address"
label="Street address"
placeholder="Enter street address"
required />
<InputText
bind:value={$changeOrganizationTier.billingAddress.addressLine2}
bind:value={addressLine2}
id="address2"
label="Address line 2"
placeholder="Unit number, floor, etc." />
<InputText
bind:value={$changeOrganizationTier.billingAddress.city}
bind:value={city}
id="city"
label="City or suburb"
placeholder="Enter your city"
Expand All @@ -100,15 +124,15 @@
<InputText
isMultiple
fullWidth
bind:value={$changeOrganizationTier.billingAddress.state}
bind:value={state}
id="state"
label="State"
placeholder="Enter your state"
required />
<InputText
isMultiple
fullWidth
bind:value={$changeOrganizationTier.billingAddress.postalCode}
bind:value={postalCode}
id="zip"
label="Postal code"
placeholder="Enter postal code" />
Expand Down
Loading