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

    rv = client.post(
        '/api/v1/payment-requests',
        data=json.dumps(
            get_payment_request_with_folio_number(folio_number=folio_number)),
        headers=headers)
    assert rv.status_code == 201
    assert rv.json.get('_links') is not None

    assert schema_utils.validate(rv.json, 'invoice')[0]
    assert rv.json.get('folioNumber') == folio_number

    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(get_payment_request()),
                     headers=headers)
    assert rv.status_code == 201
    assert rv.json.get('_links') is not None

    assert schema_utils.validate(rv.json, 'invoice')[0]
    assert rv.json.get('folioNumber') == 'MOCK1234'
Beispiel #2
0
def test_refund_routing_slips_zero_dollar_error(client, jwt):
    """Assert zero dollar refund fails."""
    payload = get_routing_slip_request(cheque_receipt_numbers=[('1234567890', PaymentMethod.CHEQUE.value, 0.00)])
    token = jwt.create_jwt(get_claims(roles=[Role.FAS_CREATE.value, Role.FAS_VIEW.value, Role.FAS_REFUND.value]),
                           token_header)
    headers = {'Authorization': f'Bearer {token}', 'content-type': 'application/json'}

    rv = client.post('/api/v1/fas/routing-slips', data=json.dumps(payload), headers=headers)
    assert rv.status_code == 201
    assert schema_utils.validate(rv.json, 'routing_slip')[0]
    rv = client.get('/api/v1/fas/routing-slips/{}'.format(rv.json.get('number')), headers=headers)
    assert rv.status_code == 200
    assert schema_utils.validate(rv.json, 'routing_slip')[0]
    refund_details = {
        'mailingAddress': {
            'city': 'Gatineau',
            'country': 'CA',
            'region': 'QC',
            'postalCode': 'J8L 2K3',
            'street': 'E-412 Rue Charles',
            'streetAdditional': ''
        },
        'name': 'Staff user'
    }
    rs_number = rv.json.get('number')
    rv = client.post('/api/v1/fas/routing-slips/{}/refunds'.format(rs_number),
                     data=json.dumps({'status': RoutingSlipStatus.REFUND_REQUESTED.value, 'details': refund_details}),
                     headers=headers)
    assert rv.status_code == 400
Beispiel #3
0
def test_refund_routing_slips(client, jwt):
    """Assert refund works for routing slips."""
    payload = get_routing_slip_request()
    token = jwt.create_jwt(get_claims(roles=[Role.FAS_CREATE.value, Role.FAS_VIEW.value, Role.FAS_REFUND.value]),
                           token_header)
    headers = {'Authorization': f'Bearer {token}', 'content-type': 'application/json'}

    rv = client.post('/api/v1/fas/routing-slips', data=json.dumps(payload), headers=headers)
    assert rv.status_code == 201
    assert schema_utils.validate(rv.json, 'routing_slip')[0]
    rv = client.get('/api/v1/fas/routing-slips/{}'.format(rv.json.get('number')), headers=headers)
    assert rv.status_code == 200
    assert schema_utils.validate(rv.json, 'routing_slip')[0]
    refund_details = {
        'mailingAddress': {
            'city': 'Gatineau',
            'country': 'CA',
            'region': 'QC',
            'postalCode': 'J8L 2K3',
            'street': 'E-412 Rue Charles',
            'streetAdditional': ''
        },
        'name': 'Staff user'
    }
    rs_number = rv.json.get('number')
    rv = client.post('/api/v1/fas/routing-slips/{}/refunds'.format(rs_number),
                     data=json.dumps({'status': RoutingSlipStatus.REFUND_REQUESTED.value, 'details': refund_details}),
                     headers=headers)
    assert rv.status_code == 202
    assert rv.json.get('message') == REFUND_SUCCESS_MESSAGES['ROUTINGSLIP.REFUND_REQUESTED']

    rv = client.get('/api/v1/fas/routing-slips/{}'.format(rs_number), headers=headers)
    assert rv.json.get('status') == RoutingSlipStatus.REFUND_REQUESTED.value
    assert RoutingSlipStatus.REFUND_AUTHORIZED.value not in rv.json.get('allowedStatuses')
    refund = rv.json.get('refunds')[0]
    assert refund_details is not None
    assert refund_details.get('name') in refund.get('details').get('name')
    assert refund_details.get('mailingAddress') == refund.get('details').get('mailingAddress')

    rv = client.post('/api/v1/fas/routing-slips/{}/refunds'.format(rs_number),
                     data=json.dumps({'status': RoutingSlipStatus.REFUND_AUTHORIZED.value, 'details': refund_details}),
                     headers=headers)
    assert rv.status_code == 400

    token = jwt.create_jwt(
        get_claims(roles=[Role.FAS_SEARCH.value, Role.FAS_VIEW.value, Role.FAS_REFUND_APPROVER.value]), token_header)
    headers = {'Authorization': f'Bearer {token}', 'content-type': 'application/json'}
    rv = client.post('/api/v1/fas/routing-slips/{}/refunds'.format(rs_number),
                     data=json.dumps({'status': RoutingSlipStatus.REFUND_AUTHORIZED.value, 'details': refund_details}),
                     headers=headers)
    assert rv.status_code == 202
    assert rv.json.get('message') == REFUND_SUCCESS_MESSAGES['ROUTINGSLIP.REFUND_AUTHORIZED']

    rv = client.get('/api/v1/fas/routing-slips/{}'.format(rs_number), headers=headers)
    assert rv.status_code == 200
    assert schema_utils.validate(rv.json, 'routing_slip')[0]
    assert rv.json.get('status') == RoutingSlipStatus.REFUND_AUTHORIZED.value
