react-native-cashfree-pg-sdk 2.1.18 → 2.1.19-dev.2
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/android/.gradle/7.2/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/7.2/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.2/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/7.2/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.2/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/.idea/caches/deviceStreaming.xml +437 -0
- package/android/.idea/gradle.xml +1 -1
- package/android/.idea/other.xml +110 -0
- package/android/.idea/runConfigurations.xml +17 -0
- package/android/build.gradle +1 -1
- package/lib/commonjs/Card/CFCardComponent.js +21 -7
- package/lib/commonjs/Card/CFCardComponent.js.map +1 -1
- package/lib/commonjs/index.js +1 -0
- package/lib/module/Card/CFCardComponent.js +24 -14
- package/lib/module/Card/CFCardComponent.js.map +1 -1
- package/lib/module/Card/index.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/Card/CFCardComponent.d.ts +1 -0
- package/package.json +1 -1
- package/src/Card/CFCardComponent.js +25 -7
- package/src/Card/CFCardComponent.tsx +186 -160
- package/android/.idea/android.iml +0 -6
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { TextInput, TextInputProps } from 'react-native';
|
|
2
2
|
import React, { forwardRef } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
CFCardPayment,
|
|
5
|
+
CFEnvironment,
|
|
6
|
+
type CFSession,
|
|
7
|
+
ElementCard,
|
|
8
|
+
} from 'cashfree-pg-api-contract';
|
|
4
9
|
import { CFPaymentGatewayService } from '../index';
|
|
5
10
|
|
|
6
11
|
function luhnCheck(cardNumber: string): boolean {
|
|
@@ -37,7 +42,7 @@ function luhnCheck(cardNumber: string): boolean {
|
|
|
37
42
|
*/
|
|
38
43
|
async function getTDR(session: CFSession, bin: string) {
|
|
39
44
|
const route: string = `/pg/sdk/js/${session.payment_session_id}/v2/tdr`;
|
|
40
|
-
const body: string = JSON.stringify({
|
|
45
|
+
const body: string = JSON.stringify({ code: bin, code_type: 'bin' });
|
|
41
46
|
return await getInfo(session.environment, route, body);
|
|
42
47
|
}
|
|
43
48
|
|
|
@@ -48,7 +53,7 @@ async function getTDR(session: CFSession, bin: string) {
|
|
|
48
53
|
*/
|
|
49
54
|
async function getCardBin(session: CFSession, bin: string) {
|
|
50
55
|
const route: string = `/pg/sdk/js/${session.payment_session_id}/cardBin`;
|
|
51
|
-
const body: string = JSON.stringify({
|
|
56
|
+
const body: string = JSON.stringify({ card_number: bin });
|
|
52
57
|
return await getInfo(session.environment, route, body);
|
|
53
58
|
}
|
|
54
59
|
|
|
@@ -78,6 +83,10 @@ async function getInfo(env: string, route: string, bodyData: string) {
|
|
|
78
83
|
|
|
79
84
|
export type CardPaymentHandle = {
|
|
80
85
|
doPayment: (cardInfo: ElementCard) => void;
|
|
86
|
+
doPaymentWithPaymentSessionId: (
|
|
87
|
+
cardInfo: ElementCard,
|
|
88
|
+
cfSession: CFSession
|
|
89
|
+
) => void;
|
|
81
90
|
};
|
|
82
91
|
|
|
83
92
|
export type CardInputProps = {
|
|
@@ -85,178 +94,195 @@ export type CardInputProps = {
|
|
|
85
94
|
cardListener: (response: string) => void;
|
|
86
95
|
} & TextInputProps;
|
|
87
96
|
|
|
88
|
-
const CardInput: any = forwardRef<CardPaymentHandle, CardInputProps>(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
97
|
+
const CardInput: any = forwardRef<CardPaymentHandle, CardInputProps>(
|
|
98
|
+
({ cfSession, cardListener, style, ...props }: CardInputProps, ref) => {
|
|
99
|
+
const [inputNumber, setInputNumber] = React.useState('');
|
|
100
|
+
React.useImperativeHandle(ref, () => ({
|
|
101
|
+
doPayment,
|
|
102
|
+
doPaymentWithPaymentSessionId,
|
|
103
|
+
}));
|
|
104
|
+
let tdrJson: any = null;
|
|
105
|
+
let cardBinJson: any = null;
|
|
106
|
+
let firstEightDigits: string = '';
|
|
107
|
+
|
|
108
|
+
const handleChange = React.useCallback(
|
|
109
|
+
async (cardNumber: string) => {
|
|
110
|
+
let completeResponse: any = {};
|
|
111
|
+
const textWithoutSpaces: string = cardNumber.replaceAll(' ', '');
|
|
112
|
+
if (textWithoutSpaces.length === 0) setInputNumber('');
|
|
113
|
+
|
|
114
|
+
let formattedText: string = '';
|
|
115
|
+
/**
|
|
116
|
+
* Code to format card input number & set to input box
|
|
117
|
+
*/
|
|
118
|
+
for (let i: number = 0; i < textWithoutSpaces.length; i += 4) {
|
|
119
|
+
let end: number = i + 4;
|
|
120
|
+
if (end > textWithoutSpaces.length) {
|
|
121
|
+
end = textWithoutSpaces.length;
|
|
122
|
+
}
|
|
123
|
+
formattedText += textWithoutSpaces.substring(i, end);
|
|
124
|
+
if (end !== textWithoutSpaces.length) {
|
|
125
|
+
formattedText += ' ';
|
|
126
|
+
}
|
|
127
|
+
setInputNumber(formattedText);
|
|
115
128
|
}
|
|
116
|
-
formattedText += textWithoutSpaces.substring(i, end);
|
|
117
|
-
if (end !== textWithoutSpaces.length) {
|
|
118
|
-
formattedText += ' ';
|
|
119
|
-
}
|
|
120
|
-
setInputNumber(formattedText);
|
|
121
|
-
}
|
|
122
129
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
130
|
+
let tdrResponse: any = null;
|
|
131
|
+
let cardBinResponse: any = null;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Fetch Tdr & CardBin data & set to local variable
|
|
135
|
+
*/
|
|
136
|
+
async function fetchDataAndSet() {
|
|
137
|
+
await getTDR(cfSession, textWithoutSpaces)
|
|
138
|
+
.then((response: string) => {
|
|
139
|
+
tdrResponse = response;
|
|
140
|
+
})
|
|
141
|
+
.catch(() => {
|
|
142
|
+
tdrResponse = null;
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
await getCardBin(cfSession, textWithoutSpaces)
|
|
146
|
+
.then((response: string) => {
|
|
147
|
+
cardBinResponse = response;
|
|
148
|
+
})
|
|
149
|
+
.catch(() => {
|
|
150
|
+
cardBinResponse = null;
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
if (tdrResponse) {
|
|
154
|
+
tdrJson = tdrResponse;
|
|
155
|
+
completeResponse['tdr_info'] = tdrJson;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (cardBinResponse) {
|
|
159
|
+
cardBinJson = cardBinResponse;
|
|
160
|
+
completeResponse['card_bin_info'] = cardBinJson;
|
|
161
|
+
}
|
|
149
162
|
}
|
|
150
163
|
|
|
151
|
-
if (
|
|
152
|
-
|
|
153
|
-
|
|
164
|
+
if (textWithoutSpaces.length === 8) {
|
|
165
|
+
firstEightDigits = textWithoutSpaces;
|
|
166
|
+
await fetchDataAndSet();
|
|
167
|
+
} else if (textWithoutSpaces.length > 8) {
|
|
168
|
+
if (firstEightDigits === textWithoutSpaces.substring(0, 8)) {
|
|
169
|
+
completeResponse['tdr_info'] = tdrJson;
|
|
170
|
+
completeResponse['card_bin_info'] = cardBinJson;
|
|
171
|
+
} else {
|
|
172
|
+
firstEightDigits = textWithoutSpaces.substring(0, 8);
|
|
173
|
+
tdrJson = null;
|
|
174
|
+
cardBinJson = null;
|
|
175
|
+
await fetchDataAndSet();
|
|
176
|
+
}
|
|
154
177
|
}
|
|
155
|
-
}
|
|
156
178
|
|
|
157
|
-
|
|
158
|
-
firstEightDigits = textWithoutSpaces;
|
|
159
|
-
await fetchDataAndSet();
|
|
160
|
-
} else if (textWithoutSpaces.length > 8) {
|
|
161
|
-
if (firstEightDigits === textWithoutSpaces.substring(0, 8)) {
|
|
162
|
-
completeResponse['tdr_info'] = tdrJson;
|
|
163
|
-
completeResponse['card_bin_info'] = cardBinJson;
|
|
164
|
-
} else {
|
|
165
|
-
firstEightDigits = textWithoutSpaces.substring(0, 8);
|
|
166
|
-
tdrJson = null;
|
|
179
|
+
if (textWithoutSpaces.length < 8) {
|
|
167
180
|
cardBinJson = null;
|
|
168
|
-
|
|
181
|
+
tdrJson = null;
|
|
182
|
+
firstEightDigits = '';
|
|
169
183
|
}
|
|
170
|
-
}
|
|
171
184
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
185
|
+
if (cardBinJson !== null) {
|
|
186
|
+
completeResponse['card_network'] = cardBinJson['scheme'];
|
|
187
|
+
}
|
|
188
|
+
let luhnStatus = luhnCheck(textWithoutSpaces);
|
|
189
|
+
if (luhnStatus) {
|
|
190
|
+
completeResponse['luhn_check_info'] = 'SUCCESS';
|
|
191
|
+
if (textWithoutSpaces && textWithoutSpaces.length > 4) {
|
|
192
|
+
completeResponse['last_four_digit'] = textWithoutSpaces.substring(
|
|
193
|
+
textWithoutSpaces.length - 4
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
} else {
|
|
197
|
+
completeResponse['luhn_check_info'] = 'FAIL';
|
|
198
|
+
}
|
|
199
|
+
completeResponse['card_length'] = textWithoutSpaces.length;
|
|
177
200
|
|
|
178
|
-
|
|
179
|
-
|
|
201
|
+
return cardListener(JSON.stringify(completeResponse));
|
|
202
|
+
},
|
|
203
|
+
[cardListener]
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
const doPayment = (cardInfo: ElementCard) => {
|
|
207
|
+
try {
|
|
208
|
+
cardInfo.cardNumber = inputNumber.replaceAll(' ', '');
|
|
209
|
+
const cardPayment = new CFCardPayment(cfSession, cardInfo);
|
|
210
|
+
CFPaymentGatewayService.makePayment(cardPayment);
|
|
211
|
+
} catch (e: any) {
|
|
212
|
+
console.log(e.message);
|
|
180
213
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const doPaymentWithPaymentSessionId = (
|
|
217
|
+
cardInfo: ElementCard,
|
|
218
|
+
session: CFSession
|
|
219
|
+
) => {
|
|
220
|
+
try {
|
|
221
|
+
cfSession = session;
|
|
222
|
+
doPayment(cardInfo);
|
|
223
|
+
} catch (e: any) {
|
|
224
|
+
console.log(e.message);
|
|
184
225
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return cardListener(JSON.stringify(completeResponse));
|
|
188
|
-
},
|
|
189
|
-
[cardListener],
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
const doPayment = (cardInfo: ElementCard) => {
|
|
193
|
-
try {
|
|
194
|
-
cardInfo.cardNumber = inputNumber.replaceAll(' ', '');
|
|
195
|
-
const cardPayment = new CFCardPayment(cfSession, cardInfo);
|
|
196
|
-
CFPaymentGatewayService.makePayment(cardPayment);
|
|
197
|
-
} catch (e: any) {
|
|
198
|
-
console.log(e.message);
|
|
199
|
-
}
|
|
200
|
-
};
|
|
226
|
+
};
|
|
201
227
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
228
|
+
const handleSubmitEditingEvent = (event: any) => {
|
|
229
|
+
const newEvent = { ...event };
|
|
230
|
+
delete newEvent.nativeEvent.text;
|
|
231
|
+
if (onSubmitEditing) {
|
|
232
|
+
onSubmitEditing(newEvent);
|
|
233
|
+
}
|
|
234
|
+
};
|
|
209
235
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
236
|
+
const handleEndEditingEvent = (event: any) => {
|
|
237
|
+
const newEvent = { ...event };
|
|
238
|
+
delete newEvent.nativeEvent.text;
|
|
239
|
+
if (onEndEditing) {
|
|
240
|
+
onEndEditing(newEvent);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
217
243
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
244
|
+
const handleFocusEvent = (event: any) => {
|
|
245
|
+
const newEvent = { ...event };
|
|
246
|
+
delete newEvent.nativeEvent.text;
|
|
247
|
+
if (onFocus) {
|
|
248
|
+
onFocus(newEvent);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
225
251
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
252
|
+
const handleBlurEvent = (event: any) => {
|
|
253
|
+
const newEvent = { ...event };
|
|
254
|
+
delete newEvent.nativeEvent.text;
|
|
255
|
+
if (onBlur) {
|
|
256
|
+
onBlur(newEvent);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const InputComponent: any = TextInput;
|
|
261
|
+
const {
|
|
262
|
+
onChangeText,
|
|
263
|
+
onChange,
|
|
264
|
+
onSubmitEditing,
|
|
265
|
+
onEndEditing,
|
|
266
|
+
onFocus,
|
|
267
|
+
onBlur,
|
|
268
|
+
...otherProps
|
|
269
|
+
} = props;
|
|
270
|
+
|
|
271
|
+
return (
|
|
272
|
+
<InputComponent
|
|
273
|
+
keyboardType="numeric"
|
|
274
|
+
inputMode={'numeric'}
|
|
275
|
+
value={inputNumber}
|
|
276
|
+
onChangeText={handleChange}
|
|
277
|
+
onSubmitEditing={handleSubmitEditingEvent}
|
|
278
|
+
onEndEditing={handleEndEditingEvent}
|
|
279
|
+
onFocus={handleFocusEvent}
|
|
280
|
+
onBlur={handleBlurEvent}
|
|
281
|
+
style={style}
|
|
282
|
+
{...otherProps}
|
|
283
|
+
/>
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
);
|
|
261
287
|
|
|
262
288
|
export default CardInput;
|