Skip to content

Commit 4e0c6db

Browse files
jfrench9claude
andauthored
Add comprehensive billing and checkout API endpoints with models (#31)
## Summary This PR introduces a complete billing and checkout system to the RoboSystems client API, adding comprehensive functionality for subscription management, payment processing, and invoice handling. ## Key Accomplishments - **New Billing API Module**: Created a dedicated billing API module with 9 endpoint implementations - **Subscription Management**: Added endpoints for creating, retrieving, listing, and canceling subscriptions - **Checkout Flow**: Implemented checkout session creation and status tracking functionality - **Payment Processing**: Added payment method management and update capabilities - **Invoice System**: Built comprehensive invoice listing and upcoming invoice retrieval - **Customer Management**: Added billing customer information retrieval - **Data Models**: Created 13 new model classes to support billing operations including: - Billing customer and subscription models - Checkout request/response and status tracking models - Invoice and invoice line item models with detailed metadata - Payment method management models ## API Endpoints Added - `cancel_subscription` - Cancel active subscriptions - `create_checkout_session` - Initialize payment checkout flows - `get_billing_customer` - Retrieve customer billing information - `get_checkout_status` - Track checkout session progress - `get_subscription` - Get individual subscription details - `get_upcoming_invoice` - Preview upcoming billing charges - `list_invoices` - Retrieve historical billing records - `list_subscriptions` - Get all customer subscriptions - `update_payment_method` - Manage payment information ## Breaking Changes None. This is a purely additive feature that extends the existing API without modifying current functionality. ## Testing Notes - All new endpoints should be tested with valid authentication tokens - Checkout flows require testing with both successful and failed payment scenarios - Subscription operations should be validated across different subscription states - Invoice retrieval should be tested with various date ranges and pagination - Payment method updates require testing with different payment provider integrations ## Infrastructure Considerations - This feature introduces dependencies on external payment processing systems - Consider rate limiting for billing-related endpoints due to financial data sensitivity - Ensure proper logging and monitoring for all payment and subscription operations - Validate that error handling appropriately manages payment gateway timeouts and failures --- 🤖 Generated with [Claude Code](https://claude.ai/code) **Branch Info:** - Source: `feature/billing-api` - Target: `main` - Type: feature Co-Authored-By: Claude <noreply@anthropic.com>
2 parents de43e5c + d3e31e9 commit 4e0c6db

23 files changed

Lines changed: 2978 additions & 0 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Contains endpoint functions for accessing the API"""
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
from http import HTTPStatus
2+
from typing import Any, Optional, Union
3+
4+
import httpx
5+
6+
from ... import errors
7+
from ...client import AuthenticatedClient, Client
8+
from ...models.graph_subscription_response import GraphSubscriptionResponse
9+
from ...models.http_validation_error import HTTPValidationError
10+
from ...types import Response
11+
12+
13+
def _get_kwargs(
14+
subscription_id: str,
15+
) -> dict[str, Any]:
16+
_kwargs: dict[str, Any] = {
17+
"method": "post",
18+
"url": f"/v1/billing/subscriptions/{subscription_id}/cancel",
19+
}
20+
21+
return _kwargs
22+
23+
24+
def _parse_response(
25+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
26+
) -> Optional[Union[GraphSubscriptionResponse, HTTPValidationError]]:
27+
if response.status_code == 200:
28+
response_200 = GraphSubscriptionResponse.from_dict(response.json())
29+
30+
return response_200
31+
32+
if response.status_code == 422:
33+
response_422 = HTTPValidationError.from_dict(response.json())
34+
35+
return response_422
36+
37+
if client.raise_on_unexpected_status:
38+
raise errors.UnexpectedStatus(response.status_code, response.content)
39+
else:
40+
return None
41+
42+
43+
def _build_response(
44+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
45+
) -> Response[Union[GraphSubscriptionResponse, HTTPValidationError]]:
46+
return Response(
47+
status_code=HTTPStatus(response.status_code),
48+
content=response.content,
49+
headers=response.headers,
50+
parsed=_parse_response(client=client, response=response),
51+
)
52+
53+
54+
def sync_detailed(
55+
subscription_id: str,
56+
*,
57+
client: AuthenticatedClient,
58+
) -> Response[Union[GraphSubscriptionResponse, HTTPValidationError]]:
59+
"""Cancel Subscription
60+
61+
Cancel a subscription.
62+
63+
The subscription will remain active until the end of the current billing period.
64+
65+
Args:
66+
subscription_id (str):
67+
68+
Raises:
69+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
70+
httpx.TimeoutException: If the request takes longer than Client.timeout.
71+
72+
Returns:
73+
Response[Union[GraphSubscriptionResponse, HTTPValidationError]]
74+
"""
75+
76+
kwargs = _get_kwargs(
77+
subscription_id=subscription_id,
78+
)
79+
80+
response = client.get_httpx_client().request(
81+
**kwargs,
82+
)
83+
84+
return _build_response(client=client, response=response)
85+
86+
87+
def sync(
88+
subscription_id: str,
89+
*,
90+
client: AuthenticatedClient,
91+
) -> Optional[Union[GraphSubscriptionResponse, HTTPValidationError]]:
92+
"""Cancel Subscription
93+
94+
Cancel a subscription.
95+
96+
The subscription will remain active until the end of the current billing period.
97+
98+
Args:
99+
subscription_id (str):
100+
101+
Raises:
102+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
103+
httpx.TimeoutException: If the request takes longer than Client.timeout.
104+
105+
Returns:
106+
Union[GraphSubscriptionResponse, HTTPValidationError]
107+
"""
108+
109+
return sync_detailed(
110+
subscription_id=subscription_id,
111+
client=client,
112+
).parsed
113+
114+
115+
async def asyncio_detailed(
116+
subscription_id: str,
117+
*,
118+
client: AuthenticatedClient,
119+
) -> Response[Union[GraphSubscriptionResponse, HTTPValidationError]]:
120+
"""Cancel Subscription
121+
122+
Cancel a subscription.
123+
124+
The subscription will remain active until the end of the current billing period.
125+
126+
Args:
127+
subscription_id (str):
128+
129+
Raises:
130+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
131+
httpx.TimeoutException: If the request takes longer than Client.timeout.
132+
133+
Returns:
134+
Response[Union[GraphSubscriptionResponse, HTTPValidationError]]
135+
"""
136+
137+
kwargs = _get_kwargs(
138+
subscription_id=subscription_id,
139+
)
140+
141+
response = await client.get_async_httpx_client().request(**kwargs)
142+
143+
return _build_response(client=client, response=response)
144+
145+
146+
async def asyncio(
147+
subscription_id: str,
148+
*,
149+
client: AuthenticatedClient,
150+
) -> Optional[Union[GraphSubscriptionResponse, HTTPValidationError]]:
151+
"""Cancel Subscription
152+
153+
Cancel a subscription.
154+
155+
The subscription will remain active until the end of the current billing period.
156+
157+
Args:
158+
subscription_id (str):
159+
160+
Raises:
161+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
162+
httpx.TimeoutException: If the request takes longer than Client.timeout.
163+
164+
Returns:
165+
Union[GraphSubscriptionResponse, HTTPValidationError]
166+
"""
167+
168+
return (
169+
await asyncio_detailed(
170+
subscription_id=subscription_id,
171+
client=client,
172+
)
173+
).parsed

0 commit comments

Comments
 (0)