diff --git a/modules/ppcp-api-client/src/Entity/Item.php b/modules/ppcp-api-client/src/Entity/Item.php index cc739635f..25478d5b0 100644 --- a/modules/ppcp-api-client/src/Entity/Item.php +++ b/modules/ppcp-api-client/src/Entity/Item.php @@ -214,7 +214,7 @@ class Item { * @return string */ public function image_url():string { - return $this->image_url; + return $this->validate_image_url() ? $this->image_url : ''; } /** @@ -269,4 +269,14 @@ class Item { return $item; } + + /** + * Validates the image url for PayPal request. + * + * @return bool true if valid, otherwise false. + */ + protected function validate_image_url(): bool { + $pattern = '/^(https:)([\/|\.|\w|\s|-])*\.(?:jpg|gif|png|jpeg|JPG|GIF|PNG|JPEG)$/'; + return (bool) preg_match( $pattern, $this->image_url ); + } }