Skip to content

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.

fix(platform): Fallback front-end-url to platform-url for billing page

Zamil Majdy875743919252
diff --git a/autogpt_platform/backend/backend/data/credit.py b/autogpt_platform/backend/backend/data/credit.py
index 452b60d750..78463f9364 100644
--- a/autogpt_platform/backend/backend/data/credit.py
+++ b/autogpt_platform/backend/backend/data/credit.py
@@ -39,6 +39,7 @@ from backend.util.settings import Settings
settings = Settings()
stripe.api_key = settings.secrets.stripe_api_key
logger = logging.getLogger(__name__)
+base_url = settings.config.frontend_base_url or settings.config.platform_base_url
class UserCreditBase(ABC):
@@ -185,6 +186,14 @@ class UserCreditBase(ABC):
"""
pass
+ @staticmethod
+ async def create_billing_portal_session(user_id: str) -> str:
+ session = stripe.billing_portal.Session.create(
+ customer=await get_stripe_customer_id(user_id),
+ return_url=base_url + "/profile/credits",
+ )
+ return session.url
+
@staticmethod
def time_now() -> datetime:
return datetime.now(timezone.utc)
@@ -765,10 +774,8 @@ class UserCredit(UserCreditBase):
ui_mode="hosted",
payment_intent_data={"setup_future_usage": "off_session"},
saved_payment_method_options={"payment_method_save": "enabled"},
- success_url=settings.config.frontend_base_url
- + "/profile/credits?topup=success",
- cancel_url=settings.config.frontend_base_url
- + "/profile/credits?topup=cancel",
+ success_url=base_url + "/profile/credits?topup=success",
+ cancel_url=base_url + "/profile/credits?topup=cancel",
allow_promotion_codes=True,
)
diff --git a/autogpt_platform/backend/backend/server/routers/v1.py b/autogpt_platform/backend/backend/server/routers/v1.py
index f695642dda..54cd33f959 100644
--- a/autogpt_platform/backend/backend/server/routers/v1.py
+++ b/autogpt_platform/backend/backend/server/routers/v1.py
@@ -38,7 +38,6 @@ from backend.data.credit import (
TransactionHistory,
get_auto_top_up,
get_block_costs,
- get_stripe_customer_id,
get_user_credit_model,
set_auto_top_up,
)
@@ -341,15 +340,7 @@ async def stripe_webhook(request: Request):
async def manage_payment_method(
user_id: Annotated[str, Depends(get_user_id)],
) -> dict[str, str]:
- session = stripe.billing_portal.Session.create(
- customer=await get_stripe_customer_id(user_id),
- return_url=settings.config.frontend_base_url + "/profile/credits",
- )
- if not session:
- raise HTTPException(
- status_code=400, detail="Failed to create billing portal session"
- )
- return {"url": session.url}
+ return {"url": await _user_credit_model.create_billing_portal_session(user_id)}
@v1_router.get(path="/credits/transactions", dependencies=[Depends(auth_middleware)])
diff --git a/autogpt_platform/frontend/src/app/profile/(user)/credits/page.tsx b/autogpt_platform/frontend/src/app/profile/(user)/credits/page.tsx
index 06ed54459e..7b76b70951 100644
--- a/autogpt_platform/frontend/src/app/profile/(user)/credits/page.tsx
+++ b/autogpt_platform/frontend/src/app/profile/(user)/credits/page.tsx
@@ -29,7 +29,6 @@ export default function CreditsPage() {
formatCredits,
refundTopUp,
refundRequests,
- fetchRefundRequests,
} = useCredits({
fetchInitialAutoTopUpConfig: true,
fetchInitialRefundRequests: true,