Skip to content

Commit f132916

Browse files
feat(api): add subscription update endpoint (#238)
1 parent beaede2 commit f132916

10 files changed

+408
-45
lines changed

.stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
configured_endpoints: 81
1+
configured_endpoints: 82

api.md

+1
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ from orb.types import (
321321
Methods:
322322

323323
- <code title="post /subscriptions">client.subscriptions.<a href="./src/orb/resources/subscriptions.py">create</a>(\*\*<a href="src/orb/types/subscription_create_params.py">params</a>) -> <a href="./src/orb/types/subscription.py">Subscription</a></code>
324+
- <code title="put /subscriptions/{subscription_id}">client.subscriptions.<a href="./src/orb/resources/subscriptions.py">update</a>(subscription_id, \*\*<a href="src/orb/types/subscription_update_params.py">params</a>) -> <a href="./src/orb/types/subscription.py">Subscription</a></code>
324325
- <code title="get /subscriptions">client.subscriptions.<a href="./src/orb/resources/subscriptions.py">list</a>(\*\*<a href="src/orb/types/subscription_list_params.py">params</a>) -> <a href="./src/orb/types/subscription.py">SyncPage[Subscription]</a></code>
325326
- <code title="post /subscriptions/{subscription_id}/cancel">client.subscriptions.<a href="./src/orb/resources/subscriptions.py">cancel</a>(subscription_id, \*\*<a href="src/orb/types/subscription_cancel_params.py">params</a>) -> <a href="./src/orb/types/subscription.py">Subscription</a></code>
326327
- <code title="get /subscriptions/{subscription_id}">client.subscriptions.<a href="./src/orb/resources/subscriptions.py">fetch</a>(subscription_id) -> <a href="./src/orb/types/subscription.py">Subscription</a></code>

src/orb/resources/subscriptions.py

+167
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
subscription_list_params,
1818
subscription_cancel_params,
1919
subscription_create_params,
20+
subscription_update_params,
2021
subscription_fetch_costs_params,
2122
subscription_fetch_usage_params,
2223
subscription_trigger_phase_params,
@@ -536,6 +537,83 @@ def create(
536537
cast_to=Subscription,
537538
)
538539

540+
def update(
541+
self,
542+
subscription_id: str,
543+
*,
544+
auto_collection: Optional[bool] | NotGiven = NOT_GIVEN,
545+
default_invoice_memo: Optional[str] | NotGiven = NOT_GIVEN,
546+
invoicing_threshold: Optional[str] | NotGiven = NOT_GIVEN,
547+
metadata: Optional[Dict[str, Optional[str]]] | NotGiven = NOT_GIVEN,
548+
net_terms: Optional[int] | NotGiven = NOT_GIVEN,
549+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
550+
# The extra values given here take precedence over values defined on the client or passed to this method.
551+
extra_headers: Headers | None = None,
552+
extra_query: Query | None = None,
553+
extra_body: Body | None = None,
554+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
555+
idempotency_key: str | None = None,
556+
) -> Subscription:
557+
"""
558+
This endpoint can be used to update the `metadata`, `net terms`,
559+
`auto_collection`, `invoicing_threshold`, and `default_invoice_memo` properties
560+
on a subscription.
561+
562+
Args:
563+
auto_collection: Determines whether issued invoices for this subscription will automatically be
564+
charged with the saved payment method on the due date. This property defaults to
565+
the plan's behavior.
566+
567+
default_invoice_memo: Determines the default memo on this subscription's invoices. Note that if this
568+
is not provided, it is determined by the plan configuration.
569+
570+
invoicing_threshold: When this subscription's accrued usage reaches this threshold, an invoice will
571+
be issued for the subscription. If not specified, invoices will only be issued
572+
at the end of the billing period.
573+
574+
metadata: User-specified key/value pairs for the resource. Individual keys can be removed
575+
by setting the value to `null`, and the entire metadata mapping can be cleared
576+
by setting `metadata` to `null`.
577+
578+
net_terms: Determines the difference between the invoice issue date for subscription
579+
invoices as the date that they are due. A value of `0` here represents that the
580+
invoice is due on issue, whereas a value of `30` represents that the customer
581+
has a month to pay the invoice.
582+
583+
extra_headers: Send extra headers
584+
585+
extra_query: Add additional query parameters to the request
586+
587+
extra_body: Add additional JSON properties to the request
588+
589+
timeout: Override the client-level default timeout for this request, in seconds
590+
591+
idempotency_key: Specify a custom idempotency key for this request
592+
"""
593+
if not subscription_id:
594+
raise ValueError(f"Expected a non-empty value for `subscription_id` but received {subscription_id!r}")
595+
return self._put(
596+
f"/subscriptions/{subscription_id}",
597+
body=maybe_transform(
598+
{
599+
"auto_collection": auto_collection,
600+
"default_invoice_memo": default_invoice_memo,
601+
"invoicing_threshold": invoicing_threshold,
602+
"metadata": metadata,
603+
"net_terms": net_terms,
604+
},
605+
subscription_update_params.SubscriptionUpdateParams,
606+
),
607+
options=make_request_options(
608+
extra_headers=extra_headers,
609+
extra_query=extra_query,
610+
extra_body=extra_body,
611+
timeout=timeout,
612+
idempotency_key=idempotency_key,
613+
),
614+
cast_to=Subscription,
615+
)
616+
539617
def list(
540618
self,
541619
*,
@@ -2166,6 +2244,83 @@ async def create(
21662244
cast_to=Subscription,
21672245
)
21682246

2247+
async def update(
2248+
self,
2249+
subscription_id: str,
2250+
*,
2251+
auto_collection: Optional[bool] | NotGiven = NOT_GIVEN,
2252+
default_invoice_memo: Optional[str] | NotGiven = NOT_GIVEN,
2253+
invoicing_threshold: Optional[str] | NotGiven = NOT_GIVEN,
2254+
metadata: Optional[Dict[str, Optional[str]]] | NotGiven = NOT_GIVEN,
2255+
net_terms: Optional[int] | NotGiven = NOT_GIVEN,
2256+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
2257+
# The extra values given here take precedence over values defined on the client or passed to this method.
2258+
extra_headers: Headers | None = None,
2259+
extra_query: Query | None = None,
2260+
extra_body: Body | None = None,
2261+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
2262+
idempotency_key: str | None = None,
2263+
) -> Subscription:
2264+
"""
2265+
This endpoint can be used to update the `metadata`, `net terms`,
2266+
`auto_collection`, `invoicing_threshold`, and `default_invoice_memo` properties
2267+
on a subscription.
2268+
2269+
Args:
2270+
auto_collection: Determines whether issued invoices for this subscription will automatically be
2271+
charged with the saved payment method on the due date. This property defaults to
2272+
the plan's behavior.
2273+
2274+
default_invoice_memo: Determines the default memo on this subscription's invoices. Note that if this
2275+
is not provided, it is determined by the plan configuration.
2276+
2277+
invoicing_threshold: When this subscription's accrued usage reaches this threshold, an invoice will
2278+
be issued for the subscription. If not specified, invoices will only be issued
2279+
at the end of the billing period.
2280+
2281+
metadata: User-specified key/value pairs for the resource. Individual keys can be removed
2282+
by setting the value to `null`, and the entire metadata mapping can be cleared
2283+
by setting `metadata` to `null`.
2284+
2285+
net_terms: Determines the difference between the invoice issue date for subscription
2286+
invoices as the date that they are due. A value of `0` here represents that the
2287+
invoice is due on issue, whereas a value of `30` represents that the customer
2288+
has a month to pay the invoice.
2289+
2290+
extra_headers: Send extra headers
2291+
2292+
extra_query: Add additional query parameters to the request
2293+
2294+
extra_body: Add additional JSON properties to the request
2295+
2296+
timeout: Override the client-level default timeout for this request, in seconds
2297+
2298+
idempotency_key: Specify a custom idempotency key for this request
2299+
"""
2300+
if not subscription_id:
2301+
raise ValueError(f"Expected a non-empty value for `subscription_id` but received {subscription_id!r}")
2302+
return await self._put(
2303+
f"/subscriptions/{subscription_id}",
2304+
body=await async_maybe_transform(
2305+
{
2306+
"auto_collection": auto_collection,
2307+
"default_invoice_memo": default_invoice_memo,
2308+
"invoicing_threshold": invoicing_threshold,
2309+
"metadata": metadata,
2310+
"net_terms": net_terms,
2311+
},
2312+
subscription_update_params.SubscriptionUpdateParams,
2313+
),
2314+
options=make_request_options(
2315+
extra_headers=extra_headers,
2316+
extra_query=extra_query,
2317+
extra_body=extra_body,
2318+
timeout=timeout,
2319+
idempotency_key=idempotency_key,
2320+
),
2321+
cast_to=Subscription,
2322+
)
2323+
21692324
def list(
21702325
self,
21712326
*,
@@ -3310,6 +3465,9 @@ def __init__(self, subscriptions: Subscriptions) -> None:
33103465
self.create = _legacy_response.to_raw_response_wrapper(
33113466
subscriptions.create,
33123467
)
3468+
self.update = _legacy_response.to_raw_response_wrapper(
3469+
subscriptions.update,
3470+
)
33133471
self.list = _legacy_response.to_raw_response_wrapper(
33143472
subscriptions.list,
33153473
)
@@ -3358,6 +3516,9 @@ def __init__(self, subscriptions: AsyncSubscriptions) -> None:
33583516
self.create = _legacy_response.async_to_raw_response_wrapper(
33593517
subscriptions.create,
33603518
)
3519+
self.update = _legacy_response.async_to_raw_response_wrapper(
3520+
subscriptions.update,
3521+
)
33613522
self.list = _legacy_response.async_to_raw_response_wrapper(
33623523
subscriptions.list,
33633524
)
@@ -3406,6 +3567,9 @@ def __init__(self, subscriptions: Subscriptions) -> None:
34063567
self.create = to_streamed_response_wrapper(
34073568
subscriptions.create,
34083569
)
3570+
self.update = to_streamed_response_wrapper(
3571+
subscriptions.update,
3572+
)
34093573
self.list = to_streamed_response_wrapper(
34103574
subscriptions.list,
34113575
)
@@ -3454,6 +3618,9 @@ def __init__(self, subscriptions: AsyncSubscriptions) -> None:
34543618
self.create = async_to_streamed_response_wrapper(
34553619
subscriptions.create,
34563620
)
3621+
self.update = async_to_streamed_response_wrapper(
3622+
subscriptions.update,
3623+
)
34573624
self.list = async_to_streamed_response_wrapper(
34583625
subscriptions.list,
34593626
)

src/orb/types/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
from .subscription_list_params import SubscriptionListParams as SubscriptionListParams
5050
from .subscription_cancel_params import SubscriptionCancelParams as SubscriptionCancelParams
5151
from .subscription_create_params import SubscriptionCreateParams as SubscriptionCreateParams
52+
from .subscription_update_params import SubscriptionUpdateParams as SubscriptionUpdateParams
5253
from .invoice_fetch_upcoming_params import InvoiceFetchUpcomingParams as InvoiceFetchUpcomingParams
5354
from .invoice_fetch_upcoming_response import InvoiceFetchUpcomingResponse as InvoiceFetchUpcomingResponse
5455
from .invoice_line_item_create_params import InvoiceLineItemCreateParams as InvoiceLineItemCreateParams

src/orb/types/coupon_create_params.py

+5-26
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
from __future__ import annotations
44

5-
from typing import List, Union, Optional
5+
from typing import Union, Optional
66
from typing_extensions import Literal, Required, TypedDict
77

8-
__all__ = ["CouponCreateParams", "Discount", "DiscountPercentageDiscount", "DiscountAmountDiscount"]
8+
__all__ = ["CouponCreateParams", "Discount", "DiscountNewCouponPercentageDiscount", "DiscountNewCouponAmountDiscount"]
99

1010

1111
class CouponCreateParams(TypedDict, total=False):
@@ -27,37 +27,16 @@ class CouponCreateParams(TypedDict, total=False):
2727
"""
2828

2929

30-
class DiscountPercentageDiscount(TypedDict, total=False):
31-
applies_to_price_ids: Required[List[str]]
32-
"""List of price_ids that this discount applies to.
33-
34-
For plan/plan phase discounts, this can be a subset of prices.
35-
"""
36-
30+
class DiscountNewCouponPercentageDiscount(TypedDict, total=False):
3731
discount_type: Required[Literal["percentage"]]
3832

3933
percentage_discount: Required[float]
40-
"""Only available if discount_type is `percentage`.
41-
42-
This is a number between 0 and 1.
43-
"""
4434

45-
reason: Optional[str]
4635

47-
48-
class DiscountAmountDiscount(TypedDict, total=False):
36+
class DiscountNewCouponAmountDiscount(TypedDict, total=False):
4937
amount_discount: Required[str]
50-
"""Only available if discount_type is `amount`."""
51-
52-
applies_to_price_ids: Required[List[str]]
53-
"""List of price_ids that this discount applies to.
54-
55-
For plan/plan phase discounts, this can be a subset of prices.
56-
"""
5738

5839
discount_type: Required[Literal["amount"]]
5940

60-
reason: Optional[str]
61-
6241

63-
Discount = Union[DiscountPercentageDiscount, DiscountAmountDiscount]
42+
Discount = Union[DiscountNewCouponPercentageDiscount, DiscountNewCouponAmountDiscount]

0 commit comments

Comments
 (0)