Skip to content

Commit

Permalink
slider dynmaic generation added (#16)
Browse files Browse the repository at this point in the history
* landing page done

some assets added

some design fix added

Signed-off-by: RajrupDasid <[email protected]>

* contact form is working
some enhacement added

Signed-off-by: RajrupDasid <[email protected]>

* made contactform dynamic

Signed-off-by: RajrupDasid <[email protected]>

* Signup authentication validation added

Signed-off-by: RajrupDasid <[email protected]>

* User authentication hasbeen implemented

user authentication hasbeen applied

some logic hasbeen rectified

Signed-off-by: RajrupDasid <[email protected]>

* Some modifications hasbeen applied

Signed-off-by: RajrupDasid <[email protected]>

* user authentication implemnted and verification added

Signed-off-by: RajrupDasid <[email protected]>

* Group based layout added

default layout changed

some auth logic improvement added

admin navbar added

Signed-off-by: RajrupDasid <[email protected]>

* Added null safety

auth improvement added

some logic changes added

some improvements added

Signed-off-by: RajrupDasid <[email protected]>

* Adapter hasbeen chnged

some other modifications added

Signed-off-by: RajrupDasid <[email protected]>

* addition

Signed-off-by: RajrupDasid <[email protected]>

* Some modifications added

Signed-off-by: RajrupDasid <[email protected]>

* some mitigation added

Signed-off-by: RajrupDasid <[email protected]>

* some adjustment added

Signed-off-by: RajrupDasid <[email protected]>

* more adjustment added

Signed-off-by: RajrupDasid <[email protected]>

* some changes added

Signed-off-by: RajrupDasid <[email protected]>

* adapter modified

Signed-off-by: RajrupDasid <[email protected]>

* worked edited

Signed-off-by: RajrupDasid <[email protected]>

* SEO added

some general improvements added

Signed-off-by: RajrupDasid <[email protected]>

* Static image fetched via cdn

Signed-off-by: RajrupDasid <[email protected]>

* SEO added

sitemap generator added

Signed-off-by: RajrupDasid <[email protected]>

* Added firebase sdk

some modifications added

client side multiple file upload added

Signed-off-by: RajrupDasid <[email protected]>

* batch processing is working

tested with firebase storage

two files hasbeen added simultaniously

Signed-off-by: RajrupDasid <[email protected]>

* added terms and conditions

added privacy policy page

Signed-off-by: RajrupDasid <[email protected]>

* Improved File uploding logic

added proper batch processing and file upload methods

both frontend and backend logics hasbeen refactored

Signed-off-by: RajrupDasid <[email protected]>

* Return and refund policy page added

Signed-off-by: RajrupDasid <[email protected]>

* AboutUs page hasbeen updated

more fixes applied

general changes will be introduce soon

Signed-off-by: RajrupDasid <[email protected]>

* Checkout page implemented

homepage sliders hasbeen made dynamic now

some bug fixes and optimization added

Signed-off-by: RajrupDasid <[email protected]>

---------

Signed-off-by: RajrupDasid <[email protected]>
  • Loading branch information
rajrupdasofficial authored Jul 12, 2024
1 parent 06bf381 commit 90802a1
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 17 deletions.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
},
"type": "module",
"dependencies": {
"@paypal/paypal-js": "^8.1.0",
"appwrite": "^15.0.0",
"argon2": "^0.40.3",
"bits-ui": "^0.21.10",
Expand Down
8 changes: 8 additions & 0 deletions src/lib/components/ui/navbar/navbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@
Contact
</a>
</li>
<li>
<a
class="block py-2 px-4 text-gray-500 transition hover:text-gray-500/75 dark:text-white dark:hover:text-white/75"
href="/checkout"
>
Checkout
</a>
</li>
</ul>
</nav>

Expand Down
49 changes: 49 additions & 0 deletions src/lib/components/ui/paypalstarter/PayPal.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<script lang="ts">
import { onMount } from 'svelte';
import { loadScript } from "@paypal/paypal-js";
import type { PayPalNamespace, OnApproveData, OnApproveActions, CreateOrderActions } from "@paypal/paypal-js";
export let amount = '0.00';
export let currency = 'USD';
export let onApprove: (details: Record<string, unknown>) => void = () => {};
let paypal: PayPalNamespace | null = null;
onMount(async () => {
paypal = await loadScript({
clientId: import.meta.env.VITE_PAYPAL_CLIENT_ID
});
if (paypal && paypal.Buttons) {
paypal.Buttons({
createOrder: (_data: Record<string, unknown>, actions: CreateOrderActions) => {
return actions.order.create({
intent: "CAPTURE",
purchase_units: [{
amount: {
value: amount,
currency_code: currency
}
}]
});
},
onApprove: (_data: OnApproveData, actions: OnApproveActions) => {
if (actions.order) {
return actions.order.capture().then(function(details: Record<string, unknown>) {
onApprove(details);
});
}
return Promise.reject('Order actions not available');
},
onError: (err: Record<string, unknown>) => {
console.error('PayPal error:', err);
// Handle the error (e.g., show an error message to the user)
}
}).render('#paypal-button-container');
} else {
console.error('PayPal SDK failed to load');
}
});
</script>

<div id="paypal-button-container"></div>
38 changes: 23 additions & 15 deletions src/lib/components/ui/website/+webstitecarousel.svelte
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
<script lang="ts">
import Autoplay from "embla-carousel-autoplay";;
import Autoplay from "embla-carousel-autoplay";
import * as Card from "$lib/components/ui/card/index.js";
import * as Carousel from "$lib/components/ui/carousel/index.js";
import { onMount } from 'svelte';
let allsliders: any[] = [];
onMount(async () => {
const res = await fetch('/api/admin/details/slider_handel/');
const result = res.headers.get('all-sliders') ?? '[]';
allsliders = JSON.parse(result);
console.log('Parsed sliders:', allsliders);
});
</script>

<Carousel.Root class="lg:w-[1700px] sm:w-[600px] md:[800px]" plugins={[
Autoplay({
delay: 4700,
}),
]}>
<Carousel.Root class="lg:w-[1700px] sm:w-[600px] md:w-[800px]"
plugins={[
Autoplay({
delay: 4700,
}),
]}>
<Carousel.Content>
{#each Array(5) as _, i (i)}
{#each allsliders as slider}
<Carousel.Item>
<div class="p-1">
<Card.Root class="w-full h-full">
<Card.Content class="flex flex-col h-full justify-center items-center p-6">
<img src={`https://robohash.org/${5}?size=300x300`} alt="cutest kitten" />
<!-- <span class="text-3xl font-bold text-white">Title</span> -->
</Card.Content>
</Card.Root>
</div>
<Card.Root class="w-full h-full">
<Card.Content class="flex flex-col h-full justify-center items-center p-6">
<img src={slider.imageUrl} alt="finnestsliderimages" class="lg:h-[300px] md:h-[200px] sm:h-[100px]"/>
</Card.Content>
</Card.Root>
</Carousel.Item>
{/each}
</Carousel.Content>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/firebase/firebaseconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const firebaseConfig = {
};

// Initialize Firebase
export const firebase_cofig = initializeApp(firebaseConfig);
export const firebase_config = initializeApp(firebaseConfig);

// Initialize Analytics

Expand Down
52 changes: 52 additions & 0 deletions src/routes/(app)/checkout/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<script lang="ts">
import PayPal from '$lib/components/ui/paypalstarter/PayPal.svelte';
import { goto } from '$app/navigation';
let amount = '';
async function handleApprove(details: Record<string, unknown>) {
console.log('Payment approved:', details);
try {
// Send payment details to your server
const response = await fetch('/api/payment', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
paymentDetails: {
orderID: details.orderID,
payerID: details.payerID,
paymentID: details.paymentID,
billingToken: details.billingToken,
facilitatorAccessToken: details.facilitatorAccessToken,
// Include any other relevant details from the PayPal response
amount: amount,
currency: 'USD', // or whatever currency you're using
}
}),
});
if (!response.ok) {
throw new Error('Server response was not ok');
}
const result = await response.json();
if (result.success) {
goto('/thank-you');
} else {
throw new Error(result.message || 'Payment processing failed');
}
} catch (error) {
console.error('Payment processing error:', error);
// Handle the error (e.g., show an error message to the user)
alert('There was an error processing your payment. Please try again.');
}
}
</script>

<h1>Checkout</h1>
<input type="number" bind:value={amount} placeholder="Enter amount" />
<PayPal amount={amount} onApprove={handleApprove} />
43 changes: 42 additions & 1 deletion src/routes/api/admin/details/slider_handel/+server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { RequestHandler } from './$types';
import { json } from '@sveltejs/kit';
import { Client, Databases } from 'appwrite';
import { env } from '$env/dynamic/private';
import { uploadImageToFirebase } from '@/firebase/firebasefileupload';
import { getStorage, ref, getDownloadURL } from 'firebase/storage';
import { firebase_config } from '@/firebase/firebaseconfig';

const appwriteendpoint = env.APPWRITE_IO;
const appwriteprojectid = env.APPWRITE_PROJECT_ID;
Expand Down Expand Up @@ -49,3 +50,43 @@ export const POST: RequestHandler = async ({ request }) => {
});
}
};

export const GET: RequestHandler = async () => {
const storage = getStorage(firebase_config);

const fetchImageUrl = async (filename) => {
try {
const downloadURL = await getDownloadURL(ref(storage, filename));
return downloadURL;
} catch (error) {
console.error(`Error fetching URL for ${filename}:`, error);
return null;
}
};

try {
const databases = new Databases(client);
const results = await databases.listDocuments(`${appwritedbid}`, `${slidercolid}`);

const imagesWithUrls = await Promise.all(
results.documents.map(async (doc) => {
const imageUrl = await fetchImageUrl(doc.filedata);
return {
imageUrl
};
})
);
return new Response(null, {
status: 200,
headers: {
'all-sliders': JSON.stringify(imagesWithUrls)
}
});
} catch (error) {
console.error('Error:', error);
return new Response(null, {
status: 500,
statusText: 'Error occurred at server side'
});
}
};
94 changes: 94 additions & 0 deletions src/routes/api/checkout/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { json, type RequestHandler } from '@sveltejs/kit';
import { env } from '$env/dynamic/private';