def test_create_routing_slips(client, jwt, payload):
    """Assert that the endpoint returns 200."""
    token = jwt.create_jwt(get_claims(roles=[Role.FAS_CREATE.value, Role.FAS_VIEW.value]), token_header)
    headers = {'Authorization': f'Bearer {token}', 'content-type': 'application/json'}

    rv = client.post('/api/v1/fas/routing-slips', data=json.dumps(payload), headers=headers)
    assert rv.status_code == 201
    assert schema_utils.validate(rv.json, 'routing_slip')[0]
    rv = client.get('/api/v1/fas/routing-slips/{}'.format(rv.json.get('number')), headers=headers)
    assert rv.status_code == 200
    assert schema_utils.validate(rv.json, 'routing_slip')[0]
    allowed_statuses = rv.json.get('allowedStatuses')
    assert len(allowed_statuses) == len(RoutingSlipStatusTransitionService.STATUS_TRANSITIONS.get('ACTIVE'))
Beispiel #5
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
Beispiel #6
0
def test_refund_routing_slips_reject(client, jwt):
    """Assert refund works for routing slips."""
    payload = get_routing_slip_request()
    token = jwt.create_jwt(
        get_claims(
            roles=[Role.FAS_CREATE.value, Role.FAS_VIEW.value, Role.FAS_REFUND.value, Role.FAS_REFUND_APPROVER.value]),
        token_header)
    headers = {'Authorization': f'Bearer {token}', 'content-type': 'application/json'}

    rv = client.post('/api/v1/fas/routing-slips', data=json.dumps(payload), headers=headers)

    rs_number = rv.json.get('number')
    rv = client.post('/api/v1/fas/routing-slips/{}/refunds'.format(rs_number),
                     data=json.dumps({'status': RoutingSlipStatus.REFUND_REQUESTED.value, }),
                     headers=headers)
    assert rv.json.get('message') == REFUND_SUCCESS_MESSAGES['ROUTINGSLIP.REFUND_REQUESTED']

    rv = client.post('/api/v1/fas/routing-slips/{}/refunds'.format(rs_number),
                     data=json.dumps({'status': RoutingSlipStatus.REFUND_REJECTED.value}),
                     headers=headers)
    assert rv.status_code == 202
    assert rv.json.get('message') == REFUND_SUCCESS_MESSAGES['ROUTINGSLIP.ACTIVE']

    rv = client.get('/api/v1/fas/routing-slips/{}'.format(rs_number), headers=headers)
    assert rv.status_code == 200
    assert schema_utils.validate(rv.json, 'routing_slip')[0]
    assert rv.json.get('status') == RoutingSlipStatus.ACTIVE.value
    assert rv.json.get('refunds') is None
    def post(payment_id, invoice_id=''):
        """Create the Receipt for the Payment."""
        request_json = request.get_json()
        current_app.logger.info('<Receipt.post')
        try:
            valid_format, errors = schema_utils.validate(
                request_json, 'payment_receipt_input')
            if not valid_format:
                return jsonify({
                    'code': 'PAY999',
                    'message': schema_utils.serialize(errors)
                }), HTTPStatus.BAD_REQUEST

            pdf = ReceiptService.create_receipt(payment_id, invoice_id,
                                                request_json)
            current_app.logger.info('<InvoiceReceipt received pdf')
            response = Response(pdf, 201)
            file_name = request_json.get('fileName')
            file_name = 'Coops-Filing' if not file_name else file_name
            response.headers.set('Content-Disposition',
                                 'attachment',
                                 filename='{}.pdf'.format(file_name))
            response.headers.set('Content-Type', 'application/pdf')
            return response

        except BusinessException as exception:
            response, status = {
                'code': exception.code,
                'message': exception.message
            }, exception.status
        current_app.logger.debug('>Transaction.post')
        return jsonify(response), status
