payme-mini-app 0.1.0 → 0.1.1

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.
@@ -1,2 +1,3 @@
1
1
  #import <React/RCTBridgeModule.h>
2
2
  #import <React/RCTViewManager.h>
3
+ #import <React/RCTEventEmitter.h>
@@ -1,8 +1,10 @@
1
1
  #import <React/RCTBridgeModule.h>
2
+ #import <React/RCTEventEmitter.h>
2
3
 
3
- @interface RCT_EXTERN_MODULE(RNPayMEMiniApp, NSObject)
4
+ @interface RCT_EXTERN_MODULE(RNPayMEMiniApp, RCTEventEmitter)
4
5
 
5
- RCT_EXTERN_METHOD(open:(NSString*)type)
6
+ RCT_EXTERN_METHOD(initPayME:(NSString*)appId publicKey:(NSString)publicKey privateKey:(NSString)privateKey)
7
+ RCT_EXTERN_METHOD(open:(NSString*)type param:(NSDictionary)param)
6
8
 
7
9
  + (BOOL)requiresMainQueueSetup
8
10
  {
@@ -10,3 +12,5 @@ RCT_EXTERN_METHOD(open:(NSString*)type)
10
12
  }
11
13
 
12
14
  @end
15
+
16
+
@@ -1,17 +1,63 @@
1
1
  import PayMEMiniApp
2
2
 
3
3
  @objc(RNPayMEMiniApp)
4
- class RNPayMEMiniApp: NSObject {
5
- let payme = PayME()
6
-
7
- @objc func open(_ type: String = "modal") {
8
- let RNVC = UIApplication.shared.delegate?.window??.rootViewController
9
- if (type == "screen") {
10
- guard let navigationController = RNVC as? UINavigationController else { return }
11
- navigationController.pushViewController(payme, animated: true)
12
- payme.open()
13
- } else {
14
- payme.open(from: RNVC)
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
15
12
  }
16
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
+ }
17
58
  }
59
+
60
+
61
+
62
+
63
+
@@ -3,10 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.PayMEMiniAppEvents = void 0;
7
+ exports.init = init;
6
8
  exports.open = open;
7
9
  var _reactNative = require("react-native");
8
10
  const RNPayMEMiniApp = _reactNative.NativeModules.RNPayMEMiniApp;
