fix: metadata extraction in Stripe checkout session#1347
Conversation
- Updated the `_get_metadata` function to handle changes in the Stripe SDK, specifically for `StripeObject` which is no longer a subclass of `dict` in `stripe>=15.0`. - Implemented a fallback mechanism in `finalize_checkout` to recover purchase type from the database if metadata extraction fails, ensuring robust handling of checkout sessions.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe pull request enhances the robustness of Stripe metadata extraction in ChangesStripe Metadata Extraction & Fallback
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
_get_metadatafunction to handle changes in the Stripe SDK, specifically forStripeObjectwhich is no longer a subclass ofdictinstripe>=15.0.finalize_checkoutto recover purchase type from the database if metadata extraction fails, ensuring robust handling of checkout sessions.Description
Motivation and Context
FIX #
Screenshots
API Changes
Change Type
Testing Performed
Checklist
High-level PR Summary
This PR fixes metadata extraction issues in Stripe checkout sessions caused by breaking changes in the Stripe SDK version 15.0 and above. The
_get_metadatafunction has been rewritten to handle three different scenarios: plain dictionaries (older SDKs), modernStripeObjectinstances using theto_dict()method, and a fallback to the private_dataattribute. Additionally, a defensive fallback mechanism was added to thefinalize_checkoutfunction that queries the database to recover the purchase type when metadata extraction fails, preventing purchases from being incorrectly routed or getting stuck.⏱️ Estimated Review Time: 5-15 minutes
💡 Review Order Suggestion
surfsense_backend/app/routes/stripe_routes.pySummary by CodeRabbit