示例#1
0
def test_create_account_payments_for_one_failed_payment(session):
    """Assert that the create account payments is working."""
    inv_number_1 = 'REG00001'
    payment_account = factory_payment_account().save()
    invoice_1 = factory_invoice(payment_account)
    invoice_1.save()
    factory_invoice_reference(invoice_1.id, invoice_number=inv_number_1).save()
    payment_1 = factory_payment(payment_status_code='FAILED',
                                payment_account_id=payment_account.id,
                                invoice_number=inv_number_1,
                                payment_method_code=PaymentMethod.PAD.value)
    payment_1.save()

    auth_account_id = PaymentAccount.find_by_id(
        payment_account.id).auth_account_id

    results = Payment_service.search_account_payments(
        auth_account_id=auth_account_id, status='FAILED', limit=1, page=1)
    assert results.get('total') == 1

    new_payment = Payment_service.create_account_payment(
        auth_account_id=auth_account_id, is_retry_payment=True)
    old_payment = Payment_service.find_by_id(payment_1.id)
    # Assert new payment invoice number is same as old payment as there is only one failed payment.
    assert new_payment.invoice_number == old_payment.invoice_number
示例#2
0
def test_account_purchase_history_invalid_request(session, client, jwt, app):
    """Assert that the endpoint returns 400."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(get_payment_request()),
                     headers=headers)

    invoice: Invoice = Invoice.find_by_id(rv.json.get('id'))
    pay_account: PaymentAccount = PaymentAccount.find_by_id(
        invoice.payment_account_id)

    search_filter = {'businessIdentifier': 1111}

    rv = client.post(
        f'/api/v1/accounts/{pay_account.auth_account_id}/payments/queries?page=1&limit=5',
        data=json.dumps(search_filter),
        headers=headers)

    assert rv.status_code == 400
    assert schema_utils.validate(rv.json, 'problem')[0]
示例#3
0
def test_account_purchase_history_export_as_pdf(session, client, jwt, app):
    """Assert that the endpoint returns 200."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(get_payment_request()),
                     headers=headers)

    invoice: Invoice = Invoice.find_by_id(rv.json.get('id'))
    pay_account: PaymentAccount = PaymentAccount.find_by_id(
        invoice.payment_account_id)

    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json',
        'Accept': 'application/pdf'
    }

    rv = client.post(
        f'/api/v1/accounts/{pay_account.auth_account_id}/payments/reports',
        data=json.dumps({}),
        headers=headers)

    assert rv.status_code == 201
示例#4
0
def test_account_purchase_history_default_list(session, client, jwt, app):
    """Assert that the endpoint returns 200."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    # Create 11 payments
    for i in range(11):
        rv = client.post('/api/v1/payment-requests',
                         data=json.dumps(get_payment_request()),
                         headers=headers)

    invoice: Invoice = Invoice.find_by_id(rv.json.get('id'))
    pay_account: PaymentAccount = PaymentAccount.find_by_id(
        invoice.payment_account_id)

    rv = client.post(
        f'/api/v1/accounts/{pay_account.auth_account_id}/payments/queries',
        data=json.dumps({}),
        headers=headers)

    assert rv.status_code == 200
    # Assert the total is coming as 10 which is the value of default TRANSACTION_REPORT_DEFAULT_TOTAL
    assert rv.json.get('total') == 10
示例#5
0
def test_account_purchase_history_pagination(session, client, jwt, app):
    """Assert that the endpoint returns 200."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    for i in range(10):
        rv = client.post('/api/v1/payment-requests',
                         data=json.dumps(get_payment_request()),
                         headers=headers)

    invoice: Invoice = Invoice.find_by_id(rv.json.get('id'))
    pay_account: PaymentAccount = PaymentAccount.find_by_id(
        invoice.payment_account_id)

    rv = client.post(
        f'/api/v1/accounts/{pay_account.auth_account_id}/payments/queries?page=1&limit=5',
        data=json.dumps({}),
        headers=headers)

    assert rv.status_code == 200
    assert rv.json.get('total') == 10
    assert len(rv.json.get('items')) == 5
