-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.php
More file actions
executable file
·274 lines (232 loc) · 9.53 KB
/
index.php
File metadata and controls
executable file
·274 lines (232 loc) · 9.53 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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<?php
require_once('init.php');
require_once('config.php');
if ($_POST) {
\Stripe\Stripe::setApiKey($STRIPE_SECRET_KEY);
$error = '';
$success = '';
try {
if (!isset($_POST['stripe_token']))
throw new Exception("The Stripe Token was not generated correctly");
\Stripe\Charge::create(array("amount" => $_POST['amount'],
"currency" => "usd",
"card" => $_POST['stripe_token'],
"description" => "Shea Silverman Campaign Donation",
"metadata" => array("email" => $_POST['email'], "occupation" => $_POST['occupation'], "employer" => $_POST['employer']),
));
$success = '<div class="alert alert-success">
<strong>Success!</strong> Your donation was successful. Thank you for your support.
</div>';
}
catch (Exception $e) {
$error = '<div class="alert alert-danger">
<strong>Error!</strong> '.$e->getMessage().'
</div>';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Donate | Shea Silverman for Florida House of Representatives District 49</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<header>
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="fa fa-bars"></span>
</button>
<a class="navbar-brand" href="#"><?php echo $header; ?></a>
</div>
</div>
</div>
</header>
<h2 class="text-left">Donate</h2>
<div class="row">
<div class="col-md-6">
<div class="well">
<div class="row text-center">
<div class="col-md-4"><button type="button" onclick="setDonation('1.00');" class="btn btn-primary btn-lg">1.00</button></div>
<div class="col-md-4"><button type="button" onclick="setDonation('5.00');" class="btn btn-primary btn-lg">5.00</button></div>
<div class="col-md-4"><button type="button" onclick="setDonation('10.00');" class="btn btn-primary btn-lg">10.00</button></div>
</div>
<p> </p>
<div class="row text-center">
<div class="col-md-4"><button type="button" onclick="setDonation('25.00');" class="btn btn-primary btn-lg">25.00</button></div>
<div class="col-md-4"><button type="button" onclick="setDonation('50.00');" class="btn btn-primary btn-lg">50.00</button></div>
<div class="col-md-4"><button type="button" onclick="setDonation('100.00');" class="btn btn-primary btn-lg">100.00</button></div>
</div>
<p> </p>
<div class="row">
<div class="col-md-6">
<div class="input-group input-group-lg">
<p><small>Occupation</small></p>
<input type="text" id="occupation" placeholder="Occupation" class="form-control" aria-label="Occupation">
</div>
</div>
<div class="col-md-6">
<div class="input-group input-group-lg">
<p><small>Employer</small></p>
<input type="text" id="employer" placeholder="Employer" class="form-control" aria-label="Employer" >
</div>
</div>
</div>
<p> </p>
<p class="lead">Other Amount:</p>
<div class="row">
<div class="col-md-6">
<div class="input-group input-group-lg">
<span class="input-group-addon">$</span>
<input type="number" min="1.00" max="2500.00" id="other_amount" name="other_amount" class="form-control" aria-label="Amount (to the nearest dollar)">
<!-- <span class="input-group-addon">.00</span> -->
</div>
</div>
<div class="col-md-6">
<button type="button" class="btn btn-primary btn-lg" id="donateButton" disabled>Donate</button>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="well">
<p class="lead">Send checks to:</p>
<p>
<address>
<strong>Shea Silverman</strong><br />
3412 Rider Place<br />
Orlando, FL 32817<br />
</address>
</div>
</div>
</div>
<?php echo $success; echo $error; ?>
<hr />
<div style="padding: 5px; text-align: center; border: solid 1px black">
<?php echo $footer; ?>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script src="https://checkout.stripe.com/checkout.js"></script>
<script>
action();
$('#occupation, #employer', '#other_amount').on("keyup", action);
$("body").on('keyup', "#occupation", action);
$("body").on('keyup', "#employer", action);
$("body").on('keyup', "#other_amount", action);
$('#other_amount').on("change", action);
function action() {
//console.log("Running");
if( $('#occupation').val().length > 0 && $('#employer').val().length > 0 && $('#other_amount').val() != '' ) {
$('#donateButton').prop("disabled", false);
} else {
$('#donateButton').prop("disabled", true);
}
}
var handler = StripeCheckout.configure({
key: '<?php echo $STRIPE_PUBLIC_KEY; ?>',
//image: '/img/documentation/checkout/marketplace.png',
locale: 'auto',
token: function(token) {
// Use the token to create the charge with a server-side script.
// You can access the token ID with `token.id`
var newForm = jQuery('<form>', {
'action': '#',
'target': '_top',
'method': 'POST',
}).append(jQuery('<input>', {
'name': 'stripe_token',
'value': token.id,
'type': 'hidden'
})).append(jQuery('<input>', {
'name': 'occupation',
'value': $('#occupation').val(),
'type': 'hidden'
})).append(jQuery('<input>', {
'name': 'employer',
'value': $('#employer').val(),
'type': 'hidden'
})).append(jQuery('<input>', {
'name': 'csrfmiddlewaretoken',
'value': getCookie('csrftoken'),
'type': 'hidden'
})).append(jQuery('<input>', {
'name': 'amount',
'value': $('#other_amount').val() * 100,
'type': 'hidden'
})).append(jQuery('<input>', {
'name': 'email',
'value': token.email,
'type': 'hidden'
}));
$("body").append(newForm);
newForm.submit();
}
});
$('#donateButton').on('click', function(e) {
// Open Checkout with further options
var amount = $("#other_amount").val();
if (amount < 0.50 || amount > 1000.00) {
alert("Sorry. The donation amount must be between $0.50 and $1000.00.");
return 1;
}
amount = amount * 100;
handler.open({
name: 'Shea Silverman',
description: 'Campaign Donation',
amount: amount,
billingAddress: true,
});
e.preventDefault();
});
var setDonation = function(amount) {
$("#other_amount").val(amount);
action();
}
// Close Checkout on page navigation
$(window).on('popstate', function() {
handler.close();
});
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-76743107-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>