diff --git a/packages/backend/src/models/user.js b/packages/backend/src/models/user.js index b1a82a71..8a0d5a69 100644 --- a/packages/backend/src/models/user.js +++ b/packages/backend/src/models/user.js @@ -15,6 +15,7 @@ import Role from './role.js'; import Step from './step.js'; import Subscription from './subscription.ee.js'; import UsageData from './usage-data.ee.js'; +import Billing from '../helpers/billing/index.ee.js'; class User extends Base { static tableName = 'users'; @@ -237,6 +238,20 @@ class User extends Base { return currentUsageData.consumedTaskCount < plan.quota; } + async getInvoices() { + const subscription = await this.$relatedQuery('currentSubscription'); + + if (!subscription) { + return []; + } + + const invoices = await Billing.paddleClient.getInvoices( + Number(subscription.paddleSubscriptionId) + ); + + return invoices; + } + async $beforeInsert(queryContext) { await super.$beforeInsert(queryContext);