示例#6
0
def test_create_account_payments(session, client, jwt, app):
    """Assert that the endpoint returns 200."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    inv_number_1 = 'REG00001'
    payment_account = factory_payment_account().save()
    invoice_1 = factory_invoice(payment_account, total=100)
    invoice_1.save()
    factory_payment_line_item(invoice_id=invoice_1.id,
                              fee_schedule_id=1).save()
    factory_invoice_reference(invoice_1.id, invoice_number=inv_number_1).save()
    payment_1 = factory_payment(payment_status_code='FAILED',
                                payment_account_id=payment_account.id,
                                invoice_number=inv_number_1,
                                invoice_amount=100,
                                payment_method_code=PaymentMethod.PAD.value)
    payment_1.save()

    auth_account_id = PaymentAccount.find_by_id(
        payment_account.id).auth_account_id

    rv = client.post(
        f'/api/v1/accounts/{auth_account_id}/payments?retryFailedPayment=true',
        headers=headers)
    assert rv.status_code == 201
示例#7
0
def test_account_payments(session, client, jwt, app):
    """Assert that the endpoint returns 200."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    inv_number = 'REG00001'
    payment_account = factory_payment_account().save()

    invoice_1 = factory_invoice(payment_account)
    invoice_1.save()
    factory_invoice_reference(invoice_1.id, invoice_number=inv_number).save()

    payment_1 = factory_payment(payment_status_code='CREATED',
                                payment_account_id=payment_account.id,
                                invoice_number=inv_number)
    payment_1.save()

    auth_account_id = PaymentAccount.find_by_id(
        payment_account.id).auth_account_id

    rv = client.get(f'/api/v1/accounts/{auth_account_id}/payments',
                    headers=headers)
    assert rv.status_code == 200
    assert rv.json.get('total') == 1
    rv = client.get(
        f'/api/v1/accounts/{auth_account_id}/payments?status=FAILED',
        headers=headers)
    assert rv.status_code == 200
    assert rv.json.get('total') == 0
示例#8
0
def test_search_payment_history_with_tz(session):
    """Assert that the search payment history is working."""
    payment_account = factory_payment_account()
    payment_created_on = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
    payment_created_on = payment_created_on.astimezone(pytz.utc)
    payment = factory_payment(payment_status_code='CREATED', created_on=payment_created_on)
    payment_account.save()
    payment.save()
    invoice = factory_invoice(payment, payment_account)
    invoice.save()
    factory_invoice_reference(invoice.id).save()
    auth_account_id = PaymentAccount.find_by_id(payment_account.account_id).auth_account_id

    results = Payment_service.search_purchase_history(auth_account_id=auth_account_id,
                                                      search_filter={}, limit=1, page=1)
    assert results is not None
    assert results.get('items') is not None
    assert results.get('total') == 1

    # Add one more payment
    payment_created_on = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
    payment_created_on = payment_created_on.astimezone(pytz.utc)
    payment = factory_payment(payment_status_code='CREATED', created_on=payment_created_on)
    payment_account.save()
    payment.save()
    invoice = factory_invoice(payment, payment_account)
    invoice.save()
    factory_invoice_reference(invoice.id).save()

    results = Payment_service.search_purchase_history(auth_account_id=auth_account_id,
                                                      search_filter={}, limit=1, page=1)
    assert results is not None
    assert results.get('items') is not None
    assert results.get('total') == 2
    def update_statement_notification_details(
            auth_account_id: str, notification_details: Tuple[Dict[str, Any]]):
        """Update statements notification settings by account id.

        Update the payment Account.
        Update the recepients
        """
        payment_account: PaymentAccountModel = PaymentAccountModel.find_by_auth_account_id(
            auth_account_id)
        if payment_account is None:
            payment_account = PaymentAccountModel()
            payment_account.auth_account_id = auth_account_id
        payment_account.name = notification_details.get('accountName')
        payment_account.statement_notification_enabled = notification_details.get(
            'statementNotificationEnabled')
        payment_account.save()
        recepient_list: list = []

        # if no object is passed , dont update anything.Empty list passed means , delete everything
        if (recepients := notification_details.get('recipients')) is not None:
            StatementRecipientsModel.delete_all_recipients(payment_account.id)
            for rec in recepients or []:
                recipient = StatementRecipientsModel()
                recipient.auth_user_id = rec.get('authUserId')
                recipient.firstname = rec.get('firstname')
                recipient.lastname = rec.get('lastname')
                recipient.email = rec.get('email')
                recipient.payment_account_id = payment_account.id
                recepient_list.append(recipient)
            StatementRecipientsModel.bulk_save_recipients(recepient_list)
