-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUranx.jsx
196 lines (188 loc) · 5 KB
/
Uranx.jsx
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import React, { useState } from 'react';
import axios from 'axios';
import { makeStyles } from '@material-ui/core/styles';
import {
Button,
Container,
TextField,
Typography,
Select,
MenuItem,
InputLabel,
FormControl,
} from '@material-ui/core';
const useStyles = makeStyles((theme) => ({
root: {
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
paddingTop: theme.spacing(6),
},
form: {
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
width: '100%',
maxWidth: '400px',
},
input: {
marginBottom: theme.spacing(2),
},
button: {
marginTop: theme.spacing(2),
backgroundColor: '#2196f3',
color: '#fff',
'&:hover': {
backgroundColor: '#1976d2',
},
},
integrationCodeContainer: {
marginTop: theme.spacing(4),
backgroundColor: '#f0f0f0',
padding: theme.spacing(2),
borderRadius: theme.spacing(1),
},
}));
const StripeIntegrationForm = () => {
const classes = useStyles();
const [integrationCode, setIntegrationCode] = useState('');
const [formData, setFormData] = useState({
stripe_secret_key: '',
stripe_publishable_key: '',
product_name: '',
price_amount: 0,
price_currency: '',
is_recurring: false,
success_url: '',
cancel_url: '',
});
const handleChange = (event) => {
const { name, value } = event.target;
setFormData({
...formData,
[name]: name === 'is_recurring' ? value === 'true' : value,
});
};
const handleSubmit = async (event) => {
event.preventDefault();
try {
const response = await axios.post(
'http://127.0.0.1:5000/integrate-stripe',
formData
);
setIntegrationCode(response.data.integration_code);
} catch (err) {
console.error(err);
}
};
return (
<Container className={classes.root}>
<Typography variant="h4" component="h1" gutterBottom>
Stripe Integration
</Typography>
<form className={classes.form} onSubmit={handleSubmit}>
<TextField
className={classes.input}
name="stripe_secret_key"
value={formData.stripe_secret_key}
onChange={handleChange}
label="Stripe Secret Key"
variant="outlined"
required
fullWidth
/>
<TextField
className={classes.input}
name="stripe_publishable_key"
value={formData.stripe_publishable_key}
onChange={handleChange}
label="Stripe Publishable Key"
variant="outlined"
required
fullWidth
/>
<TextField
className={classes.input}
name="product_name"
value={formData.product_name}
onChange={handleChange}
label="Product Name"
variant="outlined"
required
fullWidth
/>
<TextField
className={classes.input}
name="price_amount"
type="number"
value={formData.price_amount}
onChange={handleChange}
label="Price Amount"
variant="outlined"
required
fullWidth
/>
<TextField
className={classes.input}
name="price_currency"
value={formData.price_currency}
onChange={handleChange}
label="Price Currency"
variant="outlined"
required
fullWidth
/>
<FormControl variant="outlined" fullWidth className={classes.input}>
<InputLabel id="is-recurring-label">Payment Type</InputLabel>
<Select
labelId="is-recurring-label"
id="is_recurring"
name="is_recurring"
value={formData.is_recurring ? 'true' : 'false'}
onChange={handleChange}
label="Payment Type"
>
<MenuItem value={'false'}>Single</MenuItem>
<MenuItem value={'true'}>Recurring</MenuItem>
</Select>
</FormControl>
<TextField
className={classes.input}
name="success_url"
value={formData.success_url}
onChange={handleChange}
label="Success URL"
variant="outlined"
required
fullWidth
/>
<TextField
className={classes.input}
name="cancel_url"
value={formData.cancel_url}
onChange={handleChange}
label="Cancel URL"
variant="outlined"
required
fullWidth
/>
<Button
className={classes.button}
variant="contained"
type="submit"
>
Generate Stripe Integration Code
</Button>
</form>
{integrationCode && (
<div className={classes.integrationCodeContainer}>
<Typography variant="h6" component="h2" gutterBottom>
Your Integration Code
</Typography>
<pre>{integrationCode}</pre>
</div>
)}
</Container>
);
};
export default StripeIntegrationForm;