react-amwal-pay 0.1.12 → 0.1.14

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/README.md CHANGED
@@ -4,11 +4,78 @@ A React Native library for integrating Amwal Pay payment gateway into your React
4
4
 
5
5
  ## Installation
6
6
 
7
+ ### Prerequisites
8
+
9
+ - React Native project (0.79+)
10
+ - Node.js 18 or higher
11
+ - iOS: Xcode and CocoaPods installed
12
+ - Android: Android Studio and JDK installed
13
+
14
+ ### Step 1: Install the Package
15
+
7
16
  ```sh
8
17
  npm install react-amwal-pay
18
+ # or
19
+ yarn add react-amwal-pay
20
+ ```
21
+
22
+ ### Step 2: Configure React Native (Required)
23
+
24
+ Create or update `react-native.config.js` in your project root:
25
+
26
+ ```javascript
27
+ const path = require('path');
28
+ const pkg = require('react-amwal-pay/package.json');
29
+
30
+ module.exports = {
31
+ project: {
32
+ ios: {
33
+ automaticPodsInstallation: true,
34
+ },
35
+ },
36
+ dependencies: {
37
+ [pkg.name]: {
38
+ root: path.join(__dirname, 'node_modules/react-amwal-pay'),
39
+ platforms: {
40
+ ios: {},
41
+ android: {},
42
+ },
43
+ },
44
+ },
45
+ };
46
+ ```
47
+
48
+ ### Step 3: iOS Setup
49
+
50
+ #### 3.1 Update Podfile
51
+
52
+ Add the following configuration to your `ios/Podfile` inside the `post_install` block:
53
+
54
+ ```ruby
55
+ post_install do |installer|
56
+ react_native_post_install(installer, config[:reactNativePath])
57
+
58
+ # Set "Build Libraries for Distribution" to NO for amwalsdk
59
+ installer.pods_project.targets.each do |target|
60
+ if target.name == 'amwalsdk'
61
+ target.build_configurations.each do |config|
62
+ config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'NO'
63
+ config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'x86_64'
64
+ end
65
+ end
66
+ end
67
+ end
9
68
  ```
10
69
 
11
- ### iOS Installation Note
70
+ #### 3.2 Install Pods
71
+
72
+ ```bash
73
+ cd ios
74
+ pod install
75
+ cd ..
76
+ ```
77
+
78
+ #### 3.3 iOS Build Setting (Manual Step)
12
79
 
13
80
  After pod installation, you need to set "Build Libraries for Distribution" to NO in Xcode:
14
81
 
@@ -20,7 +87,7 @@ After pod installation, you need to set "Build Libraries for Distribution" to NO
20
87
 
21
88
  ![Build Libraries Setting](https://github.com/amwal-pay/AnwalPaySDKReactNative/raw/master/docs/images/ios_install_note.png)
22
89
 
23
- #### Configuring amwalsdk Subspec
90
+ #### 3.4 Configuring amwalsdk Subspec (Optional)
24
91
 
25
92
  The library uses amwalsdk as a dependency and supports both Release and Debug subspecs. By default, it uses the Debug subspec. To change this, you can set the `AMWAL_SUBSPEC` environment variable in your Podfile:
26
93
 
@@ -35,6 +102,45 @@ Or you can set it when running pod install:
35
102
  AMWAL_SUBSPEC=Release pod install
36
103
  ```
37
104
 
105
+ ### Step 4: Android Setup
106
+
107
+ No additional Android configuration is required. The SDK uses React Native's autolinking feature.
108
+
109
+ **Note:** The SDK requires minimum SDK 24 (Android 7.0). Ensure your `android/build.gradle` has:
110
+
111
+ ```gradle
112
+ minSdkVersion = 24
113
+ ```
114
+
115
+ ### Step 5: Clean and Rebuild
116
+
117
+ After installation, clean and rebuild your project:
118
+
119
+ ```bash
120
+ # iOS
121
+ cd ios
122
+ rm -rf Pods Podfile.lock
123
+ pod install
124
+ cd ..
125
+
126
+ # Android
127
+ cd android
128
+ ./gradlew clean
129
+ cd ..
130
+
131
+ # Rebuild your app
132
+ npm run ios
133
+ # or
134
+ npm run android
135
+ ```
136
+
137
+ ### Troubleshooting
138
+
139
+ - **Pods fail to install**: Clean pods and reinstall (`rm -rf Pods Podfile.lock && pod install`)
140
+ - **Linking issues**: Ensure `react-native.config.js` is in your project root
141
+ - **Build errors**: Clean build folders and rebuild your project
142
+ - **iOS build errors**: Verify that "Build Libraries for Distribution" is set to NO for amwalsdk target
143
+
38
144
  ## Usage
39
145
 
40
146
  ```js
@@ -166,6 +272,7 @@ The `AmwalPayConfig` interface includes the following properties:
166
272
  - `customerId`: (Optional) The customer's ID
167
273
  - `sessionToken`: (Optional) Your session token
168
274
  - `transactionId`: (Optional) Unique transaction identifier - auto-generated if not provided
275
+ - `merchantReference`: (Optional) Merchant reference for transaction tracking
169
276
  - `additionValues`: (Optional) Custom key-value pairs for SDK configuration (includes merchantIdentifier for Apple Pay)
170
277
  - `onCustomerId`: (Optional) Callback function for customer ID updates
171
278
  - `onResponse`: (Optional) Callback function for payment response
@@ -17,27 +17,38 @@ class ReactAmwalPayModule(reactContext: ReactApplicationContext) :
17
17
  return NAME
18
18
  }
19
19
 
