Skip to content

Commit a6a39ff

Browse files
Merge pull request #1774 from stripe/latest-codegen-beta
Update generated code for beta
2 parents f5e3f54 + bae3635 commit a6a39ff

92 files changed

Lines changed: 1016 additions & 307 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CODEGEN_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
58595eed5a9dffbf0f297ecaf3ac45acf36c5de3
1+
25e6bd225852aa44d783e9fb3b9895af39479331

OPENAPI_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2205
1+
v2206

stripe/_account_service.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# -*- coding: utf-8 -*-
22
# File generated from our OpenAPI spec
3+
import json
4+
from stripe._api_version import _ApiVersion
35
from stripe._stripe_service import StripeService
46
from stripe._util import sanitize_id
57
from typing import Optional, cast
8+
from uuid import uuid4
69
from importlib import import_module
710
from typing_extensions import TYPE_CHECKING
811

@@ -395,3 +398,27 @@ async def reject_async(
395398
options=options,
396399
),
397400
)
401+
402+
def serialize_batch_update(
403+
self,
404+
account: str,
405+
params: Optional["AccountUpdateParams"] = None,
406+
options: Optional["RequestOptions"] = None,
407+
) -> str:
408+
"""
409+
Serializes an Account update request into a batch job JSONL line.
410+
"""
411+
item_id = str(uuid4())
412+
stripe_version = (
413+
options.get("stripe_version") if options else None
414+
) or _ApiVersion.CURRENT
415+
context = options.get("stripe_context") if options else None
416+
item = {
417+
"id": item_id,
418+
"path_params": {"account": account},
419+
"params": params,
420+
"stripe_version": stripe_version,
421+
}
422+
if context is not None:
423+
item["context"] = context
424+
return json.dumps(item)

stripe/_credit_note_line_item.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# File generated from our OpenAPI spec
3+
from decimal import Decimal
34
from stripe._expandable_field import ExpandableField
45
from stripe._stripe_object import StripeObject
56
from typing import ClassVar, Dict, List, Optional
@@ -176,7 +177,7 @@ class TaxRateDetails(StripeObject):
176177
"""
177178
The cost of each unit of product being credited.
178179
"""
179-
unit_amount_decimal: Optional[str]
180+
unit_amount_decimal: Optional[Decimal]
180181
"""
181182
Same as `unit_amount`, but contains a decimal value with at most 12 decimal places.
182183
"""
@@ -186,3 +187,4 @@ class TaxRateDetails(StripeObject):
186187
"tax_calculation_reference": TaxCalculationReference,
187188
"taxes": Tax,
188189
}
190+
_field_encodings = {"unit_amount_decimal": "decimal_string"}

stripe/_credit_note_service.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# -*- coding: utf-8 -*-
22
# File generated from our OpenAPI spec
3+
import json
4+
from stripe._api_version import _ApiVersion
35
from stripe._stripe_service import StripeService
46
from stripe._util import sanitize_id
57
from typing import Optional, cast
8+
from uuid import uuid4
69
from importlib import import_module
710
from typing_extensions import TYPE_CHECKING
811

@@ -319,3 +322,25 @@ async def void_credit_note_async(
319322
options=options,
320323
),
321324
)
325+
326+
def serialize_batch_create(
327+
self,
328+
params: Optional["CreditNoteCreateParams"] = None,
329+
options: Optional["RequestOptions"] = None,
330+
) -> str:
331+
"""
332+
Serializes a CreditNote create request into a batch job JSONL line.
333+
"""
334+
item_id = str(uuid4())
335+
stripe_version = (
336+
options.get("stripe_version") if options else None
337+
) or _ApiVersion.CURRENT
338+
context = options.get("stripe_context") if options else None
339+
item = {
340+
"id": item_id,
341+
"params": params,
342+
"stripe_version": stripe_version,
343+
}
344+
if context is not None:
345+
item["context"] = context
346+
return json.dumps(item)

stripe/_customer_service.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# -*- coding: utf-8 -*-
22
# File generated from our OpenAPI spec
3+
import json
4+
from stripe._api_version import _ApiVersion
35
from stripe._stripe_service import StripeService
46
from stripe._util import sanitize_id
57
from typing import Optional, cast
8+
from uuid import uuid4
69
from importlib import import_module
710
from typing_extensions import TYPE_CHECKING
811

