Skip to content

feat(ios): merchant category code and Pay Later - #116

Merged
jkasprzyk17 merged 1 commit into
mainfrom
feat/apple-pay-mcc-pay-later
Nov 23, 2026
Merged

jkasprzyk17 merged 1 commit into
mainfrom
feat/apple-pay-mcc-pay-later

Conversation

@jkasprzyk17

@jkasprzyk17 jkasprzyk17 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Closes #78

Summary

  • Adds PaymentRequest.applePayMerchantCategoryCode?: number. It sets PKPaymentRequest.merchantCategoryCode, an ISO 18245 code from 0 to 9999, through the Swift refinement on iOS 18+, so Apple Pay leaves out the cards that don't accept the category.
  • Adds PaymentRequest.applePayLaterAvailability?: string and the ApplePayLaterAvailability type ('available' | 'itemIneligible' | 'recurringTransaction'). On iOS 17+ these map to .available / .unavailable(.itemIneligible) / .unavailable(.recurringTransaction). The field is a string, not the alias, for the same reason as shippingType.
  • Both values are checked on every iOS version, so an invalid one fails with CONFIGURATION everywhere. Only the assignment sits behind #available, so older iOS versions ignore a valid value. Android ignores both fields.
  • Error messages: Invalid merchant category code <value>. Use a whole number from 0 to 9999 (this covers fractions, NaN and values out of range; the code uses Int16(exactly:), so there is no trap) and Unknown Apple Pay Later availability "<value>". Use "available", "itemIneligible" or "recurringTransaction".
  • Docs: types.md (field notes and a new ApplePayLaterAvailability section), the CONFIGURATION row in payment-flow.md, README.md and CHANGELOG.md.

Test plan

  • cd package && bun run typecheck
  • cd package && bun run lint
  • cd package && bun run test (289 passed)
  • ./gradlew :gmisoftware_react-native-pay:testDebugUnitTest in example/android: 193 passed. No Kotlin behaviour change; this run confirms the fixture compiles against the regenerated PaymentRequest.
  • xcodebuild test ... -scheme NitroPay-Unit-Tests in example/ios on an iOS 26.5 simulator: 141 passed. New tests in PaymentRequestBuilderTests.swift cover both fields reaching PKPaymentRequest, each Pay Later value, the 0 and 9999 edges, invalid codes (-1, 10000, 5411.5, 40000, NaN) and unknown Pay Later strings.
  • cd package && bun run check:docs
  • bun run docs:build
  • bunx expo run:ios / run:android (not run): neither field shows anything in the sheet, so the XCTest assertions on the built request are the check.

Risk

  • Additive and optional; requests without these fields don't change.
  • The branches that ignore the fields below iOS 17 and 18 compile but haven't run: this Mac has only the iOS 26.5 simulator runtime.

Notes

  • Apple Pay Later was discontinued in June 2024. The iOS 27.2 SDK still has applePayLaterAvailability and doesn't deprecate it. Apple doesn't document whether it also hides the bank or Affirm installments that replaced the service. The docs describe the API as Apple defines it; open to wording it differently or adding a note.
  • PassKit's default merchantCategoryCode on a fresh request is 0000, not nil (seen on iOS 26.5), so passing 0 looks the same as leaving the field out. The 0–9999 range follows the issue.
  • usePaymentCheckout doesn't expose either field; this matches the issue's scope, and shippingType isn't in the hook either. The category code is fixed for a merchant, so it could go into the hook config in a follow-up.

Prove it works
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Adds PaymentRequest.applePayMerchantCategoryCode (iOS 18+) and
applePayLaterAvailability (iOS 17+). Both are checked on every iOS
version and fail with CONFIGURATION when invalid; Android ignores them.

Closes #78
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Added options to set an Apple Pay merchant category code and control Apple Pay Later availability.
    • Apple Pay Later availability can be set to available, itemIneligible, or recurringTransaction.
    • Supported settings take effect on iOS 18+ for merchant category codes and iOS 17+ for Apple Pay Later. Android behavior is unchanged.
  • Bug Fixes
    • Invalid values now produce a configuration error.

