id = $id; return $this; } public function set_order_id( string $order_id ): self { $this->order_id = $order_id; return $this; } public function set_amount( int $amount ): self { $this->amount = $amount; return $this; } /** * @throws WC_Vipps_Recurring_Invalid_Value_Exception */ public function set_type( string $type ): self { if ( ! in_array( $type, $this->valid_types, true ) ) { $class = get_class( $this ); throw new WC_Vipps_Recurring_Invalid_Value_Exception( "$type is not a valid value for `type` in $class." ); } $this->type = $type; return $this; } /** * @throws WC_Vipps_Recurring_Invalid_Value_Exception */ public function set_status( string $status ): self { if ( ! in_array( $status, $this->valid_statuses, true ) ) { $class = get_class( $this ); throw new WC_Vipps_Recurring_Invalid_Value_Exception( "$status is not a valid value for `status` in $class." ); } $this->status = $status; return $this; } /** * @throws WC_Vipps_Recurring_Invalid_Value_Exception */ public function set_transaction_type( string $transaction_type ): self { if ( ! in_array( $transaction_type, $this->valid_transaction_types, true ) ) { $class = get_class( $this ); throw new WC_Vipps_Recurring_Invalid_Value_Exception( "$transaction_type is not a valid value for `transaction_type` in $class." ); } $this->transaction_type = $transaction_type; return $this; } /** * @throws WC_Vipps_Recurring_Invalid_Value_Exception */ public function set_processing_mode( string $processing_mode ): self { if ( ! in_array( $processing_mode, $this->valid_processing_modes, true ) ) { $class = get_class( $this ); throw new WC_Vipps_Recurring_Invalid_Value_Exception( "$processing_mode is not a valid value for `processing_mode` in $class." ); } $this->processing_mode = $processing_mode; return $this; } public function set_transaction_id( string $transaction_id ): self { $this->transaction_id = $transaction_id; return $this; } public function set_description( ?string $description ): self { if ( strlen( $description ) > 45 ) { $description = mb_substr( $description, 0, 42 ) . '...'; } $this->description = $description; return $this; } /** * @param DateTime|string $due * * @throws Exception */ public function set_due( $due ): self { if ( is_string( $due ) ) { $this->due = new DateTime( $due ); } else { $this->due = $due; } return $this; } public function set_retry_days( int $retry_days ): self { $this->retry_days = $retry_days; return $this; } public function set_external_id( string $external_id ): self { $this->external_id = $external_id; return $this; } /** * @throws WC_Vipps_Recurring_Missing_Value_Exception */ public function to_array( bool $check_required = false ): array { if ( $check_required ) { $this->check_required(); } return array_merge( [ "orderId" => $this->order_id, "amount" => $this->amount, "description" => $this->description, "due" => $this->serialize_value( $this->due, 'Y-m-d' ), "retryDays" => $this->retry_days, "processingMode" => $this->processing_mode, ], $this->conditional( "type", $this->type ), $this->conditional( "transactionType", $this->transaction_type ), $this->conditional( "transactionId", $this->transaction_id ), $this->conditional( "externalId", $this->external_id ) ); } }