Skip to content

[Docs]- Added Payments docs and code examples#1068

Merged
madster456 merged 7 commits intodevfrom
docs/payments
Dec 22, 2025
Merged

[Docs]- Added Payments docs and code examples#1068
madster456 merged 7 commits intodevfrom
docs/payments

Conversation

@madster456
Copy link
Collaborator

@madster456 madster456 commented Dec 15, 2025

Adds payment docs and code examples to docs.

image image

Summary by CodeRabbit

  • Documentation
    • Added comprehensive Payments app guide covering Stripe integration, subscriptions, and one-time purchases
    • Included extensive, multi-language code examples for payment workflows (JavaScript/TypeScript and Python)
    • Added examples for checkout flows, item management, consuming credits, listing products, and granting products
    • Integrated the Payments examples into the central examples collection and updated docs navigation to include the Payments guide

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Dec 15, 2025

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

Project Deployment Review Updated (UTC)
stack-backend Ready Ready Preview, Comment Dec 22, 2025 3:25pm
stack-dashboard Ready Ready Preview, Comment Dec 22, 2025 3:25pm
stack-demo Ready Ready Preview, Comment Dec 22, 2025 3:25pm
stack-docs Ready Ready Preview, Comment Dec 22, 2025 3:25pm

@cmux-agent
Copy link

cmux-agent bot commented Dec 15, 2025

Older cmux preview screenshots (latest comment is below)

Preview Screenshots

Open Diff Heatmap

Preview screenshots are being captured...

Workspace and dev browser links will appear here once the preview environment is ready.


Generated by cmux preview system

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 15, 2025

Warning

Rate limit exceeded

@madster456 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 44 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 e016577 and a600af8.

📒 Files selected for processing (1)
  • docs/code-examples/payments.ts

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds a new payments examples collection and Payments guide, merges the examples into the examples index, and updates docs navigation. Changes are documentation and example assets only; no public API or runtime code modifications. (48 words)

Changes

Cohort / File(s) Summary
New code examples
docs/code-examples/payments.ts
Adds paymentsExamples: a structured collection of code examples (create-checkout-url, team-checkout-url, get-item, use-item, consume-credits-server, list-products, grant-product-server) across JavaScript/TypeScript and Python frameworks for docs rendering.
Examples index update
docs/code-examples/index.ts
Imports paymentsExamples and merges it into allExamples.apps using object spread {...apiKeysExamples, ...paymentsExamples}.
Payments guide
docs/content/docs/(guides)/apps/payments.mdx
New guide documenting the Payments app: Stripe integration, enabling the app, SDK usage (Customer, CurrentUser, Team), managing/listing/granting items, consuming credits, dashboard flows, test mode, best practices, and pricing with embedded examples.
Docs navigation
docs/content/docs/(guides)/meta.json
Adds "apps/payments" to the Apps section in site metadata/navigation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

  • Focus review on example structure and snippet correctness in docs/code-examples/payments.ts.
  • Verify merge in docs/code-examples/index.ts and that meta.json entry follows navigation conventions.
  • Spot-check payments.mdx for formatting, code fence languages, and links.

Possibly related PRs

Poem

🐰 I hopped through snippets, neat and spry,

Checkout carrots glinting in code nearby,
Stripe-sweet crumbs and routes to share,
Docs all bundled with tender care,
A happy hop — payments prepared! 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding Payments documentation and code examples to the docs.
Description check ✅ Passed The description provides a brief summary of changes with supporting screenshots, though it lacks detailed explanation of specific modifications made.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 15, 2025

Greptile Overview

Greptile Summary

Added comprehensive payments documentation and code examples across multiple frameworks (Next.js, React, Django, FastAPI, Flask, Express, Node.js). The documentation covers Stripe integration, checkout URLs, item management, product listings, and credit consumption.

Key Changes:

  • Created new payments.mdx documentation file with setup instructions, SDK usage examples, dashboard management guide, and best practices
  • Added extensive code examples in payments.ts covering 6 major sections: checkout URLs, team purchases, item retrieval, real-time updates, credit consumption, product listings, and product grants
  • Integrated payments examples into the documentation system via index.ts
  • Added payments page to navigation menu

Issues Found:

  • Logic error in credit consumption examples where credits.quantity - amount is used after tryDecreaseQuantity(), but the item object isn't updated automatically - should use credits.quantity directly (affects 3 code examples)

