-
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.
slider dynmaic generation added (#16)
* 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
1 parent
06bf381
commit 90802a1
Showing
9 changed files
with
286 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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> |
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,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} /> |
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,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); | ||
} |