payme-mini-app 0.1.2 → 0.1.4

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 (30) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +31 -31
  3. package/android/build.gradle +86 -86
  4. package/android/gradle.properties +5 -5
  5. package/android/src/main/AndroidManifest.xml +4 -4
  6. package/android/src/main/java/com/paymeminiapp/JsonConvert.kt +97 -97
  7. package/android/src/main/java/com/paymeminiapp/RNPayMEMiniAppModule.kt +144 -130
  8. package/android/src/main/java/com/paymeminiapp/RNPayMEMiniAppPackage.kt +17 -17
  9. package/ios/RNPayMEMiniApp-Bridging-Header.h +3 -3
  10. package/ios/RNPayMEMiniApp.m +16 -16
  11. package/ios/RNPayMEMiniApp.swift +57 -63
  12. package/ios/RNPayMEMiniApp.xcodeproj/project.pbxproj +281 -281
  13. package/ios/RNPayMEMiniApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -4
  14. package/ios/RNPayMEMiniApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
  15. package/ios/RNPayMEMiniApp.xcodeproj/project.xcworkspace/xcuserdata/montossc.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  16. package/ios/RNPayMEMiniApp.xcodeproj/xcuserdata/montossc.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
  17. package/lib/commonjs/index.js +2 -2
  18. package/lib/commonjs/index.js.map +1 -1
  19. package/lib/commonjs/index.type.js.map +1 -1
  20. package/lib/module/index.js +2 -2
  21. package/lib/module/index.js.map +1 -1
  22. package/lib/module/index.type.js.map +1 -1
  23. package/lib/typescript/index.d.ts +5 -5
  24. package/lib/typescript/index.d.ts.map +1 -1
  25. package/lib/typescript/index.type.d.ts +19 -18
  26. package/lib/typescript/index.type.d.ts.map +1 -1
  27. package/package.json +160 -160
  28. package/payme-mini-app.podspec +37 -37
  29. package/src/index.tsx +19 -14
  30. package/src/index.type.ts +13 -11
@@ -1,131 +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
- @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
- }
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
+ }
131
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>
@@ -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)
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,63 +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) {
8
- DispatchQueue.main.sync {
9
- PayMEConfig.instance.env = .local
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 = "modal", 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
- if (type == "screen") {
38
- guard let navigationController = RNVC as? UINavigationController else { return }
39
- navigationController.pushViewController(self.payme, animated: true)
40
- // payme.open()
41
- } else {
42
- self.payme.open(with: PayMEOpeningParam(action: openAction, phone: param["phone"] as! String, data: openData), from: RNVC)
43
- }
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.value, "code": error.code, "description": error.description])
53
- }
54
-
55
- func onResponse(action: PayMEMiniApp.PayMEAction, response: [String: String]) {
56
- sendEvent(withName: "onResponse", body: ["action": action.value].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(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
+