示例#1
0
def test_account_purchase_history_invalid_request(session, client, jwt, app):
    """Assert that the endpoint returns 400."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

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

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

    search_filter = {'businessIdentifier': 1111}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    assert rv.status_code == 400
示例#5
0
    def find_by_pay_system_id(**kwargs):
        """Find pay system account by id."""
        current_app.logger.debug('<find_by_pay_system_id', kwargs)
        if kwargs.get('credit_account_id'):
            account_dao = CreditPaymentAccount.find_by_id(kwargs.get('credit_account_id'))
        elif kwargs.get('internal_account_id'):
            account_dao = InternalPaymentAccount.find_by_id(kwargs.get('internal_account_id'))
        elif kwargs.get('bcol_account_id'):
            account_dao = BcolPaymentAccount.find_by_id(kwargs.get('bcol_account_id'))
        if not account_dao:
            raise BusinessException(Error.PAY009)

        account = PaymentAccount()
        account.populate(account_dao)  # pylint: disable=protected-access

        current_app.logger.debug('>find_by_pay_system_id')
        return account
示例#6
0
    def create(business_info: Dict[str, Any], account_details: Dict[str, str],
               payment_system: str, authorization: Dict[str, Any]):
        """Create Payment account record."""
        current_app.logger.debug('<create')
        auth_account_id = get_str_by_path(authorization, 'account/id')
        payment_account: PaymentAccountModel = PaymentAccountModel.find_by_auth_account_id(auth_account_id)
        new_payment_account: bool = False
        is_premium_payment: bool = False
        if not payment_account:
            payment_account = PaymentAccountModel()
            payment_account.auth_account_id = auth_account_id
            payment_account = payment_account.save()
            new_payment_account = True

        dao = None
        if payment_system == PaymentSystem.BCOL.value:
            dao = BcolPaymentAccount()
            dao.account_id = payment_account.id
            dao.bcol_account_id = account_details.get('bcol_account_id', None)
            dao.bcol_user_id = account_details.get('bcol_user_id', None)
            is_premium_payment = True
        elif payment_system == PaymentSystem.INTERNAL.value:
            dao = InternalPaymentAccount()
            dao.corp_number = business_info.get('businessIdentifier', None)
            dao.corp_type_code = business_info.get('corpType', None)
            dao.account_id = payment_account.id
        elif payment_system == PaymentSystem.PAYBC.value:
            dao = CreditPaymentAccount()
            dao.corp_number = business_info.get('businessIdentifier', None)
            dao.corp_type_code = business_info.get('corpType', None)
            dao.paybc_account = account_details.get('account_number', None)
            dao.paybc_party = account_details.get('party_number', None)
            dao.paybc_site = account_details.get('site_number', None)
            dao.account_id = payment_account.id

        dao = dao.save()

        if new_payment_account and is_premium_payment:
            PaymentAccount._persist_default_statement_frequency(payment_account.id)

        p = PaymentAccount()
        p.populate(dao)  # pylint: disable=protected-access
        current_app.logger.debug('>create')
        return p
示例#7
0
    def find_account(cls, business_info: Dict[str, Any],
                     authorization: Dict[str, Any],
                     payment_system: str, **kwargs):
        """Find payment account by corp number, corp type and payment system code."""
        current_app.logger.debug('<find_payment_account')
        user: UserContext = kwargs['user']
        auth_account_id: str = get_str_by_path(authorization, 'account/id')
        bcol_user_id: str = get_str_by_path(authorization, 'account/paymentPreference/bcOnlineUserId')
        bcol_account_id: str = get_str_by_path(authorization, 'account/paymentPreference/bcOnlineAccountId')
        corp_number: str = business_info.get('businessIdentifier')
        corp_type: str = business_info.get('corpType')

        account_dao = None

        if payment_system == PaymentSystem.BCOL.value:
            # If BCOL payment and if the payment is inititated by customer check if bcol_user_id is present
            # Staff and system can make payments for users with no bcol account
            if not user.is_system() and not user.is_staff() and bcol_user_id is None:
                raise BusinessException(Error.INCOMPLETE_ACCOUNT_SETUP)

            account_dao: BcolPaymentAccount = BcolPaymentAccount.find_by_bcol_user_id_and_account(
                auth_account_id=auth_account_id,
                bcol_user_id=bcol_user_id,
                bcol_account_id=bcol_account_id
            )
        elif payment_system == PaymentSystem.INTERNAL.value:
            account_dao: InternalPaymentAccount = InternalPaymentAccount. \
                find_by_corp_number_and_corp_type_and_account_id(corp_number=corp_number, corp_type=corp_type,
                                                                 account_id=auth_account_id
                                                                 )
        elif payment_system == PaymentSystem.PAYBC.value:
            if not corp_number and not corp_type:
                raise BusinessException(Error.INVALID_CORP_OR_FILING_TYPE)
            account_dao = CreditPaymentAccount.find_by_corp_number_and_corp_type_and_auth_account_id(
                corp_number=corp_number,
                corp_type=corp_type,
                auth_account_id=auth_account_id
            )
        payment_account = PaymentAccount()
        payment_account.populate(account_dao)  # pylint: disable=protected-access

        current_app.logger.debug('>find_payment_account')
        return payment_account
示例#8
0
    def find_account(cls, business_info: Dict[str, Any],
                     authorization: Dict[str, Any], payment_system: str):
        """Find payment account by corp number, corp type and payment system code."""
        current_app.logger.debug('<find_payment_account')
        auth_account_id: str = get_str_by_path(authorization, 'account/id')
        bcol_user_id: str = get_str_by_path(authorization, 'account/paymentPreference/bcOnlineUserId')
        bcol_account_id: str = get_str_by_path(authorization, 'account/paymentPreference/bcOnlineAccountId')
        corp_number: str = business_info.get('businessIdentifier')
        corp_type: str = business_info.get('corpType')

        account_dao = None

        if payment_system == PaymentSystem.BCOL.value:
            if not bcol_user_id:
                raise BusinessException(Error.PAY015)

            account_dao: BcolPaymentAccount = BcolPaymentAccount.find_by_bcol_user_id_and_account(
                auth_account_id=auth_account_id,
                bcol_user_id=bcol_user_id,
                bcol_account_id=bcol_account_id
            )
        elif payment_system == PaymentSystem.INTERNAL.value:
            account_dao: InternalPaymentAccount = InternalPaymentAccount. \
                find_by_corp_number_and_corp_type_and_account_id(corp_number=corp_number, corp_type=corp_type,
                                                                 account_id=auth_account_id
                                                                 )
        elif payment_system == PaymentSystem.PAYBC.value:
            if not corp_number and not corp_type:
                raise BusinessException(Error.PAY004)
            account_dao = CreditPaymentAccount.find_by_corp_number_and_corp_type_and_auth_account_id(
                corp_number=corp_number,
                corp_type=corp_type,
                auth_account_id=auth_account_id
            )
        payment_account = PaymentAccount()
        payment_account.populate(account_dao)  # pylint: disable=protected-access

        current_app.logger.debug('>find_payment_account')
        return payment_account