def test_records_new_payment_lines_in_database(self, app):
            # Given
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer = create_offer_with_thing_product(venue)
            paying_stock = create_stock_from_offer(offer)
            free_stock = create_stock_from_offer(offer, price=0)
            user = create_user()
            deposit = create_deposit(user, amount=500)
            booking1 = create_booking(user, paying_stock, venue, is_used=True)
            booking2 = create_booking(user, paying_stock, venue, is_used=True)
            booking3 = create_booking(user, paying_stock, venue, is_used=True)
            booking4 = create_booking(user, free_stock, venue, is_used=True)
            payment1 = create_payment(booking2,
                                      offerer,
                                      10,
                                      payment_message_name="ABCD123")

            PcObject.save(payment1)
            PcObject.save(deposit, booking1, booking3, booking4)

            initial_payment_count = Payment.query.count()

            # When
            generate_new_payments()

            # Then
            assert Payment.query.count() - initial_payment_count == 2
    def test_generate_payment_details_csv_with_right_values(self, app):
        # given
        deactivate_feature(FeatureToggle.DEGRESSIVE_REIMBURSEMENT_RATE)
        user = create_user(email='*****@*****.**')
        deposit = create_deposit(user, amount=500, source='public')
        offerer1 = create_offerer()
        user_offerer1 = create_user_offerer(user, offerer1, validation_token=None)
        venue1 = create_venue(offerer1)
        bank_information1 = create_bank_information(id_at_providers='79387501900056', venue=venue1)
        stock1 = create_stock_with_thing_offer(offerer=offerer1, venue=venue1, price=10)
        booking1 = create_booking(user, stock1, venue=venue1, token='ABCDEF', is_used=True)
        booking2 = create_booking(user, stock1, venue=venue1, token='ABCDEG')

        PcObject.save(deposit, booking1, booking2, user_offerer1, bank_information1)

        generate_new_payments()

        reimbursement_details = find_all_offerer_reimbursement_details(offerer1.id)

        # when
        csv = generate_reimbursement_details_csv(reimbursement_details)

        # then
        assert _count_non_empty_lines(csv) == 2
        assert _get_header(csv,
                           1) == "2019;Juillet : remboursement 1ère quinzaine;La petite librairie;12345678912345;123 rue de Paris;FR7630006000011234567890189;La petite librairie;Test Book;Doe;John;ABCDEF;;10.00;Remboursement initié"
def create_industrial_payments():
    logger.info('create_industrial_payments')

    pending_payments, not_processable_payments = generate_new_payments()

    logger.info('created {} payments'.format(
        len(pending_payments + not_processable_payments)
    ))
