From 86777a4699c1aae5bd7b4e491d506bc7d3804d8f Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 3 Jan 2017 09:33:25 -0400 Subject: [PATCH] credit card edit --- .../static/digitalglarus/js/payment.js | 3 + .../digitalglarus/booking_payment.html | 3 +- .../digitalglarus/booking_payment2.html | 301 ++++++++++++++++++ .../digitalglarus/membership_payment.html | 3 +- .../digitalglarus/new_credit_card.html | 21 +- digitalglarus/urls.py | 3 +- digitalglarus/views.py | 134 ++++++-- 7 files changed, 432 insertions(+), 36 deletions(-) create mode 100644 digitalglarus/templates/digitalglarus/booking_payment2.html diff --git a/digitalglarus/static/digitalglarus/js/payment.js b/digitalglarus/static/digitalglarus/js/payment.js index d9c70f36..7e30a667 100644 --- a/digitalglarus/static/digitalglarus/js/payment.js +++ b/digitalglarus/static/digitalglarus/js/payment.js @@ -28,6 +28,7 @@ $( document ).ready(function() { var hasCreditcard = window.hasCreditcard; + hasCreditcard= true; console.log("has creditcard"); console.log("has creditcard"); console.log("has creditcard"); @@ -40,9 +41,11 @@ $( document ).ready(function() { e.preventDefault(); if (hasCreditcard) { $('#billing-form').submit(); + console.log("has creditcard2"); } else  { $('#payment-form').submit(); + console.log("has creditcard3"); } diff --git a/digitalglarus/templates/digitalglarus/booking_payment.html b/digitalglarus/templates/digitalglarus/booking_payment.html index bcbf88e4..24a840c3 100644 --- a/digitalglarus/templates/digitalglarus/booking_payment.html +++ b/digitalglarus/templates/digitalglarus/booking_payment.html @@ -70,7 +70,7 @@
- {% if credit_card_data.last4 and credit_card_data.cc_brand %} + {% if credit_card_data.last4 %}

Credit CardEdit

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

@@ -78,6 +78,7 @@
{% else %} +

Credit Card (Last used)

diff --git a/digitalglarus/templates/digitalglarus/booking_payment2.html b/digitalglarus/templates/digitalglarus/booking_payment2.html new file mode 100644 index 00000000..758f918a --- /dev/null +++ b/digitalglarus/templates/digitalglarus/booking_payment2.html @@ -0,0 +1,301 @@ +{% 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%} + +{% if credit_card_data.last4 and credit_card_data.cc_brand %} + + +{%endif%} + + +{% endblock %} \ No newline at end of file diff --git a/digitalglarus/templates/digitalglarus/membership_payment.html b/digitalglarus/templates/digitalglarus/membership_payment.html index 7fe42ffb..0e68be43 100644 --- a/digitalglarus/templates/digitalglarus/membership_payment.html +++ b/digitalglarus/templates/digitalglarus/membership_payment.html @@ -120,7 +120,8 @@
- + +
diff --git a/digitalglarus/templates/digitalglarus/new_credit_card.html b/digitalglarus/templates/digitalglarus/new_credit_card.html index 3163738c..314e28f8 100644 --- a/digitalglarus/templates/digitalglarus/new_credit_card.html +++ b/digitalglarus/templates/digitalglarus/new_credit_card.html @@ -37,7 +37,7 @@

- {% if is_free %} +

Credit Card Information

- {% if credit_card_data %} -
-

Last 4: *****{{last4}}

-

Type: {{cc_brand}}

- - -
- - {% else %} +
{% csrf_token %}

Last 4: *****{{last4}}

@@ -81,7 +74,9 @@ - + + + {% csrf_token %}
@@ -151,8 +146,8 @@
- {% endif %} - {% endif %} + +
diff --git a/digitalglarus/urls.py b/digitalglarus/urls.py index f851fb45..8590dd79 100644 --- a/digitalglarus/urls.py +++ b/digitalglarus/urls.py @@ -7,12 +7,13 @@ from .views import ContactView, IndexView, AboutView, HistoryView, LoginView, Si MembershipPricingView, BookingSelectDatesView, BookingPaymentView, OrdersBookingDetailView,\ BookingOrdersListView, MembershipOrdersListView, OrdersMembershipDetailView, \ MembershipDeactivateView, MembershipDeactivateSuccessView, UserBillingAddressView, \ - MembershipReactivateView,TermsAndConditions,ValidateUser,SupportusView,Probar,TermsAndConditions2,TermsAndConditions3 + MembershipReactivateView,TermsAndConditions,ValidateUser,SupportusView,Probar,TermsAndConditions2,TermsAndConditions3,BookingPaymentView2 # from membership.views import LoginRegistrationView urlpatterns = [ + url(_(r'booking/payment/view/?$'), BookingPaymentView2, name='booking_payment_view'), url(_(r'probar3/?$'),TermsAndConditions3, name='probar3'), url(_(r'probar2/?$'),TermsAndConditions2.as_view(), name='credit_card_edit'), url(_(r'probar/?$'), Probar, name='probar'), diff --git a/digitalglarus/views.py b/digitalglarus/views.py index b5ed4a6d..a8688348 100644 --- a/digitalglarus/views.py +++ b/digitalglarus/views.py @@ -21,18 +21,15 @@ from .models import Supporter from .mixins import ChangeMembershipStatusMixin from utils.forms import ContactUsForm from utils.mailer import BaseEmail - from django.views.generic.edit import FormView from membership.calendar.calendar import BookCalendar from membership.models import Calendar as CalendarModel, StripeCustomer - - from utils.views import LoginViewMixin, SignupViewMixin, \ PasswordResetViewMixin, PasswordResetConfirmViewMixin from utils.forms import PasswordResetRequestForm, UserBillingAddressForm from utils.stripe_utils import StripeUtils from utils.models import UserBillingAddress - +import stripe from .forms import LoginForm, SignupForm, MembershipBillingForm, BookingDateForm,\ BookingBillingForm, CancelBookingForm @@ -41,14 +38,38 @@ from .models import MembershipType, Membership, MembershipOrder, Booking, Bookin BookingOrder, BookingCancellation from .mixins import MembershipRequiredMixin, IsNotMemberMixin - -''' -class Probar(TemplateView): - template_name='digitalglarus/new_credit_card.html' - model = Membership - success_url = reverse_lazy('digitalglarus:probar') -''' - + +def BookingPaymentView2(request): + #print (request.user) + resp = dict() + cus = StripeCustomer.get_or_create(email=request.user.email) + s= str(cus) + s= s.split(" ") + resp['object']='card' + resp['exp_month']=request.POST['expMonth'] + resp['exp_year']=request.POST['expYear'] + resp['number']=request.POST['cardNumber'] + resp['cvc']=request.POST['cvCode'] + resp['name']=request.POST['cardName'] + customer = stripe.Customer.retrieve(s[0]) + customer.sources.create(source=resp) + t=stripe.Customer.retrieve(s[0]).sources.all(object="card") + tt=t['data'] + x= resp['number'] + cc= dict() + for i in tt: + #print (i.id) + #print (i.last4) + #print (x[-4:]) + if i.last4 == x[-4:]: + cc['last4']= i.last4 + cc['cc_brand']= i.brand + customer.default_source= i.id + customer.save() + current_billing_address = request.user.billing_addresses.first() + #return HttpResponse(json.dumps(resp), content_type ='application/json') + #return render_to_response('digitalglarus/booking_payment.html',{'last4':cc['last4'],'stripe_key': settings.STRIPE_API_PUBLIC_KEY,'street_address': current_billing_address.street_address,'city': current_billing_address.city, 'postal_code': current_billing_address.postal_code,'country': current_billing_address.country,},context_instance= RequestContext(request)) + return HttpResponseRedirect('/digitalglarus/booking/payment/') def Probar(TemplateView): print ("hello") @@ -85,11 +106,55 @@ class ValidateView(SignupViewMixin): @csrf_exempt 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'])) + cus = StripeCustomer.get_or_create(email=request.user.email) + s= str(cus) + s= s.split(" ") + #t=stripe.Customer.retrieve(s[0]).sources.all(object="card") + #tt=t['data'] + #print (tt) + #for i in tt: + # print (i.id) + # print (i.last4) + # print ("aja estoy aqui",i.id) + # customer = stripe.Customer.retrieve(s[0]) + # customer.sources.retrieve(i.id).delete() + + # crear tarjeta de credito + + customer = stripe.Customer.retrieve(s[0]) + #print ("voy por aqui") + custom_card= customer.default_source + t=stripe.Customer.retrieve(s[0]).sources.all(object="card") + tt=t['data'] + #print (tt) + cc = dict() + for i in tt: + #print (i.id) + #print (i.last4) + if i.id== custom_card: + #print ("ESTA ES LA TARJETA ACTUAL") + cc['last4']= i.last4 + cc['cc_brand'] = i.brand + + + + + #customer.sources.create(source=resp) + #t=stripe.Customer.retrieve(s[0]).sources.all(object="card") + #tt=t['data'] + #x= resp['number'] + #for i in tt: + # print (i.id) + # print (i.last4) + # print (x[-4:]) + # if i.last4 == x[-4:]: + # print ("ESTOY AQUI") + # customer.default_source= i.id + #customer.save() 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 \ @@ -97,9 +162,13 @@ def TermsAndConditions(request): else last_membership_order.get_membership_order_cc_data() current_billing_address = request.user.billing_addresses.first() - 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,'street_address': current_billing_address.street_address,'city': current_billing_address.city, 'postal_code': current_billing_address.postal_code,'country': current_billing_address.country,},context_instance= RequestContext(request)) + + #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,'street_address': current_billing_address.street_address,'city': current_billing_address.city, 'postal_code': current_billing_address.postal_code,'country': current_billing_address.country,},context_instance= RequestContext(request)) + return render_to_response('digitalglarus/new_credit_card.html',{'last4':cc['last4'],'brand_type':cc['cc_brand'],'stripe_key': settings.STRIPE_API_PUBLIC_KEY,'street_address': current_billing_address.street_address,'city': current_billing_address.city, 'postal_code': current_billing_address.postal_code,'country': current_billing_address.country,},context_instance= RequestContext(request)) + #return render_to_response('digitalglarus/new_credit_card.html',{'last4':'probando','brand_type':'probando','stripe_key': settings.STRIPE_API_PUBLIC_KEY,'street_address': current_billing_address.street_address,'city': current_billing_address.city, 'postal_code': current_billing_address.postal_code,'country': current_billing_address.country,},context_instance= RequestContext(request)) ''' - def get_success_url(self): + def g + et_success_url(self): # redirect to membership orders list if user has at least one. print (self.request.user) print ("JNSKDJNASJDNKSJANDKJNSAKJDNKJND") @@ -256,9 +325,34 @@ class BookingPaymentView(LoginRequiredMixin, MembershipRequiredMixin, FormView): 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() + + #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() + #print ("LA TARJETA NATACHA QUE QUEREMOS VER SI FUNCIONA ES ESTA",credit_card_data) + #credit_card_data = + #### ESTOY POR AQUI CAMBIANDO ESTO UN POCO PARA VER SI FUNCIONA + ########################################################################################## + cus = StripeCustomer.get_or_create(email=user ) + s= str(cus) + s= s.split(" ") + customer = stripe.Customer.retrieve(s[0]) + #print ("voy por aqui") + custom_card= customer.default_source + t=stripe.Customer.retrieve(s[0]).sources.all(object="card") + tt=t['data'] + cc = dict() + for i in tt: + #print (i.id) + #print (i.last4) + if i.id== custom_card: + credit_card_data= i + #print ("ESTA ES LA TARJETA ACTUAL") + cc['last4']= i.last4 + cc['cc_brand'] = i.brand + ########################################################################## + + booking_data.update({ 'credit_card_data': credit_card_data if credit_card_data else None,