update dg payment
This commit is contained in:
parent
e0fc542673
commit
45730e4eb1
10 changed files with 69 additions and 60 deletions
|
|
@ -8,6 +8,7 @@ from django.core.mail import send_mail
|
|||
from django.core.validators import RegexValidator
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.sites.models import Site
|
||||
|
||||
from utils.stripe_utils import StripeUtils
|
||||
|
||||
REGISTRATION_MESSAGE = {'subject': "Validation mail",
|
||||
|
|
@ -132,8 +133,12 @@ class StripeCustomer(models.Model):
|
|||
Check if there is a registered stripe customer with that email
|
||||
or create a new one
|
||||
"""
|
||||
|
||||
try:
|
||||
stripe_utils = StripeUtils()
|
||||
stripe_customer = cls.objects.get(user__email=email)
|
||||
#check if user is not in stripe but in database
|
||||
stripe_utils.check_customer(stripe_customer.stripe_id,stripe_customer.user,token)
|
||||
return stripe_customer
|
||||
|
||||
except StripeCustomer.DoesNotExist:
|
||||
|
|
@ -142,7 +147,7 @@ class StripeCustomer(models.Model):
|
|||
stripe_utils = StripeUtils()
|
||||
stripe_data = stripe_utils.create_customer(token, email)
|
||||
|
||||
stripe_customer = StripeCustomer.objects.\
|
||||
stripe_customer = StripeCustomer.objects. \
|
||||
create(user=user, stripe_id=stripe_data.get('id'))
|
||||
|
||||
return stripe_customer
|
||||
|
|
@ -157,6 +162,10 @@ class CreditCards(models.Model):
|
|||
ccv = models.CharField(max_length=4, validators=[RegexValidator(r'\d{3,4}', _('Wrong CCV number.'))])
|
||||
payment_type = models.CharField(max_length=5, default='N')
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
# override saving to database
|
||||
pass
|
||||
|
||||
|
||||
class Calendar(models.Model):
|
||||
datebooked = models.DateField()
|
||||
|
|
@ -170,10 +179,9 @@ class Calendar(models.Model):
|
|||
super(Calendar, self).__init__(*args, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def add_dates(cls,dates,user):
|
||||
def add_dates(cls, dates, user):
|
||||
old_dates = Calendar.objects.filter(user_id=user.id)
|
||||
if old_dates:
|
||||
old_dates.delete()
|
||||
for date in dates:
|
||||
Calendar.objects.create(datebooked=date,user=user)
|
||||
|
||||
Calendar.objects.create(datebooked=date, user=user)
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@
|
|||
for coworking. It is a perfect try-out package!
|
||||
<br>
|
||||
</p>
|
||||
<a class="btn btn-primary" href="/login/buy/month/">Buy Now</a>
|
||||
<a class="btn btn-primary" href="{% url 'payment' time='month' %}">Buy Now</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -146,7 +146,7 @@
|
|||
membership.
|
||||
<br>
|
||||
</p>
|
||||
<a class="btn btn-primary" href="/login/buy/year/">Buy Now</a>
|
||||
<a class="btn btn-primary" href="{% url 'payment' time='year' %}">Buy Now</a>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<img src="https://unsplash.imgix.net/photo-1413834932717-29e7d4714192?w=1024&q=50&fm=jpg&s=d9d6cbc32dd4968d0c21e331436a6af6"
|
||||
|
|
|
|||
|
|
@ -1,17 +1,18 @@
|
|||
{% load static %}
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<script type="text/javascript" src="{% static 'digitalglarus/bower_components/jquery/dist/jquery.min.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'digitalglarus/bower_components/bootstrap/dist/js/bootstrap.min.js' %}"></script>
|
||||
<link href="{% static 'digitalglarus/css/font-awesome.min.css' %}" rel="stylesheet" type="text/css">
|
||||
<link href="{% static 'digitalglarus/bower_components/font-awesome/css/font-awesome.min.css' %}" rel="stylesheet" type="text/css">
|
||||
<link href="{% static 'digitalglarus/bower_components/bootstrap/dist/css/bootstrap.min.css' %}" rel="stylesheet"
|
||||
type="text/css">
|
||||
{% if request.session.next == None %}
|
||||
<script>
|
||||
type = "text/javascript" >
|
||||
setTimeout(function () {
|
||||
window.location.href = "/";
|
||||
window.location.href = "{% url 'membership' %}";
|
||||
}, 5000);
|
||||
</script>
|
||||
{% endif %}
|
||||
|
|
@ -25,7 +26,7 @@
|
|||
{% if msg == 'succeeded' %}
|
||||
Thank You for Your payment!<br> <p>redirecting...</p>
|
||||
{% else %}
|
||||
Your payment was not processed correctly.<br> Reason: {{ msg }}
|
||||
Your payment was not processed correctly. Please contact us <a href="{% url 'digitalglarus:contact' %}">here</a>!
|
||||
{% endif %}
|
||||
</h3>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ from django.contrib.auth import logout
|
|||
from django.http import HttpResponseRedirect
|
||||
from django.contrib.auth import login
|
||||
|
||||
from .models import CustomUser
|
||||
from .models import CustomUser,StripeCustomer
|
||||
from .forms import (LoginForm, RegisterForm, PaymentForm)
|
||||
from .payment import StripePayment
|
||||
from utils.stripe_utils import StripeUtils
|
||||
|
||||
|
||||
def validate_email(request, validate_slug):
|
||||
|
|
@ -49,10 +49,12 @@ class CreditCardView(View):
|
|||
template = 'templates/creditcard.html'
|
||||
request.session['next'] +=1
|
||||
elif next == 2:
|
||||
msg = StripePayment.make_payment(request.user, request.session['amount'],
|
||||
request.session['token'],request.session['time'])
|
||||
customer = StripeCustomer.get_or_create(email=request.user.email,token=request.session['token'])
|
||||
stripe_utils = StripeUtils()
|
||||
charge = stripe_utils.make_charge(request.session['amount'],customer=customer.stripe_id)
|
||||
template = 'templates/validated.html'
|
||||
context['msg'] = msg
|
||||
import ipdb;ipdb.set_trace()
|
||||
context['msg'] = charge.get('status')
|
||||
request.session['next'] = None
|
||||
return render(request, template, context)
|
||||
|
||||
|
|
@ -63,7 +65,6 @@ class CreditCardView(View):
|
|||
if form.is_valid():
|
||||
ret = form.save(request.user)
|
||||
amount = 35 if time == 'month' else 360
|
||||
amount = amount * 100 # payments are in 'cents'
|
||||
request.session['token'] = stripe_token
|
||||
request.session['amount'] = amount
|
||||
request.session['next'] +=1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue