├── .gitignore ├── LICENSE.txt ├── MasterCard └── Core │ ├── ApiConfig.php │ ├── ApiController.php │ ├── Exception │ └── ApiException.php │ ├── Model │ ├── BaseObject.php │ ├── CaseInsensitiveMap.php │ ├── Constants.php │ ├── Environment.php │ ├── OperationConfig.php │ ├── OperationMetadata.php │ ├── RequestMap.php │ └── SmartMap.php │ ├── Security │ ├── AuthenticationInterface.php │ ├── OAuth │ │ ├── OAuthAuthentication.php │ │ └── OAuthParameters.php │ └── SecurityUtil.php │ └── Util.php ├── README.md ├── Test └── MasterCard │ ├── Api │ ├── AccountInquiry.php │ ├── AccountInquiryTest.php │ ├── BaseTest.php │ ├── Insights.php │ ├── InsightsTest.php │ ├── JsonEcho.php │ ├── JsonEchoTest.php │ ├── MerchantCountries.php │ ├── MerchantCountriesTest.php │ ├── MultiplePathUserPost.php │ ├── MultiplePathUserPostTest.php │ ├── NodeJSFunctionalTest.php │ ├── Parameters.php │ ├── ParametersTest.php │ ├── Post.php │ ├── PostTest.php │ ├── ResourceConfig.php │ ├── User.php │ ├── UserPostHeader.php │ ├── UserPostHeaderTest.php │ ├── UserPostPath.php │ ├── UserPostPathTest.php │ └── UserTest.php │ └── Core │ ├── ApiControllerTest.php │ ├── Model │ └── BaseMapTest.php │ ├── Security │ └── OAuth │ │ └── OAuthUtilTest.php │ └── UtilTest.php ├── bin └── composer.phar ├── composer.json ├── composer.sh ├── fake-key.p12 ├── nbproject ├── project.properties └── project.xml ├── phpunit.xml └── run-test.sh /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/* 2 | vendor 3 | composer.lock 4 | /nbproject/private/ 5 | /nodejs-server/node_modules/ 6 | nbproject/ 7 | .idea/ 8 | result/ 9 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /MasterCard/Core/ApiConfig.php: -------------------------------------------------------------------------------- 1 | self::$CONNECTION_TIMEOUT, 'read_timeout' => self::$READ_TIMEOUT ]; 93 | } 94 | 95 | 96 | /** 97 | * Sets the proxy configuration 98 | * @param type $proxy 99 | */ 100 | public static function setProxy($proxy) { 101 | if (!empty($proxy)) { 102 | static::$PROXY = $proxy; 103 | } else { 104 | static::$PROXY = array(); 105 | } 106 | } 107 | 108 | 109 | /** 110 | * Get the proxy configuration 111 | * @return type 112 | */ 113 | public static function getProxy() { 114 | if (!empty(self::$PROXY)) { 115 | return [ 'proxy' => self::$PROXY ]; 116 | } else { 117 | return array(); 118 | } 119 | } 120 | 121 | /** 122 | * Sets the sandbox. 123 | * @param boolean sandbox 124 | */ 125 | public static function setSandbox($sandbox) 126 | { 127 | if ($sandbox == true) { 128 | static::setEnvironment(Environment::SANDBOX); 129 | } else { 130 | static::setEnvironment(Environment::PRODUCTION); 131 | } 132 | } 133 | 134 | 135 | /** 136 | * This method is used to set the SubDomain 137 | * @param type $subDomain 138 | */ 139 | public static function setEnvironment($environment) { 140 | if (!empty($environment)) { 141 | foreach (array_values(static::$registeredInstances) as $instance) { 142 | $instance->setEnvironment($environment); 143 | } 144 | static::$ENVIRONMENT = $environment; 145 | } 146 | 147 | } 148 | 149 | /** 150 | * This method is used to return the set environment 151 | * @return type 152 | */ 153 | public static function getEnvironment() { 154 | return static::$ENVIRONMENT; 155 | } 156 | 157 | 158 | /** 159 | * This is used to add the SDKCOnfig to the APIConfig 160 | * so when the configuration changes the underline SDKConfig 161 | * are updated. 162 | * 163 | * @param type $instance 164 | */ 165 | public static function registerResourceConfig($instance) { 166 | $className = get_class($instance); 167 | if (!array_key_exists($className, static::$registeredInstances)){ 168 | static::$registeredInstances['$className'] = $instance; 169 | } 170 | } 171 | 172 | 173 | public static function clearResourceConfig() { 174 | static::$registeredInstances = array(); 175 | } 176 | 177 | /** 178 | * Sets the sandbox. 179 | * @param boolean sandbox 180 | */ 181 | public static function setAuthentication(AuthenticationInterface $authentication) 182 | { 183 | static::$AUTHENTICATION = $authentication; 184 | } 185 | 186 | 187 | /** 188 | * Sets get debug. 189 | */ 190 | public static function getAuthentication() 191 | { 192 | return static::$AUTHENTICATION; 193 | } 194 | 195 | } -------------------------------------------------------------------------------- /MasterCard/Core/ApiController.php: -------------------------------------------------------------------------------- 1 | logger = new Logger('ApiController'); 62 | 63 | $this->checkState(); 64 | 65 | $this->client = new Client([ 66 | 'config' => [ 67 | 'curl' => [ 68 | CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1_2 69 | ] 70 | ] 71 | ]); 72 | } 73 | 74 | /// 75 | /// Checks the state. 76 | /// 77 | private function checkState() { 78 | 79 | if (ApiConfig::getAuthentication() == null) { 80 | throw new ApiException("No ApiConfig::authentication has been configured"); 81 | } 82 | 83 | } 84 | 85 | private function removeForwardSlashFromTail($url) { 86 | return preg_replace('{/$}', '', $url); 87 | } 88 | 89 | private function appendToQueryString($s, $stringToAppend) { 90 | if (strpos($s, "?") == false) { 91 | $s .= "?"; 92 | } else { 93 | $s .= "&"; 94 | } 95 | 96 | $s .= $stringToAppend; 97 | 98 | return $s; 99 | } 100 | 101 | /** 102 | * @ignore 103 | */ 104 | public function setClient($customClient) { 105 | $this->client = $customClient; 106 | } 107 | 108 | /** 109 | * This method generated the URL 110 | * @param type $operationConfig 111 | * @param type $operationMetadata 112 | * @param type $inputMap 113 | * @return type 114 | */ 115 | public function getUrl($operationConfig, $operationMetadata, &$inputMap) { 116 | 117 | $queryParams = array(); 118 | 119 | $action = $operationConfig->getAction(); 120 | $resourcePath = $operationConfig->getResourcePath(); 121 | $queryList = $operationConfig->getQueryParams(); 122 | $resolvedHostUrl = $operationMetadata->getHost(); 123 | 124 | //arizzini: we need to validate the host 125 | $this->validateHost($resolvedHostUrl); 126 | 127 | $url = "%s"; 128 | 129 | //arizzini: we need to apply the environment variable. 130 | if (strpos($resourcePath, "#env") !== FALSE) { 131 | $environment = ""; 132 | if (!empty($operationMetadata->getContext())) { 133 | $environment = $operationMetadata->getContext(); 134 | } 135 | 136 | $resourcePath = str_replace("#env", $environment, $resourcePath); 137 | $resourcePath = str_replace("//", "/", $resourcePath); 138 | } 139 | 140 | $tmpUrl = Util::getReplacedPath($this->removeForwardSlashFromTail($resolvedHostUrl).$this->removeForwardSlashFromTail($resourcePath), $inputMap); 141 | array_push($queryParams, $tmpUrl); 142 | 143 | switch ($action) { 144 | case "read": 145 | case "delete": 146 | case "list": 147 | case "query": 148 | foreach ($inputMap as $key => $value) { 149 | if(!is_array($value)) { 150 | $url = $this->appendToQueryString($url, "%s=%s"); 151 | array_push($queryParams, Util::urlEncode(strval($key))); 152 | array_push($queryParams, Util::urlEncode(strval($value))); 153 | } 154 | } 155 | break; 156 | default: 157 | break; 158 | } 159 | 160 | // we need to remove any queryParameters specified in the inputMap and 161 | // add them as quertParameters 162 | switch ($action) { 163 | case "create": 164 | case "update": 165 | $queryMap = Util::subMap($inputMap, $queryList); 166 | foreach ($queryMap as $key => $value) { 167 | if(!is_array($value)) { 168 | $url = $this->appendToQueryString($url, "%s=%s"); 169 | array_push($queryParams, Util::urlEncode(strval($key))); 170 | array_push($queryParams, Util::urlEncode(strval($value))); 171 | } 172 | } 173 | break; 174 | default: 175 | break; 176 | } 177 | 178 | if ($operationMetadata->isJsonNative() == false) { 179 | $url = $this->appendToQueryString($url, "Format=JSON"); 180 | } 181 | $url = vsprintf($url, $queryParams); 182 | 183 | return $url; 184 | } 185 | 186 | 187 | 188 | /** 189 | * This function is used to valide the host 190 | * ApiConfig subDomain 191 | * @throws ApiException 192 | */ 193 | public function validateHost($host) { 194 | if (filter_var($host, FILTER_VALIDATE_URL) == FALSE) { 195 | throw new \RuntimeException("fullUrl: '" . $host . "' is not a valid url"); 196 | } 197 | } 198 | 199 | /** 200 | * This is the function that returns a Request object 201 | * @param type $operationConfig 202 | * @param type $operationMetadata 203 | * @param type $inputMap 204 | * @return type 205 | */ 206 | public function getRequest($operationConfig, $operationMetadata, &$inputMap) { 207 | 208 | $action = $operationConfig->getAction(); 209 | $resourcePath = $operationConfig->getResourcePath(); 210 | $headerList = $operationConfig->getHeaderParams(); 211 | $queryList = $operationConfig->getQueryParams(); 212 | 213 | //arizzini: store seperately the header paramters 214 | $headerMap = Util::subMap($inputMap, $headerList); 215 | 216 | $url = $this->getUrl($operationConfig, $operationMetadata, $inputMap); 217 | 218 | 219 | // echo "-------------------------------------\n"; 220 | // echo "-------------------------------------\n"; 221 | // echo "url: $url \n"; 222 | // echo "-------------------------------------\n"; 223 | // echo "-------------------------------------\n"; 224 | 225 | $contentType = "application/json; charset=utf-8"; 226 | if (!empty($operationMetadata->getContentTypeOverride())) { 227 | $contentType = $operationMetadata->getContentTypeOverride()."; charset=utf-8"; 228 | } 229 | 230 | 231 | $request = null; 232 | $requestBody = null; 233 | if (!empty($inputMap)) { 234 | $requestBody = json_encode($inputMap); 235 | } else { 236 | $requestBody = "{}"; 237 | } 238 | 239 | switch ($action) { 240 | case "create": 241 | $request = new Request("POST", $url, [], $requestBody); 242 | $request = $request->withHeader("Content-Type", $contentType); 243 | break; 244 | case "delete": 245 | $request = new Request("DELETE", $url); 246 | break; 247 | case "update": 248 | $request = new Request("PUT", $url, [], $requestBody); 249 | $request = $request->withHeader("Content-Type", $contentType); 250 | break; 251 | case "read": 252 | case "list": 253 | case "query": 254 | $request = new Request("GET", $url); 255 | break; 256 | } 257 | 258 | $request = $request->withHeader("Accept", $contentType); 259 | $request = $request->withHeader("User-Agent", Constants::getCoreVersion() ."/". $operationMetadata->getApiVersion()); 260 | foreach ($headerMap as $key => $value) { 261 | $request = $request->withHeader($key, $value); 262 | } 263 | $request = ApiConfig::getAuthentication()->signRequest($url, $request); 264 | 265 | return $request; 266 | } 267 | 268 | /** 269 | * This function executes the request 270 | * @param type $operationConfig 271 | * @param type $operationMetadata 272 | * @param type $inputMap 273 | * @return type 274 | * @throws SystemException 275 | */ 276 | public function execute($operationConfig, $operationMetadata, $inputMap) { 277 | $request = $this->getRequest($operationConfig, $operationMetadata, $inputMap); 278 | 279 | try { 280 | $response = $this->client->send($request, array_merge(ApiConfig::getProxy(), ApiConfig::getTimeout())); 281 | $statusCode = $response->getStatusCode(); 282 | $responseContent = $response->getBody()->getContents(); 283 | 284 | if ($statusCode < self::HTTP_AMBIGUOUS) { 285 | 286 | if (ApiConfig::isDebug()) { 287 | $this->logger->debug("---------------------"); 288 | $this->logger->debug(">>request(".$request->getMethod().") ". $request->getUri()->__toString() ); 289 | $this->logger->debug(">>headers: ", $request->getHeaders()); 290 | $this->logger->debug(">>body: ". $request->getBody()); 291 | 292 | $this->logger->debug("<logger->debug("<getHeaders()); 294 | $this->logger->debug("<logger->debug("---------------------"); 296 | } 297 | 298 | if (strlen($responseContent) > 0) { 299 | return json_decode($responseContent, true); 300 | } else { 301 | return array(); 302 | } 303 | } else { 304 | $this->handleException($response, $request); 305 | } 306 | } catch (RequestException $ex) { 307 | if ($ex->hasResponse()) { 308 | $this->handleException($ex->getResponse(), $request); 309 | } else { 310 | throw new ApiException($ex->getMessage()); 311 | } 312 | } 313 | } 314 | 315 | private function handleException($response, $request) { 316 | $status = $response->getStatusCode(); 317 | $bodyContent = $response->getBody()->getContents(); 318 | $bodyArray = json_decode($bodyContent, TRUE); 319 | 320 | //arizzini: in the case of an exception we always show the error. 321 | $this->logger->debug("---------------------"); 322 | $this->logger->debug(">>request(".$request->getMethod().") ". $request->getUri()->__toString() ); 323 | $this->logger->debug(">>headers: ", $request->getHeaders()); 324 | $this->logger->debug(">>body: ". $request->getBody()); 325 | 326 | $this->logger->debug("<getStatusCode()); 327 | $this->logger->debug("<getHeaders()); 328 | $this->logger->debug("<logger->debug("---------------------"); 330 | 331 | throw new ApiException("Internal Server Error:", $status, $bodyArray); 332 | 333 | } 334 | 335 | } 336 | -------------------------------------------------------------------------------- /MasterCard/Core/Exception/ApiException.php: -------------------------------------------------------------------------------- 1 | "Continue", 101 => "Switching Protocols", 102 => "Processing", 200 => "OK", 201 => "Created", 202 => "Accepted", 203 => "Non-Authoritative Information", 204 => "No Content", 205 => "Reset Content", 206 => "Partial Content", 207 => "Multi-Status", 300 => "Multiple Choices", 301 => "Moved Permanently", 302 => "Found", 303 => "See Other", 304 => "Not Modified", 305 => "Use Proxy", 306 => "(Unused)", 307 => "Temporary Redirect", 308 => "Permanent Redirect", 400 => "Bad Request", 401 => "Unauthorized", 402 => "Payment Required", 403 => "Forbidden", 404 => "Not Found", 405 => "Method Not Allowed", 406 => "Not Acceptable", 407 => "Proxy Authentication Required", 408 => "Request Timeout", 409 => "Conflict", 410 => "Gone", 411 => "Length Required", 412 => "Precondition Failed", 413 => "Request Entity Too Large", 414 => "Request-URI Too Long", 415 => "Unsupported Media Type", 416 => "Requested Range Not Satisfiable", 417 => "Expectation Failed", 418 => "I'm a teapot", 419 => "Authentication Timeout", 420 => "Enhance Your Calm", 422 => "Unprocessable Entity", 423 => "Locked", 424 => "Failed Dependency", 424 => "Method Failure", 425 => "Unordered Collection", 426 => "Upgrade Required", 428 => "Precondition Required", 429 => "Too Many Requests", 431 => "Request Header Fields Too Large", 444 => "No Response", 449 => "Retry With", 450 => "Blocked by Windows Parental Controls", 451 => "Unavailable For Legal Reasons", 494 => "Request Header Too Large", 495 => "Cert Error", 496 => "No Cert", 497 => "HTTP to HTTPS", 499 => "Client Closed Request", 500 => "Internal Server Error", 501 => "Not Implemented", 502 => "Bad Gateway", 503 => "Service Unavailable", 504 => "Gateway Timeout", 505 => "HTTP Version Not Supported", 506 => "Variant Also Negotiates", 507 => "Insufficient Storage", 508 => "Loop Detected", 509 => "Bandwidth Limit Exceeded", 510 => "Not Extended", 511 => "Network Authentication Required", 598 => "Network read timeout error", 599 => "Network connect timeout error"); 52 | 53 | /** 54 | * @ignore 55 | */ 56 | function __construct($message, $status = null, $errorData = null) { 57 | 58 | parent::__construct(); 59 | 60 | if (!empty($status) && array_key_exists((int)$status, $this->http_status_codes)) { 61 | $this->message = $this->http_status_codes[(int)$status]; 62 | } else { 63 | $this->message = $message; 64 | } 65 | 66 | 67 | $this->httpStatus = $status; 68 | $this->reasonCode = null; 69 | $this->source = null; 70 | 71 | $this->errors = array(); 72 | $this->error = null; 73 | 74 | $this->parseRawErrorData($errorData); 75 | $this->parseErrors($errorData); 76 | $this->parseError(0); 77 | 78 | 79 | } 80 | 81 | 82 | public function getErrorSize() { 83 | return count($this->errors); 84 | } 85 | 86 | public function parseError($index) { 87 | if (!empty($this->errors) && $index >=0 && $index < $this->getErrorSize()) { 88 | $this->error = $this->errors[$index]; 89 | $this->parseErrorMap(); 90 | } 91 | } 92 | 93 | public function getError() { 94 | return $this->error; 95 | } 96 | 97 | 98 | 99 | /** 100 | * Returns a map of all error data returned by the API. 101 | * @return array a map containing API error data. 102 | */ 103 | function getRawErrorData() { 104 | return $this->rawErrorData; 105 | } 106 | 107 | /** 108 | * Returns the HTTP status for the request. 109 | * @return string HTTP status code (or null if there is no status). 110 | */ 111 | function getHttpStatus() { 112 | return $this->httpStatus; 113 | } 114 | 115 | /** 116 | * Returns unique reference for the API error. 117 | * @return string a reference (or null if there is no reference). 118 | */ 119 | function getSource() { 120 | return $this->source; 121 | } 122 | 123 | /** 124 | * Returns an code for the API error. 125 | * @return string the error code. 126 | */ 127 | function getReasonCode() { 128 | return $this->reasonCode; 129 | } 130 | 131 | /** 132 | * Returns a description of the error. 133 | * @return string Description of the error. 134 | */ 135 | function describe() { 136 | return get_class($this) . ": \"" 137 | . $this->getMessage() . "\" (http_status: " 138 | . $this->getHttpStatus() . ", reason_code: " 139 | . $this->getReasonCode() . ", source: " 140 | . $this->getSource() . ")"; 141 | } 142 | 143 | private function isAssoc($arr) 144 | { 145 | return is_array($arr) && (array_keys($arr) !== range(0, count($arr) - 1)); 146 | } 147 | 148 | private function parseRawErrorData($errorData) { 149 | if ($this->isAssoc($errorData)) { 150 | $caseInsesitiveMap = new CaseInsensitiveMap(); 151 | $caseInsesitiveMap->setAll($errorData); 152 | $this->rawErrorData = $caseInsesitiveMap; 153 | } else if (is_array ($errorData) && $this->isAssoc($errorData[0])){ 154 | $caseInsesitiveMap = new CaseInsensitiveMap(); 155 | $caseInsesitiveMap->setAll($errorData[0]); 156 | $this->rawErrorData = $caseInsesitiveMap; 157 | } 158 | } 159 | 160 | private function parseErrors($errorData) { 161 | if (!empty($errorData)) { 162 | 163 | 164 | $errors = array(); 165 | //arizzini: this takes care of the list returned in the response 166 | if ($this->isAssoc($errorData)) { 167 | $errors[] = $errorData; 168 | } else if (is_array ($errorData)){ 169 | $errors = array_merge($errors, $errorData); 170 | } else { 171 | $errors[] = $errorData; 172 | } 173 | 174 | //arizzini: then we parse each invididual error into a 175 | // case insenstive map. 176 | foreach ($errors as $error) { 177 | $smartMap = new CaseInsensitiveMap(); 178 | $smartMap->setAll($error); 179 | 180 | if ($smartMap->containsKey("errors.error.reasoncode")) { 181 | // echo "contains errors.error.reasoncode"; 182 | $this->addError($smartMap->get("errors.error")); 183 | } else if ($smartMap->containsKey("errors.error[0].reasoncode")) { 184 | // echo "contains errors.error[0].reasoncode"; 185 | $this->addError($smartMap->get("errors.error")); 186 | } else if ($smartMap->containsKey("errors[0].reasoncode")) { 187 | // echo "errors[0].reasoncode"; 188 | $this->addError($smartMap->get("errors")); 189 | } else if ($smartMap->containsKey("reasoncode")) { 190 | // echo "contains reasoncode"; 191 | $this->addError($smartMap->getBaseMapAsArray()); 192 | } 193 | } 194 | } 195 | } 196 | 197 | 198 | private function addError($error) { 199 | if ($this->isAssoc($error)) { 200 | $map = new CaseInsensitiveMap(); 201 | $map->setAll($error); 202 | $this->errors[] = $map; 203 | } else if (is_array($error)) { 204 | foreach ($error as $item) { 205 | $map = new CaseInsensitiveMap(); 206 | $map->setAll($item); 207 | $this->errors[] = $map; 208 | } 209 | } 210 | } 211 | 212 | private function parseErrorMap() { 213 | if ($this->error->containsKey('description')) 214 | { 215 | $this->message = $this->error->get('description'); 216 | } 217 | if ($this->error->containsKey('reasoncode')) 218 | { 219 | $this->reasonCode = $this->error->get('reasoncode'); 220 | } 221 | if ($this->error->containsKey('source')) 222 | { 223 | $this->source = $this->error->get('source'); 224 | } 225 | } 226 | 227 | 228 | 229 | 230 | 231 | } -------------------------------------------------------------------------------- /MasterCard/Core/Model/BaseObject.php: -------------------------------------------------------------------------------- 1 | setAll($baseMap); 51 | } 52 | 53 | } 54 | 55 | /** 56 | * @ignore 57 | */ 58 | protected static function execute($operationUUID, $inputObject) { 59 | 60 | $operationConfig = $inputObject->getOperationConfig($operationUUID); 61 | $operationMetadata = $inputObject->getOperationMetadata(); 62 | 63 | $apiController = new ApiController($operationMetadata->getApiVersion()); 64 | 65 | $responseMap = $apiController->execute($operationConfig, $operationMetadata, $inputObject->getBaseMapAsArray()); 66 | $returnObjectClass = get_class($inputObject); 67 | 68 | if ($operationConfig->getAction() == "list") { 69 | $returnObject = array(); 70 | 71 | if (array_key_exists("list", $responseMap)) { 72 | $responseMap = $responseMap["list"]; 73 | } 74 | 75 | foreach ($responseMap as $objectMap) { 76 | $baseMap = new RequestMap(); 77 | $baseMap->setAll($objectMap); 78 | $returnObject[] = new $returnObjectClass($baseMap); 79 | } 80 | return $returnObject; 81 | 82 | } else { 83 | $baseMap = new RequestMap(); 84 | $baseMap->setAll($responseMap); 85 | return new $returnObjectClass($baseMap); 86 | } 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /MasterCard/Core/Model/CaseInsensitiveMap.php: -------------------------------------------------------------------------------- 1 | properties = $this->parseMap($map); 71 | } 72 | 73 | 74 | private function parseMap($map) { 75 | $result = array(); 76 | foreach ($map as $key => $value) { 77 | if ($this->isAssoc($value)) { 78 | //this is a map 79 | $result[strtolower($key)] = $this->parseMap($value); 80 | } else if (is_array ($value)){ 81 | //this is a list 82 | $result[strtolower($key)] = $this->parseList($value); 83 | } else { 84 | /// this is a simple value 85 | $result[strtolower($key)] = $value; 86 | } 87 | } 88 | return $result; 89 | } 90 | 91 | private function parseList($list) { 92 | $result = array(); 93 | foreach ($list as $key => $value) { 94 | if (parent::isAssoc($value)) { 95 | $result[] = $this->parseMap($value); 96 | } else if (is_array ($value)) { 97 | $result[] = $this->parseList($value); 98 | } else { 99 | $result[] = $value; 100 | } 101 | } 102 | return $result; 103 | } 104 | 105 | protected function isAssoc($arr) 106 | { 107 | return is_array($arr) && (array_keys($arr) !== range(0, count($arr) - 1)); 108 | } 109 | 110 | } -------------------------------------------------------------------------------- /MasterCard/Core/Model/Constants.php: -------------------------------------------------------------------------------- 1 | ["https://api.mastercard.com", null], 53 | Environment::PRODUCTION_MTF => ["https://api.mastercard.com", "mtf"], 54 | Environment::PRODUCTION_ITF => ["https://api.mastercard.com", "itf"], 55 | Environment::SANDBOX => ["https://sandbox.api.mastercard.com", null], 56 | Environment::SANDBOX_STATIC => ["https://sandbox.api.mastercard.com", "static"], 57 | Environment::SANDBOX_MTF => ["https://sandbox.api.mastercard.com", "mtf"], 58 | Environment::SANDBOX_ITF => ["https://sandbox.api.mastercard.com", "itf"], 59 | Environment::STAGE => ["https://stage.api.mastercard.com", null], 60 | Environment::STAGE_MTF => ["https://stage.api.mastercard.com", "mtf"], 61 | Environment::STAGE_ITF => ["https://stage.api.mastercard.com", "itf"], 62 | Environment::DEV => ["https://dev.api.mastercard.com", null], 63 | Environment::LOCALHOST => ["http://localhost:8081", null], 64 | Environment::ITF => ["https://itf.api.mastercard.com", null], 65 | Environment::PERF => ["https://perf.api.mastercard.com", null] 66 | ]; 67 | 68 | } 69 | 70 | -------------------------------------------------------------------------------- /MasterCard/Core/Model/OperationConfig.php: -------------------------------------------------------------------------------- 1 | resourcePath = $resourcePath; 39 | $this->action = $action; 40 | $this->queryParams = $queryParams; 41 | $this->headerParams = $headerParams; 42 | } 43 | 44 | /** 45 | * returns the resource path for this operation 46 | * @return type 47 | */ 48 | public function getResourcePath() { 49 | return $this->resourcePath; 50 | } 51 | 52 | /** 53 | * returns the action for this operation 54 | * @return type 55 | */ 56 | public function getAction() { 57 | return $this->action; 58 | } 59 | 60 | /** 61 | * return queryParams for this operation 62 | * @return type 63 | */ 64 | public function getQueryParams() { 65 | return $this->queryParams; 66 | } 67 | 68 | 69 | /** 70 | * return headerParams for this operation 71 | * @return type 72 | */ 73 | public function getHeaderParams() { 74 | return $this->headerParams; 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /MasterCard/Core/Model/OperationMetadata.php: -------------------------------------------------------------------------------- 1 | apiVersion = $apiVersion; 39 | $this->host = $host; 40 | $this->context = $context; 41 | $this->jsonNative = $jsonNative; 42 | $this->contentTypeOverride = $contentTypeOverride; 43 | } 44 | 45 | 46 | /** 47 | * return the apiversion 48 | * @return type 49 | */ 50 | public function getApiVersion() { 51 | return $this->apiVersion; 52 | } 53 | 54 | /** 55 | * return the host 56 | * @return type 57 | */ 58 | public function getHost() { 59 | return $this->host; 60 | } 61 | 62 | /** 63 | * return the environment 64 | * @return type 65 | */ 66 | public function getContext() { 67 | return $this->context; 68 | } 69 | 70 | /** 71 | * return is this is a jsonNatice call 72 | * @return true | false 73 | */ 74 | public function isJsonNative() { 75 | return $this->jsonNative; 76 | } 77 | 78 | /** 79 | * return the environment 80 | * @return type 81 | */ 82 | public function getContentTypeOverride() { 83 | return $this->contentTypeOverride; 84 | } 85 | 86 | 87 | 88 | } -------------------------------------------------------------------------------- /MasterCard/Core/Model/RequestMap.php: -------------------------------------------------------------------------------- 1 | properties; 53 | foreach ($keys as $index=>$subKey) { 54 | if (empty($tmpArray) || empty($subKey)) 55 | { 56 | return null; 57 | } 58 | else if ($index+1 < $keysCount) 59 | { 60 | $tmpArray = $this->getArrayObject($tmpArray, $subKey); 61 | } 62 | else { 63 | return $this->getArrayObject($tmpArray, $subKey); 64 | } 65 | } 66 | } else { 67 | return $this->getArrayObject($this->properties, $key); 68 | } 69 | 70 | } 71 | 72 | 73 | private function getArrayObject($inputArray, $key) 74 | { 75 | // echo ">>>getArrayObject(key=$key)\r\n"; 76 | preg_match($this->parrentContainsSquaredBracket, $key, $matches); 77 | //arizzini: if the curent key contains a square bracket, 78 | //we are referring to an array 79 | if (!empty($matches)) 80 | { 81 | $bracketPosition = strpos($key, "["); 82 | $listName = substr($key, 0, $bracketPosition); 83 | $listIndex = $matches[1] ?: 0; 84 | 85 | // echo "listName=$listName \r\n"; 86 | // echo "listIndex=$listIndex \r\n"; 87 | if (array_key_exists($listName, $inputArray)) 88 | { 89 | 90 | if (array_key_exists($listIndex, $inputArray[$listName])) 91 | { 92 | // echo "--returning list[$listIndex]--\r\n"; 93 | return $inputArray[$listName][$listIndex]; 94 | } else { 95 | return null; 96 | } 97 | } 98 | else { 99 | // echo "--returning NULL--\r\n"; 100 | return null; 101 | } 102 | } 103 | //arizzini: if the current $index is not the last $subKey 104 | //we want to the last nested map 105 | else if (array_key_exists($key, $inputArray)) { 106 | return $inputArray[$key]; 107 | } else { 108 | return null; 109 | } 110 | } 111 | 112 | /** 113 | * This check is the map contains a key 114 | * @param type $key 115 | * @return boolean true or false 116 | */ 117 | public function containsKey($key) 118 | { 119 | if (strpos($key, ".") !== false) { 120 | //we have a dot, we need to split the ket by the dot and check 121 | //individual string if they are part of the nestes array 122 | $keys = explode('.', $key); 123 | $keysCount = count($keys); 124 | 125 | 126 | $tmpArray = $this->properties; 127 | foreach ($keys as $index=>$subKey) { 128 | 129 | 130 | if (empty($tmpArray) || empty($subKey)) 131 | { 132 | return false; 133 | } 134 | else if ($index+1 < $keysCount) 135 | { 136 | //arizzini: if the current $index is not the last $subKey 137 | //we want to check is the $tmpArray is an array 138 | $tmpArray = $this->getArrayObject($tmpArray, $subKey); 139 | } 140 | else { 141 | // echo "checking if subkey=$subKey exists"; 142 | // print_r($tmpArray); 143 | // 144 | return $this->getArrayObject($tmpArray, $subKey) !== null; 145 | //return array_key_exists($subKey, $tmpArray); 146 | 147 | } 148 | } 149 | } else { 150 | return $this->getArrayObject($this->properties, $key) !== null; 151 | 152 | } 153 | 154 | } 155 | 156 | private function assignArrayByPath(&$arr, $path, $value, $separator='.') { 157 | $keys = explode($separator, $path); 158 | 159 | foreach ($keys as $key) { 160 | preg_match($this->parrentContainsSquaredBracket, $key, $matches); 161 | if (!empty($matches)) 162 | { 163 | $indexOfSquareBraket = strpos($key, "["); 164 | $listName = substr($key, 0, $indexOfSquareBraket); 165 | $listIndex = $matches[1]; 166 | if (isset($listIndex)) { 167 | $arr = &$arr[$listName][$listIndex]; 168 | } else { 169 | $arr = &$arr[$listName][]; 170 | } 171 | } else { 172 | $arr = &$arr[$key]; 173 | } 174 | } 175 | 176 | $arr = $value; 177 | } 178 | 179 | /** 180 | * 181 | * @param type $key 182 | * @param type $value 183 | * @return \MasterCard\Core\Model\RequestMap 184 | */ 185 | public function set($key, $value) { 186 | $this->assignArrayByPath($this->properties, $key, $value); 187 | return $this; 188 | } 189 | 190 | /** 191 | * Updates the object's properties with the values in the specified map. 192 | * @param $map array Map of values to set. 193 | */ 194 | public function setAll($map) { 195 | 196 | if ($map instanceof SmartMap) { 197 | $this->properties = array_merge($this->properties, $map->getBaseMapAsArray()); 198 | } else { 199 | 200 | if ($this->isAssoc($map)) 201 | { 202 | //echo "isAssoc==TRUE\r\n"; 203 | foreach ($map as $key => $value) { 204 | $this->set($key, $value); 205 | } 206 | } else if (is_array($map)){ 207 | //echo "isAssoc==FALSE\r\n"; 208 | $list = array(); 209 | foreach ($map as $object) { 210 | $tmpBaseMap = new SmartMap(); 211 | $tmpBaseMap->setAll($object); 212 | array_push($list, $tmpBaseMap->getBaseMapAsArray()); 213 | } 214 | 215 | $this->set("list", $list); 216 | } 217 | } 218 | } 219 | 220 | 221 | protected function isAssoc($arr) 222 | { 223 | return ( array_keys($arr) !== range(0, count($arr) - 1)); 224 | } 225 | 226 | /** 227 | * Returns the size the of the map 228 | * @return integer of size 229 | */ 230 | public function size() 231 | { 232 | return sizeof($this->properties); 233 | } 234 | 235 | /** 236 | * @ignore 237 | */ 238 | public function __toString() { 239 | return json_encode($this->properties); 240 | } 241 | 242 | /** 243 | * Returns the object's properties as a map. 244 | * @return array map of properties. 245 | */ 246 | public function &getBaseMapAsArray() { 247 | return $this->properties; 248 | } 249 | } -------------------------------------------------------------------------------- /MasterCard/Core/Security/AuthenticationInterface.php: -------------------------------------------------------------------------------- 1 | clientId = $clientId; 47 | $this->privateKey = $privateKey; 48 | $this->alias = $alias; 49 | $this->password = $password; 50 | } 51 | 52 | public function getClientId() { 53 | return $this->clientId; 54 | } 55 | 56 | public function getPrivateKey() { 57 | return $this->privateKey; 58 | } 59 | 60 | public function getPassword() { 61 | return $this->password; 62 | } 63 | 64 | public static function getOAuthBaseString($url, $method, $params) 65 | { 66 | return Util::uriRfc3986Encode(strtoupper($method))."&".Util::uriRfc3986Encode(Util::normalizeUrl($url))."&".Util::uriRfc3986Encode(Util::normalizeParameters($url, $params)); 67 | } 68 | 69 | public function signRequest($uri, $request) { 70 | $method = $request->getMethod(); 71 | $body = $request->getBody()->getContents(); 72 | 73 | return $request->withHeader(OAuthParameters::AUTHORIZATION, $this->getOAuthKey($uri, $method, $body)); 74 | } 75 | 76 | 77 | public function getOAuthKey($url, $method, $body) 78 | { 79 | $oAuthParameters = new OAuthParameters(); 80 | $oAuthParameters->setOAuthConsumerKey($this->clientId); 81 | $oAuthParameters->setOAuthNonce(SecurityUtil::getNonce()); 82 | $oAuthParameters->setOAuthTimestamp(SecurityUtil::getTimestamp()); 83 | $oAuthParameters->setOAuthSignatureMethod("RSA-SHA256"); 84 | 85 | if (!empty($body)) { 86 | $encodedHash = Util::base64Encode(Util::sha256Encode($body, true)); 87 | $oAuthParameters->setOAuthBodyHash($encodedHash); 88 | } 89 | 90 | $baseString = OAuthAuthentication::getOAuthBaseString($url, $method, $oAuthParameters->getBaseParameters()); 91 | $signature = $this->signValue($baseString); 92 | $oAuthParameters->setOAuthSignature($signature); 93 | 94 | $result = ""; 95 | foreach ($oAuthParameters->getBaseParameters() as $key => $value) { 96 | if (strlen($result) == 0) 97 | { 98 | $result .= OAuthParameters::OAUTH_KEY." "; 99 | } else { 100 | $result .= ","; 101 | } 102 | $result .= Util::uriRfc3986Encode($key)."=\"".Util::uriRfc3986Encode($value)."\""; 103 | } 104 | return $result; 105 | } 106 | 107 | public function signValue($value) 108 | { 109 | openssl_pkcs12_read($this->privateKey, $certs, $this->password); 110 | $pkeyid = openssl_get_privatekey($certs["pkey"]); 111 | openssl_sign($value, $signature, $pkeyid , "SHA256"); 112 | return Util::base64Encode($signature); 113 | } 114 | 115 | 116 | 117 | } -------------------------------------------------------------------------------- /MasterCard/Core/Security/OAuth/OAuthParameters.php: -------------------------------------------------------------------------------- 1 | baseParameters[$key] = $value; 54 | } 55 | 56 | public function setOAuthConsumerKey($consumerKey) { 57 | $this->put(self::OAUTH_CONSUMER_KEY, $consumerKey); 58 | } 59 | 60 | public function setOAuthNonce($oauthNonce) { 61 | $this->put(self::OAUTH_NONCE_KEY, $oauthNonce); 62 | } 63 | 64 | public function setOAuthTimestamp($timestamp) { 65 | $this->put(self::OAUTH_TIMESTAMP_KEY, $timestamp); 66 | } 67 | 68 | public function setOAuthSignatureMethod($signatureMethod) { 69 | $this->put(self::OAUTH_SIGNATURE_METHOD_KEY, $signatureMethod); 70 | } 71 | 72 | public function setOAuthSignature($signature) { 73 | $this->put(self::OAUTH_SIGNATURE_KEY, $signature); 74 | } 75 | 76 | public function setOAuthBodyHash($bodyHash) { 77 | $this->put(self::OAUTH_BODY_HASH_KEY, $bodyHash); 78 | } 79 | 80 | 81 | public function getBaseParameters() { 82 | ksort($this->baseParameters); 83 | return $this->baseParameters; 84 | } 85 | 86 | } -------------------------------------------------------------------------------- /MasterCard/Core/Security/SecurityUtil.php: -------------------------------------------------------------------------------- 1 | $value) { 68 | $requestParameteMapCopy[$key] = $value; 69 | } 70 | } 71 | 72 | 73 | ksort($requestParameteMapCopy); 74 | 75 | $stringBuilder = ""; 76 | foreach ($requestParameteMapCopy as $key => $value) { 77 | if (strlen($stringBuilder) > 0) { 78 | $stringBuilder .= "&"; 79 | } 80 | $stringBuilder .= self::uriRfc3986Encode($key)."=".self::uriRfc3986Encode($value); 81 | } 82 | return $stringBuilder; 83 | } 84 | 85 | /** 86 | * This method is used to generate a sumMap by taking a subset of the map 87 | * which contains the key specified in the list 88 | * @param type $inputMap 89 | * @param type $keyList 90 | * @return type 91 | */ 92 | public static function subMap(&$inputMap, $keyList) { 93 | $subMap = array(); 94 | foreach ($keyList as $key) 95 | { 96 | //check is the map contain the 97 | if (array_key_exists($key, $inputMap)){ 98 | $subMap[$key] = $inputMap[$key]; 99 | unset($inputMap[$key]); 100 | } 101 | } 102 | 103 | return $subMap; 104 | } 105 | 106 | /** 107 | * Replace the path which contains {variable_id} by taking values from map 108 | * @param type $path 109 | * @param type $inputMap 110 | */ 111 | public static function getReplacedPath($path, &$inputMap) { 112 | 113 | $pattern = '/{(.*?)}/'; 114 | $result = $path; 115 | preg_match_all($pattern, $path, $matches); 116 | 117 | foreach ($matches[1] as $key) { 118 | if (array_key_exists ( $key , $inputMap )) { 119 | $result = str_replace("{".$key."}", $inputMap[$key], $result); 120 | unset($inputMap[$key]); 121 | } else { 122 | throw new \Exception ("Error, path paramer: '$key' expected but not found in input map"); 123 | } 124 | } 125 | return $result; 126 | 127 | 128 | } 129 | 130 | /** 131 | * base64Encode 132 | * @param type $data 133 | * @return type 134 | */ 135 | public static function base64Encode($data) 136 | { 137 | return base64_encode ( $data ); 138 | } 139 | 140 | /** 141 | * sha1Encode 142 | * @param type $data 143 | * @param type $raw_output 144 | * @return type 145 | */ 146 | public static function sha256Encode($data, $raw_output = false) 147 | { 148 | return hash('sha256', $data, $raw_output); 149 | } 150 | 151 | /** 152 | * sha256Encode 153 | * @param type $data 154 | * @param type $raw_output 155 | * @return type 156 | */ 157 | public static function sha1Encode($data, $raw_output = false) 158 | { 159 | return sha1( $data, $raw_output ); 160 | } 161 | 162 | /** 163 | * urlEncode 164 | * @param type $data 165 | * @return type 166 | */ 167 | public static function urlEncode($data) 168 | { 169 | return rawurlencode( $data ); 170 | } 171 | 172 | /** 173 | * uriRfc3986Encode 174 | * @param type $value 175 | * @return type 176 | */ 177 | public static function uriRfc3986Encode($value) 178 | { 179 | //return str_replace('%7E', '~', rawurlencode($value)); 180 | return rawurlencode($value); 181 | } 182 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > :warning: **This project is deprecated**. See [Mastercard](https://github.com/Mastercard) / [oauth1-signer-php](https://github.com/Mastercard/oauth1-signer-php) and [Mastercard](https://github.com/Mastercard) / [client-encryption-php](https://github.com/Mastercard/client-encryption-php) instead. 2 | 3 | # Introduction 4 | This is the SDK Core Api for all the SDK used in MasterCard. 5 | It provides some Core functionality for all our SDKs. 6 | It provide: 7 | - exception handling 8 | - security (OAUTH) 9 | - crypt utilities 10 | - message pump 11 | - smart map (for inline request creation using fluent style api) 12 | 13 | # Setup 14 | This is composer project. 15 | For simplicity i've added to the project under the bin an instance of composer. 16 | 17 | ``` 18 | chmod +x composer.sh 19 | chmod +x run-tests.sh 20 | ./composer install 21 | ./run-test 22 | ``` 23 | 24 | ## Run a single test 25 | `./composer exec -- phpunit --filter test500_invalidrequest_json_native` 26 | 27 | -------------------------------------------------------------------------------- /Test/MasterCard/Api/AccountInquiry.php: -------------------------------------------------------------------------------- 1 | set ("AccountInquiry.AccountNumber", "5343434343434343"); 61 | // ApiConfig::setProxy(['http' => 'http://localhost:9999', 'https' => 'http://localhost:9999']); 62 | 63 | // $request = new AccountInquiry($map); 64 | // $response = $request->update(); 65 | // $this->assertEquals(strtolower("True"), strtolower(str_replace("'", "", var_export($response->get("Account.Listed"), true)))); 66 | // $this->assertEquals(strtolower("S"), strtolower($response->get("Account.ReasonCode"))); 67 | // $this->assertEquals(strtolower("STOLEN"), strtolower($response->get("Account.Reason"))); 68 | 69 | // } 70 | 71 | 72 | 73 | 74 | 75 | 76 | public function test_example_stolen() 77 | { 78 | $this->markTestSkipped('sandbox is down.'); 79 | 80 | //example_stolen 81 | $map = new RequestMap(); 82 | $map->set ("AccountInquiry.AccountNumber", "5343434343434343"); 83 | 84 | $request = new AccountInquiry($map); 85 | $response = $request->update(); 86 | $this->assertEquals(strtolower("True"), strtolower(str_replace("'", "", var_export($response->get("Account.Listed"), true)))); 87 | $this->assertEquals(strtolower("S"), strtolower($response->get("Account.ReasonCode"))); 88 | $this->assertEquals(strtolower("STOLEN"), strtolower($response->get("Account.Reason"))); 89 | 90 | } 91 | 92 | 93 | public function test_example_lost() 94 | { 95 | 96 | $this->markTestSkipped('sandbox is down.'); 97 | 98 | //example_lost 99 | $map = new RequestMap(); 100 | $map->set ("AccountInquiry.AccountNumber", "5222222222222200"); 101 | 102 | $request = new AccountInquiry($map); 103 | $response = $request->update(); 104 | $this->assertEquals(strtolower("True"), strtolower(str_replace("'", "", var_export($response->get("Account.Listed"), true)))); 105 | $this->assertEquals(strtolower("L"), strtolower($response->get("Account.ReasonCode"))); 106 | $this->assertEquals(strtolower("LOST"), strtolower($response->get("Account.Reason"))); 107 | 108 | } 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | } 117 | 118 | -------------------------------------------------------------------------------- /Test/MasterCard/Api/BaseTest.php: -------------------------------------------------------------------------------- 1 | containsKey($key)) { 56 | return $response->get($key); 57 | } else { 58 | self::$logger->addError("Key:'$key' is not found in the response"); 59 | } 60 | } else { 61 | self::$logger->addError("Example:'$name' is not found in the responses"); 62 | } 63 | 64 | return null; 65 | } 66 | } 67 | 68 | protected function customAssertEqual($ignoreList, $response, $key, $expectedValue) { 69 | if (!in_array($key, $ignoreList)) { 70 | //not in the array so we need to test it. 71 | $this->customAssertValue($expectedValue, $response->get($key)); 72 | } 73 | } 74 | 75 | protected function customAssertValue($expected, $actual) { 76 | if (is_bool($actual)) { 77 | $this->assertEquals(boolval($expected), $actual); 78 | } else if (is_int($actual)) { 79 | $this->assertEquals(intval($expected), $actual); 80 | } else if (is_float($actual)) { 81 | $this->assertEquals(floatval($expected), $actual); 82 | } else { 83 | $this->assertEquals(strtolower($expected), strtolower($actual)); 84 | } 85 | } 86 | 87 | 88 | 89 | } -------------------------------------------------------------------------------- /Test/MasterCard/Api/Insights.php: -------------------------------------------------------------------------------- 1 | set("CurrentRow", "1"); 55 | // $map->set("Offset", "25"); 56 | // $map->set("Country", "US"); 57 | // 58 | // 59 | // 60 | // $response = Insights::query($map); 61 | // $this->assertEquals(str_replace("'", "", strtolower("70")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.Count"), true)))); 62 | // $this->assertEquals(str_replace("'", "", strtolower("Success")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.Message"), true)))); 63 | // $this->assertEquals(str_replace("'", "", strtolower("US")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[0].Country"), true)))); 64 | // $this->assertEquals(str_replace("'", "", strtolower("U.S. Natural and Organic Grocery Stores")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[0].Sector"), true)))); 65 | // $this->assertEquals(str_replace("'", "", strtolower("NO")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[0].Ecomm"), true)))); 66 | // $this->assertEquals(str_replace("'", "", strtolower("Monthly")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[0].Period"), true)))); 67 | // $this->assertEquals(str_replace("'", "", strtolower("11/30/2014")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[0].BeginDate"), true)))); 68 | // $this->assertEquals(str_replace("'", "", strtolower("1/3/2015")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[0].EndDate"), true)))); 69 | // $this->assertEquals(str_replace("'", "", strtolower("0.049201983")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[0].SalesIndex"), true)))); 70 | // $this->assertEquals(str_replace("'", "", strtolower("-0.029602284")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[0].AverageTicketIndex"), true)))); 71 | // $this->assertEquals(str_replace("'", "", strtolower("7146577.851")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[0].SalesIndexValue"), true)))); 72 | // $this->assertEquals(str_replace("'", "", strtolower("US")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[1].Country"), true)))); 73 | // $this->assertEquals(str_replace("'", "", strtolower("U.S. Natural and Organic Grocery Stores")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[1].Sector"), true)))); 74 | // $this->assertEquals(str_replace("'", "", strtolower("NO")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[1].Ecomm"), true)))); 75 | // $this->assertEquals(str_replace("'", "", strtolower("Monthly")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[1].Period"), true)))); 76 | // $this->assertEquals(str_replace("'", "", strtolower("11/2/2014")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[1].BeginDate"), true)))); 77 | // $this->assertEquals(str_replace("'", "", strtolower("11/29/2014")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[1].EndDate"), true)))); 78 | // $this->assertEquals(str_replace("'", "", strtolower("0.074896863")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[1].SalesIndex"), true)))); 79 | // $this->assertEquals(str_replace("'", "", strtolower("-0.007884916")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[1].AverageTicketIndex"), true)))); 80 | // $this->assertEquals(str_replace("'", "", strtolower("5390273.888")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[1].SalesIndexValue"), true)))); 81 | // $this->assertEquals(str_replace("'", "", strtolower("US")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[2].Country"), true)))); 82 | // $this->assertEquals(str_replace("'", "", strtolower("U.S. Natural and Organic Grocery Stores")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[2].Sector"), true)))); 83 | // $this->assertEquals(str_replace("'", "", strtolower("NO")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[2].Ecomm"), true)))); 84 | // $this->assertEquals(str_replace("'", "", strtolower("Monthly")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[2].Period"), true)))); 85 | // $this->assertEquals(str_replace("'", "", strtolower("10/5/2014")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[2].BeginDate"), true)))); 86 | // $this->assertEquals(str_replace("'", "", strtolower("11/1/2014")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[2].EndDate"), true)))); 87 | // $this->assertEquals(str_replace("'", "", strtolower("0.077937282")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[2].SalesIndex"), true)))); 88 | // $this->assertEquals(str_replace("'", "", strtolower("-0.010073866")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[2].AverageTicketIndex"), true)))); 89 | // $this->assertEquals(str_replace("'", "", strtolower("4776139.381")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[2].SalesIndexValue"), true)))); 90 | // $this->assertEquals(str_replace("'", "", strtolower("US")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[3].Country"), true)))); 91 | // $this->assertEquals(str_replace("'", "", strtolower("U.S. Natural and Organic Grocery Stores")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[3].Sector"), true)))); 92 | // $this->assertEquals(str_replace("'", "", strtolower("NO")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[3].Ecomm"), true)))); 93 | // $this->assertEquals(str_replace("'", "", strtolower("Monthly")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[3].Period"), true)))); 94 | // $this->assertEquals(str_replace("'", "", strtolower("9/7/2014")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[3].BeginDate"), true)))); 95 | // $this->assertEquals(str_replace("'", "", strtolower("10/4/2014")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[3].EndDate"), true)))); 96 | // $this->assertEquals(str_replace("'", "", strtolower("0.089992028")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[3].SalesIndex"), true)))); 97 | // $this->assertEquals(str_replace("'", "", strtolower("-0.00577838")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[3].AverageTicketIndex"), true)))); 98 | // $this->assertEquals(str_replace("'", "", strtolower("4716899.304")), strtolower(str_replace("'", "", var_export($response->get("SectorRecordList.SectorRecordArray.SectorRecord[3].SalesIndexValue"), true)))); 99 | // 100 | // 101 | // } 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | } 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /Test/MasterCard/Api/JsonEcho.php: -------------------------------------------------------------------------------- 1 | set("JsonEcho.string", "мảŝťễřÇāŕď Ľẵвš ạאָđ мãśţēяĈẫřđ ĀקÏ ŕồçҝş.."); 55 | $response = JsonEcho::create($map); 56 | $body = new JsonEcho($response->get("body"), true); 57 | 58 | $this->assertEquals("мảŝťễřÇāŕď Ľẵвš ạאָđ мãśţēяĈẫřđ ĀקÏ ŕồçҝş..", $body->get("JsonEcho.string")); 59 | 60 | } 61 | 62 | } 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /Test/MasterCard/Api/MerchantCountries.php: -------------------------------------------------------------------------------- 1 | set("id", $id); 110 | } 111 | if (!empty($requestMap)) { 112 | $map->setAll($requestMap); 113 | } 114 | return self::execute("40e28221-901f-4a39-a23c-80c677d63908", new MultiplePathUserPost($map)); 115 | } 116 | 117 | /** 118 | * Delete this object of type MultiplePathUserPost 119 | * 120 | * @return MultiplePathUserPost of the response of the deleted instance. 121 | */ 122 | public function delete() 123 | { 124 | return self::execute("40e28221-901f-4a39-a23c-80c677d63908", $this); 125 | } 126 | 127 | 128 | 129 | 130 | } 131 | 132 | -------------------------------------------------------------------------------- /Test/MasterCard/Api/MultiplePathUserPostTest.php: -------------------------------------------------------------------------------- 1 | set("user_id", "1"); 60 | $map->set("post_id", "2"); 61 | 62 | 63 | $responseList = MultiplePathUserPost::listByCriteria($map); 64 | 65 | $ignoreAssert = array(); 66 | 67 | $this->customAssertEqual($ignoreAssert, $responseList[0], "id", "1"); 68 | $this->customAssertEqual($ignoreAssert, $responseList[0], "title", "My Title"); 69 | $this->customAssertEqual($ignoreAssert, $responseList[0], "body", "some body text"); 70 | $this->customAssertEqual($ignoreAssert, $responseList[0], "userId", "1"); 71 | 72 | 73 | self::putResponse("get_user_posts_with_mutplie_path", $responseList[0]); 74 | 75 | } 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | public function test_update_user_posts_with_mutplie_path() 87 | { 88 | 89 | 90 | 91 | 92 | $map = new RequestMap(); 93 | $map->set ("user_id", "1"); 94 | $map->set ("post_id", "1"); 95 | $map->set ("testQuery", "testQuery"); 96 | $map->set ("name", "Joe Bloggs"); 97 | $map->set ("username", "jbloggs"); 98 | $map->set ("email", "name@example.com"); 99 | $map->set ("phone", "1-770-736-8031"); 100 | $map->set ("website", "hildegard.org"); 101 | $map->set ("address.line1", "2000 Purchase Street"); 102 | $map->set ("address.city", "New York"); 103 | $map->set ("address.state", "NY"); 104 | $map->set ("address.postalCode", "10577"); 105 | 106 | 107 | $request = new MultiplePathUserPost($map); 108 | $response = $request->update(); 109 | 110 | $ignoreAssert = array(); 111 | 112 | $this->customAssertEqual($ignoreAssert, $response, "website", "hildegard.org"); 113 | $this->customAssertEqual($ignoreAssert, $response, "address.instructions.doorman", "true"); 114 | $this->customAssertEqual($ignoreAssert, $response, "address.instructions.text", "some delivery instructions text"); 115 | $this->customAssertEqual($ignoreAssert, $response, "address.city", "New York"); 116 | $this->customAssertEqual($ignoreAssert, $response, "address.postalCode", "10577"); 117 | $this->customAssertEqual($ignoreAssert, $response, "address.id", "1"); 118 | $this->customAssertEqual($ignoreAssert, $response, "address.state", "NY"); 119 | $this->customAssertEqual($ignoreAssert, $response, "address.line1", "2000 Purchase Street"); 120 | $this->customAssertEqual($ignoreAssert, $response, "phone", "1-770-736-8031"); 121 | $this->customAssertEqual($ignoreAssert, $response, "name", "Joe Bloggs"); 122 | $this->customAssertEqual($ignoreAssert, $response, "id", "1"); 123 | $this->customAssertEqual($ignoreAssert, $response, "email", "name@example.com"); 124 | $this->customAssertEqual($ignoreAssert, $response, "username", "jbloggs"); 125 | 126 | 127 | self::putResponse("update_user_posts_with_mutplie_path", $response); 128 | 129 | } 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | public function test_delete_user_posts_with_mutplie_path() 144 | { 145 | 146 | 147 | 148 | 149 | $map = new RequestMap(); 150 | $map->set("user_id", "1"); 151 | $map->set("post_id", "2"); 152 | 153 | 154 | $response = MultiplePathUserPost::deleteById("", $map); 155 | $this->assertNotNull($response); 156 | 157 | $ignoreAssert = array(); 158 | 159 | 160 | 161 | self::putResponse("delete_user_posts_with_mutplie_path", $response); 162 | 163 | } 164 | 165 | 166 | 167 | 168 | 169 | 170 | } 171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /Test/MasterCard/Api/NodeJSFunctionalTest.php: -------------------------------------------------------------------------------- 1 | assertNotNull($readItem); 56 | 57 | $this->assertEquals(1, $readItem->get("id")); 58 | $this->assertEquals("My Title", $readItem->get("title")); 59 | $this->assertEquals("some body text", $readItem->get("body")); 60 | $this->assertEquals(1, $readItem->get("userId")); 61 | } 62 | 63 | 64 | public function testActionReadFromPostWith500() { 65 | 66 | $this->expectException(\MasterCard\Core\Exception\ApiException::class); 67 | 68 | $readItem = Post::read("aaa"); 69 | 70 | } 71 | 72 | 73 | 74 | public function testActionReadFromPostWithCriteria200() { 75 | 76 | $tmpArray = array( 77 | 'one' => 1, 78 | 'two' => 2, 79 | 'three' => 3, 80 | 'four' => 4 81 | ); 82 | 83 | $readItem = Post::read("1", $tmpArray); 84 | 85 | $this->assertNotNull($readItem); 86 | 87 | $this->assertEquals(1, $readItem->get("id")); 88 | $this->assertEquals("My Title", $readItem->get("title")); 89 | $this->assertEquals("some body text", $readItem->get("body")); 90 | $this->assertEquals(1, $readItem->get("userId")); 91 | } 92 | 93 | 94 | public function testActionListFromPostWith200() { 95 | 96 | 97 | $createdItems = Post::listByCriteria(); 98 | 99 | $this->assertInternalType('array', $createdItems); 100 | 101 | $createdItem = $createdItems[0]; 102 | 103 | $this->assertEquals(1, $createdItem->get("id")); 104 | $this->assertEquals("My Title", $createdItem->get("title")); 105 | $this->assertEquals("some body text", $createdItem->get("body")); 106 | $this->assertEquals(1, $createdItem->get("userId")); 107 | } 108 | 109 | 110 | 111 | public function testActionListFromPostWithCriteria200() { 112 | 113 | $criteria = new RequestMap(); 114 | $criteria->set("user_id", 5); 115 | 116 | $createdItems = Post::listByCriteria($criteria); 117 | 118 | $this->assertInternalType('array', $createdItems); 119 | 120 | $createdItem = $createdItems[0]; 121 | 122 | $this->assertEquals(1, $createdItem->get("id")); 123 | $this->assertEquals("My Title", $createdItem->get("title")); 124 | $this->assertEquals("some body text", $createdItem->get("body")); 125 | $this->assertEquals(1, $createdItem->get("userId")); 126 | } 127 | 128 | 129 | 130 | 131 | 132 | public function testActionCreateFromPostWith200() { 133 | 134 | $requestMap = new RequestMap(); 135 | $requestMap->set("id", 1)->set("title", "My Title")->set("body", "some long text"); 136 | 137 | $createdItem = Post::create($requestMap); 138 | 139 | $this->assertNotNull($createdItem); 140 | 141 | 142 | $this->assertEquals(1, $createdItem->get("id")); 143 | $this->assertEquals("My Title", $createdItem->get("title")); 144 | $this->assertEquals("some body text", $createdItem->get("body")); 145 | $this->assertEquals(1, $createdItem->get("userId")); 146 | } 147 | 148 | 149 | public function testActionUpdateFromPost200() { 150 | 151 | $requestMap = new RequestMap(); 152 | $requestMap->set("id", 1)->set("title", "My Title")->set("body", "some long text"); 153 | 154 | $createdItem = Post::create($requestMap); 155 | $this->assertNotNull($createdItem); 156 | 157 | $createdItem->set("body", "updated body"); 158 | $createdItem->set("title", "updated title"); 159 | 160 | $updatedItem = $createdItem->update(); 161 | 162 | 163 | $this->assertEquals(1, $updatedItem->get("id")); 164 | $this->assertEquals("updated title", $updatedItem->get("title")); 165 | $this->assertEquals("updated body", $updatedItem->get("body")); 166 | $this->assertEquals(1, $updatedItem->get("userId")); 167 | } 168 | 169 | public function testActionDeleteFromPost200() { 170 | 171 | $deletedItem = Post::deleteById("1"); 172 | 173 | $this->assertEquals(0, $deletedItem->size()); 174 | 175 | 176 | } 177 | 178 | public function testActionListFromUserPostPath200() { 179 | $requestMap = new RequestMap(); 180 | $requestMap->set("user_id", 1); 181 | 182 | $items =UserPostPath::listByCriteria($requestMap); 183 | 184 | $this->assertInternalType('array', $items); 185 | 186 | $item = $items[0]; 187 | 188 | $this->assertEquals(1, $item->get("id")); 189 | $this->assertEquals("My Title", $item->get("title")); 190 | $this->assertEquals("some body text", $item->get("body")); 191 | $this->assertEquals(1, $item->get("userId")); 192 | } 193 | 194 | public function testActionListFromUserHeaderPath200() { 195 | $requestMap = new RequestMap(); 196 | $requestMap->set("user_id", 1); 197 | 198 | $items = UserPostHeader::listByCriteria($requestMap); 199 | 200 | $this->assertInternalType('array', $items); 201 | 202 | $item = $items[0]; 203 | 204 | $this->assertEquals(1, $item->get("id")); 205 | $this->assertEquals("My Title", $item->get("title")); 206 | $this->assertEquals("some body text", $item->get("body")); 207 | $this->assertEquals(1, $item->get("userId")); 208 | } 209 | 210 | 211 | public function testActionMultipathDelete200() { 212 | $requestMap = new RequestMap(); 213 | $requestMap->set("user_id", 1); 214 | $requestMap->set("post_id", 1); 215 | 216 | 217 | 218 | $deletedItem = MultiplePathUserPost::deleteById(null, $requestMap); 219 | $this->assertEquals(0, $deletedItem->size()); 220 | 221 | $requestArray = array( 222 | 'user_id' => 1, 223 | 'post_id' => 1, 224 | ); 225 | 226 | $deletedItem = MultiplePathUserPost::deleteById(null, $requestArray); 227 | $this->assertEquals(0, $deletedItem->size()); 228 | } 229 | 230 | } 231 | 232 | -------------------------------------------------------------------------------- /Test/MasterCard/Api/Parameters.php: -------------------------------------------------------------------------------- 1 | markTestSkipped('sandbox is down.'); 53 | 54 | $map = new RequestMap(); 55 | 56 | $map->set("CurrentRow", "1"); 57 | $map->set("Offset", "25"); 58 | 59 | 60 | 61 | $response = Parameters::query($map); 62 | $this->assertEquals(strtolower("NO"), strtolower($response->get("ParameterList.ParameterArray.Parameter[1].Ecomm"))); 63 | $this->assertEquals(strtolower("Quarterly"), strtolower($response->get("ParameterList.ParameterArray.Parameter[1].Period"))); 64 | $this->assertEquals(strtolower("NO"), strtolower($response->get("ParameterList.ParameterArray.Parameter[2].Ecomm"))); 65 | $this->assertEquals(strtolower("NO"), strtolower($response->get("ParameterList.ParameterArray.Parameter[0].Ecomm"))); 66 | $this->assertEquals(strtolower("U.S. Natural and Organic Grocery Stores"), strtolower($response->get("ParameterList.ParameterArray.Parameter[0].Sector"))); 67 | $this->assertEquals(strtolower("U.S. Natural and Organic Grocery Stores"), strtolower($response->get("ParameterList.ParameterArray.Parameter[1].Sector"))); 68 | $this->assertEquals(strtolower("U.S. Natural and Organic Grocery Stores"), strtolower($response->get("ParameterList.ParameterArray.Parameter[2].Sector"))); 69 | $this->assertEquals(strtolower("Monthly"), strtolower($response->get("ParameterList.ParameterArray.Parameter[0].Period"))); 70 | $this->assertEquals(strtolower("Success"), strtolower($response->get("ParameterList.Message"))); 71 | $this->assertEquals(strtolower("3"), strtolower($response->get("ParameterList.Count"))); 72 | $this->assertEquals(strtolower("US"), strtolower($response->get("ParameterList.ParameterArray.Parameter[0].Country"))); 73 | $this->assertEquals(strtolower("Weekly"), strtolower($response->get("ParameterList.ParameterArray.Parameter[2].Period"))); 74 | $this->assertEquals(strtolower("US"), strtolower($response->get("ParameterList.ParameterArray.Parameter[1].Country"))); 75 | $this->assertEquals(strtolower("US"), strtolower($response->get("ParameterList.ParameterArray.Parameter[2].Country"))); 76 | 77 | 78 | } 79 | 80 | 81 | 82 | } 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /Test/MasterCard/Api/Post.php: -------------------------------------------------------------------------------- 1 | set("id", $id); 116 | } 117 | if ($criteria != null) { 118 | $map->setAll($criteria); 119 | } 120 | return self::execute("6d79bf40-6b37-4a27-9df4-32016d7503db",new Post($map)); 121 | } 122 | 123 | 124 | /** 125 | * Updates an object of type Post 126 | * 127 | * @return A Post object representing the response. 128 | */ 129 | public function update() { 130 | return self::execute("96ca8b65-6cdd-46d7-86bd-cdad499fa863",$this); 131 | } 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | /** 140 | * Delete object of type Post by id 141 | * 142 | * @param String id 143 | * @return Post of the response of the deleted instance. 144 | */ 145 | public static function deleteById($id, $requestMap = null) 146 | { 147 | $map = new RequestMap(); 148 | if (!empty($id)) { 149 | $map->set("id", $id); 150 | } 151 | if (!empty($requestMap)) { 152 | $map->setAll($requestMap); 153 | } 154 | return self::execute("382c96c8-12d4-439a-94b1-9e607ec11c03", new Post($map)); 155 | } 156 | 157 | /** 158 | * Delete this object of type Post 159 | * 160 | * @return Post of the response of the deleted instance. 161 | */ 162 | public function delete() 163 | { 164 | return self::execute("382c96c8-12d4-439a-94b1-9e607ec11c03", $this); 165 | } 166 | 167 | 168 | 169 | 170 | } 171 | 172 | -------------------------------------------------------------------------------- /Test/MasterCard/Api/PostTest.php: -------------------------------------------------------------------------------- 1 | customAssertEqual($ignoreAssert, $responseList[0], "id", "1"); 66 | $this->customAssertEqual($ignoreAssert, $responseList[0], "title", "My Title"); 67 | $this->customAssertEqual($ignoreAssert, $responseList[0], "body", "some body text"); 68 | $this->customAssertEqual($ignoreAssert, $responseList[0], "userId", "1"); 69 | 70 | 71 | self::putResponse("list_posts_query_1", $responseList[0]); 72 | 73 | } 74 | 75 | public function test_list_posts_query_2() 76 | { 77 | 78 | 79 | 80 | 81 | $map = new RequestMap(); 82 | $map->set("max", "10"); 83 | 84 | 85 | $responseList = Post::listByCriteria($map); 86 | 87 | $ignoreAssert = array(); 88 | 89 | $this->customAssertEqual($ignoreAssert, $responseList[0], "id", "1"); 90 | $this->customAssertEqual($ignoreAssert, $responseList[0], "title", "My Title"); 91 | $this->customAssertEqual($ignoreAssert, $responseList[0], "body", "some body text"); 92 | $this->customAssertEqual($ignoreAssert, $responseList[0], "userId", "1"); 93 | 94 | 95 | self::putResponse("list_posts_query_2", $responseList[0]); 96 | 97 | } 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | public function test_create_post_test_only() 107 | { 108 | 109 | $map = new RequestMap(); 110 | $map->set("title", "Title of Post"); 111 | $map->set("body", "Some text as a body"); 112 | 113 | 114 | $response = Post::create($map); 115 | 116 | $ignoreAssert = array(); 117 | 118 | $this->customAssertEqual($ignoreAssert, $response, "id", "1"); 119 | $this->customAssertEqual($ignoreAssert, $response, "title", "My Title"); 120 | $this->customAssertEqual($ignoreAssert, $response, "body", "some body text"); 121 | $this->customAssertEqual($ignoreAssert, $response, "userId", "1"); 122 | 123 | 124 | self::putResponse("create_post_test_only", $response); 125 | } 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | public function test_get_post_query_1() 142 | { 143 | 144 | 145 | 146 | 147 | $id = "1"; 148 | 149 | $map = new RequestMap(); 150 | 151 | 152 | 153 | $response = Post::read($id,$map); 154 | 155 | $ignoreAssert = array(); 156 | 157 | $this->customAssertEqual($ignoreAssert, $response, "id", "1"); 158 | $this->customAssertEqual($ignoreAssert, $response, "title", "My Title"); 159 | $this->customAssertEqual($ignoreAssert, $response, "body", "some body text"); 160 | $this->customAssertEqual($ignoreAssert, $response, "userId", "1"); 161 | 162 | 163 | self::putResponse("get_post_query_1", $response); 164 | 165 | } 166 | 167 | 168 | public function test_get_post_query_2() 169 | { 170 | 171 | 172 | 173 | 174 | $id = "1"; 175 | 176 | $map = new RequestMap(); 177 | $map->set("min", "1"); 178 | $map->set("max", "10"); 179 | 180 | 181 | 182 | $response = Post::read($id,$map); 183 | 184 | $ignoreAssert = array(); 185 | 186 | $this->customAssertEqual($ignoreAssert, $response, "id", "1"); 187 | $this->customAssertEqual($ignoreAssert, $response, "title", "My Title"); 188 | $this->customAssertEqual($ignoreAssert, $response, "body", "some body text"); 189 | $this->customAssertEqual($ignoreAssert, $response, "userId", "1"); 190 | 191 | 192 | self::putResponse("get_post_query_2", $response); 193 | 194 | } 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | public function test_update_post() 204 | { 205 | 206 | 207 | 208 | 209 | $map = new RequestMap(); 210 | $map->set ("id", "1111"); 211 | $map->set ("title", "updated title"); 212 | $map->set ("body", "updated body"); 213 | 214 | 215 | $request = new Post($map); 216 | $response = $request->update(); 217 | 218 | $ignoreAssert = array(); 219 | 220 | $this->customAssertEqual($ignoreAssert, $response, "id", "1"); 221 | $this->customAssertEqual($ignoreAssert, $response, "title", "updated title"); 222 | $this->customAssertEqual($ignoreAssert, $response, "body", "updated body"); 223 | $this->customAssertEqual($ignoreAssert, $response, "userId", "1"); 224 | 225 | 226 | self::putResponse("update_post", $response); 227 | 228 | } 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | public function test_delete_post() 243 | { 244 | 245 | 246 | 247 | 248 | $map = new RequestMap(); 249 | 250 | 251 | $response = Post::deleteById("1", $map); 252 | $this->assertNotNull($response); 253 | 254 | $ignoreAssert = array(); 255 | 256 | 257 | 258 | self::putResponse("delete_post", $response); 259 | 260 | } 261 | 262 | 263 | 264 | 265 | 266 | 267 | } 268 | 269 | 270 | 271 | -------------------------------------------------------------------------------- /Test/MasterCard/Api/ResourceConfig.php: -------------------------------------------------------------------------------- 1 | setEnvironment($environment); 51 | // ApiConfig::addSDKConfig($this); 52 | } 53 | 54 | 55 | public static function getInstance() 56 | { 57 | if ( is_null( static::$instance ) ) 58 | { 59 | static::$instance = new self(); 60 | } 61 | return static::$instance; 62 | } 63 | 64 | public function getContext() { 65 | return static::$context; 66 | } 67 | 68 | public function getHost() { 69 | return (static::$override!= null) ? static::$override : static::$host; 70 | } 71 | 72 | public function getVersion() { 73 | return "0.0.1"; 74 | } 75 | 76 | 77 | public function setEnvironment($environment) { 78 | if (array_key_exists($environment, Environment::$MAPPING)) { 79 | $configArray = Environment::$MAPPING[$environment]; 80 | static::$host = $configArray[0]; 81 | static::$context = $configArray[1]; 82 | } else { 83 | throw new \RuntimeException("Environment: $environment not found for sdk: ".get_class()); 84 | } 85 | } 86 | 87 | public function clearOverride() { 88 | self::$override = null; 89 | } 90 | 91 | public function setOverride() { 92 | self::$override = "http://localhost:8081"; 93 | } 94 | 95 | 96 | 97 | } 98 | 99 | -------------------------------------------------------------------------------- /Test/MasterCard/Api/User.php: -------------------------------------------------------------------------------- 1 | set("id", $id); 120 | } 121 | if ($criteria != null) { 122 | $map->setAll($criteria); 123 | } 124 | return self::execute("081760b1-928c-44f6-943d-fb904b0ab0c4",new User($map)); 125 | } 126 | 127 | 128 | /** 129 | * Updates an object of type User 130 | * 131 | * @return A User object representing the response. 132 | */ 133 | public function update() { 134 | return self::execute("2669cecc-3107-4ecb-8327-2411d1ae2a97",$this); 135 | } 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | /** 144 | * Delete object of type User by id 145 | * 146 | * @param String id 147 | * @return User of the response of the deleted instance. 148 | */ 149 | public static function deleteById($id, $requestMap = null) 150 | { 151 | $map = new RequestMap(); 152 | if (!empty($id)) { 153 | $map->set("id", $id); 154 | } 155 | if (!empty($requestMap)) { 156 | $map->setAll($requestMap); 157 | } 158 | return self::execute("09db9343-eaf4-403f-a449-a11124ffb223", new User($map)); 159 | } 160 | 161 | /** 162 | * Delete this object of type User 163 | * 164 | * @return User of the response of the deleted instance. 165 | */ 166 | public function delete() 167 | { 168 | return self::execute("09db9343-eaf4-403f-a449-a11124ffb223", $this); 169 | } 170 | 171 | 172 | 173 | 174 | 175 | /** 176 | * Delete object of type User by id 177 | * 178 | * @param String id 179 | * @return User of the response of the deleted instance. 180 | */ 181 | public static function delete200ById($id, $requestMap = null) 182 | { 183 | $map = new RequestMap(); 184 | if (!empty($id)) { 185 | $map->set("id", $id); 186 | } 187 | if (!empty($requestMap)) { 188 | $map->setAll($requestMap); 189 | } 190 | return self::execute("04b8baa4-e27c-45e5-aa17-e47130a7f720", new User($map)); 191 | } 192 | 193 | /** 194 | * Delete this object of type User 195 | * 196 | * @return User of the response of the deleted instance. 197 | */ 198 | public function delete200() 199 | { 200 | return self::execute("04b8baa4-e27c-45e5-aa17-e47130a7f720", $this); 201 | } 202 | 203 | 204 | 205 | 206 | 207 | /** 208 | * Delete object of type User by id 209 | * 210 | * @param String id 211 | * @return User of the response of the deleted instance. 212 | */ 213 | public static function delete204ById($id, $requestMap = null) 214 | { 215 | $map = new RequestMap(); 216 | if (!empty($id)) { 217 | $map->set("id", $id); 218 | } 219 | if (!empty($requestMap)) { 220 | $map->setAll($requestMap); 221 | } 222 | return self::execute("547493bc-e096-4b4c-9e33-2534c7a95aae", new User($map)); 223 | } 224 | 225 | /** 226 | * Delete this object of type User 227 | * 228 | * @return User of the response of the deleted instance. 229 | */ 230 | public function delete204() 231 | { 232 | return self::execute("547493bc-e096-4b4c-9e33-2534c7a95aae", $this); 233 | } 234 | 235 | 236 | 237 | 238 | } 239 | 240 | -------------------------------------------------------------------------------- /Test/MasterCard/Api/UserPostHeader.php: -------------------------------------------------------------------------------- 1 | set("user_id", "1"); 60 | 61 | 62 | $responseList = UserPostHeader::listByCriteria($map); 63 | 64 | $ignoreAssert = array(); 65 | 66 | $this->customAssertEqual($ignoreAssert, $responseList[0], "id", "1"); 67 | $this->customAssertEqual($ignoreAssert, $responseList[0], "title", "My Title"); 68 | $this->customAssertEqual($ignoreAssert, $responseList[0], "body", "some body text"); 69 | $this->customAssertEqual($ignoreAssert, $responseList[0], "userId", "1"); 70 | 71 | 72 | self::putResponse("get_user_posts_with_header", $responseList[0]); 73 | 74 | } 75 | 76 | 77 | 78 | 79 | 80 | 81 | } 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /Test/MasterCard/Api/UserPostPath.php: -------------------------------------------------------------------------------- 1 | set("user_id", "1"); 60 | 61 | 62 | $responseList = UserPostPath::listByCriteria($map); 63 | 64 | $ignoreAssert = array(); 65 | 66 | $this->customAssertEqual($ignoreAssert, $responseList[0], "id", "1"); 67 | $this->customAssertEqual($ignoreAssert, $responseList[0], "title", "My Title"); 68 | $this->customAssertEqual($ignoreAssert, $responseList[0], "body", "some body text"); 69 | $this->customAssertEqual($ignoreAssert, $responseList[0], "userId", "1"); 70 | 71 | 72 | self::putResponse("get_user_posts_with_path", $responseList[0]); 73 | 74 | } 75 | 76 | 77 | 78 | 79 | 80 | 81 | } 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /Test/MasterCard/Api/UserTest.php: -------------------------------------------------------------------------------- 1 | customAssertEqual($ignoreAssert, $responseList[0], "website", "hildegard.org"); 66 | $this->customAssertEqual($ignoreAssert, $responseList[0], "address.instructions.doorman", "true"); 67 | $this->customAssertEqual($ignoreAssert, $responseList[0], "address.instructions.text", "some delivery instructions text"); 68 | $this->customAssertEqual($ignoreAssert, $responseList[0], "address.city", "New York"); 69 | $this->customAssertEqual($ignoreAssert, $responseList[0], "address.postalCode", "10577"); 70 | $this->customAssertEqual($ignoreAssert, $responseList[0], "address.id", "1"); 71 | $this->customAssertEqual($ignoreAssert, $responseList[0], "address.state", "NY"); 72 | $this->customAssertEqual($ignoreAssert, $responseList[0], "address.line1", "2000 Purchase Street"); 73 | $this->customAssertEqual($ignoreAssert, $responseList[0], "phone", "1-770-736-8031"); 74 | $this->customAssertEqual($ignoreAssert, $responseList[0], "name", "Joe Bloggs"); 75 | $this->customAssertEqual($ignoreAssert, $responseList[0], "id", "1"); 76 | $this->customAssertEqual($ignoreAssert, $responseList[0], "email", "name@example.com"); 77 | $this->customAssertEqual($ignoreAssert, $responseList[0], "username", "jbloggs"); 78 | 79 | 80 | self::putResponse("list_users", $responseList[0]); 81 | 82 | } 83 | 84 | public function test_list_users_query() 85 | { 86 | 87 | 88 | 89 | 90 | $map = new RequestMap(); 91 | $map->set("max", "10"); 92 | 93 | 94 | $responseList = User::listByCriteria($map); 95 | 96 | $ignoreAssert = array(); 97 | 98 | $this->customAssertEqual($ignoreAssert, $responseList[0], "website", "hildegard.org"); 99 | $this->customAssertEqual($ignoreAssert, $responseList[0], "address.instructions.doorman", "true"); 100 | $this->customAssertEqual($ignoreAssert, $responseList[0], "address.instructions.text", "some delivery instructions text"); 101 | $this->customAssertEqual($ignoreAssert, $responseList[0], "address.city", "New York"); 102 | $this->customAssertEqual($ignoreAssert, $responseList[0], "address.postalCode", "10577"); 103 | $this->customAssertEqual($ignoreAssert, $responseList[0], "address.id", "1"); 104 | $this->customAssertEqual($ignoreAssert, $responseList[0], "address.state", "NY"); 105 | $this->customAssertEqual($ignoreAssert, $responseList[0], "address.line1", "2000 Purchase Street"); 106 | $this->customAssertEqual($ignoreAssert, $responseList[0], "phone", "1-770-736-8031"); 107 | $this->customAssertEqual($ignoreAssert, $responseList[0], "name", "Joe Bloggs"); 108 | $this->customAssertEqual($ignoreAssert, $responseList[0], "id", "1"); 109 | $this->customAssertEqual($ignoreAssert, $responseList[0], "email", "name@example.com"); 110 | $this->customAssertEqual($ignoreAssert, $responseList[0], "username", "jbloggs"); 111 | 112 | 113 | self::putResponse("list_users_query", $responseList[0]); 114 | 115 | } 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | public function test_create_user() 125 | { 126 | 127 | 128 | 129 | 130 | $map = new RequestMap(); 131 | $map->set("website", "hildegard.org"); 132 | $map->set("address.city", "New York"); 133 | $map->set("address.postalCode", "10577"); 134 | $map->set("address.state", "NY"); 135 | $map->set("address.line1", "2000 Purchase Street"); 136 | $map->set("phone", "1-770-736-8031"); 137 | $map->set("name", "Joe Bloggs"); 138 | $map->set("email", "name@example.com"); 139 | $map->set("username", "jbloggs"); 140 | 141 | 142 | $response = User::create($map); 143 | 144 | $ignoreAssert = array(); 145 | 146 | $this->customAssertEqual($ignoreAssert, $response, "website", "hildegard.org"); 147 | $this->customAssertEqual($ignoreAssert, $response, "address.instructions.doorman", "true"); 148 | $this->customAssertEqual($ignoreAssert, $response, "address.instructions.text", "some delivery instructions text"); 149 | $this->customAssertEqual($ignoreAssert, $response, "address.city", "New York"); 150 | $this->customAssertEqual($ignoreAssert, $response, "address.postalCode", "10577"); 151 | $this->customAssertEqual($ignoreAssert, $response, "address.id", "1"); 152 | $this->customAssertEqual($ignoreAssert, $response, "address.state", "NY"); 153 | $this->customAssertEqual($ignoreAssert, $response, "address.line1", "2000 Purchase Street"); 154 | $this->customAssertEqual($ignoreAssert, $response, "phone", "1-770-736-8031"); 155 | $this->customAssertEqual($ignoreAssert, $response, "name", "Joe Bloggs"); 156 | $this->customAssertEqual($ignoreAssert, $response, "id", "1"); 157 | $this->customAssertEqual($ignoreAssert, $response, "email", "name@example.com"); 158 | $this->customAssertEqual($ignoreAssert, $response, "username", "jbloggs"); 159 | 160 | 161 | self::putResponse("create_user", $response); 162 | 163 | } 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | public function test_get_user() 180 | { 181 | 182 | 183 | 184 | 185 | $id = ""; 186 | 187 | $map = new RequestMap(); 188 | 189 | $map->set("id", self::resolveResponseValue("create_user.id")); 190 | 191 | 192 | $response = User::read($id,$map); 193 | 194 | $ignoreAssert = array(); 195 | $ignoreAssert[] = "address.city"; 196 | 197 | $this->customAssertEqual($ignoreAssert, $response, "website", "hildegard.org"); 198 | $this->customAssertEqual($ignoreAssert, $response, "address.instructions.doorman", "true"); 199 | $this->customAssertEqual($ignoreAssert, $response, "address.instructions.text", "some delivery instructions text"); 200 | $this->customAssertEqual($ignoreAssert, $response, "address.city", "New York"); 201 | $this->customAssertEqual($ignoreAssert, $response, "address.postalCode", "10577"); 202 | $this->customAssertEqual($ignoreAssert, $response, "address.id", "1"); 203 | $this->customAssertEqual($ignoreAssert, $response, "address.state", "NY"); 204 | $this->customAssertEqual($ignoreAssert, $response, "address.line1", "2000 Purchase Street"); 205 | $this->customAssertEqual($ignoreAssert, $response, "phone", "1-770-736-8031"); 206 | $this->customAssertEqual($ignoreAssert, $response, "name", "Joe Bloggs"); 207 | $this->customAssertEqual($ignoreAssert, $response, "id", "1"); 208 | $this->customAssertEqual($ignoreAssert, $response, "email", "name@example.com"); 209 | $this->customAssertEqual($ignoreAssert, $response, "username", "jbloggs"); 210 | 211 | 212 | self::putResponse("get_user", $response); 213 | 214 | } 215 | 216 | 217 | public function test_get_user_query() 218 | { 219 | 220 | 221 | 222 | 223 | $id = ""; 224 | 225 | $map = new RequestMap(); 226 | $map->set("min", "1"); 227 | $map->set("max", "10"); 228 | 229 | $map->set("id", self::resolveResponseValue("create_user.id")); 230 | 231 | 232 | $response = User::read($id,$map); 233 | 234 | $ignoreAssert = array(); 235 | 236 | $this->customAssertEqual($ignoreAssert, $response, "website", "hildegard.org"); 237 | $this->customAssertEqual($ignoreAssert, $response, "address.instructions.doorman", "true"); 238 | $this->customAssertEqual($ignoreAssert, $response, "address.instructions.text", "some delivery instructions text"); 239 | $this->customAssertEqual($ignoreAssert, $response, "address.city", "New York"); 240 | $this->customAssertEqual($ignoreAssert, $response, "address.postalCode", "10577"); 241 | $this->customAssertEqual($ignoreAssert, $response, "address.id", "1"); 242 | $this->customAssertEqual($ignoreAssert, $response, "address.state", "NY"); 243 | $this->customAssertEqual($ignoreAssert, $response, "address.line1", "2000 Purchase Street"); 244 | $this->customAssertEqual($ignoreAssert, $response, "phone", "1-770-736-8031"); 245 | $this->customAssertEqual($ignoreAssert, $response, "name", "Joe Bloggs"); 246 | $this->customAssertEqual($ignoreAssert, $response, "id", "1"); 247 | $this->customAssertEqual($ignoreAssert, $response, "email", "name@example.com"); 248 | $this->customAssertEqual($ignoreAssert, $response, "username", "jbloggs"); 249 | 250 | 251 | self::putResponse("get_user_query", $response); 252 | 253 | } 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | public function test_update_user() 263 | { 264 | 265 | 266 | 267 | 268 | $map = new RequestMap(); 269 | $map->set ("name", "Joe Bloggs"); 270 | $map->set ("username", "jbloggs"); 271 | $map->set ("email", "name@example.com"); 272 | $map->set ("phone", "1-770-736-8031"); 273 | $map->set ("website", "hildegard.org"); 274 | $map->set ("address.line1", "2000 Purchase Street"); 275 | $map->set ("address.city", "New York"); 276 | $map->set ("address.state", "NY"); 277 | $map->set ("address.postalCode", "10577"); 278 | 279 | $map->set("id", self::resolveResponseValue("create_user.id")); 280 | $map->set("id2", self::resolveResponseValue("create_user.id")); 281 | $map->set("prepend", "prepend".self::resolveResponseValue("create_user.id")); 282 | $map->set("append", self::resolveResponseValue("create_user.id")."append"); 283 | $map->set("complex", "prepend-".self::resolveResponseValue("create_user.id")."-".self::resolveResponseValue("create_user.name")); 284 | $map->set("name", self::resolveResponseValue("val:Andrea Rizzini")); 285 | 286 | $request = new User($map); 287 | $response = $request->update(); 288 | 289 | $ignoreAssert = array(); 290 | 291 | $this->customAssertEqual($ignoreAssert, $response, "website", "hildegard.org"); 292 | $this->customAssertEqual($ignoreAssert, $response, "address.instructions.doorman", "true"); 293 | $this->customAssertEqual($ignoreAssert, $response, "address.instructions.text", "some delivery instructions text"); 294 | $this->customAssertEqual($ignoreAssert, $response, "address.city", "New York"); 295 | $this->customAssertEqual($ignoreAssert, $response, "address.postalCode", "10577"); 296 | $this->customAssertEqual($ignoreAssert, $response, "address.id", "1"); 297 | $this->customAssertEqual($ignoreAssert, $response, "address.state", "NY"); 298 | $this->customAssertEqual($ignoreAssert, $response, "address.line1", "2000 Purchase Street"); 299 | $this->customAssertEqual($ignoreAssert, $response, "phone", "1-770-736-8031"); 300 | $this->customAssertEqual($ignoreAssert, $response, "name", "Joe Bloggs"); 301 | $this->customAssertEqual($ignoreAssert, $response, "id", "1"); 302 | $this->customAssertEqual($ignoreAssert, $response, "email", "name@example.com"); 303 | $this->customAssertEqual($ignoreAssert, $response, "username", "jbloggs"); 304 | 305 | 306 | self::putResponse("update_user", $response); 307 | 308 | } 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | public function test_delete_user() 323 | { 324 | 325 | 326 | 327 | 328 | $map = new RequestMap(); 329 | 330 | $map->set("id", self::resolveResponseValue("create_user.id")); 331 | 332 | $response = User::deleteById("ssss", $map); 333 | $this->assertNotNull($response); 334 | 335 | $ignoreAssert = array(); 336 | 337 | 338 | 339 | self::putResponse("delete_user", $response); 340 | 341 | } 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | public function test_delete_user_200() 355 | { 356 | 357 | 358 | 359 | 360 | $map = new RequestMap(); 361 | 362 | $map->set("id", self::resolveResponseValue("create_user.id")); 363 | 364 | $response = User::delete200ById("ssss", $map); 365 | $this->assertNotNull($response); 366 | 367 | $ignoreAssert = array(); 368 | 369 | 370 | 371 | self::putResponse("delete_user_200", $response); 372 | 373 | } 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | public function test_delete_user_204() 387 | { 388 | 389 | 390 | 391 | 392 | $map = new RequestMap(); 393 | 394 | $map->set("id", self::resolveResponseValue("create_user.id")); 395 | 396 | $response = User::delete204ById("ssss", $map); 397 | $this->assertNotNull($response); 398 | 399 | $ignoreAssert = array(); 400 | 401 | 402 | 403 | self::putResponse("delete_user_204", $response); 404 | 405 | } 406 | 407 | 408 | 409 | 410 | 411 | 412 | } 413 | 414 | 415 | 416 | -------------------------------------------------------------------------------- /Test/MasterCard/Core/Security/OAuth/OAuthUtilTest.php: -------------------------------------------------------------------------------- 1 | oauthAuthentication = new OAuthAuthentication("DuEVInT1ASB7AN7grP2Wd8t6Tpg31uYUlSTzoofYxP92pgyM!qkNEwNPSA0MnulBO6jTFt7cuIOgN3BnEAgvWcAeb1Z84bgqU", $privateKey, "fake-key", "fakepassword"); 47 | ApiConfig::setAuthentication($this->oauthAuthentication); 48 | } 49 | 50 | public function testGetNonce() { 51 | $nonce = SecurityUtil::getNonce(); 52 | $this->assertNotNull($nonce); 53 | $this->assertSame(16, strlen($nonce)); 54 | } 55 | 56 | public function testGetTimestamp() { 57 | $nonce = SecurityUtil::getTimestamp(); 58 | $this->assertNotNull($nonce); 59 | $this->assertSame(10, strlen($nonce)); 60 | } 61 | 62 | 63 | public function testGenerateSignature() { 64 | $body = "{ \"name\":\"andrea\", \"surname\":\"rizzini\" }"; 65 | $method = "POST"; 66 | $url = "http://www.andrea.rizzini.com/simple_service"; 67 | 68 | $oAuthParameters = new OAuthParameters (); 69 | $oAuthParameters->setOAuthConsumerKey($this->oauthAuthentication->getClientId()); 70 | $oAuthParameters->setOAuthNonce("NONCE"); 71 | $oAuthParameters->setOAuthTimestamp("TIMESTAMP"); 72 | $oAuthParameters->setOAuthSignatureMethod("RSA-SHA1"); 73 | 74 | if (!empty($body)) { 75 | $encodedHash = Util::base64Encode(Util::sha1Encode($body, true)); 76 | $oAuthParameters->setOAuthBodyHash($encodedHash); 77 | } 78 | 79 | $baseString = OAuthAuthentication::getOAuthBaseString($url, $method, $oAuthParameters->getBaseParameters()); 80 | $this->assertEquals("POST&http%3A%2F%2Fwww.andrea.rizzini.com%2Fsimple_service&oauth_body_hash%3DapwbAT6IoMRmB9wE9K4fNHDsaMo%253D%26oauth_consumer_key%3DDuEVInT1ASB7AN7grP2Wd8t6Tpg31uYUlSTzoofYxP92pgyM%2521qkNEwNPSA0MnulBO6jTFt7cuIOgN3BnEAgvWcAeb1Z84bgqU%26oauth_nonce%3DNONCE%26oauth_signature_method%3DRSA-SHA1%26oauth_timestamp%3DTIMESTAMP", $baseString); 81 | 82 | 83 | 84 | $signature = $this->oauthAuthentication->signValue($baseString); 85 | $this->assertEquals("CL/B3OkUsVOXE7tbIrM1DLLh3fC2xigxTFq3lkw3P65FBrw5wbVymygumKFBp9CpUEwMZpV0jHT1YFbA+d+6uK64E46be2SEtLAKZ8Z3wFPkmm8k6OrYWWGvvcY7UtDGihGxRb3Yoa/uT1FNw/3VWV31PKef/iDfzoGcFAaw21UcVnfTdgJrhBDIqLZcWtGhSGzXBN37ZjgOwBKaphqOZ5Bcu16XCTjNKGU5+y1/Ce8kc1NzKmNK+P+LO1xHrACOGmYCpk49q913sUcEeEmcjVPDLm1YIxPSdkq4ZFfekVoClC/rpmJnGTUfaIFcTS8PkBr1mgPSynMFK/SF4Uj/PQ==", $signature); 86 | $oAuthParameters->setOAuthSignature($signature); 87 | 88 | $baseParams = $oAuthParameters->getBaseParameters(); 89 | $this->assertEquals(['oauth_body_hash', 'oauth_consumer_key', 'oauth_nonce', 'oauth_signature', 'oauth_signature_method', 'oauth_timestamp'], array_keys($baseParams)); 90 | 91 | $this->assertEquals("apwbAT6IoMRmB9wE9K4fNHDsaMo=", $baseParams['oauth_body_hash'] ); 92 | $this->assertEquals("DuEVInT1ASB7AN7grP2Wd8t6Tpg31uYUlSTzoofYxP92pgyM!qkNEwNPSA0MnulBO6jTFt7cuIOgN3BnEAgvWcAeb1Z84bgqU", $baseParams['oauth_consumer_key']); 93 | $this->assertEquals("NONCE", $baseParams['oauth_nonce']); 94 | $this->assertEquals("CL/B3OkUsVOXE7tbIrM1DLLh3fC2xigxTFq3lkw3P65FBrw5wbVymygumKFBp9CpUEwMZpV0jHT1YFbA+d+6uK64E46be2SEtLAKZ8Z3wFPkmm8k6OrYWWGvvcY7UtDGihGxRb3Yoa/uT1FNw/3VWV31PKef/iDfzoGcFAaw21UcVnfTdgJrhBDIqLZcWtGhSGzXBN37ZjgOwBKaphqOZ5Bcu16XCTjNKGU5+y1/Ce8kc1NzKmNK+P+LO1xHrACOGmYCpk49q913sUcEeEmcjVPDLm1YIxPSdkq4ZFfekVoClC/rpmJnGTUfaIFcTS8PkBr1mgPSynMFK/SF4Uj/PQ==", $baseParams['oauth_signature']); 95 | $this->assertEquals("RSA-SHA1", $baseParams['oauth_signature_method']); 96 | $this->assertEquals("TIMESTAMP", $baseParams['oauth_timestamp']); 97 | 98 | 99 | $this->assertEquals("apwbAT6IoMRmB9wE9K4fNHDsaMo%3D", Util::uriRfc3986Encode($baseParams['oauth_body_hash'])); 100 | $this->assertEquals("DuEVInT1ASB7AN7grP2Wd8t6Tpg31uYUlSTzoofYxP92pgyM%21qkNEwNPSA0MnulBO6jTFt7cuIOgN3BnEAgvWcAeb1Z84bgqU", Util::uriRfc3986Encode($baseParams['oauth_consumer_key'])); 101 | $this->assertEquals("NONCE", Util::uriRfc3986Encode($baseParams['oauth_nonce'] )); 102 | $this->assertEquals("CL%2FB3OkUsVOXE7tbIrM1DLLh3fC2xigxTFq3lkw3P65FBrw5wbVymygumKFBp9CpUEwMZpV0jHT1YFbA%2Bd%2B6uK64E46be2SEtLAKZ8Z3wFPkmm8k6OrYWWGvvcY7UtDGihGxRb3Yoa%2FuT1FNw%2F3VWV31PKef%2FiDfzoGcFAaw21UcVnfTdgJrhBDIqLZcWtGhSGzXBN37ZjgOwBKaphqOZ5Bcu16XCTjNKGU5%2By1%2FCe8kc1NzKmNK%2BP%2BLO1xHrACOGmYCpk49q913sUcEeEmcjVPDLm1YIxPSdkq4ZFfekVoClC%2FrpmJnGTUfaIFcTS8PkBr1mgPSynMFK%2FSF4Uj%2FPQ%3D%3D", 103 | Util::uriRfc3986Encode($baseParams['oauth_signature'])); 104 | $this->assertEquals("RSA-SHA1", Util::uriRfc3986Encode($baseParams['oauth_signature_method'])); 105 | $this->assertEquals("TIMESTAMP", Util::uriRfc3986Encode($baseParams['oauth_timestamp']) ); 106 | 107 | 108 | } 109 | 110 | public function testOauthSignatureFromCSharpExample() 111 | { 112 | $baseMap = new RequestMap(); 113 | $baseMap->set("AccountInquiry.AccountNumber", "5343434343434343"); 114 | 115 | 116 | $method = "PUT"; 117 | $body = json_encode($baseMap->getBaseMapAsArray()); 118 | $this->assertEquals('{"AccountInquiry":{"AccountNumber":"5343434343434343"}}', $body); 119 | $url = "https://sandbox.api.mastercard.com/fraud/loststolen/v1/account-inquiry?Format=JSON"; 120 | 121 | $this->assertEquals("https://sandbox.api.mastercard.com/fraud/loststolen/v1/account-inquiry?Format=JSON", $url); 122 | 123 | 124 | $oAuthParameters = new OAuthParameters (); 125 | $oAuthParameters->setOAuthConsumerKey($this->oauthAuthentication->getClientId()); 126 | $oAuthParameters->setOAuthNonce("Fl0qGYY1ZmwMzzpdN"); 127 | $oAuthParameters->setOAuthTimestamp("1457428003"); 128 | $oAuthParameters->setOAuthSignatureMethod("RSA-SHA1"); 129 | 130 | if (!empty($body)) { 131 | $encodedHash = Util::base64Encode(Util::sha1Encode($body, true)); 132 | $oAuthParameters->setOAuthBodyHash($encodedHash); 133 | } 134 | 135 | $baseString = OAuthAuthentication::getOAuthBaseString($url, $method, $oAuthParameters->getBaseParameters()); 136 | $this->assertEquals("PUT&https%3A%2F%2Fsandbox.api.mastercard.com%2Ffraud%2Floststolen%2Fv1%2Faccount-inquiry&Format%3DJSON%26oauth_body_hash%3DnmtgpSOebxR%252FPfZyg9qwNoUEsYY%253D%26oauth_consumer_key%3DDuEVInT1ASB7AN7grP2Wd8t6Tpg31uYUlSTzoofYxP92pgyM%2521qkNEwNPSA0MnulBO6jTFt7cuIOgN3BnEAgvWcAeb1Z84bgqU%26oauth_nonce%3DFl0qGYY1ZmwMzzpdN%26oauth_signature_method%3DRSA-SHA1%26oauth_timestamp%3D1457428003", $baseString); 137 | 138 | $signature = $this->oauthAuthentication->signValue($baseString); 139 | $this->assertEquals("wT30diu3fP2biXpw66pmz68gSasAEVHhTrJZkMxDVmHwheYQNYD0ZCWW34aEdA0HFrQNWI8utAUKcaHpw+lxCBZRg1VMcjeuvIH4gerDRKGmi18CWoKSb3lZ0fiFLphq8maukaNQC1niZo33PNGMEJ2RKrA7YUxo8VEAgOTaRuB4SMqznkjvZoNRDSxBccvTB+HgLIHKHGt5MqvuOG2szVvfDgF1VBLAEMdBlTTXDIxcIYyRj1kQ5WHOmMfCuKWxnm/wyjxlDYZnRXJhmsehOao/aDNzYSZPu/lwsdWAprvIBN34xp/zNpTtKFukx7M84DrLprFRlgYzKjFPyO9eCw==", $signature); 140 | $oAuthParameters->setOAuthSignature($signature); 141 | 142 | $baseParams = $oAuthParameters->getBaseParameters(); 143 | $this->assertEquals(['oauth_body_hash', 'oauth_consumer_key', 'oauth_nonce', 'oauth_signature', 'oauth_signature_method', 'oauth_timestamp'], array_keys($baseParams)); 144 | $this->assertEquals("nmtgpSOebxR/PfZyg9qwNoUEsYY=", $baseParams['oauth_body_hash'] ); 145 | $this->assertEquals("DuEVInT1ASB7AN7grP2Wd8t6Tpg31uYUlSTzoofYxP92pgyM!qkNEwNPSA0MnulBO6jTFt7cuIOgN3BnEAgvWcAeb1Z84bgqU", $baseParams['oauth_consumer_key']); 146 | $this->assertEquals("Fl0qGYY1ZmwMzzpdN", $baseParams['oauth_nonce']); 147 | $this->assertEquals("wT30diu3fP2biXpw66pmz68gSasAEVHhTrJZkMxDVmHwheYQNYD0ZCWW34aEdA0HFrQNWI8utAUKcaHpw+lxCBZRg1VMcjeuvIH4gerDRKGmi18CWoKSb3lZ0fiFLphq8maukaNQC1niZo33PNGMEJ2RKrA7YUxo8VEAgOTaRuB4SMqznkjvZoNRDSxBccvTB+HgLIHKHGt5MqvuOG2szVvfDgF1VBLAEMdBlTTXDIxcIYyRj1kQ5WHOmMfCuKWxnm/wyjxlDYZnRXJhmsehOao/aDNzYSZPu/lwsdWAprvIBN34xp/zNpTtKFukx7M84DrLprFRlgYzKjFPyO9eCw==", $baseParams['oauth_signature']); 148 | $this->assertEquals("RSA-SHA1", $baseParams['oauth_signature_method']); 149 | $this->assertEquals("1457428003", $baseParams['oauth_timestamp']); 150 | 151 | 152 | } 153 | 154 | 155 | 156 | } 157 | -------------------------------------------------------------------------------- /Test/MasterCard/Core/UtilTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($baseUrl, Util::normalizeUrl($baseUrl)); 40 | 41 | $url2WithParams = "http://php.net/manual/en/function.parse-url.php?some=parameter&some1=parameter2"; 42 | $this->assertEquals($baseUrl, Util::normalizeUrl($url2WithParams)); 43 | 44 | $url2WithParams = "http://php.net/manual/en/function.parse-url.php?some=parameter&some1=parameter2"; 45 | $this->assertEquals($baseUrl, Util::normalizeUrl($url2WithParams)); 46 | } 47 | 48 | public function testNormalizeParameter() { 49 | 50 | $url = "http://php.net/manual/en/function.parse-url.php"; 51 | $parameters = "some=parameter&some1=parameter2"; 52 | $this->assertEquals($parameters, Util::normalizeParameters($url . "?" . $parameters, array())); 53 | 54 | $paramterArray = [ "paramNameFromArray1" => "paramValueFromArray1", "paramNameFromArray2" => "paramValueFromArray2"]; 55 | 56 | $url = "http://php.net/manual/en/function.parse-url.php?some=parameter&some1=parameter2"; 57 | $parameters = "paramNameFromArray1=paramValueFromArray1¶mNameFromArray2=paramValueFromArray2&some=parameter&some1=parameter2"; 58 | $this->assertEquals($parameters, Util::normalizeParameters($url, $paramterArray)); 59 | } 60 | 61 | public function testBase64Encode() { 62 | $this->assertEquals("cGFzc3dvcmQ=", Util::base64Encode("password")); 63 | } 64 | 65 | public function testSha1Encode() { 66 | $this->assertEquals("5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", Util::sha1Encode("password")); 67 | } 68 | 69 | public function testUrlEncode() { 70 | $url = "http://php.net/manual/en/function.parse-url.php?some=parameter&some1=parameter2"; 71 | $this->assertEquals("http%3A%2F%2Fphp.net%2Fmanual%2Fen%2Ffunction.parse-url.php%3Fsome%3Dparameter%26some1%3Dparameter2", Util::urlEncode($url)); 72 | } 73 | 74 | public function testUri3986Encode() 75 | { 76 | $this->assertEquals("andrea%21andrea%2Aandrea%27andrea%28andrea%29", Util::uriRfc3986Encode("andrea!andrea*andrea'andrea(andrea)")); 77 | } 78 | 79 | 80 | public function testSubMap() { 81 | 82 | $inputMap = array( 83 | 'one' => 1, 84 | 'two' => 2, 85 | 'three' => 3, 86 | 'four' => 4, 87 | 'five' => 5 88 | ); 89 | 90 | $keyList = array ( 91 | 'one', 92 | 'three', 93 | 'five' 94 | ); 95 | 96 | $subMap = Util::subMap($inputMap, $keyList); 97 | 98 | $this->assertCount(3, $subMap); 99 | $this->assertEquals(1, $subMap['one']); 100 | $this->assertEquals(3, $subMap['three']); 101 | $this->assertEquals(5, $subMap['five']); 102 | 103 | $this->assertCount(2, $inputMap); 104 | $this->assertEquals(2, $inputMap['two']); 105 | $this->assertEquals(4, $inputMap['four']); 106 | } 107 | 108 | 109 | public function testGetReplacedPath() { 110 | 111 | $inputMap = array( 112 | 'one' => 1, 113 | 'two' => 2, 114 | 'three' => 3, 115 | 'four' => 4, 116 | 'five' => 5 117 | ); 118 | $path = "http://localhost:8080/{one}/{two}/{three}/car"; 119 | $result = Util::getReplacedPath($path, $inputMap); 120 | 121 | $this->assertEquals("http://localhost:8080/1/2/3/car", $result); 122 | $this->assertCount(2, $inputMap); 123 | } 124 | 125 | // public function testGetReplacedPathWithBaseMap() { 126 | // 127 | // $inputMap = new BaseMap(); 128 | // $inputMap->set("one", 1)->set("two", 2)->set("three", 3)->set("four", 4)->set("five", 5); 129 | // 130 | // $path = "http://localhost:8080/{one}/{two}/{three}/car"; 131 | // $result = Util::getReplacedPath($path, $inputMap); 132 | // 133 | // $this->assertEquals("http://localhost:8080/1/2/3/car", $result); 134 | // $this->assertEquals(2, count($inputMap)); 135 | // } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /bin/composer.phar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mastercard/sdk-core-php/9ce898ba7ac18b1842aefc2e1171749347afd8b0/bin/composer.phar -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mastercard/mastercard-api-core", 3 | "description": "This is the core or base package of the MasterCard Api, all different flavours of Api provided by MasterCard will reuse this package", 4 | "version": "1.4.7", 5 | "license": "BSD-3-Clause", 6 | "authors": [ 7 | { 8 | "name": "MasterCard Worldwide", 9 | "email": "APISupport@mastercard.com" 10 | } 11 | ], 12 | "require": { 13 | "guzzlehttp/guzzle": "^6.1", 14 | "monolog/monolog": "^1.19" 15 | }, 16 | "require-dev": { 17 | "phpunit/phpunit": "^5.7" 18 | }, 19 | "autoload": { 20 | "psr-0": { 21 | "MasterCard": "" 22 | } 23 | }, 24 | "autoload-dev": { 25 | "psr-0": { 26 | "MasterCard": ["MasterCard/", "Test/"] 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /composer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CURRENT_DIR=${PWD} 4 | echo "php $CURRENT_DIR/bin/composer.phar $@" 5 | php "$CURRENT_DIR/bin/composer.phar" "$@" 6 | -------------------------------------------------------------------------------- /fake-key.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mastercard/sdk-core-php/9ce898ba7ac18b1842aefc2e1171749347afd8b0/fake-key.p12 -------------------------------------------------------------------------------- /nbproject/project.properties: -------------------------------------------------------------------------------- 1 | include.path=${php.global.include.path} 2 | php.version=PHP_56 3 | source.encoding=UTF-8 4 | src.dir=. 5 | tags.asp=false 6 | tags.short=false 7 | web.root=. 8 | -------------------------------------------------------------------------------- /nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.php.project 4 | 5 | 6 | mastercard-api-core 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ./Test 6 | 7 | 8 | 9 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /run-test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ./composer.sh exec -- phpunit 3 | --------------------------------------------------------------------------------