Skip to content

Conversation

rohilsurana
Copy link
Member

@rohilsurana rohilsurana commented Oct 1, 2025

Summary

Migrate billing checkout APIs from gRPC to Connect RPC format as part of the broader migration effort to modernize the API layer.

APIs to Migrate

  • CreateCheckout - ✅ COMPLETED (commit: e6e68563)
    • Supports payment method setup, customer portal setup, subscription checkout, and product checkout
    • Comprehensive error handling for per-seat limits and validation errors
    • 11 test cases covering all scenarios
  • DelegatedCheckout - ✅ ALREADY MIGRATED
    • Pre-existing Connect RPC implementation
    • 3 test cases for subscription, product, and error scenarios
  • ListCheckouts - ✅ COMPLETED (commit: 64ff9f5)
    • Simple list API with organization validation
    • Service error handling with proper Connect error codes
    • 4 comprehensive test cases covering all scenarios
  • GetCheckout - ✅ COMPLETED (commit: 9646881)
    • Single checkout retrieval with ID and organization validation
    • Service error handling with proper Connect error codes
    • 6 comprehensive test cases covering all validation and success scenarios

Progress Summary

  • Completed: 4/4 APIs (100% ✅)
  • Migration Status: COMPLETE

Implementation Details

✅ CreateCheckout API

  • Handler: CreateCheckout(ctx, *connect.Request[CreateCheckoutRequest]) (*connect.Response[CreateCheckoutResponse], error)
  • Features:
    • Payment method setup sessions via CreateSessionForPaymentMethod
    • Customer portal setup sessions via CreateSessionForCustomerPortal
    • Subscription checkout sessions with plan validation
    • Product checkout sessions with feature validation
    • Per-seat limit error handling
  • Business Logic: Maintains exact same logic as gRPC implementation
  • Error Handling: Connect RPC error codes with proper error constants
  • Testing: 11 comprehensive test cases covering all success and error scenarios

✅ DelegatedCheckout API (Pre-existing)

  • Handler: DelegatedCheckout(ctx, *connect.Request[DelegatedCheckoutRequest]) (*connect.Response[DelegatedCheckoutResponse], error)
  • Features: Direct subscription/product application without session creation
  • Testing: 3 test cases for subscription, product, and error scenarios

✅ ListCheckouts API

  • Handler: ListCheckouts(ctx, *connect.Request[ListCheckoutsRequest]) (*connect.Response[ListCheckoutsResponse], error)
  • Features:
    • Organization ID validation with CodeInvalidArgument error
    • Customer ID filtering via service layer
    • Proper error handling with CodeInternal for service errors
    • Result transformation using existing transformCheckoutToPB function
  • Business Logic: Maintains exact same logic as gRPC implementation
  • Error Handling: Connect RPC error codes (CodeInvalidArgument, CodeInternal)
  • Testing: 4 comprehensive test cases covering validation, service errors, empty results, and successful listing

✅ GetCheckout API

  • Handler: GetCheckout(ctx, *connect.Request[GetCheckoutRequest]) (*connect.Response[GetCheckoutResponse], error)
  • Features:
    • Dual validation for both Organization ID and Checkout ID with CodeInvalidArgument error
    • Single checkout retrieval via checkoutService.GetByID
    • Proper error handling with CodeInternal for service errors
    • Result transformation using existing transformCheckoutToPB function
  • Business Logic: Maintains exact same logic as gRPC implementation
  • Error Handling: Connect RPC error codes (CodeInvalidArgument, CodeInternal)
  • Testing: 6 comprehensive test cases covering:
    • Empty org_id validation
    • Empty id validation
    • Both empty validation
    • Service error handling
    • Successful plan-based checkout retrieval
    • Successful product-based checkout retrieval

Testing Coverage

  • Total Test Cases: 24 (11 CreateCheckout + 3 DelegatedCheckout + 4 ListCheckouts + 6 GetCheckout)
  • Success Scenarios: 14 test cases
  • Error Scenarios: 10 test cases
  • Build Status: ✅ Passing
  • Lint Status: ✅ Clean (0 issues)

Technical Notes

  • Uses Connect RPC request/response wrapper pattern
  • Maintains existing service layer interfaces
  • Follows protobuf getter conventions for field access
  • Error handling mapped to appropriate Connect error codes
  • Mock services created for comprehensive testing
  • All tests use proper Connect error assertion patterns
  • Business logic preserved exactly from gRPC implementations

Files Modified/Created

  • internal/api/v1beta1connect/billing_checkout.go - All checkout API implementations
  • internal/api/v1beta1connect/billing_checkout_test.go - Comprehensive test suite
  • internal/api/v1beta1connect/mocks/checkout_service.go - Mock service

Migration Verification

  • ✅ Build compilation successful
  • ✅ All tests passing (24 test cases)
  • ✅ Lint checks clean (0 issues)
  • ✅ Business logic preserved from gRPC versions
  • ✅ Error handling patterns consistent with Connect RPC standards
  • ✅ Mock services properly implemented with expecter methods

Related Issue: Linear CLD-2278
Migration Pattern: gRPC → Connect RPC
Status: ✅ COMPLETED (4/4 APIs migrated)

Migrates the CreateCheckout API from gRPC to Connect RPC format, including:
- Implementation of CreateCheckout handler with setup, subscription, and product checkout support
- Comprehensive test suite with 11 test cases covering all scenarios
- Mock service for testing
- Error handling for per-seat limits and internal server errors
Copy link

vercel bot commented Oct 1, 2025

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

Project Deployment Preview Comments Updated (UTC)
frontier Ready Ready Preview Comment Oct 1, 2025 6:38am

@coveralls
Copy link

coveralls commented Oct 1, 2025

Pull Request Test Coverage Report for Build 18153697235

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 103 of 105 (98.1%) changed or added relevant lines in 1 file are covered.
  • 28 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.8%) to 35.102%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/api/v1beta1connect/billing_checkout.go 103 105 98.1%
Files with Coverage Reduction New Missed Lines %
internal/api/v1beta1connect/billing_plan.go 12 93.0%
internal/api/v1beta1connect/billing_subscription.go 16 26.35%
Totals Coverage Status
Change from base Build 18128131357: 0.8%
Covered Lines: 13104
Relevant Lines: 37331

💛 - Coveralls

@rohilsurana rohilsurana marked this pull request as ready for review October 1, 2025 10:47
@rohilsurana rohilsurana requested a review from Copilot October 3, 2025 11:33
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR migrates the Frontier billing checkout APIs from gRPC to Connect RPC as part of a broader API modernization effort. The migration covers four core checkout APIs: CreateCheckout, DelegatedCheckout, ListCheckouts, and GetCheckout.

Key changes implemented:

  • Complete Connect RPC implementation for all checkout APIs with proper error handling
  • Comprehensive test coverage with 24 test cases covering success and error scenarios
  • Mock service generation for testing isolation

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
internal/api/v1beta1connect/billing_checkout.go Implements all four Connect RPC checkout handlers with business logic preservation
internal/api/v1beta1connect/billing_checkout_test.go Comprehensive test suite with 24 test cases covering all API scenarios
internal/api/v1beta1connect/mocks/checkout_service.go Auto-generated mock service for testing
internal/api/v1beta1connect/errors.go Adds KYC completion error constant

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

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