f1d1674693
* feat: allow organization owners access to shared billing portal - Modify stripepayment portal endpoint to accept teamId parameter - Use team's subscription ID to get customer ID from Stripe subscription - Validate user permissions before allowing team billing access - Update platform and regular billing views to pass teamId - Maintain backward compatibility with individual user billing Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * Add `getTeamByIdIfUserIsAdmin` to `TeamRepository` * Add `getSubscriptionFromId` function * Generate portal URL via the team's subscription not the requesting user's customerId * Pass teamId to `/portal` endpoint * Undo Devin change to platform billing * Address coderabbit comments --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
34 lines
796 B
TypeScript
34 lines
796 B
TypeScript
import stripe from "./server";
|
|
|
|
interface IRetrieveSubscriptionIdResponse {
|
|
message?: string;
|
|
subscriptionId?: string;
|
|
}
|
|
|
|
export async function retrieveSubscriptionIdFromStripeCustomerId(
|
|
stripeCustomerId: string
|
|
): Promise<IRetrieveSubscriptionIdResponse> {
|
|
const customer = await stripe.customers.retrieve(stripeCustomerId, {
|
|
expand: ["subscriptions.data.plan"],
|
|
});
|
|
if (!customer || customer.deleted) {
|
|
return {
|
|
message: "Not found",
|
|
};
|
|
}
|
|
|
|
const subscription = customer.subscriptions?.data[0];
|
|
if (!subscription) {
|
|
return {
|
|
message: "Not found",
|
|
};
|
|
}
|
|
return {
|
|
subscriptionId: subscription.id,
|
|
};
|
|
}
|
|
|
|
export async function getSubscriptionFromId(subscriptionId: string) {
|
|
return await stripe.subscriptions.retrieve(subscriptionId);
|
|
}
|