MCPcopy Create free account
hub / github.com/async-labs/async / getListOfInvoicesForAccount

Method getListOfInvoicesForAccount

api/server/models/User.ts:1069–1102  ·  view source on GitHub ↗
({ userId })

Source from the content-addressed store, hash-verified

1067
1068 // use it on Billing page
1069 public static async getListOfInvoicesForAccount({ userId }) {
1070 const teamLeader = await this.findById(userId, 'stripeCustomer teamsForTeamLeader');
1071
1072 const { isSubscriptionActiveForAccount, isTrialPeriodOverForAccount } =
1073 await this.getSubscriptionStatus(userId);
1074
1075 if (
1076 !teamLeader.stripeCustomer.id ||
1077 (!isSubscriptionActiveForAccount && !isTrialPeriodOverForAccount)
1078 ) {
1079 return;
1080 }
1081
1082 const newListOfInvoices = await getListOfInvoicesFromStripe({
1083 customerId: teamLeader.stripeCustomer.id,
1084 subscriptionId: teamLeader.stripeSubscription.id,
1085 });
1086
1087 if (newListOfInvoices.data === undefined || !newListOfInvoices.data.length) {
1088 throw new Error('You have no payment history.');
1089 }
1090
1091 const updatedTeamLeader = await this.findOneAndUpdate(
1092 { _id: userId },
1093 {
1094 $set: {
1095 stripeListOfInvoices: newListOfInvoices,
1096 },
1097 },
1098 { runValidators: true, new: true },
1099 ).setOptions({ lean: true });
1100
1101 return updatedTeamLeader.stripeListOfInvoices;
1102 }
1103
1104 // used in Checkout
1105 public static async subscribeToPaidPlan({

Callers

nothing calls this directly

Calls 2

getSubscriptionStatusMethod · 0.95

Tested by

no test coverage detected