Beispiel #8
0
    def put(payment_id):
        """Update the payment records."""
        current_app.logger.info('<Payment.put')
        request_json = request.get_json()
        current_app.logger.debug(request_json)
        # Validate the input request
        valid_format, errors = schema_utils.validate(request_json,
                                                     'payment_request')
        if not valid_format:
            return jsonify({
                'code': 'PAY003',
                'message': schema_utils.serialize(errors)
            }), HTTPStatus.BAD_REQUEST

        # Check if user is authorized to perform this action
        check_auth(request_json.get('businessInfo').get('businessIdentifier'),
                   one_of_roles=[EDIT_ROLE])

        try:
            response, status = (
                PaymentService.update_payment(payment_id, request_json),
                HTTPStatus.OK,
            )
        except BusinessException as exception:
            response, status = {
                'code': exception.code,
                'message': exception.message
            }, exception.status
        except ServiceUnavailableException as exception:
            response, status = {
                'code': exception.status_code
            }, HTTPStatus.BAD_REQUEST
        current_app.logger.debug('>Payment.put')
        return jsonify(response), status
Beispiel #9
0
    def post(account_id):
        """Update the statement settings ."""
        current_app.logger.info('<AccountStatementsNotifications.post')
        request_json = request.get_json()
        valid_format, errors = schema_utils.validate(
            request_json, 'statement_notification_request')
        if not valid_format:
            return error_to_response(
                Error.INVALID_REQUEST,
                invalid_params=schema_utils.serialize(errors))

        current_app.logger.debug(request_json)
        # TODO add valid formatting
        # Check if user is authorized to perform this action
        check_auth(business_identifier=None,
                   account_id=account_id,
                   contains_role=EDIT_ROLE,
                   is_premium=True)

        try:
            StatementRecipients.update_statement_notification_details(
                account_id, request_json)

        except BusinessException as exception:
            return exception.response()
        current_app.logger.debug('>AccountStatementsNotifications.post')
        return jsonify(None), HTTPStatus.CREATED
Beispiel #10
0
    def put(payment_id):
        """Update the payment records."""
        current_app.logger.info('<Payment.put')
        request_json = request.get_json()
        current_app.logger.debug(request_json)
        # Validate the input request
        valid_format, errors = schema_utils.validate(request_json,
                                                     'payment_request')
        if not valid_format:
            return error_to_response(
                Error.INVALID_REQUEST,
                invalid_params=schema_utils.serialize(errors))

        # Check if user is authorized to perform this action
        authorization = check_auth(
            request_json.get('businessInfo').get('businessIdentifier'),
            one_of_roles=[EDIT_ROLE])

        try:
            response, status = (
                PaymentService.update_payment(payment_id, request_json,
                                              authorization),
                HTTPStatus.OK,
            )
        except (BusinessException, ServiceUnavailableException) as exception:
            return exception.response()
        current_app.logger.debug('>Payment.put')
        return jsonify(response), status
