react-native-cashfree-pg-sdk 2.2.7 → 2.3.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/README.md +2 -1
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/reactnativecashfreepgsdk/CashfreePgApiModule.java +317 -195
- package/ios/CashfreePgApi.m +3 -0
- package/ios/CashfreePgApi.swift +117 -1
- package/lib/commonjs/Card/CFCardComponent.js +1 -2
- package/lib/commonjs/Card/CFCardComponent.js.map +1 -1
- package/lib/commonjs/Card/CFSubsCardComponent.js +247 -0
- package/lib/commonjs/Card/CFSubsCardComponent.js.map +1 -0
- package/lib/commonjs/Card/index.js +7 -0
- package/lib/commonjs/Card/index.js.map +1 -1
- package/lib/commonjs/index.js +16 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/Card/CFSubsCardComponent.js +240 -0
- package/lib/module/Card/CFSubsCardComponent.js.map +1 -0
- package/lib/module/Card/index.js +1 -0
- package/lib/module/Card/index.js.map +1 -1
- package/lib/module/index.js +16 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/Card/CFSubsCardComponent.d.ts +12 -0
- package/lib/typescript/src/Card/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts +2 -0
- package/package.json +9 -2
- package/react-native-cashfree-pg-sdk.podspec +1 -1
- package/src/Card/CFSubsCardComponent.js +203 -0
- package/src/Card/CFSubsCardComponent.tsx +294 -0
- package/src/Card/index.js +1 -0
- package/src/Card/index.ts +1 -0
- package/src/index.js +19 -1
- package/src/index.ts +19 -0
- package/android/.gradle/8.10.2/checksums/checksums.lock +0 -0
- package/android/.gradle/8.10.2/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/8.10.2/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/8.10.2/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.10.2/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/8.10.2/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.10.2/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/8.10.2/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.10.2/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/8.10.2/gc.properties +0 -0
- package/android/.gradle/8.12/checksums/checksums.lock +0 -0
- package/android/.gradle/8.12/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/8.12/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/8.12/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.12/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/8.12/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.12/gc.properties +0 -0
- package/android/.gradle/8.7/checksums/checksums.lock +0 -0
- package/android/.gradle/8.7/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/8.7/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/8.7/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.7/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/8.7/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/8.7/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.7/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/8.7/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.7/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/8.7/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- 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/.gradle/config.properties +0 -2
- package/android/.gradle/configuration-cache/gc.properties +0 -0
- package/android/.gradle/file-system.probe +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/caches/deviceStreaming.xml +0 -1462
- package/android/.idea/compiler.xml +0 -6
- package/android/.idea/copilot.data.migration.ask2agent.xml +0 -6
- package/android/.idea/gradle.xml +0 -19
- package/android/.idea/jarRepositories.xml +0 -50
- package/android/.idea/kotlinc.xml +0 -6
- package/android/.idea/migrations.xml +0 -10
- package/android/.idea/misc.xml +0 -9
- package/android/.idea/modules/android.androidTest.iml +0 -6
- package/android/.idea/modules/android.main.iml +0 -6
- package/android/.idea/modules/android.unitTest.iml +0 -6
- package/android/.idea/other.xml +0 -736
- package/android/.idea/runConfigurations.xml +0 -17
- package/android/.idea/sonarlint/issuestore/0/6/066a3db98a4a279fde40d6ddf92c417b5c93198b +0 -0
- package/android/.idea/sonarlint/issuestore/3/e/3e1984987c20cd21984de8c97894175bd94b0037 +0 -3
- package/android/.idea/sonarlint/issuestore/4/4/44aaf172f11159c609e569cf1b49bcd49376a770 +0 -4
- package/android/.idea/sonarlint/issuestore/f/0/f07866736216be0ee2aba49e392191aeae700a35 +0 -0
- package/android/.idea/sonarlint/issuestore/f/b/fbe448ebfc3eb2d4e308f6b8b043666f5b57235e +0 -0
- package/android/.idea/sonarlint/issuestore/index.pb +0 -11
- package/android/.idea/sonarlint/securityhotspotstore/0/6/066a3db98a4a279fde40d6ddf92c417b5c93198b +0 -0
- package/android/.idea/sonarlint/securityhotspotstore/3/e/3e1984987c20cd21984de8c97894175bd94b0037 +0 -0
- package/android/.idea/sonarlint/securityhotspotstore/4/4/44aaf172f11159c609e569cf1b49bcd49376a770 +0 -0
- package/android/.idea/sonarlint/securityhotspotstore/f/0/f07866736216be0ee2aba49e392191aeae700a35 +0 -0
- package/android/.idea/sonarlint/securityhotspotstore/f/b/fbe448ebfc3eb2d4e308f6b8b043666f5b57235e +0 -0
- package/android/.idea/sonarlint/securityhotspotstore/index.pb +0 -11
- package/android/.idea/sonarlint.xml +0 -6
- package/android/.idea/vcs.xml +0 -6
- package/ios/CashfreePgApi.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/ios/CashfreePgApi.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/CashfreePgApi.xcodeproj/project.xcworkspace/xcuserdata/kishankumarmaurya.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/CashfreePgApi.xcodeproj/xcuserdata/kishankumarmaurya.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +0 -6
- package/ios/CashfreePgApi.xcodeproj/xcuserdata/kishankumarmaurya.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
|
@@ -0,0 +1,203 @@
|
|
|
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;
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { TextInput, TextInputProps } from 'react-native';
|
|
2
|
+
import React, { forwardRef } from 'react';
|
|
3
|
+
import {
|
|
4
|
+
CFSubsCardPayment,
|
|
5
|
+
CFEnvironment,
|
|
6
|
+
type CFSubscriptionSession,
|
|
7
|
+
ElementCard,
|
|
8
|
+
} from 'cashfree-pg-api-contract';
|
|
9
|
+
import { CFPaymentGatewayService } from '../index';
|
|
10
|
+
|
|
11
|
+
function luhnCheck(cardNumber: string): boolean {
|
|
12
|
+
if (cardNumber.length === 0) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
cardNumber = cardNumber.replace(/\s/g, '');
|
|
17
|
+
|
|
18
|
+
let sum = 0;
|
|
19
|
+
let isAlternate = false;
|
|
20
|
+
|
|
21
|
+
for (let i = cardNumber.length - 1; i >= 0; i--) {
|
|
22
|
+
let digit = parseInt(cardNumber[i], 10);
|
|
23
|
+
|
|
24
|
+
if (isAlternate) {
|
|
25
|
+
digit *= 2;
|
|
26
|
+
if (digit > 9) {
|
|
27
|
+
digit -= 9;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
sum += digit;
|
|
32
|
+
isAlternate = !isAlternate;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return sum % 10 === 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getInputValidationDetails(cardBinResponse: any) {
|
|
39
|
+
if (!cardBinResponse || !cardBinResponse.scheme) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const schemeType = cardBinResponse.scheme.toLowerCase();
|
|
44
|
+
let inputValidationDetails: { max_input_length: number; cvv_length: number };
|
|
45
|
+
switch (schemeType) {
|
|
46
|
+
case 'amex':
|
|
47
|
+
inputValidationDetails = { max_input_length: 15, cvv_length: 4 };
|
|
48
|
+
break;
|
|
49
|
+
case 'diners':
|
|
50
|
+
inputValidationDetails = { max_input_length: 14, cvv_length: 3 };
|
|
51
|
+
break;
|
|
52
|
+
default: // Covers visa, mastercard, rupay, jcb, discover, and unknown schemes
|
|
53
|
+
inputValidationDetails = { max_input_length: 16, cvv_length: 3 };
|
|
54
|
+
}
|
|
55
|
+
return inputValidationDetails;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Fetching CardBin info with card bin data & CFSubscriptionSession object
|
|
60
|
+
* @param session : for subs sessionId & env
|
|
61
|
+
* @param bin : for card number
|
|
62
|
+
*/
|
|
63
|
+
async function getCardBin(session: CFSubscriptionSession, bin: string) {
|
|
64
|
+
const route: string = `/pg/sdk/js/subscription/card/bin`;
|
|
65
|
+
const body: string = JSON.stringify({ card_number: bin });
|
|
66
|
+
let baseUrl = 'https://api.cashfree.com';
|
|
67
|
+
if (session.environment === CFEnvironment.SANDBOX) {
|
|
68
|
+
baseUrl = 'https://sandbox.cashfree.com';
|
|
69
|
+
}
|
|
70
|
+
const url = baseUrl + route;
|
|
71
|
+
try {
|
|
72
|
+
const response = await fetch(url, {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
headers: {
|
|
75
|
+
'Content-Type': 'application/json',
|
|
76
|
+
'x-sub-session-id': session.subscription_session_id,
|
|
77
|
+
},
|
|
78
|
+
body,
|
|
79
|
+
});
|
|
80
|
+
if (!response.ok) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
return await response.json();
|
|
84
|
+
} catch (error) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type SubsCardPaymentHandle = {
|
|
90
|
+
doSubscriptionPayment: (cardInfo: ElementCard) => void;
|
|
91
|
+
doSubscriptionPaymentWithNewSession: (
|
|
92
|
+
cardInfo: ElementCard,
|
|
93
|
+
cfSubscriptionSession: CFSubscriptionSession
|
|
94
|
+
) => void;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export type SubsCardInputProps = {
|
|
98
|
+
cfSubscriptionSession: CFSubscriptionSession;
|
|
99
|
+
cardListener: (response: string) => void;
|
|
100
|
+
} & TextInputProps;
|
|
101
|
+
|
|
102
|
+
const SubsCardInput: any = forwardRef<
|
|
103
|
+
SubsCardPaymentHandle,
|
|
104
|
+
SubsCardInputProps
|
|
105
|
+
>(
|
|
106
|
+
(
|
|
107
|
+
{
|
|
108
|
+
cfSubscriptionSession,
|
|
109
|
+
cardListener,
|
|
110
|
+
style,
|
|
111
|
+
...props
|
|
112
|
+
}: SubsCardInputProps,
|
|
113
|
+
ref
|
|
114
|
+
) => {
|
|
115
|
+
const [inputNumber, setInputNumber] = React.useState('');
|
|
116
|
+
const inputNumberRef = React.useRef('');
|
|
117
|
+
const sessionRef = React.useRef(cfSubscriptionSession);
|
|
118
|
+
React.useImperativeHandle(ref, () => ({
|
|
119
|
+
doSubscriptionPayment,
|
|
120
|
+
doSubscriptionPaymentWithNewSession,
|
|
121
|
+
}));
|
|
122
|
+
|
|
123
|
+
const cardBinJsonRef = React.useRef<any>(null);
|
|
124
|
+
const firstEightDigitsRef = React.useRef<string>('');
|
|
125
|
+
|
|
126
|
+
const handleChange = React.useCallback(
|
|
127
|
+
async (cardNumber: string) => {
|
|
128
|
+
let completeResponse: any = {};
|
|
129
|
+
const textWithoutSpaces: string = cardNumber.replaceAll(' ', '');
|
|
130
|
+
if (textWithoutSpaces.length === 0) setInputNumber('');
|
|
131
|
+
|
|
132
|
+
let formattedText: string = '';
|
|
133
|
+
for (let i: number = 0; i < textWithoutSpaces.length; i += 4) {
|
|
134
|
+
let end: number = i + 4;
|
|
135
|
+
if (end > textWithoutSpaces.length) {
|
|
136
|
+
end = textWithoutSpaces.length;
|
|
137
|
+
}
|
|
138
|
+
formattedText += textWithoutSpaces.substring(i, end);
|
|
139
|
+
if (end !== textWithoutSpaces.length) {
|
|
140
|
+
formattedText += ' ';
|
|
141
|
+
}
|
|
142
|
+
inputNumberRef.current = formattedText;
|
|
143
|
+
setInputNumber((prev) =>
|
|
144
|
+
prev === formattedText ? prev : formattedText
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let cardBinResponse: any = null;
|
|
149
|
+
|
|
150
|
+
async function fetchCardBinAndSet() {
|
|
151
|
+
await getCardBin(cfSubscriptionSession, textWithoutSpaces)
|
|
152
|
+
.then((response: string) => {
|
|
153
|
+
cardBinResponse = response;
|
|
154
|
+
firstEightDigitsRef.current = textWithoutSpaces.substring(0, 8);
|
|
155
|
+
})
|
|
156
|
+
.catch(() => {
|
|
157
|
+
cardBinResponse = null;
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
if (cardBinResponse) {
|
|
161
|
+
cardBinJsonRef.current = cardBinResponse;
|
|
162
|
+
completeResponse.card_bin_info = cardBinJsonRef.current;
|
|
163
|
+
completeResponse.input_validation = getInputValidationDetails(
|
|
164
|
+
cardBinJsonRef.current
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (textWithoutSpaces.length === 8) {
|
|
170
|
+
await fetchCardBinAndSet();
|
|
171
|
+
} else if (textWithoutSpaces.length > 8) {
|
|
172
|
+
if (
|
|
173
|
+
firstEightDigitsRef.current === textWithoutSpaces.substring(0, 8)
|
|
174
|
+
) {
|
|
175
|
+
completeResponse.card_bin_info = cardBinJsonRef.current;
|
|
176
|
+
completeResponse.input_validation = getInputValidationDetails(
|
|
177
|
+
cardBinJsonRef.current
|
|
178
|
+
);
|
|
179
|
+
} else {
|
|
180
|
+
cardBinJsonRef.current = null;
|
|
181
|
+
await fetchCardBinAndSet();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (textWithoutSpaces.length < 8) {
|
|
186
|
+
cardBinJsonRef.current = null;
|
|
187
|
+
firstEightDigitsRef.current = '';
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (cardBinJsonRef.current !== null) {
|
|
191
|
+
completeResponse.card_network = cardBinJsonRef.current.scheme;
|
|
192
|
+
}
|
|
193
|
+
let luhnStatus = luhnCheck(textWithoutSpaces);
|
|
194
|
+
if (luhnStatus) {
|
|
195
|
+
completeResponse.luhn_check_info = 'SUCCESS';
|
|
196
|
+
if (textWithoutSpaces && textWithoutSpaces.length > 4) {
|
|
197
|
+
completeResponse.last_four_digit = textWithoutSpaces.substring(
|
|
198
|
+
textWithoutSpaces.length - 4
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
} else {
|
|
202
|
+
completeResponse.luhn_check_info = 'FAIL';
|
|
203
|
+
}
|
|
204
|
+
completeResponse.card_length = textWithoutSpaces.length;
|
|
205
|
+
|
|
206
|
+
return cardListener(JSON.stringify(completeResponse));
|
|
207
|
+
},
|
|
208
|
+
[cfSubscriptionSession, cardListener]
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
const doSubscriptionPayment = (cardInfo: ElementCard) => {
|
|
212
|
+
try {
|
|
213
|
+
let cfCardNumber = inputNumberRef.current;
|
|
214
|
+
cardInfo.cardNumber = cfCardNumber.replaceAll(' ', '');
|
|
215
|
+
const cardPayment = new CFSubsCardPayment(sessionRef.current, cardInfo);
|
|
216
|
+
CFPaymentGatewayService.makeSubsPayment(cardPayment);
|
|
217
|
+
} catch (e: any) {
|
|
218
|
+
console.log(e.message);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const doSubscriptionPaymentWithNewSession = (
|
|
223
|
+
cardInfo: ElementCard,
|
|
224
|
+
session: CFSubscriptionSession
|
|
225
|
+
) => {
|
|
226
|
+
try {
|
|
227
|
+
sessionRef.current = session;
|
|
228
|
+
doSubscriptionPayment(cardInfo);
|
|
229
|
+
} catch (e: any) {
|
|
230
|
+
console.log(e.message);
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const handleSubmitEditingEvent = (event: any) => {
|
|
235
|
+
const newEvent = { ...event };
|
|
236
|
+
delete newEvent.nativeEvent.text;
|
|
237
|
+
if (onSubmitEditing) {
|
|
238
|
+
onSubmitEditing(newEvent);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const handleEndEditingEvent = (event: any) => {
|
|
243
|
+
const newEvent = { ...event };
|
|
244
|
+
delete newEvent.nativeEvent.text;
|
|
245
|
+
if (onEndEditing) {
|
|
246
|
+
onEndEditing(newEvent);
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const handleFocusEvent = (event: any) => {
|
|
251
|
+
const newEvent = { ...event };
|
|
252
|
+
delete newEvent.nativeEvent.text;
|
|
253
|
+
if (onFocus) {
|
|
254
|
+
onFocus(newEvent);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const handleBlurEvent = (event: any) => {
|
|
259
|
+
const newEvent = { ...event };
|
|
260
|
+
delete newEvent.nativeEvent.text;
|
|
261
|
+
if (onBlur) {
|
|
262
|
+
onBlur(newEvent);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
const InputComponent: any = TextInput;
|
|
267
|
+
const {
|
|
268
|
+
onChangeText,
|
|
269
|
+
onChange,
|
|
270
|
+
onSubmitEditing,
|
|
271
|
+
onEndEditing,
|
|
272
|
+
onFocus,
|
|
273
|
+
onBlur,
|
|
274
|
+
...otherProps
|
|
275
|
+
} = props;
|
|
276
|
+
|
|
277
|
+
return (
|
|
278
|
+
<InputComponent
|
|
279
|
+
keyboardType="numeric"
|
|
280
|
+
inputMode={'numeric'}
|
|
281
|
+
value={inputNumber}
|
|
282
|
+
onChangeText={handleChange}
|
|
283
|
+
onSubmitEditing={handleSubmitEditingEvent}
|
|
284
|
+
onEndEditing={handleEndEditingEvent}
|
|
285
|
+
onFocus={handleFocusEvent}
|
|
286
|
+
onBlur={handleBlurEvent}
|
|
287
|
+
style={style}
|
|
288
|
+
{...otherProps}
|
|
289
|
+
/>
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
export default SubsCardInput;
|
package/src/Card/index.js
CHANGED
package/src/Card/index.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { NativeAppEventEmitter, NativeEventEmitter, NativeModules, Platform, } from 'react-native';
|
|
2
2
|
import { version } from '../package.json';
|
|
3
|
-
import { CFUPIPayment, CFCardPayment, } from 'cashfree-pg-api-contract';
|
|
3
|
+
import { CFUPIPayment, CFCardPayment, CFSubsUPIPayment, CFSubsCardPayment, CFSubsNBPayment, } from 'cashfree-pg-api-contract';
|
|
4
4
|
import CFCardComponent from './Card/CFCardComponent';
|
|
5
|
+
import CFSubsCardComponent from './Card/CFSubsCardComponent';
|
|
5
6
|
const LINKING_ERROR = `The package 'react-native-cashfree-pg-api' doesn't seem to be linked. Make sure: \n\n` +
|
|
6
7
|
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
7
8
|
'- You rebuilt the app after installing the package\n' +
|
|
@@ -85,6 +86,22 @@ class CFPaymentGateway {
|
|
|
85
86
|
console.log('makePayment::==> Wrong payment object');
|
|
86
87
|
}
|
|
87
88
|
}
|
|
89
|
+
makeSubsPayment(cfPayment) {
|
|
90
|
+
cfPayment.version = version;
|
|
91
|
+
const paymentData = JSON.stringify(cfPayment);
|
|
92
|
+
if (cfPayment instanceof CFSubsUPIPayment) {
|
|
93
|
+
CashfreePgApi.doSubsUPIPayment(paymentData);
|
|
94
|
+
}
|
|
95
|
+
else if (cfPayment instanceof CFSubsCardPayment) {
|
|
96
|
+
CashfreePgApi.doSubsCardPayment(paymentData);
|
|
97
|
+
}
|
|
98
|
+
else if (cfPayment instanceof CFSubsNBPayment) {
|
|
99
|
+
CashfreePgApi.doSubsNBPayment(paymentData);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
console.log('makePayment::==> Wrong payment object');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
88
105
|
setEventSubscriber(cfEventCallback) {
|
|
89
106
|
let eventFunction = (event) => {
|
|
90
107
|
console.log(JSON.stringify(event));
|
|
@@ -167,4 +184,5 @@ export class CFErrorResponse {
|
|
|
167
184
|
}
|
|
168
185
|
}
|
|
169
186
|
export const CFCard = CFCardComponent;
|
|
187
|
+
export const CFSubsCard = CFSubsCardComponent;
|
|
170
188
|
export const CFPaymentGatewayService = new CFPaymentGateway();
|
package/src/index.ts
CHANGED
|
@@ -12,8 +12,12 @@ import {
|
|
|
12
12
|
type CFSubscriptionSession,
|
|
13
13
|
CFUPIPayment,
|
|
14
14
|
CFCardPayment,
|
|
15
|
+
CFSubsUPIPayment,
|
|
16
|
+
CFSubsCardPayment,
|
|
17
|
+
CFSubsNBPayment,
|
|
15
18
|
} from 'cashfree-pg-api-contract';
|
|
16
19
|
import CFCardComponent from './Card/CFCardComponent';
|
|
20
|
+
import CFSubsCardComponent from './Card/CFSubsCardComponent';
|
|
17
21
|
|
|
18
22
|
const LINKING_ERROR =
|
|
19
23
|
`The package 'react-native-cashfree-pg-api' doesn't seem to be linked. Make sure: \n\n` +
|
|
@@ -111,6 +115,20 @@ class CFPaymentGateway {
|
|
|
111
115
|
}
|
|
112
116
|
}
|
|
113
117
|
|
|
118
|
+
makeSubsPayment(cfPayment: CheckoutPayment){
|
|
119
|
+
cfPayment.version = version;
|
|
120
|
+
const paymentData = JSON.stringify(cfPayment);
|
|
121
|
+
if (cfPayment instanceof CFSubsUPIPayment) {
|
|
122
|
+
CashfreePgApi.doSubsUPIPayment(paymentData);
|
|
123
|
+
} else if (cfPayment instanceof CFSubsCardPayment) {
|
|
124
|
+
CashfreePgApi.doSubsCardPayment(paymentData);
|
|
125
|
+
} else if (cfPayment instanceof CFSubsNBPayment) {
|
|
126
|
+
CashfreePgApi.doSubsNBPayment(paymentData);
|
|
127
|
+
} else {
|
|
128
|
+
console.log('makePayment::==> Wrong payment object');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
114
132
|
setEventSubscriber(cfEventCallback: CFEventCallback) {
|
|
115
133
|
let eventFunction = (event: string) => {
|
|
116
134
|
console.log(JSON.stringify(event));
|
|
@@ -227,4 +245,5 @@ export class CFErrorResponse {
|
|
|
227
245
|
}
|
|
228
246
|
|
|
229
247
|
export const CFCard = CFCardComponent;
|
|
248
|
+
export const CFSubsCard = CFSubsCardComponent;
|
|
230
249
|
export const CFPaymentGatewayService = new CFPaymentGateway();
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
File without changes
|