feat: handle edge cases in payment flow — cancellation and native errors - #36
Merged
Merged
Conversation
…ors (#25) startPayment() previously assigned its onPaymentResult callback only after invokeMethod resolved, so a slow first call could overwrite a faster second call's callback even though it was triggered earlier. The callback slot is now claimed synchronously before the native call is awaited, so the last-triggered request always wins regardless of native completion order, and a superseded call's late failure no longer clobbers a newer callback. invokeMethod('startPayment', ...) now also catches PlatformException and rethrows it as MonextPaymentNativeException, carrying the native SDK's raw error code and message (e.g. an invalid/expired session token) to the Dart caller. Cancellation, timeout, network-error and malformed-JSON outcomes were already relayed as-is through onPaymentResult by design; added tests proving this explicitly per the ticket's acceptance criteria.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #25
Summary
MethodChannelMonextPayment.startPayment: theonPaymentResultcallback slot is now claimed synchronously, before the native call is awaited, instead of after it resolves. Previously, a slower firststartPaymentcall could overwrite a faster second call's callback even though it was triggered earlier — now the last-triggered request always wins, regardless of native completion order, and a superseded call's late failure no longer clobbers a newer callback.PlatformExceptionfrom the nativestartPaymentinvocation and rethrow it as a newMonextPaymentNativeException, carrying the native SDK's rawerrorCodeandmessage(e.g. an invalid/expired session token) to the Dart caller.onPaymentResultby design (no validation/transformation at this layer); added tests proving this explicitly against the ticket's acceptance criteria.Test plan
flutter analyze lib test— no issuesflutter test— 30/30 passing, including new concurrency/error-propagation/raw-relay testsdart format— clean on all touched Dart filesGenerated by Claude Code