Exemplo n.º 1
0
def test_create_pad_account_but_drawdown_is_active(session):
    """Assert updating PAD to DRAWDOWN works."""
    # Create a PAD Account first
    pad_account = PaymentAccountService.create(get_pad_account_payload())
    # Update this payment account with drawdown and assert payment method
    assert pad_account.payment_method == PaymentMethod.DRAWDOWN.value
    assert pad_account.cfs_account_id
Exemplo n.º 2
0
    def post():
        """Create the payment account records."""
        current_app.logger.info('<Account.post')
        request_json = request.get_json()
        current_app.logger.debug(request_json)

        # Check if sandbox request is authorized.
        is_sandbox = request.args.get('sandbox', 'false').lower() == 'true'
        if is_sandbox and not _jwt.validate_roles(
            [Role.CREATE_SANDBOX_ACCOUNT.value]):
            abort(HTTPStatus.FORBIDDEN)

        # Validate the input request
        valid_format, errors = schema_utils.validate(request_json,
                                                     'account_info')

        if not valid_format:
            return error_to_response(
                Error.INVALID_REQUEST,
                invalid_params=schema_utils.serialize(errors))
        try:
            response = PaymentAccountService.create(request_json, is_sandbox)
            status = HTTPStatus.ACCEPTED \
                if response.cfs_account_id and response.cfs_account_status == CfsAccountStatus.PENDING.value \
                else HTTPStatus.CREATED
        except BusinessException as exception:
            return exception.response()
        current_app.logger.debug('>Account.post')
        return jsonify(response.asdict()), status
Exemplo n.º 3
0
def test_update_online_banking_to_credit(session):
    """Assert that update from online banking to credit card works."""
    online_banking_account = PaymentAccountService.create(
        get_basic_account_payload(
            payment_method=PaymentMethod.ONLINE_BANKING.value))
    credit_account = PaymentAccountService.update(
        online_banking_account.auth_account_id, get_basic_account_payload())
    assert credit_account.payment_method == PaymentMethod.DIRECT_PAY.value
Exemplo n.º 4
0
def test_create_pad_account_to_drawdown(session):
    """Assert updating PAD to DRAWDOWN works."""
    # Create a PAD Account first
    pad_account = PaymentAccountService.create(get_unlinked_pad_account_payload())
    # Update this payment account with drawdown and assert payment method
    bcol_account = PaymentAccountService.update(pad_account.auth_account_id, get_premium_account_payload())
    assert bcol_account.auth_account_id == bcol_account.auth_account_id
    assert bcol_account.payment_method == PaymentMethod.DRAWDOWN.value
Exemplo n.º 5
0
def test_delete_account(session, payload):
    """Assert that delete payment account works."""
    pay_account: PaymentAccountService = PaymentAccountService.create(payload)
    PaymentAccountService.delete_account(payload.get('accountId'))

    # Try to find the account by id.
    pay_account = PaymentAccountService.find_by_id(pay_account.id)
    for cfs_account in CfsAccountModel.find_by_account_id(pay_account.id):
        assert cfs_account.status == CfsAccountStatus.INACTIVE.value if cfs_account else True
Exemplo n.º 6
0
def test_create_online_banking_account(session):
    """Assert that create online banking account works."""
    online_banking_account = PaymentAccountService.create(
        get_basic_account_payload(payment_method=PaymentMethod.ONLINE_BANKING.value))
    assert online_banking_account.payment_method == PaymentMethod.ONLINE_BANKING.value
    assert online_banking_account.cfs_account_id
    assert online_banking_account.cfs_account is None
    assert online_banking_account.cfs_party is None
    assert online_banking_account.cfs_site is None
    assert online_banking_account.bank_number is None
Exemplo n.º 7
0
def test_update_credit_to_online_banking(session):
    """Assert that update from credit card to online banking works."""
    credit_account = PaymentAccountService.create(get_basic_account_payload())
    online_banking_account = PaymentAccountService.update(credit_account.auth_account_id, get_basic_account_payload(
        payment_method=PaymentMethod.ONLINE_BANKING.value))
    assert online_banking_account.payment_method == PaymentMethod.ONLINE_BANKING.value
    assert online_banking_account.cfs_account_id
    assert online_banking_account.cfs_account is None
    assert online_banking_account.cfs_party is None
    assert online_banking_account.cfs_site is None
    assert online_banking_account.bank_number is None
Exemplo n.º 8
0
def test_create_bcol_account_to_pad(session):
    """Assert that update from BCOL to PAD works."""
    # Create a DRAWDOWN Account first
    bcol_account = PaymentAccountService.create(get_premium_account_payload())
    # Update to PAD
    pad_account = PaymentAccountService.update(bcol_account.auth_account_id, get_unlinked_pad_account_payload())

    assert bcol_account.auth_account_id == bcol_account.auth_account_id
    assert pad_account.payment_method == PaymentMethod.PAD.value
    assert pad_account.cfs_account_id
    assert pad_account.cfs_account is None
    assert pad_account.cfs_party is None
    assert pad_account.cfs_site is None
Exemplo n.º 9
0
def test_create_pad_account(session):
    """Assert that pad account details are created."""
    pad_account = PaymentAccountService.create(get_unlinked_pad_account_payload())
    assert pad_account.bank_number == get_unlinked_pad_account_payload().get('paymentInfo'). \
        get('bankInstitutionNumber')
    assert pad_account.bank_account_number == get_unlinked_pad_account_payload(). \
        get('paymentInfo').get('bankAccountNumber')
    assert pad_account.bank_branch_number == get_unlinked_pad_account_payload(). \
        get('paymentInfo').get('bankTransitNumber')
    assert pad_account.payment_method == PaymentMethod.PAD.value
    assert pad_account.cfs_account_id
    assert pad_account.cfs_account is None
    assert pad_account.cfs_party is None
    assert pad_account.cfs_site is None
