358 lines
9.1 KiB
PHP
358 lines
9.1 KiB
PHP
<?php
|
|
|
|
namespace LDC\LDCCRM\Models;
|
|
|
|
use LDC\LDCCRM\Enums\ApiStatus;
|
|
use LDC\LDCCRM\Enums\ArcadiaOrderType;
|
|
use LDC\LDCCRM\Utils;
|
|
|
|
/**
|
|
* This class represents the customer info with
|
|
* the account validation status
|
|
*
|
|
* @property integer $operation The arcadia operation code
|
|
* Validate: int
|
|
* Required
|
|
*
|
|
* @property string|null $email Must be a rfc valid email on a valid domain name
|
|
* @property string|null $firstname The account first name
|
|
* @property string|null $lastname The account last name
|
|
* @property string|null $phone The account phone
|
|
* @property string|null $address The account address (street number, name, build, flat number)
|
|
* @property string|null $address2 The account phone (address complement)
|
|
* @property string|null $city The account city name
|
|
* @property string|null $postcode The account city postcode
|
|
*
|
|
* @property integer|null $support_code The arcadia support code
|
|
* @property string|null $label_type_support The arcadia type support label
|
|
* @property string|null $order_date The arcadia order date 'yyyy-mm-dd HH:ii:ss'
|
|
* @property string|null $code_unique The arcadia code unique
|
|
* @property string|null $code_on_pack The arcadia code on pack
|
|
*
|
|
* @category Api Models
|
|
* @package LDCCrmClient
|
|
* @subpackage models
|
|
* @author Jérémy Munsch <jeremy.munsch@ldc.fr>
|
|
*/
|
|
class ArcadiaMailGame extends ClientModel
|
|
{
|
|
/**
|
|
* An RFC Valid Email
|
|
*
|
|
* Validate: rfc,dns,spoof,filter
|
|
*
|
|
* Required
|
|
* Min length N/A
|
|
* Max length 255
|
|
* Field Type varchar
|
|
*
|
|
* @var string|null
|
|
*/
|
|
private ?string $email = null;
|
|
|
|
/**
|
|
* First name
|
|
*
|
|
* Required
|
|
* Min length 2
|
|
* Max length 255
|
|
* Field Type varchar
|
|
*
|
|
* @var string|null
|
|
*/
|
|
private ?string $firstname = null;
|
|
|
|
/**
|
|
* Last name
|
|
*
|
|
* Required
|
|
* Min length 2
|
|
* Max length 255
|
|
* Field Type varchar
|
|
*
|
|
* @var string|null
|
|
*/
|
|
private ?string $lastname = null;
|
|
|
|
/**
|
|
* The user phone
|
|
*
|
|
* Validate: sometimes,string
|
|
*
|
|
* Required
|
|
* Min length NA
|
|
* Max length 255
|
|
* Field Type varchar
|
|
*
|
|
* @var string|null
|
|
*/
|
|
private ?string $phone = null;
|
|
|
|
/**
|
|
* The user address (street number, name, etc)
|
|
*
|
|
* Validate: sometimes,string
|
|
*
|
|
* Min length NA
|
|
* Max length 255
|
|
* Field Type varchar
|
|
*
|
|
* @var string|null
|
|
*/
|
|
private ?string $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|null
|
|
*/
|
|
private ?string $address2 = null;
|
|
|
|
/**
|
|
* The user address city
|
|
*
|
|
* Validate: sometimes,string
|
|
*
|
|
* Min length NA
|
|
* Max length 255
|
|
* Field Type varchar
|
|
*
|
|
* @var string|null
|
|
*/
|
|
private ?string $city = null;
|
|
|
|
/**
|
|
* The user address postcode
|
|
*
|
|
* Validate: string
|
|
*
|
|
* Required
|
|
* Min length NA
|
|
* Max length 255
|
|
* Field Type varchar
|
|
*
|
|
* @var string|null
|
|
*/
|
|
private ?string $postcode = null;
|
|
|
|
/**
|
|
* The arcadia operation code
|
|
*
|
|
* Validate: int
|
|
*
|
|
* Required
|
|
*
|
|
* @var integer|null
|
|
*/
|
|
private ?int $operation = null;
|
|
|
|
/**
|
|
* The arcadia support code
|
|
*
|
|
* Validate: int
|
|
*
|
|
* Required
|
|
*
|
|
* @var integer|null
|
|
*/
|
|
private ?int $support_code = null;
|
|
|
|
/**
|
|
* The arcadia type support label
|
|
*
|
|
* Validate: string
|
|
*
|
|
* Required
|
|
*
|
|
* @var string|null
|
|
*/
|
|
private ?string $label_type_support = null;
|
|
|
|
/**
|
|
* The arcadia order date
|
|
*
|
|
* Validate: date
|
|
*
|
|
* Required
|
|
*
|
|
* @var string|null
|
|
*/
|
|
private ?string $order_date = null;
|
|
|
|
/**
|
|
* The arcadia code unique
|
|
*
|
|
* Validate: string
|
|
*
|
|
* Required
|
|
*
|
|
* @var string|null
|
|
*/
|
|
private ?string $code_unique = null;
|
|
|
|
/**
|
|
* The arcadia code on pack
|
|
*
|
|
* Validate: sometimes
|
|
*
|
|
* Required
|
|
*
|
|
* @var string|null
|
|
*/
|
|
private ?string $code_on_pack = null;
|
|
|
|
/**
|
|
* The crm customer fields
|
|
*
|
|
* @var array
|
|
*/
|
|
protected array $modelFields = [
|
|
'email',
|
|
'firstname',
|
|
'lastname',
|
|
'phone',
|
|
'address',
|
|
'address2',
|
|
'city',
|
|
'postcode',
|
|
'operation',
|
|
'support_code',
|
|
'label_type_support',
|
|
'order_date',
|
|
'code_unique',
|
|
'code_on_pack',
|
|
];
|
|
|
|
/**
|
|
* Validation rules
|
|
*
|
|
* @var array
|
|
*/
|
|
protected static array $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',
|
|
'order_date' => 'required|date_format:Y/m/d H:i:s',
|
|
'code_unique' => 'required|string',
|
|
'code_on_pack' => 'sometimes|string'
|
|
];
|
|
|
|
/**
|
|
* ArcadiaMailGame
|
|
*
|
|
* @param array $properties
|
|
* @throws \LDC\LDCCRM\Exceptions\ValidationException If a field could not be validated.
|
|
*/
|
|
public function __construct(array $properties = [])
|
|
{
|
|
parent::__construct();
|
|
$this->fill($properties);
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set prop
|
|
*
|
|
* @param string $field
|
|
* @param mixed $value
|
|
* @return void
|
|
* @throws \TypeError If the field has an incorrect value.
|
|
* @throws \LDC\LDCCRM\Exceptions\AccessError If trying to set a value on a unknown property.
|
|
*/
|
|
public function __set(string $field, mixed $value): void
|
|
{
|
|
if ($field === 'state_order') {
|
|
$value = (\is_object($value) and
|
|
get_class($value) === ArcadiaOrderType::class) ? $value->value() : $value;
|
|
}
|
|
parent::__set($field, $value);
|
|
}
|
|
|
|
/**
|
|
* Fill data into this model
|
|
* using validation rules
|
|
*
|
|
* @param array $properties
|
|
* @return void
|
|
* @throws \LDC\LDCCRM\Exceptions\ValidationException If a field could not be validated.
|
|
*/
|
|
public function fill(array $properties)
|
|
{
|
|
if (isset($properties['state_order'])) {
|
|
try {
|
|
$properties['state_order'] = (\is_object($properties['state_order']) and
|
|
get_class($properties['state_order']) === ArcadiaOrderType::class) ?
|
|
$properties['state_order']->value : (ctype_digit($properties['state_order']) ?
|
|
(int)$properties['state_order'] : $properties['state_order']);
|
|
} catch (\TypeError | \BadMethodCallException) {
|
|
// * Cast anyway
|
|
$properties['state_order'] = (int)$properties['state_order'];
|
|
}
|
|
}
|
|
parent::fill($properties);
|
|
}
|
|
|
|
// * PUBLIC METHODS
|
|
|
|
/**
|
|
* Send The actual mail
|
|
*
|
|
* @return boolean true if succeeded
|
|
* @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 : - validationFailed, If provided data is wrong(CRM side).
|
|
*/
|
|
public function send(): bool
|
|
{
|
|
$this->validateAllValues();
|
|
static::setUpApiInterface();
|
|
$request = Utils::getResquest('apiV4.arcadia.outgoingMailGame', [], $this->jsonSerialize());
|
|
$response = static::$apiInterface->call($request);
|
|
if ($status = $response->status->equals(ApiStatus::OK)) {
|
|
$this->updatedValues = [];
|
|
}
|
|
$this->isNew = !$status;
|
|
return $status;
|
|
}
|
|
|
|
/**
|
|
* Serialize this object to an array
|
|
*
|
|
* @return array
|
|
*/
|
|
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,
|
|
'order_date' => $this->order_date,
|
|
'code_unique' => $this->code_unique,
|
|
'code_on_pack' => $this->code_on_pack
|
|
];
|
|
}
|
|
}
|