Skip to content

Commit eb805ec

Browse files
Merge upstream and update generated code for v2042 and
2 parents 03b33d7 + 09248ae commit eb805ec

22 files changed

+244
-182
lines changed

API_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0de52cdca31a7c51c6d11187fc88ab23ea3a1c5b
1+
13e48677b8744cdd8170f92a48ed598952515497

OPENAPI_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2031
1+
v2042

examples/event_notification_webhook_handler.py

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
"""
2-
event_notification_webhook_handler.py - receive and process thin events like the
3-
v1.billing.meter.error_report_triggered event.
2+
event_notification_webhook_handler.py - receive and process event notifications (AKA thin events) like the v1.billing.meter.error_report_triggered and v1.billing.meter.no_meter_found events.
43
54
In this example, we:
65
- create a StripeClient called client
76
- use client.parse_event_notification() to parse the received notification webhook body
87
- if its type is "v1.billing.meter.error_report_triggered":
9-
- call event_notification.fetch_event() to retrieve the full event object
108
- call event_notification.fetch_related_object() to retrieve the Meter that failed
9+
- call event_notification.fetch_event() to retrieve the full event object
10+
- log info about the failure
11+
- if its type is "v1.billing.meter.no_meter_found":
12+
- call event_notification.fetch_event() to retrieve the full event object
1113
- log info about the failure
14+
- if the SDK doesn't have types for it, it will be an UnknownEventNotification:
15+
- optionally cast it to UnknownEventNotification to get more accurate typing
16+
- match on the type property to handle specific unknown event types
1217
"""
1318

1419
import os
1520
from stripe import StripeClient
16-
from stripe import Event
17-
from stripe.v2.core import Event as V2Event, EventNotification
18-
from stripe.events import (
19-
V2CoreEventDestinationPingEventNotification,
20-
V1BillingMeterErrorReportTriggeredEvent,
21-
UnknownEventNotification,
22-
ALL_EVENT_NOTIFICATIONS,
23-
)
21+
from stripe.events import UnknownEventNotification
2422

2523
from flask import Flask, request, jsonify
2624

@@ -37,22 +35,63 @@ def webhook():
3735
sig_header = request.headers.get("Stripe-Signature")
3836