PaymentRequest adds optional Apple Pay merchant category code and Apple Pay Later availability fields. The iOS builder validates these values and applies supported values on the required iOS versions. Tests and documentation cover the new options and their configuration errors.

Changes: Apple Pay PaymentRequest Options

Layer / File(s) Summary
PaymentRequest fields and documented behavior
package/src/types/Payment.ts, docs/docs/api/types.md, README.md, CHANGELOG.md, docs/docs/payment-flow.md
PaymentRequest now documents the merchant category code and Apple Pay Later availability options. The docs describe accepted values, iOS version handling, and configuration errors. The payment-flow error documentation also lists an Android googlePayGateway validation case.
iOS configuration and validation
package/ios/HybridPaymentHandler.swift, package/ios/Tests/PaymentRequestBuilderTests.swift, package/ios/Tests/TestFixtures.swift, package/ios/Tests/PaymentSheetSessionTests.swift, package/android/src/test/java/com/margelo/nitro/pay/TestFixtures.kt
The iOS builder validates the category code range and availability values, then applies valid values on supported iOS versions. Tests cover valid, omitted, and invalid inputs. Test fixtures pass or initialize both new fields.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

  • Issue 84 tracks the iOS 26 and 27 audit gap for these two options; this change adds both fields, while the issue’s other audit items remain open.

Suggested reviewers: piotr-graczyk-dev

