Record Class Payment
java.lang.Object
java.lang.Record
com.example.orderplatform.payments.domain.Payment
- Record Components:
id- payment identifierorderId- related order identifierstatus- current payment statusamount- expected amountcreatedAt- creation timestamp- authorization timestamp when authorized
public record Payment(UUID id, UUID orderId, PaymentStatus status, Money amount, OffsetDateTime createdAt, OffsetDateTime authorizedAt)
extends Record
Framework-independent payment state used to enforce authorization transitions.
-
Constructor Summary
ConstructorsConstructorDescriptionPayment(UUID id, UUID orderId, PaymentStatus status, Money amount, OffsetDateTime createdAt, OffsetDateTime authorizedAt) Creates an instance of aPaymentrecord class. -
Method Summary
Modifier and TypeMethodDescriptionamount()Returns the value of theamountrecord component.authorize(OffsetDateTime authorizedAt) Authorizes this payment when it is still pending.Returns the value of theauthorizedAtrecord component.Returns the value of thecreatedAtrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.id()Returns the value of theidrecord component.orderId()Returns the value of theorderIdrecord component.static Paymentpending(UUID id, UUID orderId, Money amount, OffsetDateTime createdAt) Creates a pending payment for a submitted order.status()Returns the value of thestatusrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
Payment
public Payment(UUID id, UUID orderId, PaymentStatus status, Money amount, OffsetDateTime createdAt, OffsetDateTime authorizedAt) Creates an instance of aPaymentrecord class.- Parameters:
id- the value for theidrecord componentorderId- the value for theorderIdrecord componentstatus- the value for thestatusrecord componentamount- the value for theamountrecord componentcreatedAt- the value for thecreatedAtrecord componentauthorizedAt- the value for theauthorizedAtrecord component
-
-
Method Details
-
pending
Creates a pending payment for a submitted order.- Parameters:
id- generated payment identifierorderId- related order identifieramount- expected payment amountcreatedAt- creation timestamp- Returns:
- pending payment
-
authorize
Authorizes this payment when it is still pending.- Parameters:
authorizedAt- authorization timestamp- Returns:
- authorized payment state
- Throws:
BusinessRuleViolationException- when the payment is not pending
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
id
Returns the value of theidrecord component.- Returns:
- the value of the
idrecord component
-
orderId
Returns the value of theorderIdrecord component.- Returns:
- the value of the
orderIdrecord component
-
status
Returns the value of thestatusrecord component.- Returns:
- the value of the
statusrecord component
-
amount
Returns the value of theamountrecord component.- Returns:
- the value of the
amountrecord component
-
createdAt
Returns the value of thecreatedAtrecord component.- Returns:
- the value of the
createdAtrecord component
-
authorizedAt
Returns the value of theauthorizedAtrecord component.- Returns:
- the value of the
authorizedAtrecord component
-