'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' ]; 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; } /** * 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 get_class($properties['country']) === ArcadiaOrderType::class) ? $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); } // 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 */ public function send(): bool { $this->validateAllValues(); static::setUpApiInterface(); // set apiInterface $request = Utils::getResquest('apiV2.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 ]; } }