9
- function open(type) {
10
- return RNPayMEMiniApp.open(type);
11
+ function init(appId, publicKey, privateKey) {
12
+ return RNPayMEMiniApp.initPayME(appId, publicKey, privateKey);
11
13
  }
14
+ function open(type, openingParam) {
15
+ return RNPayMEMiniApp.open(type, openingParam);
16
+ }
17
+ const PayMEMiniAppEvents = new _reactNative.NativeEventEmitter(RNPayMEMiniApp);
18
+ exports.PayMEMiniAppEvents = PayMEMiniAppEvents;
12
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["RNPayMEMiniApp","NativeModules","open","type"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA;AAEA,MAAMA,cAAc,GAAGC,0BAAa,CAACD,cAAc;AAE5C,SAASE,IAAI,CAACC,IAAY,EAAE;EACjC,OAAOH,cAAc,CAACE,IAAI,CAACC,IAAI,CAAC;AAClC"}
1
+ {"version":3,"names":["RNPayMEMiniApp","NativeModules","init","appId","publicKey","privateKey","initPayME","open","type","openingParam","PayMEMiniAppEvents","NativeEventEmitter"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;AAAA;AAGA,MAAMA,cAAc,GAAGC,0BAAa,CAACD,cAAc;AAE5C,SAASE,IAAI,CAACC,KAAa,EAAEC,SAAiB,EAAEC,UAAkB,EAAE;EACzE,OAAOL,cAAc,CAACM,SAAS,CAACH,KAAK,EAAEC,SAAS,EAAEC,UAAU,CAAC;AAC/D;AAEO,SAASE,IAAI,CAACC,IAAY,EAAEC,YAA+B,EAAE;EAClE,OAAOT,cAAc,CAACO,IAAI,CAACC,IAAI,EAAEC,YAAY,CAAC;AAChD;AAEO,MAAMC,kBAAkB,GAAG,IAAIC,+BAAkB,CAACX,cAAc,CAAC;AAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=index.type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["index.type.ts"],"mappings":""}
@@ -1,6 +1,10 @@
1
- import { NativeModules } from 'react-native';
1
+ import { NativeEventEmitter, NativeModules } from 'react-native';
2
2
  const RNPayMEMiniApp = NativeModules.RNPayMEMiniApp;
3
- export function open(type) {
4
- return RNPayMEMiniApp.open(type);
3
+ export function init(appId, publicKey, privateKey) {
4
+ return RNPayMEMiniApp.initPayME(appId, publicKey, privateKey);
5
5
  }
6
+ export function open(type, openingParam) {
7
+ return RNPayMEMiniApp.open(type, openingParam);
8
+ }
9
+ export const PayMEMiniAppEvents = new NativeEventEmitter(RNPayMEMiniApp);
6
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["NativeModules","RNPayMEMiniApp","open","type"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAE5C,MAAMC,cAAc,GAAGD,aAAa,CAACC,cAAc;AAEnD,OAAO,SAASC,IAAI,CAACC,IAAY,EAAE;EACjC,OAAOF,cAAc,CAACC,IAAI,CAACC,IAAI,CAAC;AAClC"}
1
+ {"version":3,"names":["NativeEventEmitter","NativeModules","RNPayMEMiniApp","init","appId","publicKey","privateKey","initPayME","open","type","openingParam","PayMEMiniAppEvents"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,SAASA,kBAAkB,EAAEC,aAAa,QAAQ,cAAc;AAGhE,MAAMC,cAAc,GAAGD,aAAa,CAACC,cAAc;AAEnD,OAAO,SAASC,IAAI,CAACC,KAAa,EAAEC,SAAiB,EAAEC,UAAkB,EAAE;EACzE,OAAOJ,cAAc,CAACK,SAAS,CAACH,KAAK,EAAEC,SAAS,EAAEC,UAAU,CAAC;AAC/D;AAEA,OAAO,SAASE,IAAI,CAACC,IAAY,EAAEC,YAA+B,EAAE;EAClE,OAAOR,cAAc,CAACM,IAAI,CAACC,IAAI,EAAEC,YAAY,CAAC;AAChD;AAEA,OAAO,MAAMC,kBAAkB,GAAG,IAAIX,kBAAkB,CAACE,cAAc,CAAC"}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=index.type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["index.type.ts"],"mappings":""}
@@ -1,2 +1,6 @@
1
- export declare function open(type: string): any;
1
+ import { NativeEventEmitter } from 'react-native';
2
+ import type { PayMEOpeningParam } from './index.type';
3
+ export declare function init(appId: string, publicKey: string, privateKey: string): any;
4
+ export declare function open(type: string, openingParam: PayMEOpeningParam): any;
5
+ export declare const PayMEMiniAppEvents: NativeEventEmitter;
2
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAIA,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,OAEhC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAiB,MAAM,cAAc,CAAC;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAItD,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,OAExE;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,iBAAiB,OAEjE;AAED,eAAO,MAAM,kBAAkB,oBAAyC,CAAC"}
@@ -0,0 +1,18 @@
1
+ type PayMEPaymentParam = {
2
+ amount: number;
3
+ transactionId: string;
4
+ note?: string;
5
+ };
6
+ export type PayMEOpeningParam = {
7
+ action: 'PAYME';
8
+ phone: string;
9
+ } | {
10
+ action: 'OPEN';
11
+ phone: string;
12
+ } | {
13
+ action: 'PAY';
14
+ phone: string;
15
+ data: PayMEPaymentParam;
16
+ };
17
+ export {};
18
+ //# sourceMappingURL=index.type.d.ts.map
@@ -0,0 +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;CACf,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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payme-mini-app",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "test",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -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", "1.0.12"
19
+ s.dependency "PayMEMiniApp", "1.0.15"
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.
package/src/index.tsx CHANGED
@@ -1,7 +1,14 @@
1
- import { NativeModules } from 'react-native';
1
+ import { NativeEventEmitter, NativeModules } from 'react-native';
2
+ import type { PayMEOpeningParam } from './index.type';
2
3
 
3
- const RNPayMEMiniApp = NativeModules.RNPayMEMiniApp
4
+ const RNPayMEMiniApp = NativeModules.RNPayMEMiniApp;
4
5
 
5
- export function open(type: string) {
6
- return RNPayMEMiniApp.open(type);
6
+ export function init(appId: string, publicKey: string, privateKey: string) {
7
+ return RNPayMEMiniApp.initPayME(appId, publicKey, privateKey);
7
8
  }
9
+
10
+ export function open(type: string, openingParam: PayMEOpeningParam) {
11
+ return RNPayMEMiniApp.open(type, openingParam);
12
+ }
13
+
14
+ export const PayMEMiniAppEvents = new NativeEventEmitter(RNPayMEMiniApp);
@@ -0,0 +1,10 @@
1
+ type PayMEPaymentParam = {
2
+ amount: number;
3
+ transactionId: string;
4
+ note?: string;
5
+ };
6
+
7
+ export type PayMEOpeningParam =
8
+ | { action: 'PAYME'; phone: string }
9
+ | { action: 'OPEN'; phone: string }
10
+ | { action: 'PAY'; phone: string; data: PayMEPaymentParam };