async def test_pad_nsf_reconciliations(session, app, stan_server, event_loop, client_id, events_stan, future, mock_publish): """Test Reconciliations worker for NSF.""" # Call back for the subscription from reconciliations.worker import cb_subscription_handler # register the handler to test it await subscribe_to_queue( events_stan, current_app.config.get('SUBSCRIPTION_OPTIONS').get('subject'), current_app.config.get('SUBSCRIPTION_OPTIONS').get('queue'), current_app.config.get('SUBSCRIPTION_OPTIONS').get('durable_name'), cb_subscription_handler) # 1. Create payment account # 2. Create invoices and related records # 3. Create CFS Invoice records # 4. Create a CFS settlement file, and verify the records cfs_account_number = '1234' pay_account: PaymentAccountModel = factory_create_pad_account( status=CfsAccountStatus.ACTIVE.value, account_number=cfs_account_number) invoice1: InvoiceModel = factory_invoice( payment_account=pay_account, total=100, service_fees=10.0, payment_method_code=PaymentMethod.PAD.value) factory_payment_line_item(invoice_id=invoice1.id, filing_fees=90.0, service_fees=10.0, total=90.0) invoice2: InvoiceModel = factory_invoice( payment_account=pay_account, total=200, service_fees=10.0, payment_method_code=PaymentMethod.PAD.value) factory_payment_line_item(invoice_id=invoice2.id, filing_fees=190.0, service_fees=10.0, total=190.0) invoice_number = '1234567890' factory_invoice_reference(invoice_id=invoice1.id, invoice_number=invoice_number) factory_invoice_reference(invoice_id=invoice2.id, invoice_number=invoice_number) invoice1.invoice_status_code = InvoiceStatus.SETTLEMENT_SCHEDULED.value invoice2.invoice_status_code = InvoiceStatus.SETTLEMENT_SCHEDULED.value invoice1.save() invoice2.save() invoice1_id = invoice1.id invoice2_id = invoice2.id pay_account_id = pay_account.id total = invoice1.total + invoice2.total # Create a settlement file and publish. file_name: str = 'cas_settlement_file.csv' # Settlement row receipt_number = '1234567890' date = datetime.now().strftime('%d-%b-%y') row = [ RecordType.PAD.value, SourceTransaction.PAD.value, receipt_number, 100001, date, 0, cfs_account_number, 'INV', invoice_number, total, total, Status.NOT_PAID.value ] create_and_upload_settlement_file(file_name, [row]) await helper_add_event_to_queue(events_stan, file_name=file_name) # The invoice should be in SETTLEMENT_SCHEDULED status and Payment should be FAILED updated_invoice1 = InvoiceModel.find_by_id(invoice1_id) assert updated_invoice1.invoice_status_code == InvoiceStatus.SETTLEMENT_SCHEDULED.value updated_invoice2 = InvoiceModel.find_by_id(invoice2_id) assert updated_invoice2.invoice_status_code == InvoiceStatus.SETTLEMENT_SCHEDULED.value payment: PaymentModel = PaymentModel.find_payment_by_receipt_number( receipt_number) assert payment.payment_status_code == PaymentStatus.FAILED.value assert payment.paid_amount == 0 assert payment.receipt_number == receipt_number assert payment.payment_method_code == PaymentMethod.PAD.value assert payment.invoice_number == invoice_number cfs_account: CfsAccountModel = CfsAccountModel.find_effective_by_account_id( pay_account_id) assert cfs_account.status == CfsAccountStatus.FREEZE.value
async def test_eft_wire_reconciliations(session, app, stan_server, event_loop, client_id, events_stan, future, mock_publish): """Test Reconciliations worker.""" # Call back for the subscription from reconciliations.worker import cb_subscription_handler # Create a Credit Card Payment # register the handler to test it await subscribe_to_queue( events_stan, current_app.config.get('SUBSCRIPTION_OPTIONS').get('subject'), current_app.config.get('SUBSCRIPTION_OPTIONS').get('queue'), current_app.config.get('SUBSCRIPTION_OPTIONS').get('durable_name'), cb_subscription_handler) # 1. Create payment account # 2. Create invoice and related records # 3. Create CFS Invoice records # 4. Create a CFS settlement file, and verify the records cfs_account_number = '1234' pay_account: PaymentAccountModel = factory_create_online_banking_account( status=CfsAccountStatus.ACTIVE.value, cfs_account=cfs_account_number) invoice: InvoiceModel = factory_invoice( payment_account=pay_account, total=100, service_fees=10.0, payment_method_code=PaymentMethod.ONLINE_BANKING.value) factory_payment_line_item(invoice_id=invoice.id, filing_fees=90.0, service_fees=10.0, total=90.0) invoice_number = '1234567890' factory_invoice_reference(invoice_id=invoice.id, invoice_number=invoice_number) invoice.invoice_status_code = InvoiceStatus.SETTLEMENT_SCHEDULED.value invoice = invoice.save() invoice_id = invoice.id total = invoice.total # Create a payment for EFT Wire eft_wire_receipt = 'RCPT0012345' paid_amount = 100 PaymentModel(payment_method_code=PaymentMethod.EFT.value, payment_status_code=PaymentStatus.CREATED.value, payment_system_code='PAYBC', payment_account_id=pay_account.id, completed_on=datetime.now(), paid_amount=paid_amount, receipt_number=eft_wire_receipt).save() # Create a settlement file and publish. file_name: str = 'cas_settlement_file.csv' # Settlement row date = datetime.now().strftime('%d-%b-%y') row = [ RecordType.EFTP.value, SourceTransaction.EFT_WIRE.value, eft_wire_receipt, 100001, date, total, cfs_account_number, TargetTransaction.INV.value, invoice_number, total, 0, Status.PAID.value ] create_and_upload_settlement_file(file_name, [row]) await helper_add_event_to_queue(events_stan, file_name=file_name) # The invoice should be in PAID status and Payment should be completed updated_invoice = InvoiceModel.find_by_id(invoice_id) assert updated_invoice.invoice_status_code == InvoiceStatus.PAID.value payment: PaymentModel = PaymentModel.find_payment_by_receipt_number( eft_wire_receipt) assert payment.payment_status_code == PaymentStatus.COMPLETED.value assert payment.paid_amount == paid_amount assert payment.receipt_number == eft_wire_receipt
async def test_pad_reconciliations_with_credit_memo(session, app, stan_server, event_loop, client_id, events_stan, future, mock_publish): """Test Reconciliations worker.""" # Call back for the subscription from reconciliations.worker import cb_subscription_handler # Create a Credit Card Payment # register the handler to test it await subscribe_to_queue( events_stan, current_app.config.get('SUBSCRIPTION_OPTIONS').get('subject'), current_app.config.get('SUBSCRIPTION_OPTIONS').get('queue'), current_app.config.get('SUBSCRIPTION_OPTIONS').get('durable_name'), cb_subscription_handler) # 1. Create payment account # 2. Create invoices and related records # 3. Create CFS Invoice records # 4. Mimic some credits on the account # 4. Create a CFS settlement file, and verify the records cfs_account_number = '1234' pay_account: PaymentAccountModel = factory_create_pad_account( status=CfsAccountStatus.ACTIVE.value, account_number=cfs_account_number) invoice1: InvoiceModel = factory_invoice( payment_account=pay_account, total=100, service_fees=10.0, payment_method_code=PaymentMethod.PAD.value) factory_payment_line_item(invoice_id=invoice1.id, filing_fees=90.0, service_fees=10.0, total=90.0) invoice2: InvoiceModel = factory_invoice( payment_account=pay_account, total=200, service_fees=10.0, payment_method_code=PaymentMethod.PAD.value) factory_payment_line_item(invoice_id=invoice2.id, filing_fees=190.0, service_fees=10.0, total=190.0) invoice_number = '1234567890' factory_invoice_reference(invoice_id=invoice1.id, invoice_number=invoice_number) factory_invoice_reference(invoice_id=invoice2.id, invoice_number=invoice_number) invoice1.invoice_status_code = InvoiceStatus.SETTLEMENT_SCHEDULED.value invoice2.invoice_status_code = InvoiceStatus.SETTLEMENT_SCHEDULED.value invoice1.save() invoice2.save() invoice1_id = invoice1.id invoice2_id = invoice2.id total = invoice1.total + invoice2.total # Create a settlement file and publish. file_name: str = 'cas_settlement_file.csv' # Settlement row receipt_number = '1234567890' credit_memo_number = 'CM123' date = datetime.now().strftime('%d-%b-%y') credit_amount = 25 credit_row = [ RecordType.CMAP.value, SourceTransaction.CREDIT_MEMO.value, credit_memo_number, 100002, date, credit_amount, cfs_account_number, 'INV', invoice_number, total, 0, Status.PAID.value ] pad_row = [ RecordType.PAD.value, SourceTransaction.PAD.value, receipt_number, 100001, date, total - credit_amount, cfs_account_number, 'INV', invoice_number, total, 0, Status.PAID.value ] create_and_upload_settlement_file(file_name, [credit_row, pad_row]) await helper_add_event_to_queue(events_stan, file_name=file_name) # The invoice should be in PAID status and Payment should be completed updated_invoice1 = InvoiceModel.find_by_id(invoice1_id) assert updated_invoice1.invoice_status_code == InvoiceStatus.PAID.value updated_invoice2 = InvoiceModel.find_by_id(invoice2_id) assert updated_invoice2.invoice_status_code == InvoiceStatus.PAID.value payment: PaymentModel = PaymentModel.find_payment_by_receipt_number( receipt_number) assert payment.payment_status_code == PaymentStatus.COMPLETED.value assert payment.paid_amount == total - credit_amount assert payment.receipt_number == receipt_number assert payment.payment_method_code == PaymentMethod.PAD.value assert payment.invoice_number == invoice_number rcpt1: ReceiptModel = ReceiptModel.find_by_invoice_id_and_receipt_number( invoice1_id, receipt_number) rcpt2: ReceiptModel = ReceiptModel.find_by_invoice_id_and_receipt_number( invoice2_id, receipt_number) assert rcpt1 assert rcpt2 assert rcpt1.receipt_date == rcpt2.receipt_date