Switch billing provider from Stripe to Lemon Squeezy

Changed the billing provider in the `.env.development` file from Stripe to Lemon Squeezy. This requires adaptations at many levels: at the web app to load Lemon Squeezy's script in the checkout process, at the billing gateway to handle Lemon Squeezy calls, and in the database to reflect the current billing provider. The checkout process is now done using Lemon Squeezy Sessions and its billing strategy was adjusted accordingly. Billing-related components and services were also updated.
This commit is contained in:
giancarlo
2024-04-02 14:09:25 +08:00
parent d92d224250
commit 4576c8c14a
11 changed files with 106 additions and 92 deletions

View File

@@ -1,3 +1,7 @@
'use client';
import { useEffect } from 'react';
interface LemonSqueezyWindow extends Window {
createLemonSqueezy: () => void;
LemonSqueezy: {
@@ -14,16 +18,24 @@ interface LemonSqueezyWindow extends Window {
}
export function LemonSqueezyEmbeddedCheckout(props: { checkoutToken: string }) {
return (
<script
src="https://app.lemonsqueezy.com/js/lemon.js"
defer
onLoad={() => {
const win = window as unknown as LemonSqueezyWindow;
useLoadScript(props.checkoutToken);
win.createLemonSqueezy();
win.LemonSqueezy.Url.Open(props.checkoutToken);
}}
></script>
);
return null;
}
function useLoadScript(checkoutToken: string) {
useEffect(() => {
const script = document.createElement('script');
script.src = 'https://app.lemonsqueezy.com/js/lemon.js';
script.onload = () => {
const win = window as unknown as LemonSqueezyWindow;
win.createLemonSqueezy();
win.LemonSqueezy.Url.Open(checkoutToken);
};
document.body.appendChild(script);
}, [checkoutToken]);
}