mirror of
https://github.com/mendableai/firecrawl.git
synced 2024-11-16 11:42:24 +08:00
parent
6fc1ee32fd
commit
b014d99db4
|
@ -93,7 +93,7 @@
|
|||
"resend": "^3.2.0",
|
||||
"robots-parser": "^3.0.1",
|
||||
"scrapingbee": "^1.7.4",
|
||||
"stripe": "^12.2.0",
|
||||
"stripe": "^15.11.0",
|
||||
"turndown": "^7.1.3",
|
||||
"turndown-plugin-gfm": "^1.0.2",
|
||||
"typesense": "^1.5.4",
|
||||
|
|
|
@ -156,8 +156,8 @@ dependencies:
|
|||
specifier: ^1.7.4
|
||||
version: 1.7.4
|
||||
stripe:
|
||||
specifier: ^12.2.0
|
||||
version: 12.18.0
|
||||
specifier: ^15.11.0
|
||||
version: 15.11.0
|
||||
turndown:
|
||||
specifier: ^7.1.3
|
||||
version: 7.2.0
|
||||
|
@ -7483,8 +7483,8 @@ packages:
|
|||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/stripe@12.18.0:
|
||||
resolution: {integrity: sha512-cYjgBM2SY/dTm8Lr6eMyyONaHTZHA/QjHxFUIW5WH8FevSRIGAVtXEmBkUXF1fsqe7QvvRgQSGSJZmjDacegGg==}
|
||||
/stripe@15.11.0:
|
||||
resolution: {integrity: sha512-qmZF0PN1jRVpiQrXL8eTb9Jy/6S+aUlcDquKBFT2h3PkaD7RZ444FIojVXUg67FK2zFIUNXgMv02c7csdL5qHg==}
|
||||
engines: {node: '>=12.*'}
|
||||
dependencies:
|
||||
'@types/node': 20.14.1
|
||||
|
|
|
@ -8,6 +8,26 @@ const FREE_CREDITS = 500;
|
|||
export async function billTeam(team_id: string, credits: number) {
|
||||
return withAuth(supaBillTeam)(team_id, credits);
|
||||
}
|
||||
// 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');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function supaBillTeam(team_id: string, credits: number) {
|
||||
if (team_id === "preview") {
|
||||
return { success: true, message: "Preview team, no credits used" };
|
||||
|
@ -153,6 +173,19 @@ export async function supaBillTeam(team_id: string, credits: number) {
|
|||
return await createCreditUsage({ team_id, credits });
|
||||
}
|
||||
|
||||
if(subscription.is_usage){
|
||||
// console.log('subscription', subscription);
|
||||
const { data: customer } = await supabase_service
|
||||
.from("customers")
|
||||
.select("*")
|
||||
.eq("id", subscription.user_id)
|
||||
.single();
|
||||
|
||||
if (customer) {
|
||||
await trackUsage(customer.stripe_customer_id, credits);
|
||||
}
|
||||
}
|
||||
|
||||
return await createCreditUsage({
|
||||
team_id,
|
||||
subscription_id: subscription.id,
|
||||
|
|
Loading…
Reference in New Issue
Block a user