mirror of
https://github.com/mendableai/firecrawl.git
synced 2024-11-16 11:42:24 +08:00
Merge f6e6f2ef9f
into 3a342bfbf0
This commit is contained in:
commit
d9c4bb5aaf
|
@ -13,6 +13,25 @@ import { getValue, setValue } from "../redis";
|
|||
|
||||
const FREE_CREDITS = 500;
|
||||
|
||||
// Initialize Stripe with your API key
|
||||
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
|
||||
|
||||
|
||||
async function trackUsage(customer_id: string, quantity: number): Promise<void> {
|
||||
try {
|
||||
await stripe.billing.meterEvents.create({
|
||||
event_name: 'credits',
|
||||
payload: {
|
||||
value: quantity.toString(),
|
||||
stripe_customer_id: customer_id,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error creating usage record:', error);
|
||||
// throw new Error('Error creating usage record');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If you do not know the subscription_id in the current context, pass subscription_id as undefined.
|
||||
*/
|
||||
|
@ -32,6 +51,9 @@ export async function supaBillTeam(team_id: string, subscription_id: string | nu
|
|||
credits,
|
||||
});
|
||||
|
||||
// TODO: figure out a way to get the customer_id from bill_team if usage based tracking
|
||||
// await trackUsage(team_id, credits);
|
||||
|
||||
if (error) {
|
||||
Sentry.captureException(error);
|
||||
logger.error("Failed to bill team: " + JSON.stringify(error));
|
||||
|
|
Loading…
Reference in New Issue
Block a user