Merge Risk: Minimal · up to e594c · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed Title is 'feat(ios): merchant category code and Pay Later'. It names the conventional type prefix and the two main additions: the merchant category code and Pay Later availability. The changeset adds …
Description check Passed The description is clearly about this changeset. It links issue #78, lists the new applePayMerchantCategoryCode and applePayLaterAvailability fields, explains iOS version gating and CONFIGURATION erro…
Linked Issues check Passed [#78] Both requested fields are added. PaymentRequest.applePayMerchantCategoryCode?: number and PaymentRequest.applePayLaterAvailability?: string exist in package/src/types/Payment.ts, and the `…
Out of Scope Changes check Passed Every changed area maps to #78 or its acceptance criteria. The changes are: TypeScript types (Payment.ts); iOS builder logic and error messages (HybridPaymentHandler.swift); iOS and Android test f…
Security Check Passed No medium, high, or critical security vulnerability is introduced by this PR. Scope checked: the committed diff range (15 files). The security-relevant code is the iOS path in `package/ios/HybridPayme…
Full details: Title check

Explanation

Title is 'feat(ios): merchant category code and Pay Later'. It names the conventional type prefix and the two main additions: the merchant category code and Pay Later availability. The changeset adds both fields to PaymentRequest, so the title matches the main change. It is 47 characters, under the 50-character target. Brutal verdict: the title is decent, and the one thing it could do better is name the actual fields. It passes.

Full details: Description check

Explanation

The description is clearly about this changeset. It links issue #78, lists the new applePayMerchantCategoryCode and applePayLaterAvailability fields, explains iOS version gating and CONFIGURATION errors, names the docs and tests touched, and gives a test plan. Brutally direct: it is thorough, and it passes with no contest.

Full details: Linked Issues check

Explanation

[#78] Both requested fields are added. PaymentRequest.applePayMerchantCategoryCode?: number and PaymentRequest.applePayLaterAvailability?: string exist in package/src/types/Payment.ts, and the ApplePayLaterAvailability union is exported. PaymentRequestBuilder.build in package/ios/HybridPaymentHandler.swift validates both values on every iOS version. Valid category codes are set on PKPaymentRequest.merchantCategoryCode behind an iOS 18 #available guard. Valid Pay Later values map to .available, .unavailable(.itemIneligible) and .unavailable(.recurringTransaction) behind an iOS 17 guard. Invalid values throw CONFIGURATION. Android test fixtures set both fields to null, and no Kotlin behaviour changes. PaymentRequestBuilderTests.swift covers the setters, the 0 and 9999 edges, invalid codes (-1, 10000, 5411.5, 40000, NaN) and unknown Pay Later strings. The PR reports 141 iOS tests passing on iOS 26.5. types.md documents both fields and the new type. The generated PaymentRequest.swift and Kotlin/C++ bindings are excluded from review; their content was not inspected. Their presence is supported by the Android fixture compiling against the regenerated type and by the passing iOS tests. The iOS 17 and iOS 18 guarded branches were compiled but not executed on those OS versions. This does not block the assessment, because the requirement is the guard, and the guard is present.

Full details: Out of Scope Changes check

Explanation

Every changed area maps to #78 or its acceptance criteria. The changes are: TypeScript types (Payment.ts); iOS builder logic and error messages (HybridPaymentHandler.swift); iOS and Android test fixtures that add the new fields; iOS XCTest coverage; and docs for the new fields, the ApplePayLaterAvailability section, the README.md example and CHANGELOG.md. The CONFIGURATION row in payment-flow.md also gains an Android googlePayGateway case. That case predates this PR and is unrelated to #78. It is a one-line documentation change in the same table row, so it is minor and does not justify a FAIL. usePaymentCheckout is not changed, which matches the issue scope. No unrelated code changes were identified.

Full details: Security Check

Explanation

No medium, high, or critical security vulnerability is introduced by this PR. Scope checked: the committed diff range (15 files). The security-relevant code is the iOS path in package/ios/HybridPaymentHandler.swift, plus the generated bridge (nitrogen/generated/ios/swift/PaymentRequest.swift) and the TypeScript type (package/src/types/Payment.ts). - Category code: configureMerchantCategoryCode converts the input with Int16(exactly:) and checks 0...9999 before any assignment. NaN, infinity, fractions, and out-of-range values return nil and throw CONFIGURATION. No trap or overflow path exists. The value is then passed through PKPaymentRequest.MerchantCategoryCode(rawValue:) on iOS 18+ only. - Pay Later: configureApplePayLater maps the string through a closed Swift enum (available, itemIneligible, recurringTransaction). Any other string throws CONFIGURATION. Only the three known cases reach PassKit. No injection or unsafe deserialization sink exists. - Error messages: The new messages echo the rejected value back to the thrown error. The value comes from the app's own payment configuration, not from a remote or untrusted party. This is not a log-leak or injection sink in this code. - Auth, secrets, network, dependencies: The diff adds no network calls, no logging of sensitive data, no secrets, no new dependencies, and no permission or authorization changes. Android ignores both fields. - Tests and docs: The XCTest and fixture changes and the documentation edits add no executable attack surface. No injection, authn/authz, secret leakage, SSRF, XSS, request forgery, path traversal, deserialization, or supply-chain risk was found in the changed code. Per the check, no finding comments are required. Gaps: I did not run the test suite or build. The verdict rests on reading the committed diff.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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: c008e866-6a96-40ee-b0d5-28a095f145c9
Commits

Reviewing files that changed from the base of the PR and between b1dd364 and e594ccc.

Files ignored due to path filters: 4

  • package/nitrogen/generated/android/c++/JPaymentRequest.hpp is excluded by !**/generated/**
  • package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentRequest.kt is excluded by !**/generated/**
  • package/nitrogen/generated/ios/swift/PaymentRequest.swift is excluded by !**/generated/**
  • package/nitrogen/generated/shared/c++/PaymentRequest.hpp is excluded by !**/generated/**
Files selected for processing: 10

  • CHANGELOG.md
  • README.md
  • docs/docs/api/types.md
  • docs/docs/payment-flow.md
  • package/android/src/test/java/com/margelo/nitro/pay/TestFixtures.kt
  • package/ios/HybridPaymentHandler.swift
  • package/ios/Tests/PaymentRequestBuilderTests.swift
  • package/ios/Tests/PaymentSheetSessionTests.swift
  • package/ios/Tests/TestFixtures.swift
  • package/src/types/Payment.ts

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 2 reviews per hour.

@jkasprzyk17
jkasprzyk17 merged commit d731257 into main Nov 23, 2026
8 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.

iOS: merchantCategoryCode and applePayLaterAvailability on PaymentRequest

1 participant