Repository navigation
feat(ios): pass merchant ID to Wallet setup #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -155,22 +155,32 @@ struct PaymentRequestBuilder { | |||||
| } | ||||||
|
|
||||||
| private static func resolveMerchantIdentifier(from request: PaymentRequest) -> String? { | ||||||
| if let overrideIdentifier = request.applePayMerchantIdentifier?.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines), | ||||||
| resolveMerchantIdentifier(override: request.applePayMerchantIdentifier) | ||||||
| } | ||||||
|
|
||||||
| /// The override when it isn't blank, else the first ID in the Info.plist key. | ||||||
| /// Internal so `openPaymentSetup` can use it. | ||||||
| static func resolveMerchantIdentifier(override: String?) -> String? { | ||||||
| resolveMerchantIdentifier( | ||||||
| override: override, | ||||||
| configured: Bundle.main.object(forInfoDictionaryKey: BundleKey.applePayMerchantIdentifiers) | ||||||
| ) | ||||||
| } | ||||||
|
|
||||||
| /// `configured` is the Info.plist value. Internal so the NitroPay unit tests can pass one. | ||||||
| static func resolveMerchantIdentifier(override: String?, configured: Any?) -> String? { | ||||||
| if let overrideIdentifier = override?.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines), | ||||||
| !overrideIdentifier.isEmpty { | ||||||
| return overrideIdentifier | ||||||
| } | ||||||
|
|
||||||
| if let merchantIdentifiers = Bundle.main.object( | ||||||
| forInfoDictionaryKey: BundleKey.applePayMerchantIdentifiers | ||||||
| ) as? [String] { | ||||||
| if let merchantIdentifiers = configured as? [String] { | ||||||
| return merchantIdentifiers.first { | ||||||
| !$0.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).isEmpty | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| if let merchantIdentifier = Bundle.main.object( | ||||||
| forInfoDictionaryKey: BundleKey.applePayMerchantIdentifiers | ||||||
| ) as? String { | ||||||
| if let merchantIdentifier = configured as? String { | ||||||
| let trimmedIdentifier = merchantIdentifier.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) | ||||||
| return trimmedIdentifier.isEmpty ? nil : trimmedIdentifier | ||||||
| } | ||||||
|
|
@@ -837,10 +847,22 @@ class HybridPaymentHandler: HybridPaymentHandlerSpec { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| func openPaymentSetup() throws { | ||||||
| func openPaymentSetup(options: OpenPaymentSetupOptions?) throws { | ||||||
| let merchantIdentifier = PaymentRequestBuilder.resolveMerchantIdentifier( | ||||||
| override: options?.applePayMerchantIdentifier | ||||||
| ) | ||||||
| // Hands over to Wallet (Settings on iPad); does nothing without Apple Pay support. | ||||||
| DispatchQueue.main.async { | ||||||
| PKPassLibrary().openPaymentSetup() | ||||||
| let library = PKPassLibrary() | ||||||
| // iOS 26.4 attributes a card added in the setup to the merchant ID. | ||||||
| // Needs the iOS 26.4 SDK, which ships with Swift 6.3. | ||||||
| #if compiler(>=6.3) | ||||||
| if #available(iOS 26.4, *), let merchantIdentifier { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add the visionOS availability check. The reviewed podspec supports visionOS 1.0. Apple makes this overload available only from visionOS 26.4. (raw.githubusercontent.com) With compiler version 6.3 or later, this branch is compiled for visionOS. The iOS-only check does not establish visionOS availability, so the new call breaks builds with deployment targets below visionOS 26.4. Swift uses the wildcard for platforms not named in the check. (docs.swift.org) Add Proposed fix
Committable suggestion
|
||||||
| library.openPaymentSetup(merchantIdentifier: merchantIdentifier) | ||||||
| return | ||||||
| } | ||||||
| #endif | ||||||
| library.openPaymentSetup() | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
State the build and merchant ID conditions.
On iOS 26.4 or later, an app built with an older SDK still uses the call without a merchant ID. The same applies when no ID is available. Add these conditions here and in the availability guide.