Confidence Score: 4/5

  • This PR is safe to merge after fixing the credit consumption logic error
  • The PR adds valuable documentation and examples with generally correct code. The logic error in credit consumption examples is important to fix as it would mislead developers, but it's isolated to documentation examples rather than production code. The documentation structure, integration, and other code examples are solid.
  • Pay attention to docs/code-examples/payments.ts - fix the three instances of incorrect remaining quantity calculation in the consume-credits-server examples

Important Files Changed

File Analysis

Filename Score Overview
docs/code-examples/payments.ts 3/5 Added comprehensive payment code examples across multiple frameworks; found logic error in credit consumption examples where remaining quantity calculation is incorrect
docs/code-examples/index.ts 5/5 Correctly integrated payments examples into the code examples system using object spread
docs/content/docs/(guides)/apps/payments.mdx 5/5 Added comprehensive payments documentation covering setup, SDK usage, dashboard management, and best practices; well-structured and informative
docs/content/docs/(guides)/meta.json 5/5 Added payments page to navigation menu in correct location under Apps section

Sequence Diagram

sequenceDiagram
    participant User as User/Browser
    participant App as Application
    participant SDK as Stack SDK
    participant API as Stack Auth API
    participant Stripe as Stripe

    Note over User,Stripe: Creating Checkout Session
    User->>App: Click purchase button
    App->>SDK: user.createCheckoutUrl({productId, returnUrl})
    SDK->>API: POST /payments/purchases/create-purchase-url
    API->>Stripe: Create checkout session
    Stripe-->>API: Session URL
    API-->>SDK: Checkout URL
    SDK-->>App: Checkout URL
    App->>User: Redirect to Stripe checkout
    User->>Stripe: Complete payment
    Stripe->>API: Webhook: payment succeeded
    API->>API: Grant product & items to user
    Stripe->>User: Redirect to returnUrl

    Note over User,API: Consuming Credits (Server-side)
    User->>App: Perform action requiring credits
    App->>SDK: credits.tryDecreaseQuantity(amount)
    SDK->>API: POST /payments/items/.../update-quantity
    API->>API: Atomic check & decrease
    alt Sufficient credits
        API-->>SDK: Success (200)
        SDK-->>App: true
        App->>App: Perform action
        App->>User: Success response
    else Insufficient credits
        API-->>SDK: Error (400)
        SDK-->>App: false
        App->>User: Insufficient credits error
    end

    Note over User,API: Real-time Item Tracking
    User->>App: View credits page
    App->>SDK: user.useItem("credits")
    SDK->>API: GET /payments/items/user/{userId}/{itemId}
    API-->>SDK: Item data {quantity, displayName}
    SDK-->>App: Item object
    App->>User: Display credits: {nonNegativeQuantity}
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

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: 0

🧹 Nitpick comments (1)
docs/code-examples/payments.ts (1)

617-700: Clarify remaining balance calculation after tryDecreaseQuantity

In the consume-credits-server examples you compute the remaining balance as credits.quantity - amount after calling await credits.tryDecreaseQuantity(amount).

Whether this is correct depends on ServerItem semantics:

  • If tryDecreaseQuantity mutates credits.quantity, this subtraction would under-report the remaining balance.
  • If it does not mutate the instance, this happens to match the new quantity but may still be confusing to readers.

To avoid ambiguity in docs, consider either:

  • Returning the authoritative field from the updated item (e.g. nonNegativeQuantity if it’s guaranteed to be updated), or
  • Explicitly documenting that credits.quantity is not mutated and that subtracting amount is only for illustration.

Right now the example leaves the behavior unclear for readers implementing this pattern.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de9cfb3 and b9e1fbc.

📒 Files selected for processing (4)
  • docs/code-examples/index.ts (1 hunks)
  • docs/code-examples/payments.ts (1 hunks)
  • docs/content/docs/(guides)/apps/payments.mdx (1 hunks)
  • docs/content/docs/(guides)/meta.json (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Always add new E2E tests when changing the API or SDK interface
For blocking alerts and errors, never use toast; use alerts instead as they are less easily missed by the user
NEVER try-catch-all, NEVER void a promise, and NEVER .catch(console.error); use loading indicators and async callbacks instead, or use runAsynchronously/runAsynchronouslyWithAlert for error handling
Use ES6 maps instead of records wherever you can

Files:

  • docs/code-examples/payments.ts
  • docs/code-examples/index.ts
**/*.{ts,tsx,css}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx,css}: Keep hover/click transitions snappy and fast; avoid fade-in delays on hover. Apply transitions after action completion instead, like smooth fade-out when hover ends
Use hover-exit transitions instead of hover-enter transitions; for example, use 'transition-colors hover:transition-none' instead of fade-in on hover

Files:

  • docs/code-examples/payments.ts
  • docs/code-examples/index.ts
{.env*,**/*.{ts,tsx,js}}