@@ -397,3 +400,27 @@ async def search_async(
397400
options=options,
398401
),
399402
)
403+
404+
def serialize_batch_update(
405+
self,
406+
customer: str,
407+
params: Optional["CustomerUpdateParams"] = None,
408+
options: Optional["RequestOptions"] = None,
409+
) -> str:
410+
"""
411+
Serializes a Customer update request into a batch job JSONL line.
412+
"""
413+
item_id = str(uuid4())
414+
stripe_version = (
415+
options.get("stripe_version") if options else None
416+
) or _ApiVersion.CURRENT
417+
context = options.get("stripe_context") if options else None
418+
item = {
419+
"id": item_id,
420+
"path_params": {"customer": customer},
421+
"params": params,
422+
"stripe_version": stripe_version,
423+
}
424+
if context is not None:
425+
item["context"] = context
426+
return json.dumps(item)

stripe/_encode.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import datetime
33
import time
44
from collections import OrderedDict
5+
from decimal import Decimal
56
from typing import Any, Dict, Generator, Mapping, Optional, Tuple, Union
67

78

@@ -25,6 +26,8 @@ def _encode_nested_dict(key, data, fmt="%s[%s]"):
2526
def _json_encode_date_callback(value):
2627
if isinstance(value, datetime.datetime):
2728
return _encode_datetime(value)
29+
if isinstance(value, Decimal):
30+
return str(value)
2831
return value
2932

3033

@@ -82,6 +85,31 @@ def _coerce_int64_string(value: Any, *, encode: bool) -> Any:
8285
return value
8386

8487

88+
def _coerce_decimal_string(value: Any, *, encode: bool) -> Any:
89+
"""
90+
Coerce a decimal_string value in either direction.
91+
92+
encode=True: Decimal/int/float → str (request serialization)
93+
encode=False: str → Decimal (response hydration)
94+
"""
95+
if value is None:
96+
return None
97+
98+
if isinstance(value, list):
99+
return [_coerce_decimal_string(v, encode=encode) for v in value]
100+
101+
if encode:
102+
if isinstance(value, (Decimal, int, float)) and not isinstance(
103+
value, bool
104+
):
105+
return str(value)
106+
return value
107+
else:
108+
if isinstance(value, str):
109+
return Decimal(value)
110+
return value
111+
112+
85113
def _coerce_value(value: Any, schema: _SchemaNode) -> Any:
86114
"""Coerce a single value according to its schema node."""
87115
if value is None:
@@ -90,6 +118,9 @@ def _coerce_value(value: Any, schema: _SchemaNode) -> Any:
90118
if schema == "int64_string":
91119
return _coerce_int64_string(value, encode=True)
92120

121+
if schema == "decimal_string":
122+
return _coerce_decimal_string(value, encode=True)
123+
93124
if isinstance(schema, dict):
94125
# Nested object schema
95126
if isinstance(value, list):

stripe/_invoice_item.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# File generated from our OpenAPI spec
3+
from decimal import Decimal
34
from stripe._createable_api_resource import CreateableAPIResource
45
from stripe._deletable_api_resource import DeletableAPIResource
56
from stripe._expandable_field import ExpandableField
@@ -100,11 +101,12 @@ class PriceDetails(StripeObject):
100101
"""
101102
The type of the pricing details.
102103
"""
103-
unit_amount_decimal: Optional[str]
104+
unit_amount_decimal: Optional[Decimal]
104105
"""
105106
The unit amount (in the `currency` specified) of the item which contains a decimal value with at most 12 decimal places.
106107
"""
107108
_inner_class_types = {"price_details": PriceDetails}
109+
_field_encodings = {"unit_amount_decimal": "decimal_string"}
108110

109111
class ProrationDetails(StripeObject):
110112
class DiscountAmount(StripeObject):
@@ -205,7 +207,7 @@ class DiscountAmount(StripeObject):
205207
"""
206208
Quantity of units for the invoice item in integer format, with any decimal precision truncated. For the item's full-precision decimal quantity, use `quantity_decimal`. This field will be deprecated in favor of `quantity_decimal` in a future version. If the invoice item is a proration, the quantity of the subscription that the proration was computed for.
207209
"""
208-
quantity_decimal: str
210+
quantity_decimal: Decimal
209211
"""
210212
Non-negative decimal with at most 12 decimal places. The quantity of units for the invoice item.
211213
"""
@@ -450,3 +452,4 @@ async def retrieve_async(
450452
"pricing": Pricing,
451453
"proration_details": ProrationDetails,
452454
}
455+
_field_encodings = {"quantity_decimal": "decimal_string"}

