react-native-cashfree-pg-sdk 2.1.6 → 2.1.8-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.
Files changed (36) hide show
  1. package/android/.gradle/7.2/dependencies-accessors/dependencies-accessors.lock +0 -0
  2. package/android/.gradle/7.2/fileHashes/fileHashes.lock +0 -0
  3. package/android/.gradle/7.6/checksums/checksums.lock +0 -0
  4. package/android/.gradle/{7.2/executionHistory/executionHistory.bin → 7.6/checksums/md5-checksums.bin} +0 -0
  5. package/android/.gradle/7.6/checksums/sha1-checksums.bin +0 -0
  6. package/android/.gradle/7.6/dependencies-accessors/dependencies-accessors.lock +0 -0
  7. package/android/.gradle/7.6/dependencies-accessors/gc.properties +0 -0
  8. package/android/.gradle/7.6/executionHistory/executionHistory.bin +0 -0
  9. package/android/.gradle/7.6/executionHistory/executionHistory.lock +0 -0
  10. package/android/.gradle/7.6/fileChanges/last-build.bin +0 -0
  11. package/android/.gradle/7.6/fileHashes/fileHashes.bin +0 -0
  12. package/android/.gradle/7.6/fileHashes/fileHashes.lock +0 -0
  13. package/android/.gradle/{7.2 → 7.6}/fileHashes/resourceHashesCache.bin +0 -0
  14. package/android/.gradle/7.6/gc.properties +0 -0
  15. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  16. package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
  17. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  18. package/android/.gradle/checksums/checksums.lock +0 -0
  19. package/android/.gradle/file-system.probe +0 -0
  20. package/android/.idea/jarRepositories.xml +5 -0
  21. package/android/.idea/sonarlint/issuestore/2/a/2afbb999f001938c88fa43fc2ef52abf0f8213e4 +0 -0
  22. package/android/.idea/sonarlint/issuestore/index.pb +3 -1
  23. package/android/.idea/sonarlint/securityhotspotstore/2/a/2afbb999f001938c88fa43fc2ef52abf0f8213e4 +0 -0
  24. package/android/.idea/sonarlint/securityhotspotstore/index.pb +3 -1
  25. package/android/build.gradle +1 -1
  26. package/android/src/main/java/com/reactnativecashfreepgsdk/CashfreePgApiModule.java +73 -0
  27. package/lib/commonjs/index.js +30 -3
  28. package/lib/commonjs/index.js.map +1 -1
  29. package/lib/module/index.js +29 -3
  30. package/lib/module/index.js.map +1 -1
  31. package/lib/typescript/src/index.d.ts +6 -1
  32. package/package.json +2 -2
  33. package/src/index.js +32 -3
  34. package/src/index.ts +39 -13
  35. package/android/.gradle/7.2/executionHistory/executionHistory.lock +0 -0
  36. package/android/.gradle/7.2/fileHashes/fileHashes.bin +0 -0
File without changes
@@ -1,2 +1,2 @@
1
- #Thu Sep 14 12:36:17 IST 2023
2
- gradle.version=7.2
1
+ #Wed Dec 27 14:18:28 IST 2023
2
+ gradle.version=7.6
@@ -36,5 +36,10 @@
36
36
  <option name="name" value="Google2" />
37
37
  <option name="url" value="https://dl.google.com/dl/android/maven2/" />
38
38
  </remote-repository>
39
+ <remote-repository>
40
+ <option name="id" value="maven2" />
41
+ <option name="name" value="maven2" />
42
+ <option name="url" value="https://maven.juspay.in/jp-build-packages/hyper-sdk/" />
43
+ </remote-repository>
39
44
  </component>
40
45
  </project>
@@ -8,4 +8,6 @@ Csrc/main/java/com/reactnativecashfreepgsdk/CashfreePgApiModule.java,4/4/44aaf1
8
8
  t
9
9
  Dsrc/main/java/com/reactnativecashfreepgsdk/CashfreePgApiPackage.java,3/e/3e1984987c20cd21984de8c97894175bd94b0037
10
10
  <
11
- build.gradle,f/0/f07866736216be0ee2aba49e392191aeae700a35
11
+ build.gradle,f/0/f07866736216be0ee2aba49e392191aeae700a35
12
+ A
13
+ gradle.properties,2/a/2afbb999f001938c88fa43fc2ef52abf0f8213e4
@@ -8,4 +8,6 @@ Csrc/main/java/com/reactnativecashfreepgsdk/CashfreePgApiModule.java,4/4/44aaf1
8
8
  t
