def test_should_return_payment_to_retry_if_bank_information_linked_to_venue_and_current_status_is_not_processable(
            self, app):
        # Given
        offerer = create_offerer()
        user = users_factories.UserFactory()
        venue = create_venue(offerer)
        stock = create_stock_from_offer(create_offer_with_thing_product(venue),
                                        price=0)
        booking = create_booking(user=user, stock=stock)
        not_processable_payment = create_payment(
            booking,
            offerer,
            10,
            status=TransactionStatus.NOT_PROCESSABLE,
            iban="CF13QSDFGH456789",
            bic="QSDFGH8Z555")
        bank_information = create_bank_information(venue=venue)
        repository.save(not_processable_payment, bank_information)

        # When
        payments_to_retry = payment_queries.find_not_processable_with_bank_information(
        )

        # Then
        assert not_processable_payment in payments_to_retry
    def test_should_not_return_payments_to_retry_if_no_bank_information(self, app):
        # Given
        product = offers_factories.ThingProductFactory(name="Lire un livre", isNational=True)
        venue = offers_factories.VenueFactory(postalCode="34000", departementCode="34")
        offer = offers_factories.ThingOfferFactory(product=product, venue=venue)
        stock = offers_factories.ThingStockFactory(offer=offer, price=0, quantity=2)
        booking = bookings_factories.UsedIndividualBookingFactory(stock=stock, quantity=2)
        payment = factories.PaymentFactory(booking=booking, amount=10)
        factories.PaymentStatusFactory(payment=payment, status=TransactionStatus.NOT_PROCESSABLE)

        # When
        payments_to_retry = payment_queries.find_not_processable_with_bank_information()

        # Then
        assert payments_to_retry == []
Пример #3
0
def set_not_processable_payments_with_bank_information_to_retry(
        batch_date: datetime) -> None:
    payments_to_retry = payment_queries.find_not_processable_with_bank_information(
    )
    for payment in payments_to_retry:
        booking = payment.booking
        if booking.venue.bic and booking.venue.iban:
            payment.bic = booking.venue.bic
            payment.iban = booking.venue.iban
        elif booking.offerer.bic and booking.offerer.iban:
            payment.bic = booking.offerer.bic
            payment.iban = booking.offerer.iban
        payment.batchDate = batch_date
        payment.transactionLabel = make_transaction_label(datetime.utcnow())
        payment.setStatus(TransactionStatus.RETRY)
    repository.save(*payments_to_retry)
Пример #4
0
def set_not_processable_payments_with_bank_information_to_retry() -> None:
    payments_to_retry = payment_queries.find_not_processable_with_bank_information(
    )
    for payment in payments_to_retry:
        payment_bank_information_is_on_venue = (
            payment.booking.stock.offer.venue.bic
            and payment.booking.stock.offer.venue.bic)
        payment_bank_information_is_on_offerer = (
            payment.booking.stock.offer.venue.managingOfferer.bic
            and payment.booking.stock.offer.venue.managingOfferer.bic)
        if payment_bank_information_is_on_venue:
            payment.bic = payment.booking.stock.offer.venue.bic
            payment.iban = payment.booking.stock.offer.venue.iban
        elif payment_bank_information_is_on_offerer:
            payment.bic = payment.booking.stock.offer.venue.managingOfferer.bic
            payment.iban = payment.booking.stock.offer.venue.managingOfferer.iban
        payment.setStatus(TransactionStatus.RETRY)
    repository.save(*payments_to_retry)
    def test_should_return_payment_to_retry_if_bank_information_linked_to_offerer_and_current_status_is_not_processable(
        self, app
    ):
        # Given
        user_offerer = offers_factories.UserOffererFactory()
        product = offers_factories.ThingProductFactory(name="Lire un livre", isNational=True)
        venue = offers_factories.VenueFactory(
            managingOfferer=user_offerer.offerer, postalCode="34000", departementCode="34"
        )
        offer = offers_factories.ThingOfferFactory(product=product, venue=venue)
        stock = offers_factories.ThingStockFactory(offer=offer, price=0)
        booking = bookings_factories.UsedIndividualBookingFactory(stock=stock)
        not_processable_payment = factories.PaymentFactory(booking=booking, amount=10)
        factories.PaymentStatusFactory(payment=not_processable_payment, status=TransactionStatus.NOT_PROCESSABLE)
        offers_factories.BankInformationFactory(offerer=user_offerer.offerer)

        # When
        payments_to_retry = payment_queries.find_not_processable_with_bank_information()

        # Then
        assert not_processable_payment in payments_to_retry
    def test_should_not_return_payment_to_retry_if_bank_information_status_is_not_accepted(self, app):
        # Given
        user_offerer = offers_factories.UserOffererFactory()
        product = offers_factories.ThingProductFactory(name="Lire un livre", isNational=True)
        venue = offers_factories.VenueFactory(
            managingOfferer=user_offerer.offerer, postalCode="34000", departementCode="34"
        )
        offer = offers_factories.ThingOfferFactory(product=product, venue=venue)
        stock = offers_factories.ThingStockFactory(offer=offer, price=0)
        booking = bookings_factories.UsedIndividualBookingFactory(stock=stock)
        not_processable_payment = factories.PaymentFactory(
            booking=booking, amount=10, iban="CF13QSDFGH456789", bic="QSDFGH8Z555"
        )
        factories.PaymentStatusFactory(payment=not_processable_payment, status=TransactionStatus.NOT_PROCESSABLE)
        offers_factories.BankInformationFactory(
            offerer=user_offerer.offerer, iban=None, bic=None, status=BankInformationStatus.DRAFT
        )

        # When
        payments_to_retry = payment_queries.find_not_processable_with_bank_information()

        # Then
        assert payments_to_retry == []