Skip to content

Commit

Permalink
Merge pull request #1407 from stripe/jar/update-beta-branch
Browse files Browse the repository at this point in the history
Updates beta branch with changes in master
  • Loading branch information
jar-stripe authored Oct 2, 2024
2 parents 7e4cf74 + 77aaaf2 commit 0861c88
Show file tree
Hide file tree
Showing 109 changed files with 4,481 additions and 792 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ indent_size = 2

[Makefile]
indent_style = tab

[CHANGELOG.md]
trim_trailing_whitespace = false
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
}
},

"[markdown]": {
"editor.formatOnSave": false,
},

// Tests
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
Expand Down
54 changes: 43 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
# Changelog

## 11.0.0 - 2024-10-01
* [#1404](https://github.com/stripe/stripe-python/pull/1404) Support for APIs in the new API version 2024-09-30.acacia

This release changes the pinned API version to `2024-09-30.acacia`. Please read the [API Upgrade Guide](https://stripe.com/docs/upgrades#2024-09-30.acacia) and carefully review the API changes before upgrading.

### ⚠️ Breaking changes due to changes in the API


* Rename for `usage_threshold_config` to `usage_threshold` on parameter class `stripe.billing.Alert.CreateParams` and resource `stripe.billing.Alert`
* Remove support for `filter` on parameter class `stripe.billing.Alert.CreateParams` and resource `stripe.billing.Alert`. Use the filters on the `usage_threshold` instead
* * Remove support for `customer_consent_collected` on parameter class `stripe.terminal.Reader.ProcessSetupIntentParams`

### ⚠️ Other Breaking changes in the SDK
* Adjusted default values for HTTP requests. You can use the old defaults by setting them explicitly. New values are:
- max retries: `0` -> `2`
- max timeout (seconds): `2` -> `5`
* Add method `parse_thin_event()` on the `StripeClient` class to parse [thin events](https://docs.corp.stripe.com/event-destinations#events-overview). Rename `construct_event()` method on the same class to `parse_snapshot_event()` to clearly distinguish between the two kinds of events.

### Additions

* Add support for `custom_unit_amount` on parameter class `stripe.Product.CreateParamsDefaultPriceData`
* Add support for `usage_threshold` on parameter class `stripe.billing.Alert.CreateParams` and resource `stripe.billing.Alert`
* Add support for `allow_redisplay` on parameter classes `stripe.terminal.Reader.ProcessPaymentIntentParamsProcessConfig` and `stripe.terminal.Reader.ProcessSetupIntentParams`
* Add support for `international_transaction` on enum `stripe.treasury.ReceivedCredit.failure_code`
* Add support for `2024-09-30.acacia` on enum `stripe.WebhookEndpoint.CreateParams.api_version`
* Add support for new Usage Billing APIs `stripe.v2.billing.MeterEvent`, `stripe.v2.billing.MeterEventAdjustments`, `stripe.v2.billing.MeterEventSession`, `stripe.v2.billing.MeterEventStream` and the new Events API `stripe.v2.core.Events` under the [v2 namespace ](https://docs.corp.stripe.com/api-v2-overview)
* Add method [rawRequest()](https://github.com/stripe/stripe-python/tree/master?tab=readme-ov-file#custom-requests) on the `StripeClient` class that takes a HTTP method type, url and relevant parameters to make requests to the Stripe API that are not yet supported in the SDK.

### Other changes
* Change type of `default_allowed_updates` on `stripe.billing_portal.Configuration.CreateParamsFeaturesSubscriptionUpdate` from `Union[Literal[''], List[Literal['price', 'promotion_code', 'quantity']]]` to `NotRequired[Literal['']|List[Literal['price', 'promotion_code', 'quantity']]]`
* Change type of `products` on `stripe.billing_portal.Configuration.CreateParamsFeaturesSubscriptionUpdate` from `Union[Literal[''], List[Configuration.CreateParamsFeaturesSubscriptionUpdateProduct]]` to `NotRequired[Literal['']|List[Configuration.CreateParamsFeaturesSubscriptionUpdateProduct]]`

## 10.13.0b1 - 2024-09-18
* [#1395](https://github.com/stripe/stripe-python/pull/1395) Update generated code for beta
* Add support for `send_money` on parameter class `stripe.AccountSession.CreateParamsComponentsFinancialAccountFeatures`
Expand Down Expand Up @@ -105,11 +137,11 @@

## 10.8.0b1 - 2024-08-12
* [#1372](https://github.com/stripe/stripe-python/pull/1372) Update generated code for beta
* Add support for `capital_financing` on resource class `stripe.AccountSession.Components`
* Add support for `payto` on parameter class `stripe.checkout.Session.CreateParamsPaymentMethodOptions` and resource class `stripe.checkout.Session.PaymentMethodOptions`
* ⚠️ Remove support for `risk_correlation_id` on parameter classes `stripe.PaymentIntent.ConfirmParamsPaymentMethodOptionsRechnung`, `stripe.PaymentIntent.CreateParamsPaymentMethodOptionsRechnung`, and `stripe.PaymentIntent.ModifyParamsPaymentMethodOptionsRechnung` and resource class `stripe.PaymentIntent.PaymentMethodOptions.Rechnung`
* Add support for `custom` on enums `stripe.checkout.Session.ui_mode` and `stripe.checkout.Session.CreateParams.ui_mode`
* Add support for `payto` on enums `stripe.checkout.Session.CreateParams.payment_method_types`, `stripe.PaymentLink.payment_method_types`, `stripe.PaymentLink.CreateParams.payment_method_types`, and `stripe.PaymentLink.ModifyParams.payment_method_types`
* Add support for `capital_financing` on resource class `stripe.AccountSession.Components`
* Add support for `payto` on parameter class `stripe.checkout.Session.CreateParamsPaymentMethodOptions` and resource class `stripe.checkout.Session.PaymentMethodOptions`
* ⚠️ Remove support for `risk_correlation_id` on parameter classes `stripe.PaymentIntent.ConfirmParamsPaymentMethodOptionsRechnung`, `stripe.PaymentIntent.CreateParamsPaymentMethodOptionsRechnung`, and `stripe.PaymentIntent.ModifyParamsPaymentMethodOptionsRechnung` and resource class `stripe.PaymentIntent.PaymentMethodOptions.Rechnung`
* Add support for `custom` on enums `stripe.checkout.Session.ui_mode` and `stripe.checkout.Session.CreateParams.ui_mode`
* Add support for `payto` on enums `stripe.checkout.Session.CreateParams.payment_method_types`, `stripe.PaymentLink.payment_method_types`, `stripe.PaymentLink.CreateParams.payment_method_types`, and `stripe.PaymentLink.ModifyParams.payment_method_types`
* Add support for `invalid_mandate_reference_prefix_format` on enum `stripe.QuotePreviewInvoice.LastFinalizationError.code`

## 10.7.0 - 2024-08-08
Expand Down Expand Up @@ -217,12 +249,12 @@

## 10.3.0b1 - 2024-07-05
* [#1355](https://github.com/stripe/stripe-python/pull/1355) Update generated code for beta
* ⚠️ Remove support for `payment_method_update` on resource class `stripe.CustomerSession.Components.PaymentElement.Features` and parameter class `stripe.CustomerSession.CreateParamsComponentsPaymentElementFeatures`. Users are expected to completely migrate from using payment_method_update.
* Add support for `payment_method_allow_redisplay_filters`, `payment_method_redisplay`, `payment_method_save_usage` on resource class `stripe.CustomerSession.Components.PaymentElement.Features` and parameter class `stripe.CustomerSession.CreateParamsComponentsPaymentElementFeatures`
* Add support for `institution` on parameter classes `stripe.Invoice.CreateParamsPaymentSettingsPaymentMethodOptionsUsBankAccountFinancialConnectionsFilters`, `stripe.Invoice.ModifyParamsPaymentSettingsPaymentMethodOptionsUsBankAccountFinancialConnectionsFilters`, `stripe.PaymentIntent.ConfirmParamsPaymentMethodOptionsUsBankAccountFinancialConnectionsFilters`, `stripe.PaymentIntent.CreateParamsPaymentMethodOptionsUsBankAccountFinancialConnectionsFilters`, `stripe.PaymentIntent.ModifyParamsPaymentMethodOptionsUsBankAccountFinancialConnectionsFilters`, `stripe.SetupIntent.ConfirmParamsPaymentMethodOptionsUsBankAccountFinancialConnectionsFilters`, `stripe.SetupIntent.CreateParamsPaymentMethodOptionsUsBankAccountFinancialConnectionsFilters`, `stripe.SetupIntent.ModifyParamsPaymentMethodOptionsUsBankAccountFinancialConnectionsFilters`, `stripe.Subscription.CreateParamsPaymentSettingsPaymentMethodOptionsUsBankAccountFinancialConnectionsFilters`, `stripe.Subscription.ModifyParamsPaymentSettingsPaymentMethodOptionsUsBankAccountFinancialConnectionsFilters`, and `stripe.financial_connections.Session.CreateParamsFilters` and resource classes `stripe.Invoice.PaymentSettings.PaymentMethodOptions.UsBankAccount.FinancialConnections.Filters`, `stripe.PaymentIntent.PaymentMethodOptions.UsBankAccount.FinancialConnections.Filters`, `stripe.QuotePreviewInvoice.PaymentSettings.PaymentMethodOptions.UsBankAccount.FinancialConnections.Filters`, `stripe.SetupIntent.PaymentMethodOptions.UsBankAccount.FinancialConnections.Filters`, `stripe.Subscription.PaymentSettings.PaymentMethodOptions.UsBankAccount.FinancialConnections.Filters`, `stripe.checkout.Session.PaymentMethodOptions.UsBankAccount.FinancialConnections.Filters`, and `stripe.financial_connections.Session.Filters`
* Add support for resource `stripe.financial_connections.Institution`
* Add support for `balance` on enums `stripe.financial_connections.Account.subscriptions`, `stripe.financial_connections.Account.SubscribeParams.features`, and `stripe.financial_connections.Account.UnsubscribeParams.features`
* Add support for `financial_connections_institution_unavailable` on enums `stripe.Invoice.LastFinalizationError.code`, `stripe.PaymentIntent.LastPaymentError.code`, `stripe.QuotePreviewInvoice.LastFinalizationError.code`, `stripe.SetupAttempt.SetupError.code`, and `stripe.SetupIntent.LastSetupError.code`
* ⚠️ Remove support for `payment_method_update` on resource class `stripe.CustomerSession.Components.PaymentElement.Features` and parameter class `stripe.CustomerSession.CreateParamsComponentsPaymentElementFeatures`. Users are expected to completely migrate from using payment_method_update.
* Add support for `payment_method_allow_redisplay_filters`, `payment_method_redisplay`, `payment_method_save_usage` on resource class `stripe.CustomerSession.Components.PaymentElement.Features` and parameter class `stripe.CustomerSession.CreateParamsComponentsPaymentElementFeatures`
* Add support for `institution` on parameter classes `stripe.Invoice.CreateParamsPaymentSettingsPaymentMethodOptionsUsBankAccountFinancialConnectionsFilters`, `stripe.Invoice.ModifyParamsPaymentSettingsPaymentMethodOptionsUsBankAccountFinancialConnectionsFilters`, `stripe.PaymentIntent.ConfirmParamsPaymentMethodOptionsUsBankAccountFinancialConnectionsFilters`, `stripe.PaymentIntent.CreateParamsPaymentMethodOptionsUsBankAccountFinancialConnectionsFilters`, `stripe.PaymentIntent.ModifyParamsPaymentMethodOptionsUsBankAccountFinancialConnectionsFilters`, `stripe.SetupIntent.ConfirmParamsPaymentMethodOptionsUsBankAccountFinancialConnectionsFilters`, `stripe.SetupIntent.CreateParamsPaymentMethodOptionsUsBankAccountFinancialConnectionsFilters`, `stripe.SetupIntent.ModifyParamsPaymentMethodOptionsUsBankAccountFinancialConnectionsFilters`, `stripe.Subscription.CreateParamsPaymentSettingsPaymentMethodOptionsUsBankAccountFinancialConnectionsFilters`, `stripe.Subscription.ModifyParamsPaymentSettingsPaymentMethodOptionsUsBankAccountFinancialConnectionsFilters`, and `stripe.financial_connections.Session.CreateParamsFilters` and resource classes `stripe.Invoice.PaymentSettings.PaymentMethodOptions.UsBankAccount.FinancialConnections.Filters`, `stripe.PaymentIntent.PaymentMethodOptions.UsBankAccount.FinancialConnections.Filters`, `stripe.QuotePreviewInvoice.PaymentSettings.PaymentMethodOptions.UsBankAccount.FinancialConnections.Filters`, `stripe.SetupIntent.PaymentMethodOptions.UsBankAccount.FinancialConnections.Filters`, `stripe.Subscription.PaymentSettings.PaymentMethodOptions.UsBankAccount.FinancialConnections.Filters`, `stripe.checkout.Session.PaymentMethodOptions.UsBankAccount.FinancialConnections.Filters`, and `stripe.financial_connections.Session.Filters`
* Add support for resource `stripe.financial_connections.Institution`
* Add support for `balance` on enums `stripe.financial_connections.Account.subscriptions`, `stripe.financial_connections.Account.SubscribeParams.features`, and `stripe.financial_connections.Account.UnsubscribeParams.features`
* Add support for `financial_connections_institution_unavailable` on enums `stripe.Invoice.LastFinalizationError.code`, `stripe.PaymentIntent.LastPaymentError.code`, `stripe.QuotePreviewInvoice.LastFinalizationError.code`, `stripe.SetupAttempt.SetupError.code`, and `stripe.SetupIntent.LastSetupError.code`
* Add support for `payment_intent_fx_quote_invalid` on enum `stripe.QuotePreviewInvoice.LastFinalizationError.code`

## 10.2.0 - 2024-07-05
Expand Down
2 changes: 1 addition & 1 deletion OPENAPI_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1267
v1268
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,16 @@ stripe.add_beta_version("feature_beta", "v3")
### Custom requests
If you would like to send a request to an undocumented API (for example you are in a private beta), or if you prefer to bypass the method definitions in the library and specify your request details directly, you can use the `raw_request` method on `stripe`.
If you would like to send a request to an undocumented API (for example you are in a private beta), or if you prefer to bypass the method definitions in the library and specify your request details directly, you can use the `raw_request` method on `StripeClient`.
```python
response = stripe.raw_request(
client = StripeClient("sk_test_...")
response = client.raw_request(
"post", "/v1/beta_endpoint", param=123, stripe_version="2022-11-15; feature_beta=v3"
)
# (Optional) response is a StripeResponse. You can use `stripe.deserialize` to get a StripeObject.
deserialized_resp = stripe.deserialize(response)
# (Optional) response is a StripeResponse. You can use `client.deserialize` to get a StripeObject.
deserialized_resp = client.deserialize(response, api_mode='V1')
```
### Async
Expand Down
11 changes: 11 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Running an example

From the examples folder, run:
`PYTHONPATH=../ python your_example.py`

## Adding a new example

1. Clone new_example.py
2. Implement your example
3. Run it (as per above)
4. 👍
44 changes: 44 additions & 0 deletions examples/meter_event_stream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from datetime import datetime, timezone
import stripe

# Global variable for the meter event session
meter_event_session = None


def refresh_meter_event_session(api_key):
global meter_event_session

# Check if the session is None or expired
if meter_event_session is None or datetime.fromisoformat(
meter_event_session["expires_at"]
) <= datetime.now(timezone.utc):
# Create a new meter event session if the existing session has expired
client = stripe.StripeClient(api_key)
meter_event_session = client.v2.billing.meter_event_session.create()


def send_meter_event(meter_event, api_key):
# Refresh the meter event session if necessary
refresh_meter_event_session(api_key)
if not meter_event_session:
raise RuntimeError("Unable to refresh meter event session")

# Create a meter event with the current session's authentication token
client = stripe.StripeClient(meter_event_session["authentication_token"])
client.v2.billing.meter_event_stream.create(
params={"events": [meter_event]}
)


# Set your API key here
api_key = "{{API_KEY}}"
customer_id = "{{CUSTOMER_ID}}"

# Send meter event
send_meter_event(
{
"event_name": "alpaca_ai_tokens",
"payload": {"stripe_customer_id": customer_id, "value": "25"},
},
api_key,
)
8 changes: 8 additions & 0 deletions examples/new_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import stripe

# Set your API key here
api_key = "{{API_KEY}}"

print("Hello world")
# client = stripe.StripeClient(api_key)
# client.v2....
15 changes: 15 additions & 0 deletions examples/raw_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from stripe import StripeClient

# Set your API key here
api_key = "{{API_KEY}}"

client = StripeClient(api_key)
response = client.raw_request(
"post",
"/v1/beta_endpoint",
param=123,
stripe_version="2022-11-15; feature_beta=v3",
)

# (Optional) response is a StripeResponse. You can use `client.deserialize` to get a StripeObject.
deserialized_resp = client.deserialize(response, api_mode="V1")
40 changes: 40 additions & 0 deletions examples/stripe_webhook_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
from stripe import StripeClient
from stripe.events import V1BillingMeterErrorReportTriggeredEvent

from flask import Flask, request, jsonify

app = Flask(__name__)
api_key = os.environ.get("STRIPE_API_KEY")
webhook_secret = os.environ.get("WEBHOOK_SECRET")

client = StripeClient(api_key)


@app.route("/webhook", methods=["POST"])
def webhook():
webhook_body = request.data
sig_header = request.headers.get("Stripe-Signature")

try:
thin_event = client.parse_thin_event(
webhook_body, sig_header, webhook_secret
)

# Fetch the event data to understand the failure
event = client.v2.core.events.retrieve(thin_event.id)
if isinstance(event, V1BillingMeterErrorReportTriggeredEvent):
meter = event.fetch_related_object()
meter_id = meter.id
print("Success! " + str(meter_id))

# Record the failures and alert your team
# Add your logic here

return jsonify(success=True), 200
except Exception as e:
return jsonify(error=str(e)), 400


if __name__ == "__main__":
app.run(port=4242)
Loading

0 comments on commit 0861c88

Please sign in to comment.