diff --git a/src/lib/components/CookieConsent.svelte b/src/lib/components/CookieConsent.svelte index 09984b7..760cc72 100644 --- a/src/lib/components/CookieConsent.svelte +++ b/src/lib/components/CookieConsent.svelte @@ -21,7 +21,9 @@
We use cookies to ensure you get the best experience on our website. By continuing, you agree - to our use of cookies. + to our use of cookies. For details, please see our Privacy Policy.
{ return product as Product; }; +const getUserSubscriptions = async (userId: string) => { + try { + // Step 1: Retrieve subscription data + const { data: subscriptions, error } = await supabaseAdmin + .from('subscriptions') + .select('*') + .eq('user_id', userId); + + if (error) { + console.error('Error retrieving subscriptions:', error.message); + throw new Error('Failed to fetch subscriptions'); + } + + // Step 2: Map through each subscription and fetch product and price details + const subscriptionDetails = await Promise.all( + subscriptions.map(async (sub) => { + // Fetch product and price details from Stripe + const product = await stripeClient.products.retrieve(sub.product_id); + const price = await stripeClient.prices.retrieve(sub.price_id); + + const expiryDate = new Date(sub.current_period_end); + + // Format output data + return { + productName: product.name, + amount: (price.unit_amount / 100).toFixed(2), + currency: price.currency.toUpperCase(), + interval: price.recurring?.interval || 'one-time', + expiryDate: expiryDate.toLocaleDateString('en-GB', { + day: '2-digit', + month: '2-digit', + year: 'numeric' + }), + status: sub.status + }; + }) + ); + + return subscriptionDetails; + } catch (error) { + console.error('An error occurred while retrieving subscription details:', error); + throw new Error('Could not retrieve subscription details'); + } +}; + +const getUserTransactions = async (userId: string) => { + try { + // Step 1: Retrieve the customer ID associated with the user + const { data, error } = await supabaseAdmin + .from('customers') + .select('stripe_customer_id') + .eq('id', userId) + .single(); + + if (error) { + console.error('Error retrieving user data:', error.message); + throw new Error('Failed to fetch user data'); + } + + const customerId = data?.stripe_customer_id; + if (!customerId) { + throw new Error('No Stripe customer ID found for this user'); + } + + // Step 2: Fetch charge transactions from Stripe + const charges = await stripeClient.charges.list({ customer: customerId }); + + // Step 3: Format transaction data + const transactions = charges.data.map((charge) => ({ + amount: (charge.amount / 100).toFixed(2), + currency: charge.currency.toUpperCase(), + description: charge.description ?? 'No description provided', + status: charge.status, + created: new Date(charge.created * 1000).toLocaleDateString('en-GB', { + day: '2-digit', + month: '2-digit', + year: 'numeric' + }), + receipt_url: charge.receipt_url + })); + + return transactions; + } catch (error) { + console.error('An error occurred while retrieving transactions:', error); + throw new Error('Could not retrieve transactions'); + } +}; + export { upsertProductRecord, upsertPriceRecord, @@ -496,5 +584,7 @@ export { getActiveProductsWithPrices, getProductById, upsertCustomerToSupabase, - getStripeCustomerId + getStripeCustomerId, + getUserSubscriptions, + getUserTransactions }; diff --git a/src/routes/(policies)/cookies/+page.svelte b/src/routes/(policies)/cookies/+page.svelte new file mode 100644 index 0000000..511b4e0 --- /dev/null +++ b/src/routes/(policies)/cookies/+page.svelte @@ -0,0 +1,85 @@ +Effective Date: [Insert Date]
+ ++ This Cookie Policy explains how [Your Company/Website Name] ("we", "us", or "our") uses + cookies and similar technologies to collect and store information when you visit our website. +
++ Cookies are small text files stored on your device (computer, tablet, smartphone) by your web + browser when you visit a website. They help us remember your preferences and improve your + experience on our website. +
++ We use cookies to improve the functionality and performance of our website, analyse visitor + usage, and provide personalised content and advertisements. This helps us improve our website + and better understand our audience. +
++ You have the right to accept or reject cookies. You can manage your cookie preferences by + adjusting your browser settings. However, disabling certain cookies may affect your experience + on our website. For specific instructions on managing cookies, please consult your browser's + help documentation. +
++ We may update this Cookie Policy from time to time. Significant changes will be posted on this + page. We encourage you to review this policy periodically to stay informed about our use of + cookies. +
++ For questions about our Cookie Policy, please contact us at [Your Contact Email] + or visit our Contact Page. +
+Effective Date: [Insert Date]
+ ++ This Privacy Policy explains how we at [Your Company/Website Name] collect, use, and protect + your personal information when you visit our website. We are committed to safeguarding your + data and complying with relevant data protection laws, including the General Data Protection + Regulation (GDPR). +
++ We collect personal and non-personal information to provide our services and enhance your + experience. +
++ We work with trusted third-party providers to offer secure services, such as payment + processing and authentication. +
++ For payment processing, we use Stripe. Please refer to their + Privacy Policy for details. +
++ For database and authentication, we use Supabase. See their + Privacy Policy for more information. +
++ We use cookies to provide essential site functionality, analytics, and improved user + experience. By continuing to use our site, you consent to our use of cookies. You can manage + your cookie preferences in your browser settings. For more details, please refer to our Cookie Policy. +
++ Under GDPR, you have the right to access, correct, delete, and restrict the processing of your + personal data. To make a request, please contact us at [Your Contact Email]. +
++ We take reasonable steps to protect your information through encryption and secure access + protocols. However, no online service can be 100% secure. +
++ We may update this policy periodically. Significant changes will be posted on this page, so + please review it regularly. +
++ If you have questions about this Privacy Policy, please contact us at [Your Contact Email] + or visit our Contact Page. +
+Copyright © 2024 - All right reserved
+Copyright © 2024 - All rights reserved
+