Beispiel #11
0
def test_payment_invalid_corp_type(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'
    }
    data = {
        'businessInfo': {
            'businessIdentifier': 'CP0001234',
            'corpType': 'PC',
            'businessName': 'ABC Corp',
            'contactInfo': {
                'city': 'Victoria',
                'postalCode': 'V8P2P2',
                'province': 'BC',
                'addressLine1': '100 Douglas Street',
                'country': 'CA'
            }
        },
        'filingInfo': {
            'filingTypes': [{
                'filingTypeCode': 'OTADD',
                'filingDescription': 'TEST'
            }, {
                'filingTypeCode': 'OTANN'
            }]
        }
    }
    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(data),
                     headers=headers)
    assert rv.status_code == 400
    assert schema_utils.validate(rv.json, 'problem')[0]
Beispiel #12
0
    def post(account_number: str):
        """Create the payment records."""
        current_app.logger.info('<AccountPurchaseHistory.post')
        request_json = request.get_json()
        current_app.logger.debug(request_json)
        # Validate the input request
        valid_format, errors = schema_utils.validate(
            request_json, 'purchase_history_request')
        if not valid_format:
            return error_to_response(
                Error.INVALID_REQUEST,
                invalid_params=schema_utils.serialize(errors))

        # Check if user is authorized to perform this action
        check_auth(business_identifier=None,
                   account_id=account_number,
                   contains_role=EDIT_ROLE,
                   is_premium=True)

        page: int = int(request.args.get('page', '1'))
        limit: int = int(request.args.get('limit', '10'))
        response, status = Payment.search_purchase_history(
            account_number, request_json, page, limit), HTTPStatus.OK
        current_app.logger.debug('>AccountPurchaseHistory.post')
        return jsonify(response), status