9
9
  Dsrc/main/java/com/reactnativecashfreepgsdk/CashfreePgApiPackage.java,3/e/3e1984987c20cd21984de8c97894175bd94b0037
10
10
  <
11
- build.gradle,f/0/f07866736216be0ee2aba49e392191aeae700a35
11
+ build.gradle,f/0/f07866736216be0ee2aba49e392191aeae700a35
12
+ A
13
+ gradle.properties,2/a/2afbb999f001938c88fa43fc2ef52abf0f8213e4
@@ -66,7 +66,7 @@ dependencies {
66
66
  implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
67
67
  implementation 'androidx.gridlayout:gridlayout:1.0.0'
68
68
 
69
- implementation 'com.cashfree.pg:api:2.1.5'
69
+ implementation 'com.cashfree.pg:api:2.1.6'
70
70
 
71
71
  implementation "com.facebook.react:react-native:+" // From node_modules
72
72
  }
@@ -1,6 +1,10 @@
1
1
  package com.reactnativecashfreepgapi;
2
2
 
3
3
  import android.app.Activity;
4
+ import android.content.Intent;
5
+ import android.content.pm.PackageManager;
6
+ import android.content.pm.ResolveInfo;
7
+ import android.net.Uri;
4
8
  import android.util.Log;
5
9
 
6
10
  import androidx.annotation.NonNull;
@@ -9,16 +13,20 @@ import androidx.annotation.Nullable;
9
13
  import com.cashfree.pg.api.CFPaymentGatewayService;
10
14
  import com.cashfree.pg.cf_analytics.CFAnalyticsService;
11
15
  import com.cashfree.pg.cf_analytics.CFEventsSubscriber;
16
+ import com.cashfree.pg.core.api.CFCorePaymentGatewayService;
12
17
  import com.cashfree.pg.core.api.CFSession;
13
18
  import com.cashfree.pg.core.api.base.CFPayment;
14
19
  import com.cashfree.pg.core.api.callback.CFCheckoutResponseCallback;
15
20
  import com.cashfree.pg.core.api.card.CFCard;
16
21
  import com.cashfree.pg.core.api.card.CFCardPayment;
17
22
  import com.cashfree.pg.core.api.exception.CFException;
23
+ import com.cashfree.pg.core.api.upi.CFUPI;
24
+ import com.cashfree.pg.core.api.upi.CFUPIPayment;
18
25
  import com.cashfree.pg.core.api.utils.CFErrorResponse;
19
26
  import com.cashfree.pg.core.api.webcheckout.CFWebCheckoutPayment;
20
27
  import com.cashfree.pg.ui.api.CFDropCheckoutPayment;
21
28
  import com.cashfree.pg.ui.api.upi.intent.CFUPIIntentCheckoutPayment;
29
+ import com.facebook.react.bridge.Callback;
22
30
  import com.facebook.react.bridge.ReactApplicationContext;
23
31
  import com.facebook.react.bridge.ReactContextBaseJavaModule;
24
32
  import com.facebook.react.bridge.ReactMethod;
@@ -26,9 +34,11 @@ import com.facebook.react.module.annotations.ReactModule;
26
34
  import com.facebook.react.modules.core.RCTNativeAppEventEmitter;
27
35
  import com.cashfree.pg.api.util.DropPaymentParser;
28
36
 
37
+ import org.json.JSONArray;
29
38
  import org.json.JSONException;
30
39
  import org.json.JSONObject;
31
40
 
41
+ import java.util.List;
32
42
  import java.util.Map;
33
43
 
34
44
  @ReactModule(name = CashfreePgApiModule.NAME)
@@ -163,6 +173,69 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
163
173
  }
164
174
  }
165
175
 