20
-
21
-
22
- private fun sendEvent(eventName: String, params: WritableMap?) {
20
+ private fun sendEvent(eventName: String, params: Any?) {
23
21
  reactApplicationContext
24
22
  .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
25
23
  .emit(eventName, params)
26
24
  }
25
+
26
+ private fun emitOnResponse(params: WritableMap) {
27
+ sendEvent("onResponse", params)
28
+ }
29
+
30
+ private fun emitOnCustomerId(customerId: String?) {
31
+ sendEvent("onCustomerId", customerId)
32
+ }
33
+
34
+ override fun addListener(eventName: String?) {
35
+ // Required for RN built in Event Emitter Calls.
36
+ }
37
+
38
+ override fun removeListeners(count: Double) {
39
+ // Required for RN built in Event Emitter Calls.
40
+ }
27
41
 
28
42
  override fun initiate(config: ReadableMap) {
29
43
  Log.d(NAME, "initiate called")
30
44
  val activity = reactApplicationContext.currentActivity
31
45
  if (activity == null) {
32
- // Since we can't use Promise here (method signature must match the spec),
33
- // we'll send an error event
34
46
  val params = Arguments.createMap()
35
- params.putString("type", "onResponse")
36
47
  val errorData = Arguments.createMap()
37
48
  errorData.putString("status", "ERROR")
38
49
  errorData.putString("message", "Activity context is not available")
39
50
  params.putMap("data", errorData)
40
- sendEvent("AmwalPayEvent", params)
51
+ emitOnResponse(params)
41
52
  return
42
53
  }
43
54
 
@@ -102,12 +113,11 @@ class ReactAmwalPayModule(reactContext: ReactApplicationContext) :
102
113
  } catch (e: Exception) {
103
114
  Log.e(NAME, "Error initializing AmwalSDK", e)
104
115
  val params = Arguments.createMap()
105
- params.putString("type", "onResponse")
106
116
  val errorData = Arguments.createMap()
107
117
  errorData.putString("status", "ERROR")
108
118
  errorData.putString("message", e.message ?: "Unknown error")
109
119
  params.putMap("data", errorData)
110
- sendEvent("AmwalPayEvent", params)
120
+ emitOnResponse(params)
111
121
  }
112
122
  }
113
123
 
@@ -3,12 +3,10 @@
3
3
 
4
4
  @interface RCT_EXTERN_MODULE(ReactAmwalPay, RCTEventEmitter)
5
5
 
6
- RCT_EXTERN_METHOD(initiate:(NSDictionary *)config
7
- resolver:(RCTPromiseResolveBlock)resolve
8
- rejecter:(RCTPromiseRejectBlock)reject)
6
+ RCT_EXTERN_METHOD(initiate:(NSDictionary *)config)
9
7
 
10
- RCT_EXTERN_METHOD(onResponse:(RCTResponseSenderBlock)callback)
8
+ RCT_EXTERN_METHOD(addListener:(NSString *)eventName)
11
9
 
12
- RCT_EXTERN_METHOD(onCustomerId:(RCTResponseSenderBlock)callback)
10
+ RCT_EXTERN_METHOD(removeListeners:(double)count)
13
11
 
14
12
  @end
@@ -1,11 +1,118 @@
1
1
  import Foundation
2
2
  import amwalsdk
3
3
  import React
4
+ import UIKit
5
+
6
+ // MARK: - Fix UIViewController presentation for share sheets
7
+ public extension UIViewController {
8
+ static let swizzlePresentOnce: Void = {
9
+ let originalSelector = #selector(UIViewController.present(_:animated:completion:))
10
+ let swizzledSelector = #selector(UIViewController.swizzled_present(_:animated:completion:))
11
+
12
+ guard let originalMethod = class_getInstanceMethod(UIViewController.self, originalSelector),
13
+ let swizzledMethod = class_getInstanceMethod(UIViewController.self, swizzledSelector) else {
14
+ return
15
+ }
16
+
17
+ method_exchangeImplementations(originalMethod, swizzledMethod)
18
+ }()
19
+
20
+ @objc dynamic func swizzled_present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) {
21
+ // Check if this view controller's view is in the window hierarchy
22
+ if self.view.window == nil {
23
+ print("⚠️ Attempting to present on VC not in hierarchy, finding correct presenter...")
24
+ // Find the correct view controller to present from
25
+ if let topVC = UIViewController.getTopMostViewController() {
26
+ topVC.swizzled_present(viewControllerToPresent, animated: flag, completion: completion)
27
+ return
28
+ }
29
+ }
30
+
31
+ // Check if we're already presenting something
32
+ if self.presentedViewController != nil {
33
+ print("⚠️ Already presenting, dismissing first...")
34
+ self.dismiss(animated: false) { [weak self] in
35
+ self?.swizzled_present(viewControllerToPresent, animated: flag, completion: completion)
36
+ }
37
+ return
38
+ }
39
+
40
+ // Call original implementation
41
+ self.swizzled_present(viewControllerToPresent, animated: flag, completion: completion)
42
+ }
43
+
44
+ static func getTopMostViewController() -> UIViewController? {
45
+ var topController: UIViewController?
46
+
47
+ if #available(iOS 13.0, *) {
48
+ let keyWindow = UIApplication.shared.connectedScenes
49
+ .compactMap { $0 as? UIWindowScene }
50
+ .flatMap { $0.windows }
51
+ .first { $0.isKeyWindow }
52
+ topController = keyWindow?.rootViewController
53
+ } else {
54
+ topController = UIApplication.shared.keyWindow?.rootViewController
55
+ }
56
+
57
+ while let presented = topController?.presentedViewController {
58
+ topController = presented
59
+ }
60
+
61
+ return topController
62
+ }
63
+ }
4
64
 
5
65
  @objc(ReactAmwalPay)