Beispiel #13
0
def test_transaction_post_direct_pay(session, client, jwt, app):
    """Assert that the endpoint returns 201."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    # Create a payment first
    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(
                         get_payment_request_with_payment_method(
                             payment_method=PaymentMethod.DIRECT_PAY.value)),
                     headers=headers)
    invoice_id = rv.json.get('id')
    data = {
        'clientSystemUrl':
        'http://localhost:8080/coops-web/transactions/transaction_id=abcd',
        'payReturnUrl': 'http://localhost:8080/pay-web'
    }
    rv = client.post(f'/api/v1/payment-requests/{invoice_id}/transactions',
                     data=json.dumps(data),
                     headers={'content-type': 'application/json'})
    assert rv.status_code == 201
    assert rv.json.get('paymentId')
    assert schema_utils.validate(rv.json, 'transaction')[0]
Beispiel #14
0
    def post(invoice_id: int = None, payment_id: int = None):
        """Create the Transaction records."""
        current_app.logger.info('<Transaction.post')
        request_json = request.get_json()

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

        if not valid_format:
            return error_to_response(
                Error.INVALID_REQUEST,
                invalid_params=schema_utils.serialize(errors))

        try:
            if invoice_id:
                response, status = TransactionService.create_transaction_for_invoice(
                    invoice_id, request_json).asdict(), HTTPStatus.CREATED
            elif payment_id:
                response, status = TransactionService.create_transaction_for_payment(
                    payment_id, request_json).asdict(), HTTPStatus.CREATED

        except BusinessException as exception:
            return exception.response()
        current_app.logger.debug('>Transaction.post')
        return jsonify(response), status
Beispiel #15
0
    def post(payment_id):
        """Create the Transaction records."""
        current_app.logger.info('<Transaction.post')
        request_json = request.get_json()

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

        if not valid_format:
            return jsonify({
                'code': 'PAY007',
                'message': schema_utils.serialize(errors)
            }), HTTPStatus.BAD_REQUEST

        try:
            response, status = TransactionService.create(
                payment_id, request_json).asdict(), HTTPStatus.CREATED
        except BusinessException as exception:
            response, status = {
                'code': exception.code,
                'message': exception.message
            }, exception.status
        current_app.logger.debug('>Transaction.post')
        return jsonify(response), status
Beispiel #16
0
    def post(invoice_id):
        """Create the Receipt for the Invoice."""
        request_json = request.get_json()
        current_app.logger.info('<Receipt.post')
        try:
            valid_format, errors = schema_utils.validate(
                request_json, 'payment_receipt_input')
            if not valid_format:
                return error_to_response(
                    Error.INVALID_REQUEST,
                    invalid_params=schema_utils.serialize(errors))

            pdf = ReceiptService.create_receipt(invoice_id, request_json)
            current_app.logger.info('<InvoiceReceipt received pdf')
            response = Response(pdf, 201)
            file_name = request_json.get('fileName')
            file_name = 'Coops-Filing' if not file_name else file_name
            response.headers.set('Content-Disposition',
                                 'attachment',
                                 filename=f'{file_name}.pdf')
            response.headers.set('Content-Type', 'application/pdf')
            response.headers.set('Access-Control-Expose-Headers',
                                 'Content-Disposition')
            return response

        except BusinessException as exception:
            return exception.response()
        current_app.logger.debug('>Transaction.post')
        return jsonify(response), 200
Beispiel #17
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]
Beispiel #18
0
def test_transaction_get(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 a payment first
    rv = client.post(f'/api/v1/payment-requests',
                     data=json.dumps(get_payment_request()),
                     headers=headers)
    payment_id = rv.json.get('id')
    data = {
        'clientSystemUrl':
        'http://localhost:8080/coops-web/transactions/transaction_id=abcd',
        'payReturnUrl': 'http://localhost:8080/pay-web'
    }
    rv = client.post(f'/api/v1/payment-requests/{payment_id}/transactions',
                     data=json.dumps(data),
                     headers={'content-type': 'application/json'})
    txn_id = rv.json.get('id')
    rv = client.get(
        f'/api/v1/payment-requests/{payment_id}/transactions/{txn_id}',
        headers=headers)
    assert rv.status_code == 200
    assert rv.json.get('paymentId') == payment_id
    assert rv.json.get('id') == txn_id
    assert schema_utils.validate(rv.json, 'transaction')[0]
Beispiel #19
0
def test_transaction_get(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 a payment first
    rv = client.post(f'/api/v1/payment-requests',
                     data=json.dumps(get_payment_request()),
                     headers=headers)
    payment_id = rv.json.get('id')
    redirect_uri = 'http%3A//localhost%3A8080/coops-web/transactions%3Ftransaction_id%3Dabcd'
    rv = client.post(
        f'/api/v1/payment-requests/{payment_id}/transactions?redirect_uri={redirect_uri}',
        data=None,
        headers=headers)
    txn_id = rv.json.get('id')
    rv = client.get(
        f'/api/v1/payment-requests/{payment_id}/transactions/{txn_id}',
        headers=headers)
    assert rv.status_code == 200
    assert rv.json.get('paymentId') == payment_id
    assert rv.json.get('id') == txn_id
    assert schema_utils.validate(rv.json, 'transaction')[0]
Beispiel #20
0
    def put(account_number: str):
        """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.update(account_number,
                                                    request_json)
        except ServiceUnavailableException as exception:
            return exception.response()

        status = HTTPStatus.ACCEPTED \
            if response.cfs_account_id and response.cfs_account_status == CfsAccountStatus.PENDING.value \
            else HTTPStatus.OK

        current_app.logger.debug('>Account.post')
        return jsonify(response.asdict()), status
Beispiel #21
0
    def post():
        """Create the payment records."""
        current_app.logger.info('<Payment.post')
        request_json = request.get_json()
        current_app.logger.debug(request_json)
        # Validate the input request
        valid_format, errors = schema_utils.validate(request_json,
                                                     'payment_request')

        if not valid_format:
            return error_to_response(
                Error.INVALID_REQUEST,
                invalid_params=schema_utils.serialize(errors))

        # Check if user is authorized to perform this action
        business_identifier = get_str_by_path(
            request_json, 'businessInfo/businessIdentifier')
        corp_type_code = get_str_by_path(request_json, 'businessInfo/corpType')

        authorization = check_auth(business_identifier=business_identifier,
                                   corp_type_code=corp_type_code,
                                   contains_role=EDIT_ROLE)
        try:
            response, status = PaymentService.create_payment(
                request_json, authorization), HTTPStatus.CREATED
        except (BusinessException, ServiceUnavailableException) as exception:
            return exception.response()
        current_app.logger.debug('>Payment.post')
        return jsonify(response), status
