| 1 |
package com.paymentlink.model.entity; |
| 2 |
|
| 3 |
import com.fasterxml.jackson.annotation.JsonManagedReference; |
| 4 |
import jakarta.persistence.*; |
| 5 |
import lombok.AllArgsConstructor; |
| 6 |
import lombok.Builder; |
| 7 |
import lombok.Data; |
| 8 |
import lombok.NoArgsConstructor; |
| 9 |
import org.hibernate.annotations.CreationTimestamp; |
| 10 |
import org.hibernate.annotations.UpdateTimestamp; |
| 11 |
|
| 12 |
import java.time.LocalDateTime; |
| 13 |
import java.util.ArrayList; |
| 14 |
import java.util.List; |
| 15 |
|
| 16 |
@Entity |
| 17 |
@Table(name = "payment_links") |
| 18 |
@Data |
| 19 |
@NoArgsConstructor |
| 20 |
@AllArgsConstructor |
| 21 |
@Builder |
| 22 |
public class PaymentLink { |
| 23 |
|
| 24 |
@Id |
| 25 |
@GeneratedValue(strategy = GenerationType.IDENTITY) |
| 26 |
private Long id; |
| 27 |
|
| 28 |
@Column(name = "link_id", unique = true, nullable = false) |
| 29 |
private String linkId; |
| 30 |
|
| 31 |
@OneToMany(mappedBy = "paymentLink", cascade = CascadeType.ALL, orphanRemoval = true) |
| 32 |
@Builder.Default |
| 33 |
@JsonManagedReference |
| 34 |
private List<PaymentLinkItem> items = new ArrayList<>(); |
| 35 |
|
| 36 |
@Column(nullable = false) |
| 37 |
private Long amount; |
| 38 |
|
| 39 |
@Column(nullable = false) |
| 40 |
private Long subtotal; |
| 41 |
|
| 42 |
@Column(name = "shipping_cost") |
| 43 |
private Long shippingCost; |
| 44 |
|
| 45 |
@Column(name = "tax_amount") |
| 46 |
private Long taxAmount; |
| 47 |
|
| 48 |
@Column(nullable = false, length = 3) |
| 49 |
private String currency; |
| 50 |
|
| 51 |
@Column(nullable = false) |
| 52 |
private String status; |
| 53 |
|
| 54 |
@Column(name = "order_id") |
| 55 |
private String orderId; |
| 56 |
|
| 57 |
@Column(name = "stripe_payment_intent_id") |
| 58 |
private String stripePaymentIntentId; |
| 59 |
|
| 60 |
@Column(name = "customer_email") |
| 61 |
private String customerEmail; |
| 62 |
|
| 63 |
@Column(name = "customer_name") |
| 64 |
private String customerName; |
| 65 |
|
| 66 |
@Column(name = "customer_phone") |
| 67 |
private String customerPhone; |
| 68 |
|
| 69 |
@Column(name = "shipping_address") |
| 70 |
private String shippingAddress; |
| 71 |
|
| 72 |
@Column(name = "shipping_city") |
| 73 |
private String shippingCity; |
| 74 |
|
| 75 |
@Column(name = "shipping_state") |
| 76 |
private String shippingState; |
| 77 |
|
| 78 |
@Column(name = "shipping_zip") |
| 79 |
private String shippingZip; |
| 80 |
|
| 81 |
@Column(name = "shipping_country") |
| 82 |
private String shippingCountry; |
| 83 |
|
| 84 |
@Column(name = "shipping_method") |
| 85 |
private String shippingMethod; |
| 86 |
|
| 87 |
@Column(name = "node_id") |
| 88 |
private String nodeId; |
| 89 |
|
| 90 |
@CreationTimestamp |
| 91 |
@Column(name = "created_at", updatable = false) |
| 92 |
private LocalDateTime createdAt; |
| 93 |
|
| 94 |
@UpdateTimestamp |
| 95 |
@Column(name = "updated_at") |
| 96 |
private LocalDateTime updatedAt; |
| 97 |
|
| 98 |
|
| 99 |
public void addItem(PaymentLinkItem item) { |
| 100 |
items.add(item); |
| 101 |
item.setPaymentLink(this); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
|