6
- class ReactAmwalPay: RCTEventEmitter {
66
+ open class ReactAmwalPay: RCTEventEmitter {
7
67
  private var hasListeners = false
8
68
 
69
+ // Initialize swizzling when the class is first loaded
70
+ private static let initializeSwizzling: Void = {
71
+ _ = UIViewController.swizzlePresentOnce
72
+ }()
73
+
74
+ // Initialize swizzling when the module is loaded
75
+ public override init() {
76
+ super.init()
77
+ _ = ReactAmwalPay.initializeSwizzling
78
+ }
79
+
80
+ open override func supportedEvents() -> [String]! {
81
+ return ["onResponse", "onCustomerId"]
82
+ }
83
+
84
+ open override func startObserving() {
85
+ print("🔴 startObserving called - setting hasListeners = true")
86
+ hasListeners = true
87
+ }
88
+
89
+ open override func stopObserving() {
90
+ print("🔴 stopObserving called - setting hasListeners = false")
91
+ hasListeners = false
92
+ }
93
+
94
+ private func emitOnResponse(_ params: [String: Any]) {
95
+ print("🔴 emitOnResponse called with params: \(params)")
96
+ print("🔴 hasListeners: \(hasListeners)")
97
+ if hasListeners {
98
+ print("🔴 Sending onResponse event to JS")
99
+ sendEvent(withName: "onResponse", body: params)
100
+ } else {
101
+ print("🔴 NOT sending - no listeners!")
102
+ }
103
+ }
104
+
105
+ private func emitOnCustomerId(_ customerId: String?) {
106
+ print("🔴 emitOnCustomerId called with: \(customerId ?? "nil")")
107
+ print("🔴 hasListeners: \(hasListeners)")
108
+ if hasListeners {
109
+ print("🔴 Sending onCustomerId event to JS")
110
+ sendEvent(withName: "onCustomerId", body: customerId)
111
+ } else {
112
+ print("🔴 NOT sending - no listeners!")
113
+ }
114
+ }
115
+
9
116
  private func mapEnvironment(environment: String) -> Config.Environment {
10
117
  switch environment {
11
118
  case "PROD": return .PROD
@@ -39,8 +146,6 @@ class ReactAmwalPay: RCTEventEmitter {
39
146
  }
40
147
  }
41
148
 
42
- private var onResponseCallback: RCTResponseSenderBlock?
43
- private var onCustomerIdCallback: RCTResponseSenderBlock?
44
149
  private func prepareConfig(config: [String: Any]) -> Config {
45
150
  // Handle additionValues
46
151
  var additionValues: [String: String] = Config.generateDefaultAdditionValues()
@@ -50,7 +155,7 @@ class ReactAmwalPay: RCTEventEmitter {
50
155
  additionValues[key] = value
51
156
  }
52
157
  }
53
-
158
+
54
159
  return Config(
55
160
  environment: mapEnvironment(environment: config["environment"] as? String ?? "PROD"),
56
161
  sessionToken: config["sessionToken"] as? String ?? "",
@@ -68,56 +173,91 @@ class ReactAmwalPay: RCTEventEmitter {
68
173
  }
69
174
 
70
175
  @objc
71
- func initiate(_ config: [String: Any],
72
- resolver resolve: @escaping RCTPromiseResolveBlock,
73
- rejecter reject: @escaping RCTPromiseRejectBlock) {
176
+ open func initiate(_ config: [String: Any]) {
74
177
  DispatchQueue.main.async {
75
178
  do {
76
179
  let sdkConfig = self.prepareConfig(config: config)
77
180
  let sdk = AmwalSDK()
78
-
181
+
79
182
  guard let rootVC = UIApplication.shared.keyWindow?.rootViewController else {
80
- reject("NO_ROOT_VC", "No root view controller found", nil)
183
+ let errorData: [String: Any] = [
184
+ "data": [
185
+ "status": "ERROR",
186
+ "message": "No root view controller found"
187
+ ]
188
+ ]
189
+ self.emitOnResponse(errorData)
81
190
  return
82
191
  }
83
-
192
+
84
193
  let sdkVC = try sdk.createViewController(
85
194
  config: sdkConfig,
86
195
  onResponse: { [weak self] response in
87
- self?.onResponseCallback?([[
88
- "status": response != nil ? "success" : "error",
89
- "message": response != nil ? "Transaction completed" : "Transaction failed",
90
- "data": response ?? ""
91
- ]])
92
- },
196
+ print("🟠 SDK onResponse callback fired!")
197
+ print("🟠 Response type: \(type(of: response))")
198
+ print("🟠 Response value: \(response ?? "nil")")
199
+
200
+ // The SDK returns a JSON string, we need to parse it
201
+ if let responseString = response as? String,
202
+ let data = responseString.data(using: .utf8),
203
+ let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
204
+ print("🟠 Successfully parsed JSON string to dictionary")
205
+ self?.emitOnResponse(json)
206
+ } else if let responseDict = response as? [String: Any] {
207
+ print("🟠 Response is already a dictionary")
208
+ self?.emitOnResponse(responseDict)
209
+ } else {
210
+ print("🟠 Could not parse response, sending as-is")
211
+ let errorData: [String: Any] = [
212
+ "status": "error",
213
+ "message": "Invalid response format",
214
+ "rawResponse": String(describing: response)
215
+ ]
216
+ self?.emitOnResponse(errorData)
217
+ }
218
+ },
93
219
  onCustomerId: { [weak self] customerId in
94
- self?.onCustomerIdCallback?([customerId])
95
- }
220
+ print("🟠 SDK onCustomerId callback fired with: \(customerId ?? "nil")")
221
+ self?.emitOnCustomerId(customerId)
222
+ }
96
223
  )
97
-
224
+
225
+ print("🟠 SDK ViewController created successfully")
226
+ print("🟠 About to present SDK ViewController...")
227
+
98
228
  // Present modally (critical missing piece)
99
229
  rootVC.present(sdkVC, animated: true)
100
-
101
- resolve(true)
102
230
  } catch {
103
231
  print("Presentation failed: \(error.localizedDescription)")
104
- reject("PRESENTATION_ERROR", error.localizedDescription, error)
232
+ let errorData: [String: Any] = [
233
+ "data": [
234
+ "status": "ERROR",
235
+ "message": error.localizedDescription
236
+ ]
237
+ ]
238
+ self.emitOnResponse(errorData)
105
239
  }
106
240
  }
107
241
  }
108
242
 
109
- @objc
110
- func onResponse(_ callback: @escaping RCTResponseSenderBlock) {
111
- onResponseCallback = callback
112
- }
113
-
114
- @objc
115
- func onCustomerId(_ callback: @escaping RCTResponseSenderBlock) {
116
- onCustomerIdCallback = callback
117
- }
118
-
119
-
120
- override static func requiresMainQueueSetup() -> Bool {
243
+ @objc
244
+ open override func addListener(_ eventName: String) {
245
+ super.addListener(eventName)
246
+ print("🔴 addListener called for: \(eventName)")
247
+ if !hasListeners {
248
+ hasListeners = true
249
+ print("🔴 Set hasListeners = true")
250
+ }
251
+ }
252
+
253
+ @objc
254
+ open override func removeListeners(_ count: Double) {
255
+ super.removeListeners(count)
256
+ print("🔴 removeListeners called with count: \(count)")
257
+ }
258
+
259
+ @objc
260
+ public override static func requiresMainQueueSetup() -> Bool {
121
261
  return true
122
262
  }
123
263
  }
@@ -28,7 +28,9 @@ class AmwalPaySDK {
28
28
  const networkClient = NetworkClient.getInstance();
29
29
 
30
30
  // Fetch session token
31
+ console.log('Fetching session token for environment:', config.environment);
31
32
  const sessionToken = await networkClient.fetchSessionToken(config.environment, config.merchantId, config.customerId, config.secureHash);
33
+ console.log('Session token result:', sessionToken ? 'Success' : 'Failed');
32
34
  if (!sessionToken) {
33
35
  // If session token is null, the error has already been shown by NetworkClient
34
36
  return;
@@ -41,6 +43,7 @@ class AmwalPaySDK {
41
43
  };
42
44
 
43
45
  // Initiate the payment process
46
+ console.log('Initiating native payment with config:', JSON.stringify(completeConfig));
44
47
  initiate(completeConfig);
45
48
  } catch (error) {
46
49
  console.error('Error starting payment:', error);
@@ -58,14 +61,28 @@ class AmwalPaySDK {
58
61
  setupEventListeners(config) {
59
62
  // Remove any existing listeners
60
63
  this.removeEventListeners();
64
+ console.log('🟢 Setting up event listeners...');
65
+ console.log('🟢 onResponse callback exists?', typeof config.onResponse === 'function');
66
+ console.log('🟢 onCustomerId callback exists?', typeof config.onCustomerId === 'function');
61
67
  this.onResponseSubscription = onResponse(response => {
68
+ console.log('🟢 SDK onResponse listener triggered with:', response);
62
69
  console.log('Received AmwalPayResponse:', response);
63
- config.onResponse(response);
70
+ if (config.onResponse) {
71
+ config.onResponse(response);
72
+ } else {
73
+ console.error('❌ config.onResponse is not a function!');
74
+ }
64
75
  });
65
76
  this.onCustomerIdSubscription = onCustomerId(customerId => {
77
+ console.log('🟢 SDK onCustomerId listener triggered with:', customerId);
66
78
  console.log('Received customerId:', customerId);
67
- config.onCustomerId(customerId);
79
+ if (config.onCustomerId) {
80
+ config.onCustomerId(customerId);
81
+ } else {
82
+ console.error('❌ config.onCustomerId is not a function!');
83
+ }
68
84
  });
85
+ console.log('🟢 Event listeners set up complete');
69
86
  }
70
87
 
71
88
  /**
@@ -1 +1 @@
1
- {"version":3,"names":["initiate","onCustomerId","onResponse","NetworkClient","AmwalPaySDK","onResponseSubscription","onCustomerIdSubscription","constructor","getInstance","instance","startPayment","config","setupEventListeners","networkClient","sessionToken","fetchSessionToken","environment","merchantId","customerId","secureHash","completeConfig","error","console","dispose","removeEventListeners","response","log","remove"],"sourceRoot":"../../src","sources":["AmwalPaySDK.ts"],"mappings":";;AAAA,SAASA,QAAQ,EAAEC,YAAY,EAAEC,UAAU,QAA6B,YAAS;AACjF,OAAOC,aAAa,MAAM,4BAAyB;AAInD,MAAMC,WAAW,CAAC;EAGRC,sBAAsB,GAA2B,IAAI;EAErDC,wBAAwB,GAA2B,IAAI;EAEvDC,WAAWA,CAAA,EAAG;IACpB;EAAA;EAIF,OAAOC,WAAWA,CAAA,EAAgB;IAChC,IAAI,CAACJ,WAAW,CAACK,QAAQ,EAAE;MACzBL,WAAW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AAC;IACjC,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;EACUM,oBAAoBA,CAAA,EAAS;IACnC,IAAI,CAACnB,sBAAsB,EAAEsB,MAAM,CAAC,CAAC;IACrC,IAAI,CAACrB,wBAAwB,EAAEqB,MAAM,CAAC,CAAC;IACvC,IAAI,CAACtB,sBAAsB,GAAG,IAAI;IAClC,IAAI,CAACC,wBAAwB,GAAG,IAAI;EACtC;AACF;AAEA,eAAeF,WAAW","ignoreList":[]}
1
+ {"version":3,"names":["initiate","onCustomerId","onResponse","NetworkClient","AmwalPaySDK","onResponseSubscription","onCustomerIdSubscription","constructor","getInstance","instance","startPayment","config","setupEventListeners","networkClient","console","log","environment","sessionToken","fetchSessionToken","merchantId","customerId","secureHash","completeConfig","JSON","stringify","error","dispose","removeEventListeners","response","remove"],"sourceRoot":"../../src","sources":["AmwalPaySDK.ts"],"mappings":";;AAAA,SAASA,QAAQ,EAAEC,YAAY,EAAEC,UAAU,QAA6B,YAAS;AACjF,OAAOC,aAAa,MAAM,4BAAyB;AAInD,MAAMC,WAAW,CAAC;EAGRC,sBAAsB,GAA6B,IAAI;EAEvDC,wBAAwB,GAA6B,IAAI;EAEzDC,WAAWA,CAAA,EAAG;IACpB;EAAA;EAIF,OAAOC,WAAWA,CAAA,EAAgB;IAChC,IAAI,CAACJ,WAAW,CAACK,QAAQ,EAAE;MACzBL,WAAW,CAACK,QAAQ,GAAG,IAAIL,WAAW,CAAC,CAAC;IAC1C;IACA,OAAOA,WAAW,CAACK,QAAQ;EAC7B;;EAEA;AACF;AACA;AACA;EACE,MAAMC,YAAYA,CAACC,MAA4C,EAAiB;IAC9E,IAAI;MACF;MACA,IAAI,CAACC,mBAAmB,CAACD,MAAM,CAAC;;MAEhC;MACA,MAAME,aAAa,GAAGV,aAAa,CAACK,WAAW,CAAC,CAAC;;MAEjD;MACAM,OAAO,CAACC,GAAG,CAAC,yCAAyC,EAAEJ,MAAM,CAACK,WAAW,CAAC;MAC1E,MAAMC,YA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UAAU,CAAC0B,QAAQ,CAAC;MAC7B,CAAC,MAAM;QACLd,OAAO,CAACW,KAAK,CAAC,wCAAwC,CAAC;MACzD;IACF,CAAC,CAAC;IAEF,IAAI,CAACnB,wBAAwB,GAAGL,YAAY,CAAEmB,UAAU,IAAK;MAC3DN,OAAO,CAACC,GAAG,CAAC,8CAA8C,EAAEK,UAAU,CAAC;MACvEN,OAAO,CAACC,GAAG,CAAC,sBAAsB,EAAEK,UAAU,CAAC;MAC/C,IAAIT,MAAM,CAACV,YAAY,EAAE;QACvBU,MAAM,CAACV,YAAY,CAACmB,UAAU,CAAC;MACjC,CAAC,MAAM;QACLN,OAAO,CAACW,KAAK,CAAC,0CAA0C,CAAC;MAC3D;IACF,CAAC,CAAC;IAEFX,OAAO,CAACC,GAAG,CAAC,oCAAoC,CAAC;EACnD;;EAEA;AACF;AACA;EACUY,oBAAoBA,CAAA,EAAS;IACnC,IAAI,CAACtB,sBAAsB,EAAEwB,MAAM,CAAC,CAAC;IACrC,IAAI,CAACvB,wBAAwB,EAAEuB,MAAM,CAAC,CAAC;IACvC,IAAI,CAACxB,sBAAsB,GAAG,IAAI;IAClC,IAAI,CAACC,wBAAwB,GAAG,IAAI;EACtC;AACF;AAEA,eAAeF,WAAW","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["TurboModuleRegistry","Environment","Currency","TransactionType","getEnforcing"],"sourceRoot":"../../src","sources":["NativeReactAmwalPay.ts"],"mappings":";;AACA,SAASA,mBAAmB,QAAQ,cAAc;AAGlD,WAAYC,WAAW,0BAAXA,WAAW;EAAXA,WAAW;EAAXA,WAAW;EAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA;AAMvB,WAAYC,QAAQ,0BAARA,QAAQ;EAARA,QAAQ;EAAA,OAARA,QAAQ;AAAA;AAIpB,WAAYC,eAAe,0BAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA;;AAY3B;;AAmBA;;AAwBA,eAAeH,mBAAmB,CAACI,YAAY,CAAO,eAAe,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["TurboModuleRegistry","Environment","Currency","TransactionType","getEnforcing"],"sourceRoot":"../../src","sources":["NativeReactAmwalPay.ts"],"mappings":";;AACA,SAASA,mBAAmB,QAAQ,cAAc;AAElD,WAAYC,WAAW,0BAAXA,WAAW;EAAXA,WAAW;EAAXA,WAAW;EAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA;AAMvB,WAAYC,QAAQ,0BAARA,QAAQ;EAARA,QAAQ;EAAA,OAARA,QAAQ;AAAA;AAIpB,WAAYC,eAAe,0BAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA;;AAY3B;;AAmBA;;AAwBA,eAAeH,mBAAmB,CAACI,YAAY,CAAO,eAAe,CAAC","ignoreList":[]}
@@ -3,8 +3,10 @@
3
3
  import ReactAmwalPay, { Environment, Currency, TransactionType } from "./NativeReactAmwalPay.js";
4
4
  import AmwalPaySDK from "./AmwalPaySDK.js";
5
5
  import { UuidUtil } from "./utils/UuidUtil.js";
6
- // Create an event emitter for the native module
6
+ import { NativeEventEmitter } from 'react-native';
7
7
 
8
+ // Create an event emitter for the native module
9
+ const eventEmitter = new NativeEventEmitter(ReactAmwalPay);
8
10
  export function initiate(config) {
9
11
  // Create default additionValues with merchantIdentifier for iOS if not provided
10
12
  const defaultAdditionValues = {
@@ -34,10 +36,10 @@ export function initiate(config) {
34
36
  ReactAmwalPay.initiate(nativeConfig);
35
37
  }
36
38
  export function onResponse(callback) {
37
- return ReactAmwalPay.onResponse(callback);
39
+ return eventEmitter.addListener('onResponse', callback);
38
40
  }
39
41
  export function onCustomerId(callback) {
40
- return ReactAmwalPay.onCustomerId(callback);
42
+ return eventEmitter.addListener('onCustomerId', callback);
41
43
  }
42
44
  export { Environment, Currency, TransactionType, AmwalPaySDK, UuidUtil };
43
45
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ReactAmwalPay","Environment","Currency","TransactionType","AmwalPaySDK","UuidUtil","initiate","config","defaultAdditionValues","merchantIdentifier","finalAdditionValues","additionValues","nativeConfig","environment","secureHash","currency","amount","merchantId","terminalId","locale","customerId","transactionType","sessionToken","transactionId","generateTransactionId","merchantReference","onResponse","callback","onCustomerId"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,aAAa,IAClBC,WAAW,EACXC,QAAQ,EACRC,eAAe,QAIV,0BAAuB;AAC9B,OAAOC,WAAW,MAAM,kBAAe;AACvC,SAASC,QAAQ,QAAQ,qBAAkB;AAG3C;;AAEA,OAAO,SAASC,QAAQA,CAACC,MAAsB,EAAQ;EACrD;EACA,MAAMC,qBAAqB,GAAG;IAC5BC,kBAAkB,EAAE;EACtB,CAAC;EAED,MAAMC,mBAAmB,GAAG;IAC1B,GAAGF,qBAAqB;IACxB,GAAGD,MAAM,CAACI;EACZ,CAAC;EAED,MAAMC,YAAkC,GAAG;IACzCC,WAAW,EAAEN,MAAM,CAACM,WAAW;IAC/BC,UAAU,EAAEP,MAAM,CAACO,UAAU;IAC7BC,QAAQ,EAAER,MAAM,CAACQ,QAAQ;IACzBC,MAAM,EAAET,MAAM,CAACS,MAAM;IACrBC,UAAU,EAAEV,MAAM,CAACU,UAAU;IAC7BC,UAAU,EAAEX,MAAM,CAACW,UAAU;IAC7BC,MAAM,EAAEZ,MAAM,CAACY,MAAM;IACrBC,UAAU,EAAEb,MAAM,CAACa,UAAU;IAC7BC,eAAe,EAAEd,MAAM,CAACc,eAAe;IACvCC,YAAY,EAAEf,MAAM,CAACe,YAAY;IACjCC,aAAa,EAAEhB,MAAM,CAACgB,aAAa,IAAIlB,QAAQ,CAACmB,qBAAqB,CAAC,CAAC;IACvEb,cAAc,EAAED,mBAAmB;IACnCe,iBAAiB,EAAElB,MAAM,CAACkB;EAC5B,CAAC;;EAED;EACAzB,aAAa,CAACM,QAAQ,CAACM,YAAY,CAAC;AACtC;AAEA,OAAO,SAASc,UAAUA,CAACC,QAA8C,EAAoB;EAC3F,OAAO3B,aAAa,CAAC0B,UAAU,CAACC,QAAQ,CAAC;AAC3C;AACA,OAAO,SAASC,YAAYA,CAACD,QAAsC,EAAoB;EACrF,OAAO3B,aAAa,CAAC4B,YAAY,CAACD,QAAQ,CAAC;AAC7C;AAEA,SACE1B,WAAW,EACXC,QAAQ,EACRC,eAAe,EAGfC,WAAW,EACXC,QAAQ","ignoreList":[]}
1
+ {"version":3,"names":["ReactAmwalPay","Environment","Currency","TransactionType","AmwalPaySDK","UuidUtil","NativeEventEmitter","eventEmitter","initiate","config","defaultAdditionValues","merchantIdentifier","finalAdditionValues","additionValues","nativeConfig","environment","secureHash","currency","amount","merchantId","terminalId","locale","customerId","transactionType","sessionToken","transactionId","generateTransactionId","merchantReference","onResponse","callback","addListener","onCustomerId"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,aAAa,IAClBC,WAAW,EACXC,QAAQ,EACRC,eAAe,QAIV,0BAAuB;AAC9B,OAAOC,WAAW,MAAM,kBAAe;AACvC,SAASC,QAAQ,QAAQ,qBAAkB;AAC3C,SACEC,kBAAkB,QAEb,cAAc;;AAErB;AACA,MAAMC,YAAY,GAAG,IAAID,kBAAkB,CAACN,aAAoB,CAAC;AAEjE,OAAO,SAASQ,QAAQA,CAACC,MAAsB,EAAQ;EACrD;EACA,MAAMC,qBAAqB,GAAG;IAC5BC,kBAAkB,EAAE;EACtB,CAAC;EAED,MAAMC,mBAAmB,GAAG;IAC1B,GAAGF,qBAAqB;IACxB,GAAGD,MAAM,CAACI;EACZ,CAAC;EAED,MAAMC,YAAkC,GAAG;IACzCC,WAAW,EAAEN,MAAM,CAACM,WAAW;IAC/BC,UAAU,EAAEP,MAAM,CAACO,UAAU;IAC7BC,QAAQ,EAAER,MAAM,CAACQ,QAAQ;IACzBC,MAAM,EAAET,MAAM,CAACS,MAAM;IACrBC,UAAU,EAAE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;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAe3B;;OAEG;IACH,OAAO,CAAC,oBAAoB;CAM7B;AAED,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"AmwalPaySDK.d.ts","sourceRoot":"","sources":["../../../src/AmwalPaySDK.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAKlF,cAAM,WAAW;IACf,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAc;IAErC,OAAO,CAAC,sBAAsB,CAAkC;IAEhE,OAAO,CAAC,wBAAwB,CAAkC;IAElE,OAAO;IAKP,MAAM,CAAC,WAAW,IAAI,WAAW;IAOjC;;;OAGG;IACG,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,cAAc,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAsC/E,OAAO,IAAI,IAAI;IAKf;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IA+B3B;;OAEG;IACH,OAAO,CAAC,oBAAoB;CAM7B;AAED,eAAe,WAAW,CAAC"}
@@ -1,5 +1,4 @@
1
1
  import type { TurboModule } from 'react-native';
2
- import type { EventEmitter } from 'react-native/Libraries/Types/CodegenTypes';
3
2
  export declare enum Environment {
4
3
  SIT = "SIT",
5
4
  UAT = "UAT",
@@ -56,8 +55,8 @@ export interface AmwalPayNativeConfig {
56
55
  }
57
56
  export interface Spec extends TurboModule {
58
57
  initiate(config: AmwalPayNativeConfig): void;
59
- onResponse: EventEmitter<AmwalPayResponse>;
60
- onCustomerId: EventEmitter<string>;
58
+ addListener(eventName: string): void;
59
+ removeListeners(count: number): void;
61
60
  }
62
61
  declare const _default: Spec;
63
62
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"NativeReactAmwalPay.d.ts","sourceRoot":"","sources":["../../../src/NativeReactAmwalPay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,O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
  import AmwalPaySDK from './AmwalPaySDK';
3
3
  import { UuidUtil } from './utils/UuidUtil';
4
- import type { EventSubscription } from 'react-native';
4
+ import { type EventSubscription } from 'react-native';
5
5
  export declare function initiate(config: AmwalPayConfig): void;
6
6
  export declare function onResponse(callback: (response: AmwalPayResponse) => void): EventSubscription;
7
7
  export declare function onCustomerId(callback: (customerId: string) => void): EventSubscription;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAsB,EACpB,WAAW,EACX,QAAQ,EACR,eAAe,EACf,KAAK,gBAAgB,EACrB,KAAK,cAAc,EAEpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAItD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CA6BrD;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,IAAI,GAAE,iBAAiB,CAE3F;AACD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,GAAE,iBAAiB,CAErF;AAED,OAAO,EACL,WAAW,EACX,QAAQ,EACR,eAAe,EACf,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,WAAW,EACX,QAAQ,GACT,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAsB,EACpB,WAAW,EACX,QAAQ,EACR,eAAe,EACf,KAAK,gBAAgB,EACrB,KAAK,cAAc,EAEpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,cAAc,CAAC;AAKtB,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CA6BrD;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,IAAI,GAAG,iBAAiB,CAE5F;AACD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,GAAG,iBAAiB,CAEtF;AAED,OAAO,EACL,WAAW,EACX,QAAQ,EACR,eAAe,EACf,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,WAAW,EACX,QAAQ,GACT,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-amwal-pay",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "amwal pay",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -1,27 +1,27 @@
1
1
  import { initiate, onCustomerId, onResponse, type AmwalPayConfig } from './index';
2
2
  import NetworkClient from './network/NetworkClient';
3
- import { type EventSubscription } from 'react-native';
3
+ import { type EventSubscription } from 'react-native';
4
4
 
5
5
 
6
6
  class AmwalPaySDK {
7
7
  private static instance: AmwalPaySDK;
8
8
 
9
- private onResponseSubscription: EventSubscription|null = null;
9
+ private onResponseSubscription: EventSubscription | null = null;
10
+
11
+ private onCustomerIdSubscription: EventSubscription | null = null;
10
12
 
11
- private onCustomerIdSubscription: EventSubscription|null = null;
12
-
13
13
  private constructor() {
14
14
  // Initialize the event emitter
15
-
15
+
16
16
  }
17
-
17
+
18
18
  static getInstance(): AmwalPaySDK {
19
19
  if (!AmwalPaySDK.instance) {
20
20
  AmwalPaySDK.instance = new AmwalPaySDK();
21
21
  }
22
22
  return AmwalPaySDK.instance;
23
23
  }
24
-
24
+
25
25
  /**
26
26
  * Initiates the payment process by first fetching a session token and then starting the payment flow
27
27
  * @param config The payment configuration
@@ -30,30 +30,34 @@ class AmwalPaySDK {
30
30
  try {
31
31
  // Set up event listeners before starting the payment process
32
32
  this.setupEventListeners(config);
33
-
33
+
34
34
  // Get network client instance
35
35
  const networkClient = NetworkClient.getInstance();
36
-
36
+
37
37
  // Fetch session token
38
+ console.log('Fetching session token for environment:', config.environment);
38
39
  const sessionToken = await networkClient.fetchSessionToken(
39
40
  config.environment,
40
41
  config.merchantId,
41
42
  config.customerId,
42
43
  config.secureHash
43
44
  );
44
-
45
+
46
+ console.log('Session token result:', sessionToken ? 'Success' : 'Failed');
47
+
45
48
  if (!sessionToken) {
46
49
  // If session token is null, the error has already been shown by NetworkClient
47
50
  return;
48
51
  }
49
-
52
+
50
53
  // Create complete config with session token
51
54
  const completeConfig: AmwalPayConfig = {
52
55
  ...config,
53
56
  sessionToken
54
57
  };
55
-
58
+
56
59
  // Initiate the payment process
60
+ console.log('Initiating native payment with config:', JSON.stringify(completeConfig));
57
61
  initiate(completeConfig);
58
62
  } catch (error) {
59
63
  console.error('Error starting payment:', error);
@@ -64,7 +68,7 @@ class AmwalPaySDK {
64
68
  // Remove all event listeners
65
69
  this.removeEventListeners();
66
70
  }
67
-
71
+
68
72
  /**
69
73
  * Sets up event listeners for AmwalPay events
70
74
  * @param config The payment configuration containing callback functions
@@ -72,18 +76,34 @@ class AmwalPaySDK {
72
76
  private setupEventListeners(config: Omit<AmwalPayConfig, 'sessionToken'>): void {
73
77
  // Remove any existing listeners
74
78
  this.removeEventListeners();
75
-
79
+
80
+ console.log('🟢 Setting up event listeners...');
81
+ console.log('🟢 onResponse callback exists?', typeof config.onResponse === 'function');
82
+ console.log('🟢 onCustomerId callback exists?', typeof config.onCustomerId === 'function');
83
+
76
84
  this.onResponseSubscription = onResponse((response) => {
85
+ console.log('🟢 SDK onResponse listener triggered with:', response);
77
86
  console.log('Received AmwalPayResponse:', response);
78
- config.onResponse(response);
87
+ if (config.onResponse) {
88
+ config.onResponse(response);
89
+ } else {
90
+ console.error('❌ config.onResponse is not a function!');
91
+ }
79
92
  });
80
93
 
81
94
  this.onCustomerIdSubscription = onCustomerId((customerId) => {
95
+ console.log('🟢 SDK onCustomerId listener triggered with:', customerId);
82
96
  console.log('Received customerId:', customerId);
83
- config.onCustomerId(customerId);
97
+ if (config.onCustomerId) {
98
+ config.onCustomerId(customerId);
99
+ } else {
100
+ console.error('❌ config.onCustomerId is not a function!');
101
+ }
84
102
  });
103
+
104
+ console.log('🟢 Event listeners set up complete');
85
105
  }
86
-
106
+
87
107
  /**
88
108
  * Removes all event listeners
89
109
  */
@@ -1,6 +1,5 @@
1
1
  import type { TurboModule } from 'react-native';
2
2
  import { TurboModuleRegistry } from 'react-native';
3
- import type { EventEmitter } from 'react-native/Libraries/Types/CodegenTypes';
4
3
 
5
4
  export enum Environment {
6
5
  SIT = 'SIT',
@@ -13,9 +12,9 @@ export enum Currency {
13
12
  }
14
13
 
15
14
  export enum TransactionType {
16
- NFC= 'NFC' ,
17
- CARD_WALLET= 'CARD_WALLET',
18
- APPLE_PAY= 'APPLE_PAY'
15
+ NFC = 'NFC',
16
+ CARD_WALLET = 'CARD_WALLET',
17
+ APPLE_PAY = 'APPLE_PAY'
19
18
  }
20
19
 
21
20
  export interface AmwalPayResponse {
@@ -63,8 +62,8 @@ export interface AmwalPayNativeConfig {
63
62
  export interface Spec extends TurboModule {
64
63
  // Change the parameter type to AmwalPayNativeConfig
65
64
  initiate(config: AmwalPayNativeConfig): void;
66
- onResponse: EventEmitter<AmwalPayResponse>,
67
- onCustomerId: EventEmitter<string>,
65
+ addListener(eventName: string): void;
66
+ removeListeners(count: number): void;
68
67
  }
69
68
 
70
69
  export default TurboModuleRegistry.getEnforcing<Spec>('ReactAmwalPay');
package/src/index.tsx CHANGED
@@ -8,16 +8,20 @@ import ReactAmwalPay, {
8
8
  } from './NativeReactAmwalPay';
9
9
  import AmwalPaySDK from './AmwalPaySDK';
10
10
  import { UuidUtil } from './utils/UuidUtil';
11
- import type { EventSubscription } from 'react-native';
11
+ import {
12
+ NativeEventEmitter,
13
+ type EventSubscription,
14
+ } from 'react-native';
12
15
 
13
16
  // Create an event emitter for the native module
17
+ const eventEmitter = new NativeEventEmitter(ReactAmwalPay as any);
14
18
 
15
19
  export function initiate(config: AmwalPayConfig): void {
16
20
  // Create default additionValues with merchantIdentifier for iOS if not provided
17
21
  const defaultAdditionValues = {
18
22
  merchantIdentifier: 'merchant.applepay.amwalpay',
19
23
  };
20
-
24
+
21
25
  const finalAdditionValues = {
22
26
  ...defaultAdditionValues,
23
27
  ...config.additionValues,
@@ -43,11 +47,11 @@ export function initiate(config: AmwalPayConfig): void {
43
47
  ReactAmwalPay.initiate(nativeConfig);
44
48
  }
45
49
 
46
- export function onResponse(callback: (response: AmwalPayResponse) => void):EventSubscription {
47
- return ReactAmwalPay.onResponse(callback);
50
+ export function onResponse(callback: (response: AmwalPayResponse) => void): EventSubscription {
51
+ return eventEmitter.addListener('onResponse', callback);
48
52
  }
49
- export function onCustomerId(callback: (customerId: string) => void):EventSubscription {
50
- return ReactAmwalPay.onCustomerId(callback);
53
+ export function onCustomerId(callback: (customerId: string) => void): EventSubscription {
54
+ return eventEmitter.addListener('onCustomerId', callback);
51
55
  }
52
56
 
53
57
  export {