PluginProbe
Moloni / 3.0.51
Moloni v3.0.51
5.0.10 5.0.09 5.0.08 5.0.07 5.0.06 trunk 0.4.0.00 0.4.8.1 3.0.10 3.0.11 3.0.35 3.0.36 3.0.37 3.0.38 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.0.46 3.0.47 3.0.48 3.0.49 3.0.50 All 98 releases
moloni / src / Controllers / DeliveryMethod.php

DeliveryMethod.php in Moloni 3.0.51, at src/Controllers/DeliveryMethod.php

84 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 *
4 * Plugin Name: Moloni
5 * Plugin URI: https://plugins.moloni.com/woocommerce
6 * Description: Send your orders automatically to your Moloni invoice software
7 * Version: 0.0.1
8 * Author: Moloni.com
9 * Author URI: https://moloni.com
10 * License: GPL2
11 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
12 *
13 */
14
15 namespace Moloni\Controllers;
16
17
18 use Moloni\Curl;
19 use Moloni\Error;
20
21 class DeliveryMethod
22 {
23 public $delivery_method_id;
24 public $name;
25 public $value = 0;
26
27 /**
28 * Payment constructor.
29 * @param string $name
30 */
31 public function __construct($name)
32 {
33 $this->name = trim($name);
34 }
35
36 /**
37 * @throws Error
38 */
39 public function loadByName()
40 {
41 $deliveryMethods = Curl::simple('deliveryMethods/getAll', []);
42 if (!empty($deliveryMethods) && is_array($deliveryMethods)) {
43 foreach ($deliveryMethods as $deliveryMethod) {
44 if ($deliveryMethod['name'] === $this->name) {
45 $this->delivery_method_id = $deliveryMethod['delivery_method_id'];
46 return $this;
47 }
48 }
49 }
50
51 return false;
52 }
53
54
55 /**
56 * Create a Payment Methods based on the name
57 * @throws Error
58 */
59 public function create()
60 {
61 $insert = Curl::simple('deliveryMethods/insert', $this->mapPropsToValues());
62
63 if (isset($insert['delivery_method_id'])) {
64 $this->delivery_method_id = $insert['delivery_method_id'];
65 return $this;
66 }
67
68 throw new Error(__('Erro ao inserir a método de transporte') . $this->name);
69 }
70
71
72 /**
73 * Map this object properties to an array to insert/update a moloni Payment Value
74 * @return array
75 */
76 private function mapPropsToValues()
77 {
78 $values = [];
79
80 $values['name'] = $this->name;
81
82 return $values;
83 }
84 }