Skip to main content

Overview

The Payment Service (jea-pagos) manages payment methods used throughout the Sistema de Ventas platform. It provides a simple catalog of payment options for sales, purchases, and orders. Database: MySQL (pagos-ms) Port: Dynamic (configured via Eureka)

Core Entities

FormaPago

Payment method definition. Location: jea-pagos/src/main/java/com/example/jeapagos/entity/FormaPago.java:10 Fields:
  • id (Long) - Primary key
  • nombre (String) - Payment method name
Table: forma_pago Examples:
  • Efectivo (Cash)
  • Tarjeta de Crédito (Credit Card)
  • Tarjeta de Débito (Debit Card)
  • Transferencia Bancaria (Bank Transfer)
  • Cheque (Check)

Key Components

Controllers

FormaPagoController

Location: jea-pagos/src/main/java/com/example/jeapagos/controller/FormaPagoController.java:12 Endpoints:
  • GET /pagos - List all payment methods
  • GET /pagos/{id} - Get payment method by ID
  • POST /pagos - Create new payment method
  • PUT /pagos/{id} - Update payment method
  • DELETE /pagos/{id} - Delete payment method
Features:
  • Simple CRUD operations
  • Standard REST conventions
  • Exception handling for not found scenarios

Services

FormaPagoService

Location: jea-pagos/src/main/java/com/example/jeapagos/service/FormaPagoService.java Implementation: FormaPagoServiceImpl.java Key Methods:
  • listarFormasPago() - List all payment methods
  • buscarPorId() - Find by ID
  • guardar() - Create new payment method
  • actualizar() - Update existing payment method
  • eliminar() - Delete payment method

Repositories

FormaPagoRepository

Location: jea-pagos/src/main/java/com/example/jeapagos/repository/FormaPagoRepository.java Extends JpaRepository<FormaPago, Long> Provides standard data access operations.

Dependencies

Spring Boot Version: 3.1.3 Spring Cloud Version: 2022.0.2 Key Dependencies:
  • spring-boot-starter-data-jpa - JPA/Hibernate
  • spring-boot-starter-web - REST API
  • spring-boot-starter-validation - Bean validation
  • spring-cloud-starter-netflix-eureka-client - Service discovery
  • spring-cloud-starter-config:4.0.4 - Centralized configuration
  • springdoc-openapi-starter-webmvc-ui:2.0.2 - OpenAPI/Swagger UI
  • mysql-connector-j - MySQL driver
  • lombok - Code generation

Configuration

Config File: config-data/jea-pagos-service.yml Key Settings:
server:
  port: ${PORT:${SERVER_PORT:0}}

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/pagos-ms
    username: root
    password: ""
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8090/eureka

Database Schema

Main Tables:
  • forma_pago - Payment methods
    • Primary key: id
    • Fields: nombre
Sample Data:
INSERT INTO forma_pago (nombre) VALUES 
  ('Efectivo'),
  ('Tarjeta de Crédito'),
  ('Tarjeta de Débito'),
  ('Transferencia Bancaria'),
  ('Cheque');

Key Features

  • Simple payment method catalog
  • Full CRUD operations
  • Referenced by Sales, Purchase, and Order services
  • Lightweight microservice
  • OpenAPI/Swagger documentation
  • Eureka service discovery integration
  • Centralized configuration via Config Server

Integration Points

Consumed by:

  • Sales Service - References payment methods for sales transactions
  • Purchase Service - References payment methods for purchase orders
  • Orders Service - References payment methods for customer orders

APIs Exposed:

  • Payment method CRUD operations
  • Payment method listing
  • Payment method lookup by ID

Usage Pattern

Other services reference payment methods by ID:
// In Venta, Compra, or Pedido entity
@Column(name = "formapago_id")
private Long formapagoId;

@Transient
private FormaPago formaPago; // Retrieved via Feign client
Services use Feign clients to fetch payment method details:
@FeignClient(name = "jea-pagos-service")
public interface FormaPagoFeign {
    @GetMapping("/pagos/{id}")
    FormaPago obtenerPorId(@PathVariable Long id);
}

Design Considerations

Why a Separate Service?

  1. Centralized Management - Single source of truth for payment methods
  2. Consistency - Same payment options across all transaction types
  3. Flexibility - Easy to add new payment methods without modifying other services
  4. Microservice Principles - Each service owns its domain data

Simplicity

This is one of the simplest services in the system:
  • Single entity (FormaPago)
  • No complex business logic
  • No external service dependencies
  • Straightforward CRUD operations
  • Serves as reference data for other services

Future Enhancements

Potential additions:
  • Payment method categories (online, offline)
  • Enable/disable flags
  • Processing fees or transaction costs
  • Integration with payment gateways
  • Payment method icons or images
  • Default payment method configuration

Build docs developers (and LLMs) love