Beispiel #1
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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
0
    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 #11
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 #12
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 #13
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 #14
0
    def post():
        """Create routing slip."""
        current_app.logger.info('<RoutingSlips.post')
        request_json = request.get_json()
        # Validate payload.
        valid_format, errors = schema_utils.validate(request_json, 'routing_slip')
        if not valid_format:
            return error_to_response(Error.INVALID_REQUEST, invalid_params=schema_utils.serialize(errors))

        try:
            response, status = RoutingSlipService.create(request_json), HTTPStatus.CREATED
        except (BusinessException, ServiceUnavailableException) as exception:
            return exception.response()

        current_app.logger.debug('>RoutingSlips.post')
        return jsonify(response), status
Beispiel #15
0
    def post():
        """Get routing slip links ;ie parent/child details."""
        current_app.logger.info('<RoutingSlipLink.post')

        request_json = request.get_json()
        valid_format, errors = schema_utils.validate(request_json, 'routing_slip_link_request')
        if not valid_format:
            return error_to_response(Error.INVALID_REQUEST, invalid_params=schema_utils.serialize(errors))

        try:
            response, status = RoutingSlipService.do_link(request_json.get('childRoutingSlipNumber'),
                                                          request_json.get('parentRoutingSlipNumber')), HTTPStatus.OK
        except BusinessException as exception:
            return exception.response()

        current_app.logger.debug('>RoutingSlipLink.post')
        return jsonify(response), status
Beispiel #16
0
    def post():
        """Create the payment records."""
        current_app.logger.info('<Payment.post')
        request_json = request.get_json()
        # Validate the input request
        valid_format, errors = schema_utils.validate(request_json, 'payment_request')
        if not valid_format:
            return jsonify({'code': 'PAY999', 'message': schema_utils.serialize(errors)}), HTTPStatus.BAD_REQUEST

        try:
            response, status = PaymentService.create_payment(request_json,
                                                             g.jwt_oidc_token_info.get('preferred_username',
                                                                                       None)), HTTPStatus.CREATED
        except BusinessException as exception:
            response, status = {'code': exception.code, 'message': exception.message}, exception.status
        current_app.logger.debug('>Payment.post')
        return jsonify(response), status
Beispiel #17
0
    def post(invoice_id):
        """Create the Refund for the Invoice."""
        current_app.logger.info(f'<Refund.post : {invoice_id}')
        request_json = request.get_json(silent=True)
        try:
            valid_format, errors = schema_utils.validate(
                request_json, 'refund') if request_json else (True, None)
            if not valid_format:
                return error_to_response(
                    Error.INVALID_REQUEST,
                    invalid_params=schema_utils.serialize(errors))

            response = RefundService.create_refund(invoice_id, request_json)

        except BusinessException as exception:
            return exception.response()
        current_app.logger.debug(f'>Refund.post : {invoice_id}')
        return jsonify(response), HTTPStatus.ACCEPTED
Beispiel #18
0
    def post():
        """Get routing slips."""
        current_app.logger.info('<RoutingSlips.query.post')
        request_json = request.get_json()
        current_app.logger.debug(request_json)
        # validate the request
        valid_format, errors = schema_utils.validate(request_json, 'routing_slip_search_request')
        if not valid_format:
            return error_to_response(Error.INVALID_REQUEST, invalid_params=schema_utils.serialize(errors))

        # if no page param , return all results
        return_all = not request_json.get('page', None)

        page: int = int(request_json.get('page', '1'))
        limit: int = int(request_json.get('limit', '10'))
        response, status = RoutingSlipService.search(request_json, page,
                                                     limit, return_all=return_all), HTTPStatus.OK
        current_app.logger.debug('>RoutingSlips.query.post')
        return jsonify(response), status
Beispiel #19
0
    def post():
        """Create a new distribution from the payload."""
        request_json = request.get_json()

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

        try:
            response, status = (
                DistributionCodeService.save_or_update(request_json),
                HTTPStatus.CREATED,
            )
        except BusinessException as exception:
            return exception.response()
        return jsonify(response), status
Beispiel #20
0
    def put(account_number: str, product: str):
        """Create or update the account fee settings."""
        current_app.logger.info('<AccountFee.post')
        request_json = request.get_json()
        # Validate the input request
        valid_format, errors = schema_utils.validate(request_json,
                                                     'account_fee')

        if not valid_format:
            return error_to_response(
                Error.INVALID_REQUEST,
                invalid_params=schema_utils.serialize(errors))
        try:
            response, status = PaymentAccountService.save_account_fee(
                account_number, product, request_json), HTTPStatus.OK
        except BusinessException as exception:
            return exception.response()
        current_app.logger.debug('>AccountFee.post')
        return jsonify(response), status
Beispiel #21
0
    def post():
        """Validate the bank account details against CFS."""
        current_app.logger.info('<BankAccounts.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_info')

        if not valid_format:
            return error_to_response(Error.INVALID_REQUEST, invalid_params=schema_utils.serialize(errors))
        try:
            response, status = CFSService.validate_bank_account(request_json), HTTPStatus.OK
        except BusinessException as exception:
            current_app.logger.error(exception)
            return exception.response()
        except ServiceUnavailableException as exception:
            current_app.logger.error(exception)
            return exception.response()
        current_app.logger.debug('>Account.post')
        return jsonify(response), status
Beispiel #22
0
    def post(account_number: str):
        """Create the payment records."""
        current_app.logger.info('<AccountPurchaseReport.post')
        response_content_type = request.headers.get('Accept',
                                                    ContentType.PDF.value)
        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))

        report_name = 'bcregistry-transactions-{}'.format(
            datetime.now().strftime('%m-%d-%Y'))

        if response_content_type == ContentType.PDF.value:
            report_name = f'{report_name}.pdf'
        else:
            report_name = f'{report_name}.csv'

        # 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)

        report = Payment.create_payment_report(account_number, request_json,
                                               response_content_type,
                                               report_name)
        response = Response(report, 201)
        response.headers.set('Content-Disposition',
                             'attachment',
                             filename=report_name)
        response.headers.set('Content-Type', response_content_type)
        response.headers.set('Access-Control-Expose-Headers',
                             'Content-Disposition')
        return response
Beispiel #23
0
    def put(payment_id):
        """Update the payment records."""
        current_app.logger.info('<Payment.put')
        request_json = request.get_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

        try:
            response, status = (
                PaymentService.update_payment(
                    payment_id, request_json, g.jwt_oidc_token_info.get('preferred_username', None)
                ),
                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 #24
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 #25
0
    def post():
        """Create the payment records."""
        current_app.logger.info('<Payment.post')
        request_json = request.get_json()

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

        if not valid_format:
            return jsonify({
                'code': 'PAY999',
                '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'),
                   _jwt,
                   contains_role=EDIT_ROLE)

        try:
            response, status = PaymentService.create_payment(
                request_json,
                g.jwt_oidc_token_info.get('preferred_username',
                                          None)), HTTPStatus.CREATED
        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.post')
        return jsonify(response), status