def test_payment_date_should_return_payment_date_for_status_sent(self):
            # Given
            payment_date = datetime.utcnow()
            payment = Payment()
            payment_status = PaymentStatus()
            payment_status.status = TransactionStatus.SENT
            payment_status.date = payment_date
            payment.statuses = [payment_status]

            # When/Then
            payment_sent_date = payment.lastProcessedDate
            assert payment_sent_date == payment_date  # pylint: disable=comparison-with-callable
Example #2
0
        def test_payment_date_should_return_no_payment_date_for_status_pending(self):
            # Given
            payment_date = datetime.utcnow()
            payment = Payment()
            payment_status = PaymentStatus()
            payment_status.status = TransactionStatus.PENDING
            payment_status.date = payment_date
            payment.statuses = [payment_status]

            # When/Then
            payment_sent_date = payment.lastProcessedDate
            assert payment_sent_date is None
    def test_appends_a_status_to_a_new_payment(self):
        # given
        one_second = timedelta(seconds=1)
        now = datetime.utcnow()
        payment = Payment()

        # when
        payment.setStatus(TransactionStatus.PENDING)

        # then
        assert len(payment.statuses) == 1
        assert payment.statuses[0].status == TransactionStatus.PENDING
        assert payment.statuses[0].detail is None
        assert now - one_second < payment.statuses[0].date < now + one_second
Example #4
0
        def test_payment_date_should_return_oldest_payment_date_for_status_sent_if_several(self, app):
            # Given
            payment_date = datetime.utcnow()
            payment = Payment()
            payment_status = PaymentStatus()
            payment_status.status = TransactionStatus.SENT
            payment_status.date = payment_date
            payment.statuses = [payment_status]
            older_payment_date = datetime.utcnow() - timedelta(days=1)
            payment_status.status = TransactionStatus.SENT
            payment_status.date = older_payment_date
            payment.statuses = [payment_status]

            # When/Then
            payment_sent_date = payment.lastProcessedDate
            assert payment_sent_date == older_payment_date  # pylint: disable=comparison-with-callable
Example #5
0
    def test_it_returns_an_empty_list_if_everything_has_been_reimbursed(self):
        # Given
        booking_paid1 = Booking()
        booking_paid1.payments = [Payment()]
        booking_reimbursement1 = BookingReimbursement(
            booking_paid1, ReimbursementRules.PHYSICAL_OFFERS, Decimal(10))

        booking_paid2 = Booking()
        booking_paid2.payments = [Payment()]
        booking_reimbursement2 = BookingReimbursement(
            booking_paid2, ReimbursementRules.PHYSICAL_OFFERS, Decimal(10))

        # When
        bookings_not_paid = filter_out_already_paid_for_bookings(
            [booking_reimbursement1, booking_reimbursement2])

        # Then
        assert bookings_not_paid == []
    def test_appends_a_status_to_a_payment_with_existing_status(self):
        # given
        one_second = timedelta(seconds=1)
        now = datetime.utcnow()
        payment = Payment()
        payment_status = PaymentStatus()
        payment_status.status = TransactionStatus.PENDING
        payment_status.date = datetime.utcnow()
        payment.statuses = [payment_status]

        # when
        payment.setStatus(TransactionStatus.SENT)

        # then
        assert len(payment.statuses) == 2
        assert payment.statuses[1].status == TransactionStatus.SENT
        assert payment.statuses[1].detail is None
        assert now - one_second < payment.statuses[1].date < now + one_second
Example #7
0
    def test_it_returns_reimbursements_on_bookings_with_no_existing_payments(
            self):
        # Given
        booking_paid = Booking()
        booking_paid.payments = [Payment()]
        booking_reimbursement1 = BookingReimbursement(
            booking_paid, ReimbursementRules.PHYSICAL_OFFERS, Decimal(10))
        booking_not_paid = Booking()
        booking_reimbursement2 = BookingReimbursement(
            booking_not_paid, ReimbursementRules.PHYSICAL_OFFERS, Decimal(10))
        booking_reimbursements = [
            booking_reimbursement1, booking_reimbursement2
        ]

        # When
        bookings_not_paid = filter_out_already_paid_for_bookings(
            booking_reimbursements)

        # Then
        assert len(bookings_not_paid) == 1
        assert not bookings_not_paid[0].booking.payments
Example #8
0
def create_payment_for_booking(
        booking_reimbursement: BookingReimbursement) -> Payment:
    venue = booking_reimbursement.booking.stock.offer.venue

    payment = Payment()
    payment.booking = booking_reimbursement.booking
    payment.amount = booking_reimbursement.reimbursed_amount
    payment.reimbursementRule = booking_reimbursement.reimbursement.value.description
    payment.reimbursementRate = booking_reimbursement.reimbursement.value.rate
    payment.author = "batch"
    payment.transactionLabel = make_transaction_label(datetime.utcnow())

    if venue.iban:
        payment.iban = format_raw_iban_and_bic(venue.iban)
        payment.bic = format_raw_iban_and_bic(venue.bic)
    else:
        offerer = venue.managingOfferer
        payment.iban = format_raw_iban_and_bic(offerer.iban)
        payment.bic = format_raw_iban_and_bic(offerer.bic)

    payment.recipientName = venue.managingOfferer.name
    payment.recipientSiren = venue.managingOfferer.siren

    if payment.iban:
        payment.setStatus(TransactionStatus.PENDING)
    else:
        payment.setStatus(TransactionStatus.NOT_PROCESSABLE,
                          detail="IBAN et BIC manquants sur l'offreur")

    return payment
Example #9
0
def create_payment_for_booking(reimbursement: BookingReimbursement,
                               batch_date: datetime) -> Payment:
    venue = reimbursement.booking.venue
    offerer = reimbursement.booking.offerer

    payment = Payment()
    payment.bookingId = reimbursement.booking.id
    payment.amount = reimbursement.reimbursed_amount
    if isinstance(reimbursement.rule, payments_models.CustomReimbursementRule):
        payment.customReimbursementRuleId = reimbursement.rule.id
    else:
        payment.reimbursementRule = reimbursement.rule.description
    payment.reimbursementRate = reimbursement.rule.rate
    payment.author = "batch"
    payment.transactionLabel = make_transaction_label(datetime.utcnow())
    payment.batchDate = batch_date

    if venue.iban:
        payment.iban = format_raw_iban_and_bic(venue.iban)
        payment.bic = format_raw_iban_and_bic(venue.bic)
    else:
        payment.iban = format_raw_iban_and_bic(offerer.iban)
        payment.bic = format_raw_iban_and_bic(offerer.bic)

    payment.recipientName = offerer.name
    payment.recipientSiren = offerer.siren

    return payment