Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ios/Classes/Extensions/AuthorizationExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,13 @@ extension AuthorizationError {
}
}
}

extension Location {
func toMap() -> [String: Any] {
return [
"id": id,
"currencyCode": currency.getCurrencyCode(),
"name": name
]
}
}
2 changes: 2 additions & 0 deletions ios/Classes/Extensions/ReaderExtension.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SquareMobilePaymentsSDK
#if MOCK_READER_UI_ENABLED
import MockReaderUI

extension MockReaderUIError {
Expand All @@ -18,3 +19,4 @@ extension MockReaderUIError {
}
}
}
#endif
7 changes: 7 additions & 0 deletions ios/Classes/Modules/AuthModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ public class AuthModule {
return result(authManager.state.getName())
}

public static func getAuthorizedLocation(result: @escaping FlutterResult) {
guard let location = authManager.location else {
return result(nil)
}
return result(location.toMap())
}

public static func authorize(
result: @escaping FlutterResult,
accessToken: String,
Expand Down
12 changes: 12 additions & 0 deletions ios/Classes/Modules/ReaderModule.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import Flutter
import SquareMobilePaymentsSDK
#if MOCK_READER_UI_ENABLED
import MockReaderUI
#endif

public class ReaderModule {
private static var globalReaderObserver: ReaderObserverCallback?
private static var globalPairingHandle: PairingHandle?

#if MOCK_READER_UI_ENABLED
static var mockReader: MockReaderUI? = {
do {
return try MockReaderUI(for: MobilePaymentsSDK.shared)
} catch {
return nil
}
}()
#endif

static func parseTapToPayError(error: NSError, defaultError: String) -> String {
let tapToPayReaderError = TapToPayReaderError(rawValue: error.code)
Expand Down Expand Up @@ -53,17 +57,25 @@ public class ReaderModule {
}

public static func showMockReaderUI(result: @escaping FlutterResult) {
#if MOCK_READER_UI_ENABLED
do {
try mockReader?.present()
result("Mock Reader has been successfully presented.")
} catch let error {
result(FlutterError(code: "SHOW_MOCK_READER_UI", message: error.localizedDescription, details: nil))
}
#else
result(FlutterError(code: "MOCK_READER_UNAVAILABLE", message: "MockReaderUI is not available. Add MockReaderUI to your Podfile to enable mock reader support.", details: nil))
#endif
}

public static func hideMockReaderUI(result: @escaping FlutterResult) {
#if MOCK_READER_UI_ENABLED
mockReader?.dismiss()
result("Mock Reader has been successfully hidden.")
#else
result(FlutterError(code: "MOCK_READER_UNAVAILABLE", message: "MockReaderUI is not available. Add MockReaderUI to your Podfile to enable mock reader support.", details: nil))
#endif
}

public static func linkAppleAccount(result: @escaping FlutterResult) {
Expand Down
2 changes: 2 additions & 0 deletions ios/Classes/SquareMobilePaymentsSdkPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class SquareMobilePaymentsSdkPlugin: NSObject, FlutterPlugin, FlutterStre
AuthModule.deauthorize(result: result)
case "getAuthorizationState":
AuthModule.getAuthorizationState(result: result)
case "getAuthorizedLocation":
AuthModule.getAuthorizedLocation(result: result)
case "showMockReaderUI":
ReaderModule.showMockReaderUI(result: result)
case "hideMockReaderUI":
Expand Down
39 changes: 39 additions & 0 deletions ios/enable_mock_reader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Helper to enable MockReaderUI in the square_mobile_payments_sdk Flutter plugin.
#
# MockReaderUI is a debug/sandbox-only tool provided by Square for testing
# in-person payments without physical hardware. It should NOT be included
# in release/production builds submitted to the App Store.
#
# Usage in your app's Podfile:
#
# pod 'MockReaderUI', '~> 2.4.0', :configurations => ['Debug']
#
# post_install do |installer|
# require_relative '.symlinks/plugins/square_mobile_payments_sdk/ios/enable_mock_reader'
# enable_square_mock_reader(installer)
# end
#

def enable_square_mock_reader(installer, configurations: ['Debug'])
installer.pods_project.targets.each do |target|
next unless target.name == 'square_mobile_payments_sdk'

target.build_configurations.each do |config|
next unless configurations.include?(config.name)

# Set the Swift compilation flag so #if MOCK_READER_UI_ENABLED guards compile in
swift_flags = config.build_settings['OTHER_SWIFT_FLAGS'] || '$(inherited)'
unless swift_flags.include?('MOCK_READER_UI_ENABLED')
config.build_settings['OTHER_SWIFT_FLAGS'] = "#{swift_flags} -DMOCK_READER_UI_ENABLED"
end

# Add MockReaderUI to framework search paths so the compiler and linker can find it
search_paths = config.build_settings['FRAMEWORK_SEARCH_PATHS'] || ['$(inherited)']
mock_reader_path = '"${PODS_CONFIGURATION_BUILD_DIR}/MockReaderUI"'
unless search_paths.include?(mock_reader_path)
search_paths << mock_reader_path
config.build_settings['FRAMEWORK_SEARCH_PATHS'] = search_paths
end
end
end
end
6 changes: 5 additions & 1 deletion ios/square_mobile_payments_sdk.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ Allows developers to take in-person payments using Square hardware.
s.platform = :ios, '16.0'

s.dependency "SquareMobilePaymentsSDK", "~> 2.4.0"
s.dependency "MockReaderUI", "~> 2.4.0"
# MockReaderUI is intentionally NOT a hard dependency. It is a sandbox/debug-only
# framework that must not be embedded in App Store builds. Consumer apps that
# need it for development should add it to their Podfile as a Debug-only pod
# and call `enable_square_mock_reader(installer)` from `post_install` (see
# ios/enable_mock_reader.rb).

# Flutter.framework does not contain a i386 slice.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
Expand Down