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/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();
|