diff --git a/reference.md b/reference.md index 0edd785..5db7d7f 100644 --- a/reference.md +++ b/reference.md @@ -2688,6 +2688,84 @@ client.features.count_flags() ## billing +
client.billing.list_coupons(...) +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```python +from schematic import Schematic + +client = Schematic( + api_key="YOUR_API_KEY", +) +client.billing.list_coupons() + +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**is_active:** `typing.Optional[bool]` + +
+
+ +
+
+ +**q:** `typing.Optional[str]` + +
+
+ +
+
+ +**limit:** `typing.Optional[int]` — Page limit (default 100) + +
+
+ +
+
+ +**offset:** `typing.Optional[int]` — Page offset (default 0) + +
+
+ +
+
+ +**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration. + +
+
+
+
+ + +
+
+
+
client.billing.upsert_billing_coupon(...)
@@ -3839,7 +3917,7 @@ client.billing.upsert_billing_price( price=1, price_external_id="price_external_id", product_external_id="product_external_id", - usage_type="usage_type", + usage_type="licensed", ) ``` @@ -3904,7 +3982,7 @@ client.billing.upsert_billing_price(
-**usage_type:** `str` +**usage_type:** `CreateBillingPriceRequestBodyUsageType`
@@ -3990,7 +4068,7 @@ client.billing.list_product_prices()
-**price_usage_type:** `typing.Optional[str]` +**price_usage_type:** `typing.Optional[ListProductPricesRequestPriceUsageType]`
@@ -4256,7 +4334,7 @@ client.billing.list_billing_products()
-**price_usage_type:** `typing.Optional[str]` +**price_usage_type:** `typing.Optional[ListBillingProductsRequestPriceUsageType]`
@@ -4374,7 +4452,7 @@ client.billing.count_billing_products()
-**price_usage_type:** `typing.Optional[str]` +**price_usage_type:** `typing.Optional[CountBillingProductsRequestPriceUsageType]`
@@ -4722,6 +4800,14 @@ client.checkout.internal(
+**coupon_external_id:** `typing.Optional[str]` + +
+
+ +
+
+ **payment_method_id:** `typing.Optional[str]`
@@ -4769,7 +4855,7 @@ client = Schematic( api_key="YOUR_API_KEY", ) client.checkout.get_checkout_data( - checkout_internal_id="checkout_internal_id", + company_id="company_id", ) ``` @@ -4786,7 +4872,15 @@ client.checkout.get_checkout_data(
-**checkout_internal_id:** `str` — checkout_internal_id +**company_id:** `str` + +
+
+ +
+
+ +**selected_plan_id:** `typing.Optional[str]`
@@ -4900,6 +4994,14 @@ client.checkout.preview_checkout_internal(
+**coupon_external_id:** `typing.Optional[str]` + +
+
+ +
+
+ **payment_method_id:** `typing.Optional[str]`
diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f502f1b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +httpx>=0.21.2 +pydantic>= 1.9.2 +pydantic-core==^2.18.2 +typing_extensions>= 4.0.0 diff --git a/src/schematic/__init__.py b/src/schematic/__init__.py index fba1add..dea2960 100644 --- a/src/schematic/__init__.py +++ b/src/schematic/__init__.py @@ -189,12 +189,19 @@ ) from .billing import ( CountBillingProductsParams, + CountBillingProductsRequestPriceUsageType, CountBillingProductsResponse, + CountBillingProductsResponseParamsPriceUsageType, CountCustomersParams, CountCustomersResponse, + CreateBillingPriceRequestBodyUsageType, DeleteProductPriceResponse, ListBillingProductsParams, + ListBillingProductsRequestPriceUsageType, ListBillingProductsResponse, + ListBillingProductsResponseParamsPriceUsageType, + ListCouponsParams, + ListCouponsResponse, ListCustomersParams, ListCustomersResponse, ListInvoicesParams, @@ -204,7 +211,9 @@ ListPaymentMethodsParams, ListPaymentMethodsResponse, ListProductPricesParams, + ListProductPricesRequestPriceUsageType, ListProductPricesResponse, + ListProductPricesResponseParamsPriceUsageType, SearchBillingPricesParams, SearchBillingPricesResponse, UpsertBillingCouponResponse, @@ -488,7 +497,9 @@ "CountAudienceCompaniesResponse", "CountAudienceUsersResponse", "CountBillingProductsParams", + "CountBillingProductsRequestPriceUsageType", "CountBillingProductsResponse", + "CountBillingProductsResponseParamsPriceUsageType", "CountCompaniesParams", "CountCompaniesResponse", "CountCompanyOverridesParams", @@ -532,6 +543,7 @@ "CountWebhooksResponse", "CouponRequestBody", "CreateApiKeyResponse", + "CreateBillingPriceRequestBodyUsageType", "CreateCompanyOverrideRequestBodyMetricPeriod", "CreateCompanyOverrideRequestBodyMetricPeriodMonthReset", "CreateCompanyOverrideRequestBodyValueType", @@ -670,7 +682,9 @@ "ListAudienceCompaniesResponse", "ListAudienceUsersResponse", "ListBillingProductsParams", + "ListBillingProductsRequestPriceUsageType", "ListBillingProductsResponse", + "ListBillingProductsResponseParamsPriceUsageType", "ListCompaniesParams", "ListCompaniesResponse", "ListCompanyMembershipsParams", @@ -679,6 +693,8 @@ "ListCompanyOverridesResponse", "ListComponentsParams", "ListComponentsResponse", + "ListCouponsParams", + "ListCouponsResponse", "ListCrmProductsParams", "ListCrmProductsResponse", "ListCustomersParams", @@ -720,7 +736,9 @@ "ListPlansResponse", "ListPlansResponseParamsPlanType", "ListProductPricesParams", + "ListProductPricesRequestPriceUsageType", "ListProductPricesResponse", + "ListProductPricesResponseParamsPriceUsageType", "ListUsersParams", "ListUsersResponse", "ListWebhookEventsParams", diff --git a/src/schematic/billing/__init__.py b/src/schematic/billing/__init__.py index a783de1..fba40e7 100644 --- a/src/schematic/billing/__init__.py +++ b/src/schematic/billing/__init__.py @@ -2,12 +2,19 @@ from .types import ( CountBillingProductsParams, + CountBillingProductsRequestPriceUsageType, CountBillingProductsResponse, + CountBillingProductsResponseParamsPriceUsageType, CountCustomersParams, CountCustomersResponse, + CreateBillingPriceRequestBodyUsageType, DeleteProductPriceResponse, ListBillingProductsParams, + ListBillingProductsRequestPriceUsageType, ListBillingProductsResponse, + ListBillingProductsResponseParamsPriceUsageType, + ListCouponsParams, + ListCouponsResponse, ListCustomersParams, ListCustomersResponse, ListInvoicesParams, @@ -17,7 +24,9 @@ ListPaymentMethodsParams, ListPaymentMethodsResponse, ListProductPricesParams, + ListProductPricesRequestPriceUsageType, ListProductPricesResponse, + ListProductPricesResponseParamsPriceUsageType, SearchBillingPricesParams, SearchBillingPricesResponse, UpsertBillingCouponResponse, @@ -32,12 +41,19 @@ __all__ = [ "CountBillingProductsParams", + "CountBillingProductsRequestPriceUsageType", "CountBillingProductsResponse", + "CountBillingProductsResponseParamsPriceUsageType", "CountCustomersParams", "CountCustomersResponse", + "CreateBillingPriceRequestBodyUsageType", "DeleteProductPriceResponse", "ListBillingProductsParams", + "ListBillingProductsRequestPriceUsageType", "ListBillingProductsResponse", + "ListBillingProductsResponseParamsPriceUsageType", + "ListCouponsParams", + "ListCouponsResponse", "ListCustomersParams", "ListCustomersResponse", "ListInvoicesParams", @@ -47,7 +63,9 @@ "ListPaymentMethodsParams", "ListPaymentMethodsResponse", "ListProductPricesParams", + "ListProductPricesRequestPriceUsageType", "ListProductPricesResponse", + "ListProductPricesResponseParamsPriceUsageType", "SearchBillingPricesParams", "SearchBillingPricesResponse", "UpsertBillingCouponResponse", diff --git a/src/schematic/billing/client.py b/src/schematic/billing/client.py index d92f108..1edbed8 100644 --- a/src/schematic/billing/client.py +++ b/src/schematic/billing/client.py @@ -3,7 +3,7 @@ import typing from ..core.client_wrapper import SyncClientWrapper from ..core.request_options import RequestOptions -from .types.upsert_billing_coupon_response import UpsertBillingCouponResponse +from .types.list_coupons_response import ListCouponsResponse from ..core.pydantic_utilities import parse_obj_as from ..errors.bad_request_error import BadRequestError from ..types.api_error import ApiError as types_api_error_ApiError @@ -12,6 +12,7 @@ from ..errors.internal_server_error import InternalServerError from json.decoder import JSONDecodeError from ..core.api_error import ApiError as core_api_error_ApiError +from .types.upsert_billing_coupon_response import UpsertBillingCouponResponse from .types.upsert_billing_customer_response import UpsertBillingCustomerResponse from .types.list_customers_response import ListCustomersResponse from .types.count_customers_response import CountCustomersResponse @@ -23,12 +24,16 @@ from .types.list_payment_methods_response import ListPaymentMethodsResponse from .types.upsert_payment_method_response import UpsertPaymentMethodResponse from .types.search_billing_prices_response import SearchBillingPricesResponse +from .types.create_billing_price_request_body_usage_type import CreateBillingPriceRequestBodyUsageType from .types.upsert_billing_price_response import UpsertBillingPriceResponse +from .types.list_product_prices_request_price_usage_type import ListProductPricesRequestPriceUsageType from .types.list_product_prices_response import ListProductPricesResponse from .types.delete_product_price_response import DeleteProductPriceResponse from ..core.jsonable_encoder import jsonable_encoder from .types.upsert_billing_product_response import UpsertBillingProductResponse +from .types.list_billing_products_request_price_usage_type import ListBillingProductsRequestPriceUsageType from .types.list_billing_products_response import ListBillingProductsResponse +from .types.count_billing_products_request_price_usage_type import CountBillingProductsRequestPriceUsageType from .types.count_billing_products_response import CountBillingProductsResponse from ..types.billing_subscription_discount import BillingSubscriptionDiscount from ..types.billing_product_pricing import BillingProductPricing @@ -44,6 +49,110 @@ class BillingClient: def __init__(self, *, client_wrapper: SyncClientWrapper): self._client_wrapper = client_wrapper + def list_coupons( + self, + *, + is_active: typing.Optional[bool] = None, + q: typing.Optional[str] = None, + limit: typing.Optional[int] = None, + offset: typing.Optional[int] = None, + request_options: typing.Optional[RequestOptions] = None, + ) -> ListCouponsResponse: + """ + Parameters + ---------- + is_active : typing.Optional[bool] + + q : typing.Optional[str] + + limit : typing.Optional[int] + Page limit (default 100) + + offset : typing.Optional[int] + Page offset (default 0) + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + ListCouponsResponse + OK + + Examples + -------- + from schematic import Schematic + + client = Schematic( + api_key="YOUR_API_KEY", + ) + client.billing.list_coupons() + """ + _response = self._client_wrapper.httpx_client.request( + "billing/coupons", + method="GET", + params={ + "is_active": is_active, + "q": q, + "limit": limit, + "offset": offset, + }, + request_options=request_options, + ) + try: + if 200 <= _response.status_code < 300: + return typing.cast( + ListCouponsResponse, + parse_obj_as( + type_=ListCouponsResponse, # type: ignore + object_=_response.json(), + ), + ) + if _response.status_code == 400: + raise BadRequestError( + typing.cast( + types_api_error_ApiError, + parse_obj_as( + type_=types_api_error_ApiError, # type: ignore + object_=_response.json(), + ), + ) + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast( + types_api_error_ApiError, + parse_obj_as( + type_=types_api_error_ApiError, # type: ignore + object_=_response.json(), + ), + ) + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast( + types_api_error_ApiError, + parse_obj_as( + type_=types_api_error_ApiError, # type: ignore + object_=_response.json(), + ), + ) + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast( + types_api_error_ApiError, + parse_obj_as( + type_=types_api_error_ApiError, # type: ignore + object_=_response.json(), + ), + ) + ) + _response_json = _response.json() + except JSONDecodeError: + raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text) + raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json) + def upsert_billing_coupon( self, *, @@ -1359,7 +1468,7 @@ def upsert_billing_price( price: int, price_external_id: str, product_external_id: str, - usage_type: str, + usage_type: CreateBillingPriceRequestBodyUsageType, meter_id: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> UpsertBillingPriceResponse: @@ -1378,7 +1487,7 @@ def upsert_billing_price( product_external_id : str - usage_type : str + usage_type : CreateBillingPriceRequestBodyUsageType meter_id : typing.Optional[str] @@ -1404,7 +1513,7 @@ def upsert_billing_price( price=1, price_external_id="price_external_id", product_external_id="product_external_id", - usage_type="usage_type", + usage_type="licensed", ) """ _response = self._client_wrapper.httpx_client.request( @@ -1486,7 +1595,7 @@ def list_product_prices( ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None, name: typing.Optional[str] = None, q: typing.Optional[str] = None, - price_usage_type: typing.Optional[str] = None, + price_usage_type: typing.Optional[ListProductPricesRequestPriceUsageType] = None, without_linked_to_plan: typing.Optional[bool] = None, with_zero_price: typing.Optional[bool] = None, with_prices_only: typing.Optional[bool] = None, @@ -1503,7 +1612,7 @@ def list_product_prices( q : typing.Optional[str] - price_usage_type : typing.Optional[str] + price_usage_type : typing.Optional[ListProductPricesRequestPriceUsageType] without_linked_to_plan : typing.Optional[bool] Filter products that are not linked to any plan @@ -1816,7 +1925,7 @@ def list_billing_products( ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None, name: typing.Optional[str] = None, q: typing.Optional[str] = None, - price_usage_type: typing.Optional[str] = None, + price_usage_type: typing.Optional[ListBillingProductsRequestPriceUsageType] = None, without_linked_to_plan: typing.Optional[bool] = None, with_zero_price: typing.Optional[bool] = None, with_prices_only: typing.Optional[bool] = None, @@ -1833,7 +1942,7 @@ def list_billing_products( q : typing.Optional[str] - price_usage_type : typing.Optional[str] + price_usage_type : typing.Optional[ListBillingProductsRequestPriceUsageType] without_linked_to_plan : typing.Optional[bool] Filter products that are not linked to any plan @@ -1943,7 +2052,7 @@ def count_billing_products( ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None, name: typing.Optional[str] = None, q: typing.Optional[str] = None, - price_usage_type: typing.Optional[str] = None, + price_usage_type: typing.Optional[CountBillingProductsRequestPriceUsageType] = None, without_linked_to_plan: typing.Optional[bool] = None, with_zero_price: typing.Optional[bool] = None, with_prices_only: typing.Optional[bool] = None, @@ -1960,7 +2069,7 @@ def count_billing_products( q : typing.Optional[str] - price_usage_type : typing.Optional[str] + price_usage_type : typing.Optional[CountBillingProductsRequestPriceUsageType] without_linked_to_plan : typing.Optional[bool] Filter products that are not linked to any plan @@ -2254,6 +2363,118 @@ class AsyncBillingClient: def __init__(self, *, client_wrapper: AsyncClientWrapper): self._client_wrapper = client_wrapper + async def list_coupons( + self, + *, + is_active: typing.Optional[bool] = None, + q: typing.Optional[str] = None, + limit: typing.Optional[int] = None, + offset: typing.Optional[int] = None, + request_options: typing.Optional[RequestOptions] = None, + ) -> ListCouponsResponse: + """ + Parameters + ---------- + is_active : typing.Optional[bool] + + q : typing.Optional[str] + + limit : typing.Optional[int] + Page limit (default 100) + + offset : typing.Optional[int] + Page offset (default 0) + + request_options : typing.Optional[RequestOptions] + Request-specific configuration. + + Returns + ------- + ListCouponsResponse + OK + + Examples + -------- + import asyncio + + from schematic import AsyncSchematic + + client = AsyncSchematic( + api_key="YOUR_API_KEY", + ) + + + async def main() -> None: + await client.billing.list_coupons() + + + asyncio.run(main()) + """ + _response = await self._client_wrapper.httpx_client.request( + "billing/coupons", + method="GET", + params={ + "is_active": is_active, + "q": q, + "limit": limit, + "offset": offset, + }, + request_options=request_options, + ) + try: + if 200 <= _response.status_code < 300: + return typing.cast( + ListCouponsResponse, + parse_obj_as( + type_=ListCouponsResponse, # type: ignore + object_=_response.json(), + ), + ) + if _response.status_code == 400: + raise BadRequestError( + typing.cast( + types_api_error_ApiError, + parse_obj_as( + type_=types_api_error_ApiError, # type: ignore + object_=_response.json(), + ), + ) + ) + if _response.status_code == 401: + raise UnauthorizedError( + typing.cast( + types_api_error_ApiError, + parse_obj_as( + type_=types_api_error_ApiError, # type: ignore + object_=_response.json(), + ), + ) + ) + if _response.status_code == 403: + raise ForbiddenError( + typing.cast( + types_api_error_ApiError, + parse_obj_as( + type_=types_api_error_ApiError, # type: ignore + object_=_response.json(), + ), + ) + ) + if _response.status_code == 500: + raise InternalServerError( + typing.cast( + types_api_error_ApiError, + parse_obj_as( + type_=types_api_error_ApiError, # type: ignore + object_=_response.json(), + ), + ) + ) + _response_json = _response.json() + except JSONDecodeError: + raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text) + raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json) + async def upsert_billing_coupon( self, *, @@ -3657,7 +3878,7 @@ async def upsert_billing_price( price: int, price_external_id: str, product_external_id: str, - usage_type: str, + usage_type: CreateBillingPriceRequestBodyUsageType, meter_id: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> UpsertBillingPriceResponse: @@ -3676,7 +3897,7 @@ async def upsert_billing_price( product_external_id : str - usage_type : str + usage_type : CreateBillingPriceRequestBodyUsageType meter_id : typing.Optional[str] @@ -3707,7 +3928,7 @@ async def main() -> None: price=1, price_external_id="price_external_id", product_external_id="product_external_id", - usage_type="usage_type", + usage_type="licensed", ) @@ -3792,7 +4013,7 @@ async def list_product_prices( ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None, name: typing.Optional[str] = None, q: typing.Optional[str] = None, - price_usage_type: typing.Optional[str] = None, + price_usage_type: typing.Optional[ListProductPricesRequestPriceUsageType] = None, without_linked_to_plan: typing.Optional[bool] = None, with_zero_price: typing.Optional[bool] = None, with_prices_only: typing.Optional[bool] = None, @@ -3809,7 +4030,7 @@ async def list_product_prices( q : typing.Optional[str] - price_usage_type : typing.Optional[str] + price_usage_type : typing.Optional[ListProductPricesRequestPriceUsageType] without_linked_to_plan : typing.Optional[bool] Filter products that are not linked to any plan @@ -4146,7 +4367,7 @@ async def list_billing_products( ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None, name: typing.Optional[str] = None, q: typing.Optional[str] = None, - price_usage_type: typing.Optional[str] = None, + price_usage_type: typing.Optional[ListBillingProductsRequestPriceUsageType] = None, without_linked_to_plan: typing.Optional[bool] = None, with_zero_price: typing.Optional[bool] = None, with_prices_only: typing.Optional[bool] = None, @@ -4163,7 +4384,7 @@ async def list_billing_products( q : typing.Optional[str] - price_usage_type : typing.Optional[str] + price_usage_type : typing.Optional[ListBillingProductsRequestPriceUsageType] without_linked_to_plan : typing.Optional[bool] Filter products that are not linked to any plan @@ -4281,7 +4502,7 @@ async def count_billing_products( ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None, name: typing.Optional[str] = None, q: typing.Optional[str] = None, - price_usage_type: typing.Optional[str] = None, + price_usage_type: typing.Optional[CountBillingProductsRequestPriceUsageType] = None, without_linked_to_plan: typing.Optional[bool] = None, with_zero_price: typing.Optional[bool] = None, with_prices_only: typing.Optional[bool] = None, @@ -4298,7 +4519,7 @@ async def count_billing_products( q : typing.Optional[str] - price_usage_type : typing.Optional[str] + price_usage_type : typing.Optional[CountBillingProductsRequestPriceUsageType] without_linked_to_plan : typing.Optional[bool] Filter products that are not linked to any plan diff --git a/src/schematic/billing/types/__init__.py b/src/schematic/billing/types/__init__.py index 79ece5e..df57ebb 100644 --- a/src/schematic/billing/types/__init__.py +++ b/src/schematic/billing/types/__init__.py @@ -1,12 +1,19 @@ # This file was auto-generated by Fern from our API Definition. from .count_billing_products_params import CountBillingProductsParams +from .count_billing_products_request_price_usage_type import CountBillingProductsRequestPriceUsageType from .count_billing_products_response import CountBillingProductsResponse +from .count_billing_products_response_params_price_usage_type import CountBillingProductsResponseParamsPriceUsageType from .count_customers_params import CountCustomersParams from .count_customers_response import CountCustomersResponse +from .create_billing_price_request_body_usage_type import CreateBillingPriceRequestBodyUsageType from .delete_product_price_response import DeleteProductPriceResponse from .list_billing_products_params import ListBillingProductsParams +from .list_billing_products_request_price_usage_type import ListBillingProductsRequestPriceUsageType from .list_billing_products_response import ListBillingProductsResponse +from .list_billing_products_response_params_price_usage_type import ListBillingProductsResponseParamsPriceUsageType +from .list_coupons_params import ListCouponsParams +from .list_coupons_response import ListCouponsResponse from .list_customers_params import ListCustomersParams from .list_customers_response import ListCustomersResponse from .list_invoices_params import ListInvoicesParams @@ -16,7 +23,9 @@ from .list_payment_methods_params import ListPaymentMethodsParams from .list_payment_methods_response import ListPaymentMethodsResponse from .list_product_prices_params import ListProductPricesParams +from .list_product_prices_request_price_usage_type import ListProductPricesRequestPriceUsageType from .list_product_prices_response import ListProductPricesResponse +from .list_product_prices_response_params_price_usage_type import ListProductPricesResponseParamsPriceUsageType from .search_billing_prices_params import SearchBillingPricesParams from .search_billing_prices_response import SearchBillingPricesResponse from .upsert_billing_coupon_response import UpsertBillingCouponResponse @@ -30,12 +39,19 @@ __all__ = [ "CountBillingProductsParams", + "CountBillingProductsRequestPriceUsageType", "CountBillingProductsResponse", + "CountBillingProductsResponseParamsPriceUsageType", "CountCustomersParams", "CountCustomersResponse", + "CreateBillingPriceRequestBodyUsageType", "DeleteProductPriceResponse", "ListBillingProductsParams", + "ListBillingProductsRequestPriceUsageType", "ListBillingProductsResponse", + "ListBillingProductsResponseParamsPriceUsageType", + "ListCouponsParams", + "ListCouponsResponse", "ListCustomersParams", "ListCustomersResponse", "ListInvoicesParams", @@ -45,7 +61,9 @@ "ListPaymentMethodsParams", "ListPaymentMethodsResponse", "ListProductPricesParams", + "ListProductPricesRequestPriceUsageType", "ListProductPricesResponse", + "ListProductPricesResponseParamsPriceUsageType", "SearchBillingPricesParams", "SearchBillingPricesResponse", "UpsertBillingCouponResponse", diff --git a/src/schematic/billing/types/count_billing_products_params.py b/src/schematic/billing/types/count_billing_products_params.py index f1ee291..4e53984 100644 --- a/src/schematic/billing/types/count_billing_products_params.py +++ b/src/schematic/billing/types/count_billing_products_params.py @@ -3,6 +3,7 @@ from ...core.pydantic_utilities import UniversalBaseModel import typing import pydantic +from .count_billing_products_response_params_price_usage_type import CountBillingProductsResponseParamsPriceUsageType from ...core.pydantic_utilities import IS_PYDANTIC_V2 @@ -23,7 +24,7 @@ class CountBillingProductsParams(UniversalBaseModel): Page offset (default 0) """ - price_usage_type: typing.Optional[str] = None + price_usage_type: typing.Optional[CountBillingProductsResponseParamsPriceUsageType] = None q: typing.Optional[str] = None with_prices_only: typing.Optional[bool] = pydantic.Field(default=None) """ diff --git a/src/schematic/billing/types/count_billing_products_request_price_usage_type.py b/src/schematic/billing/types/count_billing_products_request_price_usage_type.py new file mode 100644 index 0000000..1b27265 --- /dev/null +++ b/src/schematic/billing/types/count_billing_products_request_price_usage_type.py @@ -0,0 +1,5 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +CountBillingProductsRequestPriceUsageType = typing.Union[typing.Literal["licensed", "metered"], typing.Any] diff --git a/src/schematic/billing/types/count_billing_products_response_params_price_usage_type.py b/src/schematic/billing/types/count_billing_products_response_params_price_usage_type.py new file mode 100644 index 0000000..0515275 --- /dev/null +++ b/src/schematic/billing/types/count_billing_products_response_params_price_usage_type.py @@ -0,0 +1,5 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +CountBillingProductsResponseParamsPriceUsageType = typing.Union[typing.Literal["licensed", "metered"], typing.Any] diff --git a/src/schematic/billing/types/create_billing_price_request_body_usage_type.py b/src/schematic/billing/types/create_billing_price_request_body_usage_type.py new file mode 100644 index 0000000..cb5e88a --- /dev/null +++ b/src/schematic/billing/types/create_billing_price_request_body_usage_type.py @@ -0,0 +1,5 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +CreateBillingPriceRequestBodyUsageType = typing.Union[typing.Literal["licensed", "metered"], typing.Any] diff --git a/src/schematic/billing/types/list_billing_products_params.py b/src/schematic/billing/types/list_billing_products_params.py index 15199ec..a644cb3 100644 --- a/src/schematic/billing/types/list_billing_products_params.py +++ b/src/schematic/billing/types/list_billing_products_params.py @@ -3,6 +3,7 @@ from ...core.pydantic_utilities import UniversalBaseModel import typing import pydantic +from .list_billing_products_response_params_price_usage_type import ListBillingProductsResponseParamsPriceUsageType from ...core.pydantic_utilities import IS_PYDANTIC_V2 @@ -23,7 +24,7 @@ class ListBillingProductsParams(UniversalBaseModel): Page offset (default 0) """ - price_usage_type: typing.Optional[str] = None + price_usage_type: typing.Optional[ListBillingProductsResponseParamsPriceUsageType] = None q: typing.Optional[str] = None with_prices_only: typing.Optional[bool] = pydantic.Field(default=None) """ diff --git a/src/schematic/billing/types/list_billing_products_request_price_usage_type.py b/src/schematic/billing/types/list_billing_products_request_price_usage_type.py new file mode 100644 index 0000000..12267aa --- /dev/null +++ b/src/schematic/billing/types/list_billing_products_request_price_usage_type.py @@ -0,0 +1,5 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +ListBillingProductsRequestPriceUsageType = typing.Union[typing.Literal["licensed", "metered"], typing.Any] diff --git a/src/schematic/billing/types/list_billing_products_response_params_price_usage_type.py b/src/schematic/billing/types/list_billing_products_response_params_price_usage_type.py new file mode 100644 index 0000000..e95d659 --- /dev/null +++ b/src/schematic/billing/types/list_billing_products_response_params_price_usage_type.py @@ -0,0 +1,5 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +ListBillingProductsResponseParamsPriceUsageType = typing.Union[typing.Literal["licensed", "metered"], typing.Any] diff --git a/src/schematic/billing/types/list_coupons_params.py b/src/schematic/billing/types/list_coupons_params.py new file mode 100644 index 0000000..927bf0b --- /dev/null +++ b/src/schematic/billing/types/list_coupons_params.py @@ -0,0 +1,34 @@ +# This file was auto-generated by Fern from our API Definition. + +from ...core.pydantic_utilities import UniversalBaseModel +import typing +import pydantic +from ...core.pydantic_utilities import IS_PYDANTIC_V2 + + +class ListCouponsParams(UniversalBaseModel): + """ + Input parameters + """ + + is_active: typing.Optional[bool] = None + limit: typing.Optional[int] = pydantic.Field(default=None) + """ + Page limit (default 100) + """ + + offset: typing.Optional[int] = pydantic.Field(default=None) + """ + Page offset (default 0) + """ + + q: typing.Optional[str] = None + + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 + else: + + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/src/schematic/billing/types/list_coupons_response.py b/src/schematic/billing/types/list_coupons_response.py new file mode 100644 index 0000000..57e93be --- /dev/null +++ b/src/schematic/billing/types/list_coupons_response.py @@ -0,0 +1,29 @@ +# This file was auto-generated by Fern from our API Definition. + +from ...core.pydantic_utilities import UniversalBaseModel +import typing +from ...types.billing_coupon_response_data import BillingCouponResponseData +import pydantic +from .list_coupons_params import ListCouponsParams +from ...core.pydantic_utilities import IS_PYDANTIC_V2 + + +class ListCouponsResponse(UniversalBaseModel): + data: typing.List[BillingCouponResponseData] = pydantic.Field() + """ + The returned resources + """ + + params: ListCouponsParams = pydantic.Field() + """ + Input parameters + """ + + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 + else: + + class Config: + frozen = True + smart_union = True + extra = pydantic.Extra.allow diff --git a/src/schematic/billing/types/list_product_prices_params.py b/src/schematic/billing/types/list_product_prices_params.py index 9bdeacd..304b776 100644 --- a/src/schematic/billing/types/list_product_prices_params.py +++ b/src/schematic/billing/types/list_product_prices_params.py @@ -3,6 +3,7 @@ from ...core.pydantic_utilities import UniversalBaseModel import typing import pydantic +from .list_product_prices_response_params_price_usage_type import ListProductPricesResponseParamsPriceUsageType from ...core.pydantic_utilities import IS_PYDANTIC_V2 @@ -23,7 +24,7 @@ class ListProductPricesParams(UniversalBaseModel): Page offset (default 0) """ - price_usage_type: typing.Optional[str] = None + price_usage_type: typing.Optional[ListProductPricesResponseParamsPriceUsageType] = None q: typing.Optional[str] = None with_prices_only: typing.Optional[bool] = pydantic.Field(default=None) """ diff --git a/src/schematic/billing/types/list_product_prices_request_price_usage_type.py b/src/schematic/billing/types/list_product_prices_request_price_usage_type.py new file mode 100644 index 0000000..a81cbbc --- /dev/null +++ b/src/schematic/billing/types/list_product_prices_request_price_usage_type.py @@ -0,0 +1,5 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +ListProductPricesRequestPriceUsageType = typing.Union[typing.Literal["licensed", "metered"], typing.Any] diff --git a/src/schematic/billing/types/list_product_prices_response_params_price_usage_type.py b/src/schematic/billing/types/list_product_prices_response_params_price_usage_type.py new file mode 100644 index 0000000..6251a14 --- /dev/null +++ b/src/schematic/billing/types/list_product_prices_response_params_price_usage_type.py @@ -0,0 +1,5 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +ListProductPricesResponseParamsPriceUsageType = typing.Union[typing.Literal["licensed", "metered"], typing.Any] diff --git a/src/schematic/checkout/client.py b/src/schematic/checkout/client.py index 396e3bc..937cb4f 100644 --- a/src/schematic/checkout/client.py +++ b/src/schematic/checkout/client.py @@ -16,11 +16,11 @@ from json.decoder import JSONDecodeError from ..core.api_error import ApiError as core_api_error_ApiError from .types.get_checkout_data_response import GetCheckoutDataResponse -from ..core.jsonable_encoder import jsonable_encoder -from ..errors.not_found_error import NotFoundError from .types.preview_checkout_internal_response import PreviewCheckoutInternalResponse import datetime as dt from .types.update_customer_subscription_trial_end_response import UpdateCustomerSubscriptionTrialEndResponse +from ..core.jsonable_encoder import jsonable_encoder +from ..errors.not_found_error import NotFoundError from ..core.client_wrapper import AsyncClientWrapper # this is used as the default value for optional parameters @@ -39,6 +39,7 @@ def internal( new_plan_id: str, new_price_id: str, pay_in_advance: typing.Sequence[UpdatePayInAdvanceRequestBody], + coupon_external_id: typing.Optional[str] = OMIT, payment_method_id: typing.Optional[str] = OMIT, promo_code: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, @@ -56,6 +57,8 @@ def internal( pay_in_advance : typing.Sequence[UpdatePayInAdvanceRequestBody] + coupon_external_id : typing.Optional[str] + payment_method_id : typing.Optional[str] promo_code : typing.Optional[str] @@ -105,6 +108,7 @@ def internal( object_=add_on_ids, annotation=typing.Sequence[UpdateAddOnRequestBody], direction="write" ), "company_id": company_id, + "coupon_external_id": coupon_external_id, "new_plan_id": new_plan_id, "new_price_id": new_price_id, "pay_in_advance": convert_and_respect_annotation_metadata( @@ -171,13 +175,18 @@ def internal( raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json) def get_checkout_data( - self, checkout_internal_id: str, *, request_options: typing.Optional[RequestOptions] = None + self, + *, + company_id: str, + selected_plan_id: typing.Optional[str] = OMIT, + request_options: typing.Optional[RequestOptions] = None, ) -> GetCheckoutDataResponse: """ Parameters ---------- - checkout_internal_id : str - checkout_internal_id + company_id : str + + selected_plan_id : typing.Optional[str] request_options : typing.Optional[RequestOptions] Request-specific configuration. @@ -195,13 +204,21 @@ def get_checkout_data( api_key="YOUR_API_KEY", ) client.checkout.get_checkout_data( - checkout_internal_id="checkout_internal_id", + company_id="company_id", ) """ _response = self._client_wrapper.httpx_client.request( - f"checkout-internal/{jsonable_encoder(checkout_internal_id)}/data", - method="GET", + "checkout-internal/data", + method="POST", + json={ + "company_id": company_id, + "selected_plan_id": selected_plan_id, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, + omit=OMIT, ) try: if 200 <= _response.status_code < 300: @@ -212,8 +229,8 @@ def get_checkout_data( object_=_response.json(), ), ) - if _response.status_code == 401: - raise UnauthorizedError( + if _response.status_code == 400: + raise BadRequestError( typing.cast( types_api_error_ApiError, parse_obj_as( @@ -222,8 +239,8 @@ def get_checkout_data( ), ) ) - if _response.status_code == 403: - raise ForbiddenError( + if _response.status_code == 401: + raise UnauthorizedError( typing.cast( types_api_error_ApiError, parse_obj_as( @@ -232,8 +249,8 @@ def get_checkout_data( ), ) ) - if _response.status_code == 404: - raise NotFoundError( + if _response.status_code == 403: + raise ForbiddenError( typing.cast( types_api_error_ApiError, parse_obj_as( @@ -265,6 +282,7 @@ def preview_checkout_internal( new_plan_id: str, new_price_id: str, pay_in_advance: typing.Sequence[UpdatePayInAdvanceRequestBody], + coupon_external_id: typing.Optional[str] = OMIT, payment_method_id: typing.Optional[str] = OMIT, promo_code: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, @@ -282,6 +300,8 @@ def preview_checkout_internal( pay_in_advance : typing.Sequence[UpdatePayInAdvanceRequestBody] + coupon_external_id : typing.Optional[str] + payment_method_id : typing.Optional[str] promo_code : typing.Optional[str] @@ -331,6 +351,7 @@ def preview_checkout_internal( object_=add_on_ids, annotation=typing.Sequence[UpdateAddOnRequestBody], direction="write" ), "company_id": company_id, + "coupon_external_id": coupon_external_id, "new_plan_id": new_plan_id, "new_price_id": new_price_id, "pay_in_advance": convert_and_respect_annotation_metadata( @@ -519,6 +540,7 @@ async def internal( new_plan_id: str, new_price_id: str, pay_in_advance: typing.Sequence[UpdatePayInAdvanceRequestBody], + coupon_external_id: typing.Optional[str] = OMIT, payment_method_id: typing.Optional[str] = OMIT, promo_code: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, @@ -536,6 +558,8 @@ async def internal( pay_in_advance : typing.Sequence[UpdatePayInAdvanceRequestBody] + coupon_external_id : typing.Optional[str] + payment_method_id : typing.Optional[str] promo_code : typing.Optional[str] @@ -593,6 +617,7 @@ async def main() -> None: object_=add_on_ids, annotation=typing.Sequence[UpdateAddOnRequestBody], direction="write" ), "company_id": company_id, + "coupon_external_id": coupon_external_id, "new_plan_id": new_plan_id, "new_price_id": new_price_id, "pay_in_advance": convert_and_respect_annotation_metadata( @@ -659,13 +684,18 @@ async def main() -> None: raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json) async def get_checkout_data( - self, checkout_internal_id: str, *, request_options: typing.Optional[RequestOptions] = None + self, + *, + company_id: str, + selected_plan_id: typing.Optional[str] = OMIT, + request_options: typing.Optional[RequestOptions] = None, ) -> GetCheckoutDataResponse: """ Parameters ---------- - checkout_internal_id : str - checkout_internal_id + company_id : str + + selected_plan_id : typing.Optional[str] request_options : typing.Optional[RequestOptions] Request-specific configuration. @@ -688,16 +718,24 @@ async def get_checkout_data( async def main() -> None: await client.checkout.get_checkout_data( - checkout_internal_id="checkout_internal_id", + company_id="company_id", ) asyncio.run(main()) """ _response = await self._client_wrapper.httpx_client.request( - f"checkout-internal/{jsonable_encoder(checkout_internal_id)}/data", - method="GET", + "checkout-internal/data", + method="POST", + json={ + "company_id": company_id, + "selected_plan_id": selected_plan_id, + }, + headers={ + "content-type": "application/json", + }, request_options=request_options, + omit=OMIT, ) try: if 200 <= _response.status_code < 300: @@ -708,8 +746,8 @@ async def main() -> None: object_=_response.json(), ), ) - if _response.status_code == 401: - raise UnauthorizedError( + if _response.status_code == 400: + raise BadRequestError( typing.cast( types_api_error_ApiError, parse_obj_as( @@ -718,8 +756,8 @@ async def main() -> None: ), ) ) - if _response.status_code == 403: - raise ForbiddenError( + if _response.status_code == 401: + raise UnauthorizedError( typing.cast( types_api_error_ApiError, parse_obj_as( @@ -728,8 +766,8 @@ async def main() -> None: ), ) ) - if _response.status_code == 404: - raise NotFoundError( + if _response.status_code == 403: + raise ForbiddenError( typing.cast( types_api_error_ApiError, parse_obj_as( @@ -761,6 +799,7 @@ async def preview_checkout_internal( new_plan_id: str, new_price_id: str, pay_in_advance: typing.Sequence[UpdatePayInAdvanceRequestBody], + coupon_external_id: typing.Optional[str] = OMIT, payment_method_id: typing.Optional[str] = OMIT, promo_code: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, @@ -778,6 +817,8 @@ async def preview_checkout_internal( pay_in_advance : typing.Sequence[UpdatePayInAdvanceRequestBody] + coupon_external_id : typing.Optional[str] + payment_method_id : typing.Optional[str] promo_code : typing.Optional[str] @@ -835,6 +876,7 @@ async def main() -> None: object_=add_on_ids, annotation=typing.Sequence[UpdateAddOnRequestBody], direction="write" ), "company_id": company_id, + "coupon_external_id": coupon_external_id, "new_plan_id": new_plan_id, "new_price_id": new_price_id, "pay_in_advance": convert_and_respect_annotation_metadata( diff --git a/src/schematic/core/http_client.py b/src/schematic/core/http_client.py index 1a1a131..17b942c 100644 --- a/src/schematic/core/http_client.py +++ b/src/schematic/core/http_client.py @@ -85,8 +85,8 @@ def _retry_timeout(response: httpx.Response, retries: int) -> float: def _should_retry(response: httpx.Response) -> bool: - retriable_400s = [429, 408, 409] - return response.status_code >= 500 or response.status_code in retriable_400s + retryable_400s = [429, 408, 409] + return response.status_code >= 500 or response.status_code in retryable_400s def remove_omit_from_dict( diff --git a/src/schematic/core/pydantic_utilities.py b/src/schematic/core/pydantic_utilities.py index ee8f0e4..ca1f479 100644 --- a/src/schematic/core/pydantic_utilities.py +++ b/src/schematic/core/pydantic_utilities.py @@ -79,7 +79,7 @@ def to_jsonable_with_fallback( class UniversalBaseModel(pydantic.BaseModel): if IS_PYDANTIC_V2: model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict( - # Allow fields begining with `model_` to be used in the model + # Allow fields beginning with `model_` to be used in the model protected_namespaces=(), ) # type: ignore # Pydantic v2 @@ -128,7 +128,7 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: Override the default dict method to `exclude_unset` by default. This function patches `exclude_unset` to work include fields within non-None default values. """ - # Note: the logic here is multi-plexed given the levers exposed in Pydantic V1 vs V2 + # Note: the logic here is multiplexed given the levers exposed in Pydantic V1 vs V2 # Pydantic V1's .dict can be extremely slow, so we do not want to call it twice. # # We'd ideally do the same for Pydantic V2, but it shells out to a library to serialize models diff --git a/src/schematic/types/billing_coupon_response_data.py b/src/schematic/types/billing_coupon_response_data.py index fe79f62..e2dec80 100644 --- a/src/schematic/types/billing_coupon_response_data.py +++ b/src/schematic/types/billing_coupon_response_data.py @@ -8,10 +8,6 @@ class BillingCouponResponseData(UniversalBaseModel): - """ - The created resource - """ - account_id: str amount_off: typing.Optional[int] = None currency: typing.Optional[str] = None diff --git a/src/schematic/types/change_subscription_internal_request_body.py b/src/schematic/types/change_subscription_internal_request_body.py index 4a6f811..cd6838b 100644 --- a/src/schematic/types/change_subscription_internal_request_body.py +++ b/src/schematic/types/change_subscription_internal_request_body.py @@ -11,6 +11,7 @@ class ChangeSubscriptionInternalRequestBody(UniversalBaseModel): add_on_ids: typing.List[UpdateAddOnRequestBody] company_id: str + coupon_external_id: typing.Optional[str] = None new_plan_id: str new_price_id: str pay_in_advance: typing.List[UpdatePayInAdvanceRequestBody] diff --git a/src/schematic/types/change_subscription_request_body.py b/src/schematic/types/change_subscription_request_body.py index 7732b66..f214723 100644 --- a/src/schematic/types/change_subscription_request_body.py +++ b/src/schematic/types/change_subscription_request_body.py @@ -10,6 +10,7 @@ class ChangeSubscriptionRequestBody(UniversalBaseModel): add_on_ids: typing.List[UpdateAddOnRequestBody] + coupon_external_id: typing.Optional[str] = None new_plan_id: str new_price_id: str pay_in_advance: typing.List[UpdatePayInAdvanceRequestBody] diff --git a/src/schematic/types/checkout_data_response_data.py b/src/schematic/types/checkout_data_response_data.py index 8bedaaa..73a5f19 100644 --- a/src/schematic/types/checkout_data_response_data.py +++ b/src/schematic/types/checkout_data_response_data.py @@ -13,7 +13,7 @@ class CheckoutDataResponseData(UniversalBaseModel): """ - The returned resource + The requested resource """ active_add_ons: typing.List[PlanDetailResponseData] @@ -21,6 +21,8 @@ class CheckoutDataResponseData(UniversalBaseModel): active_usage_based_entitlements: typing.List[UsageBasedEntitlementResponseData] company: typing.Optional[CompanyDetailResponseData] = None feature_usage: typing.Optional[FeatureUsageDetailResponseData] = None + selected_plan: typing.Optional[PlanDetailResponseData] = None + selected_usage_based_entitlements: typing.List[UsageBasedEntitlementResponseData] subscription: typing.Optional[CompanySubscriptionResponseData] = None if IS_PYDANTIC_V2: