credit card edit
This commit is contained in:
parent
ad581bbf40
commit
86777a4699
7 changed files with 432 additions and 36 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue