-
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.
refactor: send sticker png to printify
- Loading branch information
1 parent
6549e7d
commit 2b4ee1f
Showing
13 changed files
with
98 additions
and
71 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 was deleted.
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,24 @@ | ||
'use client'; | ||
|
||
import { useEffect } from 'react'; | ||
|
||
export default function Error({ error, reset }: { error: Error & { digest?: string }; reset: () => void }) { | ||
useEffect(() => { | ||
// Log the error to an error reporting service | ||
console.error(error); | ||
}, [error]); | ||
|
||
return ( | ||
<div> | ||
<h2>Something went wrong!</h2> | ||
<button | ||
onClick={ | ||
// Attempt to recover by trying to re-render the segment | ||
() => reset() | ||
} | ||
> | ||
Try again | ||
</button> | ||
</div> | ||
); | ||
} |
File renamed without changes.
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,46 @@ | ||
'use client'; | ||
|
||
import { useRouter } from 'next/navigation'; | ||
import { useRef, useState } from 'react'; | ||
import { CartEntry } from 'use-shopping-cart/core'; | ||
|
||
const CheckoutButton: React.FC<{ cartCount?: number; cartItems: CartEntry[] }> = ({ cartCount, cartItems }) => { | ||
const router = useRouter(); | ||
const isProcessing = useRef(false); | ||
const [error, setError] = useState(''); | ||
|
||
const handleCheckoutClick = async () => { | ||
if (!cartCount || cartCount === 0 || isProcessing.current) { | ||
return; | ||
} | ||
|
||
isProcessing.current = true; | ||
|
||
try { | ||
const res = await fetch('/api/v1/checkout', { | ||
method: 'POST', | ||
body: JSON.stringify({ cartItems }), | ||
}); | ||
|
||
const { checkoutUrl } = await res.json(); | ||
if (!checkoutUrl) { | ||
setError('Unable to checkout at this time. Please try again later.'); | ||
return; | ||
} | ||
router.push(checkoutUrl); | ||
} catch (err) { | ||
console.error('Checkout request threw an error', err, error); | ||
setError('An error occurred during checkout. Please try again later.'); | ||
} finally { | ||
isProcessing.current = false; | ||
} | ||
}; | ||
|
||
return ( | ||
<button disabled={cartCount === 0 || isProcessing.current} className="bg-green-500 text-white px-4 py-2 rounded-md focus:outline-none" onClick={handleCheckoutClick}> | ||
Checkout | ||
</button> | ||
); | ||
}; | ||
|
||
export default CheckoutButton; |
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 |
---|---|---|
|
@@ -60,7 +60,6 @@ export async function createCheckoutSession( | |
mode: 'payment', | ||
success_url: `${process.env.NEXT_PUBLIC_URL}/order-confirmation?session_id={CHECKOUT_SESSION_ID}`, | ||
cancel_url: `${process.env.NEXT_PUBLIC_URL}/cart`, | ||
// TODO_AUTH_ORDERS | ||
// customer: 'customerId', | ||
// customer_email: '[email protected]', | ||
shipping_address_collection: { | ||
|
@@ -115,7 +114,6 @@ export async function createCheckoutSession( | |
}); | ||
} | ||
|
||
// TODO_AUTH_ORDERS | ||
export async function retrieveCheckoutSession(sessionId: string) { | ||
return await stripe.checkout.sessions.retrieve(sessionId, { | ||
expand: ['line_items'], | ||
|
@@ -130,8 +128,6 @@ export async function validateStripeSession(sessionId?: string) { | |
|
||
if (session.object !== 'checkout.session') return { validSession: false }; | ||
|
||
// TODO_AUTH_ORDERS - only this users' orders | ||
|
||
return { validSession: true }; | ||
} catch (error) { | ||
return { validSession: false }; | ||
|