Skip to content

fix(learn): fulfill paid activities removed from the cart - #1295

Open
PixelCraftLab wants to merge 4 commits into
alphaonelabs:mainfrom
PixelCraftLab:fix/learn-paid-cart-fulfillment
Open

PixelCraftLab wants to merge 4 commits into
alphaonelabs:mainfrom
PixelCraftLab:fix/learn-paid-cart-fulfillment

Conversation

@PixelCraftLab

@PixelCraftLab PixelCraftLab commented Nov 26, 2026 •

Copy link
Copy Markdown

Related issues

Fixes #1294

What changed

Paid checkout completion now enrolls the authenticated buyer in activities from the verified Stripe line-item metadata even if those activities were removed from the cart while payment was open. Free activities still in the cart retain their existing behavior.

The change keeps ownership and paid-status checks, guest checkout behavior, and duplicate-safe enrollment inserts. There are no schema changes or new dependencies.

Two regression cases cover an empty edited cart and a cart containing only an unrelated unpaid activity. Both fail before the fix and pass afterward.

Validation

  • Python 3.12: all 37 checkout tests pass, including the two new regression cases.
  • Full suite: 421 passed, 29 failed. Upstream baseline: 419 passed, 29 failed, excluding the two new cases. The 29 failure names are identical before and after this patch.
  • Python syntax compilation and reverse patch application check passed. No trailing whitespace on added lines.
  • Full pre-commit, Wrangler/D1 integration and browser/Stripe end-to-end checks were not run. No real payment was made.

This PR fixes cart removal during authenticated paid fulfillment. It does not redesign checkout snapshots, line-item pagination or enrollment-write error handling.

Checklist

  • Ran full pre-commit, not run; see validation limits above.
  • Tested the change with local regression tests and the existing checkout suite.
  • Added screenshots, not applicable to this backend-only change.

AI assistance was used to investigate the failure and prepare the patch and tests. The validation above describes the checks actually performed.

Fixes api_complete_checkout in learn/src/worker.py. Paid enrollments now come from verified Stripe paid line items, not from current cart membership. A paid activity removed from the cart during checkout still gets enrollment. Free activities still in the cart keep their existing behavior. The code builds a set of enrollment IDs and inserts each one in sorted order, using the existing INSERT OR IGNORE for duplicate safety. Ownership and paid-status checks are unchanged.

Adds a parameterized test covering an empty remaining cart and a cart with only an unrelated unpaid activity.

Impact: buyers who remove a paid activity during checkout are enrolled. Both regression cases passed. The full test suite completed with 421 passing tests and 29 unchanged baseline failures. Browser and Stripe end-to-end checks were not run.

@github-actions github-actions Bot added the files-changed: 2 PR changes 2 files label Nov 26, 2026
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Checkout completion now enrolls authenticated buyers in activities represented by paid Stripe line items, even when those activities are no longer in the cart. Free activities still in the cart remain included. A parameterized test covers both an empty cart and one containing a different unpaid activity.

Changes

Checkout enrollment

Layer / File(s) Summary
Enrollment sources and regression coverage
learn/src/worker.py, learn/tests/test_api_cart_checkout.py
api_complete_checkout builds enrollment IDs from paid Stripe line items and free activities still in the cart, then deduplicates and sorts them. The parameterized test checks that a paid activity is enrolled when it is absent from the remaining cart.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: a1l13n, gopikrishna-20, 10done

Merge Risk: Minimal · up to 95c90

Checkout completion now enrolls buyers in paid activities that were removed from the cart while payment was open, and free cart activities keep their existing behavior. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: paid activities removed from the cart are now fulfilled (enrolled). It uses the conventional fix(learn) prefix and matches the summary, which enrolls buyers in paid li…
Linked Issues check Passed Issue #1294 requires that api_complete_checkout enroll the buyer in paid activities from verified Stripe line items, even when removed from the cart. Free activities still in the cart must keep their …
Out of Scope Changes check Passed The worker.py change touches only the enrollment selection in api_complete_checkout. It changes the set of enrollment IDs and the loop variable. The sorted and deduplicated iteration is a small side e…
Full details: Title check

Explanation

The title names the main change: paid activities removed from the cart are now fulfilled (enrolled). It uses the conventional fix(learn) prefix and matches the summary, which enrolls buyers in paid line-item activities even when they left the cart during checkout, and the objectives, which describe the same behavior.

Full details: Linked Issues check

Explanation

Issue #1294 requires that api_complete_checkout enroll the buyer in paid activities from verified Stripe line items, even when removed from the cart. Free activities still in the cart must keep their behavior. Ownership and paid checks must remain, and enrollment inserts must stay duplicate-safe.

The worker.py diff at the reviewed head shows:

  • paid_activity_ids is built from verified Stripe line-item metadata, and it is copied into enrollment_ids without any cart-membership filter.
  • Only free rows (unit_price_cents <= 0) from the current cart are added to enrollment_ids.
  • The loop over sorted(enrollment_ids) runs the existing INSERT OR IGNORE enrollment statement. This keeps duplicate-safe inserts.

This matches the requested approach. The previous skip for paid activities missing from the cart is removed. The ownership and paid-status checks sit outside the changed hunk. The diff shows they are not modified, so they remain.

The test file diff could not be read. The PR description and the change summary report a parameterized regression test for an empty cart and for a cart with only an unrelated unpaid activity. Those cases are not verified from source here. The issue does not explicitly require tests, so this does not affect the verdict.

Full details: Out of Scope Changes check

Explanation

The worker.py change touches only the enrollment selection in api_complete_checkout. It changes the set of enrollment IDs and the loop variable. The sorted and deduplicated iteration is a small side effect of building a set. It is directly tied to the enrollment logic the issue covers. No unrelated files are reported in the change summary. The PR description says there are no schema changes and no new dependencies. The test file change is a supporting regression test for the same behavior, so it is in scope. The PR states that snapshot redesign, pagination, and enrollment-write error handling are excluded. The reviewed diff does not change those areas.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e6ece26 and 95c9011.

Files selected for processing: 2

  • learn/src/worker.py
  • learn/tests/test_api_cart_checkout.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

👀 Peer Review Required

Hi @PixelCraftLab! This pull request does not yet have a peer review.

Before this PR can be merged, please request a review from one of your peers:

  • Go to the PR page and click "Reviewers" on the right sidebar.
  • Select a team member or contributor to review your changes.
  • Once they approve, this reminder will be automatically removed.

Thank you for contributing! 🎉

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

files-changed: 2 PR changes 2 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Paid checkout misses enrollment when a purchased activity is removed from the cart

1 participant