Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(payment)/order listing #690

Closed
wants to merge 111 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
609cce1
Merge pull request #98 from tihlde/bug/accept_form_2
zaimimr Apr 1, 2020
8a149aa
Merge pull request #102 from tihlde/dev
zaimimr May 14, 2020
b63a7e7
Merge pull request #106 from tihlde/dev
zaimimr Jun 7, 2020
f5548c0
Merge pull request #110 from tihlde/dev
zaimimr Jul 28, 2020
a31df75
Merge pull request #124 from tihlde/dev
zaimimr Sep 8, 2020
d509d97
Merge pull request #136 from tihlde/dev
zaimimr Sep 17, 2020
1813598
Merge pull request #157 from tihlde/dev
Eirsteir Oct 1, 2020
cf472f4
Merge pull request #171 from tihlde/dev
Eirsteir Oct 12, 2020
cfdcc23
Merge pull request #175 from tihlde/dev
zaimimr Oct 12, 2020
3574dea
Merge pull request #193 from tihlde/dev
Eirsteir Oct 24, 2020
0f47c52
Merge pull request #214 from tihlde/dev
Eirsteir Nov 5, 2020
c5f24e6
Merge pull request #217 from tihlde/dev
Eirsteir Nov 6, 2020
50e67f4
Merge pull request #226 from tihlde/dev
Eirsteir Nov 14, 2020
e912bcf
Merge pull request #228 from tihlde/dev
Eirsteir Nov 15, 2020
710b10c
Merge pull request #238 from tihlde/dev
Eirsteir Jan 22, 2021
e44f383
Merge pull request #241 from tihlde/dev
Eirsteir Jan 22, 2021
8f5b2b7
Merge pull request #246 from tihlde/dev
Eirsteir Feb 1, 2021
60e9888
Merge pull request #256 from tihlde/dev
Eirsteir Feb 9, 2021
0a264ed
Merge pull request #267 from tihlde/dev
Eirsteir Feb 14, 2021
4d12a13
Merge pull request #285 from tihlde/dev
Eirsteir Feb 22, 2021
3217ead
Merge pull request #26 from TIHLDE/dev
Eirsteir Mar 9, 2021
cddc250
Merge pull request #32 from TIHLDE/dev
Eirsteir Mar 16, 2021
80925c8
Merge pull request #46 from TIHLDE/dev
Eirsteir Mar 25, 2021
c880912
Merge pull request #56 from TIHLDE/dev
olros Apr 9, 2021
48c423c
Merge pull request #64 from TIHLDE/dev
Eirsteir Apr 12, 2021
75a9610
Merge pull request #98 from TIHLDE/dev
olros Apr 26, 2021
a72fe6c
Merge pull request #112 from TIHLDE/dev
Eirsteir May 1, 2021
e0c4425
Merge pull request #130 from TIHLDE/dev
olros May 5, 2021
7cd764e
Merge pull request #134 from TIHLDE/dev
olros May 5, 2021
af9ae90
Merge pull request #144 from TIHLDE/dev
olros May 10, 2021
8f05cb3
Merge pull request #157 from TIHLDE/dev
olros Aug 11, 2021
29cd09d
Merge pull request #163 from TIHLDE/dev
olros Aug 30, 2021
ee5f516
Merge branch 'dev'
olros Aug 30, 2021
8c93f4b
Merge pull request #178 from TIHLDE/dev
olros Sep 6, 2021
92d1a24
Merge pull request #194 from TIHLDE/dev
olros Sep 12, 2021
d7a9e40
Merge pull request #206 from TIHLDE/dev
olros Sep 15, 2021
b770011
Merge pull request #224 from TIHLDE/dev
Eirsteir Sep 21, 2021
4bed027
Merge pull request #237 from TIHLDE/dev
Eirsteir Sep 24, 2021
87503fb
Merge pull request #258 from TIHLDE/dev
olros Sep 30, 2021
fbfeafe
Merge pull request #276 from TIHLDE/dev
Eirsteir Oct 6, 2021
bb94d6d
Merge pull request #281 from TIHLDE/dev
Eirsteir Oct 11, 2021
8d99ef8
Merge pull request #293 from TIHLDE/dev
olros Oct 21, 2021
b9bd653
Merge pull request #309 from TIHLDE/dev
Eirsteir Oct 29, 2021
6f9ea28
Registrations update hotfix (#313)
olros Nov 1, 2021
ce1b310
Develop (#335)
Eirsteir Nov 16, 2021
b262a84
Weekly update (#347)
olros Nov 16, 2021
279801e
Fix strikes (#350)
olros Nov 18, 2021
fdd0140
Merge pull request #360 from TIHLDE/dev
trthingnes Nov 30, 2021
e8f33b4
New year update 🎆 (#373)
olros Jan 1, 2022
aa3b270
Prod update (#381)
olros Jan 15, 2022
afc23df
Merge pull request #407 from TIHLDE/dev
trthingnes Jan 31, 2022
c66e44b
Merge pull request #418 from TIHLDE/dev
trthingnes Feb 3, 2022
fd071f9
fix(permissions): check if user exists (#421) (#422)
olros Feb 4, 2022
153bfc8
Production release (#427)
trthingnes Feb 6, 2022
3d65e72
Prod update (#443)
olros Feb 17, 2022
e853e1d
Fix event filter (#446)
olros Feb 18, 2022
43ffa72
Merge pull request #449 from TIHLDE/dev
CJGutz Feb 24, 2022
236c8a2
Fix forms permissions (#462)
olros Feb 28, 2022
8d19a57
fix(events): queryset filtering (#464) (#465)
olros Feb 28, 2022
e77ba28
Merge pull request #468 from TIHLDE/dev
olros Feb 28, 2022
960cdde
Merge pull request #471 from TIHLDE/dev
Eirsteir Mar 1, 2022
b572ac5
Merge pull request #474 from TIHLDE/dev
Eirsteir Mar 2, 2022
0d64f20
Merge pull request #484 from TIHLDE/dev
olros Mar 4, 2022
2eb6c21
Exceptions fix (#488)
olros Mar 5, 2022
7c8203b
Merge pull request #493 from TIHLDE/dev
olros Mar 8, 2022
653a305
feat(user): study and year migration to groups migration script (#482…
Eirsteir Mar 10, 2022
536b0c0
Merge pull request #498 from TIHLDE/dev
Eirsteir Mar 10, 2022
de7317b
Weekly update (#512)
olros Mar 13, 2022
342b202
Merge pull request #525 from TIHLDE/dev
Her0elt Mar 18, 2022
df4b674
Tuesday fix (#530)
olros Mar 22, 2022
bee436a
Weekly update (#534)
olros Mar 24, 2022
8743223
End of easter update 🐔 (#555)
olros Apr 21, 2022
ce60b28
Friday release (#562)
olros Apr 29, 2022
9b16856
Merge branch 'dev'
olros Apr 29, 2022
92813dd
Merge branch 'dev'
olros Apr 29, 2022
666d4d9
Tuesday update (#568)
olros May 3, 2022
b80b14d
Friday update 🍟 (#574)
olros May 6, 2022
6145723
Sunday update 🌞 (#578)
olros May 8, 2022
d4e1f7b
May update 🍹 (#584)
olros May 12, 2022
8817351
October update (#635)
trthingnes Oct 13, 2022
4087d1e
Merge remote-tracking branch 'refs/remotes/origin/dev'
thomsen85 Nov 17, 2022
6ab8032
Temp Jubileum Permissions (#681)
thomsen85 Mar 6, 2023
c6e1179
started on order viewset
MadsNyl Sep 6, 2023
2608db2
made viewset for Order, with listing, filtering and retrieving of a s…
MadsNyl Sep 6, 2023
52f7fca
Added Fondet to allowed and fixed typo (#691)
thomsen85 Sep 7, 2023
44759fa
removed celery task_always_eager local variable (#694)
MadsNyl Sep 11, 2023
dd212d3
Resolved merge conflict by incorporating both suggestions.
martcl Sep 11, 2023
03a3b5c
September Update 🎉 (#695)
martcl Sep 11, 2023
4389a41
fix: pliz 💀
martcl Sep 11, 2023
8d97827
chore: merge
martcl Sep 11, 2023
75ad5f6
chore: remove fucker file
martcl Sep 11, 2023
6a6df4f
Midnight release 🌃 (#700)
martcl Sep 15, 2023
3de0527
Vipps fix
thomsen85 Sep 18, 2023
f974530
added endpoint for user info on payment orders
MadsNyl Sep 18, 2023
8183319
fixed small bug
thomsen85 Sep 18, 2023
3699590
Merge remote-tracking branch 'origin/master' into dev
thomsen85 Sep 18, 2023
6b3e13b
lint
thomsen85 Sep 18, 2023
a48c1ca
fixed circular import error in order serializer
MadsNyl Sep 19, 2023
de0ec41
fix: added is_paid_event (#703)
martcl Sep 19, 2023
a1bea0d
altered orderlistserializer
MadsNyl Sep 19, 2023
e0ce5e8
added search bar for admin site for memberships (#704)
MadsNyl Sep 22, 2023
623076c
filtered out expired events for order listing
MadsNyl Sep 24, 2023
f19357a
started on order viewset
MadsNyl Sep 6, 2023
3133195
made viewset for Order, with listing, filtering and retrieving of a s…
MadsNyl Sep 6, 2023
2cab1cf
added endpoint for user info on payment orders
MadsNyl Sep 18, 2023
df00f37
fixed circular import error in order serializer
MadsNyl Sep 19, 2023
7ed7b77
altered orderlistserializer
MadsNyl Sep 19, 2023
3f7843c
filtered out expired events for order listing
MadsNyl Sep 24, 2023
c871470
changes
MadsNyl Sep 27, 2023
d901e93
made filter for user payements order for events
MadsNyl Sep 27, 2023
65be818
added id to event in eventorderlist serializer
MadsNyl Sep 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
---

## Neste versjon

- ✨ **Spørreskjemaer** NOK medlemmer kan lage spørreskjema.
- ⚡ **Bruker** Nå kan ikke HS lenger endre eller slette brukere.
- ⚡ **Bruker** Nå kan ikke HS lenger endre eller slette brukere.
- ⚡ **Mails** Nå logger vi på eposttjeneren kun en gang per batch med epost som sendes.
- 🦟 **Bøter** Nå skal bilder på bøter ikke lengre forsvinne.
- ✨ **Betalte arrangementer med Vipps betaling**. Det kan nå opprettes arrangementer som krever betaling for å melde seg på. Denne betalingen betales via Vipps.
- ⚡ **Nyheter** Fondesforvalere kan nå lage nyheter.

## Versjon 2022.10.13

Expand Down
3 changes: 2 additions & 1 deletion app/common/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ def admin(cls):

class Groups(ChoiceEnum):
TIHLDE = "TIHLDE"
REDAKSJONEN = "redaksjonen"
JUBKOM = "JubKom"
REDAKSJONEN = "Redaksjonen"
FONDET = "Forvaltningsgruppen"


class AppModel(ChoiceEnum):
Expand Down
4 changes: 2 additions & 2 deletions app/content/models/news.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf import settings
from django.db import models

from app.common.enums import AdminGroup
from app.common.enums import AdminGroup, Groups
from app.common.permissions import BasePermissionModel
from app.util.models import BaseModel, OptionalImage

Expand All @@ -18,7 +18,7 @@ class News(BaseModel, OptionalImage, BasePermissionModel):
)
body = models.TextField()

write_access = AdminGroup.all()
write_access = [*AdminGroup.all(), Groups.FONDET]

class Meta:
verbose_name_plural = "News"
Expand Down
1 change: 1 addition & 0 deletions app/content/serializers/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Meta:
"permissions",
"priority_pools",
"paid_information",
"is_paid_event",
"contact_person",
)

Expand Down
6 changes: 5 additions & 1 deletion app/content/views/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ def create(self, request, *args, **kwargs):
serializer, event=event, user=request.user
)

create_payment_order(event, request, registration)
try:
create_payment_order(event, request, registration)
except Exception as e:
registration.delete()
raise e

registration_serializer = RegistrationSerializer(
registration, context={"user": registration.user}
Expand Down
15 changes: 14 additions & 1 deletion app/content/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
MembershipHistorySerializer,
MembershipSerializer,
)
from app.payment.views import OrderListSerializer
from app.util.export_user_data import export_user_data
from app.util.utils import CaseInsensitiveBooleanQueryParam

from app.payment.util.order_utils import filter_user_event_orders

class UserViewSet(BaseViewSet, ActionMixin):
"""API endpoint to display one user"""
Expand Down Expand Up @@ -285,6 +286,18 @@ def get_user_events(self, request, *args, **kwargs):
data=events, serializer=EventListSerializer, context={"request": request}
)

@action(detail=False, methods=["get"], url_path="me/payment_orders")
def get_user_payment_orders(self, request, *args, **kwargs):
payment_orders = request.user.orders.all()

filtered_orders = filter_user_event_orders(payment_orders)

return self.paginate_response(
data=filtered_orders,
serializer=OrderListSerializer,
context={"request": request},
)

@action(detail=False, methods=["get"], url_path="me/forms")
def get_user_forms(self, request, *args, **kwargs):
forms = request.user.forms
Expand Down
5 changes: 5 additions & 0 deletions app/group/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class MembershipAdmin(admin.ModelAdmin):
"user",
)

search_fields = [
"user__first_name",
"user__last_name"
]


@admin.register(models.MembershipHistory)
class MembershipHistoryAdmin(admin.ModelAdmin):
Expand Down
2 changes: 2 additions & 0 deletions app/payment/factories/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from app.payment.factories.order_factory import OrderFactory
from app.payment.factories.paid_event_factory import PaidEventFactory
2 changes: 2 additions & 0 deletions app/payment/factories/order_factory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import random
import string
from datetime import timedelta

import factory
Expand All @@ -19,3 +20,4 @@ class Meta:
event = factory.SubFactory(EventFactory)
status = random.choice([e.value for e in OrderStatus])
expire_date = now() + timedelta(hours=1)
payment_link = "".join(random.choices(string.ascii_letters, k=36))
1 change: 1 addition & 0 deletions app/payment/filters/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from app.payment.filters.order import OrderFilter
26 changes: 26 additions & 0 deletions app/payment/filters/order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django.db.models import Exists, OuterRef
from django_filters import filters
from django_filters.rest_framework.filterset import FilterSet

from app.payment.models import Order, PaidEvent


class OrderFilter(FilterSet):
"""
Filters payment orders by user, paid events and status.
"""

user = filters.CharFilter(method="filter_user")
event = filters.NumberFilter(method="filter_paid_event")

class Meta:
model = Order
fields = ["user", "event", "status"]

def filter_user(self, queryset, name, value):
if value and self.request.user:
return queryset.filter(user__user_id=self.request.user.user_id)
return queryset

def filter_paid_event(self, queryset, name, value):
return queryset.filter(Exists(PaidEvent.objects.filter(event=value)))
10 changes: 5 additions & 5 deletions app/payment/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.0.8 on 2023-05-08 17:11
# Generated by Django 4.0.8 on 2023-09-11 19:01

from django.conf import settings
from django.db import migrations, models
Expand All @@ -11,8 +11,8 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('content', '0052_event_rules_and_photo_in_user'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('content', '0053_event_contact_person'),
]

operations = [
Expand All @@ -21,7 +21,7 @@ class Migration(migrations.Migration):
fields=[
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('event', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, primary_key=True, related_name='paid_information', serialize=False, to='content.event')),
('event', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, related_name='paid_information', serialize=False, to='content.event')),
('price', models.DecimalField(decimal_places=2, max_digits=6)),
('paytime', models.TimeField()),
],
Expand All @@ -38,8 +38,8 @@ class Migration(migrations.Migration):
('status', models.CharField(choices=[('INITIATE', 'Initiate'), ('RESERVE', 'Reserve'), ('CAPTURE', 'Capture'), ('REFUND', 'Refund'), ('CANCEL', 'Cancel'), ('SALE', 'Sale'), ('VOID', 'Void')], default='INITIATE', max_length=16)),
('expire_date', models.DateTimeField()),
('payment_link', models.URLField(max_length=2000)),
('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='orders', to='content.event')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='orders', to=settings.AUTH_USER_MODEL)),
('event', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='orders', to='content.event')),
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='orders', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name_plural': 'Orders',
Expand Down
20 changes: 0 additions & 20 deletions app/payment/migrations/0002_alter_paidevent_event.py

This file was deleted.

27 changes: 0 additions & 27 deletions app/payment/migrations/0003_alter_order_event_alter_order_user.py

This file was deleted.

4 changes: 2 additions & 2 deletions app/payment/models/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class Meta:
verbose_name_plural = "Orders"
ordering = ("-created_at",)

def __str__(self):
return f"{self.order_id} {self.user} {self.event} {self.status} {self.expire_date}"
def __str__(self):
return f"{self.user.first_name} {self.user.last_name} - {self.status} - {self.created_at}"

@property
def expired(self):
Expand Down
6 changes: 5 additions & 1 deletion app/payment/serializers/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
from .order import OrderSerializer
from app.payment.serializers.order import (
OrderSerializer,
OrderListSerializer,
OrderUpdateCreateSerializer,
)
14 changes: 14 additions & 0 deletions app/payment/serializers/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,17 @@ def create(self, validated_data):
return Order.objects.create(
user=user, expired_date=now() + paytime, **validated_data
)


class OrderEventListSerializer(BaseModelSerializer):
class Meta:
model = Event
fields = ("title", "id")


class OrderListSerializer(BaseModelSerializer):
event = OrderEventListSerializer(read_only=True)

class Meta:
model = Order
fields = ("order_id", "status", "payment_link", "user", "event")
41 changes: 41 additions & 0 deletions app/payment/util/order_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from app.payment.enums import OrderStatus


def filter_user_event_orders(orders):
"""
Filter user payment orders for events, so the user only get
displayed the paid order for an event. All refunds will be displayed.
"""

STATUS_PRIORITY = [
OrderStatus.SALE,
OrderStatus.RESERVE,
OrderStatus.CAPTURE,
OrderStatus.INITIATE,
OrderStatus.CANCEL
]

filtered_orders = {}
final_orders = []

for order in orders:
if (
not order.event or
order.event.expired
):
continue

if order.status == OrderStatus.REFUND:
final_orders.append(order)
continue

if (
order.event.id not in filtered_orders or
STATUS_PRIORITY.index(order.status) < STATUS_PRIORITY.index(filtered_orders[order.event.id].status)
):
filtered_orders[order.event.id] = order

filtered_orders = list(filtered_orders.values())
final_orders += filtered_orders

return final_orders
8 changes: 7 additions & 1 deletion app/payment/util/payment_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ def get_new_access_token():
"Merchant-Serial-Number": settings.VIPPS_MERCHANT_SERIAL_NUMBER,
}

response = requests.post(TOKEN_URL, headers=TOKEN_HEADERS).json()
response = requests.post(TOKEN_URL, headers=TOKEN_HEADERS)

if response.status_code != 200:
raise Exception("Could not get access token")

response = response.json()

return (response["expires_on"], response["access_token"])


Expand Down
1 change: 1 addition & 0 deletions app/payment/views/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from app.payment.views.order import Order, OrderListSerializer
Loading
Loading