payme-mini-app 0.2.2 → 0.2.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.
- package/LICENSE +20 -20
- package/README.md +5 -5
- package/android/build.gradle +86 -86
- package/android/gradle.properties +5 -5
- package/android/src/main/AndroidManifest.xml +4 -4
- package/android/src/main/java/com/paymeminiapp/JsonConvert.kt +101 -101
- package/android/src/main/java/com/paymeminiapp/RNPayMEMiniAppModule.kt +167 -167
- package/android/src/main/java/com/paymeminiapp/RNPayMEMiniAppPackage.kt +17 -17
- package/ios/RNPayMEMiniApp-Bridging-Header.h +3 -3
- package/ios/RNPayMEMiniApp.m +17 -17
- package/ios/RNPayMEMiniApp.swift +63 -63
- package/ios/RNPayMEMiniApp.xcodeproj/project.pbxproj +281 -281
- package/ios/RNPayMEMiniApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -4
- package/ios/RNPayMEMiniApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
- package/ios/RNPayMEMiniApp.xcodeproj/xcuserdata/montossc.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.type.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.type.js.map +1 -1
- package/lib/typescript/index.d.ts +6 -6
- package/lib/typescript/index.type.d.ts +19 -19
- package/package.json +160 -160
- package/payme-mini-app.podspec +37 -37
- package/src/index.tsx +23 -23
- package/src/index.type.ts +13 -13
|
@@ -1,168 +1,168 @@
|
|
|
1
|
-
package com.paymeminiapp
|
|
2
|
-
|
|
3
|
-
import android.content.Context
|
|
4
|
-
import android.util.Log
|
|
5
|
-
import com.facebook.react.bridge.*
|
|
6
|
-
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
7
|
-
import com.payme.sdk.PayMEMiniApp
|
|
8
|
-
import com.payme.sdk.models.*
|
|
9
|
-
import org.json.JSONObject
|
|
10
|
-
|
|
11
|
-
class RNPayMEMiniAppModule(reactContext: ReactApplicationContext) :
|
|
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
|
-
private var listenerCount = 0
|
|
21
|
-
|
|
22
|
-
@ReactMethod
|
|
23
|
-
fun addListener(eventName: String) {
|
|
24
|
-
if (listenerCount == 0) {
|
|
25
|
-
// Set up any upstream listeners or background tasks as necessary
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
listenerCount += 1
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
@ReactMethod
|
|
32
|
-
fun removeListeners(count: Int) {
|
|
33
|
-
listenerCount -= count
|
|
34
|
-
if (listenerCount == 0) {
|
|
35
|
-
// Remove upstream listeners, stop unnecessary background tasks
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
@ReactMethod
|
|
40
|
-
fun initPayME(appId: String, publicKey: String, privateKey: String, env: String) {
|
|
41
|
-
payMEMiniApp = PayMEMiniApp(
|
|
42
|
-
reactApplicationContext.applicationContext, appId, publicKey, privateKey, getEnv(env)
|
|
43
|
-
)
|
|
44
|
-
payMEMiniApp?.setUpListener(onResponse = { actionOpenMiniApp: ActionOpenMiniApp, jsonObject: JSONObject? ->
|
|
45
|
-
onResponse(actionOpenMiniApp, jsonObject)
|
|
46
|
-
},
|
|
47
|
-
onError = { actionOpenMiniApp: ActionOpenMiniApp, payMEError: PayMEError ->
|
|
48
|
-
onError(actionOpenMiniApp, payMEError)
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@ReactMethod
|
|
53
|
-
fun getBalance(phone: String) {
|
|
54
|
-
payMEMiniApp?.getBalance(phone)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
@ReactMethod
|
|
58
|
-
fun open(type: String, openingParam: ReadableMap) {
|
|
59
|
-
val action = openingParam.getString("action") ?: "PAYME"
|
|
60
|
-
val phone = openingParam.getString("phone") ?: ""
|
|
61
|
-
val data = openingParam.getMap("data")
|
|
62
|
-
val amount = data?.getInt("amount")
|
|
63
|
-
val transactionId = data?.getString("transactionId")
|
|
64
|
-
val note = data?.getString("note")
|
|
65
|
-
val ipnUrl = data?.getString("ipnUrl")
|
|
66
|
-
var paymentData: PaymentData? = null
|
|
67
|
-
if (amount != null && transactionId != null) {
|
|
68
|
-
paymentData = PaymentData(transactionId, amount, note, ipnUrl)
|
|
69
|
-
}
|
|
70
|
-
val openMiniAppData = getOpenMiniAppData(action, phone, paymentData)
|
|
71
|
-
payMEMiniApp?.openMiniApp(
|
|
72
|
-
getTypeOpenMiniApp(type),
|
|
73
|
-
openMiniAppData
|
|
74
|
-
)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
private fun onResponse(actionOpenMiniApp: ActionOpenMiniApp, jsonObject: JSONObject?) {
|
|
78
|
-
if (jsonObject != null) {
|
|
79
|
-
try {
|
|
80
|
-
Log.d("PAYMELOG", "jsonObject $jsonObject")
|
|
81
|
-
val payload = JsonConvert.jsonToReact(jsonObject)
|
|
82
|
-
payload.putString("action", actionOpenMiniApp.toString())
|
|
83
|
-
sendEvent(
|
|
84
|
-
reactApplicationContext,
|
|
85
|
-
"onResponse", payload
|
|
86
|
-
)
|
|
87
|
-
} catch (e: Exception) {
|
|
88
|
-
Log.d("PAYMELOG", "exception $e")
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
private fun onError(actionOpenMiniApp: ActionOpenMiniApp, payMEError: PayMEError) {
|
|
94
|
-
val payload = Arguments.createMap()
|
|
95
|
-
payload.putString("action", actionOpenMiniApp.toString())
|
|
96
|
-
payload.putString("code", payMEError.code)
|
|
97
|
-
payload.putString("description", payMEError.description)
|
|
98
|
-
sendEvent(
|
|
99
|
-
reactApplicationContext,
|
|
100
|
-
"onError", payload
|
|
101
|
-
)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
private fun getEnv(env: String): ENV {
|
|
105
|
-
if (env == ENV.LOCAL.toString()) {
|
|
106
|
-
return ENV.LOCAL
|
|
107
|
-
}
|
|
108
|
-
if (env == ENV.DEV.toString()) {
|
|
109
|
-
return ENV.DEV
|
|
110
|
-
}
|
|
111
|
-
if (env == ENV.SANDBOX.toString()) {
|
|
112
|
-
return ENV.SANDBOX
|
|
113
|
-
}
|
|
114
|
-
if (env == ENV.PRODUCTION.toString()) {
|
|
115
|
-
return ENV.PRODUCTION
|
|
116
|
-
}
|
|
117
|
-
return ENV.PRODUCTION
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
private fun getTypeOpenMiniApp(type: String): OpenMiniAppType {
|
|
121
|
-
return OpenMiniAppType.screen
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
private fun getActionOpenMiniApp(action: String): ActionOpenMiniApp {
|
|
125
|
-
if (action == ActionOpenMiniApp.PAYME.toString()) {
|
|
126
|
-
return ActionOpenMiniApp.PAYME
|
|
127
|
-
}
|
|
128
|
-
if (action == ActionOpenMiniApp.OPEN.toString()) {
|
|
129
|
-
return ActionOpenMiniApp.OPEN
|
|
130
|
-
}
|
|
131
|
-
if (action == ActionOpenMiniApp.PAY.toString()) {
|
|
132
|
-
return ActionOpenMiniApp.PAY
|
|
133
|
-
}
|
|
134
|
-
if (action == ActionOpenMiniApp.GET_BALANCE.toString()) {
|
|
135
|
-
return ActionOpenMiniApp.GET_BALANCE
|
|
136
|
-
}
|
|
137
|
-
return ActionOpenMiniApp.PAYME
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
private fun getOpenMiniAppData(
|
|
141
|
-
action: String,
|
|
142
|
-
phone: String,
|
|
143
|
-
paymentData: PaymentData? = null
|
|
144
|
-
): OpenMiniAppDataInterface {
|
|
145
|
-
if (getActionOpenMiniApp(action) == ActionOpenMiniApp.OPEN) {
|
|
146
|
-
return OpenMiniAppOpenData(phone)
|
|
147
|
-
}
|
|
148
|
-
if (getActionOpenMiniApp(action) == ActionOpenMiniApp.PAY) {
|
|
149
|
-
return OpenMiniAppPaymentData(phone, paymentData!!)
|
|
150
|
-
}
|
|
151
|
-
if (getActionOpenMiniApp(action) == ActionOpenMiniApp.PAYME) {
|
|
152
|
-
return OpenMiniAppPayMEData()
|
|
153
|
-
}
|
|
154
|
-
return OpenMiniAppPayMEData()
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
private fun sendEvent(reactContext: ReactContext, eventName: String, params: WritableMap?) {
|
|
158
|
-
if (eventNames.contains(eventName)) {
|
|
159
|
-
reactContext
|
|
160
|
-
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
161
|
-
.emit(eventName, params)
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
companion object {
|
|
166
|
-
const val NAME = "RNPayMEMiniApp"
|
|
167
|
-
}
|
|
1
|
+
package com.paymeminiapp
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.util.Log
|
|
5
|
+
import com.facebook.react.bridge.*
|
|
6
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
7
|
+
import com.payme.sdk.PayMEMiniApp
|
|
8
|
+
import com.payme.sdk.models.*
|
|
9
|
+
import org.json.JSONObject
|
|
10
|
+
|
|
11
|
+
class RNPayMEMiniAppModule(reactContext: ReactApplicationContext) :
|
|
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
|
+
private var listenerCount = 0
|
|
21
|
+
|
|
22
|
+
@ReactMethod
|
|
23
|
+
fun addListener(eventName: String) {
|
|
24
|
+
if (listenerCount == 0) {
|
|
25
|
+
// Set up any upstream listeners or background tasks as necessary
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
listenerCount += 1
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@ReactMethod
|
|
32
|
+
fun removeListeners(count: Int) {
|
|
33
|
+
listenerCount -= count
|
|
34
|
+
if (listenerCount == 0) {
|
|
35
|
+
// Remove upstream listeners, stop unnecessary background tasks
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@ReactMethod
|
|
40
|
+
fun initPayME(appId: String, publicKey: String, privateKey: String, env: String) {
|
|
41
|
+
payMEMiniApp = PayMEMiniApp(
|
|
42
|
+
reactApplicationContext.applicationContext, appId, publicKey, privateKey, getEnv(env)
|
|
43
|
+
)
|
|
44
|
+
payMEMiniApp?.setUpListener(onResponse = { actionOpenMiniApp: ActionOpenMiniApp, jsonObject: JSONObject? ->
|
|
45
|
+
onResponse(actionOpenMiniApp, jsonObject)
|
|
46
|
+
},
|
|
47
|
+
onError = { actionOpenMiniApp: ActionOpenMiniApp, payMEError: PayMEError ->
|
|
48
|
+
onError(actionOpenMiniApp, payMEError)
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@ReactMethod
|
|
53
|
+
fun getBalance(phone: String) {
|
|
54
|
+
payMEMiniApp?.getBalance(phone)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@ReactMethod
|
|
58
|
+
fun open(type: String, openingParam: ReadableMap) {
|
|
59
|
+
val action = openingParam.getString("action") ?: "PAYME"
|
|
60
|
+
val phone = openingParam.getString("phone") ?: ""
|
|
61
|
+
val data = openingParam.getMap("data")
|
|
62
|
+
val amount = data?.getInt("amount")
|
|
63
|
+
val transactionId = data?.getString("transactionId")
|
|
64
|
+
val note = data?.getString("note")
|
|
65
|
+
val ipnUrl = data?.getString("ipnUrl")
|
|
66
|
+
var paymentData: PaymentData? = null
|
|
67
|
+
if (amount != null && transactionId != null) {
|
|
68
|
+
paymentData = PaymentData(transactionId, amount, note, ipnUrl)
|
|
69
|
+
}
|
|
70
|
+
val openMiniAppData = getOpenMiniAppData(action, phone, paymentData)
|
|
71
|
+
payMEMiniApp?.openMiniApp(
|
|
72
|
+
getTypeOpenMiniApp(type),
|
|
73
|
+
openMiniAppData
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private fun onResponse(actionOpenMiniApp: ActionOpenMiniApp, jsonObject: JSONObject?) {
|
|
78
|
+
if (jsonObject != null) {
|
|
79
|
+
try {
|
|
80
|
+
Log.d("PAYMELOG", "jsonObject $jsonObject")
|
|
81
|
+
val payload = JsonConvert.jsonToReact(jsonObject)
|
|
82
|
+
payload.putString("action", actionOpenMiniApp.toString())
|
|
83
|
+
sendEvent(
|
|
84
|
+
reactApplicationContext,
|
|
85
|
+
"onResponse", payload
|
|
86
|
+
)
|
|
87
|
+
} catch (e: Exception) {
|
|
88
|
+
Log.d("PAYMELOG", "exception $e")
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private fun onError(actionOpenMiniApp: ActionOpenMiniApp, payMEError: PayMEError) {
|
|
94
|
+
val payload = Arguments.createMap()
|
|
95
|
+
payload.putString("action", actionOpenMiniApp.toString())
|
|
96
|
+
payload.putString("code", payMEError.code)
|
|
97
|
+
payload.putString("description", payMEError.description)
|
|
98
|
+
sendEvent(
|
|
99
|
+
reactApplicationContext,
|
|
100
|
+
"onError", payload
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private fun getEnv(env: String): ENV {
|
|
105
|
+
if (env == ENV.LOCAL.toString()) {
|
|
106
|
+
return ENV.LOCAL
|
|
107
|
+
}
|
|
108
|
+
if (env == ENV.DEV.toString()) {
|
|
109
|
+
return ENV.DEV
|
|
110
|
+
}
|
|
111
|
+
if (env == ENV.SANDBOX.toString()) {
|
|
112
|
+
return ENV.SANDBOX
|
|
113
|
+
}
|
|
114
|
+
if (env == ENV.PRODUCTION.toString()) {
|
|
115
|
+
return ENV.PRODUCTION
|
|
116
|
+
}
|
|
117
|
+
return ENV.PRODUCTION
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private fun getTypeOpenMiniApp(type: String): OpenMiniAppType {
|
|
121
|
+
return OpenMiniAppType.screen
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private fun getActionOpenMiniApp(action: String): ActionOpenMiniApp {
|
|
125
|
+
if (action == ActionOpenMiniApp.PAYME.toString()) {
|
|
126
|
+
return ActionOpenMiniApp.PAYME
|
|
127
|
+
}
|
|
128
|
+
if (action == ActionOpenMiniApp.OPEN.toString()) {
|
|
129
|
+
return ActionOpenMiniApp.OPEN
|
|
130
|
+
}
|
|
131
|
+
if (action == ActionOpenMiniApp.PAY.toString()) {
|
|
132
|
+
return ActionOpenMiniApp.PAY
|
|
133
|
+
}
|
|
134
|
+
if (action == ActionOpenMiniApp.GET_BALANCE.toString()) {
|
|
135
|
+
return ActionOpenMiniApp.GET_BALANCE
|
|
136
|
+
}
|
|
137
|
+
return ActionOpenMiniApp.PAYME
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private fun getOpenMiniAppData(
|
|
141
|
+
action: String,
|
|
142
|
+
phone: String,
|
|
143
|
+
paymentData: PaymentData? = null
|
|
144
|
+
): OpenMiniAppDataInterface {
|
|
145
|
+
if (getActionOpenMiniApp(action) == ActionOpenMiniApp.OPEN) {
|
|
146
|
+
return OpenMiniAppOpenData(phone)
|
|
147
|
+
}
|
|
148
|
+
if (getActionOpenMiniApp(action) == ActionOpenMiniApp.PAY) {
|
|
149
|
+
return OpenMiniAppPaymentData(phone, paymentData!!)
|
|
150
|
+
}
|
|
151
|
+
if (getActionOpenMiniApp(action) == ActionOpenMiniApp.PAYME) {
|
|
152
|
+
return OpenMiniAppPayMEData()
|
|
153
|
+
}
|
|
154
|
+
return OpenMiniAppPayMEData()
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private fun sendEvent(reactContext: ReactContext, eventName: String, params: WritableMap?) {
|
|
158
|
+
if (eventNames.contains(eventName)) {
|
|
159
|
+
reactContext
|
|
160
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
161
|
+
.emit(eventName, params)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
companion object {
|
|
166
|
+
const val NAME = "RNPayMEMiniApp"
|
|
167
|
+
}
|
|
168
168
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
package com.paymeminiapp
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.ReactPackage
|
|
4
|
-
import com.facebook.react.bridge.NativeModule
|
|
5
|
-
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
-
import com.facebook.react.uimanager.ViewManager
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class RNPayMEMiniAppPackage : ReactPackage {
|
|
10
|
-
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
11
|
-
return listOf(RNPayMEMiniAppModule(reactContext))
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
15
|
-
return emptyList()
|
|
16
|
-
}
|
|
17
|
-
}
|
|
1
|
+
package com.paymeminiapp
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.uimanager.ViewManager
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class RNPayMEMiniAppPackage : ReactPackage {
|
|
10
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
11
|
+
return listOf(RNPayMEMiniAppModule(reactContext))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
15
|
+
return emptyList()
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#import <React/RCTBridgeModule.h>
|
|
2
|
-
#import <React/RCTViewManager.h>
|
|
3
|
-
#import <React/RCTEventEmitter.h>
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
#import <React/RCTViewManager.h>
|
|
3
|
+
#import <React/RCTEventEmitter.h>
|
package/ios/RNPayMEMiniApp.m
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
#import <React/RCTBridgeModule.h>
|
|
2
|
-
#import <React/RCTEventEmitter.h>
|
|
3
|
-
|
|
4
|
-
@interface RCT_EXTERN_MODULE(RNPayMEMiniApp, RCTEventEmitter)
|
|
5
|
-
|
|
6
|
-
RCT_EXTERN_METHOD(initPayME:(NSString*)appId publicKey:(NSString)publicKey privateKey:(NSString)privateKey env:(NSString)env)
|
|
7
|
-
RCT_EXTERN_METHOD(open:(NSString*)type param:(NSDictionary)param)
|
|
8
|
-
RCT_EXTERN_METHOD(getBalance:(NSString*)phone)
|
|
9
|
-
|
|
10
|
-
+ (BOOL)requiresMainQueueSetup
|
|
11
|
-
{
|
|
12
|
-
return YES;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
@end
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
#import <React/RCTEventEmitter.h>
|
|
3
|
+
|
|
4
|
+
@interface RCT_EXTERN_MODULE(RNPayMEMiniApp, RCTEventEmitter)
|
|
5
|
+
|
|
6
|
+
RCT_EXTERN_METHOD(initPayME:(NSString*)appId publicKey:(NSString)publicKey privateKey:(NSString)privateKey env:(NSString)env)
|
|
7
|
+
RCT_EXTERN_METHOD(open:(NSString*)type param:(NSDictionary)param)
|
|
8
|
+
RCT_EXTERN_METHOD(getBalance:(NSString*)phone)
|
|
9
|
+
|
|
10
|
+
+ (BOOL)requiresMainQueueSetup
|
|
11
|
+
{
|
|
12
|
+
return YES;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@end
|
|
16
|
+
|
|
17
|
+
|
package/ios/RNPayMEMiniApp.swift
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import PayMEMiniApp
|
|
2
|
-
|
|
3
|
-
@objc(RNPayMEMiniApp)
|
|
4
|
-
class RNPayMEMiniApp: RCTEventEmitter, PayMEDelegate {
|
|
5
|
-
var payme: PayME!
|
|
6
|
-
|
|
7
|
-
@objc func initPayME(_ appId: String, publicKey: String, privateKey: String, env: String) {
|
|
8
|
-
DispatchQueue.main.sync {
|
|
9
|
-
PayMEConfig.instance.env = (env == "SANDBOX") ? .sbx : .prod
|
|
10
|
-
self.payme = PayME(key: PayMEKey(appId: appId, publicKey: publicKey, privateKey: privateKey))
|
|
11
|
-
self.payme.delegate = self
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
@objc func open(_ type: String, param: NSDictionary) {
|
|
16
|
-
let openAction: PayMEAction = {
|
|
17
|
-
switch param["action"] as? String {
|
|
18
|
-
case "PAYME": return PayMEAction.PayME
|
|
19
|
-
case "OPEN": return PayMEAction.Open
|
|
20
|
-
case "PAY": return PayMEAction.Pay
|
|
21
|
-
default: fatalError("Invalid action!")
|
|
22
|
-
}
|
|
23
|
-
}()
|
|
24
|
-
var openData: Any? {
|
|
25
|
-
guard let data = param["data"] as? NSDictionary else { return nil }
|
|
26
|
-
switch param["action"] as? String {
|
|
27
|
-
case "PAYME": fallthrough
|
|
28
|
-
case "OPEN": return nil
|
|
29
|
-
case "PAY":
|
|
30
|
-
return PayMEPaymentParam(amount: data["amount"] as! Int, transactionId: data["transactionId"] as! String, note: data["note"] as? String, ipnUrl: data["ipnUrl"] as? String)
|
|
31
|
-
default: fatalError("Invalid action!")
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
DispatchQueue.main.sync {
|
|
36
|
-
let RNVC = UIApplication.shared.delegate?.window??.rootViewController
|
|
37
|
-
self.payme.open(with: PayMEOpeningParam(action: openAction, phone: param["phone"] as! String, data: openData), from: RNVC)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
@objc func getBalance(_ phone: String) {
|
|
42
|
-
DispatchQueue.main.sync {
|
|
43
|
-
self.payme.getBalance(of: phone)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
override func supportedEvents() -> [String]! {
|
|
48
|
-
return ["onError", "onResponse"]
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
func onError(action: PayMEMiniApp.PayMEAction, error: PayMEMiniApp.PayMEError) {
|
|
52
|
-
sendEvent(withName: "onError", body: ["action": action.rawValue, "code": error.code, "description": error.description])
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
func onResponse(action: PayMEMiniApp.PayMEAction, response: [String: Any]) {
|
|
56
|
-
sendEvent(withName: "onResponse", body: ["action": action.rawValue].merging(response) { (_, new) in new })
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
1
|
+
import PayMEMiniApp
|
|
2
|
+
|
|
3
|
+
@objc(RNPayMEMiniApp)
|
|
4
|
+
class RNPayMEMiniApp: RCTEventEmitter, PayMEDelegate {
|
|
5
|
+
var payme: PayME!
|
|
6
|
+
|
|
7
|
+
@objc func initPayME(_ appId: String, publicKey: String, privateKey: String, env: String) {
|
|
8
|
+
DispatchQueue.main.sync {
|
|
9
|
+
PayMEConfig.instance.env = (env == "SANDBOX") ? .sbx : .prod
|
|
10
|
+
self.payme = PayME(key: PayMEKey(appId: appId, publicKey: publicKey, privateKey: privateKey))
|
|
11
|
+
self.payme.delegate = self
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@objc func open(_ type: String, param: NSDictionary) {
|
|
16
|
+
let openAction: PayMEAction = {
|
|
17
|
+
switch param["action"] as? String {
|
|
18
|
+
case "PAYME": return PayMEAction.PayME
|
|
19
|
+
case "OPEN": return PayMEAction.Open
|
|
20
|
+
case "PAY": return PayMEAction.Pay
|
|
21
|
+
default: fatalError("Invalid action!")
|
|
22
|
+
}
|
|
23
|
+
}()
|
|
24
|
+
var openData: Any? {
|
|
25
|
+
guard let data = param["data"] as? NSDictionary else { return nil }
|
|
26
|
+
switch param["action"] as? String {
|
|
27
|
+
case "PAYME": fallthrough
|
|
28
|
+
case "OPEN": return nil
|
|
29
|
+
case "PAY":
|
|
30
|
+
return PayMEPaymentParam(amount: data["amount"] as! Int, transactionId: data["transactionId"] as! String, note: data["note"] as? String, ipnUrl: data["ipnUrl"] as? String)
|
|
31
|
+
default: fatalError("Invalid action!")
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
DispatchQueue.main.sync {
|
|
36
|
+
let RNVC = UIApplication.shared.delegate?.window??.rootViewController
|
|
37
|
+
self.payme.open(with: PayMEOpeningParam(action: openAction, phone: param["phone"] as! String, data: openData), from: RNVC)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@objc func getBalance(_ phone: String) {
|
|
42
|
+
DispatchQueue.main.sync {
|
|
43
|
+
self.payme.getBalance(of: phone)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
override func supportedEvents() -> [String]! {
|
|
48
|
+
return ["onError", "onResponse"]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
func onError(action: PayMEMiniApp.PayMEAction, error: PayMEMiniApp.PayMEError) {
|
|
52
|
+
sendEvent(withName: "onError", body: ["action": action.rawValue, "code": error.code, "description": error.description])
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
func onResponse(action: PayMEMiniApp.PayMEAction, response: [String: Any]) {
|
|
56
|
+
sendEvent(withName: "onResponse", body: ["action": action.rawValue].merging(response) { (_, new) in new })
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|