diff --git a/bornhack/settings/base.py b/bornhack/settings/base.py
index ae2c5978..816b468a 100644
--- a/bornhack/settings/base.py
+++ b/bornhack/settings/base.py
@@ -1,5 +1,8 @@
import os
+import environ
+env = environ.Env()
+environ.Env.read_env()
def local_dir(entry):
return os.path.join(
@@ -91,3 +94,6 @@ BOOTSTRAP3 = {
'jquery_url': '/static/js/jquery.min.js',
'javascript_url': '/static/js/bootstrap.min.js'
}
+
+EPAY_MERCHANT_NUMBER = env('EPAY_MERCHANT_NUMBER')
+EPAY_MD5_SECRET = env('EPAY_MD5_SECRET')
diff --git a/bornhack/settings/env.dist b/bornhack/settings/env.dist
index 23b99a18..dea3f432 100644
--- a/bornhack/settings/env.dist
+++ b/bornhack/settings/env.dist
@@ -7,3 +7,5 @@ EMAIL_HOST_USER='mymailuser'
EMAIL_HOST_PASSWORD='mymailpassword'
EMAIL_USE_TLS=True
EMAIL_FROM='noreply@example.com'
+EPAY_MERCHANT_NUMBER=something
+EPAY_MD5_SECRET=something
diff --git a/tickets/admin.py b/tickets/admin.py
index 3cefc7a0..6519db95 100644
--- a/tickets/admin.py
+++ b/tickets/admin.py
@@ -8,12 +8,14 @@ class TicketAdmin(admin.ModelAdmin):
list_display = [
'user',
'ticket_type',
+ 'payment_method',
'paid',
]
list_filter = [
'paid',
'ticket_type',
+ 'payment_method',
]
diff --git a/tickets/forms.py b/tickets/forms.py
index 82412ddb..8cd05fee 100644
--- a/tickets/forms.py
+++ b/tickets/forms.py
@@ -8,9 +8,14 @@ class TicketForm(forms.ModelForm):
model = Ticket
fields = [
'ticket_type',
+ 'payment_method',
]
+ widgets = {
+ 'payment_method': forms.RadioSelect()
+ }
ticket_type = forms.ModelChoiceField(
queryset=TicketType.objects.available()
)
+
diff --git a/tickets/migrations/0004_ticket_payment_method.py b/tickets/migrations/0004_ticket_payment_method.py
new file mode 100644
index 00000000..ed92e3b2
--- /dev/null
+++ b/tickets/migrations/0004_ticket_payment_method.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.5 on 2016-05-08 11:21
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('tickets', '0003_auto_20160506_2016'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='ticket',
+ name='payment_method',
+ field=models.CharField(choices=[('credit_card', 'Credit card'), ('altcoin', 'Altcoin'), ('bank_transfer', 'Bank transfer')], default='credit_card', max_length=50),
+ ),
+ ]
diff --git a/tickets/models.py b/tickets/models.py
index 595781a6..9ca7bf30 100644
--- a/tickets/models.py
+++ b/tickets/models.py
@@ -1,7 +1,8 @@
from django.db import models
-from django.contrib.postgres.fields import DateTimeRangeField
+from django.contrib.postgres.fields import DateTimeRangeField, JSONField
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone
+from django.core.urlresolvers import reverse_lazy
from bornhack.utils import CreatedUpdatedModel, UUIDModel
@@ -31,12 +32,33 @@ class Ticket(CreatedUpdatedModel, UUIDModel):
verbose_name=_('Ticket type'),
)
+ CREDIT_CARD = 'credit_card'
+ ALTCOIN = 'altcoin'
+ BANK_TRANSFER = 'bank_transfer'
+
+ PAYMENT_METHODS = [
+ (CREDIT_CARD, 'Credit card'),
+ (ALTCOIN, 'Altcoin'),
+ (BANK_TRANSFER, 'Bank transfer'),
+ ]
+
+ payment_method = models.CharField(
+ max_length=50,
+ choices=PAYMENT_METHODS,
+ default=CREDIT_CARD
+ )
+
def __str__(self):
return '{} ({})'.format(
self.ticket_type.name,
self.ticket_type.camp
)
+ def get_absolute_url(self):
+ return reverse_lazy('ticket:detail', kwargs={
+ 'pk': self.pk
+ })
+
class TicketType(CreatedUpdatedModel, UUIDModel):
class Meta:
@@ -74,3 +96,20 @@ class TicketType(CreatedUpdatedModel, UUIDModel):
def is_available(self):
now = timezone.now()
return now in self.available_in
+
+
+class EpayCallback(CreatedUpdatedModel, UUIDModel):
+ class Meta:
+ verbose_name = 'Epay Callback'
+ verbose_name_plural = 'Epay Callbacks'
+ payload = JSONField()
+
+
+class EpayPayment(CreatedUpdatedModel, UUIDModel):
+ class Meta:
+ verbose_name = 'Epay Payment'
+ verbose_name_plural = 'Epay Payments'
+
+ ticket = models.OneToOneField('tickets.Ticket')
+ callback = models.ForeignKey('tickets.EpayCallback')
+ txnid = models.IntegerField()
diff --git a/tickets/templates/tickets/epay_form.html b/tickets/templates/tickets/epay_form.html
new file mode 100644
index 00000000..d88988d8
--- /dev/null
+++ b/tickets/templates/tickets/epay_form.html
@@ -0,0 +1,27 @@
+{% extends "base.html" %}
+
+{% block content %}
+