-
-
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
1 parent
1639075
commit 2c2cc33
Showing
4 changed files
with
65 additions
and
5 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 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,58 @@ | ||
import express from 'express'; | ||
import { bot } from '../../main.js'; | ||
import { Constants } from '../../constants.js'; | ||
import { EmbedBuilder, TextChannel } from 'discord.js'; | ||
|
||
const app = express.Router(); | ||
|
||
type StripeBase = { | ||
id: string; | ||
object: string; | ||
}; | ||
|
||
type StripePaymentIntent = StripeBase & { | ||
amount: number; | ||
currency: number; | ||
created: number; | ||
description: string; | ||
}; | ||
|
||
const isStripePaymentIntent = (payload: StripeBase): payload is StripeBase => { | ||
if ((payload as StripeBase).object === 'payment_intent') { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
const isImmichPaymentIntent = (payload: StripePaymentIntent): payload is StripePaymentIntent => { | ||
return ['immich-server', 'immich-client'].includes((payload as StripePaymentIntent).description); | ||
}; | ||
|
||
app.post('/stripe-payments/:slug', async (req, res) => { | ||
if (req.params.slug !== process.env.STRIPE_PAYMENT_SLUG) { | ||
res.status(401).send(); | ||
return; | ||
} | ||
|
||
res.status(204).send(); | ||
|
||
const body = req.body; | ||
console.log(JSON.stringify(body)); | ||
|
||
if (!isStripePaymentIntent(body)) return; | ||
|
||
const paymentIntent = body as StripePaymentIntent; | ||
if (!isImmichPaymentIntent(paymentIntent)) return; | ||
|
||
const licenseType = paymentIntent.description.split('-')[1]; | ||
const channel = (await bot.channels.fetch(Constants.Channels.Stripe)) as TextChannel; | ||
const embed = new EmbedBuilder({ | ||
title: `Immich ${licenseType} license purchased`, | ||
author: { name: 'Stripe Payments', url: 'https://stripe.com' }, | ||
url: `https://dashboard.stripe.com/payments/${paymentIntent.id}`, | ||
description: `Total: ${paymentIntent.amount} ${paymentIntent.currency}`, | ||
}); | ||
await channel.send({ embeds: [embed] }); | ||
}); | ||
|
||
export const stripeWebhooks = app; |
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