Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a portal redirect endpoint #23375

Merged
merged 26 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6eeb747
Add a portal redirect endpoint
zlwaterfield Jul 1, 2024
cbb56f5
update fixtures and added tests
zlwaterfield Jul 1, 2024
8aa96be
fix response type
zlwaterfield Jul 1, 2024
f5138f6
Update query snapshots
github-actions[bot] Jul 1, 2024
9b88921
update portal test response type
zlwaterfield Jul 1, 2024
ed5ba1f
fix test
zlwaterfield Jul 1, 2024
a8c6898
Merge branch 'master' into zach/generate-less-stripe-portal-sessions
zlwaterfield Jul 1, 2024
e2f66ac
Update query snapshots
github-actions[bot] Jul 1, 2024
c5aebc7
fix(data-warehouse): schema status optional type (#23379)
EDsCODE Jul 2, 2024
ffe3cfa
fix: add experimental settings to actors_query_runner (#23380)
aspicer Jul 2, 2024
17b64db
feat(web-analytics): Add option behind FF to switch to V2 web analyti…
robbie-c Jul 2, 2024
20934bd
chore(capture-rs): add capture_billing_limits_loaded_tokens metric (#…
xvello Jul 2, 2024
c611313
feat: remove non-hogql replay filtering (#23345)
pauldambra Jul 2, 2024
978e432
fix: replay storybook scene rot (#23383)
pauldambra Jul 2, 2024
dce298d
feat: include org id when creating new tickets (#23388)
MarconLP Jul 2, 2024
123c580
feat: sample message too large to s3 (#23374)
pauldambra Jul 2, 2024
2fbf3e9
chore(capture): add billing limits integration tests (#23389)
xvello Jul 2, 2024
62c5abd
fix(multi project flags): remove flag id from URL when switching proj…
jurajmajerik Jul 2, 2024
e87c525
chore(data-warehouse): Added number formatting for source settings (#…
Gilbert09 Jul 2, 2024
934c2dc
chore: maybe this will stop them flapping (#23401)
pauldambra Jul 2, 2024
6ce9620
feat(survey): Allow events to repeatedly activate surveys (#23238)
Phanatic Jul 2, 2024
054a993
fix(experiments): provide `required_scope` for experiments API (#23385)
dmarticus Jul 2, 2024
ac364a2
Update query snapshots
github-actions[bot] Jul 2, 2024
14324c3
merge master in
zlwaterfield Jul 2, 2024
ec93e63
remove dup tests
zlwaterfield Jul 2, 2024
52af19b
merge master in
zlwaterfield Jul 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1955,5 +1955,5 @@
"discount_amount_usd": null,
"amount_off_expires_at": null,
"never_drop_data": null,
"stripe_portal_url": "https://billing.stripe.com/p/session/test_YWNjdF8xSElNRERFdUlhdFJYU2R6LF9PdXhKRW1kYVNRb3BOcFpVVHl6emVCUjdSUDJrQTJs0100akrliUs0"
"stripe_portal_url": "http://localhost:8000/api/billing/portal"
}
2 changes: 1 addition & 1 deletion cypress/fixtures/api/billing/billing-unsubscribed.json
Original file line number Diff line number Diff line change
Expand Up @@ -3657,5 +3657,5 @@
"session_replay": 3,
"product_analytics": 3
},
"stripe_portal_url": "https://billing.stripe.com/p/session/test_YWNjdF8xSElNRERFdUlhdFJYU2R6LF9QaEVaQ0hCTUE0aE8wUFhlVWVqd29MaElGd3lwRjFa010044U4IxJp"
"stripe_portal_url": "http://localhost:8000/api/billing/portal"
}
2 changes: 1 addition & 1 deletion cypress/fixtures/api/billing/billing.json
Original file line number Diff line number Diff line change
Expand Up @@ -3777,5 +3777,5 @@
"session_replay": 3,
"product_analytics": 3
},
"stripe_portal_url": "https://billing.stripe.com/p/session/test_YWNjdF8xSElNRERFdUlhdFJYU2R6LF9QaEVpVHFJNXdKYk9DaG04SVhMaUV4TDlxOTR1WEZi0100SMJCDr2e"
"stripe_portal_url": "http://localhost:8000/api/billing/portal"
}
14 changes: 14 additions & 0 deletions ee/api/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,20 @@ def deactivate(self, request: Request, *args: Any, **kwargs: Any) -> HttpRespons

return self.list(request, *args, **kwargs)

@action(methods=["GET"], detail=False)
def portal(self, request: Request, *args: Any, **kwargs: Any) -> HttpResponse:
license = get_cached_instance_license()
if not license:
return Response(
{"sucess": True},
status=status.HTTP_200_OK,
)

organization = self._get_org_required()

res = BillingManager(license)._get_stripe_portal_url(organization)
return redirect(res)

@action(methods=["GET"], detail=False)
def get_invoices(self, request: Request, *args: Any, **kwargs: Any) -> HttpResponse:
license = get_cached_instance_license()
Expand Down
16 changes: 14 additions & 2 deletions ee/api/test/test_billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def mock_implementation(url: str, headers: Any = None, params: Any = None) -> Ma
"available_product_features": [],
"custom_limits_usd": {},
"has_active_subscription": True,
"stripe_portal_url": "https://billing.stripe.com/p/session/test_1234",
"stripe_portal_url": "http://localhost:8000/api/billing/portal",
"current_total_amount_usd": "100.00",
"deactivated": False,
"products": [
Expand Down Expand Up @@ -562,7 +562,7 @@ def mock_implementation(url: str, headers: Any = None, params: Any = None) -> Ma
"free_trial_until": None,
"current_total_amount_usd": "0.00",
"deactivated": False,
"stripe_portal_url": "https://billing.stripe.com/p/session/test_1234",
"stripe_portal_url": "http://localhost:8000/api/billing/portal",
}

@patch("ee.api.billing.requests.get")
Expand Down Expand Up @@ -839,6 +839,18 @@ def mock_implementation(url: str, headers: Any = None, params: Any = None) -> Ma
assert self.organization.customer_trust_scores == {"recordings": 0, "events": 15, "rows_synced": 0}


class TestPortalBillingAPI(APILicensedTest):
@patch("ee.api.billing.requests.get")
def test_portal_success(self, mock_request):
mock_request.return_value.status_code = 200
mock_request.return_value.json.return_value = {"url": "https://billing.stripe.com/p/session/test_1234"}

response = self.client.get("/api/billing/portal")

self.assertEqual(response.status_code, status.HTTP_302_FOUND)
self.assertIn("https://billing.stripe.com/p/session/test_1234", response.url)


class TestActivateBillingAPI(APILicensedTest):
def test_activate_success(self):
url = "/api/billing/activate"
Expand Down
6 changes: 3 additions & 3 deletions ee/billing/billing_manager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.conf import settings
from datetime import datetime, timedelta
from enum import Enum
from typing import Any, Optional, cast
Expand Down Expand Up @@ -85,8 +86,7 @@ def get_billing(self, organization: Optional[Organization], plan_keys: Optional[
products = self.get_default_products(organization)
response["products"] = products["products"]

stripe_portal_url = self._get_stripe_portal_url(organization)
response["stripe_portal_url"] = stripe_portal_url
response["stripe_portal_url"] = f"{settings.SITE_URL}/api/billing/portal"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change for the PR.


# Extend the products with accurate usage_limit info
for product in response["products"]:
Expand Down Expand Up @@ -207,7 +207,7 @@ def _get_billing(self, organization: Organization) -> BillingStatus:

return data

def _get_stripe_portal_url(self, organization: Organization) -> BillingStatus:
def _get_stripe_portal_url(self, organization: Organization) -> str:
"""
Retrieves stripe protal url
"""
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion frontend/src/mocks/fixtures/_billing_unsubscribed.json
Original file line number Diff line number Diff line change
Expand Up @@ -1872,5 +1872,5 @@
"discount_amount_usd": null,
"amount_off_expires_at": null,
"never_drop_data": null,
"stripe_portal_url": "https://billing.stripe.com/p/session/test_YWNjdF8xSElNRERFdUlhdFJYU2R6LF9QN0ltZVQ3RmpLbTZacXgzYWo3Q0FFbFpITHZydlpK0100iKmkfAZi"
"stripe_portal_url": "http://localhost:8000/api/billing/portal"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2769,5 +2769,5 @@
]
}
],
"stripe_portal_url": "https://billing.stripe.com/p/session/XYZ"
"stripe_portal_url": "http://localhost:8000/api/billing/portal"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4683,5 +4683,5 @@
"session_replay": 3,
"product_analytics": 3
},
"stripe_portal_url": "https://billing.stripe.com/p/session/test_YWNjdF8xSElNRERFdUlhdFJYU2R6LF9RNE9kdEg5elRmWE1wZkY1SGlsTFFFQXRKRmVkdnpJ0100M2MwqzHs"
"stripe_portal_url": "http://localhost:8000/api/billing/portal"
}
2 changes: 1 addition & 1 deletion frontend/src/mocks/fixtures/_billing_with_discount.json
Original file line number Diff line number Diff line change
Expand Up @@ -2767,5 +2767,5 @@
]
}
],
"stripe_portal_url": "https://billing.stripe.com/p/session/XYZ"
"stripe_portal_url": "http://localhost:8000/api/billing/portal"
}
2 changes: 1 addition & 1 deletion frontend/src/mocks/fixtures/_billing_with_flat_fee.json
Original file line number Diff line number Diff line change
Expand Up @@ -1447,5 +1447,5 @@
"discount_amount_usd": null,
"amount_off_expires_at": null,
"never_drop_data": false,
"stripe_portal_url": "https://billing.stripe.com/p/session/live_YWNjdF8xSElNRERFdUlhdFJYU2R6LF9PeG9wUmZuUFpmcTlvaWVjeUd0ZlhFN2hHbjJUWDR30100sm6GDMjx"
"stripe_portal_url": "http://localhost:8000/api/billing/portal"
}
1 change: 1 addition & 0 deletions frontend/src/scenes/billing/Billing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export function Billing(): JSX.Element {
htmlType="submit"
to={billing.stripe_portal_url}
disableClientSideRouting
targetBlank
center
>
Manage card details and view past invoices
Expand Down
Loading