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.
- package/README.md +36 -16
- package/android/build.gradle +5 -3
- package/android/src/main/java/com/reactnativecashfreepgsdk/CashfreePgApiModule.java +75 -27
- package/android/src/main/java/com/reactnativecashfreepgsdk/CashfreePgApiPackage.java +32 -18
- package/ios/CashfreeEmitter.swift +11 -11
- package/ios/CashfreePgApi.swift +35 -19
- package/ios/CashfreePgApiAdapter.h +15 -0
- package/ios/CashfreePgApiAdapter.mm +94 -0
- package/lib/commonjs/Card/CFCardComponent.js +4 -2
- package/lib/commonjs/Card/CFCardComponent.js.map +1 -1
- package/lib/commonjs/Card/CFSubsCardComponent.js +4 -2
- package/lib/commonjs/Card/CFSubsCardComponent.js.map +1 -1
- package/lib/commonjs/NativeCashfreePgApi.js +9 -0
- package/lib/commonjs/NativeCashfreePgApi.js.map +1 -0
- package/lib/commonjs/index.js +18 -50
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/Card/CFCardComponent.js +12 -6
- package/lib/module/Card/CFCardComponent.js.map +1 -1
- package/lib/module/Card/CFSubsCardComponent.js +4 -2
- package/lib/module/Card/CFSubsCardComponent.js.map +1 -1
- package/lib/module/NativeCashfreePgApi.js +3 -0
- package/lib/module/NativeCashfreePgApi.js.map +1 -0
- package/lib/module/PPIWallet/PPIWalletPayment.js.map +1 -1
- package/lib/module/index.js +4 -38
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NativeCashfreePgApi.d.ts +21 -0
- package/lib/typescript/src/index.d.ts +1 -2
- package/package.json +31 -9
- package/react-native-cashfree-pg-sdk.podspec +5 -2
- package/src/Card/CFCardComponent.tsx +4 -2
- package/src/Card/CFSubsCardComponent.tsx +4 -2
- package/src/NativeCashfreePgApi.ts +23 -0
- package/src/index.ts +5 -59
- package/ios/CashfreeEventEmitter.m +0 -16
- package/ios/CashfreeEventEmitter.swift +0 -28
- package/ios/CashfreePgApi.m +0 -26
- package/src/CFErrorResponse.js +0 -35
- package/src/Card/CFCardComponent.js +0 -238
- package/src/Card/CFSubsCardComponent.js +0 -203
- package/src/Card/index.js +0 -2
- package/src/PPIWallet/PPIWalletPayment.js +0 -94
- package/src/index.js +0 -174
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# react-native-cashfree-pg-sdk
|
|
2
2
|
|
|
3
|
-
     [     [](https://packagephobia.com/result?p=react-native-cashfree-pg-sdk)
|
|
4
4
|
|
|
5
5
|
[](https://nodei.co/npm/react-native-cashfree-pg-sdk/)
|
|
6
6
|
|
|
@@ -10,6 +10,10 @@ Click [here](https://docs.cashfree.com/docs/react-native-integration) for more D
|
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
13
|
+
**Requires React Native 0.73.0 or newer.** (Use 0.73.2+ if you're on the 0.73 line — see
|
|
14
|
+
[MIGRATION-3.0.md](docs/MIGRATION-3.0.md) for why.) If you're on an older React Native
|
|
15
|
+
version, stay on the `2.5.x` line of this SDK.
|
|
16
|
+
|
|
13
17
|
```sh
|
|
14
18
|
npm install react-native-cashfree-pg-sdk
|
|
15
19
|
```
|
|
@@ -30,29 +34,45 @@ Add the following code to application's info.plist file.
|
|
|
30
34
|
|
|
31
35
|
## Usage
|
|
32
36
|
|
|
37
|
+
Register the result callback **once**, then start a payment:
|
|
38
|
+
|
|
33
39
|
```js
|
|
34
40
|
import {
|
|
35
|
-
CFCallback,
|
|
36
41
|
CFErrorResponse,
|
|
37
42
|
CFPaymentGatewayService,
|
|
38
43
|
} from 'react-native-cashfree-pg-sdk';
|
|
39
|
-
import {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
CFPaymentGatewayService.
|
|
51
|
-
}
|
|
52
|
-
|
|
44
|
+
import { CFEnvironment, CFSession } from 'cashfree-pg-api-contract';
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
CFPaymentGatewayService.setCallback({
|
|
48
|
+
onVerify(orderID: string) {
|
|
49
|
+
// Payment flow finished — now confirm the order on your server.
|
|
50
|
+
},
|
|
51
|
+
onError(error: CFErrorResponse, orderID: string) {
|
|
52
|
+
console.log(error.getMessage(), orderID);
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
return () => CFPaymentGatewayService.removeCallback();
|
|
56
|
+
}, []);
|
|
57
|
+
|
|
58
|
+
function pay(paymentSessionId: string, orderId: string) {
|
|
59
|
+
try {
|
|
60
|
+
const session = new CFSession(paymentSessionId, orderId, CFEnvironment.SANDBOX);
|
|
61
|
+
CFPaymentGatewayService.doWebPayment(session);
|
|
62
|
+
} catch (e: any) {
|
|
63
|
+
console.log(e.message);
|
|
64
|
+
}
|
|
53
65
|
}
|
|
54
66
|
```
|
|
55
67
|
|
|
68
|
+
- **Register `setCallback` in exactly one place.** Each registration receives every result, so
|
|
69
|
+
registering twice delivers each callback twice. Pair it with `removeCallback()` if the
|
|
70
|
+
registering component can mount more than once.
|
|
71
|
+
- **Confirm payments server-side.** On `onVerify`, check the order with
|
|
72
|
+
`GET /pg/orders/{order_id}` from your server and fulfil only on `order_status: PAID`.
|
|
73
|
+
|
|
74
|
+
Use `CFEnvironment.PRODUCTION` for live payments.
|
|
75
|
+
|
|
56
76
|
## Contributing
|
|
57
77
|
|
|
58
78
|
If you want to contribute please read the [Contributing](CONTRIBUTING.md) guidelines.
|
package/android/build.gradle
CHANGED
|
@@ -7,11 +7,13 @@ buildscript {
|
|
|
7
7
|
|
|
8
8
|
dependencies {
|
|
9
9
|
classpath 'com.android.tools.build:gradle:8.6.1'
|
|
10
|
+
classpath 'com.facebook.react:react-native-gradle-plugin'
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
apply plugin: 'com.android.library'
|
|
16
|
+
apply plugin: 'com.facebook.react'
|
|
15
17
|
|
|
16
18
|
android {
|
|
17
19
|
namespace "com.reactnativecashfreepgsdk"
|
|
@@ -29,8 +31,8 @@ android {
|
|
|
29
31
|
disable 'GradleCompatible'
|
|
30
32
|
}
|
|
31
33
|
compileOptions {
|
|
32
|
-
sourceCompatibility JavaVersion.
|
|
33
|
-
targetCompatibility JavaVersion.
|
|
34
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
35
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
|
|
@@ -59,5 +61,5 @@ dependencies {
|
|
|
59
61
|
implementation 'androidx.gridlayout:gridlayout:1.0.0'
|
|
60
62
|
|
|
61
63
|
implementation 'com.cashfree.pg:api:2.6.0'
|
|
62
|
-
implementation
|
|
64
|
+
implementation 'com.facebook.react:react-android'
|
|
63
65
|
}
|
|
@@ -39,12 +39,11 @@ import com.cashfree.pg.core.api.utils.CFSubscriptionResponse;
|
|
|
39
39
|
import com.cashfree.pg.core.api.webcheckout.CFWebCheckoutPayment;
|
|
40
40
|
import com.cashfree.pg.ui.api.CFDropCheckoutPayment;
|
|
41
41
|
import com.cashfree.pg.ui.api.upi.intent.CFUPIIntentCheckoutPayment;
|
|
42
|
-
import com.facebook.react.bridge.
|
|
42
|
+
import com.facebook.react.bridge.Promise;
|
|
43
43
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
44
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
45
44
|
import com.facebook.react.bridge.ReactMethod;
|
|
46
45
|
import com.facebook.react.module.annotations.ReactModule;
|
|
47
|
-
import com.facebook.react.modules.core.
|
|
46
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
48
47
|
import com.cashfree.pg.api.util.DropPaymentParser;
|
|
49
48
|
|
|
50
49
|
import org.json.JSONArray;
|
|
@@ -55,7 +54,9 @@ import java.util.List;
|
|
|
55
54
|
import java.util.Map;
|
|
56
55
|
|
|
57
56
|
@ReactModule(name = CashfreePgApiModule.NAME)
|
|
58
|
-
public class CashfreePgApiModule extends
|
|
57
|
+
public class CashfreePgApiModule extends NativeCashfreePgApiSpec
|
|
58
|
+
implements CFCheckoutResponseCallback, CFEventsSubscriber, CFSubscriptionResponseCallback {
|
|
59
|
+
|
|
59
60
|
public static final String NAME = "CashfreePgApi";
|
|
60
61
|
|
|
61
62
|
public CashfreePgApiModule(ReactApplicationContext reactContext) {
|
|
@@ -68,15 +69,17 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
68
69
|
return NAME;
|
|
69
70
|
}
|
|
70
71
|
|
|
72
|
+
@Override
|
|
71
73
|
@ReactMethod
|
|
72
74
|
public void doPayment(String cfPaymentString) {
|
|
73
75
|
Log.d("CashfreePgApiModule", cfPaymentString);
|
|
74
76
|
try {
|
|
75
|
-
Activity activity = getCurrentActivity();
|
|
77
|
+
Activity activity = getReactApplicationContext().getCurrentActivity();
|
|
76
78
|
CFDropCheckoutPayment cfDropCheckoutPayment = DropPaymentParser.getDropCheckoutPayment(cfPaymentString);
|
|
77
79
|
cfDropCheckoutPayment.setCfsdkFramework(CFPayment.CFSDKFramework.REACT_NATIVE);
|
|
78
80
|
cfDropCheckoutPayment.setCfSDKFlavour(CFPayment.CFSDKFlavour.DROP);
|
|
79
81
|
if (activity != null) {
|
|
82
|
+
registerCheckoutCallback();
|
|
80
83
|
CFPaymentGatewayService.getInstance().doPayment(activity, cfDropCheckoutPayment);
|
|
81
84
|
} else {
|
|
82
85
|
throw new IllegalStateException("activity is null");
|
|
@@ -86,15 +89,17 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
91
|
|
|
92
|
+
@Override
|
|
89
93
|
@ReactMethod
|
|
90
94
|
public void doUPIPayment(String cfPaymentString) {
|
|
91
95
|
Log.d("CashfreePgApiModule", cfPaymentString);
|
|
92
96
|
try {
|
|
93
|
-
Activity activity = getCurrentActivity();
|
|
97
|
+
Activity activity = getReactApplicationContext().getCurrentActivity();
|
|
94
98
|
CFUPIIntentCheckoutPayment cfupiIntentCheckoutPayment = DropPaymentParser.getUPICheckoutPayment(cfPaymentString);
|
|
95
99
|
cfupiIntentCheckoutPayment.setCfsdkFramework(CFPayment.CFSDKFramework.REACT_NATIVE);
|
|
96
100
|
cfupiIntentCheckoutPayment.setCfSDKFlavour(CFPayment.CFSDKFlavour.INTENT);
|
|
97
101
|
if (activity != null) {
|
|
102
|
+
registerCheckoutCallback();
|
|
98
103
|
CFPaymentGatewayService.getInstance().doPayment(activity, cfupiIntentCheckoutPayment);
|
|
99
104
|
} else {
|
|
100
105
|
throw new IllegalStateException("activity is null");
|
|
@@ -104,6 +109,7 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
104
109
|
}
|
|
105
110
|
}
|
|
106
111
|
|
|
112
|
+
@Override
|
|
107
113
|
@ReactMethod
|
|
108
114
|
public void doWebPayment(String sessionString) {
|
|
109
115
|
Log.d("CashfreePgApiModule Web", sessionString);
|
|
@@ -119,13 +125,14 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
119
125
|
throw new IllegalStateException("Session is invalid");
|
|
120
126
|
}
|
|
121
127
|
try {
|
|
122
|
-
Activity activity = getCurrentActivity();
|
|
128
|
+
Activity activity = getReactApplicationContext().getCurrentActivity();
|
|
123
129
|
CFWebCheckoutPayment cfWebCheckoutPayment = new CFWebCheckoutPayment.CFWebCheckoutPaymentBuilder()
|
|
124
130
|
.setSession(cfSession)
|
|
125
131
|
.build();
|
|
126
132
|
cfWebCheckoutPayment.setCfsdkFramework(CFPayment.CFSDKFramework.REACT_NATIVE);
|
|
127
133
|
cfWebCheckoutPayment.setCfSDKFlavour(CFPayment.CFSDKFlavour.WEB_CHECKOUT);
|
|
128
134
|
if (activity != null) {
|
|
135
|
+
registerCheckoutCallback();
|
|
129
136
|
CFPaymentGatewayService.getInstance().doPayment(activity, cfWebCheckoutPayment);
|
|
130
137
|
} else {
|
|
131
138
|
throw new IllegalStateException("activity is null");
|
|
@@ -135,6 +142,7 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
135
142
|
}
|
|
136
143
|
}
|
|
137
144
|
|
|
145
|
+
@Override
|
|
138
146
|
@ReactMethod
|
|
139
147
|
public void doSubscriptionPayment(String sessionString) {
|
|
140
148
|
CFSubscriptionSession cfSubsSession = null;
|
|
@@ -149,14 +157,14 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
149
157
|
throw new IllegalStateException("Subscription Session is invalid");
|
|
150
158
|
}
|
|
151
159
|
try {
|
|
152
|
-
Activity activity = getCurrentActivity();
|
|
160
|
+
Activity activity = getReactApplicationContext().getCurrentActivity();
|
|
153
161
|
CFSubscriptionPayment cfSubscriptionPayment = new CFSubscriptionPayment.CFSubscriptionCheckoutBuilder()
|
|
154
162
|
.setSubscriptionSession(cfSubsSession)
|
|
155
163
|
.build();
|
|
156
164
|
cfSubscriptionPayment.setCfsdkFramework(CFPayment.CFSDKFramework.REACT_NATIVE);
|
|
157
165
|
cfSubscriptionPayment.setCfSDKFlavour(CFPayment.CFSDKFlavour.SUBSCRIPTION);
|
|
158
166
|
if (activity != null) {
|
|
159
|
-
|
|
167
|
+
registerSubscriptionCallback();
|
|
160
168
|
CFPaymentGatewayService.getInstance().doSubscriptionPayment(activity, cfSubscriptionPayment);
|
|
161
169
|
} else {
|
|
162
170
|
throw new IllegalStateException("activity is null");
|
|
@@ -166,6 +174,7 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
166
174
|
}
|
|
167
175
|
}
|
|
168
176
|
|
|
177
|
+
@Override
|
|
169
178
|
@ReactMethod
|
|
170
179
|
public void doCardPayment(String data) {
|
|
171
180
|
CFSession cfSession = null;
|
|
@@ -200,7 +209,7 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
200
209
|
throw new IllegalStateException(exception.getMessage());
|
|
201
210
|
}
|
|
202
211
|
try {
|
|
203
|
-
Activity activity = getCurrentActivity();
|
|
212
|
+
Activity activity = getReactApplicationContext().getCurrentActivity();
|
|
204
213
|
CFCardPayment cardPayment = new CFCardPayment.CFCardPaymentBuilder()
|
|
205
214
|
.setSession(cfSession)
|
|
206
215
|
.setCard(card)
|
|
@@ -210,6 +219,7 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
210
219
|
cardPayment.setCfsdkFramework(CFPayment.CFSDKFramework.REACT_NATIVE);
|
|
211
220
|
cardPayment.setCfSDKFlavour(CFPayment.CFSDKFlavour.ELEMENT);
|
|
212
221
|
if (activity != null) {
|
|
222
|
+
registerCheckoutCallback();
|
|
213
223
|
CFPaymentGatewayService.getInstance().doPayment(activity, cardPayment);
|
|
214
224
|
} else {
|
|
215
225
|
throw new IllegalStateException("activity is null");
|
|
@@ -219,9 +229,10 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
219
229
|
}
|
|
220
230
|
}
|
|
221
231
|
|
|
232
|
+
@Override
|
|
222
233
|
@ReactMethod
|
|
223
|
-
public void getInstalledUpiApps(
|
|
224
|
-
Activity activity = getCurrentActivity();
|
|
234
|
+
public void getInstalledUpiApps(Promise promise) {
|
|
235
|
+
Activity activity = getReactApplicationContext().getCurrentActivity();
|
|
225
236
|
final Intent intent = new Intent();
|
|
226
237
|
intent.setAction(Intent.ACTION_VIEW);
|
|
227
238
|
intent.setData(Uri.parse("upi://pay"));
|
|
@@ -240,9 +251,10 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
240
251
|
ex.printStackTrace();
|
|
241
252
|
}
|
|
242
253
|
Log.d("CashfreePgApiModule", "getInstalledUpiApps::--" + packageNames);
|
|
243
|
-
|
|
254
|
+
promise.resolve(packageNames.toString());
|
|
244
255
|
}
|
|
245
256
|
|
|
257
|
+
@Override
|
|
246
258
|
@ReactMethod
|
|
247
259
|
public void doElementUPIPayment(String upiPaymentData) {
|
|
248
260
|
Log.d("CashfreePgApiModule", upiPaymentData);
|
|
@@ -274,8 +286,9 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
274
286
|
cfupiPayment.setCfSDKFlow(CFPayment.CFSDKFlow.WITH_CASHFREE_FULLSCREEN_LOADER);
|
|
275
287
|
cfupiPayment.setCfsdkFramework(CFPayment.CFSDKFramework.REACT_NATIVE);
|
|
276
288
|
cfupiPayment.setCfSDKFlavour(CFPayment.CFSDKFlavour.ELEMENT);
|
|
277
|
-
Activity activity = getCurrentActivity();
|
|
289
|
+
Activity activity = getReactApplicationContext().getCurrentActivity();
|
|
278
290
|
if (activity != null) {
|
|
291
|
+
registerCheckoutCallback();
|
|
279
292
|
CFCorePaymentGatewayService.getInstance().doPayment(activity, cfupiPayment);
|
|
280
293
|
} else {
|
|
281
294
|
throw new IllegalStateException("activity is null");
|
|
@@ -285,6 +298,7 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
285
298
|
}
|
|
286
299
|
}
|
|
287
300
|
|
|
301
|
+
@Override
|
|
288
302
|
@ReactMethod
|
|
289
303
|
public void doElementNBPayment(String nbPaymentData) {
|
|
290
304
|
Log.d("CashfreePgApiModule", nbPaymentData);
|
|
@@ -314,8 +328,9 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
314
328
|
cfNetBankingPayment.setCfSDKFlow(CFPayment.CFSDKFlow.WITH_CASHFREE_FULLSCREEN_LOADER);
|
|
315
329
|
cfNetBankingPayment.setCfsdkFramework(CFPayment.CFSDKFramework.REACT_NATIVE);
|
|
316
330
|
cfNetBankingPayment.setCfSDKFlavour(CFPayment.CFSDKFlavour.ELEMENT);
|
|
317
|
-
Activity activity = getCurrentActivity();
|
|
331
|
+
Activity activity = getReactApplicationContext().getCurrentActivity();
|
|
318
332
|
if (activity != null) {
|
|
333
|
+
registerCheckoutCallback();
|
|
319
334
|
CFCorePaymentGatewayService.getInstance().doPayment(activity, cfNetBankingPayment);
|
|
320
335
|
} else {
|
|
321
336
|
throw new IllegalStateException("activity is null");
|
|
@@ -325,6 +340,7 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
325
340
|
}
|
|
326
341
|
}
|
|
327
342
|
|
|
343
|
+
@Override
|
|
328
344
|
@ReactMethod
|
|
329
345
|
public void doSubsCardPayment(String data) {
|
|
330
346
|
CFSubscriptionSession cfSubsSession = null;
|
|
@@ -360,6 +376,7 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
360
376
|
}
|
|
361
377
|
}
|
|
362
378
|
|
|
379
|
+
@Override
|
|
363
380
|
@ReactMethod
|
|
364
381
|
public void doSubsUPIPayment(String data) {
|
|
365
382
|
CFSubscriptionSession cfSubsSession = null;
|
|
@@ -391,6 +408,7 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
391
408
|
}
|
|
392
409
|
}
|
|
393
410
|
|
|
411
|
+
@Override
|
|
394
412
|
@ReactMethod
|
|
395
413
|
public void doSubsNBPayment(String data) {
|
|
396
414
|
CFSubscriptionSession cfSubsSession = null;
|
|
@@ -426,11 +444,11 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
426
444
|
|
|
427
445
|
private void doSubscriptionElementPayment(CFSubsPayment subsPayment){
|
|
428
446
|
try {
|
|
429
|
-
Activity activity = getCurrentActivity();
|
|
447
|
+
Activity activity = getReactApplicationContext().getCurrentActivity();
|
|
430
448
|
subsPayment.setCfsdkFramework(CFPayment.CFSDKFramework.REACT_NATIVE);
|
|
431
449
|
subsPayment.setCfSDKFlavour(CFPayment.CFSDKFlavour.SUBSCRIPTION);
|
|
432
450
|
if (activity != null) {
|
|
433
|
-
|
|
451
|
+
registerSubscriptionCallback();
|
|
434
452
|
CFPaymentGatewayService.getInstance().doSubscriptionPayment(activity, subsPayment);
|
|
435
453
|
} else {
|
|
436
454
|
throw new IllegalStateException("activity is null");
|
|
@@ -440,14 +458,30 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
440
458
|
}
|
|
441
459
|
}
|
|
442
460
|
|
|
461
|
+
|
|
462
|
+
// Registered before every payment, not just once, so the current module
|
|
463
|
+
// instance is always the one that receives the result — including after
|
|
464
|
+
// Android recreates the host Activity when a UPI app returns. This sets a
|
|
465
|
+
// single callback rather than appending, so repeat calls never duplicate.
|
|
466
|
+
// Keep it per payment; do not reduce it to the one call in setCallback().
|
|
467
|
+
private void registerCheckoutCallback() throws CFException {
|
|
468
|
+
CFPaymentGatewayService.getInstance().setCheckoutCallback(this);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
private void registerSubscriptionCallback() throws CFException {
|
|
472
|
+
CFPaymentGatewayService.getInstance().setSubscriptionCheckoutCallback(this);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
@Override
|
|
443
476
|
@ReactMethod
|
|
444
477
|
public void setCallback() {
|
|
445
478
|
try {
|
|
446
|
-
|
|
479
|
+
registerCheckoutCallback();
|
|
447
480
|
} catch (CFException cfException) {
|
|
448
481
|
}
|
|
449
482
|
}
|
|
450
483
|
|
|
484
|
+
@Override
|
|
451
485
|
@ReactMethod
|
|
452
486
|
public void setEventSubscriber() {
|
|
453
487
|
try {
|
|
@@ -456,6 +490,7 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
456
490
|
}
|
|
457
491
|
}
|
|
458
492
|
|
|
493
|
+
@Override
|
|
459
494
|
@ReactMethod
|
|
460
495
|
public void removeEventSubscriber() {
|
|
461
496
|
try {
|
|
@@ -464,11 +499,24 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
464
499
|
}
|
|
465
500
|
}
|
|
466
501
|
|
|
502
|
+
@Override
|
|
503
|
+
@ReactMethod
|
|
504
|
+
public void addListener(String eventName) {
|
|
505
|
+
// Required by the generated spec / NativeEventEmitter contract. Events are
|
|
506
|
+
// delivered via RCTDeviceEventEmitter, so there is nothing to register here.
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
@Override
|
|
510
|
+
@ReactMethod
|
|
511
|
+
public void removeListeners(double count) {
|
|
512
|
+
// Required by the generated spec. `double` is what codegen emits for a JS number.
|
|
513
|
+
}
|
|
514
|
+
|
|
467
515
|
@Override
|
|
468
516
|
public void onPaymentVerify(String orderID) {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
517
|
+
getReactApplicationContext()
|
|
518
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
519
|
+
.emit("cfSuccess", orderID);
|
|
472
520
|
}
|
|
473
521
|
|
|
474
522
|
@Override
|
|
@@ -482,9 +530,9 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
482
530
|
} catch (JSONException e) {
|
|
483
531
|
e.printStackTrace();
|
|
484
532
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
533
|
+
getReactApplicationContext()
|
|
534
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
535
|
+
.emit("cfFailure", jsonObject.toString());
|
|
488
536
|
}
|
|
489
537
|
|
|
490
538
|
@Override
|
|
@@ -502,9 +550,9 @@ public class CashfreePgApiModule extends ReactContextBaseJavaModule implements C
|
|
|
502
550
|
} catch (JSONException e) {
|
|
503
551
|
e.printStackTrace();
|
|
504
552
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
553
|
+
getReactApplicationContext()
|
|
554
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
555
|
+
.emit("cfEvent", jsonObject.toString());
|
|
508
556
|
}
|
|
509
557
|
|
|
510
558
|
@Override
|
|
@@ -1,28 +1,42 @@
|
|
|
1
1
|
package com.reactnativecashfreepgsdk;
|
|
2
2
|
|
|
3
|
-
import androidx.annotation.
|
|
3
|
+
import androidx.annotation.Nullable;
|
|
4
4
|
|
|
5
|
-
import com.facebook.react.
|
|
5
|
+
import com.facebook.react.TurboReactPackage;
|
|
6
6
|
import com.facebook.react.bridge.NativeModule;
|
|
7
7
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
-
import com.facebook.react.
|
|
8
|
+
import com.facebook.react.module.model.ReactModuleInfo;
|
|
9
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
|
9
10
|
|
|
10
|
-
import java.util.
|
|
11
|
-
import java.util.
|
|
12
|
-
import java.util.List;
|
|
11
|
+
import java.util.HashMap;
|
|
12
|
+
import java.util.Map;
|
|
13
13
|
|
|
14
|
-
public class CashfreePgApiPackage
|
|
15
|
-
@NonNull
|
|
16
|
-
@Override
|
|
17
|
-
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
|
18
|
-
List<NativeModule> modules = new ArrayList<>();
|
|
19
|
-
modules.add(new CashfreePgApiModule(reactContext));
|
|
20
|
-
return modules;
|
|
21
|
-
}
|
|
14
|
+
public class CashfreePgApiPackage extends TurboReactPackage {
|
|
22
15
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
@Nullable
|
|
17
|
+
@Override
|
|
18
|
+
public NativeModule getModule(String name, ReactApplicationContext reactContext) {
|
|
19
|
+
if (CashfreePgApiModule.NAME.equals(name)) {
|
|
20
|
+
return new CashfreePgApiModule(reactContext);
|
|
27
21
|
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Override
|
|
26
|
+
public ReactModuleInfoProvider getReactModuleInfoProvider() {
|
|
27
|
+
return () -> {
|
|
28
|
+
Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
|
|
29
|
+
moduleInfos.put(
|
|
30
|
+
CashfreePgApiModule.NAME,
|
|
31
|
+
new ReactModuleInfo(
|
|
32
|
+
CashfreePgApiModule.NAME, // name
|
|
33
|
+
CashfreePgApiModule.NAME, // className
|
|
34
|
+
false, // canOverrideExistingModule
|
|
35
|
+
false, // needsEagerInit
|
|
36
|
+
false, // isCxxModule
|
|
37
|
+
true // isTurboModule
|
|
38
|
+
));
|
|
39
|
+
return moduleInfos;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
28
42
|
}
|
|
@@ -5,32 +5,32 @@
|
|
|
5
5
|
// Created by Aabhas Jindal on 14/06/22.
|
|
6
6
|
//
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
@objc(CashfreeEmitter)
|
|
9
|
+
public class CashfreeEmitter: NSObject {
|
|
9
10
|
|
|
10
11
|
/// Shared Instance.
|
|
11
|
-
public static var sharedInstance = CashfreeEmitter()
|
|
12
|
+
@objc public static var sharedInstance = CashfreeEmitter()
|
|
12
13
|
|
|
13
|
-
//
|
|
14
|
-
private var eventEmitter:
|
|
14
|
+
// The active RCTEventEmitter, registered by the module when React Native creates it.
|
|
15
|
+
private var eventEmitter: RCTEventEmitter?
|
|
15
16
|
|
|
16
|
-
private init() {}
|
|
17
|
+
private override init() {}
|
|
17
18
|
|
|
18
19
|
// When React Native instantiates the emitter it is registered here.
|
|
19
|
-
func registerEventEmitter(eventEmitter:
|
|
20
|
+
@objc public func registerEventEmitter(eventEmitter: RCTEventEmitter) {
|
|
20
21
|
self.eventEmitter = eventEmitter
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
func dispatch(name: String, body: Any?) {
|
|
24
|
-
eventEmitter
|
|
24
|
+
@objc public func dispatch(name: String, body: Any?) {
|
|
25
|
+
eventEmitter?.sendEvent(withName: name, body: body)
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
/// All Events which must be
|
|
28
|
-
lazy var allEvents: [String] = {
|
|
28
|
+
/// All Events which must be supported by React Native.
|
|
29
|
+
@objc public lazy var allEvents: [String] = {
|
|
29
30
|
var allEventNames: [String] = ["cfSuccess", "cfFailure", "cfEvent", "cfUpiApps"]
|
|
30
31
|
|
|
31
32
|
// Append all events here
|
|
32
33
|
|
|
33
34
|
return allEventNames
|
|
34
35
|
}()
|
|
35
|
-
|
|
36
36
|
}
|