📄 CodeRabbit inference engine (AGENTS.md)

Prefix environment variables with STACK_ (or NEXT_PUBLIC_STACK_ if public) so changes are picked up by Turborepo and improves readability

Files:

  • docs/code-examples/payments.ts
  • docs/code-examples/index.ts
🧬 Code graph analysis (2)
docs/code-examples/payments.ts (1)
docs/lib/code-examples.ts (1)
  • CodeExample (15-22)
docs/code-examples/index.ts (3)
docs/lib/code-examples.ts (1)
  • CodeExample (15-22)
docs/code-examples/api-keys.ts (1)
  • apiKeysExamples (3-1351)
docs/code-examples/payments.ts (1)
  • paymentsExamples (3-1017)
🪛 LanguageTool
docs/content/docs/(guides)/apps/payments.mdx

[uncategorized] ~190-~190: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...ways validate credit consumption on the server side 2. Use tryDecreaseQuantity: This ...

(EN_COMPOUND_ADJECTIVE_INTERNAL)

⏰ 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). (12)
  • GitHub Check: build (22.x)
  • GitHub Check: E2E Tests (Node 22.x, Freestyle prod)
  • GitHub Check: E2E Tests (Node 22.x, Freestyle mock)
  • GitHub Check: check_prisma_migrations (22.x)
  • GitHub Check: build (22.x)
  • GitHub Check: restart-dev-and-test-with-custom-base-port
  • GitHub Check: all-good
  • GitHub Check: restart-dev-and-test
  • GitHub Check: lint_and_build (latest)
  • GitHub Check: setup-tests-with-custom-base-port
  • GitHub Check: docker
  • GitHub Check: setup-tests
🔇 Additional comments (5)
docs/code-examples/payments.ts (1)

1-3: Overall examples structure and wiring look correct

paymentsExamples uses payments as the subsection key and groups examples under names that match the <PlatformCodeblock document="apps/payments" examples={...} /> usage in payments.mdx. Arrays are consistently cast to CodeExample[], so the shape aligns with allExamples and CodeExample. No structural issues here.

Also applies to: 228-229, 915-1016

docs/content/docs/(guides)/meta.json (1)

14-23: Navigation entry for Payments is consistent

Adding "apps/payments" under the Apps section matches the new apps/payments.mdx guide and follows the existing pattern used by other apps (e.g., apps/api-keys). Looks good.

docs/code-examples/index.ts (1)

3-4: Apps examples merge correctly include Payments

Spreading paymentsExamples into the 'apps' section alongside apiKeysExamples ensures that apps/payments document paths resolve via getExample/getDocumentExamples without changing their call sites. This is a straightforward extension of the existing pattern and looks correct, assuming subsection keys in apiKeysExamples and paymentsExamples remain distinct.

Also applies to: 6-12

docs/content/docs/(guides)/apps/payments.mdx (2)

50-121: Guide correctly references Payments code examples

The <PlatformCodeblock> usages with document="apps/payments" and example names ("create-checkout-url", "team-checkout-url", "get-item", "use-item", "consume-credits-server", "list-products", "grant-product-server") line up with the keys defined in paymentsExamples. The guide and examples are well-aligned.


188-193: Minor wording tweak: “server-side” as a compound adjective

In “Always validate credit consumption on the server side”, consider hyphenating “server-side” since it’s used as a compound adjective (“server-side validation”) rather than a noun phrase.

Suggested edit:

-1. **Validate on Server**: Always validate credit consumption on the server side
+1. **Validate on Server**: Always validate credit consumption on the server-side

Likely an incorrect or invalid review comment.

@cmux-agent
Copy link

cmux-agent bot commented Dec 16, 2025

Older cmux preview screenshots (latest comment is below)

Preview Screenshots

Open Diff Heatmap

Preview screenshots are being captured...

Workspace and dev browser links will appear here once the preview environment is ready.


Generated by cmux preview system

@cmux-agent
Copy link

cmux-agent bot commented Dec 22, 2025

Older cmux preview screenshots (latest comment is below)

Preview Screenshots

Open Diff Heatmap

Preview screenshots are being captured...

Workspace and dev browser links will appear here once the preview environment is ready.


Generated by cmux preview system

@cmux-agent
Copy link