Exemplo n.º 10
0
def test_pad_factory_for_system_fails(session, system_user_mock):
    """Test payment system creation for PAD payment instances."""
    from pay_api.factory.payment_system_factory import PaymentSystemFactory  # noqa I001; errors out the test case
    from pay_api.exceptions import BusinessException

    pad_account = PaymentAccountService.create(get_unlinked_pad_account_payload())
    # Try a DRAWDOWN for system user

    with pytest.raises(BusinessException) as excinfo:
        PaymentSystemFactory.create(payment_method='PAD', payment_account=pad_account)
    assert excinfo.value.code == Error.ACCOUNT_IN_PAD_CONFIRMATION_PERIOD.name

    time_delay = current_app.config['PAD_CONFIRMATION_PERIOD_IN_DAYS']
    with freeze_time(datetime.today() + timedelta(days=time_delay + 1, minutes=1)):
        instance = PaymentSystemFactory.create(payment_method='PAD', payment_account=pad_account)
        assert isinstance(instance, PadService)
Exemplo n.º 11
0
def test_delete_account_failures(session):
    """Assert that delete payment account works."""
    # Create a PAD Account.
    # Add credit and assert account cannot be deleted.
    # Remove the credit.
    # Add a PAD transaction for within N days and mark as PAID.
    # Assert account cannot be deleted.
    # Mark the account as NSF and assert account cannot be deleted.
    payload = get_pad_account_payload()
    pay_account: PaymentAccountService = PaymentAccountService.create(payload)
    pay_account.credit = 100
    pay_account.save()

    with pytest.raises(BusinessException) as excinfo:
        PaymentAccountService.delete_account(payload.get('accountId'))

    assert excinfo.value.code == Error.OUTSTANDING_CREDIT.code

    # Now mark the credit as zero and mark teh CFS account status as FREEZE.
    pay_account.credit = 0
    pay_account.save()

    cfs_account = CfsAccountModel.find_effective_by_account_id(pay_account.id)
    cfs_account.status = CfsAccountStatus.FREEZE.value
    cfs_account.save()

    with pytest.raises(BusinessException) as excinfo:
        PaymentAccountService.delete_account(payload.get('accountId'))

    assert excinfo.value.code == Error.FROZEN_ACCOUNT.code

    # Now mark the status ACTIVE and create transactions within configured time.
    cfs_account = CfsAccountModel.find_effective_by_account_id(pay_account.id)
    cfs_account.status = CfsAccountStatus.ACTIVE.value
    cfs_account.save()

    created_on: datetime = get_outstanding_txns_from_date() + timedelta(
        minutes=1)
    factory_invoice(pay_account,
                    payment_method_code=PaymentMethod.PAD.value,
                    created_on=created_on,
                    status_code=InvoiceStatus.PAID.value).save()

    with pytest.raises(BusinessException) as excinfo:
        PaymentAccountService.delete_account(payload.get('accountId'))

    assert excinfo.value.code == Error.TRANSACTIONS_IN_PROGRESS.code
Exemplo n.º 12
0
def test_create_pad_to_bcol_to_pad(session):
    """Assert that update from BCOL to PAD works."""
    # Create a PAD Account first
    pad_account_1 = PaymentAccountService.create(get_unlinked_pad_account_payload(bank_number='009'))
    assert pad_account_1.bank_number == '009'

    # Update this payment account with drawdown and assert payment method
    bcol_account = PaymentAccountService.update(pad_account_1.auth_account_id, get_premium_account_payload())
    assert bcol_account.auth_account_id == bcol_account.auth_account_id
    assert bcol_account.payment_method == PaymentMethod.DRAWDOWN.value

    # Update to PAD again
    pad_account_2 = PaymentAccountService.update(pad_account_1.auth_account_id,
                                                 get_unlinked_pad_account_payload(bank_number='010'))
    assert pad_account_2.bank_number == '010'
    assert pad_account_2.payment_method == PaymentMethod.PAD.value
    assert pad_account_2.cfs_account_id != pad_account_1.cfs_account_id
Exemplo n.º 13
0
    def post():
        """Create the payment account records."""
        current_app.logger.info('<Account.post')
        request_json = request.get_json()
        current_app.logger.debug(request_json)
        # Validate the input request
        valid_format, errors = schema_utils.validate(request_json,
                                                     'account_info')

        if not valid_format:
            return error_to_response(
                Error.INVALID_REQUEST,
                invalid_params=schema_utils.serialize(errors))
        try:
            response = PaymentAccountService.create(request_json)
            status = HTTPStatus.ACCEPTED \
                if response.cfs_account_id and response.cfs_account_status == CfsAccountStatus.PENDING.value \
                else HTTPStatus.CREATED
        except BusinessException as exception:
            return exception.response()
        current_app.logger.debug('>Account.post')
        return jsonify(response.asdict()), status
Exemplo n.º 14
0
def test_create_online_credit_account(session):
    """Assert that create credit card account works."""
    credit_account = PaymentAccountService.create(get_basic_account_payload())
    assert credit_account.payment_method == PaymentMethod.DIRECT_PAY.value
    assert credit_account.cfs_account_id is None