Files
erp-imprimelibros/src/main/java/com/imprimelibros/erp/payments/model/Payment.java
2025-11-04 14:40:18 +01:00

174 lines
6.2 KiB
Java

package com.imprimelibros.erp.payments.model;
import jakarta.persistence.*;
import java.time.LocalDateTime;
@Entity
@Table(name = "payments")
public class Payment {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "order_id")
private Long orderId;
@Column(name = "user_id")
private Long userId;
@Column(nullable = false, length = 3)
private String currency;
@Column(name = "amount_total_cents", nullable = false)
private Long amountTotalCents;
@Column(name = "amount_captured_cents", nullable = false)
private Long amountCapturedCents = 0L;
@Column(name = "amount_refunded_cents", nullable = false)
private Long amountRefundedCents = 0L;
@Enumerated(EnumType.STRING)
@Column(nullable = false, length = 32)
private PaymentStatus status = PaymentStatus.requires_payment_method;
@Enumerated(EnumType.STRING)
@Column(name = "capture_method", nullable = false, length = 16)
private CaptureMethod captureMethod = CaptureMethod.automatic;
@Column(nullable = false, length = 32)
private String gateway;
@Column(name = "gateway_payment_id", length = 128)
private String gatewayPaymentId;
@Column(name = "gateway_order_id", length = 12)
private String gatewayOrderId;
@Column(name = "authorization_code", length = 32)
private String authorizationCode;
@Enumerated(EnumType.STRING)
@Column(name = "three_ds_status", nullable = false, length = 32)
private ThreeDSStatus threeDsStatus = ThreeDSStatus.not_applicable;
@Column(length = 22)
private String descriptor;
@Lob
@Column(name = "client_ip", columnDefinition = "varbinary(16)")
private byte[] clientIp;
@Column(name = "authorized_at")
private LocalDateTime authorizedAt;
@Column(name = "captured_at")
private LocalDateTime capturedAt;
@Column(name = "canceled_at")
private LocalDateTime canceledAt;
@Column(name = "failed_at")
private LocalDateTime failedAt;
@Column(columnDefinition = "json")
private String metadata;
@Column(name = "created_at", nullable = false,
columnDefinition = "datetime default current_timestamp")
private LocalDateTime createdAt;
@Column(name = "updated_at", nullable = false,
columnDefinition = "datetime default current_timestamp on update current_timestamp")
private LocalDateTime updatedAt;
public Payment() {}
// Getters y setters ↓ (los típicos)
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public Long getOrderId() { return orderId; }
public void setOrderId(Long orderId) { this.orderId = orderId; }
public Long getUserId() { return userId; }
public void setUserId(Long userId) { this.userId = userId; }
public String getCurrency() { return currency; }
public void setCurrency(String currency) { this.currency = currency; }
public Long getAmountTotalCents() { return amountTotalCents; }
public void setAmountTotalCents(Long amountTotalCents) { this.amountTotalCents = amountTotalCents; }
public Long getAmountCapturedCents() { return amountCapturedCents; }
public void setAmountCapturedCents(Long amountCapturedCents) { this.amountCapturedCents = amountCapturedCents; }
public Long getAmountRefundedCents() { return amountRefundedCents; }
public void setAmountRefundedCents(Long amountRefundedCents) { this.amountRefundedCents = amountRefundedCents; }
public PaymentStatus getStatus() { return status; }
public void setStatus(PaymentStatus status) { this.status = status; }
public CaptureMethod getCaptureMethod() { return captureMethod; }
public void setCaptureMethod(CaptureMethod captureMethod) { this.captureMethod = captureMethod; }
public String getGateway() { return gateway; }
public void setGateway(String gateway) { this.gateway = gateway; }
public String getGatewayPaymentId() { return gatewayPaymentId; }
public void setGatewayPaymentId(String gatewayPaymentId) { this.gatewayPaymentId = gatewayPaymentId; }
public String getGatewayOrderId() { return gatewayOrderId; }
public void setGatewayOrderId(String gatewayOrderId) { this.gatewayOrderId = gatewayOrderId; }
public String getAuthorizationCode() { return authorizationCode; }
public void setAuthorizationCode(String authorizationCode) { this.authorizationCode = authorizationCode; }
public ThreeDSStatus getThreeDsStatus() { return threeDsStatus; }
public void setThreeDsStatus(ThreeDSStatus threeDsStatus) { this.threeDsStatus = threeDsStatus; }
public String getDescriptor() { return descriptor; }
public void setDescriptor(String descriptor) { this.descriptor = descriptor; }
public byte[] getClientIp() { return clientIp; }
public void setClientIp(byte[] clientIp) { this.clientIp = clientIp; }
public LocalDateTime getAuthorizedAt() { return authorizedAt; }
public void setAuthorizedAt(LocalDateTime authorizedAt) { this.authorizedAt = authorizedAt; }
public LocalDateTime getCapturedAt() { return capturedAt; }
public void setCapturedAt(LocalDateTime capturedAt) { this.capturedAt = capturedAt; }
public LocalDateTime getCanceledAt() { return canceledAt; }
public void setCanceledAt(LocalDateTime canceledAt) { this.canceledAt = canceledAt; }
public LocalDateTime getFailedAt() { return failedAt; }
public void setFailedAt(LocalDateTime failedAt) { this.failedAt = failedAt; }
public String getMetadata() { return metadata; }
public void setMetadata(String metadata) { this.metadata = metadata; }
public LocalDateTime getCreatedAt() { return createdAt; }
public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }
public LocalDateTime getUpdatedAt() { return updatedAt; }
public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; }
@PrePersist
public void prePersist() {
LocalDateTime now = LocalDateTime.now();
if (createdAt == null) {
createdAt = now;
}
if (updatedAt == null) {
updatedAt = now;
}
}
@PreUpdate
public void preUpdate() {
updatedAt = LocalDateTime.now();
}
}