@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.
- package/LICENSE +20 -0
- package/NativeSquareMobilePaymentSDK.podspec +23 -0
- package/README.md +66 -0
- package/android/build.gradle +81 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/DateFormatUtils.java +29 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/ErrorUtilities.kt +56 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentAuthorization.kt +185 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentException.kt +8 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentPayment.kt +542 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentReader.kt +344 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentSDK.kt +47 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentSDKPackage.kt +77 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/MobilePaymentSetting.kt +144 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/AdditionalPaymentMethodConvert.kt +46 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/AuthorizationStateConvert.kt +26 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/CardConvert.kt +53 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/CardDetailsConvert.kt +74 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/CardEntryMethodConvert.kt +31 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/CashPaymentDetailsConvert.kt +18 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/CurrencyCodeConvert.kt +204 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/DelayActionConvert.kt +33 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/DeniedReasonConvert.kt +28 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/DigitalWalletDetailsConvert.kt +18 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/ErrorDetailsConvert.kt +32 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/ExternalPaymentDetailsConvert.kt +25 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/LocationConvert.kt +31 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/MoneyConvert.kt +31 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/OfflineStatusConvert.kt +21 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/PaymentConvert.kt +93 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/PaymentProcessingFeeConvert.kt +39 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/PaymentSettingsConvert.kt +26 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/ProcessingModeConvert.kt +28 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderBatteryStatusConvert.kt +19 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderChangeEventConvert.kt +75 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderConnectionTypeConvert.kt +17 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderInfoConvert.kt +51 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderModalConvert.kt +18 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderStateConvert.kt +51 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/ReaderStatusConvert.kt +51 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/SdkSettingsConvert.kt +30 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/SquareAccountDetailsConvert.kt +20 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/TrackingConsentStateConvert.kt +17 -0
- package/android/src/main/java/com/connexup/square/mobilepayment/convert/WalletBrandConvert.kt +41 -0
- package/ios/Converters/AdditionalPaymentMethod+Extension.swift +17 -0
- package/ios/Converters/AdditionalPaymentMethodType+Extension.swift +44 -0
- package/ios/Converters/AuthorizationState+Extension.swift +22 -0
- package/ios/Converters/BatteryLevel+Extension.swift +27 -0
- package/ios/Converters/Card+Extension.swift +33 -0
- package/ios/Converters/CardBrand+Extension.swift +47 -0
- package/ios/Converters/CardCoBrand+Extension.swift +24 -0
- package/ios/Converters/CardEntryMethod+Extension.swift +30 -0
- package/ios/Converters/CardInputMethods+Extension.swift +35 -0
- package/ios/Converters/CardInsertionStatus+Extension.swift +24 -0
- package/ios/Converters/CardPaymentDetails+Extensions.swift +31 -0
- package/ios/Converters/CardPaymentStatus+Extension.swift +28 -0
- package/ios/Converters/Currency+Extension.swift +50 -0
- package/ios/Converters/Location+Extension.swift +19 -0
- package/ios/Converters/MoneyAmount+Extension.swift +30 -0
- package/ios/Converters/Payment+Extension.swift +44 -0
- package/ios/Converters/PaymentSettings+Extension.swift +19 -0
- package/ios/Converters/PaymentStatus+Extension.swift +53 -0
- package/ios/Converters/ProcessingMode+Extension.swift +37 -0
- package/ios/Converters/ReaderBatteryStatus+Extension.swift +19 -0
- package/ios/Converters/ReaderChange+Extension.swift +41 -0
- package/ios/Converters/ReaderConnectionFailureInfo+Extension.swift +20 -0
- package/ios/Converters/ReaderConnectionFailureReason+Extension.swift +40 -0
- package/ios/Converters/ReaderConnectionFailureRecoverySuggestion+Extension.swift +30 -0
- package/ios/Converters/ReaderConnectionInfo+Extension.swift +18 -0
- package/ios/Converters/ReaderConnectionStatus+Extension.swift +26 -0
- package/ios/Converters/ReaderFirmwareInfo+Extension.swift +19 -0
- package/ios/Converters/ReaderInfo+Extension.swift +30 -0
- package/ios/Converters/ReaderModel+Extension.swift +28 -0
- package/ios/Converters/ReaderState+Extension.swift +30 -0
- package/ios/Converters/ReaderStatus+Extension.swift +60 -0
- package/ios/Converters/ReaderStatusInfo+Extension.swift +22 -0
- package/ios/Converters/SDKSettings+Extension.swift +25 -0
- package/ios/Converters/SourceType+Extension.swift +32 -0
- package/ios/Converters/TrackingConsentState+Extension.swift +25 -0
- package/ios/ErrorUtilities.swift +41 -0
- package/ios/MobilePaymentAuthorization.swift +154 -0
- package/ios/MobilePaymentDateFormatter.swift +15 -0
- package/ios/MobilePaymentPayment.swift +478 -0
- package/ios/MobilePaymentReader.swift +248 -0
- package/ios/MobilePaymentSDK.swift +36 -0
- package/ios/MobilePaymentSetting.swift +86 -0
- package/ios/MockReaderUIManage.swift +52 -0
- package/ios/Models/NativeErrorInfo.swift +22 -0
- package/ios/Models/RCTPaymentMoneyParameter.swift +20 -0
- package/ios/Models/RCTPaymentParameters.swift +50 -0
- package/ios/Models/RCTPromptParameters.swift +20 -0
- package/ios/NotificationKeys.swift +9 -0
- package/ios/NotificationUtils.swift +21 -0
- package/ios/RCTMobilePaymentAuthorization.h +12 -0
- package/ios/RCTMobilePaymentAuthorization.mm +78 -0
- package/ios/RCTMobilePaymentPayment.h +12 -0
- package/ios/RCTMobilePaymentPayment.mm +116 -0
- package/ios/RCTMobilePaymentReader.h +12 -0
- package/ios/RCTMobilePaymentReader.mm +114 -0
- package/ios/RCTMobilePaymentSetting.h +10 -0
- package/ios/RCTMobilePaymentSetting.mm +94 -0
- package/ios/UIColor+Extension.swift +81 -0
- package/lib/module/authorization/NativeMobilePaymentAuthorization.js +60 -0
- package/lib/module/authorization/NativeMobilePaymentAuthorization.js.map +1 -0
- package/lib/module/authorization/index.js +44 -0
- package/lib/module/authorization/index.js.map +1 -0
- package/lib/module/index.js +7 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/payment/NativeMobilePaymentPayment.js +138 -0
- package/lib/module/payment/NativeMobilePaymentPayment.js.map +1 -0
- package/lib/module/payment/index.js +113 -0
- package/lib/module/payment/index.js.map +1 -0
- package/lib/module/reader/NativeMobilePaymentReader.js +151 -0
- package/lib/module/reader/NativeMobilePaymentReader.js.map +1 -0
- package/lib/module/reader/index.js +109 -0
- package/lib/module/reader/index.js.map +1 -0
- package/lib/module/setting/NativeMobilePaymentSetting.js +5 -0
- package/lib/module/setting/NativeMobilePaymentSetting.js.map +1 -0
- package/lib/module/setting/index.js +74 -0
- package/lib/module/setting/index.js.map +1 -0
- package/lib/module/type.js +27 -0
- package/lib/module/type.js.map +1 -0
- package/lib/module/util.js +32 -0
- package/lib/module/util.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/authorization/NativeMobilePaymentAuthorization.d.ts +82 -0
- package/lib/typescript/src/authorization/NativeMobilePaymentAuthorization.d.ts.map +1 -0
- package/lib/typescript/src/authorization/index.d.ts +14 -0
- package/lib/typescript/src/authorization/index.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +5 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/payment/NativeMobilePaymentPayment.d.ts +725 -0
- package/lib/typescript/src/payment/NativeMobilePaymentPayment.d.ts.map +1 -0
- package/lib/typescript/src/payment/index.d.ts +13 -0
- package/lib/typescript/src/payment/index.d.ts.map +1 -0
- package/lib/typescript/src/reader/NativeMobilePaymentReader.d.ts +318 -0
- package/lib/typescript/src/reader/NativeMobilePaymentReader.d.ts.map +1 -0
- package/lib/typescript/src/reader/index.d.ts +19 -0
- package/lib/typescript/src/reader/index.d.ts.map +1 -0
- package/lib/typescript/src/setting/NativeMobilePaymentSetting.d.ts +49 -0
- package/lib/typescript/src/setting/NativeMobilePaymentSetting.d.ts.map +1 -0
- package/lib/typescript/src/setting/index.d.ts +17 -0
- package/lib/typescript/src/setting/index.d.ts.map +1 -0
- package/lib/typescript/src/type.d.ts +23 -0
- package/lib/typescript/src/type.d.ts.map +1 -0
- package/lib/typescript/src/util.d.ts +3 -0
- package/lib/typescript/src/util.d.ts.map +1 -0
- package/package.json +178 -0
- package/src/authorization/NativeMobilePaymentAuthorization.ts +297 -0
- package/src/authorization/index.ts +60 -0
- package/src/index.ts +4 -0
- package/src/payment/NativeMobilePaymentPayment.ts +1220 -0
- package/src/payment/index.ts +161 -0
- package/src/reader/NativeMobilePaymentReader.ts +463 -0
- package/src/reader/index.ts +140 -0
- package/src/setting/NativeMobilePaymentSetting.ts +254 -0
- package/src/setting/index.ts +91 -0
- package/src/type.ts +35 -0
- package/src/util.ts +31 -0
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
//
|
|
2
|
+
// RNMobilePaymentPayment.swift
|
|
3
|
+
//
|
|
4
|
+
// Created by chancetio on 2023/9/13.
|
|
5
|
+
//
|
|
6
|
+
|
|
7
|
+
import Foundation
|
|
8
|
+
import SquareMobilePaymentsSDK
|
|
9
|
+
|
|
10
|
+
let PaymentErrorNoNetwork = "PAYMENT_ERROR_NO_NETWORK"
|
|
11
|
+
let PaymentErrorNotAuthorized = "PAYMENT_ERROR_NOT_AUTHORIZED"
|
|
12
|
+
let PaymentErrorInvalidPaymentParameters = "PAYMENT_ERROR_INVALID_PAYMENT_PARAMETERS"
|
|
13
|
+
let PaymentErrorTimedOut = "PAYMENT_ERROR_TIMED_OUT"
|
|
14
|
+
let PaymentErrorLocationPermissionNeeded = "PAYMENT_ERROR_LOCATION_PERMISSION_NEEDED"
|
|
15
|
+
let PaymentErrorPaymentAlreadyInProgress = "PAYMENT_ERROR_PAYMENT_ALREADY_IN_PROGRESS"
|
|
16
|
+
let PaymentErrorIdempotencyKeyReused = "PAYMENT_ERROR_IDEMPOTENCY_KEY_REUSED"
|
|
17
|
+
let PaymentErrorInvalidPaymentSource = "PAYMENT_ERROR_INVALID_PAYMENT_SOURCE"
|
|
18
|
+
let PaymentErrorUnexpected = "PAYMENT_ERROR_UNEXPECTED"
|
|
19
|
+
let PaymentErrorMerchantNotOptedIntoOfflineProcessing =
|
|
20
|
+
"PAYMENT_ERROR_MERCHANT_NOT_OPTED_INTO_OFFLINE_PROCESSING"
|
|
21
|
+
let PaymentErrorOfflineTransactionAmountExceeded =
|
|
22
|
+
"PAYMENT_ERROR_OFFLINE_TRANSACTION_AMOUNT_EXCEEDED"
|
|
23
|
+
let PaymentErrorOfflineStoredAmountExceeded =
|
|
24
|
+
"PAYMENT_ERROR_OFFLINE_STORED_AMOUNT_EXCEEDED"
|
|
25
|
+
let PaymentErrorSandboxUnsupportedForOfflineProcessing =
|
|
26
|
+
"PAYMENT_ERROR_SANDBOX_UNSUPPORTED_FOR_OFFLINE_PROCESSING"
|
|
27
|
+
let PaymentDeviceClockSkewed = "PAYMENT_DEVICE_CLOCK_SKEWED"
|
|
28
|
+
let PaymentErrorUnsupportedMode = "PAYMENT_ERROR_UNSUPPORTED_MODE"
|
|
29
|
+
let PaymentTrackingConsentIsPending = "PAYMENT_TRACKING_CONSENT_IS_PENDING"
|
|
30
|
+
let PaymentAttemptIdRequiredForSca = "PAYMENT_ATTEMPT_ID_REQUIRED_FOR_SCA"
|
|
31
|
+
let PaymentAttemptIdReused = "PAYMENT_ATTEMPT_ID_REUSED"
|
|
32
|
+
|
|
33
|
+
@objc public protocol RCTMobilePaymentPaymentEventEmitter {
|
|
34
|
+
func onAvailableCardInputMethodsChange(_ value: [String])
|
|
35
|
+
func onPaymentFlowStatusChange(_ value: [String: Any])
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@objcMembers
|
|
39
|
+
public class MobilePaymentPayment: NSObject {
|
|
40
|
+
private lazy var observer = MobilePaymentPaymentObserver(owner: self)
|
|
41
|
+
|
|
42
|
+
public weak var emitter: RCTMobilePaymentPaymentEventEmitter?
|
|
43
|
+
|
|
44
|
+
deinit {
|
|
45
|
+
invalidate()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public func initialize() {
|
|
49
|
+
NotificationUtils.addObserver(self, selector: #selector(onSDKInitialize), name: MobilePaymentNotificationKeys.sdkInitialized.rawValue)
|
|
50
|
+
if MobilePaymentSDK.shared.isInitialized {
|
|
51
|
+
onSDKInitialize()
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public func invalidate() {
|
|
56
|
+
NotificationUtils.removeObserver(self)
|
|
57
|
+
if MobilePaymentSDK.shared.isInitialized {
|
|
58
|
+
MobilePaymentsSDK.shared.paymentManager.remove(observer)
|
|
59
|
+
DispatchQueue.main.async {
|
|
60
|
+
if let paymentHandle = MobilePaymentsSDK.shared.paymentManager.currentPaymentHandle, paymentHandle.isPaymentCancelable {
|
|
61
|
+
paymentHandle.cancelPayment()
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@objc
|
|
68
|
+
private func onSDKInitialize() {
|
|
69
|
+
MobilePaymentsSDK.shared.paymentManager.remove(observer)
|
|
70
|
+
MobilePaymentsSDK.shared.paymentManager.add(observer)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public func startPayment(paymentParameters: RCTPaymentParameters,
|
|
74
|
+
promptParameters: RCTPromptParameters,
|
|
75
|
+
completion: @escaping (_ error: NativeErrorInfo?) -> Void)
|
|
76
|
+
{
|
|
77
|
+
DispatchQueue.main.async {
|
|
78
|
+
guard let paymentParameters = self.makePaymentParameters(from: paymentParameters) else {
|
|
79
|
+
completion(NativeErrorInfo(code: ErrorUtilities.PARAMS_ERROR, message: ErrorUtilities.createNativeModuleError(code: ErrorUtilities.PARAMS_ERROR, message: "PaymentParameters Error"), error: nil))
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
guard let promptParameters = self.makePromptParameters(from: promptParameters) else {
|
|
84
|
+
completion(NativeErrorInfo(code: ErrorUtilities.PARAMS_ERROR, message: ErrorUtilities.createNativeModuleError(code: ErrorUtilities.PARAMS_ERROR, message: "PromptParameters Error"), error: nil))
|
|
85
|
+
return
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
guard let rootViewController = UIApplication.shared.delegate?.window??.rootViewController else {
|
|
89
|
+
completion(NativeErrorInfo(code: ErrorUtilities.UNKNOWN_ERROR, message: ErrorUtilities.createNativeModuleError(code: ErrorUtilities.UNKNOWN_ERROR, message: "RootViewController Not Found"), error: nil))
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if let paymentHandle = MobilePaymentsSDK.shared.paymentManager.currentPaymentHandle, paymentHandle.isPaymentCancelable {
|
|
94
|
+
paymentHandle.cancelPayment()
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
MobilePaymentsSDK.shared.paymentManager.startPayment(paymentParameters, promptParameters: promptParameters, from: rootViewController, delegate: self.observer)
|
|
98
|
+
completion(nil)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public func availableCardInputMethods() -> [String] {
|
|
103
|
+
return MobilePaymentsSDK.shared.paymentManager.availableCardInputMethods.jsonValue
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public func additionalPaymentMethods() -> [[String: Any]] {
|
|
107
|
+
return MobilePaymentsSDK.shared.paymentManager.currentPaymentHandle?.additionalPaymentMethods.map { $0.jsonDictionary } ?? []
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public func triggerPaymentWithAdditionalPaymentMethod(_ paymentSource: [String: Any], completion: @escaping (_ error: NativeErrorInfo?) -> Void)
|
|
111
|
+
{
|
|
112
|
+
DispatchQueue.main.async {
|
|
113
|
+
guard let sourceType = paymentSource["type"] as? String, let realSourceType = AdditionalPaymentMethodType.make(from: sourceType) else {
|
|
114
|
+
completion(NativeErrorInfo(code: ErrorUtilities.PARAMS_ERROR, message: ErrorUtilities.createNativeModuleError(code: ErrorUtilities.PARAMS_ERROR, message: "Params sourceType Not Found"), error: nil))
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
guard let paymentHandle = MobilePaymentsSDK.shared.paymentManager.currentPaymentHandle else {
|
|
119
|
+
completion(NativeErrorInfo(code: ErrorUtilities.UNKNOWN_ERROR, message: ErrorUtilities.createNativeModuleError(code: ErrorUtilities.UNKNOWN_ERROR, message: "PaymentHandle Not Found"), error: nil))
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
guard let additionalPaymentMethod = paymentHandle.additionalPaymentMethods.first(where: { $0.type == realSourceType }) else {
|
|
124
|
+
completion(NativeErrorInfo(code: ErrorUtilities.UNKNOWN_ERROR, message: ErrorUtilities.createNativeModuleError(code: ErrorUtilities.UNKNOWN_ERROR, message: "AdditionalPaymentMethod Not Found"), error: nil))
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
var realPaymenSouce: PaymentSource?
|
|
129
|
+
switch additionalPaymentMethod.type {
|
|
130
|
+
case .keyed:
|
|
131
|
+
realPaymenSouce = KeyedCardPaymentSource()
|
|
132
|
+
case .cardOnFile:
|
|
133
|
+
guard let cardID = paymentSource["cardID"] as? String else {
|
|
134
|
+
completion(NativeErrorInfo(code: ErrorUtilities.PARAMS_ERROR, message: ErrorUtilities.createNativeModuleError(code: ErrorUtilities.PARAMS_ERROR, message: "Params cardID Not Found"), error: nil))
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
realPaymenSouce = CardOnFilePaymentSource(cardID: cardID)
|
|
138
|
+
case .houseAccount:
|
|
139
|
+
guard let houseAccountPaymentSourceId = paymentSource["houseAccountPaymentSourceId"] as? String else {
|
|
140
|
+
completion(NativeErrorInfo(code: ErrorUtilities.PARAMS_ERROR, message: ErrorUtilities.createNativeModuleError(code: ErrorUtilities.PARAMS_ERROR, message: "Params houseAccountPaymentSourceId Not Found"), error: nil))
|
|
141
|
+
return
|
|
142
|
+
}
|
|
143
|
+
realPaymenSouce = HouseAccountPaymentSource(paymentSourceID: houseAccountPaymentSourceId)
|
|
144
|
+
case .tapToPay:
|
|
145
|
+
realPaymenSouce = TapToPayPaymentSource()
|
|
146
|
+
case .cash:
|
|
147
|
+
realPaymenSouce = CashPaymentSource()
|
|
148
|
+
@unknown default:
|
|
149
|
+
realPaymenSouce = nil
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
guard let realPaymenSouce = realPaymenSouce else {
|
|
153
|
+
completion(NativeErrorInfo(code: ErrorUtilities.UNKNOWN_ERROR, message: ErrorUtilities.createNativeModuleError(code: ErrorUtilities.UNKNOWN_ERROR, message: "RealPaymenSouce is nil"), error: nil))
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
do {
|
|
158
|
+
try additionalPaymentMethod.triggerPayment(with: realPaymenSouce)
|
|
159
|
+
completion(nil)
|
|
160
|
+
} catch {
|
|
161
|
+
completion(NativeErrorInfo(code: ErrorUtilities.UNKNOWN_ERROR, message: ErrorUtilities.serializeErrorToJson(code: ErrorUtilities.UNKNOWN_ERROR, error: error as NSError), error: error))
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
public func currentPayment() -> [String: Any]? {
|
|
167
|
+
return MobilePaymentsSDK.shared.paymentManager.currentPaymentHandle?.payment.jsonDictionary
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public func isCurrentPaymentCancelable() -> Bool {
|
|
171
|
+
return MobilePaymentsSDK.shared.paymentManager.currentPaymentHandle?.isPaymentCancelable ?? true
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
public func cancelCurrentPayment(resolve: @escaping (_ value: Bool) -> Void,
|
|
175
|
+
reject: @escaping (_ error: NativeErrorInfo) -> Void)
|
|
176
|
+
{
|
|
177
|
+
DispatchQueue.main.async {
|
|
178
|
+
guard let paymentHandle = MobilePaymentsSDK.shared.paymentManager.currentPaymentHandle else {
|
|
179
|
+
resolve(true)
|
|
180
|
+
return
|
|
181
|
+
}
|
|
182
|
+
if !paymentHandle.isPaymentCancelable {
|
|
183
|
+
resolve(false)
|
|
184
|
+
return
|
|
185
|
+
}
|
|
186
|
+
resolve(paymentHandle.cancelPayment())
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private func makePaymentParameters(from parameters: RCTPaymentParameters) -> PaymentParameters? {
|
|
191
|
+
guard let amountMoney = Money.make(from: parameters.amountMoney) else {
|
|
192
|
+
return nil
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
guard let processingMode = ProcessingMode.make(from: parameters.processingMode) else {
|
|
196
|
+
return nil
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
let result = PaymentParameters(paymentAttemptID: parameters.paymentAttemptId, amountMoney: amountMoney, processingMode: processingMode)
|
|
200
|
+
|
|
201
|
+
if let acceptPartialAuthorization = parameters.acceptPartialAuthorization {
|
|
202
|
+
result.acceptPartialAuthorization = acceptPartialAuthorization
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if let autocomplete = parameters.autocomplete {
|
|
206
|
+
result.autocomplete = autocomplete
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if let delayAction = parameters.delayAction {
|
|
210
|
+
switch delayAction {
|
|
211
|
+
case "CANCEL":
|
|
212
|
+
result.delayAction = .cancel
|
|
213
|
+
case "COMPLETE":
|
|
214
|
+
result.delayAction = .complete
|
|
215
|
+
default:
|
|
216
|
+
break
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if let delayDuration = parameters.delayDuration {
|
|
221
|
+
result.delayDuration = delayDuration
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if let tipMoney = Money.make(from: parameters.tipMoney) {
|
|
225
|
+
result.tipMoney = tipMoney
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if let appFeeMoney = Money.make(from: parameters.appFeeMoney) {
|
|
229
|
+
result.appFeeMoney = appFeeMoney
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if let locationID = parameters.locationID {
|
|
233
|
+
result.locationID = locationID
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if let orderID = parameters.orderID {
|
|
237
|
+
result.orderID = orderID
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if let referenceID = parameters.referenceID {
|
|
241
|
+
result.referenceID = referenceID
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if let customerID = parameters.customerID {
|
|
245
|
+
result.customerID = customerID
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if let teamMemberID = parameters.teamMemberID {
|
|
249
|
+
result.teamMemberID = teamMemberID
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if let note = parameters.note {
|
|
253
|
+
result.note = note
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if let statementDescriptionIdentifier = parameters.statementDescriptionIdentifier {
|
|
257
|
+
result.statementDescriptionIdentifier = statementDescriptionIdentifier
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// TODO: cardHandle
|
|
261
|
+
|
|
262
|
+
return result
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
private func makePromptParameters(from parameters: RCTPromptParameters) -> PromptParameters? {
|
|
266
|
+
var mode = PromptMode.default
|
|
267
|
+
var additionalMethods = AdditionalPaymentMethods.all
|
|
268
|
+
|
|
269
|
+
switch parameters.mode {
|
|
270
|
+
case "DEFAULT":
|
|
271
|
+
mode = PromptMode.default
|
|
272
|
+
case "CUSTOM":
|
|
273
|
+
mode = PromptMode.custom
|
|
274
|
+
default:
|
|
275
|
+
break
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// TODO: improve this
|
|
279
|
+
if let additionalMethodsParams = parameters.additionalMethods {
|
|
280
|
+
switch additionalMethodsParams {
|
|
281
|
+
case "ALL":
|
|
282
|
+
additionalMethods = .all
|
|
283
|
+
case "KEYED":
|
|
284
|
+
additionalMethods = .keyed
|
|
285
|
+
default:
|
|
286
|
+
break
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return PromptParameters(mode: mode, additionalMethods: additionalMethods)
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// TODO: theme
|
|
294
|
+
/*
|
|
295
|
+
private func makeTheme(from jsonTheme: [String: Any]?) -> Theme {
|
|
296
|
+
let result = Theme()
|
|
297
|
+
|
|
298
|
+
if let jsonTheme = jsonTheme {
|
|
299
|
+
if let titleColor = jsonTheme["titleColor"] as? String {
|
|
300
|
+
result.titleColor = UIColor(fromHex: titleColor)
|
|
301
|
+
}
|
|
302
|
+
if let titleFont = jsonTheme["titleFont"] as? [String: Any] {
|
|
303
|
+
result.titleFont = makeFont(origin: result.titleFont, jsonFont: titleFont)
|
|
304
|
+
}
|
|
305
|
+
if let subtitleColor = jsonTheme["subtitleColor"] as? String {
|
|
306
|
+
result.subtitleColor = UIColor(fromHex: subtitleColor)
|
|
307
|
+
}
|
|
308
|
+
if let subtitleFont = jsonTheme["subtitleFont"] as? [String: Any] {
|
|
309
|
+
result.subtitleFont = makeFont(origin: result.subtitleFont, jsonFont: subtitleFont)
|
|
310
|
+
}
|
|
311
|
+
if let tintColor = jsonTheme["tintColor"] as? String {
|
|
312
|
+
result.tintColor = UIColor(fromHex: tintColor)
|
|
313
|
+
}
|
|
314
|
+
if let backgroundColor = jsonTheme["backgroundColor"] as? String {
|
|
315
|
+
result.backgroundColor = UIColor(fromHex: backgroundColor)
|
|
316
|
+
}
|
|
317
|
+
if let buttonTextColor = jsonTheme["buttonTextColor"] as? String {
|
|
318
|
+
result.buttonTextColor = UIColor(fromHex: buttonTextColor)
|
|
319
|
+
}
|
|
320
|
+
if let buttonFont = jsonTheme["buttonFont"] as? [String: Any] {
|
|
321
|
+
result.buttonFont = makeFont(origin: result.buttonFont, jsonFont: buttonFont)
|
|
322
|
+
}
|
|
323
|
+
if let buttonCornerRadius = jsonTheme["buttonCornerRadius"] as? CGFloat {
|
|
324
|
+
result.buttonCornerRadius = buttonCornerRadius
|
|
325
|
+
}
|
|
326
|
+
if let informationIconColor = jsonTheme["informationIconColor"] as? String {
|
|
327
|
+
result.informationIconColor = UIColor(fromHex: informationIconColor)
|
|
328
|
+
}
|
|
329
|
+
if let successIconColor = jsonTheme["successIconColor"] as? String {
|
|
330
|
+
result.successIconColor = UIColor(fromHex: successIconColor)
|
|
331
|
+
}
|
|
332
|
+
if let errorIconColor = jsonTheme["errorIconColor"] as? String {
|
|
333
|
+
result.errorIconColor = UIColor(fromHex: errorIconColor)
|
|
334
|
+
}
|
|
335
|
+
if let cornerRadius = jsonTheme["cornerRadius"] as? CGFloat {
|
|
336
|
+
result.cornerRadius = cornerRadius
|
|
337
|
+
}
|
|
338
|
+
if let presentationStyle = jsonTheme["presentationStyle"] as? String {
|
|
339
|
+
if presentationStyle == "AUTOMATIC" {
|
|
340
|
+
result.presentationStyle = .automatic
|
|
341
|
+
}
|
|
342
|
+
if presentationStyle == "ALWAYS_FULLSCREEN" {
|
|
343
|
+
result.presentationStyle = .alwaysFullscreen
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if let inputFieldColor = jsonTheme["inputFieldColor"] as? String {
|
|
347
|
+
result.inputFieldColor = UIColor(fromHex: inputFieldColor)
|
|
348
|
+
}
|
|
349
|
+
if let inputFieldTextColor = jsonTheme["inputFieldTextColor"] as? String {
|
|
350
|
+
result.inputFieldTextColor = UIColor(fromHex: inputFieldTextColor)
|
|
351
|
+
}
|
|
352
|
+
if let inputFieldPlaceholderTextColor = jsonTheme["inputFieldPlaceholderTextColor"] as? String {
|
|
353
|
+
result.inputFieldPlaceholderTextColor = UIColor(fromHex: inputFieldPlaceholderTextColor)
|
|
354
|
+
}
|
|
355
|
+
if let inputFieldErrorColor = jsonTheme["inputFieldErrorColor"] as? String {
|
|
356
|
+
result.inputFieldErrorColor = UIColor(fromHex: inputFieldErrorColor)
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return result
|
|
361
|
+
}
|
|
362
|
+
*/
|
|
363
|
+
|
|
364
|
+
/*
|
|
365
|
+
private func makeFont(origin: UIFont, jsonFont: [String: Any]) -> UIFont {
|
|
366
|
+
var targetFontSize = origin.pointSize
|
|
367
|
+
var targetFontName = origin.fontName
|
|
368
|
+
|
|
369
|
+
if let size = jsonFont["size"] as? CGFloat {
|
|
370
|
+
targetFontSize = size
|
|
371
|
+
}
|
|
372
|
+
if let fontName = jsonFont["fontName"] as? String {
|
|
373
|
+
targetFontName = fontName
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
return UIFont(name: targetFontName, size: targetFontSize) ?? origin.withSize(targetFontSize)
|
|
377
|
+
}
|
|
378
|
+
*/
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
class MobilePaymentPaymentObserver {
|
|
382
|
+
weak var owner: MobilePaymentPayment?
|
|
383
|
+
|
|
384
|
+
init(owner: MobilePaymentPayment) {
|
|
385
|
+
self.owner = owner
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
extension MobilePaymentPaymentObserver: AvailableCardInputMethodsObserver {
|
|
390
|
+
func availableCardInputMethodsDidChange(_ cardInputMethods: CardInputMethods) {
|
|
391
|
+
owner?.emitter?.onAvailableCardInputMethodsChange(cardInputMethods.jsonValue)
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
extension MobilePaymentPaymentObserver: PaymentManagerDelegate {
|
|
396
|
+
func paymentManager(_ paymentManager: PaymentManager, didStart payment: Payment) {
|
|
397
|
+
handlePayment(name: "didStart", payment: payment, error: nil)
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
func paymentManager(_ paymentManager: PaymentManager, willFinish payment: Payment) {
|
|
401
|
+
handlePayment(name: "willFinish", payment: payment, error: nil)
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
func paymentManager(_ paymentManager: PaymentManager, didFinish payment: Payment) {
|
|
405
|
+
handlePayment(name: "didFinish", payment: payment, error: nil)
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
func paymentManager(_ paymentManager: PaymentManager, didFail payment: Payment, withError error: Error) {
|
|
409
|
+
handlePayment(name: "didFail", payment: payment, error: error)
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
func paymentManager(_ paymentManager: PaymentManager, willCancel payment: Payment) {
|
|
413
|
+
handlePayment(name: "willCancel", payment: payment, error: nil)
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
func paymentManager(_ paymentManager: PaymentManager, didCancel payment: Payment) {
|
|
417
|
+
handlePayment(name: "didCancel", payment: payment, error: nil)
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
private func handlePayment(name: String, payment: Payment, error: Error?) {
|
|
421
|
+
var body: [String: Any] = [:]
|
|
422
|
+
body["name"] = name
|
|
423
|
+
body["payment"] = payment.jsonDictionary
|
|
424
|
+
if let error = error {
|
|
425
|
+
let realError = error as NSError
|
|
426
|
+
let errorCode = paymentErrorCode(nativeErrorCode: realError.code)
|
|
427
|
+
body["error"] = ErrorUtilities.serializeErrorToJson(code: errorCode, error: realError)
|
|
428
|
+
}
|
|
429
|
+
owner?.emitter?.onPaymentFlowStatusChange(body)
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
private func paymentErrorCode(nativeErrorCode: Int) -> String {
|
|
433
|
+
if let error = PaymentError(rawValue: nativeErrorCode) {
|
|
434
|
+
switch error {
|
|
435
|
+
case .noNetwork:
|
|
436
|
+
return PaymentErrorNoNetwork
|
|
437
|
+
case .notAuthorized:
|
|
438
|
+
return PaymentErrorNotAuthorized
|
|
439
|
+
case .invalidPaymentParameters:
|
|
440
|
+
return PaymentErrorInvalidPaymentParameters
|
|
441
|
+
case .timedOut:
|
|
442
|
+
return PaymentErrorTimedOut
|
|
443
|
+
case .locationPermissionNeeded:
|
|
444
|
+
return PaymentErrorLocationPermissionNeeded
|
|
445
|
+
case .paymentAlreadyInProgress:
|
|
446
|
+
return PaymentErrorPaymentAlreadyInProgress
|
|
447
|
+
case .idempotencyKeyReused:
|
|
448
|
+
return PaymentErrorIdempotencyKeyReused
|
|
449
|
+
case .invalidPaymentSource:
|
|
450
|
+
return PaymentErrorInvalidPaymentSource
|
|
451
|
+
case .unexpected:
|
|
452
|
+
return PaymentErrorUnexpected
|
|
453
|
+
case .merchantNotOptedIntoOfflineProcessing:
|
|
454
|
+
return PaymentErrorMerchantNotOptedIntoOfflineProcessing
|
|
455
|
+
case .offlineTransactionAmountExceeded:
|
|
456
|
+
return PaymentErrorOfflineTransactionAmountExceeded
|
|
457
|
+
case .offlineStoredAmountExceeded:
|
|
458
|
+
return PaymentErrorOfflineStoredAmountExceeded
|
|
459
|
+
case .sandboxUnsupportedForOfflineProcessing:
|
|
460
|
+
return PaymentErrorSandboxUnsupportedForOfflineProcessing
|
|
461
|
+
case .deviceTimeDoesNotMatchServerTime:
|
|
462
|
+
return PaymentDeviceClockSkewed
|
|
463
|
+
case .unsupportedMode:
|
|
464
|
+
return PaymentErrorUnsupportedMode
|
|
465
|
+
case .trackingConsentIsPending:
|
|
466
|
+
return PaymentTrackingConsentIsPending
|
|
467
|
+
case .paymentAttemptIdRequiredForSca:
|
|
468
|
+
return PaymentAttemptIdRequiredForSca
|
|
469
|
+
case .paymentAttemptIdReused:
|
|
470
|
+
return PaymentAttemptIdReused
|
|
471
|
+
@unknown default:
|
|
472
|
+
return ErrorUtilities.UNKNOWN_ERROR
|
|
473
|
+
}
|
|
474
|
+
} else {
|
|
475
|
+
return ErrorUtilities.UNKNOWN_ERROR
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|