-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaymentScreen.js
108 lines (75 loc) · 2.72 KB
/
paymentScreen.js
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
//import liraries
import { useState } from 'react';
import { SafeAreaView, StyleSheet, View, Modal, TouchableOpacity, Text, Button } from 'react-native';
import { CardField ,createToken} from '@stripe/stripe-react-native';
// create a component
const PaymentScreen = () => {
const [cardInfo, setCardInfo] = useState(null)
const [isLoading, setLoading] = useState(false)
const fetchCardDetail = (cardDetail) => {
console.log("my card details",cardDetail)
if (cardDetail.complete) {
setCardInfo(cardDetail)
} else {
setCardInfo(null)
}
}
const onDone = async () => {
console.log("cardInfocardInfocardInfo", cardInfo)
if (!!cardInfo) {
try {
console.log({ ...cardInfo, type: 'Card' });
const resToken = await createToken({ ...cardInfo, type: 'Card' })
console.log("resToken", resToken)
} catch (error) {
console.log(error,'error');
alert("Error raised during create token")
}
}
}
return (
<View style={styles.container}>
<SafeAreaView style={{ flex: 1 }}>
<View style={{ padding: 16 }}>
<CardField
postalCodeEnabled={false}
placeholders={{
number: '4242 4242 4242 4242',
}}
cardStyle={{
backgroundColor: '#FFFFFF',
textColor: '#000000',
}}
style={{
width: '100%',
height: 50,
marginVertical: 30,
}}
onCardChange={(cardDetails) => {
fetchCardDetail(cardDetails)
}}
onFocus={(focusedField) => {
console.log('focusField', focusedField);
}}
/>
<TouchableOpacity
style={{
backgroundColor: 'red',
textColor: '#000000',
}}
onPress={onDone}
disabled={!cardInfo}
><Text>gggggg</Text></TouchableOpacity>
</View>
</SafeAreaView>
</View>
);
};
// define your styles
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
//make this component available to the app
export default PaymentScreen;