Merge branch 'claim' into 'develop'
fix: ✅ add missing client tests for registering a claim
See merge request ldc-web/projets/crm-client!12
This commit is contained in:
commit
04f3bc8698
4 changed files with 161 additions and 10 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
101
src/Models/Claim.php
Normal file
101
src/Models/Claim.php
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
|
||||
namespace LDC\LDCCRM\Models;
|
||||
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use LDC\LDCCRM\CrmApiV4;
|
||||
use LDC\LDCCRM\Enums\ApiStatus;
|
||||
use LDC\LDCCRM\Utils;
|
||||
|
||||
/**
|
||||
* This class allows to handle claim.
|
||||
*
|
||||
* @category Api Models
|
||||
* @package LDCCrmClient
|
||||
* @subpackage models
|
||||
*/
|
||||
abstract class Claim extends ClientModel
|
||||
{
|
||||
/**
|
||||
* Validation rules.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static array $validation = [
|
||||
'first_name' => '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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue