Major update
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
from app.api.services.rac_check import RACCheckService
|
||||
from app.api.services.disbursement import DisbursementService
|
||||
from app.api.services.select_offer import SelectOfferService
|
||||
from app.api.services.provide_loan import ProvideLoanService
|
||||
from app.api.services.loan_status import LoanStatusService
|
||||
from app.api.services.repayment import RepaymentService
|
||||
from app.api.services.collect_loan import CollectLoanService
|
||||
from app.api.services.rac_check import RACCheckService
|
||||
from app.api.services.transaction_verify import TransactionVerifyService
|
||||
from app.api.services.penal_charge import PenalChargeService
|
||||
from app.api.services.revoke_enable_consent import RevokeEnableConsentService
|
||||
from app.api.services.token_validation import TokenValidationService
|
||||
from app.api.services.lien_check import LienCheckService
|
||||
from app.api.services.new_transaction_check import NewTransactionCheckService
|
||||
from app.api.services.repayment import RepaymentService
|
||||
from app.api.services.status_call import StatusCallService
|
||||
from app.api.services.status_call import StatusCallService
|
||||
from app.api.services.sms import SMSService
|
||||
from app.api.services.bulk_sms import BulkSMSService
|
||||
|
||||
# from app.api.services.revoke_enable_consent import RevokeEnableConsentService
|
||||
# from app.api.services.token_validation import TokenValidationService
|
||||
# from app.api.services.new_transaction_check import NewTransactionCheckService
|
||||
# from app.api.services.status_call import StatusCallService
|
||||
@@ -0,0 +1,78 @@
|
||||
from flask import request, jsonify
|
||||
from marshmallow import ValidationError
|
||||
from app.utils.logger import logger
|
||||
from app.api.schemas.bulk_sms import BulkSMSSchema, BulkSMSResponseSchema
|
||||
|
||||
|
||||
class BulkSMSService:
|
||||
@staticmethod
|
||||
def process_request(data):
|
||||
"""
|
||||
Process the BulkSMS request.
|
||||
|
||||
Args:
|
||||
data (list): The request data as a list of SMS items.
|
||||
|
||||
Returns:
|
||||
dict: A standardized response.
|
||||
"""
|
||||
try:
|
||||
logger.info("Processing BulkSMS request")
|
||||
|
||||
# Check if the data is a list and not too large
|
||||
if not isinstance(data, list):
|
||||
return jsonify({
|
||||
"data": "",
|
||||
"statusCode": 400,
|
||||
"IsSuccessful": False,
|
||||
"errorMessage": "Request must be a list of SMS items"
|
||||
}), 400
|
||||
|
||||
if len(data) > 20:
|
||||
return jsonify({
|
||||
"data": "",
|
||||
"statusCode": 400,
|
||||
"IsSuccessful": False,
|
||||
"errorMessage": "Maximum of 20 SMS items allowed"
|
||||
}), 400
|
||||
|
||||
# Validate each item in the list
|
||||
schema = BulkSMSSchema()
|
||||
# We need to wrap the list in a dictionary with a key that matches the schema field name
|
||||
validated_data = schema.load({"_schema": data}) # Raises ValidationError if invalid
|
||||
|
||||
# Simulated processing logic
|
||||
# In a real implementation, this would interact with your business logic
|
||||
# to send bulk SMS messages to customers
|
||||
|
||||
# For demonstration, we'll simulate a successful bulk SMS send
|
||||
response_data = {
|
||||
"data": "",
|
||||
"statusCode": 200,
|
||||
"IsSuccessful": True,
|
||||
"errorMessage": None
|
||||
}
|
||||
|
||||
# Validate the response using the response schema
|
||||
response_schema = BulkSMSResponseSchema()
|
||||
validated_response = response_schema.dump(response_data)
|
||||
|
||||
return jsonify(validated_response)
|
||||
|
||||
except ValidationError as err:
|
||||
logger.error(f"Validation Error: {err.messages}")
|
||||
return jsonify({
|
||||
"data": "",
|
||||
"statusCode": 400,
|
||||
"IsSuccessful": False,
|
||||
"errorMessage": f"Validation error: {err.messages}"
|
||||
}), 400
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {str(e)}", exc_info=True)
|
||||
return jsonify({
|
||||
"data": "",
|
||||
"statusCode": 500,
|
||||
"IsSuccessful": False,
|
||||
"errorMessage": f"Error occurred: {str(e)}"
|
||||
}), 500
|
||||
@@ -1,8 +1,8 @@
|
||||
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.collect_loan import CollectLoanSchema
|
||||
from app.api.schemas.collect_loan import CollectLoanSchema, CollectLoanResponseSchema
|
||||
|
||||
|
||||
class CollectLoanService:
|
||||
@staticmethod
|
||||
@@ -21,41 +21,47 @@ class CollectLoanService:
|
||||
|
||||
# Validate input data using CollectLoanSchema
|
||||
schema = CollectLoanSchema()
|
||||
validated_data = schema.load(data)
|
||||
validated_data = schema.load(data) # Raises ValidationError if invalid
|
||||
|
||||
# Simulated processing logic
|
||||
# In a real implementation, this would interact with your business logic
|
||||
# to process the loan collection
|
||||
|
||||
# For demonstration, we'll simulate a partial collection
|
||||
collect_amount = validated_data.get('collectAmount') * 0.75 # 75% of requested amount
|
||||
lien_amount = validated_data.get('lienAmount') * 0.25 # 25% of requested amount as lien
|
||||
|
||||
response_data = {
|
||||
"transactionId": "T002",
|
||||
"debtId": "273194670",
|
||||
"customerId": "CN621868",
|
||||
"accountId": "2017821799",
|
||||
"productId": "101",
|
||||
"collectAmount": 60000.00,
|
||||
"penalCharge": 0,
|
||||
"lienAmount": 20000,
|
||||
"countryId": "01",
|
||||
"comment": "Testing CollectionLoanRequest",
|
||||
"transactionId": validated_data.get('transactionId'),
|
||||
"debtId": validated_data.get('debtId'),
|
||||
"customerId": validated_data.get('customerId'),
|
||||
"accountId": validated_data.get('accountId'),
|
||||
"productId": validated_data.get('productId'),
|
||||
"collectAmount": collect_amount,
|
||||
"penalCharge": validated_data.get('penalCharge', 0),
|
||||
"lienAmount": lien_amount,
|
||||
"countryId": validated_data.get('countryId'),
|
||||
"comment": validated_data.get('comment', ""),
|
||||
"resultCode": "00",
|
||||
"resultDescription": "Loan Collection Successful"
|
||||
}
|
||||
|
||||
# Validate the response using the response schema
|
||||
response_schema = CollectLoanResponseSchema()
|
||||
validated_response = response_schema.dump(response_data)
|
||||
|
||||
# return ResponseHelper.success(
|
||||
# data=response_data,
|
||||
# message="Loan collection 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
|
||||
@@ -1,8 +1,8 @@
|
||||
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.lien_check import LienCheckSchema
|
||||
from flask import request, jsonify
|
||||
from app.api.schemas.lien_check import LienCheckSchema, LienCheckResponseSchema
|
||||
|
||||
|
||||
class LienCheckService:
|
||||
@staticmethod
|
||||
@@ -23,29 +23,33 @@ class LienCheckService:
|
||||
schema = LienCheckSchema()
|
||||
validated_data = schema.load(data) # Raises ValidationError if invalid
|
||||
|
||||
# Simulated lien check logic
|
||||
# Simulated processing logic
|
||||
# In a real implementation, this would interact with your business logic
|
||||
# to check the lien amount on the account
|
||||
|
||||
# For demonstration, we'll simulate a lien amount of 20000.0
|
||||
response_data = {
|
||||
"lienAmount": 20000.0,
|
||||
"resultCode": "00",
|
||||
"resultDescription": "Successful"
|
||||
}
|
||||
|
||||
# Validate the response using the response schema
|
||||
response_schema = LienCheckResponseSchema()
|
||||
validated_response = response_schema.dump(response_data)
|
||||
|
||||
# return ResponseHelper.success(
|
||||
# data=response_data,
|
||||
# message="Lien check 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
|
||||
@@ -0,0 +1,77 @@
|
||||
from flask import request, jsonify
|
||||
from marshmallow import ValidationError
|
||||
from app.utils.logger import logger
|
||||
from app.api.schemas.loan_status import LoanStatusSchema, LoanStatusResponseSchema
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
|
||||
class LoanStatusService:
|
||||
@staticmethod
|
||||
def process_request(data):
|
||||
"""
|
||||
Process the LoanStatus request.
|
||||
|
||||
Args:
|
||||
data (dict): The request data.
|
||||
|
||||
Returns:
|
||||
dict: A standardized response.
|
||||
"""
|
||||
try:
|
||||
logger.info("Processing LoanStatus request")
|
||||
|
||||
# Validate input data using LoanStatusSchema
|
||||
schema = LoanStatusSchema()
|
||||
validated_data = schema.load(data) # Raises ValidationError if invalid
|
||||
|
||||
# Simulated processing logic
|
||||
# In a real implementation, this would interact with your business logic
|
||||
# to retrieve the customer's loan status
|
||||
|
||||
# For demonstration, we'll create a sample response with one loan
|
||||
# In a real implementation, you would query your database for actual loan data
|
||||
current_date = datetime.now()
|
||||
loan_date = (current_date - timedelta(days=30)).strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
|
||||
due_date = (current_date + timedelta(days=30)).strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
|
||||
|
||||
# Sample loan data
|
||||
loan_data = {
|
||||
"debtId": "123456789",
|
||||
"loanDate": loan_date,
|
||||
"dueDate": due_date,
|
||||
"currentLoanAmount": 8500.0,
|
||||
"initialLoanAmount": 10000.0,
|
||||
"defaultPenaltyFee": 0.0,
|
||||
"continuousFee": 0.0,
|
||||
"productId": "101"
|
||||
}
|
||||
|
||||
# Create response with the loan data
|
||||
response_data = {
|
||||
"customerId": validated_data.get('customerId'),
|
||||
"transactionId": validated_data.get('transactionId'),
|
||||
"loans": [loan_data], # Array with one loan
|
||||
"totalDebtAmount": 8500.0, # Same as currentLoanAmount for this example
|
||||
"resultCode": "00",
|
||||
"resultDescription": "Successful"
|
||||
}
|
||||
|
||||
# Validate the response using the response schema
|
||||
response_schema = LoanStatusResponseSchema()
|
||||
validated_response = response_schema.dump(response_data)
|
||||
|
||||
return jsonify(validated_response)
|
||||
|
||||
except ValidationError as err:
|
||||
logger.error(f"Validation Error: {err.messages}")
|
||||
return jsonify({
|
||||
"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({
|
||||
"resultCode": "08",
|
||||
"resultDescription": f"Error occurred: {str(e)}"
|
||||
}), 500
|
||||
@@ -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.penal_charge import PenalChargeSchema
|
||||
from app.api.schemas.penal_charge import PenalChargeSchema, PenalChargeResponseSchema
|
||||
|
||||
|
||||
class PenalChargeService:
|
||||
@@ -25,27 +24,31 @@ class PenalChargeService:
|
||||
validated_data = schema.load(data) # Raises ValidationError if invalid
|
||||
|
||||
# Simulated processing logic
|
||||
# In a real implementation, this would interact with your business logic
|
||||
# to process the penal charge
|
||||
|
||||
# For demonstration, we'll simulate a successful penal charge
|
||||
response_data = {
|
||||
"resultCode": "00",
|
||||
"resultDescription": "Penal charge debited successfully"
|
||||
}
|
||||
|
||||
# Validate the response using the response schema
|
||||
response_schema = PenalChargeResponseSchema()
|
||||
validated_response = response_schema.dump(response_data)
|
||||
|
||||
# return ResponseHelper.success(
|
||||
# data=response_data,
|
||||
# message="Penal charge applied 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
|
||||
@@ -0,0 +1,56 @@
|
||||
from flask import request, jsonify
|
||||
from marshmallow import ValidationError
|
||||
from app.utils.logger import logger
|
||||
from app.api.schemas.provide_loan import ProvideLoanSchema, ProvideLoanResponseSchema
|
||||
|
||||
class ProvideLoanService:
|
||||
@staticmethod
|
||||
def process_request(data):
|
||||
"""
|
||||
Process the ProvideLoan request.
|
||||
|
||||
Args:
|
||||
data (dict): The request data.
|
||||
|
||||
Returns:
|
||||
dict: A standardized response.
|
||||
"""
|
||||
try:
|
||||
logger.info("Processing ProvideLoan request")
|
||||
|
||||
# Validate input data using ProvideLoanSchema
|
||||
schema = ProvideLoanSchema()
|
||||
validated_data = schema.load(data) # Raises ValidationError if invalid
|
||||
|
||||
# Simulated processing logic
|
||||
# In a real implementation, this would interact with your business logic
|
||||
# to process the loan provision request
|
||||
response_data = {
|
||||
"requestId": validated_data.get('requestId', f"REQ-{validated_data.get('transactionId')}"),
|
||||
"transactionId": validated_data.get('transactionId'),
|
||||
"customerId": validated_data.get('customerId'),
|
||||
"accountId": validated_data.get('accountId'),
|
||||
"msisdn": validated_data.get('msisdn', ""),
|
||||
"resultCode": "00",
|
||||
"resultDescription": "Successful"
|
||||
}
|
||||
|
||||
# Validate the response using the response schema
|
||||
response_schema = ProvideLoanResponseSchema()
|
||||
validated_response = response_schema.dump(response_data)
|
||||
|
||||
return jsonify(validated_response)
|
||||
|
||||
except ValidationError as err:
|
||||
logger.error(f"Validation Error: {err.messages}")
|
||||
return jsonify({
|
||||
"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({
|
||||
"resultCode": "08",
|
||||
"resultDescription": f"Error occurred: {str(e)}"
|
||||
}), 500
|
||||
@@ -1,8 +1,8 @@
|
||||
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.rac_check import RACCheckSchema
|
||||
from app.api.schemas.rac_check import RACCheckSchema, RACCheckResponseSchema
|
||||
|
||||
|
||||
class RACCheckService:
|
||||
@staticmethod
|
||||
@@ -24,40 +24,49 @@ class RACCheckService:
|
||||
validated_data = schema.load(data) # Raises ValidationError if invalid
|
||||
|
||||
# Simulated processing logic
|
||||
# In a real implementation, this would interact with your business logic
|
||||
# to check the RAC criteria
|
||||
|
||||
# For demonstration, we'll simulate all checks passing
|
||||
rac_response = {
|
||||
"Salary account": "1",
|
||||
"BVN": "1",
|
||||
"BVNAttachedToAccount": "1",
|
||||
"CRMS": "1",
|
||||
"CRC": "1",
|
||||
"AccountStatus": "1",
|
||||
"Lien": "1",
|
||||
"NoBouncedCheck": "1",
|
||||
"Whitelist": "1",
|
||||
"NoPastDueSalaryLoan": "1",
|
||||
"NoPastDueOtherLoan": "1"
|
||||
}
|
||||
|
||||
response_data = {
|
||||
"transactionId": validated_data.get('transactionId'),
|
||||
"customerId": validated_data.get('customerId'),
|
||||
"accountId": validated_data.get('accountId'),
|
||||
"RACResponse": rac_response,
|
||||
"resultCode": "00",
|
||||
"RACResponse": {
|
||||
"SalaryAccount": "1",
|
||||
"BVN": "1",
|
||||
"BVNAttachedToAccount": "1",
|
||||
"CRMS": "1",
|
||||
"CRC": "1",
|
||||
"AccountStatus": "1",
|
||||
"Lien": "1",
|
||||
"NoBouncedCheck": "1",
|
||||
"Whitelist": "1",
|
||||
"NoPastDueSalaryLoan": "1",
|
||||
"NoPastDueOtherLoan": "1"
|
||||
},
|
||||
"resultDescription": "RAC Check Successful"
|
||||
}
|
||||
|
||||
# Validate the response using the response schema
|
||||
response_schema = RACCheckResponseSchema()
|
||||
validated_response = response_schema.dump(response_data)
|
||||
|
||||
# return ResponseHelper.success(
|
||||
# data=response_data,
|
||||
# message="RAC check 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
|
||||
@@ -1,64 +1,68 @@
|
||||
from flask import jsonify
|
||||
from flask import request, jsonify
|
||||
from marshmallow import ValidationError
|
||||
from app.utils.logger import logger
|
||||
from app.api.schemas.repayment import RepaymentSchema, RepaymentResponseSchema
|
||||
|
||||
|
||||
class RepaymentService:
|
||||
@staticmethod
|
||||
def process_request(data):
|
||||
"""
|
||||
Process a repayment request from Simbrella to FirstBank
|
||||
Process the Repayment request.
|
||||
|
||||
Args:
|
||||
data (dict): The request data containing repayment details
|
||||
data (dict): The request data.
|
||||
|
||||
Returns:
|
||||
flask.Response: JSON response with the result of the repayment operation
|
||||
dict: A standardized response.
|
||||
"""
|
||||
try:
|
||||
# Log the incoming request
|
||||
logger.info(f"Processing repayment request: {data}")
|
||||
logger.info("Processing Repayment request")
|
||||
|
||||
# Validate required fields
|
||||
required_fields = [
|
||||
"requestId", "countryCode", "transactionId", "debtId",
|
||||
"customerId", "accountId", "productId", "collectAmount",
|
||||
"collectionMethod", "lienAmount"
|
||||
]
|
||||
# Validate input data using RepaymentSchema
|
||||
schema = RepaymentSchema()
|
||||
validated_data = schema.load(data) # Raises ValidationError if invalid
|
||||
|
||||
for field in required_fields:
|
||||
if field not in data:
|
||||
logger.error(f"Missing required field: {field}")
|
||||
return jsonify({
|
||||
"resultCode": "01",
|
||||
"resultDescription": f"Missing required field: {field}"
|
||||
}), 400
|
||||
# Simulated processing logic
|
||||
# In a real implementation, this would interact with your business logic
|
||||
# to process the repayment
|
||||
|
||||
# Process the repayment request
|
||||
# This is where you would implement the actual business logic
|
||||
# For now, we'll just return a successful response
|
||||
# For demonstration, we'll simulate a partial repayment
|
||||
collected_amount = validated_data.get('collectedAmount') * 0.75 # 75% of requested amount
|
||||
lien_amount = validated_data.get('lienAmount') * 0.25 # 25% of requested amount as lien
|
||||
|
||||
response = {
|
||||
"requestId": data.get("requestId"),
|
||||
"countryCode": data.get("countryCode"),
|
||||
"transactionId": data.get("transactionId"),
|
||||
"debtId": data.get("debtId"),
|
||||
"customerId": data.get("customerId"),
|
||||
"accountId": data.get("accountId"),
|
||||
"productId": data.get("productId"),
|
||||
"collectAmount": data.get("collectAmount"),
|
||||
"penalCharge": data.get("penalCharge", 0),
|
||||
"lienAmount": data.get("lienAmount"),
|
||||
"comment": data.get("comment", ""),
|
||||
response_data = {
|
||||
"requestId": validated_data.get('requestId'),
|
||||
"countryCode": validated_data.get('countryCode'),
|
||||
"transactionId": validated_data.get('transactionId'),
|
||||
"debtId": validated_data.get('debtId'),
|
||||
"customerId": validated_data.get('customerId'),
|
||||
"accountId": validated_data.get('accountId'),
|
||||
"productId": validated_data.get('productId'),
|
||||
"collectedAmount": collected_amount,
|
||||
"penalCharge": validated_data.get('penalCharge', 0),
|
||||
"lienAmount": lien_amount,
|
||||
"comment": validated_data.get('comment', ""),
|
||||
"resultCode": "00",
|
||||
"resultDescription": "Loan Collection Successful"
|
||||
}
|
||||
|
||||
logger.info(f"Repayment response: {response}")
|
||||
return jsonify(response)
|
||||
# Validate the response using the response schema
|
||||
response_schema = RepaymentResponseSchema()
|
||||
validated_response = response_schema.dump(response_data)
|
||||
|
||||
return jsonify(validated_response)
|
||||
|
||||
except ValidationError as err:
|
||||
logger.error(f"Validation Error: {err.messages}")
|
||||
return jsonify({
|
||||
"resultCode": "01",
|
||||
"resultDescription": f"Validation error: {err.messages}"
|
||||
}), 422
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error processing repayment request: {str(e)}")
|
||||
logger.error(f"An error occurred: {str(e)}", exc_info=True)
|
||||
return jsonify({
|
||||
"resultCode": "08",
|
||||
"resultDescription": "Error occurred"
|
||||
"resultDescription": f"Error occurred: {str(e)}"
|
||||
}), 500
|
||||
@@ -0,0 +1,60 @@
|
||||
from flask import request, jsonify
|
||||
from marshmallow import ValidationError
|
||||
from app.utils.logger import logger
|
||||
from app.api.schemas.sms import SMSSchema, SMSResponseSchema
|
||||
|
||||
|
||||
class SMSService:
|
||||
@staticmethod
|
||||
def process_request(data):
|
||||
"""
|
||||
Process the SMS request.
|
||||
|
||||
Args:
|
||||
data (dict): The request data.
|
||||
|
||||
Returns:
|
||||
dict: A standardized response.
|
||||
"""
|
||||
try:
|
||||
logger.info("Processing SMS request")
|
||||
|
||||
# Validate input data using SMSSchema
|
||||
schema = SMSSchema()
|
||||
validated_data = schema.load(data) # Raises ValidationError if invalid
|
||||
|
||||
# Simulated processing logic
|
||||
# In a real implementation, this would interact with your business logic
|
||||
# to send an SMS to the customer
|
||||
|
||||
# For demonstration, we'll simulate a successful SMS send
|
||||
response_data = {
|
||||
"data": "",
|
||||
"statusCode": 200,
|
||||
"IsSuccessful": True,
|
||||
"errorMessage": None
|
||||
}
|
||||
|
||||
# Validate the response using the response schema
|
||||
response_schema = SMSResponseSchema()
|
||||
validated_response = response_schema.dump(response_data)
|
||||
|
||||
return jsonify(validated_response)
|
||||
|
||||
except ValidationError as err:
|
||||
logger.error(f"Validation Error: {err.messages}")
|
||||
return jsonify({
|
||||
"data": "",
|
||||
"statusCode": 400,
|
||||
"IsSuccessful": False,
|
||||
"errorMessage": f"Validation error: {err.messages}"
|
||||
}), 400
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {str(e)}", exc_info=True)
|
||||
return jsonify({
|
||||
"data": "",
|
||||
"statusCode": 500,
|
||||
"IsSuccessful": False,
|
||||
"errorMessage": f"Error occurred: {str(e)}"
|
||||
}), 500
|
||||
@@ -1,84 +1,77 @@
|
||||
from flask import jsonify
|
||||
from flask import request, jsonify
|
||||
from marshmallow import ValidationError
|
||||
from app.utils.logger import logger
|
||||
from app.api.schemas.status_call import StatusCallSchema, StatusCallResponseSchema
|
||||
|
||||
|
||||
class StatusCallService:
|
||||
@staticmethod
|
||||
def process_request(data):
|
||||
"""
|
||||
Process a status call request to check transaction status
|
||||
Process the StatusCall request.
|
||||
|
||||
Args:
|
||||
data (dict): The request data containing transaction details to check
|
||||
data (dict): The request data.
|
||||
|
||||
Returns:
|
||||
flask.Response: JSON response with the status of the transaction
|
||||
dict: A standardized response.
|
||||
"""
|
||||
try:
|
||||
# Log the incoming request
|
||||
logger.info(f"Processing status call request: {data}")
|
||||
logger.info("Processing StatusCall request")
|
||||
|
||||
# Validate required fields
|
||||
required_fields = [
|
||||
"transactionId", "transactionType", "customerId"
|
||||
]
|
||||
# Validate input data using StatusCallSchema
|
||||
schema = StatusCallSchema()
|
||||
validated_data = schema.load(data) # Raises ValidationError if invalid
|
||||
|
||||
for field in required_fields:
|
||||
if field not in data:
|
||||
logger.error(f"Missing required field: {field}")
|
||||
return jsonify({
|
||||
"resultCode": "01",
|
||||
"resultDescription": f"Missing required field: {field}"
|
||||
}), 400
|
||||
# Simulated processing logic
|
||||
# In a real implementation, this would interact with your business logic
|
||||
# to check the status of a transaction
|
||||
|
||||
# Process the status call request based on transaction type
|
||||
transaction_type = data.get("transactionType")
|
||||
# For demonstration, we'll simulate different responses based on transaction type
|
||||
transaction_type = validated_data.get('transactionType')
|
||||
|
||||
# Prepare the response based on transaction type
|
||||
if transaction_type == "Disbursement":
|
||||
status = {
|
||||
"providedAmount": 1000.00,
|
||||
"collectedAmount": 0.00,
|
||||
"resultCode": "00",
|
||||
"resultDescription": "Loan Provision is successful"
|
||||
}
|
||||
provided_amount = 1000.00
|
||||
collected_amount = 0.00
|
||||
inner_result_description = "Loan Provision is successful"
|
||||
elif transaction_type == "Collection":
|
||||
status = {
|
||||
"providedAmount": 0.00,
|
||||
"collectedAmount": 100.00,
|
||||
"resultCode": "00",
|
||||
"resultDescription": "Loan Collection is successful"
|
||||
}
|
||||
elif transaction_type == "PenalCharge":
|
||||
status = {
|
||||
"transactionId": data.get("transactionId"),
|
||||
"providedAmount": 0.00,
|
||||
"collectedAmount": 100.00,
|
||||
"resultCode": "00",
|
||||
"resultDescription": "Penal Charge is successful"
|
||||
}
|
||||
else:
|
||||
logger.error(f"Invalid transaction type: {transaction_type}")
|
||||
return jsonify({
|
||||
"resultCode": "01",
|
||||
"resultDescription": f"Invalid transaction type: {transaction_type}"
|
||||
}), 400
|
||||
provided_amount = 0.00
|
||||
collected_amount = 1050.00
|
||||
inner_result_description = "Loan Collection is successful"
|
||||
else: # PenalCharge
|
||||
provided_amount = 0.00
|
||||
collected_amount = 50.00
|
||||
inner_result_description = "Penal Charge is successful"
|
||||
|
||||
response = {
|
||||
"requestId": data.get("requestId", ""),
|
||||
"countryCode": data.get("countryCode", "NGR"),
|
||||
"transactionId": data.get("transactionId"),
|
||||
"Status": status,
|
||||
response_data = {
|
||||
"transactionId": "24110114545374721", # This would be generated in a real system
|
||||
"data": {
|
||||
"transactionId": validated_data.get('transactionId'),
|
||||
"providedAmount": provided_amount,
|
||||
"collectedAmount": collected_amount,
|
||||
"resultCode": "00",
|
||||
"resultDescription": inner_result_description
|
||||
},
|
||||
"resultCode": "00",
|
||||
"resultDescription": "SUCCESS"
|
||||
}
|
||||
|
||||
logger.info(f"Status call response: {response}")
|
||||
return jsonify(response)
|
||||
# Validate the response using the response schema
|
||||
response_schema = StatusCallResponseSchema()
|
||||
validated_response = response_schema.dump(response_data)
|
||||
|
||||
return jsonify(validated_response)
|
||||
|
||||
except ValidationError as err:
|
||||
logger.error(f"Validation Error: {err.messages}")
|
||||
return jsonify({
|
||||
"resultCode": "01",
|
||||
"resultDescription": f"Validation error: {err.messages}"
|
||||
}), 422
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error processing status call request: {str(e)}")
|
||||
logger.error(f"An error occurred: {str(e)}", exc_info=True)
|
||||
return jsonify({
|
||||
"resultCode": "08",
|
||||
"resultDescription": "Error occurred"
|
||||
"resultDescription": f"Error occurred: {str(e)}"
|
||||
}), 500
|
||||
@@ -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