def test_create_payment_record_rollback_on_paybc_connection_error( session, public_user_mock): """Assert that the payment records are not created.""" # Create a payment account factory_payment_account() # 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')): with pytest.raises(ServiceUnavailableException) as excinfo: PaymentService.create_invoice(get_payment_request(), get_auth_basic_user()) assert excinfo.type == ServiceUnavailableException with patch('pay_api.services.oauth_service.requests.post', side_effect=ConnectTimeout('mocked error')): with pytest.raises(ServiceUnavailableException) as excinfo: PaymentService.create_invoice(get_payment_request(), get_auth_basic_user()) assert excinfo.type == ServiceUnavailableException with patch('pay_api.services.oauth_service.requests.post', side_effect=HTTPError('mocked error')) as post_mock: post_mock.status_Code = 503 with pytest.raises(HTTPError) as excinfo: PaymentService.create_invoice(get_payment_request(), get_auth_basic_user()) assert excinfo.type == HTTPError
def test_create_eft_payment(session, public_user_mock): """Assert that the payment records are created.""" factory_payment_account(payment_method_code=PaymentMethod.EFT.value).save() payment_response = PaymentService.create_invoice( get_payment_request_with_service_fees(business_identifier='CP0002000'), get_auth_premium_user()) assert payment_response is not None assert payment_response.get('payment_method') == PaymentMethod.EFT.value assert payment_response.get('status_code') == 'CREATED'
def test_search_account_failed_payments(session): """Assert that the search account payments is working.""" inv_number_1 = 'REG00001' payment_account = factory_payment_account().save() invoice_1 = factory_invoice(payment_account) invoice_1.save() inv_ref_1 = 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('items') assert results.get('total') == 1 # Create one more payment with failed status. inv_number_2 = 'REG00002' invoice_2 = factory_invoice(payment_account) invoice_2.save() inv_ref_2 = 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, 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=1, page=1) assert results.get('items') assert results.get('total') == 2 # Now combine both payments into one, by setting status to invoice reference. - NSF payments inv_ref_1.status_code = InvoiceReferenceStatus.CANCELLED.value inv_ref_2.status_code = InvoiceReferenceStatus.CANCELLED.value inv_ref_1.save() inv_ref_2.save() # Now create new invoice reference for consolidated invoice inv_number_3 = 'REG00003' factory_invoice_reference(invoice_1.id, invoice_number=inv_number_3).save() factory_invoice_reference(invoice_2.id, invoice_number=inv_number_3).save() results = Payment_service.search_account_payments( auth_account_id=auth_account_id, status='FAILED', limit=1, page=1) # Now there are no active failed payments, so it should return zero records assert not results.get('items') assert results.get('total') == 0
def test_find_older_records_invalid_status(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=payment, payment_account=payment_account) invoice.save() payment_transaction_now = factory_payment_transaction( payment_id=payment.id, status_code='COMPLETED') payment_transaction_now.save() # not eligible payment_transaction_now_draft = factory_payment_transaction( payment_id=payment.id, status_code='CREATED') payment_transaction_now_draft.save() # not eligible payment_transaction_now_draft_3_hours = factory_payment_transaction( payment_id=payment.id, status_code='CREATED', transaction_start_time=datetime.now() - timedelta(hours=3)) payment_transaction_now_draft_3_hours.save() # this is eligible payment_transaction_now_draft_completed_3_hours = factory_payment_transaction( payment_id=payment.id, status_code='COMPLETED', transaction_start_time=datetime.now() - timedelta(hours=3)) payment_transaction_now_draft_completed_3_hours.save() # not eligible all_records = payment_transaction_now.find_stale_records( hours=2, minutes=59) # find records which are 2.59 hourolder assert len(all_records) == 1
def test_invoice_with_temproary_business_identifier(session): """Assert that the invoice dictionary is not include temproary business identifier.""" payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.save() i = factory_invoice(payment=payment, payment_account=payment_account, business_identifier='Tzxcasd') 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() 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.payment_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 invoice.payment_line_items is not None assert invoice.folio_number is not None assert invoice.business_identifier is not None invoice_dict = invoice.asdict() assert invoice_dict.get('business_identifier') is None
def test_create_receipt_without_invoice(session, public_user_mock): """Try creating a receipt without invoice number.""" payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.save() invoice = factory_invoice(payment.id, payment_account.id) 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.update_payment(payment.id, get_payment_request()) input_data = { 'corpName': 'Pennsular Coop ', 'filingDateTime': '1999', 'fileName': 'coopser' } response = ReceiptService.create_receipt(payment.id, '', input_data, skip_auth_check=True) assert response is not None
def test_create_receipt_with_no_receipt(session, public_user_mock): """Try creating a receipt with invoice number.""" payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.save() invoice = factory_invoice(payment.id, payment_account.id) 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() PaymentService.update_payment(payment.id, get_payment_request()) input_data = { 'corpName': 'Pennsular Coop ', 'filingDateTime': '1999', 'fileName': 'coopser' } with pytest.raises(BusinessException) as excinfo: ReceiptService.create_receipt(payment.id, '', input_data, skip_auth_check=True) assert excinfo.type == BusinessException
def test_create_comment(session, monkeypatch): """Assert create comment.""" # create a routing slip # create a comment # retrieve all comments of a routing slip def token_info(): # pylint: disable=unused-argument; mocks of library methods return { 'username': '******', 'realm_access': { 'roles': ['system', 'edit'] } } def mock_auth(): # pylint: disable=unused-argument; mocks of library methods return 'test' monkeypatch.setattr('pay_api.utils.user_context._get_token', mock_auth) monkeypatch.setattr('pay_api.utils.user_context._get_token_info', token_info) payment_account = factory_payment_account() payment_account.save() rs = factory_routing_slip(payment_account_id=payment_account.id, number='test_number') rs.save() CommentService.create(comment_value='test', rs_number=rs.number) result = CommentService.find_all_comments_for_a_routingslip(rs.number) assert result comments = result.get('comments') assert len(comments) == 1 assert comments[0].get('routing_slip_number') == rs.number
def test_create_transaction_for_completed_nsf_payment(session): """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. 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='COMPLETED', payment_account_id=payment_account.id, invoice_number=inv_number_1, invoice_amount=100, payment_method_code=PaymentMethod.CC.value) payment_2.save() with pytest.raises(BusinessException) as excinfo: PaymentTransactionService.create_transaction_for_payment( payment_2.id, get_paybc_transaction_request()) assert excinfo.value.code == Error.INVALID_PAYMENT_ID.name
def test_update_transaction_for_direct_pay_without_response_url(session): """Assert that the receipt records are created.""" current_app.config['DIRECT_PAY_ENABLED'] = True payment_account = factory_payment_account( payment_method_code=PaymentMethod.DIRECT_PAY.value) payment = factory_payment( payment_method_code=PaymentMethod.DIRECT_PAY.value) payment_account.save() payment.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.create_transaction_for_invoice( invoice.id, get_paybc_transaction_request()) # Update transaction without response url, which should update the receipt transaction = PaymentTransactionService.update_transaction( transaction.id, None) assert transaction.status_code == TransactionStatus.COMPLETED.value
def test_update_transaction_for_direct_pay_with_response_url(session): """Assert that the receipt records are created.""" current_app.config['DIRECT_PAY_ENABLED'] = True response_url = 'trnApproved=1&messageText=Approved&trnOrderId=1003598&trnAmount=201.00&paymentMethod=CC' \ '&cardType=VI&authCode=TEST&trnDate=2020-08-11&pbcTxnNumber=1' valid_hash = f'&hashValue={HashingService.encode(response_url)}' payment_account = factory_payment_account( payment_method_code=PaymentMethod.DIRECT_PAY.value) payment = factory_payment( payment_method_code=PaymentMethod.DIRECT_PAY.value) payment_account.save() payment.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.create_transaction_for_invoice( invoice.id, get_paybc_transaction_request()) # Update transaction with invalid hash transaction = PaymentTransactionService.update_transaction( transaction.id, f'{response_url}1234567890') assert transaction.status_code == TransactionStatus.FAILED.value # Update transaction with valid hash transaction = PaymentTransactionService.create_transaction_for_invoice( invoice.id, get_paybc_transaction_request()) transaction = PaymentTransactionService.update_transaction( transaction.id, f'{response_url}{valid_hash}') assert transaction.status_code == TransactionStatus.COMPLETED.value
def test_transaction_update(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') 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.COMPLETED.value
def test_transaction_for_direct_pay_create_from_new(session): """Assert that the payment is saved to the table.""" 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) invoice.save() invoice_reference = factory_invoice_reference(invoice.id).save() factory_payment(invoice_number=invoice_reference.invoice_number).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_transaction_for_invoice( invoice.id, get_paybc_transaction_request()) 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.asdict() is not None
def test_routing_slip_find_search(session): """Assert a routing slip is stored. Start with a blank database. """ payment_account = factory_payment_account() payment_account.save() rs = factory_routing_slip(number=fake.name(), payment_account_id=payment_account.id) rs.save() for i in range(20): factory_routing_slip(number=fake.name(), payment_account_id=payment_account.id).save() routing_slip = RoutingSlip() search_dict = {'routingSlipNumber': rs.number} res, count = routing_slip.search(search_dict, page=1, limit=1, return_all=True) assert count == 1 assert len(res) == 1, 'searched with routing slip.so only one record' res, count = routing_slip.search({}, page=1, limit=1, return_all=True) assert count == 21 assert len(res) == 21, 'retun all true ;so shud return all records' res, count = routing_slip.search({}, page=1, limit=1, return_all=False) assert count == 1 assert len(res) == 1, 'return all false'
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
def test_get_receipt(session, public_user_mock): """Assert that get receipt is working.""" response_url = 'trnApproved=1&messageText=Approved&trnOrderId=1003598&trnAmount=201.00&paymentMethod=CC' \ '&cardType=VI&authCode=TEST&trnDate=2020-08-11&pbcTxnNumber=1' invalid_hash = '&hashValue=0f7953db6f02f222f1285e1544c6a765' 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') service_fee = 100 line = factory_payment_line_item(invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id, service_fees=service_fee) line.save() direct_pay_service = DirectPayService() rcpt = direct_pay_service.get_receipt(payment_account, f'{response_url}{invalid_hash}', invoice_ref) assert rcpt is None valid_hash = f'&hashValue={HashingService.encode(response_url)}' rcpt = direct_pay_service.get_receipt(payment_account, f'{response_url}{valid_hash}', invoice_ref) assert rcpt is not None # Test receipt without response_url rcpt = direct_pay_service.get_receipt(payment_account, None, invoice_ref) assert rcpt is not None
def test_get_payment_system_url_service_fees(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() # Set service fee distribution distribution_code_payload.update({'serviceFeeDistributionCodeId': distribution_code.distribution_code_id}) # update the existing gl code with new values distribution_code_svc.save_or_update(distribution_code_payload, distribution_code.distribution_code_id) service_fee = 100 line = factory_payment_line_item(invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id, service_fees=service_fee) 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' revenue_str_service_fee = f"2:{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:{format(service_fee, DECIMAL_PRECISION)}' assert url_param_dict['revenue'] == f'{revenue_str}|{revenue_str_service_fee}' 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}|' \ f'{revenue_str_service_fee}' expected_hash_str = HashingService.encode(urlstring) assert expected_hash_str == url_param_dict['hashValue']
def test_create_refund_for_paid_invoice(session, monkeypatch, payment_method, invoice_status, pay_status, has_reference, expected_inv_status): """Assert that the create refund succeeds for paid invoices.""" expected = REFUND_SUCCESS_MESSAGES[f'{payment_method}.{invoice_status}'] payment_account = factory_payment_account() payment_account.save() i = factory_invoice(payment_account=payment_account, payment_method_code=payment_method) i.save() if has_reference: inv_ref = factory_invoice_reference(i.id) inv_ref.status_code = InvoiceReferenceStatus.COMPLETED.value inv_ref.save() payment = factory_payment(invoice_number=inv_ref.invoice_number, payment_status_code=pay_status).save() factory_payment_transaction(payment_id=payment.id, status_code=TransactionStatus.COMPLETED.value).save() i.invoice_status_code = invoice_status i.save() factory_receipt(invoice_id=i.id).save() monkeypatch.setattr('pay_api.services.payment_transaction.publish_response', lambda *args, **kwargs: None) message = RefundService.create_refund(invoice_id=i.id, request={'reason': 'Test'}) i = InvoiceModel.find_by_id(i.id) assert i.invoice_status_code == expected_inv_status assert message['message'] == expected
def test_create_invoice(session): """Test create_invoice.""" pay_account = factory_payment_account(payment_system_code='BCOL', account_number='BCOL_ACC_1', bcol_user_id='test') pay_account.save() payment = factory_payment() payment.save() i = factory_invoice(payment=payment, payment_account=pay_account) 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() line = PaymentLineItem.find_by_id(line.id) # payment_account: PaymentAccount, line_items: [PaymentLineItem], invoice_id: str, **kwargs inv = bcol_service.create_invoice( payment_account=pay_account, line_items=[line], invoice=i, filing_info={'folioNumber': '1234567890'}, corp_type_code=i.corp_type_code, business_identifier=i.business_identifier) assert inv is not None assert inv.get('invoice_number') == 'TEST'
def test_create_duplicate_refund_for_paid_invoice(session, monkeypatch): """Assert that the create duplicate refund fails for paid invoices.""" payment_account = factory_payment_account() payment_account.save() i = factory_invoice(payment_account=payment_account) i.save() inv_ref = factory_invoice_reference(i.id) inv_ref.status_code = InvoiceReferenceStatus.COMPLETED.value inv_ref.save() payment = factory_payment(invoice_number=inv_ref.invoice_number).save() factory_payment_transaction(payment_id=payment.id, status_code=TransactionStatus.COMPLETED.value).save() i.invoice_status_code = InvoiceStatus.PAID.value i.save() factory_receipt(invoice_id=i.id).save() monkeypatch.setattr('pay_api.services.payment_transaction.publish_response', lambda *args, **kwargs: None) RefundService.create_refund(invoice_id=i.id, request={'reason': 'Test'}) i = InvoiceModel.find_by_id(i.id) payment: PaymentModel = PaymentModel.find_by_id(payment.id) assert i.invoice_status_code == InvoiceStatus.REFUND_REQUESTED.value assert payment.payment_status_code == PaymentStatus.REFUNDED.value with pytest.raises(Exception) as excinfo: RefundService.create_refund(invoice_id=i.id, request={'reason': 'Test'}) assert excinfo.type == BusinessException
def test_receipt_saved_from_new(session): """Assert that the receipt is saved to the table.""" payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.save() i = factory_invoice(payment_id=payment.id, account_id=payment_account.id) i.save() factory_invoice_reference(i.id).save() receipt_service = ReceiptService() receipt_service.receipt_number = '1234567890' receipt_service.invoice_id = i.id receipt_service.receipt_date = datetime.now() receipt_service.receipt_amount = 100 receipt_service = receipt_service.save() receipt_service = ReceiptService.find_by_id(receipt_service.id) assert receipt_service is not None assert receipt_service.id is not None assert receipt_service.receipt_date is not None assert receipt_service.invoice_id is not None receipt_service = ReceiptService.find_by_invoice_id_and_receipt_number( i.id, receipt_service.receipt_number) assert receipt_service is not None assert receipt_service.id is not None
def test_transaction_update_with_no_receipt(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, invoice_number='').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()) transaction = PaymentTransactionService.update_transaction( payment.id, transaction.id, None) 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 == Status.FAILED.value assert transaction.asdict() is not None
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_account, total=10) invoice.save() invoice_reference = factory_invoice_reference(invoice.id).save() # Create a payment for this reference payment = factory_payment(invoice_number=invoice_reference.invoice_number, invoice_amount=10).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_invoice(invoice.id) invoice = Invoice.find_by_id(invoice.id) payment = Payment.find_by_id(payment.id) assert invoice.invoice_status_code == InvoiceStatus.DELETED.value assert payment.payment_status_code == PaymentStatus.DELETED.value
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 = 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()) transaction = PaymentTransactionService.update_transaction( payment.id, transaction.id, '123451') with pytest.raises(BusinessException) as excinfo: PaymentTransactionService.update_transaction(payment.id, transaction.id, '123451') assert excinfo.value.status == Error.PAY006.status assert excinfo.value.message == Error.PAY006.message assert excinfo.value.code == Error.PAY006.name
def test_transaction_find_active_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.CREATED.value) transaction.save() transaction = PaymentTransactionService.find_active_by_payment_id( payment.id) 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.status_code == Status.CREATED.value
def test_transaction_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, 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() payment_transaction = PaymentTransactionService() payment_transaction.status_code = 'DRAFT' payment_transaction.transaction_end_time = datetime.now() payment_transaction.transaction_start_time = datetime.now() payment_transaction.pay_system_url = 'http://google.com' payment_transaction.client_system_url = 'http://google.com' payment_transaction.payment_id = payment.id payment_transaction = payment_transaction.save() transaction = PaymentTransactionService.find_by_id(payment.id, payment_transaction.id) 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
def test_invoice_saved_from_new(session): """Assert that the invoice 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() 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() 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.payment_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 invoice.payment_line_items is not None assert invoice.folio_number is not None assert invoice.business_identifier is not None
def test_transaction_create_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, 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()) 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.asdict() is not None
def test_line_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.id, payment_account.id) 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() line = factory_payment_line_item(invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id, status='DELETED') line.save() p = PaymentLineService.find_by_id(line.id) assert p is not None assert p.id is not None assert p.invoice_id is not None assert p.filing_fees is not None assert p.fee_schedule_id is not None assert p.gst is None assert p.pst is None assert p.line_item_status_code is not None assert p.priority_fees is None assert p.future_effective_fees is None invoice = Invoice.find_by_id(invoice.id) schema = InvoiceSchema() d = schema.dump(invoice) assert d.get('id') == invoice.id assert len(d.get('line_items')) == 1
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