payme-mini-app 1.0.2 → 1.1.0-beta.3

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 (39) hide show
  1. package/LICENSE +1 -1
  2. package/android/build.gradle +9 -21
  3. package/android/gradle.properties +5 -5
  4. package/android/src/main/AndroidManifest.xml +0 -1
  5. package/android/src/main/java/com/paymeminiapp/JsonConvert.kt +87 -85
  6. package/android/src/main/java/com/paymeminiapp/PaymeMiniAppModule.kt +394 -0
  7. package/android/src/main/java/com/paymeminiapp/{RNPayMEMiniAppPackage.kt → PaymeMiniAppPackage.kt} +2 -2
  8. package/ios/{RNPayMEMiniApp.m → PaymeMiniApp.mm} +1 -3
  9. package/ios/{RNPayMEMiniApp.swift → PaymeMiniApp.swift} +2 -2
  10. package/lib/commonjs/index.js +5 -7
  11. package/lib/commonjs/index.js.map +1 -1
  12. package/lib/commonjs/index.type.js.map +1 -1
  13. package/lib/module/index.js +7 -6
  14. package/lib/module/index.js.map +1 -1
  15. package/lib/module/index.type.js +1 -1
  16. package/lib/module/index.type.js.map +1 -1
  17. package/lib/typescript/commonjs/package.json +1 -0
  18. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  19. package/lib/typescript/{index.type.d.ts → commonjs/src/index.type.d.ts} +5 -5
  20. package/lib/typescript/commonjs/src/index.type.d.ts.map +1 -0
  21. package/lib/typescript/module/package.json +1 -0
  22. package/lib/typescript/module/src/index.d.ts +10 -0
  23. package/lib/typescript/module/src/index.d.ts.map +1 -0
  24. package/lib/typescript/module/src/index.type.d.ts +80 -0
  25. package/lib/typescript/module/src/index.type.d.ts.map +1 -0
  26. package/package.json +51 -23
  27. package/payme-mini-app.podspec +1 -2
  28. package/src/index.tsx +3 -2
  29. package/src/index.type.ts +5 -5
  30. package/android/src/main/java/com/paymeminiapp/RNPayMEMiniAppModule.kt +0 -333
  31. package/ios/RNPayMEMiniApp.xcodeproj/project.pbxproj +0 -283
  32. package/ios/RNPayMEMiniApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -4
  33. package/ios/RNPayMEMiniApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  34. package/ios/RNPayMEMiniApp.xcodeproj/project.xcworkspace/xcuserdata/montossc.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  35. package/ios/RNPayMEMiniApp.xcodeproj/xcuserdata/montossc.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
  36. package/lib/typescript/index.d.ts.map +0 -1
  37. package/lib/typescript/index.type.d.ts.map +0 -1
  38. /package/ios/{RNPayMEMiniApp-Bridging-Header.h → PaymeMiniApp-Bridging-Header.h} +0 -0
  39. /package/lib/typescript/{index.d.ts → commonjs/src/index.d.ts} +0 -0
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 Phan Thanh Nam
3
+ Copyright (c) 2024 Trần Minh Đạt
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
6
6
  in the Software without restriction, including without limitation the rights
@@ -1,6 +1,7 @@
1
1
  buildscript {
2
- // Buildscript is evaluated before everything else so we can't use getExtOrDefault
3
- def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["RNPayMEMiniApp_kotlinVersion"]
2
+ ext.getExtOrDefault = {name ->
3
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['PaymeMiniApp_' + name]
4
+ }
4
5
 
5
6
  repositories {
6
7
  google()
@@ -8,17 +9,11 @@ buildscript {
8
9
  }
9
10
 
10
11
  dependencies {
11
- classpath "com.android.tools.build:gradle:7.2.1"
12
- // noinspection DifferentKotlinGradleVersion
13
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
12
+ classpath "com.android.tools.build:gradle:8.7.2"
13
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
14
14
  }
15
15
  }
16
16
 
17
- def reactNativeArchitectures() {
18
- def value = rootProject.getProperties().get("reactNativeArchitectures")
19
- return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
20
- }
21
-
22
17
  def isNewArchitectureEnabled() {
23
18
  return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
24
19
  }
@@ -30,12 +25,8 @@ if (isNewArchitectureEnabled()) {
30
25
  apply plugin: "com.facebook.react"
31
26
  }
32
27
 
33
- def getExtOrDefault(name) {
34
- return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["RNPayMEMiniApp_" + name]
35
- }
36
-
37
28
  def getExtOrIntegerDefault(name) {
38
- return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["RNPayMEMiniApp_" + name]).toInteger()
29
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["PaymeMiniApp_" + name]).toInteger()
39
30
  }
