Skip to content
Merged
Changes from all commits
Commits
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
22 changes: 12 additions & 10 deletions library/serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.db import transaction
from django.utils import timezone
from rest_framework import serializers
from library.models import Borrowing, Book
Expand Down Expand Up @@ -42,17 +43,18 @@ def validate_expected_return_date(self, value):
def create(self, validated_data):
user = validated_data.pop("user")

borrowing = Borrowing.objects.create(user=user, **validated_data)
with transaction.atomic():
borrowing = Borrowing.objects.create(user=user, **validated_data)

session = create_payment_session(borrowing)
session = create_payment_session(borrowing)

Payment.objects.create(
borrowing=borrowing,
session_id=session.id,
session_url=session.url,
money=session.total_price,
status=Payment.Status.PENDING,
type=Payment.Type.PAYMENT,
)
Payment.objects.create(
borrowing=borrowing,
session_id=session.id,
session_url=session.url,
money=session.total_price,
status=Payment.Status.PENDING,
type=Payment.Type.PAYMENT,
)

return borrowing