react-native-cashfree-pg-sdk 2.1.8 → 2.1.9-dev.0

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.
@@ -26,7 +26,7 @@ class CashfreeEmitter {
26
26
 
27
27
  /// All Events which must be support by React Native.
28
28
  lazy var allEvents: [String] = {
29
- var allEventNames: [String] = ["cfSuccess", "cfFailure", "cfEvent"]
29
+ var allEventNames: [String] = ["cfSuccess", "cfFailure", "cfEvent", "cfUpiApps"]
30
30
 
31
31
  // Append all events here
32
32
 
@@ -8,6 +8,9 @@ RCT_EXTERN_METHOD(doPayment:(NSString)paymentObject)
8
8
  RCT_EXTERN_METHOD(doUPIPayment:(NSString)paymentObject)
9
9
 
10
10
  RCT_EXTERN_METHOD(doWebPayment:(NSString)paymentObject)
11
+ RCT_EXTERN_METHOD(doCardPayment:(NSString)paymentObject)
12
+ RCT_EXTERN_METHOD(doElementUPIPayment:(NSString)paymentObject)
13
+ RCT_EXTERN_METHOD(getInstalledUpiApps)
11
14
 
12
15
  RCT_EXTERN_METHOD(setCallback)
13
16
 
@@ -57,6 +57,47 @@ class CashfreePgApi: NSObject {
57
57
  }
58
58
  }
59
59
 
60
+ @objc func doCardPayment(_ paymentObject: NSString) -> Void {
61
+ do {
62
+ if let cfCardPayment = try parseCardObject(paymentObject: "\(paymentObject)") {
63
+ if let vc = RCTPresentedViewController() {
64
+ try CFPaymentGatewayService.getInstance().doPayment(cfCardPayment, viewController: vc)
65
+ }
66
+ }
67
+ }
68
+ catch {
69
+ print (error)
70
+ }
71
+ }
72
+
73
+ @objc func getInstalledUpiApps(){
74
+ let upiApplications = CFUPIUtils().getInstalledUPIApplications()
75
+ var appsToSend: [NSDictionary] = []
76
+ for upi in upiApplications {
77
+ if (upi["id"] ?? "").contains("cred") {
78
+ continue
79
+ }
80
+ appsToSend.append([
81
+ "appPackage": upi["id"] ?? "",
82
+ "appName": upi["displayName"] ?? ""
83
+ ])
84
+ }
85
+ CashfreeEmitter.sharedInstance.dispatch(name: "cfUpiApps", body: stringify(json: appsToSend))
86
+ }
87
+
88
+ @objc func doElementUPIPayment(_ paymentObject: NSString) -> Void {
89
+ do {
90
+ if let cfUPIPayment = try parseUpiObject(paymentObject: "\(paymentObject)") {
91
+ if let vc = RCTPresentedViewController() {
92
+ try CFPaymentGatewayService.getInstance().doPayment(cfUPIPayment, viewController: vc)
93
+ }
94
+ }
95
+ }
96
+ catch {
97
+ print (error)
98
+ }
99
+ }
100
+
60
101
  @objc func setCallback() -> Void {
61
102
  CFPaymentGatewayService.getInstance().setCallback(self)
62
103
  }
@@ -69,6 +110,59 @@ class CashfreePgApi: NSObject {
69
110
  analyticsCallbackEnabled = false
70
111
  }
71
112
 
113
+ private func parseCardObject(paymentObject: String) throws -> CFCardPayment? {
114
+ let data = paymentObject.data(using: .utf8)!
115
+ if let output = try! JSONSerialization.jsonObject(with: data, options: .allowFragments) as? Dictionary<String, Any> {
116
+ do {
117
+ let finalSession = getSession(paymentObject: output)
118
+ if let cfCard = getCard(paymentObject: output){
119
+ let savePaymentMethod = isForSavePayment(paymentObject: output)
120
+ print(savePaymentMethod)
121
+
122
+ let cardPayment = try CFCardPayment.CFCardPaymentBuilder()
123
+ .setCard(cfCard)
124
+ .setSession(finalSession!)
125
+ .saveInstrument(savePaymentMethod)
126
+ .build()
127
+
128
+ let systemVersion = UIDevice.current.systemVersion
129
+
130
+ cardPayment.setPlatform("irnx-e-2.1.9-x-m-s-x-i-\(systemVersion.prefix(4))")
131
+
132
+ return cardPayment
133
+ }
134
+ return nil
135
+ } catch let e {
136
+ let error = e as! CashfreeError
137
+ print(error.localizedDescription)
138
+ }
139
+ }
140
+ return nil
141
+ }
142
+
143
+ private func parseUpiObject(paymentObject: String) throws -> CFUPIPayment? {
144
+ let data = paymentObject.data(using: .utf8)!
145
+ if let output = try! JSONSerialization.jsonObject(with: data, options: .allowFragments) as? Dictionary<String, Any> {
146
+ do {
147
+ let finalSession = getSession(paymentObject: output)
148
+ let cfUPI = getUpi(paymentObject: output)
149
+
150
+ let upiPayment = try CFUPIPayment.CFUPIPaymentBuilder()
151
+ .setSession(finalSession!)
152
+ .setUPI(cfUPI!)
153
+ .build()
154
+ let systemVersion = UIDevice.current.systemVersion
155
+ upiPayment.setPlatform("irnx-e-2.1.9-x-m-s-x-i-\(systemVersion.prefix(4))")
156
+
157
+ return upiPayment
158
+ } catch let e {
159
+ let error = e as! CashfreeError
160
+ print(error.localizedDescription)
161
+ }
162
+ }
163
+ return nil
164
+ }
165
+
72
166
  private func parseDropPayment(paymentObject: String) throws -> CFDropCheckoutPayment? {
73
167
  // print(paymentObject)
74
168
  let data = paymentObject.data(using: .utf8)!
@@ -163,6 +257,53 @@ class CashfreePgApi: NSObject {
163
257
  return nil
164
258
  }
165
259
 
260
+ private func getCard(paymentObject: Dictionary<String,Any>) -> CFCard? {
261
+ let card = paymentObject["card"] as? NSDictionary ?? [:]
262
+ do {
263
+ var cardObject: CFCard!
264
+ if card["instrumentId"] != nil && card["instrumentId"] as? String ?? "" != "" {
265
+ cardObject = try CFCard.CFCardBuilder()
266
+ .setCVV(card["cardCvv"] as? String ?? "")
267
+ .setInstrumentId(card["instrumentId"] as? String ?? "")
268
+ .build()
269
+ } else {
270
+ cardObject = try CFCard.CFCardBuilder()
271
+ .setCVV(card["cardCvv"] as? String ?? "")
272
+ .setCardNumber(card["cardNumber"] as? String ?? "")
273
+ .setCardExpiryYear(card["cardExpiryYY"] as? String ?? "")
274
+ .setCardExpiryMonth(card["cardExpiryMM"] as? String ?? "")
275
+ .setCardHolderName(card["cardHolderName"] as? String ?? "")
276
+ .build()
277
+ }
278
+ return cardObject
279
+ } catch let e {
280
+ let error = e as! CashfreeError
281
+ print(error.localizedDescription)
282
+ return nil
283
+ }
284
+ }
285
+
286
+ private func isForSavePayment(paymentObject: Dictionary<String,Any>) -> Bool {
287
+ let card = paymentObject["card"] as? NSDictionary ?? [:]
288
+ return card["saveCard"] as? Bool ?? false
289
+ }
290
+
291
+ private func getUpi(paymentObject: Dictionary<String,Any>) -> CFUPI?{
292
+ if let upi = paymentObject["upi"] as? Dictionary<String, String> {
293
+ do {
294
+ let cfUPI = try CFUPI.CFUPIBuilder()
295
+ .setChannel(upi["mode"] ?? "" == "COLLECT" ? .COLLECT : .INTENT)
296
+ .setUPIID(upi["id"] ?? "")
297
+ .build()
298
+ return cfUPI
299
+ } catch let e {
300
+ let err = e as! CashfreeError
301
+ print(err.localizedDescription)
302
+ }
303
+ }
304
+ return nil
305
+ }
306
+
166
307
  private func getComponents(paymentObject: Dictionary<String,Any>) -> CFPaymentComponent? {
167
308
  if let components = paymentObject["components"] as? Array<String> {
168
309
  do {
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Workspace
3
+ version = "1.0">
4
+ <FileRef
5
+ location = "self:">
6
+ </FileRef>
7
+ </Workspace>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>IDEDidComputeMac32BitWarning</key>
6
+ <true/>
7
+ </dict>
8
+ </plist>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Bucket
3
+ uuid = "4075B5AF-BE54-4DA4-B387-03B4668144C8"
4
+ type = "1"
5
+ version = "2.0">
6
+ </Bucket>
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>SchemeUserState</key>
6
+ <dict>
7
+ <key>CashfreePgApi.xcscheme_^#shared#^_</key>
8
+ <dict>
9
+ <key>orderHint</key>
10
+ <integer>0</integer>
11
+ </dict>
12
+ </dict>
13
+ </dict>
14
+ </plist>
@@ -25,6 +25,7 @@ class CFPaymentGateway {
25
25
  _defineProperty(this, "successSubscription", null);
26
26
  _defineProperty(this, "failureSubscription", null);
27
27
  _defineProperty(this, "eventSubscription", null);
28
+ _defineProperty(this, "upiAppsSubscription", null);
28
29
  this.emitter = _reactNative.Platform.OS === 'ios' ? new _reactNative.NativeEventEmitter(_reactNative.NativeModules.CashfreeEventEmitter) : _reactNative.NativeAppEventEmitter;
29
30
  }
30
31
  doPayment(checkoutPayment) {
@@ -47,13 +48,26 @@ class CFPaymentGateway {
47
48
  }
48
49
  async getInstalledUpiApps() {
49
50
  return new Promise((resolve, reject) => {
50
- CashfreePgApi.getInstalledUpiApps(apps => {
51
- if (apps) {
52
- resolve(apps);
53
- } else {
54
- reject('No UPI apps found');
55
- }
56
- });
51
+ if (_reactNative.Platform.OS === 'ios') {
52
+ let fetchUpiList = apps => {
53
+ console.log(JSON.stringify(apps));
54
+ if (apps) {
55
+ resolve(apps);
56
+ } else {
57
+ reject('No UPI apps found');
58
+ }
59
+ };
60
+ this.upiAppsSubscription = this.emitter.addListener('cfUpiApps', fetchUpiList);
61
+ CashfreePgApi.getInstalledUpiApps();
62
+ } else {
63
+ CashfreePgApi.getInstalledUpiApps(apps => {
64
+ if (apps) {
65
+ resolve(apps);
66
+ } else {
67
+ reject('No UPI apps found');
68
+ }
69
+ });
70
+ }
57
71
  });
58
72
  }
59
73
  makePayment(cfPayment) {
@@ -111,6 +125,10 @@ class CFPaymentGateway {
111
125
  this.failureSubscription.remove();
112
126
  this.failureSubscription = null;
113
127
  }
128
+ if (this.upiAppsSubscription !== undefined && this.upiAppsSubscription !== null) {
129
+ this.upiAppsSubscription.remove();
130
+ this.upiAppsSubscription = null;
131
+ }
114
132
  }
115
133
  }
116
134
  class CFErrorResponse {
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","_package","_cashfreePgApiContract","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","LINKING_ERROR","Platform","select","ios","default","CashfreePgApi","NativeModules","Proxy","get","Error","CFPaymentGateway","constructor","emitter","OS","NativeEventEmitter","CashfreeEventEmitter","NativeAppEventEmitter","doPayment","checkoutPayment","version","JSON","stringify","doUPIPayment","doWebPayment","cfSession","doCardPayment","cardPayment","makePayment","getInstalledUpiApps","Promise","resolve","reject","apps","cfPayment","paymentData","CFUPIPayment","doElementUPIPayment","CFCardPayment","console","log","setEventSubscriber","cfEventCallback","eventFunction","event","data","parse","onReceivedEvent","eventName","meta","eventSubscription","addListener","removeEventSubscriber","remove","setCallback","cfCallback","successFunction","orderID","onVerify","failureFunction","error","response","CFErrorResponse","message","fromJSON","onError","successSubscription","failureSubscription","removeCallback","errorString","object","status","code","type","getStatus","getMessage","getCode","getType","exports","CFPaymentGatewayService"],"sources":["index.ts"],"sourcesContent":["import {\n EmitterSubscription,\n EventEmitter,\n NativeAppEventEmitter,\n NativeEventEmitter,\n NativeModules,\n Platform,\n} from 'react-native';\nimport { version } from '../package.json';\nimport { type CheckoutPayment, type CFSession, CFUPIPayment, CFCardPayment } from 'cashfree-pg-api-contract';\n\nconst LINKING_ERROR =\n `The package 'react-native-cashfree-pg-api' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: '- You have run \\'pod install\\'\\n', default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo managed workflow\\n';\n\nconst CashfreePgApi = NativeModules.CashfreePgApi\n ? NativeModules.CashfreePgApi\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n },\n );\n\nclass CFPaymentGateway {\n private emitter: EventEmitter;\n private successSubscription: EmitterSubscription | null = null;\n private failureSubscription: EmitterSubscription | null = null;\n private eventSubscription: EmitterSubscription | null = null;\n\n constructor() {\n this.emitter =\n Platform.OS === 'ios'\n ? new NativeEventEmitter(NativeModules.CashfreeEventEmitter)\n : NativeAppEventEmitter;\n }\n\n doPayment(checkoutPayment: CheckoutPayment) {\n checkoutPayment.version = version;\n CashfreePgApi.doPayment(JSON.stringify(checkoutPayment));\n }\n\n doUPIPayment(checkoutPayment: CheckoutPayment) {\n checkoutPayment.version = version;\n CashfreePgApi.doUPIPayment(JSON.stringify(checkoutPayment));\n }\n\n doWebPayment(cfSession: CFSession) {\n CashfreePgApi.doWebPayment(cfSession);\n }\n\n /**\n * @deprecated : Instead call makePayment\n */\n doCardPayment(cardPayment: CheckoutPayment) {\n this.makePayment(cardPayment);\n }\n\n async getInstalledUpiApps() {\n return new Promise((resolve, reject) => {\n CashfreePgApi.getInstalledUpiApps((apps: string) => {\n if (apps) {\n resolve(apps);\n } else {\n reject('No UPI apps found');\n }\n });\n });\n }\n\n makePayment(cfPayment: CheckoutPayment) {\n cfPayment.version = version;\n const paymentData = JSON.stringify(cfPayment);\n if (cfPayment instanceof CFUPIPayment) {\n CashfreePgApi.doElementUPIPayment(paymentData);\n } else if (cfPayment instanceof CFCardPayment) {\n CashfreePgApi.doCardPayment(paymentData);\n } else {\n console.log('makePayment::==> Wrong payment object');\n }\n }\n\n setEventSubscriber(cfEventCallback: CFEventCallback) {\n let eventFunction = (event: string) => {\n console.log(JSON.stringify(event));\n let data = JSON.parse(event);\n cfEventCallback.onReceivedEvent(data.eventName, data.meta);\n };\n this.eventSubscription = this.emitter.addListener('cfEvent', eventFunction);\n CashfreePgApi.setEventSubscriber();\n }\n\n removeEventSubscriber() {\n if (\n this.eventSubscription !== undefined &&\n this.eventSubscription !== null\n ) {\n this.eventSubscription.remove();\n this.eventSubscription = null;\n }\n CashfreePgApi.removeEventSubscriber();\n }\n\n setCallback(cfCallback: CFCallback) {\n // this.cfCallback = cfCallback;\n let successFunction = (orderID: string) => {\n console.log('response is : ' + JSON.stringify(orderID));\n cfCallback.onVerify(orderID);\n };\n let failureFunction = (error: string) => {\n console.log('reason: ' + JSON.stringify(error));\n const response = new CFErrorResponse();\n // @ts-ignore\n const message = JSON.parse(error);\n response.fromJSON(message.error);\n // @ts-ignore\n cfCallback.onError(response, message.orderID);\n };\n this.successSubscription = this.emitter.addListener(\n 'cfSuccess',\n successFunction,\n );\n this.failureSubscription = this.emitter.addListener(\n 'cfFailure',\n failureFunction,\n );\n CashfreePgApi.setCallback();\n }\n\n removeCallback() {\n if (\n this.successSubscription !== undefined &&\n this.successSubscription !== null\n ) {\n this.successSubscription.remove();\n this.successSubscription = null;\n }\n if (\n this.failureSubscription !== undefined &&\n this.failureSubscription !== null\n ) {\n this.failureSubscription.remove();\n this.failureSubscription = null;\n }\n }\n}\n\nexport interface CFCallback {\n onVerify(orderID: string): void;\n\n onError(error: CFErrorResponse, orderID: string): void;\n}\n\nexport interface CFEventCallback {\n onReceivedEvent(eventName: string, map: Map<string, string>): void;\n}\n\nexport class CFErrorResponse {\n private status: string = 'FAILED';\n private message: string = 'payment has failed';\n private code: string = 'payment_failed';\n private type: string = 'request_failed';\n\n fromJSON(errorString: string) {\n console.log('errorString :' + errorString);\n const object = JSON.parse(errorString);\n console.log('errorStringObject :' + object);\n this.status = object.status;\n this.message = object.message;\n this.code = object.code;\n this.type = object.type;\n }\n\n getStatus(): string {\n return this.status;\n }\n\n getMessage(): string {\n return this.message;\n }\n\n getCode(): string {\n return this.code;\n }\n\n getType(): string {\n return this.type;\n }\n}\n\nexport const CFPaymentGatewayService = new CFPaymentGateway();\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAQA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAF,OAAA;AAA6G,SAAAG,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,IAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,OAAAA,GAAA,IAAAD,GAAA,IAAAI,MAAA,CAAAC,cAAA,CAAAL,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAI,UAAA,QAAAC,YAAA,QAAAC,QAAA,o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EAEAC,SAASA,CAAA,EAAW;IAClB,OAAO,IAAI,CAACH,MAAM;EACpB;EAEAI,UAAUA,CAAA,EAAW;IACnB,OAAO,IAAI,CAACZ,OAAO;EACrB;EAEAa,OAAOA,CAAA,EAAW;IAChB,OAAO,IAAI,CAACJ,IAAI;EAClB;EAEAK,OAAOA,CAAA,EAAW;IAChB,OAAO,IAAI,CAACJ,IAAI;EAClB;AACF;AAACK,OAAA,CAAAhB,eAAA,GAAAA,eAAA;AAEM,MAAMiB,uBAAuB,GAAG,IAAIpE,gBAAgB,CAAC,CAAC;AAACmE,OAAA,CAAAC,uBAAA,GAAAA,uBAAA"}
1
+ {"version":3,"names":["_reactNative","require","_package","_cashfreePgApiContract","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","LINKING_ERROR","Platform","select","ios","default","CashfreePgApi","NativeModules","Proxy","get","Error","CFPaymentGateway","constructor","emitter","OS","NativeEventEmitter","CashfreeEventEmitter","NativeAppEventEmitter","doPayment","checkoutPayment","version","JSON","stringify","doUPIPayment","doWebPayment","cfSession","doCardPayment","cardPayment","makePayment","getInstalledUpiApps","Promise","resolve","reject","fetchUpiList","apps","console","log","upiAppsSubscription","addListener","cfPayment","paymentData","CFUPIPayment","doElementUPIPayment","CFCardPayment","setEventSubscriber","cfEventCallback","eventFunction","event","data","parse","onReceivedEvent","eventName","meta","eventSubscription","removeEventSubscriber","remove","setCallback","cfCallback","successFunction","orderID","onVerify","failureFunction","error","response","CFErrorResponse","message","fromJSON","onError","successSubscription","failureSubscription","removeCallback","errorString","object","status","code","type","getStatus","getMessage","getCode","getType","exports","CFPaymentGatewayService"],"sources":["index.ts"],"sourcesContent":["import {\n EmitterSubscription,\n EventEmitter,\n NativeAppEventEmitter,\n NativeEventEmitter,\n NativeModules,\n Platform,\n} from 'react-native';\nimport { version } from '../package.json';\nimport { type CheckoutPayment, type CFSession, CFUPIPayment, CFCardPayment } from 'cashfree-pg-api-contract';\n\nconst LINKING_ERROR =\n `The package 'react-native-cashfree-pg-api' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: '- You have run \\'pod install\\'\\n', default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo managed workflow\\n';\n\nconst CashfreePgApi = NativeModules.CashfreePgApi\n ? NativeModules.CashfreePgApi\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n },\n );\n\nclass CFPaymentGateway {\n private emitter: EventEmitter;\n private successSubscription: EmitterSubscription | null = null;\n private failureSubscription: EmitterSubscription | null = null;\n private eventSubscription: EmitterSubscription | null = null;\n private upiAppsSubscription: EmitterSubscription | null = null;\n\n constructor() {\n this.emitter =\n Platform.OS === 'ios'\n ? new NativeEventEmitter(NativeModules.CashfreeEventEmitter)\n : NativeAppEventEmitter;\n }\n\n doPayment(checkoutPayment: CheckoutPayment) {\n checkoutPayment.version = version;\n CashfreePgApi.doPayment(JSON.stringify(checkoutPayment));\n }\n\n doUPIPayment(checkoutPayment: CheckoutPayment) {\n checkoutPayment.version = version;\n CashfreePgApi.doUPIPayment(JSON.stringify(checkoutPayment));\n }\n\n doWebPayment(cfSession: CFSession) {\n CashfreePgApi.doWebPayment(cfSession);\n }\n\n /**\n * @deprecated : Instead call makePayment\n */\n doCardPayment(cardPayment: CheckoutPayment) {\n this.makePayment(cardPayment);\n }\n\n async getInstalledUpiApps() {\n return new Promise((resolve, reject) => {\n if(Platform.OS === 'ios'){\n let fetchUpiList = (apps: string) => {\n console.log(JSON.stringify(apps));\n if (apps) {\n resolve(apps);\n } else {\n reject('No UPI apps found');\n }\n };\n this.upiAppsSubscription = this.emitter.addListener('cfUpiApps', fetchUpiList);\n CashfreePgApi.getInstalledUpiApps()\n }\n else {\n CashfreePgApi.getInstalledUpiApps((apps: string) => {\n if (apps) {\n resolve(apps);\n } else {\n reject('No UPI apps found');\n }\n });\n }\n });\n }\n\n makePayment(cfPayment: CheckoutPayment) {\n cfPayment.version = version;\n const paymentData = JSON.stringify(cfPayment);\n if (cfPayment instanceof CFUPIPayment) {\n CashfreePgApi.doElementUPIPayment(paymentData);\n } else if (cfPayment instanceof CFCardPayment) {\n CashfreePgApi.doCardPayment(paymentData);\n } else {\n console.log('makePayment::==> Wrong payment object');\n }\n }\n\n setEventSubscriber(cfEventCallback: CFEventCallback) {\n let eventFunction = (event: string) => {\n console.log(JSON.stringify(event));\n let data = JSON.parse(event);\n cfEventCallback.onReceivedEvent(data.eventName, data.meta);\n };\n this.eventSubscription = this.emitter.addListener('cfEvent', eventFunction);\n CashfreePgApi.setEventSubscriber();\n }\n\n removeEventSubscriber() {\n if (\n this.eventSubscription !== undefined &&\n this.eventSubscription !== null\n ) {\n this.eventSubscription.remove();\n this.eventSubscription = null;\n }\n CashfreePgApi.removeEventSubscriber();\n }\n\n setCallback(cfCallback: CFCallback) {\n // this.cfCallback = cfCallback;\n let successFunction = (orderID: string) => {\n console.log('response is : ' + JSON.stringify(orderID));\n cfCallback.onVerify(orderID);\n };\n let failureFunction = (error: string) => {\n console.log('reason: ' + JSON.stringify(error));\n const response = new CFErrorResponse();\n // @ts-ignore\n const message = JSON.parse(error);\n response.fromJSON(message.error);\n // @ts-ignore\n cfCallback.onError(response, message.orderID);\n };\n this.successSubscription = this.emitter.addListener(\n 'cfSuccess',\n successFunction,\n );\n this.failureSubscription = this.emitter.addListener(\n 'cfFailure',\n failureFunction,\n );\n CashfreePgApi.setCallback();\n }\n\n removeCallback() {\n if (\n this.successSubscription !== undefined &&\n this.successSubscription !== null\n ) {\n this.successSubscription.remove();\n this.successSubscription = null;\n }\n if (\n this.failureSubscription !== undefined &&\n this.failureSubscription !== null\n ) {\n this.failureSubscription.remove();\n this.failureSubscription = null;\n }\n if (\n this.upiAppsSubscription !== undefined &&\n this.upiAppsSubscription !== null\n ) {\n this.upiAppsSubscription.remove();\n this.upiAppsSubscription = null;\n }\n }\n}\n\nexport interface CFCallback {\n onVerify(orderID: string): void;\n\n onError(error: CFErrorResponse, orderID: string): void;\n}\n\nexport interface CFEventCallback {\n onReceivedEvent(eventName: string, map: Map<string, string>): void;\n}\n\nexport class CFErrorResponse {\n private status: string = 'FAILED';\n private message: string = 'payment has failed';\n private code: string = 'payment_failed';\n private type: string = 'request_failed';\n\n fromJSON(errorString: string) {\n console.log('errorString :' + errorString);\n const object = JSON.parse(errorString);\n console.log('errorStringObject :' + object);\n this.status = object.status;\n this.message = object.message;\n this.code = object.code;\n this.type = object.type;\n }\n\n getStatus(): string {\n return this.status;\n }\n\n getMessage(): string {\n return this.message;\n }\n\n getCode(): string {\n return this.code;\n }\n\n getType(): string {\n return this.type;\n }\n}\n\nexport const CFPaymentGatewayService = new CFPaymentGateway();\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAQA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAF,OAAA;AAA6G,SAAAG,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,IAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,OAAAA,GAAA,IAAAD,GAAA,IAAAI,MAAA,CAAAC,cAAA,CAAAL,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAI,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAR,GAAA,CAAAC,GAAA,IAAAC,KAAA,WAAAF,GAAA;AAAA,SAAAG,eAAAM,GAAA,QAAAR,GAAA,GAAAS,YAAA,CAAAD,GAAA,2BAAAR,GAAA,gBAAAA,GAAA,GAAAU,MAAA,CAAAV,GAAA;AAAA,SAAAS,aAAAE,KAAA,EAAAC,IAAA,eAAAD,KAAA,iBAAAA,KAAA,kBAAAA,KAAA,MAAAE,IAAA,GAAAF,KAAA,CAAAG,MAAA,CAAAC,WAAA,OAAAF,IAAA,KAAAG,SAAA,QAAAC,GAAA,GAAAJ,IAAA,CAAAK,IAAA,CAAAP,KAAA,E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AW,CAAC;IACtCpC,OAAO,CAACC,GAAG,CAAC,qBAAqB,GAAGoC,MAAM,CAAC;IAC3C,IAAI,CAACC,MAAM,GAAGD,MAAM,CAACC,MAAM;IAC3B,IAAI,CAACR,OAAO,GAAGO,MAAM,CAACP,OAAO;IAC7B,IAAI,CAACS,IAAI,GAAGF,MAAM,CAACE,IAAI;IACvB,IAAI,CAACC,IAAI,GAAGH,MAAM,CAACG,IAAI;EACzB;EAEAC,SAASA,CAAA,EAAW;IAClB,OAAO,IAAI,CAACH,MAAM;EACpB;EAEAI,UAAUA,CAAA,EAAW;IACnB,OAAO,IAAI,CAACZ,OAAO;EACrB;EAEAa,OAAOA,CAAA,EAAW;IAChB,OAAO,IAAI,CAACJ,IAAI;EAClB;EAEAK,OAAOA,CAAA,EAAW;IAChB,OAAO,IAAI,CAACJ,IAAI;EAClB;AACF;AAACK,OAAA,CAAAhB,eAAA,GAAAA,eAAA;AAEM,MAAMiB,uBAAuB,GAAG,IAAItE,gBAAgB,CAAC,CAAC;AAACqE,OAAA,CAAAC,uBAAA,GAAAA,uBAAA"}
@@ -19,6 +19,7 @@ class CFPaymentGateway {
19
19
  _defineProperty(this, "successSubscription", null);
20
20
  _defineProperty(this, "failureSubscription", null);
21
21
  _defineProperty(this, "eventSubscription", null);
22
+ _defineProperty(this, "upiAppsSubscription", null);
22
23
  this.emitter = Platform.OS === 'ios' ? new NativeEventEmitter(NativeModules.CashfreeEventEmitter) : NativeAppEventEmitter;
23
24
  }
24
25
  doPayment(checkoutPayment) {
@@ -32,7 +33,6 @@ class CFPaymentGateway {
32
33
  doWebPayment(cfSession) {
33
34
  CashfreePgApi.doWebPayment(cfSession);
34
35
  }
35
-
36
36
  /**
37
37
  * @deprecated : Instead call makePayment
38
38
  */
@@ -41,13 +41,26 @@ class CFPaymentGateway {
41
41
  }
42
42
  async getInstalledUpiApps() {
43
43
  return new Promise((resolve, reject) => {
44
- CashfreePgApi.getInstalledUpiApps(apps => {
45
- if (apps) {
46
- resolve(apps);
47
- } else {
48
- reject('No UPI apps found');
49
- }
50
- });
44
+ if (Platform.OS === 'ios') {
45
+ let fetchUpiList = apps => {
46
+ console.log(JSON.stringify(apps));
47
+ if (apps) {
48
+ resolve(apps);
49
+ } else {
50
+ reject('No UPI apps found');
51
+ }
52
+ };
53
+ this.upiAppsSubscription = this.emitter.addListener('cfUpiApps', fetchUpiList);
54
+ CashfreePgApi.getInstalledUpiApps();
55
+ } else {
56
+ CashfreePgApi.getInstalledUpiApps(apps => {
57
+ if (apps) {
58
+ resolve(apps);
59
+ } else {
60
+ reject('No UPI apps found');
61
+ }
62
+ });
63
+ }
51
64
  });
52
65
  }
53
66
  makePayment(cfPayment) {
@@ -105,6 +118,10 @@ class CFPaymentGateway {
105
118
  this.failureSubscription.remove();
106
119
  this.failureSubscription = null;
107
120
  }
121
+ if (this.upiAppsSubscription !== undefined && this.upiAppsSubscription !== null) {
122
+ this.upiAppsSubscription.remove();
123
+ this.upiAppsSubscription = null;
124
+ }
108
125
  }
109
126
  }
110
127
  export class CFErrorResponse {
@@ -1 +1 @@
1
- {"version":3,"names":["NativeAppEventEmitter","NativeEventEmitter","NativeModules","Platform","version","CFUPIPayment","CFCardPayment","LINKING_ERROR","select","ios","default","CashfreePgApi","Proxy","get","Error","CFPaymentGateway","constructor","_defineProperty","emitter","OS","CashfreeEventEmitter","doPayment","checkoutPayment","JSON","stringify","doUPIPayment","doWebPayment","cfSession","doCardPayment","cardPayment","makePayment","getInstalledUpiApps","Promise","resolve","reject","apps","cfPayment","paymentData","doElementUPIPayment","console","log","setEventSubscriber","cfEventCallback","eventFunction","event","data","parse","onReceivedEvent","eventName","meta","eventSubscription","addListener","removeEventSubscriber","undefined","remove","setCallback","cfCallback","successFunction","orderID","onVerify","failureFunction","error","response","CFErrorResponse","message","fromJSON","onError","successSubscription","failureSubscription","removeCallback","errorString","object","status","code","type","getStatus","getMessage","getCode","getType","CFPaymentGatewayService"],"sources":["index.ts"],"sourcesContent":["import {\n EmitterSubscription,\n EventEmitter,\n NativeAppEventEmitter,\n NativeEventEmitter,\n NativeModules,\n Platform,\n} from 'react-native';\nimport { version } from '../package.json';\nimport { type CheckoutPayment, type CFSession, CFUPIPayment, CFCardPayment } from 'cashfree-pg-api-contract';\n\nconst LINKING_ERROR =\n `The package 'react-native-cashfree-pg-api' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: '- You have run \\'pod install\\'\\n', default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo managed workflow\\n';\n\nconst CashfreePgApi = NativeModules.CashfreePgApi\n ? NativeModules.CashfreePgApi\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n },\n );\n\nclass CFPaymentGateway {\n private emitter: EventEmitter;\n private successSubscription: EmitterSubscription | null = null;\n private failureSubscription: EmitterSubscription | null = null;\n private eventSubscription: EmitterSubscription | null = null;\n\n constructor() {\n this.emitter =\n Platform.OS === 'ios'\n ? new NativeEventEmitter(NativeModules.CashfreeEventEmitter)\n : NativeAppEventEmitter;\n }\n\n doPayment(checkoutPayment: CheckoutPayment) {\n checkoutPayment.version = version;\n CashfreePgApi.doPayment(JSON.stringify(checkoutPayment));\n }\n\n doUPIPayment(checkoutPayment: CheckoutPayment) {\n checkoutPayment.version = version;\n CashfreePgApi.doUPIPayment(JSON.stringify(checkoutPayment));\n }\n\n doWebPayment(cfSession: CFSession) {\n CashfreePgApi.doWebPayment(cfSession);\n }\n\n /**\n * @deprecated : Instead call makePayment\n */\n doCardPayment(cardPayment: CheckoutPayment) {\n this.makePayment(cardPayment);\n }\n\n async getInstalledUpiApps() {\n return new Promise((resolve, reject) => {\n CashfreePgApi.getInstalledUpiApps((apps: string) => {\n if (apps) {\n resolve(apps);\n } else {\n reject('No UPI apps found');\n }\n });\n });\n }\n\n makePayment(cfPayment: CheckoutPayment) {\n cfPayment.version = version;\n const paymentData = JSON.stringify(cfPayment);\n if (cfPayment instanceof CFUPIPayment) {\n CashfreePgApi.doElementUPIPayment(paymentData);\n } else if (cfPayment instanceof CFCardPayment) {\n CashfreePgApi.doCardPayment(paymentData);\n } else {\n console.log('makePayment::==> Wrong payment object');\n }\n }\n\n setEventSubscriber(cfEventCallback: CFEventCallback) {\n let eventFunction = (event: string) => {\n console.log(JSON.stringify(event));\n let data = JSON.parse(event);\n cfEventCallback.onReceivedEvent(data.eventName, data.meta);\n };\n this.eventSubscription = this.emitter.addListener('cfEvent', eventFunction);\n CashfreePgApi.setEventSubscriber();\n }\n\n removeEventSubscriber() {\n if (\n this.eventSubscription !== undefined &&\n this.eventSubscription !== null\n ) {\n this.eventSubscription.remove();\n this.eventSubscription = null;\n }\n CashfreePgApi.removeEventSubscriber();\n }\n\n setCallback(cfCallback: CFCallback) {\n // this.cfCallback = cfCallback;\n let successFunction = (orderID: string) => {\n console.log('response is : ' + JSON.stringify(orderID));\n cfCallback.onVerify(orderID);\n };\n let failureFunction = (error: string) => {\n console.log('reason: ' + JSON.stringify(error));\n const response = new CFErrorResponse();\n // @ts-ignore\n const message = JSON.parse(error);\n response.fromJSON(message.error);\n // @ts-ignore\n cfCallback.onError(response, message.orderID);\n };\n this.successSubscription = this.emitter.addListener(\n 'cfSuccess',\n successFunction,\n );\n this.failureSubscription = this.emitter.addListener(\n 'cfFailure',\n failureFunction,\n );\n CashfreePgApi.setCallback();\n }\n\n removeCallback() {\n if (\n this.successSubscription !== undefined &&\n this.successSubscription !== null\n ) {\n this.successSubscription.remove();\n this.successSubscription = null;\n }\n if (\n this.failureSubscription !== undefined &&\n this.failureSubscription !== null\n ) {\n this.failureSubscription.remove();\n this.failureSubscription = null;\n }\n }\n}\n\nexport interface CFCallback {\n onVerify(orderID: string): void;\n\n onError(error: CFErrorResponse, orderID: string): void;\n}\n\nexport interface CFEventCallback {\n onReceivedEvent(eventName: string, map: Map<string, string>): void;\n}\n\nexport class CFErrorResponse {\n private status: string = 'FAILED';\n private message: string = 'payment has failed';\n private code: string = 'payment_failed';\n private type: string = 'request_failed';\n\n fromJSON(errorString: string) {\n console.log('errorString :' + errorString);\n const object = JSON.parse(errorString);\n console.log('errorStringObject :' + object);\n this.status = object.status;\n this.message = object.message;\n this.code = object.code;\n this.type = object.type;\n }\n\n getStatus(): string {\n return this.status;\n }\n\n getMessage(): string {\n return this.message;\n }\n\n getCode(): string {\n return this.code;\n }\n\n getType(): string {\n return this.type;\n }\n}\n\nexport const CFPaymentGatewayService = new CFPaymentGateway();\n"],"mappings":";;;AAAA,SAGEA,qBAAqB,EACrBC,kBAAkB,EAClBC,aAAa,EACbC,QAAQ,QACH,cAAc;AACrB,SAASC,OAAO,QAAQ,iBAAiB;AACzC,SAA+CC,YAAY,EAAEC,aAAa,QAAQ,0BAA0B;AAE5G,MAAMC,aAAa,GAChB,uFAAsF,GACvFJ,QAAQ,CAACK,MAAM,CAAC;EAAEC,GAAG,EAAE,kCAAkC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACzE,sDAAsD,GACtD,6CAA6C;AAE/C,MAAMC,aAAa,GAAGT,aAAa,CAACS,aAAa,GAC7CT,aAAa,CAACS,aAAa,GAC3B,IAAIC,KAAK,CACT,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACP,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEH,MAAMQ,gBAAgB,CAAC;EAMrBC,WAAWA,CAAA,EAAG;IAAAC,eAAA;IAAAA,eAAA,8BAJ4C,IAAI;IAAAA,eAAA,8BACJ,IAAI;IAAAA,eAAA,4BACN,IAAI;IAG1D,IAAI,CAACC,OAAO,GACVf,QAAQ,CAACgB,EAAE,KAAK,KAAK,GACjB,IAAIlB,kBAAkB,CAACC,aAAa,CAACkB,oBAAoB,CAAC,GAC1DpB,qBAAqB;EAC7B;EAEAqB,SAASA,CAACC,eAAgC,EAAE;IAC1CA,eAAe,CAAClB,OAAO,GAAGA,OAAO;IACjCO,aAAa,CAACU,SAAS,CAACE,IAAI,CAACC,SAAS,C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AEAI,UAAUA,CAAA,EAAW;IACnB,OAAO,IAAI,CAACZ,OAAO;EACrB;EAEAa,OAAOA,CAAA,EAAW;IAChB,OAAO,IAAI,CAACJ,IAAI;EAClB;EAEAK,OAAOA,CAAA,EAAW;IAChB,OAAO,IAAI,CAACJ,IAAI;EAClB;AACF;AAEA,OAAO,MAAMK,uBAAuB,GAAG,IAAIhE,gBAAgB,CAAC,CAAC"}
1
+ {"version":3,"names":["NativeAppEventEmitter","NativeEventEmitter","NativeModules","Platform","version","CFUPIPayment","CFCardPayment","LINKING_ERROR","select","ios","default","CashfreePgApi","Proxy","get","Error","CFPaymentGateway","constructor","_defineProperty","emitter","OS","CashfreeEventEmitter","doPayment","checkoutPayment","JSON","stringify","doUPIPayment","doWebPayment","cfSession","doCardPayment","cardPayment","makePayment","getInstalledUpiApps","Promise","resolve","reject","fetchUpiList","apps","console","log","upiAppsSubscription","addListener","cfPayment","paymentData","doElementUPIPayment","setEventSubscriber","cfEventCallback","eventFunction","event","data","parse","onReceivedEvent","eventName","meta","eventSubscription","removeEventSubscriber","undefined","remove","setCallback","cfCallback","successFunction","orderID","onVerify","failureFunction","error","response","CFErrorResponse","message","fromJSON","onError","successSubscription","failureSubscription","removeCallback","errorString","object","status","code","type","getStatus","getMessage","getCode","getType","CFPaymentGatewayService"],"sources":["index.js"],"sourcesContent":["import { NativeAppEventEmitter, NativeEventEmitter, NativeModules, Platform, } from 'react-native';\nimport { version } from '../package.json';\nimport { CFUPIPayment, CFCardPayment } from 'cashfree-pg-api-contract';\nconst LINKING_ERROR = `The package 'react-native-cashfree-pg-api' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: '- You have run \\'pod install\\'\\n', default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo managed workflow\\n';\nconst CashfreePgApi = NativeModules.CashfreePgApi\n ? NativeModules.CashfreePgApi\n : new Proxy({}, {\n get() {\n throw new Error(LINKING_ERROR);\n },\n });\nclass CFPaymentGateway {\n emitter;\n successSubscription = null;\n failureSubscription = null;\n eventSubscription = null;\n upiAppsSubscription = null;\n constructor() {\n this.emitter =\n Platform.OS === 'ios'\n ? new NativeEventEmitter(NativeModules.CashfreeEventEmitter)\n : NativeAppEventEmitter;\n }\n doPayment(checkoutPayment) {\n checkoutPayment.version = version;\n CashfreePgApi.doPayment(JSON.stringify(checkoutPayment));\n }\n doUPIPayment(checkoutPayment) {\n checkoutPayment.version = version;\n CashfreePgApi.doUPIPayment(JSON.stringify(checkoutPayment));\n }\n doWebPayment(cfSession) {\n CashfreePgApi.doWebPayment(cfSession);\n }\n /**\n * @deprecated : Instead call makePayment\n */\n doCardPayment(cardPayment) {\n this.makePayment(cardPayment);\n }\n async getInstalledUpiApps() {\n return new Promise((resolve, reject) => {\n if (Platform.OS === 'ios') {\n let fetchUpiList = (apps) => {\n console.log(JSON.stringify(apps));\n if (apps) {\n resolve(apps);\n }\n else {\n reject('No UPI apps found');\n }\n };\n this.upiAppsSubscription = this.emitter.addListener('cfUpiApps', fetchUpiList);\n CashfreePgApi.getInstalledUpiApps();\n }\n else {\n CashfreePgApi.getInstalledUpiApps((apps) => {\n if (apps) {\n resolve(apps);\n }\n else {\n reject('No UPI apps found');\n }\n });\n }\n });\n }\n makePayment(cfPayment) {\n cfPayment.version = version;\n const paymentData = JSON.stringify(cfPayment);\n if (cfPayment instanceof CFUPIPayment) {\n CashfreePgApi.doElementUPIPayment(paymentData);\n }\n else if (cfPayment instanceof CFCardPayment) {\n CashfreePgApi.doCardPayment(paymentData);\n }\n else {\n console.log('makePayment::==> Wrong payment object');\n }\n }\n setEventSubscriber(cfEventCallback) {\n let eventFunction = (event) => {\n console.log(JSON.stringify(event));\n let data = JSON.parse(event);\n cfEventCallback.onReceivedEvent(data.eventName, data.meta);\n };\n this.eventSubscription = this.emitter.addListener('cfEvent', eventFunction);\n CashfreePgApi.setEventSubscriber();\n }\n removeEventSubscriber() {\n if (this.eventSubscription !== undefined &&\n this.eventSubscription !== null) {\n this.eventSubscription.remove();\n this.eventSubscription = null;\n }\n CashfreePgApi.removeEventSubscriber();\n }\n setCallback(cfCallback) {\n // this.cfCallback = cfCallback;\n let successFunction = (orderID) => {\n console.log('response is : ' + JSON.stringify(orderID));\n cfCallback.onVerify(orderID);\n };\n let failureFunction = (error) => {\n console.log('reason: ' + JSON.stringify(error));\n const response = new CFErrorResponse();\n // @ts-ignore\n const message = JSON.parse(error);\n response.fromJSON(message.error);\n // @ts-ignore\n cfCallback.onError(response, message.orderID);\n };\n this.successSubscription = this.emitter.addListener('cfSuccess', successFunction);\n this.failureSubscription = this.emitter.addListener('cfFailure', failureFunction);\n CashfreePgApi.setCallback();\n }\n removeCallback() {\n if (this.successSubscription !== undefined &&\n this.successSubscription !== null) {\n this.successSubscription.remove();\n this.successSubscription = null;\n }\n if (this.failureSubscription !== undefined &&\n this.failureSubscription !== null) {\n this.failureSubscription.remove();\n this.failureSubscription = null;\n }\n if (this.upiAppsSubscription !== undefined &&\n this.upiAppsSubscription !== null) {\n this.upiAppsSubscription.remove();\n this.upiAppsSubscription = null;\n }\n }\n}\nexport class CFErrorResponse {\n status = 'FAILED';\n message = 'payment has failed';\n code = 'payment_failed';\n type = 'request_failed';\n fromJSON(errorString) {\n console.log('errorString :' + errorString);\n const object = JSON.parse(errorString);\n console.log('errorStringObject :' + object);\n this.status = object.status;\n this.message = object.message;\n this.code = object.code;\n this.type = object.type;\n }\n getStatus() {\n return this.status;\n }\n getMessage() {\n return this.message;\n }\n getCode() {\n return this.code;\n }\n getType() {\n return this.type;\n }\n}\nexport const CFPaymentGatewayService = new CFPaymentGateway();\n"],"mappings":";;;AAAA,SAASA,qBAAqB,EAAEC,kBAAkB,EAAEC,aAAa,EAAEC,QAAQ,QAAS,cAAc;AAClG,SAASC,OAAO,QAAQ,iBAAiB;AACzC,SAASC,YAAY,EAAEC,aAAa,QAAQ,0BAA0B;AACtE,MAAMC,aAAa,GAAI,uFAAsF,GACzGJ,QAAQ,CAACK,MAAM,CAAC;E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AGF,MAAM,CAACE,IAAI;IACvB,IAAI,CAACC,IAAI,GAAGH,MAAM,CAACG,IAAI;EAC3B;EACAC,SAASA,CAAA,EAAG;IACR,OAAO,IAAI,CAACH,MAAM;EACtB;EACAI,UAAUA,CAAA,EAAG;IACT,OAAO,IAAI,CAACZ,OAAO;EACvB;EACAa,OAAOA,CAAA,EAAG;IACN,OAAO,IAAI,CAACJ,IAAI;EACpB;EACAK,OAAOA,CAAA,EAAG;IACN,OAAO,IAAI,CAACJ,IAAI;EACpB;AACJ;AACA,OAAO,MAAMK,uBAAuB,GAAG,IAAIlE,gBAAgB,CAAC,CAAC"}
@@ -4,6 +4,7 @@ declare class CFPaymentGateway {
4
4
  private successSubscription;
5
5
  private failureSubscription;
6
6
  private eventSubscription;
7
+ private upiAppsSubscription;
7
8
  constructor();
8
9
  doPayment(checkoutPayment: CheckoutPayment): void;
9
10
  doUPIPayment(checkoutPayment: CheckoutPayment): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-cashfree-pg-sdk",
3
- "version": "2.1.8",
3
+ "version": "2.1.9-dev.0",
4
4
  "description": "Cashfree PG Plugin for React Native",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",
package/src/index.js CHANGED
@@ -17,6 +17,7 @@ class CFPaymentGateway {
17
17
  successSubscription = null;
18
18
  failureSubscription = null;
19
19
  eventSubscription = null;
20
+ upiAppsSubscription = null;
20
21
  constructor() {
21
22
  this.emitter =
22
23
  Platform.OS === 'ios'
@@ -42,14 +43,29 @@ class CFPaymentGateway {
42
43
  }
43
44
  async getInstalledUpiApps() {
44
45
  return new Promise((resolve, reject) => {
45
- CashfreePgApi.getInstalledUpiApps((apps) => {
46
- if (apps) {
47
- resolve(apps);
48
- }
49
- else {
50
- reject('No UPI apps found');
51
- }
52
- });
46
+ if (Platform.OS === 'ios') {
47
+ let fetchUpiList = (apps) => {
48
+ console.log(JSON.stringify(apps));
49
+ if (apps) {
50
+ resolve(apps);
51
+ }
52
+ else {
53
+ reject('No UPI apps found');
54
+ }
55
+ };
56
+ this.upiAppsSubscription = this.emitter.addListener('cfUpiApps', fetchUpiList);
57
+ CashfreePgApi.getInstalledUpiApps();
58
+ }
59
+ else {
60
+ CashfreePgApi.getInstalledUpiApps((apps) => {
61
+ if (apps) {
62
+ resolve(apps);
63
+ }
64
+ else {
65
+ reject('No UPI apps found');
66
+ }
67
+ });
68
+ }
53
69
  });
54
70
  }
55
71
  makePayment(cfPayment) {
@@ -112,6 +128,11 @@ class CFPaymentGateway {
112
128
  this.failureSubscription.remove();
113
129
  this.failureSubscription = null;
114
130
  }
131
+ if (this.upiAppsSubscription !== undefined &&
132
+ this.upiAppsSubscription !== null) {
133
+ this.upiAppsSubscription.remove();
134
+ this.upiAppsSubscription = null;
135
+ }
115
136
  }
116
137
  }
117
138
  export class CFErrorResponse {
package/src/index.ts CHANGED
@@ -31,6 +31,7 @@ class CFPaymentGateway {
31
31
  private successSubscription: EmitterSubscription | null = null;
32
32
  private failureSubscription: EmitterSubscription | null = null;
33
33
  private eventSubscription: EmitterSubscription | null = null;
34
+ private upiAppsSubscription: EmitterSubscription | null = null;
34
35
 
35
36
  constructor() {
36
37
  this.emitter =
@@ -62,13 +63,27 @@ class CFPaymentGateway {
62
63
 
63
64
  async getInstalledUpiApps() {
64
65
  return new Promise((resolve, reject) => {
65
- CashfreePgApi.getInstalledUpiApps((apps: string) => {
66
- if (apps) {
67
- resolve(apps);
68
- } else {
69
- reject('No UPI apps found');
70
- }
71
- });
66
+ if(Platform.OS === 'ios'){
67
+ let fetchUpiList = (apps: string) => {
68
+ console.log(JSON.stringify(apps));
69
+ if (apps) {
70
+ resolve(apps);
71
+ } else {
72
+ reject('No UPI apps found');
73
+ }
74
+ };
75
+ this.upiAppsSubscription = this.emitter.addListener('cfUpiApps', fetchUpiList);
76
+ CashfreePgApi.getInstalledUpiApps()
77
+ }
78
+ else {
79
+ CashfreePgApi.getInstalledUpiApps((apps: string) => {
80
+ if (apps) {
81
+ resolve(apps);
82
+ } else {
83
+ reject('No UPI apps found');
84
+ }
85
+ });
86
+ }
72
87
  });
73
88
  }
74
89
 
@@ -146,6 +161,13 @@ class CFPaymentGateway {
146
161
  this.failureSubscription.remove();
147
162
  this.failureSubscription = null;
148
163
  }
164
+ if (
165
+ this.upiAppsSubscription !== undefined &&
166
+ this.upiAppsSubscription !== null
167
+ ) {
168
+ this.upiAppsSubscription.remove();
169
+ this.upiAppsSubscription = null;
170
+ }
149
171
  }
150
172
  }
151
173