cal/packages/app-store/stripepayment/lib/subscriptions.ts
alannnc 6e351a4b20
fix/premium-username-flow (#5815)
* 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>
2022-12-07 12:55:47 -07:00

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,
};
}