* Removes user plan logic for stripe sub * Update hardcoded price * Removed checkoutSessionId metadata and fix for trpc query * Remove or comment team billing unused code * Add todo note * Fix type checks * Change function that was renamed * Remove duplicated test * remove plan when creating user on test Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com>
30 lines
661 B
TypeScript
30 lines
661 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,
|
|
};
|
|
}
|