From 0580f8168a73b519a5904b75b72d76990c837690 Mon Sep 17 00:00:00 2001 From: felixojiambo Date: Sun, 15 Dec 2024 21:35:39 +0300 Subject: [PATCH] Removed the Invoice entity from the Payment Service models. Added invoiceId as a UUID to reference invoices managed by the Invoice Service. Maintained the paymentGateway field to identify the external payment gateway used. --- .../payment_service/models/Payment.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/payment-service/src/main/java/com/finpay/payment_service/models/Payment.java b/payment-service/src/main/java/com/finpay/payment_service/models/Payment.java index 64f6d86..def3021 100644 --- a/payment-service/src/main/java/com/finpay/payment_service/models/Payment.java +++ b/payment-service/src/main/java/com/finpay/payment_service/models/Payment.java @@ -2,6 +2,9 @@ import jakarta.persistence.*; import lombok.*; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; + import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.Set; @@ -20,7 +23,7 @@ public class Payment { private UUID id; @Column(nullable = false, unique = true) - private String paymentReference; + private String paymentReference; // Unique reference for the payment @Column(nullable = false) private BigDecimal amount; @@ -32,13 +35,11 @@ public class Payment { @Column(nullable = false) private PaymentStatus status; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "payment_method_id") - private PaymentMethod paymentMethod; + @Column(nullable = false) + private UUID invoiceId; // Reference to Invoice managed by Invoice Service - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "payment_gateway_id") - private PaymentGateway paymentGateway; + @Column(nullable = false) + private String paymentGateway; // e.g., Stripe, PayPal @OneToMany(mappedBy = "payment", cascade = CascadeType.ALL, orphanRemoval = true) private Set transactions; @@ -46,8 +47,10 @@ public class Payment { @OneToMany(mappedBy = "payment", cascade = CascadeType.ALL, orphanRemoval = true) private Set refunds; - @Column(nullable = false) + @CreationTimestamp + @Column(nullable = false, updatable = false) private LocalDateTime createdAt; + @UpdateTimestamp private LocalDateTime updatedAt; }