示例#10
0
def test_post_default_statement_settings_daily(session, client, jwt, app):
    """Assert that the post endpoint works."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(
                         get_payment_request(business_identifier='CP0002000')),
                     headers=headers)

    invoice: Invoice = Invoice.find_by_id(rv.json.get('id'))
    pay_account: PaymentAccount = PaymentAccount.find_by_id(
        invoice.payment_account_id)

    rv = client.get(
        f'/api/v1/accounts/{pay_account.auth_account_id}/statements/settings',
        data=json.dumps({}),
        headers=headers)
    assert rv.status_code == 200
    assert rv.json.get('currentFrequency').get(
        'frequency') == StatementFrequency.WEEKLY.value

    # Set the frequency to Daily and assert
    daily_frequency = {'frequency': 'DAILY'}
    rv = client.post(
        f'/api/v1/accounts/{pay_account.auth_account_id}/statements/settings',
        data=json.dumps(daily_frequency),
        headers=headers)
    assert rv.json.get('frequency') == StatementFrequency.DAILY.value
    end_date = get_week_start_and_end_date()[1]
    assert rv.json.get('fromDate') == (end_date +
                                       timedelta(days=1)).strftime('%Y-%m-%d')

    # Set the frequency to Monthly and assert
    daily_frequency = {'frequency': 'MONTHLY'}
    rv = client.post(
        f'/api/v1/accounts/{pay_account.auth_account_id}/statements/settings',
        data=json.dumps(daily_frequency),
        headers=headers)
    end_date = get_first_and_last_dates_of_month(current_local_time().month,
                                                 current_local_time().year)[1]
    assert rv.json.get('frequency') == StatementFrequency.MONTHLY.value
    assert rv.json.get('fromDate') == (end_date +
                                       timedelta(days=1)).strftime('%Y-%m-%d')

    # Get the latest frequency
    rv = client.get(
        f'/api/v1/accounts/{pay_account.auth_account_id}/statements/settings',
        data=json.dumps({}),
        headers=headers)
    assert rv.status_code == 200
    assert rv.json.get('currentFrequency').get(
        'frequency') == StatementFrequency.MONTHLY.value
示例#11
0
def test_create_payment_record(session):
    """Assert that the payment records are created."""
    payment_request = {
        'payment_info': {
            'method_of_payment': 'CC'
        },
        'business_info': {
            'business_identifier': 'CP1234',
            'corp_type': 'CP',
            'business_name': 'ABC Corp',
            'contact_info': {
                'city': 'Victoria',
                'postal_code': 'V8P2P2',
                'province': 'BC',
                'address_line_1': '100 Douglas Street',
                'country': 'CA'
            }
        },
        'filing_info': {
            'filing_types': [{
                'filing_type_code': 'OTADD',
                'filing_description': 'TEST'
            }, {
                'filing_type_code': 'OTANN'
            }]
        }
    }
    payment_response = PaymentService.create_payment(payment_request, 'test')
    account_model = PaymentAccountModel.find_by_corp_number_and_corp_type_and_system(
        'CP1234', 'CP', 'PAYBC')
    account_id = account_model.id
    assert account_id is not None
    assert payment_response.get('id') is not None
    # Create another payment with same request, the account should be the same
    PaymentService.create_payment(payment_request, 'test')
    account_model = PaymentAccountModel.find_by_corp_number_and_corp_type_and_system(
        'CP1234', 'CP', 'PAYBC')
    assert account_id == account_model.id
示例#12
0
def test_get_default_statement_settings_weekly(session, client, jwt, app):
    """Assert that the default statement setting is weekly."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {'Authorization': f'Bearer {token}', 'content-type': 'application/json'}
    rv = client.post('/api/v1/payment-requests', data=json.dumps(get_payment_request(business_identifier='CP0002000')),
                     headers=headers)

    payment: Payment = Payment.find_by_id(rv.json.get('id'))
    bcol_account: BcolPaymentAccount = BcolPaymentAccount.find_by_id(payment.invoices[0].bcol_account_id)
    pay_account: PaymentAccount = PaymentAccount.find_by_id(bcol_account.account_id)
    rv = client.get(f'/api/v1/accounts/{pay_account.auth_account_id}/statements/settings',
                    headers=headers)
    assert rv.status_code == 200
    assert rv.json.get('frequency') == StatementFrequency.WEEKLY.value