176
+ @ReactMethod
177
+ public void getInstalledUpiApps(Callback cb){
178
+ Activity activity = getCurrentActivity();
179
+ final Intent intent = new Intent();
180
+ intent.setAction(Intent.ACTION_VIEW);
181
+ intent.setData(Uri.parse("upi://pay"));
182
+ PackageManager pm = activity.getPackageManager();
183
+ final List<ResolveInfo> resInfo = pm.queryIntentActivities(intent, 0);
184
+ JSONArray packageNames = new JSONArray();
185
+ try {
186
+ for (ResolveInfo info : resInfo) {
187
+ JSONObject appInfo = new JSONObject();
188
+ String appName = (String)activity.getPackageManager().getApplicationLabel(info.activityInfo.applicationInfo);
189
+ appInfo.put("appName", appName);
190
+ appInfo.put("appPackage", info.activityInfo.packageName);
191
+ packageNames.put(appInfo);
192
+ }
193
+ } catch (Exception ex) {
194
+ ex.printStackTrace();
195
+ }
196
+ Log.d("CashfreePgApiModule", "getInstalledUpiApps::--" + packageNames);
197
+ cb.invoke(packageNames.toString());
198
+ }
199
+
200
+ @ReactMethod
201
+ public void doElementUPIPayment(String upiPaymentData) {
202
+ Log.d("CashfreePgApiModule", upiPaymentData);
203
+ CFSession cfSession = null;
204
+ CFUPI cfupi = null;
205
+ try {
206
+ JSONObject jsonObject = new JSONObject(upiPaymentData);
207
+ JSONObject session = jsonObject.getJSONObject("session");
208
+ JSONObject upiObject = jsonObject.getJSONObject("upi");
209
+ cfSession = new CFSession.CFSessionBuilder()
210
+ .setEnvironment(CFSession.Environment.valueOf(session.getString("environment")))
211
+ .setOrderId(session.getString("orderID"))
212
+ .setPaymentSessionID(session.getString("payment_session_id"))
213
+ .build();
214
+ CFUPI.Mode mode = CFUPI.Mode.valueOf(upiObject.getString("mode"));
215
+ String upiId = upiObject.getString("id");
216
+ cfupi = new CFUPI.CFUPIBuilder()
217
+ .setMode(mode)
218
+ .setUPIID(upiId)
219
+ .build();
220
+ } catch (Exception exception) {
221
+ throw new IllegalStateException(exception.getMessage());
222
+ }
223
+ try {
224
+ CFUPIPayment cfupiPayment = new CFUPIPayment.CFUPIPaymentBuilder()
225
+ .setSession(cfSession)
226
+ .setCfUPI(cfupi)
227
+ .build();
228
+ Activity activity = getCurrentActivity();
229
+ if (activity != null) {
230
+ CFCorePaymentGatewayService.getInstance().doPayment(activity, cfupiPayment);
231
+ } else {
232
+ throw new IllegalStateException("activity is null");
233
+ }
234
+ } catch (CFException exception) {
235
+ exception.printStackTrace();
236
+ }
237
+ }
238
+
166
239
  @ReactMethod
