Skip to content

This project implements a payment processor using Spring Batch that validates and processes payments from an input file, generating output files for processed and rejected payments, and an overall report.

License

Notifications You must be signed in to change notification settings

andresWeitzel/Spring_Batch_Processing_Payments

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation





Spring Batch Payments Processor (status-completed)

This project implements a payment processor using Spring Batch that validates and processes payments from an input file, generating output files for processed payments, rejected payments, and a general report.

Sections

1. Features
  • Batch payment processing
  • Amount, currency, and customer data validation
  • Commission calculation
  • Report generation
  • Error handling and rejected payments
  • Support for multiple currencies (USD, EUR, GBP, JPY)
2. Requirements
  • Java 17 or higher
  • Maven 3.6 or higher
  • Spring Boot 2.7.0
  • Spring Batch 4.3.6
3. Configuration and Execution
  1. Clone the repository:
git clone [repository-url]
cd spring_batch_processing_payments
  1. The project uses different profiles for development and production. To run in development mode:
mvn spring-boot:run -Dspring-boot.run.profiles=dev
4. Project Structure
src/main/java/com/example/batch/
├── config/         # Spring Batch configuration
├── model/          # Data models
├── processor/      # Payment processors
└── enums/          # Enumerations
5. Processing Flow
  1. Payment Reading: Reads payments from input/payments.txt
  2. Validation and Processing:
    • Validates amounts (minimum: 10.00, maximum: 10000.00)
    • Validates supported currencies
    • Validates email format
    • Calculates commissions
  3. Result Writing:
    • Valid payments → output/processed_payments.txt
    • Rejected payments → output/rejected_payments.txt
    • General report → output/payment_report.txt
6. File Formats

Input File (payments.txt)

id,amount,currency,status,paymentDate,paymentType,customerName,customerEmail
1,100.00,USD,PENDING,2024-03-20T10:00:00,CREDIT_CARD,John Doe,[email protected]
2,500.00,EUR,PENDING,2024-03-20T10:05:00,DEBIT_CARD,Jane Smith,[email protected]
3,1000.00,GBP,PENDING,2024-03-20T10:10:00,CREDIT_CARD,Bob Johnson,[email protected]
4,5000.00,JPY,PENDING,2024-03-20T10:15:00,DEBIT_CARD,Alice Brown,[email protected]

Processed Payments File (processed_payments.txt)

id,amount,currency,status,paymentDate,paymentType,customerName,customerEmail,amountInUSD,commission,validationStatus
1,100.00,USD,PROCESSED,2024-03-20T10:00:00,CREDIT_CARD,John Doe,[email protected],100.00,2.00,VALID
2,500.00,EUR,PROCESSED,2024-03-20T10:05:00,DEBIT_CARD,Jane Smith,[email protected],545.00,10.90,VALID
3,1000.00,GBP,PROCESSED,2024-03-20T10:10:00,CREDIT_CARD,Bob Johnson,[email protected],1270.00,25.40,VALID
4,5000.00,JPY,PROCESSED,2024-03-20T10:15:00,DEBIT_CARD,Alice Brown,[email protected],33.50,0.67,VALID

Rejected Payments File (rejected_payments.txt)

id,amount,currency,status,paymentDate,paymentType,customerName,customerEmail,errorMessage
5,5.00,USD,INVALID,2024-03-20T10:20:00,CREDIT_CARD,Charlie Wilson,[email protected],Amount is below minimum allowed: 10.0
6,15000.00,EUR,INVALID,2024-03-20T10:25:00,DEBIT_CARD,Diana Miller,[email protected],Amount exceeds maximum allowed: 10000.0
7,200.00,MXN,INVALID,2024-03-20T10:30:00,CREDIT_CARD,Edward Davis,[email protected],Unsupported currency: MXN
8,300.00,GBP,INVALID,2024-03-20T10:35:00,INVALID_TYPE,Frank Lee,[email protected],Invalid payment type: INVALID_TYPE
9,400.00,USD,INVALID,2024-03-20T10:40:00,CREDIT_CARD,Grace Kim,invalid-email,Invalid email format
10,500.00,EUR,INVALID,2024-03-20T10:45:00,DEBIT_CARD,Henry Park,,Email cannot be empty
11,600.00,GBP,INVALID,2024-03-20T10:50:00,CREDIT_CARD,Ivy Chen,[email protected],Invalid or empty payment date

General Report File (payment_report.txt)

=== Payment Processing Report ===
Processing Date: 2024-03-20T11:00:00
Total Processed Payments: 4
Total Rejected Payments: 7
Total Payments: 11

=== Currency Statistics ===
USD: 2 payments (1 processed, 1 rejected)
EUR: 3 payments (1 processed, 2 rejected)
GBP: 3 payments (1 processed, 2 rejected)
JPY: 1 payment (1 processed, 0 rejected)
MXN: 1 payment (0 processed, 1 rejected)

=== Payment Type Statistics ===
CREDIT_CARD: 6 payments
DEBIT_CARD: 4 payments
INVALID_TYPE: 1 payment

=== Rejection Reasons ===
Amount too low: 1
Amount too high: 1
Unsupported currency: 1
Invalid payment type: 1
Invalid email: 2
Invalid date: 1

=== Total Amounts ===
Total Processed (USD): 1948.40
Total Commissions (USD): 38.97
7. Payment Examples

Valid Payments

  1. USD payment within allowed range:
