Prod live updates
This commit is contained in:
@@ -53,7 +53,7 @@ MIDDLEWARE = [
|
||||
]
|
||||
|
||||
ROOT_URLCONF = "scha.urls"
|
||||
|
||||
CSRF_TRUSTED_ORIGINS = ["https://schawheaton.aimloperations.com","https://www.schawheaton.aimloperations.com", "https://www.schawheaton.com", "https://schawheaton.com"]
|
||||
TEMPLATES = [
|
||||
{
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
|
||||
@@ -23,6 +23,7 @@ from django.conf import settings
|
||||
from schasite.views import stripe_cancelled, stripe_success, stripe_webhook
|
||||
|
||||
urlpatterns = [
|
||||
path("schasite/", include("schasite.urls")),
|
||||
path("", include("schasite.urls")),
|
||||
path("success/", stripe_success),
|
||||
path("cancelled/", stripe_cancelled),
|
||||
|
||||
@@ -11,21 +11,20 @@ from .models import (
|
||||
from phonenumber_field.formfields import PhoneNumberField
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
# from django_recaptcha.fields import ReCaptchaField
|
||||
# from django.conf import settings
|
||||
# from django_recaptcha.widgets import ReCaptchaV3
|
||||
from django_recaptcha.fields import ReCaptchaField
|
||||
from django.conf import settings
|
||||
from django_recaptcha.widgets import ReCaptchaV3
|
||||
|
||||
# class CaptchaForm(forms.Form):
|
||||
# captcha = ReCaptchaField(
|
||||
# public_key=settings.RECAPTCHA_PUBLIC_KEY,
|
||||
# private_key=settings.RECAPTCHA_PRIVATE_KEY,
|
||||
# widget=ReCaptchaV3(
|
||||
# attrs={
|
||||
# 'required_score':0.85,
|
||||
# }
|
||||
# ),
|
||||
|
||||
# )
|
||||
class CaptchaForm(forms.Form):
|
||||
captcha = ReCaptchaField(
|
||||
public_key=settings.RECAPTCHA_PUBLIC_KEY,
|
||||
private_key=settings.RECAPTCHA_PRIVATE_KEY,
|
||||
widget=ReCaptchaV3(
|
||||
attrs={
|
||||
'required_score':0.85,
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class ChildrenForm(ModelForm):
|
||||
|
||||
@@ -109,9 +109,8 @@
|
||||
<i class="bi bi-credit-card text-success display-4 mb-3"></i>
|
||||
<h4 class="text-success">Credit/Debit Card</h4>
|
||||
<p class="card-text">Pay securely with Visa, Mastercard, American Express, or Discover.</p>
|
||||
<a href="https://buy.stripe.com/test_14k6rE7jD3hQ2SQ144" class="btn btn-success mt-3" target="_blank" id="submitBtn">
|
||||
Pay with Card
|
||||
</a>
|
||||
|
||||
<button class="btn btn-success mt-3" id="submitBtn">Pay Dues</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -192,39 +191,6 @@
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
|
||||
<!-- Stripe Integration Script (example) -->
|
||||
<script>
|
||||
// This would be replaced with your actual Stripe integration code
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Example: Track outbound links to Stripe
|
||||
const stripeLinks = document.querySelectorAll('a[href*="stripe.com"]');
|
||||
stripeLinks.forEach(link => {
|
||||
link.addEventListener('click', function(e) {
|
||||
// You could add analytics tracking here
|
||||
console.log('Redirecting to Stripe payment');
|
||||
});
|
||||
});
|
||||
|
||||
// Example: Dynamic balance loading (would connect to your backend)
|
||||
function loadAccountBalance() {
|
||||
// In a real implementation, this would fetch from your database
|
||||
// This is just a placeholder example
|
||||
return {
|
||||
member: "John Doe (Lot #42)",
|
||||
balance: "$600.00",
|
||||
dueDate: "January 15, 2024",
|
||||
lastPayment: "$600.00 on January 10, 2023"
|
||||
};
|
||||
}
|
||||
|
||||
// Update the account info section (example)
|
||||
const accountInfo = loadAccountBalance();
|
||||
document.querySelector('.bg-light p:nth-child(1)').innerHTML =
|
||||
`<strong>Member:</strong> ${accountInfo.member}`;
|
||||
document.querySelector('.bg-light p:nth-child(2)').innerHTML =
|
||||
`<strong>Current Balance:</strong> ${accountInfo.balance} (Due ${accountInfo.dueDate})`;
|
||||
document.querySelector('.bg-light p:nth-child(3)').innerHTML =
|
||||
`<strong>Last Payment:</strong> ${accountInfo.lastPayment}`;
|
||||
});
|
||||
</script>
|
||||
<script src="https://js.stripe.com/v3/"></script>
|
||||
<script src="{% static 'main.js' %}"></script>
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
<h4 class="mb-0">{{ officer.position }}</h4>
|
||||
</div>
|
||||
<div class="card-body text-center">
|
||||
<img src="../images/board/john-smith.jpg" alt="John Smith" class="rounded-circle mb-3" width="150" height="150">
|
||||
<!--<img src="../images/board/john-smith.jpg" alt="John Smith" class="rounded-circle mb-3" width="150" height="150">-->
|
||||
<h5 class="card-title">{{ officer.name }}</h5>
|
||||
<!-- <p class="text-muted">Term: 2022-2024</p>
|
||||
<p class="card-text">John has lived in Greenwood Estates since 2015 and brings 20 years of financial management experience to the board.</p> -->
|
||||
@@ -84,7 +84,7 @@
|
||||
<h4 class="mb-0">TBD</h4>
|
||||
</div>
|
||||
<div class="card-body text-center">
|
||||
<img src="../images/board/john-smith.jpg" alt="John Smith" class="rounded-circle mb-3" width="150" height="150">
|
||||
<!--<img src="../images/board/john-smith.jpg" alt="John Smith" class="rounded-circle mb-3" width="150" height="150">-->
|
||||
<h5 class="card-title">TBD</h5>
|
||||
<p class="text-muted">TBD</p>
|
||||
<p class="card-text">TBD</p>
|
||||
@@ -99,4 +99,4 @@
|
||||
|
||||
</div>
|
||||
</main>
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from django.shortcuts import render, redirect
|
||||
from .models import UsefulLinks, CalendarEvent, MembershipPerson, Payments, SCHAOfficer, Membership, CommunityPost
|
||||
from .models import UsefulLinks, CalendarEvent, MembershipPerson, Payments, SCHAOfficer, Membership
|
||||
from .forms import (
|
||||
ChildrenForm,
|
||||
CommunityPostForm,
|
||||
@@ -7,8 +7,8 @@ from .forms import (
|
||||
PeopleForm,
|
||||
CommitteeForm,
|
||||
ServicesForm,
|
||||
|
||||
) # , CaptchaForm
|
||||
CaptchaForm
|
||||
)
|
||||
from django.db import transaction, IntegrityError
|
||||
|
||||
# Stripe required imports
|
||||
@@ -36,28 +36,27 @@ def stripe_config(request):
|
||||
|
||||
@csrf_exempt
|
||||
def create_checkout_session(request):
|
||||
if request.method == "GET":
|
||||
domain_url = "http://localhost:8000/"
|
||||
if request.method == 'GET':
|
||||
domain_url ="https://www.schawheaton.com/"
|
||||
stripe.api_key = settings.STRIPE_SECRET_KEY
|
||||
try:
|
||||
checkout_session = stripe.checkout.Session.create(
|
||||
success_url=domain_url + "success?session_id={CHECKOUT_SESSION_ID}",
|
||||
cancel_url=domain_url + "cancelled/",
|
||||
payment_method_types=["card"],
|
||||
success_url = domain_url+'success?session_id={CHECKOUT_SESSION_ID}',
|
||||
cancel_url = domain_url+'cancelled/',
|
||||
payment_method_types=['card'],
|
||||
mode="payment",
|
||||
line_items=[
|
||||
{
|
||||
# 'name':'SCHA Dues',
|
||||
"quantity": 1,
|
||||
# 'currency': 'usd',
|
||||
"price": "price_1OxZLfDV0RPXOyxG5ipjhUXk",
|
||||
}
|
||||
],
|
||||
line_items = [{
|
||||
# 'name':'SCHA Dues',
|
||||
'quantity': 1,
|
||||
# 'currency': 'usd',
|
||||
'price':'price_1P5KBtIbGKYTLTtMJ0Rh1jMu',
|
||||
#'price_1P5K7uIbGKYTLTtMFNxbkA8X'
|
||||
#'price_1OxZLfDV0RPXOyxG5ipjhUXk',
|
||||
}]
|
||||
)
|
||||
return JsonResponse({"sessionId": checkout_session["id"]})
|
||||
return JsonResponse({'sessionId': checkout_session['id']})
|
||||
except Exception as e:
|
||||
return JsonResponse({"error": str(e)})
|
||||
|
||||
return JsonResponse({'error': str(e)})
|
||||
|
||||
def stripe_success(request):
|
||||
return render(request, "schasite/dues_success.html", {})
|
||||
@@ -72,11 +71,13 @@ def stripe_webhook(request):
|
||||
stripe.api_key = settings.STRIPE_SECRET_KEY
|
||||
endpoint_secret = settings.STRIPE_ENDPOINT_SECRET
|
||||
payload = request.body
|
||||
sig_header = request.META["HTTP_STRIPE_SIGNATURE"]
|
||||
sig_header = request.META['HTTP_STRIPE_SIGNATURE']
|
||||
event = None
|
||||
|
||||
try:
|
||||
event = stripe.Webhook.construct_event(payload, sig_header, endpoint_secret)
|
||||
event = stripe.Webhook.construct_event(
|
||||
payload, sig_header, endpoint_secret
|
||||
)
|
||||
except ValueError as e:
|
||||
# Invalid payload
|
||||
return HttpResponse(status=400)
|
||||
@@ -85,17 +86,18 @@ def stripe_webhook(request):
|
||||
return HttpResponse(status=400)
|
||||
|
||||
# Handle the checkout.session.completed event
|
||||
if event["type"] == "checkout.session.completed":
|
||||
if event['type'] == 'checkout.session.completed':
|
||||
email = None
|
||||
try:
|
||||
email = event["data"]["object"]["customer_details"]["email"]
|
||||
email = event['data']['object']['customer_details']['email']
|
||||
except:
|
||||
pass
|
||||
person = MembershipPerson.objects.filter(
|
||||
email=email
|
||||
).first() # just take the first
|
||||
person = MembershipPerson.objects.filter(email=email).first() # just take the first
|
||||
|
||||
payment = Payments.objects.create(email=email, person=person)
|
||||
payment = Payments.objects.create(
|
||||
email=email,
|
||||
person = person
|
||||
)
|
||||
# try to link to a member
|
||||
payment.save()
|
||||
# TODO: run some custom code here
|
||||
@@ -170,8 +172,6 @@ def dues2(request):
|
||||
|
||||
|
||||
def membership_form2(request):
|
||||
print(request)
|
||||
print(request.POST)
|
||||
def sanitize_phone_number(data):
|
||||
if len(data) > 0:
|
||||
data = data.replace("-", "")
|
||||
@@ -241,51 +241,61 @@ def membership_form2(request):
|
||||
|
||||
peopleForm1 = PeopleForm(person1_data)
|
||||
peopleForm2 = PeopleForm(person2_data)
|
||||
print(peopleForm1)
|
||||
breakpoint()
|
||||
|
||||
|
||||
for form in [addressForm, servicesForm, committeeForm, peopleForm1, peopleForm2]:
|
||||
print(f"is form valid: {form.is_valid()}")
|
||||
if not form.is_valid():
|
||||
print(f"form Errors: {form.errors}")
|
||||
print("Validating the captcha form")
|
||||
print(request.POST.get("captcha",""))
|
||||
captchaForm = CaptchaForm({
|
||||
"captcha": request.POST.get("captcha","")
|
||||
})
|
||||
print(f"Captch form is: {captchaForm.is_valid()}")
|
||||
|
||||
|
||||
print(f"peopleForm1 form is: {peopleForm1.is_valid()}")
|
||||
print(f"peopleForm2 form is: {peopleForm2.is_valid()}")
|
||||
print(f"servicesForm form is: {servicesForm.is_valid()}")
|
||||
|
||||
# captchaForm = CaptchaForm(post_data)
|
||||
|
||||
if (
|
||||
addressForm.is_valid()
|
||||
and committeeForm.is_valid()
|
||||
and (peopleForm1.is_valid() or peopleForm2.is_valid())
|
||||
and servicesForm.is_valid()
|
||||
): # and captchaForm.is_valid():
|
||||
and captchaForm.is_valid()
|
||||
):
|
||||
with transaction.atomic():
|
||||
membership = Membership.objects.create()
|
||||
print("starting to save")
|
||||
try:
|
||||
membership = Membership.objects.create()
|
||||
|
||||
if peopleForm1.is_valid():
|
||||
people1_obj = peopleForm1.save(commit=False)
|
||||
people1_obj.membership = membership
|
||||
people1_obj.save()
|
||||
if peopleForm1.is_valid():
|
||||
people1_obj = peopleForm1.save(commit=False)
|
||||
people1_obj.membership = membership
|
||||
people1_obj.save()
|
||||
|
||||
if peopleForm2.is_valid():
|
||||
people2_obj = peopleForm2.save(commit=False)
|
||||
people2_obj.membership = membership
|
||||
people2_obj.save()
|
||||
if peopleForm2.is_valid():
|
||||
people2_obj = peopleForm2.save(commit=False)
|
||||
people2_obj.membership = membership
|
||||
people2_obj.save()
|
||||
|
||||
committee_obj = committeeForm.save(commit=False)
|
||||
committee_obj.membership = membership
|
||||
committee_obj.save()
|
||||
committee_obj = committeeForm.save(commit=False)
|
||||
committee_obj.membership = membership
|
||||
committee_obj.save()
|
||||
|
||||
services_obj = servicesForm.save(commit=False)
|
||||
services_obj.membership = membership
|
||||
services_obj.save()
|
||||
services_obj = servicesForm.save(commit=False)
|
||||
services_obj.membership = membership
|
||||
services_obj.save()
|
||||
|
||||
address_obj = addressForm.save(commit=False)
|
||||
address_obj.membership = membership
|
||||
address_obj.save()
|
||||
address_obj = addressForm.save(commit=False)
|
||||
address_obj.membership = membership
|
||||
address_obj.save()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
return redirect("index2")
|
||||
|
||||
else:
|
||||
print("Some field is not valid")
|
||||
return render(
|
||||
request,
|
||||
"schasite/membership_form2.html",
|
||||
@@ -295,7 +305,7 @@ def membership_form2(request):
|
||||
"addressForm": addressForm,
|
||||
"committeeForm": committeeForm,
|
||||
"servicesForm": servicesForm,
|
||||
# 'captchaForm': captchaForm,
|
||||
'captchaForm': captchaForm,
|
||||
},
|
||||
)
|
||||
else:
|
||||
@@ -307,7 +317,7 @@ def membership_form2(request):
|
||||
"peopleForm2": PeopleForm(prefix="person2"),
|
||||
"committeeForm": CommitteeForm(),
|
||||
"servicesForm": ServicesForm(),
|
||||
# 'captchaForm': CaptchaForm(),
|
||||
'captchaForm': CaptchaForm(),
|
||||
"addressForm": AddressForm(
|
||||
initial={
|
||||
"city": "Wheaton",
|
||||
@@ -523,4 +533,4 @@ def profile(request):
|
||||
if request.method == "POST":
|
||||
raise NotImplementedError()
|
||||
else:
|
||||
return render(request, "schasite/profile.html",{})
|
||||
return render(request, "schasite/profile.html",{})
|
||||
|
||||
Reference in New Issue
Block a user