From 8f44c438508ed49120f2c88fb9cf7ed1f4519b9f Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Dec 2016 11:29:01 -0400 Subject: [PATCH] credit card --- digitalglarus/models.py | 1 + .../static/digitalglarus/js/payment.js | 9 +- .../digitalglarus/booking_payment.html | 2 +- .../credit_card_edit_confirmation.html | 113 ++++++ .../digitalglarus/new_credit_card.html | 347 ++++++++++++++++++ .../digitalglarus/reset_password.html | 2 +- digitalglarus/urls.py | 7 +- digitalglarus/views.py | 182 ++------- 8 files changed, 510 insertions(+), 153 deletions(-) create mode 100644 digitalglarus/templates/digitalglarus/credit_card_edit_confirmation.html create mode 100644 digitalglarus/templates/digitalglarus/new_credit_card.html diff --git a/digitalglarus/models.py b/digitalglarus/models.py index 26ecb4ff..73e04aca 100644 --- a/digitalglarus/models.py +++ b/digitalglarus/models.py @@ -1,4 +1,5 @@ + import calendar from datetime import datetime, date, timedelta from dateutil.relativedelta import relativedelta diff --git a/digitalglarus/static/digitalglarus/js/payment.js b/digitalglarus/static/digitalglarus/js/payment.js index 3179f721..90e922b1 100644 --- a/digitalglarus/static/digitalglarus/js/payment.js +++ b/digitalglarus/static/digitalglarus/js/payment.js @@ -19,6 +19,7 @@ $( document ).ready(function() { } if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) { // Only send the token to relative URLs i.e. locally. + alert("POR AQUI"); xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')); } } @@ -33,6 +34,7 @@ $( document ).ready(function() { function submit_payment(e){ $('#billing-form').submit(); + alert("POR AQUI2"); // $form.submit(); } @@ -42,7 +44,7 @@ $( document ).ready(function() { /* If you're using Stripe for payments */ function payWithStripe(e) { - console.log("submiting"); + console.log("submiting33"); e.preventDefault(); if (!$('.agree-terms').is(':checked')){ @@ -53,12 +55,15 @@ $( document ).ready(function() { /* Visual feedback */ $form.find('[type=submit]').html('Validating '); - + alert("POR AQUI3"); + console.log("submiting2"); var PublishableKey = window.stripeKey; + alert(PublishableKey); Stripe.setPublishableKey(PublishableKey); Stripe.card.createToken($form, function stripeResponseHandler(status, response) { if (response.error) { /* Visual feedback */ + alert("POR AQUI32345"); $form.find('[type=submit]').html('Try again'); /* Show Stripe errors on the form */ $form.find('.payment-errors').text(response.error.message); diff --git a/digitalglarus/templates/digitalglarus/booking_payment.html b/digitalglarus/templates/digitalglarus/booking_payment.html index 5c7cd604..f257d1d9 100644 --- a/digitalglarus/templates/digitalglarus/booking_payment.html +++ b/digitalglarus/templates/digitalglarus/booking_payment.html @@ -72,7 +72,7 @@ {% if credit_card_data %}
-

Credit CardEdit

+

Credit CardEdit

Last 4: *****{{credit_card_data.last4}}

Type: {{credit_card_data.cc_brand}}

diff --git a/digitalglarus/templates/digitalglarus/credit_card_edit_confirmation.html b/digitalglarus/templates/digitalglarus/credit_card_edit_confirmation.html new file mode 100644 index 00000000..3fea39d2 --- /dev/null +++ b/digitalglarus/templates/digitalglarus/credit_card_edit_confirmation.html @@ -0,0 +1,113 @@ +{% extends "new_base_glarus.html" %} +{% load staticfiles cms_tags bootstrap3%} +{% block title %}crowdfunding{% endblock %} + +{% block content %} + + + +
+ + + + +
+
+
+
+
+
+ Digital Glarus
+ In der Au 7 Schwanden 8762 Switzerland +
info@digitalglarus.ch +
+ (044) 534-66-22 +

 

+
+
+

 

+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/digitalglarus/templates/digitalglarus/new_credit_card.html b/digitalglarus/templates/digitalglarus/new_credit_card.html new file mode 100644 index 00000000..6d262cb4 --- /dev/null +++ b/digitalglarus/templates/digitalglarus/new_credit_card.html @@ -0,0 +1,347 @@ +{% extends "new_base_glarus.html" %} +{% load staticfiles bootstrap3 i18n %} +{% block content %} + + + +
+ + + + +
+ + + +
+
+
+
+
+ Digital Glarus
+ In der Au 7 Schwanden 8762 Switzerland +
info@digitalglarus.ch +
+ (044) 534-66-22 +

 

+
+
+

 

+
+
+
+
+ + +{% if stripe_key %} + +{%endif%} + + + + +{% endblock %} \ No newline at end of file diff --git a/digitalglarus/templates/digitalglarus/reset_password.html b/digitalglarus/templates/digitalglarus/reset_password.html index 7d701d02..f38c0fbd 100644 --- a/digitalglarus/templates/digitalglarus/reset_password.html +++ b/digitalglarus/templates/digitalglarus/reset_password.html @@ -26,7 +26,7 @@
- +
diff --git a/digitalglarus/urls.py b/digitalglarus/urls.py index f42ec6aa..9793e8cd 100644 --- a/digitalglarus/urls.py +++ b/digitalglarus/urls.py @@ -7,17 +7,18 @@ from .views import ContactView, IndexView, AboutView, HistoryView, LoginView, Si MembershipPricingView, BookingSelectDatesView, BookingPaymentView, OrdersBookingDetailView,\ BookingOrdersListView, MembershipOrdersListView, OrdersMembershipDetailView, \ MembershipDeactivateView, MembershipDeactivateSuccessView, UserBillingAddressView, \ - MembershipReactivateView,TermsAndConditions,ValidateUser,SupportusView,Probar + MembershipReactivateView,TermsAndConditions,ValidateUser,SupportusView,Probar,TermsAndConditions2,TermsAndConditions3 # from membership.views import LoginRegistrationView urlpatterns = [ - + url(_(r'probar3/?$'),TermsAndConditions3, name='probar3'), + url(_(r'probar2/?$'),TermsAndConditions2.as_view(), name='credit_card_edit'), url(_(r'probar/?$'), Probar, name='probar'), url(_(r'login/validate/(?P\!\w+)/?$'), ValidateUser.as_view(), name='validate-login'), url(_(r'^$'), IndexView.as_view(), name='landing'), - url(_(r'terms_conditions/?$'), TermsAndConditions.as_view(), name='TermsAndConditions'), + url(_(r'terms_conditions/?$'), TermsAndConditions, name='TermsAndConditions'), url(_(r'support-us/?$'), SupportusView.as_view(), name='supportus'), url(_(r'contact/?$'), ContactView.as_view(), name='contact'), url(_(r'login/?$'), LoginView.as_view(), name='login'), diff --git a/digitalglarus/views.py b/digitalglarus/views.py index 74d50ba9..f13537b6 100644 --- a/digitalglarus/views.py +++ b/digitalglarus/views.py @@ -14,8 +14,8 @@ from djangocms_blog.models import Post from django.contrib import messages from django.http import JsonResponse from django.views.generic import View, DetailView, ListView, DeleteView - - +from django.http import HttpResponse, HttpResponseRedirect +from django.shortcuts import render_to_response, redirect, render from .models import Supporter from .mixins import ChangeMembershipStatusMixin from utils.forms import ContactUsForm @@ -43,152 +43,13 @@ from .mixins import MembershipRequiredMixin, IsNotMemberMixin ''' class Probar(TemplateView): - template_name='digitalglarus/pinchecha.html' + template_name='digitalglarus/new_credit_card.html' model = Membership success_url = reverse_lazy('digitalglarus:probar') ''' -class Probar(TemplateView): - template_name = "digitalglarus/pinchecha.html" - success_url = reverse_lazy('digitalglarus:probar') - # success_url = reverse_lazy('digitalglarus:booking_payment') -''' - def dispatch(self, request, *args, **kwargs): - from_booking = all(field in request.session.keys() - for field in self.booking_needed_fields) - if not from_booking: - return HttpResponseRedirect(reverse('digitalglarus:booking')) - - return super(BookingPaymentView, self).dispatch(request, *args, **kwargs) - - def get_success_url(self, order_id): - return reverse('digitalglarus:booking_orders_detail', kwargs={'pk': order_id}) - - def get_form_kwargs(self): - current_billing_address = self.request.user.billing_addresses.first() - form_kwargs = super(BookingPaymentView, self).get_form_kwargs() - form_kwargs.update({ - 'initial': { - 'start_date': self.request.session.get('start_date'), - 'end_date': self.request.session.get('end_date'), - 'price': self.request.session.get('final_price'), - 'street_address': current_billing_address.street_address, - 'city': current_billing_address.city, - 'postal_code': current_billing_address.postal_code, - 'country': current_billing_address.country, - } - }) - return form_kwargs - - def get_context_data(self, *args, **kwargs): - context = super(BookingPaymentView, self).get_context_data(*args, **kwargs) - - booking_data = {key: self.request.session.get(key) - for key in self.booking_needed_fields} - user = self.request.user - last_booking_order = BookingOrder.objects.filter(customer__user=user).last() - last_membership_order = MembershipOrder.objects.filter(customer__user=user).last() - credit_card_data = last_booking_order.get_booking_cc_data() if last_booking_order \ - and last_booking_order.get_booking_cc_data() \ - else last_membership_order.get_membership_order_cc_data() - - booking_data.update({ - 'credit_card_data': credit_card_data if credit_card_data else None, - 'stripe_key': settings.STRIPE_API_PUBLIC_KEY - }) - context.update(booking_data) - return context - - def form_valid(self, form): - data = form.cleaned_data - context = self.get_context_data() - token = data.get('token') - start_date = data.get('start_date') - end_date = data.get('end_date') - is_free = context.get('is_free') - normal_price, final_price, free_days = Booking.\ - booking_price(self.request.user, start_date, end_date) - charge = None - - # if not credit_card_needed: - # Get or create stripe customer - customer = StripeCustomer.get_or_create(email=self.request.user.email, - token=token) - if not customer: - form.add_error("__all__", "Invalid credit card") - return self.render_to_response(self.get_context_data(form=form)) - - # If booking is not free, make the stripe charge - if not is_free: - # Make stripe charge to a customer - stripe_utils = StripeUtils() - charge_response = stripe_utils.make_charge(amount=final_price, - customer=customer.stripe_id) - charge = charge_response.get('response_object') - - # Check if the payment was approved - if not charge: - context.update({ - 'paymentError': charge_response.get('error'), - 'form': form - }) - return render(self.request, self.template_name, context) - - charge = charge_response.get('response_object') - - # Create Billing Address for Membership Order - billing_address = form.save() - - # Create Billing Address for User if he does not have one - if not customer.user.billing_addresses.count(): - data.update({ - 'user': customer.user.id - }) - billing_address_user_form = UserBillingAddressForm(data) - billing_address_user_form.is_valid() - billing_address_user_form.save() - - # Create Booking - booking_data = { - 'start_date': start_date, - 'end_date': end_date, - 'start_date': start_date, - 'free_days': free_days, - 'price': normal_price, - 'final_price': final_price, - } - booking = Booking.create(booking_data) - - # Create Booking order - order_data = { - 'booking': booking, - 'customer': customer, - 'billing_address': billing_address, - 'stripe_charge': charge, - 'amount': final_price, - 'original_price': normal_price, - 'special_month_price': BookingPrice.objects.last().special_month_price, - } - order = BookingOrder.create(order_data) - - context = { - 'booking': booking, - 'order': order, - 'base_url': "{0}://{1}".format(self.request.scheme, self.request.get_host()) - } - - email_data = { - 'subject': 'Your booking order has been placed', - 'to': self.request.user.email, - 'context': context, - 'template_name': 'booking_order_email', - 'template_path': 'digitalglarus/emails/' - } - email = BaseEmail(**email_data) - email.send() - - return HttpResponseRedirect(self.get_success_url(order.id)) -''' +def Probar(TemplateView): + print ("hello") class ValidateUser(TemplateView): #print ("ENTRE AQUI AL MENOS Y",pk) @@ -222,8 +83,37 @@ class ValidateView(SignupViewMixin): #resp['msg'] = 0 #0 para exito #return HttpResponse(json.dumps(resp), content_type ='application/json') -class TermsAndConditions(TemplateView): - template_name ="digitalglarus/pinchecha.html" +def TermsAndConditions(request): +#template_name ="digitalglarus/new_credit_card.html" + print (request.user) + #u+Contacto.objects.filter(asesor = U.objects.get(email=request.session['user'])) + m=MembershipOrder.objects.filter(customer__user=request.user) + customer = StripeCustomer.get_or_create(email=request.user.email) + last_booking_order = BookingOrder.objects.filter(customer__user=request.user).last() + last_membership_order = MembershipOrder.objects.filter(customer__user=request.user).last() + credit_card_data = last_booking_order.get_booking_cc_data() if last_booking_order \ + and last_booking_order.get_booking_cc_data() \ + else last_membership_order.get_membership_order_cc_data() + for t in m: + print (t) + print ("Credit cad last4",credit_card_data['last4']) + print ("Brand type",credit_card_data) + resp = dict() + resp['msg'] = 0 #0 para exito + #return HttpResponse(json.dumps(resp), content_type ='application/json') + return render_to_response('digitalglarus/new_credit_card.html',{'last4':credit_card_data['last4'],'brand_type':credit_card_data['cc_brand'],'stripe_key': settings.STRIPE_API_PUBLIC_KEY}) + ''' + def get_success_url(self): + # redirect to membership orders list if user has at least one. + print (self.request.user) + print ("JNSKDJNASJDNKSJANDKJNSAKJDNKJND") + ''' +def TermsAndConditions3(request): + print ("hola hola hola hola hola") + return render_to_response('digitalglarus/new_credit_card.html',{'last4':credit_card_data['last4'],'brand_type':credit_card_data['cc_brand']}) + +class TermsAndConditions2(TemplateView): + template_name ="digitalglarus/credit_card_edit_confirmation.html" class IndexView(TemplateView):