The SRA Website https://socialistra.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

464 lines
14 KiB

<?php
// Copyright (C) 2021 Socialist Rifle Association
//
// This file is part of SRA Website.
//
// website is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// website is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with website. If not, see <http://www.gnu.org/licenses/>.
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Socialist Rifle Association</title>
<?php include("../res/php/headtags.php") ?>
<script src="https://srastatic.nyc3.cdn.digitaloceanspaces.com/web/js/lib/material-display.js" type="text/javascript"></script>
<script src="https://srastatic.nyc3.cdn.digitaloceanspaces.com/web/js/stripe/card.js" type="text/javascript"></script>
<script src="https://js.stripe.com/v3/"></script>
</head>
<style type="text/css">
::placeholder { /* Chrome, Firefox, Opera, Safari 10.1+ */
color: #000 !important;
opacity: 1; /* Firefox */
}
::-webkit-input-placeholder { /* WebKit, Blink, Edge */
color: #000 !important;
}
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
color: #000 !important;
opacity: 1;
}
::-moz-placeholder { /* Mozilla Firefox 19+ */
color: #000 !important;
opacity: 1;
}
:-ms-input-placeholder { /* Internet Explorer 10-11 */
color: #000 !important;
}
::-ms-input-placeholder { /* Microsoft Edge */
color: #000 !important;
}
::placeholder { /* Most modern browsers support this now. */
color: #000 !important;
}
#member-con {
font-family: 'Heebo', sans-serif;
paddinecho $response;g-bottom: 50em;
}
#pform {
width: 100%;
margin: auto auto;
display: block;
font-family: 'Heebo', sans-serif;
font-weight: 100;
color: #aab9c6;
background-color: #fff;
border-radius: 5px;
}
#card-element {
border: 3px dotted #000;
padding: 10px;
border-radius: 5px;
}
#card-element input[type=tel] {
border: 2px solid #000;
}
input {
width: 95%;
font-size: 16px;
font-weight: 100;
margin: 10px 0 10px 0;
border: 2px solid #000;
padding: 2%;
font-family: 'Heebo', sans-serif;
}
select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
font-size: 16px;
padding: 10px;
border: 2px solid #000;
border-radius: 0;
margin: 10px 0 10px 0;
}
::-webkit-input-placeholder { /* WebKit, Blink, Edge */
color: #aab9c6;
}
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
color: #aab9c6;n
opacity: 1;
}
::-moz-placeholder { /* Mozilla Firefox 19+ */
color: #aab9c6;
opacity: 1;
}
:-ms-input-placeholder { /* Internet Explorer 10-11 */
color: #aab9c6;
}
::-ms-input-placeholder { /* Microsoft Edge */
color: #aab9c6;
}
::placeholder { /* Most modern browsers support this now. */
color: #aab9c6;
}
input[type=submit] {
background-color: #000;
color: #fff;
width: 100%;
}
label {
color: #000;
font-weight: 400;
}
#card-errors {
color: #000;
font-weight: 400;
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
}
#contact-left h2 {
text-align: center;
}
.donate_buttons {
margin-left: 20px
}
.span_1_of_3 {
width: 25%;
}
.donate_button {
background-color: #f5c739;
color: #000;
text-align: center;
margin-right: 15px;
padding: 10px;
border-radius: 4px;
cursor: pointer;
border: none;
}
.clicked_button {
background-color: #fff;
border: 3px dashed #000;
color: #000;
text-align: center;
margin-right: 15px;
padding: 7px;
border-radius: 4px;
cursor: pointer;
}
.fas.fa-money-bill {
font-size: 1.5em;
}
.section {
margin-bottom: 20px;
}
.custom_donation {
display: inline-block;
}
.custom_input {
width: 50%;
text-align: center;
}
@media screen and (max-width: 736px) {
#member-con {
padding-bottom: 90em;
}
.section {
background-color: #fff;
}
.span_1_of_3 {
width: 22%;
}
}
</style>
<style>
/* Error Message Styling */
.error-body blockquote {
border-left: 8px solid red;
background-color: #feecf0;
padding-left: 1em;
padding-top: 0.1em;
padding-bottom: 0.1em;
}
.error-body h2 {
color: black;
}
/* Success Message Styling */
.success-body blockquote {
border-left: 8px solid #48c774;
background-color: #effaf3;
padding-left: 1em;
padding-top: 0.1em;
padding-bottom: 0.1em;
}
.success-body h2 {
color: black
}
</style>
<body>
<?php include("../res/php/top.php") ?>
<div id="section-title">Donate to the SRA</div>
<hr>
<?php
/*
Code for displaying errors if a donation fails and a user is redirected here.
*/
function displayError($title, $text) {
/*
Display error messages based on what is present in the GET parameter
*/
echo '
<div class="error-body">
<blockquote>
<h2>' . $title . '</h2><hr>
<p>' . $text . '</p>
<p>If you believe this to be a mistake, please contact
<a href="mailto:[email protected]">[email protected]</a></p>
</blockquote>
</div>'; // Error message template
}
function displaySuccess() {
/*
Display a successful donation message similar to the error message
*/
echo '
<div class="success-body">
<blockquote>
<h2>Thank you!</h2><br>
<p>Your donation was completed successfully and you will be emailed a receipt.</p>
</blockquote>
</div>
';
}
// Get error message from GET parameter
if (isset($_GET["error"])) {
$error = strip_tags($_GET["error"]);
}
// Switch statement to display the correct error message
if (isset($error)) {
switch ($error) {
case "email_mismatch":
displayError("Emails Don't Match", "The provided email addresses do not match. Make sure you typed your address correctly.");
break;
case "email_invalid":
displayError("Invalid Email Address", "The email address you provided is not a properly formatted address.");
break;
case "amount_not_numeric":
displayError("Donation Amount isn't a number", "The donation amount you enter has to be a number.");
break;
case "maximum_amount":
displayError("Amount Too Large", "We appreciate your generosity, but only amounts up to $1,000.00 are accepted.");
break;
case "minimum_amount":
displayError("Amount Too Small", "Unfortunately we can only accept donations greater than or equal to than $1.");
break;
case "invalid_recipient":
displayError("Invalid Recipient", "An invalid recipient was provided. Make sure you select a recipient from the dropdown.");
break;
case "succeeded":
displaySuccess();
break;
default:
displayError($error, "There is no error message written for this issue. If this arose natually, please contact Aayla.");
break;
}
}
?>
<br>
<div id="member-con">
<div id="contact-left">
<div style="text-align: center;"><img src="https://srastatic.nyc3.cdn.digitaloceanspaces.com/web/img/donate/give.png" alt="hand holding flower"></div>
<p style="text-align: center;">Donations will allow us to carry on the hard work we've been doing to make the
SRA the best firearms association in the country! Your donation will help us fund things like disaster
relief supplies, instructor sponsorships, and other SRA programs.</p>
<br>
</div>
<div id="contact-right">
<div id="pform">
<form action="./capture.php" method="post" id="payment-form">
<div class="form-row">
<h4>Who would you like to donate to?</h4>
<div>
<select name="recipient" id="recipient" required>
<option value="National SRA">National SRA</option>
<?php
// Populate selection with list of chapters
$chapters = json_decode(
file_get_contents("../chapters/chapters.json"),
true
);
$chapterIndex = 1;
foreach ($chapters as $state => $list) {
foreach($list as $chapter) {
echo '<option value="'
. $state . ': ' . $chapter["name"] .
'"';
if (isset($_GET["chapter"]) && $chapterIndex == $_GET["chapter"]) {
echo ' selected';
}
echo '>';
echo $state . ': ' . $chapter["name"] . '</option>';
$chapterIndex += 1;
}
}
?>
</select>
</div>
<h4>Your receipt will be sent to this address</h4>
<div id="email">
<input type="email" name="email" placeholder="Email" required>
</div>
<div id="email2">
<input type="email" name="email2" placeholder="Email (again)" required>
</div>
<h4>How much would you like to donate? (In dollars)</h4>
<input type="number" name="amount" value="5">
<h4>Payment Info</h4>
<div id="card-element">
<!-- A Stripe Element will be inserted here. -->
</div>
<!-- Used to display form errors. -->
<div id="card-errors" role="alert"></div>
</div>
<br>
<br>
<h5>Disclaimer: The Socialist Rifle Association Inc. (SRA) is a not-for-profit corporation incorporated in Wichita, Kansas. It is exempt from income tax under section 501(c)(4) of the Internal Revenue Code as a social welfare organization. Contributions to 501(c)(4) entities, and thus the SRA, are not tax deductible by donors and are not to be considered charitable donations.</h5>
<input type="submit" name="" value="Submit Payment">
</form>
</div>
</div>
</div>
<?php include("../res/php/bottom.php") ?>
<script type="text/javascript">
// Create a Stripe client.
var stripe = Stripe('pk_live_BZ1zqXFctBlrARB6AsTxI6k6');
// Create an instance of Elements.
var elements = stripe.elements();
// Custom styling can be passed to options when creating an Element.
// (Note that this demo uses a wider set of styles than the guide below.)
var style = {
base: {
color: '#32325d',
lineHeight: '30px',
padding: '5px',
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
fontSmoothing: 'antialiased',
fontSize: '16px',
'::placeholder': {
color: '#aab7c4'
}
},
invalid: {
color: '#fa755a',
iconColor: '#fa755a'
}
};
// Create an instance of the card Element.
var card = elements.create('card', {style: style});
// Add an instance of the card Element into the `card-element` <div>.
card.mount('#card-element');
// Handle real-time validation errors from the card Element.
card.addEventListener('change', function (event) {
var displayError = document.getElementById('card-errors');
if (event.error) {
displayError.textContent = event.error.message;
} else {
displayError.textContent = '';
}
});
// Handle form submission.
var form = document.getElementById('payment-form');
form.addEventListener('submit', function (event) {
event.preventDefault();
$submitButton = $('input[type="submit"]')
$submitButton.find(':input[type=submit]').prop('disabled', true);
$submitButton.attr("disabled", "disabled");
$submitButton.hide();
stripe.createToken(card).then(function (result) {
if (result.error) {
// Inform the user if there was an error.
var errorElement = document.getElementById('card-errors');
errorElement.textContent = result.error.message;
} else {
// Send the token to your server.
stripeTokenHandler(result.token);
}
});
});
function stripeTokenHandler(token) {
// Insert the token ID into the form so it gets submitted to the server
var form = document.getElementById('payment-form');
var hiddenInput = document.createElement('input');
hiddenInput.setAttribute('type', 'hidden');
hiddenInput.setAttribute('name', 'stripeToken');
hiddenInput.setAttribute('value', token.id);
form.appendChild(hiddenInput);
// Submit the form
form.submit();
}
</script>
</body>
</html>