-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixed flake8 (#672) * Added Event permissions to Jubkom temporarily (#680) * Feat(event)/contact person (#685) * altered Event model: contact_person with foregin key to an user added. Updated Event serializer and wrote a test for creating event with contact person * small changes in event serializer * formating * feat(payments): create payment system (#675) * Created model, started views * fixed merge * fixed merge * started on paid event factory and model test * added model tests and integration test for creating paid event * added field to Event serializer * Related Manager Error When testing * Paid Event Done, Order started on * Formatted * change * Order Done * removed print * added .env * debugging registration tests * added possibilty for adding a paid event without a price, test finished * Fixed test * started on update test of paid event * created update test for paid event * started on adding celery task for removing unpaid orders * A good days work * finished test_not_paid_order_is_kicked_of_event_after_timeout * added unit test for order task * started on vipps callback * made test for checking if vipps callback updates order status * started on test for forcing vipps payment * must change check of is_paid_event * fixed check for paid event in registration * fixed deletion of events such that the paid event also gets deleted, and made a test for it * bugfixes * changed event endpoint for deleting event. Now orders also get deleted * started on viewset for orders, and made test for retrieving order for an user at a given event * need to fix bug with payment tokens * fixed bug with expire date for orders * fixed new order bug * must fix config for celery always_eager * fixed elways eager * fixed update of order after payment * checks if user already has a paid order * fixed updating from paid event to not paid event and vice versa * fixed failing tests, and put all vipps urls and config variables in env so they are easy to change for production * removed secret keys etc... * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md * removed conf update from celery.app * fixed paid_information property in event model * fixed .local file * fixed .local file * updated order model for cascade * formated * fixed flake8 errors * added migration * Fixed migrations * fixed migrations * fixed order factory * refactored code for PR * refactored code * altered order model to allow an order not to get deleted when a related event or user is deleted * small changes from PR * empty commit --------- Co-authored-by: Lea Raknes <[email protected]> Co-authored-by: Mads Nylund <[email protected]> Co-authored-by: Mads Nylund <[email protected]> * Added Fondet to allowed and fixed typo (#691) * removed celery task_always_eager local variable (#694) * September Update 🎉 (#695) * Fixed flake8 (#672) * Added Event permissions to Jubkom temporarily (#680) * Feat(event)/contact person (#685) * altered Event model: contact_person with foregin key to an user added. Updated Event serializer and wrote a test for creating event with contact person * small changes in event serializer * formating * feat(payments): create payment system (#675) * Created model, started views * fixed merge * fixed merge * started on paid event factory and model test * added model tests and integration test for creating paid event * added field to Event serializer * Related Manager Error When testing * Paid Event Done, Order started on * Formatted * change * Order Done * removed print * added .env * debugging registration tests * added possibilty for adding a paid event without a price, test finished * Fixed test * started on update test of paid event * created update test for paid event * started on adding celery task for removing unpaid orders * A good days work * finished test_not_paid_order_is_kicked_of_event_after_timeout * added unit test for order task * started on vipps callback * made test for checking if vipps callback updates order status * started on test for forcing vipps payment * must change check of is_paid_event * fixed check for paid event in registration * fixed deletion of events such that the paid event also gets deleted, and made a test for it * bugfixes * changed event endpoint for deleting event. Now orders also get deleted * started on viewset for orders, and made test for retrieving order for an user at a given event * need to fix bug with payment tokens * fixed bug with expire date for orders * fixed new order bug * must fix config for celery always_eager * fixed elways eager * fixed update of order after payment * checks if user already has a paid order * fixed updating from paid event to not paid event and vice versa * fixed failing tests, and put all vipps urls and config variables in env so they are easy to change for production * removed secret keys etc... * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md * removed conf update from celery.app * fixed paid_information property in event model * fixed .local file * fixed .local file * updated order model for cascade * formated * fixed flake8 errors * added migration * Fixed migrations * fixed migrations * fixed order factory * refactored code for PR * refactored code * altered order model to allow an order not to get deleted when a related event or user is deleted * small changes from PR * empty commit --------- Co-authored-by: Lea Raknes <[email protected]> Co-authored-by: Mads Nylund <[email protected]> Co-authored-by: Mads Nylund <[email protected]> * Added Fondet to allowed and fixed typo (#691) * removed celery task_always_eager local variable (#694) --------- Co-authored-by: Thomas Svendal <[email protected]> Co-authored-by: Mads Nylund <[email protected]> Co-authored-by: Lea Raknes <[email protected]> Co-authored-by: Mads Nylund <[email protected]> * fix: pliz 💀 * chore: remove fucker file --------- Co-authored-by: Thomas Svendal <[email protected]> Co-authored-by: Mads Nylund <[email protected]> Co-authored-by: Lea Raknes <[email protected]> Co-authored-by: Mads Nylund <[email protected]>
- Loading branch information
1 parent
6ab8032
commit 6a6df4f
Showing
51 changed files
with
975 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,7 @@ | |
result_serializer="json", | ||
timezone=settings.TIME_ZONE, | ||
enable_utc=True, | ||
task_always_eager=False, | ||
) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Generated by Django 4.0.8 on 2023-09-01 06:29 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('content', '0052_event_rules_and_photo_in_user'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='event', | ||
name='contact_person', | ||
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='contact_events', to=settings.AUTH_USER_MODEL), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import os | ||
import uuid | ||
from datetime import datetime, timedelta | ||
|
||
from app.payment.enums import OrderStatus | ||
from app.payment.models.order import Order | ||
from app.payment.tasks import check_if_has_paid | ||
from app.payment.util.payment_utils import ( | ||
get_new_access_token, | ||
initiate_payment, | ||
) | ||
|
||
|
||
def create_payment_order(event, request, registration): | ||
""" | ||
Checks if event is a paid event | ||
and creates a new Vipps payment order. | ||
""" | ||
|
||
if event.is_paid_event: | ||
access_token = os.environ.get("PAYMENT_ACCESS_TOKEN") | ||
expires_at = os.environ.get("PAYMENT_ACCESS_TOKEN_EXPIRES_AT") | ||
if not access_token or datetime.now() >= datetime.fromtimestamp( | ||
int(expires_at) | ||
): | ||
(expires_at, access_token) = get_new_access_token() | ||
os.environ.update({"PAYMENT_ACCESS_TOKEN": access_token}) | ||
os.environ.update({"PAYMENT_ACCESS_TOKEN_EXPIRES_AT": str(expires_at)}) | ||
|
||
prev_orders = Order.objects.filter(event=event, user=request.user) | ||
has_paid_order = False | ||
|
||
for order in prev_orders: | ||
if ( | ||
order.status == OrderStatus.CAPTURE | ||
or order.status == OrderStatus.RESERVE | ||
or order.status == OrderStatus.SALE | ||
): | ||
has_paid_order = True | ||
break | ||
|
||
if not has_paid_order: | ||
|
||
paytime = event.paid_information.paytime | ||
|
||
expire_date = datetime.now() + timedelta( | ||
hours=paytime.hour, minutes=paytime.minute, seconds=paytime.second | ||
) | ||
|
||
# Create Order | ||
order_id = uuid.uuid4() | ||
amount = int(event.paid_information.price * 100) | ||
res = initiate_payment(amount, str(order_id), event.title, access_token) | ||
payment_link = res["url"] | ||
order = Order.objects.create( | ||
order_id=order_id, | ||
user=request.user, | ||
event=event, | ||
payment_link=payment_link, | ||
expire_date=expire_date, | ||
) | ||
order.save() | ||
check_if_has_paid.apply_async( | ||
args=(order.order_id, registration.registration_id), | ||
countdown=(paytime.hour * 60 + paytime.minute) * 60 + paytime.second, | ||
) |
Oops, something went wrong.