Add Slack revenue notifications to Stripe webhook (invoice.payment_succeeded)#359
Open
Copilot wants to merge 3 commits into
Open
Add Slack revenue notifications to Stripe webhook (invoice.payment_succeeded)#359Copilot wants to merge 3 commits into
invoice.payment_succeeded)#359Copilot wants to merge 3 commits into
Conversation
Copilot created this pull request from a session on behalf of
LVT-ENG
June 3, 2026 09:48
View session
Member
|
Supercommit_max.sh |
Member
|
Supercommit_maxsh |
There was a problem hiding this comment.
Pull request overview
This PR extends the existing Flask /api/webhook Stripe webhook handler to emit a Slack Incoming Webhook notification when an invoice.payment_succeeded event is received, and adds unit tests to validate the behavior and error handling.
Changes:
- Handle
invoice.payment_succeededin/api/webhookby extractingamount_paid,currency, anddescription, then calling a Slack notifier. - Add
notify_slack(amount, currency, message)to send a structured Slack webhook payload (and no-op whenSLACK_WEBHOOK_URLis unset). - Add
tests/test_stripe_webhook.pyto cover Slack-notification behavior, ignored event types, and invalid payload handling.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
api/index.py |
Adds Slack notification helper, reads SLACK_WEBHOOK_URL, and processes invoice.payment_succeeded events in the Stripe webhook handler. |
tests/test_stripe_webhook.py |
Adds unit tests for the Stripe webhook route and Slack notification behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| amount_paid = 0 | ||
| currency = str(invoice.get("currency", "")).upper() | ||
| description = str(invoice.get("description") or "Pago de cliente confirmado") | ||
| notify_slack(amount_paid / 100, currency, description) |
Comment on lines
+363
to
+367
| response = requests.post(SLACK_WEBHOOK_URL, json=payload, timeout=5) | ||
| return response.status_code == 200 | ||
| except requests.RequestException as e: | ||
| print(f"[tryonyou] slack webhook error: {e}", file=sys.stderr) | ||
| return False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This updates the Stripe webhook flow so confirmed invoice payments are surfaced in Slack in real time, using server-side signature validation and environment-scoped secrets. The webhook now emits structured payment notifications only for
invoice.payment_succeededevents.Webhook event handling
/api/webhookto processinvoice.payment_succeeded(instead of a no-op path).amount_paid,currency, and invoice description from the Stripe payload.Slack integration (server-mediated)
notify_slack(amount, currency, message)inapi/index.py.SLACK_WEBHOOK_URLis unset and handles request failures safely.Runtime configuration and secrets
STRIPE_SECRET_KEY,STRIPE_ENDPOINT_SECRET, andSLACK_WEBHOOK_URLfrom environment variables.