示例#13
0
def test_create_account_payments_for_multiple_failed_payments(session):
    """Assert that the create account payments is working."""
    inv_number_1 = 'REG00001'
    payment_account = factory_payment_account().save()
    invoice_1 = factory_invoice(payment_account, total=100)
    invoice_1.save()
    factory_payment_line_item(invoice_id=invoice_1.id,
                              fee_schedule_id=1).save()
    factory_invoice_reference(invoice_1.id, invoice_number=inv_number_1).save()
    payment_1 = factory_payment(payment_status_code='FAILED',
                                payment_account_id=payment_account.id,
                                invoice_number=inv_number_1,
                                invoice_amount=100,
                                payment_method_code=PaymentMethod.PAD.value)
    payment_1.save()

    # Create one more payment with failed status.
    inv_number_2 = 'REG00002'
    invoice_2 = factory_invoice(payment_account, total=100)
    invoice_2.save()
    factory_payment_line_item(invoice_id=invoice_2.id,
                              fee_schedule_id=1).save()
    factory_invoice_reference(invoice_2.id, invoice_number=inv_number_2).save()

    payment_2 = factory_payment(payment_status_code='FAILED',
                                payment_account_id=payment_account.id,
                                invoice_number=inv_number_2,
                                invoice_amount=100,
                                payment_method_code=PaymentMethod.PAD.value)
    payment_2.save()

    auth_account_id = PaymentAccount.find_by_id(
        payment_account.id).auth_account_id

    results = Payment_service.search_account_payments(
        auth_account_id=auth_account_id, status='FAILED', limit=10, page=1)
    assert results.get('total') == 2

    new_payment = Payment_service.create_account_payment(
        auth_account_id=auth_account_id, is_retry_payment=True)
    payment_1 = Payment_service.find_by_id(payment_1.id)
    payment_2 = Payment_service.find_by_id(payment_2.id)
    # Assert new payment invoice number is different from old payment as there are more than one failed payments.
    assert new_payment.invoice_number != payment_1.invoice_number
    assert new_payment.invoice_number != payment_2.invoice_number
    assert payment_1.cons_inv_number == new_payment.invoice_number
    assert payment_2.cons_inv_number == new_payment.invoice_number
    assert new_payment.invoice_amount == payment_1.invoice_amount + payment_2.invoice_amount
示例#14
0
def test_create_payment_report_pdf(session, rest_call_mock):
    """Assert that the create payment report is working."""
    payment_account = factory_payment_account()
    payment_account.save()
    auth_account_id = PaymentAccount.find_by_id(payment_account.account_id).auth_account_id

    for i in range(20):
        payment = factory_payment(payment_status_code='CREATED')
        payment.save()
        invoice = factory_invoice(payment, payment_account)
        invoice.save()
        factory_invoice_reference(invoice.id).save()

    Payment_service.create_payment_report(auth_account_id=auth_account_id, search_filter={},
                                          content_type='application/pdf', report_name='test')
    assert True  # If no error, then good
示例#15
0
    def find_statement_notification_details(auth_account_id: str):
        """Find statements by account id."""
        current_app.logger.debug(
            f'<find_statement_notification_details {auth_account_id}')
        recipients = StatementRecipientsModel.find_all_recipients(
            auth_account_id)
        payment_account: PaymentAccountModel = PaymentAccountModel.find_by_auth_account_id(
            auth_account_id)
        data = {
            'recipients':
            NotificationSchema().dump(recipients, many=True),
            'statement_notification_enabled':
            getattr(payment_account, 'statement_notification_enabled', False)
        }

        current_app.logger.debug('>find_statement_notification_details')
        return data
