def test_create_pad_invoice_multiple_transactions(session):
    """Assert PAD invoices are created."""
    # Create an account and an invoice for the account
    account = factory_create_pad_account(auth_account_id='1',
                                         status=CfsAccountStatus.ACTIVE.value)
    previous_day = datetime.now() - timedelta(days=1)
    # Create an invoice for this account
    invoice = factory_invoice(payment_account=account,
                              created_on=previous_day,
                              total=10,
                              payment_method_code=None)
    fee_schedule = FeeScheduleModel.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()

    # Create another invoice for this account
    invoice2 = factory_invoice(payment_account=account,
                               created_on=previous_day,
                               total=10,
                               payment_method_code=None)
    fee_schedule2 = FeeScheduleModel.find_by_filing_type_and_corp_type(
        'CP', 'OTADD')
    line2 = factory_payment_line_item(
        invoice2.id, fee_schedule_id=fee_schedule2.fee_schedule_id)
    line2.save()

    CreateInvoiceTask.create_invoices()
    invoice2 = InvoiceModel.find_by_id(invoice2.id)
    invoice = InvoiceModel.find_by_id(invoice.id)
    assert invoice2.invoice_status_code == invoice.invoice_status_code == InvoiceStatus.SETTLEMENT_SCHEDULED.value
示例#2
0
def factory_fee_schedule_model(filing_type: FilingType,
                               corp_type: CorpType,
                               fee_code: FeeCode,
                               fee_start_date: date = date.today(),
                               fee_end_date: date = None):
    """Return the fee schedule model."""
    fee_schedule = FeeSchedule(filing_type_code=filing_type.filing_type_code,
                               corp_type_code=corp_type.corp_type_code,
                               fee_code=fee_code.fee_code,
                               fee_start_date=fee_start_date,
                               fee_end_date=fee_end_date)
    fee_schedule.save()
    return fee_schedule
示例#3
0
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_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_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_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
示例#7
0
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
示例#8
0
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
示例#9
0
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
示例#10
0
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_transaction_update(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()
    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,
                                                   'http://google.com/')
    transaction = PaymentTransactionService.update_transaction(
        payment.id, transaction.id, '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 == Status.COMPLETED.value
示例#12
0
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_id=payment.id, account_id=payment_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()
    invoice = Invoice_service.find_by_id(i.id)

    assert invoice is not None
    assert invoice.id is not None
    assert invoice.payment_id is not None
    assert invoice.invoice_number is None
    assert invoice.reference_number is 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.created_on is not None
    assert invoice.created_by is not None
    assert invoice.updated_by is None
    assert invoice.updated_on is None
    assert invoice.account_id is not None
    assert invoice.payment_line_items is not None
示例#13
0
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']
示例#14
0
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
示例#15
0
    def find_by_corp_type_and_filing_type(  # pylint: disable=too-many-arguments
        cls,
        corp_type: str,
        filing_type_code: str,
        valid_date: date,
        jurisdiction: str,
        priority: bool,
    ):
        """Calculate fees for the filing by using the arguments."""
        current_app.logger.debug('<get_fees_by_corp_type_and_filing_type')
        if not corp_type and not filing_type_code:
            raise BusinessException(Error.PAY001)
        if jurisdiction or priority:
            current_app.logger.warn(
                'Not using Jurisdiction and priority now!!!')
        fee_schedule_dao = FeeScheduleModel.find_by_filing_type_and_corp_type(
            corp_type, filing_type_code, valid_date)

        if not fee_schedule_dao:
            raise BusinessException(Error.PAY002)
        fee_schedule = FeeSchedule()
        fee_schedule._dao = fee_schedule_dao  # pylint: disable=protected-access

        current_app.logger.debug('>get_fees_by_corp_type_and_filing_type')
        return fee_schedule
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_pad_invoice_for_frozen_accounts(session):
    """Assert PAD invoices are created."""
    # Create an account and an invoice for the account
    account = factory_create_pad_account(auth_account_id='1',
                                         status=CfsAccountStatus.FREEZE.value)
    previous_day = datetime.now() - timedelta(days=1)
    # Create an invoice for this account
    invoice = factory_invoice(payment_account=account,
                              created_on=previous_day,
                              total=10,
                              payment_method_code=None)

    fee_schedule = FeeScheduleModel.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()

    assert invoice.invoice_status_code == InvoiceStatus.CREATED.value

    CreateInvoiceTask.create_invoices()

    updated_invoice: InvoiceModel = InvoiceModel.find_by_id(invoice.id)
    inv_ref: InvoiceReferenceModel = InvoiceReferenceModel. \
        find_reference_by_invoice_id_and_status(invoice.id, InvoiceReferenceStatus.ACTIVE.value)

    assert inv_ref is None
    assert updated_invoice.invoice_status_code == InvoiceStatus.CREATED.value
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.id, payment_account.id)
    invoice.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