id,amount,currency,status,paymentDate,paymentType,customerName,customerEmail
1,100.00,USD,PENDING,2024-03-20T10:00:00,CREDIT_CARD,John Doe,[email protected]
2,500.00,USD,PENDING,2024-03-20T10:05:00,DEBIT_CARD,Jane Smith,[email protected]
3,1000.00,USD,PENDING,2024-03-20T10:10:00,CREDIT_CARD,Bob Johnson,[email protected]
  1. EUR payment with valid email:
id,amount,currency,status,paymentDate,paymentType,customerName,customerEmail
4,500.00,EUR,PENDING,2024-03-20T11:00:00,DEBIT_CARD,Jane Smith,[email protected]
5,750.00,EUR,PENDING,2024-03-20T11:05:00,CREDIT_CARD,Alice Brown,[email protected]
6,2500.00,EUR,PENDING,2024-03-20T11:10:00,DEBIT_CARD,Charlie Wilson,[email protected]
  1. GBP payment with varied amounts:
id,amount,currency,status,paymentDate,paymentType,customerName,customerEmail
7,50.00,GBP,PENDING,2024-03-20T12:00:00,CREDIT_CARD,David Miller,[email protected]
8,200.00,GBP,PENDING,2024-03-20T12:05:00,DEBIT_CARD,Eva Garcia,[email protected]
9,5000.00,GBP,PENDING,2024-03-20T12:10:00,CREDIT_CARD,Frank Lee,[email protected]
  1. JPY payment with different payment types:
id,amount,currency,status,paymentDate,paymentType,customerName,customerEmail
10,10000.00,JPY,PENDING,2024-03-20T13:00:00,CREDIT_CARD,Grace Kim,[email protected]
11,50000.00,JPY,PENDING,2024-03-20T13:05:00,DEBIT_CARD,Henry Park,[email protected]
12,100000.00,JPY,PENDING,2024-03-20T13:10:00,CREDIT_CARD,Ivy Chen,[email protected]

Rejected Payments

  1. Very low amounts:
id,amount,currency,status,paymentDate,paymentType,customerName,customerEmail
13,5.00,USD,PENDING,2024-03-20T14:00:00,CREDIT_CARD,Jack Wilson,[email protected]
14,1.00,EUR,PENDING,2024-03-20T14:05:00,DEBIT_CARD,Kate Brown,[email protected]
15,0.50,GBP,PENDING,2024-03-20T14:10:00,CREDIT_CARD,Liam Davis,[email protected]
  1. Unsupported currencies:
id,amount,currency,status,paymentDate,paymentType,customerName,customerEmail
16,1000.00,MXN,PENDING,2024-03-20T15:00:00,DEBIT_CARD,Maria Garcia,[email protected]
17,500.00,CAD,PENDING,2024-03-20T15:05:00,CREDIT_CARD,Noah Smith,[email protected]
18,2000.00,AUD,PENDING,2024-03-20T15:10:00,DEBIT_CARD,Olivia Lee,[email protected]
  1. Invalid emails:
id,amount,currency,status,paymentDate,paymentType,customerName,customerEmail
19,200.00,USD,PENDING,2024-03-20T16:00:00,CREDIT_CARD,Peter Davis,invalid-email
20,300.00,EUR,PENDING,2024-03-20T16:05:00,DEBIT_CARD,Quinn Wilson,not-an-email
21,400.00,GBP,PENDING,2024-03-20T16:10:00,CREDIT_CARD,Rachel Brown,missing@domain
  1. Very high amounts:
id,amount,currency,status,paymentDate,paymentType,customerName,customerEmail
22,15000.00,USD,PENDING,2024-03-20T17:00:00,DEBIT_CARD,Sam Miller,[email protected]
23,20000.00,EUR,PENDING,2024-03-20T17:05:00,CREDIT_CARD,Tina Garcia,[email protected]
24,25000.00,GBP,PENDING,2024-03-20T17:10:00,DEBIT_CARD,Victor Lee,[email protected]
  1. Invalid or empty dates:
id,amount,currency,status,paymentDate,paymentType,customerName,customerEmail
25,100.00,USD,PENDING,,CREDIT_CARD,Will Smith,[email protected]
26,200.00,EUR,PENDING,invalid-date,DEBIT_CARD,Xena Brown,[email protected]
27,300.00,GBP,PENDING,2024-13-45T25:61:99,CREDIT_CARD,Yara Davis,[email protected]
  1. Invalid payment types:
id,amount,currency,status,paymentDate,paymentType,customerName,customerEmail
28,100.00,USD,PENDING,2024-03-20T18:00:00,INVALID_TYPE,Zack Wilson,[email protected]
29,200.00,EUR,PENDING,2024-03-20T18:05:00,UNKNOWN,Anna Brown,[email protected]
30,300.00,GBP,PENDING,2024-03-20T18:10:00,,Bob Davis,[email protected]
8. Implemented Validations
  1. Amount:

    • Minimum: 10.00
    • Maximum: 10000.00
  2. Supported Currencies:

    • USD (US Dollar)
    • EUR (Euro)
    • GBP (British Pound)
    • JPY (Japanese Yen)
  3. Email:

    • Valid format
    • Cannot be empty
  4. Payment Date:

    • Cannot be empty
    • ISO 8601 format
9. Reports

The system generates three types of output files:

  1. processed_payments.txt: Contains all valid processed payments
  2. rejected_payments.txt: Contains payments that failed validation
  3. payment_report.txt: General report with processing statistics
10. Functionality Test
11. Contributing
  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request
12. License

This project is under the MIT License - see the LICENSE file for details.

About

This project implements a payment processor using Spring Batch that validates and processes payments from an input file, generating output files for processed and rejected payments, and an overall report.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages