payme-mini-app 0.1.4 → 0.1.6
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 +31 -31
- 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 +97 -97
- package/android/src/main/java/com/paymeminiapp/RNPayMEMiniAppModule.kt +144 -144
- package/android/src/main/java/com/paymeminiapp/RNPayMEMiniAppPackage.kt +17 -17
- package/ios/RNPayMEMiniApp-Bridging-Header.h +3 -3
- package/ios/RNPayMEMiniApp.m +16 -16
- package/ios/RNPayMEMiniApp.swift +57 -57
- 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 +5 -5
- 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 +19 -19
- package/src/index.type.ts +13 -13
|
@@ -1,145 +1,145 @@
|
|
|
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
|
-
currentActivity as Context, appId, publicKey, privateKey, getEnv(env)
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
@ReactMethod
|
|
47
|
-
fun open(type: String, openingParam: ReadableMap) {
|
|
48
|
-
val action = openingParam.getString("action") ?: "PAYME"
|
|
49
|
-
val phone = openingParam.getString("phone") ?: ""
|
|
50
|
-
val data = openingParam.getMap("data")
|
|
51
|
-
val amount = data?.getInt("amount")
|
|
52
|
-
val transactionId = data?.getString("transactionId")
|
|
53
|
-
val note = data?.getString("note")
|
|
54
|
-
val ipnUrl = data?.getString("ipnUrl")
|
|
55
|
-
var paymentData: PaymentData? = null
|
|
56
|
-
if (amount != null && transactionId != null) {
|
|
57
|
-
paymentData = PaymentData(transactionId, amount, note, ipnUrl)
|
|
58
|
-
}
|
|
59
|
-
val openMiniAppData =
|
|
60
|
-
OpenMiniAppData(
|
|
61
|
-
getActionOpenMiniApp(action),
|
|
62
|
-
phone,
|
|
63
|
-
paymentData = paymentData
|
|
64
|
-
)
|
|
65
|
-
payMEMiniApp?.openMiniApp(
|
|
66
|
-
getTypeOpenMiniApp(type),
|
|
67
|
-
openMiniAppData,
|
|
68
|
-
onSuccess = { actionOpenMiniApp: ActionOpenMiniApp, jsonObject: JSONObject? ->
|
|
69
|
-
if (jsonObject != null) {
|
|
70
|
-
try {
|
|
71
|
-
val payload = JsonConvert.jsonToReact(jsonObject)
|
|
72
|
-
payload.putString("action", actionOpenMiniApp.toString())
|
|
73
|
-
sendEvent(
|
|
74
|
-
reactApplicationContext,
|
|
75
|
-
"onResponse", payload
|
|
76
|
-
)
|
|
77
|
-
} catch (e: Exception) {
|
|
78
|
-
Log.d("PAYME", "exception $e")
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
onError = { actionOpenMiniApp: ActionOpenMiniApp, payMEError: PayMEError ->
|
|
83
|
-
val payload = Arguments.createMap()
|
|
84
|
-
payload.putString("action", actionOpenMiniApp.toString())
|
|
85
|
-
payload.putString("code", payMEError.code)
|
|
86
|
-
payload.putString("description", payMEError.message)
|
|
87
|
-
sendEvent(
|
|
88
|
-
reactApplicationContext,
|
|
89
|
-
"onError", payload
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
private fun getEnv(env: String): ENV {
|
|
96
|
-
if (env == ENV.LOCAL.toString()) {
|
|
97
|
-
return ENV.LOCAL
|
|
98
|
-
}
|
|
99
|
-
if (env == ENV.DEV.toString()) {
|
|
100
|
-
return ENV.DEV
|
|
101
|
-
}
|
|
102
|
-
if (env == ENV.SANDBOX.toString()) {
|
|
103
|
-
return ENV.SANDBOX
|
|
104
|
-
}
|
|
105
|
-
if (env == ENV.PRODUCTION.toString()) {
|
|
106
|
-
return ENV.PRODUCTION
|
|
107
|
-
}
|
|
108
|
-
return ENV.PRODUCTION
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private fun getTypeOpenMiniApp(type: String): OpenMiniAppType {
|
|
112
|
-
if (type.lowercase() == OpenMiniAppType.modal.toString()) {
|
|
113
|
-
return OpenMiniAppType.modal
|
|
114
|
-
}
|
|
115
|
-
if (type.lowercase() == OpenMiniAppType.screen.toString()) {
|
|
116
|
-
return OpenMiniAppType.screen
|
|
117
|
-
}
|
|
118
|
-
return OpenMiniAppType.screen
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
private fun getActionOpenMiniApp(action: String): ActionOpenMiniApp {
|
|
122
|
-
if (action == ActionOpenMiniApp.PAYME.toString()) {
|
|
123
|
-
return ActionOpenMiniApp.PAYME
|
|
124
|
-
}
|
|
125
|
-
if (action == ActionOpenMiniApp.OPEN.toString()) {
|
|
126
|
-
return ActionOpenMiniApp.OPEN
|
|
127
|
-
}
|
|
128
|
-
if (action == ActionOpenMiniApp.PAY.toString()) {
|
|
129
|
-
return ActionOpenMiniApp.PAY
|
|
130
|
-
}
|
|
131
|
-
return ActionOpenMiniApp.PAYME
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
private fun sendEvent(reactContext: ReactContext, eventName: String, params: WritableMap?) {
|
|
135
|
-
if (eventNames.contains(eventName)) {
|
|
136
|
-
reactContext
|
|
137
|
-
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
138
|
-
.emit(eventName, params)
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
companion object {
|
|
143
|
-
const val NAME = "RNPayMEMiniApp"
|
|
144
|
-
}
|
|
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
|
+
currentActivity as Context, appId, publicKey, privateKey, getEnv(env)
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@ReactMethod
|
|
47
|
+
fun open(type: String, openingParam: ReadableMap) {
|
|
48
|
+
val action = openingParam.getString("action") ?: "PAYME"
|
|
49
|
+
val phone = openingParam.getString("phone") ?: ""
|
|
50
|
+
val data = openingParam.getMap("data")
|
|
51
|
+
val amount = data?.getInt("amount")
|
|
52
|
+
val transactionId = data?.getString("transactionId")
|
|
53
|
+
val note = data?.getString("note")
|
|
54
|
+
val ipnUrl = data?.getString("ipnUrl")
|
|
55
|
+
var paymentData: PaymentData? = null
|
|
56
|
+
if (amount != null && transactionId != null) {
|
|
57
|
+
paymentData = PaymentData(transactionId, amount, note, ipnUrl)
|
|
58
|
+
}
|
|
59
|
+
val openMiniAppData =
|
|
60
|
+
OpenMiniAppData(
|
|
61
|
+
getActionOpenMiniApp(action),
|
|
62
|
+
phone,
|
|
63
|
+
paymentData = paymentData
|
|
64
|
+
)
|
|
65
|
+
payMEMiniApp?.openMiniApp(
|
|
66
|
+
getTypeOpenMiniApp(type),
|
|
67
|
+
openMiniAppData,
|
|
68
|
+
onSuccess = { actionOpenMiniApp: ActionOpenMiniApp, jsonObject: JSONObject? ->
|
|
69
|
+
if (jsonObject != null) {
|
|
70
|
+
try {
|
|
71
|
+
val payload = JsonConvert.jsonToReact(jsonObject)
|
|
72
|
+
payload.putString("action", actionOpenMiniApp.toString())
|
|
73
|
+
sendEvent(
|
|
74
|
+
reactApplicationContext,
|
|
75
|
+
"onResponse", payload
|
|
76
|
+
)
|
|
77
|
+
} catch (e: Exception) {
|
|
78
|
+
Log.d("PAYME", "exception $e")
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
onError = { actionOpenMiniApp: ActionOpenMiniApp, payMEError: PayMEError ->
|
|
83
|
+
val payload = Arguments.createMap()
|
|
84
|
+
payload.putString("action", actionOpenMiniApp.toString())
|
|
85
|
+
payload.putString("code", payMEError.code)
|
|
86
|
+
payload.putString("description", payMEError.message)
|
|
87
|
+
sendEvent(
|
|
88
|
+
reactApplicationContext,
|
|
89
|
+
"onError", payload
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private fun getEnv(env: String): ENV {
|
|
96
|
+
if (env == ENV.LOCAL.toString()) {
|
|
97
|
+
return ENV.LOCAL
|
|
98
|
+
}
|
|
99
|
+
if (env == ENV.DEV.toString()) {
|
|
100
|
+
return ENV.DEV
|
|
101
|
+
}
|
|
102
|
+
if (env == ENV.SANDBOX.toString()) {
|
|
103
|
+
return ENV.SANDBOX
|
|
104
|
+
}
|
|
105
|
+
if (env == ENV.PRODUCTION.toString()) {
|
|
106
|
+
return ENV.PRODUCTION
|
|
107
|
+
}
|
|
108
|
+
return ENV.PRODUCTION
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private fun getTypeOpenMiniApp(type: String): OpenMiniAppType {
|
|
112
|
+
if (type.lowercase() == OpenMiniAppType.modal.toString()) {
|
|
113
|
+
return OpenMiniAppType.modal
|
|
114
|
+
}
|
|
115
|
+
if (type.lowercase() == OpenMiniAppType.screen.toString()) {
|
|
116
|
+
return OpenMiniAppType.screen
|
|
117
|
+
}
|
|
118
|
+
return OpenMiniAppType.screen
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private fun getActionOpenMiniApp(action: String): ActionOpenMiniApp {
|
|
122
|
+
if (action == ActionOpenMiniApp.PAYME.toString()) {
|
|
123
|
+
return ActionOpenMiniApp.PAYME
|
|
124
|
+
}
|
|
125
|
+
if (action == ActionOpenMiniApp.OPEN.toString()) {
|
|
126
|
+
return ActionOpenMiniApp.OPEN
|
|
127
|
+
}
|
|
128
|
+
if (action == ActionOpenMiniApp.PAY.toString()) {
|
|
129
|
+
return ActionOpenMiniApp.PAY
|
|
130
|
+
}
|
|
131
|
+
return ActionOpenMiniApp.PAYME
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private fun sendEvent(reactContext: ReactContext, eventName: String, params: WritableMap?) {
|
|
135
|
+
if (eventNames.contains(eventName)) {
|
|
136
|
+
reactContext
|
|
137
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
138
|
+
.emit(eventName, params)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
companion object {
|
|
143
|
+
const val NAME = "RNPayMEMiniApp"
|
|
144
|
+
}
|
|
145
145
|
}
|
|
@@ -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,16 +1,16 @@
|
|
|
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)
|
|
7
|
-
RCT_EXTERN_METHOD(open:(NSString*)type param:(NSDictionary)param)
|
|
8
|
-
|
|
9
|
-
+ (BOOL)requiresMainQueueSetup
|
|
10
|
-
{
|
|
11
|
-
return YES;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
@end
|
|
15
|
-
|
|
16
|
-
|
|
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
|
+
|
|
9
|
+
+ (BOOL)requiresMainQueueSetup
|
|
10
|
+
{
|
|
11
|
+
return YES;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@end
|
|
15
|
+
|
|
16
|
+
|
package/ios/RNPayMEMiniApp.swift
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
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(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)
|
|
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
|
-
override func supportedEvents() -> [String]! {
|
|
42
|
-
return ["onError", "onResponse"]
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
func onError(action: PayMEMiniApp.PayMEAction, error: PayMEMiniApp.PayMEError) {
|
|
46
|
-
sendEvent(withName: "onError", body: ["action": action.value, "code": error.code, "description": error.description])
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
func onResponse(action: PayMEMiniApp.PayMEAction, response: [String: String]) {
|
|
50
|
-
sendEvent(withName: "onResponse", body: ["action": action.value].merging(response) { (_, new) in new })
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
+
override func supportedEvents() -> [String]! {
|
|
42
|
+
return ["onError", "onResponse"]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
func onError(action: PayMEMiniApp.PayMEAction, error: PayMEMiniApp.PayMEError) {
|
|
46
|
+
sendEvent(withName: "onError", body: ["action": action.value, "code": error.code, "description": error.description])
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
func onResponse(action: PayMEMiniApp.PayMEAction, response: [String: String]) {
|
|
50
|
+
sendEvent(withName: "onResponse", body: ["action": action.value].merging(response) { (_, new) in new })
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|