示例#19
0
    def find_by_corp_type_and_filing_type(  # pylint: disable=too-many-arguments
            cls, corp_type: str, filing_type_code: str, valid_date: date,
            **kwargs):
        """Calculate fees for the filing by using the arguments."""
        current_app.logger.debug('<get_fees_by_corp_type_and_filing_type')
        if not corp_type and not filing_type_code:
            raise BusinessException(Error.PAY001)
        if kwargs.get('jurisdiction'):
            current_app.logger.warn('Not using Jurisdiction now!!!')

        fee_schedule_dao = FeeScheduleModel.find_by_filing_type_and_corp_type(
            corp_type, filing_type_code, valid_date)

        if not fee_schedule_dao:
            raise BusinessException(Error.PAY002)
        fee_schedule = FeeSchedule()
        fee_schedule._dao = fee_schedule_dao  # pylint: disable=protected-access

        if kwargs.get('is_priority') and fee_schedule_dao.priority_fee:
            fee_schedule.priority_fee = fee_schedule_dao.priority_fee.amount
        if kwargs.get('is_future_effective'
                      ) and fee_schedule_dao.future_effective_fee:
            fee_schedule.future_effective_fee = fee_schedule_dao.future_effective_fee.amount
        if kwargs.get('waive_fees'):
            fee_schedule.fee_amount = 0

        current_app.logger.debug('>get_fees_by_corp_type_and_filing_type')
        return fee_schedule
def test_transaction_create_new_on_completed_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.id, payment_account.id)
    invoice.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,
                                                   'http://google.com/',
                                                   skip_auth_check=True)
    PaymentTransactionService.update_transaction(payment.id,
                                                 transaction.id,
                                                 '123451',
                                                 skip_auth_check=True)

    with pytest.raises(BusinessException) as excinfo:
        PaymentTransactionService.create(payment.id,
                                         'http://google.com/',
                                         skip_auth_check=True)
    assert excinfo.value.status == Error.PAY006.status
    assert excinfo.value.message == Error.PAY006.message
    assert excinfo.value.code == Error.PAY006.name
def test_multiple_transactions_for_single_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.id, payment_account.id)
    invoice.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()

    PaymentTransactionService.create(payment.id,
                                     'http://google.com/',
                                     skip_auth_check=True)
    PaymentTransactionService.create(payment.id,
                                     'http://google.com/',
                                     skip_auth_check=True)
    transaction = PaymentTransactionService.create(payment.id,
                                                   'http://google.com/',
                                                   skip_auth_check=True)

    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.id, payment_account.id)
    invoice.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_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.id, payment_account.id)
    invoice.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,
                                                   'http://google.com/',
                                                   skip_auth_check=True)
    transaction = PaymentTransactionService.update_transaction(
        payment.id, transaction.id, None, skip_auth_check=True)

    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
示例#24
0
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
示例#25
0
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
示例#26
0
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_create_pad_invoice_single_transaction_run_again(session):
    """Assert PAD invoices are created."""
    # Create an account and an invoice for the account
    account = factory_create_pad_account(auth_account_id='1', status=CfsAccountStatus.ACTIVE.value)
    previous_day = datetime.now() - timedelta(days=1)
    # Create an invoice for this account
    invoice = factory_invoice(payment_account=account, created_on=previous_day, total=10,
                              status_code=InvoiceStatus.APPROVED.value, payment_method_code=None)

    fee_schedule = FeeScheduleModel.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()
    invoice_response = {'invoice_number': '10021', 'pbc_ref_number': '10005', 'party_number': '11111',
                        'party_name': 'invoice'}
    assert invoice.invoice_status_code == InvoiceStatus.APPROVED.value
    the_response = Response()
    the_response._content = json.dumps(invoice_response).encode('utf-8')

    with patch.object(CFSService, 'create_account_invoice', return_value=the_response) as mock_cfs:
        CreateInvoiceTask.create_invoices()
        mock_cfs.assert_called()

    updated_invoice: InvoiceModel = InvoiceModel.find_by_id(invoice.id)
    inv_ref: InvoiceReferenceModel = InvoiceReferenceModel. \
        find_reference_by_invoice_id_and_status(invoice.id, InvoiceReferenceStatus.ACTIVE.value)

    assert inv_ref
    assert updated_invoice.invoice_status_code == InvoiceStatus.APPROVED.value

    with patch.object(CFSService, 'create_account_invoice', return_value=the_response) as mock_cfs:
        CreateInvoiceTask.create_invoices()
        mock_cfs.assert_not_called()
示例#28
0
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
示例#29
0
def test_event_failed_transactions(session, public_user_mock, stan_server,
                                   monkeypatch):
    """Assert that the transaction status is EVENT_FAILED when Q is not available."""
    # 1. Create payment records
    # 2. Create a transaction
    # 3. Fail the queue publishing which will mark the payment as COMPLETED and transaction as EVENT_FAILED
    # 4. Update the transansaction with queue up which will mark the transaction as COMPLETED
    current_app.config['DIRECT_PAY_ENABLED'] = True
    payment_account = factory_payment_account(
        payment_method_code=PaymentMethod.DIRECT_PAY.value)
    payment_account.save()
    fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN')

    invoice = factory_invoice(payment_account, total=30)
    invoice.save()
    factory_invoice_reference(invoice.id).save()
    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())

    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)

    with patch('pay_api.services.payment_transaction.publish_response',
               side_effect=ConnectionError('mocked error')):
        transaction = PaymentTransactionService.update_transaction(
            transaction.id, pay_response_url='?key=value')

    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.EVENT_FAILED.value

    # Now update the transaction and check the status of the transaction
    transaction = PaymentTransactionService.update_transaction(
        transaction.id, pay_response_url=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 == TransactionStatus.COMPLETED.value
示例#30
0
def factory_fee_schedule(filing_type_code: str, corp_type_code: str,
                         fee_code: str, fee_start_date: date,
                         fee_end_date: date):
    """Return a valid FeeSchedule object."""
    return FeeSchedule(filing_type_code=filing_type_code,
                       corp_type_code=corp_type_code,
                       fee_code=fee_code,
                       fee_start_date=fee_start_date,
                       fee_end_date=fee_end_date)