Esempio n. 4
0
    def test_find_all_offerer_reimbursement_details(self, app):
        # Given
        user = create_user(email='*****@*****.**')
        deposit = create_deposit(user, amount=500, source='public')
        offerer1 = create_offerer()
        user_offerer1 = create_user_offerer(user,
                                            offerer1,
                                            validation_token=None)
        venue1 = create_venue(offerer1)
        venue2 = create_venue(offerer1, siret='12345678912346')
        bank_information1 = create_bank_information(
            id_at_providers='79387501900056', venue=venue1)
        bank_information2 = create_bank_information(
            id_at_providers='79387501900057', venue=venue2)

        offer1 = create_offer_with_thing_product(
            venue1,
            url='https://host/path/{token}?offerId={offerId}&email={email}')
        offer2 = create_offer_with_thing_product(venue2)
        stock1 = create_stock_with_thing_offer(offerer=offerer1,
                                               venue=venue1,
                                               price=10)
        stock2 = create_stock_with_thing_offer(offerer=offerer1,
                                               venue=venue2,
                                               price=11)
        booking1 = create_booking(user,
                                  stock1,
                                  venue=venue1,
                                  token='ABCDEF',
                                  is_used=True)
        booking2 = create_booking(user, stock1, venue=venue1, token='ABCDEG')
        booking3 = create_booking(user,
                                  stock2,
                                  venue=venue2,
                                  token='ABCDEH',
                                  is_used=True)
        PcObject.save(deposit, booking1, booking2, booking3, user_offerer1,
                      bank_information1, bank_information2)
        generate_new_payments()

        # When
        reimbursement_details = find_all_offerer_reimbursement_details(
            offerer1.id)

        # Then
        assert len(reimbursement_details) == 2
        def when_user_has_an_offerer_attached(self, app):
            # Given
            user = create_user(email='*****@*****.**')
            deposit = create_deposit(user, amount=500, source='public')
            offerer1 = create_offerer()
            offerer2 = create_offerer(siren='123456788')
            user_offerer1 = create_user_offerer(user, offerer1, validation_token=None)
            user_offerer2 = create_user_offerer(user, offerer2, validation_token=None)
            venue1 = create_venue(offerer1)
            venue2 = create_venue(offerer1, siret='12345678912346')
            venue3 = create_venue(offerer2, siret='12345678912347')
            bank_information1 = create_bank_information(id_at_providers='79387501900056', venue=venue1)
            bank_information2 = create_bank_information(id_at_providers='79387501900057', venue=venue2)
            stock1 = create_stock_with_thing_offer(offerer=offerer1, venue=venue1, price=10)
            stock2 = create_stock_with_thing_offer(offerer=offerer1, venue=venue2, price=11)
            stock3 = create_stock_with_thing_offer(offerer=offerer2, venue=venue3, price=12)
            stock4 = create_stock_with_thing_offer(offerer=offerer2, venue=venue3, price=13)
            booking1 = create_booking(user, stock1, venue=venue1, token='ABCDEF', is_used=True)
            booking2 = create_booking(user, stock1, venue=venue1, token='ABCDEG')
            booking3 = create_booking(user, stock2, venue=venue2, token='ABCDEH', is_used=True)
            booking4 = create_booking(user, stock3, venue=venue3, token='ABCDEI', is_used=True)
            booking5 = create_booking(user, stock4, venue=venue3, token='ABCDEJ', is_used=True)
            booking6 = create_booking(user, stock4, venue=venue3, token='ABCDEK', is_used=True)
            PcObject.save(deposit, booking1, booking2, booking3,
                          booking4, booking5, booking6, user_offerer1,
                          user_offerer2, bank_information1, bank_information2)
            generate_new_payments()

            # When
            response = TestClient(app.test_client()).with_auth(user.email).get(
                '/reimbursements/csv')
            response_lines = response.data.decode('utf-8').split('\n')

            # Then
            assert response.status_code == 200
            assert response.headers['Content-type'] == 'text/csv; charset=utf-8;'
            assert response.headers['Content-Disposition'] == 'attachment; filename=remboursements_pass_culture.csv'
            assert len(response_lines) == 7
        def test_reimburses_95_percent_for_book_product_when_bookings_exceed_100000_euros(
                self, app):
            # Given
            offerer1 = create_offerer(siren='123456789')
            PcObject.save(offerer1)
            bank_information = create_bank_information(
                bic='BDFEFR2LCCB',
                iban='FR7630006000011234567890189',
                id_at_providers='123456789',
                offerer=offerer1)
            venue1 = create_venue(offerer1, siret='12345678912345')
            venue2 = create_venue(offerer1, siret='98765432154321')
            venue3 = create_venue(offerer1, siret='98123432154321')
            offer1 = create_offer_with_thing_product(
                venue1, thing_type=ThingType.LIVRE_EDITION, url=None)
            offer2 = create_offer_with_thing_product(
                venue2, thing_type=ThingType.LIVRE_EDITION, url=None)
            offer3 = create_offer_with_thing_product(
                venue3, thing_type=ThingType.LIVRE_EDITION, url=None)
            paying_stock1 = create_stock_from_offer(offer1, price=10000)
            paying_stock2 = create_stock_from_offer(offer2, price=10000)
            paying_stock3 = create_stock_from_offer(offer3, price=100000)
            user = create_user()
            deposit = create_deposit(user, amount=120000)
            booking1 = create_booking(user,
                                      paying_stock1,
                                      venue1,
                                      quantity=1,
                                      is_used=True)
            booking2 = create_booking(user,
                                      paying_stock2,
                                      venue2,
                                      quantity=1,
                                      is_used=True)
            booking3 = create_booking(user,
                                      paying_stock3,
                                      venue3,
                                      quantity=1,
                                      is_used=True)
            PcObject.save(deposit, booking1, booking2, booking3,
                          bank_information)

            # When
            pending, not_processable = generate_new_payments()

            # Then
            assert len(pending) == 3
            assert len(not_processable) == 0
            assert sum(p.amount for p in pending) == 115000
        def test_should_not_reimburse_offerer_if_he_has_more_than_20000_euros_in_bookings_on_several_venues(
                self, app):
            # Given
            deactivate_feature(FeatureToggle.DEGRESSIVE_REIMBURSEMENT_RATE)
            offerer1 = create_offerer(siren='123456789')
            PcObject.save(offerer1)
            bank_information = create_bank_information(
                bic='BDFEFR2LCCB',
                iban='FR7630006000011234567890189',
                id_at_providers='123456789',
                offerer=offerer1)
            venue1 = create_venue(offerer1, siret='12345678912345')
            venue2 = create_venue(offerer1, siret='98765432154321')
            venue3 = create_venue(offerer1, siret='98123432154321')
            offer1 = create_offer_with_thing_product(venue1)
            offer2 = create_offer_with_thing_product(venue2)
            offer3 = create_offer_with_thing_product(venue3)
            paying_stock1 = create_stock_from_offer(offer1, price=10000)
            paying_stock2 = create_stock_from_offer(offer2, price=10000)
            paying_stock3 = create_stock_from_offer(offer3, price=10000)
            user = create_user()
            deposit = create_deposit(user, amount=50000)
            booking1 = create_booking(user,
                                      paying_stock1,
                                      venue1,
                                      quantity=1,
                                      is_used=True)
            booking2 = create_booking(user,
                                      paying_stock2,
                                      venue2,
                                      quantity=1,
                                      is_used=True)
            booking3 = create_booking(user,
                                      paying_stock3,
                                      venue3,
                                      quantity=1,
                                      is_used=True)
            PcObject.save(deposit, booking1, booking2, booking3,
                          bank_information)

            # When
            pending, not_processable = generate_new_payments()

            # Then
            assert len(pending) == 2
            assert len(not_processable) == 0
            assert sum(p.amount for p in pending) == 20000