示例#16
0
def test_get_default_statement_settings_weekly(session, client, jwt, app):
    """Assert that the default statement setting is weekly."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }
    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(
                         get_payment_request(business_identifier='CP0002000')),
                     headers=headers)

    invoice: Invoice = Invoice.find_by_id(rv.json.get('id'))
    pay_account: PaymentAccount = PaymentAccount.find_by_id(
        invoice.payment_account_id)

    rv = client.get(
        f'/api/v1/accounts/{pay_account.auth_account_id}/statements/settings',
        headers=headers)
    assert rv.status_code == 200
    assert rv.json.get('currentFrequency').get(
        'frequency') == StatementFrequency.WEEKLY.value
    # Assert the array of the frequncies
    for freqeuncy in rv.json.get('frequencies'):
        if freqeuncy.get('frequency') == StatementFrequency.WEEKLY.value:
            actual_weekly = dateutil.parser.parse(
                freqeuncy.get('startDate')).date()
            expected_weekly = (get_week_start_and_end_date()[1] +
                               timedelta(days=1)).date()
            assert actual_weekly == expected_weekly, 'weekly matches'
        if freqeuncy.get('frequency') == StatementFrequency.MONTHLY.value:
            today = datetime.today()
            actual_monthly = dateutil.parser.parse(
                freqeuncy.get('startDate')).date()
            expected_monthly = (
                get_first_and_last_dates_of_month(today.month, today.year)[1] +
                timedelta(days=1)).date()
            assert actual_monthly == expected_monthly, 'monthly matches'
        if freqeuncy.get('frequency') == StatementFrequency.DAILY.value:
            actual_daily = dateutil.parser.parse(
                freqeuncy.get('startDate')).date()
            # since current frequncy is weekly , daily changes will happen at the end of the week
            expected_weekly = (get_week_start_and_end_date()[1] +
                               timedelta(days=1)).date()
            assert actual_daily == expected_weekly, 'daily matches'
示例#17
0
def test_search_payment_history_for_all(session):
    """Assert that the search payment history is working."""
    payment_account = factory_payment_account()
    payment_account.save()
    auth_account_id = PaymentAccount.find_by_id(payment_account.account_id).auth_account_id

    for i in range(20):
        payment = factory_payment(payment_status_code='CREATED')
        payment.save()
        invoice = factory_invoice(payment, payment_account)
        invoice.save()
        factory_invoice_reference(invoice.id).save()

    results = Payment_service.search_all_purchase_history(auth_account_id=auth_account_id, search_filter={})
    assert results is not None
    assert results.get('items') is not None
    # Returns only the default number if payload is empty
    assert results.get('total') == 10
示例#18
0
def test_create_account_payments_after_consolidation(session):
    """Assert creating account payments after consolidation yields same payment record."""
    inv_number_1 = 'REG00001'
    payment_account = factory_payment_account().save()
    invoice_1 = factory_invoice(payment_account, total=100)
    invoice_1.save()
    factory_payment_line_item(invoice_id=invoice_1.id,
                              fee_schedule_id=1).save()
    factory_invoice_reference(invoice_1.id, invoice_number=inv_number_1).save()
    payment_1 = factory_payment(payment_status_code='FAILED',
                                payment_account_id=payment_account.id,
                                invoice_number=inv_number_1,
                                invoice_amount=100,
                                payment_method_code=PaymentMethod.PAD.value)
    payment_1.save()

    # Create one more payment with failed status.
    inv_number_2 = 'REG00002'
    invoice_2 = factory_invoice(payment_account, total=100)
    invoice_2.save()
    factory_payment_line_item(invoice_id=invoice_2.id,
                              fee_schedule_id=1).save()
    factory_invoice_reference(invoice_2.id, invoice_number=inv_number_2).save()
    payment_2 = factory_payment(payment_status_code='FAILED',
                                payment_account_id=payment_account.id,
                                invoice_number=inv_number_2,
                                invoice_amount=100,
                                payment_method_code=PaymentMethod.PAD.value)
    payment_2.save()

    auth_account_id = PaymentAccount.find_by_id(
        payment_account.id).auth_account_id

    results = Payment_service.search_account_payments(
        auth_account_id=auth_account_id, status='FAILED', limit=10, page=1)
    assert results.get('total') == 2

    new_payment_1 = Payment_service.create_account_payment(
        auth_account_id=auth_account_id, is_retry_payment=True)
    # Create account payment again and assert both payments returns same.
    new_payment_2 = Payment_service.create_account_payment(
        auth_account_id=auth_account_id, is_retry_payment=True)

    assert new_payment_1.id == new_payment_2.id
示例#19
0
    def update_statement_settings(auth_account_id: str, frequency: str):
        """Update statements by account id.

        rather than checking frequency changes by individual if , it just applies the following logic.
        find the maximum frequency of current one and new one ;and calculate the date which it will keep on going.

        """
        statements_settings_schema = StatementSettingsModelSchema()
        today = datetime.today()
        current_statements_settings = StatementSettingsModel.find_active_settings(
            auth_account_id, today)
        payment_account: PaymentAccountModel = PaymentAccountModel.find_by_auth_account_id(
            auth_account_id)
        if current_statements_settings is None:
            # no frequency yet.first time accessing the statement settings.so create a new record
            statements_settings = StatementSettingsModel(
                frequency=frequency, payment_account_id=payment_account.id)
            statements_settings.save()
            return statements_settings_schema.dump(statements_settings)

        # check if the latest one is the active one.. if not , inactivate the latest one.
        # this handles the case of quickly changing of frequencies..
        # changed from daily to monthly but then changed back to weekly..
        # the monthly didn't get applied ,but even before that its being changed to weekly
        future_statements_settings = StatementSettingsModel.find_latest_settings(
            auth_account_id)
        if future_statements_settings is not None and current_statements_settings.id != future_statements_settings.id:
            future_statements_settings.to_date = today
            future_statements_settings.save()

        max_frequency = StatementSettings._find_longest_frequency(
            current_statements_settings.frequency, frequency)
        last_date = StatementSettings._get_end_of(max_frequency)
        current_statements_settings.to_date = last_date
        current_statements_settings.save()

        new_statements_settings = StatementSettingsModel(
            frequency=frequency,
            payment_account_id=payment_account.id,
            from_date=last_date + timedelta(days=1))

        new_statements_settings.save()
        return statements_settings_schema.dump(new_statements_settings)
示例#20
0
def test_account_purchase_history_with_service_account(session, client, jwt,
                                                       app):
    """Assert that purchase history returns only invoices for that product."""
    # Create one invoice for CSO and one fpr BUSINESS.
    # Then query without any filter and make sure only CSO invoice is returned for service account with CSO product_code
    for corp_filing_type in (['CSO', 'CSBVFEE'], ['PPR', 'FSDIS']):
        token = jwt.create_jwt(
            get_claims(roles=[Role.SYSTEM.value],
                       product_code=corp_filing_type[0]), token_header)
        headers = {
            'Authorization': f'Bearer {token}',
            'content-type': 'application/json'
        }
        rv = client.post('/api/v1/payment-requests',
                         data=json.dumps(
                             get_payment_request_with_service_fees(
                                 corp_type=corp_filing_type[0],
                                 filing_type=corp_filing_type[1])),
                         headers=headers)

    invoice: Invoice = Invoice.find_by_id(rv.json.get('id'))
    pay_account: PaymentAccount = PaymentAccount.find_by_id(
        invoice.payment_account_id)

    token = jwt.create_jwt(
        get_claims(roles=[Role.SYSTEM.value], product_code='CSO'),
        token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }
    rv = client.post(
        f'/api/v1/accounts/{pay_account.auth_account_id}/payments/queries?page=1&limit=5',
        data=json.dumps({}),
        headers=headers)

    assert rv.status_code == 200
    assert rv.json.get('total') == 1
    assert len(rv.json.get('items')) == 1
    assert rv.json.get('items')[0]['corpTypeCode'] == 'CSO'
示例#21
0
def test_search_account_payments(session):
    """Assert that the search account payments is working."""
    inv_number = 'REG00001'
    payment_account = factory_payment_account().save()

    invoice_1 = factory_invoice(payment_account)
    invoice_1.save()
    factory_invoice_reference(invoice_1.id, invoice_number=inv_number).save()

    payment_1 = factory_payment(payment_status_code='CREATED',
                                payment_account_id=payment_account.id,
                                invoice_number=inv_number,
                                payment_method_code=PaymentMethod.PAD.value)
    payment_1.save()

    auth_account_id = PaymentAccount.find_by_id(
        payment_account.id).auth_account_id

    results = Payment_service.search_account_payments(
        auth_account_id=auth_account_id, status=None, limit=1, page=1)
    assert results is not None
    assert results.get('items') is not None
    assert results.get('total') == 1
示例#22
0
def test_account_purchase_history(session, client, jwt, app):
    """Assert that the endpoint returns 200."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(get_payment_request()),
                     headers=headers)

    payment: Payment = Payment.find_by_id(rv.json.get('id'))
    credit_account: CreditPaymentAccount = CreditPaymentAccount.find_by_id(
        payment.invoices[0].credit_account_id)
    pay_account: PaymentAccount = PaymentAccount.find_by_id(
        credit_account.account_id)

    rv = client.post(
        f'/api/v1/accounts/{pay_account.auth_account_id}/payments/queries',
        data=json.dumps({}),
        headers=headers)

    assert rv.status_code == 200
