Skip to content

fix: stabilize auth and payment checkout flow - #43

Merged
gurnoorpannu merged 1 commit into
masterfrom
kmp/ios-migration
May 30, 2026
Merged

fix: stabilize auth and payment checkout flow#43
gurnoorpannu merged 1 commit into
masterfrom
kmp/ios-migration

Conversation

@gurnoorpannu

@gurnoorpannu gurnoorpannu commented May 30, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Enhanced payment checkout error handling and validation for improved reliability.
    • Improved profile information resolution with better data fallback logic.
    • Strengthened WebView payment processing with enhanced configuration.
  • Tests

    • Expanded payment checkout and verification test coverage.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 30, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 46b9941d-4162-4577-9dbf-e8ec88f405cc

📥 Commits

Reviewing files that changed from the base of the PR and between 1675b97 and dc22fc0.

📒 Files selected for processing (10)
  • app/src/main/java/com/example/talkeys_new/screens/payment/EventPaymentScreen.kt
  • app/src/main/java/com/example/talkeys_new/screens/payment/WebViewPaymentScreen.kt
  • app/src/main/java/com/example/talkeys_new/screens/profile/ProfileScreen.kt
  • app/src/main/res/values/strings.xml
  • shared/src/commonMain/kotlin/com/talkeys/shared/data/payment/PaymentModels.kt
  • shared/src/commonMain/kotlin/com/talkeys/shared/data/payment/PaymentRepository.kt
  • shared/src/commonMain/kotlin/com/talkeys/shared/di/SharedModule.kt
  • shared/src/commonMain/kotlin/com/talkeys/shared/network/PaymentApiService.kt
  • shared/src/commonMain/kotlin/com/talkeys/shared/presentation/payment/PaymentCheckoutViewModel.kt
  • shared/src/commonTest/kotlin/com/talkeys/shared/presentation/payment/PaymentCheckoutViewModelTest.kt

📝 Walkthrough

Walkthrough

This PR refactors the payment checkout flow by centralizing token resolution in the repository layer, updating data models to support flexible backend responses, enhancing API error handling with detailed diagnostics, and simplifying the PhonePe UI to remove local token-loading coroutines. Supporting changes include WebView handler enhancements for third-party cookies and popup handling, profile screen fallback logic, and expanded test coverage.

Changes

Payment Flow Refactoring

Layer / File(s) Summary
Data model updates for flexible backend response handling
shared/src/commonMain/kotlin/com/talkeys/shared/data/payment/PaymentModels.kt
BookTicketRequest adds optional teamCode field. PaymentOrderData fields become nullable/optional with @JsonNames/@SerialName mappings to accept multiple backend key variants, collection fields default to emptyList(), and new checkoutTokenOrUrl() method derives effective checkout value from paymentUrl or token.
API service endpoint and error handling enhancements
shared/src/commonMain/kotlin/com/talkeys/shared/network/PaymentApiService.kt
Endpoint changes from /api/book-ticket-app to /api/book-ticket. Response parsing now uses bodyAsText() with Json.decodeFromString instead of Ktor's automatic deserialization. New private helpers formatHttpError and describePayloadShape analyze JSON structure for detailed error messages; SerializationException and non-success HTTP responses return structured failures with payload analysis.
Repository token resolution and auth flow
shared/src/commonMain/kotlin/com/talkeys/shared/data/payment/PaymentRepository.kt, shared/src/commonMain/kotlin/com/talkeys/shared/di/SharedModule.kt
PaymentRepository accepts optional TokenStorage dependency. New resolveAuthToken helper normalizes and validates auth tokens (preferred provided token, fallback to stored token). bookTicket includes optional teamCode and resolves auth before API calls. verifyPaymentStatus resolves auth with "Please login to verify payment" error message on failure. DI wiring updates PaymentRepository registration to inject second dependency.
ViewModel checkout flow with validation
shared/src/commonMain/kotlin/com/talkeys/shared/presentation/payment/PaymentCheckoutViewModel.kt
startCheckout adds optional teamCode parameter and validates derived checkout token/URL via paymentOrder.checkoutTokenOrUrl()—sets error and returns early if null/blank. Upfront auth guards removed from both startCheckout and verifyPaymentStatus, delegating auth validation to repository layer.
PhonePe UI integration simplification
app/src/main/java/com/example/talkeys_new/screens/payment/EventPaymentScreen.kt
EventPaymentScreen removes LocalContext and token-loading coroutine scope. PhonePePaymentSection now calls paymentViewModel.startCheckout directly with authToken=null and teamCode=null, relying on repository-level token resolution instead of local token fetching.
WebView payment handler enhancements
app/src/main/java/com/example/talkeys_new/screens/payment/WebViewPaymentScreen.kt
CookieManager explicitly enables third-party cookies. WebView settings extended with multiple-window support, image/cache/content access flags, and user-agent string cleanup. onPageFinished logging includes parsed page host. New WebChromeClient.onCreateWindow intercepts popup creation, extracts popup URL, and opens externally via ACTION_VIEW intent.
Profile screen fallback resolution logic
app/src/main/java/com/example/talkeys_new/screens/profile/ProfileScreen.kt
New firstNonBlank utility helper selects first non-null, non-blank string. UserProfile construction uses fallback chains for name, email, id, and profileImageUrl (each falling back through profile and Google fields).
Test updates and configuration
app/src/main/res/values/strings.xml, shared/src/commonTest/kotlin/com/talkeys/shared/presentation/payment/PaymentCheckoutViewModelTest.kt
PaymentCheckoutViewModelTest updates startCheckout_requiresAuthToken to use repository failure result; adds tests for backend paymentUrl handling (direct usage and missing checkout details); updates verifyPaymentStatus_requiresAuthToken to simulate backend verification failure. Test helpers expanded: orderData supports nullable token and optional paymentUrl; fakeRepository adds teamCode parameter. Google OAuth string resource default_web_client_id added to strings.xml.

Possibly Related PRs

  • gurnoorpannu/Talkeys_Official#26: Overlaps with PhonePe checkout initiation refactoring in EventPaymentScreen, removing token-loading coroutine flow and directly invoking checkout.

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 Token flows now resolve with grace,
Data models flexed for backend's pace,
PhonePe clicks without a local scope,
Error messages give debugging hope,
The payment dance is cleaner now! 🎫

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch kmp/ios-migration

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.

@gurnoorpannu
gurnoorpannu merged commit c9350ab into master May 30, 2026
4 of 5 checks passed
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.

1 participant