chore: Remove stripe-related functionality

This commit is contained in:
Faruk AYDIN
2023-03-21 11:49:44 +03:00
parent dec55709a3
commit d3ef45db1b
10 changed files with 0 additions and 225 deletions

View File

@@ -1,42 +0,0 @@
import Stripe from 'stripe';
import PaymentPlan from '../../models/payment-plan.ee';
import Billing from './index.ee';
const handleWebhooks = async (event: Stripe.Event) => {
const trackedWebhookTypes = [
'customer.subscription.created',
'customer.subscription.updated',
'customer.subscription.deleted',
];
if (!trackedWebhookTypes.includes(event.type)) {
return;
}
await updatePaymentPlan(event);
};
const updatePaymentPlan = async (event: Stripe.Event) => {
const subscription = event.data.object as Stripe.Subscription;
const priceKey = subscription.items.data[0].plan.id;
const plan = Billing.plans.find((plan) => plan.price === priceKey);
const paymentPlan = await PaymentPlan.query().findOne({
stripe_customer_id: subscription.customer,
});
await paymentPlan.$query().patchAndFetch({
name: plan.name,
taskCount: plan.taskCount,
stripeSubscriptionId: subscription.id,
});
const user = await paymentPlan.$relatedQuery('user');
const usageData = await user.$relatedQuery('usageData');
await usageData.$query().patchAndFetch({
nextResetAt: new Date(subscription.current_period_end * 1000).toISOString(),
});
};
export default handleWebhooks;