-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
608 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { NextRequest } from 'next/server' | ||
import { z } from 'zod' | ||
|
||
import { APIResponse } from '@/lib/api' | ||
import { capturePayPalPayment } from '@/lib/paypal' | ||
import { notifyOfPayPalPurchase } from '@/lib/slack' | ||
|
||
const CapturePaymentSchema = z.object({ | ||
orderId: z.string(), | ||
}) | ||
|
||
export const POST = async (req: NextRequest, { params }: { params: { orderId: string } }) => { | ||
try { | ||
const safeParams = CapturePaymentSchema.parse(params) | ||
|
||
const order = await capturePayPalPayment(safeParams.orderId) | ||
|
||
console.log('Captured PayPal Payment', order) | ||
|
||
// send email to customer | ||
|
||
// send slack message to admin | ||
try { | ||
await notifyOfPayPalPurchase( | ||
order.payer.email_address, | ||
order.purchase_units[0].payments.captures[0].seller_receivable_breakdown.net_amount.value, | ||
) | ||
} catch (e) {} | ||
|
||
return APIResponse.success(order, 201) | ||
} catch (error: any) { | ||
console.error('[API] Error capturing PayPal payment', error) | ||
|
||
if (error instanceof z.ZodError) { | ||
return APIResponse.error('Invalid data', 422, error.errors) | ||
} | ||
|
||
return APIResponse.error(error.message) | ||
} | ||
} |
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,31 @@ | ||
import { NextRequest } from 'next/server' | ||
import { z } from 'zod' | ||
|
||
import { ProductPrices, ProductSKU } from '@/config/products' | ||
import { APIResponse } from '@/lib/api' | ||
import { createPayPalOrder } from '@/lib/paypal' | ||
|
||
const CreateOrderSchema = z.object({ | ||
sku: z.nativeEnum(ProductSKU), | ||
}) | ||
|
||
export const POST = async (req: NextRequest) => { | ||
try { | ||
const json = await req.json() | ||
const body = CreateOrderSchema.parse(json) | ||
|
||
const order = await createPayPalOrder(ProductPrices[body.sku]) | ||
|
||
console.log('Created PayPal order', order) | ||
|
||
return APIResponse.success(order, 201) | ||
} catch (error: any) { | ||
console.error('[API] Error creating PayPal order', error) | ||
|
||
if (error instanceof z.ZodError) { | ||
return APIResponse.error('Invalid data', 422, error.errors) | ||
} | ||
|
||
return APIResponse.error(error.message) | ||
} | ||
} |
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,47 @@ | ||
import { z } from 'zod' | ||
|
||
import { APIResponse } from '@/lib/api' | ||
import { getNowPlaying } from '@/lib/spotify' | ||
|
||
export const runtime = 'edge' | ||
export const dynamic = 'force-dynamic' | ||
|
||
export const GET = async () => { | ||
try { | ||
const response = await getNowPlaying() | ||
|
||
if (response.status === 204 || response.status > 400 || response?.data?.item === null || !response.data) { | ||
return APIResponse.success({ isPlaying: false }) | ||
} | ||
|
||
const song = response.data | ||
|
||
if (song.is_playing === false) { | ||
return APIResponse.success({ isPlaying: false }) | ||
} | ||
|
||
const isPlaying = song.is_playing | ||
const name = song.item.name | ||
const artist = song.item.artists.map((_artist) => _artist.name).join(', ') | ||
const album = song.item.album.name | ||
const albumImage = song.item.album.images[0].url | ||
const songUrl = song.item.external_urls.spotify | ||
|
||
return APIResponse.success({ | ||
isPlaying, | ||
name, | ||
artist, | ||
album, | ||
albumImage, | ||
songUrl, | ||
}) | ||
} catch (error: any) { | ||
console.error('[API] Error creating PayPal order', error) | ||
|
||
if (error instanceof z.ZodError) { | ||
return APIResponse.error('Invalid data', 422, error.errors) | ||
} | ||
|
||
return APIResponse.error(error.message) | ||
} | ||
} |
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,31 @@ | ||
'use client' | ||
|
||
import Script from 'next/script' | ||
|
||
import { env } from '@/env.mjs' | ||
|
||
export function GTM() { | ||
return ( | ||
<> | ||
<noscript> | ||
<iframe | ||
title='google-tag-manager' | ||
src={`https://www.googletagmanager.com/ns.html?id=${env.NEXT_PUBLIC_GTM_MEASUREMENT_ID}`} | ||
height='0' | ||
width='0' | ||
style={{ display: 'none', visibility: 'hidden' }} | ||
/> | ||
</noscript> | ||
|
||
<Script id='google-tag-manager' strategy='afterInteractive'> | ||
{` | ||
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': | ||
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], | ||
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= | ||
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); | ||
})(window,document,'script','dataLayer','${env.NEXT_PUBLIC_GTM_MEASUREMENT_ID}'); | ||
`} | ||
</Script> | ||
</> | ||
) | ||
} |
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
Oops, something went wrong.