Esempio n. 8
0
def generate_or_collect_payments(
        payment_message_id: str = None) -> Tuple[List[Payment], List[Payment]]:
    if payment_message_id is None:
        logger.info('[BATCH][PAYMENTS] STEP 1 : generate payments')
        pending_payments, not_processable_payments = generate_new_payments()

        logger.info(
            '[BATCH][PAYMENTS] STEP 2 : collect payments in ERROR and RETRY statuses'
        )
        payments_to_send = concatenate_payments_with_errors_and_retries(
            pending_payments)
    else:
        logger.info(
            '[BATCH][PAYMENTS] STEP 1 Bis : collect payments corresponding to payment_message_id'
        )
        not_processable_payments = []
        payments_to_send = get_payments_by_message_id(payment_message_id)
    return not_processable_payments, payments_to_send
        def test_returns_a_tuple_of_pending_and_not_processable_payments(
                self, app):
            # Given
            deactivate_feature(FeatureToggle.DEGRESSIVE_REIMBURSEMENT_RATE)
            offerer1 = create_offerer(siren='123456789')
            offerer2 = create_offerer(siren='987654321')
            PcObject.save(offerer1)
            bank_information = create_bank_information(
                bic='BDFEFR2LCCB',
                iban='FR7630006000011234567890189',
                id_at_providers='123456789',
                offerer=offerer1)
            venue1 = create_venue(offerer1, siret='12345678912345')
            venue2 = create_venue(offerer2, siret='98765432154321')
            offer1 = create_offer_with_thing_product(venue1)
            offer2 = create_offer_with_thing_product(venue2)
            paying_stock1 = create_stock_from_offer(offer1)
            paying_stock2 = create_stock_from_offer(offer2)
            free_stock1 = create_stock_from_offer(offer1, price=0)
            user = create_user()
            deposit = create_deposit(user, amount=500)
            booking1 = create_booking(user,
                                      paying_stock1,
                                      venue1,
                                      is_used=True)
            booking2 = create_booking(user,
                                      paying_stock1,
                                      venue1,
                                      is_used=True)
            booking3 = create_booking(user,
                                      paying_stock2,
                                      venue2,
                                      is_used=True)
            booking4 = create_booking(user, free_stock1, venue1, is_used=True)
            PcObject.save(deposit, booking1, booking2, booking3, booking4,
                          bank_information)

            # When
            pending, not_processable = generate_new_payments()

            # Then
            assert len(pending) == 2
            assert len(not_processable) == 1