diff --git a/scaleway-async/scaleway_async/billing/v2beta1/__init__.py b/scaleway-async/scaleway_async/billing/v2beta1/__init__.py index 97f6fb9d3..928ccab0c 100644 --- a/scaleway-async/scaleway_async/billing/v2beta1/__init__.py +++ b/scaleway-async/scaleway_async/billing/v2beta1/__init__.py @@ -27,6 +27,7 @@ from .types import ListInvoicesResponse from .types import ListTaxesRequest from .types import ListTaxesResponse +from .types import RedeemCouponRequest from .api import BillingV2Beta1API __all__ = [ @@ -57,5 +58,6 @@ "ListInvoicesResponse", "ListTaxesRequest", "ListTaxesResponse", + "RedeemCouponRequest", "BillingV2Beta1API", ] diff --git a/scaleway-async/scaleway_async/billing/v2beta1/api.py b/scaleway-async/scaleway_async/billing/v2beta1/api.py index 3b1e1350f..b51dcf650 100644 --- a/scaleway-async/scaleway_async/billing/v2beta1/api.py +++ b/scaleway-async/scaleway_async/billing/v2beta1/api.py @@ -34,6 +34,7 @@ ListTaxesResponseTax, ) from .marshalling import ( + unmarshal_Discount, unmarshal_Invoice, unmarshal_ListConsumptionsResponse, unmarshal_ListDiscountsResponse, @@ -506,3 +507,37 @@ async def list_discounts_all( "organization_id": organization_id, }, ) + + async def redeem_coupon( + self, + *, + code: str, + organization_id: Optional[str] = None, + ) -> Discount: + """ + Redeem coupon. + Redeem a coupon given the related code. + :param code: The code of the coupon to redeem. + :param organization_id: The Organization ID of the discount. + :return: :class:`Discount ` + + Usage: + :: + + result = await api.redeem_coupon( + code="example", + ) + """ + + res = self._request( + "POST", + "/billing/v2beta1/redeem-coupon", + params={ + "code": code, + "organization_id": organization_id + or self.client.default_organization_id, + }, + ) + + self._throw_on_error(res) + return unmarshal_Discount(res.json()) diff --git a/scaleway-async/scaleway_async/billing/v2beta1/marshalling.py b/scaleway-async/scaleway_async/billing/v2beta1/marshalling.py index 19355940d..57b1d89a7 100644 --- a/scaleway-async/scaleway_async/billing/v2beta1/marshalling.py +++ b/scaleway-async/scaleway_async/billing/v2beta1/marshalling.py @@ -8,12 +8,12 @@ unmarshal_Money, ) from .types import ( - Invoice, - ListConsumptionsResponseConsumption, - ListConsumptionsResponse, DiscountCoupon, DiscountFilter, Discount, + Invoice, + ListConsumptionsResponseConsumption, + ListConsumptionsResponse, ListDiscountsResponse, ListInvoicesResponse, ListTaxesResponseTax, @@ -21,6 +21,117 @@ ) +def unmarshal_DiscountCoupon(data: Any) -> DiscountCoupon: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'DiscountCoupon' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("description", None) + if field is not None: + args["description"] = field + else: + args["description"] = None + + return DiscountCoupon(**args) + + +def unmarshal_DiscountFilter(data: Any) -> DiscountFilter: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'DiscountFilter' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("type", None) + if field is not None: + args["type_"] = field + + field = data.get("value", None) + if field is not None: + args["value"] = field + + field = data.get("exclude", None) + if field is not None: + args["exclude"] = field + + return DiscountFilter(**args) + + +def unmarshal_Discount(data: Any) -> Discount: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Discount' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + + field = data.get("organization_id", None) + if field is not None: + args["organization_id"] = field + + field = data.get("description", None) + if field is not None: + args["description"] = field + + field = data.get("value", None) + if field is not None: + args["value"] = field + + field = data.get("value_used", None) + if field is not None: + args["value_used"] = field + + field = data.get("value_remaining", None) + if field is not None: + args["value_remaining"] = field + + field = data.get("mode", None) + if field is not None: + args["mode"] = field + + field = data.get("filters", None) + if field is not None: + args["filters"] = ( + [unmarshal_DiscountFilter(v) for v in field] if field is not None else None + ) + + field = data.get("creation_date", None) + if field is not None: + args["creation_date"] = ( + parser.isoparse(field) if isinstance(field, str) else field + ) + else: + args["creation_date"] = None + + field = data.get("start_date", None) + if field is not None: + args["start_date"] = parser.isoparse(field) if isinstance(field, str) else field + else: + args["start_date"] = None + + field = data.get("stop_date", None) + if field is not None: + args["stop_date"] = parser.isoparse(field) if isinstance(field, str) else field + else: + args["stop_date"] = None + + field = data.get("coupon", None) + if field is not None: + args["coupon"] = unmarshal_DiscountCoupon(field) + else: + args["coupon"] = None + + return Discount(**args) + + def unmarshal_Invoice(data: Any) -> Invoice: if not isinstance(data, dict): raise TypeError( @@ -204,117 +315,6 @@ def unmarshal_ListConsumptionsResponse(data: Any) -> ListConsumptionsResponse: return ListConsumptionsResponse(**args) -def unmarshal_DiscountCoupon(data: Any) -> DiscountCoupon: - if not isinstance(data, dict): - raise TypeError( - "Unmarshalling the type 'DiscountCoupon' failed as data isn't a dictionary." - ) - - args: Dict[str, Any] = {} - - field = data.get("description", None) - if field is not None: - args["description"] = field - else: - args["description"] = None - - return DiscountCoupon(**args) - - -def unmarshal_DiscountFilter(data: Any) -> DiscountFilter: - if not isinstance(data, dict): - raise TypeError( - "Unmarshalling the type 'DiscountFilter' failed as data isn't a dictionary." - ) - - args: Dict[str, Any] = {} - - field = data.get("type", None) - if field is not None: - args["type_"] = field - - field = data.get("value", None) - if field is not None: - args["value"] = field - - field = data.get("exclude", None) - if field is not None: - args["exclude"] = field - - return DiscountFilter(**args) - - -def unmarshal_Discount(data: Any) -> Discount: - if not isinstance(data, dict): - raise TypeError( - "Unmarshalling the type 'Discount' failed as data isn't a dictionary." - ) - - args: Dict[str, Any] = {} - - field = data.get("id", None) - if field is not None: - args["id"] = field - - field = data.get("organization_id", None) - if field is not None: - args["organization_id"] = field - - field = data.get("description", None) - if field is not None: - args["description"] = field - - field = data.get("value", None) - if field is not None: - args["value"] = field - - field = data.get("value_used", None) - if field is not None: - args["value_used"] = field - - field = data.get("value_remaining", None) - if field is not None: - args["value_remaining"] = field - - field = data.get("mode", None) - if field is not None: - args["mode"] = field - - field = data.get("filters", None) - if field is not None: - args["filters"] = ( - [unmarshal_DiscountFilter(v) for v in field] if field is not None else None - ) - - field = data.get("creation_date", None) - if field is not None: - args["creation_date"] = ( - parser.isoparse(field) if isinstance(field, str) else field - ) - else: - args["creation_date"] = None - - field = data.get("start_date", None) - if field is not None: - args["start_date"] = parser.isoparse(field) if isinstance(field, str) else field - else: - args["start_date"] = None - - field = data.get("stop_date", None) - if field is not None: - args["stop_date"] = parser.isoparse(field) if isinstance(field, str) else field - else: - args["stop_date"] = None - - field = data.get("coupon", None) - if field is not None: - args["coupon"] = unmarshal_DiscountCoupon(field) - else: - args["coupon"] = None - - return Discount(**args) - - def unmarshal_ListDiscountsResponse(data: Any) -> ListDiscountsResponse: if not isinstance(data, dict): raise TypeError( diff --git a/scaleway-async/scaleway_async/billing/v2beta1/types.py b/scaleway-async/scaleway_async/billing/v2beta1/types.py index 3bb5b5d25..acb11d3e7 100644 --- a/scaleway-async/scaleway_async/billing/v2beta1/types.py +++ b/scaleway-async/scaleway_async/billing/v2beta1/types.py @@ -617,3 +617,16 @@ class ListTaxesResponse: """ Last consumption update date. """ + + +@dataclass +class RedeemCouponRequest: + code: str + """ + The code of the coupon to redeem. + """ + + organization_id: Optional[str] + """ + The Organization ID of the discount. + """ diff --git a/scaleway/scaleway/billing/v2beta1/__init__.py b/scaleway/scaleway/billing/v2beta1/__init__.py index 97f6fb9d3..928ccab0c 100644 --- a/scaleway/scaleway/billing/v2beta1/__init__.py +++ b/scaleway/scaleway/billing/v2beta1/__init__.py @@ -27,6 +27,7 @@ from .types import ListInvoicesResponse from .types import ListTaxesRequest from .types import ListTaxesResponse +from .types import RedeemCouponRequest from .api import BillingV2Beta1API __all__ = [ @@ -57,5 +58,6 @@ "ListInvoicesResponse", "ListTaxesRequest", "ListTaxesResponse", + "RedeemCouponRequest", "BillingV2Beta1API", ] diff --git a/scaleway/scaleway/billing/v2beta1/api.py b/scaleway/scaleway/billing/v2beta1/api.py index 268bf0327..9c5f00b6a 100644 --- a/scaleway/scaleway/billing/v2beta1/api.py +++ b/scaleway/scaleway/billing/v2beta1/api.py @@ -34,6 +34,7 @@ ListTaxesResponseTax, ) from .marshalling import ( + unmarshal_Discount, unmarshal_Invoice, unmarshal_ListConsumptionsResponse, unmarshal_ListDiscountsResponse, @@ -506,3 +507,37 @@ def list_discounts_all( "organization_id": organization_id, }, ) + + def redeem_coupon( + self, + *, + code: str, + organization_id: Optional[str] = None, + ) -> Discount: + """ + Redeem coupon. + Redeem a coupon given the related code. + :param code: The code of the coupon to redeem. + :param organization_id: The Organization ID of the discount. + :return: :class:`Discount ` + + Usage: + :: + + result = api.redeem_coupon( + code="example", + ) + """ + + res = self._request( + "POST", + "/billing/v2beta1/redeem-coupon", + params={ + "code": code, + "organization_id": organization_id + or self.client.default_organization_id, + }, + ) + + self._throw_on_error(res) + return unmarshal_Discount(res.json()) diff --git a/scaleway/scaleway/billing/v2beta1/marshalling.py b/scaleway/scaleway/billing/v2beta1/marshalling.py index 19355940d..57b1d89a7 100644 --- a/scaleway/scaleway/billing/v2beta1/marshalling.py +++ b/scaleway/scaleway/billing/v2beta1/marshalling.py @@ -8,12 +8,12 @@ unmarshal_Money, ) from .types import ( - Invoice, - ListConsumptionsResponseConsumption, - ListConsumptionsResponse, DiscountCoupon, DiscountFilter, Discount, + Invoice, + ListConsumptionsResponseConsumption, + ListConsumptionsResponse, ListDiscountsResponse, ListInvoicesResponse, ListTaxesResponseTax, @@ -21,6 +21,117 @@ ) +def unmarshal_DiscountCoupon(data: Any) -> DiscountCoupon: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'DiscountCoupon' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("description", None) + if field is not None: + args["description"] = field + else: + args["description"] = None + + return DiscountCoupon(**args) + + +def unmarshal_DiscountFilter(data: Any) -> DiscountFilter: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'DiscountFilter' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("type", None) + if field is not None: + args["type_"] = field + + field = data.get("value", None) + if field is not None: + args["value"] = field + + field = data.get("exclude", None) + if field is not None: + args["exclude"] = field + + return DiscountFilter(**args) + + +def unmarshal_Discount(data: Any) -> Discount: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'Discount' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("id", None) + if field is not None: + args["id"] = field + + field = data.get("organization_id", None) + if field is not None: + args["organization_id"] = field + + field = data.get("description", None) + if field is not None: + args["description"] = field + + field = data.get("value", None) + if field is not None: + args["value"] = field + + field = data.get("value_used", None) + if field is not None: + args["value_used"] = field + + field = data.get("value_remaining", None) + if field is not None: + args["value_remaining"] = field + + field = data.get("mode", None) + if field is not None: + args["mode"] = field + + field = data.get("filters", None) + if field is not None: + args["filters"] = ( + [unmarshal_DiscountFilter(v) for v in field] if field is not None else None + ) + + field = data.get("creation_date", None) + if field is not None: + args["creation_date"] = ( + parser.isoparse(field) if isinstance(field, str) else field + ) + else: + args["creation_date"] = None + + field = data.get("start_date", None) + if field is not None: + args["start_date"] = parser.isoparse(field) if isinstance(field, str) else field + else: + args["start_date"] = None + + field = data.get("stop_date", None) + if field is not None: + args["stop_date"] = parser.isoparse(field) if isinstance(field, str) else field + else: + args["stop_date"] = None + + field = data.get("coupon", None) + if field is not None: + args["coupon"] = unmarshal_DiscountCoupon(field) + else: + args["coupon"] = None + + return Discount(**args) + + def unmarshal_Invoice(data: Any) -> Invoice: if not isinstance(data, dict): raise TypeError( @@ -204,117 +315,6 @@ def unmarshal_ListConsumptionsResponse(data: Any) -> ListConsumptionsResponse: return ListConsumptionsResponse(**args) -def unmarshal_DiscountCoupon(data: Any) -> DiscountCoupon: - if not isinstance(data, dict): - raise TypeError( - "Unmarshalling the type 'DiscountCoupon' failed as data isn't a dictionary." - ) - - args: Dict[str, Any] = {} - - field = data.get("description", None) - if field is not None: - args["description"] = field - else: - args["description"] = None - - return DiscountCoupon(**args) - - -def unmarshal_DiscountFilter(data: Any) -> DiscountFilter: - if not isinstance(data, dict): - raise TypeError( - "Unmarshalling the type 'DiscountFilter' failed as data isn't a dictionary." - ) - - args: Dict[str, Any] = {} - - field = data.get("type", None) - if field is not None: - args["type_"] = field - - field = data.get("value", None) - if field is not None: - args["value"] = field - - field = data.get("exclude", None) - if field is not None: - args["exclude"] = field - - return DiscountFilter(**args) - - -def unmarshal_Discount(data: Any) -> Discount: - if not isinstance(data, dict): - raise TypeError( - "Unmarshalling the type 'Discount' failed as data isn't a dictionary." - ) - - args: Dict[str, Any] = {} - - field = data.get("id", None) - if field is not None: - args["id"] = field - - field = data.get("organization_id", None) - if field is not None: - args["organization_id"] = field - - field = data.get("description", None) - if field is not None: - args["description"] = field - - field = data.get("value", None) - if field is not None: - args["value"] = field - - field = data.get("value_used", None) - if field is not None: - args["value_used"] = field - - field = data.get("value_remaining", None) - if field is not None: - args["value_remaining"] = field - - field = data.get("mode", None) - if field is not None: - args["mode"] = field - - field = data.get("filters", None) - if field is not None: - args["filters"] = ( - [unmarshal_DiscountFilter(v) for v in field] if field is not None else None - ) - - field = data.get("creation_date", None) - if field is not None: - args["creation_date"] = ( - parser.isoparse(field) if isinstance(field, str) else field - ) - else: - args["creation_date"] = None - - field = data.get("start_date", None) - if field is not None: - args["start_date"] = parser.isoparse(field) if isinstance(field, str) else field - else: - args["start_date"] = None - - field = data.get("stop_date", None) - if field is not None: - args["stop_date"] = parser.isoparse(field) if isinstance(field, str) else field - else: - args["stop_date"] = None - - field = data.get("coupon", None) - if field is not None: - args["coupon"] = unmarshal_DiscountCoupon(field) - else: - args["coupon"] = None - - return Discount(**args) - - def unmarshal_ListDiscountsResponse(data: Any) -> ListDiscountsResponse: if not isinstance(data, dict): raise TypeError( diff --git a/scaleway/scaleway/billing/v2beta1/types.py b/scaleway/scaleway/billing/v2beta1/types.py index 3bb5b5d25..acb11d3e7 100644 --- a/scaleway/scaleway/billing/v2beta1/types.py +++ b/scaleway/scaleway/billing/v2beta1/types.py @@ -617,3 +617,16 @@ class ListTaxesResponse: """ Last consumption update date. """ + + +@dataclass +class RedeemCouponRequest: + code: str + """ + The code of the coupon to redeem. + """ + + organization_id: Optional[str] + """ + The Organization ID of the discount. + """