AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Merge remote-tracking branch 'origin/master' into dev
Krzysztof Czerwinski4e0a854a7401
diff --cc autogpt_platform/backend/backend/data/credit.pyindex d90d72904d,41b086a700..43608642b5--- a/autogpt_platform/backend/backend/data/credit.py+++ b/autogpt_platform/backend/backend/data/credit.py@@@ -1243,80 -1153,7 +1243,49 @@@ class UserCredit(UserCreditBase))]+ async def list_invoices(+ self, user_id: str, limit: int = 24+ ) -> list[InvoiceListItem]:+ # Skip the Stripe call entirely for users that have never been+ # provisioned a customer — listing invoices must NOT have the side+ # effect of creating a Stripe Customer record (would orphan billable+ # customers for every beta user that opens the billing page).+ user = await get_user_by_id(user_id)+ if not user.stripe_customer_id:+ return []++ # Bound limit to Stripe's per-page maximum (100) and at least 1+ limit = max(1, min(limit, 100))++ try:+ invoices = await run_in_threadpool(+ stripe.Invoice.list,+ customer=user.stripe_customer_id,+ limit=limit,+ )+ except stripe.StripeError:+ logger.exception("Stripe invoice list failed for user %s", user_id)+ return []++ return [+ InvoiceListItem(+ id=invoice.id or "",+ number=invoice.number,+ created_at=datetime.fromtimestamp(+ invoice.created or 0, tz=timezone.utc+ ),+ total_cents=invoice.total or 0,+ amount_paid_cents=invoice.amount_paid or 0,+ currency=(invoice.currency or "usd").lower(),+ status=invoice.status or "open",+ description=invoice.description,+ hosted_invoice_url=invoice.hosted_invoice_url,+ invoice_pdf_url=invoice.invoice_pdf,+ )+ for invoice in invoices.data+ ]+- class BetaUserCredit(UserCredit):- """- This is a temporary class to handle the test user utilizing monthly credit refill.- TODO: Remove this class & its feature toggle.- """-- def __init__(self, num_user_credits_refill: int):- self.num_user_credits_refill = num_user_credits_refill-- async def get_credits(self, user_id: str) -> int:- cur_time = self.time_now().date()- balance, snapshot_time = await self._get_credits(user_id)- if (snapshot_time.year, snapshot_time.month) == (cur_time.year, cur_time.month):- return balance-- target = self.num_user_credits_refill-- try:- balance, _ = await self._add_transaction(- user_id=user_id,- amount=max(target - balance, 0),- transaction_type=CreditTransactionType.GRANT,- transaction_key=f"MONTHLY-CREDIT-TOP-UP-{cur_time}",- metadata=SafeJson({"reason": "Monthly credit refill"}),- )- return balance- except UniqueViolationError:- # Already refilled this month- return (await self._get_credits(user_id))[0]--class DisabledUserCredit(UserCreditBase):async def get_credits(self, *args, **kwargs) -> int:return 100