order_intent_id < 1 ) { throw new DomainException( 'transaction_intent.order_intent_id', 'order_intent_id must be positive.' ); } if ( '' === trim( $this->gateway ) ) { throw new DomainException( 'transaction_intent.gateway', 'gateway must not be empty.' ); } if ( $this->amount->is_negative() || 0 === $this->amount->amount_minor() ) { throw new DomainException( 'transaction_intent.amount', 'amount must be positive.' ); } } /** * Database id. * * @since 0.1.0 */ public function id(): ?int { return $this->id; } /** * Public UUID. * * @since 0.1.0 */ public function uuid(): Uuid { return $this->uuid; } /** * Parent order intent id. * * @since 0.1.0 */ public function order_intent_id(): int { return $this->order_intent_id; } /** * Gateway key. * * @since 0.1.0 */ public function gateway(): string { return $this->gateway; } /** * Gateway intent id. * * @since 0.1.0 */ public function gateway_intent_id(): ?string { return $this->gateway_intent_id; } /** * Amount. * * @since 0.1.0 */ public function amount(): Money { return $this->amount; } /** * Payment type. * * @since 0.1.0 */ public function payment_type(): TransactionPaymentType { return $this->payment_type; } /** * Status. * * @since 0.1.0 */ public function status(): TransactionIntentStatus { return $this->status; } /** * Idempotency key. * * @since 0.1.0 */ public function idempotency_key(): ?string { return $this->idempotency_key; } /** * Client secret hash. * * @since 0.1.0 */ public function client_secret_hash(): ?string { return $this->client_secret_hash; } /** * Failure code. * * @since 0.1.0 */ public function failure_code(): ?string { return $this->failure_code; } /** * Failure message. * * @since 0.1.0 */ public function failure_message(): ?string { return $this->failure_message; } /** * Created at. * * @since 0.1.0 */ public function created_at(): DateTimeImmutable { return $this->created_at; } /** * Updated at. * * @since 0.1.0 */ public function updated_at(): DateTimeImmutable { return $this->updated_at; } /** * Assign id after insert. * * @param int $id New id. * * @throws DomainException When already assigned. * * @since 0.1.0 */ public function assign_id( int $id ): void { if ( null !== $this->id ) { throw new DomainException( 'transaction_intent.id_assigned', 'Transaction intent id is already assigned.' ); } if ( $id < 1 ) { throw new DomainException( 'transaction_intent.id_invalid', 'Transaction intent id must be positive.' ); } $this->id = $id; } /** * Record the gateway intent id after creation at the provider. * * @param string $gateway_intent_id Provider id. * @param DateTimeImmutable $now Instant. * * @throws DomainException When empty. * * @since 0.1.0 */ public function attach_gateway_intent( string $gateway_intent_id, DateTimeImmutable $now ): void { if ( '' === trim( $gateway_intent_id ) ) { throw new DomainException( 'transaction_intent.gateway_intent_id', 'gateway_intent_id must not be empty.' ); } $this->gateway_intent_id = $gateway_intent_id; $this->updated_at = $now->setTimezone( new DateTimeZone( 'UTC' ) ); } /** * Transition status. * * @param TransactionIntentStatus $status New status. * @param DateTimeImmutable $now Instant. * @param string|null $code Failure code. * @param string|null $message Failure message. * * @since 0.1.0 */ public function set_status( TransactionIntentStatus $status, DateTimeImmutable $now, ?string $code = null, ?string $message = null ): void { $this->status = $status; $this->failure_code = $code; $this->failure_message = $message; $this->updated_at = $now->setTimezone( new DateTimeZone( 'UTC' ) ); } }