From d6d9b9d54c11592734fcf2dbb7f7d17c3e1c5d82 Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Tue, 26 Aug 2025 09:40:08 +0200 Subject: [PATCH 1/2] fix: :white_check_mark: add missing client tests for registering a claim --- src/CrmApiV4.php | 65 ++++++++++++++++++++++++---- src/Models/Claim.php | 101 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+), 9 deletions(-) create mode 100644 src/Models/Claim.php diff --git a/src/CrmApiV4.php b/src/CrmApiV4.php index e8bf403..7390cb8 100644 --- a/src/CrmApiV4.php +++ b/src/CrmApiV4.php @@ -3,26 +3,27 @@ namespace LDC\LDCCRM; use LDC\LDCCRM\Enums\ApiStatus; +use LDC\LDCCRM\Models\Claim; use LDC\LDCCRM\Models\Customer; use LDC\LDCCRM\Models\SingleOptin; use LDC\LDCCRM\Transport\ApiInterface; /** - * This is the main class to interact with the CRM + * This is the main class to interact with the CRM. * * @package LDCCrmClient */ class CrmApiV4 { /** - * The Api object that will handle requests and responses + * The Api object that will handle requests and responses. * * @var \LDC\LDCCRM\Transport\ApiInterface */ private static $apiInterface; /** - * CrmApiV4 + * CrmApiV4. * * @param string|null $endpoint * @param string|null $bearerToken @@ -42,7 +43,7 @@ class CrmApiV4 } /** - * Use this the ping the crm and know its current status + * Use this the ping the crm and know its current status. * * @return boolean * @throws \LDC\LDCCRM\Exceptions\CrmException If an error occurs @@ -57,7 +58,7 @@ class CrmApiV4 /** * - * Get a customer from its hashcode or email + * Get a customer from its hashcode or email. * If it does not exists a new instance * will be returned. You would have * to call its save method later on. @@ -75,7 +76,7 @@ class CrmApiV4 } /** - * Get a customer from its hashcode or email + * Get a customer from its hashcode or email. * If it does not exists a new instance * will be returned. You would have * to call its save method later on. @@ -93,7 +94,7 @@ class CrmApiV4 } /** - * Set the single optin status for an email + * Set the single optin status for an email. * * @param string $email * @param boolean $opt_in @@ -111,7 +112,7 @@ class CrmApiV4 } /** - * Set the single optin status for an email + * Unset the single optin status for an email. * * @param string $hashcode * @return boolean true if succeeded @@ -127,7 +128,53 @@ class CrmApiV4 } /** - * Test a customer credentials to see if it can login + * Set new claim. + * + * @param string $last_name + * @param string $first_name + * @param string $email + * @param string $message + * @param integer $brand_id + * @param integer $subject_id + * @param string|null $address + * @param string|null $city + * @param string|null $postcode + * @param string|null $file + * @return boolean true if succeeded + * @throws \LDC\LDCCRM\Exceptions\ValidationException If a field email could not be validated. + * @throws \LDC\LDCCRM\Exceptions\CrmException If an error occurs on server side or on getting response. + * @throws \LDC\LDCCRM\Exceptions\ApiErrorException If any error or \LDC\LDCCRM\Enums\ApiError occurs. + * Possibles are : - singleOptinCustomerExists, If a customer exists with this email. + * @phpcs:ignore Squiz.Commenting.FunctionCommentThrowTag.WrongNumber + */ + public static function setClaim( + #[\SensitiveParameter] string $last_name, + #[\SensitiveParameter] string $first_name, + #[\SensitiveParameter] string $email, + #[\SensitiveParameter] string $message, + #[\SensitiveParameter] int $brand_id, + #[\SensitiveParameter] int $subject_id, + #[\SensitiveParameter] ?string $address = null, + #[\SensitiveParameter] ?string $city = null, + #[\SensitiveParameter] ?string $postcode = null, + #[\SensitiveParameter] ?string $file = null, + ): bool { + return Claim::setClaim( + $last_name, + $first_name, + $email, + $message, + $brand_id, + $subject_id, + $address, + $city, + $postcode, + $file, + ); + } + + /** + * Test a customer credentials to see if it can login. * * @param string $email * @param string $password diff --git a/src/Models/Claim.php b/src/Models/Claim.php new file mode 100644 index 0000000..13be2da --- /dev/null +++ b/src/Models/Claim.php @@ -0,0 +1,101 @@ + 'required|string|min:3|max:255', + 'last_name' => 'required|string|min:3|max:255', + 'email' => 'required|email:rfc,dns,spoof,filter|max:255', + 'address' => 'sometimes|nullable|string|max:255', + 'city' => 'sometimes|nullable|string|min:2|max:255', + 'postcode' => 'sometimes|nullable|string', + 'file' => 'sometimes|nullable|max:5120', + 'message' => 'required|string|min:3', + 'brand_id' => 'required|int|min:1', + 'subject_id' => 'required|int|min:1', + 'customer_id' => 'sometimes|nullable|int|min:1', + ]; + + /** + * Set new claim. + * + * @param string $last_name + * @param string $first_name + * @param string $email + * @param string $message + * @param integer $brand_id + * @param integer $subject_id + * @param string|null $address + * @param string|null $city + * @param string|null $postcode + * @param UploadedFile|string|null $file + * @return boolean True if succeeded. + * @throws \LDC\LDCCRM\Exceptions\ValidationException If a field could not be validated. + * @throws \LDC\LDCCRM\Exceptions\CrmException If an error occurs on server side or on getting response. + * @throws \LDC\LDCCRM\Exceptions\ApiErrorException If any error or \LDC\LDCCRM\Enums\ApiError occurs. + * @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed,Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed + */ + public static function setClaim( + #[\SensitiveParameter] string $last_name, + #[\SensitiveParameter] string $first_name, + #[\SensitiveParameter] string $email, + #[\SensitiveParameter] string $message, + #[\SensitiveParameter] int $brand_id, + #[\SensitiveParameter] int $subject_id, + #[\SensitiveParameter] ?string $address = null, + #[\SensitiveParameter] ?string $city = null, + #[\SensitiveParameter] ?string $postcode = null, + #[\SensitiveParameter] UploadedFile|string|null $file = null, + ): bool { + // @phpcs:enable + $params = compact( + 'last_name', + 'first_name', + 'email', + 'message', + 'brand_id', + 'subject_id', + 'address', + 'city', + 'postcode', + ); + + $params['file'] = ($file instanceof UploadedFile) + ? base64_encode(file_get_contents($file->getRealPath())) + : $file; + + // Add customer relation if exist. + $crmCustomer = (new CrmApiV4())->getCustomer($email); + $params['customer_id'] = $crmCustomer; + + // Validate all data. + foreach ($params as $key => $value) { + self::validateValue($key, $value); + } + + static::setUpApiInterface(); + $response = static::$apiInterface->call( + Utils::getResquest('apiV4.claim.store', [], $params) + ); + return $response->status->equals(ApiStatus::OK); + } +} From dd8ff9af787ad5e93dad10fc10ca5a44e1803da0 Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Tue, 26 Aug 2025 09:43:57 +0200 Subject: [PATCH 2/2] =?UTF-8?q?chore:=20=F0=9F=94=96=20release=20v4.1.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 +++ composer.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e0c0bd..64ec449 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ### All notable changes to `CRM CLient V4` will be documented in this file. +# version 4.1.3 +- Added: client tests for registering a claim + # version 4.1.2 - Changed: force string cast in ctype_digit method diff --git a/composer.json b/composer.json index 7108217..95319b5 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "library", "description": "LDC CRM Client V4", "license": "MIT", - "version": "4.1.2", + "version": "4.1.3", "authors": [ { "name": "Jérémy Munsch",