diff --git a/digitalglarus/forms.py b/digitalglarus/forms.py index 4084ced5..6982037f 100644 --- a/digitalglarus/forms.py +++ b/digitalglarus/forms.py @@ -57,7 +57,7 @@ class MembershipOrderForm(forms.ModelForm): class BookingBillingForm(BillingAddressForm): - token = forms.CharField(widget=forms.HiddenInput()) + token = forms.CharField(widget=forms.HiddenInput(), required=False) start_date = forms.DateField(widget=forms.HiddenInput()) end_date = forms.DateField(widget=forms.HiddenInput()) price = forms.FloatField(widget=forms.HiddenInput()) diff --git a/digitalglarus/migrations/0020_auto_20161013_0253.py b/digitalglarus/migrations/0020_auto_20161013_0253.py new file mode 100644 index 00000000..f9d49868 --- /dev/null +++ b/digitalglarus/migrations/0020_auto_20161013_0253.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.4 on 2016-10-13 02:53 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('digitalglarus', '0019_auto_20160929_0324'), + ] + + operations = [ + migrations.AlterField( + model_name='bookingorder', + name='cc_brand', + field=models.CharField(blank=True, max_length=10), + ), + migrations.AlterField( + model_name='bookingorder', + name='last4', + field=models.CharField(blank=True, max_length=4), + ), + migrations.AlterField( + model_name='membershiporder', + name='cc_brand', + field=models.CharField(blank=True, max_length=10), + ), + migrations.AlterField( + model_name='membershiporder', + name='last4', + field=models.CharField(blank=True, max_length=4), + ), + ] diff --git a/digitalglarus/mixins.py b/digitalglarus/mixins.py index 013cdd78..5392ad37 100644 --- a/digitalglarus/mixins.py +++ b/digitalglarus/mixins.py @@ -32,8 +32,8 @@ class Ordereable(models.Model): billing_address = models.ForeignKey(BillingAddress) created_at = models.DateTimeField(auto_now_add=True) approved = models.BooleanField(default=False) - last4 = models.CharField(max_length=4) - cc_brand = models.CharField(max_length=10) + last4 = models.CharField(max_length=4, blank=True) + cc_brand = models.CharField(max_length=10, blank=True) stripe_charge_id = models.CharField(max_length=100, null=True) class Meta: @@ -43,6 +43,8 @@ class Ordereable(models.Model): def create(cls, data): stripe_charge = data.pop('stripe_charge', None) instance = cls.objects.create(**data) + if not stripe_charge: + return instance instance.stripe_charge_id = stripe_charge.id instance.last4 = stripe_charge.source.last4 instance.cc_brand = stripe_charge.source.brand diff --git a/digitalglarus/models.py b/digitalglarus/models.py index 17621bfd..9d423f3d 100644 --- a/digitalglarus/models.py +++ b/digitalglarus/models.py @@ -71,12 +71,12 @@ class Membership(models.Model): @classmethod def is_digitalglarus_active_member(cls, user): past_month = (datetime.today() - relativedelta(months=1)).month - has_booking_current_month = Q(membershiporder__customer__user=user, - membershiporder__created_at__month=datetime.today().month) - has_booking_past_month = Q(membershiporder__customer__user=user, - membershiporder__created_at__month=past_month) + has_order_current_month = Q(membershiporder__customer__user=user, + membershiporder__created_at__month=datetime.today().month) + has_order_past_month = Q(membershiporder__customer__user=user, + membershiporder__created_at__month=past_month) active_membership = Q(active=True) - return cls.objects.filter(has_booking_past_month | has_booking_current_month).\ + return cls.objects.filter(has_order_past_month | has_order_current_month).\ filter(active_membership).exists() def deactivate(self): @@ -147,7 +147,7 @@ class Booking(models.Model): def get_ramaining_free_days(cls, user, start_date, end_date): TWO_DAYS = 2 - + ONE_DAY = 1 start_month = start_date.month end_month = end_date.month months = abs(start_month - (end_month + 12) if end_month < start_month @@ -156,6 +156,10 @@ class Booking(models.Model): current_month_bookings = cls.objects.filter(bookingorder__customer__user=user, start_date__month=current_date.month) free_days_this_month = TWO_DAYS - sum(map(lambda x: x.free_days, current_month_bookings)) + + if start_date == end_date and free_days_this_month == TWO_DAYS: + free_days_this_month = ONE_DAY + total_free_days = months * TWO_DAYS + free_days_this_month return total_free_days @@ -190,11 +194,11 @@ class Booking(models.Model): # Calculating membership required months price for booking required_membership_months = 0 membership_booking_price = 0.0 - if BookingOrder.user_has_not_bookings(user): - today = datetime.today().date() - membership_price = MembershipType.objects.get(name=MembershipType.STANDARD).price - required_membership_months = cls.membership_required_booking_months(today, end_date) - membership_booking_price = membership_price * required_membership_months + # if not BookingOrder.user_has_not_bookings(user): + today = datetime.today().date() + membership_price = MembershipType.objects.get(name=MembershipType.STANDARD).price + required_membership_months = cls.membership_required_booking_months(today, end_date) + membership_booking_price = membership_price * required_membership_months # Add required membership months to final prices final_booking_price += membership_booking_price @@ -210,11 +214,15 @@ class BookingOrder(Ordereable, models.Model): membership_required_months = models.IntegerField(default=0) membership_required_months_price = models.FloatField(default=0) - @classmethod def user_has_not_bookings(cls, user): return cls.objects.filter(customer__user=user).exists() + def get_booking_cc_data(self): + return { + 'last4': self.last4, + 'cc_brand': self.cc_brand, + } def booking_days(self): return (self.booking.end_date - self.booking.start_date).days + 1 diff --git a/digitalglarus/static/digitalglarus/css/agency.css b/digitalglarus/static/digitalglarus/css/agency.css index 7be17307..39289c6e 100755 --- a/digitalglarus/static/digitalglarus/css/agency.css +++ b/digitalglarus/static/digitalglarus/css/agency.css @@ -241,6 +241,8 @@ fieldset[disabled] .btn-xl.active { .navbar-default .navbar-collapse { border-color: rgba(255,255,255,.02); + padding-right: 100px; + text-align: right; } .navbar-default .navbar-toggle { @@ -259,7 +261,7 @@ fieldset[disabled] .btn-xl.active { .navbar-default .nav li a { text-transform: uppercase; - font-family: Montserrat,"Helvetica Neue",Helvetica,Arial,sans-serif; + font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; font-weight: 400; letter-spacing: 1px; color: #fff; diff --git a/digitalglarus/static/digitalglarus/css/price.css b/digitalglarus/static/digitalglarus/css/price.css index 22d37b99..359b47fe 100644 --- a/digitalglarus/static/digitalglarus/css/price.css +++ b/digitalglarus/static/digitalglarus/css/price.css @@ -197,7 +197,7 @@ } .glyphicon-ok { - font-size: 42px; + font-size: 28px; display: block; text-align: center; margin-bottom: 20px; @@ -364,7 +364,7 @@ } .form-control { - color: #999; + color: #000; border-radius: 0px; box-shadow: none; } diff --git a/digitalglarus/static/digitalglarus/js/payment.js b/digitalglarus/static/digitalglarus/js/payment.js index dd6c64d4..d9c6e0f7 100644 --- a/digitalglarus/static/digitalglarus/js/payment.js +++ b/digitalglarus/static/digitalglarus/js/payment.js @@ -24,12 +24,21 @@ $( document ).ready(function() { } }); + var submit_form_btn = $('#payment_button'); + submit_form_btn.on('click', submit_payment); + + function submit_payment(e){ + $('#billing-form').submit(); + // $form.submit(); + } + var $form = $('#payment-form'); $form.submit(payWithStripe); /* If you're using Stripe for payments */ function payWithStripe(e) { + console.log("submiting"); e.preventDefault(); /* Visual feedback */ diff --git a/digitalglarus/templates/digitalglarus/booking_orders_list.html b/digitalglarus/templates/digitalglarus/booking_orders_list.html index bff0e231..9fa3d793 100644 --- a/digitalglarus/templates/digitalglarus/booking_orders_list.html +++ b/digitalglarus/templates/digitalglarus/booking_orders_list.html @@ -39,11 +39,15 @@ -
Your membership will be automatically renewed each month. For deactivating go tomy page
+Your membership will be automatically renewed each month. For deactivating go todeactivate page
You will be charged on the first of the month until you + cancel your subscription. Previous charges won't be refunded.
This box is here just to thank you
+ + {% endif %} + + + -This box is here just to thank you