@connexup/react-native-square-mobile-payment-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/LICENSE +20 -0
  2. package/NativeSquareMobilePaymentSDK.podspec +23 -0
  3. package/README.md +66 -0
  4. package/android/build.gradle +81 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/com/connexup/square/mobilepayment/DateFormatUtils.java +29 -0
  8. package/android/src/main/java/com/connexup/square/mobilepayment/ErrorUtilities.kt +56 -0
  9. package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentAuthorization.kt +185 -0
  10. package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentException.kt +8 -0
  11. package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentPayment.kt +542 -0
  12. package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentReader.kt +344 -0
  13. package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentSDK.kt +47 -0
  14. package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentSDKPackage.kt +77 -0
  15. package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentSetting.kt +144 -0
  16. package/android/src/main/java/com/connexup/square/mobilepayment/convert/AdditionalPaymentMethodConvert.kt +46 -0
  17. package/android/src/main/java/com/connexup/square/mobilepayment/convert/AuthorizationStateConvert.kt +26 -0
  18. package/android/src/main/java/com/connexup/square/mobilepayment/convert/CardConvert.kt +53 -0
  19. package/android/src/main/java/com/connexup/square/mobilepayment/convert/CardDetailsConvert.kt +74 -0
  20. package/android/src/main/java/com/connexup/square/mobilepayment/convert/CardEntryMethodConvert.kt +31 -0
  21. package/android/src/main/java/com/connexup/square/mobilepayment/convert/CashPaymentDetailsConvert.kt +18 -0
  22. package/android/src/main/java/com/connexup/square/mobilepayment/convert/CurrencyCodeConvert.kt +204 -0
  23. package/android/src/main/java/com/connexup/square/mobilepayment/convert/DelayActionConvert.kt +33 -0
  24. package/android/src/main/java/com/connexup/square/mobilepayment/convert/DeniedReasonConvert.kt +28 -0
  25. package/android/src/main/java/com/connexup/square/mobilepayment/convert/DigitalWalletDetailsConvert.kt +18 -0
  26. package/android/src/main/java/com/connexup/square/mobilepayment/convert/ErrorDetailsConvert.kt +32 -0
  27. package/android/src/main/java/com/connexup/square/mobilepayment/convert/ExternalPaymentDetailsConvert.kt +25 -0
  28. package/android/src/main/java/com/connexup/square/mobilepayment/convert/LocationConvert.kt +31 -0
  29. package/android/src/main/java/com/connexup/square/mobilepayment/convert/MoneyConvert.kt +31 -0
  30. package/android/src/main/java/com/connexup/square/mobilepayment/convert/OfflineStatusConvert.kt +21 -0
  31. package/android/src/main/java/com/connexup/square/mobilepayment/convert/PaymentConvert.kt +93 -0
  32. package/android/src/main/java/com/connexup/square/mobilepayment/convert/PaymentProcessingFeeConvert.kt +39 -0
  33. package/android/src/main/java/com/connexup/square/mobilepayment/convert/PaymentSettingsConvert.kt +26 -0
  34. package/android/src/main/java/com/connexup/square/mobilepayment/convert/ProcessingModeConvert.kt +28 -0
  35. package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderBatteryStatusConvert.kt +19 -0
  36. package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderChangeEventConvert.kt +75 -0
  37. package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderConnectionTypeConvert.kt +17 -0
  38. package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderInfoConvert.kt +51 -0
  39. package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderModalConvert.kt +18 -0
  40. package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderStateConvert.kt +51 -0
  41. package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderStatusConvert.kt +51 -0
  42. package/android/src/main/java/com/connexup/square/mobilepayment/convert/SdkSettingsConvert.kt +30 -0
  43. package/android/src/main/java/com/connexup/square/mobilepayment/convert/SquareAccountDetailsConvert.kt +20 -0
  44. package/android/src/main/java/com/connexup/square/mobilepayment/convert/TrackingConsentStateConvert.kt +17 -0
  45. package/android/src/main/java/com/connexup/square/mobilepayment/convert/WalletBrandConvert.kt +41 -0
  46. package/ios/Converters/AdditionalPaymentMethod+Extension.swift +17 -0
  47. package/ios/Converters/AdditionalPaymentMethodType+Extension.swift +44 -0
  48. package/ios/Converters/AuthorizationState+Extension.swift +22 -0
  49. package/ios/Converters/BatteryLevel+Extension.swift +27 -0
  50. package/ios/Converters/Card+Extension.swift +33 -0
  51. package/ios/Converters/CardBrand+Extension.swift +47 -0
  52. package/ios/Converters/CardCoBrand+Extension.swift +24 -0
  53. package/ios/Converters/CardEntryMethod+Extension.swift +30 -0
  54. package/ios/Converters/CardInputMethods+Extension.swift +35 -0
  55. package/ios/Converters/CardInsertionStatus+Extension.swift +24 -0
  56. package/ios/Converters/CardPaymentDetails+Extensions.swift +31 -0
  57. package/ios/Converters/CardPaymentStatus+Extension.swift +28 -0
  58. package/ios/Converters/Currency+Extension.swift +50 -0
  59. package/ios/Converters/Location+Extension.swift +19 -0
  60. package/ios/Converters/MoneyAmount+Extension.swift +30 -0
  61. package/ios/Converters/Payment+Extension.swift +44 -0
  62. package/ios/Converters/PaymentSettings+Extension.swift +19 -0
  63. package/ios/Converters/PaymentStatus+Extension.swift +53 -0
  64. package/ios/Converters/ProcessingMode+Extension.swift +37 -0
  65. package/ios/Converters/ReaderBatteryStatus+Extension.swift +19 -0
  66. package/ios/Converters/ReaderChange+Extension.swift +41 -0
  67. package/ios/Converters/ReaderConnectionFailureInfo+Extension.swift +20 -0
  68. package/ios/Converters/ReaderConnectionFailureReason+Extension.swift +40 -0
  69. package/ios/Converters/ReaderConnectionFailureRecoverySuggestion+Extension.swift +30 -0
  70. package/ios/Converters/ReaderConnectionInfo+Extension.swift +18 -0
  71. package/ios/Converters/ReaderConnectionStatus+Extension.swift +26 -0
  72. package/ios/Converters/ReaderFirmwareInfo+Extension.swift +19 -0
  73. package/ios/Converters/ReaderInfo+Extension.swift +30 -0
  74. package/ios/Converters/ReaderModel+Extension.swift +28 -0
  75. package/ios/Converters/ReaderState+Extension.swift +30 -0
  76. package/ios/Converters/ReaderStatus+Extension.swift +60 -0
  77. package/ios/Converters/ReaderStatusInfo+Extension.swift +22 -0
  78. package/ios/Converters/SDKSettings+Extension.swift +25 -0
  79. package/ios/Converters/SourceType+Extension.swift +32 -0
  80. package/ios/Converters/TrackingConsentState+Extension.swift +25 -0
  81. package/ios/ErrorUtilities.swift +41 -0
  82. package/ios/MobilePaymentAuthorization.swift +154 -0
  83. package/ios/MobilePaymentDateFormatter.swift +15 -0
  84. package/ios/MobilePaymentPayment.swift +478 -0
  85. package/ios/MobilePaymentReader.swift +248 -0
  86. package/ios/MobilePaymentSDK.swift +36 -0
  87. package/ios/MobilePaymentSetting.swift +86 -0
  88. package/ios/MockReaderUIManage.swift +52 -0
  89. package/ios/Models/NativeErrorInfo.swift +22 -0
  90. package/ios/Models/RCTPaymentMoneyParameter.swift +20 -0
  91. package/ios/Models/RCTPaymentParameters.swift +50 -0
  92. package/ios/Models/RCTPromptParameters.swift +20 -0
  93. package/ios/NotificationKeys.swift +9 -0
  94. package/ios/NotificationUtils.swift +21 -0
  95. package/ios/RCTMobilePaymentAuthorization.h +12 -0
  96. package/ios/RCTMobilePaymentAuthorization.mm +78 -0
  97. package/ios/RCTMobilePaymentPayment.h +12 -0
  98. package/ios/RCTMobilePaymentPayment.mm +116 -0
  99. package/ios/RCTMobilePaymentReader.h +12 -0
  100. package/ios/RCTMobilePaymentReader.mm +114 -0
  101. package/ios/RCTMobilePaymentSetting.h +10 -0
  102. package/ios/RCTMobilePaymentSetting.mm +94 -0
  103. package/ios/UIColor+Extension.swift +81 -0
  104. package/lib/module/authorization/NativeMobilePaymentAuthorization.js +60 -0
  105. package/lib/module/authorization/NativeMobilePaymentAuthorization.js.map +1 -0
  106. package/lib/module/authorization/index.js +44 -0
  107. package/lib/module/authorization/index.js.map +1 -0
  108. package/lib/module/index.js +7 -0
  109. package/lib/module/index.js.map +1 -0
  110. package/lib/module/package.json +1 -0
  111. package/lib/module/payment/NativeMobilePaymentPayment.js +138 -0
  112. package/lib/module/payment/NativeMobilePaymentPayment.js.map +1 -0
  113. package/lib/module/payment/index.js +113 -0
  114. package/lib/module/payment/index.js.map +1 -0
  115. package/lib/module/reader/NativeMobilePaymentReader.js +151 -0
  116. package/lib/module/reader/NativeMobilePaymentReader.js.map +1 -0
  117. package/lib/module/reader/index.js +109 -0
  118. package/lib/module/reader/index.js.map +1 -0
  119. package/lib/module/setting/NativeMobilePaymentSetting.js +5 -0
  120. package/lib/module/setting/NativeMobilePaymentSetting.js.map +1 -0
  121. package/lib/module/setting/index.js +74 -0
  122. package/lib/module/setting/index.js.map +1 -0
  123. package/lib/module/type.js +27 -0
  124. package/lib/module/type.js.map +1 -0
  125. package/lib/module/util.js +32 -0
  126. package/lib/module/util.js.map +1 -0
  127. package/lib/typescript/package.json +1 -0
  128. package/lib/typescript/src/authorization/NativeMobilePaymentAuthorization.d.ts +82 -0
  129. package/lib/typescript/src/authorization/NativeMobilePaymentAuthorization.d.ts.map +1 -0
  130. package/lib/typescript/src/authorization/index.d.ts +14 -0
  131. package/lib/typescript/src/authorization/index.d.ts.map +1 -0
  132. package/lib/typescript/src/index.d.ts +5 -0
  133. package/lib/typescript/src/index.d.ts.map +1 -0
  134. package/lib/typescript/src/payment/NativeMobilePaymentPayment.d.ts +725 -0
  135. package/lib/typescript/src/payment/NativeMobilePaymentPayment.d.ts.map +1 -0
  136. package/lib/typescript/src/payment/index.d.ts +13 -0
  137. package/lib/typescript/src/payment/index.d.ts.map +1 -0
  138. package/lib/typescript/src/reader/NativeMobilePaymentReader.d.ts +318 -0
  139. package/lib/typescript/src/reader/NativeMobilePaymentReader.d.ts.map +1 -0
  140. package/lib/typescript/src/reader/index.d.ts +19 -0
  141. package/lib/typescript/src/reader/index.d.ts.map +1 -0
  142. package/lib/typescript/src/setting/NativeMobilePaymentSetting.d.ts +49 -0
  143. package/lib/typescript/src/setting/NativeMobilePaymentSetting.d.ts.map +1 -0
  144. package/lib/typescript/src/setting/index.d.ts +17 -0
  145. package/lib/typescript/src/setting/index.d.ts.map +1 -0
  146. package/lib/typescript/src/type.d.ts +23 -0
  147. package/lib/typescript/src/type.d.ts.map +1 -0
  148. package/lib/typescript/src/util.d.ts +3 -0
  149. package/lib/typescript/src/util.d.ts.map +1 -0
  150. package/package.json +178 -0
  151. package/src/authorization/NativeMobilePaymentAuthorization.ts +297 -0
  152. package/src/authorization/index.ts +60 -0
  153. package/src/index.ts +4 -0
  154. package/src/payment/NativeMobilePaymentPayment.ts +1220 -0
  155. package/src/payment/index.ts +161 -0
  156. package/src/reader/NativeMobilePaymentReader.ts +463 -0
  157. package/src/reader/index.ts +140 -0
  158. package/src/setting/NativeMobilePaymentSetting.ts +254 -0
  159. package/src/setting/index.ts +91 -0
  160. package/src/type.ts +35 -0
  161. package/src/util.ts +31 -0
