Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@devkiran
Copy link
Collaborator

@devkiran devkiran commented Oct 3, 2025

Summary by CodeRabbit

  • New Features

    • Added sale amount support across rewards and partner commission flows; reward context and UI now reflect amount with currency semantics.
  • Integrations

    • Stripe checkout/invoice and Shopify sale events include sale amount in commission processing; general sale tracking forwards amount for evaluation.
  • Tests

    • E2E tests added to verify tracking and commission behavior for differing sale amounts.
  • Chores

    • Reward rules expanded with an additional high-value sale modifier.

@vercel
Copy link
Contributor

vercel bot commented Oct 3, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Oct 3, 2025 7:09pm

@devkiran devkiran requested a review from steven-tey October 3, 2025 17:45
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 3, 2025

Warning

Rate limit exceeded

@devkiran has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 38 seconds before requesting another review.

βŒ› How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 9d3b011 and e3fcddd.

πŸ“’ Files selected for processing (1)
  • apps/web/tests/tracks/track-sale.test.ts (1 hunks)

Walkthrough

Adds sale.amount to reward schemas and threads it through partner commission contexts across Stripe checkout, Stripe invoice, generic sale tracking, and Shopify integration. Updates Zod schema, attribute types, labels, and context validation to include amount.

Changes

Cohort / File(s) Summary
Schema updates
apps/web/lib/zod/schemas/rewards.ts
Add amount to CONDITION_SALE_ATTRIBUTES; add sale.amount: "currency" in ENTITY_ATTRIBUTE_TYPES; add UI label amount: "Amount"; extend rewardContextSchema to accept sale.amount as z.number().nullish().
Stripe webhooks
apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts, apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts
Pass sale.amount (from saleData.amount) into the partner commission context when creating partner commissions.
Sale tracking API
apps/web/lib/api/conversions/track-sale.ts
Include sale.amount in the metadata/context passed to _trackSale β†’ createPartnerCommission.
Shopify integration
apps/web/lib/integrations/shopify/create-sale.ts
Add sale.amount to the commission context (alongside customer.country) when creating partner commission, conditional on existing programId/partnerId checks.
Tests / Test fixtures
apps/web/tests/tracks/track-sale.test.ts, apps/web/tests/utils/resource.ts
Add test exercising tracking sales with different amounts; add a second modifier in E2E_REWARD.modifiers targeting sale.amount threshold (modifier with operator AND, amount 5000, condition on sale.amount greater_than 15000).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant SC as Stripe Checkout
  participant SI as Stripe Invoice
  participant SH as Shopify
  participant CT as Conversions API
  participant BH as Backend Handler
  participant CPC as createPartnerCommission
  participant RE as Rewards Engine

  rect rgba(230,245,255,0.6)
  note over SC,BH: Checkout-session-completed webhook
  SC->>BH: webhook payload (saleData)
  BH->>CPC: context { sale: { productId, amount } }
  end

  rect rgba(230,255,230,0.6)
  note over SI,BH: Invoice-paid webhook
  SI->>BH: webhook payload (saleData)
  BH->>CPC: context { sale: { productId, amount } }
  end

  rect rgba(255,245,230,0.6)
  note over SH,BH: Shopify create-sale
  SH->>BH: create-sale event
  BH->>CPC: context { sale: { amount }, customer: { country } }
  end

  rect rgba(245,230,255,0.6)
  note over CT,BH: Generic track-sale
  CT->>BH: track-sale request
  BH->>CPC: context { sale: { amount } }
  end

  CPC->>RE: Evaluate rewards using sale.amount
  RE-->>CPC: Commission decision/results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • steven-tey
  • TWilson023

Poem

I’m a rabbit with a ledger bright,
I hopped through webhooks late at night.
I stitched each sale with an amount so true,
Now carrots count per purchase through.
Thump-thump β€” commissions hop anew πŸ₯•

Pre-merge checks and finishing touches

βœ… Passed checks (3 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check βœ… Passed The title clearly and concisely summarizes the primary changeβ€”adding support for sale amount in reward conditionsβ€”without extraneous detail, making it immediately clear to reviewers what the pull request achieves.
Docstring Coverage βœ… Passed No functions found in the changes. Docstring coverage check skipped.

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

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

πŸ“œ Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 6fcfbbb and cd411e7.

πŸ“’ Files selected for processing (2)
  • apps/web/tests/tracks/track-sale.test.ts (1 hunks)
  • apps/web/tests/utils/resource.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/web/tests/tracks/track-sale.test.ts (3)
apps/web/tests/utils/helpers.ts (1)
  • randomId (4-4)
apps/web/lib/types.ts (1)
  • TrackSaleResponse (411-411)
apps/web/tests/utils/resource.ts (2)
  • E2E_CUSTOMER_EXTERNAL_ID_2 (40-40)
  • E2E_REWARD (41-71)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
πŸ”‡ Additional comments (1)
apps/web/tests/utils/resource.ts (1)

58-69: LGTM!

The new modifier correctly extends the reward fixture to test sale amount conditions. The structure is consistent with existing modifiers, and the threshold-based logic (amount > 15000 β†’ 5000 reward) aligns with the PR's goal to support sale.amount in reward conditions.

@steven-tey steven-tey merged commit 4f48a61 into main Oct 3, 2025
8 checks passed
@steven-tey steven-tey deleted the reward-condition-sale-amount branch October 3, 2025 19:16
@coderabbitai coderabbitai bot mentioned this pull request Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants