Add EmbeddedPaymentElement update support and fix #2426#2427
Add EmbeddedPaymentElement update support and fix #2426#2427programmeraditya wants to merge 4 commits into
Conversation
📝 WalkthroughWalkthroughThis PR adds async ChangesEmbeddedPaymentElement update() and iOS dependency injection
Sequence Diagram(s)sequenceDiagram
participant Controller as EmbeddedPaymentElementController
participant Widget as EmbeddedPaymentElement (Dart)
participant Android as Android Platform
participant iOS as iOS Platform
Controller->>Widget: update(IntentConfiguration)
alt Android
Widget->>Widget: Register pending update completer
Widget->>Android: invokeMethod('update', intentConfig)
Android->>Android: Validate & build config
Android->>Android: Update embedded view
Note over Android: Async completion via callback
Android-->>Widget: embeddedPaymentElementUpdateComplete
Widget->>Widget: Complete pending completer
Widget-->>Controller: Future<Map?>
else iOS
Widget->>iOS: invokeMethod('update', intentConfig)
iOS->>iOS: Validate & build config
iOS->>iOS: Update embedded view
iOS-->>Widget: Immediate result Map
Widget-->>Controller: Future<Map?>
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/stripe/lib/src/widgets/embedded_payment_element.dart (1)
187-192: ⚡ Quick winConsider adding error cleanup for consistency.
The Android
confirm()path doesn't clear_pendingConfirmifinvokeMethodthrows, unlike theupdate()method (lines 419–426) which explicitly clears_pendingUpdateon exception. While this isn't a memory leak (the next operation will cancel it), adding consistent error cleanup would prevent leaving an uncompleted completer referenced.♻️ Proposed fix to match update() pattern
if (defaultTargetPlatform == TargetPlatform.android) { _completePendingConfirm({'status': 'canceled'}); final completer = Completer<Map<String, dynamic>?>(); _pendingConfirm = completer; - await channel.invokeMethod('confirm'); + try { + await channel.invokeMethod('confirm'); + } catch (_) { + if (identical(_pendingConfirm, completer)) { + _pendingConfirm = null; + } + rethrow; + } return completer.future; }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/stripe/lib/src/widgets/embedded_payment_element.dart` around lines 187 - 192, The Android confirm() path can leave _pendingConfirm set if channel.invokeMethod('confirm') throws; wrap the await channel.invokeMethod('confirm') call in a try/catch and in the catch clear _pendingConfirm (set it to null) before rethrowing the error so it matches the error-cleanup pattern used by update() (and keeps _completePendingConfirm and the created Completer behavior unchanged).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/stripe/lib/src/widgets/embedded_payment_element.dart`:
- Around line 187-192: The Android confirm() path can leave _pendingConfirm set
if channel.invokeMethod('confirm') throws; wrap the await
channel.invokeMethod('confirm') call in a try/catch and in the catch clear
_pendingConfirm (set it to null) before rethrowing the error so it matches the
error-cleanup pattern used by update() (and keeps _completePendingConfirm and
the created Completer behavior unchanged).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: fdbac2da-cb03-4e2a-80ec-841e05ba0a88
📒 Files selected for processing (5)
packages/stripe/lib/src/widgets/embedded_payment_element.dartpackages/stripe/lib/src/widgets/embedded_payment_element_controller.dartpackages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkEmbeddedPaymentElementPlatformView.ktpackages/stripe_ios/ios/stripe_ios/Sources/stripe_ios/EmbeddedPaymentElementFactory.swiftpackages/stripe_ios/ios/stripe_ios/Sources/stripe_ios/StripePlugin.swift
|
@remonh87 I traced this on iOS: |
Adds
EmbeddedPaymentElementController.update(...)so Flutter apps can update the embedded payment element intent configuration without recreating the platform view.Also fixes #2426
Changes
update(IntentConfiguration)toEmbeddedPaymentElementController.Summary by CodeRabbit
New Features
update()method to EmbeddedPaymentElement and EmbeddedPaymentElementController, enabling dynamic configuration updates without recreating the payment form.Bug Fixes
Improvements