2021-08-09 09:18:46 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace LDC\LDCCRM\Models;
|
|
|
|
|
|
|
|
|
|
use LDC\LDCCRM\Enums\ApiStatus;
|
|
|
|
|
use LDC\LDCCRM\Enums\ArcadiaOrderType;
|
|
|
|
|
use LDC\LDCCRM\Utils;
|
2021-10-18 16:05:03 +02:00
|
|
|
use TypeError;
|
2021-08-09 09:18:46 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This class represents the customer info with
|
|
|
|
|
* the account validation status
|
|
|
|
|
*
|
|
|
|
|
* @property int $operation The arcadia operation code
|
|
|
|
|
* Validate: int
|
|
|
|
|
* Required
|
|
|
|
|
*
|
2021-10-18 09:02:31 +02:00
|
|
|
* @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
|
|
|
|
|
*
|
2021-08-09 09:18:46 +02:00
|
|
|
* @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'
|
|
|
|
|
* @property string $code_unique The arcadia code unique
|
|
|
|
|
* @property string $code_on_pack The arcadia code on pack
|
|
|
|
|
*
|
|
|
|
|
* @category Api Models
|
|
|
|
|
* @package LDCCrmClient
|
|
|
|
|
* @subpackage models
|
|
|
|
|
*/
|
|
|
|
|
class ArcadiaMailGame extends CrmClientModel
|
|
|
|
|
{
|
|
|
|
|
|
2021-10-18 09:02:31 +02:00
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
2021-12-06 00:16:13 +01:00
|
|
|
private $lastname = null;
|
2021-10-18 09:02:31 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
|
2021-08-09 09:18:46 +02:00
|
|
|
/**
|
|
|
|
|
* @var int
|
|
|
|
|
* @access private
|
|
|
|
|
* */
|
|
|
|
|
private $operation = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The arcadia support code
|
|
|
|
|
*
|
|
|
|
|
* Validate: int
|
|
|
|
|
*
|
|
|
|
|
* Required
|
|
|
|
|
*
|
|
|
|
|
* @var int
|
|
|
|
|
*/
|
|
|
|
|
private $support_code = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The arcadia type support label
|
|
|
|
|
*
|
|
|
|
|
* Validate: string
|
|
|
|
|
*
|
|
|
|
|
* Required
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
private $label_type_support = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The arcadia order date
|
|
|
|
|
*
|
|
|
|
|
* Validate: date
|
|
|
|
|
*
|
|
|
|
|
* Required
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
private $order_date = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The arcadia code unique
|
|
|
|
|
*
|
|
|
|
|
* Validate: string
|
|
|
|
|
*
|
|
|
|
|
* Required
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
private $code_unique = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The arcadia code on pack
|
|
|
|
|
*
|
|
|
|
|
* Validate: sometimes
|
|
|
|
|
*
|
|
|
|
|
* Required
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
private $code_on_pack = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The crm customer fields
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $modelFields = [
|
2021-10-18 09:02:31 +02:00
|
|
|
'email', 'firstname',
|
|
|
|
|
'lastname', 'phone', 'address',
|
|
|
|
|
'address2', 'city', 'postcode',
|
2021-08-09 09:18:46 +02:00
|
|
|
'operation', 'support_code', 'label_type_support',
|
|
|
|
|
'order_date', 'code_unique', 'code_on_pack'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Validation rules
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected static $validation = [
|
2021-10-18 09:02:31 +02:00
|
|
|
'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',
|
2021-08-09 09:18:46 +02:00
|
|
|
'operation' => 'required|int',
|
|
|
|
|
'support_code' => 'required|int',
|
|
|
|
|
'label_type_support' => 'required|string|min:2|max:255',
|
2021-08-13 10:24:57 +02:00
|
|
|
'order_date' => 'required|date_format:Y/m/d H:i:s',
|
2021-08-09 09:18:46 +02:00
|
|
|
'code_unique' => 'required|string',
|
|
|
|
|
'code_on_pack' => 'sometimes|string'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function __construct(array $properties = [])
|
|
|
|
|
{
|
|
|
|
|
parent::__construct();
|
|
|
|
|
$this->fill($properties);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set prop
|
|
|
|
|
*
|
|
|
|
|
* @param string $field
|
|
|
|
|
* @param mixed $value
|
|
|
|
|
* @throws TypeError if the field has an incorrect value
|
|
|
|
|
* @return mixed|null The input value or null is this prop does not exists
|
|
|
|
|
*/
|
|
|
|
|
public function __set(string $field, $value)
|
|
|
|
|
{
|
|
|
|
|
$out = parent::__set($field, $value);
|
|
|
|
|
if (in_array($field, $this->modelFields)) {
|
|
|
|
|
$this->updatedValues[$field] = (\is_object($value) and
|
|
|
|
|
get_class($value) === ArcadiaOrderType::class) ? $value->value : $value;
|
|
|
|
|
$this->setRawProperty($this, $field, $this->updatedValues[$field]);
|
|
|
|
|
}
|
|
|
|
|
return $out;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 16:05:03 +02:00
|
|
|
/**
|
|
|
|
|
* Fill data into this model
|
|
|
|
|
* using validation rules
|
|
|
|
|
*
|
|
|
|
|
* @param array $properties
|
|
|
|
|
* @return void
|
|
|
|
|
* @throws TypeError if any valid is not validated
|
|
|
|
|
*/
|
|
|
|
|
public function fill(array $properties)
|
|
|
|
|
{
|
|
|
|
|
if (isset($properties['state_order'])) {
|
|
|
|
|
try {
|
|
|
|
|
$properties['state_order'] = (\is_object($properties['state_order']) and
|
2021-11-30 16:10:00 +01:00
|
|
|
get_class($properties['state_order']) === ArcadiaOrderType::class) ?
|
2021-10-18 16:05:03 +02:00
|
|
|
$properties['state_order']->value : (ctype_digit($properties['state_order']) ?
|
|
|
|
|
(int)$properties['state_order'] : $properties['state_order']);
|
|
|
|
|
} catch (TypeError $e) {
|
|
|
|
|
// cast anyway
|
|
|
|
|
$properties['state_order'] = (int)$properties['state_order'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
parent::fill($properties);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-09 09:18:46 +02:00
|
|
|
// PUBLIC METHODS
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send The actual mail
|
|
|
|
|
*
|
|
|
|
|
* @return boolean true if succeeded
|
2021-08-12 14:49:27 +02:00
|
|
|
* @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
|
2021-08-09 09:18:46 +02:00
|
|
|
*/
|
2021-10-18 09:02:31 +02:00
|
|
|
public function send(): bool
|
2021-08-09 09:18:46 +02:00
|
|
|
{
|
2021-10-18 09:02:31 +02:00
|
|
|
$this->validateAllValues();
|
2021-08-09 09:18:46 +02:00
|
|
|
static::setUpApiInterface(); // set apiInterface
|
2021-12-06 00:16:13 +01:00
|
|
|
$request = Utils::getResquest('apiV2.arcadia.outgoingMailGame', [], $this->jsonSerialize());
|
2021-08-09 09:18:46 +02:00
|
|
|
$response = static::$apiInterface->call($request);
|
|
|
|
|
if ($status = $response->status->equals(ApiStatus::OK())) {
|
|
|
|
|
$this->updatedValues = [];
|
|
|
|
|
}
|
|
|
|
|
$this->isNew = !$status;
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
2021-08-16 13:22:34 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Serialize this object to an array
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function jsonSerialize()
|
|
|
|
|
{
|
|
|
|
|
return [
|
2021-10-18 09:02:31 +02:00
|
|
|
'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,
|
|
|
|
|
],
|
2021-08-16 13:22:34 +02:00
|
|
|
'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
|
|
|
|
|
];
|
|
|
|
|
}
|
2021-08-09 09:18:46 +02:00
|
|
|
}
|