payme-mini-app 0.1.1 → 0.1.2
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/android/build.gradle +1 -1
- package/android/src/main/java/com/paymeminiapp/JsonConvert.kt +98 -0
- package/android/src/main/java/com/paymeminiapp/RNPayMEMiniAppModule.kt +125 -20
- package/lib/typescript/index.type.d.ts +1 -0
- package/lib/typescript/index.type.d.ts.map +1 -1
- package/package.json +1 -1
- package/payme-mini-app.podspec +1 -1
- package/src/index.type.ts +1 -0
package/android/build.gradle
CHANGED
|
@@ -74,7 +74,7 @@ dependencies {
|
|
|
74
74
|
//noinspection GradleDynamicVersion
|
|
75
75
|
implementation "com.facebook.react:react-native"
|
|
76
76
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
77
|
-
implementation 'com.github.PayME-Miniapp:native-android:0.0.
|
|
77
|
+
implementation 'com.github.PayME-Miniapp:native-android:0.0.20'
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
if (isNewArchitectureEnabled()) {
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
package com.paymeminiapp
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.*
|
|
4
|
+
import org.json.JSONArray
|
|
5
|
+
import org.json.JSONException
|
|
6
|
+
import org.json.JSONObject
|
|
7
|
+
|
|
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
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return jsonObject
|
|
30
|
+
}
|
|
31
|
+
|
|
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
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return jsonArray
|
|
51
|
+
}
|
|
52
|
+
|
|
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) {
|
|
61
|
+
writableMap.putDouble(key, jsonObject.getDouble(key))
|
|
62
|
+
} else if (value is Number) {
|
|
63
|
+
writableMap.putInt(key, jsonObject.getInt(key))
|
|
64
|
+
} else if (value is String) {
|
|
65
|
+
writableMap.putString(key, jsonObject.getString(key))
|
|
66
|
+
} else if (value is JSONObject) {
|
|
67
|
+
writableMap.putMap(key, jsonToReact(jsonObject.getJSONObject(key)))
|
|
68
|
+
} else if (value is JSONArray) {
|
|
69
|
+
writableMap.putArray(key, jsonToReact(jsonObject.getJSONArray(key)))
|
|
70
|
+
} else if (value === JSONObject.NULL) {
|
|
71
|
+
writableMap.putNull(key)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return writableMap
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@Throws(JSONException::class)
|
|
78
|
+
fun jsonToReact(jsonArray: JSONArray): WritableArray {
|
|
79
|
+
val writableArray: WritableArray = Arguments.createArray()
|
|
80
|
+
for (i in 0 until jsonArray.length()) {
|
|
81
|
+
val value: Any = jsonArray.get(i)
|
|
82
|
+
if (value is Float || value is Double) {
|
|
83
|
+
writableArray.pushDouble(jsonArray.getDouble(i))
|
|
84
|
+
} else if (value is Number) {
|
|
85
|
+
writableArray.pushInt(jsonArray.getInt(i))
|
|
86
|
+
} else if (value is String) {
|
|
87
|
+
writableArray.pushString(jsonArray.getString(i))
|
|
88
|
+
} else if (value is JSONObject) {
|
|
89
|
+
writableArray.pushMap(jsonToReact(jsonArray.getJSONObject(i)))
|
|
90
|
+
} else if (value is JSONArray) {
|
|
91
|
+
writableArray.pushArray(jsonToReact(jsonArray.getJSONArray(i)))
|
|
92
|
+
} else if (value === JSONObject.NULL) {
|
|
93
|
+
writableArray.pushNull()
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return writableArray
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -1,26 +1,131 @@
|
|
|
1
1
|
package com.paymeminiapp
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
|
-
import
|
|
5
|
-
import com.facebook.react.bridge
|
|
6
|
-
import com.facebook.react.
|
|
7
|
-
import com.facebook.react.bridge.Promise
|
|
4
|
+
import android.util.Log
|
|
5
|
+
import com.facebook.react.bridge.*
|
|
6
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
8
7
|
import com.payme.sdk.PayMEMiniApp
|
|
8
|
+
import com.payme.sdk.models.*
|
|
9
|
+
import org.json.JSONObject
|
|
9
10
|
|
|
10
11
|
class RNPayMEMiniAppModule(reactContext: ReactApplicationContext) :
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
ReactContextBaseJavaModule(reactContext) {
|
|
13
|
+
private var payMEMiniApp: PayMEMiniApp? = null
|
|
14
|
+
override fun getName(): String {
|
|
15
|
+
return NAME
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private val eventNames = arrayListOf("onResponse", "onError")
|
|
19
|
+
|
|
20
|
+
@ReactMethod
|
|
21
|
+
fun initPayME(appId: String, publicKey: String, privateKey: String) {
|
|
22
|
+
payMEMiniApp = PayMEMiniApp(
|
|
23
|
+
currentActivity as Context, appId, publicKey, privateKey
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@ReactMethod
|
|
28
|
+
fun open(type: String, openingParam: ReadableMap) {
|
|
29
|
+
val action = openingParam.getString("action") ?: "PAYME"
|
|
30
|
+
val phone = openingParam.getString("phone") ?: ""
|
|
31
|
+
val data = openingParam.getMap("data")
|
|
32
|
+
val amount = data?.getInt("amount")
|
|
33
|
+
val transactionId = data?.getString("transactionId")
|
|
34
|
+
val note = data?.getString("note")
|
|
35
|
+
val ipnUrl = data?.getString("ipnUrl")
|
|
36
|
+
val env = data?.getString("env")
|
|
37
|
+
var paymentData: PaymentData? = null
|
|
38
|
+
if (amount != null && transactionId != null) {
|
|
39
|
+
paymentData = PaymentData(transactionId, amount, note, ipnUrl)
|
|
40
|
+
}
|
|
41
|
+
val openMiniAppData =
|
|
42
|
+
OpenMiniAppData(
|
|
43
|
+
getActionOpenMiniApp(action),
|
|
44
|
+
phone,
|
|
45
|
+
env = ENV.LOCAL,
|
|
46
|
+
paymentData = paymentData
|
|
47
|
+
)
|
|
48
|
+
payMEMiniApp?.openMiniApp(
|
|
49
|
+
getTypeOpenMiniApp(type),
|
|
50
|
+
openMiniAppData,
|
|
51
|
+
onSuccess = { actionOpenMiniApp: ActionOpenMiniApp, jsonObject: JSONObject? ->
|
|
52
|
+
if (jsonObject != null) {
|
|
53
|
+
try {
|
|
54
|
+
val payload = JsonConvert.jsonToReact(jsonObject)
|
|
55
|
+
payload.putString("action", actionOpenMiniApp.toString())
|
|
56
|
+
sendEvent(
|
|
57
|
+
reactApplicationContext,
|
|
58
|
+
"onResponse", payload
|
|
59
|
+
)
|
|
60
|
+
} catch (e: Exception) {
|
|
61
|
+
Log.d("PAYME", "exception $e")
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
onError = { actionOpenMiniApp: ActionOpenMiniApp, payMEError: PayMEError ->
|
|
66
|
+
val payload = Arguments.createMap()
|
|
67
|
+
payload.putString("action", actionOpenMiniApp.toString())
|
|
68
|
+
payload.putString("code", payMEError.code)
|
|
69
|
+
payload.putString("description", payMEError.message)
|
|
70
|
+
sendEvent(
|
|
71
|
+
reactApplicationContext,
|
|
72
|
+
"onError", payload
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private var listenerCount = 0
|
|
79
|
+
|
|
80
|
+
@ReactMethod
|
|
81
|
+
fun addListener(eventName: String) {
|
|
82
|
+
if (listenerCount == 0) {
|
|
83
|
+
// Set up any upstream listeners or background tasks as necessary
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
listenerCount += 1
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@ReactMethod
|
|
90
|
+
fun removeListeners(count: Int) {
|
|
91
|
+
listenerCount -= count
|
|
92
|
+
if (listenerCount == 0) {
|
|
93
|
+
// Remove upstream listeners, stop unnecessary background tasks
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private fun getTypeOpenMiniApp(type: String): OpenMiniAppType {
|
|
98
|
+
if (type.lowercase() == OpenMiniAppType.modal.toString()) {
|
|
99
|
+
return OpenMiniAppType.modal
|
|
100
|
+
}
|
|
101
|
+
if (type.lowercase() == OpenMiniAppType.screen.toString()) {
|
|
102
|
+
return OpenMiniAppType.screen
|
|
103
|
+
}
|
|
104
|
+
return OpenMiniAppType.screen
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private fun getActionOpenMiniApp(action: String): ActionOpenMiniApp {
|
|
108
|
+
if (action == ActionOpenMiniApp.PAYME.toString()) {
|
|
109
|
+
return ActionOpenMiniApp.PAYME
|
|
110
|
+
}
|
|
111
|
+
if (action == ActionOpenMiniApp.OPEN.toString()) {
|
|
112
|
+
return ActionOpenMiniApp.OPEN
|
|
113
|
+
}
|
|
114
|
+
if (action == ActionOpenMiniApp.PAY.toString()) {
|
|
115
|
+
return ActionOpenMiniApp.PAY
|
|
116
|
+
}
|
|
117
|
+
return ActionOpenMiniApp.PAYME
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private fun sendEvent(reactContext: ReactContext, eventName: String, params: WritableMap?) {
|
|
121
|
+
if (eventNames.contains(eventName)) {
|
|
122
|
+
reactContext
|
|
123
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
124
|
+
.emit(eventName, params)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
companion object {
|
|
129
|
+
const val NAME = "RNPayMEMiniApp"
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.type.d.ts","sourceRoot":"","sources":["../../src/index.type.ts"],"names":[],"mappings":"AAAA,KAAK,iBAAiB,GAAG;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.type.d.ts","sourceRoot":"","sources":["../../src/index.type.ts"],"names":[],"mappings":"AAAA,KAAK,iBAAiB,GAAG;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GACzB;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,MAAM,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,iBAAiB,CAAA;CAAE,CAAC"}
|
package/package.json
CHANGED
package/payme-mini-app.podspec
CHANGED
|
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
|
|
|
16
16
|
s.swift_versions = "5.0"
|
|
17
17
|
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
18
18
|
|
|
19
|
-
s.dependency "PayMEMiniApp", "
|
|
19
|
+
s.dependency "PayMEMiniApp", "0.0.1"
|
|
20
20
|
s.dependency "React-Core"
|
|
21
21
|
s.pod_target_xcconfig = { 'BUILD_LIBRARY_FOR_DISTRIBUTION' => 'YES' }
|
|
22
22
|
# Don't install the dependencies when we run `pod install` in the old architecture.
|