示例#23
0
def test_failed_payment_after_consolidation(session):
    """Assert creating account payments after consolidation works."""
    # Create 2 failed payments, consolidate it, and then again create another failed payment.
    # Consolidate it and make sure amount matches.
    inv_number_1 = 'REG00001'
    payment_account = factory_payment_account().save()
    invoice_1 = factory_invoice(payment_account, total=100)
    invoice_1.save()
    factory_payment_line_item(invoice_id=invoice_1.id,
                              fee_schedule_id=1).save()
    factory_invoice_reference(invoice_1.id, invoice_number=inv_number_1).save()
    payment_1 = factory_payment(payment_status_code='FAILED',
                                payment_account_id=payment_account.id,
                                invoice_number=inv_number_1,
                                invoice_amount=100,
                                payment_method_code=PaymentMethod.PAD.value)
    payment_1.save()

    # Create one more payment with failed status.
    inv_number_2 = 'REG00002'
    invoice_2 = factory_invoice(payment_account, total=100)
    invoice_2.save()
    factory_payment_line_item(invoice_id=invoice_2.id,
                              fee_schedule_id=1).save()
    factory_invoice_reference(invoice_2.id, invoice_number=inv_number_2).save()
    payment_2 = factory_payment(payment_status_code='FAILED',
                                payment_account_id=payment_account.id,
                                invoice_number=inv_number_2,
                                invoice_amount=100,
                                payment_method_code=PaymentMethod.PAD.value)
    payment_2.save()

    auth_account_id = PaymentAccount.find_by_id(
        payment_account.id).auth_account_id

    results = Payment_service.search_account_payments(
        auth_account_id=auth_account_id, status='FAILED', limit=10, page=1)
    assert results.get('total') == 2

    new_payment_1 = Payment_service.create_account_payment(
        auth_account_id=auth_account_id, is_retry_payment=True)

    # Create another failed payment.
    inv_number_3 = 'REG00003'
    invoice_3 = factory_invoice(payment_account, total=100)
    invoice_3.save()
    factory_payment_line_item(invoice_id=invoice_3.id,
                              fee_schedule_id=1).save()
    factory_invoice_reference(invoice_3.id, invoice_number=inv_number_3).save()
    payment_3 = factory_payment(payment_status_code='FAILED',
                                payment_account_id=payment_account.id,
                                invoice_number=inv_number_3,
                                invoice_amount=100,
                                payment_method_code=PaymentMethod.PAD.value)
    payment_3.save()

    new_payment_2 = Payment_service.create_account_payment(
        auth_account_id=auth_account_id, is_retry_payment=True)
    assert new_payment_1.id != new_payment_2.id
    assert new_payment_2.invoice_amount == payment_1.invoice_amount + payment_2.invoice_amount + \
           payment_3.invoice_amount
示例#24
0
def test_search_payment_history(session):
    """Assert that the search payment history is working."""
    payment_account = factory_payment_account()
    payment = factory_payment(payment_status_code='CREATED')
    payment_account.save()
    payment.save()
    invoice = factory_invoice(payment, payment_account)
    invoice.save()
    factory_invoice_reference(invoice.id).save()
    auth_account_id = PaymentAccount.find_by_id(
        payment_account.account_id).auth_account_id

    results = Payment_service.search_purchase_history(
        auth_account_id=auth_account_id, search_filter={}, limit=1, page=1)
    assert results is not None
    assert results.get('items') is not None
    assert results.get('total') == 1

    # Add one more payment
    payment = factory_payment(payment_status_code='CREATED')
    payment_account.save()
    payment.save()
    invoice = factory_invoice(payment, payment_account)
    invoice.save()
    factory_invoice_reference(invoice.id).save()

    results = Payment_service.search_purchase_history(
        auth_account_id=auth_account_id, search_filter={}, limit=1, page=1)
    assert results is not None
    assert results.get('items') is not None
    assert results.get('total') == 2

    # Search by different filter
    search_filter = {'status': 'CREATED'}
    results = Payment_service.search_purchase_history(
        auth_account_id=auth_account_id,
        search_filter=search_filter,
        limit=1,
        page=1)
    assert results is not None
    assert results.get('items') is not None
    assert results.get('total') == 2

    # Search by different filter
    search_filter = {'status': 'COMPLETED'}
    results = Payment_service.search_purchase_history(
        auth_account_id=auth_account_id,
        search_filter=search_filter,
        limit=1,
        page=1)
    assert results is not None
    assert results.get('items') is not None
    assert results.get('total') == 0

    # Search by different filter
    search_filter = {'folioNumber': '1234567890'}
    results = Payment_service.search_purchase_history(
        auth_account_id=auth_account_id,
        search_filter=search_filter,
        limit=1,
        page=1)
    assert results is not None
    assert results.get('items') is not None
    assert results.get('total') == 2

    # Search by different filter
    search_filter = {'businessIdentifier': invoice.business_identifier}
    results = Payment_service.search_purchase_history(
        auth_account_id=auth_account_id,
        search_filter=search_filter,
        limit=1,
        page=1)
    assert results is not None
    assert results.get('items') is not None
    assert results.get('total') == 2

    # Search by different filter
    search_filter = {
        'dateFilter': {
            'createdFrom': datetime.now().strftime('%m/%d/%Y'),
            'createdTo': datetime.now().strftime('%m/%d/%Y')
        }
    }
    results = Payment_service.search_purchase_history(
        auth_account_id=auth_account_id,
        search_filter=search_filter,
        limit=1,
        page=1)
    assert results is not None
    assert results.get('items') is not None
    assert results.get('total') == 2

    # Search by different filter
    search_filter = {'weekFilter': {'index': 2}}
    results = Payment_service.search_purchase_history(
        auth_account_id=auth_account_id,
        search_filter=search_filter,
        limit=1,
        page=1)
    assert results is not None
    assert results.get('items') is not None
    assert results.get('total') == 0

    # Search by different filter
    search_filter = {
        'monthFilter': {
            'month': datetime.now().month,
            'year': datetime.now().year
        }
    }
    results = Payment_service.search_purchase_history(
        auth_account_id=auth_account_id,
        search_filter=search_filter,
        limit=1,
        page=1)
    assert results is not None
    assert results.get('items') is not None
    assert results.get('total') == 2

    # Search by different filter
    search_filter = {'createdBy': payment.created_name}
    results = Payment_service.search_purchase_history(
        auth_account_id=auth_account_id,
        search_filter=search_filter,
        limit=1,
        page=1)
    assert results is not None
    assert results.get('items') is not None
    assert results.get('total') == 2