[update]: Eligibility check request
This commit is contained in:
@@ -0,0 +1 @@
|
||||
from .transaction_type import transaction_type
|
||||
@@ -0,0 +1,6 @@
|
||||
from enum import Enum
|
||||
|
||||
class transaction_type(str, Enum):
|
||||
ELIGIBILITY_CHECK = "eligibility_check"
|
||||
PAYMENT = "payment"
|
||||
REPAYMENT = "repayment"
|
||||
@@ -0,0 +1,28 @@
|
||||
from app.models import Transaction
|
||||
from app.api.enums import transaction_type
|
||||
from flask import jsonify
|
||||
from marshmallow import ValidationError
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class BaseService:
|
||||
TRANSACTION_TYPE = None
|
||||
|
||||
@classmethod
|
||||
def log_transaction(cls, data, schema):
|
||||
logger.info(f"Processing {cls.TRANSACTION_TYPE} request")
|
||||
|
||||
validated_data = schema.load(data)
|
||||
|
||||
transaction = Transaction.create_transaction(
|
||||
id=validated_data.get("transactionId"),
|
||||
account_id=validated_data.get("accountId"),
|
||||
customer_id=validated_data.get("customerId"),
|
||||
type=cls.TRANSACTION_TYPE,
|
||||
channel=validated_data.get("channel"),
|
||||
msisdn=validated_data.get("msisdn"),
|
||||
country_code=validated_data.get("countryCode")
|
||||
)
|
||||
|
||||
return transaction
|
||||
@@ -1,9 +1,14 @@
|
||||
from flask import session, jsonify
|
||||
from app.utils.logger import logger
|
||||
from app.api.services.base_service import BaseService
|
||||
from app.api.schemas.eligibility_check import EligibilityCheckSchema
|
||||
from marshmallow import ValidationError
|
||||
from app.models import Transaction
|
||||
from app.api.enums import transaction_type
|
||||
|
||||
class EligibilityCheckService(BaseService):
|
||||
TRANSACTION_TYPE = transaction_type.ELIGIBILITY_CHECK
|
||||
|
||||
class EligibilityCheckService:
|
||||
@staticmethod
|
||||
def process_request(data):
|
||||
"""
|
||||
@@ -16,11 +21,14 @@ class EligibilityCheckService:
|
||||
dict: A standardized response.
|
||||
"""
|
||||
try:
|
||||
logger.info("Processing EligibilityCheck request")
|
||||
transaction = EligibilityCheckService.log_transaction(data, EligibilityCheckSchema())
|
||||
|
||||
if not transaction:
|
||||
logger.error(f"Customer creation failed")
|
||||
return jsonify({
|
||||
"message": "Customer creation failed." . customer
|
||||
}), 400
|
||||
|
||||
# Validate input data using Schema
|
||||
schema = EligibilityCheckSchema()
|
||||
validated_data = schema.load(data) # Raises an error if invalid
|
||||
|
||||
offers = [
|
||||
{
|
||||
@@ -51,13 +59,6 @@ class EligibilityCheckService:
|
||||
"accountId": "ACN8263457"
|
||||
}
|
||||
|
||||
|
||||
# Return a success response
|
||||
# return ResponseHelper.success(
|
||||
# data=response_data,
|
||||
# message="Eligibility check completed successfully"
|
||||
# )
|
||||
|
||||
return response_data
|
||||
except ValidationError as err:
|
||||
logger.error(f"Validation Error: {err.messages}")
|
||||
|
||||
Reference in New Issue
Block a user