diff --git a/examples/README.md b/examples/README.md index c73c6149f..d70b4a6ba 100644 --- a/examples/README.md +++ b/examples/README.md @@ -3,9 +3,14 @@ From the examples folder, run: `PYTHONPATH=../ python your_example.py` +e.g. + +`PYTHONPATH=../ python thinevent_webhook_handler.py` + ## Adding a new example -1. Clone new_example.py +1. Clone example_template.py 2. Implement your example -3. Run it (as per above) -4. 👍 +3. Fill out the file comment. Include a description and key steps that are being demonstrated. +4. Run it (as per above) +5. 👍 diff --git a/examples/example_template.py b/examples/example_template.py new file mode 100644 index 000000000..8edbed126 --- /dev/null +++ b/examples/example_template.py @@ -0,0 +1,22 @@ +""" +example_template.py - This is a template for defining new examples. It is not intended to be used directly. + + + +In this example, we: + - + - +""" + +import stripe + +# Set your API key here +api_key = "{{API_KEY}}" + +print("Hello world") +# client = stripe.StripeClient(api_key) +# client.v2.... diff --git a/examples/meter_event_stream.py b/examples/meter_event_stream.py index 0d02bb9d8..852decf0e 100644 --- a/examples/meter_event_stream.py +++ b/examples/meter_event_stream.py @@ -1,3 +1,15 @@ +""" +meter_event_stream.py - use the high-throughput meter event stream to report create billing meter events. + +In this example, we: + - create a meter event session and store the session's authentication token + - define an event with a payload + - use the meter_event_stream service accessor in StripeClient to create an event stream that reports this event + +This example expects a billing meter with an event_name of 'alpaca_ai_tokens'. If you have +a different meter event name, you can change it before running this example. +""" + from datetime import datetime, timezone import stripe diff --git a/examples/new_example.py b/examples/new_example.py deleted file mode 100644 index 53a93e7e6..000000000 --- a/examples/new_example.py +++ /dev/null @@ -1,8 +0,0 @@ -import stripe - -# Set your API key here -api_key = "{{API_KEY}}" - -print("Hello world") -# client = stripe.StripeClient(api_key) -# client.v2.... diff --git a/examples/stripe_webhook_handler.py b/examples/thinevent_webhook_handler.py similarity index 68% rename from examples/stripe_webhook_handler.py rename to examples/thinevent_webhook_handler.py index e4452d9c7..f93e0a560 100644 --- a/examples/stripe_webhook_handler.py +++ b/examples/thinevent_webhook_handler.py @@ -1,3 +1,16 @@ +""" +thinevent_webhook_handler.py - receive and process thin events like the +v1.billing.meter.error_report_triggered event. + +In this example, we: + - create a StripeClient called client + - use client.parse_thin_event to parse the received thin event webhook body + - call client.v2.core.events.retrieve to retrieve the full event object + - if it is a V1BillingMeterErrorReportTriggeredEvent event type, call + event.fetchRelatedObject to retrieve the Billing Meter object associated + with the event. +""" + import os from stripe import StripeClient from stripe.events import V1BillingMeterErrorReportTriggeredEvent