| 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 SquareConnect\Configuration; |
| 27 |
use \WooCommerce\Square\Framework\Api\API_Request; |
| 28 |
|
| 29 |
defined( 'ABSPATH' ) || exit; |
| 30 |
|
| 31 |
/** |
| 32 |
* Base WooCommerce Square API request object. |
| 33 |
* |
| 34 |
* @since 2.0.0 |
| 35 |
*/ |
| 36 |
class Request implements 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 = array(); |
| 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 |
return $this->square_api_method; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
/** |
| 84 |
* Gets the arguments to call the Square API method with. |
| 85 |
* |
| 86 |
* @since 2.0.0 |
| 87 |
* |
| 88 |
* @return array |
| 89 |
*/ |
| 90 |
public function get_square_api_args() { |
| 91 |
|
| 92 |
return $this->square_api_args; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
/** |
| 97 |
* Returns whether this request is set to get HTTP info. |
| 98 |
* |
| 99 |
* @since 2.0.0 |
| 100 |
* |
| 101 |
* @return bool |
| 102 |
*/ |
| 103 |
public function get_with_http_info() { |
| 104 |
|
| 105 |
return $this->with_http_info; |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
/** |
| 110 |
* Gets the HTTP method. |
| 111 |
* |
| 112 |
* @since 2.0.0 |
| 113 |
* |
| 114 |
* @return string |
| 115 |
*/ |
| 116 |
public function get_method() { |
| 117 |
// TODO: Implement get_method() method. |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
/** |
| 122 |
* Gets the query parameters. |
| 123 |
* |
| 124 |
* @since 2.0.0 |
| 125 |
* |
| 126 |
* @return array |
| 127 |
*/ |
| 128 |
public function get_params() { |
| 129 |
// TODO: Implement get_params() method. |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
/** |
| 134 |
* Gets the path. |
| 135 |
* |
| 136 |
* @since 2.0.0 |
| 137 |
* |
| 138 |
* @return string |
| 139 |
*/ |
| 140 |
public function get_path() { |
| 141 |
// TODO: Implement get_path() method. |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
/** |
| 146 |
* Gets the request data. |
| 147 |
* |
| 148 |
* @since 2.0.0 |
| 149 |
* |
| 150 |
* @return array |
| 151 |
*/ |
| 152 |
public function get_data() { |
| 153 |
// TODO: Implement get_data() method. |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
/** |
| 158 |
* Gets the request data as a string. |
| 159 |
* |
| 160 |
* @since 2.0.0 |
| 161 |
* |
| 162 |
* @return string |
| 163 |
*/ |
| 164 |
public function to_string() { |
| 165 |
|
| 166 |
$body = ''; |
| 167 |
|
| 168 |
if ( is_callable( array( $this->square_request, '__toString' ) ) ) { |
| 169 |
|
| 170 |
$body = $this->square_request->__toString(); |
| 171 |
|
| 172 |
} elseif ( is_array( $this->square_api_args ) ) { |
| 173 |
|
| 174 |
$body = array(); |
| 175 |
|
| 176 |
foreach ( $this->square_api_args as $key => $arg ) { |
| 177 |
|
| 178 |
if ( is_callable( array( $arg, '__toString' ) ) ) { |
| 179 |
$body[ $key ] = $arg->__toString(); |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
$body = implode( ',', $body ); |
| 184 |
} |
| 185 |
|
| 186 |
return $body; |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
/** |
| 191 |
* Gets the request data as a string with all sensitive information masked. |
| 192 |
* |
| 193 |
* @since 2.0.0 |
| 194 |
* |
| 195 |
* @return string |
| 196 |
*/ |
| 197 |
public function to_string_safe() { |
| 198 |
|
| 199 |
return $this->to_string(); |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
} |
| 204 |
|