fix: (#764) fundraising subscription cancellation issue - Handle Donation Cancellations with Subscription ID Prefixing #1706
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.
Overview
Issue - #764
This pull request introduces a new approach to managing donation cancellations by appending a prefix ("c") to the stripe_subscription_id of donations that have been requested for cancellation. This method aims to improve our handling of webhook events and ensure that our database remains in sync with Stripe's subscription status.
Key Changes
def cancel_donation(request, hero):
When a donation is canceled, the stripe_subscription_id is prefixed with
"cancel"
to indicate that a cancellation has been initiated.This allows us to easily identify donations that are in the process of being canceled but may not yet have received confirmation from Stripe.
Webhook Handling:
def subscription_cancelled(self):
inclass WebhookHandler:
The subscription_cancelled method in the webhook handler is updated to look for donations with the prefixed stripe_subscription_id.
The method constructs the prefixed ID when querying the donation, ensuring that the lookup reflects the current state of the database. And finally sets it to
""
.Data Integrity:
By using a prefix, we can filter donations that have initiated cancellation without losing the original subscription ID.
Once the webhook processes successfully, it will clear the stripe_subscription_id, ensuring the database is accurately updated.
Concerns Addressed
Webhook Failure:
If the webhook fails to deliver the cancellation event, the prefixed IDs will allow us to identify donations that are pending cancellation. This can help with future cleanup processes or notifications to users.
Webhook Success:
If the webhook processes successfully, the prefixed IDs will be updated to reflect the cancellation (to
""
), effectively maintaining data integrity and consistency within the application.Assumptions
The webhook is reliable, but we need to account for potential delivery failures. The prefixing approach serves as a safeguard against this possibility.
Conclusion
This implementation enhances our ability to manage donation cancellations efficiently while addressing potential issues with webhook delivery. The prefixing strategy offers a straightforward way to track pending cancellations and maintain synchronization between our database and Stripe.