def delete(payment_id): """Soft delete the payment records.""" current_app.logger.info('<Payment.delete') try: PaymentService.accept_delete(payment_id) response, status = None, HTTPStatus.ACCEPTED except BusinessException as exception: return exception.response() current_app.logger.debug('>Payment.delete') return jsonify(response), status
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
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
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
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
def get(payment_id): """Get the payment records.""" try: response, status = PaymentService.get_payment(payment_id), HTTPStatus.OK except BusinessException as exception: response, status = {'code': exception.code, 'message': exception.message}, exception.status return jsonify(response), status
def get(payment_id): """Get the payment records.""" try: response, status = PaymentService.get_payment( payment_id), HTTPStatus.OK except BusinessException as exception: return exception.response() return jsonify(response), status
def delete_marked_payments(app): """Update stale payment records. This is to handle edge cases where the user has completed payment and some error occured and payment status is not up-to-date. """ invoices_to_delete = InvoiceModel.find_invoices_marked_for_delete() if len(invoices_to_delete) == 0: app.logger.info( f'Delete Invoice Job Ran at {datetime.datetime.now()}.But No records found!' ) for invoice in invoices_to_delete: try: app.logger.info( 'Delete Payment Job found records.Payment Id: {}'.format( invoice.id)) PaymentService.delete_invoice(invoice.id) app.logger.info( 'Delete Payment Job Updated records.Payment Id: {}'.format( invoice.id)) except BusinessException as err: # just catch and continue .Don't stop app.logger.error('Error on delete_payment') app.logger.error(err)
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
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
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