167
240
  public void setCallback() {
168
241
  try {
@@ -6,11 +6,12 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.CFPaymentGatewayService = exports.CFErrorResponse = void 0;
7
7
  var _reactNative = require("react-native");
8
8
  var _package = require("../package.json");
9
+ var _cashfreePgApiContract = require("cashfree-pg-api-contract");
9
10
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
11
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
11
12
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
12
13
  const LINKING_ERROR = `The package 'react-native-cashfree-pg-api' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
13
- ios: "- You have run 'pod install'\n",
14
+ ios: '- You have run \'pod install\'\n',
14
15
  default: ''
15
16
  }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo managed workflow\n';
16
17
  const CashfreePgApi = _reactNative.NativeModules.CashfreePgApi ? _reactNative.NativeModules.CashfreePgApi : new Proxy({}, {
@@ -37,9 +38,34 @@ class CFPaymentGateway {
37
38
  doWebPayment(cfSession) {
38
39
  CashfreePgApi.doWebPayment(cfSession);
39
40
  }
41
+
42
+ /**
43
+ * @deprecated : Instead call makePayment
44
+ */
40
45
  doCardPayment(cardPayment) {
41
- cardPayment.version = _package.version;
42
- CashfreePgApi.doCardPayment(JSON.stringify(cardPayment));
46
+ this.makePayment(cardPayment);
47
+ }
48
+ async getInstalledUpiApps() {
49
+ 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
+ });
57
+ });
58
+ }
59
+ makePayment(cfPayment) {
60
+ cfPayment.version = _package.version;
61
+ const paymentData = JSON.stringify(cfPayment);
62
+ if (cfPayment instanceof _cashfreePgApiContract.CFUPIPayment) {
63
+ CashfreePgApi.doElementUPIPayment(paymentData);
64
+ } else if (cfPayment instanceof _cashfreePgApiContract.CFCardPayment) {
65
+ CashfreePgApi.doCardPayment(paymentData);
66
+ } else {
67
+ console.log('makePayment::==> Wrong payment object');
68
+ }
43
69
  }
44
70
  setEventSubscriber(cfEventCallback) {
45
71
  let eventFunction = event => {
@@ -119,4 +145,5 @@ class CFErrorResponse {
119
145
  exports.CFErrorResponse = CFErrorResponse;
120
146
  const CFPaymentGatewayService = new CFPaymentGateway();
121
147
  exports.CFPaymentGatewayService = CFPaymentGatewayService;
148
+ //# sourceMappingURL=index.js.maptGatewayService;
122
149
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","_package","_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","setEventSubscriber","cfEventCallback","eventFunction","event","console","log","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.js"],"sourcesContent":["import { NativeAppEventEmitter, NativeEventEmitter, NativeModules, Platform, } from 'react-native';\nimport { version } from '../package.json';\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 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 doCardPayment(cardPayment) {\n cardPayment.version = version;\n CashfreePgApi.doCardPayment(JSON.stringify(cardPayment));\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 }\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,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAA0C,SAAAE,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,EAAAC,IAAA,2BAAAK,GAAA,sBAAAA,GAAA,YAAAE,SAAA,4DAAAP,IAAA,gBAAAF,MAAA,GAAAU,MAAA,EAAAT,KAAA;AAC1C,MAAMU,aAAa,GAAI,uFAAsF,GACzGC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,6CAA6C;AACjD,MAAMC,aAAa,GAAGC,0BAAa,CAACD,aAAa,GAC3CC,0BAAa,CAACD,aAAa,GAC3B,IA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,IAAI,CAACJ,IAAI;EACpB;EACAK,OAAOA,CAAA,EAAG;IACN,OAAO,IAAI,CAACJ,IAAI;EACpB;AACJ;AAACK,OAAA,CAAAhB,eAAA,GAAAA,eAAA;AACM,MAAMiB,uBAAuB,GAAG,IAAIzD,gBAAgB,CAAC,CAAC;AAACwD,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","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,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AMC,MAAM,GAAGjD,IAAI,CAACyB,KAAK,CAACuB,WAAW,CAAC;IACtC9B,OAAO,CAACC,GAAG,CAAC,qBAAqB,GAAG8B,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,IAAIpE,gBAAgB,CAAC,CAAC;AAACmE,OAAA,CAAAC,uBAAA,GAAAA,uBAAA"}
@@ -3,8 +3,9 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typ
3
3
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
4
4
  import { NativeAppEventEmitter, NativeEventEmitter, NativeModules, Platform } from 'react-native';
5
5
  import { version } from '../package.json';
6
+ import { CFUPIPayment, CFCardPayment } from 'cashfree-pg-api-contract';
6
7
  const LINKING_ERROR = `The package 'react-native-cashfree-pg-api' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
7
- ios: "- You have run 'pod install'\n",
8
+ ios: '- You have run \'pod install\'\n',
8
9
  default: ''
9
10
  }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo managed workflow\n';
10
11
  const CashfreePgApi = NativeModules.CashfreePgApi ? NativeModules.CashfreePgApi : new Proxy({}, {
@@ -31,9 +32,34 @@ class CFPaymentGateway {
31
32
  doWebPayment(cfSession) {
32
33
  CashfreePgApi.doWebPayment(cfSession);
33
34
  }
35
+ /**
36
+ * @deprecated : Instead call makePayment
37
+ */
34
38
  doCardPayment(cardPayment) {
35
- cardPayment.version = version;
36
- CashfreePgApi.doCardPayment(JSON.stringify(cardPayment));
39
+ this.makePayment(cardPayment);
40
+ }
41
+ async getInstalledUpiApps() {
42
+ return new Promise((resolve, reject) => {
43
+ CashfreePgApi.getInstalledUpiApps(apps => {
44
+ if (apps) {
45
+ resolve(apps);
46
+ } else {
47
+ reject('No UPI apps found');
48
+ }
49
+ });
50
+ });
51
+ }
52
+ makePayment(cfPayment) {
53
+ cfPayment.version = version;
54
+ const paymentData = JSON.stringify(cfPayment);
55
+ console.log('makePayment::==>' + paymentData);
56
+ if (cfPayment instanceof CFUPIPayment) {
57
+ CashfreePgApi.doElementUPIPayment(paymentData);
58
+ } else if (cfPayment instanceof CFCardPayment) {
59
+ CashfreePgApi.doCardPayment(paymentData);
60
+ } else {
61
+ console.log('makePayment::==> Wrong payment object');
62
+ }
37
63
  }
38
64
  setEventSubscriber(cfEventCallback) {
39
65
  let eventFunction = event => {
@@ -1 +1 @@
1
- {"version":3,"names":["NativeAppEventEmitter","NativeEventEmitter","NativeModules","Platform","version","LINKING_ERROR","select","ios","default","CashfreePgApi","Proxy","get","Error","CFPaymentGateway","constructor","_defineProperty","emitter","OS","CashfreeEventEmitter","doPayment","checkoutPayment","JSON","stringify","doUPIPayment","doWebPayment","cfSession","doCardPayment","cardPayment","setEventSubscriber","cfEventCallback","eventFunction","event","console","log","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, CFSession } 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 doCardPayment(cardPayment: CheckoutPayment) {\n cardPayment.version = version;\n CashfreePgApi.doCardPayment(JSON.stringify(cardPayment))\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 CFPaym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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;AAEA,OAAO,MAAMK,uBAAuB,GAAG,IAAIvD,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","apps","cfPayment","paymentData","console","log","doElementUPIPayment","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.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 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 CashfreePgApi.getInstalledUpiApps((apps) => {\n if (apps) {\n resolve(apps);\n }\n else {\n reject('No UPI apps found');\n }\n });\n });\n }\n makePayment(cfPayment) {\n cfPayment.version = version;\n const paymentData = JSON.stringify(cfPayment);\n console.log('makePayment::==>' + paymentData);\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 }\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;EAAEC,GAAG,EAAE,kCAAk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B,CAACd,MAAM,CAAC,CAAC;MACjC,IAAI,CAACc,mBAAmB,GAAG,IAAI;IACnC;EACJ;AACJ;AACA,OAAO,MAAML,eAAe,CAAC;EAAA/C,YAAA;IAAAC,eAAA,iBAChB,QAAQ;IAAAA,eAAA,kBACP,oBAAoB;IAAAA,eAAA,eACvB,gBAAgB;IAAAA,eAAA,eAChB,gBAAgB;EAAA;EACvBgD,QAAQA,CAACK,WAAW,EAAE;IAClBhC,OAAO,CAACC,GAAG,CAAC,eAAe,GAAG+B,WAAW,CAAC;IAC1C,MAAMC,MAAM,GAAGhD,IAAI,CAACuB,KAAK,CAACwB,WAAW,CAAC;IACtChC,OAAO,CAACC,GAAG,CAAC,qBAAqB,GAAGgC,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;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,IAAIhE,gBAAgB,CAAC,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { CheckoutPayment, CFSession } from 'cashfree-pg-api-contract';
1
+ import { type CheckoutPayment, type CFSession } from 'cashfree-pg-api-contract';
2
2
  declare class CFPaymentGateway {
3
3
  private emitter;
4
4
  private successSubscription;
@@ -8,7 +8,12 @@ declare class CFPaymentGateway {
8
8
  doPayment(checkoutPayment: CheckoutPayment): void;
9
9
  doUPIPayment(checkoutPayment: CheckoutPayment): void;
10
10
  doWebPayment(cfSession: CFSession): void;
11
+ /**
12
+ * @deprecated : Instead call makePayment
13
+ */
11
14
  doCardPayment(cardPayment: CheckoutPayment): void;
15
+ getInstalledUpiApps(): Promise<unknown>;
16
+ makePayment(cfPayment: CheckoutPayment): void;
12
17
  setEventSubscriber(cfEventCallback: CFEventCallback): void;
13
18
  removeEventSubscriber(): void;
14
19
  setCallback(cfCallback: CFCallback): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-cashfree-pg-sdk",
3
- "version": "2.1.6",
3
+ "version": "2.1.8-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",
@@ -145,6 +145,6 @@
145
145
  ]
146
146
  },
147
147
  "dependencies": {
148
- "cashfree-pg-api-contract": "^2.0.5"
148
+ "cashfree-pg-api-contract": "^2.0.6-dev.0"
149
149
  }
150
150
  }
package/src/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { NativeAppEventEmitter, NativeEventEmitter, NativeModules, Platform, } from 'react-native';
2
2
  import { version } from '../package.json';
3
+ import { CFUPIPayment, CFCardPayment } from 'cashfree-pg-api-contract';
3
4
  const LINKING_ERROR = `The package 'react-native-cashfree-pg-api' doesn't seem to be linked. Make sure: \n\n` +
4
- Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
5
+ Platform.select({ ios: '- You have run \'pod install\'\n', default: '' }) +
5
6
  '- You rebuilt the app after installing the package\n' +
6
7
  '- You are not using Expo managed workflow\n';
7
8
  const CashfreePgApi = NativeModules.CashfreePgApi
@@ -33,9 +34,37 @@ class CFPaymentGateway {
33
34
  doWebPayment(cfSession) {
34
35
  CashfreePgApi.doWebPayment(cfSession);
35
36
  }
37
+ /**
38
+ * @deprecated : Instead call makePayment
39
+ */
36
40
  doCardPayment(cardPayment) {
37
- cardPayment.version = version;
38
- CashfreePgApi.doCardPayment(JSON.stringify(cardPayment));
41
+ this.makePayment(cardPayment);
42
+ }
43
+ async getInstalledUpiApps() {
44
+ 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
+ });
53
+ });
54
+ }
55
+ makePayment(cfPayment) {
56
+ cfPayment.version = version;
57
+ const paymentData = JSON.stringify(cfPayment);
58
+ console.log('makePayment::==>' + paymentData);
59
+ if (cfPayment instanceof CFUPIPayment) {
60
+ CashfreePgApi.doElementUPIPayment(paymentData);
61
+ }
62
+ else if (cfPayment instanceof CFCardPayment) {
63
+ CashfreePgApi.doCardPayment(paymentData);
64
+ }
65
+ else {
66
+ console.log('makePayment::==> Wrong payment object');
67
+ }
39
68
  }
40
69
  setEventSubscriber(cfEventCallback) {
41
70
  let eventFunction = (event) => {
package/src/index.ts CHANGED
@@ -7,24 +7,24 @@ import {
7
7
  Platform,
8
8
  } from 'react-native';
9
9
  import { version } from '../package.json';
10
- import type { CheckoutPayment, CFSession } from 'cashfree-pg-api-contract';
10
+ import { type CheckoutPayment, type CFSession, CFUPIPayment, CFCardPayment } from 'cashfree-pg-api-contract';
11
11
 
12
12
  const LINKING_ERROR =
13
13
  `The package 'react-native-cashfree-pg-api' doesn't seem to be linked. Make sure: \n\n` +
14
- Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
14
+ Platform.select({ ios: '- You have run \'pod install\'\n', default: '' }) +
15
15
  '- You rebuilt the app after installing the package\n' +
16
16
  '- You are not using Expo managed workflow\n';
17
17
 
18
18
  const CashfreePgApi = NativeModules.CashfreePgApi
19
19
  ? NativeModules.CashfreePgApi
20
20
  : new Proxy(
21
- {},
22
- {
23
- get() {
24
- throw new Error(LINKING_ERROR);
25
- },
26
- }
27
- );
21
+ {},
22
+ {
23
+ get() {
24
+ throw new Error(LINKING_ERROR);
25
+ },
26
+ },
27
+ );
28
28
 
29
29
  class CFPaymentGateway {
30
30
  private emitter: EventEmitter;
@@ -53,9 +53,35 @@ class CFPaymentGateway {
53
53
  CashfreePgApi.doWebPayment(cfSession);
54
54
  }
55
55
 
56
+ /**
57
+ * @deprecated : Instead call makePayment
58
+ */
56
59
  doCardPayment(cardPayment: CheckoutPayment) {
57
- cardPayment.version = version;
58
- CashfreePgApi.doCardPayment(JSON.stringify(cardPayment))
60
+ this.makePayment(cardPayment);
61
+ }
62
+
63
+ async getInstalledUpiApps() {
64
+ 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
+ });
72
+ });
73
+ }
74
+
75
+ makePayment(cfPayment: CheckoutPayment) {
76
+ cfPayment.version = version;
77
+ const paymentData = JSON.stringify(cfPayment);
78
+ if (cfPayment instanceof CFUPIPayment) {
79
+ CashfreePgApi.doElementUPIPayment(paymentData);
80
+ } else if (cfPayment instanceof CFCardPayment) {
81
+ CashfreePgApi.doCardPayment(paymentData);
82
+ } else {
83
+ console.log('makePayment::==> Wrong payment object');
84
+ }
59
85
  }
60
86
 
61
87
  setEventSubscriber(cfEventCallback: CFEventCallback) {
@@ -96,11 +122,11 @@ class CFPaymentGateway {
96
122
  };
97
123
  this.successSubscription = this.emitter.addListener(
98
124
  'cfSuccess',
99
- successFunction
125
+ successFunction,
100
126
  );
101
127
  this.failureSubscription = this.emitter.addListener(
102
128
  'cfFailure',
103
- failureFunction
129
+ failureFunction,
104
130
  );
105
131
  CashfreePgApi.setCallback();
106
132
  }