40
31
 
41
32
  def supportsNamespace() {
@@ -63,6 +54,7 @@ android {
63
54
  defaultConfig {
64
55
  minSdkVersion getExtOrIntegerDefault("minSdkVersion")
65
56
  targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
57
+
66
58
  }
67
59
 
68
60
  buildTypes {
@@ -84,17 +76,13 @@ android {
84
76
  repositories {
85
77
  mavenCentral()
86
78
  google()
87
- maven { url 'https://jitpack.io' }
88
79
  }
89
80
 
90
81
  def kotlin_version = getExtOrDefault("kotlinVersion")
91
82
 
92
83
  dependencies {
93
- // For < 0.71, this will be from the local maven repo
94
- // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
95
- //noinspection GradleDynamicVersion
96
- implementation "com.facebook.react:react-native:+"
84
+ implementation "com.facebook.react:react-android"
97
85
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
98
- implementation 'com.github.PayME-Miniapp:native-android:0.4.0'
86
+ implementation 'com.github.PayME-Miniapp:native-android:0.5.0-alpha.3'
99
87
  }
100
88
 
@@ -1,5 +1,5 @@
1
- RNPayMEMiniApp_kotlinVersion=1.7.0
2
- RNPayMEMiniApp_minSdkVersion=21
3
- RNPayMEMiniApp_targetSdkVersion=31
4
- RNPayMEMiniApp_compileSdkVersion=31
5
- RNPayMEMiniApp_ndkversion=21.4.7075529
1
+ PaymeMiniApp_kotlinVersion=2.0.21
2
+ PaymeMiniApp_minSdkVersion=24
3
+ PaymeMiniApp_targetSdkVersion=34
4
+ PaymeMiniApp_compileSdkVersion=35
5
+ PaymeMiniApp_ndkversion=27.1.12297006
@@ -1,4 +1,3 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
2
  package="com.paymeminiapp">
3
-
4
3
  </manifest>
@@ -6,97 +6,99 @@ import org.json.JSONException
6
6
  import org.json.JSONObject
7
7
 
8
8
  object JsonConvert {
9
- @Throws(JSONException::class)
10
- fun reactToJSON(readableMap: ReadableMap?): JSONObject {
11
- val jsonObject = JSONObject()
12
- val iterator = readableMap!!.keySetIterator()
13
- while (iterator.hasNextKey()) {
14
- val key = iterator.nextKey()
15
- val valueType = readableMap.getType(key)
16
- when (valueType) {
17
- ReadableType.Null -> jsonObject.put(key, JSONObject.NULL)
18
- ReadableType.Boolean -> jsonObject.put(key, readableMap.getBoolean(key))
19
- ReadableType.Number -> try {
20
- jsonObject.put(key, readableMap.getInt(key))
21
- } catch (e: Exception) {
22
- jsonObject.put(key, readableMap.getDouble(key))
23
- }
24
- ReadableType.String -> jsonObject.put(key, readableMap.getString(key))
25
- ReadableType.Map -> jsonObject.put(key, reactToJSON(readableMap.getMap(key)))
26
- ReadableType.Array -> jsonObject.put(key, reactToJSON(readableMap.getArray(key)))
27
- }
9
+ @Throws(JSONException::class)
10
+ fun reactToJSON(readableMap: ReadableMap?): JSONObject {
11
+ val jsonObject = JSONObject()
12
+ val iterator = readableMap!!.keySetIterator()
13
+ while (iterator.hasNextKey()) {
14
+ val key = iterator.nextKey()
15
+ val valueType = readableMap.getType(key)
16
+ when (valueType) {
17
+ ReadableType.Null -> jsonObject.put(key, JSONObject.NULL)
18
+ ReadableType.Boolean -> jsonObject.put(key, readableMap.getBoolean(key))
19
+ ReadableType.Number -> try {
20
+ jsonObject.put(key, readableMap.getInt(key))
21
+ } catch (e: Exception) {
22
+ jsonObject.put(key, readableMap.getDouble(key))
28
23
  }
29
- return jsonObject
24
+
25
+ ReadableType.String -> jsonObject.put(key, readableMap.getString(key))
26
+ ReadableType.Map -> jsonObject.put(key, reactToJSON(readableMap.getMap(key)))
27
+ ReadableType.Array -> jsonObject.put(key, reactToJSON(readableMap.getArray(key)))
28
+ }
30
29
  }
30
+ return jsonObject
31
+ }
31
32
 
32
- @Throws(JSONException::class)
33
- fun reactToJSON(readableArray: ReadableArray?): JSONArray {
34
- val jsonArray = JSONArray()
35
- for (i in 0 until readableArray!!.size()) {
36
- val valueType = readableArray.getType(i)
37
- when (valueType) {
38
- ReadableType.Null -> jsonArray.put(JSONObject.NULL)
39
- ReadableType.Boolean -> jsonArray.put(readableArray.getBoolean(i))
40
- ReadableType.Number -> try {
41
- jsonArray.put(readableArray.getInt(i))
42
- } catch (e: Exception) {
43
- jsonArray.put(readableArray.getDouble(i))
44
- }
45
- ReadableType.String -> jsonArray.put(readableArray.getString(i))
46
- ReadableType.Map -> jsonArray.put(reactToJSON(readableArray.getMap(i)))
47
- ReadableType.Array -> jsonArray.put(reactToJSON(readableArray.getArray(i)))
48
- }
33
+ @Throws(JSONException::class)
34
+ fun reactToJSON(readableArray: ReadableArray?): JSONArray {
35
+ val jsonArray = JSONArray()
36
+ for (i in 0 until readableArray!!.size()) {
37
+ val valueType = readableArray.getType(i)
38
+ when (valueType) {
39
+ ReadableType.Null -> jsonArray.put(JSONObject.NULL)
40
+ ReadableType.Boolean -> jsonArray.put(readableArray.getBoolean(i))
41
+ ReadableType.Number -> try {
42
+ jsonArray.put(readableArray.getInt(i))
43
+ } catch (e: Exception) {
44
+ jsonArray.put(readableArray.getDouble(i))
49
45
  }
50
- return jsonArray
46
+
47
+ ReadableType.String -> jsonArray.put(readableArray.getString(i))
48
+ ReadableType.Map -> jsonArray.put(reactToJSON(readableArray.getMap(i)))
49
+ ReadableType.Array -> jsonArray.put(reactToJSON(readableArray.getArray(i)))
50
+ }
51
51
  }
52
+ return jsonArray
53
+ }
52
54
 
53
- @Throws(JSONException::class)
54
- fun jsonToReact(jsonObject: JSONObject): WritableMap {
55
- val writableMap: WritableMap = Arguments.createMap()
56
- val iterator: Iterator<*> = jsonObject.keys()
57
- while (iterator.hasNext()) {
58
- val key = iterator.next() as String
59
- val value: Any = jsonObject.get(key)
60
- if (value is Float || value is Double || value is Number) {
61
- writableMap.putDouble(key, jsonObject.getDouble(key))
62
- } else if (value is Int) {
63
- writableMap.putInt(key, jsonObject.getInt(key))
64
- } else if (value is Boolean) {
65
- writableMap.putBoolean(key, jsonObject.getBoolean(key))
66
- } else if (value is String) {
67
- writableMap.putString(key, jsonObject.getString(key))
68
- } else if (value is JSONObject) {
69
- writableMap.putMap(key, jsonToReact(jsonObject.getJSONObject(key)))
70
- } else if (value is JSONArray) {
71
- writableMap.putArray(key, jsonToReact(jsonObject.getJSONArray(key)))
72
- } else if (value === JSONObject.NULL) {
73
- writableMap.putNull(key)
74
- }
75
- }
76
- return writableMap
55
+ @Throws(JSONException::class)
56
+ fun jsonToReact(jsonObject: JSONObject): WritableMap {
57
+ val writableMap: WritableMap = Arguments.createMap()
58
+ val iterator: Iterator<*> = jsonObject.keys()
59
+ while (iterator.hasNext()) {
60
+ val key = iterator.next() as String
61
+ val value: Any = jsonObject.get(key)
62
+ if (value is Int) {
63
+ writableMap.putInt(key, jsonObject.getInt(key))
64
+ } else if (value is Float || value is Double || value is Number) {
65
+ writableMap.putDouble(key, jsonObject.getDouble(key))
66
+ } else if (value is Boolean) {
67
+ writableMap.putBoolean(key, jsonObject.getBoolean(key))
68
+ } else if (value is String) {
69
+ writableMap.putString(key, jsonObject.getString(key))
70
+ } else if (value is JSONObject) {
71
+ writableMap.putMap(key, jsonToReact(jsonObject.getJSONObject(key)))
72
+ } else if (value is JSONArray) {
73
+ writableMap.putArray(key, jsonToReact(jsonObject.getJSONArray(key)))
74
+ } else if (value === JSONObject.NULL) {
75
+ writableMap.putNull(key)
76
+ }
77
77
  }
78
+ return writableMap
79
+ }
78
80
 
79
- @Throws(JSONException::class)
80
- fun jsonToReact(jsonArray: JSONArray): WritableArray {
81
- val writableArray: WritableArray = Arguments.createArray()
82
- for (i in 0 until jsonArray.length()) {
83
- val value: Any = jsonArray.get(i)
84
- if (value is Float || value is Double || value is Number) {
85
- writableArray.pushDouble(jsonArray.getDouble(i))
86
- } else if (value is Int) {
87
- writableArray.pushInt(jsonArray.getInt(i))
88
- } else if (value is Boolean) {
89
- writableArray.pushBoolean(jsonArray.getBoolean(i))
90
- } else if (value is String) {
91
- writableArray.pushString(jsonArray.getString(i))
92
- } else if (value is JSONObject) {
93
- writableArray.pushMap(jsonToReact(jsonArray.getJSONObject(i)))
94
- } else if (value is JSONArray) {
95
- writableArray.pushArray(jsonToReact(jsonArray.getJSONArray(i)))
96
- } else if (value === JSONObject.NULL) {
97
- writableArray.pushNull()
98
- }
99
- }
100
- return writableArray
81
+ @Throws(JSONException::class)
82
+ fun jsonToReact(jsonArray: JSONArray): WritableArray {
83
+ val writableArray: WritableArray = Arguments.createArray()
84
+ for (i in 0 until jsonArray.length()) {
85
+ val value: Any = jsonArray.get(i)
86
+ if (value is Int) {
87
+ writableArray.pushInt(jsonArray.getInt(i))
88
+ } else if (value is Float || value is Double || value is Number) {
89
+ writableArray.pushDouble(jsonArray.getDouble(i))
90
+ } else if (value is Boolean) {
91
+ writableArray.pushBoolean(jsonArray.getBoolean(i))
92
+ } else if (value is String) {
93
+ writableArray.pushString(jsonArray.getString(i))
94
+ } else if (value is JSONObject) {
95
+ writableArray.pushMap(jsonToReact(jsonArray.getJSONObject(i)))
96
+ } else if (value is JSONArray) {
97
+ writableArray.pushArray(jsonToReact(jsonArray.getJSONArray(i)))
98
+ } else if (value === JSONObject.NULL) {
99
+ writableArray.pushNull()
100
+ }
101
101
  }
102
- }
102
+ return writableArray
103
+ }
104
+ }
@@ -0,0 +1,394 @@
1
+ package com.paymeminiapp
2
+
3
+ import android.app.Activity
4
+ import android.util.Log
5
+ import com.facebook.react.bridge.Arguments
6
+ import com.facebook.react.bridge.ReactApplicationContext
7
+ import com.facebook.react.bridge.ReactContext
8
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
9
+ import com.facebook.react.bridge.ReactMethod
10
+ import com.facebook.react.bridge.ReadableMap
11
+ import com.facebook.react.bridge.WritableMap
12
+ import com.facebook.react.modules.core.DeviceEventManagerModule
13
+ import com.payme.sdk.PayMEMiniApp
14
+ import com.payme.sdk.models.ActionOpenMiniApp
15
+ import com.payme.sdk.models.DepositWithdrawTransferData
16
+ import com.payme.sdk.models.ENV
17
+ import com.payme.sdk.models.Locale
18
+ import com.payme.sdk.models.OpenMiniAppDataInterface
19
+ import com.payme.sdk.models.OpenMiniAppDepositData
20
+ import com.payme.sdk.models.OpenMiniAppKYCData
21
+ import com.payme.sdk.models.OpenMiniAppOpenData
22
+ import com.payme.sdk.models.OpenMiniAppPayMEData
23
+ import com.payme.sdk.models.OpenMiniAppPaymentData
24
+ import com.payme.sdk.models.OpenMiniAppPaymentDirectData
25
+ import com.payme.sdk.models.OpenMiniAppServiceData
26
+ import com.payme.sdk.models.OpenMiniAppTransferData
27
+ import com.payme.sdk.models.OpenMiniAppTransferQRData
28
+ import com.payme.sdk.models.OpenMiniAppType
29
+ import com.payme.sdk.models.OpenMiniAppWithdrawData
30
+ import com.payme.sdk.models.PayMEError
31
+ import com.payme.sdk.models.PaymentData
32
+ import com.payme.sdk.models.PaymentDirectData
33
+ import com.payme.sdk.models.ServiceData
34
+ import com.payme.sdk.models.TransferQRData
35
+ import org.json.JSONObject
36
+
37
+
38
+ class PaymeMiniAppModule(reactContext: ReactApplicationContext) :
39
+ ReactContextBaseJavaModule(reactContext) {
40
+ private var payMEMiniApp: PayMEMiniApp? = null
41
+ override fun getName(): String {
42
+ return NAME
43
+ }
44
+
45
+ private val eventNames = arrayListOf("onResponse", "onError")
46
+
47
+ private var listenerCount = 0
48
+
49
+ @ReactMethod
50
+ fun addListener() {
51
+ if (listenerCount == 0) {
52
+ // Set up any upstream listeners or background tasks as necessary
53
+ }
54
+
55
+ listenerCount += 1
56
+ }
57
+
58
+ @ReactMethod
59
+ fun removeListeners(count: Int) {
60
+ listenerCount -= count
61
+ if (listenerCount == 0) {
62
+ // Remove upstream listeners, stop unnecessary background tasks
63
+ }
64
+ }
65
+
66
+ @ReactMethod
67
+ fun initPayME(
68
+ appId: String,
69
+ publicKey: String,
70
+ privateKey: String,
71
+ locale: String,
72
+ env: String,
73
+ mode: String
74
+ ) {
75
+ val fragmentActivity: Activity? = currentActivity
76
+
77
+ payMEMiniApp = fragmentActivity?.let {
78
+ PayMEMiniApp(
79
+ it, appId, publicKey, privateKey, getEnv(env), getLocale(locale)
80
+ )
81
+ }
82
+ // payMEMiniApp?.setLanguage(locale)
83
+ payMEMiniApp?.setMode(mode)
84
+ payMEMiniApp?.setUpListener(onResponse = { actionOpenMiniApp: ActionOpenMiniApp, jsonObject: JSONObject? ->
85
+ onResponse(actionOpenMiniApp, jsonObject)
86
+ },
87
+ onError = { actionOpenMiniApp: ActionOpenMiniApp, payMEError: PayMEError ->
88
+ onError(actionOpenMiniApp, payMEError)
89
+ })
90
+ }
91
+
92
+ @ReactMethod
93
+ fun getBalance(phone: String) {
94
+ payMEMiniApp?.getBalance(phone)
95
+ }
96
+
97
+ @ReactMethod
98
+ fun getAccountInfo(phone: String) {
99
+ payMEMiniApp?.getAccountInformation(phone)
100
+ }
101
+
102
+ @ReactMethod
103
+ fun setLanguage(language: String) {
104
+ val locale = getLocale(language)
105
+ payMEMiniApp?.setLanguage(locale)
106
+ }
107
+
108
+ @ReactMethod
109
+ fun closeMiniApp() {
110
+ payMEMiniApp?.close()
111
+ }
112
+
113
+ @ReactMethod
114
+ fun open(type: String, openingParam: ReadableMap) {
115
+ val action = openingParam.getString("action") ?: "PAYME"
116
+ val phone = openingParam.getString("phone") ?: ""
117
+ val data = openingParam.getMap("data")
118
+
119
+ if (action == "DEPOSIT" || action == "WITHDRAW" || action == "TRANSFER") {
120
+ val description =
121
+ if (data?.hasKey("description") == true) data.getString("description") else ""
122
+ val extraData =
123
+ if (data?.hasKey("extraData") == true) data.getMap("extraData")?.toHashMap()
124
+ ?.filterValues { it != null }?.mapValues { it.value!! } else null
125
+ val isBackToApp =
126
+ if (data?.hasKey("isBackToApp") == true) data.getBoolean("isBackToApp") else true
127
+ val isShowResult =
128
+ if (data?.hasKey("isShowResult") == true) data.getBoolean("isShowResult") else true
129
+ val amount = if (data?.hasKey("amount") == true) data.getInt("amount") else null
130
+ val additionalData =
131
+ DepositWithdrawTransferData(description, amount, extraData, isBackToApp, isShowResult)
132
+ val openMiniAppData = getOpenMiniAppData(action, phone, additionalData)
133
+ payMEMiniApp?.openMiniApp(
134
+ getTypeOpenMiniApp(type),
135
+ openMiniAppData
136
+ )
137
+ return
138
+ }
139
+ if (action == "SERVICE") {
140
+ val service = data?.getString("service") ?: ""
141
+ val extraData =
142
+ if (data?.hasKey("extraData") == true) data.getMap("extraData")?.toHashMap()
143
+ ?.filterValues { it != null }?.mapValues { it.value!! } else null
144
+ val isBackToApp =
145
+ if (data?.hasKey("isBackToApp") == true) data.getBoolean("isBackToApp") else true
146
+ val isShowResult =
147
+ if (data?.hasKey("isShowResult") == true) data.getBoolean("isShowResult") else true
148
+ val additionalData = ServiceData(service, extraData, isBackToApp, isShowResult)
149
+ val openMiniAppData = getOpenMiniAppData(action, phone, additionalData)
150
+ payMEMiniApp?.openMiniApp(
151
+ getTypeOpenMiniApp(type),
152
+ openMiniAppData
153
+ )
154
+ return
155
+ }
156
+ if (action == "PAY") {
157
+ val transactionId = data?.getString("transactionId")
158
+ val amount = data?.getInt("amount")
159
+ val note = if (data?.hasKey("note") == true) data.getString("note") else ""
160
+ val ipnUrl = if (data?.hasKey("ipnUrl") == true) data.getString("ipnUrl") else ""
161
+ val extraData =
162
+ if (data?.hasKey("extraData") == true) data.getMap("extraData")?.toHashMap()
163
+ ?.filterValues { it != null }?.mapValues { it.value!! } else null
164
+ val isShowResult =
165
+ if (data?.hasKey("isShowResult") == true) data.getBoolean("isShowResult") else true
166
+ var paymentData: PaymentData? = null
167
+ if (amount != null && transactionId != null) {
168
+ paymentData = PaymentData(transactionId, amount, note, ipnUrl, extraData, isShowResult)
169
+ }
170
+ val openMiniAppData = getOpenMiniAppData(action, phone, paymentData)
171
+ payMEMiniApp?.openMiniApp(
172
+ getTypeOpenMiniApp(type),
173
+ openMiniAppData
174
+ )
175
+ return
176
+ }
177
+ if (action == "PAYMENT") {
178
+ val transaction = data?.getString("transaction")
179
+ val extraData =
180
+ if (data?.hasKey("extraData") == true) data.getMap("extraData")?.toHashMap()
181
+ ?.filterValues { it != null }?.mapValues { it.value!! } else null
182
+ val isShowResult =
183
+ if (data?.hasKey("isShowResult") == true) data.getBoolean("isShowResult") else true
184
+ var paymentData: PaymentDirectData? = null
185
+ if (transaction != null) {
186
+ paymentData = PaymentDirectData(transaction, extraData, isShowResult)
187
+ }
188
+ val openMiniAppData = getOpenMiniAppData(action, phone, paymentData)
189
+ payMEMiniApp?.openMiniApp(
190
+ getTypeOpenMiniApp(type),
191
+ openMiniAppData
192
+ )
193
+ return
194
+ }
195
+ if (action == "TRANSFER_QR") {
196
+ val amount = data?.getInt("amount")
197
+ val bankNumber = data?.getString("bankNumber")
198
+ val swiftCode = data?.getString("swiftCode")
199
+ val cardHolder = data?.getString("cardHolder")
200
+ val extraData =
201
+ if (data?.hasKey("extraData") == true) data.getMap("extraData")?.toHashMap()
202
+ ?.filterValues { it != null }?.mapValues { it.value!! } else null
203
+ val partnerTransaction =
204
+ if (data?.hasKey("partnerTransaction") == true) data.getString("partnerTransaction") else ""
205
+ val note = if (data?.hasKey("note") == true) data.getString("note") else ""
206
+ val isShowResult =
207
+ if (data?.hasKey("isShowResult") == true) data.getBoolean("isShowResult") else true
208
+ var transferQRData: TransferQRData? = null
209
+ if (amount != null && bankNumber != null && swiftCode != null && cardHolder != null) {
210
+ transferQRData = TransferQRData(
211
+ amount,
212
+ bankNumber,
213
+ swiftCode,
214
+ cardHolder,
215
+ note,
216
+ partnerTransaction,
217
+ extraData,
218
+ isShowResult
219
+ )
220
+ }
221
+ val openMiniAppData = getOpenMiniAppData(action, phone, transferQRData)
222
+ payMEMiniApp?.openMiniApp(
223
+ getTypeOpenMiniApp(type),
224
+ openMiniAppData
225
+ )
226
+ return
227
+ }
228
+ if (action == "OPEN" || action == "KYC" || action == "PAYME") {
229
+ val openMiniAppData = getOpenMiniAppData(action, phone)
230
+ payMEMiniApp?.openMiniApp(
231
+ getTypeOpenMiniApp(type),
232
+ openMiniAppData
233
+ )
234
+ return
235
+ }
236
+ }
237
+
238
+ private fun onResponse(actionOpenMiniApp: ActionOpenMiniApp, jsonObject: JSONObject?) {
239
+ if (jsonObject != null) {
240
+ try {
241
+ Log.d("PAYMELOG", "jsonObject $jsonObject")
242
+ val payload = JsonConvert.jsonToReact(jsonObject)
243
+ if (!payload.hasKey("action")) {
244
+ payload.putString("action", actionOpenMiniApp.toString())
245
+ }
246
+ sendEvent(
247
+ reactApplicationContext,
248
+ "onResponse", payload
249
+ )
250
+ } catch (e: Exception) {
251
+ Log.d("PAYMELOG", "exception $e")
252
+ }
253
+ }
254
+ }
255
+
256
+ private fun onError(actionOpenMiniApp: ActionOpenMiniApp, payMEError: PayMEError) {
257
+ val payload = Arguments.createMap()
258
+ payload.putString("action", actionOpenMiniApp.toString())
259
+ payload.putString("code", payMEError.code)
260
+ payload.putString("description", payMEError.description)
261
+ sendEvent(
262
+ reactApplicationContext,
263
+ "onError", payload
264
+ )
265
+ }
266
+
267
+ private fun getEnv(env: String): ENV {
268
+ if (env == ENV.SANDBOX.toString()) {
269
+ return ENV.SANDBOX
270
+ }
271
+ if (env == ENV.PRODUCTION.toString()) {
272
+ return ENV.PRODUCTION
273
+ }
274
+ return ENV.PRODUCTION
275
+ }
276
+
277
+ private fun getLocale(locale: String): Locale {
278
+ if (locale == Locale.en.toString()) {
279
+ return Locale.en
280
+ }
281
+ if (locale == Locale.vi.toString()) {
282
+ return Locale.vi
283
+ }
284
+ return Locale.vi
285
+ }
286
+
287
+ private fun getTypeOpenMiniApp(type: String): OpenMiniAppType {
288
+ if (type.lowercase() == OpenMiniAppType.modal.toString()) {
289
+ return OpenMiniAppType.modal
290
+ }
291
+ if (type.lowercase() == OpenMiniAppType.screen.toString()) {
292
+ return OpenMiniAppType.screen
293
+ }
294
+ return OpenMiniAppType.screen
295
+ // return OpenMiniAppType.screen
296
+ }
297
+
298
+ private fun getActionOpenMiniApp(action: String): ActionOpenMiniApp {
299
+ return try {
300
+ ActionOpenMiniApp.valueOf(action.uppercase())
301
+ } catch (e: Exception) {
302
+ ActionOpenMiniApp.PAYME
303
+ }
304
+ }
305
+
306
+ private fun getOpenMiniAppData(
307
+ action: String,
308
+ phone: String,
309
+ ): OpenMiniAppDataInterface {
310
+ if (getActionOpenMiniApp(action) == ActionOpenMiniApp.OPEN) {
311
+ return OpenMiniAppOpenData(phone)
312
+ }
313
+ if (getActionOpenMiniApp(action) == ActionOpenMiniApp.PAYME) {
314
+ return OpenMiniAppPayMEData()
315
+ }
316
+ if (getActionOpenMiniApp(action) == ActionOpenMiniApp.KYC) {
317
+ return OpenMiniAppKYCData(phone)
318
+ }
319
+ return OpenMiniAppPayMEData()
320
+ }
321
+
322
+ private fun getOpenMiniAppData(
323
+ action: String,
324
+ phone: String,
325
+ additionalData: DepositWithdrawTransferData? = null
326
+ ): OpenMiniAppDataInterface {
327
+ if (getActionOpenMiniApp(action) == ActionOpenMiniApp.DEPOSIT && additionalData != null) {
328
+ return OpenMiniAppDepositData(phone, additionalData)
329
+ }
330
+ if (getActionOpenMiniApp(action) == ActionOpenMiniApp.WITHDRAW && additionalData != null) {
331
+ return OpenMiniAppWithdrawData(phone, additionalData)
332
+ }
333
+ if (getActionOpenMiniApp(action) == ActionOpenMiniApp.TRANSFER && additionalData != null) {
334
+ return OpenMiniAppTransferData(phone, additionalData)
335
+ }
336
+ return OpenMiniAppPayMEData()
337
+ }
338
+
339
+ private fun getOpenMiniAppData(
340
+ action: String,
341
+ phone: String,
342
+ paymentData: PaymentData? = null,
343
+ ): OpenMiniAppDataInterface {
344
+ if (getActionOpenMiniApp(action) == ActionOpenMiniApp.PAY && paymentData != null) {
345
+ return OpenMiniAppPaymentData(phone, paymentData)
346
+ }
347
+ return OpenMiniAppPayMEData()
348
+ }
349
+
350
+ private fun getOpenMiniAppData(
351
+ action: String,
352
+ phone: String,
353
+ paymentData: PaymentDirectData? = null,
354
+ ): OpenMiniAppDataInterface {
355
+ if (getActionOpenMiniApp(action) == ActionOpenMiniApp.PAYMENT && paymentData != null) {
356
+ return OpenMiniAppPaymentDirectData(phone, paymentData)
357
+ }
358
+ return OpenMiniAppPayMEData()
359
+ }
360
+
361
+ private fun getOpenMiniAppData(
362
+ action: String,
363
+ phone: String,
364
+ transferQRData: TransferQRData? = null,
365
+ ): OpenMiniAppDataInterface {
366
+ if (getActionOpenMiniApp(action) == ActionOpenMiniApp.TRANSFER_QR && transferQRData != null) {
367
+ return OpenMiniAppTransferQRData(phone, transferQRData)
368
+ }
369
+ return OpenMiniAppPayMEData()
370
+ }
371
+
372
+ private fun getOpenMiniAppData(
373
+ action: String,
374
+ phone: String,
375
+ additionalData: ServiceData? = null
376
+ ): OpenMiniAppDataInterface {
377
+ if (getActionOpenMiniApp(action) == ActionOpenMiniApp.SERVICE && additionalData != null) {
378
+ return OpenMiniAppServiceData(phone, additionalData)
379
+ }
380
+ return OpenMiniAppPayMEData()
381
+ }
382
+
383
+ private fun sendEvent(reactContext: ReactContext, eventName: String, params: WritableMap?) {
384
+ if (eventNames.contains(eventName)) {
385
+ reactContext
386
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
387
+ .emit(eventName, params)
388
+ }
389
+ }
390
+
391
+ companion object {
392
+ const val NAME = "PaymeMiniApp"
393
+ }
394
+ }