cmux-agent bot commented Dec 22, 2025

Older cmux preview screenshots (latest comment is below)

Preview Screenshots

Open Diff Heatmap

Preview screenshots are being captured...

Workspace and dev browser links will appear here once the preview environment is ready.


Generated by cmux preview system

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: 0

🧹 Nitpick comments (1)
docs/code-examples/index.ts (1)

9-9: Consider adding a merge validation helper to prevent future key collisions.

The spread operator {...apiKeysExamples, ...paymentsExamples} currently works safely since apiKeysExamples contains 'api-keys' and paymentsExamples contains 'payments' with no overlapping keys. However, this approach has no runtime safeguard against accidental collisions if future sections are added. A simple merge helper would catch such issues early:

+function mergeExamples(...sources: Record<string, any>[]) {
+  const merged: Record<string, any> = {};
+  for (const source of sources) {
+    for (const key of Object.keys(source)) {
+      if (key in merged) {
+        throw new Error(`Duplicate key '${key}' found when merging examples`);
+      }
+      merged[key] = source[key];
+    }
+  }
+  return merged;
+}
+
 const allExamples: Record<string, Record<string, Record<string, CodeExample[]>>> = {
   'setup': setupExamples,
-  'apps': {...apiKeysExamples, ...paymentsExamples },
+  'apps': mergeExamples(apiKeysExamples, paymentsExamples),
   'getting-started': viteExamples,
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5eff2e3 and e016577.

📒 Files selected for processing (2)
  • docs/code-examples/index.ts
  • docs/content/docs/(guides)/meta.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/content/docs/(guides)/meta.json
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Always add new E2E tests when changing the API or SDK interface
For blocking alerts and errors, never use toast; use alerts instead as they are less easily missed by the user
NEVER try-catch-all, NEVER void a promise, and NEVER .catch(console.error); use loading indicators and async callbacks instead, or use runAsynchronously/runAsynchronouslyWithAlert for error handling
Use ES6 maps instead of records wherever you can

Files:

  • docs/code-examples/index.ts
**/*.{ts,tsx,css}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx,css}: Keep hover/click transitions snappy and fast; avoid fade-in delays on hover. Apply transitions after action completion instead, like smooth fade-out when hover ends
Use hover-exit transitions instead of hover-enter transitions; for example, use 'transition-colors hover:transition-none' instead of fade-in on hover

Files:

  • docs/code-examples/index.ts
{.env*,**/*.{ts,tsx,js}}

📄 CodeRabbit inference engine (AGENTS.md)

Prefix environment variables with STACK_ (or NEXT_PUBLIC_STACK_ if public) so changes are picked up by Turborepo and improves readability

Files:

  • docs/code-examples/index.ts
🧬 Code graph analysis (1)
docs/code-examples/index.ts (3)
docs/lib/code-examples.ts (1)
  • CodeExample (15-23)
docs/code-examples/api-keys.ts (1)
  • apiKeysExamples (3-1351)
docs/code-examples/payments.ts (1)
  • paymentsExamples (3-1017)
⏰ 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). (13)
  • GitHub Check: Vercel Agent Review
  • GitHub Check: E2E Tests (Node 22.x, Freestyle prod)
  • GitHub Check: E2E Tests (Node 22.x, Freestyle mock)
  • GitHub Check: restart-dev-and-test-with-custom-base-port
  • GitHub Check: setup-tests
  • GitHub Check: lint_and_build (latest)
  • GitHub Check: setup-tests-with-custom-base-port
  • GitHub Check: build (22.x)
  • GitHub Check: restart-dev-and-test
  • GitHub Check: check_prisma_migrations (22.x)
  • GitHub Check: docker
  • GitHub Check: build (22.x)
  • GitHub Check: all-good
🔇 Additional comments (1)
docs/code-examples/index.ts (1)

3-3: LGTM!

The import follows the established pattern and is correctly structured.

@cmux-agent
Copy link

cmux-agent bot commented Dec 22, 2025

Preview Screenshots

Open Diff Heatmap

Preview screenshots are being captured...

Workspace and dev browser links will appear here once the preview environment is ready.


Generated by cmux preview system

@madster456 madster456 enabled auto-merge (squash) December 22, 2025 15:19
@madster456 madster456 disabled auto-merge December 22, 2025 15:23
@madster456 madster456 merged commit b6180d5 into dev Dec 22, 2025
20 of 21 checks passed
@madster456 madster456 deleted the docs/payments branch December 22, 2025 15:23
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.

2 participants