3937
try:
40-
event_notification = client.parse_event_notification(
38+
event_notif = client.parse_event_notification(
4139
webhook_body, sig_header, webhook_secret
4240
)
4341

44-
# Fetch the event data to understand the failure
45-
if (
46-
event_notification.type
47-
== "v1.billing.meter.error_report_triggered"
48-
):
49-
meter = event_notification.fetch_related_object()
50-
event = event_notification.fetch_event()
42+
# type checkers will narrow the type based on the `type` property
43+
if event_notif.type == "v1.billing.meter.error_report_triggered":
44+
# in this block, event_notification is typed as
45+
# a V1BillingMeterErrorReportTriggeredEventNotification
46+
47+
# there's basic info about the related object in the notification
48+
print(f"Meter w/ id {event_notif.related_object.id} had a problem")
49+
50+
# or you can fetch the full object form the API for more details
51+
meter = event_notif.fetch_related_object()
52+
print(f"Meter {meter.display_name} ({meter.id}) had a problem")
53+
54+
# And you can always fetch the full event:
55+
event = event_notif.fetch_event()
56+
print(f"More info: {event.data.developer_message_summary}")
57+
58+
elif event_notif.type == "v1.billing.meter.no_meter_found":
59+
# in this block, event_notification is typed as
60+
# a V1BillingMeterNoMeterFoundEventNotification
61+
62+
# that class doesn't define `fetch_related_object` because the event
63+
# has no related object.
64+
# so this line would correctly give a type error:
65+
# meter = event_notif.fetch_related_object()
66+
67+
# but fetching the event always works:
68+
event = event_notif.fetch_event()
5169
print(
52-
f"Err! Meter {meter.id} had a problem (more info: {event.data.developer_message_summary})"
70+
f"Err! No meter found: {event.data.developer_message_summary}"
5371
)
54-
# Record the failures and alert your team
55-
# Add your logic here
72+
73+
# Events that were introduced after this SDK version release are
74+
# represented as `UnknownEventNotification`s.
75+
# They're valid, the SDK just doesn't have corresponding classes for them.
76+
# You must match on the "type" property instead.
77+
elif isinstance(event_notif, UnknownEventNotification):
78+
# these lines are optional, but will give you more accurate typing in this block
79+
from typing import cast
80+
81+
event_notif = cast(UnknownEventNotification, event_notif)
82+
83+
# continue matching on the type property
84+
# from this point on, the `related_object` property _may_ be None
85+
# (depending on the event type)
86+
if event_notif.type == "some.new.event":
87+
# if this event type has a related object, you can fetch it
88+
obj = event_notif.fetch_related_object()
89+
# otherwise, `obj` will just be `None`
90+
print(f"Related object: {obj}")
91+
92+
# you can still fetch the full event, but it will be untyped
93+
event = event_notif.fetch_event()
94+
print(f"New event: {event.data}") # type: ignore
5695

5796
return jsonify(success=True), 200
5897
except Exception as e:

stripe/_charge.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,10 @@ class Qris(StripeObject):
18821882
pass
18831883

18841884
class Rechnung(StripeObject):
1885-
pass
1885+
payment_portal_url: Optional[str]
1886+
"""
1887+
Payment portal URL.
1888+
"""
18861889

18871890
class RevolutPay(StripeObject):
18881891
class Funding(StripeObject):

stripe/_file.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class File(CreateableAPIResource["File"], ListableAPIResource["File"]):
6363
"identity_document_downloadable",
6464
"issuing_regulatory_reporting",
6565
"pci_document",
66+
"platform_terms_of_service",
6667
"selfie",
6768
"sigma_scheduled_query",
6869
"tax_document_user_upload",

stripe/_payment_attempt_record.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,10 @@ class Qris(StripeObject):
15531553
pass
15541554

15551555
class Rechnung(StripeObject):
1556-
pass
1556+
payment_portal_url: Optional[str]
1557+
"""
1558+
Payment portal URL.
1559+
"""
15571560

15581561
class RevolutPay(StripeObject):
15591562
class Funding(StripeObject):

stripe/_payment_method_configuration.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,28 @@ class DisplayPreference(StripeObject):
732732
display_preference: DisplayPreference
733733
_inner_class_types = {"display_preference": DisplayPreference}
734734

735+
class MbWay(StripeObject):
736+
class DisplayPreference(StripeObject):
737+
overridable: Optional[bool]
738+
"""
739+
For child configs, whether or not the account's preference will be observed. If `false`, the parent configuration's default is used.
740+
"""
741+
preference: Literal["none", "off", "on"]
742+
"""
743+
The account's display preference.
744+
"""
745+
value: Literal["off", "on"]
746+
"""
747+
The effective display preference value.
748+
"""
749+
750+
available: bool
751+
"""
752+
Whether this payment method may be offered at checkout. True if `display_preference` is `on` and the payment method's capability is active.
753+
"""
754+
display_preference: DisplayPreference
755+
_inner_class_types = {"display_preference": DisplayPreference}
756+
735757
class Mobilepay(StripeObject):
736758
class DisplayPreference(StripeObject):
737759
overridable: Optional[bool]
@@ -1355,6 +1377,7 @@ class DisplayPreference(StripeObject):
13551377
"""
13561378
Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
13571379
"""
1380+
mb_way: Optional[MbWay]
13581381
mobilepay: Optional[Mobilepay]
13591382
multibanco: Optional[Multibanco]
13601383
name: str
@@ -1562,6 +1585,7 @@ async def retrieve_async(
15621585
"konbini": Konbini,
15631586
"kr_card": KrCard,
15641587
"link": Link,
1588+
"mb_way": MbWay,
15651589
"mobilepay": Mobilepay,
15661590
"multibanco": Multibanco,
15671591
"naver_pay": NaverPay,

stripe/_payment_record.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,10 @@ class Qris(StripeObject):
15661566
pass
15671567

15681568
class Rechnung(StripeObject):
1569-
pass
1569+
payment_portal_url: Optional[str]
1570+
"""
1571+
Payment portal URL.
1572+
"""
15701573

15711574
class RevolutPay(StripeObject):
15721575
class Funding(StripeObject):

stripe/events/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
V1BillingMeterNoMeterFoundEvent as V1BillingMeterNoMeterFoundEvent,
1717
V1BillingMeterNoMeterFoundEventNotification as V1BillingMeterNoMeterFoundEventNotification,
1818
)
19-
from stripe.events._v2_billing_bill_setting_updated_event import (
20-
V2BillingBillSettingUpdatedEvent as V2BillingBillSettingUpdatedEvent,
21-
V2BillingBillSettingUpdatedEventNotification as V2BillingBillSettingUpdatedEventNotification,
22-
)
2319
from stripe.events._v2_core_account_closed_event import (
2420
V2CoreAccountClosedEvent as V2CoreAccountClosedEvent,
2521
V2CoreAccountClosedEventNotification as V2CoreAccountClosedEventNotification,

stripe/events/_event_classes.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
V1BillingMeterNoMeterFoundEvent,
1010
V1BillingMeterNoMeterFoundEventNotification,
1111
)
12-
from stripe.events._v2_billing_bill_setting_updated_event import (
13-
V2BillingBillSettingUpdatedEvent,
14-
V2BillingBillSettingUpdatedEventNotification,
15-
)
1612
from stripe.events._v2_core_account_closed_event import (
1713
V2CoreAccountClosedEvent,
1814
V2CoreAccountClosedEventNotification,
@@ -262,7 +258,6 @@
262258
V2_EVENT_CLASS_LOOKUP = {
263259
V1BillingMeterErrorReportTriggeredEvent.LOOKUP_TYPE: V1BillingMeterErrorReportTriggeredEvent,
264260
V1BillingMeterNoMeterFoundEvent.LOOKUP_TYPE: V1BillingMeterNoMeterFoundEvent,
265-
V2BillingBillSettingUpdatedEvent.LOOKUP_TYPE: V2BillingBillSettingUpdatedEvent,
266261
V2CoreAccountClosedEvent.LOOKUP_TYPE: V2CoreAccountClosedEvent,
267262
V2CoreAccountCreatedEvent.LOOKUP_TYPE: V2CoreAccountCreatedEvent,
268263
V2CoreAccountIncludingConfigurationCustomerCapabilityStatusUpdatedEvent.LOOKUP_TYPE: V2CoreAccountIncludingConfigurationCustomerCapabilityStatusUpdatedEvent,
@@ -329,7 +324,6 @@
329324
V2_EVENT_NOTIFICATION_CLASS_LOOKUP = {
330325
V1BillingMeterErrorReportTriggeredEventNotification.LOOKUP_TYPE: V1BillingMeterErrorReportTriggeredEventNotification,
331326
V1BillingMeterNoMeterFoundEventNotification.LOOKUP_TYPE: V1BillingMeterNoMeterFoundEventNotification,
332-
V2BillingBillSettingUpdatedEventNotification.LOOKUP_TYPE: V2BillingBillSettingUpdatedEventNotification,
333327
V2CoreAccountClosedEventNotification.LOOKUP_TYPE: V2CoreAccountClosedEventNotification,
334328
V2CoreAccountCreatedEventNotification.LOOKUP_TYPE: V2CoreAccountCreatedEventNotification,
335329
V2CoreAccountIncludingConfigurationCustomerCapabilityStatusUpdatedEventNotification.LOOKUP_TYPE: V2CoreAccountIncludingConfigurationCustomerCapabilityStatusUpdatedEventNotification,
@@ -396,7 +390,6 @@
396390
ALL_EVENT_NOTIFICATIONS = Union[
397391
V1BillingMeterErrorReportTriggeredEventNotification,
398392
V1BillingMeterNoMeterFoundEventNotification,
399-
V2BillingBillSettingUpdatedEventNotification,
400393
V2CoreAccountClosedEventNotification,
401394
V2CoreAccountCreatedEventNotification,
402395
V2CoreAccountIncludingConfigurationCustomerCapabilityStatusUpdatedEventNotification,

0 commit comments

Comments
 (0)