react-native-cashfree-pg-sdk 2.5.0 → 3.0.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 (42) hide show
  1. package/README.md +36 -16
  2. package/android/build.gradle +5 -3
  3. package/android/src/main/java/com/reactnativecashfreepgsdk/CashfreePgApiModule.java +75 -27
  4. package/android/src/main/java/com/reactnativecashfreepgsdk/CashfreePgApiPackage.java +32 -18
  5. package/ios/CashfreeEmitter.swift +11 -11
  6. package/ios/CashfreePgApi.swift +35 -19
  7. package/ios/CashfreePgApiAdapter.h +15 -0
  8. package/ios/CashfreePgApiAdapter.mm +94 -0
  9. package/lib/commonjs/Card/CFCardComponent.js +4 -2
  10. package/lib/commonjs/Card/CFCardComponent.js.map +1 -1
  11. package/lib/commonjs/Card/CFSubsCardComponent.js +4 -2
  12. package/lib/commonjs/Card/CFSubsCardComponent.js.map +1 -1
  13. package/lib/commonjs/NativeCashfreePgApi.js +9 -0
  14. package/lib/commonjs/NativeCashfreePgApi.js.map +1 -0
  15. package/lib/commonjs/index.js +18 -50
  16. package/lib/commonjs/index.js.map +1 -1
  17. package/lib/module/Card/CFCardComponent.js +12 -6
  18. package/lib/module/Card/CFCardComponent.js.map +1 -1
  19. package/lib/module/Card/CFSubsCardComponent.js +4 -2
  20. package/lib/module/Card/CFSubsCardComponent.js.map +1 -1
  21. package/lib/module/NativeCashfreePgApi.js +3 -0
  22. package/lib/module/NativeCashfreePgApi.js.map +1 -0
  23. package/lib/module/PPIWallet/PPIWalletPayment.js.map +1 -1
  24. package/lib/module/index.js +4 -38
  25. package/lib/module/index.js.map +1 -1
  26. package/lib/typescript/src/NativeCashfreePgApi.d.ts +21 -0
  27. package/lib/typescript/src/index.d.ts +1 -2
  28. package/package.json +31 -9
  29. package/react-native-cashfree-pg-sdk.podspec +5 -2
  30. package/src/Card/CFCardComponent.tsx +4 -2
  31. package/src/Card/CFSubsCardComponent.tsx +4 -2
  32. package/src/NativeCashfreePgApi.ts +23 -0
  33. package/src/index.ts +5 -59
  34. package/ios/CashfreeEventEmitter.m +0 -16
  35. package/ios/CashfreeEventEmitter.swift +0 -28
  36. package/ios/CashfreePgApi.m +0 -26
  37. package/src/CFErrorResponse.js +0 -35
  38. package/src/Card/CFCardComponent.js +0 -238
  39. package/src/Card/CFSubsCardComponent.js +0 -203
  40. package/src/Card/index.js +0 -2
  41. package/src/PPIWallet/PPIWalletPayment.js +0 -94
  42. package/src/index.js +0 -174
