Fix localhost domain issue in economically unviable refund emails #89

Merged
russellballestrini merged 1 commit from fix/localhost-domain-in-refund-emails into master 2025-10-03 17:57:13 -04:00
russellballestrini commented 2025-10-03 17:53:06 -04:00 (Migrated from git2.unturf.com)

Updated economically unviable refund email notifications to use
create_shop_context_request() instead of passing env_request directly
or creating DummyRequest objects. This ensures emails are sent from
the proper shop domain instead of localhost.

Fixed in:

  • Expired payment processing (line ~2147)
  • Underpayment processing (line ~2911)
  • Passive monitoring refund retries (line ~3290)

Note: Duplicate payment processing was already correct.

Summary by CodeRabbit

  • Bug Fixes
    • Purchase and refund emails now consistently use the correct shop domain and links.
    • Improved handling of overpayments, underpayments, expired invoices, and out-of-stock scenarios to ensure accurate notifications.
    • Email sending is attempted only when required invoice and user details are available, reducing missed or misrouted messages.
    • Greater consistency across duplicate-payment flows, reducing confusion in payment status emails.
Updated economically unviable refund email notifications to use create_shop_context_request() instead of passing env_request directly or creating DummyRequest objects. This ensures emails are sent from the proper shop domain instead of localhost. Fixed in: - Expired payment processing (line ~2147) - Underpayment processing (line ~2911) - Passive monitoring refund retries (line ~3290) Note: Duplicate payment processing was already correct. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - Bug Fixes - Purchase and refund emails now consistently use the correct shop domain and links. - Improved handling of overpayments, underpayments, expired invoices, and out-of-stock scenarios to ensure accurate notifications. - Email sending is attempted only when required invoice and user details are available, reducing missed or misrouted messages. - Greater consistency across duplicate-payment flows, reducing confusion in payment status emails. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
coderabbitai commented 2025-10-03 17:53:18 -04:00 (Migrated from git2.unturf.com)

Walkthrough

Introduces a ShopContextRequestWrapper and create_shop_context_request to construct a shop-scoped request for email generation. Updates refund/duplicate/exception email flows to use the wrapper, ensuring domain/host/app context is derived from the shop. Adds guards to send emails only when invoice and user context exist.

Changes

Cohort / File(s) Summary of edits
Email context wrapper integration
make_post_sell/lib/crypto_watcher/__init__.py
Added ShopContextRequestWrapper proxy class and create_shop_context_request function. Replaced ad-hoc/DummyRequest email contexts with the new shop-scoped request. Adjusted refund/overpayment/underpayment/expired/out-of-stock email paths to use the wrapper and to check for invoice and user before sending. No existing public APIs changed; two new public declarations added.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant EnvRequest as Env Request
  participant CryptoWatcher
  participant Shop
  participant EmailService

  User->>CryptoWatcher: Payment/refund event
  CryptoWatcher->>Shop: Resolve shop from CryptoPayment
  CryptoWatcher->>CryptoWatcher: create_shop_context_request(EnvRequest, CryptoPayment)
  note right of CryptoWatcher: Returns ShopContextRequestWrapper\n(domain, host_url, app from Shop)
  CryptoWatcher->>EmailService: Send purchase/refund email using email_request (wrapper)
  alt Invoice and User exist
    EmailService-->>User: Email delivered
  else Missing context
    CryptoWatcher-->>EmailService: Skip sending
  end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I thump my paws: a context found,
From shop to host, the emails bound.
No Dummy trails, no wayward night—
A wrapper wraps the domain right.
Refunds and sales now hop in tune,
With proper links—hip hop, harpoon! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between b0dc15b06a and 94c6b65cd2.

📒 Files selected for processing (1)
  • make_post_sell/lib/crypto_watcher/__init__.py (3 hunks)

📝 NOTE

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

