-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
270 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use server'; | ||
|
||
import getCurrentUser from '@/_queries/get-current-user'; | ||
|
||
import { | ||
createCheckout, | ||
lemonSqueezySetup, | ||
} from '@lemonsqueezy/lemonsqueezy.js'; | ||
|
||
const createCustomerCheckout = async () => { | ||
const user = await getCurrentUser(); | ||
if (!user) return { url: null }; | ||
lemonSqueezySetup({ apiKey: process.env.LEMON_SQUEEZY_API_KEY! }); | ||
|
||
const res = await createCheckout( | ||
process.env.LEMON_SQUEEZY_STORE_ID!, | ||
process.env.LEMON_SQUEEZY_VARIANT_ID!, | ||
{ | ||
checkoutData: { | ||
custom: { user_id: user.id }, | ||
email: user.email, | ||
name: `${user.user_metadata.first_name} ${user.user_metadata.last_name}`, | ||
}, | ||
}, | ||
); | ||
|
||
return { url: res.data?.data.attributes.url ?? null }; | ||
}; | ||
|
||
export default createCustomerCheckout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use server'; | ||
|
||
import getCustomer from '@/_queries/get-customer'; | ||
|
||
import { | ||
getCustomer as lemonSqueezyGetCustomer, | ||
lemonSqueezySetup, | ||
} from '@lemonsqueezy/lemonsqueezy.js'; | ||
|
||
const getCustomerBillingPortal = async () => { | ||
const { data: customer } = await getCustomer(); | ||
if (!customer) return { url: null }; | ||
lemonSqueezySetup({ apiKey: process.env.LEMON_SQUEEZY_API_KEY! }); | ||
const res = await lemonSqueezyGetCustomer(customer.customer_id); | ||
return { url: res.data?.data.attributes.urls.customer_portal ?? null }; | ||
}; | ||
|
||
export default getCustomerBillingPortal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import createServerSupabaseClient from '@/_utilities/create-server-supabase-client'; | ||
|
||
const getCustomer = () => | ||
createServerSupabaseClient() | ||
.from('customers') | ||
.select('customer_id, subscription_status') | ||
.single(); | ||
|
||
export type GetCustomerData = Awaited<ReturnType<typeof getCustomer>>['data']; | ||
|
||
export default getCustomer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.