package/src/index.js DELETED
@@ -1,174 +0,0 @@
1
- import { NativeAppEventEmitter, NativeEventEmitter, NativeModules, Platform, } from 'react-native';
2
- import { version } from '../package.json';
3
- import { CFUPIPayment, CFCardPayment, CFNBPayment, CFSubsUPIPayment, CFSubsCardPayment, CFSubsNBPayment, } from 'cashfree-pg-api-contract';
4
- import CFCardComponent from './Card/CFCardComponent';
5
- import CFSubsCardComponent from './Card/CFSubsCardComponent';
6
- import { CFErrorResponse } from './CFErrorResponse';
7
- import { doPPIWalletPayment } from './PPIWallet/PPIWalletPayment';
8
- const LINKING_ERROR = `The package 'react-native-cashfree-pg-api' doesn't seem to be linked. Make sure: \n\n` +
9
- Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
10
- '- You rebuilt the app after installing the package\n' +
11
- '- You are not using Expo managed workflow\n';
12
- const CashfreePgApi = NativeModules.CashfreePgApi
13
- ? NativeModules.CashfreePgApi
14
- : new Proxy({}, {
15
- get() {
16
- throw new Error(LINKING_ERROR);
17
- },
18
- });
19
- class CFPaymentGateway {
20
- emitter;
21
- successSubscription = null;
22
- failureSubscription = null;
23
- eventSubscription = null;
24
- upiAppsSubscription = null;
25
- constructor() {
26
- this.emitter =
27
- Platform.OS === 'ios'
28
- ? new NativeEventEmitter(NativeModules.CashfreeEventEmitter)
29
- : NativeAppEventEmitter;
30
- }
31
- doPayment(checkoutPayment) {
32
- checkoutPayment.version = version;
33
- CashfreePgApi.doPayment(JSON.stringify(checkoutPayment));
34
- }
35
- doUPIPayment(checkoutPayment) {
36
- checkoutPayment.version = version;
37
- CashfreePgApi.doUPIPayment(JSON.stringify(checkoutPayment));
38
- }
39
- doWebPayment(cfSession) {
40
- CashfreePgApi.doWebPayment(JSON.stringify(cfSession));
41
- }
42
- doSubscriptionPayment(cfSession) {
43
- CashfreePgApi.doSubscriptionPayment(JSON.stringify(cfSession));
44
- }
45
- /**
46
- * @deprecated : Instead call makePayment
47
- */
48
- doCardPayment(cardPayment) {
49
- this.makePayment(cardPayment);
50
- }
51
- async getInstalledUpiApps() {
52
- return new Promise((resolve, reject) => {
53
- if (Platform.OS === 'ios') {
54
- let fetchUpiList = (apps) => {
55
- console.log(JSON.stringify(apps));
56
- if (apps) {
57
- resolve(apps);
58
- }
59
- else {
60
- reject('No UPI apps found');
61
- }
62
- };
63
- this.upiAppsSubscription = this.emitter.addListener('cfUpiApps', fetchUpiList);
64
- CashfreePgApi.getInstalledUpiApps();
65
- }
66
- else {
67
- CashfreePgApi.getInstalledUpiApps((apps) => {
68
- if (apps) {
69
- resolve(apps);
70
- }
71
- else {
72
- reject('No UPI apps found');
73
- }
74
- });
75
- }
76
- });
77
- }
78
- makePayment(cfPayment) {
79
- cfPayment.version = version;
80
- const paymentData = JSON.stringify(cfPayment);
81
- if (cfPayment instanceof CFUPIPayment) {
82
- CashfreePgApi.doElementUPIPayment(paymentData);
83
- }
84
- else if (cfPayment instanceof CFCardPayment) {
85
- CashfreePgApi.doCardPayment(paymentData);
86
- }
87
- else if (cfPayment instanceof CFNBPayment) {
88
- CashfreePgApi.doElementNBPayment(paymentData);
89
- }
90
- else {
91
- console.log('makePayment::==> Wrong payment object');
92
- }
93
- }
94
- makeSubsPayment(cfPayment) {
95
- cfPayment.version = version;
96
- const paymentData = JSON.stringify(cfPayment);
97
- if (cfPayment instanceof CFSubsUPIPayment) {
98
- CashfreePgApi.doSubsUPIPayment(paymentData);
99
- }
100
- else if (cfPayment instanceof CFSubsCardPayment) {
101
- CashfreePgApi.doSubsCardPayment(paymentData);
102
- }
103
- else if (cfPayment instanceof CFSubsNBPayment) {
104
- CashfreePgApi.doSubsNBPayment(paymentData);
105
- }
106
- else {
107
- console.log('makePayment::==> Wrong payment object');
108
- }
109
- }
110
- /**
111
- * Creates a PPI wallet order session via Cashfree's API.
112
- * Resolves with the API response as-is; rejects with CFErrorResponse.
113
- */
114
- doPPIWalletPayment(payment) {
115
- return doPPIWalletPayment(payment);
116
- }
117
- setEventSubscriber(cfEventCallback) {
118
- let eventFunction = (event) => {
119
- console.log(JSON.stringify(event));
120
- let data = JSON.parse(event);
121
- cfEventCallback.onReceivedEvent(data.eventName, data.meta);
122
- };
123
- this.eventSubscription = this.emitter.addListener('cfEvent', eventFunction);
124
- CashfreePgApi.setEventSubscriber();
125
- }
126
- removeEventSubscriber() {
127
- if (this.eventSubscription !== undefined &&
128
- this.eventSubscription !== null) {
129
- this.eventSubscription.remove();
130
- this.eventSubscription = null;
131
- }
132
- CashfreePgApi.removeEventSubscriber();
133
- }
134
- setCallback(cfCallback) {
135
- // this.cfCallback = cfCallback;
136
- let successFunction = (orderID) => {
137
- console.log('response is : ' + JSON.stringify(orderID));
138
- cfCallback.onVerify(orderID);
139
- };
140
- let failureFunction = (error) => {
141
- console.log('reason: ' + JSON.stringify(error));
142
- const response = new CFErrorResponse();
143
- // @ts-ignore
144
- const message = JSON.parse(error);
145
- response.fromJSON(message.error);
146
- // @ts-ignore
147
- cfCallback.onError(response, message.orderID);
148
- };
149
- this.successSubscription = this.emitter.addListener('cfSuccess', successFunction);
150
- this.failureSubscription = this.emitter.addListener('cfFailure', failureFunction);
151
- CashfreePgApi.setCallback();
152
- }
153
- removeCallback() {
154
- if (this.successSubscription !== undefined &&
155
- this.successSubscription !== null) {
156
- this.successSubscription.remove();
157
- this.successSubscription = null;
158
- }
159
- if (this.failureSubscription !== undefined &&
160
- this.failureSubscription !== null) {
161
- this.failureSubscription.remove();
162
- this.failureSubscription = null;
163
- }
164
- if (this.upiAppsSubscription !== undefined &&
165
- this.upiAppsSubscription !== null) {
166
- this.upiAppsSubscription.remove();
167
- this.upiAppsSubscription = null;
168
- }
169
- }
170
- }
171
- export { CFErrorResponse };
172
- export const CFCard = CFCardComponent;
173
- export const CFSubsCard = CFSubsCardComponent;
174
- export const CFPaymentGatewayService = new CFPaymentGateway();