Beispiel #22
0
    def post(account_id: str):
        """Create account payments."""
        current_app.logger.info('<Payments.post')
        # Check if user is authorized to perform this action
        check_auth(business_identifier=None,
                   account_id=account_id,
                   contains_role=MAKE_PAYMENT)
        # If it's a staff user, then create credits.
        if set([Role.STAFF.value, Role.CREATE_CREDITS.value
                ]).issubset(set(g.jwt_oidc_token_info.get('roles'))):
            credit_request = request.get_json()
            # Valid payment payload.
            valid_format, errors = schema_utils.validate(
                credit_request, 'payment')
            if not valid_format:
                return error_to_response(
                    Error.INVALID_REQUEST,
                    invalid_params=schema_utils.serialize(errors))

            if credit_request.get('paymentMethod') in \
                    (PaymentMethod.EFT.value, PaymentMethod.WIRE.value, PaymentMethod.DRAWDOWN.value):
                response, status = PaymentService.create_payment_receipt(
                    auth_account_id=account_id,
                    credit_request=credit_request).asdict(), HTTPStatus.CREATED
        else:
            is_retry_payment: bool = (request.args.get(
                'retryFailedPayment', 'false').lower() == 'true')

            response, status = PaymentService.create_account_payment(
                auth_account_id=account_id,
                is_retry_payment=is_retry_payment).asdict(), HTTPStatus.CREATED

        current_app.logger.debug('>Payments.post')
        return jsonify(response), status
Beispiel #23
0
    def patch(invoice_id: int = None):
        """Update the payment method for an online banking ."""
        current_app.logger.info('<Invoices.patch for invoice : %s', invoice_id)

        request_json = request.get_json()
        current_app.logger.debug(request_json)
        # Validate the input request
        valid_format, errors = schema_utils.validate(request_json,
                                                     'payment_info')

        is_apply_credit = request.args.get('applyCredit',
                                           'false').lower() == 'true'

        if not valid_format:
            return error_to_response(
                Error.INVALID_REQUEST,
                invalid_params=schema_utils.serialize(errors))

        try:
            response, status = PaymentService.update_invoice(
                invoice_id, request_json, is_apply_credit), HTTPStatus.OK
        except BusinessException as exception:
            return exception.response()
        current_app.logger.debug('>Invoices.post')
        return jsonify(response), status
Beispiel #24
0
def test_payment_put_incomplete_input(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)
    pay_id = rv.json.get('id')

    transaction = factory_payment_transaction(pay_id)
    transaction.save()

    data = {
        'businessInfo': {
            'businessIdentifier': 'CP0001234',
            'corpType': 'CP',
            'businessName': 'ABC Corp',
            'contactInfo': {
                'city': 'Victoria',
                'postalCode': 'V8P2P2',
                'province': 'BC',
                'addressLine1': '100 Douglas Street',
                'country': 'CA'
            }
        }
    }
    rv = client.put(f'/api/v1/payment-requests/{pay_id}',
                    data=json.dumps(data),
                    headers=headers)
    assert rv.status_code == 400
    assert schema_utils.validate(rv.json, 'problem')[0]
Beispiel #25
0
def test_fees_with_corp_type_and_filing_type_with_invalid_start_date(session, client, jwt, app):
    """Assert that the endpoint returns 400."""
    # Insert a record first and then query for it
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {'Authorization': f'Bearer {token}', 'content-type': 'application/json'}

    corp_type = 'XX'
    filing_type_code = 'XOTANN'
    now = date.today()
    factory_fee_schedule_model(
        factory_filing_type_model('XOTANN', 'TEST'),
        factory_corp_type_model('XX', 'TEST'),
        factory_fee_model('XXX', 100),
        now + timedelta(1))
    rv = client.get(f'/api/v1/fees/{corp_type}/{filing_type_code}?valid_date={now}', headers=headers)
    assert rv.status_code == 400
    assert schema_utils.validate(rv.json, 'error')[0]
    assert not schema_utils.validate(rv.json, 'fees')[0]