<!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- walkthrough_start --> ## Walkthrough Introduces a ShopContextRequestWrapper and create_shop_context_request to construct a shop-scoped request for email generation. Updates refund/duplicate/exception email flows to use the wrapper, ensuring domain/host/app context is derived from the shop. Adds guards to send emails only when invoice and user context exist. ## Changes | Cohort / File(s) | Summary of edits | | --- | --- | | **Email context wrapper integration**<br>`make_post_sell/lib/crypto_watcher/__init__.py` | Added ShopContextRequestWrapper proxy class and create_shop_context_request function. Replaced ad-hoc/DummyRequest email contexts with the new shop-scoped request. Adjusted refund/overpayment/underpayment/expired/out-of-stock email paths to use the wrapper and to check for invoice and user before sending. No existing public APIs changed; two new public declarations added. | ## Sequence Diagram(s) ```mermaid sequenceDiagram autonumber actor User participant EnvRequest as Env Request participant CryptoWatcher participant Shop participant EmailService User->>CryptoWatcher: Payment/refund event CryptoWatcher->>Shop: Resolve shop from CryptoPayment CryptoWatcher->>CryptoWatcher: create_shop_context_request(EnvRequest, CryptoPayment) note right of CryptoWatcher: Returns ShopContextRequestWrapper\n(domain, host_url, app from Shop) CryptoWatcher->>EmailService: Send purchase/refund email using email_request (wrapper) alt Invoice and User exist EmailService-->>User: Email delivered else Missing context CryptoWatcher-->>EmailService: Skip sending end ``` ## Estimated code review effort 🎯 3 (Moderate) | ⏱️ ~25 minutes ## Poem > I thump my paws: a context found, > From shop to host, the emails bound. > No Dummy trails, no wayward night— > A wrapper wraps the domain right. > Refunds and sales now hop in tune, > With proper links—hip hop, harpoon! 🐇✨ <!-- walkthrough_end --> --- <details> <summary>📜 Recent review details</summary> **Configuration used**: CodeRabbit UI **Review profile**: CHILL **Plan**: Free <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between b0dc15b06a62a12ce63b56f0598a177ffd8ad1a6 and 94c6b65cd2e299aa459c223904a152d8c0eb4694. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `make_post_sell/lib/crypto_watcher/__init__.py` (3 hunks) </details> </details> <!-- tips_start --> --- > 📝 **NOTE** > <details> > <summary>🎁 Summarized by CodeRabbit Free</summary> > > Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting <https://app.coderabbit.ai/login>. > > </details> <sub>Comment `@coderabbitai help` to get the list of available commands and usage tips.</sub> <!-- tips_end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Y2Y+NwASYThDKADlo23cRXAYdIAAUMn4SbqBvZBdzNWdFhFYb821SgUscMQaLzc6syPA7TIAbmZHho2dM6LvrBgmhNOFdkoLMwj2n4/laHF6LMTtmK1bZKLTXr+SuIUCdwMVsW9X0KCZXqZ3oSQhqklS0e+5NrR0HQUnSGzciRqM+xkeHhE6UzijKEKFlXOcYZOK9YVhGYanSB1Wnly7gZMjAuAAAxkMoccYlFu0J7bcQJInsXJTxKR8Ty0K4AUvAIK7AsZPWOMgPXDBMCwrBsOxHBcNwPFd6k/FwAIghCMIIlMKIRD1201cdTX/TI/XRcDF0yZYqnJWlSgvbfX3jDMXMg4cZxXHcO2qV8fxAgoYJQnCGxE+iFPIHUSByf4wSFn1w3IDjjuQhxYOSnJBYBx+62FM7Bke77q7vhlZXEBH18MD18k9dLGwK33n3ay9nEaMBcwN8oXAxDYFkfnPLRe6gAAhEgKho4fQ3wcNIwGRbugXAe03B4CKtGO8/ZEw/SglRSAV8fYhFILgGqFAQgpy0AAUSkoYVc0gsztBoiQPg0EDScEgAACQTLAeIiRbRgG0FoPQUAyA8TKGgPAhAjS5FaEwVg7AuC8H4KMYQYhmaEKoPIRQKg1CaBYeAKAAjmARHgLQRARISE8DoKYFsJBcZoIoA8BRiiICQAAJwABYGAADZxC2IAKwMFoAAJhIK4ixFi0BoCsY4ixDBXGuIAMwWIAAxWLQAARkca42gAAOBgYSSDiCsbY6x6gmG6CUesVgaiNFaIjDo2gej2hmHYZkjQQA=== --> <!-- internal state end -->
russellballestrini (Migrated from git2.unturf.com) scheduled this pull request to auto merge when all checks succeed 2025-10-03 17:53:20 -04:00
coderabbitai commented 2025-10-03 17:53:44 -04:00 (Migrated from git2.unturf.com)

changed the description

changed the description
russellballestrini commented 2025-10-03 17:57:13 -04:00 (Migrated from git2.unturf.com)

mentioned in commit 973f82ba59

mentioned in commit 973f82ba5969fddc43c09742e3ded17ca1e13d52
russellballestrini (Migrated from git2.unturf.com) merged commit 973f82ba59 into master 2025-10-03 17:57:13 -04:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: engineering/make_post_sell#89
No description provided.