PluginProbe
Moloni / trunk
Moloni vtrunk
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 / Payment.php

Payment.php in Moloni trunk, at src/Controllers/Payment.php

94 lines 2.2 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.pt
9 * Author URI: https://moloni.pt
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\Exceptions\APIException;
20 use Moloni\Exceptions\GenericException;
21
22 class Payment
23 {
24 public $payment_method_id;
25 public $name;
26 public $value = 0;
27
28 /**
29 * Payment constructor.
30 * @param string $name
31 */
32 public function __construct($name)
33 {
34 $this->name = strip_tags(trim($name));
35 }
36
37 /**
38 * This method SHOULD be replaced by a productCategories/getBySearch
39 *
40 * @throws APIException
41 */
42 public function loadByName()
43 {
44 $paymentMethods = Curl::simple('paymentMethods/getAll', []);
45
46 if (!empty($paymentMethods) && is_array($paymentMethods)) {
47 foreach ($paymentMethods as $paymentMethod) {
48 if ($paymentMethod['name'] === $this->name) {
49 $this->payment_method_id = $paymentMethod['payment_method_id'];
50
51 return $this;
52 }
53 }
54 }
55
56 return false;
57 }
58
59
60 /**
61 * Create a Payment Methods based on the name
62 *
63 * @return Payment
64 *
65 * @throws APIException
66 * @throws GenericException
67 */
68 public function create()
69 {
70 $insert = Curl::simple('paymentMethods/insert', $this->mapPropsToValues());
71
72 if (isset($insert['payment_method_id'])) {
73 $this->payment_method_id = $insert['payment_method_id'];
74 return $this;
75 }
76
77 throw new GenericException(__('Erro ao inserir a método de pagamento') . $this->name);
78 }
79
80
81 /**
82 * Map this object properties to an array to insert/update a moloni Payment Value
83 * @return array
84 */
85 private function mapPropsToValues()
86 {
87 $values = [];
88
89 $values['name'] = $this->name;
90
91 return $values;
92 }
93 }
94