react-native-cashfree-pg-sdk 2.1.18 → 2.1.19-dev.1
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 +20 -18
- package/lib/commonjs/Card/CFCardComponent.js.map +1 -1
- package/lib/module/Card/CFCardComponent.js +17 -12
- 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 +17 -5
- package/src/Card/CFCardComponent.tsx +179 -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,188 @@ 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
|
+
completeResponse['luhn_check_info'] = 'SUCCESS';
|
|
189
|
+
if (!luhnCheck(textWithoutSpaces)) {
|
|
190
|
+
completeResponse['luhn_check_info'] = 'FAIL';
|
|
191
|
+
}
|
|
192
|
+
completeResponse['card_length'] = textWithoutSpaces.length;
|
|
177
193
|
|
|
178
|
-
|
|
179
|
-
|
|
194
|
+
return cardListener(JSON.stringify(completeResponse));
|
|
195
|
+
},
|
|
196
|
+
[cardListener]
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
const doPayment = (cardInfo: ElementCard) => {
|
|
200
|
+
try {
|
|
201
|
+
cardInfo.cardNumber = inputNumber.replaceAll(' ', '');
|
|
202
|
+
const cardPayment = new CFCardPayment(cfSession, cardInfo);
|
|
203
|
+
CFPaymentGatewayService.makePayment(cardPayment);
|
|
204
|
+
} catch (e: any) {
|
|
205
|
+
console.log(e.message);
|
|
180
206
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const doPaymentWithPaymentSessionId = (
|
|
210
|
+
cardInfo: ElementCard,
|
|
211
|
+
session: CFSession
|
|
212
|
+
) => {
|
|
213
|
+
try {
|
|
214
|
+
cfSession = session;
|
|
215
|
+
doPayment(cardInfo);
|
|
216
|
+
} catch (e: any) {
|
|
217
|
+
console.log(e.message);
|
|
184
218
|
}
|
|
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
|
-
};
|
|
219
|
+
};
|
|
201
220
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
221
|
+
const handleSubmitEditingEvent = (event: any) => {
|
|
222
|
+
const newEvent = { ...event };
|
|
223
|
+
delete newEvent.nativeEvent.text;
|
|
224
|
+
if (onSubmitEditing) {
|
|
225
|
+
onSubmitEditing(newEvent);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
209
228
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
229
|
+
const handleEndEditingEvent = (event: any) => {
|
|
230
|
+
const newEvent = { ...event };
|
|
231
|
+
delete newEvent.nativeEvent.text;
|
|
232
|
+
if (onEndEditing) {
|
|
233
|
+
onEndEditing(newEvent);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
217
236
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
237
|
+
const handleFocusEvent = (event: any) => {
|
|
238
|
+
const newEvent = { ...event };
|
|
239
|
+
delete newEvent.nativeEvent.text;
|
|
240
|
+
if (onFocus) {
|
|
241
|
+
onFocus(newEvent);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
225
244
|
|
|
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
|
-
|
|
245
|
+
const handleBlurEvent = (event: any) => {
|
|
246
|
+
const newEvent = { ...event };
|
|
247
|
+
delete newEvent.nativeEvent.text;
|
|
248
|
+
if (onBlur) {
|
|
249
|
+
onBlur(newEvent);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const InputComponent: any = TextInput;
|
|
254
|
+
const {
|
|
255
|
+
onChangeText,
|
|
256
|
+
onChange,
|
|
257
|
+
onSubmitEditing,
|
|
258
|
+
onEndEditing,
|
|
259
|
+
onFocus,
|
|
260
|
+
onBlur,
|
|
261
|
+
...otherProps
|
|
262
|
+
} = props;
|
|
263
|
+
|
|
264
|
+
return (
|
|
265
|
+
<InputComponent
|
|
266
|
+
keyboardType="numeric"
|
|
267
|
+
inputMode={'numeric'}
|
|
268
|
+
value={inputNumber}
|
|
269
|
+
onChangeText={handleChange}
|
|
270
|
+
onSubmitEditing={handleSubmitEditingEvent}
|
|
271
|
+
onEndEditing={handleEndEditingEvent}
|
|
272
|
+
onFocus={handleFocusEvent}
|
|
273
|
+
onBlur={handleBlurEvent}
|
|
274
|
+
style={style}
|
|
275
|
+
{...otherProps}
|
|
276
|
+
/>
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
);
|
|
261
280
|
|
|
262
281
|
export default CardInput;
|