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;
|
|
|
|
|
use ReflectionClass;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This class represents the customer info with
|
|
|
|
|
* the account validation status
|
|
|
|
|
*
|
|
|
|
|
* @property int $operation The arcadia operation code
|
|
|
|
|
* Validate: int
|
|
|
|
|
* Required
|
|
|
|
|
*
|
|
|
|
|
* @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
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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 = [
|
|
|
|
|
'operation', 'support_code', 'label_type_support',
|
|
|
|
|
'order_date', 'code_unique', 'code_on_pack'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Validation rules
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected static $validation = [
|
|
|
|
|
'operation' => 'required|int',
|
|
|
|
|
'support_code' => 'required|int',
|
|
|
|
|
'label_type_support' => 'required|string|min:2|max:255',
|
|
|
|
|
'order_date' => 'required|date',
|
|
|
|
|
'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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
*/
|
|
|
|
|
public function send(Customer $customer): 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();
|
|
|
|
|
static::setUpApiInterface(); // set apiInterface
|
|
|
|
|
$request = Utils::getResquest('apiV2.arcadia.outgoingMailGame', [
|
|
|
|
|
'customer' => $customer->hashcode
|
|
|
|
|
], $data);
|
|
|
|
|
$response = static::$apiInterface->call($request);
|
|
|
|
|
if ($status = $response->status->equals(ApiStatus::OK())) {
|
|
|
|
|
$this->updatedValues = [];
|
|
|
|
|
}
|
|
|
|
|
$this->isNew = !$status;
|
|
|
|
|
return $status;
|
|
|
|
|
}
|
|
|
|
|
}
|