diff --git a/digitalglarus/static/digitalglarus/js/edit_creditcard.js b/digitalglarus/static/digitalglarus/js/edit_creditcard.js new file mode 100644 index 00000000..d4141f0c --- /dev/null +++ b/digitalglarus/static/digitalglarus/js/edit_creditcard.js @@ -0,0 +1,119 @@ +$( document ).ready(function() { + + var $form = $('#new-card-form'); + $form.submit(changeCreditCard); + + + // var submit_form_btn = $('#change-card-button'); + // submit_form_btn.on('click', submit_new_card); + + function submit_new_card(e){ + + // $('#billing-form').submit(); + // alert("POR AQUI2"); + // $form.submit(); + } + + /* If you're using Stripe for payments */ + function changeCreditCard(e) { + console.log("submiting"); + e.preventDefault(); + + if (!$('.agree-terms').is(':checked')){ + alert("You must accept terms and conditions."); + return; + } + + + /* Visual feedback */ + $form.find('[type=submit]').html('Validating '); + + var PublishableKey = window.stripeKey; + Stripe.setPublishableKey(PublishableKey); + Stripe.card.createToken($form, function stripeResponseHandler(status, response) { + console.log("response",response); + if (response.error) { + /* Visual feedback */ + alert("POR AQUI3"); + $form.find('[type=submit]').html('Try again'); + /* Show Stripe errors on the form */ + $form.find('.payment-errors').text(response.error.message); + $form.find('.payment-errors').closest('.row').show(); + } else { + /* Visual feedback */ + $form.find('[type=submit]').html('Processing '); + /* Hide Stripe errors on the form */ + $form.find('.payment-errors').closest('.row').hide(); + $form.find('.payment-errors').text(""); + // response contains id and card, which contains additional card details + var token = response.id; + // AJAX + + //set token on a hidden input + $('#id_token').val(token); + $('#change-card-form').submit(); + } + }); + } + + + /* Form validation */ + $.validator.addMethod("month", function(value, element) { + return this.optional(element) || /^(01|02|03|04|05|06|07|08|09|10|11|12)$/.test(value); + }, "Please specify a valid 2-digit month."); + + $.validator.addMethod("year", function(value, element) { + return this.optional(element) || /^[0-9]{2}$/.test(value); + }, "Please specify a valid 2-digit year."); + + validator = $form.validate({ + rules: { + cardNumber: { + required: true, + creditcard: true, + digits: true + }, + expMonth: { + required: true, + month: true + }, + expYear: { + required: true, + year: true + }, + cvCode: { + required: true, + digits: true + } + }, + highlight: function(element) { + $(element).closest('.form-control').removeClass('success').addClass('error'); + }, + unhighlight: function(element) { + $(element).closest('.form-control').removeClass('error').addClass('success'); + }, + errorPlacement: function(error, element) { + $(element).closest('.form-group').append(error); + } + }); + + paymentFormReady = function() { + if ($form.find('[name=cardNumber]').hasClass("success") && + $form.find('[name=expMonth]').hasClass("success") && + $form.find('[name=expYear]').hasClass("success") && + $form.find('[name=cvCode]').val().length > 1) { + return true; + } else { + return false; + } + }; + + $form.find('[type=submit]').prop('disabled', true); + var readyInterval = setInterval(function() { + if (paymentFormReady()) { + $form.find('[type=submit]').prop('disabled', false); + clearInterval(readyInterval); + } + }, 250); + +}); diff --git a/digitalglarus/static/digitalglarus/js/payment.js b/digitalglarus/static/digitalglarus/js/payment.js index 7e30a667..8307be03 100644 --- a/digitalglarus/static/digitalglarus/js/payment.js +++ b/digitalglarus/static/digitalglarus/js/payment.js @@ -28,10 +28,7 @@ $( document ).ready(function() { var hasCreditcard = window.hasCreditcard; - hasCreditcard= true; - console.log("has creditcard"); - console.log("has creditcard"); - console.log("has creditcard"); + hasCreditcard= true; var submit_form_btn = $('#payment_button'); submit_form_btn.on('click', submit_payment); @@ -103,6 +100,7 @@ $( document ).ready(function() { }); } + /* Form validation */ $.validator.addMethod("month", function(value, element) { return this.optional(element) || /^(01|02|03|04|05|06|07|08|09|10|11|12)$/.test(value); diff --git a/digitalglarus/templates/digitalglarus/booking_payment.html b/digitalglarus/templates/digitalglarus/booking_payment.html index 744e9789..4c2e7116 100644 --- a/digitalglarus/templates/digitalglarus/booking_payment.html +++ b/digitalglarus/templates/digitalglarus/booking_payment.html @@ -76,7 +76,7 @@ {% if credit_card_data.last4 %}
-

Credit CardNew

+

Credit CardNew

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

Type: {{credit_card_data.cc_brand}}

diff --git a/digitalglarus/templates/digitalglarus/edit_credit_card.html b/digitalglarus/templates/digitalglarus/edit_credit_card.html index 8fbe2224..acdb6458 100644 --- a/digitalglarus/templates/digitalglarus/edit_credit_card.html +++ b/digitalglarus/templates/digitalglarus/edit_credit_card.html @@ -30,34 +30,69 @@
-

Edit Credit Card

+

New Credit Card


-
+ +

Credit Card Information

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

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

Type: {{cc_brand}}

-

Exp month: {{expMonth}}

-

Exp year: {{expYear}}

- -

Edit Card credit card

- - + +
- -
+
- +
@@ -135,159 +183,9 @@ {% if stripe_key %} {%endif%} - - {% endblock %} \ No newline at end of file diff --git a/digitalglarus/templates/digitalglarus/membership_deactivated2.html b/digitalglarus/templates/digitalglarus/membership_deactivated2.html deleted file mode 100644 index 4283b8b5..00000000 --- a/digitalglarus/templates/digitalglarus/membership_deactivated2.html +++ /dev/null @@ -1,106 +0,0 @@ -{% extends "new_base_glarus.html" %} -{% load staticfiles cms_tags bootstrap3%} -{% block title %}crowdfunding{% endblock %} - -{% block content %} - - - -
-
-
-
- - -
-

Membership Deactivation

-
-

Do you want to cancel your membership with us ?

-
-
- - - - - - -
-
-
-
- - - -
-
-
-
-
-
- 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 deleted file mode 100644 index d2105a02..00000000 --- a/digitalglarus/templates/digitalglarus/new_credit_card.html +++ /dev/null @@ -1,340 +0,0 @@ -{% extends "new_base_glarus.html" %} -{% load staticfiles bootstrap3 i18n %} -{% block content %} - - - -
-
-
-
-

New Credit Card

- -
- -

- -

- -
-

Credit Card Information

- - - -
- {% csrf_token %} -

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

-

Type: {{cc_brand}}

- -
-

Credit Card (New One)

- - - -
-
- -
- - - -
- - - -
-
-
-
-
- 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/new_base_glarus.html b/digitalglarus/templates/new_base_glarus.html index dad13883..713b5ca8 100644 --- a/digitalglarus/templates/new_base_glarus.html +++ b/digitalglarus/templates/new_base_glarus.html @@ -281,11 +281,12 @@ + - + diff --git a/digitalglarus/urls.py b/digitalglarus/urls.py index f0fe44e0..eba9896e 100644 --- a/digitalglarus/urls.py +++ b/digitalglarus/urls.py @@ -2,25 +2,20 @@ from django.conf.urls import url from django.utils.translation import ugettext_lazy as _ from . import views -from .views import ContactView, IndexView, AboutView, HistoryView, LoginView, SignupView,\ +from .views import ContactView, IndexView, HistoryView, LoginView, SignupView,\ PasswordResetView, PasswordResetConfirmView, MembershipPaymentView, MembershipActivatedView,\ MembershipPricingView, BookingSelectDatesView, BookingPaymentView, OrdersBookingDetailView,\ BookingOrdersListView, MembershipOrdersListView, OrdersMembershipDetailView, \ - MembershipDeactivateView, MembershipDeactivateSuccessView, UserBillingAddressView,EditCreditCard, \ - MembershipReactivateView,TermsAndConditions,ValidateUser,SupportusView,Probar,TermsAndConditions2,TermsAndConditions3,BookingPaymentView2 + MembershipDeactivateView, MembershipDeactivateSuccessView, UserBillingAddressView, EditCreditCardView, \ + MembershipReactivateView, SupportusView # from membership.views import LoginRegistrationView urlpatterns = [ - url(_(r'booking/payment/edit/?$'),EditCreditCard,name= 'edit_credit_card'), - 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'), - url(_(r'login/validate/(?P\!\w+)/?$'), ValidateUser.as_view(), name='validate-login'), + url(_(r'booking/payment/edit/?$'), EditCreditCardView.as_view(), name='edit_credit_card'), url(_(r'^$'), IndexView.as_view(), name='landing'), - url(_(r'new_credit_card/?$'), TermsAndConditions, name='TermsAndConditions'), + # url(_(r'new_credit_card/?$'), 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'), @@ -57,8 +52,6 @@ urlpatterns = [ url(_(r'membership/orders/?$'), MembershipOrdersListView.as_view(), name='membership_orders_list'), url(_(r'supporters/?$'), views.supporters, name='supporters'), - url(r'calendar_api/(?P\d+)/(?P\d+)?$', views.CalendarApi.as_view(),name='calendar_api_1'), - url(r'calendar_api/', views.CalendarApi.as_view(),name='calendar_api'), # url(_(r'support-us/?$'), views.support, name='support'), url(r'^blog/(?P\w[-\w]*)/$', views.blog_detail, name='blog-detail'), url(r'blog/$', views.blog, name='blog'), diff --git a/digitalglarus/views.py b/digitalglarus/views.py index ed9e062b..a33775c9 100644 --- a/digitalglarus/views.py +++ b/digitalglarus/views.py @@ -1,10 +1,5 @@ -import json -import datetime -from django.views.decorators.csrf import csrf_protect, csrf_exempt -from django.template import RequestContext from django.conf import settings -from django.shortcuts import get_object_or_404, render -from django.forms import ModelForm +from django.shortcuts import render from django.http import HttpResponseRedirect from django.core.urlresolvers import reverse_lazy, reverse from django.utils.translation import ugettext_lazy as _ @@ -13,23 +8,18 @@ from django.contrib.auth.mixins import LoginRequiredMixin from django.utils.translation import get_language 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 django.views.generic import DetailView, ListView 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 membership.models import StripeCustomer from utils.views import LoginViewMixin, SignupViewMixin, \ PasswordResetViewMixin, PasswordResetConfirmViewMixin -from utils.forms import PasswordResetRequestForm, UserBillingAddressForm +from utils.forms import PasswordResetRequestForm, UserBillingAddressForm, EditCreditCardForm from utils.stripe_utils import StripeUtils from utils.models import UserBillingAddress -import stripe from .forms import LoginForm, SignupForm, MembershipBillingForm, BookingDateForm,\ BookingBillingForm, CancelBookingForm @@ -38,142 +28,6 @@ from .models import MembershipType, Membership, MembershipOrder, Booking, Bookin BookingOrder, BookingCancellation from .mixins import MembershipRequiredMixin, IsNotMemberMixin - -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") - -class ValidateUser(TemplateView): - #print ("ENTRE AQUI AL MENOS Y",pk) - template_name = "digitalglarus/signup.html" - #form_class = SignupForm - success_url = reverse_lazy('digitalglarus:login') - #if request.method == 'POST': - #u = U.objects.get(pk = pk) - #u.is_active = True - #u.save() - #messages.info(request, 'Usuario Activado') - #Log('activar','usuario',request) - #resp = dict() - #resp['msg'] = 0 #0 para exito - #return HttpResponse(json.dumps(resp), content_type ='application/json') - -class ValidateView(SignupViewMixin): - template_name = "digitalglarus/signup.html" - form_class = SignupForm - success_url = reverse_lazy('digitalglarus:login') - -@csrf_exempt -def TermsAndConditions(request): - cus = StripeCustomer.get_or_create(email=request.user.email) - s= str(cus) - s= s.split(" ") - cc = dict() - customer = stripe.Customer.retrieve(s[0]) - custom_card= customer.default_source - card = customer.sources.retrieve(custom_card) - cc['last4']= card.last4 - cc['cc_brand'] = card.brand - 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() - current_billing_address = request.user.billing_addresses.first() - 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)) - - -def TermsAndConditions3(request): - return render_to_response('digitalglarus/new_credit_card.html',{'last4':credit_card_data['last4'],'brand_type':credit_card_data['cc_brand']}) - -def EditCreditCard(request): - 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 - cc['exp_month']=i.exp_month - cc['exp_year']= i.exp_year - #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 \ - and last_booking_order.get_booking_cc_data() \ - else last_membership_order.get_membership_order_cc_data() - - current_billing_address = request.user.billing_addresses.first() - return render_to_response('digitalglarus/edit_credit_card.html',{'last4':cc['last4'],'brand_type':cc['cc_brand'],'expMonth': cc['exp_month'], 'expYear': cc['exp_year']}) - -class TermsAndConditions2(TemplateView): - template_name ="digitalglarus/credit_card_edit_confirmation.html" class IndexView(TemplateView): @@ -237,6 +91,32 @@ class HistoryView(TemplateView): return context +class EditCreditCardView(FormView): + template_name = "digitalglarus/edit_credit_card.html" + form_class = EditCreditCardForm + success_url = reverse_lazy('digitalglarus:booking_payment') + + def get_context_data(self, *args, **kwargs): + context = super(EditCreditCardView, self).get_context_data(*args, **kwargs) + context.update({ + 'stripe_key': settings.STRIPE_API_PUBLIC_KEY + }) + return context + + def form_valid(self, form): + token = form.cleaned_data.get('token') + user = self.request.user + customer = user.stripecustomer + stripe_utls = StripeUtils() + card_response = stripe_utls.update_customer_card(customer.stripe_id, token) + new_card_data = card_response.get('response_object') + self.request.session.update({ + 'new_change_credit_card': new_card_data + }) + + return super(EditCreditCardView, self).form_valid(form) + + class BookingSelectDatesView(LoginRequiredMixin, MembershipRequiredMixin, FormView): template_name = "digitalglarus/booking.html" form_class = BookingDateForm @@ -320,34 +200,16 @@ 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() - #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 - ########################################################################## - - + + # check if user changes his credit card + credit_card_data = self.request.session.get('new_change_credit_card') + # import pdb + # pdb.set_trace() + + if not credit_card_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() booking_data.update({ 'credit_card_data': credit_card_data if credit_card_data else None, @@ -369,8 +231,6 @@ class BookingPaymentView(LoginRequiredMixin, MembershipRequiredMixin, FormView): # if not credit_card_needed: # Get or create stripe customer - # import pdb - # pdb.set_trace() customer = StripeCustomer.get_or_create(email=self.request.user.email, token=token) if not customer: @@ -738,23 +598,6 @@ class OrdersMembershipDetailView(LoginRequiredMixin, DetailView): return context -# class BookingCancelView(FormView): -# success_message = "Your booking has been cancelled" -# model = BookingOrder -# form_class = CancelBookingForm - -# def get_success_url(self): -# pk = self.kwargs.get(self.pk_url_kwarg) -# return reverse_lazy('digitalglarus:booking_orders_list', kwargs={'pk': pk}) - -# def form_valid(self, form): -# booking_order = self.get_object() -# # booking_order.cancel() -# request = self.request - -# return HttpResponseRedirect(self.get_success_url()) - - class OrdersBookingDetailView(LoginRequiredMixin, UpdateView): template_name = "digitalglarus/booking_orders_detail.html" context_object_name = "order" @@ -865,19 +708,6 @@ class BookingOrdersListView(LoginRequiredMixin, ListView): return queryset -############## OLD VIEWS -class CalendarApi(View): - def get(self,request,month,year): - calendar = BookCalendar(request.user,requested_month=month).formatmonth(int(year),int(month)) - ret = {'calendar':calendar,'month':month,'year':year} - return JsonResponse(ret) - - def post(self,request): - pd = json.loads(request.POST.get('data','')) - ret = {'status':'success'} - CalendarModel.add_dates(pd,request.user) - return JsonResponse(ret) - class ContactView(FormView): template_name = 'contact.html' form_class = ContactUsForm @@ -890,25 +720,7 @@ class ContactView(FormView): messages.add_message(self.request, messages.SUCCESS, self.success_message) return super(ContactView, self).form_valid(form) - -class AboutView(TemplateView): - template_name = "digitalglarus/about.html" - -def detail(request, message_id): - p = get_object_or_404(Message, pk=message_id) - - context = { 'message': p, } - return render(request, 'digitalglarus/detail.html', context) - -def about(request): - return render(request, 'digitalglarus/about.html') - -def home(request): - return render(request, 'index.html') - -def letscowork(request): - return render(request, 'digitalglarus/letscowork.html') - +############## OLD VIEWS def blog(request): tags = ["digitalglarus"] diff --git a/utils/forms.py b/utils/forms.py index e8580f9d..85c23721 100644 --- a/utils/forms.py +++ b/utils/forms.py @@ -95,6 +95,10 @@ class SetPasswordForm(forms.Form): return password2 +class EditCreditCardForm(forms.Form): + token = forms.CharField(widget=forms.HiddenInput()) + + class BillingAddressForm(forms.ModelForm): token = forms.CharField(widget=forms.HiddenInput()) diff --git a/utils/stripe_utils.py b/utils/stripe_utils.py index 0edba66b..679a8b58 100644 --- a/utils/stripe_utils.py +++ b/utils/stripe_utils.py @@ -59,11 +59,23 @@ class StripeUtils(object): self.stripe = stripe def update_customer_token(self, customer, token): - # customer = stripe.Customer.retrieve(id) - customer.source = token customer.save() + @handleStripeError + def update_customer_card(self, customer_id, token): + customer = stripe.Customer.retrieve(customer_id) + current_card_token = customer.default_source + customer.sources.retrieve(current_card_token).delete() + customer.source = token + customer.save() + credit_card_raw_data = customer.sources.data.pop() + new_card_data = { + 'last4': credit_card_raw_data.last4, + 'brand': credit_card_raw_data.brand + } + return new_card_data + def check_customer(self, id, user, token): customers = self.stripe.Customer.all() if not customers.get('data'): @@ -77,6 +89,12 @@ class StripeUtils(object): user.stripecustomer.save() return customer + @handleStripeError + def get_customer(self, id): + customer = stripe.Customer.retrieve(id) + # data = customer.get('response_object') + return customer + @handleStripeError def create_customer(self, token, email):