@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,542 @@
|
|
|
1
|
+
package com.connexup.square.mobilepayment
|
|
2
|
+
|
|
3
|
+
import com.connexup.square.mobilepayment.convert.readableArray
|
|
4
|
+
import com.connexup.square.mobilepayment.convert.readableMap
|
|
5
|
+
import com.connexup.square.mobilepayment.convert.toAdditionalPaymentMethodType
|
|
6
|
+
import com.connexup.square.mobilepayment.convert.toDelayAction
|
|
7
|
+
import com.connexup.square.mobilepayment.convert.toMoney
|
|
8
|
+
import com.connexup.square.mobilepayment.convert.toProcessingMode
|
|
9
|
+
import com.connexup.square.mobilepayment.convert.writableArray
|
|
10
|
+
import com.facebook.react.bridge.Promise
|
|
11
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
12
|
+
import com.facebook.react.bridge.ReadableMap
|
|
13
|
+
import com.facebook.react.bridge.WritableArray
|
|
14
|
+
import com.facebook.react.bridge.WritableMap
|
|
15
|
+
import com.facebook.react.bridge.WritableNativeArray
|
|
16
|
+
import com.facebook.react.bridge.WritableNativeMap
|
|
17
|
+
import com.squareup.sdk.mobilepayments.MobilePaymentsSdk
|
|
18
|
+
import com.squareup.sdk.mobilepayments.core.Result
|
|
19
|
+
import com.squareup.sdk.mobilepayments.core.CallbackReference
|
|
20
|
+
import com.squareup.sdk.mobilepayments.extensions.PaymentResult
|
|
21
|
+
import com.squareup.sdk.mobilepayments.payment.AdditionalPaymentMethod
|
|
22
|
+
import com.squareup.sdk.mobilepayments.payment.PaymentErrorCode
|
|
23
|
+
import com.squareup.sdk.mobilepayments.payment.PaymentHandle
|
|
24
|
+
import com.squareup.sdk.mobilepayments.payment.PaymentParameters
|
|
25
|
+
import com.squareup.sdk.mobilepayments.payment.PromptMode
|
|
26
|
+
import com.squareup.sdk.mobilepayments.payment.PromptParameters
|
|
27
|
+
import kotlinx.coroutines.CoroutineScope
|
|
28
|
+
import kotlinx.coroutines.Dispatchers
|
|
29
|
+
import kotlinx.coroutines.SupervisorJob
|
|
30
|
+
import kotlinx.coroutines.launch
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Description:
|
|
34
|
+
* @author lukechen@chancetop.com
|
|
35
|
+
* @date 2026/2/2
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
private const val PAYMENT_ERROR_NO_NETWORK = "PAYMENT_ERROR_NO_NETWORK"
|
|
39
|
+
private const val PAYMENT_ERROR_NOT_AUTHORIZED = "PAYMENT_ERROR_NOT_AUTHORIZED"
|
|
40
|
+
private const val PAYMENT_ERROR_INVALID_PAYMENT_PARAMETERS =
|
|
41
|
+
"PAYMENT_ERROR_INVALID_PAYMENT_PARAMETERS"
|
|
42
|
+
private const val PAYMENT_ERROR_TIMED_OUT = "PAYMENT_ERROR_TIMED_OUT"
|
|
43
|
+
private const val PAYMENT_ERROR_LOCATION_PERMISSION_NEEDED =
|
|
44
|
+
"PAYMENT_ERROR_LOCATION_PERMISSION_NEEDED"
|
|
45
|
+
private const val PAYMENT_ERROR_PAYMENT_ALREADY_IN_PROGRESS =
|
|
46
|
+
"PAYMENT_ERROR_PAYMENT_ALREADY_IN_PROGRESS"
|
|
47
|
+
private const val PAYMENT_ERROR_IDEMPOTENCY_KEY_REUSED = "PAYMENT_ERROR_IDEMPOTENCY_KEY_REUSED"
|
|
48
|
+
private const val PAYMENT_ERROR_INVALID_PAYMENT_SOURCE = "PAYMENT_ERROR_INVALID_PAYMENT_SOURCE"
|
|
49
|
+
private const val PAYMENT_ERROR_CANCELED = "PAYMENT_ERROR_CANCELED"
|
|
50
|
+
private const val PAYMENT_CONSENT_NOT_PROVIDED = "PAYMENT_CONSENT_NOT_PROVIDED"
|
|
51
|
+
private const val PAYMENT_DEVICE_CLOCK_SKEWED = "PAYMENT_DEVICE_CLOCK_SKEWED"
|
|
52
|
+
private const val PAYMENT_ERROR_UNEXPECTED = "PAYMENT_ERROR_UNEXPECTED"
|
|
53
|
+
|
|
54
|
+
class MobilePaymentPayment(reactContext: ReactApplicationContext) :
|
|
55
|
+
NativeMobilePaymentPaymentSpec(reactContext) {
|
|
56
|
+
|
|
57
|
+
private val scope: CoroutineScope by lazy {
|
|
58
|
+
CoroutineScope(
|
|
59
|
+
SupervisorJob() + Dispatchers.Main
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private var availableCardEntryMethodChangedCallbackRef: CallbackReference? = null
|
|
64
|
+
|
|
65
|
+
private var initializeListener: InitializeListener? = null
|
|
66
|
+
|
|
67
|
+
override fun initialize() {
|
|
68
|
+
super.initialize()
|
|
69
|
+
this.initializeListener = MobilePaymentSDK.addInitializeListener {
|
|
70
|
+
onSDKInitialize()
|
|
71
|
+
}
|
|
72
|
+
if (MobilePaymentSDK.isInitialize) {
|
|
73
|
+
initializeListener?.onInitialize()
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
override fun invalidate() {
|
|
78
|
+
initializeListener?.let {
|
|
79
|
+
MobilePaymentSDK.removeInitializeListener(it)
|
|
80
|
+
}
|
|
81
|
+
initializeListener = null
|
|
82
|
+
availableCardEntryMethodChangedCallbackRef?.clear()
|
|
83
|
+
availableCardEntryMethodChangedCallbackRef = null
|
|
84
|
+
scope.launch {
|
|
85
|
+
MobilePaymentsSdk.paymentManager().currentPaymentHandle?.cancel()
|
|
86
|
+
}
|
|
87
|
+
super.invalidate()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private fun onSDKInitialize() {
|
|
91
|
+
availableCardEntryMethodChangedCallbackRef?.clear()
|
|
92
|
+
availableCardEntryMethodChangedCallbackRef =
|
|
93
|
+
MobilePaymentsSdk.paymentManager().setAvailableCardEntryMethodChangedCallback {
|
|
94
|
+
emitOnAvailableCardInputMethodsChange(it.readableArray)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
override fun startPayment(
|
|
99
|
+
paymentParameters: ReadableMap,
|
|
100
|
+
promptParameters: ReadableMap,
|
|
101
|
+
promise: Promise
|
|
102
|
+
) {
|
|
103
|
+
//TODO handle theme
|
|
104
|
+
scope.launch {
|
|
105
|
+
val paymentParametersMap = paymentParameters.toHashMap()
|
|
106
|
+
|
|
107
|
+
val allowCardSurcharge = paymentParametersMap["allowCardSurcharge"] as? Boolean
|
|
108
|
+
if (allowCardSurcharge == null) {
|
|
109
|
+
promise.reject(
|
|
110
|
+
PARAMS_ERROR, RNMobilePaymentErrorUtilities.createNativeModuleError(
|
|
111
|
+
PARAMS_ERROR,
|
|
112
|
+
"Params allowCardSurcharge Not Found"
|
|
113
|
+
), null
|
|
114
|
+
)
|
|
115
|
+
return@launch
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
val paymentAttemptId = paymentParametersMap["paymentAttemptId"] as? String
|
|
119
|
+
if (paymentAttemptId == null) {
|
|
120
|
+
promise.reject(
|
|
121
|
+
PARAMS_ERROR, RNMobilePaymentErrorUtilities.createNativeModuleError(
|
|
122
|
+
PARAMS_ERROR,
|
|
123
|
+
"Params paymentAttemptId Not Found"
|
|
124
|
+
), null
|
|
125
|
+
)
|
|
126
|
+
return@launch
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
val amountMoney =
|
|
130
|
+
(paymentParametersMap["amountMoney"] as? Map<String?, Any?>)?.toMoney()
|
|
131
|
+
if (amountMoney == null) {
|
|
132
|
+
promise.reject(
|
|
133
|
+
PARAMS_ERROR, RNMobilePaymentErrorUtilities.createNativeModuleError(
|
|
134
|
+
PARAMS_ERROR,
|
|
135
|
+
"Params amountMoney Not Found"
|
|
136
|
+
), null
|
|
137
|
+
)
|
|
138
|
+
return@launch
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
val processingMode =
|
|
142
|
+
(paymentParametersMap["processingMode"] as? String)?.toProcessingMode()
|
|
143
|
+
if (processingMode == null) {
|
|
144
|
+
promise.reject(
|
|
145
|
+
PARAMS_ERROR, RNMobilePaymentErrorUtilities.createNativeModuleError(
|
|
146
|
+
PARAMS_ERROR,
|
|
147
|
+
"Params processingMode Not Found"
|
|
148
|
+
), null
|
|
149
|
+
)
|
|
150
|
+
return@launch
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
var paymentParametersBuilder =
|
|
154
|
+
PaymentParameters.Builder(amountMoney, processingMode, allowCardSurcharge)
|
|
155
|
+
.paymentAttemptId(paymentAttemptId)
|
|
156
|
+
|
|
157
|
+
val acceptPartialAuthorization =
|
|
158
|
+
paymentParametersMap["acceptPartialAuthorization"] as? Boolean
|
|
159
|
+
if (acceptPartialAuthorization != null) {
|
|
160
|
+
paymentParametersBuilder =
|
|
161
|
+
paymentParametersBuilder.acceptPartialAuthorization(acceptPartialAuthorization)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
val autocomplete = paymentParametersMap["autocomplete"] as? Boolean
|
|
165
|
+
if (autocomplete != null) {
|
|
166
|
+
paymentParametersBuilder =
|
|
167
|
+
paymentParametersBuilder.autocomplete(autocomplete)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
val delayAction = (paymentParametersMap["delayAction"] as? String)?.toDelayAction()
|
|
171
|
+
if (delayAction != null) {
|
|
172
|
+
paymentParametersBuilder =
|
|
173
|
+
paymentParametersBuilder.delayAction(delayAction)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
//TODO delayDuration logic
|
|
177
|
+
val delayDuration = (paymentParametersMap["delayDuration"] as? Number)?.toLong()
|
|
178
|
+
if (delayDuration != null) {
|
|
179
|
+
paymentParametersBuilder =
|
|
180
|
+
paymentParametersBuilder.delayDuration(delayDuration)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
val tipMoney = (paymentParametersMap["tipMoney"] as? Map<String?, Any?>)?.toMoney()
|
|
184
|
+
if (tipMoney != null) {
|
|
185
|
+
paymentParametersBuilder =
|
|
186
|
+
paymentParametersBuilder.tipMoney(tipMoney)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
val appFeeMoney =
|
|
190
|
+
(paymentParametersMap["appFeeMoney"] as? Map<String?, Any?>)?.toMoney()
|
|
191
|
+
if (appFeeMoney != null) {
|
|
192
|
+
paymentParametersBuilder =
|
|
193
|
+
paymentParametersBuilder.appFeeMoney(appFeeMoney)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
val locationID = paymentParametersMap["locationID"] as? String
|
|
197
|
+
if (locationID != null) {
|
|
198
|
+
paymentParametersBuilder =
|
|
199
|
+
paymentParametersBuilder.locationId(locationID)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
val orderID = paymentParametersMap["orderID"] as? String
|
|
203
|
+
if (orderID != null) {
|
|
204
|
+
paymentParametersBuilder =
|
|
205
|
+
paymentParametersBuilder.orderId(orderID)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
val referenceID = paymentParametersMap["referenceID"] as? String
|
|
209
|
+
if (referenceID != null) {
|
|
210
|
+
paymentParametersBuilder =
|
|
211
|
+
paymentParametersBuilder.referenceId(referenceID)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
val customerID = paymentParametersMap["customerID"] as? String
|
|
215
|
+
if (customerID != null) {
|
|
216
|
+
paymentParametersBuilder =
|
|
217
|
+
paymentParametersBuilder.customerId(customerID)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
val teamMemberID = paymentParametersMap["teamMemberID"] as? String
|
|
221
|
+
if (teamMemberID != null) {
|
|
222
|
+
paymentParametersBuilder =
|
|
223
|
+
paymentParametersBuilder.teamMemberId(teamMemberID)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
val note = paymentParametersMap["note"] as? String
|
|
227
|
+
if (note != null) {
|
|
228
|
+
paymentParametersBuilder =
|
|
229
|
+
paymentParametersBuilder.note(note)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
val statementDescriptionIdentifier =
|
|
233
|
+
paymentParametersMap["statementDescriptionIdentifier"] as? String
|
|
234
|
+
if (statementDescriptionIdentifier != null) {
|
|
235
|
+
paymentParametersBuilder =
|
|
236
|
+
paymentParametersBuilder.statementDescription(statementDescriptionIdentifier)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
val promptParametersMap = promptParameters.toHashMap()
|
|
240
|
+
|
|
241
|
+
val promptModeParams = promptParametersMap["mode"]
|
|
242
|
+
val promptMode = when (promptModeParams) {
|
|
243
|
+
"DEFAULT" -> PromptMode.DEFAULT
|
|
244
|
+
"CUSTOM" -> PromptMode.CUSTOM
|
|
245
|
+
else -> PromptMode.DEFAULT
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
//TODO improve this
|
|
249
|
+
val additionalMethodsParams = promptParametersMap["additionalMethods"]
|
|
250
|
+
val additionalMethods = when (additionalMethodsParams) {
|
|
251
|
+
"ALL" -> AdditionalPaymentMethod.allPaymentMethods
|
|
252
|
+
"KEYED" -> listOf(AdditionalPaymentMethod.Type.KEYED)
|
|
253
|
+
else -> AdditionalPaymentMethod.allPaymentMethods
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
MobilePaymentsSdk.paymentManager().currentPaymentHandle?.cancel()
|
|
257
|
+
MobilePaymentsSdk.paymentManager().startPaymentActivity(
|
|
258
|
+
paymentParametersBuilder.build(),
|
|
259
|
+
PromptParameters(promptMode, additionalMethods)
|
|
260
|
+
) {
|
|
261
|
+
onPaymentCallback(it)
|
|
262
|
+
}
|
|
263
|
+
promise.resolve(null)
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
override fun availableCardInputMethods(): WritableArray {
|
|
268
|
+
return MobilePaymentsSdk.paymentManager().getAvailableCardEntryMethods().writableArray
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
override fun additionalPaymentMethods(): WritableArray {
|
|
272
|
+
return MobilePaymentsSdk.paymentManager().currentPaymentHandle?.additionalPaymentMethods?.writableArray
|
|
273
|
+
?: WritableNativeArray()
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
override fun triggerPaymentWithAdditionalPaymentMethod(
|
|
277
|
+
paymentSource: ReadableMap,
|
|
278
|
+
promise: Promise
|
|
279
|
+
) {
|
|
280
|
+
scope.launch {
|
|
281
|
+
val sourceType = paymentSource.getString("type")?.toAdditionalPaymentMethodType()
|
|
282
|
+
if (sourceType == null) {
|
|
283
|
+
promise.reject(
|
|
284
|
+
PARAMS_ERROR, RNMobilePaymentErrorUtilities.createNativeModuleError(
|
|
285
|
+
PARAMS_ERROR,
|
|
286
|
+
"Params sourceType Not Found"
|
|
287
|
+
), null
|
|
288
|
+
)
|
|
289
|
+
return@launch
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
val paymentHandle = MobilePaymentsSdk.paymentManager().currentPaymentHandle
|
|
293
|
+
if (paymentHandle == null) {
|
|
294
|
+
promise.reject(
|
|
295
|
+
UNKNOWN_ERROR, RNMobilePaymentErrorUtilities.createNativeModuleError(
|
|
296
|
+
UNKNOWN_ERROR,
|
|
297
|
+
"PaymentHandle Not Found"
|
|
298
|
+
), null
|
|
299
|
+
)
|
|
300
|
+
return@launch
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
val additionalPaymentMethod = paymentHandle.findMethod(sourceType)
|
|
304
|
+
|
|
305
|
+
if (additionalPaymentMethod == null) {
|
|
306
|
+
promise.reject(
|
|
307
|
+
UNKNOWN_ERROR, RNMobilePaymentErrorUtilities.createNativeModuleError(
|
|
308
|
+
UNKNOWN_ERROR,
|
|
309
|
+
"AdditionalPaymentMethod Not Found"
|
|
310
|
+
), null
|
|
311
|
+
)
|
|
312
|
+
return@launch
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
try {
|
|
316
|
+
when (additionalPaymentMethod) {
|
|
317
|
+
is AdditionalPaymentMethod.KeyedMethod -> {
|
|
318
|
+
additionalPaymentMethod.trigger()
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/* is AdditionalPaymentMethod.CardOnFileEntryMethod -> {
|
|
322
|
+
val cardID = paymentSource.getString("cardID")
|
|
323
|
+
if (cardID == null) {
|
|
324
|
+
promise.reject(
|
|
325
|
+
PARAMS_ERROR, RNMobilePaymentErrorUtilities.createNativeModuleError(
|
|
326
|
+
PARAMS_ERROR,
|
|
327
|
+
"Params cardID Not Found"
|
|
328
|
+
), null
|
|
329
|
+
)
|
|
330
|
+
return@launch
|
|
331
|
+
}
|
|
332
|
+
val customerID = paymentSource.getString("customerID")
|
|
333
|
+
if (customerID == null) {
|
|
334
|
+
promise.reject(
|
|
335
|
+
PARAMS_ERROR, RNMobilePaymentErrorUtilities.createNativeModuleError(
|
|
336
|
+
PARAMS_ERROR,
|
|
337
|
+
"Params cardID Not Found"
|
|
338
|
+
), null
|
|
339
|
+
)
|
|
340
|
+
return@launch
|
|
341
|
+
}
|
|
342
|
+
additionalPaymentMethod.trigger(cardID, customerID)
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
is AlternatePaymentMethod.CashEntryMethod -> {
|
|
346
|
+
val buyerSuppliedMoney = paymentSource.getMap("buyerSuppliedMoney")
|
|
347
|
+
if (buyerSuppliedMoney == null) {
|
|
348
|
+
promise.reject(
|
|
349
|
+
PARAMS_ERROR, RNMobilePaymentErrorUtilities.createNativeModuleError(
|
|
350
|
+
PARAMS_ERROR,
|
|
351
|
+
"Params buyerSuppliedMoney Not Found"
|
|
352
|
+
), null
|
|
353
|
+
)
|
|
354
|
+
return@launch
|
|
355
|
+
}
|
|
356
|
+
val realBuyerSuppliedMoney = buyerSuppliedMoney.toMoney()
|
|
357
|
+
if (realBuyerSuppliedMoney == null) {
|
|
358
|
+
promise.reject(
|
|
359
|
+
PARAMS_ERROR, RNMobilePaymentErrorUtilities.createNativeModuleError(
|
|
360
|
+
PARAMS_ERROR,
|
|
361
|
+
"Params buyerSuppliedMoney error"
|
|
362
|
+
), null
|
|
363
|
+
)
|
|
364
|
+
return@launch
|
|
365
|
+
}
|
|
366
|
+
additionalPaymentMethod.trigger(realBuyerSuppliedMoney)
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
is AlternatePaymentMethod.ExternalEntryMethod -> {
|
|
370
|
+
val externalTenderTyp = paymentSource.getString("externalTenderTyp")
|
|
371
|
+
if (externalTenderTyp == null) {
|
|
372
|
+
promise.reject(
|
|
373
|
+
PARAMS_ERROR, RNMobilePaymentErrorUtilities.createNativeModuleError(
|
|
374
|
+
PARAMS_ERROR,
|
|
375
|
+
"Params externalTenderTyp Not Found"
|
|
376
|
+
), null
|
|
377
|
+
)
|
|
378
|
+
return@launch
|
|
379
|
+
}
|
|
380
|
+
val source = paymentSource.getString("source")
|
|
381
|
+
if (source == null) {
|
|
382
|
+
promise.reject(
|
|
383
|
+
PARAMS_ERROR, RNMobilePaymentErrorUtilities.createNativeModuleError(
|
|
384
|
+
PARAMS_ERROR,
|
|
385
|
+
"Params source Not Found"
|
|
386
|
+
), null
|
|
387
|
+
)
|
|
388
|
+
return@launch
|
|
389
|
+
}
|
|
390
|
+
val sourceId = paymentSource.getString("sourceId")
|
|
391
|
+
val sourceFeeMoney = paymentSource.getMap("sourceFeeMoney")
|
|
392
|
+
//TODO sourceFeeMoney
|
|
393
|
+
var realSourceFeeMoney: Money? = null
|
|
394
|
+
if (sourceFeeMoney != null) {
|
|
395
|
+
realSourceFeeMoney = sourceFeeMoney.toMoney()
|
|
396
|
+
if (realSourceFeeMoney == null) {
|
|
397
|
+
promise.reject(
|
|
398
|
+
PARAMS_ERROR,
|
|
399
|
+
RNMobilePaymentErrorUtilities.createNativeModuleError(
|
|
400
|
+
PARAMS_ERROR,
|
|
401
|
+
"Params sourceFeeMoney error"
|
|
402
|
+
),
|
|
403
|
+
null
|
|
404
|
+
)
|
|
405
|
+
return@launch
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
additionalPaymentMethod.trigger(
|
|
409
|
+
ExternalPaymentDetails.Builder(
|
|
410
|
+
externalTenderTyp,
|
|
411
|
+
source,
|
|
412
|
+
sourceId,
|
|
413
|
+
realSourceFeeMoney
|
|
414
|
+
).build()
|
|
415
|
+
)
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
is AlternatePaymentMethod.HouseAccountEntryMethod -> {
|
|
419
|
+
val paymentSourceToken = paymentSource.getString("paymentSourceToken")
|
|
420
|
+
if (paymentSourceToken == null) {
|
|
421
|
+
promise.reject(
|
|
422
|
+
PARAMS_ERROR, RNMobilePaymentErrorUtilities.createNativeModuleError(
|
|
423
|
+
PARAMS_ERROR,
|
|
424
|
+
"Params paymentSourceToken Not Found"
|
|
425
|
+
), null
|
|
426
|
+
)
|
|
427
|
+
return@launch
|
|
428
|
+
}
|
|
429
|
+
val customerId = paymentSource.getString("customerId")
|
|
430
|
+
if (customerId == null) {
|
|
431
|
+
promise.reject(
|
|
432
|
+
PARAMS_ERROR, RNMobilePaymentErrorUtilities.createNativeModuleError(
|
|
433
|
+
PARAMS_ERROR,
|
|
434
|
+
"Params customerId Not Found"
|
|
435
|
+
), null
|
|
436
|
+
)
|
|
437
|
+
return@launch
|
|
438
|
+
}
|
|
439
|
+
additionalPaymentMethod.trigger(paymentSourceToken, customerId)
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
is AlternatePaymentMethod.ManualEntryMethod -> {
|
|
443
|
+
additionalPaymentMethod.trigger()
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
is AlternatePaymentMethod.QrScanMethod -> {
|
|
447
|
+
val tag =
|
|
448
|
+
additionalPaymentMethod.tag as? AlternatePaymentMethod.PaymentMethodTag.QrScanMethodTag
|
|
449
|
+
if (tag == null) {
|
|
450
|
+
promise.reject(
|
|
451
|
+
UNKNOWN_ERROR,
|
|
452
|
+
RNMobilePaymentErrorUtilities.createNativeModuleError(
|
|
453
|
+
UNKNOWN_ERROR,
|
|
454
|
+
"tag == null"
|
|
455
|
+
),
|
|
456
|
+
null
|
|
457
|
+
)
|
|
458
|
+
return@launch
|
|
459
|
+
}
|
|
460
|
+
additionalPaymentMethod.trigger(tag)
|
|
461
|
+
}*/
|
|
462
|
+
}
|
|
463
|
+
} catch (e: Exception) {
|
|
464
|
+
promise.reject(
|
|
465
|
+
UNKNOWN_ERROR, RNMobilePaymentErrorUtilities.createNativeModuleError(
|
|
466
|
+
UNKNOWN_ERROR,
|
|
467
|
+
e.message ?: "",
|
|
468
|
+
), e
|
|
469
|
+
)
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
override fun currentPayment(): WritableMap? {
|
|
475
|
+
return null
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
override fun isCurrentPaymentCancelable(): Boolean {
|
|
479
|
+
val paymentHandle = MobilePaymentsSdk.paymentManager().currentPaymentHandle ?: return true
|
|
480
|
+
//TODO isCurrentPaymentCancelable
|
|
481
|
+
return true
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
override fun cancelCurrentPayment(promise: Promise) {
|
|
485
|
+
scope.launch {
|
|
486
|
+
val paymentHandle = MobilePaymentsSdk.paymentManager().currentPaymentHandle
|
|
487
|
+
if (paymentHandle == null) {
|
|
488
|
+
promise.resolve(true)
|
|
489
|
+
return@launch
|
|
490
|
+
}
|
|
491
|
+
promise.resolve(
|
|
492
|
+
when (paymentHandle.cancel()) {
|
|
493
|
+
PaymentHandle.CancelResult.NO_PAYMENT_IN_PROGRESS -> true
|
|
494
|
+
PaymentHandle.CancelResult.CANCELED -> true
|
|
495
|
+
PaymentHandle.CancelResult.NOT_CANCELABLE -> false
|
|
496
|
+
}
|
|
497
|
+
)
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
private fun onPaymentCallback(paymentResult: PaymentResult) {
|
|
502
|
+
val result = WritableNativeMap()
|
|
503
|
+
|
|
504
|
+
when (paymentResult) {
|
|
505
|
+
is Result.Failure -> {
|
|
506
|
+
val errorCode = when (paymentResult.errorCode) {
|
|
507
|
+
PaymentErrorCode.NOT_AUTHORIZED -> PAYMENT_ERROR_NOT_AUTHORIZED
|
|
508
|
+
PaymentErrorCode.TIMEOUT -> PAYMENT_ERROR_TIMED_OUT
|
|
509
|
+
PaymentErrorCode.LOCATION_SERVICES_DISABLED -> PAYMENT_ERROR_LOCATION_PERMISSION_NEEDED
|
|
510
|
+
PaymentErrorCode.USAGE_ERROR -> PAYMENT_ERROR_UNEXPECTED
|
|
511
|
+
PaymentErrorCode.DEVICE_CLOCK_SKEWED -> PAYMENT_DEVICE_CLOCK_SKEWED
|
|
512
|
+
PaymentErrorCode.CANCELED -> PAYMENT_ERROR_CANCELED
|
|
513
|
+
PaymentErrorCode.CONSENT_NOT_PROVIDED -> PAYMENT_CONSENT_NOT_PROVIDED
|
|
514
|
+
}
|
|
515
|
+
if (paymentResult.errorCode == PaymentErrorCode.CANCELED) {
|
|
516
|
+
result.putString("name", "didCancel")
|
|
517
|
+
} else {
|
|
518
|
+
result.putString("name", "didFail")
|
|
519
|
+
result.putString(
|
|
520
|
+
"error", RNMobilePaymentErrorUtilities.serializeErrorToJson(
|
|
521
|
+
errorCode,
|
|
522
|
+
paymentResult.errorMessage,
|
|
523
|
+
paymentResult.debugCode,
|
|
524
|
+
paymentResult.debugMessage
|
|
525
|
+
)
|
|
526
|
+
)
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
is Result.Success -> {
|
|
531
|
+
result.putString("name", "didFinish")
|
|
532
|
+
result.putMap("payment", paymentResult.value.readableMap)
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
this.emitOnPaymentFlowStatusChange(result)
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
companion object {
|
|
540
|
+
const val NAME = NativeMobilePaymentPaymentSpec.NAME
|
|
541
|
+
}
|
|
542
|
+
}
|