Skip to content

feat: handle edge cases in payment flow — cancellation and native errors - #36

Merged
taorepoara merged 1 commit into
mainfrom
feat/25-payment-edge-case-handling
Aug 6, 2026
Merged

feat: handle edge cases in payment flow — cancellation and native errors#36
taorepoara merged 1 commit into
mainfrom
feat/25-payment-edge-case-handling

Conversation

@taorepoara

Copy link
Copy Markdown
Member

Closes #25

Summary

  • Fix a race in MethodChannelMonextPayment.startPayment: the onPaymentResult callback slot is now claimed synchronously, before the native call is awaited, instead of after it resolves. Previously, a slower first startPayment call 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.
  • Catch PlatformException from the native startPayment invocation and rethrow it as a new MonextPaymentNativeException, carrying the native SDK's raw errorCode and message (e.g. an invalid/expired session token) to the Dart caller.
  • Cancellation, timeout, network-error and malformed-JSON outcomes were already relayed untouched through onPaymentResult by 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 issues
  • flutter test — 30/30 passing, including new concurrency/error-propagation/raw-relay tests
  • dart format — clean on all touched Dart files

Generated by Claude Code

…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.
@taorepoara
taorepoara merged commit 0cf4715 into main Aug 6, 2026
5 checks passed
@taorepoara
taorepoara deleted the feat/25-payment-edge-case-handling branch August 6, 2026 07:36
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.

Edge Case Handling for Payment Flows

2 participants