Skip to content

fix(ios): let the payer retry after onAuthorize reports a failure - #55

Merged
jkasprzyk17 merged 1 commit into
fix/ios-apple-pay-sheet-windowfrom
fix/ios-authorization-retry
Oct 27, 2026
Merged

jkasprzyk17 merged 1 commit into
fix/ios-apple-pay-sheet-windowfrom
fix/ios-authorization-retry

Conversation

@jkasprzyk17

@jkasprzyk17 jkasprzyk17 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #54. Review and merge that one first; only the last commit belongs to this PR.

Summary

  • iOS: after onAuthorize resolves with 'failure', rejects, or times out, the payer can retry from the same Apple Pay sheet, as testing.md, server-processing.md, the README and the onAuthorize JSDoc already said. Each retry calls onAuthorize again with a new token.
  • Before, the library completed the sheet with PKPaymentAuthorizationResult(status: .failure, errors: nil), which PassKit treats as final: the sheet showed "Payment Failed" and closed by itself. It now completes with PKPaymentError.unknownError carrying the error text. Apple documents that code as non-fatal: "The user can attempt to authorize the transaction again."
  • When the sheet closes, startPayment still resolves with the last attempt's result (code: 'PROVIDER_ERROR' for a failure).
  • Docs: no wording change was needed, because the retry claims are now true. CHANGELOG, plus a line in testing.md saying that the simulator can rehearse a retry.

Test plan

  • cd package && bun run typecheck
  • cd package && bun run lint
  • cd package && bun run test:ci (135 tests)
  • cd package && bun run check:docs
  • cd package && bun run check:pack
  • xcodebuild test ... -scheme NitroPay-Unit-Tests (63 tests, 3 new for AuthorizationResultBuilder)
  • Example app on the iOS 26.5 simulator with the Simulated Server set to decline: after the decline the sheet stays up, a second "Pay" calls onAuthorize again, and closing the sheet resolves with "Declined by the test server". Run before rebasing onto feat: report a typed status and error code on every payment result #52 and feat!: add JS wrappers for the pay buttons #53.
  • bun run docs:build
  • Real iPhone with an Apple Pay sandbox account (not run)
  • ./gradlew :gmisoftware_react-native-pay:testDebugUnitTest (not run; no Kotlin changes)

Risk

  • Behaviour change on iOS: after a decline, the payer stays in the sheet until they retry or close it, so startPayment resolves later than before. Android is unchanged.
  • The 25-second timeout is retryable too, so a retry can start while the timed-out charge is still running on your server. The docs already ask for charges that are idempotent per order ID.

Notes

  • Failure results tried on the iOS 26.5 simulator, read from PassKit's log:

    errors passed with .failure PassKit state Retry
    nil (before) "Checking for errors based on legacy status", then PKPaymentAuthorizationStateFatalError No, the sheet closes
    [] same as nil No
    NSError from another domain PKPaymentAuthorizationStateFatalError No
    PKPaymentError(.unknownError) with a message PKPaymentAuthorizationStateError, then back to Authenticate Yes: a second didAuthorizePayment
  • stripe-ios passes its own error domain here and notes, from iOS 12, that the user "is prompted to try again". On iOS 26.5 that domain is fatal: only PKPaymentErrorDomain errors leave the sheet open.

  • PKPaymentAuthorizationViewController uses the same PKPaymentAuthorizationCoordinator, so the old code closed the sheet in the same way. The retry claim came from feat: let the app settle Apple Pay authorization with onAuthorize #30, whose test plan lists "retry after a failure" as not run.

  • Not verified: a retry that then succeeds (the result logic is unchanged and keeps the last attempt), and whether the sheet shows the error text or only "Payment Failed".


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

PassKit treats a failure that carries no PassKit error as final: the
sheet showed "Payment Failed" and closed, although the docs promise a
retry from the same sheet. Complete a failure, a rejected promise and
the 25-second timeout with PKPaymentError.unknownError and the error
text, which PassKit lets the payer retry. Each retry calls onAuthorize
with a new token.

On the iOS 26.5 simulator, nil, an empty array and an NSError from
another domain all end in PKPaymentAuthorizationStateFatalError, while
unknownError ends in the non-fatal PKPaymentAuthorizationStateError.
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: e441eddd-0fd9-43ec-a51e-6e7a4c3daaf0
Commits

Reviewing files that changed from the base of the PR and between af73ba7 and 40a460b.

Files selected for processing: 4
  • CHANGELOG.md
  • docs/docs/guides/testing.md
  • package/ios/HybridPaymentHandler.swift
  • package/ios/Tests/AuthorizationResultBuilderTests.swift

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 3 reviews per hour.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Apple Pay now displays an error when authorization fails, is rejected, or times out, allowing the payer to retry.
    • When the Apple Pay sheet closes, the payment flow returns the result of the most recent attempt. Failed attempts continue to report a provider error.
  • Documentation
    • Updated the iOS Simulator testing guide to include retrying after an authorization failure.

The iOS authorization delegate now returns a PassKit failure result with a retryable unknown error and an error description. Tests cover success, supplied failure messages, and a fallback message. Documentation describes the retry flow.

Changes: iOS Authorization

Layer / File(s) Summary
Build and validate PassKit authorization results
package/ios/HybridPaymentHandler.swift, package/ios/Tests/AuthorizationResultBuilderTests.swift, CHANGELOG.md, docs/docs/guides/testing.md
The authorization delegate uses a builder that returns a success result without errors or a failure result with a retryable .unknownError. Failure results use the supplied message or the fallback "Payment authorization failed". Tests cover these results. The changelog and testing guide describe the retry flow.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: piotr-graczyk-dev

Merge Risk: Minimal · up to 40a46

The iOS retry change is mergeable after normal checks; no actionable issue is established by the supplied evidence.

Pre-merge checks: Passed 5 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 5 passed
Check name Status Explanation
Title check Passed The title accurately describes the iOS retry behavior and uses the required fix: prefix. It is 65 characters, which exceeds the preferred 50-character length, but it remains concise and descriptive.
Description check Passed The description clearly explains the iOS Apple Pay retry change, implementation behavior, testing, risks, and unverified cases. It is directly related to the changeset.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Security Check Passed No medium, high, or critical vulnerability is introduced. The diff only changes iOS PassKit failure results to use PKPaymentError.unknownError and carries the existing onAuthorize error text in th…
Full details: Security Check

Explanation

No medium, high, or critical vulnerability is introduced. The diff only changes iOS PassKit failure results to use PKPaymentError.unknownError and carries the existing onAuthorize error text in the payment sheet. The text reaches PassKit and the normal PaymentResult.error field; it is not used in a shell, query, URL, deserializer, log sink, or authorization decision. The retry behavior creates a documented need for server-side idempotency by order ID, but it does not bypass authentication or payment authorization and is not a security finding under this check.

Full details: Docstring Coverage

Explanation

Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 2 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.

Comment @coderabbitai help to get the list of available commands.

@jkasprzyk17
jkasprzyk17 merged commit 83afca4 into fix/ios-apple-pay-sheet-window Oct 27, 2026
7 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