stripe/_invoice_line_item.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# File generated from our OpenAPI spec
3+
from decimal import Decimal
34
from stripe._expandable_field import ExpandableField
45
from stripe._stripe_object import StripeObject
56
from stripe._updateable_api_resource import UpdateableAPIResource
@@ -190,11 +191,12 @@ class PriceDetails(StripeObject):
190191
"""
191192
The type of the pricing details.
192193
"""
193-
unit_amount_decimal: Optional[str]
194+
unit_amount_decimal: Optional[Decimal]
194195
"""
195196
The unit amount (in the `currency` specified) of the item which contains a decimal value with at most 12 decimal places.
196197
"""
197198
_inner_class_types = {"price_details": PriceDetails}
199+
_field_encodings = {"unit_amount_decimal": "decimal_string"}
198200

199201
class TaxCalculationReference(StripeObject):
200202
calculation_id: Optional[str]
@@ -325,7 +327,7 @@ class TaxRateDetails(StripeObject):
325327
"""
326328
Quantity of units for the invoice line item in integer format, with any decimal precision truncated. For the line item's full-precision decimal quantity, use `quantity_decimal`. This field will be deprecated in favor of `quantity_decimal` in a future version. If the line item is a proration or subscription, the quantity of the subscription that the proration was computed for.
327329
"""
328-
quantity_decimal: Optional[str]
330+
quantity_decimal: Optional[Decimal]
329331
"""
330332
Non-negative decimal with at most 12 decimal places. The quantity of units for the line item.
331333
"""
@@ -399,3 +401,4 @@ async def modify_async(
399401
"tax_calculation_reference": TaxCalculationReference,
400402
"taxes": Tax,
401403
}
404+
_field_encodings = {"quantity_decimal": "decimal_string"}

stripe/_invoice_service.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# -*- coding: utf-8 -*-
22
# File generated from our OpenAPI spec
3+
import json
4+
from stripe._api_version import _ApiVersion
35
from stripe._stripe_service import StripeService
46
from stripe._util import sanitize_id
57
from typing import Optional, cast
8+
from uuid import uuid4
69
from importlib import import_module
710
from typing_extensions import TYPE_CHECKING
811

@@ -847,3 +850,51 @@ async def create_preview_async(
847850
options=options,
848851
),
849852
)
853+
854+
def serialize_batch_update(
855+
self,
856+
invoice: str,
857+
params: Optional["InvoiceUpdateParams"] = None,
858+
options: Optional["RequestOptions"] = None,
859+
) -> str:
860+
"""
861+
Serializes an Invoice update request into a batch job JSONL line.
862+
"""
863+
item_id = str(uuid4())
864+
stripe_version = (
865+
options.get("stripe_version") if options else None
866+
) or _ApiVersion.CURRENT
867+
context = options.get("stripe_context") if options else None
868+
item = {
869+
"id": item_id,
870+
"path_params": {"invoice": invoice},
871+
"params": params,
872+
"stripe_version": stripe_version,
873+
}
874+
if context is not None:
875+
item["context"] = context
876+
return json.dumps(item)
877+
878+
def serialize_batch_pay(
879+
self,
880+
invoice: str,
881+
params: Optional["InvoicePayParams"] = None,
882+
options: Optional["RequestOptions"] = None,
883+
) -> str:
884+
"""
885+
Serializes an Invoice pay request into a batch job JSONL line.
886+
"""
887+
item_id = str(uuid4())
888+
stripe_version = (
889+
options.get("stripe_version") if options else None
890+
) or _ApiVersion.CURRENT
891+
context = options.get("stripe_context") if options else None
892+
item = {
893+
"id": item_id,
894+
"path_params": {"invoice": invoice},
895+
"params": params,
896+
"stripe_version": stripe_version,
897+
}
898+
if context is not None:
899+
item["context"] = context
900+
return json.dumps(item)

0 commit comments

Comments
 (0)