name = trim($name); } /** * @throws APIException */ public function loadByName() { $deliveryMethods = Curl::simple('deliveryMethods/getAll', []); if (!empty($deliveryMethods) && is_array($deliveryMethods)) { foreach ($deliveryMethods as $deliveryMethod) { if ($deliveryMethod['name'] === $this->name) { $this->delivery_method_id = $deliveryMethod['delivery_method_id']; return $this; } } } return false; } /** * Create a Payment Methods based on the name * * @return DeliveryMethod * * @throws GenericException * @throws APIException */ public function create(): DeliveryMethod { $insert = Curl::simple('deliveryMethods/insert', $this->mapPropsToValues()); if (isset($insert['delivery_method_id'])) { $this->delivery_method_id = $insert['delivery_method_id']; return $this; } throw new GenericException(__('Erro ao inserir a método de transporte') . $this->name); } /** * Map this object properties to an array to insert/update a moloni Payment Value * * @return array */ private function mapPropsToValues(): array { $values = []; $values['name'] = $this->name; return $values; } }