コード例 #1
0
def check_is_usable(booking: Booking) -> None:
    booking_payment = payment_queries.find_by_booking_id(booking.id)
    if booking_payment is not None:
        forbidden = api_errors.ForbiddenError()
        forbidden.add_error("payment", "Cette réservation a été remboursée")
        raise forbidden

    if booking.isUsed:
        gone = api_errors.ResourceGoneError()
        gone.add_error("booking", "Cette réservation a déjà été validée")
        raise gone

    if booking.isCancelled:
        forbidden = api_errors.ForbiddenError()
        forbidden.add_error("booking", "Cette réservation a été annulée")
        raise forbidden

    is_booking_for_event_and_not_confirmed = booking.stock.beginningDatetime and not booking.isConfirmed
    if is_booking_for_event_and_not_confirmed:
        forbidden = api_errors.ForbiddenError()
        booking_date = datetime.datetime.strftime(booking.dateCreated,
                                                  "%d/%m/%Y à %H:%M")
        max_cancellation_date = datetime.datetime.strftime(
            api.compute_confirmation_date(booking.stock.beginningDatetime,
                                          booking.dateCreated),
            "%d/%m/%Y à %H:%M")

        forbidden.add_error(
            "booking",
            f"Cette réservation a été effectuée le {booking_date}. "
            f"Veuillez attendre jusqu’au {max_cancellation_date} pour valider la contremarque.",
        )
        raise forbidden
コード例 #2
0
    def test_should_return_a_payment_when_one_linked_to_booking(self, app):
        # Given
        beneficiary = users_factories.UserFactory()
        offerer = create_offerer()
        booking = create_booking(user=beneficiary)
        valid_payment = create_payment(booking=booking, offerer=offerer)
        repository.save(valid_payment)

        # When
        payment = payment_queries.find_by_booking_id(booking_id=booking.id)

        # Then
        assert payment == valid_payment
コード例 #3
0
    def test_should_return_nothing_when_no_payment_linked_to_booking(
            self, app):
        # Given
        invalid_booking_id = "99999"
        beneficiary = create_user()
        create_deposit(beneficiary)
        offerer = create_offerer()
        booking = create_booking(user=beneficiary)
        valid_payment = create_payment(booking=booking, offerer=offerer)
        repository.save(valid_payment)

        # When
        payment = payment_queries.find_by_booking_id(
            booking_id=invalid_booking_id)

        # Then
        assert payment is None
コード例 #4
0
def canceling_token_validation(token: str) -> None:
    booking = booking_repository.find_used_by_token(token)

    if booking:
        payment = payment_queries.find_by_booking_id(booking_id=booking.id)

        if payment is None:
            booking.isUsed = False
            booking.dateUsed = None
            repository.save(booking)

            print(f"The token ({token}) is cancelled")
        else:
            print(
                f"We did not cancelled the booking whose token is {token} because it has been already paid"
            )
    else:
        print(f"The token ({token}) is invalid")
コード例 #5
0
def check_can_be_mark_as_unused(booking: Booking) -> None:
    if not booking.isUsed:
        gone = api_errors.ResourceGoneError()
        gone.add_error("booking",
                       "Cette réservation n'a pas encore été validée")
        raise gone

    if booking.isCancelled:
        forbidden = api_errors.ForbiddenError()
        forbidden.add_error("booking", "Cette réservation a été annulée")
        raise forbidden

    booking_payment = payment_queries.find_by_booking_id(booking.id)
    if booking_payment is not None:
        gone = api_errors.ResourceGoneError()
        gone.add_error("payment",
                       "Le remboursement est en cours de traitement")
        raise gone