Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Payment Processing Application

A mock credit card payment processing application built with Java 11, Spring Boot, and React.

Features

Backend (Java 11 + Spring Boot)

  • REST API Endpoints:

    • POST /api/payments/authorize - Authorize a card transaction
    • POST /api/payments/capture - Capture an authorized transaction
    • POST /api/payments/refund - Refund a captured transaction
    • GET /api/payments/{id} - Get transaction status
    • GET /api/payments/history - List recent transactions (last 20)
    • POST /admin/cache/clear - Clear local cache
    • GET /actuator/health - Health check endpoint
    • GET /actuator/prometheus - Prometheus metrics
  • Technology Stack:

    • In-memory H2 database
    • Caffeine cache for transaction lookups
    • Realistic processing delays (200-500ms)
    • Random transaction declines (10% probability)
    • Realistic response codes (approved, declined, insufficient funds, expired card)

Frontend (React)

  • Payment form with card number, expiry, CVV, and amount fields
  • Transaction history dashboard
  • Status badges: Authorized (yellow), Captured (green), Declined (red), Refunded (gray)
  • Capture and refund actions directly from the UI

Test Card Numbers

  • Visa: 4263970000005262
  • MasterCard: 5425230000004415
  • Amex: 374101000000608

Use any future expiry date (e.g., 12/25) and any 3-4 digit CVV.

Quick Start

Prerequisites

  • Java 11
  • Maven 3.6+

Run the Application

cd payment-app-java11
mvn spring-boot:run

The application will start on http://localhost:8081

Open your browser and navigate to http://localhost:8081 to access the payment form.

API Examples

Authorize a Payment

curl -X POST http://localhost:8081/api/payments/authorize \
  -H "Content-Type: application/json" \
  -d '{
    "cardNumber": "4263970000005262",
    "cardExpiry": "12/25",
    "cvv": "123",
    "amount": 100.00
  }'

Capture a Transaction

curl -X POST http://localhost:8081/api/payments/capture \
  -H "Content-Type: application/json" \
  -d '{"transactionId": 1}'

Refund a Transaction

curl -X POST http://localhost:8081/api/payments/refund \
  -H "Content-Type: application/json" \
  -d '{"transactionId": 1}'

Get Transaction Status

curl http://localhost:8081/api/payments/1

Get Transaction History

curl http://localhost:8081/api/payments/history

Clear Cache

curl -X POST http://localhost:8081/admin/cache/clear

Health Check

curl http://localhost:8081/actuator/health

Prometheus Metrics

curl http://localhost:8081/actuator/prometheus

Docker

Build the Image

docker build -t payment-app:latest .

Run the Container

docker run -p 8081:8081 payment-app:latest

OpenShift Deployment

The application includes OpenShift deployment manifests with placeholder values.

Placeholder Variables

  • ${NAMESPACE} - Target namespace (e.g., bob-demo-staging or bob-demo-prod)
  • ${IMAGE_TAG} - Git SHA or version tag

Deploy to OpenShift

# Set environment variables
export NAMESPACE=bob-demo-staging
export IMAGE_TAG=abc123def

# Replace placeholders and apply
envsubst < k8s/deployment.yaml | oc apply -f -

Image Registry

The deployment uses the internal OpenShift image registry:

image-registry.openshift-image-registry.svc:5000/${NAMESPACE}/payment-app:${IMAGE_TAG}

At deploy time:

  • ${NAMESPACE}bob-demo-staging (or bob-demo-prod)
  • ${IMAGE_TAG} → Git SHA

The CI job pushes images via the external registry route.

Deployment Features

  • 3 replicas with horizontal pod autoscaling (3-10 pods)
  • Resource limits: 1Gi memory, 1 CPU
  • Readiness and liveness probes
  • PodDisruptionBudget (max 1 unavailable)
  • TLS-enabled Route
  • Non-root security context
  • ServiceAccount with minimal RBAC

Project Structure

payment-app-java11/
├── src/
│   └── main/
│       ├── java/com/demo/payment/
│       │   ├── controller/          # REST controllers
│       │   │   ├── PaymentController.java
│       │   │   └── AdminController.java
│       │   ├── service/             # Business logic
│       │   │   └── PaymentService.java
│       │   ├── model/               # Entities and DTOs
│       │   │   ├── Transaction.java
│       │   │   ├── TransactionStatus.java
│       │   │   ├── TransactionType.java
│       │   │   ├── TransactionRepository.java
│       │   │   ├── PaymentRequest.java
│       │   │   └── PaymentResponse.java
│       │   ├── config/              # Configuration
│       │   │   └── CacheConfig.java
│       │   └── PaymentApplication.java
│       └── resources/
│           ├── static/              # React frontend
│           │   └── index.html
│           └── application.properties
├── pom.xml
├── Dockerfile
├── k8s/
│   └── deployment.yaml              # OpenShift manifests
└── README.md

Transaction Flow

  1. Authorize: Reserve funds on the card

    • Status: AUTHORIZED
    • Can be captured or will expire
  2. Capture: Settle the authorized transaction

    • Status: CAPTURED
    • Funds are transferred
    • Can be refunded
  3. Refund: Return funds to the cardholder

    • Status: REFUNDED
    • Final state

Response Codes

  • APPROVED - Transaction successful
  • DECLINED - Transaction declined by issuer
  • INVALID_CARD - Invalid card number
  • EXPIRED_CARD - Card has expired
  • INSUFFICIENT_FUNDS - Amount exceeds limit (>$10,000)

Monitoring

Health Check

curl http://localhost:8081/actuator/health

Response:

{
  "status": "UP",
  "components": {
    "db": {"status": "UP"},
    "diskSpace": {"status": "UP"},
    "ping": {"status": "UP"}
  }
}

Metrics

Prometheus metrics are available at /actuator/prometheus for monitoring:

  • JVM metrics
  • HTTP request metrics
  • Cache statistics
  • Custom application metrics

Development

Build

mvn clean package

Run Tests

mvn test

Run Locally

mvn spring-boot:run

Notes

  • This is a demo application for testing and development purposes only
  • Uses in-memory H2 database (data is lost on restart)
  • Simulates realistic payment processing delays and random declines
  • Not suitable for production use without significant enhancements
  • No actual payment processing or external API calls

License

This is a demo application for educational purposes.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages