halo-sdk-react-native 1.0.4 → 1.0.5
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/CHANGELOG.md +56 -27
- package/README.md +735 -735
- package/android/build.gradle +90 -89
- package/android/settings.gradle +1 -1
- package/android/src/main/AndroidManifest.xml +9 -9
- package/android/src/main/kotlin/za/co/synthesis/halo/sdkreactnativeplugin/AnimationActivity.kt +160 -160
- package/android/src/main/kotlin/za/co/synthesis/halo/sdkreactnativeplugin/Const.kt +15 -15
- package/android/src/main/kotlin/za/co/synthesis/halo/sdkreactnativeplugin/HaloCallbacks.kt +126 -126
- package/android/src/main/kotlin/za/co/synthesis/halo/sdkreactnativeplugin/HaloReactActivity.kt +61 -61
- package/android/src/main/kotlin/za/co/synthesis/halo/sdkreactnativeplugin/HaloSdkImplementation.kt +81 -81
- package/android/src/main/kotlin/za/co/synthesis/halo/sdkreactnativeplugin/HaloSdkModule.kt +74 -74
- package/android/src/main/kotlin/za/co/synthesis/halo/sdkreactnativeplugin/HaloSdkPackage.kt +16 -16
- package/android/src/main/kotlin/za/co/synthesis/halo/sdkreactnativeplugin/UIContext.kt +20 -20
- package/android/src/main/kotlin/za/co/synthesis/halo/sdkreactnativeplugin/Utils.kt +154 -154
- package/package.json +34 -34
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
package za.co.synthesis.halo.sdkreactnativeplugin
|
|
2
|
-
|
|
3
|
-
import android.content.Intent
|
|
4
|
-
import android.os.Looper
|
|
5
|
-
import android.util.Log
|
|
6
|
-
import com.facebook.react.bridge.Arguments
|
|
7
|
-
import com.facebook.react.bridge.ReactApplicationContext
|
|
8
|
-
import com.facebook.react.bridge.WritableMap
|
|
9
|
-
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
10
|
-
import za.co.synthesis.halo.haloCommonInterface.HaloErrorCode
|
|
11
|
-
import za.co.synthesis.halo.haloCommonInterface.HaloTransactionResult
|
|
12
|
-
import za.co.synthesis.halo.haloCommonInterface.HaloTransactionResultType
|
|
13
|
-
import za.co.synthesis.halo.sdk.model.HaloAttestationHealthResult
|
|
14
|
-
import za.co.synthesis.halo.sdk.model.HaloInitializationResult
|
|
15
|
-
import za.co.synthesis.halo.sdk.model.HaloUIMessage
|
|
16
|
-
import za.co.synthesis.halo.sdk.model.IHaloCallbacks
|
|
17
|
-
|
|
18
|
-
const val HALO_SDK_EVENT = "haloSdkEvent"
|
|
19
|
-
|
|
20
|
-
class HaloCallbacks(
|
|
21
|
-
private val reactContext: ReactApplicationContext
|
|
22
|
-
) : IHaloCallbacks() {
|
|
23
|
-
private val TAG = "HaloCallbacks"
|
|
24
|
-
private val handler = android.os.Handler(Looper.getMainLooper())
|
|
25
|
-
private var _jwtCallback: ((String) -> Unit)? = null
|
|
26
|
-
|
|
27
|
-
private fun sendEvent(params: WritableMap) {
|
|
28
|
-
handler.post {
|
|
29
|
-
if (reactContext.hasActiveCatalystInstance()) {
|
|
30
|
-
reactContext
|
|
31
|
-
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
32
|
-
.emit(HALO_SDK_EVENT, params)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
override fun onAttestationError(details: HaloAttestationHealthResult) {
|
|
38
|
-
Log.d(TAG, "onAttestationError: $details")
|
|
39
|
-
val params = Arguments.createMap().apply {
|
|
40
|
-
putString("eventType", "attestation")
|
|
41
|
-
putMap("data", makeWritableMap(details))
|
|
42
|
-
}
|
|
43
|
-
sendEvent(params)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
override fun onHaloTransactionResult(result: HaloTransactionResult) {
|
|
47
|
-
Log.d(TAG, "onHaloTransactionResult: $result")
|
|
48
|
-
val association = "${result.receipt?.association}"
|
|
49
|
-
val maskedPAN = "${result.receipt?.maskedPAN}"
|
|
50
|
-
val transactionApproved = result.resultType == HaloTransactionResultType.Approved
|
|
51
|
-
|
|
52
|
-
val params = Arguments.createMap().apply {
|
|
53
|
-
putString("eventType", "transaction")
|
|
54
|
-
putMap("data", makeWritableMap(result))
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
handler.post {
|
|
58
|
-
val context = UIContext.getActivity()
|
|
59
|
-
val showSchemeAnimations = UIContext.areSchemeAnimationsEnabled()
|
|
60
|
-
if (context != null && transactionApproved && showSchemeAnimations) {
|
|
61
|
-
val intent = Intent(context, AnimationActivity::class.java)
|
|
62
|
-
intent.putExtra(Const.CARD_ASSOCIATION, association)
|
|
63
|
-
intent.putExtra(Const.MASKED_PAN, maskedPAN)
|
|
64
|
-
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
65
|
-
context.startActivity(intent)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (reactContext.hasActiveCatalystInstance()) {
|
|
69
|
-
reactContext
|
|
70
|
-
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
71
|
-
.emit(HALO_SDK_EVENT, params)
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
override fun onHaloUIMessage(message: HaloUIMessage) {
|
|
77
|
-
Log.d(TAG, "onHaloUIMessage: $message")
|
|
78
|
-
val params = Arguments.createMap().apply {
|
|
79
|
-
putString("eventType", "ui")
|
|
80
|
-
putMap("data", makeWritableMap(message))
|
|
81
|
-
}
|
|
82
|
-
sendEvent(params)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
override fun onInitializationResult(result: HaloInitializationResult) {
|
|
86
|
-
Log.d(TAG, "onInitializationResult resultType: ${result.resultType}")
|
|
87
|
-
Log.d(TAG, "onInitializationResult errorCode: ${result.errorCode}")
|
|
88
|
-
|
|
89
|
-
val params = Arguments.createMap().apply {
|
|
90
|
-
putString("eventType", "initialization")
|
|
91
|
-
putMap("data", makeWritableMap(result))
|
|
92
|
-
}
|
|
93
|
-
sendEvent(params)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
override fun onRequestJWT(callback: (String) -> Unit) {
|
|
97
|
-
Log.d(TAG, "onRequestJWT")
|
|
98
|
-
_jwtCallback = callback
|
|
99
|
-
val params = Arguments.createMap().apply {
|
|
100
|
-
putString("eventType", "onJwtRequest")
|
|
101
|
-
}
|
|
102
|
-
sendEvent(params)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
override fun onSecurityError(errorCode: HaloErrorCode) {
|
|
106
|
-
Log.d(TAG, "onSecurityError: $errorCode")
|
|
107
|
-
val params = Arguments.createMap().apply {
|
|
108
|
-
putString("eventType", "security")
|
|
109
|
-
putString("data", errorCode.name)
|
|
110
|
-
}
|
|
111
|
-
sendEvent(params)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
override fun onCameraControlLost() {
|
|
115
|
-
Log.d(TAG, "onCameraControlLost")
|
|
116
|
-
val params = Arguments.createMap().apply {
|
|
117
|
-
putString("eventType", "camera")
|
|
118
|
-
putString("data", "onCameraControlLost")
|
|
119
|
-
}
|
|
120
|
-
sendEvent(params)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
fun jwtCallback(jwt: String) {
|
|
124
|
-
_jwtCallback?.invoke(jwt)
|
|
125
|
-
}
|
|
126
|
-
}
|
|
1
|
+
package za.co.synthesis.halo.sdkreactnativeplugin
|
|
2
|
+
|
|
3
|
+
import android.content.Intent
|
|
4
|
+
import android.os.Looper
|
|
5
|
+
import android.util.Log
|
|
6
|
+
import com.facebook.react.bridge.Arguments
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
8
|
+
import com.facebook.react.bridge.WritableMap
|
|
9
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
10
|
+
import za.co.synthesis.halo.haloCommonInterface.HaloErrorCode
|
|
11
|
+
import za.co.synthesis.halo.haloCommonInterface.HaloTransactionResult
|
|
12
|
+
import za.co.synthesis.halo.haloCommonInterface.HaloTransactionResultType
|
|
13
|
+
import za.co.synthesis.halo.sdk.model.HaloAttestationHealthResult
|
|
14
|
+
import za.co.synthesis.halo.sdk.model.HaloInitializationResult
|
|
15
|
+
import za.co.synthesis.halo.sdk.model.HaloUIMessage
|
|
16
|
+
import za.co.synthesis.halo.sdk.model.IHaloCallbacks
|
|
17
|
+
|
|
18
|
+
const val HALO_SDK_EVENT = "haloSdkEvent"
|
|
19
|
+
|
|
20
|
+
class HaloCallbacks(
|
|
21
|
+
private val reactContext: ReactApplicationContext
|
|
22
|
+
) : IHaloCallbacks() {
|
|
23
|
+
private val TAG = "HaloCallbacks"
|
|
24
|
+
private val handler = android.os.Handler(Looper.getMainLooper())
|
|
25
|
+
private var _jwtCallback: ((String) -> Unit)? = null
|
|
26
|
+
|
|
27
|
+
private fun sendEvent(params: WritableMap) {
|
|
28
|
+
handler.post {
|
|
29
|
+
if (reactContext.hasActiveCatalystInstance()) {
|
|
30
|
+
reactContext
|
|
31
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
32
|
+
.emit(HALO_SDK_EVENT, params)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
override fun onAttestationError(details: HaloAttestationHealthResult) {
|
|
38
|
+
Log.d(TAG, "onAttestationError: $details")
|
|
39
|
+
val params = Arguments.createMap().apply {
|
|
40
|
+
putString("eventType", "attestation")
|
|
41
|
+
putMap("data", makeWritableMap(details))
|
|
42
|
+
}
|
|
43
|
+
sendEvent(params)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
override fun onHaloTransactionResult(result: HaloTransactionResult) {
|
|
47
|
+
Log.d(TAG, "onHaloTransactionResult: $result")
|
|
48
|
+
val association = "${result.receipt?.association}"
|
|
49
|
+
val maskedPAN = "${result.receipt?.maskedPAN}"
|
|
50
|
+
val transactionApproved = result.resultType == HaloTransactionResultType.Approved
|
|
51
|
+
|
|
52
|
+
val params = Arguments.createMap().apply {
|
|
53
|
+
putString("eventType", "transaction")
|
|
54
|
+
putMap("data", makeWritableMap(result))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
handler.post {
|
|
58
|
+
val context = UIContext.getActivity()
|
|
59
|
+
val showSchemeAnimations = UIContext.areSchemeAnimationsEnabled()
|
|
60
|
+
if (context != null && transactionApproved && showSchemeAnimations) {
|
|
61
|
+
val intent = Intent(context, AnimationActivity::class.java)
|
|
62
|
+
intent.putExtra(Const.CARD_ASSOCIATION, association)
|
|
63
|
+
intent.putExtra(Const.MASKED_PAN, maskedPAN)
|
|
64
|
+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
65
|
+
context.startActivity(intent)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (reactContext.hasActiveCatalystInstance()) {
|
|
69
|
+
reactContext
|
|
70
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
71
|
+
.emit(HALO_SDK_EVENT, params)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
override fun onHaloUIMessage(message: HaloUIMessage) {
|
|
77
|
+
Log.d(TAG, "onHaloUIMessage: $message")
|
|
78
|
+
val params = Arguments.createMap().apply {
|
|
79
|
+
putString("eventType", "ui")
|
|
80
|
+
putMap("data", makeWritableMap(message))
|
|
81
|
+
}
|
|
82
|
+
sendEvent(params)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
override fun onInitializationResult(result: HaloInitializationResult) {
|
|
86
|
+
Log.d(TAG, "onInitializationResult resultType: ${result.resultType}")
|
|
87
|
+
Log.d(TAG, "onInitializationResult errorCode: ${result.errorCode}")
|
|
88
|
+
|
|
89
|
+
val params = Arguments.createMap().apply {
|
|
90
|
+
putString("eventType", "initialization")
|
|
91
|
+
putMap("data", makeWritableMap(result))
|
|
92
|
+
}
|
|
93
|
+
sendEvent(params)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
override fun onRequestJWT(callback: (String) -> Unit) {
|
|
97
|
+
Log.d(TAG, "onRequestJWT")
|
|
98
|
+
_jwtCallback = callback
|
|
99
|
+
val params = Arguments.createMap().apply {
|
|
100
|
+
putString("eventType", "onJwtRequest")
|
|
101
|
+
}
|
|
102
|
+
sendEvent(params)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
override fun onSecurityError(errorCode: HaloErrorCode) {
|
|
106
|
+
Log.d(TAG, "onSecurityError: $errorCode")
|
|
107
|
+
val params = Arguments.createMap().apply {
|
|
108
|
+
putString("eventType", "security")
|
|
109
|
+
putString("data", errorCode.name)
|
|
110
|
+
}
|
|
111
|
+
sendEvent(params)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
override fun onCameraControlLost() {
|
|
115
|
+
Log.d(TAG, "onCameraControlLost")
|
|
116
|
+
val params = Arguments.createMap().apply {
|
|
117
|
+
putString("eventType", "camera")
|
|
118
|
+
putString("data", "onCameraControlLost")
|
|
119
|
+
}
|
|
120
|
+
sendEvent(params)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
fun jwtCallback(jwt: String) {
|
|
124
|
+
_jwtCallback?.invoke(jwt)
|
|
125
|
+
}
|
|
126
|
+
}
|
package/android/src/main/kotlin/za/co/synthesis/halo/sdkreactnativeplugin/HaloReactActivity.kt
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
package za.co.synthesis.halo.sdkreactnativeplugin
|
|
2
|
-
|
|
3
|
-
import android.nfc.NfcAdapter
|
|
4
|
-
import android.os.Bundle
|
|
5
|
-
import android.util.Log
|
|
6
|
-
import com.facebook.react.ReactActivity
|
|
7
|
-
import za.co.synthesis.halo.sdk.HaloSDK
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Abstract base activity for React Native apps using Halo SDK.
|
|
11
|
-
*
|
|
12
|
-
* Your app's MainActivity should extend HaloReactActivity instead of ReactActivity:
|
|
13
|
-
*
|
|
14
|
-
* ```kotlin
|
|
15
|
-
* class MainActivity : HaloReactActivity() {
|
|
16
|
-
* override fun getMainComponentName() = "YourAppName"
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* This class handles the full HaloSDK lifecycle (onCreate, onStart, onResume, onPause, onStop),
|
|
21
|
-
* mirroring the Flutter plugin's HaloActivity.
|
|
22
|
-
*/
|
|
23
|
-
abstract class HaloReactActivity : ReactActivity() {
|
|
24
|
-
private val TAG = "HaloReactActivity"
|
|
25
|
-
|
|
26
|
-
private val nfcAdapter: NfcAdapter? by lazy {
|
|
27
|
-
NfcAdapter.getDefaultAdapter(this)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
override fun onCreate(savedInstanceState: Bundle?) {
|
|
31
|
-
Log.d(TAG, "onCreate")
|
|
32
|
-
super.onCreate(savedInstanceState)
|
|
33
|
-
if (nfcAdapter?.isEnabled == true) {
|
|
34
|
-
HaloSDK.onCreate(this, this, savedInstanceState, null)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
override fun onStart() {
|
|
39
|
-
Log.d(TAG, "onStart")
|
|
40
|
-
super.onStart()
|
|
41
|
-
HaloSDK.onStart()
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
override fun onResume() {
|
|
45
|
-
Log.d(TAG, "onResume")
|
|
46
|
-
super.onResume()
|
|
47
|
-
HaloSDK.onResume()
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
override fun onPause() {
|
|
51
|
-
Log.d(TAG, "onPause")
|
|
52
|
-
HaloSDK.onPause()
|
|
53
|
-
super.onPause()
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
override fun onStop() {
|
|
57
|
-
Log.d(TAG, "onStop")
|
|
58
|
-
HaloSDK.onStop()
|
|
59
|
-
super.onStop()
|
|
60
|
-
}
|
|
61
|
-
}
|
|
1
|
+
package za.co.synthesis.halo.sdkreactnativeplugin
|
|
2
|
+
|
|
3
|
+
import android.nfc.NfcAdapter
|
|
4
|
+
import android.os.Bundle
|
|
5
|
+
import android.util.Log
|
|
6
|
+
import com.facebook.react.ReactActivity
|
|
7
|
+
import za.co.synthesis.halo.sdk.HaloSDK
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Abstract base activity for React Native apps using Halo SDK.
|
|
11
|
+
*
|
|
12
|
+
* Your app's MainActivity should extend HaloReactActivity instead of ReactActivity:
|
|
13
|
+
*
|
|
14
|
+
* ```kotlin
|
|
15
|
+
* class MainActivity : HaloReactActivity() {
|
|
16
|
+
* override fun getMainComponentName() = "YourAppName"
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* This class handles the full HaloSDK lifecycle (onCreate, onStart, onResume, onPause, onStop),
|
|
21
|
+
* mirroring the Flutter plugin's HaloActivity.
|
|
22
|
+
*/
|
|
23
|
+
abstract class HaloReactActivity : ReactActivity() {
|
|
24
|
+
private val TAG = "HaloReactActivity"
|
|
25
|
+
|
|
26
|
+
private val nfcAdapter: NfcAdapter? by lazy {
|
|
27
|
+
NfcAdapter.getDefaultAdapter(this)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
|
31
|
+
Log.d(TAG, "onCreate")
|
|
32
|
+
super.onCreate(savedInstanceState)
|
|
33
|
+
if (nfcAdapter?.isEnabled == true) {
|
|
34
|
+
HaloSDK.onCreate(this, this, savedInstanceState, null)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
override fun onStart() {
|
|
39
|
+
Log.d(TAG, "onStart")
|
|
40
|
+
super.onStart()
|
|
41
|
+
HaloSDK.onStart()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
override fun onResume() {
|
|
45
|
+
Log.d(TAG, "onResume")
|
|
46
|
+
super.onResume()
|
|
47
|
+
HaloSDK.onResume()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
override fun onPause() {
|
|
51
|
+
Log.d(TAG, "onPause")
|
|
52
|
+
HaloSDK.onPause()
|
|
53
|
+
super.onPause()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
override fun onStop() {
|
|
57
|
+
Log.d(TAG, "onStop")
|
|
58
|
+
HaloSDK.onStop()
|
|
59
|
+
super.onStop()
|
|
60
|
+
}
|
|
61
|
+
}
|
package/android/src/main/kotlin/za/co/synthesis/halo/sdkreactnativeplugin/HaloSdkImplementation.kt
CHANGED
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
package za.co.synthesis.halo.sdkreactnativeplugin
|
|
2
|
-
|
|
3
|
-
import android.util.Log
|
|
4
|
-
import com.facebook.react.bridge.Promise
|
|
5
|
-
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
-
import za.co.synthesis.halo.haloCommonInterface.HaloException
|
|
7
|
-
import za.co.synthesis.halo.haloCommonInterface.TransactionType
|
|
8
|
-
import za.co.synthesis.halo.sdk.HaloSDK
|
|
9
|
-
import za.co.synthesis.halo.sdk.model.HaloInitializationParameters
|
|
10
|
-
|
|
11
|
-
class HaloSdkImplementation(reactContext: ReactApplicationContext) {
|
|
12
|
-
private val TAG = "HaloSdkImplementation"
|
|
13
|
-
private val ON_START_TRANSACTION_TIME_OUT = 300000L
|
|
14
|
-
private val haloCallbacks: HaloCallbacks = HaloCallbacks(reactContext)
|
|
15
|
-
|
|
16
|
-
fun initializeHaloSDK(promise: Promise, args: HashMap<String, Any>) {
|
|
17
|
-
Log.d(TAG, "initializeHaloSDK: $args")
|
|
18
|
-
try {
|
|
19
|
-
HaloSDK.initialize(
|
|
20
|
-
HaloInitializationParameters(
|
|
21
|
-
haloCallbacks,
|
|
22
|
-
(args[Const.ON_START_TRANSACTION_TIME_OUT] as? Number)?.toLong()
|
|
23
|
-
?: ON_START_TRANSACTION_TIME_OUT,
|
|
24
|
-
args[Const.APPLICATION_PACKAGE_NAME] as String,
|
|
25
|
-
args[Const.APPLICATION_VERSION] as String
|
|
26
|
-
)
|
|
27
|
-
)
|
|
28
|
-
UIContext.enableSchemeAnimations(
|
|
29
|
-
(args[Const.ENABLE_SCHEME_ANIMATIONS] as Boolean?) ?: false
|
|
30
|
-
)
|
|
31
|
-
promise.resolve(null)
|
|
32
|
-
} catch (e: Exception) {
|
|
33
|
-
if (e is HaloException) {
|
|
34
|
-
promise.reject("sdkreactnativeplugin error", e.message, e)
|
|
35
|
-
} else {
|
|
36
|
-
promise.reject("sdkreactnativeplugin error", e.message, e)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
fun startTransaction(
|
|
42
|
-
promise: Promise,
|
|
43
|
-
args: HashMap<String, Any>,
|
|
44
|
-
transactionType: TransactionType = TransactionType.Purchase
|
|
45
|
-
) {
|
|
46
|
-
Log.d(TAG, "startTransaction: $args")
|
|
47
|
-
try {
|
|
48
|
-
val extraFields = getRest<String>(
|
|
49
|
-
args,
|
|
50
|
-
listOf(
|
|
51
|
-
Const.TRANSACTION_AMOUNT,
|
|
52
|
-
Const.MERCHANT_TRANSACTION_REFERENCE,
|
|
53
|
-
Const.TRANSACTION_CURRENCY
|
|
54
|
-
)
|
|
55
|
-
)
|
|
56
|
-
val result = HaloSDK.startTransaction(
|
|
57
|
-
(args[Const.TRANSACTION_AMOUNT] as Double).toBigDecimal(),
|
|
58
|
-
args[Const.MERCHANT_TRANSACTION_REFERENCE] as String,
|
|
59
|
-
args[Const.TRANSACTION_CURRENCY] as String,
|
|
60
|
-
extraFields,
|
|
61
|
-
null,
|
|
62
|
-
transactionType
|
|
63
|
-
)
|
|
64
|
-
promise.resolve(makeWritableMap(result))
|
|
65
|
-
} catch (e: Exception) {
|
|
66
|
-
promise.reject("sdkreactnativeplugin error", e.message, e)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
fun cancelTransaction(promise: Promise) {
|
|
71
|
-
Log.d(TAG, "cancelTransaction")
|
|
72
|
-
HaloSDK.requestTransactionCancellation()
|
|
73
|
-
promise.resolve(null)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
fun jwtCallback(promise: Promise, jwt: String) {
|
|
77
|
-
Log.d(TAG, "jwtCallback")
|
|
78
|
-
haloCallbacks.jwtCallback(jwt)
|
|
79
|
-
promise.resolve(null)
|
|
80
|
-
}
|
|
81
|
-
}
|
|
1
|
+
package za.co.synthesis.halo.sdkreactnativeplugin
|
|
2
|
+
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import com.facebook.react.bridge.Promise
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import za.co.synthesis.halo.haloCommonInterface.HaloException
|
|
7
|
+
import za.co.synthesis.halo.haloCommonInterface.TransactionType
|
|
8
|
+
import za.co.synthesis.halo.sdk.HaloSDK
|
|
9
|
+
import za.co.synthesis.halo.sdk.model.HaloInitializationParameters
|
|
10
|
+
|
|
11
|
+
class HaloSdkImplementation(reactContext: ReactApplicationContext) {
|
|
12
|
+
private val TAG = "HaloSdkImplementation"
|
|
13
|
+
private val ON_START_TRANSACTION_TIME_OUT = 300000L
|
|
14
|
+
private val haloCallbacks: HaloCallbacks = HaloCallbacks(reactContext)
|
|
15
|
+
|
|
16
|
+
fun initializeHaloSDK(promise: Promise, args: HashMap<String, Any>) {
|
|
17
|
+
Log.d(TAG, "initializeHaloSDK: $args")
|
|
18
|
+
try {
|
|
19
|
+
HaloSDK.initialize(
|
|
20
|
+
HaloInitializationParameters(
|
|
21
|
+
haloCallbacks,
|
|
22
|
+
(args[Const.ON_START_TRANSACTION_TIME_OUT] as? Number)?.toLong()
|
|
23
|
+
?: ON_START_TRANSACTION_TIME_OUT,
|
|
24
|
+
args[Const.APPLICATION_PACKAGE_NAME] as String,
|
|
25
|
+
args[Const.APPLICATION_VERSION] as String
|
|
26
|
+
)
|
|
27
|
+
)
|
|
28
|
+
UIContext.enableSchemeAnimations(
|
|
29
|
+
(args[Const.ENABLE_SCHEME_ANIMATIONS] as Boolean?) ?: false
|
|
30
|
+
)
|
|
31
|
+
promise.resolve(null)
|
|
32
|
+
} catch (e: Exception) {
|
|
33
|
+
if (e is HaloException) {
|
|
34
|
+
promise.reject("sdkreactnativeplugin error", e.message, e)
|
|
35
|
+
} else {
|
|
36
|
+
promise.reject("sdkreactnativeplugin error", e.message, e)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
fun startTransaction(
|
|
42
|
+
promise: Promise,
|
|
43
|
+
args: HashMap<String, Any>,
|
|
44
|
+
transactionType: TransactionType = TransactionType.Purchase
|
|
45
|
+
) {
|
|
46
|
+
Log.d(TAG, "startTransaction: $args")
|
|
47
|
+
try {
|
|
48
|
+
val extraFields = getRest<String>(
|
|
49
|
+
args,
|
|
50
|
+
listOf(
|
|
51
|
+
Const.TRANSACTION_AMOUNT,
|
|
52
|
+
Const.MERCHANT_TRANSACTION_REFERENCE,
|
|
53
|
+
Const.TRANSACTION_CURRENCY
|
|
54
|
+
)
|
|
55
|
+
)
|
|
56
|
+
val result = HaloSDK.startTransaction(
|
|
57
|
+
(args[Const.TRANSACTION_AMOUNT] as Double).toBigDecimal(),
|
|
58
|
+
args[Const.MERCHANT_TRANSACTION_REFERENCE] as String,
|
|
59
|
+
args[Const.TRANSACTION_CURRENCY] as String,
|
|
60
|
+
extraFields,
|
|
61
|
+
null,
|
|
62
|
+
transactionType
|
|
63
|
+
)
|
|
64
|
+
promise.resolve(makeWritableMap(result))
|
|
65
|
+
} catch (e: Exception) {
|
|
66
|
+
promise.reject("sdkreactnativeplugin error", e.message, e)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
fun cancelTransaction(promise: Promise) {
|
|
71
|
+
Log.d(TAG, "cancelTransaction")
|
|
72
|
+
HaloSDK.requestTransactionCancellation()
|
|
73
|
+
promise.resolve(null)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
fun jwtCallback(promise: Promise, jwt: String) {
|
|
77
|
+
Log.d(TAG, "jwtCallback")
|
|
78
|
+
haloCallbacks.jwtCallback(jwt)
|
|
79
|
+
promise.resolve(null)
|
|
80
|
+
}
|
|
81
|
+
}
|