diff --git a/apiConfig.readonly.json b/apiConfig.readonly.json index 8784673..0e607c4 100644 --- a/apiConfig.readonly.json +++ b/apiConfig.readonly.json @@ -1,5 +1,5 @@ { - "version": "2.1.8", + "version": "2.2.0", "tokenTimeout": 60, "apiRequestRatePerMinute": 256, "servicesDBCache": 10 diff --git a/changelog.md b/changelog.md index 341d5fe..b3c7de0 100644 --- a/changelog.md +++ b/changelog.md @@ -2,5 +2,9 @@ All notable changes to `CRM CLient V2` will be documented in this file. +# version 2.2.0 +- Fixed Utils.php getResquest method +- Changed Arcadia mails, add customer parameters for these calls + # version 2.1.9 - Fixed method CrmClientModel::fill now validates data and put value to updatedValues array diff --git a/composer.json b/composer.json index ea2643f..b70fe16 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "library", "description": "LDC CRM Client V2", "license": "MIT", - "version": "2.1.9", + "version": "2.2.0", "authors": [ { "name": "Jérémy Munsch", diff --git a/src/Models/ArcadiaMailDefault.php b/src/Models/ArcadiaMailDefault.php index 581d12e..6c12b41 100644 --- a/src/Models/ArcadiaMailDefault.php +++ b/src/Models/ArcadiaMailDefault.php @@ -5,13 +5,21 @@ namespace LDC\LDCCRM\Models; use LDC\LDCCRM\Enums\ApiStatus; use LDC\LDCCRM\Enums\ArcadiaOrderType; use LDC\LDCCRM\Utils; -use ReflectionClass; use TypeError; /** * This class represents the customer info with * the account validation status * + * @property string $email Must be a rfc valid email on a valid domain name + * @property string $firstname The account first name + * @property string $lastname The account last name + * @property string $phone The account phone + * @property string $address The account address (street number, name, build, flat number) + * @property string $address2 The account phone (address complement) + * @property string $city The account city name + * @property string $postcode The account city postcode + * * @property int $operation The arcadia operation code * @property int $support_code The arcadia support code * @property string $label_type_support The arcadia type support label @@ -27,6 +35,111 @@ use TypeError; class ArcadiaMailDefault extends CrmClientModel { + /** + * An RFC Valid Email + * + * Validate: rfc,dns,spoof,filter + * + * Required + * Min length N/A + * Max length 255 + * Field Type varchar + * + * @var string + */ + private $email = null; + + /** + * First name + * + * Required + * Min length 2 + * Max length 255 + * Field Type varchar + * + * @var string + */ + private $firstname = null; + + /** + * Last name + * + * Required + * Min length 2 + * Max length 255 + * Field Type varchar + * + * @var string + */ + private $lastname = null; + + /** + * The user phone + * + * Validate: sometimes,string + * + * Required + * Min length NA + * Max length 255 + * Field Type varchar + * + * @var string + */ + private $phone = null; + + /** + * The user address (street number, name, etc) + * + * Validate: sometimes,string + * + * Min length NA + * Max length 255 + * Field Type varchar + * + * @var string + */ + private $address = null; + + /** + * The user address 2nd part (street number, name, more, etc) + * + * Validate: sometimes,string + * + * Min length NA + * Max length 255 + * Field Type varchar + * + * @var string + */ + private $address2 = null; + + /** + * The user address city + * + * Validate: sometimes,string + * + * Min length NA + * Max length 255 + * Field Type varchar + * + * @var string + */ + private $city = null; + + /** + * The user address postcode + * + * Validate: string + * + * Required + * Min length NA + * Max length 255 + * Field Type varchar + * + * @var string + */ + private $postcode = null; + /** * The arcadia operation code * @@ -110,6 +223,9 @@ class ArcadiaMailDefault extends CrmClientModel * @var array */ protected $modelFields = [ + 'email', 'firstname', + 'lastname', 'phone', 'address', + 'address2', 'city', 'postcode', 'operation', 'support_code', 'label_type_support', 'order_date', 'order_num', 'state_order', 'package_unit_weight', @@ -121,6 +237,14 @@ class ArcadiaMailDefault extends CrmClientModel * @var array */ protected static $validation = [ + 'email' => 'required|email', + 'firstname' => 'required|string|min:2|max:255', + 'lastname' => 'required|string|min:2|max:255', + 'phone' => 'sometimes|string|min:10|max:255', + 'address' => 'sometimes|string|max:255', + 'address2' => 'sometimes|string|max:255', + 'city' => 'sometimes|string|max:255', + 'postcode' => 'sometimes|string|max:255', 'operation' => 'required|int', 'support_code' => 'required|int', 'label_type_support' => 'required|string|min:2|max:255', @@ -233,20 +357,11 @@ class ArcadiaMailDefault extends CrmClientModel * @throws \LDC\LDCCRM\Exceptions\ApiErrorException * If any error or \LDC\LDCCRM\Enums\ApiError occurs */ - public function send(Customer $customer): bool + public function send(): bool { - // validate customer hashcode - $refClass = new ReflectionClass(\get_class($customer)); - $refMeth = $refClass->getMethod('validateValue'); - $refMeth->setAccessible(true); - $refMeth->invokeArgs($customer, ['hashcode', $customer->hashcode]); - - // Send mail - $data = $this->validateAllValues(); + $this->validateAllValues(); static::setUpApiInterface(); // set apiInterface - $request = Utils::getResquest('apiV2.arcadia.outgoingMailDefault', [ - 'customer' => $customer->hashcode - ], $data); + $request = Utils::getResquest('apiV2.arcadia.outgoingMailDefault', $this->jsonSerialize()); $response = static::$apiInterface->call($request); if ($status = $response->status->equals(ApiStatus::OK())) { $this->updatedValues = []; @@ -263,6 +378,16 @@ class ArcadiaMailDefault extends CrmClientModel public function jsonSerialize() { return [ + 'deliver' => [ + 'email' => $this->email, + 'firstname' => $this->firstname, + 'lastname' => $this->lastname, + 'phone' => $this->phone, + 'address' => $this->address, + 'address2' => $this->address2, + 'city' => $this->city, + 'postcode' => $this->postcode, + ], 'operation' => $this->operation, 'support_code' => $this->support_code, 'label_type_support' => $this->label_type_support, diff --git a/src/Models/ArcadiaMailGame.php b/src/Models/ArcadiaMailGame.php index 1917fa9..5edd564 100644 --- a/src/Models/ArcadiaMailGame.php +++ b/src/Models/ArcadiaMailGame.php @@ -5,7 +5,6 @@ namespace LDC\LDCCRM\Models; use LDC\LDCCRM\Enums\ApiStatus; use LDC\LDCCRM\Enums\ArcadiaOrderType; use LDC\LDCCRM\Utils; -use ReflectionClass; /** * This class represents the customer info with @@ -15,6 +14,15 @@ use ReflectionClass; * Validate: int * Required * + * @property string $email Must be a rfc valid email on a valid domain name + * @property string $firstname The account first name + * @property string $lastname The account last name + * @property string $phone The account phone + * @property string $address The account address (street number, name, build, flat number) + * @property string $address2 The account phone (address complement) + * @property string $city The account city name + * @property string $postcode The account city postcode + * * @property int $support_code The arcadia support code * @property string $label_type_support The arcadia type support label * @property string $order_date The arcadia order date 'yyyy-mm-dd HH:ii:ss' @@ -28,6 +36,111 @@ use ReflectionClass; class ArcadiaMailGame extends CrmClientModel { + /** + * An RFC Valid Email + * + * Validate: rfc,dns,spoof,filter + * + * Required + * Min length N/A + * Max length 255 + * Field Type varchar + * + * @var string + */ + private $email = null; + + /** + * First name + * + * Required + * Min length 2 + * Max length 255 + * Field Type varchar + * + * @var string + */ + private $firstname = null; + + /** + * Last name + * + * Required + * Min length 2 + * Max length 255 + * Field Type varchar + * + * @var string + */ + private $lastname = null; + + /** + * The user phone + * + * Validate: sometimes,string + * + * Required + * Min length NA + * Max length 255 + * Field Type varchar + * + * @var string + */ + private $phone = null; + + /** + * The user address (street number, name, etc) + * + * Validate: sometimes,string + * + * Min length NA + * Max length 255 + * Field Type varchar + * + * @var string + */ + private $address = null; + + /** + * The user address 2nd part (street number, name, more, etc) + * + * Validate: sometimes,string + * + * Min length NA + * Max length 255 + * Field Type varchar + * + * @var string + */ + private $address2 = null; + + /** + * The user address city + * + * Validate: sometimes,string + * + * Min length NA + * Max length 255 + * Field Type varchar + * + * @var string + */ + private $city = null; + + /** + * The user address postcode + * + * Validate: string + * + * Required + * Min length NA + * Max length 255 + * Field Type varchar + * + * @var string + */ + private $postcode = null; + /** * @var int * @access private @@ -95,6 +208,9 @@ class ArcadiaMailGame extends CrmClientModel * @var array */ protected $modelFields = [ + 'email', 'firstname', + 'lastname', 'phone', 'address', + 'address2', 'city', 'postcode', 'operation', 'support_code', 'label_type_support', 'order_date', 'code_unique', 'code_on_pack' ]; @@ -105,6 +221,14 @@ class ArcadiaMailGame extends CrmClientModel * @var array */ protected static $validation = [ + 'email' => 'required|email', + 'firstname' => 'required|string|min:2|max:255', + 'lastname' => 'required|string|min:2|max:255', + 'phone' => 'sometimes|string|min:10|max:255', + 'address' => 'sometimes|string|max:255', + 'address2' => 'sometimes|string|max:255', + 'city' => 'sometimes|string|max:255', + 'postcode' => 'sometimes|string|max:255', 'operation' => 'required|int', 'support_code' => 'required|int', 'label_type_support' => 'required|string|min:2|max:255', @@ -150,20 +274,11 @@ class ArcadiaMailGame extends CrmClientModel * @throws \LDC\LDCCRM\Exceptions\ApiErrorException * If any error or \LDC\LDCCRM\Enums\ApiError occurs */ - public function send(Customer $customer): bool + public function send(): bool { - // validate customer hashcode - $refClass = new ReflectionClass(\get_class($customer)); - $refMeth = $refClass->getMethod('validateValue'); - $refMeth->setAccessible(true); - $refMeth->invokeArgs($customer, ['hashcode', $customer->hashcode]); - - // Send mail - $data = $this->validateAllValues(); + $this->validateAllValues(); static::setUpApiInterface(); // set apiInterface - $request = Utils::getResquest('apiV2.arcadia.outgoingMailGame', [ - 'customer' => $customer->hashcode - ], $data); + $request = Utils::getResquest('apiV2.arcadia.outgoingMailGame', $this->jsonSerialize()); $response = static::$apiInterface->call($request); if ($status = $response->status->equals(ApiStatus::OK())) { $this->updatedValues = []; @@ -180,6 +295,16 @@ class ArcadiaMailGame extends CrmClientModel public function jsonSerialize() { return [ + 'deliver' => [ + 'email' => $this->email, + 'firstname' => $this->firstname, + 'lastname' => $this->lastname, + 'phone' => $this->phone, + 'address' => $this->address, + 'address2' => $this->address2, + 'city' => $this->city, + 'postcode' => $this->postcode, + ], 'operation' => $this->operation, 'support_code' => $this->support_code, 'label_type_support' => $this->label_type_support, diff --git a/src/Utils.php b/src/Utils.php index d679bc5..b79f504 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -131,7 +131,7 @@ class Utils return \is_string($data[$attribute]) and \strlen($data[$attribute]) >= (int)$rParams[0]; }, - 'error' => self::translate($attribute) . " doit avoir moins ou $rParams[0] caratères" + 'error' => self::translate($attribute) . " doit avoir au moins $rParams[0] caratères" ]; break; case 'max': @@ -308,11 +308,9 @@ class Utils $matchedIndex[$matches[1][$k]] = $query[$matches[1][$k]]; } } - $query = \array_flip($query); - foreach ($matchedIndex as $key) { + foreach ($matchedIndex as $key => $value) { unset($query[$key]); } - $query = \array_flip($query); if (count($query)) { $route['uri'] = sprintf('%s?%s', $route['uri'], \http_build_query($query)); } diff --git a/src/routes.json b/src/routes.json index 6483290..128be2a 100644 --- a/src/routes.json +++ b/src/routes.json @@ -63,13 +63,13 @@ ] }, "apiV2.arcadia.outgoingMailDefault": { - "uri": "api/v2/arcadia/outgoing-mail/{customer}/default", + "uri": "api/v2/arcadia/outgoing-mail/default", "methods": [ "POST" ] }, "apiV2.arcadia.outgoingMailGame": { - "uri": "api/v2/arcadia/outgoing-mail/{customer}/game", + "uri": "api/v2/arcadia/outgoing-mail/game", "methods": [ "POST" ]