// You should store these in environment variables
const PAYPAL_CLIENT_ID = env.VITE_PAYPAL_CLIENT_ID;
const PAYPAL_CLIENT_SECRET = env.VITE_PAYPAL_CLIENT_SECRET;
const PAYPAL_API_BASE = 'https://api-m.sandbox.paypal.com'; // Use 'https://api-m.paypal.com' for production

interface PaymentDetails {
currency: string;
amount: string;
orderID: string;
payerID: string;
paymentID: string;
billingToken?: string;
facilitatorAccessToken: string;
}

export const POST: RequestHandler = async ({ request }) => {
const { paymentDetails }: { paymentDetails: PaymentDetails } = await request.json();

try {
const verified = await verifyPaymentWithPayPal(paymentDetails);
if (verified) {
await updateDatabase(paymentDetails);
return json({ success: true, message: 'Payment processed successfully' });
} else {
return json({ success: false, message: 'Payment verification failed' }, { status: 400 });
}
} catch (error) {
console.error('Error processing payment:', error);
return json(
{ success: false, message: 'An error occurred while processing the payment' },
{ status: 500 }
);
}
};

async function getAccessToken(): Promise<string> {
const response = await fetch(`${PAYPAL_API_BASE}/v1/oauth2/token`, {
method: 'POST',
body: 'grant_type=client_credentials',
headers: {
Authorization: `Basic ${Buffer.from(`${PAYPAL_CLIENT_ID}:${PAYPAL_CLIENT_SECRET}`).toString('base64')}`
}
});

const data = await response.json();
return data.access_token;
}

async function verifyPaymentWithPayPal(paymentDetails: PaymentDetails): Promise<boolean> {
const accessToken = await getAccessToken();

const response = await fetch(`${PAYPAL_API_BASE}/v2/checkout/orders/${paymentDetails.orderID}`, {
headers: {
Authorization: `Bearer ${accessToken}`
}
});

const order = await response.json();

// Verify the important details of the order
if (
order.status === 'COMPLETED' &&
order.purchase_units[0].amount.value === paymentDetails.amount &&
order.purchase_units[0].amount.currency_code === paymentDetails.currency
) {
return true;
}

return false;
}

async function updateDatabase(paymentDetails: PaymentDetails): Promise<void> {
// This is where you would implement your database update logic
// For example, using Prisma ORM:

// import { PrismaClient } from '@prisma/client'
// const prisma = new PrismaClient()

// await prisma.payment.create({
// data: {
// orderId: paymentDetails.orderID,
// payerId: paymentDetails.payerID,
// paymentId: paymentDetails.paymentID,
// amount: paymentDetails.amount,
// currency: paymentDetails.currency,
// status: 'completed',
// },
// });

console.log('Updating database with payment details:', paymentDetails);
}

0 comments on commit 90802a1

Please sign in to comment.