@@ -0,0 +1,248 @@
1
+ //
2
+ // RNMobilePaymentReader.swift
3
+ //
4
+ // Created by chancetio on 2023/9/12.
5
+ //
6
+ import Foundation
7
+ import SquareMobilePaymentsSDK
8
+
9
+ let PairingErrorAlreadyInProgress = "PAIRING_ERROR_ALREADY_IN_PROGRESS"
10
+ let PairingErrorNotAuthorized = "PAIRING_ERROR_NOT_AUTHORIZED"
11
+ let PairingErrorSandboxNotSupported = "PAIRING_ERROR_SANDBOX_NOT_SUPPORTED"
12
+ let PairingErrorSimulatorNotSupported = "PAIRING_ERROR_SIMULATOR_NOT_SUPPORTED"
13
+ let PairingErrorTimedOut = "PAIRING_ERROR_TIMED_OUT"
14
+ let PairingErrorReaderAlreadyPairing = "PAIRING_ERROR_READER_ALREADY_PAIRING"
15
+ let PairingErrorFailedToConnect = "PAIRING_ERROR_FAILED_TO_CONNECT"
16
+ let PairingErrorBluetoothDisabled = "PAIRING_ERROR_BLUETOOTH_DISABLED"
17
+ let PairingErrorUpdateRequired = "PAIRING_ERROR_UPDATE_REQUIRED"
18
+ let PairingErrorBluetoothPermissionNotDetermined = "PAIRING_ERROR_BLUETOOTH_PERMISSION_NOT_DETERMINED"
19
+ let PairingErrorBluetoothPermissionRestricted = "PAIRING_ERROR_BLUETOOTH_PERMISSION_RESTRICTED"
20
+ let PairingErrorBluetoothPermissionDenied = "PAIRING_ERROR_BLUETOOTH_PERMISSION_DENIED"
21
+ let PairingErrorBluetoothPermissionUnknownCase = "PAIRING_ERROR_BLUETOOTH_PERMISSION_UNKNOWN_CASE"
22
+ let PairingErrorBluetoothNotSupported = "PAIRING_ERROR_BLUETOOTH_NOT_SUPPORTED"
23
+ let PairingErrorBluetoothNotReady = "PAIRING_ERROR_BLUETOOTH_NOT_READY"
24
+ let PairingErrorBluetoothResetting = "PAIRING_ERROR_BLUETOOTH_RESETTING"
25
+ let PairingErrorBondingRemoved = "PAIRING_ERROR_BONDING_REMOVED"
26
+ let PairingErrorBluetoothUnknownError = "PAIRING_ERROR_BLUETOOTH_UNKNOWN_ERROR"
27
+
28
+ @objc public protocol RCTMobilePaymentReaderEventEmitter {
29
+ func onReaderChange(_ value: [String: Any])
30
+ func onReaderPairingStatusChange(_ value: [String: Any])
31
+ }
32
+
33
+ @objcMembers
34
+ public class MobilePaymentReader: NSObject {
35
+ private var pairHandle: PairingHandle?
36
+
37
+ private lazy var observer = MobilePaymentReaderObserver(owner: self)
38
+
39
+ public weak var emitter: RCTMobilePaymentReaderEventEmitter?
40
+
41
+ deinit {
42
+ invalidate()
43
+ }
44
+
45
+ public func initialize() {
46
+ NotificationUtils.addObserver(self, selector: #selector(onSDKInitialize), name: MobilePaymentNotificationKeys.sdkInitialized.rawValue)
47
+ if MobilePaymentSDK.shared.isInitialized {
48
+ onSDKInitialize()
49
+ }
50
+ }
51
+
52
+ public func invalidate() {
53
+ NotificationUtils.removeObserver(self)
54
+ if MobilePaymentSDK.shared.isInitialized {
55
+ MobilePaymentsSDK.shared.readerManager.remove(observer)
56
+ }
57
+ }
58
+
59
+ @objc
60
+ private func onSDKInitialize() {
61
+ MobilePaymentsSDK.shared.readerManager.remove(observer)
62
+ MobilePaymentsSDK.shared.readerManager.add(observer)
63
+ }
64
+
65
+ public func isPairingInProgress() -> Bool {
66
+ return MobilePaymentsSDK.shared.readerManager.isPairingInProgress
67
+ }
68
+
69
+ public func readers() -> [[String: Any]] {
70
+ return MobilePaymentsSDK.shared.readerManager.readers.map { $0.jsonDictionary
71
+ }
72
+ }
73
+
74
+ public func bink(readerId: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
75
+ DispatchQueue.main.async {
76
+ guard let reader = self.getReaderById(id: readerId) else {
77
+ completion(NativeErrorInfo(code: ErrorUtilities.UNKNOWN_ERROR, message: ErrorUtilities.createNativeModuleError(code: ErrorUtilities.UNKNOWN_ERROR, message: "Reader Not Found"), error: nil))
78
+ return
79
+ }
80
+ if !reader.isBlinkable {
81
+ completion(NativeErrorInfo(code: ErrorUtilities.UNKNOWN_ERROR, message: ErrorUtilities.createNativeModuleError(code: ErrorUtilities.UNKNOWN_ERROR, message: "Reader Cannot Bink"), error: nil))
82
+ return
83
+ }
84
+ MobilePaymentsSDK.shared.readerManager.blink(reader)
85
+ completion(nil)
86
+ }
87
+ }
88
+
89
+ public func forget(readerId: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
90
+ DispatchQueue.main.async {
91
+ guard let reader = self.getReaderById(id: readerId) else {
92
+ completion(NativeErrorInfo(code: ErrorUtilities.UNKNOWN_ERROR, message: ErrorUtilities.createNativeModuleError(code: ErrorUtilities.UNKNOWN_ERROR, message: "Reader Not Found"), error: nil))
93
+ return
94
+ }
95
+ if !reader.isForgettable {
96
+ completion(NativeErrorInfo(code: ErrorUtilities.UNKNOWN_ERROR, message: ErrorUtilities.createNativeModuleError(code: ErrorUtilities.UNKNOWN_ERROR, message: "Reader Cannot Forget"), error: nil))
97
+ return
98
+ }
99
+ MobilePaymentsSDK.shared.readerManager.forget(reader)
100
+ completion(nil)
101
+ }
102
+ }
103
+
104
+ public func retryConnection(readerId: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
105
+ DispatchQueue.main.async {
106
+ guard let reader = self.getReaderById(id: readerId) else {
107
+ completion(NativeErrorInfo(code: ErrorUtilities.UNKNOWN_ERROR, message: ErrorUtilities.createNativeModuleError(code: ErrorUtilities.UNKNOWN_ERROR, message: "Reader Not Found"), error: nil))
108
+ return
109
+ }
110
+ if !reader.isConnectionRetryable {
111
+ completion(NativeErrorInfo(code: ErrorUtilities.UNKNOWN_ERROR, message: ErrorUtilities.createNativeModuleError(code: ErrorUtilities.UNKNOWN_ERROR, message: "Reader Cannot Retry Connection"), error: nil))
112
+ return
113
+ }
114
+ MobilePaymentsSDK.shared.readerManager.retryConnection(reader)
115
+ completion(nil)
116
+ }
117
+ }
118
+
119
+ public func startPairing(completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
120
+ DispatchQueue.main.async {
121
+ self.pairHandle = MobilePaymentsSDK.shared.readerManager.startPairing(with: self.observer)
122
+ completion(nil)
123
+ }
124
+ }
125
+
126
+ public func stopPairing(resolve: @escaping (_ value: Bool) -> Void,
127
+ reject: @escaping (_ error: NativeErrorInfo) -> Void)
128
+ {
129
+ DispatchQueue.main.async {
130
+ guard let pairHandle = self.pairHandle else {
131
+ resolve(true)
132
+ return
133
+ }
134
+ let isOk = pairHandle.stop() == true
135
+ if isOk {
136
+ self.pairHandle = nil
137
+ }
138
+ resolve(isOk)
139
+ }
140
+ }
141
+
142
+ private func getReaderById(id: String) -> ReaderInfo? {
143
+ guard let id = UInt(id) else {
144
+ return nil
145
+ }
146
+ return MobilePaymentsSDK.shared.readerManager.readers.first(where: { $0.id == id })
147
+ }
148
+ }
149
+
150
+ class MobilePaymentReaderObserver {
151
+ weak var owner: MobilePaymentReader?
152
+
153
+ init(owner: MobilePaymentReader) {
154
+ self.owner = owner
155
+ }
156
+ }
157
+
158
+ extension MobilePaymentReaderObserver: ReaderObserver {
159
+ func readerWasAdded(_ readerInfo: ReaderInfo) {
160
+ sendReaderChangeEvent(name: "readerWasAdded", readerInfo: readerInfo, change: nil)
161
+ }
162
+
163
+ func readerWasRemoved(_ readerInfo: ReaderInfo) {
164
+ sendReaderChangeEvent(name: "readerWasRemoved", readerInfo: readerInfo, change: nil)
165
+ }
166
+
167
+ func readerDidChange(_ readerInfo: ReaderInfo, change: ReaderChange) {
168
+ sendReaderChangeEvent(name: "readerDidChange", readerInfo: readerInfo, change: change)
169
+ }
170
+
171
+ private func sendReaderChangeEvent(name: String, readerInfo: ReaderInfo, change: ReaderChange?) {
172
+ var body: [String: Any] = [:]
173
+ body["name"] = name
174
+ body["readerInfo"] = readerInfo.jsonDictionary
175
+ body["readerChange"] = change?.jsonValue
176
+ owner?.emitter?.onReaderChange(body)
177
+ }
178
+ }
179
+
180
+ extension MobilePaymentReaderObserver: ReaderPairingDelegate {
181
+ func readerPairingDidBegin() {
182
+ sendPairingStatusChangeEvent(name: "didBegin", error: nil)
183
+ }
184
+
185
+ func readerPairingDidSucceed() {
186
+ sendPairingStatusChangeEvent(name: "didSucceed", error: nil)
187
+ }
188
+
189
+ func readerPairingDidFail(with error: any Error) {
190
+ sendPairingStatusChangeEvent(name: "didFail", error: error)
191
+ }
192
+
193
+ private func sendPairingStatusChangeEvent(name: String, error: Error?) {
194
+ var body: [String: Any] = [:]
195
+ body["name"] = name
196
+ if let error = error {
197
+ let realError = error as NSError
198
+ let errorCode = pairingErrorCode(nativeErrorCode: realError.code)
199
+ body["error"] = ErrorUtilities.serializeErrorToJson(code: errorCode, error: realError)
200
+ }
201
+ owner?.emitter?.onReaderPairingStatusChange(body)
202
+ }
203
+
204
+ private func pairingErrorCode(nativeErrorCode: Int) -> String {
205
+ if let error = ReaderPairingError(rawValue: nativeErrorCode) {
206
+ switch error {
207
+ case .bluetoothDisabled:
208
+ return PairingErrorBluetoothDisabled
209
+ case .bluetoothNotReady:
210
+ return PairingErrorBluetoothNotReady
211
+ case .bluetoothNotSupported:
212
+ return PairingErrorBluetoothNotSupported
213
+ case .bluetoothPermissionDenied:
214
+ return PairingErrorBluetoothPermissionDenied
215
+ case .bluetoothPermissionNotDetermined:
216
+ return PairingErrorBluetoothPermissionNotDetermined
217
+ case .bluetoothPermissionRestricted:
218
+ return PairingErrorBluetoothPermissionRestricted
219
+ case .bluetoothPermissionUnknownCase:
220
+ return PairingErrorBluetoothPermissionUnknownCase
221
+ case .bluetoothResetting:
222
+ return PairingErrorBluetoothResetting
223
+ case .bluetoothUnknownError:
224
+ return PairingErrorBluetoothUnknownError
225
+ case .bondingRemoved:
226
+ return PairingErrorBondingRemoved
227
+ case .failedToConnect:
228
+ return PairingErrorFailedToConnect
229
+ case .notAuthorized:
230
+ return PairingErrorNotAuthorized
231
+ case .sandboxNotSupported:
232
+ return PairingErrorSandboxNotSupported
233
+ case .simulatorNotSupported:
234
+ return PairingErrorSimulatorNotSupported
235
+ case .readerAlreadyPairing:
236
+ return PairingErrorReaderAlreadyPairing
237
+ case .timedOut:
238
+ return PairingErrorTimedOut
239
+ case .updateRequired:
240
+ return PairingErrorUpdateRequired
241
+ @unknown default:
242
+ return ErrorUtilities.UNKNOWN_ERROR
243
+ }
244
+ } else {
245
+ return ErrorUtilities.UNKNOWN_ERROR
246
+ }
247
+ }
248
+ }
@@ -0,0 +1,36 @@
1
+ import SquareMobilePaymentsSDK
2
+
3
+ @objc
4
+ public final class MobilePaymentSDK: NSObject {
5
+ @objc public static let shared = MobilePaymentSDK()
6
+
7
+ private override init() {}
8
+
9
+ public private(set) var applicationId: String?
10
+
11
+ private var launchOptionsKey: [UIApplication.LaunchOptionsKey: Any]?
12
+
13
+ public var isInitialized: Bool {
14
+ return applicationId != nil
15
+ }
16
+
17
+ @objc
18
+ public func setLaunchOptions(_ launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
19
+ launchOptionsKey = launchOptions
20
+ }
21
+
22
+ @objc
23
+ public func initialize(applicationId: String) -> Bool {
24
+ return initialize(applicationId: applicationId, launchOptionsKey: launchOptionsKey)
25
+ }
26
+
27
+ private func initialize(applicationId: String, launchOptionsKey: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
28
+ guard !isInitialized else {
29
+ return self.applicationId == applicationId
30
+ }
31
+ MobilePaymentsSDK.initialize(applicationLaunchOptions: launchOptionsKey, squareApplicationID: applicationId)
32
+ self.applicationId = applicationId
33
+ NotificationUtils.post(name: MobilePaymentNotificationKeys.sdkInitialized.rawValue)
34
+ return true
35
+ }
36
+ }
@@ -0,0 +1,86 @@
1
+ //
2
+ // MobilePaymentSetting.swift
3
+ //
4
+ // Created by chancetio on 2024/6/18.
5
+ //
6
+
7
+ import Foundation
8
+ import SquareMobilePaymentsSDK
9
+
10
+ let InitSDKError = "INIT_SDK_ERROR"
11
+ let PresentSettingsErrorUnexpected = "PRESENT_SETTINGS_ERROR_UNEXPECTED"
12
+ let PresentMockUIErrorUnexpected = "PRESENT_MOCK_UI_ERROR_UNEXPECTED"
13
+
14
+ @objcMembers public class MobilePaymentSetting: NSObject {
15
+ public func initialize(applicationId: String,
16
+ resolve: @escaping (_ value: Bool) -> Void,
17
+ reject: @escaping (_ error: NativeErrorInfo) -> Void)
18
+ {
19
+ DispatchQueue.main.async {
20
+ resolve(MobilePaymentSDK.shared.initialize(applicationId: applicationId))
21
+ }
22
+ }
23
+
24
+ public func applicationId() -> String? {
25
+ return MobilePaymentSDK.shared.applicationId
26
+ }
27
+
28
+ public func sdkSettings() -> [String: Any] {
29
+ return MobilePaymentsSDK.shared.settingsManager.sdkSettings.jsonDictionary
30
+ }
31
+
32
+ public func paymentSettings() -> [String: Any] {
33
+ return MobilePaymentsSDK.shared.settingsManager.paymentSettings.jsonDictionary
34
+ }
35
+
36
+ public func trackingConsentState() -> String {
37
+ return MobilePaymentsSDK.shared.settingsManager.trackingConsentState.jsonValue
38
+ }
39
+
40
+ public func updateTrackingConsent(granted: Bool, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
41
+ DispatchQueue.main.async {
42
+ MobilePaymentsSDK.shared.settingsManager.updateTrackingConsent(withGranted: granted)
43
+ completion(nil)
44
+ }
45
+ }
46
+
47
+ public func presentSettings(completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
48
+ DispatchQueue.main.async {
49
+ guard let rootViewController = UIApplication.shared.delegate?.window??.rootViewController else {
50
+ completion(NativeErrorInfo(code: ErrorUtilities.UNKNOWN_ERROR, message: ErrorUtilities.createNativeModuleError(code: ErrorUtilities.UNKNOWN_ERROR, message: "RootViewController Not Found"), error: nil))
51
+ return
52
+ }
53
+ MobilePaymentsSDK.shared.settingsManager.presentSettings(with: rootViewController) { [weak self] error in
54
+ guard self != nil else {
55
+ return
56
+ }
57
+
58
+ if let error = error as? NSError {
59
+ completion(NativeErrorInfo(code: PresentSettingsErrorUnexpected, message: ErrorUtilities.serializeErrorToJson(code: PresentSettingsErrorUnexpected, error: error as NSError), error: error))
60
+ return
61
+ }
62
+
63
+ completion(nil)
64
+ }
65
+ }
66
+ }
67
+
68
+ public func presentMockReaderUI(completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
69
+ DispatchQueue.main.async {
70
+ do {
71
+ MockReaderUIManage.shared.dismiss()
72
+ try MockReaderUIManage.shared.present()
73
+ completion(nil)
74
+ } catch {
75
+ completion(NativeErrorInfo(code: PresentMockUIErrorUnexpected, message: ErrorUtilities.serializeErrorToJson(code: PresentMockUIErrorUnexpected, error: error as NSError), error: error))
76
+ }
77
+ }
78
+ }
79
+
80
+ public func dismissMockReaderUI(completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
81
+ DispatchQueue.main.async {
82
+ MockReaderUIManage.shared.dismiss()
83
+ completion(nil)
84
+ }
85
+ }
86
+ }
@@ -0,0 +1,52 @@
1
+ //
2
+ // MockReaderUIManage.swift
3
+ //
4
+ // Created by chancetio on 2025/11/18.
5
+ //
6
+
7
+ import Foundation
8
+ import SquareMobilePaymentsSDK
9
+
10
+ #if canImport(MockReaderUI)
11
+ import MockReaderUI
12
+ #endif
13
+
14
+ class MockReaderUIManage {
15
+ static let shared = MockReaderUIManage()
16
+
17
+ #if canImport(MockReaderUI)
18
+ private lazy var mockReaderUI: MockReaderUI? = {
19
+ guard MobilePaymentsSDK.shared.settingsManager.sdkSettings.environment == .sandbox else {
20
+ return nil
21
+ }
22
+ do {
23
+ return try MockReaderUI(for: MobilePaymentsSDK.shared)
24
+ } catch {
25
+ debugPrint("Could not instantiate a mock reader UI: \(error.localizedDescription)")
26
+ }
27
+ return nil
28
+ }()
29
+ #endif
30
+
31
+ private init() {}
32
+
33
+ func present() throws {
34
+ #if canImport(MockReaderUI)
35
+ try self.mockReaderUI?.present()
36
+ #endif
37
+ }
38
+
39
+ func dismiss() {
40
+ #if canImport(MockReaderUI)
41
+ self.mockReaderUI?.dismiss()
42
+ #endif
43
+ }
44
+
45
+ func isPresented() -> Bool {
46
+ #if canImport(MockReaderUI)
47
+ return self.mockReaderUI?.isPresented == true
48
+ #else
49
+ return false
50
+ #endif
51
+ }
52
+ }
@@ -0,0 +1,22 @@
1
+ //
2
+ // NativeErrorInfo.swift
3
+ //
4
+ // Created by chancetio on 2026/1/28.
5
+ //
6
+ @objcMembers
7
+ public class NativeErrorInfo: NSObject {
8
+ public let code: String?
9
+ public let message: String?
10
+ public let error: Error?
11
+
12
+ public init(code: String?, message: String?, error: Error?) {
13
+ self.code = code
14
+ self.message = message
15
+ self.error = error
16
+ super.init()
17
+ }
18
+
19
+ override public var description: String {
20
+ "NativeErrorInfo(code=\(String(describing: code)), message=\(String(describing: message)), error=\(String(describing: error)))"
21
+ }
22
+ }
@@ -0,0 +1,20 @@
1
+ //
2
+ // PaymentMoneyParameter.swift
3
+ //
4
+ // Created by chancetio on 2026/1/28.
5
+ //
6
+ @objcMembers
7
+ public class RCTPaymentMoneyParameter: NSObject {
8
+ public let amount: Double
9
+ public let currency: String
10
+
11
+ public init(amount: Double, currency: String) {
12
+ self.amount = amount
13
+ self.currency = currency
14
+ super.init()
15
+ }
16
+
17
+ override public var description: String {
18
+ "RCTPaymentMoneyParameter(amount=\(String(describing: amount)), currency=\(String(describing: currency)))"
19
+ }
20
+ }
@@ -0,0 +1,50 @@
1
+ //
2
+ // PaymentParameters.swift
3
+ //
4
+ // Created by chancetio on 2026/1/28.
5
+ //
6
+ @objcMembers
7
+ public class RCTPaymentParameters: NSObject {
8
+ public let allowCardSurcharge: Bool
9
+ public let paymentAttemptId: String
10
+ public let acceptPartialAuthorization: Bool?
11
+ public let autocomplete: Bool?
12
+ public let delayAction: String?
13
+ public let delayDuration: Double?
14
+ public let amountMoney: RCTPaymentMoneyParameter
15
+ public let tipMoney: RCTPaymentMoneyParameter?
16
+ public let appFeeMoney: RCTPaymentMoneyParameter?
17
+ public let locationID: String?
18
+ public let orderID: String?
19
+ public let referenceID: String?
20
+ public let customerID: String?
21
+ public let teamMemberID: String?
22
+ public let note: String?
23
+ public let statementDescriptionIdentifier: String?
24
+ public let processingMode: String
25
+
26
+ public init(allowCardSurcharge: Bool, paymentAttemptId: String, acceptPartialAuthorization: NSNumber?, autocomplete: NSNumber?, delayAction: String?, delayDuration: NSNumber?, amountMoney: RCTPaymentMoneyParameter, tipMoney: RCTPaymentMoneyParameter?, appFeeMoney: RCTPaymentMoneyParameter?, locationID: String?, orderID: String?, referenceID: String?, customerID: String?, teamMemberID: String?, note: String?, statementDescriptionIdentifier: String?, processingMode: String) {
27
+ self.allowCardSurcharge = allowCardSurcharge
28
+ self.paymentAttemptId = paymentAttemptId
29
+ self.acceptPartialAuthorization = acceptPartialAuthorization?.boolValue
30
+ self.autocomplete = autocomplete?.boolValue
31
+ self.delayAction = delayAction
32
+ self.delayDuration = delayDuration?.doubleValue
33
+ self.amountMoney = amountMoney
34
+ self.tipMoney = tipMoney
35
+ self.appFeeMoney = appFeeMoney
36
+ self.locationID = locationID
37
+ self.orderID = orderID
38
+ self.referenceID = referenceID
39
+ self.customerID = customerID
40
+ self.teamMemberID = teamMemberID
41
+ self.note = note
42
+ self.statementDescriptionIdentifier = statementDescriptionIdentifier
43
+ self.processingMode = processingMode
44
+ super.init()
45
+ }
46
+
47
+ override public var description: String {
48
+ "RCTPaymentParameters(allowCardSurcharge=\(String(describing: allowCardSurcharge)), paymentAttemptId=\(String(describing: paymentAttemptId)), acceptPartialAuthorization=\(String(describing: acceptPartialAuthorization)), autocomplete=\(String(describing: autocomplete)), delayAction=\(String(describing: delayAction)), delayDuration=\(String(describing: delayDuration)), amountMoney=\(String(describing: amountMoney)), tipMoney=\(String(describing: tipMoney)), appFeeMoney=\(String(describing: appFeeMoney)), locationID=\(String(describing: locationID)), orderID=\(String(describing: orderID)), referenceID=\(String(describing: referenceID)), customerID=\(String(describing: customerID)), teamMemberID=\(String(describing: teamMemberID)), note=\(String(describing: note)), statementDescriptionIdentifier=\(String(describing: statementDescriptionIdentifier)), processingMode=\(String(describing: processingMode)))"
49
+ }
50
+ }
@@ -0,0 +1,20 @@
1
+ //
2
+ // RCTPromptParameters.swift
3
+ //
4
+ // Created by chancetio on 2026/1/28.
5
+ //
6
+ @objcMembers
7
+ public class RCTPromptParameters: NSObject {
8
+ public let mode: String
9
+ public let additionalMethods: String?
10
+
11
+ public init(mode: String, additionalMethods: String?) {
12
+ self.mode = mode
13
+ self.additionalMethods = additionalMethods
14
+ super.init()
15
+ }
16
+
17
+ override public var description: String {
18
+ "RCTPromptParameters(mode=\(String(describing: mode)), additionalMethods=\(String(describing: additionalMethods)))"
19
+ }
20
+ }
@@ -0,0 +1,9 @@
1
+ //
2
+ // NotificationKeys.swift
3
+ //
4
+ // Created by chancetio on 2025/11/6.
5
+ //
6
+
7
+ enum MobilePaymentNotificationKeys: String {
8
+ case sdkInitialized = "MobilePaymentSDKInitialized"
9
+ }
@@ -0,0 +1,21 @@
1
+ //
2
+ // Notification.swift
3
+ //
4
+ // Created by chancetio on 2025/11/6.
5
+ //
6
+ enum NotificationUtils {
7
+ static func addObserver(_ observer: Any, selector: Selector, name: String, object: Any? = nil) {
8
+ NotificationCenter.default.addObserver(
9
+ observer, selector: selector,
10
+ name: NSNotification.Name(rawValue: name),
11
+ object: object)
12
+ }
13
+
14
+ static func removeObserver(_ observer: Any) {
15
+ NotificationCenter.default.removeObserver(observer)
16
+ }
17
+
18
+ static func post(name: String, object: Any? = nil, userInfo: [AnyHashable: Any]? = nil) {
19
+ NotificationCenter.default.post(name: NSNotification.Name(name), object: object, userInfo: userInfo)
20
+ }
21
+ }
@@ -0,0 +1,12 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <NativeSquareMobilePaymentSDKSpec/NativeSquareMobilePaymentSDKSpec.h>
3
+ #import <React/RCTInitializing.h>
4
+ #import <React/RCTInvalidating.h>
5
+
6
+ NS_ASSUME_NONNULL_BEGIN
7
+
8
+ @interface RCTMobilePaymentAuthorization : NativeMobilePaymentAuthorizationSpecBase <NativeMobilePaymentAuthorizationSpec, RCTInitializing, RCTInvalidating>
9
+
10
+ @end
11
+
12
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,78 @@
1
+ #import "RCTMobilePaymentAuthorization.h"
2
+ #import "NativeSquareMobilePaymentSDK-Swift.h"
3
+
4
+ @interface RCTMobilePaymentAuthorization () <RCTMobilePaymentAuthorizationEventEmitter>
5
+ @end
6
+
7
+ @implementation RCTMobilePaymentAuthorization {
8
+ MobilePaymentAuthorization* authorization;
9
+ }
10
+
11
+ - (id) init {
12
+ if (self = [super init]) {
13
+ authorization = [MobilePaymentAuthorization new];
14
+ authorization.emitter = self;
15
+ }
16
+ return self;
17
+ }
18
+
19
+ - (void)dealloc {
20
+
21
+ }
22
+
23
+ - (void)initialize {
24
+ [authorization initialize];
25
+ }
26
+
27
+ - (void)invalidate {
28
+ [authorization invalidate];
29
+ }
30
+
31
+ - (void)authorize:(nonnull NSString *)accessToken locationID:(nonnull NSString *)locationID resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
32
+ [authorization authorizeWithAccessToken:accessToken locationId:locationID completion:^(NativeErrorInfo * _Nullable errorInfo) {
33
+ if (errorInfo) {
34
+ reject(errorInfo.code, errorInfo.message, errorInfo.error);
35
+ }else{
36
+ resolve(nil);
37
+ }
38
+ }];
39
+ }
40
+
41
+ - (void)deauthorize:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
42
+ [authorization deauthorizeWithCompletion:^(NativeErrorInfo * _Nullable errorInfo) {
43
+ if (errorInfo) {
44
+ reject(errorInfo.code, errorInfo.message,errorInfo.error);
45
+ }else{
46
+ resolve(nil);
47
+ }
48
+ }];
49
+ }
50
+
51
+ - (NSDictionary * _Nullable)location {
52
+ return [authorization location];
53
+ }
54
+
55
+ - (nonnull NSString *)state {
56
+ return [authorization state];
57
+ }
58
+
59
+ - (void)onAuthorizationStateDidChange:(NSString * _Nonnull)value {
60
+ try {
61
+ [self emitOnAuthorizationStateChange:value];
62
+ } catch (const std::bad_function_call &e) {
63
+ NSLog(@"[MobilePayment] std::bad_function_call in emitOnAuthorizationStateChange: %s", e.what());
64
+ }
65
+ }
66
+
67
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
68
+ (const facebook::react::ObjCTurboModule::InitParams &)params
69
+ {
70
+ return std::make_shared<facebook::react::NativeMobilePaymentAuthorizationSpecJSI>(params);
71
+ }
72
+
73
+ + (NSString *)moduleName
74
+ {
75
+ return @"NativeMobilePaymentAuthorization";
76
+ }
77
+
78
+ @end
@@ -0,0 +1,12 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <NativeSquareMobilePaymentSDKSpec/NativeSquareMobilePaymentSDKSpec.h>
3
+ #import <React/RCTInitializing.h>
4
+ #import <React/RCTInvalidating.h>
5
+
6
+ NS_ASSUME_NONNULL_BEGIN
7
+
8
+ @interface RCTMobilePaymentPayment : NativeMobilePaymentPaymentSpecBase <NativeMobilePaymentPaymentSpec, RCTInitializing, RCTInvalidating>
9
+
10
+ @end
11
+
12
+ NS_ASSUME_NONNULL_END