Skip to content

Conversation

@cubic-dev-local
Copy link

@cubic-dev-local cubic-dev-local bot commented Aug 29, 2025

## What does this PR do?

This PR optimizes payment app imports by creating a dedicated PaymentServiceMap that only loads payment apps with PaymentService implementations, avoiding the need to load the entire app store when only payment functionality is needed. This follows the same optimization pattern established in PR calcom#23372 for analytics services.

Key changes:

  • Adds PaymentServiceMap generation to the app-store-cli build process
  • Creates payment.services.generated.ts with lazy imports for 6 payment services (alby, btcpayserver, hitpay, mock-payment-app, paypal, stripepayment)
  • Updates 6 files to use PaymentServiceMap instead of importing the full appStore

Performance benefits:

  • Reduces bundle size by avoiding import of 100+ apps when only payment functionality is needed
  • Uses lazy imports for better code splitting
  • Loads only 6 payment services instead of entire app store

How should this be tested?

Critical testing areas:

  1. Payment flows: Test all payment providers (PayPal, Stripe, Alby, HitPay, BTCPay Server) to ensure payment creation, charging, and refunds still work
  2. E2E tests: Verify E2E tests pass with the conditional PaymentServiceMap logic
  3. Build process: Confirm yarn app-store:build generates payment.services.generated.ts correctly
  4. Connected apps: Test the connected apps page shows payment app setup status correctly

Test configuration:

  • Set up credentials for at least one payment provider (Stripe recommended)
  • Create test bookings with payment requirements
  • Test both successful payments and error scenarios

Expected behavior:

  • All existing payment functionality should work identically
  • No performance regressions in payment flows
  • Generated file should contain imports for all 6 payment services

Checklist

  • I have self-reviewed the code
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. N/A - This is an internal optimization that doesn't change public APIs
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

Link to Devin run: https://app.devin.ai/sessions/6ff5d1bb0e98478180209c3a930013c2
Requested by: @keithwillcode

⚠️ Important for reviewers:

  • This PR changes how payment services are imported at runtime - please verify all payment flows work correctly

  • The chargeCard method signature was updated to include booking.id - confirm this matches all PaymentService implementations

  • Test that the generated PaymentServiceMap contains all expected payment services after running yarn app-store:build


    Based on: perf: optimize payment app imports to avoid loading entire app store calcom/cal.com#23408


Summary by cubic

Optimizes payment app imports by generating a PaymentServiceMap and lazy‑loading only payment providers instead of the full app store. This reduces bundle size and speeds up payment flows with no public API changes.

  • Performance

    • Loads only 6 payment services on demand (alby, btcpayserver, hitpay, mock-payment-app, paypal, stripepayment) instead of importing 100+ apps.
    • Uses lazy imports for better code splitting and faster initial load.
  • Refactors

    • app-store-cli now generates payment.services.generated.ts with PaymentServiceMap.
    • Replaced appStore imports with PaymentServiceMap in getConnectedApps, payment handlers (create/charge/refund/delete), and tRPC payment routes; chargeCard now receives booking.id.
    • Updated test setup to mock PaymentServiceMap and removed obsolete appStore mocks.

devin-ai-integration bot and others added 5 commits August 27, 2025 18:02
- Add PaymentServiceMap generation to app-store-cli build process
- Generate payment.services.generated.ts with lazy imports for 6 payment services
- Update handlePayment.ts, deletePayment.ts, handlePaymentRefund.ts to use PaymentServiceMap
- Update getConnectedApps.ts and tRPC payment routers to use PaymentServiceMap
- Follow same pattern as analytics optimization in PR calcom#23372
- Reduces bundle size by avoiding import of 100+ apps when only payment functionality needed

Co-Authored-By: [email protected] <[email protected]>
- Remove obsolete appStoreMock line from bookingScenario.ts since handlePayment now uses PaymentServiceMap
- Update setupVitest.ts to import prismaMock from correct PrismockClient instance
- Add PaymentServiceMap mock following PR calcom#22450 pattern for calendar services
- Ensure MockPaymentService uses consistent externalId across test files
- Fix webhook handler to return 200 status by ensuring payment records are found correctly

Co-Authored-By: [email protected] <[email protected]>
…vi.spyOn() calls

- Remove global prismaMock import from setupVitest.ts that was causing 'is not a spy' errors
- Update MockPaymentService to import prismaMock locally to maintain payment test functionality
- Fixes organization and outOfOffice tests while preserving payment service optimization

Co-Authored-By: [email protected] <[email protected]>
- Payment services map now always includes all payment apps regardless of E2E environment
- Ensures payment functionality is consistently available across all environments
- Addresses CI failures caused by conditional payment service loading

Co-Authored-By: [email protected] <[email protected]>
@github-actions
Copy link

This PR is being marked as stale due to inactivity.

@github-actions github-actions bot added the Stale label Sep 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants