├── .DS_Store ├── .editorconfig ├── .eslintignore ├── .eslintrc.json ├── .github ├── dependabot.yml └── workflows │ ├── comment.yml │ ├── publish.yml │ ├── snyk.yml │ ├── stale.yml │ └── updates.test.yml ├── .gitignore ├── .ncurc.json ├── .npmrc ├── LICENSE ├── README.md ├── configs ├── tsconfig.base.json ├── tsconfig.cjs.json └── tsconfig.esm.json ├── images └── woocommerce-wordpress-logo.png ├── jest.config.ts ├── package-lock.json ├── package.json ├── reminder └── reminder.md ├── renovate.json ├── src ├── index.ts ├── test │ ├── api-data.json │ ├── coupons.json │ ├── customersJson-response.json │ ├── customersJson.json │ ├── example_data_orders.json │ ├── ordersJson.json │ ├── productsJson-response.json │ ├── productsJson.json │ └── wc.test.ts └── typesANDinterfaces.ts └── tsconfig.json /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yuri-Lima/woocommerce-rest-api-ts-lib/9b09cbae8ad27e13659cf36ecaae197aaebec0c6/.DS_Store -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | indent_style = space 6 | indent_size = 2 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [*.{json,yml}] 15 | insert_final_newline = false 16 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | lib 4 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "es6": true 4 | }, 5 | "plugins": [ 6 | "@typescript-eslint" 7 | ], 8 | "extends": [ 9 | "standard", 10 | "prettier", 11 | "plugin:jest/recommended", 12 | "plugin:@typescript-eslint/eslint-recommended", 13 | "plugin:@typescript-eslint/recommended" 14 | ], 15 | "globals": { 16 | "Atomics": "readonly", 17 | "SharedArrayBuffer": "readonly" 18 | }, 19 | "parserOptions": { 20 | "ecmaVersion": 2018, 21 | "sourceType": "module" 22 | }, 23 | "rules": { 24 | "indent": [ 25 | 2, 26 | 4 27 | ], 28 | "@typescript-eslint/no-explicit-any": ["off"], // allow any 29 | "@typescript-eslint/no-unused-vars": ["warn"], // warn 30 | "@typescript-eslint/no-disabled-tests ": ["off"], // warn 31 | "no-console": 1 // warn 32 | } 33 | } 34 | // npm i -D eslint eslint-config-prettier eslint-config-standard eslint-plugin-import eslint-plugin-jest eslint-plugin-node eslint-plugin-promise eslint-plugin-standard eslint-plugin-prettier -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "weekly" 12 | -------------------------------------------------------------------------------- /.github/workflows/comment.yml: -------------------------------------------------------------------------------- 1 | name: Merged notification 2 | 3 | # **What it does**: When we merge an open-source pull request, we want to set expectations that deployment may take awhile. 4 | # **Why we have it**: We deploy to production from docs-internal, not docs. 5 | # **Who does it impact**: Open-source contributors. 6 | 7 | on: 8 | pull_request_target: 9 | types: 10 | - 'closed' 11 | 12 | permissions: 13 | issues: write 14 | pull-requests: write 15 | 16 | jobs: 17 | comment: 18 | if: github.repository == 'github/docs' && github.event.pull_request.merged && github.event.pull_request.base.ref == github.event.repository.default_branch 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d 22 | with: 23 | script: | 24 | github.issues.createComment({ 25 | ...context.repo, 26 | issue_number: context.payload.pull_request.number, 27 | body: "Thanks very much for contributing! Your pull request has been merged 🎉 You should see your changes appear on our app in approximately 24 hours." 28 | }) 29 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node 2 | # Os: ubuntu-latest, windows-latest and macos-latest 3 | name: Publish NPM CI 4 | on: 5 | push: 6 | branches: [ "main" ] 7 | pull_request: 8 | branches: [ "main" ] 9 | workflow_dispatch: 10 | jobs: 11 | publish: 12 | runs-on: ubuntu-latest 13 | if: github.ref == 'refs/heads/main' 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: Use Node.js ${{ matrix.node-version }} 17 | uses: actions/setup-node@v3 18 | with: 19 | node-version: ${{ matrix.node-version }} 20 | cache: 'npm' 21 | - run: npm ci 22 | - run: npm run semantic-release 23 | env: 24 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 25 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 26 | -------------------------------------------------------------------------------- /.github/workflows/snyk.yml: -------------------------------------------------------------------------------- 1 | name: Snyk Security Check 2 | on: [push,pull_request] 3 | jobs: 4 | security: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@main 8 | - name: Run Snyk to check for vulnerabilities 9 | uses: snyk/actions/node@master 10 | env: 11 | SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: Stale 2 | 3 | # **What it does**: Close issues and pull requests after no updates for 365 days. 4 | # **Why we have it**: We want to manage our queue of issues and pull requests. 5 | # **Who does it impact**: Everyone that works on docs or docs-internal. 6 | 7 | on: 8 | schedule: 9 | - cron: '20 16 * * *' # Run every day at 16:20 UTC / 8:20 PST 10 | 11 | permissions: 12 | issues: write 13 | pull-requests: write 14 | 15 | jobs: 16 | stale: 17 | if: github.repository == 'github/docs-internal' || github.repository == 'github/docs' 18 | runs-on: ubuntu-latest 19 | steps: 20 | - uses: actions/stale@9c1b1c6e115ca2af09755448e0dbba24e5061cc8 21 | with: 22 | repo-token: ${{ secrets.GITHUB_TOKEN }} 23 | stale-issue-message: 'This issue is stale because there have been no updates in 60 days.' 24 | stale-pr-message: 'This PR is stale because there have been no updates in 60 days.' 25 | days-before-stale: 60 26 | days-before-close: 0 27 | stale-issue-label: 'stale' 28 | stale-pr-label: 'stale' 29 | exempt-pr-labels: 'never-stale,waiting for review' 30 | exempt-issue-labels: 'never-stale,help wanted,waiting for review' 31 | operations-per-run: 1000 32 | close-issue-reason: not_planned -------------------------------------------------------------------------------- /.github/workflows/updates.test.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node 2 | # Os: ubuntu-latest, windows-latest and macos-latest 3 | name: Updates Test CI 4 | on: 5 | push: 6 | branches: [ "updates" ] 7 | pull_request: 8 | branches: [ "updates" ] 9 | workflow_dispatch: 10 | jobs: 11 | test: 12 | runs-on: ${{ matrix.os }} 13 | strategy: 14 | matrix: 15 | node-version: [14.x, 16.x, 18.x] 16 | os: [ubuntu-latest, windows-latest, macOS-12] 17 | # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ 18 | steps: 19 | - uses: actions/checkout@v3 20 | - name: Use Node.js ${{ matrix.node-version }} 21 | uses: actions/setup-node@v3 22 | with: 23 | node-version: ${{ matrix.node-version }} 24 | cache: 'npm' 25 | - run: npm ci 26 | - run: npm run dep:update # update dependencies and run tests 27 | - run: npm run build --if-present 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | run.* 4 | index.js 5 | dist 6 | .env 7 | .src/test 8 | .reminder 9 | ./reminder/ 10 | setEnvVars.js -------------------------------------------------------------------------------- /.ncurc.json: -------------------------------------------------------------------------------- 1 | { 2 | "upgrade": true 3 | } -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=true 2 | @yurilima:registry= https://registry.npmjs.org/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 WooCommerce 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Updates Test CI](https://github.com/Yuri-Lima/woocommerce-rest-api-ts-lib/actions/workflows/updates.test.yml/badge.svg?branch=main)](https://github.com/Yuri-Lima/woocommerce-rest-api-ts-lib/actions/workflows/updates.test.yml) 2 | ![npm](https://img.shields.io/npm/v/woocommerce-rest-ts-api) 3 | ![npm](https://img.shields.io/npm/dt/woocommerce-rest-ts-api) 4 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 5 | [![Known Vulnerabilities](https://snyk.io/test/github/Yuri-Lima/woocommerce-rest-api-ts-lib/badge.svg?targetFile=package.json)](https://snyk.io/test/github/Yuri-Lima/woocommerce-rest-api-ts-lib?targetFile=package.json) 6 | 7 |
8 | woocommerce_integration_api 9 |
10 | 11 | # WooCommerce REST API - TypeScript Library 12 | 13 | This is alternative library which provides a set of TypeScript classes that can be used to interact with the WooCommerce REST API. 14 | `However, it is not a complete implementation of the API, but rather a subset of the API that is useful for.` 15 | 16 | New TypeScript library for WooCommerce REST API. Supports CommonJS (CJS) and ECMAScript (ESM) 17 | 18 | ## Fixing the issues [Triggered Date: 2022-11-15] 19 | 1. This new package was to fixe the issue with the official [WooCommerce REST API JavaScript library](https://github.com/woocommerce/woocommerce-rest-api-js-lib), which is not compatible with the security features for some packages used for. 20 | 2. **Axios** package used by them, had a `Cricital vulnerability` which seems not beeing updated often. 21 | 22 | Requests are made with [Axios library](https://github.com/axios/axios) with [support to promises](https://github.com/axios/axios#promises). 23 | 24 | ## Installation 25 | 26 | ``` 27 | npm install --save woocommerce-rest-ts-api 28 | ``` 29 | 30 | ## Getting started 31 | 32 | Generate API credentials (Consumer Key & Consumer Secret) following this instructions 33 | . 34 | 35 | Check out the WooCommerce API endpoints and data that can be manipulated in . 36 | 37 | ## Setup 38 | 39 | ### ESM example: 40 | 41 | ```ts 42 | import WooCommerceRestApi,{WooRestApiOptions} from "woocommerce-rest-ts-api"; 43 | const opt:WooRestApiOptions = { 44 | url: "http://example.com" , 45 | consumerKey: "ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 46 | consumerSecret: "cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 47 | version: "wc/v3", 48 | queryStringAuth: false // Force Basic Authentication as query string true and using under 49 | } 50 | const api = new WooCommerceRestApi(opt); 51 | ``` 52 | 53 | ### CJS example: 54 | 55 | ```js 56 | const WooCommerceRestApi = require("woocommerce-rest-ts-api").default; 57 | 58 | const api = new WooCommerceRestApi({ 59 | url: "http://example.com", 60 | consumerKey: "ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 61 | consumerSecret: "cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 62 | version: "wc/v3", 63 | queryStringAuth: false // Force Basic Authentication as query string true and using under HTTPS 64 | }); 65 | ``` 66 | 67 | ### Options 68 | 69 | | Option | Type | Required | Description | 70 | |-------------------|-----------|----------|---------------------------------------------------------------------------------------------------------------------| 71 | | `url` | `String` | yes | Your Store URL, example: http://woo.dev/ | 72 | | `consumerKey` | `String` | yes | Your API consumer key | 73 | | `consumerSecret` | `String` | yes | Your API consumer secret | 74 | | `wpAPIPrefix` | `String` | no | Custom WP REST API URL prefix, used to support custom prefixes created with the `rest_url_prefix` filter | 75 | | `version` | `String` | no | API version, default is `v3` | 76 | | `encoding` | `String` | no | Encoding, default is 'utf-8' | 77 | | `queryStringAuth` | `Bool` | no | When `true` and using under HTTPS force Basic Authentication as query string, default is `false` | 78 | | `port` | `string` | no | Provide support for URLs with ports, eg: `8080` | 79 | | `timeout` | `Integer` | no | Define the request timeout | 80 | | `axiosConfig` | `Object` | no | Define the custom [Axios config](https://github.com/axios/axios#request-config), also override this library options | 81 | 82 | ## Methods 83 | 84 | ### GET 85 | 86 | - `.get(endpoint)` 87 | - `.get(endpoint, params)` 88 | - params?: Partial 89 | 90 | | Params | Type | Description | 91 | |------------|----------|---------------------------------------------------------------| 92 | | `endpoint` | `String` | WooCommerce API endpoint, example: `customers` or `orders/12` | 93 | | `params` | `Object` | Query strings params, example: `{ per_page: 20 }` | 94 | 95 | ### POST 96 | 97 | - `.post(endpoint, data)` 98 | - `.post(endpoint, data, params)` 99 | - data: Record 100 | - params?: Partial 101 | 102 | | Params | Type | Description | 103 | |------------|----------|-------------------------------------------------------------| 104 | | `endpoint` | `String` | WooCommerce API endpoint, example: `customers` or `orders` | 105 | | `data` | `Object` | JS object to be converted into JSON and sent in the request | 106 | | `params` | `Object` | Query strings params | 107 | 108 | ### PUT 109 | 110 | - `.put(endpoint, data)` 111 | - `.put(endpoint, data, params)` 112 | - data: Record 113 | - params?: Partial 114 | 115 | | Params | Type | Description | 116 | |------------|----------|-------------------------------------------------------------------| 117 | | `endpoint` | `String` | WooCommerce API endpoint, example: `customers/1` or `orders/1234` | 118 | | `data` | `Object` | JS object to be converted into JSON and sent in the request | 119 | | `params` | `Object` | Query strings params | 120 | 121 | ### DELETE 122 | 123 | - `.delete(endpoint)` 124 | - `.delete(endpoint, params)` 125 | - data: Pick, 126 | - params: Pick 127 | 128 | | Params | Type | Description | 129 | |------------|----------|-----------------------------------------------------------------| 130 | | `endpoint` | `String` | WooCommerce API endpoint, example: `customers/2` or `orders/12` | 131 | | `params` | `Object` | Query strings params, example: `{ force: true }` | 132 | 133 | ### OPTIONS 134 | 135 | - `.options(endpoint)` 136 | - `.options(endpoint, params)` 137 | - params?: Partial 138 | 139 | | Params | Type | Description | 140 | |------------|----------|-----------------------------------------------------------------| 141 | | `endpoint` | `String` | WooCommerce API endpoint, example: `customers/2` or `orders/12` | 142 | | `params` | `Object` | Query strings params | 143 | 144 | ## Example of use 145 | 146 | ```ts 147 | import WooCommerceRestApi,{CouponsParams, ProductsMainParams, OrdersMainParams, WooRestApiOptions} from "woocommerce-rest-ts-api"; 148 | // const WooCommerceRestApi = require("woocommerce-rest-ts-api").default; 149 | 150 | const api = new WooCommerceRestApi({ 151 | url: "http://example.com", 152 | consumerKey: "ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 153 | consumerSecret: "cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 154 | version: "wc/v3", 155 | queryStringAuth: false // Force Basic Authentication as query string true and using under HTTPS 156 | }); 157 | 158 | // List products 159 | const products = await api.get("products", { 160 | per_page: 20, // 20 products per page 161 | }); 162 | products.status; // 200 163 | product.headers.get('x-wp-totalpages') 164 | products.headers.get('x-wp-total') 165 | products.headers.forEach((header) => { 166 | console.log(header); 167 | }); 168 | products.data.forEach((product) => { 169 | console.log(product.name); 170 | }); 171 | 172 | // Create a product 173 | // See more in https://woocommerce.github.io/woocommerce-rest-api-docs/#product-properties 174 | const data:ProductsMainParams = { 175 | name: "Premium Quality", 176 | type: "simple", 177 | regular_price: "21.99", 178 | description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", 179 | short_description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", 180 | categories: [ 181 | { 182 | id: 9 183 | }, 184 | { 185 | id: 14 186 | } 187 | ], 188 | images: [ 189 | { 190 | src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg" 191 | }, 192 | { 193 | src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg" 194 | } 195 | ] 196 | }; 197 | const products = await api.post("products", data); 198 | products.status; // 201 199 | products.data; // { id: 11, ... } 200 | products.headers.get('x-wp-totalpages') 201 | products.headers.get('x-wp-total') 202 | 203 | // Edit/Update a product 204 | const data:ProductsMainParams = { 205 | name: "Premium Quality Updated-" + randomstring.generate({length:4, capitalization:"uppercase", charset: "alphanumeric"}), 206 | type: "simple", 207 | regular_price: "30.22", 208 | description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", 209 | short_description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", 210 | categories: [ 211 | { 212 | id: 9 213 | }, 214 | { 215 | id: 14 216 | } 217 | ], 218 | images: [ 219 | { 220 | src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg" 221 | }, 222 | { 223 | src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg" 224 | } 225 | ] 226 | }; 227 | const products = await api.put("products", data, {id: 11}); 228 | products.status; // 201 229 | products.data; // { id: 11, ... } 230 | products.headers.get('x-wp-totalpages') 231 | products.headers.get('x-wp-total') 232 | 233 | // Delete a product 234 | const products = await wooCommerce.delete("products", {force: true}, {id: 11}); 235 | products.status; // 201 236 | products.data; // { id: 11, ... } 237 | products.headers.get('x-wp-totalpages') 238 | products.headers.get('x-wp-total') 239 | 240 | // Create a order 241 | const data:OrdersMainParams = { 242 | payment_method: "bacs", 243 | payment_method_title: "Direct Bank Transfer", 244 | set_paid: true, 245 | billing: { 246 | first_name: `John ${Math.random()}`, 247 | last_name: "Doe", 248 | address_1: "969 Market", 249 | address_2: "", 250 | city: "San Francisco", 251 | state: "CA", 252 | postcode: "94103", 253 | country: "US", 254 | email: "john.doe@example.com", 255 | phone: "85996859001", 256 | company: "WooCommerce" 257 | }, 258 | shipping: { 259 | first_name: "John", 260 | last_name: "Doe", 261 | address_1: "969 Market", 262 | address_2: "", 263 | city: "San Francisco", 264 | state: "CA", 265 | postcode: "94103", 266 | country: "US", 267 | company: "WooCommerce" 268 | }, 269 | line_items: [ 270 | { 271 | product_id: 93, 272 | quantity: 2 273 | }, 274 | { 275 | product_id: 22, 276 | variation_id: 23, 277 | quantity: 1 278 | } 279 | ], 280 | shipping_lines: [ 281 | { 282 | method_id: "flat_rate", 283 | method_title: "Flat Rate", 284 | total: "10.00" 285 | } 286 | ] 287 | }; 288 | const order = await api.post("orders", data); 289 | order.status; // 201 290 | order.data; // { id: 11, ... } 291 | order.headers.get('x-wp-totalpages') 292 | order.headers.get('x-wp-total') 293 | 294 | // Edit/Update a order 295 | const data:OrdersMainParams = { 296 | payment_method: "bacs", 297 | payment_method_title: "Direct Bank Transfer", 298 | set_paid: true, 299 | billing: { 300 | first_name: `Yuri ${Math.random()}`, 301 | last_name: "Doe", 302 | address_1: "969 Market", 303 | address_2: "", 304 | city: "San Francisco", 305 | }, 306 | }; 307 | const order = await api.put("orders", data, {id: 11}); 308 | order.status; // 201 309 | order.data; // { id: 11, ... } 310 | order.headers.get('x-wp-totalpages') 311 | order.headers.get('x-wp-total') 312 | 313 | // Delete a order 314 | const order = await api.delete("orders", {force: true}, {id: 11}); 315 | order.status; // 201 316 | order.data; // { id: 11, ... } 317 | order.headers.get('x-wp-totalpages') 318 | order.headers.get('x-wp-total') 319 | ``` 320 | 321 | ## Changelog 322 | 323 | [See changelog for details](https://github.com/woocommerce/woocommerce-rest-api-js-lib/blob/master/CHANGELOG.md) 324 | 325 | ## Thanks / Credits / Bibliography 326 | - [snyk - Best Pratice Guide](https://snyk.io/blog/best-practices-create-modern-npm-package/) 327 | - [woocommerce](https://woocommerce.github.io/woocommerce-rest-api-docs/) 328 | - [dennismphil - Updates dependencies](https://dev.to/dennismphil/automate-your-node-dependency-updates-4aga) 329 | - [emojis](https://www.webfx.com/tools/emoji-cheat-sheet/) 330 | - [eslint-for-typescript](https://khalilstemmler.com/blogs/typescript/eslint-for-typescript/) 331 | - [Yoni Goldberg’s - Tests](https://github.com/goldbergyoni/javascript-testing-best-practices) 332 | - [Ben Awad - Generic Types](https://youtu.be/nViEqpgwxHE) 333 | - [Anthony Fu - Publish ESM and CJS in a single package](https://antfu.me/posts/publish-esm-and-cjs) 334 | - [Semantic Releases - egghead](https://egghead.io/lessons/javascript-automating-releases-with-semantic-release) 335 | - [GH006 Protected Branch Update Failed - paulmowat](https://www.paulmowat.co.uk/blog/resolve-github-action-gh006-protected-branch-update-failed) 336 | - [swizec - jest-with-typescript](https://swizec.com/blog/how-to-configure-jest-with-typescript/) 337 | 338 | > ### Contact 339 | **Atention** If you email me, please use as a email subject, the name of the project, in this case: **(WooCommerce TS Library) - INFO** 340 | 341 | | Name | Email | Mobile/Whatsapp | 342 | |-------|--------|---------| 343 | | Yuri Lima | y.m.lima19@gmail.com | +353 83 419.1605 | 344 | -------------------------------------------------------------------------------- /configs/tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | // "incremental": true, 4 | "strict": true, 5 | "strictPropertyInitialization": false, 6 | "esModuleInterop": true, 7 | "forceConsistentCasingInFileNames": true, 8 | "skipLibCheck": true, 9 | "checkJs": true, 10 | "allowJs": true, 11 | "declaration": true, 12 | "declarationMap": true, 13 | "allowSyntheticDefaultImports": true, 14 | // "experimentalDecorators": true, 15 | // "emitDecoratorMetadata": true, 16 | // "resolveJsonModule": true, 17 | // "removeComments": true, 18 | // "noUnusedLocals": false, 19 | // "noUnusedParameters": false 20 | }, 21 | "files": [ 22 | "../src/index.ts" 23 | ], 24 | "include": [ 25 | "../src/**/*.ts" 26 | ], 27 | } -------------------------------------------------------------------------------- /configs/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", // <- this is the important part to extend the base config 3 | "compilerOptions": { 4 | "lib": ["ES6", "DOM"], // <-- property indicates to TypeScript what types it should reference to assist you while writing code for your project. 5 | "target": "ES6", // <-- property indicates to TypeScript what version of JavaScript you want to target. 6 | "module": "CommonJS", // <-- property indicates to TypeScript what module system you want yo be used when compiling your code. 7 | "moduleResolution": "Node", // <-- property indicates to TypeScript how to resolve modules like import statements. 8 | "outDir": "../lib/cjs", // <-- property indicates to TypeScript where to put the compiled JavaScript files. 9 | "declarationDir": "../lib/cjs/types" // <-- property indicates to TypeScript where to put the compiled TypeScript declaration files. 10 | } 11 | } -------------------------------------------------------------------------------- /configs/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", // <- this is the important part to extend the base config 3 | "compilerOptions": { 4 | "lib": ["ES2022", "DOM"], // <-- property indicates to TypeScript what types it should reference to assist you while writing code for your project. 5 | "target": "ES2022", // <-- property indicates to TypeScript what version of JavaScript you want to target. 6 | "module": "ESNext", // <-- property indicates to TypeScript what module system you want yo be used when compiling your code. 7 | "moduleResolution": "Node", // <-- property indicates to TypeScript how to resolve modules like import statements. 8 | "outDir": "../lib/esm", // <-- property indicates to TypeScript where to put the compiled JavaScript files. 9 | "declarationDir": "../lib/esm/types" // <-- property indicates to TypeScript where to put the compiled TypeScript declaration files. 10 | } 11 | } -------------------------------------------------------------------------------- /images/woocommerce-wordpress-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yuri-Lima/woocommerce-rest-api-ts-lib/9b09cbae8ad27e13659cf36ecaae197aaebec0c6/images/woocommerce-wordpress-logo.png -------------------------------------------------------------------------------- /jest.config.ts: -------------------------------------------------------------------------------- 1 | /** @type {import('ts-jest').JestConfigWithTsJest} */ 2 | import type { Config } from "jest"; 3 | import os from "os"; 4 | 5 | const config: Config = { 6 | preset: "ts-jest", 7 | testEnvironment: "node", 8 | verbose: true, 9 | maxWorkers: (os.cpus().length - 1) / 2, // 50% of the available cores 10 | detectOpenHandles: false, // Detects when a test leaves something behind that it shouldn't 11 | testMatch: ["**/test/test.ts", "**/test/wc.test.ts"], 12 | testPathIgnorePatterns: ["node_modules", "dist"], 13 | coveragePathIgnorePatterns: ["node_modules", "dist"], 14 | collectCoverage: true, 15 | collectCoverageFrom: ["src/**/*.ts"], 16 | coverageReporters: ["json", "lcov", "text", "clover"], 17 | coverageDirectory: "coverage", 18 | setupFiles: [ 19 | "/setEnvVars.js", // Sets the environment variables 20 | ], 21 | transform: { 22 | "^.+\\.tsx?$": "ts-jest", 23 | }, 24 | }; 25 | 26 | export default config; 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "woocommerce-rest-ts-api", 3 | "version": "7.0.2", 4 | "description": "WooCommerce REST API - Type Script Library", 5 | "author": "Yuri Lima", 6 | "license": "MIT", 7 | "engines": { 8 | "node": ">=14.0.0" 9 | }, 10 | "main": "./dist/index.js", 11 | "module": "./dist/index.mjs", 12 | "types": "./dist/src/index.d.ts", 13 | "files": [ 14 | "./dist/**/*" 15 | ], 16 | "exports": { 17 | ".": { 18 | "require": "./dist/index.js", 19 | "import": "./dist/index.mjs", 20 | "types": "./dist/src/index.d.ts" 21 | } 22 | }, 23 | "scripts": { 24 | "build": "npm run prepack", 25 | "dep:update": "ncu && ncu --doctor -u && ncu -u", 26 | "test": "jest", 27 | "data:generate": "ts-node ./src/test/generate-data.ts", 28 | "format": "prettier --write \"**/*.ts\"", 29 | "lint": "eslint . --ext .ts", 30 | "lint-and-fix": "eslint . --ext .ts --fix", 31 | "prepublishOnly": "npm run dep:update && npm run format && npm run lint-and-fix", 32 | "clean": "rm -rf ./dist", 33 | "build:types": "npx tsc --emitDeclarationOnly --declaration", 34 | "build:cjs:esm": "npx tsup ./src/index.ts --format cjs,esm --sourcemap", 35 | "prepack": "npm run clean && npm run build:cjs:esm && npm run build:types", 36 | "semantic-release": "semantic-release", 37 | "commit": "cz", 38 | "postinstall": "tsc --outDir ./build" 39 | }, 40 | "lint-staged": { 41 | "*.{ts,js,json}": [ 42 | "eslint --fix", 43 | "prettier --write" 44 | ] 45 | }, 46 | "dependencies": { 47 | "axios": "^1.5.1", 48 | "dynamic.envs": "^1.0.4", 49 | "oauth-1.0a": "^2.2.6", 50 | "typescript": "^5.2.2", 51 | "url-parse": "^1.5.10" 52 | }, 53 | "devDependencies": { 54 | "@semantic-release/git": "^10.0.1", 55 | "@semantic-release/github": "^8.0.7", 56 | "@types/jest": "^29.5.0", 57 | "@types/luxon": "^3.3.0", 58 | "@types/randomstring": "^1.1.8", 59 | "@types/url-parse": "^1.4.8", 60 | "@typescript-eslint/eslint-plugin": "^5.57.1", 61 | "@typescript-eslint/parser": "^5.57.1", 62 | "commitizen": "^4.3.0", 63 | "cz-conventional-changelog": "^3.3.0", 64 | "del-cli": "^5.0.0", 65 | "eslint": "^8.38.0", 66 | "eslint-config-prettier": "^8.8.0", 67 | "eslint-config-standard": "^17.0.0", 68 | "eslint-plugin-import": "^2.27.5", 69 | "eslint-plugin-jest": "^27.2.1", 70 | "eslint-plugin-n": "^15.7.0", 71 | "eslint-plugin-node": "^11.1.0", 72 | "eslint-plugin-prettier": "^4.2.1", 73 | "eslint-plugin-promise": "^6.1.1", 74 | "jest": "^29.5.0", 75 | "lint-staged": "13.2.1", 76 | "luxon": "^3.3.0", 77 | "nock": "13.3.0", 78 | "npm-check-updates": "^16.10.7", 79 | "prettier": "2.8.7", 80 | "randomstring": "^1.2.3", 81 | "semantic-release": "^21.0.1", 82 | "ts-jest": "^29.1.0", 83 | "ts-node": "^10.9.1", 84 | "tsup": "^6.7.0" 85 | }, 86 | "homepage": "https://yurilima.uk/", 87 | "repository": { 88 | "type": "git", 89 | "url": "https://github.com/Yuri-Lima/woocommerce-rest-api-ts-lib" 90 | }, 91 | "bugs": { 92 | "url": "https://github.com/Yuri-Lima/woocommerce-rest-api-ts-lib/issues" 93 | }, 94 | "release": { 95 | "branches": [ 96 | "updates", 97 | "master", 98 | "main" 99 | ], 100 | "plugins": [ 101 | "@semantic-release/commit-analyzer", 102 | "@semantic-release/release-notes-generator", 103 | "@semantic-release/github", 104 | "@semantic-release/npm", 105 | "@semantic-release/git" 106 | ] 107 | }, 108 | "publishConfig": { 109 | "access": "public", 110 | "registry": "https://registry.npmjs.org/" 111 | }, 112 | "private": false, 113 | "config": { 114 | "commitizen": { 115 | "path": "./node_modules/cz-conventional-changelog", 116 | "disableScopeLowerCase": true 117 | } 118 | }, 119 | "keywords": [ 120 | "wordpress", 121 | "woocommerce", 122 | "rest", 123 | "promise", 124 | "node", 125 | "typescript", 126 | "api" 127 | ] 128 | } 129 | -------------------------------------------------------------------------------- /reminder/reminder.md: -------------------------------------------------------------------------------- 1 | Argument of type '""' is not assignable to parameter of type 'WooRestApiEndpoint'. -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import axios, { RawAxiosRequestHeaders, AxiosRequestConfig } from "axios"; 2 | import crypto from "node:crypto"; 3 | import OAuth from "oauth-1.0a"; 4 | import Url from "url-parse"; 5 | import { 6 | WooRestApiMethod, 7 | // IWooRestApiQuery, 8 | IWooRestApiOptions, 9 | WooRestApiEndpoint, 10 | OrdersMainParams, 11 | ProductsMainParams, 12 | SystemStatusParams, 13 | CouponsParams, 14 | CustomersParams, 15 | DELETE, 16 | } from "./typesANDinterfaces.js"; // Typescript types for the library 17 | 18 | export { 19 | WooRestApiMethod, 20 | IWooRestApiQuery, 21 | IWooRestApiOptions, 22 | WooRestApiEndpoint, 23 | OrdersMainParams, 24 | ProductsMainParams, 25 | SystemStatusParams, 26 | CouponsParams, 27 | CustomersParams, 28 | DELETE, 29 | } from "./typesANDinterfaces.js"; // Export all the types 30 | 31 | /** 32 | * Set the axiosConfig property to the axios config object. 33 | * Could reveive any axios |... config objects. 34 | * @param {AxiosRequestConfig} axiosConfig 35 | */ 36 | export type WooRestApiOptions = IWooRestApiOptions; 37 | 38 | /** 39 | * Set all the possible query params for the WooCommerce REST API. 40 | */ 41 | export type WooRestApiParams = CouponsParams & 42 | CustomersParams & 43 | OrdersMainParams & 44 | ProductsMainParams & 45 | SystemStatusParams & 46 | DELETE; 47 | 48 | /** 49 | * WooCommerce REST API wrapper 50 | * 51 | * @param {Object} opt 52 | */ 53 | export default class WooCommerceRestApi { 54 | protected _opt: T; 55 | 56 | /** 57 | * Class constructor. 58 | * 59 | * @param {Object} opt 60 | */ 61 | constructor(opt: T) { 62 | this._opt = opt; 63 | 64 | /** 65 | * If the class is not instantiated, return a new instance. 66 | * This is useful for the static methods. 67 | */ 68 | if (!(this instanceof WooCommerceRestApi)) { 69 | return new WooCommerceRestApi(opt); 70 | } 71 | 72 | /** 73 | * Check if the url is defined. 74 | */ 75 | if (!this._opt.url || this._opt.url === "") { 76 | throw new OptionsException("url is required"); 77 | } 78 | 79 | /** 80 | * Check if the consumerKey is defined. 81 | */ 82 | if (!this._opt.consumerKey || this._opt.consumerKey === "") { 83 | throw new OptionsException("consumerKey is required"); 84 | } 85 | 86 | /** 87 | * Check if the consumerSecret is defined. 88 | */ 89 | if (!this._opt.consumerSecret || this._opt.consumerSecret === "") { 90 | throw new OptionsException("consumerSecret is required"); 91 | } 92 | 93 | /** 94 | * Set default options 95 | */ 96 | this._setDefaultsOptions(this._opt); 97 | } 98 | 99 | /** 100 | * Set default options 101 | * 102 | * @param {Object} opt 103 | */ 104 | _setDefaultsOptions(opt: T): void { 105 | this._opt.wpAPIPrefix = opt.wpAPIPrefix || "wp-json"; 106 | this._opt.version = opt.version || "wc/v3"; 107 | this._opt.isHttps = /^https/i.test(this._opt.url); 108 | this._opt.encoding = opt.encoding || "utf-8"; 109 | this._opt.queryStringAuth = opt.queryStringAuth || false; 110 | this._opt.classVersion = "0.0.2"; 111 | } 112 | 113 | /** 114 | * Parse params to object. 115 | * 116 | * @param {Object} params 117 | * @param {Object} query 118 | * @return {Object} IWooRestApiQuery 119 | */ 120 | // _parseParamsObject(params: Record, query: Record): IWooRestApiQuery { 121 | // for (const key in params) { 122 | // if (typeof params[key] === "object") { 123 | // // If the value is an object, loop through it and add it to the query object 124 | // for (const subKey in params[key]) { 125 | // query[key + "[" + subKey + "]"] = params[key][subKey]; 126 | // } 127 | // } else { 128 | // query[key] = params[key]; // If the value is not an object, add it to the query object 129 | // } 130 | // } 131 | // return query; // Return the query object 132 | // } 133 | 134 | /** 135 | * Normalize query string for oAuth 1.0a 136 | * Depends on the _parseParamsObject method 137 | * 138 | * @param {String} url 139 | * @param {Object} params 140 | * 141 | * @return {String} 142 | */ 143 | _normalizeQueryString( 144 | url: string, 145 | params: Partial> 146 | ): string { 147 | /** 148 | * Exit if url and params are not defined 149 | */ 150 | if (url.indexOf("?") === -1 && Object.keys(params).length === 0) { 151 | return url; 152 | } 153 | const query = new Url(url, true).query; // Parse the query string returned by the url 154 | 155 | // console.log("params:", params); 156 | const values = []; 157 | 158 | let queryString = ""; 159 | 160 | // Include params object into URL.searchParams. 161 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 162 | // const a = this._parseParamsObject(params, query); 163 | // console.log("A:", a); 164 | 165 | /** 166 | * Loop through the params object and push the key and value into the values array 167 | * Example: values = ['key1=value1', 'key2=value2'] 168 | */ 169 | for (const key in query) { 170 | values.push(key); 171 | } 172 | 173 | values.sort(); // Sort the values array 174 | 175 | for (const i in values) { 176 | /* 177 | * If the queryString is not empty, add an ampersand to the end of the string 178 | */ 179 | if (queryString.length) queryString += "&"; 180 | 181 | /** 182 | * Add the key and value to the queryString 183 | */ 184 | queryString += 185 | encodeURIComponent(values[i]) + 186 | "=" + 187 | encodeURIComponent(query[values[i]]); 188 | } 189 | /** 190 | * Replace %5B with [ and %5D with ] 191 | */ 192 | queryString = queryString.replace(/%5B/g, "[").replace(/%5D/g, "]"); 193 | 194 | /** 195 | * Return the url with the queryString 196 | */ 197 | const urlObject = url.split("?")[0] + "?" + queryString; 198 | 199 | return urlObject; 200 | } 201 | 202 | /** 203 | * Get URL 204 | * 205 | * @param {String} endpoint 206 | * @param {Object} params 207 | * 208 | * @return {String} 209 | */ 210 | _getUrl(endpoint: string, params: Partial>): string { 211 | const api = this._opt.wpAPIPrefix + "/"; // Add prefix to endpoint 212 | 213 | let url = 214 | this._opt.url.slice(-1) === "/" ? this._opt.url : this._opt.url + "/"; 215 | 216 | url = url + api + this._opt.version + "/" + endpoint; 217 | // Add id param to url 218 | if (params.id) { 219 | url = url + "/" + params.id; 220 | delete params.id; 221 | } 222 | 223 | // Add query params to url 224 | if (Object.keys(params).length !== 0) { 225 | for (const key in params) { 226 | url = url + "?" + key + "=" + params[key]; 227 | } 228 | } 229 | 230 | /** 231 | * If port is defined, add it to the url 232 | */ 233 | if (this._opt.port) { 234 | const hostname = new Url(url).hostname; 235 | url = url.replace(hostname, hostname + ":" + this._opt.port); 236 | } 237 | 238 | /** 239 | * If isHttps is true, normalize the query string 240 | */ 241 | // if (this._opt.isHttps) { 242 | // url = this._normalizeQueryString(url, params); 243 | // return url; 244 | // } 245 | return url; 246 | } 247 | 248 | /** 249 | * Create Hmac was deprecated fot this version at 16.11.2022 250 | * Get OAuth 1.0a since it is mandatory for WooCommerce REST API 251 | * You must use OAuth 1.0a "one-legged" authentication to ensure REST API credentials cannot be intercepted by an attacker. 252 | * Reference: https://woocommerce.github.io/woocommerce-rest-api-docs/#authentication-over-http 253 | * @return {Object} 254 | */ 255 | _getOAuth(): OAuth { 256 | const data = { 257 | consumer: { 258 | key: this._opt.consumerKey, 259 | secret: this._opt.consumerSecret, 260 | }, 261 | signature_method: "HMAC-SHA256", 262 | hash_function: (base: any, key: any) => { 263 | return crypto.createHmac("sha256", key).update(base).digest("base64"); 264 | }, 265 | }; 266 | 267 | return new OAuth(data); 268 | } 269 | 270 | /** 271 | * Axios request 272 | * Mount the options to send to axios and send the request. 273 | * 274 | * @param {String} method 275 | * @param {String} endpoint 276 | * @param {Object} data 277 | * @param {Object} params 278 | * 279 | * @return {Object} 280 | */ 281 | _request( 282 | method: WooRestApiMethod, 283 | endpoint: string, 284 | data?: Record, 285 | params: Record = {} 286 | ): Promise { 287 | const url = this._getUrl(endpoint, params); 288 | 289 | const header: RawAxiosRequestHeaders = { 290 | Accept: "application/json", 291 | }; 292 | // only set "User-Agent" in node environment 293 | // the checking method is identical to upstream axios 294 | if ( 295 | typeof process !== "undefined" && 296 | Object.prototype.toString.call(process) === "[object process]" 297 | ) { 298 | header["User-Agent"] = 299 | "WooCommerce REST API - TS Client/" + this._opt.classVersion; 300 | } 301 | 302 | let options: AxiosRequestConfig = { 303 | url, 304 | method, 305 | responseEncoding: this._opt.encoding, 306 | timeout: this._opt.timeout, 307 | responseType: "json", 308 | headers: { ...header }, 309 | params: {}, 310 | data: data ? JSON.stringify(data) : null, 311 | }; 312 | 313 | /** 314 | * If isHttps is false, add the query string to the params object 315 | */ 316 | if (this._opt.isHttps) { 317 | if (this._opt.queryStringAuth) { 318 | options.params = { 319 | consumer_key: this._opt.consumerKey, 320 | consumer_secret: this._opt.consumerSecret, 321 | }; 322 | } else { 323 | options.auth = { 324 | username: this._opt.consumerKey, 325 | password: this._opt.consumerSecret, 326 | }; 327 | } 328 | 329 | options.params = { ...options.params, ...params }; 330 | } else { 331 | options.params = this._getOAuth().authorize({ 332 | url, 333 | method, 334 | }); 335 | } 336 | 337 | if (options.data) { 338 | options.headers = { 339 | ...header, 340 | "Content-Type": `application/json; charset=${this._opt.encoding}`, 341 | }; 342 | } 343 | 344 | // Allow set and override Axios options. 345 | options = { ...options, ...this._opt.axiosConfig }; 346 | 347 | return axios(options); 348 | } 349 | 350 | /** 351 | * GET requests 352 | * 353 | * @param {String} endpoint 354 | * @param {Object} params 355 | * 356 | * @return {Object} 357 | */ 358 | get( 359 | endpoint: T, 360 | params?: Partial 361 | ): Promise { 362 | return this._request("GET", endpoint, undefined, params); 363 | } 364 | 365 | /** 366 | * POST requests 367 | * 368 | * @param {String} endpoint 369 | * @param {Object} data 370 | * @param {Object} params 371 | * 372 | * @return {Object} 373 | */ 374 | post( 375 | endpoint: T, 376 | data: Record, 377 | params?: Partial 378 | ): Promise { 379 | return this._request("POST", endpoint, data, params); 380 | } 381 | 382 | /** 383 | * PUT requests 384 | * 385 | * @param {String} endpoint 386 | * @param {Object} data 387 | * @param {Object} params 388 | * 389 | * @return {Object} 390 | */ 391 | put( 392 | endpoint: T, 393 | data: Record, 394 | params?: Partial 395 | ): Promise { 396 | return this._request("PUT", endpoint, data, params); 397 | } 398 | 399 | /** 400 | * DELETE requests 401 | * 402 | * @param {String} endpoint 403 | * @param {Object} params 404 | * @param {Object} params 405 | * 406 | * @return {Object} 407 | */ 408 | delete( 409 | endpoint: T, 410 | data: Pick, 411 | params: Pick 412 | ): Promise { 413 | return this._request("DELETE", endpoint, data, params); 414 | } 415 | 416 | /** 417 | * OPTIONS requests 418 | * 419 | * @param {String} endpoint 420 | * @param {Object} params 421 | * 422 | * @return {Object} 423 | */ 424 | options( 425 | endpoint: T, 426 | params?: Partial 427 | ): Promise { 428 | return this._request("OPTIONS", endpoint, {}, params); 429 | } 430 | } 431 | 432 | /** 433 | * Options Exception. 434 | */ 435 | export class OptionsException { 436 | public name: "Options Error"; 437 | public message: string; 438 | /** 439 | * Constructor. 440 | * 441 | * @param {String} message 442 | */ 443 | constructor(message: string) { 444 | this.name = "Options Error"; 445 | this.message = message; 446 | } 447 | } 448 | -------------------------------------------------------------------------------- /src/test/coupons.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "id": 720, 3 | "code": "free shipping", 4 | "amount": "0.00", 5 | "status": "publish", 6 | "date_created": "2017-03-21T15:25:02", 7 | "date_created_gmt": "2017-03-21T18:25:02", 8 | "date_modified": "2017-03-21T15:25:02", 9 | "date_modified_gmt": "2017-03-21T18:25:02", 10 | "discount_type": "fixed_cart", 11 | "description": "", 12 | "date_expires": "", 13 | "date_expires_gmt": "", 14 | "usage_count": 0, 15 | "individual_use": true, 16 | "product_ids": [], 17 | "excluded_product_ids": [], 18 | "usage_limit": 0, 19 | "usage_limit_per_user": 0, 20 | "limit_usage_to_x_items": 0, 21 | "free_shipping": true, 22 | "product_categories": [], 23 | "excluded_product_categories": [], 24 | "exclude_sale_items": false, 25 | "minimum_amount": "0.00", 26 | "maximum_amount": "0.00", 27 | "email_restrictions": [], 28 | "used_by": [], 29 | "meta_data": [ 30 | { 31 | "id": 721, 32 | "key": "discount_type", 33 | "value": "fixed_cart" 34 | }, 35 | { 36 | "id": 722, 37 | "key": "coupon_amount", 38 | "value": "0" 39 | } 40 | ], 41 | "_links": { 42 | "self": [ 43 | { 44 | "href": "https://example.com/wp-json/wc/v3/coupons/720" 45 | } 46 | ], 47 | "collection": [ 48 | { 49 | "href": "https://example.com/wp-json/wc/v3/coupons" 50 | } 51 | ] 52 | } 53 | }] -------------------------------------------------------------------------------- /src/test/customersJson-response.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "id": 25, 3 | "date_created": "2017-03-21T16:09:28", 4 | "date_created_gmt": "2017-03-21T19:09:28", 5 | "date_modified": "2017-03-21T16:09:30", 6 | "date_modified_gmt": "2017-03-21T19:09:30", 7 | "email": "john.doe@example.com", 8 | "first_name": "John", 9 | "last_name": "Doe", 10 | "role": "customer", 11 | "username": "john.doe", 12 | "billing": { 13 | "first_name": "John", 14 | "last_name": "Doe", 15 | "company": "", 16 | "address_1": "969 Market", 17 | "address_2": "", 18 | "city": "San Francisco", 19 | "state": "CA", 20 | "postcode": "94103", 21 | "country": "US", 22 | "email": "john.doe@example.com", 23 | "phone": "(555) 555-5555" 24 | }, 25 | "shipping": { 26 | "first_name": "John", 27 | "last_name": "Doe", 28 | "company": "", 29 | "address_1": "969 Market", 30 | "address_2": "", 31 | "city": "San Francisco", 32 | "state": "CA", 33 | "postcode": "94103", 34 | "country": "US" 35 | }, 36 | "is_paying_customer": false, 37 | "avatar_url": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96", 38 | "meta_data": [], 39 | "_links": { 40 | "self": [ 41 | { 42 | "href": "https://example.com/wp-json/wc/v3/customers/25" 43 | } 44 | ], 45 | "collection": [ 46 | { 47 | "href": "https://example.com/wp-json/wc/v3/customers" 48 | } 49 | ] 50 | } 51 | }] -------------------------------------------------------------------------------- /src/test/customersJson.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "id": 303, 3 | "date_created": "2022-04-09T15:29:04", 4 | "date_created_gmt": "2022-04-09T18:29:04", 5 | "date_modified": "2022-04-09T15:29:04", 6 | "date_modified_gmt": "2022-04-09T18:29:04", 7 | "email": "abreusfelipe@gmail.com", 8 | "first_name": "", 9 | "last_name": "", 10 | "role": "customer", 11 | "username": "abreusfelipe", 12 | "billing": { 13 | "first_name": "", 14 | "last_name": "", 15 | "company": "", 16 | "address_1": "", 17 | "address_2": "", 18 | "city": "", 19 | "postcode": "", 20 | "country": "", 21 | "state": "", 22 | "email": "", 23 | "phone": "", 24 | "number": "", 25 | "neighborhood": "", 26 | "persontype": "F", 27 | "cpf": "", 28 | "rg": "", 29 | "cnpj": "", 30 | "ie": "", 31 | "birthdate": "", 32 | "sex": "", 33 | "cellphone": "" 34 | }, 35 | "shipping": { 36 | "first_name": "", 37 | "last_name": "", 38 | "company": "", 39 | "address_1": "", 40 | "address_2": "", 41 | "city": "", 42 | "postcode": "", 43 | "country": "", 44 | "state": "", 45 | "phone": "", 46 | "number": "", 47 | "neighborhood": "" 48 | }, 49 | "is_paying_customer": false, 50 | "avatar_url": "https://secure.gravatar.com/avatar/0a3114732ffd608c96a3aed0bc99c391?s=96&d=mm&r=g", 51 | "meta_data": [ 52 | { 53 | "id": 10744, 54 | "key": "_yoast_wpseo_profile_updated", 55 | "value": "1649528944" 56 | }, 57 | { "id": 10747, "key": "wc_last_active", "value": "1649462400" } 58 | ], 59 | "_links": { "self": [ ["Object"] ], "collection": [ ["Object"] ] } 60 | }] -------------------------------------------------------------------------------- /src/test/example_data_orders.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 36875, 4 | "parent_id": 0, 5 | "status": "completed", 6 | "currency": "BRL", 7 | "version": "6.6.0", 8 | "prices_include_tax": true, 9 | "date_created": "2022-07-02T19:10:21", 10 | "date_modified": "2022-07-03T09:49:19", 11 | "discount_total": "0.00", 12 | "discount_tax": "0.00", 13 | "shipping_total": "15.00", 14 | "shipping_tax": "0.00", 15 | "cart_tax": "0.00", 16 | "total": "164.90", 17 | "total_tax": "0.00", 18 | "customer_id": 0, 19 | "order_key": "wc_order_CsufiGQ7amiLL", 20 | "billing": { 21 | "first_name": "Mariana", 22 | "last_name": "Barreto", 23 | "company": "", 24 | "address_1": "Rua Nove de Julho", 25 | "address_2": "", 26 | "city": "São José", 27 | "state": "SC", 28 | "postcode": "88111-380", 29 | "country": "BR", 30 | "email": "maris.barreto19@gmail.com", 31 | "phone": "85996859001", 32 | "payment": "", 33 | "billing_cpf": "061.828.689-61", 34 | "billing_cnpj": "", 35 | "billing_company": "", 36 | "space": "", 37 | "delivery": "", 38 | "billing_recipient": "Vanessa Barreto Bossle", 39 | "billing_recipient_phone": "85996859001", 40 | "billing_number": "611", 41 | "billing_complementary": "Casa Branca em frente ao salão de Beleza", 42 | "billing_neighborhood": "Bairro Ipiranga", 43 | "billing_msg": "Nessa, que seu dia seja repleto de amor.\r\n\r\nDaqueles que te amam e te querem bem.\r\n\r\nCom carinho,\r\nRenato, Josiani, Mana, Mari, Manu e Miguelzinho", 44 | "space_2": "", 45 | "number": "611", 46 | "neighborhood": "Bairro Ipiranga", 47 | "persontype": "F", 48 | "cpf": "06182868961", 49 | "rg": "", 50 | "cnpj": "", 51 | "ie": "", 52 | "birthdate": "", 53 | "sex": "", 54 | "cellphone": "" 55 | }, 56 | "shipping": { 57 | "first_name": "", 58 | "last_name": "", 59 | "company": "", 60 | "address_1": "", 61 | "address_2": "", 62 | "city": "", 63 | "state": "", 64 | "postcode": "", 65 | "country": "", 66 | "phone": "", 67 | "number": "", 68 | "neighborhood": "" 69 | }, 70 | "payment_method": "bacs", 71 | "payment_method_title": "PIX ou Transferência ", 72 | "transaction_id": "", 73 | "customer_ip_address": "189.4.77.0", 74 | "customer_user_agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Mobile/15E148 Safari/604.1", 75 | "created_via": "checkout", 76 | "customer_note": "", 77 | "date_completed": "2022-07-03T09:49:19", 78 | "date_paid": "2022-07-03T09:49:19", 79 | "cart_hash": "a7fee777c8ff0919b8e9cbf0d90849e8", 80 | "number": "36875", 81 | "meta_data": [ 82 | { 83 | "id": 996295, 84 | "key": "_billing_persontype", 85 | "value": "1" 86 | }, 87 | { 88 | "id": 996296, 89 | "key": "_billing_cpf", 90 | "value": "061.828.689-61" 91 | }, 92 | { 93 | "id": 996297, 94 | "key": "_billing_cnpj", 95 | "value": "" 96 | }, 97 | { 98 | "id": 996298, 99 | "key": "_billing_recipient", 100 | "value": "Vanessa Barreto Bossle" 101 | }, 102 | { 103 | "id": 996299, 104 | "key": "_billing_recipient_phone", 105 | "value": "48998051955" 106 | }, 107 | { 108 | "id": 996300, 109 | "key": "_billing_number", 110 | "value": "611" 111 | }, 112 | { 113 | "id": 996301, 114 | "key": "_billing_complementary", 115 | "value": "Casa Branca em frente ao salão de Beleza" 116 | }, 117 | { 118 | "id": 996302, 119 | "key": "_billing_neighborhood", 120 | "value": "Bairro Ipiranga" 121 | }, 122 | { 123 | "id": 996303, 124 | "key": "_billing_msg", 125 | "value": "Nessa, que seu dia seja repleto de amor.\n\nDaqueles que te amam e te querem bem.\n\nCom carinho,\nRenato, Josiani, Mana, Mari, Manu e Miguelzinho" 126 | }, 127 | { 128 | "id": 996304, 129 | "key": "is_vat_exempt", 130 | "value": "no" 131 | }, 132 | { 133 | "id": 996305, 134 | "key": "_thwcfe_ship_to_billing", 135 | "value": "1" 136 | }, 137 | { 138 | "id": 996306, 139 | "key": "_thwcfe_disabled_fields", 140 | "value": "time" 141 | }, 142 | { 143 | "id": 996307, 144 | "key": "billing_cpf", 145 | "value": "061.828.689-61" 146 | }, 147 | { 148 | "id": 996308, 149 | "key": "billing_recipient", 150 | "value": "Vanessa Barreto Bossle" 151 | }, 152 | { 153 | "id": 996309, 154 | "key": "billing_recipient_phone", 155 | "value": "48998051955" 156 | }, 157 | { 158 | "id": 996310, 159 | "key": "billing_number", 160 | "value": "611" 161 | }, 162 | { 163 | "id": 996311, 164 | "key": "billing_complementary", 165 | "value": "Casa Branca em frente ao salão de Beleza" 166 | }, 167 | { 168 | "id": 996312, 169 | "key": "billing_neighborhood", 170 | "value": "Bairro Ipiranga" 171 | }, 172 | { 173 | "id": 996313, 174 | "key": "billing_msg", 175 | "value": "Nessa, que seu dia seja repleto de amor.\r\n\r\nDaqueles que te amam e te querem bem.\r\n\r\nCom carinho,\r\nRenato, Josiani, Mana, Mari, Manu e Miguelzinho" 176 | }, 177 | { 178 | "id": 996314, 179 | "key": "date", 180 | "value": "03/07/2022" 181 | }, 182 | { 183 | "id": 996315, 184 | "key": "time_celebration", 185 | "value": "Período da Manhã" 186 | }, 187 | { 188 | "id": 996316, 189 | "key": "_wc_facebook_for_woocommerce_order_placed", 190 | "value": "yes" 191 | }, 192 | { 193 | "id": 996320, 194 | "key": "_new_order_email_sent", 195 | "value": "true" 196 | }, 197 | { 198 | "id": 996321, 199 | "key": "_wc_facebook_for_woocommerce_purchase_tracked", 200 | "value": "yes" 201 | }, 202 | { 203 | "id": 996328, 204 | "key": "_shipping_number", 205 | "value": "" 206 | }, 207 | { 208 | "id": 996329, 209 | "key": "_shipping_neighborhood", 210 | "value": "" 211 | } 212 | ], 213 | "line_items": [ 214 | { 215 | "id": 18074, 216 | "name": "Doce Encanto", 217 | "product_id": 2157, 218 | "variation_id": 0, 219 | "quantity": 1, 220 | "tax_class": "", 221 | "subtotal": "149.90", 222 | "subtotal_tax": "0.00", 223 | "total": "149.90", 224 | "total_tax": "0.00", 225 | "taxes": [], 226 | "meta_data": [], 227 | "sku": "", 228 | "price": 149.9, 229 | "image": { 230 | "id": "807", 231 | "src": "https://innovacestas.com.br/wp-content/uploads/2020/05/Doce-Encanto.jpg" 232 | }, 233 | "parent_name": null 234 | } 235 | ], 236 | "tax_lines": [], 237 | "shipping_lines": [ 238 | { 239 | "id": 18075, 240 | "method_title": "Delivery", 241 | "method_id": "flat_rate", 242 | "instance_id": "9", 243 | "total": "15.00", 244 | "total_tax": "0.00", 245 | "taxes": [], 246 | "meta_data": [ 247 | { 248 | "id": 148342, 249 | "key": "Itens", 250 | "value": "Doce Encanto × 1", 251 | "display_key": "Itens", 252 | "display_value": "Doce Encanto × 1" 253 | } 254 | ] 255 | } 256 | ], 257 | "fee_lines": [], 258 | "coupon_lines": [], 259 | "refunds": [], 260 | "payment_url": "https://innovacestas.com.br/finalizar-compra/order-pay/36875/?pay_for_order=true&key=wc_order_CsufiGQ7amiLL", 261 | "is_editable": false, 262 | "needs_payment": false, 263 | "needs_processing": true, 264 | "date_created_gmt": "2022-07-02T22:10:21", 265 | "date_modified_gmt": "2022-07-03T12:49:19", 266 | "date_completed_gmt": "2022-07-03T12:49:19", 267 | "date_paid_gmt": "2022-07-03T12:49:19", 268 | "schedule": { 269 | "date": "03/07/2022", 270 | "time": "", 271 | "delivery_alert": "", 272 | "time_celebration": "Período da Manhã", 273 | "space_3": "" 274 | }, 275 | "currency_symbol": "R$", 276 | "_links": { 277 | "self": [ 278 | { 279 | "href": "https://innovacestas.com.br/wp-json/wc/v3/orders/36875" 280 | } 281 | ], 282 | "collection": [ 283 | { 284 | "href": "https://innovacestas.com.br/wp-json/wc/v3/orders" 285 | } 286 | ] 287 | } 288 | }, 289 | { 290 | "id": 36874, 291 | "parent_id": 0, 292 | "status": "completed", 293 | "currency": "BRL", 294 | "version": "6.6.0", 295 | "prices_include_tax": true, 296 | "date_created": "2022-07-02T17:55:52", 297 | "date_modified": "2022-07-03T10:05:31", 298 | "discount_total": "0.00", 299 | "discount_tax": "0.00", 300 | "shipping_total": "20.00", 301 | "shipping_tax": "0.00", 302 | "cart_tax": "0.00", 303 | "total": "309.90", 304 | "total_tax": "0.00", 305 | "customer_id": 0, 306 | "order_key": "wc_order_PYC1jtOGNjsb7", 307 | "billing": { 308 | "first_name": "Nayara", 309 | "last_name": "Gonçalves", 310 | "company": "", 311 | "address_1": "Rua José Graciliano da Silva", 312 | "address_2": "", 313 | "city": "São José", 314 | "state": "SC", 315 | "postcode": "88115-239", 316 | "country": "BR", 317 | "email": "nayarapg@hotmail.com", 318 | "phone": "85996859001", 319 | "payment": "", 320 | "billing_cpf": "035.916.769-18", 321 | "billing_cnpj": "", 322 | "billing_company": "", 323 | "space": "", 324 | "delivery": "", 325 | "billing_recipient": "Scheila Pereira", 326 | "billing_recipient_phone": "85996859001", 327 | "billing_number": "170", 328 | "billing_complementary": "Bloco 4 apto 104", 329 | "billing_neighborhood": "Serraria", 330 | "billing_msg": "Parabéns para a minha amiga irmã que está quarentando ainda mais linda!\r\nTe amo e desejo apenas as melhores coisas desse mundão!!\r\nBeijos\r\nNay", 331 | "space_2": "", 332 | "number": "170", 333 | "neighborhood": "Serraria", 334 | "persontype": "F", 335 | "cpf": "03591676918", 336 | "rg": "", 337 | "cnpj": "", 338 | "ie": "", 339 | "birthdate": "", 340 | "sex": "", 341 | "cellphone": "" 342 | }, 343 | "shipping": { 344 | "first_name": "", 345 | "last_name": "", 346 | "company": "", 347 | "address_1": "", 348 | "address_2": "", 349 | "city": "", 350 | "state": "", 351 | "postcode": "", 352 | "country": "", 353 | "phone": "", 354 | "number": "", 355 | "neighborhood": "" 356 | }, 357 | "payment_method": "bacs", 358 | "payment_method_title": "PIX ou Transferência ", 359 | "transaction_id": "", 360 | "customer_ip_address": "179.232.120.95", 361 | "customer_user_agent": "Mozilla/5.0 (Linux; Android 11; moto g(10)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36", 362 | "created_via": "checkout", 363 | "customer_note": "", 364 | "date_completed": "2022-07-03T10:05:31", 365 | "date_paid": "2022-07-03T10:05:31", 366 | "cart_hash": "b24cdbd254b0bc0202d60224586b50bf", 367 | "number": "36874", 368 | "meta_data": [ 369 | { 370 | "id": 996240, 371 | "key": "_billing_persontype", 372 | "value": "1" 373 | }, 374 | { 375 | "id": 996241, 376 | "key": "_billing_cpf", 377 | "value": "035.916.769-18" 378 | }, 379 | { 380 | "id": 996242, 381 | "key": "_billing_cnpj", 382 | "value": "" 383 | }, 384 | { 385 | "id": 996243, 386 | "key": "_billing_recipient", 387 | "value": "Scheila Pereira" 388 | }, 389 | { 390 | "id": 996244, 391 | "key": "_billing_recipient_phone", 392 | "value": "48 99830-6708" 393 | }, 394 | { 395 | "id": 996245, 396 | "key": "_billing_number", 397 | "value": "170" 398 | }, 399 | { 400 | "id": 996246, 401 | "key": "_billing_complementary", 402 | "value": "Bloco 4 apto 104" 403 | }, 404 | { 405 | "id": 996247, 406 | "key": "_billing_neighborhood", 407 | "value": "Serraria" 408 | }, 409 | { 410 | "id": 996248, 411 | "key": "_billing_msg", 412 | "value": "Parabéns para a minha amiga irmã que está quarentando ainda mais linda!\nTe amo e desejo apenas as melhores coisas desse mundão!!\nBeijos\nNay" 413 | }, 414 | { 415 | "id": 996249, 416 | "key": "is_vat_exempt", 417 | "value": "no" 418 | }, 419 | { 420 | "id": 996250, 421 | "key": "_thwcfe_ship_to_billing", 422 | "value": "1" 423 | }, 424 | { 425 | "id": 996251, 426 | "key": "_thwcfe_disabled_fields", 427 | "value": "time" 428 | }, 429 | { 430 | "id": 996252, 431 | "key": "billing_cpf", 432 | "value": "035.916.769-18" 433 | }, 434 | { 435 | "id": 996253, 436 | "key": "billing_recipient", 437 | "value": "Scheila Pereira" 438 | }, 439 | { 440 | "id": 996254, 441 | "key": "billing_recipient_phone", 442 | "value": "48 99830-6708" 443 | }, 444 | { 445 | "id": 996255, 446 | "key": "billing_number", 447 | "value": "170" 448 | }, 449 | { 450 | "id": 996256, 451 | "key": "billing_complementary", 452 | "value": "Bloco 4 apto 104" 453 | }, 454 | { 455 | "id": 996257, 456 | "key": "billing_neighborhood", 457 | "value": "Serraria" 458 | }, 459 | { 460 | "id": 996258, 461 | "key": "billing_msg", 462 | "value": "Parabéns para a minha amiga irmã que está quarentando ainda mais linda!\r\nTe amo e desejo apenas as melhores coisas desse mundão!!\r\nBeijos\r\nNay" 463 | }, 464 | { 465 | "id": 996259, 466 | "key": "date", 467 | "value": "03/07/2022" 468 | }, 469 | { 470 | "id": 996260, 471 | "key": "time_celebration", 472 | "value": "Período da Manhã" 473 | }, 474 | { 475 | "id": 996261, 476 | "key": "_wc_facebook_for_woocommerce_order_placed", 477 | "value": "yes" 478 | }, 479 | { 480 | "id": 996265, 481 | "key": "_new_order_email_sent", 482 | "value": "true" 483 | }, 484 | { 485 | "id": 996266, 486 | "key": "_wc_facebook_for_woocommerce_purchase_tracked", 487 | "value": "yes" 488 | }, 489 | { 490 | "id": 996324, 491 | "key": "_shipping_number", 492 | "value": "" 493 | }, 494 | { 495 | "id": 996325, 496 | "key": "_shipping_neighborhood", 497 | "value": "" 498 | } 499 | ], 500 | "line_items": [ 501 | { 502 | "id": 18072, 503 | "name": "Baú Rosas Carinho Chandon", 504 | "product_id": 2102, 505 | "variation_id": 0, 506 | "quantity": 1, 507 | "tax_class": "", 508 | "subtotal": "289.90", 509 | "subtotal_tax": "0.00", 510 | "total": "289.90", 511 | "total_tax": "0.00", 512 | "taxes": [], 513 | "meta_data": [], 514 | "sku": "", 515 | "price": 289.9, 516 | "image": { 517 | "id": "688", 518 | "src": "https://innovacestas.com.br/wp-content/uploads/2020/05/Baú-Rosas-Carinho-Chandon-1.jpg" 519 | }, 520 | "parent_name": null 521 | } 522 | ], 523 | "tax_lines": [], 524 | "shipping_lines": [ 525 | { 526 | "id": 18073, 527 | "method_title": "Delivery", 528 | "method_id": "flat_rate", 529 | "instance_id": "11", 530 | "total": "20.00", 531 | "total_tax": "0.00", 532 | "taxes": [], 533 | "meta_data": [ 534 | { 535 | "id": 148327, 536 | "key": "Itens", 537 | "value": "Baú Rosas Carinho Chandon × 1", 538 | "display_key": "Itens", 539 | "display_value": "Baú Rosas Carinho Chandon × 1" 540 | } 541 | ] 542 | } 543 | ], 544 | "fee_lines": [], 545 | "coupon_lines": [], 546 | "refunds": [], 547 | "payment_url": "https://innovacestas.com.br/finalizar-compra/order-pay/36874/?pay_for_order=true&key=wc_order_PYC1jtOGNjsb7", 548 | "is_editable": false, 549 | "needs_payment": false, 550 | "needs_processing": true, 551 | "date_created_gmt": "2022-07-02T20:55:52", 552 | "date_modified_gmt": "2022-07-03T13:05:31", 553 | "date_completed_gmt": "2022-07-03T13:05:31", 554 | "date_paid_gmt": "2022-07-03T13:05:31", 555 | "schedule": { 556 | "date": "03/07/2022", 557 | "time": "", 558 | "delivery_alert": "", 559 | "time_celebration": "Período da Manhã", 560 | "space_3": "" 561 | }, 562 | "currency_symbol": "R$", 563 | "_links": { 564 | "self": [ 565 | { 566 | "href": "https://innovacestas.com.br/wp-json/wc/v3/orders/36874" 567 | } 568 | ], 569 | "collection": [ 570 | { 571 | "href": "https://innovacestas.com.br/wp-json/wc/v3/orders" 572 | } 573 | ] 574 | } 575 | }, 576 | { 577 | "id": 36873, 578 | "parent_id": 0, 579 | "status": "completed", 580 | "currency": "BRL", 581 | "version": "6.6.0", 582 | "prices_include_tax": true, 583 | "date_created": "2022-07-02T13:30:57", 584 | "date_modified": "2022-07-03T08:48:14", 585 | "discount_total": "0.00", 586 | "discount_tax": "0.00", 587 | "shipping_total": "32.00", 588 | "shipping_tax": "0.00", 589 | "cart_tax": "0.00", 590 | "total": "251.90", 591 | "total_tax": "0.00", 592 | "customer_id": 0, 593 | "order_key": "wc_order_xyhq7G0pGlaSc", 594 | "billing": { 595 | "first_name": "Elis", 596 | "last_name": "Capeletti", 597 | "company": "", 598 | "address_1": "Rua Dario João de Souza", 599 | "address_2": "", 600 | "city": "florianopolis", 601 | "state": "SC", 602 | "postcode": "88053-760", 603 | "country": "BR", 604 | "email": "eliscapeletti@hotmail.com", 605 | "phone": "85996859001", 606 | "payment": "", 607 | "billing_cpf": "921.232.520-34", 608 | "billing_cnpj": "", 609 | "billing_company": "", 610 | "space": "", 611 | "delivery": "", 612 | "billing_recipient": "Marcia Capeletti", 613 | "billing_recipient_phone": "85996859001", 614 | "billing_number": "61", 615 | "billing_complementary": "apto. 210B", 616 | "billing_neighborhood": "Jurere", 617 | "billing_msg": "Mana, tenha um dia muito doce, te amamos! Feliz aniver!\r\nElis e Letícia", 618 | "space_2": "", 619 | "number": "61", 620 | "neighborhood": "Jurere", 621 | "persontype": "F", 622 | "cpf": "92123252034", 623 | "rg": "", 624 | "cnpj": "", 625 | "ie": "", 626 | "birthdate": "", 627 | "sex": "", 628 | "cellphone": "" 629 | }, 630 | "shipping": { 631 | "first_name": "", 632 | "last_name": "", 633 | "company": "", 634 | "address_1": "", 635 | "address_2": "", 636 | "city": "", 637 | "state": "", 638 | "postcode": "", 639 | "country": "", 640 | "phone": "", 641 | "number": "", 642 | "neighborhood": "" 643 | }, 644 | "payment_method": "bacs", 645 | "payment_method_title": "PIX ou Transferência ", 646 | "transaction_id": "", 647 | "customer_ip_address": "189.6.245.142", 648 | "customer_user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.66 Safari/537.36 Edg/103.0.1264.44", 649 | "created_via": "checkout", 650 | "customer_note": "", 651 | "date_completed": "2022-07-03T08:48:14", 652 | "date_paid": "2022-07-03T08:48:14", 653 | "cart_hash": "e472b17fe31d78eaf5191713b4eda912", 654 | "number": "36873", 655 | "meta_data": [ 656 | { 657 | "id": 996159, 658 | "key": "_billing_persontype", 659 | "value": "1" 660 | }, 661 | { 662 | "id": 996160, 663 | "key": "_billing_cpf", 664 | "value": "921.232.520-34" 665 | }, 666 | { 667 | "id": 996161, 668 | "key": "_billing_cnpj", 669 | "value": "" 670 | }, 671 | { 672 | "id": 996162, 673 | "key": "_billing_recipient", 674 | "value": "Marcia Capeletti" 675 | }, 676 | { 677 | "id": 996163, 678 | "key": "_billing_recipient_phone", 679 | "value": "48991639003" 680 | }, 681 | { 682 | "id": 996164, 683 | "key": "_billing_number", 684 | "value": "61" 685 | }, 686 | { 687 | "id": 996165, 688 | "key": "_billing_complementary", 689 | "value": "apto. 210B" 690 | }, 691 | { 692 | "id": 996166, 693 | "key": "_billing_neighborhood", 694 | "value": "Jurere" 695 | }, 696 | { 697 | "id": 996167, 698 | "key": "_billing_msg", 699 | "value": "Mana, tenha um dia muito doce, te amamos! Feliz aniver!\nElis e Letícia" 700 | }, 701 | { 702 | "id": 996168, 703 | "key": "is_vat_exempt", 704 | "value": "no" 705 | }, 706 | { 707 | "id": 996169, 708 | "key": "_thwcfe_ship_to_billing", 709 | "value": "1" 710 | }, 711 | { 712 | "id": 996170, 713 | "key": "_thwcfe_disabled_fields", 714 | "value": "time" 715 | }, 716 | { 717 | "id": 996171, 718 | "key": "billing_cpf", 719 | "value": "921.232.520-34" 720 | }, 721 | { 722 | "id": 996172, 723 | "key": "billing_recipient", 724 | "value": "Marcia Capeletti" 725 | }, 726 | { 727 | "id": 996173, 728 | "key": "billing_recipient_phone", 729 | "value": "48991639003" 730 | }, 731 | { 732 | "id": 996174, 733 | "key": "billing_number", 734 | "value": "61" 735 | }, 736 | { 737 | "id": 996175, 738 | "key": "billing_complementary", 739 | "value": "apto. 210B" 740 | }, 741 | { 742 | "id": 996176, 743 | "key": "billing_neighborhood", 744 | "value": "Jurere" 745 | }, 746 | { 747 | "id": 996177, 748 | "key": "billing_msg", 749 | "value": "Mana, tenha um dia muito doce, te amamos! Feliz aniver!\r\nElis e Letícia" 750 | }, 751 | { 752 | "id": 996178, 753 | "key": "date", 754 | "value": "03/07/2022" 755 | }, 756 | { 757 | "id": 996179, 758 | "key": "time_celebration", 759 | "value": "Período da Manhã" 760 | }, 761 | { 762 | "id": 996180, 763 | "key": "_wc_facebook_for_woocommerce_order_placed", 764 | "value": "yes" 765 | }, 766 | { 767 | "id": 996184, 768 | "key": "_new_order_email_sent", 769 | "value": "true" 770 | }, 771 | { 772 | "id": 996185, 773 | "key": "_wc_facebook_for_woocommerce_purchase_tracked", 774 | "value": "yes" 775 | }, 776 | { 777 | "id": 996192, 778 | "key": "_shipping_number", 779 | "value": "" 780 | }, 781 | { 782 | "id": 996193, 783 | "key": "_shipping_neighborhood", 784 | "value": "" 785 | } 786 | ], 787 | "line_items": [ 788 | { 789 | "id": 18070, 790 | "name": "Caixa Surpresa de Aniversário", 791 | "product_id": 2025, 792 | "variation_id": 0, 793 | "quantity": 1, 794 | "tax_class": "", 795 | "subtotal": "219.90", 796 | "subtotal_tax": "0.00", 797 | "total": "219.90", 798 | "total_tax": "0.00", 799 | "taxes": [], 800 | "meta_data": [], 801 | "sku": "", 802 | "price": 219.9, 803 | "image": { 804 | "id": "23189", 805 | "src": "https://innovacestas.com.br/wp-content/uploads/2020/06/pinnkk.jpg" 806 | }, 807 | "parent_name": null 808 | } 809 | ], 810 | "tax_lines": [], 811 | "shipping_lines": [ 812 | { 813 | "id": 18071, 814 | "method_title": "Uber Flash", 815 | "method_id": "flat_rate", 816 | "instance_id": "16", 817 | "total": "32.00", 818 | "total_tax": "0.00", 819 | "taxes": [], 820 | "meta_data": [ 821 | { 822 | "id": 148312, 823 | "key": "Itens", 824 | "value": "Caixa Surpresa de Aniversário × 1", 825 | "display_key": "Itens", 826 | "display_value": "Caixa Surpresa de Aniversário × 1" 827 | } 828 | ] 829 | } 830 | ], 831 | "fee_lines": [], 832 | "coupon_lines": [], 833 | "refunds": [], 834 | "payment_url": "https://innovacestas.com.br/finalizar-compra/order-pay/36873/?pay_for_order=true&key=wc_order_xyhq7G0pGlaSc", 835 | "is_editable": false, 836 | "needs_payment": false, 837 | "needs_processing": true, 838 | "date_created_gmt": "2022-07-02T16:30:57", 839 | "date_modified_gmt": "2022-07-03T11:48:14", 840 | "date_completed_gmt": "2022-07-03T11:48:14", 841 | "date_paid_gmt": "2022-07-03T11:48:14", 842 | "schedule": { 843 | "date": "03/07/2022", 844 | "time": "", 845 | "delivery_alert": "", 846 | "time_celebration": "Período da Manhã", 847 | "space_3": "" 848 | }, 849 | "currency_symbol": "R$", 850 | "_links": { 851 | "self": [ 852 | { 853 | "href": "https://innovacestas.com.br/wp-json/wc/v3/orders/36873" 854 | } 855 | ], 856 | "collection": [ 857 | { 858 | "href": "https://innovacestas.com.br/wp-json/wc/v3/orders" 859 | } 860 | ] 861 | } 862 | } 863 | ] -------------------------------------------------------------------------------- /src/test/ordersJson.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 66621, 4 | "parent_id": 0, 5 | "status": "on-hold", 6 | "currency": "BRL", 7 | "version": "6.0.1", 8 | "prices_include_tax": false, 9 | "date_created": "2022-05-01T15:17:30", 10 | "date_modified": "2022-05-01T15:17:30", 11 | "discount_total": "0.00", 12 | "discount_tax": "0.00", 13 | "shipping_total": "0.00", 14 | "shipping_tax": "0.00", 15 | "cart_tax": "0.00", 16 | "total": "374.80", 17 | "total_tax": "0.00", 18 | "customer_id": 1, 19 | "order_key": "wc_order_T11dai6ISTCS0", 20 | "billing": { 21 | "first_name": "Teste", 22 | "last_name": "Teste", 23 | "company": "Teste", 24 | "address_1": "VITOR KONDER", 25 | "address_2": "", 26 | "city": "florianópolis", 27 | "state": "SC", 28 | "postcode": "88015-400", 29 | "country": "BR", 30 | "email": "jardel.godinho@gmail.com", 31 | "phone": "(85) 99685-9001", 32 | "payment": "", 33 | "billing_cpf": "005.762.739-88", 34 | "billing_cnpj": "18.270.630/0001-41", 35 | "billing_company": "Teste", 36 | "space": "", 37 | "delivery": "", 38 | "billing_recipient": "teste", 39 | "billing_recipient_phone": "85996859001", 40 | "billing_number": "302", 41 | "billing_complementary": "APTO 704", 42 | "billing_neighborhood": "CENTRO", 43 | "billing_msg": "testes", 44 | "space_2": "", 45 | "number": "302", 46 | "neighborhood": "CENTRO", 47 | "persontype": "J", 48 | "cpf": "00576273988", 49 | "rg": "", 50 | "cnpj": "18270630000141", 51 | "ie": "", 52 | "birthdate": "", 53 | "sex": "", 54 | "cellphone": "" 55 | }, 56 | "shipping": { 57 | "first_name": "", 58 | "last_name": "", 59 | "company": "", 60 | "address_1": "", 61 | "address_2": "", 62 | "city": "", 63 | "state": "", 64 | "postcode": "", 65 | "country": "", 66 | "phone": "", 67 | "number": "", 68 | "neighborhood": "" 69 | }, 70 | "payment_method": "bacs", 71 | "payment_method_title": "PIX", 72 | "transaction_id": "", 73 | "customer_ip_address": "127.0.0.1", 74 | "customer_user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36", 75 | "created_via": "checkout", 76 | "customer_note": "", 77 | "date_completed": null, 78 | "date_paid": null, 79 | "cart_hash": "d503384c6706e15cc7ce3abb181c8df9", 80 | "number": "66621", 81 | "meta_data": [ 82 | { 83 | "id": 1559419, 84 | "key": "tm_woo_api_sync_enabled_for_Loja+Base", 85 | "value": "no" 86 | }, 87 | { 88 | "id": 1559449, 89 | "key": "_billing_persontype", 90 | "value": "2" 91 | }, 92 | { 93 | "id": 1559450, 94 | "key": "_billing_cpf", 95 | "value": "005.762.739-88" 96 | }, 97 | { 98 | "id": 1559451, 99 | "key": "_billing_cnpj", 100 | "value": "18.270.630/0001-41" 101 | }, 102 | { 103 | "id": 1559452, 104 | "key": "_billing_recipient", 105 | "value": "teste" 106 | }, 107 | { 108 | "id": 1559453, 109 | "key": "_billing_recipient_phone", 110 | "value": "85996859001" 111 | }, 112 | { 113 | "id": 1559454, 114 | "key": "_billing_number", 115 | "value": "302" 116 | }, 117 | { 118 | "id": 1559455, 119 | "key": "_billing_complementary", 120 | "value": "APTO 704" 121 | }, 122 | { 123 | "id": 1559456, 124 | "key": "_billing_neighborhood", 125 | "value": "CENTRO" 126 | }, 127 | { 128 | "id": 1559457, 129 | "key": "_billing_msg", 130 | "value": "testes" 131 | }, 132 | { 133 | "id": 1559458, 134 | "key": "is_vat_exempt", 135 | "value": "no" 136 | }, 137 | { 138 | "id": 1559459, 139 | "key": "thwcfe_ship_to_billing", 140 | "value": "1" 141 | }, 142 | { 143 | "id": 1559460, 144 | "key": "_thwcfe_disabled_fields", 145 | "value": "time" 146 | }, 147 | { 148 | "id": 1559461, 149 | "key": "billing_cpf", 150 | "value": "005.762.739-88" 151 | }, 152 | { 153 | "id": 1559462, 154 | "key": "billing_cnpj", 155 | "value": "18.270.630/0001-41" 156 | }, 157 | { 158 | "id": 1559463, 159 | "key": "billing_company", 160 | "value": "Teste" 161 | }, 162 | { 163 | "id": 1559464, 164 | "key": "billing_recipient", 165 | "value": "teste" 166 | }, 167 | { 168 | "id": 1559465, 169 | "key": "billing_recipient_phone", 170 | "value": "85996859001" 171 | }, 172 | { 173 | "id": 1559466, 174 | "key": "billing_number", 175 | "value": "302" 176 | }, 177 | { 178 | "id": 1559467, 179 | "key": "billing_complementary", 180 | "value": "APTO 704" 181 | }, 182 | { 183 | "id": 1559468, 184 | "key": "billing_neighborhood", 185 | "value": "CENTRO" 186 | }, 187 | { 188 | "id": 1559469, 189 | "key": "billing_msg", 190 | "value": "testes" 191 | }, 192 | { 193 | "id": 1559470, 194 | "key": "date", 195 | "value": "01/05/2022" 196 | }, 197 | { 198 | "id": 1559471, 199 | "key": "time_celebration", 200 | "value": "Antes das 8h00" 201 | } 202 | ], 203 | "line_items": [ 204 | { 205 | "id": 46981, 206 | "name": "Box Petiscos", 207 | "product_id": 32205, 208 | "variation_id": 0, 209 | "quantity": 1, 210 | "tax_class": "", 211 | "subtotal": "199.90", 212 | "subtotal_tax": "0.00", 213 | "total": "199.90", 214 | "total_tax": "0.00", 215 | "taxes": [], 216 | "meta_data": [], 217 | "sku": "", 218 | "price": 199.9, 219 | "parent_name": null 220 | }, 221 | { 222 | "id": 46982, 223 | "name": "Cesta Café da Manhã Coqueiros", 224 | "product_id": 32129, 225 | "variation_id": 0, 226 | "quantity": 1, 227 | "tax_class": "", 228 | "subtotal": "159.90", 229 | "subtotal_tax": "0.00", 230 | "total": "159.90", 231 | "total_tax": "0.00", 232 | "taxes": [], 233 | "meta_data": [], 234 | "sku": "", 235 | "price": 159.9, 236 | "parent_name": null 237 | } 238 | ], 239 | "tax_lines": [], 240 | "shipping_lines": [ 241 | { 242 | "id": 46984, 243 | "method_title": "Frete grátis", 244 | "method_id": "free_shipping", 245 | "instance_id": "30", 246 | "total": "0.00", 247 | "total_tax": "0.00", 248 | "taxes": [], 249 | "meta_data": [ 250 | { 251 | "id": 380952, 252 | "key": "Itens", 253 | "value": "Box Petiscos × 1, Cesta Café da Manhã Coqueiros × 1", 254 | "display_key": "Itens", 255 | "display_value": "Box Petiscos × 1, Cesta Café da Manhã Coqueiros × 1" 256 | } 257 | ] 258 | } 259 | ], 260 | "fee_lines": [ 261 | { 262 | "id": 46983, 263 | "name": "Horário de Entrega (Antes das 8h00)", 264 | "tax_class": "0", 265 | "tax_status": "taxable", 266 | "amount": "15", 267 | "total": "15.00", 268 | "total_tax": "0.00", 269 | "taxes": [], 270 | "meta_data": [] 271 | } 272 | ], 273 | "coupon_lines": [], 274 | "refunds": [], 275 | "date_created_gmt": "2022-05-01T18:17:30", 276 | "date_modified_gmt": "2022-05-01T18:17:30", 277 | "date_completed_gmt": null, 278 | "date_paid_gmt": null, 279 | "schedule": { 280 | "date": "01/05/2022", 281 | "time": "", 282 | "time_celebration": "Antes das 8h00", 283 | "space_3": "" 284 | }, 285 | "currency_symbol": "R$", 286 | "_links": { 287 | "self": [ 288 | { 289 | "href": "http://localhost:10003/wp-json/wc/v3/orders/66621" 290 | } 291 | ], 292 | "collection": [ 293 | { 294 | "href": "http://localhost:10003/wp-json/wc/v3/orders" 295 | } 296 | ], 297 | "customer": [ 298 | { 299 | "href": "http://localhost:10003/wp-json/wc/v3/customers/1" 300 | } 301 | ] 302 | } 303 | }, 304 | { 305 | "id": 36875, 306 | "parent_id": 0, 307 | "status": "completed", 308 | "currency": "BRL", 309 | "version": "6.6.0", 310 | "prices_include_tax": true, 311 | "date_created": "2022-07-02T19:10:21", 312 | "date_modified": "2022-07-03T09:49:19", 313 | "discount_total": "0.00", 314 | "discount_tax": "0.00", 315 | "shipping_total": "15.00", 316 | "shipping_tax": "0.00", 317 | "cart_tax": "0.00", 318 | "total": "164.90", 319 | "total_tax": "0.00", 320 | "customer_id": 0, 321 | "order_key": "wc_order_CsufiGQ7amiLL", 322 | "billing": { 323 | "first_name": "Mariana", 324 | "last_name": "Barreto", 325 | "company": "", 326 | "address_1": "Rua Nove de Julho", 327 | "address_2": "", 328 | "city": "São José", 329 | "state": "SC", 330 | "postcode": "88111-380", 331 | "country": "BR", 332 | "email": "maris.barreto19@gmail.com", 333 | "phone": "85996859001", 334 | "payment": "", 335 | "billing_cpf": "061.828.689-61", 336 | "billing_cnpj": "", 337 | "billing_company": "", 338 | "space": "", 339 | "delivery": "", 340 | "billing_recipient": "Vanessa Barreto Bossle", 341 | "billing_recipient_phone": "85996859001", 342 | "billing_number": "611", 343 | "billing_complementary": "Casa Branca em frente ao salão de Beleza", 344 | "billing_neighborhood": "Bairro Ipiranga", 345 | "billing_msg": "Nessa, que seu dia seja repleto de amor.\r\n\r\nDaqueles que te amam e te querem bem.\r\n\r\nCom carinho,\r\nRenato, Josiani, Mana, Mari, Manu e Miguelzinho", 346 | "space_2": "", 347 | "number": "611", 348 | "neighborhood": "Bairro Ipiranga", 349 | "persontype": "F", 350 | "cpf": "06182868961", 351 | "rg": "", 352 | "cnpj": "", 353 | "ie": "", 354 | "birthdate": "", 355 | "sex": "", 356 | "cellphone": "" 357 | }, 358 | "shipping": { 359 | "first_name": "", 360 | "last_name": "", 361 | "company": "", 362 | "address_1": "", 363 | "address_2": "", 364 | "city": "", 365 | "state": "", 366 | "postcode": "", 367 | "country": "", 368 | "phone": "", 369 | "number": "", 370 | "neighborhood": "" 371 | }, 372 | "payment_method": "bacs", 373 | "payment_method_title": "PIX ou Transferência ", 374 | "transaction_id": "", 375 | "customer_ip_address": "189.4.77.0", 376 | "customer_user_agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Mobile/15E148 Safari/604.1", 377 | "created_via": "checkout", 378 | "customer_note": "", 379 | "date_completed": "2022-07-03T09:49:19", 380 | "date_paid": "2022-07-03T09:49:19", 381 | "cart_hash": "a7fee777c8ff0919b8e9cbf0d90849e8", 382 | "number": "36875", 383 | "meta_data": [ 384 | { 385 | "id": 996295, 386 | "key": "_billing_persontype", 387 | "value": "1" 388 | }, 389 | { 390 | "id": 996296, 391 | "key": "_billing_cpf", 392 | "value": "061.828.689-61" 393 | }, 394 | { 395 | "id": 996297, 396 | "key": "_billing_cnpj", 397 | "value": "" 398 | }, 399 | { 400 | "id": 996298, 401 | "key": "_billing_recipient", 402 | "value": "Vanessa Barreto Bossle" 403 | }, 404 | { 405 | "id": 996299, 406 | "key": "_billing_recipient_phone", 407 | "value": "48998051955" 408 | }, 409 | { 410 | "id": 996300, 411 | "key": "_billing_number", 412 | "value": "611" 413 | }, 414 | { 415 | "id": 996301, 416 | "key": "_billing_complementary", 417 | "value": "Casa Branca em frente ao salão de Beleza" 418 | }, 419 | { 420 | "id": 996302, 421 | "key": "_billing_neighborhood", 422 | "value": "Bairro Ipiranga" 423 | }, 424 | { 425 | "id": 996303, 426 | "key": "_billing_msg", 427 | "value": "Nessa, que seu dia seja repleto de amor.\n\nDaqueles que te amam e te querem bem.\n\nCom carinho,\nRenato, Josiani, Mana, Mari, Manu e Miguelzinho" 428 | }, 429 | { 430 | "id": 996304, 431 | "key": "is_vat_exempt", 432 | "value": "no" 433 | }, 434 | { 435 | "id": 996305, 436 | "key": "_thwcfe_ship_to_billing", 437 | "value": "1" 438 | }, 439 | { 440 | "id": 996306, 441 | "key": "_thwcfe_disabled_fields", 442 | "value": "time" 443 | }, 444 | { 445 | "id": 996307, 446 | "key": "billing_cpf", 447 | "value": "061.828.689-61" 448 | }, 449 | { 450 | "id": 996308, 451 | "key": "billing_recipient", 452 | "value": "Vanessa Barreto Bossle" 453 | }, 454 | { 455 | "id": 996309, 456 | "key": "billing_recipient_phone", 457 | "value": "48998051955" 458 | }, 459 | { 460 | "id": 996310, 461 | "key": "billing_number", 462 | "value": "611" 463 | }, 464 | { 465 | "id": 996311, 466 | "key": "billing_complementary", 467 | "value": "Casa Branca em frente ao salão de Beleza" 468 | }, 469 | { 470 | "id": 996312, 471 | "key": "billing_neighborhood", 472 | "value": "Bairro Ipiranga" 473 | }, 474 | { 475 | "id": 996313, 476 | "key": "billing_msg", 477 | "value": "Nessa, que seu dia seja repleto de amor.\r\n\r\nDaqueles que te amam e te querem bem.\r\n\r\nCom carinho,\r\nRenato, Josiani, Mana, Mari, Manu e Miguelzinho" 478 | }, 479 | { 480 | "id": 996314, 481 | "key": "date", 482 | "value": "03/07/2022" 483 | }, 484 | { 485 | "id": 996315, 486 | "key": "time_celebration", 487 | "value": "Período da Manhã" 488 | }, 489 | { 490 | "id": 996316, 491 | "key": "_wc_facebook_for_woocommerce_order_placed", 492 | "value": "yes" 493 | }, 494 | { 495 | "id": 996320, 496 | "key": "_new_order_email_sent", 497 | "value": "true" 498 | }, 499 | { 500 | "id": 996321, 501 | "key": "_wc_facebook_for_woocommerce_purchase_tracked", 502 | "value": "yes" 503 | }, 504 | { 505 | "id": 996328, 506 | "key": "_shipping_number", 507 | "value": "" 508 | }, 509 | { 510 | "id": 996329, 511 | "key": "_shipping_neighborhood", 512 | "value": "" 513 | } 514 | ], 515 | "line_items": [ 516 | { 517 | "id": 18074, 518 | "name": "Doce Encanto", 519 | "product_id": 2157, 520 | "variation_id": 0, 521 | "quantity": 1, 522 | "tax_class": "", 523 | "subtotal": "149.90", 524 | "subtotal_tax": "0.00", 525 | "total": "149.90", 526 | "total_tax": "0.00", 527 | "taxes": [], 528 | "meta_data": [], 529 | "sku": "", 530 | "price": 149.9, 531 | "image": { 532 | "id": "807", 533 | "src": "https://innovacestas.com.br/wp-content/uploads/2020/05/Doce-Encanto.jpg" 534 | }, 535 | "parent_name": null 536 | } 537 | ], 538 | "tax_lines": [], 539 | "shipping_lines": [ 540 | { 541 | "id": 18075, 542 | "method_title": "Delivery", 543 | "method_id": "flat_rate", 544 | "instance_id": "9", 545 | "total": "15.00", 546 | "total_tax": "0.00", 547 | "taxes": [], 548 | "meta_data": [ 549 | { 550 | "id": 148342, 551 | "key": "Itens", 552 | "value": "Doce Encanto × 1", 553 | "display_key": "Itens", 554 | "display_value": "Doce Encanto × 1" 555 | } 556 | ] 557 | } 558 | ], 559 | "fee_lines": [], 560 | "coupon_lines": [], 561 | "refunds": [], 562 | "payment_url": "https://innovacestas.com.br/finalizar-compra/order-pay/36875/?pay_for_order=true&key=wc_order_CsufiGQ7amiLL", 563 | "is_editable": false, 564 | "needs_payment": false, 565 | "needs_processing": true, 566 | "date_created_gmt": "2022-07-02T22:10:21", 567 | "date_modified_gmt": "2022-07-03T12:49:19", 568 | "date_completed_gmt": "2022-07-03T12:49:19", 569 | "date_paid_gmt": "2022-07-03T12:49:19", 570 | "schedule": { 571 | "date": "03/07/2022", 572 | "time": "", 573 | "delivery_alert": "", 574 | "time_celebration": "Período da Manhã", 575 | "space_3": "" 576 | }, 577 | "currency_symbol": "R$", 578 | "_links": { 579 | "self": [ 580 | { 581 | "href": "https://innovacestas.com.br/wp-json/wc/v3/orders/36875" 582 | } 583 | ], 584 | "collection": [ 585 | { 586 | "href": "https://innovacestas.com.br/wp-json/wc/v3/orders" 587 | } 588 | ] 589 | } 590 | }, 591 | { 592 | "id": 36874, 593 | "parent_id": 0, 594 | "status": "completed", 595 | "currency": "BRL", 596 | "version": "6.6.0", 597 | "prices_include_tax": true, 598 | "date_created": "2022-07-02T17:55:52", 599 | "date_modified": "2022-07-03T10:05:31", 600 | "discount_total": "0.00", 601 | "discount_tax": "0.00", 602 | "shipping_total": "20.00", 603 | "shipping_tax": "0.00", 604 | "cart_tax": "0.00", 605 | "total": "309.90", 606 | "total_tax": "0.00", 607 | "customer_id": 0, 608 | "order_key": "wc_order_PYC1jtOGNjsb7", 609 | "billing": { 610 | "first_name": "Nayara", 611 | "last_name": "Gonçalves", 612 | "company": "", 613 | "address_1": "Rua José Graciliano da Silva", 614 | "address_2": "", 615 | "city": "São José", 616 | "state": "SC", 617 | "postcode": "88115-239", 618 | "country": "BR", 619 | "email": "nayarapg@hotmail.com", 620 | "phone": "85996859001", 621 | "payment": "", 622 | "billing_cpf": "035.916.769-18", 623 | "billing_cnpj": "", 624 | "billing_company": "", 625 | "space": "", 626 | "delivery": "", 627 | "billing_recipient": "Scheila Pereira", 628 | "billing_recipient_phone": "85996859001", 629 | "billing_number": "170", 630 | "billing_complementary": "Bloco 4 apto 104", 631 | "billing_neighborhood": "Serraria", 632 | "billing_msg": "Parabéns para a minha amiga irmã que está quarentando ainda mais linda!\r\nTe amo e desejo apenas as melhores coisas desse mundão!!\r\nBeijos\r\nNay", 633 | "space_2": "", 634 | "number": "170", 635 | "neighborhood": "Serraria", 636 | "persontype": "F", 637 | "cpf": "03591676918", 638 | "rg": "", 639 | "cnpj": "", 640 | "ie": "", 641 | "birthdate": "", 642 | "sex": "", 643 | "cellphone": "" 644 | }, 645 | "shipping": { 646 | "first_name": "", 647 | "last_name": "", 648 | "company": "", 649 | "address_1": "", 650 | "address_2": "", 651 | "city": "", 652 | "state": "", 653 | "postcode": "", 654 | "country": "", 655 | "phone": "", 656 | "number": "", 657 | "neighborhood": "" 658 | }, 659 | "payment_method": "bacs", 660 | "payment_method_title": "PIX ou Transferência ", 661 | "transaction_id": "", 662 | "customer_ip_address": "179.232.120.95", 663 | "customer_user_agent": "Mozilla/5.0 (Linux; Android 11; moto g(10)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Mobile Safari/537.36", 664 | "created_via": "checkout", 665 | "customer_note": "", 666 | "date_completed": "2022-07-03T10:05:31", 667 | "date_paid": "2022-07-03T10:05:31", 668 | "cart_hash": "b24cdbd254b0bc0202d60224586b50bf", 669 | "number": "36874", 670 | "meta_data": [ 671 | { 672 | "id": 996240, 673 | "key": "_billing_persontype", 674 | "value": "1" 675 | }, 676 | { 677 | "id": 996241, 678 | "key": "_billing_cpf", 679 | "value": "035.916.769-18" 680 | }, 681 | { 682 | "id": 996242, 683 | "key": "_billing_cnpj", 684 | "value": "" 685 | }, 686 | { 687 | "id": 996243, 688 | "key": "_billing_recipient", 689 | "value": "Scheila Pereira" 690 | }, 691 | { 692 | "id": 996244, 693 | "key": "_billing_recipient_phone", 694 | "value": "48 99830-6708" 695 | }, 696 | { 697 | "id": 996245, 698 | "key": "_billing_number", 699 | "value": "170" 700 | }, 701 | { 702 | "id": 996246, 703 | "key": "_billing_complementary", 704 | "value": "Bloco 4 apto 104" 705 | }, 706 | { 707 | "id": 996247, 708 | "key": "_billing_neighborhood", 709 | "value": "Serraria" 710 | }, 711 | { 712 | "id": 996248, 713 | "key": "_billing_msg", 714 | "value": "Parabéns para a minha amiga irmã que está quarentando ainda mais linda!\nTe amo e desejo apenas as melhores coisas desse mundão!!\nBeijos\nNay" 715 | }, 716 | { 717 | "id": 996249, 718 | "key": "is_vat_exempt", 719 | "value": "no" 720 | }, 721 | { 722 | "id": 996250, 723 | "key": "_thwcfe_ship_to_billing", 724 | "value": "1" 725 | }, 726 | { 727 | "id": 996251, 728 | "key": "_thwcfe_disabled_fields", 729 | "value": "time" 730 | }, 731 | { 732 | "id": 996252, 733 | "key": "billing_cpf", 734 | "value": "035.916.769-18" 735 | }, 736 | { 737 | "id": 996253, 738 | "key": "billing_recipient", 739 | "value": "Scheila Pereira" 740 | }, 741 | { 742 | "id": 996254, 743 | "key": "billing_recipient_phone", 744 | "value": "48 99830-6708" 745 | }, 746 | { 747 | "id": 996255, 748 | "key": "billing_number", 749 | "value": "170" 750 | }, 751 | { 752 | "id": 996256, 753 | "key": "billing_complementary", 754 | "value": "Bloco 4 apto 104" 755 | }, 756 | { 757 | "id": 996257, 758 | "key": "billing_neighborhood", 759 | "value": "Serraria" 760 | }, 761 | { 762 | "id": 996258, 763 | "key": "billing_msg", 764 | "value": "Parabéns para a minha amiga irmã que está quarentando ainda mais linda!\r\nTe amo e desejo apenas as melhores coisas desse mundão!!\r\nBeijos\r\nNay" 765 | }, 766 | { 767 | "id": 996259, 768 | "key": "date", 769 | "value": "03/07/2022" 770 | }, 771 | { 772 | "id": 996260, 773 | "key": "time_celebration", 774 | "value": "Período da Manhã" 775 | }, 776 | { 777 | "id": 996261, 778 | "key": "_wc_facebook_for_woocommerce_order_placed", 779 | "value": "yes" 780 | }, 781 | { 782 | "id": 996265, 783 | "key": "_new_order_email_sent", 784 | "value": "true" 785 | }, 786 | { 787 | "id": 996266, 788 | "key": "_wc_facebook_for_woocommerce_purchase_tracked", 789 | "value": "yes" 790 | }, 791 | { 792 | "id": 996324, 793 | "key": "_shipping_number", 794 | "value": "" 795 | }, 796 | { 797 | "id": 996325, 798 | "key": "_shipping_neighborhood", 799 | "value": "" 800 | } 801 | ], 802 | "line_items": [ 803 | { 804 | "id": 18072, 805 | "name": "Baú Rosas Carinho Chandon", 806 | "product_id": 2102, 807 | "variation_id": 0, 808 | "quantity": 1, 809 | "tax_class": "", 810 | "subtotal": "289.90", 811 | "subtotal_tax": "0.00", 812 | "total": "289.90", 813 | "total_tax": "0.00", 814 | "taxes": [], 815 | "meta_data": [], 816 | "sku": "", 817 | "price": 289.9, 818 | "image": { 819 | "id": "688", 820 | "src": "https://innovacestas.com.br/wp-content/uploads/2020/05/Baú-Rosas-Carinho-Chandon-1.jpg" 821 | }, 822 | "parent_name": null 823 | } 824 | ], 825 | "tax_lines": [], 826 | "shipping_lines": [ 827 | { 828 | "id": 18073, 829 | "method_title": "Delivery", 830 | "method_id": "flat_rate", 831 | "instance_id": "11", 832 | "total": "20.00", 833 | "total_tax": "0.00", 834 | "taxes": [], 835 | "meta_data": [ 836 | { 837 | "id": 148327, 838 | "key": "Itens", 839 | "value": "Baú Rosas Carinho Chandon × 1", 840 | "display_key": "Itens", 841 | "display_value": "Baú Rosas Carinho Chandon × 1" 842 | } 843 | ] 844 | } 845 | ], 846 | "fee_lines": [], 847 | "coupon_lines": [], 848 | "refunds": [], 849 | "payment_url": "https://innovacestas.com.br/finalizar-compra/order-pay/36874/?pay_for_order=true&key=wc_order_PYC1jtOGNjsb7", 850 | "is_editable": false, 851 | "needs_payment": false, 852 | "needs_processing": true, 853 | "date_created_gmt": "2022-07-02T20:55:52", 854 | "date_modified_gmt": "2022-07-03T13:05:31", 855 | "date_completed_gmt": "2022-07-03T13:05:31", 856 | "date_paid_gmt": "2022-07-03T13:05:31", 857 | "schedule": { 858 | "date": "03/07/2022", 859 | "time": "", 860 | "delivery_alert": "", 861 | "time_celebration": "Período da Manhã", 862 | "space_3": "" 863 | }, 864 | "currency_symbol": "R$", 865 | "_links": { 866 | "self": [ 867 | { 868 | "href": "https://innovacestas.com.br/wp-json/wc/v3/orders/36874" 869 | } 870 | ], 871 | "collection": [ 872 | { 873 | "href": "https://innovacestas.com.br/wp-json/wc/v3/orders" 874 | } 875 | ] 876 | } 877 | }, 878 | { 879 | "id": 36873, 880 | "parent_id": 0, 881 | "status": "completed", 882 | "currency": "BRL", 883 | "version": "6.6.0", 884 | "prices_include_tax": true, 885 | "date_created": "2022-07-02T13:30:57", 886 | "date_modified": "2022-07-03T08:48:14", 887 | "discount_total": "0.00", 888 | "discount_tax": "0.00", 889 | "shipping_total": "32.00", 890 | "shipping_tax": "0.00", 891 | "cart_tax": "0.00", 892 | "total": "251.90", 893 | "total_tax": "0.00", 894 | "customer_id": 0, 895 | "order_key": "wc_order_xyhq7G0pGlaSc", 896 | "billing": { 897 | "first_name": "Elis", 898 | "last_name": "Capeletti", 899 | "company": "", 900 | "address_1": "Rua Dario João de Souza", 901 | "address_2": "", 902 | "city": "florianopolis", 903 | "state": "SC", 904 | "postcode": "88053-760", 905 | "country": "BR", 906 | "email": "eliscapeletti@hotmail.com", 907 | "phone": "85996859001", 908 | "payment": "", 909 | "billing_cpf": "921.232.520-34", 910 | "billing_cnpj": "", 911 | "billing_company": "", 912 | "space": "", 913 | "delivery": "", 914 | "billing_recipient": "Marcia Capeletti", 915 | "billing_recipient_phone": "85996859001", 916 | "billing_number": "61", 917 | "billing_complementary": "apto. 210B", 918 | "billing_neighborhood": "Jurere", 919 | "billing_msg": "Mana, tenha um dia muito doce, te amamos! Feliz aniver!\r\nElis e Letícia", 920 | "space_2": "", 921 | "number": "61", 922 | "neighborhood": "Jurere", 923 | "persontype": "F", 924 | "cpf": "92123252034", 925 | "rg": "", 926 | "cnpj": "", 927 | "ie": "", 928 | "birthdate": "", 929 | "sex": "", 930 | "cellphone": "" 931 | }, 932 | "shipping": { 933 | "first_name": "", 934 | "last_name": "", 935 | "company": "", 936 | "address_1": "", 937 | "address_2": "", 938 | "city": "", 939 | "state": "", 940 | "postcode": "", 941 | "country": "", 942 | "phone": "", 943 | "number": "", 944 | "neighborhood": "" 945 | }, 946 | "payment_method": "bacs", 947 | "payment_method_title": "PIX ou Transferência ", 948 | "transaction_id": "", 949 | "customer_ip_address": "189.6.245.142", 950 | "customer_user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.66 Safari/537.36 Edg/103.0.1264.44", 951 | "created_via": "checkout", 952 | "customer_note": "", 953 | "date_completed": "2022-07-03T08:48:14", 954 | "date_paid": "2022-07-03T08:48:14", 955 | "cart_hash": "e472b17fe31d78eaf5191713b4eda912", 956 | "number": "36873", 957 | "meta_data": [ 958 | { 959 | "id": 996159, 960 | "key": "_billing_persontype", 961 | "value": "1" 962 | }, 963 | { 964 | "id": 996160, 965 | "key": "_billing_cpf", 966 | "value": "921.232.520-34" 967 | }, 968 | { 969 | "id": 996161, 970 | "key": "_billing_cnpj", 971 | "value": "" 972 | }, 973 | { 974 | "id": 996162, 975 | "key": "_billing_recipient", 976 | "value": "Marcia Capeletti" 977 | }, 978 | { 979 | "id": 996163, 980 | "key": "_billing_recipient_phone", 981 | "value": "48991639003" 982 | }, 983 | { 984 | "id": 996164, 985 | "key": "_billing_number", 986 | "value": "61" 987 | }, 988 | { 989 | "id": 996165, 990 | "key": "_billing_complementary", 991 | "value": "apto. 210B" 992 | }, 993 | { 994 | "id": 996166, 995 | "key": "_billing_neighborhood", 996 | "value": "Jurere" 997 | }, 998 | { 999 | "id": 996167, 1000 | "key": "_billing_msg", 1001 | "value": "Mana, tenha um dia muito doce, te amamos! Feliz aniver!\nElis e Letícia" 1002 | }, 1003 | { 1004 | "id": 996168, 1005 | "key": "is_vat_exempt", 1006 | "value": "no" 1007 | }, 1008 | { 1009 | "id": 996169, 1010 | "key": "_thwcfe_ship_to_billing", 1011 | "value": "1" 1012 | }, 1013 | { 1014 | "id": 996170, 1015 | "key": "_thwcfe_disabled_fields", 1016 | "value": "time" 1017 | }, 1018 | { 1019 | "id": 996171, 1020 | "key": "billing_cpf", 1021 | "value": "921.232.520-34" 1022 | }, 1023 | { 1024 | "id": 996172, 1025 | "key": "billing_recipient", 1026 | "value": "Marcia Capeletti" 1027 | }, 1028 | { 1029 | "id": 996173, 1030 | "key": "billing_recipient_phone", 1031 | "value": "48991639003" 1032 | }, 1033 | { 1034 | "id": 996174, 1035 | "key": "billing_number", 1036 | "value": "61" 1037 | }, 1038 | { 1039 | "id": 996175, 1040 | "key": "billing_complementary", 1041 | "value": "apto. 210B" 1042 | }, 1043 | { 1044 | "id": 996176, 1045 | "key": "billing_neighborhood", 1046 | "value": "Jurere" 1047 | }, 1048 | { 1049 | "id": 996177, 1050 | "key": "billing_msg", 1051 | "value": "Mana, tenha um dia muito doce, te amamos! Feliz aniver!\r\nElis e Letícia" 1052 | }, 1053 | { 1054 | "id": 996178, 1055 | "key": "date", 1056 | "value": "03/07/2022" 1057 | }, 1058 | { 1059 | "id": 996179, 1060 | "key": "time_celebration", 1061 | "value": "Período da Manhã" 1062 | }, 1063 | { 1064 | "id": 996180, 1065 | "key": "_wc_facebook_for_woocommerce_order_placed", 1066 | "value": "yes" 1067 | }, 1068 | { 1069 | "id": 996184, 1070 | "key": "_new_order_email_sent", 1071 | "value": "true" 1072 | }, 1073 | { 1074 | "id": 996185, 1075 | "key": "_wc_facebook_for_woocommerce_purchase_tracked", 1076 | "value": "yes" 1077 | }, 1078 | { 1079 | "id": 996192, 1080 | "key": "_shipping_number", 1081 | "value": "" 1082 | }, 1083 | { 1084 | "id": 996193, 1085 | "key": "_shipping_neighborhood", 1086 | "value": "" 1087 | } 1088 | ], 1089 | "line_items": [ 1090 | { 1091 | "id": 18070, 1092 | "name": "Caixa Surpresa de Aniversário", 1093 | "product_id": 2025, 1094 | "variation_id": 0, 1095 | "quantity": 1, 1096 | "tax_class": "", 1097 | "subtotal": "219.90", 1098 | "subtotal_tax": "0.00", 1099 | "total": "219.90", 1100 | "total_tax": "0.00", 1101 | "taxes": [], 1102 | "meta_data": [], 1103 | "sku": "", 1104 | "price": 219.9, 1105 | "image": { 1106 | "id": "23189", 1107 | "src": "https://innovacestas.com.br/wp-content/uploads/2020/06/pinnkk.jpg" 1108 | }, 1109 | "parent_name": null 1110 | } 1111 | ], 1112 | "tax_lines": [], 1113 | "shipping_lines": [ 1114 | { 1115 | "id": 18071, 1116 | "method_title": "Uber Flash", 1117 | "method_id": "flat_rate", 1118 | "instance_id": "16", 1119 | "total": "32.00", 1120 | "total_tax": "0.00", 1121 | "taxes": [], 1122 | "meta_data": [ 1123 | { 1124 | "id": 148312, 1125 | "key": "Itens", 1126 | "value": "Caixa Surpresa de Aniversário × 1", 1127 | "display_key": "Itens", 1128 | "display_value": "Caixa Surpresa de Aniversário × 1" 1129 | } 1130 | ] 1131 | } 1132 | ], 1133 | "fee_lines": [], 1134 | "coupon_lines": [], 1135 | "refunds": [], 1136 | "payment_url": "https://innovacestas.com.br/finalizar-compra/order-pay/36873/?pay_for_order=true&key=wc_order_xyhq7G0pGlaSc", 1137 | "is_editable": false, 1138 | "needs_payment": false, 1139 | "needs_processing": true, 1140 | "date_created_gmt": "2022-07-02T16:30:57", 1141 | "date_modified_gmt": "2022-07-03T11:48:14", 1142 | "date_completed_gmt": "2022-07-03T11:48:14", 1143 | "date_paid_gmt": "2022-07-03T11:48:14", 1144 | "schedule": { 1145 | "date": "03/07/2022", 1146 | "time": "", 1147 | "delivery_alert": "", 1148 | "time_celebration": "Período da Manhã", 1149 | "space_3": "" 1150 | }, 1151 | "currency_symbol": "R$", 1152 | "_links": { 1153 | "self": [ 1154 | { 1155 | "href": "https://innovacestas.com.br/wp-json/wc/v3/orders/36873" 1156 | } 1157 | ], 1158 | "collection": [ 1159 | { 1160 | "href": "https://innovacestas.com.br/wp-json/wc/v3/orders" 1161 | } 1162 | ] 1163 | } 1164 | } 1165 | ] -------------------------------------------------------------------------------- /src/test/productsJson-response.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "id": 794, 3 | "name": "Premium Quality", 4 | "slug": "premium-quality-19", 5 | "permalink": "https://example.com/product/premium-quality-19/", 6 | "date_created": "2017-03-23T17:01:14", 7 | "date_created_gmt": "2017-03-23T20:01:14", 8 | "date_modified": "2017-03-23T17:01:14", 9 | "date_modified_gmt": "2017-03-23T20:01:14", 10 | "type": "simple", 11 | "status": "publish", 12 | "featured": false, 13 | "catalog_visibility": "visible", 14 | "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", 15 | "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", 16 | "sku": "", 17 | "price": "21.99", 18 | "regular_price": "21.99", 19 | "sale_price": "", 20 | "date_on_sale_from": null, 21 | "date_on_sale_from_gmt": null, 22 | "date_on_sale_to": null, 23 | "date_on_sale_to_gmt": null, 24 | "price_html": "$21.99", 25 | "on_sale": false, 26 | "purchasable": true, 27 | "total_sales": 0, 28 | "virtual": false, 29 | "downloadable": false, 30 | "downloads": [], 31 | "download_limit": -1, 32 | "download_expiry": -1, 33 | "external_url": "", 34 | "button_text": "", 35 | "tax_status": "taxable", 36 | "tax_class": "", 37 | "manage_stock": false, 38 | "stock_quantity": null, 39 | "stock_status": "instock", 40 | "backorders": "no", 41 | "backorders_allowed": false, 42 | "backordered": false, 43 | "sold_individually": false, 44 | "weight": "", 45 | "dimensions": { 46 | "length": "", 47 | "width": "", 48 | "height": "" 49 | }, 50 | "shipping_required": true, 51 | "shipping_taxable": true, 52 | "shipping_class": "", 53 | "shipping_class_id": 0, 54 | "reviews_allowed": true, 55 | "average_rating": "0.00", 56 | "rating_count": 0, 57 | "related_ids": [ 58 | 53, 59 | 40, 60 | 56, 61 | 479, 62 | 99 63 | ], 64 | "upsell_ids": [], 65 | "cross_sell_ids": [], 66 | "parent_id": 0, 67 | "purchase_note": "", 68 | "categories": [ 69 | { 70 | "id": 9, 71 | "name": "Clothing", 72 | "slug": "clothing" 73 | }, 74 | { 75 | "id": 14, 76 | "name": "T-shirts", 77 | "slug": "t-shirts" 78 | } 79 | ], 80 | "tags": [], 81 | "images": [ 82 | { 83 | "id": 792, 84 | "date_created": "2017-03-23T14:01:13", 85 | "date_created_gmt": "2017-03-23T20:01:13", 86 | "date_modified": "2017-03-23T14:01:13", 87 | "date_modified_gmt": "2017-03-23T20:01:13", 88 | "src": "https://example.com/wp-content/uploads/2017/03/T_2_front-4.jpg", 89 | "name": "", 90 | "alt": "" 91 | }, 92 | { 93 | "id": 793, 94 | "date_created": "2017-03-23T14:01:14", 95 | "date_created_gmt": "2017-03-23T20:01:14", 96 | "date_modified": "2017-03-23T14:01:14", 97 | "date_modified_gmt": "2017-03-23T20:01:14", 98 | "src": "https://example.com/wp-content/uploads/2017/03/T_2_back-2.jpg", 99 | "name": "", 100 | "alt": "" 101 | } 102 | ], 103 | "attributes": [], 104 | "default_attributes": [], 105 | "variations": [], 106 | "grouped_products": [], 107 | "menu_order": 0, 108 | "meta_data": [], 109 | "_links": { 110 | "self": [ 111 | { 112 | "href": "https://example.com/wp-json/wc/v3/products/794" 113 | } 114 | ], 115 | "collection": [ 116 | { 117 | "href": "https://example.com/wp-json/wc/v3/products" 118 | } 119 | ] 120 | } 121 | }] -------------------------------------------------------------------------------- /src/test/productsJson.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "id": 39474, 3 | "name": "Kit Natal Doce", 4 | "slug": "kit-natal-doce", 5 | "permalink": "https://innova.eetp.com.br/produto/kit-natal-doce/", 6 | "date_created": "2022-11-18T18:08:01", 7 | "date_created_gmt": "2022-11-18T21:08:01", 8 | "date_modified": "2022-11-18T18:08:01", 9 | "date_modified_gmt": "2022-11-18T21:08:01", 10 | "type": "simple", 11 | "status": "publish", 12 | "featured": false, 13 | "catalog_visibility": "visible", 14 | "description": "", 15 | "short_description": "", 16 | "sku": "", 17 | "price": "129.90", 18 | "regular_price": "129.90", 19 | "sale_price": "", 20 | "date_on_sale_from": null, 21 | "date_on_sale_from_gmt": null, 22 | "date_on_sale_to": null, 23 | "date_on_sale_to_gmt": null, 24 | "on_sale": false, 25 | "purchasable": true, 26 | "total_sales": 0, 27 | "virtual": false, 28 | "downloadable": false, 29 | "downloads": [], 30 | "download_limit": -1, 31 | "download_expiry": -1, 32 | "external_url": "", 33 | "button_text": "", 34 | "tax_status": "taxable", 35 | "tax_class": "", 36 | "manage_stock": false, 37 | "stock_quantity": null, 38 | "backorders": "no", 39 | "backorders_allowed": false, 40 | "backordered": false, 41 | "low_stock_amount": null, 42 | "sold_individually": true, 43 | "weight": "", 44 | "dimensions": { "length": "", "width": "", "height": "" }, 45 | "shipping_required": true, 46 | "shipping_taxable": true, 47 | "shipping_class": "", 48 | "shipping_class_id": 0, 49 | "reviews_allowed": false, 50 | "average_rating": "0.00", 51 | "rating_count": 0, 52 | "upsell_ids": [], 53 | "cross_sell_ids": [], 54 | "parent_id": 0, 55 | "purchase_note": "", 56 | "categories": [ ["Object"] ], 57 | "tags": [], 58 | "images": [ ["Object"] ], 59 | "attributes": [], 60 | "default_attributes": [], 61 | "variations": [], 62 | "grouped_products": [], 63 | "menu_order": 0, 64 | "price_html": "
R$129,90 à vista
ou 3x de R$43,30
", 65 | "related_ids": [ 39476, 39465, 39463, 39672, 39470 ], 66 | "meta_data": [ 67 | ["Object"], ["Object"], 68 | ["Object"], ["Object"], 69 | ["Object"], ["Object"], 70 | ["Object"], ["Object"], 71 | ["Object"], ["Object"], 72 | ["Object"], ["Object"] 73 | ], 74 | "stock_status": "instock", 75 | "has_options": false, 76 | "yoast_head": "\nKit Natal Doce - Versão de desenvolvimento\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n\n\n", 77 | "yoast_head_json": { 78 | "title": "Kit Natal Doce - Versão de desenvolvimento", 79 | "robots": ["Object"], 80 | "og_locale": "pt_BR", 81 | "og_type": "article", 82 | "og_title": "Kit Natal Doce - Versão de desenvolvimento", 83 | "og_url": "https://innova.eetp.com.br/produto/kit-natal-doce/", 84 | "og_site_name": "Versão de desenvolvimento", 85 | "article_publisher": "https://www.facebook.com/innova.cestas/", 86 | "og_image": ["Array"], 87 | "twitter_card": "summary_large_image", 88 | "schema": ["Object"] 89 | }, 90 | "_links": { "self": ["Array"], "collection": ["Array"] } 91 | } 92 | ] -------------------------------------------------------------------------------- /src/test/wc.test.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-array-constructor */ 2 | /* eslint-disable jest/no-focused-tests */ 3 | /* eslint-disable array-callback-return */ 4 | /* eslint-disable jest/no-conditional-expect */ 5 | /* eslint-disable no-console */ 6 | /* eslint-disable camelcase */ 7 | /* no-disabled-tests */ 8 | /* eslint-disable @typescript-eslint/no-explicit-any */ 9 | /* eslint-disable @typescript-eslint/no-unused-vars */ 10 | /* eslint-disable @typescript-eslint/no-non-null-assertion */ 11 | /* eslint-disable @typescript-eslint/no-var-requires */ 12 | /* eslint-disable-next-line jest/no-conditional-expect */ 13 | 14 | "use strict"; 15 | // import { randomUUID } from 'crypto' 16 | import WooCommerceRestApi, { 17 | CouponsParams, 18 | ProductsMainParams, 19 | WooRestApiOptions, 20 | WooRestApiMethod, 21 | OrdersMainParams, 22 | } from "../index"; 23 | import couponsJson from "./coupons.json"; 24 | import productsJson from "./productsJson.json"; 25 | import productsJsonResponse from "./productsJson-response.json"; 26 | import ordersJson from "./ordersJson.json"; 27 | import constomersJson from "./customersJson.json"; 28 | import userOrder from "./example_data_orders.json"; 29 | import randomstring from "randomstring"; 30 | import constomersJsonResponse from "./customersJson-response.json"; 31 | import { DateTime } from "luxon"; 32 | 33 | /* 34 | * @param {Json} data 35 | * @data { years, month, days, hours, minutes} 36 | * @timezone default 'America/Fortaleza' 37 | * @returns date from time, day, month or years ago in Iso Format 38 | */ 39 | const WOODateMinus = async ( 40 | data: Partial<{ years: any; month: any; days: any; hours: any; minutes: any }> 41 | ) => { 42 | const dateTime = DateTime.now(); 43 | const newDate = dateTime 44 | .minus({ 45 | years: data.years || 0, 46 | months: data.month || 0, 47 | days: data.days || 0, 48 | hours: data.hours || 0, 49 | minutes: data.minutes || 0, 50 | }) 51 | .startOf("day") 52 | .setZone("America/Fortaleza"); 53 | return newDate.toISO(); 54 | }; 55 | /** 56 | * Return the experires days for cupons 57 | * @param {Json} data 58 | * @data { years, month, days, hours, minutes} 59 | * @timezone default 'America/Fortaleza' 60 | * @returns date from time, day, month or years ago in Iso Format 61 | */ 62 | const WOODatePlus = async ( 63 | data: Partial<{ years: any; month: any; days: any; hours: any; minutes: any }> 64 | ) => { 65 | const dateTime = DateTime.now(); 66 | const newDate = dateTime 67 | .plus({ 68 | years: data.years || 0, 69 | months: data.month || 0, 70 | days: data.days || 0, 71 | hours: data.hours || 0, 72 | minutes: data.minutes || 0, 73 | }) 74 | .startOf("day") 75 | .setZone("America/Fortaleza"); 76 | return newDate.toISO(); 77 | }; 78 | 79 | const opt: WooRestApiOptions = { 80 | url: process.env.URL, 81 | consumerKey: process.env.CONSUMERKEY, 82 | consumerSecret: process.env.CONSUMERSECRET, 83 | version: "wc/v3", 84 | queryStringAuth: false, 85 | }; 86 | const env = { ...opt }; 87 | describe.only("#options/#methods", () => { 88 | let wooCommerce: WooCommerceRestApi<{ 89 | url: string; 90 | consumerKey: string; 91 | consumerSecret: string; 92 | }>; 93 | beforeAll(() => { 94 | wooCommerce = new WooCommerceRestApi({ 95 | url: env.url, 96 | consumerKey: env.consumerKey, 97 | consumerSecret: env.consumerSecret, 98 | version: "wc/v3", 99 | queryStringAuth: false, 100 | }); 101 | }); 102 | 103 | // #Constructor 104 | test("instance should be an object", () => { 105 | expect(typeof wooCommerce).toBe(typeof {}); 106 | }); 107 | test("url is required", () => { 108 | expect(() => { 109 | const wooCommerceInstance = new WooCommerceRestApi({ 110 | url: "", 111 | consumerKey: env.consumerKey, 112 | consumerSecret: env.consumerSecret, 113 | version: "wc/v3", 114 | queryStringAuth: false, 115 | }); 116 | }).toThrow("url is required"); 117 | }); 118 | test("consumerKey is required", () => { 119 | expect(() => { 120 | const wooCommerceInstance = new WooCommerceRestApi({ 121 | url: env.url, 122 | consumerKey: "", 123 | consumerSecret: env.consumerSecret, 124 | version: "wc/v3", 125 | queryStringAuth: false, 126 | }); 127 | }).toThrow("consumerKey is required"); 128 | }); 129 | test("consumerSecret is required", () => { 130 | expect(() => { 131 | const wooCommerceInstance = new WooCommerceRestApi({ 132 | url: env.url, 133 | consumerKey: env.consumerSecret, 134 | consumerSecret: "", 135 | version: "wc/v3", 136 | queryStringAuth: false, 137 | }); 138 | }).toThrow("consumerSecret is required"); 139 | }); 140 | 141 | // #Options 142 | test("wpAPIPrefix should set WP REST API custom path", () => { 143 | const endpoint = "products"; 144 | const expected = env.url + "/wp-json/wc/v3/" + endpoint; 145 | const url = wooCommerce._getUrl(endpoint, {}); 146 | 147 | expect(url).toBe(expected); 148 | }); 149 | // #Methods 150 | const endpoint = "products"; 151 | test("_getUrl should return full endpoint URL", () => { 152 | // Fix #1 This is the same test as the one above 153 | 154 | const expected = env.url + "/wp-json/wc/v3/" + endpoint; 155 | const url = wooCommerce._getUrl(endpoint, {}); 156 | 157 | expect(url).toBe(expected); 158 | }); 159 | 160 | test("_normalizeQueryString should return query string sorted by name", () => { 161 | const url = 162 | env.url + 163 | "/wp-json/wc/v3/" + 164 | endpoint + 165 | "?filter[q]=Woo+Album&fields=id&filter[limit]=1"; 166 | const expected = 167 | env.url + 168 | "/wp-json/wc/v3/" + 169 | endpoint + 170 | "?fields=id&filter[limit]=1&filter[q]=Woo%20Album"; 171 | const normalized = wooCommerce._normalizeQueryString(url, {}); 172 | 173 | expect(normalized).toBe(expected); 174 | }); 175 | }); 176 | 177 | describe.only("Test Coupons", () => { 178 | let wooCommerce: WooCommerceRestApi<{ 179 | url: string; 180 | consumerKey: string; 181 | consumerSecret: string; 182 | }>; 183 | let each: (typeof userOrder)[0]; 184 | let first_name: string; 185 | let middle_name: string; 186 | let last_name: string; 187 | let full_name: string; 188 | let discount: string | number; 189 | let best_before: string; 190 | 191 | beforeAll(() => { 192 | wooCommerce = new WooCommerceRestApi({ 193 | url: env.url, 194 | consumerKey: env.consumerKey, 195 | consumerSecret: env.consumerSecret, 196 | version: "wc/v3", 197 | queryStringAuth: false, 198 | }); 199 | }); 200 | 201 | beforeEach(() => { 202 | jest.resetModules(); // Clears the cache 203 | each = userOrder[0]; 204 | // Coupon 205 | discount = "15"; 206 | best_before = "2021-12-31T00:00:00"; 207 | // Customer 208 | first_name = String(each.billing?.first_name).split(" ")[0]; 209 | first_name = 210 | `${first_name.charAt(0).toLocaleUpperCase()}${first_name 211 | .slice(1) 212 | .toLocaleLowerCase()}` || " "; 213 | middle_name = String(each.billing?.first_name).split(" ")[1] || " "; 214 | middle_name = 215 | `${middle_name.charAt(0).toLocaleUpperCase()}${middle_name 216 | .slice(1) 217 | .toLocaleLowerCase()}` || " "; 218 | last_name = 219 | `${String(each.billing?.last_name).charAt(0).toLocaleUpperCase()}${String( 220 | each.billing?.last_name 221 | ) 222 | .slice(1) 223 | .toLocaleLowerCase()}` || " "; 224 | full_name = `${first_name} ${middle_name} ${last_name}` || " "; 225 | }); 226 | 227 | test("should return a list with all coupons created", async () => { 228 | const coupons = await wooCommerce.get("coupons"); 229 | 230 | expect(coupons).toBeInstanceOf(Object); 231 | 232 | if (coupons.headers["x-wp-totalpages"] > 1) { 233 | expect(coupons).toHaveProperty("data", expect.any(Array)); 234 | } 235 | 236 | if (coupons.data.length > 0) { 237 | const expectedKeys = Object.keys(couponsJson[0]); // Array of the keys of the couponsJson object 238 | const keys = Object.keys(coupons.data[0]); // Array of the keys of the first coupon in the coupons.data array 239 | console.table([ 240 | { 241 | Keys: expectedKeys.length, 242 | Expected: keys.length, 243 | diff: expectedKeys.length - keys.length, 244 | }, 245 | ]); 246 | ConsoleMacthKeys(keys, expectedKeys); 247 | keys.forEach((key: any, index) => { 248 | expect(keys[index]).toEqual(expectedKeys[index]); 249 | }); 250 | } 251 | }, 20000); // 20 seconds 252 | 253 | // Get Per page 254 | test("should return a list with all coupons created per page", async () => { 255 | const coupons = await wooCommerce.get("coupons", { per_page: 3 }); 256 | expect(coupons).toBeInstanceOf(Object); 257 | 258 | // coupons.data has to be an array with a length of 3 259 | expect(coupons.data.length).toBe(3); 260 | 261 | if (coupons.headers["x-wp-totalpages"] > 1) { 262 | expect(coupons).toHaveProperty("data", expect.any(Array)); 263 | } 264 | 265 | if (coupons.data.length > 0) { 266 | const expectedKeys = Object.keys(couponsJson[0]); // Array of the keys of the couponsJson object 267 | const keys = Object.keys(coupons.data[0]); // Array of the keys of the first coupon in the coupons.data array 268 | console.table([ 269 | { 270 | Keys: expectedKeys.length, 271 | Expected: keys.length, 272 | diff: expectedKeys.length - keys.length, 273 | }, 274 | ]); 275 | ConsoleMacthKeys(keys, expectedKeys); 276 | keys.forEach((key: any, index) => { 277 | expect(keys[index]).toEqual(expectedKeys[index]); 278 | }); 279 | } 280 | }, 20000); // 20 seconds 281 | 282 | test("should create a Coupon", async () => { 283 | /** 284 | * Get the discount amount from the discount % from Google Sheet 285 | * @param {Number} discount - The discount % 286 | * @param {Number} total - The total amount of the order 287 | * @return {Number} shipping_total - The discount amount 288 | */ 289 | const total_products_price = 290 | Number(each.total) - Number(each.shipping_total); 291 | const total_products_price_with_discount = ( 292 | total_products_price * 293 | (Number(discount) / 100) 294 | ).toFixed(2); 295 | console.log( 296 | `Total: ${total_products_price} - Discount: ${discount} - Total with discount: ${total_products_price_with_discount}` 297 | ); 298 | /** 299 | * Data to Create new Coupons 300 | * @description Create a new Coupon with the following format: first + 12 + - + id 301 | */ 302 | const coupom_data: CouponsParams = { 303 | code: 304 | first_name.substring(0, 3).toLocaleUpperCase() + 305 | randomstring.generate({ 306 | length: 2, 307 | capitalization: "uppercase", 308 | charset: "numeric", 309 | }) + 310 | `-${each.id}`, 311 | discount_type: "fixed_cart", 312 | amount: total_products_price_with_discount, 313 | individual_use: true, 314 | exclude_sale_items: false, 315 | minimum_amount: "300", 316 | usage_limit: 1, 317 | usage_limit_per_user: 1, 318 | description: "Campanha de CashBack para clientes Test", 319 | date_expires: (await WOODatePlus({ days: -3 })) as string, 320 | }; 321 | const coupons = await wooCommerce.post("coupons", coupom_data); 322 | 323 | expect(coupons).toBeInstanceOf(Object); 324 | 325 | if (coupons.headers["x-wp-totalpages"] > 1) { 326 | expect(coupons).toHaveProperty("data", expect.any(Array)); 327 | } 328 | if (coupons.data.length > 0) { 329 | const expectedKeys = Object.keys(couponsJson[0]); // Array of the keys of the couponsJson object 330 | const keys = Object.keys(coupons.data); // Array of the keys of the first coupon in the coupons.data array 331 | console.table([ 332 | { 333 | Keys: expectedKeys.length, 334 | Expected: keys.length, 335 | diff: expectedKeys.length - keys.length, 336 | couponID: coupons.data.id, 337 | }, 338 | ]); 339 | 340 | ConsoleMacthKeys(keys, expectedKeys); 341 | keys.forEach((key: any, index, array) => { 342 | expect(key).toEqual(expectedKeys[index]); 343 | }); 344 | } 345 | console.log(coupons.data); 346 | }, 20000); // 20 seconds 347 | 348 | test("should retrive a Coupon", async () => { 349 | const getAllCoupons = await wooCommerce.get("coupons"); 350 | 351 | if (getAllCoupons.headers["x-wp-totalpages"] > 1) { 352 | expect(getAllCoupons).toHaveProperty("data", expect.any(Array)); 353 | } 354 | const coupons = await wooCommerce.get("coupons", { 355 | code: getAllCoupons.data[0].id, 356 | }); 357 | console.log(coupons.data.code); 358 | 359 | expect(coupons).toBeInstanceOf(Object); 360 | 361 | if (coupons.headers["x-wp-totalpages"] > 1) { 362 | expect(coupons).toHaveProperty("data", expect.any(Array)); 363 | } 364 | 365 | if (coupons.data.length > 0) { 366 | const expectedKeys = Object.keys(couponsJson[0]); // Array of the keys of the couponsJson object 367 | const keys = Object.keys(coupons.data[0]); // Array of the keys of the first coupon in the coupons.data array 368 | console.table([ 369 | { 370 | Keys: expectedKeys.length, 371 | Expected: keys.length, 372 | diff: expectedKeys.length - keys.length, 373 | }, 374 | ]); 375 | ConsoleMacthKeys(keys, expectedKeys); 376 | keys.forEach((key: any, index) => { 377 | expect(key).toEqual(expectedKeys[index]); 378 | }); 379 | } 380 | }, 20000); // 20 seconds 381 | 382 | test("should update a Coupon", async () => { 383 | const getAllCoupons = await wooCommerce.get("coupons"); 384 | 385 | if (getAllCoupons.headers["x-wp-totalpages"] > 1) { 386 | expect(getAllCoupons).toHaveProperty("data", expect.any(Array)); 387 | } 388 | const coupons = await wooCommerce.put( 389 | "coupons", 390 | { 391 | description: 392 | "Campanha de CashBack para clientes Test - Updated - " + 393 | randomstring.generate({ 394 | length: 4, 395 | capitalization: "uppercase", 396 | charset: "alphanumeric", 397 | }), 398 | }, 399 | { 400 | id: getAllCoupons.data[0].id, 401 | } 402 | ); 403 | console.log(coupons.data); 404 | expect(coupons).toBeInstanceOf(Object); 405 | 406 | if (coupons.headers["x-wp-totalpages"] > 1) { 407 | expect(coupons).toHaveProperty("data", expect.any(Array)); 408 | } 409 | 410 | if (coupons.data.length > 0) { 411 | const expectedKeys = Object.keys(couponsJson[0]); // Array of the keys of the couponsJson object 412 | const keys = Object.keys(coupons.data[0]); // Array of the keys of the first coupon in the coupons.data array 413 | console.table([ 414 | { 415 | Keys: expectedKeys.length, 416 | Expected: keys.length, 417 | diff: expectedKeys.length - keys.length, 418 | }, 419 | ]); 420 | ConsoleMacthKeys(keys, expectedKeys); 421 | keys.forEach((key: any, index) => { 422 | expect(key).toEqual(expectedKeys[index]); 423 | }); 424 | } 425 | }, 20000); // 20 seconds 426 | 427 | test("should delete a Coupon", async () => { 428 | const getAllCoupons = await wooCommerce.get("coupons"); 429 | 430 | if (getAllCoupons.headers["x-wp-totalpages"] > 1) { 431 | expect(getAllCoupons).toHaveProperty("data", expect.any(Array)); 432 | } 433 | const coupons = await wooCommerce.delete( 434 | "coupons", 435 | { force: true }, 436 | { id: getAllCoupons.data[0].id } 437 | ); 438 | console.log(coupons.data); 439 | expect(coupons).toBeInstanceOf(Object); 440 | 441 | if (coupons.headers["x-wp-totalpages"] > 1) { 442 | expect(coupons).toHaveProperty("data", expect.any(Array)); 443 | } 444 | 445 | if (coupons.data.length > 0) { 446 | const expectedKeys = Object.keys(couponsJson[0]); // Array of the keys of the couponsJson object 447 | const keys = Object.keys(coupons.data[0]); // Array of the keys of the first coupon in the coupons.data array 448 | console.table([ 449 | { 450 | Keys: expectedKeys.length, 451 | Expected: keys.length, 452 | diff: expectedKeys.length - keys.length, 453 | }, 454 | ]); 455 | ConsoleMacthKeys(keys, expectedKeys); 456 | keys.forEach((key: any, index) => { 457 | expect(key).toEqual(expectedKeys[index]); 458 | }); 459 | } 460 | }, 20000); // 20 seconds 461 | }); 462 | 463 | describe.only("Test Products", () => { 464 | let wooCommerce: WooCommerceRestApi<{ 465 | url: string; 466 | consumerKey: string; 467 | consumerSecret: string; 468 | }>; 469 | beforeAll(() => { 470 | wooCommerce = new WooCommerceRestApi({ 471 | url: env.url, 472 | consumerKey: env.consumerKey, 473 | consumerSecret: env.consumerSecret, 474 | version: "wc/v3", 475 | queryStringAuth: false, 476 | }); 477 | }); 478 | test("should return a list with all products created", async () => { 479 | const products = await wooCommerce.get("products"); 480 | // console.log(products.data); 481 | expect(products).toBeInstanceOf(Object); 482 | if (products.headers["x-wp-totalpages"] > 1) { 483 | // eslint-disable-next-line jest/no-conditional-expect 484 | expect(products).toHaveProperty("data", expect.any(Array)); 485 | } 486 | if (products.data.length > 0) { 487 | const expectedKeys = Object.keys(productsJson[0]); // Array of the keys of the productsJson object 488 | const keys = Object.keys(products.data[0]); // Array of the keys of the first product in the products.data array 489 | console.table([ 490 | { 491 | Keys: expectedKeys.length, 492 | Expected: keys.length, 493 | diff: expectedKeys.length - keys.length, 494 | }, 495 | ]); 496 | ConsoleMacthKeys(keys, expectedKeys); 497 | keys.forEach((key: any, index) => { 498 | // eslint-disable-next-line jest/no-conditional-expect 499 | expect(key).toEqual(expectedKeys[index]); 500 | }); 501 | } 502 | }, 20000); // 20 seconds 503 | 504 | test("should create a new product", async () => { 505 | const data: ProductsMainParams = { 506 | name: "Premium Quality", 507 | type: "simple", 508 | regular_price: "21.99", 509 | description: 510 | "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", 511 | short_description: 512 | "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", 513 | categories: [ 514 | { 515 | id: 9, 516 | }, 517 | { 518 | id: 14, 519 | }, 520 | ], 521 | images: [ 522 | { 523 | src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg", 524 | }, 525 | { 526 | src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg", 527 | }, 528 | ], 529 | }; 530 | const products = await wooCommerce.post("products", data); 531 | expect(products).toBeInstanceOf(Object); 532 | if (products.headers["x-wp-totalpages"] > 1) { 533 | expect(products).toHaveProperty("data", expect.any(Array)); 534 | } 535 | if (products.data) { 536 | const expectedKeys = Object.keys(productsJsonResponse[0]); // Array of the keys of the productsJson object 537 | const keys = Object.keys(products.data); // Array of the keys of the first product in the products.data array 538 | console.table([ 539 | { 540 | Keys: expectedKeys.length, 541 | Expected: keys.length, 542 | diff: expectedKeys.length - keys.length, 543 | }, 544 | ]); 545 | ConsoleMacthKeys(keys, expectedKeys); 546 | keys.every((key: any, index) => { 547 | if (index === 4) return false; // only to test the first 4 keys, because the last key is the date of creation could be different 548 | expect(key).toEqual(expectedKeys[index]); 549 | }); 550 | } 551 | }, 20000); // 20 seconds 552 | 553 | test("should retrive a product", async () => { 554 | const getAllProducts = await wooCommerce.get("products"); 555 | 556 | if (getAllProducts.headers["x-wp-totalpages"] > 1) { 557 | expect(getAllProducts).toHaveProperty("data", expect.any(Array)); 558 | } 559 | const products = await wooCommerce.get("products", { 560 | id: getAllProducts.data[0].id, 561 | }); 562 | // console.log(products.data); 563 | 564 | expect(products).toBeInstanceOf(Object); 565 | 566 | if (products.headers["x-wp-totalpages"] > 1) { 567 | expect(products).toHaveProperty("data", expect.any(Array)); 568 | } 569 | 570 | if (products.data.length > 0) { 571 | const expectedKeys = Object.keys(productsJson[0]); // Array of the keys of the productsJson object 572 | const keys = Object.keys(products.data[0]); // Array of the keys of the first product in the products.data array 573 | console.table([ 574 | { 575 | Keys: expectedKeys.length, 576 | Expected: keys.length, 577 | diff: expectedKeys.length - keys.length, 578 | }, 579 | ]); 580 | ConsoleMacthKeys(keys, expectedKeys); 581 | keys.every((key: any, index) => { 582 | if (index === 4) return false; // only to test the first 4 keys, because the last key is the date of creation could be different 583 | expect(key).toEqual(expectedKeys[index]); 584 | }); 585 | } 586 | }, 20000); // 20 seconds 587 | 588 | test("should update/edit a product", async () => { 589 | const getAllProducts = await wooCommerce.get("products"); 590 | if (getAllProducts.headers["x-wp-totalpages"] > 1) { 591 | expect(getAllProducts).toHaveProperty("data", expect.any(Array)); 592 | } 593 | // Update the product 594 | const data: ProductsMainParams = { 595 | name: 596 | "Premium Quality Updated-" + 597 | randomstring.generate({ 598 | length: 4, 599 | capitalization: "uppercase", 600 | charset: "alphanumeric", 601 | }), 602 | type: "simple", 603 | regular_price: "30.22", 604 | description: 605 | "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", 606 | short_description: 607 | "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", 608 | categories: [ 609 | { 610 | id: 9, 611 | }, 612 | { 613 | id: 14, 614 | }, 615 | ], 616 | images: [ 617 | { 618 | src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg", 619 | }, 620 | { 621 | src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg", 622 | }, 623 | ], 624 | }; 625 | const products = await wooCommerce.put("products", data, { 626 | id: getAllProducts.data[0].id, 627 | }); 628 | expect(products).toBeInstanceOf(Object); 629 | if (products.headers["x-wp-totalpages"] > 1) { 630 | expect(products).toHaveProperty("data", expect.any(Array)); 631 | } 632 | if (products.data) { 633 | const expectedKeys = Object.keys(productsJsonResponse[0]); // Array of the keys of the productsJson object 634 | const keys = Object.keys(products.data); // Array of the keys of the first product in the products.data array 635 | console.table([ 636 | { 637 | Keys: expectedKeys.length, 638 | Expected: keys.length, 639 | diff: expectedKeys.length - keys.length, 640 | }, 641 | ]); 642 | ConsoleMacthKeys(keys, expectedKeys); 643 | keys.every((key: any, index) => { 644 | if (index === 4) return false; // only to test the first 4 keys, because the last key is the date of creation could be different 645 | expect(key).toEqual(expectedKeys[index]); 646 | }); 647 | } 648 | }, 20000); // 20 seconds 649 | 650 | test("should delete a product", async () => { 651 | const getAllProducts = await wooCommerce.get("products"); 652 | if (getAllProducts.headers["x-wp-totalpages"] > 1) { 653 | expect(getAllProducts).toHaveProperty("data", expect.any(Array)); 654 | } 655 | const products = await wooCommerce.delete( 656 | "products", 657 | { force: true }, 658 | { id: getAllProducts.data[0].id } 659 | ); 660 | expect(products).toBeInstanceOf(Object); 661 | if (products.headers["x-wp-totalpages"] > 1) { 662 | expect(products).toHaveProperty("data", expect.any(Array)); 663 | } 664 | if (products.data) { 665 | const expectedKeys = Object.keys(productsJsonResponse[0]); // Array of the keys of the productsJson object 666 | const keys = Object.keys(products.data); // Array of the keys of the first product in the products.data array 667 | console.table([ 668 | { 669 | Keys: expectedKeys.length, 670 | Expected: keys.length, 671 | diff: expectedKeys.length - keys.length, 672 | }, 673 | ]); 674 | ConsoleMacthKeys(keys, expectedKeys); 675 | keys.every((key: any, index) => { 676 | if (index === 4) return false; // only to test the first 4 keys, because the last key is the date of creation could be different 677 | expect(key).toEqual(expectedKeys[index]); 678 | }); 679 | } 680 | }, 20000); // 20 seconds 681 | }); 682 | 683 | describe.only("Test Orders", () => { 684 | let wooCommerce: WooCommerceRestApi<{ 685 | url: string; 686 | consumerKey: string; 687 | consumerSecret: string; 688 | }>; 689 | 690 | beforeAll(() => { 691 | wooCommerce = new WooCommerceRestApi({ 692 | url: env.url, 693 | consumerKey: env.consumerKey, 694 | consumerSecret: env.consumerSecret, 695 | version: "wc/v3", 696 | queryStringAuth: false, 697 | }); 698 | }); 699 | 700 | test("should get all orders", async () => { 701 | const orders = await wooCommerce.get("orders"); 702 | expect(orders).toBeInstanceOf(Object); 703 | if (orders.headers["x-wp-totalpages"] > 1) { 704 | expect(orders).toHaveProperty("data", expect.any(Array)); 705 | } 706 | if (orders.data.length > 0) { 707 | const expectedKeys = Object.keys(ordersJson[0]); // Array of the keys of the productsJson object 708 | const keys = Object.keys(orders.data[0]); // Array of the keys of the first product in the products.data array 709 | console.table([ 710 | { 711 | Keys: expectedKeys.length, 712 | Expected: keys.length, 713 | diff: expectedKeys.length - keys.length, 714 | }, 715 | ]); 716 | ConsoleMacthKeys(keys, expectedKeys); 717 | keys.every((key: any, index) => { 718 | if (index === 8) return false; // only to test the first 4 keys, because the last key is the date of creation could be different 719 | expect(key).toEqual(expectedKeys[index]); 720 | }); 721 | } 722 | }, 20000); // 20 seconds 723 | 724 | test("should get an order", async () => { 725 | const getAllOrders = await wooCommerce.get("orders"); 726 | if (getAllOrders.headers["x-wp-totalpages"] > 1) { 727 | expect(getAllOrders).toHaveProperty("data", expect.any(Array)); 728 | } 729 | // console.log("ID: ", getAllOrders.data[0].id); 730 | const orders = await wooCommerce.get("orders", { 731 | id: getAllOrders.data[0].id, 732 | }); 733 | // console.log("Order", orders.data); 734 | expect(orders).toBeInstanceOf(Object); 735 | if (orders.headers["x-wp-totalpages"] > 1) { 736 | expect(orders).toHaveProperty("data", expect.any(Array)); 737 | } 738 | if (orders.data) { 739 | const expectedKeys = Object.keys(ordersJson[0]); // Array of the keys of the productsJson object 740 | const keys = Object.keys(orders.data); // Array of the keys of the first product in the products.data array 741 | console.table([ 742 | { 743 | Keys: expectedKeys.length, 744 | Expected: keys.length, 745 | diff: expectedKeys.length - keys.length, 746 | }, 747 | ]); 748 | ConsoleMacthKeys(keys, expectedKeys); 749 | keys.every((key: any, index) => { 750 | if (index === 8) return false; // only to test the first 4 keys, because the last key is the date of creation could be different 751 | expect(key).toEqual(expectedKeys[index]); 752 | }); 753 | } 754 | }, 20000); // 20 seconds 755 | 756 | test("should create an order", async () => { 757 | const data: OrdersMainParams = { 758 | payment_method: "bacs", 759 | payment_method_title: "Direct Bank Transfer", 760 | set_paid: true, 761 | billing: { 762 | first_name: `John ${Math.random()}`, 763 | last_name: "Doe", 764 | address_1: "969 Market", 765 | address_2: "", 766 | city: "San Francisco", 767 | state: "CA", 768 | postcode: "94103", 769 | country: "US", 770 | email: "john.doe@example.com", 771 | phone: "85996859001", 772 | company: "WooCommerce", 773 | }, 774 | shipping: { 775 | first_name: "John", 776 | last_name: "Doe", 777 | address_1: "969 Market", 778 | address_2: "", 779 | city: "San Francisco", 780 | state: "CA", 781 | postcode: "94103", 782 | country: "US", 783 | company: "WooCommerce", 784 | }, 785 | line_items: [ 786 | { 787 | product_id: 93, 788 | quantity: 2, 789 | }, 790 | { 791 | product_id: 22, 792 | variation_id: 23, 793 | quantity: 1, 794 | }, 795 | ], 796 | shipping_lines: [ 797 | { 798 | method_id: "flat_rate", 799 | method_title: "Flat Rate", 800 | total: "10.00", 801 | }, 802 | ], 803 | }; 804 | const order = await wooCommerce.post("orders", data); 805 | // console.log("Order", order.data); 806 | expect(order).toBeInstanceOf(Object); 807 | if (order.headers["x-wp-totalpages"] > 1) { 808 | expect(order).toHaveProperty("data", expect.any(Array)); 809 | } 810 | if (order.data) { 811 | const expectedKeys = Object.keys(ordersJson[0]); // Array of the keys of the productsJson object 812 | const keys = Object.keys(order.data); // Array of the keys of the first product in the products.data array 813 | console.table([ 814 | { 815 | Keys: expectedKeys.length, 816 | Expected: keys.length, 817 | diff: expectedKeys.length - keys.length, 818 | }, 819 | ]); 820 | ConsoleMacthKeys(keys, expectedKeys); 821 | keys.every((key: any, index) => { 822 | if (index === 4) return false; // only to test the first 4 keys, because the last key is the date of creation could be different 823 | expect(key).toEqual(expectedKeys[index]); 824 | }); 825 | } 826 | }, 20000); // 20 seconds 827 | 828 | test("should update an order", async () => { 829 | const getAllCoupons = await wooCommerce.get("orders"); 830 | if (getAllCoupons.headers["x-wp-totalpages"] > 1) { 831 | expect(getAllCoupons).toHaveProperty("data", expect.any(Array)); 832 | } 833 | const data: OrdersMainParams = { 834 | payment_method: "bacs", 835 | payment_method_title: "Direct Bank Transfer", 836 | set_paid: true, 837 | billing: { 838 | first_name: `Yuri ${Math.random()}`, 839 | last_name: "Doe", 840 | address_1: "969 Market", 841 | address_2: "", 842 | city: "San Francisco", 843 | }, 844 | }; 845 | const order = await wooCommerce.put("orders", data, { 846 | id: getAllCoupons.data[0].id, 847 | }); 848 | // console.log("Order", order.data); 849 | expect(order).toBeInstanceOf(Object); 850 | if (order.headers["x-wp-totalpages"] > 1) { 851 | expect(order).toHaveProperty("data", expect.any(Array)); 852 | } 853 | if (order.data) { 854 | const expectedKeys = Object.keys(ordersJson[0]); // Array of the keys of the productsJson object 855 | const keys = Object.keys(order.data); // Array of the keys of the first product in the products.data array 856 | console.table([ 857 | { 858 | Keys: expectedKeys.length, 859 | Expected: keys.length, 860 | diff: expectedKeys.length - keys.length, 861 | }, 862 | ]); 863 | ConsoleMacthKeys(keys, expectedKeys); 864 | keys.every((key: any, index) => { 865 | if (index === 4) return false; // only to test the first 4 keys, because the last key is the date of creation could be different 866 | expect(key).toEqual(expectedKeys[index]); 867 | }); 868 | } 869 | }, 20000); // 20 seconds 870 | 871 | test("should delete an order", async () => { 872 | const getAllCoupons = await wooCommerce.get("orders"); 873 | if (getAllCoupons.headers["x-wp-totalpages"] > 1) { 874 | expect(getAllCoupons).toHaveProperty("data", expect.any(Array)); 875 | } 876 | const order = await wooCommerce.delete( 877 | "orders", 878 | { force: true }, 879 | { id: getAllCoupons.data[0].id } 880 | ); 881 | console.log("Order", order.data); 882 | expect(order).toBeInstanceOf(Object); 883 | if (order.headers["x-wp-totalpages"] > 1) { 884 | expect(order).toHaveProperty("data", expect.any(Array)); 885 | } 886 | if (order.data) { 887 | const expectedKeys = Object.keys(ordersJson[0]); // Array of the keys of the productsJson object 888 | const keys = Object.keys(order.data); // Array of the keys of the first product in the products.data array 889 | console.table([ 890 | { 891 | Keys: expectedKeys.length, 892 | Expected: keys.length, 893 | diff: expectedKeys.length - keys.length, 894 | }, 895 | ]); 896 | ConsoleMacthKeys(keys, expectedKeys); 897 | keys.every((key: any, index) => { 898 | if (index === 4) return false; // only to test the first 4 keys, because the last key is the date of creation could be different 899 | expect(key).toEqual(expectedKeys[index]); 900 | }); 901 | } 902 | }, 20000); // 20 seconds 903 | }); 904 | 905 | describe("Test Customers", () => { 906 | let wooCommerce: WooCommerceRestApi<{ 907 | url: string; 908 | consumerKey: string; 909 | consumerSecret: string; 910 | }>; 911 | 912 | beforeAll(() => { 913 | wooCommerce = new WooCommerceRestApi({ 914 | url: env.url, 915 | consumerKey: env.consumerKey, 916 | consumerSecret: env.consumerSecret, 917 | version: "wc/v3", 918 | queryStringAuth: false, 919 | }); 920 | }); 921 | 922 | test.only("should get all customers", async () => { 923 | const customers = await wooCommerce.get("customers"); 924 | // console.log("Customers", customers.data[0]); 925 | 926 | expect(customers).toBeInstanceOf(Object); 927 | if (customers.headers["x-wp-totalpages"] > 1) { 928 | expect(customers).toHaveProperty("data", expect.any(Array)); 929 | } 930 | if (customers.data) { 931 | const expectedKeys = Object.keys(constomersJson[0]); // Array of the keys of the productsJson object 932 | const keys = Object.keys(customers.data[0]); // Array of the keys of the first product in the products.data array 933 | console.table([ 934 | { 935 | Keys: expectedKeys.length, 936 | Expected: keys.length, 937 | diff: expectedKeys.length - keys.length, 938 | }, 939 | ]); 940 | ConsoleMacthKeys(keys, expectedKeys); 941 | keys.every((key: any, index) => { 942 | if (index === 8) return false; // only to test the first 4 keys, because the last key is the date of creation could be different 943 | expect(key).toEqual(expectedKeys[index]); 944 | }); 945 | } 946 | }, 20000); // 20 seconds 947 | 948 | test.only("should get a customer", async () => { 949 | const getAllCustomers = await wooCommerce.get("customers"); 950 | if (getAllCustomers.headers["x-wp-totalpages"] > 1) { 951 | expect(getAllCustomers).toHaveProperty("data", expect.any(Array)); 952 | } 953 | const customer = await wooCommerce.get("customers", { 954 | id: getAllCustomers.data[0].id, 955 | }); 956 | console.log("Customer", customer.data); 957 | expect(customer).toBeInstanceOf(Object); 958 | if (customer.headers["x-wp-totalpages"] > 1) { 959 | expect(customer).toHaveProperty("data", expect.any(Array)); 960 | } 961 | if (customer.data) { 962 | const expectedKeys = Object.keys(constomersJson[0]); // Array of the keys of the productsJson object 963 | const keys = Object.keys(customer.data); // Array of the keys of the first product in the products.data array 964 | console.table([ 965 | { 966 | Keys: expectedKeys.length, 967 | Expected: keys.length, 968 | diff: expectedKeys.length - keys.length, 969 | }, 970 | ]); 971 | ConsoleMacthKeys(keys, expectedKeys); 972 | keys.every((key: any, index) => { 973 | if (index === 8) return false; // only to test the first 4 keys, because the last key is the date of creation could be different 974 | expect(key).toEqual(expectedKeys[index]); 975 | }); 976 | } 977 | }, 20000); // 20 seconds 978 | 979 | // Probably this test is failling because of permissions #TODO 980 | test("should create a customer", async () => { 981 | const data = { 982 | email: "john.doe@example.com", 983 | first_name: `Yuri`, 984 | last_name: "Doe", 985 | username: "john.doe", 986 | billing: { 987 | first_name: "John", 988 | last_name: "Doe", 989 | company: "", 990 | address_1: "969 Market", 991 | address_2: "", 992 | city: "San Francisco", 993 | state: "CA", 994 | postcode: "94103", 995 | country: "US", 996 | email: "john.doe@example.com", 997 | phone: "85996859001", 998 | number: "123", 999 | neighborhood: "123", 1000 | }, 1001 | shipping: { 1002 | first_name: "John", 1003 | last_name: "Doe", 1004 | company: "", 1005 | address_1: "969 Market", 1006 | address_2: "", 1007 | city: "San Francisco", 1008 | state: "CA", 1009 | postcode: "94103", 1010 | country: "US", 1011 | phone: "85996859001", 1012 | number: "123", 1013 | neighborhood: "123", 1014 | }, 1015 | }; 1016 | const customer = await wooCommerce.post("customers", data); 1017 | console.log("Customer", customer.data); 1018 | expect(customer).toBeInstanceOf(Object); 1019 | if (customer.headers["x-wp-totalpages"] > 1) { 1020 | expect(customer).toHaveProperty("data", expect.any(Array)); 1021 | } 1022 | if (customer.data) { 1023 | const expectedKeys = Object.keys(constomersJsonResponse[0]); // Array of the keys of the productsJson object 1024 | const keys = Object.keys(customer.data); // Array of the keys of the first product in the products.data array 1025 | console.table([ 1026 | { 1027 | Keys: expectedKeys.length, 1028 | Expected: keys.length, 1029 | diff: expectedKeys.length - keys.length, 1030 | }, 1031 | ]); 1032 | ConsoleMacthKeys(keys, expectedKeys); 1033 | keys.every((key: any, index) => { 1034 | if (index === 8) return false; // only to test the first 4 keys, because the last key is the date of creation could be different 1035 | expect(key).toEqual(expectedKeys[index]); 1036 | }); 1037 | } 1038 | }, 20000); // 20 seconds 1039 | 1040 | // Probably this test is failling because of permissions #TODO 1041 | test("should update a customer", async () => { 1042 | const getAllCustomers = await wooCommerce.get("customers"); 1043 | if (getAllCustomers.headers["x-wp-totalpages"] > 1) { 1044 | expect(getAllCustomers).toHaveProperty("data", expect.any(Array)); 1045 | } 1046 | const data = { 1047 | email: "y.m.limaTEST@gmail.com", 1048 | first_name: `Yuri`, 1049 | last_name: "Doe", 1050 | username: "john.doe", 1051 | billing: { 1052 | first_name: "John", 1053 | last_name: "Doe", 1054 | company: "", 1055 | address_1: "969 Market", 1056 | address_2: "", 1057 | city: "San Francisco", 1058 | state: "CA", 1059 | postcode: "94103", 1060 | country: "US", 1061 | }, 1062 | shipping: { 1063 | first_name: "John", 1064 | last_name: "Doe", 1065 | company: "", 1066 | address_1: "969 Market", 1067 | address_2: "", 1068 | city: "San Francisco", 1069 | state: "CA", 1070 | postcode: "94103", 1071 | country: "US", 1072 | }, 1073 | }; 1074 | const customer = await wooCommerce.put("customers", { 1075 | id: getAllCustomers.data[0].id, 1076 | data, 1077 | }); 1078 | console.log("Customer", customer.data); 1079 | expect(customer).toBeInstanceOf(Object); 1080 | if (customer.headers["x-wp-totalpages"] > 1) { 1081 | expect(customer).toHaveProperty("data", expect.any(Array)); 1082 | } 1083 | if (customer.data) { 1084 | const expectedKeys = Object.keys(constomersJsonResponse[0]); // Array of the keys of the productsJson object 1085 | const keys = Object.keys(customer.data); // Array of the keys of the first product in the products.data array 1086 | console.table([ 1087 | { 1088 | Keys: expectedKeys.length, 1089 | Expected: keys.length, 1090 | diff: expectedKeys.length - keys.length, 1091 | }, 1092 | ]); 1093 | ConsoleMacthKeys(keys, expectedKeys); 1094 | keys.every((key: any, index) => { 1095 | if (index === 8) return false; // only to test the first 4 keys, because the last key is the date of creation could be different 1096 | expect(key).toEqual(expectedKeys[index]); 1097 | }); 1098 | } 1099 | }, 20000); // 20 seconds 1100 | 1101 | test.only("should delete a customer", async () => { 1102 | const getAllCustomers = await wooCommerce.get("customers"); 1103 | if (getAllCustomers.headers["x-wp-totalpages"] > 1) { 1104 | expect(getAllCustomers).toHaveProperty("data", expect.any(Array)); 1105 | } 1106 | const customer = await wooCommerce.delete( 1107 | "customers", 1108 | { force: true }, 1109 | { id: getAllCustomers.data[0].id } 1110 | ); 1111 | console.log("Customer", customer.data); 1112 | expect(customer).toBeInstanceOf(Object); 1113 | if (customer.headers["x-wp-totalpages"] > 1) { 1114 | expect(customer).toHaveProperty("data", expect.any(Array)); 1115 | } 1116 | if (customer.data) { 1117 | const expectedKeys = Object.keys(constomersJsonResponse[0]); // Array of the keys of the productsJson object 1118 | const keys = Object.keys(customer.data); // Array of the keys of the first product in the products.data array 1119 | console.table([ 1120 | { 1121 | Keys: expectedKeys.length, 1122 | Expected: keys.length, 1123 | diff: expectedKeys.length - keys.length, 1124 | }, 1125 | ]); 1126 | ConsoleMacthKeys(keys, expectedKeys); 1127 | keys.every((key: any, index) => { 1128 | if (index === 8) return false; // only to test the first 4 keys, because the last key is the date of creation could be different 1129 | expect(key).toEqual(expectedKeys[index]); 1130 | }); 1131 | } 1132 | }, 20000); // 20 seconds 1133 | }); 1134 | 1135 | function ConsoleMacthKeys(keys: string[], expectedKeys: string[]) { 1136 | const arr = Array(); 1137 | keys.forEach((key: any, index, array) => { 1138 | arr.push(keys[index]); 1139 | if (index === keys.length - 1) { 1140 | const table = arr.map((key, index) => { 1141 | return { 1142 | Keys: key, 1143 | Expected: expectedKeys[index], 1144 | Macth: key === expectedKeys[index] ? "OK" : "ERROR", 1145 | }; 1146 | }); 1147 | const table2 = [ 1148 | { 1149 | Keys: keys.length, 1150 | Expected: expectedKeys.length, 1151 | Macth: keys.length === expectedKeys.length ? "OK" : "ERROR", 1152 | }, 1153 | ]; 1154 | console.table(table); 1155 | console.table(table2); 1156 | } 1157 | }); 1158 | } 1159 | -------------------------------------------------------------------------------- /src/typesANDinterfaces.ts: -------------------------------------------------------------------------------- 1 | export declare type WooRestApiVersion = "wc/v3"; 2 | // | "wc/v2" 3 | // | "wc/v1" 4 | // | "wc-api/v3" 5 | // | "wc-api/v2" 6 | // | "wc-api/v1"; 7 | export declare type WooRestApiEncoding = "utf-8" | "ascii"; 8 | export declare type WooRestApiMethod = 9 | | "GET" 10 | | "POST" 11 | | "PUT" 12 | | "DELETE" 13 | | "OPTIONS"; 14 | 15 | export declare type WooRestApiEndpoint = 16 | | "coupons" 17 | | "customers" 18 | | "orders" 19 | | "products" 20 | | "products/attributes" 21 | | "products/categories" 22 | | "products/shipping_classes" 23 | | "products/tags" 24 | | "products/reviews" 25 | | "system_status" 26 | | "reports" // TODO: add support for reports 27 | | "settings" // TODO: add support for settings 28 | | "webhooks" // TODO: add support for webhooks 29 | | "shipping" // TODO: add support for shipping 30 | | "shipping_methods" // TODO: add support for shipping_methods 31 | | "taxes" // TODO: add support for taxes 32 | | "payment_gateways" // TODO: add support for payment_gateways 33 | | string; // I need to have next endpoint: "orders//notes" 34 | 35 | export declare type IWooRestApiQuery = Record; 36 | 37 | export type IWooCredentials = { 38 | /* Your API consumer key */ 39 | consumerKey: string; 40 | /* Your API consumer secret */ 41 | consumerSecret: string; 42 | }; 43 | 44 | export type WooCommerceRestApiTypeFunctions = { 45 | get: (endpoint: string, params?: T) => Promise; 46 | post: (endpoint: string, params?: T) => Promise; 47 | put: (endpoint: string, params?: T) => Promise; 48 | delete: (endpoint: string, params?: T) => Promise; 49 | }; 50 | 51 | export interface IWooRestApiOptions extends IWooCredentials { 52 | /* Your Store URL, example: http://woo.dev/ */ 53 | url: string; 54 | 55 | /* Custom WP REST API URL prefix, used to support custom prefixes created with the `rest_url_prefix filter` */ 56 | wpAPIPrefix?: string; 57 | 58 | /* API version, default is `v3` */ 59 | version?: WooRestApiVersion; 60 | 61 | /* Encoding, default is 'utf-8' */ 62 | encoding?: WooRestApiEncoding; 63 | 64 | /* When `true` and using under HTTPS force Basic Authentication as query string, default is `false` */ 65 | queryStringAuth?: boolean; 66 | 67 | /* Provide support for URLs with ports, eg: `8080` */ 68 | port?: number; 69 | 70 | /* Provide support for custom timeout, eg: `5000` */ 71 | timeout?: number; 72 | 73 | /* Define the custom Axios config, also override this library options */ 74 | axiosConfig?: T; 75 | 76 | /* Version of this library */ 77 | classVersion?: string; 78 | 79 | /* Https or Http */ 80 | isHttps?: boolean; 81 | } 82 | 83 | /* Start of the Types */ 84 | export type Meta_Data = { 85 | id: number; 86 | key: string; 87 | value: string; 88 | }; 89 | 90 | export type Links = { 91 | self: Array<{ 92 | href: string; 93 | }>; 94 | collection: Array<{ 95 | href: string; 96 | }>; 97 | up: Array<{ 98 | href: string; 99 | }>; 100 | }; 101 | 102 | export type Billing = { 103 | first_name: string; 104 | last_name: string; 105 | company: string; 106 | address_1: string; 107 | address_2: string; 108 | city: string; 109 | state: string; 110 | postcode: string; 111 | country: string; 112 | email: string; 113 | phone: string; 114 | }; 115 | 116 | export type Shipping = { 117 | first_name: string; 118 | last_name: string; 119 | company: string; 120 | address_1: string; 121 | address_2: string; 122 | city: string; 123 | state: string; 124 | postcode: string; 125 | country: string; 126 | }; 127 | 128 | export type Taxes = { 129 | id: number; 130 | rate_code: string; 131 | rate_id: number; 132 | label: string; 133 | compound: boolean; 134 | tax_total: string; 135 | shipping_tax_total: string; 136 | meta_data: Meta_Data; 137 | }; 138 | 139 | export type Shipping_Lines = { 140 | id: number; 141 | method_title: string; 142 | method_id: string; 143 | total: string; 144 | total_tax: string; 145 | taxes: Taxes[]; 146 | meta_data: Meta_Data; 147 | }; 148 | 149 | export type Line_Items = { 150 | id: number; 151 | name: string; 152 | product_id: number; 153 | variation_id: number; 154 | quantity: number; 155 | tax_class: string; 156 | subtotal: string; 157 | subtotal_tax: string; 158 | total: string; 159 | total_tax: string; 160 | taxes: Taxes[]; 161 | meta_data: Meta_Data; 162 | sku: string; 163 | price: number; 164 | }; 165 | 166 | export type Tax_Lines = { 167 | id: number; 168 | rate_code: string; 169 | rate_id: number; 170 | label: string; 171 | compound: boolean; 172 | tax_total: string; 173 | shipping_tax_total: string; 174 | meta_data: Partial; 175 | }; 176 | 177 | export type Fee_Lines = { 178 | id: number; 179 | name: string; 180 | tax_class: string; 181 | tax_status: string; 182 | total: string; 183 | total_tax: string; 184 | taxes: Partial[]; 185 | meta_data: Partial; 186 | }; 187 | 188 | export type Coupon_Lines = { 189 | id: number; 190 | code: string; 191 | discount: string; 192 | discount_tax: string; 193 | meta_data: Partial; 194 | }; 195 | 196 | export type Refunds = { 197 | id: number; 198 | reason: string; 199 | total: string; 200 | }; 201 | 202 | export type Orders_Refunds_Lines = { 203 | id: number; 204 | total: string; 205 | subtotal: string; 206 | refund_total: number; 207 | }; 208 | 209 | export type Orders_Refunds_Line_Items = { 210 | id: number; 211 | name: string; 212 | product_id: number; 213 | variation_id: number; 214 | quantity: number; 215 | tax_class: string; 216 | subtotal: string; 217 | subtotal_tax: string; 218 | total: string; 219 | total_tax: string; 220 | taxes: Partial[]; 221 | meta_data: Partial[]; 222 | sku: string; 223 | price: string; 224 | refund_total: number; 225 | }; 226 | 227 | export type Downloads = { 228 | id: number; 229 | name: string; 230 | file: string; 231 | }; 232 | 233 | export type Dimensions = { 234 | length: string; 235 | width: string; 236 | height: string; 237 | }; 238 | 239 | export type Categories = { 240 | id: number; 241 | name: string; 242 | slug: string; 243 | }; 244 | 245 | export type Tags = { 246 | id: number; 247 | name: string; 248 | slug: string; 249 | }; 250 | 251 | export type Images = { 252 | id: number; 253 | date_created: Date; 254 | date_created_gmt: Date; 255 | date_modified: Date; 256 | date_modified_gmt: Date; 257 | src: string; 258 | name: string; 259 | alt: string; 260 | }; 261 | 262 | export type Attributes = { 263 | id: number; 264 | name: string; 265 | position: number; 266 | visible: boolean; 267 | variation: boolean; 268 | options: string[]; 269 | }; 270 | 271 | export type Default_Attributes = { 272 | id: number; 273 | name: string; 274 | option: string; 275 | }; 276 | 277 | export type SystemStatusEnvironment = { 278 | home_url: string; 279 | site_url: string; 280 | wc_version: string; 281 | log_directory: string; 282 | log_directory_writable: boolean; 283 | wp_version: string; 284 | wp_multisite: boolean; 285 | wp_memory_limit: number; 286 | wp_debug_mode: boolean; 287 | wp_cron: boolean; 288 | language: string; 289 | server_info: string; 290 | php_version: string; 291 | php_post_max_size: number; 292 | php_max_execution_time: number; 293 | php_max_input_vars: number; 294 | curl_version: string; 295 | suhosin_installed: boolean; 296 | max_upload_size: number; 297 | mysql_version: string; 298 | default_timezone: string; 299 | fsockopen_or_curl_enabled: boolean; 300 | soapclient_enabled: boolean; 301 | domdocument_enabled: boolean; 302 | gzip_enabled: boolean; 303 | mbstring_enabled: boolean; 304 | remote_post_successful: boolean; 305 | remote_post_response: string; 306 | remote_get_successful: boolean; 307 | remote_get_response: string; 308 | }; 309 | 310 | export type SystemStatusDatabase = { 311 | wc_database_version: string; 312 | database_prefix: string; 313 | maxmind_geoip_database: string; 314 | database_tables: string[]; 315 | }; 316 | 317 | export type SystemStatusTheme = { 318 | name: string; 319 | version: string; 320 | version_latest: string; 321 | author_url: string; 322 | is_child_theme: boolean; 323 | parent_theme_name: string; 324 | has_woocommerce_support: boolean; 325 | has_woocommerce_file: boolean; 326 | has_outdated_templates: boolean; 327 | overrides: string[]; 328 | parent_name: string; 329 | parent_version: string; 330 | parent_author_url: string; 331 | }; 332 | 333 | export type SystemStatusSettings = { 334 | api_enabled: boolean; 335 | force_ssl: boolean; 336 | currency: string; 337 | currency_symbol: string; 338 | currency_position: string; 339 | thousand_separator: string; 340 | decimal_separator: string; 341 | number_of_decimals: number; 342 | geolocate_enabled: boolean; 343 | taxnomies: string[]; 344 | }; 345 | 346 | export type SystemStatusSecurity = { 347 | secure_connection: boolean; 348 | hide_errors: boolean; 349 | }; 350 | /* End of Types */ 351 | 352 | export interface DELETE { 353 | id: number | string; 354 | force?: boolean | string; 355 | } 356 | 357 | /* Start of Interfaces */ 358 | export interface Coupons { 359 | id: number; 360 | code: string; 361 | amount: string; 362 | date_created: Date; 363 | date_created_gmt: Date; 364 | date_modified: Date; 365 | date_modified_gmt: Date; 366 | discount_type: string; 367 | description: string; 368 | date_expires: string; 369 | date_expires_gmt: string; 370 | usage_count: number; 371 | individual_use: boolean; 372 | product_ids: number[]; 373 | excluded_product_ids: number[]; 374 | usage_limit: number; 375 | usage_limit_per_user: number; 376 | limit_usage_to_x_items: number; 377 | free_shipping: boolean; 378 | product_categories: number[]; 379 | excluded_product_categories: number[]; 380 | exclude_sale_items: boolean; 381 | minimum_amount: string; 382 | maximum_amount: string; 383 | email_restrictions: string[]; 384 | used_by: string[]; 385 | meta_data: Meta_Data[]; 386 | } 387 | 388 | export interface Customers { 389 | id: number; 390 | date_created: Date; 391 | date_created_gmt: Date; 392 | date_modified: Date; 393 | date_modified_gmt: Date; 394 | email: string; 395 | first_name: string; 396 | last_name: string; 397 | role: string; 398 | username: string; 399 | billing: Billing; 400 | shipping: Shipping; 401 | is_paying_customer: boolean; 402 | avatar_url: string; 403 | meta_data: Meta_Data[]; 404 | } 405 | 406 | export interface Orders { 407 | id: number; 408 | parent_id: number; 409 | number: string; 410 | order_key: string; 411 | created_via: string; 412 | version: string; 413 | status: string; 414 | currency: string; 415 | date_created: Date; 416 | date_created_gmt: Date; 417 | date_modified: Date; 418 | date_modified_gmt: Date; 419 | discount_total: string; 420 | discount_tax: string; 421 | shipping_total: string; 422 | shipping_tax: string; 423 | cart_tax: string; 424 | total: string; 425 | total_tax: string; 426 | prices_include_tax: boolean; 427 | customer_id: number; 428 | customer_ip_address: string; 429 | customer_user_agent: string; 430 | customer_note: string; 431 | billing: Partial; 432 | shipping: Shipping; 433 | payment_method: string; 434 | payment_method_title: string; 435 | transaction_id: string; 436 | date_paid: string; 437 | date_paid_gmt: string; 438 | date_completed: string; 439 | date_completed_gmt: string; 440 | cart_hash: string; 441 | meta_data: Partial[]; 442 | line_items: Partial[]; 443 | tax_lines: Partial[]; 444 | shipping_lines: Partial[]; 445 | fee_lines: Partial[]; 446 | coupon_lines: Partial[]; 447 | refunds: Partial[]; 448 | set_paid: boolean; 449 | } 450 | export interface OrdersNotes { 451 | id: number; 452 | author: string; 453 | date_created: Date; 454 | date_created_gmt: Date; 455 | note: string; 456 | customer_note: boolean; 457 | added_by_user: boolean; 458 | } 459 | 460 | export interface OrdersRefunds { 461 | id: number; 462 | date_created: Date; 463 | date_created_gmt: Date; 464 | amount: string; 465 | reason: string; 466 | refunded_by: number; 467 | refunded_payment: boolean; 468 | meta_data: Partial[]; 469 | line_items: Partial[]; 470 | api_refund: boolean; 471 | } 472 | 473 | export interface Products { 474 | id: number; 475 | name: string; 476 | slug: string; 477 | permalink: string; 478 | date_created: Date; 479 | date_created_gmt: Date; 480 | date_modified: Date; 481 | date_modified_gmt: Date; 482 | catalog_visibility: string; 483 | description: string; 484 | short_description: string; 485 | price: string; 486 | regular_price: string; 487 | sale_price: string; 488 | date_on_sale_from: Date; 489 | date_on_sale_from_gmt: Date; 490 | date_on_sale_to: Date; 491 | date_on_sale_to_gmt: Date; 492 | price_html: string; 493 | purchasable: boolean; 494 | total_sales: number; 495 | virtual: boolean; 496 | downloadable: boolean; 497 | downloads: Partial[]; 498 | download_limit: number; 499 | download_expiry: number; 500 | external_url: string; 501 | button_text: string; 502 | tax_status: string; 503 | manage_stock: boolean; 504 | stock_quantity: number; 505 | backorders: string; 506 | backorders_allowed: boolean; 507 | backordered: boolean; 508 | sold_individually: boolean; 509 | weight: string; 510 | dimensions: Partial; 511 | shipping_required: boolean; 512 | shipping_taxable: boolean; 513 | shipping_class: string; 514 | shipping_class_id: number; 515 | reviews_allowed: boolean; 516 | average_rating: string; 517 | rating_count: number; 518 | related_ids: number[]; 519 | upsell_ids: number[]; 520 | cross_sell_ids: number[]; 521 | parent_id: number; 522 | purchase_note: string; 523 | categories: Partial[]; 524 | tags: Partial[]; 525 | images: Partial[]; 526 | attributes: Partial[]; 527 | default_attributes: Partial[]; 528 | variations: number[]; 529 | grouped_products: number[]; 530 | menu_order: number; 531 | meta_data: Partial[]; 532 | per_page: number; 533 | page: number; 534 | context: "views" | "edit" | string; 535 | search: string; 536 | after: string; 537 | before: string; 538 | modified_after: string; 539 | modified_before: string; 540 | dates_are_gmt: boolean; 541 | exclude: number[]; 542 | include: number[]; 543 | offset: number; 544 | order: "asc" | "desc" | string; 545 | orderby: 546 | | "id" 547 | | "include" 548 | | "name" 549 | | "date" 550 | | "title" 551 | | "slug" 552 | | "price" 553 | | "popularity" 554 | | "rating" 555 | | string; 556 | parent: number[]; 557 | parent_exclude: number[]; 558 | status: "draft" | "any" | "pending" | "publish" | "private" | string; 559 | type: "simple" | "grouped" | "external" | "variable" | string; 560 | sku: string; 561 | featured: boolean; 562 | category: string; 563 | tag: string; 564 | attribute: string; 565 | attribute_term: string; 566 | tax_class: string; 567 | on_sale: boolean; 568 | min_price: string; 569 | max_price: string; 570 | stock_status: "instock" | "outofstock" | "onbackorder" | string; 571 | } 572 | 573 | export interface ProductsVariations { 574 | id: number; 575 | date_created: Date; 576 | date_created_gmt: Date; 577 | date_modified: Date; 578 | date_modified_gmt: Date; 579 | description: string; 580 | permalink: string; 581 | sku: string; 582 | price: string; 583 | regular_price: string; 584 | sale_price: string; 585 | date_on_sale_from: Date; 586 | date_on_sale_from_gmt: Date; 587 | date_on_sale_to: Date; 588 | date_on_sale_to_gmt: Date; 589 | on_sale: boolean; 590 | status: string; 591 | purchasable: boolean; 592 | virtual: boolean; 593 | downloadable: boolean; 594 | downloads: Partial[]; 595 | download_limit: number; 596 | download_expiry: number; 597 | tax_status: string; 598 | tax_class: string; 599 | manage_stock: boolean; 600 | stock_quantity: number; 601 | stock_status: string; 602 | backorders: string; 603 | backorders_allowed: boolean; 604 | backordered: boolean; 605 | weight: string; 606 | dimensions: Partial; 607 | shipping_class: string; 608 | shipping_class_id: number; 609 | image: Partial; 610 | attributes: Partial[]; 611 | menu_order: number; 612 | meta_data: Partial[]; 613 | } 614 | 615 | export interface ProductsAttributes { 616 | id: number; 617 | name: string; 618 | slug: string; 619 | type: string; 620 | order_by: string; 621 | has_archives: boolean; 622 | } 623 | 624 | export interface ProductsAttributesTerms { 625 | id: number; 626 | name: string; 627 | slug: string; 628 | description: string; 629 | menu_order: number; 630 | count: number; 631 | } 632 | 633 | export interface ProductsCategories { 634 | id: number; 635 | name: string; 636 | slug: string; 637 | parent: number; 638 | description: string; 639 | display: string; 640 | image: Partial; 641 | menu_order: number; 642 | count: number; 643 | } 644 | 645 | export interface ProductsShippingClasses { 646 | id: number; 647 | name: string; 648 | slug: string; 649 | description: string; 650 | count: number; 651 | } 652 | 653 | export interface ProductsTags { 654 | id: number; 655 | name: string; 656 | slug: string; 657 | description: string; 658 | count: number; 659 | } 660 | 661 | export interface ProductsReviews { 662 | id: number; 663 | date_created: Date; 664 | date_created_gmt: Date; 665 | parent_id: number; 666 | status: string; 667 | reviewer: string; 668 | reviewer_email: string; 669 | review: string; 670 | verified: boolean; 671 | } 672 | 673 | // interface Reports {} // TODO 674 | // interface ReportsCoupons {} // TODO 675 | // interface ReportsCustomers {} // TODO 676 | // interface ReportsOrders {} // TODO 677 | // interface ReportsProducts {} // TODO 678 | // interface ReportsReviews {} // TODO 679 | // interface ReportsTopSellers {} // TODO 680 | // interface ReportsSales {} // TODO 681 | 682 | export interface TaxRates { 683 | id: number; 684 | country: string; 685 | state: string; 686 | postcode: string; 687 | city: string; 688 | postcodes: string[]; 689 | cities: string[]; 690 | rate: string; 691 | name: string; 692 | priority: number; 693 | compound: boolean; 694 | shipping: boolean; 695 | order: number; 696 | class: string; 697 | } 698 | 699 | export interface TaxClasses { 700 | slug: string; 701 | name: string; 702 | } 703 | 704 | export interface Webhooks { 705 | id: number; 706 | name: string; 707 | status: "all" | "active" | "paused" | "disabled" | string; 708 | topic: string; 709 | resource: string; 710 | event: string; 711 | hooks: string[]; 712 | delivery_url: string; 713 | secret: string; 714 | date_created: Date; 715 | date_created_gmt: Date; 716 | date_modified: Date; 717 | date_modified_gmt: Date; 718 | links: Partial; 719 | context: "view" | "edit" | string; 720 | page: 1 | number; 721 | per_page: 10 | 25 | 50 | 100 | number; 722 | search: string; 723 | after: string; 724 | before: string; 725 | exclude: number[]; 726 | include: number[]; 727 | offset: number; 728 | order: "asc" | "desc" | string; 729 | orderby: "id" | "include" | "name" | "date" | "title" | "slug" | string; 730 | force: boolean; 731 | } 732 | 733 | export interface Settings { 734 | id: string; 735 | label: string; 736 | description: string; 737 | parent_id: string; 738 | sub_groups: string[]; 739 | } 740 | 741 | export interface SettingsOptions { 742 | id: string; 743 | label: string; 744 | description: string; 745 | type: string; 746 | default: string; 747 | options: { 748 | [key: string]: string; 749 | }; 750 | tip: string; 751 | value: string; 752 | group_id: string; 753 | } 754 | 755 | export interface PaymentGatewaysSettings { 756 | id: string; 757 | label: string; 758 | description: string; 759 | type: "text" | "email" | "number" | "color" | "password" | "textarea" | "select" | "multiselect" | "radio" | "image_width" | "checkbox"; 760 | value: string; 761 | default: string; 762 | tip: string; 763 | placeholder: string; 764 | } 765 | 766 | export interface PaymentGateways { 767 | id: string; 768 | title: string; 769 | description: string; 770 | order: number; 771 | enabled: boolean; 772 | method_title: string; 773 | method_description: string; 774 | method_supports: string[]; 775 | settings: Partial[]; 776 | } 777 | 778 | export interface ShippingZones { 779 | id: number; 780 | name: string; 781 | order: number; 782 | } 783 | 784 | export interface ShippingZonesLocations { 785 | code: string; 786 | type: "postcode" | "state" | "country" | "continent" 787 | } 788 | 789 | export interface ShippingZonesMethodsSettings { 790 | id: string; 791 | label: string; 792 | description: string; 793 | type: "text" | "email" | "number" | "color" | "password" | "textarea" | "select" | "multiselect" | "radio" | "image_width" | "checkbox"; 794 | value: string; 795 | default: string; 796 | tip: string; 797 | placeholder: string; 798 | } 799 | 800 | export interface ShippingZonesMethods { 801 | instace_id: number; 802 | title: string; 803 | order: number; 804 | enabled: boolean; 805 | method_id: string; 806 | method_title: string; 807 | method_description: string; 808 | method_supports: Partial[]; 809 | } 810 | 811 | export interface ShippingMethods { 812 | id: string; 813 | title: string; 814 | description: string; 815 | } 816 | 817 | export interface SystemStatus { 818 | environment: Partial; 819 | database: Partial; 820 | active_plugins: string[]; 821 | theme: Partial; 822 | settings: Partial; 823 | security: Partial; 824 | pages: string[]; 825 | } 826 | // interface SystemStatusTools {} // TODO 827 | // interface Data {} // TODO 828 | 829 | export type CouponsParams = Partial; // Partial means all properties are optional [Temporary] 830 | 831 | export type CustomersParams = Partial; // Partial means all properties are optional [Temporary] 832 | 833 | export type OrdersParams = Partial; // Partial means all properties are optional [Temporary] 834 | export type OrdersNotesParams = Partial; // Partial means all properties are optional [Temporary] 835 | export type OrdersRefundsParams = Partial; // Partial means all properties are optional [Temporary] 836 | /** 837 | * Union type for all possible params for Orders 838 | */ 839 | export type OrdersMainParams = OrdersParams & 840 | OrdersNotesParams & 841 | OrdersRefundsParams; // Partial means all properties are optional [Temporary] 842 | 843 | // Products 844 | type ProductsParams = Partial; // Partial means all properties are optional [Temporary] 845 | type ProductsVariationsParams = Partial; // Partial means all properties are optional [Temporary] 846 | type ProductsAttributesParams = Partial; // Partial means all properties are optional [Temporary] 847 | type ProductsAttributesTermsParams = Partial; // Partial means all properties are optional [Temporary] 848 | type ProductsCategoriesParams = Partial; // Partial means all properties are optional [Temporary] 849 | type ProductsShippingClassesParams = Partial; // Partial means all properties are optional [Temporary] 850 | type ProductsTagsParams = Partial; // Partial means all properties are optional [Temporary] 851 | type ProductsReviewsParams = Partial; // Partial means all properties are optional [Temporary] 852 | 853 | /** 854 | * Union type for all possible params for Products 855 | */ 856 | export type ProductsMainParams = 857 | | (ProductsParams & ProductsVariationsParams & ProductsAttributesParams) 858 | | ProductsAttributesTermsParams 859 | | ProductsCategoriesParams 860 | | ProductsShippingClassesParams 861 | | ProductsTagsParams 862 | | ProductsReviewsParams; // Partial means all properties are optional [Temporary] 863 | 864 | 865 | // Tax 866 | export type TaxRatesParams = Partial; // Partial means all properties are optional [Temporary] 867 | export type TaxClassesParams = Partial; // Partial means all properties are optional [Temporary] 868 | 869 | // Settings 870 | export type SettingsParams = Partial; // Partial means all properties are optional [Temporary] 871 | export type SettingsOptionsParams = Partial; // Partial means all properties are optional [Temporary] 872 | 873 | // Payment Gateways 874 | export type PaymentGatewaysParams = Partial; // Partial means all properties are optional [Temporary] 875 | export type PaymentGatewaysSettingsParams = Partial; // Partial means all properties are optional [Temporary] 876 | 877 | // Shipping 878 | export type ShippingZonesParams = Partial; // Partial means all properties are optional [Temporary] 879 | export type ShippingZonesLocationsParams = Partial; // Partial means all properties are optional [Temporary] 880 | export type ShippingZonesMethodsParams = Partial; // Partial means all properties are optional [Temporary] 881 | export type ShippingMethodsParams = Partial; // Partial means all properties are optional [Temporary] 882 | 883 | // SystemStatus 884 | export type SystemStatusParams = Partial; // Partial means all properties are optional [Temporary8] 885 | 886 | // Webhooks 887 | export type WebhooksParams = Partial; // Partial means all properties are optional [Temporary] 888 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Projects */ 4 | "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ 5 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 6 | // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ 7 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ 8 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 9 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 10 | 11 | /* Language and Environment */ 12 | "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ 13 | // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ 14 | // "jsx": "preserve", /* Specify what JSX code is generated. */ 15 | "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ 16 | "emitDecoratorMetadata": false, /* Emit design-type metadata for decorated declarations in source files. */ 17 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ 18 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 19 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ 20 | // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ 21 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 22 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 23 | // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ 24 | 25 | /* Modules */ 26 | "module": "NodeNext", /* Specify what module code is generated. */ 27 | "rootDir": "./", /* Specify the root folder within your source files. */ 28 | "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ 29 | "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ 30 | "paths": { 31 | "crypto": [ 32 | "node_modules/crypto-js" 33 | ] 34 | }, /* Specify a set of entries that re-map imports to additional lookup locations. */ 35 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 36 | "typeRoots": [ 37 | "./node_modules/@types", 38 | "./src/types" 39 | ], /* Specify multiple folders that act like './node_modules/@types'. */ 40 | // "types": [], /* Specify type package names to be included without being referenced in a source file. */ 41 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 42 | // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ 43 | "resolveJsonModule": true, /* Enable importing .json files. */ 44 | // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ 45 | 46 | /* JavaScript Support */ 47 | "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ 48 | "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 49 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ 50 | 51 | /* Emit */ 52 | "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 53 | "declarationMap": true, /* Create sourcemaps for d.ts files. */ 54 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 55 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 56 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ 57 | "outDir": "./dist", /* Specify an output folder for all emitted files. */ 58 | "removeComments": true, /* Disable emitting comments. */ 59 | // "noEmit": true, /* Disable emitting files from a compilation. */ 60 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 61 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ 62 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 63 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 64 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 65 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 66 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 67 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 68 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 69 | // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ 70 | // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ 71 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 72 | // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ 73 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 74 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ 75 | 76 | /* Interop Constraints */ 77 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ 78 | "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ 79 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ 80 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 81 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ 82 | 83 | /* Type Checking */ 84 | "strict": true, /* Enable all strict type-checking options. */ 85 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ 86 | // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ 87 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 88 | // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ 89 | "strictPropertyInitialization": false, /* Check for class properties that are declared but not set in the constructor. */ 90 | // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ 91 | // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ 92 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 93 | "noUnusedLocals": false, /* Enable error reporting when local variables aren't read. */ 94 | "noUnusedParameters": false, /* Raise an error when a function parameter isn't read. */ 95 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 96 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 97 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 98 | // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ 99 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 100 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ 101 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 102 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 103 | 104 | /* Completeness */ 105 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 106 | "skipLibCheck": true /* Skip type checking all .d.ts files. */ 107 | }, 108 | "files": [ 109 | "src/index.ts" 110 | ], 111 | "include": [ 112 | "src/**/*.ts" 113 | , "config/jsonTOenv.ts"], 114 | "exclude": [ 115 | "node_modules", 116 | "dist", 117 | "lib", 118 | "configs", 119 | "test", 120 | ] 121 | } 122 | --------------------------------------------------------------------------------