more work on payment gateway

This commit is contained in:
Oly 2017-01-30 17:08:37 +00:00
parent fb271941bb
commit e5c1e15010
10 changed files with 155 additions and 3 deletions

View File

@ -16,5 +16,5 @@ class MemberListView(LoginRequiredMixin, ListView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(MemberListView, self).get_context_data(**kwargs) context = super(MemberListView, self).get_context_data(**kwargs)
context['members'] = self.get_queryset() context['members'] = self.get_queryset()
context['total'] = self.get_queryset().filter(groups__name='member').count() context['total'] = self.get_queryset().filter(groups__name='members').count()
return context return context

View File

@ -0,0 +1,41 @@
from datetime import datetime
from django.utils import timezone
from django.contrib.auth.models import Group
from django.forms.models import model_to_dict
from django.core.management.base import BaseCommand
from mhackspace.subscriptions.payments import select_provider
from mhackspace.users.models import Membership, User
from mhackspace.subscriptions.models import Payments
class Command(BaseCommand):
help = 'Update user subscriptions'
def handle(self, *args, **options):
provider = select_provider('gocardless')
self.stdout.write(
self.style.NOTICE(
'== Gocardless customers =='))
Payments.objects.all().delete()
for customer in provider.fetch_customers():
self.stdout.write(str(dir(customer)))
self.stdout.write(str(customer))
Payments.objects.create(
user=None,
user_reference=customer.get('user_id'),
user_email=customer.get('email'),
reference=customer.get('payment_id'),
amount=customer.get('amount'),
type=Payments.lookup_payment_type(customer.get('payment_type')),
date=customer.get('payment_date')
)
# self.stdout.write(str(customer.email))
# self.stdout.write(str(dir(customer['email']())))
# self.stdout.write(
# self.style.SUCCESS(
# '\t{reference} - {payment} - {status} - {email}'.format(**model_to_dict(subscriptions[-1]))))

View File

@ -20,7 +20,7 @@ class Command(BaseCommand):
Membership.objects.all().delete() Membership.objects.all().delete()
subscriptions = [] subscriptions = []
group = Group.objects.get(name='member') group = Group.objects.get(name='members')
for sub in provider.fetch_subscriptions(): for sub in provider.fetch_subscriptions():
try: try:

View File

@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-01-29 21:55
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Payments',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('user_reference', models.CharField(max_length=255)),
('user_email', models.CharField(max_length=255)),
('reference', models.CharField(max_length=255, unique=True)),
('amount', models.DecimalField(decimal_places=2, default=0.0, max_digits=6)),
('type', models.PositiveSmallIntegerField(default=0)),
('date', models.DateTimeField()),
('user', models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='from_user', to=settings.AUTH_USER_MODEL)),
],
),
]

View File

@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import
from django.conf import settings
from django.contrib.auth.models import AbstractUser
from django.core.urlresolvers import reverse
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from stdimage.models import StdImageField
PAYMENT_TYPES = {
'unknown': 0,
'subscription': 1,
'payment': 2
}
@python_2_unicode_compatible
class Payments(models.Model):
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
null=True, blank=True,
default=None,
related_name='from_user'
)
user_reference = models.CharField(max_length=255)
user_email = models.CharField(max_length=255)
reference = models.CharField(max_length=255, unique=True)
amount = models.DecimalField(max_digits=6, decimal_places=2, default=0.0)
type = models.PositiveSmallIntegerField(default=0)
date = models.DateTimeField()
def lookup_payment_type(name):
return PAYMENT_TYPES.get(name, 0)
def get_payment_type(self):
return self.type
def __str__(self):
return self.reference

View File

@ -50,6 +50,39 @@ class gocardless_provider:
'success': response.success 'success': response.success
} }
def fetch_customers(self):
merchant = gocardless.client.merchant()
for customer in merchant.bills():
user = customer.user()
print(dir(customer))
print(dir(customer.reference_fields))
print(customer.reference_fields)
print(customer.payout_id)
print(customer.reference_fields.payout_id)
result = {
'user_id': user.id,
'email': user.email,
'status': customer.status,
'payment_id': customer.source_id,
'payment_type': customer.source_type,
'payment_date': customer.created_at,
'amount': customer.amount
}
yield result #customer
# for customer in self.client.users():
# result = {
# 'email': customer.email,
# 'created_date': customer.created_at,
# 'first_name': customer.first_name,
# 'last_name': customer.last_name
# }
# yield customer
def fetch_subscriptions(self): def fetch_subscriptions(self):
for paying_member in self.client.subscriptions(): for paying_member in self.client.subscriptions():
user=paying_member.user() user=paying_member.user()

View File

@ -4,5 +4,7 @@
{% block content %} {% block content %}
<h2>Introduction</h2> <h2>Introduction</h2>
Hackspaces are a shared space where artists, designers, makers, hackers, programmers, tinkerers, professionals and hobbyists can work on their projects, share knowledge and collaborate.We are in the process of developing Maidstone Hackspace. We're previous members of (ICMP) and looking to form a new space in the future. At the moment, communication is via google groups, email, and the website. If you're at all intrested please join our mailing list and make yourself known! Hackspaces are a shared space where artists, designers, makers, hackers, programmers, tinkerers, professionals and hobbyists can work on their projects, share knowledge and collaborate.We are in the process of developing Maidstone Hackspace. We're previous members of (ICMP) and looking to form a new space in the future. At the moment, communication is via google groups, email, and the website. If you're at all intrested please join our mailing list and make yourself known!
Click here to chat with us https://hangouts.google.com/group/oDcAL0nDfQYfO3qq1
{% show_feeds %} {% show_feeds %}
{% endblock content %} {% endblock content %}

View File

@ -36,7 +36,7 @@
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<div id="membercard" class="registered"> <div id="membercard" class="registered">
<div class="date">Joined </div> <div class="date">Joined {{membership.start_date}}</div>
<div class="container"> <div class="container">
<div class="middle"> <div class="middle">
<p>MHS{{ user.id|stringformat:"05d" }}</p><p>{{user.name}}{{user.last_name}}</p> <p>MHS{{ user.id|stringformat:"05d" }}</p><p>{{user.name}}{{user.last_name}}</p>

View File

@ -0,0 +1,2 @@
Postgres is up - continuing...
[{"model": "auth.group", "pk": 1, "fields": {"name": "members", "permissions": []}}]