def test_patch_transaction_for_nsf_payment(session, monkeypatch): """Assert that the payment is saved to the table.""" # Create a FAILED payment (NSF), then clone the payment to create another one for CC payment # Create a transaction and assert it's success. # Patch transaction and check the status of records inv_number_1 = 'REG00001' payment_account = factory_payment_account( cfs_account_status=CfsAccountStatus.FREEZE.value, payment_method_code='PAD').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 payment for NSF payment. payment_2 = factory_payment(payment_status_code='CREATED', payment_account_id=payment_account.id, invoice_number=inv_number_1, invoice_amount=100, payment_method_code=PaymentMethod.CC.value) payment_2.save() def get_receipt(cls, payment_account, pay_response_url: str, invoice_reference): # pylint: disable=unused-argument; mocks of library methods return '1234567890', datetime.now(), 100.00 monkeypatch.setattr( 'pay_api.services.paybc_service.PaybcService.get_receipt', get_receipt) txn = PaymentTransactionService.create_transaction_for_payment( payment_2.id, get_paybc_transaction_request()) txn = PaymentTransactionService.update_transaction( txn.id, pay_response_url='receipt_number=123451') assert txn.status_code == 'COMPLETED' payment_2 = Payment.find_by_id(payment_2.id) assert payment_2.payment_status_code == 'COMPLETED' invoice_1: Invoice = Invoice.find_by_id(invoice_1.id) assert invoice_1.invoice_status_code == 'PAID' cfs_account = CfsAccount.find_effective_by_account_id(payment_account.id) assert cfs_account.status == 'ACTIVE'
def test_invoice_saved_from_new(session): """Assert that the invoice reference is saved to the table.""" payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.save() i = factory_invoice(payment=payment, payment_account=payment_account) i.save() invoice_reference = InvoiceReference.create(i.id, 'TEST_INV_NUMBER', 'TEST_REF_NUMBER') assert invoice_reference is not None assert invoice_reference.id is not None assert invoice_reference.invoice_id == i.id assert invoice_reference.status_code == InvoiceReferenceStatus.ACTIVE.value
def test_create_invoice(session): """Test create_invoice.""" pay_account = factory_payment_account(payment_system_code='BCOL', account_number='BCOL_ACC_1', user_id='test') pay_account.save() payment = factory_payment() payment.save() i = factory_invoice(payment_id=payment.id, account_id=pay_account.id) i.save() fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN') line = factory_payment_line_item(i.id, fee_schedule_id=fee_schedule.fee_schedule_id) line.save() # payment_account: PaymentAccount, line_items: [PaymentLineItem], invoice_id: str, **kwargs inv = bcol_service.create_invoice(pay_account, [line], i.id, filing_info={'folioNumber': '1234567890'}) assert inv is not None assert inv.get('invoice_number') == 'TEST'
def test_invoice_find_by_id(session): """Assert a invoice is stored. Start with a blank database. """ payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.save() invoice = factory_invoice(payment=payment, payment_account=payment_account) invoice.save() assert invoice.find_by_id(invoice.id) is not None schema = InvoiceSchema() d = schema.dump(invoice) assert d.get('id') == invoice.id
def test_get_receipt(session): """Test cancel_invoice.""" pay_account = factory_payment_account(payment_system_code='BCOL', account_number='BCOL_ACC_1', user_id='test') pay_account.save() payment = factory_payment() payment.save() i = factory_invoice(payment_id=payment.id, account_id=pay_account.id) i.save() fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN') line = factory_payment_line_item(i.id, fee_schedule_id=fee_schedule.fee_schedule_id) line.save() inv_ref = factory_invoice_reference(i.id).save() receipt = bcol_service.get_receipt(pay_account, None, inv_ref) assert receipt is not None
def test_payment_saved_from_new(session): """Assert that the payment is saved to the table.""" payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.save() invoice = factory_invoice(payment_account) invoice.save() factory_invoice_reference(invoice.id).save() p = Payment_service.find_by_id(payment.id) assert p is not None assert p.id is not None assert p.payment_system_code is not None assert p.payment_method_code is not None assert p.payment_status_code is not None
def test_no_existing_transaction(session): """Assert that the payment is saved to the table.""" payment_account = factory_payment_account() payment_account.save() invoice = factory_invoice(payment_account) invoice.save() factory_invoice_reference(invoice.id).save() fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN') line = factory_payment_line_item( invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id) line.save() transaction = PaymentTransactionService.find_active_by_invoice_id( invoice.id) assert transaction is None
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
def test_get_payment_system_url(session, public_user_mock): """Assert that the url returned is correct.""" today = current_local_time().strftime(PAYBC_DATE_FORMAT) payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.save() invoice = factory_invoice(payment_account) invoice.save() invoice_ref = factory_invoice_reference(invoice.id).save() fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN') distribution_code = DistributionCodeModel.find_by_active_for_fee_schedule(fee_schedule.fee_schedule_id) distribution_code_svc = DistributionCode() distribution_code_payload = get_distribution_code_payload() # update the existing gl code with new values distribution_code_svc.save_or_update(distribution_code_payload, distribution_code.distribution_code_id) line = factory_payment_line_item(invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id) line.save() direct_pay_service = DirectPayService() payment_response_url = direct_pay_service.get_payment_system_url_for_invoice(invoice, invoice_ref, 'google.com') url_param_dict = dict(urllib.parse.parse_qsl(urllib.parse.urlsplit(payment_response_url).query)) assert url_param_dict['trnDate'] == today assert url_param_dict['glDate'] == today assert url_param_dict['description'] == 'Direct_Sale' assert url_param_dict['pbcRefNumber'] == current_app.config.get('PAYBC_DIRECT_PAY_REF_NUMBER') assert url_param_dict['trnNumber'] == generate_transaction_number(invoice.id) assert url_param_dict['trnAmount'] == str(invoice.total) assert url_param_dict['paymentMethod'] == 'CC' assert url_param_dict['redirectUri'] == 'google.com' revenue_str = f"1:{distribution_code_payload['client']}." \ f"{distribution_code_payload['responsibilityCentre']}." \ f"{distribution_code_payload['serviceLine']}." \ f"{distribution_code_payload['stob']}." \ f"{distribution_code_payload['projectCode']}." \ f'000000.0000:10.00' assert url_param_dict['revenue'] == revenue_str urlstring = f"trnDate={today}&pbcRefNumber={current_app.config.get('PAYBC_DIRECT_PAY_REF_NUMBER')}&" \ f'glDate={today}&description=Direct_Sale&' \ f'trnNumber={generate_transaction_number(invoice.id)}&' \ f'trnAmount={invoice.total}&' \ f'paymentMethod=CC&' \ f'redirectUri=google.com&' \ f'currency=CAD&' \ f'revenue={revenue_str}' expected_hash_str = HashingService.encode(urlstring) assert expected_hash_str == url_param_dict['hashValue']
def test_update_distribution(session, public_user_mock, stan_server, monkeypatch): """Assert that the invoice status is updated when the distribution is updated.""" # 1. Create a distribution code # 2. Attach a fee schedule to the distribution # 3. Create and complete payment # 4. Update the distribution and assert the invoice status is changed. distribution_code_svc = services.DistributionCode() fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN') # Create a direct pay current_app.config['DIRECT_PAY_ENABLED'] = True payment_account = factory_payment_account(payment_method_code=PaymentMethod.DIRECT_PAY.value) payment_account.save() invoice = factory_invoice(payment_account, total=30) invoice.save() invoice_reference = factory_invoice_reference(invoice.id).save() line = factory_payment_line_item(invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id) line.save() factory_payment(invoice_number=invoice_reference.invoice_number, payment_method_code=PaymentMethod.DIRECT_PAY.value, invoice_amount=30).save() distribution_id = line.fee_distribution_id distribution_code = distribution_code_svc.find_by_id(distribution_id) transaction = PaymentTransactionService.create_transaction_for_invoice(invoice.id, get_paybc_transaction_request()) def get_receipt(cls, payment_account, pay_response_url: str, invoice_reference): # pylint: disable=unused-argument; mocks of library methods return '1234567890', datetime.now(), 30.00 monkeypatch.setattr('pay_api.services.direct_pay_service.DirectPayService.get_receipt', get_receipt) # Update transaction without response url, which should update the receipt PaymentTransactionService.update_transaction(transaction.id, pay_response_url=None) invoice = InvoiceModel.find_by_id(invoice.id) assert invoice.invoice_status_code == InvoiceStatus.PAID.value # Update distribution code distribution_code['client'] = '000' distribution_code_svc.save_or_update(distribution_code, distribution_id) invoice = InvoiceModel.find_by_id(invoice.id) assert invoice.invoice_status_code == InvoiceStatus.UPDATE_REVENUE_ACCOUNT.value
def test_transaction_create_from_invalid_payment(session): """Assert that the payment is saved to the table.""" payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.save() invoice = factory_invoice(payment, payment_account) invoice.save() factory_invoice_reference(invoice.id).save() fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN') line = factory_payment_line_item( invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id) line.save() with pytest.raises(BusinessException) as excinfo: PaymentTransactionService.create(999, get_paybc_transaction_request()) assert excinfo.value.code == Error.INVALID_PAYMENT_ID.name
def test_invoice_find_by_id(session): """Assert that the invoice is saved to the table.""" payment_account = factory_payment_account() payment_account.save() i = factory_invoice(payment_account=payment_account) i.save() invoice = Invoice_service.find_by_id(i.id, skip_auth_check=True) assert invoice is not None assert invoice.id is not None assert invoice.invoice_status_code is not None assert invoice.refund is None assert invoice.payment_date is None assert invoice.total is not None assert invoice.paid is None assert not invoice.payment_line_items
def test_update_payment_record(session, public_user_mock): """Assert that the payment records are updated.""" payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.save() invoice = factory_invoice(payment, payment_account) invoice.save() factory_invoice_reference(invoice.id).save() fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN') line = factory_payment_line_item(invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id) line.save() transaction = factory_payment_transaction(payment.id) transaction.save() payment_response = PaymentService.update_payment(payment.id, get_payment_request(), get_auth_basic_user()) assert payment_response.get('id') is not None
def test_statement_settings_find_by_account(session): """Assert that the statement settings by id works.""" bcol_account = factory_premium_payment_account() bcol_account.save() payment = factory_payment() payment.save() i = factory_invoice(payment_account=bcol_account) i.save() factory_invoice_reference(i.id).save() factory_statement_settings(payment_account_id=bcol_account.id, frequency=StatementFrequency.DAILY.value) payment_account = PaymentAccount.find_by_id(bcol_account.id) statement_settings = StatementSettingsService.find_by_account_id(payment_account.auth_account_id) assert statement_settings is not None assert statement_settings.get('current_frequency').get('frequency') == StatementFrequency.DAILY.value
def test_active_reference_by_invoice_id(session): """Assert that the invoice reference lookup is working.""" payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.save() i = factory_invoice(payment=payment, payment_account=payment_account) i.save() InvoiceReference.create(i.id, 'TEST_INV_NUMBER', 'TEST_REF_NUMBER') # Do a look up invoice_reference = InvoiceReference.find_active_reference_by_invoice_id(i.id) assert invoice_reference is not None assert invoice_reference.id is not None assert invoice_reference.invoice_id == i.id
def test_transaction_update_on_paybc_connection_error(session, stan_server): """Assert that the payment is saved to the table.""" payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.save() invoice = factory_invoice(payment, payment_account) invoice.save() factory_invoice_reference(invoice.id).save() fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN') line = factory_payment_line_item( invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id) line.save() transaction = PaymentTransactionService.create( payment.id, get_paybc_transaction_request()) from unittest.mock import patch from requests.exceptions import ConnectTimeout, ConnectionError # Mock here that the invoice update fails here to test the rollback scenario with patch('pay_api.services.oauth_service.requests.post', side_effect=ConnectionError('mocked error')): transaction = PaymentTransactionService.update_transaction( payment.id, transaction.id, pay_response_url='receipt_number=123451') assert transaction.pay_system_reason_code == 'SERVICE_UNAVAILABLE' with patch('pay_api.services.oauth_service.requests.post', side_effect=ConnectTimeout('mocked error')): transaction = PaymentTransactionService.update_transaction( payment.id, transaction.id, pay_response_url='receipt_number=123451') assert transaction.pay_system_reason_code == 'SERVICE_UNAVAILABLE' assert transaction is not None assert transaction.id is not None assert transaction.status_code is not None assert transaction.payment_id is not None assert transaction.client_system_url is not None assert transaction.pay_system_url is not None assert transaction.transaction_start_time is not None assert transaction.transaction_end_time is not None assert transaction.status_code == TransactionStatus.FAILED.value
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
def test_receipt(session): """Assert a receipt is stored. Start with a blank database. """ payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.save() invoice = factory_invoice(payment_account=payment_account) invoice = invoice.save() receipt = Receipt() receipt.receipt_amount = 100 receipt.receipt_date = datetime.now() receipt.invoice_id = invoice.id receipt.receipt_number = '123451' receipt = receipt.save() assert receipt.id is not None
def test_find_older_records(session): """Assert a payment_transaction is stored. Start with a blank database. """ payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.save() invoice = factory_invoice(payment_account=payment_account) invoice.save() payment_transaction_now = factory_payment_transaction(payment_id=payment.id) payment_transaction_now.save() payment_transaction_100_days_old = factory_payment_transaction( payment_id=payment.id, transaction_start_time=datetime.now() - timedelta(days=100)) payment_transaction_100_days_old.save() payment_transaction_3_hours_old = factory_payment_transaction( payment_id=payment.id, transaction_start_time=datetime.now() - timedelta( hours=3)) payment_transaction_3_hours_old.save() payment_transaction_1_hour_old = factory_payment_transaction( payment_id=payment.id, transaction_start_time=datetime.now() - timedelta( hours=1)) payment_transaction_1_hour_old.save() payment_transaction_2_hours_old = factory_payment_transaction( payment_id=payment.id, transaction_start_time=datetime.now() - timedelta( hours=2)) payment_transaction_2_hours_old.save() all_records = payment_transaction_now.find_stale_records(hours=2, minutes=10) # find records which are 2.10 hours older assert len(all_records) == 2 for record in all_records: assert record.transaction_start_time < datetime.now() - timedelta(hours=2)
def test_transaction_post_for_nsf_payment(session, client, jwt, app): """Assert that the endpoint returns 201.""" 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 payment for NSF payment. payment_2 = factory_payment(payment_status_code='CREATED', payment_account_id=payment_account.id, invoice_number=inv_number_1, invoice_amount=100, payment_method_code=PaymentMethod.CC.value) payment_2.save() token = jwt.create_jwt(get_claims(), token_header) headers = { 'Authorization': f'Bearer {token}', 'content-type': 'application/json' } data = { 'clientSystemUrl': 'http://localhost:8080/coops-web/transactions/transaction_id=abcd', 'payReturnUrl': 'http://localhost:8080/pay-web' } rv = client.post(f'/api/v1/payments/{payment_2.id}/transactions', data=json.dumps(data), headers=headers) assert rv.status_code == 201 assert rv.json.get('paymentId') == payment_2.id assert schema_utils.validate(rv.json, 'transaction')[0]
def test_find_completed_reference_by_invoice_id(session): """Assert that the completed invoice reference lookup is working.""" payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.save() i = factory_invoice(payment=payment, payment_account=payment_account) i.save() invoice_reference = InvoiceReference.create(i.id, 'TEST_INV_NUMBER', 'TEST_REF_NUMBER') invoice_reference.status_code = InvoiceReferenceStatus.COMPLETED.value invoice_reference.save() # Do a look up invoice_reference = InvoiceReference.find_completed_reference_by_invoice_id(i.id) assert invoice_reference is not None assert invoice_reference.id is not None assert invoice_reference.invoice_id == i.id
def test_update_statement_monthly(session): """Assert that the statement settings by id works.""" bcol_account = factory_premium_payment_account() bcol_account.save() payment = factory_payment() payment.save() i = factory_invoice(payment_account=bcol_account) i.save() factory_invoice_reference(i.id).save() factory_statement_settings(payment_account_id=bcol_account.id, frequency=StatementFrequency.MONTHLY.value) # update to weekly payment_account = PaymentAccount.find_by_id(bcol_account.id) statement_settings = StatementSettingsService.update_statement_settings( payment_account.auth_account_id, StatementFrequency.WEEKLY.value) assert statement_settings is not None assert statement_settings.get( 'frequency') == StatementFrequency.WEEKLY.value assert statement_settings.get('to_date') is None # monthly to weekly - assert weekly should start by next week first day end_of_month_date = get_first_and_last_dates_of_month( datetime.today().month, datetime.today().year)[1] assert statement_settings.get('from_date') == ( end_of_month_date + timedelta(days=1)).strftime(DT_SHORT_FORMAT) # monthly to weekly - assert current active one is stil monthly ending end of the week current_statement_settings = StatementSettingsModel.find_active_settings( payment_account.auth_account_id, datetime.today()) assert current_statement_settings is not None assert current_statement_settings.frequency == StatementFrequency.MONTHLY.value assert current_statement_settings.to_date == end_of_month_date.date() # travel to next week and see whats active with freeze_time(end_of_month_date + timedelta(days=2)): next_week_statement_settings = StatementSettingsModel.find_active_settings( payment_account.auth_account_id, datetime.today()) assert next_week_statement_settings is not None assert next_week_statement_settings.frequency == StatementFrequency.WEEKLY.value assert next_week_statement_settings.to_date is None
def test_delete_completed_payment(session, auth_mock): """Assert that the payment records are soft deleted.""" payment_account = factory_payment_account() payment = factory_payment(payment_status_code=PaymentStatus.COMPLETED.value) payment_account.save() payment.save() invoice = factory_invoice(payment, payment_account) invoice.save() factory_invoice_reference(invoice.id).save() fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN') line = factory_payment_line_item(invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id) line.save() transaction = factory_payment_transaction(payment.id) transaction.save() with pytest.raises(Exception) as excinfo: PaymentService.delete_payment(payment.id) assert excinfo.type == BusinessException
def test_transaction_create_new_on_completed_payment(session): """Assert that the payment is saved to the table.""" payment_account = factory_payment_account() payment_account.save() invoice = factory_invoice(payment_account) invoice.save() invoice_reference = factory_invoice_reference(invoice.id).save() fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN') line = factory_payment_line_item( invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id) line.save() factory_payment(invoice_number=invoice_reference.invoice_number, payment_status_code=PaymentStatus.COMPLETED.value).save() with pytest.raises(BusinessException) as excinfo: PaymentTransactionService.create_transaction_for_invoice( invoice.id, get_paybc_transaction_request()) assert excinfo.value.code == Error.COMPLETED_PAYMENT.name
def test_delete_payment(session, auth_mock, public_user_mock): """Assert that the payment records are soft deleted.""" payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.save() invoice = factory_invoice(payment, payment_account) invoice.save() factory_invoice_reference(invoice.id).save() fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN') line = factory_payment_line_item(invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id) line.save() transaction = factory_payment_transaction(payment.id) transaction.save() PaymentService.delete_payment(payment.id) payment = Payment.find_by_id(payment.id) assert payment.payment_status_code == PaymentStatus.DELETED.value assert payment.invoices[0].invoice_status_code == InvoiceStatus.DELETED.value
def test_transaction_find_by_payment_id(session): """Find all transactions by payment id..""" payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.save() invoice = factory_invoice(payment, payment_account) invoice.save() factory_invoice_reference(invoice.id).save() fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN') line = factory_payment_line_item( invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id) line.save() transaction = factory_payment_transaction(payment.id, Status.CREATED.value) transaction.save() transaction = PaymentTransactionService.find_by_payment_id(payment.id) assert transaction is not None assert transaction.get('items') is not None assert transaction.get('items')[0].get('_links') is not None
def test_transaction_find_active_none_lookup(session): """Invalid lookup..""" payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.save() invoice = factory_invoice(payment, payment_account) invoice.save() factory_invoice_reference(invoice.id).save() fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN') line = factory_payment_line_item( invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id) line.save() transaction = factory_payment_transaction(payment.id, Status.COMPLETED.value) transaction.save() transaction = PaymentTransactionService.find_active_by_payment_id( payment.id) assert transaction is None
def test_update_payment_deleted_invalid(session, public_user_mock): """Assert that the payment records are not updated.""" payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.payment_status_code = PaymentStatus.DELETED.value payment.save() invoice = factory_invoice(payment, payment_account) invoice.save() factory_invoice_reference(invoice.id).save() fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN') line = factory_payment_line_item(invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id) line.save() transaction = factory_payment_transaction(payment.id) transaction.save() with pytest.raises(BusinessException) as excinfo: PaymentService.update_payment(payment.id, get_payment_request(), get_auth_basic_user()) assert excinfo.type == BusinessException
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
def test_transaction_update_completed(session, stan_server, public_user_mock): """Assert that the payment is saved to the table.""" payment_account = factory_payment_account() payment_account.save() invoice = factory_invoice(payment_account) invoice.save() invoice_reference = factory_invoice_reference(invoice.id).save() fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN') line = factory_payment_line_item( invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id) line.save() factory_payment(invoice_number=invoice_reference.invoice_number).save() transaction = PaymentTransactionService.create_transaction_for_invoice( invoice.id, get_paybc_transaction_request()) transaction = PaymentTransactionService.update_transaction( transaction.id, pay_response_url='receipt_number=123451') with pytest.raises(BusinessException) as excinfo: PaymentTransactionService.update_transaction( transaction.id, pay_response_url='receipt_number=123451') assert excinfo.value.code == Error.INVALID_TRANSACTION.name