Request.php
207 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce Square |
| 4 | * |
| 5 | * This source file is subject to the GNU General Public License v3.0 |
| 6 | * that is bundled with this package in the file license.txt. |
| 7 | * It is also available through the world-wide-web at this URL: |
| 8 | * http://www.gnu.org/licenses/gpl-3.0.html |
| 9 | * If you did not receive a copy of the license and are unable to |
| 10 | * obtain it through the world-wide-web, please send an email |
| 11 | * to license@woocommerce.com so we can send you a copy immediately. |
| 12 | * |
| 13 | * DISCLAIMER |
| 14 | * |
| 15 | * Do not edit or add to this file if you wish to upgrade WooCommerce Square to newer |
| 16 | * versions in the future. If you wish to customize WooCommerce Square for your |
| 17 | * needs please refer to https://docs.woocommerce.com/document/woocommerce-square/ |
| 18 | * |
| 19 | * @author WooCommerce |
| 20 | * @copyright Copyright: (c) 2019, Automattic, Inc. |
| 21 | * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 |
| 22 | */ |
| 23 | |
| 24 | namespace WooCommerce\Square\API; |
| 25 | |
| 26 | use SkyVerge\WooCommerce\PluginFramework\v5_4_0 as Framework; |
| 27 | use SquareConnect\Configuration; |
| 28 | |
| 29 | defined( 'ABSPATH' ) or exit; |
| 30 | |
| 31 | /** |
| 32 | * Base WooCommerce Square API request object. |
| 33 | * |
| 34 | * @since 2.0.0 |
| 35 | */ |
| 36 | class Request implements Framework\SV_WC_API_Request { |
| 37 | |
| 38 | |
| 39 | /** @var Configuration the configuration object */ |
| 40 | protected $configuration; |
| 41 | |
| 42 | /** @var mixed the Square API class instance being used for this request */ |
| 43 | protected $square_api; |
| 44 | |
| 45 | /** @var string method name on the square API to call */ |
| 46 | protected $square_api_method; |
| 47 | |
| 48 | /** @var array arguments for the method call */ |
| 49 | protected $square_api_args = []; |
| 50 | |
| 51 | /** @var null|object the square API request model */ |
| 52 | protected $square_request; |
| 53 | |
| 54 | /** @var bool whether the request is being made 'WithHTTPInfo' or not */ |
| 55 | protected $with_http_info = true; |
| 56 | |
| 57 | |
| 58 | /** |
| 59 | * Gets the Square API instance to use for this request. |
| 60 | * |
| 61 | * @since 2.0.0 |
| 62 | * |
| 63 | * @return mixed |
| 64 | */ |
| 65 | public function get_square_api() { |
| 66 | |
| 67 | return $this->square_api; |
| 68 | } |
| 69 | |
| 70 | |
| 71 | /** |
| 72 | * Get the method to call on the Square API instance. |
| 73 | * |
| 74 | * @since 2.0.0 |
| 75 | * |
| 76 | * @return string |
| 77 | */ |
| 78 | public function get_square_api_method() { |
| 79 | |
| 80 | $method = $this->square_api_method; |
| 81 | |
| 82 | return $this->with_http_info ? $method . 'WithHttpInfo' : $method; |
| 83 | } |
| 84 | |
| 85 | |
| 86 | /** |
| 87 | * Gets the arguments to call the Square API method with. |
| 88 | * |
| 89 | * @since 2.0.0 |
| 90 | * |
| 91 | * @return array |
| 92 | */ |
| 93 | public function get_square_api_args() { |
| 94 | |
| 95 | return $this->square_api_args; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | /** |
| 100 | * Returns whether this request is set to get HTTP info. |
| 101 | * |
| 102 | * @since 2.0.0 |
| 103 | * |
| 104 | * @return bool |
| 105 | */ |
| 106 | public function get_with_http_info() { |
| 107 | |
| 108 | return $this->with_http_info; |
| 109 | } |
| 110 | |
| 111 | |
| 112 | /** |
| 113 | * Gets the HTTP method. |
| 114 | * |
| 115 | * @since 2.0.0 |
| 116 | * |
| 117 | * @return string |
| 118 | */ |
| 119 | public function get_method() { |
| 120 | // TODO: Implement get_method() method. |
| 121 | } |
| 122 | |
| 123 | |
| 124 | /** |
| 125 | * Gets the query parameters. |
| 126 | * |
| 127 | * @since 2.0.0 |
| 128 | * |
| 129 | * @return array |
| 130 | */ |
| 131 | public function get_params() { |
| 132 | // TODO: Implement get_params() method. |
| 133 | } |
| 134 | |
| 135 | |
| 136 | /** |
| 137 | * Gets the path. |
| 138 | * |
| 139 | * @since 2.0.0 |
| 140 | * |
| 141 | * @return string |
| 142 | */ |
| 143 | public function get_path() { |
| 144 | // TODO: Implement get_path() method. |
| 145 | } |
| 146 | |
| 147 | |
| 148 | /** |
| 149 | * Gets the request data. |
| 150 | * |
| 151 | * @since 2.0.0 |
| 152 | * |
| 153 | * @return array |
| 154 | */ |
| 155 | public function get_data() { |
| 156 | // TODO: Implement get_data() method. |
| 157 | } |
| 158 | |
| 159 | |
| 160 | /** |
| 161 | * Gets the request data as a string. |
| 162 | * |
| 163 | * @since 2.0.0 |
| 164 | * |
| 165 | * @return string |
| 166 | */ |
| 167 | public function to_string() { |
| 168 | |
| 169 | $body = ''; |
| 170 | |
| 171 | if ( is_callable( [ $this->square_request, '__toString' ] ) ) { |
| 172 | |
| 173 | $body = $this->square_request->__toString(); |
| 174 | |
| 175 | } elseif ( is_array( $this->square_api_args ) ) { |
| 176 | |
| 177 | $body = []; |
| 178 | |
| 179 | foreach ( $this->square_api_args as $key => $arg ) { |
| 180 | |
| 181 | if ( is_callable( [ $arg, '__toString' ] ) ) { |
| 182 | $body[ $key ] = $arg->__toString(); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | $body = implode( ',', $body ); |
| 187 | } |
| 188 | |
| 189 | return $body; |
| 190 | } |
| 191 | |
| 192 | |
| 193 | /** |
| 194 | * Gets the request data as a string with all sensitive information masked. |
| 195 | * |
| 196 | * @since 2.0.0 |
| 197 | * |
| 198 | * @return string |
| 199 | */ |
| 200 | public function to_string_safe() { |
| 201 | |
| 202 | return $this->to_string(); |
| 203 | } |
| 204 | |
| 205 | |
| 206 | } |
| 207 |