forked from Proder/cardTokenizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcard.js
More file actions
128 lines (113 loc) · 3.17 KB
/
card.js
File metadata and controls
128 lines (113 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import React, { Component } from "react";
import {View, SafeAreaView , StyleSheet,TextInput,Dimensions,ActivityIndicator,Alert,Button} from 'react-native';
import { IconButton } from "react-native-paper";
import * as SecureStore from "expo-secure-store"
const getToken = async ()=>{
let result = {}
result.t = await SecureStore.getItemAsync("access_token");
result.id = await SecureStore.getItemAsync("id");
return result
}
const deviceWidth = Math.round(Dimensions.get('window').width)
export default class Card extends Component {
constructor() {
super();
this.state = {
fullPAN: "",
expDate: "",
isLoading: false,
};
}
updateInputVal = (val, prop) => {
const state = this.state;
state[prop] = val;
this.setState(state);
};
functino =()=>{
this.cardRegister();
Alert.alert("New Card Registered");
this.props.navigation.navigate('Listing')
}
cardRegister = () => {
getToken()
.then((result)=>{
if (this.state.fullPAN === "" && this.state.expDate === "") {
Alert.alert("Enter details to Update!");
} else {
this.setState({
isLoading: true,
});
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Accept", "application/json");
myHeaders.append("Authorization", `Bearer ${result.t}`);
var raw = JSON.stringify({
fullPAN: this.state.fullPAN,
expDate: this.state.expDate,
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://web-production-eedc.up.railway.app/card/", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
}})
.catch(error => console.log('error', error));
}
render() {
if (this.state.isLoading) {
return (
<View style={styles.preloader}>
<ActivityIndicator size="large" color="#9E9E9E" />
</View>
);
}
return (
<SafeAreaView style={styles.container}>
<View>
<TextInput style = {styles.formField}
placeholder="PanNo."
value={this.state.fullPAN}
onChangeText={(val) => this.updateInputVal(val, "fullPAN")}
/>
<TextInput style = {styles.formField}
placeholder="Enter Expiry Date"
value={this.state.expDate}
onChangeText={(val) => this.updateInputVal(val, "expDate")}
/>
</View>
<View style={{marginTop:30,marginBottom:30}}>
<IconButton
icon="credit-card-plus-outline"
iconColor={"#000000"}
size={50}
onPress={() => this.functino()}
/>
</View>
<Button
color="#3740FE"
style={styles.button}
title="Check your cards"
onPress={() =>this.props.navigation.navigate("Listing")}
/>
</SafeAreaView>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center"
},
formField:{
marginBottom : 20,
width : deviceWidth - 25,
backgroundColor:'#a29bfe',
height : 40,
borderRadius : 20,
}
});