Esempio n. 1
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
Esempio n. 2
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
Esempio n. 3
0
 def get(account_id: str):
     """Get account payments."""
     current_app.logger.info('<Payments.get')
     # Check if user is authorized to perform this action
     check_auth(business_identifier=None, account_id=account_id, contains_role=MAKE_PAYMENT)
     page: int = int(request.args.get('page', '1'))
     limit: int = int(request.args.get('limit', '10'))
     status: str = request.args.get('status', None)
     response, status = PaymentService.search_account_payments(auth_account_id=account_id, status=status,
                                                               page=page, limit=limit), HTTPStatus.OK
     current_app.logger.debug('>Payments.get')
     return jsonify(response), status
Esempio n. 4
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