url = $url; $this->event_types = $event_types; $this->id = $id; } /** * Returns the id of the webhook. * * @return string */ public function id(): string { return $this->id; } /** * Returns the URL listening to the hook. * * @return string */ public function url(): string { return $this->url; } /** * Returns the event types. * * @return stdClass[] */ public function event_types(): array { return $this->event_types; } /** * Returns the human-friendly names of the event types. * * @return string[] */ public function humanfriendly_event_names(): array { return array_map( function ( $event ): string { return Webhook::get_humanfriendly_event_name( $event->name ); }, $this->event_types ); } /** * Converts event names to more human-friendly form. * * @param string $name The event name like 'CHECKOUT.ORDER.APPROVED'. * @return string */ public static function get_humanfriendly_event_name( string $name ): string { return strtolower( str_replace( '.', ' ', $name ) ); } /** * Returns the object as array. * * @return array */ public function to_array(): array { $data = array( 'url' => $this->url(), 'event_types' => $this->event_types(), ); if ( $this->id() ) { $data['id'] = $this->id(); } return $data; } }