react-native-cashfree-pg-sdk 2.4.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/.project +6 -0
- package/android/build.gradle +6 -4
- 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 +36 -20
- package/ios/CashfreePgApiAdapter.h +15 -0
- package/ios/CashfreePgApiAdapter.mm +94 -0
- package/lib/commonjs/CFErrorResponse.js +43 -0
- package/lib/commonjs/CFErrorResponse.js.map +1 -0
- package/lib/commonjs/Card/CFCardComponent.js +12 -6
- package/lib/commonjs/Card/CFCardComponent.js.map +1 -1
- package/lib/commonjs/Card/CFSubsCardComponent.js +9 -6
- package/lib/commonjs/Card/CFSubsCardComponent.js.map +1 -1
- package/lib/commonjs/Card/index.js.map +1 -1
- package/lib/commonjs/NativeCashfreePgApi.js +9 -0
- package/lib/commonjs/NativeCashfreePgApi.js.map +1 -0
- package/lib/commonjs/PPIWallet/PPIWalletPayment.js +104 -0
- package/lib/commonjs/PPIWallet/PPIWalletPayment.js.map +1 -0
- package/lib/commonjs/index.js +37 -83
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/CFErrorResponse.js +36 -0
- package/lib/module/CFErrorResponse.js.map +1 -0
- 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 +98 -0
- package/lib/module/PPIWallet/PPIWalletPayment.js.map +1 -0
- package/lib/module/index.js +17 -68
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/CFErrorResponse.d.ts +16 -0
- package/lib/typescript/src/NativeCashfreePgApi.d.ts +21 -0
- package/lib/typescript/src/PPIWallet/PPIWalletPayment.d.ts +6 -0
- package/lib/typescript/src/index.d.ts +9 -15
- package/package.json +32 -10
- package/react-native-cashfree-pg-sdk.podspec +6 -3
- package/src/CFErrorResponse.ts +38 -0
- package/src/Card/CFCardComponent.tsx +4 -2
- package/src/Card/CFSubsCardComponent.tsx +4 -2
- package/src/NativeCashfreePgApi.ts +23 -0
- package/src/PPIWallet/PPIWalletPayment.ts +120 -0
- package/src/index.ts +17 -92
- package/ios/CashfreeEventEmitter.m +0 -16
- package/ios/CashfreeEventEmitter.swift +0 -28
- package/ios/CashfreePgApi.m +0 -26
- package/src/Card/CFCardComponent.js +0 -238
- package/src/Card/CFSubsCardComponent.js +0 -203
- package/src/Card/index.js +0 -2
- package/src/index.js +0 -191
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import { TextInput } from 'react-native';
|
|
2
|
-
import React, { forwardRef } from 'react';
|
|
3
|
-
import { CFCardPayment, CFEnvironment, } from 'cashfree-pg-api-contract';
|
|
4
|
-
import { CFPaymentGatewayService } from '../index';
|
|
5
|
-
function luhnCheck(cardNumber) {
|
|
6
|
-
if (cardNumber.length === 0) {
|
|
7
|
-
return false;
|
|
8
|
-
}
|
|
9
|
-
cardNumber = cardNumber.replace(/\s/g, ''); // Remove spaces
|
|
10
|
-
let sum = 0;
|
|
11
|
-
let isAlternate = false;
|
|
12
|
-
for (let i = cardNumber.length - 1; i >= 0; i--) {
|
|
13
|
-
let digit = parseInt(cardNumber[i], 10);
|
|
14
|
-
if (isAlternate) {
|
|
15
|
-
digit *= 2;
|
|
16
|
-
if (digit > 9) {
|
|
17
|
-
digit -= 9;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
sum += digit;
|
|
21
|
-
isAlternate = !isAlternate;
|
|
22
|
-
}
|
|
23
|
-
return sum % 10 === 0;
|
|
24
|
-
}
|
|
25
|
-
function getInputValidationDetails(cardBinResponse) {
|
|
26
|
-
if (!cardBinResponse || !cardBinResponse.scheme) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
let schemeType = cardBinResponse.scheme.toLowerCase();
|
|
30
|
-
let inputValidationDetails;
|
|
31
|
-
switch (schemeType) {
|
|
32
|
-
case 'amex':
|
|
33
|
-
inputValidationDetails = { max_input_length: 15, cvv_length: 4 };
|
|
34
|
-
break;
|
|
35
|
-
case 'diners':
|
|
36
|
-
inputValidationDetails = { max_input_length: 14, cvv_length: 3 };
|
|
37
|
-
break;
|
|
38
|
-
default: // Covers visa, mastercard, rupay, jcb, discover, and unknown schemes
|
|
39
|
-
inputValidationDetails = { max_input_length: 16, cvv_length: 3 };
|
|
40
|
-
}
|
|
41
|
-
return inputValidationDetails;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Fetching Tdr info with card bin data & cfSession object
|
|
45
|
-
* @param session : for payment sessionId & env
|
|
46
|
-
* @param bin : for card number
|
|
47
|
-
*/
|
|
48
|
-
async function getTDR(session, bin) {
|
|
49
|
-
const route = `/pg/sdk/js/${session.payment_session_id}/v2/tdr`;
|
|
50
|
-
const body = JSON.stringify({ code: bin, code_type: 'bin' });
|
|
51
|
-
return await getInfo(session.environment, route, body);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Fetching CardBin info with card bin data & cfSession object
|
|
55
|
-
* @param session : for payment sessionId & env
|
|
56
|
-
* @param bin : for card number
|
|
57
|
-
*/
|
|
58
|
-
async function getCardBin(session, bin) {
|
|
59
|
-
const route = `/pg/sdk/js/${session.payment_session_id}/cardBin`;
|
|
60
|
-
const body = JSON.stringify({ card_number: bin });
|
|
61
|
-
return await getInfo(session.environment, route, body);
|
|
62
|
-
}
|
|
63
|
-
async function getInfo(env, route, bodyData) {
|
|
64
|
-
let baseUrl = 'https://api.cashfree.com';
|
|
65
|
-
if (env === CFEnvironment.SANDBOX) {
|
|
66
|
-
baseUrl = 'https://sandbox.cashfree.com';
|
|
67
|
-
}
|
|
68
|
-
const url = baseUrl + route;
|
|
69
|
-
try {
|
|
70
|
-
const response = await fetch(url, {
|
|
71
|
-
method: 'POST',
|
|
72
|
-
headers: {
|
|
73
|
-
'Content-Type': 'application/json',
|
|
74
|
-
},
|
|
75
|
-
body: bodyData,
|
|
76
|
-
});
|
|
77
|
-
if (!response.ok) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
return await response.json();
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
const CardInput = forwardRef(({ cfSession, cardListener, style, ...props }, ref) => {
|
|
87
|
-
const [inputNumber, setInputNumber] = React.useState('');
|
|
88
|
-
const inputNumberRef = React.useRef('');
|
|
89
|
-
const sessionRef = React.useRef(cfSession);
|
|
90
|
-
React.useImperativeHandle(ref, () => ({
|
|
91
|
-
doPayment,
|
|
92
|
-
doPaymentWithPaymentSessionId,
|
|
93
|
-
}));
|
|
94
|
-
const tdrJsonRef = React.useRef(null);
|
|
95
|
-
const cardBinJsonRef = React.useRef(null);
|
|
96
|
-
const firstEightDigitsRef = React.useRef('');
|
|
97
|
-
const handleChange = React.useCallback(async (cardNumber) => {
|
|
98
|
-
let completeResponse = {};
|
|
99
|
-
const textWithoutSpaces = cardNumber.replaceAll(' ', '');
|
|
100
|
-
if (textWithoutSpaces.length === 0)
|
|
101
|
-
setInputNumber('');
|
|
102
|
-
let formattedText = '';
|
|
103
|
-
/**
|
|
104
|
-
* Code to format card input number & set to input box
|
|
105
|
-
*/
|
|
106
|
-
for (let i = 0; i < textWithoutSpaces.length; i += 4) {
|
|
107
|
-
let end = i + 4;
|
|
108
|
-
if (end > textWithoutSpaces.length) {
|
|
109
|
-
end = textWithoutSpaces.length;
|
|
110
|
-
}
|
|
111
|
-
formattedText += textWithoutSpaces.substring(i, end);
|
|
112
|
-
if (end !== textWithoutSpaces.length) {
|
|
113
|
-
formattedText += ' ';
|
|
114
|
-
}
|
|
115
|
-
inputNumberRef.current = formattedText;
|
|
116
|
-
setInputNumber((prev) => prev === formattedText ? prev : formattedText);
|
|
117
|
-
}
|
|
118
|
-
let tdrResponse = null;
|
|
119
|
-
let cardBinResponse = null;
|
|
120
|
-
/**
|
|
121
|
-
* Fetch Tdr & CardBin data & set to local variable
|
|
122
|
-
*/
|
|
123
|
-
async function fetchDataAndSet() {
|
|
124
|
-
await getTDR(cfSession, textWithoutSpaces)
|
|
125
|
-
.then((response) => {
|
|
126
|
-
tdrResponse = response;
|
|
127
|
-
firstEightDigitsRef.current = textWithoutSpaces.substring(0, 8);
|
|
128
|
-
})
|
|
129
|
-
.catch(() => {
|
|
130
|
-
tdrResponse = null;
|
|
131
|
-
});
|
|
132
|
-
await getCardBin(cfSession, textWithoutSpaces)
|
|
133
|
-
.then((response) => {
|
|
134
|
-
cardBinResponse = response;
|
|
135
|
-
firstEightDigitsRef.current = textWithoutSpaces.substring(0, 8);
|
|
136
|
-
})
|
|
137
|
-
.catch(() => {
|
|
138
|
-
cardBinResponse = null;
|
|
139
|
-
});
|
|
140
|
-
if (tdrResponse) {
|
|
141
|
-
tdrJsonRef.current = tdrResponse;
|
|
142
|
-
completeResponse.tdr_info = tdrJsonRef.current;
|
|
143
|
-
}
|
|
144
|
-
if (cardBinResponse) {
|
|
145
|
-
cardBinJsonRef.current = cardBinResponse;
|
|
146
|
-
completeResponse.card_bin_info = cardBinJsonRef.current;
|
|
147
|
-
completeResponse.input_validation = getInputValidationDetails(cardBinJsonRef.current);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
if (textWithoutSpaces.length === 8) {
|
|
151
|
-
await fetchDataAndSet();
|
|
152
|
-
}
|
|
153
|
-
else if (textWithoutSpaces.length > 8) {
|
|
154
|
-
if (firstEightDigitsRef.current === textWithoutSpaces.substring(0, 8)) {
|
|
155
|
-
completeResponse.tdr_info = tdrJsonRef.current;
|
|
156
|
-
completeResponse.card_bin_info = cardBinJsonRef.current;
|
|
157
|
-
completeResponse.input_validation = getInputValidationDetails(cardBinJsonRef.current);
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
tdrJsonRef.current = null;
|
|
161
|
-
cardBinJsonRef.current = null;
|
|
162
|
-
await fetchDataAndSet();
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (textWithoutSpaces.length < 8) {
|
|
166
|
-
tdrJsonRef.current = null;
|
|
167
|
-
cardBinJsonRef.current = null;
|
|
168
|
-
firstEightDigitsRef.current = '';
|
|
169
|
-
}
|
|
170
|
-
if (cardBinJsonRef.current !== null) {
|
|
171
|
-
completeResponse.card_network = cardBinJsonRef.current.scheme;
|
|
172
|
-
}
|
|
173
|
-
let luhnStatus = luhnCheck(textWithoutSpaces);
|
|
174
|
-
if (luhnStatus) {
|
|
175
|
-
completeResponse.luhn_check_info = 'SUCCESS';
|
|
176
|
-
if (textWithoutSpaces && textWithoutSpaces.length > 4) {
|
|
177
|
-
completeResponse.last_four_digit = textWithoutSpaces.substring(textWithoutSpaces.length - 4);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
completeResponse.luhn_check_info = 'FAIL';
|
|
182
|
-
}
|
|
183
|
-
completeResponse.card_length = textWithoutSpaces.length;
|
|
184
|
-
return cardListener(JSON.stringify(completeResponse));
|
|
185
|
-
}, [cfSession, cardListener]);
|
|
186
|
-
const doPayment = (cardInfo) => {
|
|
187
|
-
try {
|
|
188
|
-
let cfCardNumber = inputNumberRef.current;
|
|
189
|
-
cardInfo.cardNumber = cfCardNumber.replaceAll(' ', '');
|
|
190
|
-
const cardPayment = new CFCardPayment(sessionRef.current, cardInfo);
|
|
191
|
-
CFPaymentGatewayService.makePayment(cardPayment);
|
|
192
|
-
}
|
|
193
|
-
catch (e) {
|
|
194
|
-
console.log(e.message);
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
const doPaymentWithPaymentSessionId = (cardInfo, session) => {
|
|
198
|
-
try {
|
|
199
|
-
sessionRef.current = session;
|
|
200
|
-
doPayment(cardInfo);
|
|
201
|
-
}
|
|
202
|
-
catch (e) {
|
|
203
|
-
console.log(e.message);
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
const handleSubmitEditingEvent = (event) => {
|
|
207
|
-
const newEvent = { ...event };
|
|
208
|
-
delete newEvent.nativeEvent.text;
|
|
209
|
-
if (onSubmitEditing) {
|
|
210
|
-
onSubmitEditing(newEvent);
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
const handleEndEditingEvent = (event) => {
|
|
214
|
-
const newEvent = { ...event };
|
|
215
|
-
delete newEvent.nativeEvent.text;
|
|
216
|
-
if (onEndEditing) {
|
|
217
|
-
onEndEditing(newEvent);
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
const handleFocusEvent = (event) => {
|
|
221
|
-
const newEvent = { ...event };
|
|
222
|
-
delete newEvent.nativeEvent.text;
|
|
223
|
-
if (onFocus) {
|
|
224
|
-
onFocus(newEvent);
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
const handleBlurEvent = (event) => {
|
|
228
|
-
const newEvent = { ...event };
|
|
229
|
-
delete newEvent.nativeEvent.text;
|
|
230
|
-
if (onBlur) {
|
|
231
|
-
onBlur(newEvent);
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
const InputComponent = TextInput;
|
|
235
|
-
const { onChangeText, onChange, onSubmitEditing, onEndEditing, onFocus, onBlur, ...otherProps } = props;
|
|
236
|
-
return (React.createElement(InputComponent, { keyboardType: "numeric", inputMode: 'numeric', value: inputNumber, onChangeText: handleChange, onSubmitEditing: handleSubmitEditingEvent, onEndEditing: handleEndEditingEvent, onFocus: handleFocusEvent, onBlur: handleBlurEvent, style: style, ...otherProps }));
|
|
237
|
-
});
|
|
238
|
-
export default CardInput;
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import { TextInput } from 'react-native';
|
|
2
|
-
import React, { forwardRef } from 'react';
|
|
3
|
-
import { CFSubsCardPayment, CFEnvironment, } from 'cashfree-pg-api-contract';
|
|
4
|
-
import { CFPaymentGatewayService } from '../index';
|
|
5
|
-
function luhnCheck(cardNumber) {
|
|
6
|
-
if (cardNumber.length === 0) {
|
|
7
|
-
return false;
|
|
8
|
-
}
|
|
9
|
-
cardNumber = cardNumber.replace(/\s/g, '');
|
|
10
|
-
let sum = 0;
|
|
11
|
-
let isAlternate = false;
|
|
12
|
-
for (let i = cardNumber.length - 1; i >= 0; i--) {
|
|
13
|
-
let digit = parseInt(cardNumber[i], 10);
|
|
14
|
-
if (isAlternate) {
|
|
15
|
-
digit *= 2;
|
|
16
|
-
if (digit > 9) {
|
|
17
|
-
digit -= 9;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
sum += digit;
|
|
21
|
-
isAlternate = !isAlternate;
|
|
22
|
-
}
|
|
23
|
-
return sum % 10 === 0;
|
|
24
|
-
}
|
|
25
|
-
function getInputValidationDetails(cardBinResponse) {
|
|
26
|
-
if (!cardBinResponse || !cardBinResponse.scheme) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
const schemeType = cardBinResponse.scheme.toLowerCase();
|
|
30
|
-
let inputValidationDetails;
|
|
31
|
-
switch (schemeType) {
|
|
32
|
-
case 'amex':
|
|
33
|
-
inputValidationDetails = { max_input_length: 15, cvv_length: 4 };
|
|
34
|
-
break;
|
|
35
|
-
case 'diners':
|
|
36
|
-
inputValidationDetails = { max_input_length: 14, cvv_length: 3 };
|
|
37
|
-
break;
|
|
38
|
-
default: // Covers visa, mastercard, rupay, jcb, discover, and unknown schemes
|
|
39
|
-
inputValidationDetails = { max_input_length: 16, cvv_length: 3 };
|
|
40
|
-
}
|
|
41
|
-
return inputValidationDetails;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Fetching CardBin info with card bin data & CFSubscriptionSession object
|
|
45
|
-
* @param session : for subs sessionId & env
|
|
46
|
-
* @param bin : for card number
|
|
47
|
-
*/
|
|
48
|
-
async function getCardBin(session, bin) {
|
|
49
|
-
const route = `/pg/sdk/js/subscription/card/bin`;
|
|
50
|
-
const body = JSON.stringify({ card_number: bin });
|
|
51
|
-
let baseUrl = 'https://api.cashfree.com';
|
|
52
|
-
if (session.environment === CFEnvironment.SANDBOX) {
|
|
53
|
-
baseUrl = 'https://sandbox.cashfree.com';
|
|
54
|
-
}
|
|
55
|
-
const url = baseUrl + route;
|
|
56
|
-
try {
|
|
57
|
-
const response = await fetch(url, {
|
|
58
|
-
method: 'POST',
|
|
59
|
-
headers: {
|
|
60
|
-
'Content-Type': 'application/json',
|
|
61
|
-
'x-sub-session-id': session.subscription_session_id,
|
|
62
|
-
},
|
|
63
|
-
body,
|
|
64
|
-
});
|
|
65
|
-
if (!response.ok) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
return await response.json();
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
const SubsCardInput = forwardRef(({ cfSubscriptionSession, cardListener, style, ...props }, ref) => {
|
|
75
|
-
const [inputNumber, setInputNumber] = React.useState('');
|
|
76
|
-
const inputNumberRef = React.useRef('');
|
|
77
|
-
const sessionRef = React.useRef(cfSubscriptionSession);
|
|
78
|
-
React.useImperativeHandle(ref, () => ({
|
|
79
|
-
doSubscriptionPayment,
|
|
80
|
-
doSubscriptionPaymentWithNewSession,
|
|
81
|
-
}));
|
|
82
|
-
const cardBinJsonRef = React.useRef(null);
|
|
83
|
-
const firstEightDigitsRef = React.useRef('');
|
|
84
|
-
const handleChange = React.useCallback(async (cardNumber) => {
|
|
85
|
-
let completeResponse = {};
|
|
86
|
-
const textWithoutSpaces = cardNumber.replaceAll(' ', '');
|
|
87
|
-
if (textWithoutSpaces.length === 0)
|
|
88
|
-
setInputNumber('');
|
|
89
|
-
let formattedText = '';
|
|
90
|
-
for (let i = 0; i < textWithoutSpaces.length; i += 4) {
|
|
91
|
-
let end = i + 4;
|
|
92
|
-
if (end > textWithoutSpaces.length) {
|
|
93
|
-
end = textWithoutSpaces.length;
|
|
94
|
-
}
|
|
95
|
-
formattedText += textWithoutSpaces.substring(i, end);
|
|
96
|
-
if (end !== textWithoutSpaces.length) {
|
|
97
|
-
formattedText += ' ';
|
|
98
|
-
}
|
|
99
|
-
inputNumberRef.current = formattedText;
|
|
100
|
-
setInputNumber((prev) => prev === formattedText ? prev : formattedText);
|
|
101
|
-
}
|
|
102
|
-
let cardBinResponse = null;
|
|
103
|
-
async function fetchCardBinAndSet() {
|
|
104
|
-
await getCardBin(cfSubscriptionSession, textWithoutSpaces)
|
|
105
|
-
.then((response) => {
|
|
106
|
-
cardBinResponse = response;
|
|
107
|
-
firstEightDigitsRef.current = textWithoutSpaces.substring(0, 8);
|
|
108
|
-
})
|
|
109
|
-
.catch(() => {
|
|
110
|
-
cardBinResponse = null;
|
|
111
|
-
});
|
|
112
|
-
if (cardBinResponse) {
|
|
113
|
-
cardBinJsonRef.current = cardBinResponse;
|
|
114
|
-
completeResponse.card_bin_info = cardBinJsonRef.current;
|
|
115
|
-
completeResponse.input_validation = getInputValidationDetails(cardBinJsonRef.current);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (textWithoutSpaces.length === 8) {
|
|
119
|
-
await fetchCardBinAndSet();
|
|
120
|
-
}
|
|
121
|
-
else if (textWithoutSpaces.length > 8) {
|
|
122
|
-
if (firstEightDigitsRef.current === textWithoutSpaces.substring(0, 8)) {
|
|
123
|
-
completeResponse.card_bin_info = cardBinJsonRef.current;
|
|
124
|
-
completeResponse.input_validation = getInputValidationDetails(cardBinJsonRef.current);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
cardBinJsonRef.current = null;
|
|
128
|
-
await fetchCardBinAndSet();
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (textWithoutSpaces.length < 8) {
|
|
132
|
-
cardBinJsonRef.current = null;
|
|
133
|
-
firstEightDigitsRef.current = '';
|
|
134
|
-
}
|
|
135
|
-
if (cardBinJsonRef.current !== null) {
|
|
136
|
-
completeResponse.card_network = cardBinJsonRef.current.scheme;
|
|
137
|
-
}
|
|
138
|
-
let luhnStatus = luhnCheck(textWithoutSpaces);
|
|
139
|
-
if (luhnStatus) {
|
|
140
|
-
completeResponse.luhn_check_info = 'SUCCESS';
|
|
141
|
-
if (textWithoutSpaces && textWithoutSpaces.length > 4) {
|
|
142
|
-
completeResponse.last_four_digit = textWithoutSpaces.substring(textWithoutSpaces.length - 4);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
completeResponse.luhn_check_info = 'FAIL';
|
|
147
|
-
}
|
|
148
|
-
completeResponse.card_length = textWithoutSpaces.length;
|
|
149
|
-
return cardListener(JSON.stringify(completeResponse));
|
|
150
|
-
}, [cfSubscriptionSession, cardListener]);
|
|
151
|
-
const doSubscriptionPayment = (cardInfo) => {
|
|
152
|
-
try {
|
|
153
|
-
let cfCardNumber = inputNumberRef.current;
|
|
154
|
-
cardInfo.cardNumber = cfCardNumber.replaceAll(' ', '');
|
|
155
|
-
const cardPayment = new CFSubsCardPayment(sessionRef.current, cardInfo);
|
|
156
|
-
CFPaymentGatewayService.makeSubsPayment(cardPayment);
|
|
157
|
-
}
|
|
158
|
-
catch (e) {
|
|
159
|
-
console.log(e.message);
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
const doSubscriptionPaymentWithNewSession = (cardInfo, session) => {
|
|
163
|
-
try {
|
|
164
|
-
sessionRef.current = session;
|
|
165
|
-
doSubscriptionPayment(cardInfo);
|
|
166
|
-
}
|
|
167
|
-
catch (e) {
|
|
168
|
-
console.log(e.message);
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
const handleSubmitEditingEvent = (event) => {
|
|
172
|
-
const newEvent = { ...event };
|
|
173
|
-
delete newEvent.nativeEvent.text;
|
|
174
|
-
if (onSubmitEditing) {
|
|
175
|
-
onSubmitEditing(newEvent);
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
const handleEndEditingEvent = (event) => {
|
|
179
|
-
const newEvent = { ...event };
|
|
180
|
-
delete newEvent.nativeEvent.text;
|
|
181
|
-
if (onEndEditing) {
|
|
182
|
-
onEndEditing(newEvent);
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
const handleFocusEvent = (event) => {
|
|
186
|
-
const newEvent = { ...event };
|
|
187
|
-
delete newEvent.nativeEvent.text;
|
|
188
|
-
if (onFocus) {
|
|
189
|
-
onFocus(newEvent);
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
const handleBlurEvent = (event) => {
|
|
193
|
-
const newEvent = { ...event };
|
|
194
|
-
delete newEvent.nativeEvent.text;
|
|
195
|
-
if (onBlur) {
|
|
196
|
-
onBlur(newEvent);
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
const InputComponent = TextInput;
|
|
200
|
-
const { onChangeText, onChange, onSubmitEditing, onEndEditing, onFocus, onBlur, ...otherProps } = props;
|
|
201
|
-
return (React.createElement(InputComponent, { keyboardType: "numeric", inputMode: 'numeric', value: inputNumber, onChangeText: handleChange, onSubmitEditing: handleSubmitEditingEvent, onEndEditing: handleEndEditingEvent, onFocus: handleFocusEvent, onBlur: handleBlurEvent, style: style, ...otherProps }));
|
|
202
|
-
});
|
|
203
|
-
export default SubsCardInput;
|
package/src/Card/index.js
DELETED
package/src/index.js
DELETED
|
@@ -1,191 +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
|
-
const LINKING_ERROR = `The package 'react-native-cashfree-pg-api' doesn't seem to be linked. Make sure: \n\n` +
|
|
7
|
-
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
8
|
-
'- You rebuilt the app after installing the package\n' +
|
|
9
|
-
'- You are not using Expo managed workflow\n';
|
|
10
|
-
const CashfreePgApi = NativeModules.CashfreePgApi
|
|
11
|
-
? NativeModules.CashfreePgApi
|
|
12
|
-
: new Proxy({}, {
|
|
13
|
-
get() {
|
|
14
|
-
throw new Error(LINKING_ERROR);
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
class CFPaymentGateway {
|
|
18
|
-
emitter;
|
|
19
|
-
successSubscription = null;
|
|
20
|
-
failureSubscription = null;
|
|
21
|
-
eventSubscription = null;
|
|
22
|
-
upiAppsSubscription = null;
|
|
23
|
-
constructor() {
|
|
24
|
-
this.emitter =
|
|
25
|
-
Platform.OS === 'ios'
|
|
26
|
-
? new NativeEventEmitter(NativeModules.CashfreeEventEmitter)
|
|
27
|
-
: NativeAppEventEmitter;
|
|
28
|
-
}
|
|
29
|
-
doPayment(checkoutPayment) {
|
|
30
|
-
checkoutPayment.version = version;
|
|
31
|
-
CashfreePgApi.doPayment(JSON.stringify(checkoutPayment));
|
|
32
|
-
}
|
|
33
|
-
doUPIPayment(checkoutPayment) {
|
|
34
|
-
checkoutPayment.version = version;
|
|
35
|
-
CashfreePgApi.doUPIPayment(JSON.stringify(checkoutPayment));
|
|
36
|
-
}
|
|
37
|
-
doWebPayment(cfSession) {
|
|
38
|
-
CashfreePgApi.doWebPayment(JSON.stringify(cfSession));
|
|
39
|
-
}
|
|
40
|
-
doSubscriptionPayment(cfSession) {
|
|
41
|
-
CashfreePgApi.doSubscriptionPayment(JSON.stringify(cfSession));
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* @deprecated : Instead call makePayment
|
|
45
|
-
*/
|
|
46
|
-
doCardPayment(cardPayment) {
|
|
47
|
-
this.makePayment(cardPayment);
|
|
48
|
-
}
|
|
49
|
-
async getInstalledUpiApps() {
|
|
50
|
-
return new Promise((resolve, reject) => {
|
|
51
|
-
if (Platform.OS === 'ios') {
|
|
52
|
-
let fetchUpiList = (apps) => {
|
|
53
|
-
console.log(JSON.stringify(apps));
|
|
54
|
-
if (apps) {
|
|
55
|
-
resolve(apps);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
reject('No UPI apps found');
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
this.upiAppsSubscription = this.emitter.addListener('cfUpiApps', fetchUpiList);
|
|
62
|
-
CashfreePgApi.getInstalledUpiApps();
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
CashfreePgApi.getInstalledUpiApps((apps) => {
|
|
66
|
-
if (apps) {
|
|
67
|
-
resolve(apps);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
reject('No UPI apps found');
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
makePayment(cfPayment) {
|
|
77
|
-
cfPayment.version = version;
|
|
78
|
-
const paymentData = JSON.stringify(cfPayment);
|
|
79
|
-
if (cfPayment instanceof CFUPIPayment) {
|
|
80
|
-
CashfreePgApi.doElementUPIPayment(paymentData);
|
|
81
|
-
}
|
|
82
|
-
else if (cfPayment instanceof CFCardPayment) {
|
|
83
|
-
CashfreePgApi.doCardPayment(paymentData);
|
|
84
|
-
}
|
|
85
|
-
else if (cfPayment instanceof CFNBPayment) {
|
|
86
|
-
CashfreePgApi.doElementNBPayment(paymentData);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
console.log('makePayment::==> Wrong payment object');
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
makeSubsPayment(cfPayment) {
|
|
93
|
-
cfPayment.version = version;
|
|
94
|
-
const paymentData = JSON.stringify(cfPayment);
|
|
95
|
-
if (cfPayment instanceof CFSubsUPIPayment) {
|
|
96
|
-
CashfreePgApi.doSubsUPIPayment(paymentData);
|
|
97
|
-
}
|
|
98
|
-
else if (cfPayment instanceof CFSubsCardPayment) {
|
|
99
|
-
CashfreePgApi.doSubsCardPayment(paymentData);
|
|
100
|
-
}
|
|
101
|
-
else if (cfPayment instanceof CFSubsNBPayment) {
|
|
102
|
-
CashfreePgApi.doSubsNBPayment(paymentData);
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
console.log('makePayment::==> Wrong payment object');
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
setEventSubscriber(cfEventCallback) {
|
|
109
|
-
let eventFunction = (event) => {
|
|
110
|
-
console.log(JSON.stringify(event));
|
|
111
|
-
let data = JSON.parse(event);
|
|
112
|
-
cfEventCallback.onReceivedEvent(data.eventName, data.meta);
|
|
113
|
-
};
|
|
114
|
-
this.eventSubscription = this.emitter.addListener('cfEvent', eventFunction);
|
|
115
|
-
CashfreePgApi.setEventSubscriber();
|
|
116
|
-
}
|
|
117
|
-
removeEventSubscriber() {
|
|
118
|
-
if (this.eventSubscription !== undefined &&
|
|
119
|
-
this.eventSubscription !== null) {
|
|
120
|
-
this.eventSubscription.remove();
|
|
121
|
-
this.eventSubscription = null;
|
|
122
|
-
}
|
|
123
|
-
CashfreePgApi.removeEventSubscriber();
|
|
124
|
-
}
|
|
125
|
-
setCallback(cfCallback) {
|
|
126
|
-
// this.cfCallback = cfCallback;
|
|
127
|
-
let successFunction = (orderID) => {
|
|
128
|
-
console.log('response is : ' + JSON.stringify(orderID));
|
|
129
|
-
cfCallback.onVerify(orderID);
|
|
130
|
-
};
|
|
131
|
-
let failureFunction = (error) => {
|
|
132
|
-
console.log('reason: ' + JSON.stringify(error));
|
|
133
|
-
const response = new CFErrorResponse();
|
|
134
|
-
// @ts-ignore
|
|
135
|
-
const message = JSON.parse(error);
|
|
136
|
-
response.fromJSON(message.error);
|
|
137
|
-
// @ts-ignore
|
|
138
|
-
cfCallback.onError(response, message.orderID);
|
|
139
|
-
};
|
|
140
|
-
this.successSubscription = this.emitter.addListener('cfSuccess', successFunction);
|
|
141
|
-
this.failureSubscription = this.emitter.addListener('cfFailure', failureFunction);
|
|
142
|
-
CashfreePgApi.setCallback();
|
|
143
|
-
}
|
|
144
|
-
removeCallback() {
|
|
145
|
-
if (this.successSubscription !== undefined &&
|
|
146
|
-
this.successSubscription !== null) {
|
|
147
|
-
this.successSubscription.remove();
|
|
148
|
-
this.successSubscription = null;
|
|
149
|
-
}
|
|
150
|
-
if (this.failureSubscription !== undefined &&
|
|
151
|
-
this.failureSubscription !== null) {
|
|
152
|
-
this.failureSubscription.remove();
|
|
153
|
-
this.failureSubscription = null;
|
|
154
|
-
}
|
|
155
|
-
if (this.upiAppsSubscription !== undefined &&
|
|
156
|
-
this.upiAppsSubscription !== null) {
|
|
157
|
-
this.upiAppsSubscription.remove();
|
|
158
|
-
this.upiAppsSubscription = null;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
export class CFErrorResponse {
|
|
163
|
-
status = 'FAILED';
|
|
164
|
-
message = 'payment has failed';
|
|
165
|
-
code = 'payment_failed';
|
|
166
|
-
type = 'request_failed';
|
|
167
|
-
fromJSON(errorString) {
|
|
168
|
-
console.log('errorString :' + errorString);
|
|
169
|
-
const object = JSON.parse(errorString);
|
|
170
|
-
console.log('errorStringObject :' + object);
|
|
171
|
-
this.status = object.status;
|
|
172
|
-
this.message = object.message;
|
|
173
|
-
this.code = object.code;
|
|
174
|
-
this.type = object.type;
|
|
175
|
-
}
|
|
176
|
-
getStatus() {
|
|
177
|
-
return this.status;
|
|
178
|
-
}
|
|
179
|
-
getMessage() {
|
|
180
|
-
return this.message;
|
|
181
|
-
}
|
|
182
|
-
getCode() {
|
|
183
|
-
return this.code;
|
|
184
|
-
}
|
|
185
|
-
getType() {
|
|
186
|
-
return this.type;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
export const CFCard = CFCardComponent;
|
|
190
|
-
export const CFSubsCard = CFSubsCardComponent;
|
|
191
|
-
export const CFPaymentGatewayService = new CFPaymentGateway();
|