Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set proper expiry time for stripe orders #2589

Merged
merged 1 commit into from
Jul 22, 2024

Conversation

pavelbrm
Copy link
Contributor

@pavelbrm pavelbrm commented Jul 5, 2024

Summary

This PR updates the handling of the Stripe webhooks, improving on how it's done as well as setting the expiry time on orders more accurately.

Main Changes

  • the invoice.updated webhook is now completely ignored, as it has never had any useful processing;
  • the order expiry date is now set up to the expiry date from an invoice.paid event plus a leeway (for the case if the next billing cycle's event has been delayed for whatever reason);
  • the code is prepared for handling the subscription cancellation events.

Type of Change

  • Product feature
  • Bug fix
  • Performance improvement
  • Refactor
  • Other

Tested Environments

  • Development
  • Staging
  • Production

Before Requesting Review

  • Does your code build cleanly without any errors or warnings?
  • Have you used auto closing keywords?
  • Have you added tests for new functionality?
  • Have validated query efficiency for new database queries?
  • Have documented new functionality in README or in comments?
  • Have you squashed all intermediate commits?
  • Is there a clear title that explains what the PR does?
  • Have you used intuitive function, variable and other naming?
  • Have you requested security and/or privacy review if needed
  • Have you performed a self review of this PR?

Manual Test Plan


@pavelbrm pavelbrm changed the base branch from master to fix-receipt-order-expiry-01 July 5, 2024 09:16
@pavelbrm pavelbrm self-assigned this Jul 5, 2024
@pavelbrm pavelbrm marked this pull request as ready for review July 11, 2024 09:19
@pavelbrm pavelbrm changed the title fix: fix expiration for stripe orders fix: set proper expiry time for stripe orders Jul 11, 2024
@pavelbrm pavelbrm requested a review from clD11 July 11, 2024 13:10
Copy link
Contributor

@clD11 clD11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work. Approved

Base automatically changed from fix-receipt-order-expiry-01 to fix-android-webhooks-01 July 16, 2024 12:42
Base automatically changed from fix-android-webhooks-01 to master July 18, 2024 12:00
@pavelbrm pavelbrm force-pushed the fix-receipt-order-expiry-02 branch from 368a7a7 to dec08dd Compare July 18, 2024 13:34
Copy link

[puLL-Merge] - brave-intl/bat-go@2589

Description

This PR refactors the Stripe webhook handling logic in the SKUs service. It introduces a new stripeNotification struct and associated methods to parse and process Stripe events more efficiently. The changes aim to improve error handling, logging, and overall code organization for Stripe-related operations.

Possible Issues

  1. The PR removes some existing error handling and logging statements. This might reduce visibility into certain edge cases if not properly replaced by new logging mechanisms.
  2. The new parseStripeNotification function might not cover all possible Stripe event types, potentially leading to unhandled cases.

Security Hotspots

No significant security vulnerabilities were identified in this change. However, careful review of the webhook signature verification and event parsing logic is always recommended when dealing with external payment processing systems.

Changes

Changes

  1. services/skus/controllers.go:

    • Refactored handleStripeWebhook function to use the new stripeNotification struct.
    • Improved error handling and logging.
    • Removed direct handling of specific event types in favor of a more generic approach.
  2. services/skus/order.go:

    • Removed constants for Stripe webhook event types.
    • Removed RenewOrder method, likely replaced by new functionality.
  3. services/skus/service.go:

    • Added processStripeNotification and processStripeNotificationTx methods to handle Stripe notifications.
    • Implemented logic for renewing and canceling orders based on Stripe events.
  4. services/skus/service_nonint_test.go:

    • Added extensive unit tests for the new Stripe notification processing logic.
  5. services/skus/stripe.go (new file):

    • Introduced stripeNotification struct and associated methods for parsing and processing Stripe events.
    • Implemented helper functions for extracting relevant information from Stripe events.
  6. services/skus/stripe_test.go (new file):

    • Added comprehensive unit tests for the new Stripe notification parsing and processing logic.
  7. services/skus/testdata/ (new directory):

    • Added JSON files containing sample Stripe event payloads for testing purposes.

Overall, this PR significantly refactors the Stripe webhook handling logic, making it more modular and easier to maintain. It also improves test coverage for Stripe-related functionality.

@pavelbrm pavelbrm merged commit 395a2fd into master Jul 22, 2024
12 checks passed
@pavelbrm pavelbrm deleted the fix-receipt-order-expiry-02 branch July 22, 2024 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants