This document outlines the key architectural and design decisions made during the development of the Payment Gateway API.
Approach:
- Custom validation performed in
RequestValidatorutility class - No
@Validannotation used on@RequestBodyparameters
Reasoning:
- Custom Error Messages: Able to provide more detailed, user-friendly error messages
- Validation Logic: Complex validation can be implemented (e.g., expiry date in the future)
- Flexibility: Easier to modify validation rules and error messages without touching model classes
Validation Rules Implemented:
- All below fields are required
- Card number: 14-19 digits, numeric only
- Expiry date: MM/YY or MM/YYYY format, must be in the future
- Currency: Must be one of the supported codes (GBP, USD, EUR)
- Amount: Must be greater than 0
- CVV: Must be 3 or 4 digits
Approach:
- Single
PaymentResponseclass to represent bothPOSTandGETresponses
Reasoning:
- Simplicity: Easier to manage and extend a single response structure
- Removing Redundancy: Avoids duplication of similar fields across multiple response classes
Approach:
BankRequestclass mirrors fields fromPaymentRequest- Expiry Month and Year are set to Expiry Date in
BankRequest
Reasoning:
- Open For Future Changes: If bank requirements change, mapping logic can be adjusted without affecting
PaymentRequest
Approach:
BankResponseclass includesauthorizationCodefield
Reasoning:
- Requirement Changes: Authorization code is stored but is not used in the
PaymentResponsethis is added in case of future requirements
- Only payments that pass validation are saved in the
PaymentsRepository Statusfield indicates whether payment isAUTHORIZEDorDECLINED
Reasoning:
- Data Relevance: Only valid payments are relevant for future retrieval
- Filtering: Only payments that are valid reach the bank simulator
Approach:
@ControllerAdvicewithCommonExceptionHandlercatches all exceptions globally- Specific exception classes for different error scenarios
- Generic exception handler as safety net
HTTP Status Code Mapping:
- 400 (Bad Request): Validation failures, malformed requests
- 404 (Not Found): Payment ID does not exist in repository
- 503 (Service Unavailable): Bank simulator is down or unreachable
- 500 (Internal Server Error): Unexpected errors