Beispiel #26
0
def test_fees_with_corp_type_and_filing_type(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'}
    corp_type = 'XX'
    filing_type_code = 'XOTANN'
    factory_fee_schedule_model(
        factory_filing_type_model('XOTANN', 'TEST'),
        factory_corp_type_model('XX', 'TEST'),
        factory_fee_model('XXX', 100))
    rv = client.get(f'/api/v1/fees/{corp_type}/{filing_type_code}', headers=headers)
    assert rv.status_code == 200
    assert schema_utils.validate(rv.json, 'fees')[0]
Beispiel #27
0
    def post(routing_slip_number: str):
        """Create comment for a slip."""
        current_app.logger.info('<Comment.post.request')
        request_json = request.get_json()
        # Validate payload.
        try:
            valid_format, errors = schema_utils.validate(request_json, 'comment')
            if valid_format:
                comment = request_json.get('comment')
            else:
                valid_format, errors = schema_utils.validate(request_json, 'comment_bcrs_schema')
                if valid_format:
                    comment = request_json.get('comment').get('comment')
                else:
                    return error_to_response(Error.INVALID_REQUEST, invalid_params=schema_utils.serialize(errors))
            if comment:
                response, status = \
                    CommentService.create(comment_value=comment, rs_number=routing_slip_number), HTTPStatus.CREATED
        except (BusinessException, ServiceUnavailableException) as exception:
            return exception.response()

        current_app.logger.debug('>Comment.post.request')
        return jsonify(response), status
Beispiel #28
0
def test_bcol_payment_creation_by_system(session, client, jwt, app):
    """Assert that the endpoint returns 201."""
    token = jwt.create_jwt(
        get_claims(roles=['system'],
                   username='******',
                   login_source=None), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }
    dat_number: str = 'C1234567890'
    payload = {
        'accountInfo': {
            'datNumber': dat_number,
            'bcolAccountNumber': '000000'
        },
        'businessInfo': {
            'businessIdentifier': 'CP0002000',
            'corpType': 'CP',
            'businessName': 'ABC Corp',
            'contactInfo': {
                'city': 'Victoria',
                'postalCode': 'V8P2P2',
                'province': 'BC',
                'addressLine1': '100 Douglas Street',
                'country': 'CA'
            }
        },
        'filingInfo': {
            'filingTypes': [{
                'filingTypeCode': 'OTADD',
                'filingDescription': 'TEST'
            }, {
                'filingTypeCode': 'OTANN'
            }],
            'folioNumber':
            'TEST'
        }
    }

    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(payload),
                     headers=headers)
    assert rv.status_code == 201
    assert rv.json.get('datNumber') == dat_number
    assert rv.json.get('paymentMethod') == 'DRAWDOWN'

    assert not rv.json.get('isPaymentActionRequired')

    assert schema_utils.validate(rv.json, 'invoice')[0]
Beispiel #29
0
def test_create_comment_with_invalid_comment_bcrs_schema(client, jwt):
    """Assert that the endpoint returns 201 for valid comment schema."""
    token = jwt.create_jwt(get_claims(roles=[Role.FAS_CREATE.value, Role.FAS_VIEW.value]), token_header)
    headers = {'Authorization': f'Bearer {token}', 'content-type': 'application/json'}

    rv = client.post('/api/v1/fas/routing-slips', data=json.dumps(get_routing_slip_request()), headers=headers)
    assert rv.status_code == 201
    assert schema_utils.validate(rv.json, 'routing_slip')[0]

    rv = client.post('/api/v1/fas/routing-slips/{}/comments'.format(rv.json.get('number')),
                     data=json.dumps({'comment': {'businessId': 'test'}}),
                     headers=headers)
    assert rv.json.get('type') == 'INVALID_REQUEST'
    assert rv.status_code == 400
Beispiel #30
0
def test_zero_dollar_payment_creation_with_waive_fees_unauthorized(
        session, client, jwt, app):
    """Assert that the endpoint returns 201."""
    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_waive_fees_payment_request()),
                     headers=headers)

    assert rv.status_code == 401
    assert schema_utils.validate(rv.json, 'problem')[0]