Major update
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
from flask import request, jsonify
|
||||
from marshmallow import ValidationError
|
||||
from app.utils.logger import logger
|
||||
from app.api.helpers.response_helper import ResponseHelper
|
||||
from app.api.schemas.transaction_verify import TransactionVerifySchema
|
||||
from app.api.schemas.transaction_verify import TransactionVerifySchema, TransactionVerifyResponseSchema
|
||||
|
||||
|
||||
class TransactionVerifyService:
|
||||
@@ -25,33 +24,54 @@ class TransactionVerifyService:
|
||||
validated_data = schema.load(data) # Raises ValidationError if invalid
|
||||
|
||||
# Simulated processing logic
|
||||
# In a real implementation, this would interact with your business logic
|
||||
# to verify the transaction status
|
||||
|
||||
# For demonstration, we'll simulate different responses based on transaction type
|
||||
transaction_type = validated_data.get('transactionType')
|
||||
|
||||
if transaction_type == "Disbursement":
|
||||
provided_amount = 100.0
|
||||
collected_amount = 0.0
|
||||
result_description = "Disbursement Status retrieved successfully."
|
||||
elif transaction_type == "Collection":
|
||||
provided_amount = 0.0
|
||||
collected_amount = 75.0
|
||||
result_description = "Collection Status retrieved successfully."
|
||||
else: # Penalty
|
||||
provided_amount = 0.0
|
||||
collected_amount = 7.50
|
||||
result_description = "Penalty Status retrieved successfully."
|
||||
|
||||
response_data = {
|
||||
"type": "TransactionCheckResponse",
|
||||
"nativeId": "FBN20191031104405CN621868",
|
||||
"customerId": "CN621868",
|
||||
"accountId": "2017821799",
|
||||
"providedAmount": 0.0,
|
||||
"collectedAmount": 7.50,
|
||||
"requestId": validated_data.get('requestId'),
|
||||
"countryCode": validated_data.get('countryCode'),
|
||||
"transactionId": validated_data.get('transactionId'),
|
||||
"transactionType": transaction_type,
|
||||
"customerId": validated_data.get('customerId'),
|
||||
"accountId": validated_data.get('accountId'),
|
||||
"providedAmount": provided_amount,
|
||||
"collectedAmount": collected_amount,
|
||||
"resultCode": "00",
|
||||
"resultDescription": "Collect Status retrieved successfully."
|
||||
"resultDescription": result_description
|
||||
}
|
||||
|
||||
# Validate the response using the response schema
|
||||
response_schema = TransactionVerifyResponseSchema()
|
||||
validated_response = response_schema.dump(response_data)
|
||||
|
||||
# return ResponseHelper.success(
|
||||
# data=response_data,
|
||||
# message="Transaction verification completed successfully"
|
||||
# )
|
||||
|
||||
return response_data
|
||||
return jsonify(validated_response)
|
||||
|
||||
except ValidationError as err:
|
||||
logger.error(f"Validation Error: {err.messages}")
|
||||
return jsonify({
|
||||
"message": "Validation exception"
|
||||
}) , 422
|
||||
"resultCode": "01",
|
||||
"resultDescription": f"Validation error: {err.messages}"
|
||||
}), 422
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {str(e)}", exc_info=True)
|
||||
return jsonify({
|
||||
"message": "Internal Server Error"
|
||||
}) , 500
|
||||
"resultCode": "08",
|
||||
"resultDescription": f"Error occurred: {str(e)}"
|
||||
}), 500
|
||||
Reference in New Issue
Block a user