Overview
Thebilling client provides access to subscription management, Stripe Checkout session creation, and the Stripe Billing Portal.
Access the billing client via client.billing.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Manage subscriptions, create checkout sessions, and access the billing portal with the Grantex Python SDK.
billing client provides access to subscription management, Stripe Checkout session creation, and the Stripe Billing Portal.
Access the billing client via client.billing.
from grantex import Grantex
with Grantex(api_key="gx_live_...") as client:
sub = client.billing.get_subscription()
print(f"Plan: {sub.plan}")
print(f"Status: {sub.status}")
print(f"Current period ends: {sub.current_period_end}")
| Field | Type | Description |
|---|---|---|
plan | str | Current plan ("free", "pro", or "enterprise"). |
status | str | Subscription status ("active", "past_due", "canceled"). |
current_period_end | str | None | ISO 8601 timestamp when the current billing period ends. |
from grantex import Grantex, CreateCheckoutParams
with Grantex(api_key="gx_live_...") as client:
checkout = client.billing.create_checkout(CreateCheckoutParams(
plan="pro",
success_url="https://myapp.com/billing/success",
cancel_url="https://myapp.com/billing/cancel",
))
print(f"Redirect to: {checkout.checkout_url}")
| Parameter | Type | Required | Description |
|---|---|---|---|
plan | str | Yes | The plan to subscribe to ("pro" or "enterprise"). |
success_url | str | Yes | URL to redirect to after successful payment. |
cancel_url | str | Yes | URL to redirect to if the user cancels. |
| Field | Type | Description |
|---|---|---|
checkout_url | str | The Stripe Checkout session URL. |
from grantex import Grantex, CreatePortalParams
with Grantex(api_key="gx_live_...") as client:
portal = client.billing.create_portal(CreatePortalParams(
return_url="https://myapp.com/settings",
))
print(f"Redirect to: {portal.portal_url}")
| Parameter | Type | Required | Description |
|---|---|---|---|
return_url | str | Yes | URL to redirect to when the user exits the portal. |
| Field | Type | Description |
|---|---|---|
portal_url | str | The Stripe Billing Portal session URL. |
from grantex import Grantex, CreateCheckoutParams, CreatePortalParams
with Grantex(api_key="gx_live_...") as client:
# Check current plan
sub = client.billing.get_subscription()
if sub.plan == "free":
# Upgrade to pro
checkout = client.billing.create_checkout(CreateCheckoutParams(
plan="pro",
success_url="https://myapp.com/billing/success",
cancel_url="https://myapp.com/billing/cancel",
))
print(f"Upgrade: {checkout.checkout_url}")
else:
# Manage existing subscription
portal = client.billing.create_portal(CreatePortalParams(
return_url="https://myapp.com/settings",
))
print(f"Manage: {portal.portal_url}")