├── .gitignore ├── CHANGELOG ├── LICENSE ├── README.md ├── composer.json ├── example ├── composer-example.php └── example.php └── lib ├── woocommerce-api.php └── woocommerce-api ├── class-wc-api-client-authentication.php ├── class-wc-api-client-http-request.php ├── class-wc-api-client.php ├── exceptions ├── class-wc-api-client-exception.php └── class-wc-api-client-http-exception.php └── resources ├── abstract-wc-api-client-resource.php ├── class-wc-api-client-resource-coupons.php ├── class-wc-api-client-resource-custom.php ├── class-wc-api-client-resource-customers.php ├── class-wc-api-client-resource-index.php ├── class-wc-api-client-resource-order-notes.php ├── class-wc-api-client-resource-order-refunds.php ├── class-wc-api-client-resource-orders.php ├── class-wc-api-client-resource-products.php ├── class-wc-api-client-resource-reports.php └── class-wc-api-client-resource-webhooks.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | ## Changelog 2 | 3 | **version 2.0.1 - 2015-07-13** 4 | - Fix composer configuration 5 | 6 | **version 2.0.0 - 2015-05-05** 7 | - Add support for v2 API (v1 is no longer supported) 8 | - Greatly improved error handling and logging 9 | - Add store URL validation 10 | 11 | **version 0.3.1 - 2014-05-02** 12 | 13 | - Fix parameter normalization issue with WC 2.1.7+ 14 | 15 | **version 0.3 - 2014-02-20** 16 | 17 | - Add HTTP error messages on failed cURL calls 18 | 19 | **version 0.2 - 2014-01-22** 20 | 21 | - Add support for filters/params to endpoint functions 22 | - Add new top sellers report endpoint function 23 | - Add function to call custom endpoints 24 | 25 | **version 0.1 - 2013-12-10** 26 | 27 | - Initial release 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | WooCommerce REST API PHP Client Library 2 | ======================================= 3 | 4 | ## About 5 | 6 | A PHP wrapper for the WooCommerce REST API. Easily interact with the WooCommerce REST API using this library. 7 | 8 | Feedback and bug reports are appreciated. 9 | 10 | ## Requirements 11 | 12 | PHP 5.2.x 13 | cURL 14 | WooCommerce 2.2 at least on the store 15 | 16 | ## Getting started 17 | 18 | Generate API credentials (Consumer Key & Consumer Secret) under WP Admin > Your Profile. 19 | 20 | ## Setup the library 21 | 22 | ```php 23 | require_once( 'lib/woocommerce-api.php' ); 24 | 25 | $options = array( 26 | 'ssl_verify' => false, 27 | ); 28 | 29 | try { 30 | 31 | $client = new WC_API_Client( 'http://your-store-url.com', $consumer_key, $consumer_secret, $options ); 32 | 33 | } catch ( WC_API_Client_Exception $e ) { 34 | 35 | echo $e->getMessage() . PHP_EOL; 36 | echo $e->getCode() . PHP_EOL; 37 | 38 | if ( $e instanceof WC_API_Client_HTTP_Exception ) { 39 | 40 | print_r( $e->get_request() ); 41 | print_r( $e->get_response() ); 42 | } 43 | } 44 | ``` 45 | 46 | ### Options 47 | 48 | * `debug` (default `false`) - set to `true` to add request/response information to the returned data. This is particularly useful for troubleshooting errors. 49 | 50 | * `return_as_array` (default `false`) - all methods return data as a `stdClass` by default, but you can set this option to `true` to return data as an associative array instead. 51 | 52 | * `validate_url` (default `false`) - set this to `true` to verify that the URL provided has a valid, parseable WC API index, and optionally force SSL when supported. 53 | 54 | * `timeout` (default `30`) - set this to control the HTTP timeout for requests. 55 | 56 | * `ssl_verify` (default `true`) - set this to `false` if you don't want to perform SSL peer verification for every request. 57 | 58 | 59 | ### Error handling 60 | Exceptions are thrown when errors are encountered, most will be instances of `WC_API_Client_HTTP_Exception` which has two additional methods, `get_request()` and `get_response()` -- these return the request and response objects to help with debugging. 61 | 62 | 63 | ## Methods 64 | 65 | ### Index 66 | 67 | * `$client->index->get()` - get the API index 68 | 69 | ### Orders 70 | 71 | * `$client->orders->get()` - get a list of orders 72 | * `$client->orders->get( null, array( 'status' => 'completed' ) )` - get a list of completed orders 73 | * `$client->orders->get( $order_id )` - get a single order 74 | 75 | 76 | ## Credit 77 | 78 | Copyright (c) 2013-2014 - [Gerhard Potgieter](http://gerhardpotgieter.com/), [Max Rice](http://maxrice.com) and other contributors 79 | 80 | ## License 81 | Released under the [GPL3 license](http://www.gnu.org/licenses/gpl-3.0.html) 82 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "woothemes/woocommerce-api", 3 | "description": "A client library for the WooCommerce REST API", 4 | "license": "GPL v3", 5 | "authors": [ 6 | { 7 | "name": "Max Rice", 8 | "email": "max@maxrice.com" 9 | }, 10 | { 11 | "name": "Gerhard Potgieter" 12 | } 13 | ], 14 | "autoload": { 15 | "classmap": ["lib/woocommerce-api"] 16 | }, 17 | "minimum-stability": "stable", 18 | "require": { 19 | "php": ">= 5.2.0", 20 | "ext-curl": "*", 21 | "ext-json": "*" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /example/composer-example.php: -------------------------------------------------------------------------------- 1 | true, 8 | 'return_as_array' => false, 9 | 'validate_url' => false, 10 | 'timeout' => 30, 11 | 'ssl_verify' => false, 12 | ); 13 | 14 | try { 15 | $client = new WC_API_Client( 16 | 'http://your-store-url.com', 17 | 'ck_enter_your_consumer_key', 18 | 'cs_enter_your_consumer_secret', 19 | $options 20 | ); 21 | 22 | // index 23 | //print_r($client->index->get()); 24 | 25 | // For other endpoints, see example.php 26 | 27 | } catch (WC_API_Client_Exception $e) { 28 | echo $e->getMessage() . PHP_EOL; 29 | echo $e->getCode() . PHP_EOL; 30 | 31 | if ($e instanceof WC_API_Client_HTTP_Exception) { 32 | print_r($e->get_request()); 33 | print_r($e->get_response()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /example/example.php: -------------------------------------------------------------------------------- 1 | true, 7 | 'return_as_array' => false, 8 | 'validate_url' => false, 9 | 'timeout' => 30, 10 | 'ssl_verify' => false, 11 | ); 12 | 13 | try { 14 | 15 | $client = new WC_API_Client( 'http://your-store-url.com', 'ck_enter_your_consumer_key', 'cs_enter_your_consumer_secret', $options ); 16 | 17 | // coupons 18 | //print_r( $client->coupons->get() ); 19 | //print_r( $client->coupons->get( $coupon_id ) ); 20 | //print_r( $client->coupons->get_by_code( 'coupon-code' ) ); 21 | //print_r( $client->coupons->create( array( 'code' => 'test-coupon', 'type' => 'fixed_cart', 'amount' => 10 ) ) ); 22 | //print_r( $client->coupons->update( $coupon_id, array( 'description' => 'new description' ) ) ); 23 | //print_r( $client->coupons->delete( $coupon_id ) ); 24 | //print_r( $client->coupons->get_count() ); 25 | 26 | // custom 27 | //$client->custom->setup( 'webhooks', 'webhook' ); 28 | //print_r( $client->custom->get( $params ) ); 29 | 30 | // customers 31 | //print_r( $client->customers->get() ); 32 | //print_r( $client->customers->get( $customer_id ) ); 33 | //print_r( $client->customers->get_by_email( 'help@woothemes.com' ) ); 34 | //print_r( $client->customers->create( array( 'email' => 'woothemes@mailinator.com' ) ) ); 35 | //print_r( $client->customers->update( $customer_id, array( 'first_name' => 'John', 'last_name' => 'Galt' ) ) ); 36 | //print_r( $client->customers->delete( $customer_id ) ); 37 | //print_r( $client->customers->get_count( array( 'filter[limit]' => '-1' ) ) ); 38 | //print_r( $client->customers->get_orders( $customer_id ) ); 39 | //print_r( $client->customers->get_downloads( $customer_id ) ); 40 | //$customer = $client->customers->get( $customer_id ); 41 | //$customer->customer->last_name = 'New Last Name'; 42 | //print_r( $client->customers->update( $customer_id, (array) $customer ) ); 43 | 44 | // index 45 | //print_r( $client->index->get() ); 46 | 47 | // orders 48 | //print_r( $client->orders->get() ); 49 | //print_r( $client->orders->get( $order_id ) ); 50 | //print_r( $client->orders->update_status( $order_id, 'pending' ) ); 51 | 52 | // order notes 53 | //print_r( $client->order_notes->get( $order_id ) ); 54 | //print_r( $client->order_notes->create( $order_id, array( 'note' => 'Some order note' ) ) ); 55 | //print_r( $client->order_notes->update( $order_id, $note_id, array( 'note' => 'An updated order note' ) ) ); 56 | //print_r( $client->order_notes->delete( $order_id, $note_id ) ); 57 | 58 | // order refunds 59 | //print_r( $client->order_refunds->get( $order_id ) ); 60 | //print_r( $client->order_refunds->get( $order_id, $refund_id ) ); 61 | //print_r( $client->order_refunds->create( $order_id, array( 'amount' => 1.00, 'reason' => 'cancellation' ) ) ); 62 | //print_r( $client->order_refunds->update( $order_id, $refund_id, array( 'reason' => 'who knows' ) ) ); 63 | //print_r( $client->order_refunds->delete( $order_id, $refund_id ) ); 64 | 65 | // products 66 | //print_r( $client->products->get() ); 67 | //print_r( $client->products->get( $product_id ) ); 68 | //print_r( $client->products->get( $variation_id ) ); 69 | //print_r( $client->products->get_by_sku( 'a-product-sku' ) ); 70 | //print_r( $client->products->create( array( 'title' => 'Test Product', 'type' => 'simple', 'regular_price' => '9.99', 'description' => 'test' ) ) ); 71 | //print_r( $client->products->update( $product_id, array( 'title' => 'Yet another test product' ) ) ); 72 | //print_r( $client->products->delete( $product_id, true ) ); 73 | //print_r( $client->products->get_count() ); 74 | //print_r( $client->products->get_count( array( 'type' => 'simple' ) ) ); 75 | //print_r( $client->products->get_categories() ); 76 | //print_r( $client->products->get_categories( $category_id ) ); 77 | 78 | // reports 79 | //print_r( $client->reports->get() ); 80 | //print_r( $client->reports->get_sales( array( 'filter[date_min]' => '2014-07-01' ) ) ); 81 | //print_r( $client->reports->get_top_sellers( array( 'filter[date_min]' => '2014-07-01' ) ) ); 82 | 83 | // webhooks 84 | //print_r( $client->webhooks->get() ); 85 | //print_r( $client->webhooks->create( array( 'topic' => 'coupon.created', 'delivery_url' => 'http://requestb.in/' ) ) ); 86 | //print_r( $client->webhooks->update( $webhook_id, array( 'secret' => 'some_secret' ) ) ); 87 | //print_r( $client->webhooks->delete( $webhook_id ) ); 88 | //print_r( $client->webhooks->get_count() ); 89 | //print_r( $client->webhooks->get_deliveries( $webhook_id ) ); 90 | //print_r( $client->webhooks->get_delivery( $webhook_id, $delivery_id ); 91 | 92 | // trigger an error 93 | //print_r( $client->orders->get( 0 ) ); 94 | 95 | } catch ( WC_API_Client_Exception $e ) { 96 | 97 | echo $e->getMessage() . PHP_EOL; 98 | echo $e->getCode() . PHP_EOL; 99 | 100 | if ( $e instanceof WC_API_Client_HTTP_Exception ) { 101 | 102 | print_r( $e->get_request() ); 103 | print_r( $e->get_response() ); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /lib/woocommerce-api.php: -------------------------------------------------------------------------------- 1 | url = $url; 36 | $this->consumer_key = $consumer_key; 37 | $this->consumer_secret = $consumer_secret; 38 | } 39 | 40 | 41 | /** 42 | * Generate the parameters required for OAuth 1.0a authentication 43 | * 44 | * @since 2.0 45 | * @param $params 46 | * @param $method 47 | * @return array 48 | */ 49 | public function get_oauth_params( $params, $method ) { 50 | 51 | $params = array_merge( $params, array( 52 | 'oauth_consumer_key' => $this->consumer_key, 53 | 'oauth_timestamp' => time(), 54 | 'oauth_nonce' => sha1( microtime() ), 55 | 'oauth_signature_method' => 'HMAC-' . self::HASH_ALGORITHM, 56 | ) ); 57 | 58 | // the params above must be included in the signature generation 59 | $params['oauth_signature'] = $this->generate_oauth_signature( $params, $method ); 60 | 61 | return $params; 62 | } 63 | 64 | 65 | 66 | /** 67 | * Generate OAuth signature, see server-side method here: 68 | * 69 | * @link https://github.com/woothemes/woocommerce/blob/master/includes/api/class-wc-api-authentication.php#L196-L252 70 | * 71 | * @since 2.0 72 | * 73 | * @param array $params query parameters (including oauth_*) 74 | * @param string $http_method, e.g. GET 75 | * @return string signature 76 | */ 77 | public function generate_oauth_signature( $params, $http_method ) { 78 | 79 | $base_request_uri = rawurlencode( $this->url ); 80 | 81 | if ( isset( $params['filter'] ) ) { 82 | $filters = $params['filter']; 83 | unset( $params['filter'] ); 84 | foreach ( $filters as $filter => $filter_value ) { 85 | $params['filter[' . $filter . ']'] = $filter_value; 86 | } 87 | } 88 | 89 | // normalize parameter key/values and sort them 90 | $params = $this->normalize_parameters( $params ); 91 | uksort( $params, 'strcmp' ); 92 | 93 | // form query string 94 | $query_params = array(); 95 | foreach ( $params as $param_key => $param_value ) { 96 | $query_params[] = $param_key . '%3D' . $param_value; // join with equals sign 97 | } 98 | 99 | $query_string = implode( '%26', $query_params ); // join with ampersand 100 | 101 | // form string to sign (first key) 102 | $string_to_sign = $http_method . '&' . $base_request_uri . '&' . $query_string; 103 | 104 | return base64_encode( hash_hmac( self::HASH_ALGORITHM, $string_to_sign, $this->consumer_secret, true ) ); 105 | } 106 | 107 | 108 | /** 109 | * Normalize each parameter by assuming each parameter may have already been 110 | * encoded, so attempt to decode, and then re-encode according to RFC 3986 111 | * 112 | * Note both the key and value is normalized so a filter param like: 113 | * 114 | * 'filter[period]' => 'week' 115 | * 116 | * is encoded to: 117 | * 118 | * 'filter%5Bperiod%5D' => 'week' 119 | * 120 | * This conforms to the OAuth 1.0a spec which indicates the entire query string 121 | * should be URL encoded 122 | * 123 | * Modeled after the core method here: 124 | * 125 | * @link https://github.com/woothemes/woocommerce/blob/master/includes/api/class-wc-api-authentication.php#L254-L288 126 | * 127 | * @since 2.0 128 | * @see rawurlencode() 129 | * @param array $parameters un-normalized pararmeters 130 | * @return array normalized parameters 131 | */ 132 | private function normalize_parameters( $parameters ) { 133 | 134 | $normalized_parameters = array(); 135 | 136 | foreach ( $parameters as $key => $value ) { 137 | 138 | // percent symbols (%) must be double-encoded 139 | $key = str_replace( '%', '%25', rawurlencode( rawurldecode( $key ) ) ); 140 | $value = str_replace( '%', '%25', rawurlencode( rawurldecode( $value ) ) ); 141 | 142 | $normalized_parameters[ $key ] = $value; 143 | } 144 | 145 | return $normalized_parameters; 146 | } 147 | 148 | 149 | /** 150 | * Returns true if accessing the API over SSL, primarily used to determine 151 | * which authentication mechanism should be used (HTTP Basic Auth or OAuth) 152 | * 153 | * @since 2.0 154 | * @return bool 155 | */ 156 | public function is_ssl() { 157 | 158 | return substr( $this->url, 0, 5 ) === 'https'; 159 | } 160 | 161 | 162 | /** 163 | * Return the consumer key 164 | * 165 | * @since 2.0 166 | * @return string 167 | */ 168 | public function get_consumer_key() { 169 | return $this->consumer_key; 170 | } 171 | 172 | 173 | /** 174 | * Return the consumer secret 175 | * 176 | * @since 2.0 177 | * @return string 178 | */ 179 | public function get_consumer_secret() { 180 | return $this->consumer_secret; 181 | } 182 | 183 | 184 | } 185 | -------------------------------------------------------------------------------- /lib/woocommerce-api/class-wc-api-client-http-request.php: -------------------------------------------------------------------------------- 1 | request = new stdClass(); 40 | 41 | $this->request->headers = array( 42 | 'Accept: application/json', 43 | 'Content-Type: application/json', 44 | 'User-Agent: WooCommerce API Client-PHP/' . WC_API_Client::VERSION, 45 | ); 46 | 47 | // GET, POST, PUT, DELETE, etc. 48 | $this->request->method = $args['method']; 49 | 50 | // trailing slashes tend to cause OAuth authentication issues, so strip them 51 | $this->request->url = rtrim( $args['url'], '/' ); 52 | 53 | $this->request->params = array(); 54 | $this->request->data = $args['data']; 55 | 56 | // JSON output format 57 | $this->json_decode_as_array = ( 'array' === $args['options']['json_decode'] ); 58 | 59 | // debug mode? 60 | $this->debug = (bool) $args['options']['debug']; 61 | 62 | // optional cURL opts 63 | $timeout = (int) $args['options']['timeout']; 64 | $ssl_verify = (bool) $args['options']['ssl_verify']; 65 | 66 | $this->ch = curl_init(); 67 | 68 | // default cURL opts 69 | curl_setopt( $this->ch, CURLOPT_SSL_VERIFYPEER, $ssl_verify ); 70 | curl_setopt( $this->ch, CURLOPT_SSL_VERIFYHOST, $ssl_verify ); 71 | curl_setopt( $this->ch, CURLOPT_CONNECTTIMEOUT, $timeout ); 72 | curl_setopt( $this->ch, CURLOPT_TIMEOUT, (int) $timeout ); 73 | curl_setopt( $this->ch, CURLOPT_RETURNTRANSFER, true ); 74 | 75 | // set request headers 76 | curl_setopt( $this->ch, CURLOPT_HTTPHEADER, $this->request->headers ); 77 | 78 | // save response headers 79 | curl_setopt( $this->ch, CURLOPT_HEADERFUNCTION, array( $this, 'curl_stream_headers' ) ); 80 | 81 | // set request method and data 82 | switch ( $this->request->method ) { 83 | 84 | case 'GET': 85 | $this->request->body = null; 86 | $this->request->params = (array) $this->request->data; 87 | break; 88 | 89 | case 'PUT': 90 | $this->request->body = json_encode( $this->request->data ); 91 | curl_setopt( $this->ch, CURLOPT_CUSTOMREQUEST, 'PUT' ); 92 | curl_setopt( $this->ch, CURLOPT_POSTFIELDS, $this->request->body ); 93 | break; 94 | 95 | case 'POST': 96 | $this->request->body = json_encode( $this->request->data ); 97 | curl_setopt( $this->ch, CURLOPT_POST, true ); 98 | curl_setopt( $this->ch, CURLOPT_POSTFIELDS, $this->request->body ); 99 | break; 100 | 101 | case 'DELETE': 102 | $this->request->body = null; 103 | $this->request->params = (array) $this->request->data; 104 | curl_setopt( $this->ch, CURLOPT_CUSTOMREQUEST, 'DELETE' ); 105 | break; 106 | } 107 | 108 | // auth 109 | $this->request->url = $this->get_url_with_auth( $args['consumer_key'], $args['consumer_secret'] ); 110 | 111 | // set request url 112 | curl_setopt( $this->ch, CURLOPT_URL, $this->request->url ); 113 | } 114 | 115 | 116 | /** 117 | * Set authentication parameters for the request 118 | * 119 | * @since 2.0 120 | * @param string $consumer_key API consumer key 121 | * @param string $consumer_secret API consumer secret 122 | * @return string request URL with authentication parameters added 123 | */ 124 | protected function get_url_with_auth( $consumer_key, $consumer_secret ) { 125 | 126 | $auth = new WC_API_Client_Authentication( $this->request->url, $consumer_key, $consumer_secret ); 127 | 128 | if ( $auth->is_ssl() ) { 129 | 130 | // query string authentication over SSL works with all servers, whereas HTTP basic auth fails in certain cases 131 | // see https://github.com/kloon/WooCommerce-REST-API-Client-Library/issues/29 132 | $this->request->params = array_merge( $this->request->params, array( 133 | 'consumer_key' => $auth->get_consumer_key(), 134 | 'consumer_secret' => $auth->get_consumer_secret(), 135 | ) ); 136 | 137 | } else { 138 | 139 | $this->request->params = array_merge( $this->request->params, $auth->get_oauth_params( $this->request->params, $this->request->method ) ); 140 | } 141 | 142 | // build url 143 | return $this->request->url . ( ! empty( $this->request->params ) ? '?' . http_build_query( $this->request->params ) : '' ); 144 | } 145 | 146 | 147 | /** 148 | * Send the request 149 | * 150 | * @since 2.0 151 | * @return object|array result 152 | * @throws WC_API_Client_HTTP_Exception invalid decoded JSON or any non-HTTP 200/201 response 153 | */ 154 | public function dispatch() { 155 | 156 | $this->response = new stdClass(); 157 | 158 | // blank headers 159 | $this->curl_headers = ''; 160 | 161 | $start_time = microtime( true ); 162 | 163 | // send request + save raw response body 164 | $this->response->body = curl_exec( $this->ch ); 165 | 166 | // request duration 167 | $this->request->duration = round( microtime( true ) - $start_time, 5 ); 168 | 169 | // response code 170 | $this->response->code = curl_getinfo( $this->ch, CURLINFO_HTTP_CODE ); 171 | 172 | // response headers 173 | $this->response->headers = $this->get_response_headers(); 174 | 175 | curl_close( $this->ch ); 176 | 177 | $parsed_response = $this->get_parsed_response( $this->response->body ); 178 | 179 | // check for invalid JSON 180 | if ( null === $parsed_response ) { 181 | 182 | throw new WC_API_Client_HTTP_Exception( sprintf( 'Invalid JSON returned for %s.', $this->request->url ), $this->response->code, $this->request, $this->response ); 183 | } 184 | 185 | // any non-200/201/202 response code indicates an error 186 | if ( ! in_array( $this->response->code, array( '200', '201', '202' ) ) ) { 187 | 188 | // error message/code is nested sometimes 189 | if ( $this->json_decode_as_array ) { 190 | 191 | list( $error_message, $error_code ) = is_array( $parsed_response['errors'] ) ? array( 192 | $parsed_response['errors'][0]['message'], 193 | $parsed_response['errors'][0]['code'] 194 | ) : array( 195 | $parsed_response['errors']['message'], 196 | $parsed_response['errors']['code'] 197 | ); 198 | 199 | } else { 200 | 201 | list( $error_message, $error_code ) = is_array( $parsed_response->errors ) ? array( 202 | $parsed_response->errors[0]->message, 203 | $parsed_response->errors[0]->code 204 | ) : array( 205 | $parsed_response->errors->message, 206 | $parsed_response->errors->code 207 | ); 208 | } 209 | 210 | throw new WC_API_Client_HTTP_Exception( sprintf( 'Error: %s [%s]', $error_message, $error_code ), $this->response->code, $this->request, $this->response); 211 | } 212 | 213 | return $this->build_result( $parsed_response ); 214 | } 215 | 216 | 217 | /** 218 | * JSON decode the response body after stripping any invalid leading or 219 | * trailing characters. 220 | * 221 | * Plugins (looking at you WP Super Cache) or themes 222 | * can add output to the returned JSON which breaks decoding. 223 | * 224 | * @since 2.0 225 | * @param string $raw_body raw response body 226 | * @return object|array JSON decoded response body 227 | */ 228 | protected function get_parsed_response( $raw_body ) { 229 | 230 | $json_start = strpos( $raw_body, '{' ); 231 | $json_end = strrpos( $raw_body, '}' ) + 1; // inclusive 232 | 233 | $json = substr( $raw_body, $json_start, ( $json_end - $json_start ) ); 234 | 235 | return json_decode( $json, $this->json_decode_as_array ); 236 | } 237 | 238 | 239 | /** 240 | * Build the result object/array 241 | * 242 | * @since 2.0.0 243 | * @param object|array JSON decoded result 244 | * @return object|array in format: 245 | * { 246 | * 247 | * 'http' => 248 | * 'request' => stdClass( 249 | * 'url' => request URL 250 | * 'method' => request method 251 | * 'body' => JSON encoded request body entity 252 | * 'headers' => array of request headers 253 | * 'duration' => request duration, in seconds 254 | * 'params' => optional raw params 255 | * 'data' => optional raw request data 256 | * 'duration' => 257 | * ) 258 | * 'response' => stdClass( 259 | * 'body' => raw response body 260 | * 'code' => HTTP response code 261 | * 'headers' => HTTP response headers in assoc array 262 | * ) 263 | * } 264 | */ 265 | protected function build_result( $parsed_response ) { 266 | 267 | // add cURL log, HTTP request/response object 268 | if ( $this->debug ) { 269 | 270 | if ( $this->json_decode_as_array ) { 271 | 272 | $parsed_response['http'] = array( 273 | 'request' => json_decode( json_encode( $this->request ), true ), 274 | 'response' => json_decode( json_encode( $this->response ), true ), 275 | ); 276 | 277 | } else { 278 | 279 | $parsed_response->http = new stdClass(); 280 | $parsed_response->http->request = $this->request; 281 | $parsed_response->http->response = $this->response; 282 | } 283 | } 284 | 285 | return $parsed_response; 286 | } 287 | 288 | 289 | /** 290 | * Save the cURL response headers for later processing 291 | * 292 | * @since 2.0 293 | * @see WP_Http_Curl::stream_headers() 294 | * @param object $_ the cURL resource handle (unused) 295 | * @param string $headers the current response headers 296 | * @return int the size of the processed headers 297 | */ 298 | public function curl_stream_headers( $_, $headers ) { 299 | 300 | $this->curl_headers .= $headers; 301 | return strlen( $headers ); 302 | } 303 | 304 | 305 | /** 306 | * Parse the raw response headers into an assoc array in format: 307 | * { 308 | * 'Header-Key' => header value 309 | * 'Duplicate-Key' => array( 310 | * 0 => value 1 311 | * 1 => value 2 312 | * ) 313 | * } 314 | * 315 | * @since 2.0 316 | * @see WP_HTTP::processHeaders 317 | * @return array 318 | */ 319 | protected function get_response_headers() { 320 | 321 | // get the raw headers 322 | $raw_headers = preg_replace('/\n[ \t]/', ' ', str_replace( "\r\n", "\n", $this->curl_headers ) ); 323 | 324 | // spit them 325 | $raw_headers = array_filter( explode( "\n", $raw_headers ), 'strlen' ); 326 | 327 | $headers = array(); 328 | 329 | // parse into assoc array 330 | foreach ( $raw_headers as $header ) { 331 | 332 | // skip response codes (appears as HTTP/1.1 200 OK or HTTP/1.1 100 Continue) 333 | if ( 'HTTP/' === substr( $header, 0, 5 ) ) { 334 | continue; 335 | } 336 | 337 | list( $key, $value ) = explode( ':', $header, 2 ); 338 | 339 | if ( isset( $headers[ $key ] ) ) { 340 | 341 | // ensure duplicate headers aren't overwritten 342 | $headers[ $key ] = array( $headers[ $key ] ); 343 | $headers[ $key ][] = $value; 344 | 345 | } else { 346 | $headers[ $key ] = $value; 347 | } 348 | 349 | } 350 | 351 | return $headers; 352 | } 353 | 354 | } 355 | -------------------------------------------------------------------------------- /lib/woocommerce-api/class-wc-api-client.php: -------------------------------------------------------------------------------- 1 | store_url = $store_url; 95 | $this->consumer_key = $consumer_key; 96 | $this->consumer_secret = $consumer_secret; 97 | 98 | // load each API resource 99 | $this->init_resources(); 100 | 101 | // build API url from store URL 102 | $this->build_api_url(); 103 | 104 | // set options 105 | $this->parse_options( $options ); 106 | 107 | if ( $this->validate_url ) { 108 | $this->validate_api_url(); 109 | } 110 | } 111 | 112 | 113 | /** 114 | * Load each API resource 115 | * 116 | * @since 2.0 117 | */ 118 | public function init_resources() { 119 | 120 | $resources = array( 121 | 'WC_API_Client_Resource_Coupons' => 'coupons', 122 | 'WC_API_Client_Resource_Custom' => 'custom', 123 | 'WC_API_Client_Resource_Customers' => 'customers', 124 | 'WC_API_Client_Resource_Index' => 'index', 125 | 'WC_API_Client_Resource_Orders' => 'orders', 126 | 'WC_API_Client_Resource_Order_Notes' => 'order_notes', 127 | 'WC_API_Client_Resource_Order_Refunds' => 'order_refunds', 128 | 'WC_API_Client_Resource_Products' => 'products', 129 | 'WC_API_Client_Resource_Reports' => 'reports', 130 | 'WC_API_Client_Resource_Webhooks' => 'webhooks', 131 | ); 132 | 133 | foreach ( $resources as $resource_class => $resource_method ) { 134 | 135 | if ( class_exists( $resource_class ) ) { 136 | $this->$resource_method = new $resource_class( $this ); 137 | } 138 | } 139 | } 140 | 141 | 142 | /** 143 | * Build the correct API URL given the store URL provided 144 | * 145 | * @since 2.0 146 | */ 147 | public function build_api_url() { 148 | 149 | $url = parse_url( $this->store_url ); 150 | 151 | // default to http if not provided 152 | $scheme = isset( $url['scheme'] ) ? $url['scheme'] : 'http'; 153 | 154 | // set host 155 | $host = $url['host']; 156 | 157 | // add port to host if provided 158 | $host .= isset( $url['port'] ) ? ':' . $url['port'] : ''; 159 | 160 | // set path and strip any trailing slashes 161 | $path = isset( $url['path'] ) ? rtrim( $url['path'], '/' ) : ''; 162 | 163 | // add WC API path 164 | $path .= '/wc-api/v2/'; 165 | 166 | // build URL 167 | $this->api_url = "{$scheme}://{$host}{$path}"; 168 | } 169 | 170 | 171 | /** 172 | * Parse client options, current available options are: 173 | * 174 | * `debug` - true to include cURL log, HTTP request object, and HTTP response object in result 175 | * `return_as_array` - true to return the response as an associative array instead of object 176 | * `validate_url` - true to validate the API URL is correct before making API calls 177 | * 178 | * 179 | * to implement: 180 | * `timeout` - HTTP request timeout 181 | * ... additional HTTP options for handling proxy servers, etc. 182 | * 183 | * @since 2.0 184 | * @param array $options 185 | */ 186 | public function parse_options( $options ) { 187 | 188 | $valid_options = array( 189 | 'debug', 190 | 'return_as_array', 191 | 'validate_url', 192 | 'timeout', 193 | 'ssl_verify', 194 | ); 195 | 196 | foreach ( (array) $options as $opt_key => $opt_value ) { 197 | 198 | // backwards compat 199 | if ( 'verbose_mode' === $opt_key ) { 200 | $opt_key = 'debug'; 201 | } 202 | 203 | if ( ! in_array( $opt_key, $valid_options ) ) { 204 | continue; 205 | } 206 | 207 | $this->$opt_key = $opt_value; 208 | } 209 | } 210 | 211 | 212 | /** 213 | * Validate the API URL by checking if the API index exists and is parseable, 214 | * as well as forcing SSL for stores that allow it 215 | * 216 | * @since 2.0 217 | * @throws WC_API_Client_Exception 218 | */ 219 | public function validate_api_url() { 220 | 221 | $index = @file_get_contents( $this->api_url ); 222 | 223 | // check for HTTP 404 response (file_get_contents() returns false when encountering 404) 224 | // this usually means: 225 | // 1) the store URL is not correct (missing sub-directory path, etc) 226 | // 2) pretty permalinks are disabled 227 | if ( false === $index ) { 228 | throw new WC_API_Client_Exception( sprintf( 'Invalid URL, no WC API found at %s -- ensure your store URL is correct and pretty permalinks are enabled.', $this->api_url ), 404 ); 229 | } 230 | 231 | // older versions of WC (2.0 and under) will simply return a "1" 232 | if ( '1' === $index ) { 233 | throw new WC_API_Client_Exception( sprintf( 'Please upgrade the WooCommerce version on %s to v2.2 or greater.', $this->api_url ) ); 234 | } 235 | 236 | // strip invalid leading/trailing characters from JSON 237 | $json_start = strpos( $index, '{' ); 238 | $json_end = strrpos( $index, '}' ) + 1; // inclusive 239 | 240 | $index = json_decode( substr( $index, $json_start, ( $json_end - $json_start ) ) ); 241 | 242 | // check for invalid JSON, an error here usually means: 243 | // 1) there's some garbage in the JSON output, WP Super Cache is notorious for adding an HTML comment to non-cached pages 244 | if ( null === $index ) { 245 | throw new WC_API_Client_Exception( sprintf( 'WC API found, but JSON is corrupt -- ensure the index at %s is valid JSON.', $this->api_url ) ); 246 | } 247 | 248 | // check if the site URL returned is SSL, but SSL is not enabled 249 | if ( 'https' === parse_url( $index->store->URL, PHP_URL_SCHEME ) && ! $index->store->meta->ssl_enabled ) { 250 | 251 | // override the user-entered URL with the SSL version 252 | $this->api_url = str_replace( 'http://', 'https://', $this->api_url ); 253 | } 254 | } 255 | 256 | 257 | /** 258 | * Make the API call to specified endpoint with the given data -- also 259 | * handle decoding the JSON 260 | * 261 | * @since 2.0 262 | * @param string $method HTTP method, e.g. GET 263 | * @param string $path request path, e.g. orders/123 264 | * @param array $request_data either query parameters or the request body 265 | * @return object|array object by default 266 | * @throws WC_API_Client_Exception HTTP or authentication errors 267 | */ 268 | public function make_api_call( $method, $path, $request_data ) { 269 | 270 | $args = array( 271 | 'method' => $method, 272 | 'url' => $this->api_url . $path, 273 | 'data' => $request_data, 274 | 'consumer_key' => $this->consumer_key, 275 | 'consumer_secret' => $this->consumer_secret, 276 | 'options' => array( 277 | 'timeout' => $this->timeout, 278 | 'ssl_verify' => $this->ssl_verify, 279 | 'json_decode' => $this->return_as_array ? 'array' : 'object', 280 | 'debug' => $this->debug, 281 | ) 282 | ); 283 | 284 | $request = new WC_API_Client_HTTP_Request( $args ); 285 | 286 | return $request->dispatch(); 287 | } 288 | 289 | 290 | } 291 | -------------------------------------------------------------------------------- /lib/woocommerce-api/exceptions/class-wc-api-client-exception.php: -------------------------------------------------------------------------------- 1 | request = $request; 31 | $this->response = $response; 32 | } 33 | 34 | /** 35 | * Return the HTTP request class from the request, in the format: 36 | * 37 | * { 38 | * headers: array of string request headers 39 | * method: request method, e.g. GET 40 | * url: request URL 41 | * params: request parameter array 42 | * data: request data array 43 | * body: JSON encoded request body entity 44 | * duration: request duration, in seconds 45 | * } 46 | * 47 | * @since 2.0 48 | * @return array 49 | */ 50 | public function get_request() { 51 | 52 | return $this->request; 53 | } 54 | 55 | /** 56 | * Return the HTTP response class from the request, in the format: 57 | * 58 | * { 59 | * body: raw response body 60 | * code: HTTP response code 61 | * headers: array of HTTP response headers 62 | * } 63 | * 64 | * @since 2.0 65 | * @return array 66 | */ 67 | public function get_response() { 68 | 69 | return $this->response; 70 | } 71 | 72 | 73 | } 74 | -------------------------------------------------------------------------------- /lib/woocommerce-api/resources/abstract-wc-api-client-resource.php: -------------------------------------------------------------------------------- 1 | 'processing' } */ 26 | protected $request_params; 27 | 28 | /** @var array request body data, only used for PUT/POST requests */ 29 | protected $request_body; 30 | 31 | 32 | /** 33 | * Set the endpoint and client 34 | * 35 | * @since 2.0 36 | * @param string $endpoint top-level endpoint, e.g. `orders` 37 | * @param string $object_namespace the JSON object namespace for this resource, e.g. `order` 38 | * @param WC_API_Client $client class instance 39 | */ 40 | public function __construct( $endpoint, $object_namespace, $client ) { 41 | 42 | $this->endpoint = $endpoint; 43 | $this->object_namespace = $object_namespace; 44 | $this->client = $client; 45 | } 46 | 47 | 48 | /** 49 | * Set the arguments for the request, required: 50 | * 51 | * `method` 52 | * `path` 53 | * 54 | * optional: 55 | * 56 | * `params` 57 | * `body` 58 | * 59 | * @since 2.0 60 | * @param array $args 61 | */ 62 | protected function set_request_args( $args ) { 63 | 64 | $this->request_method = $args['method']; 65 | $this->request_path = isset( $args['path'] ) ? $args['path'] : null; 66 | $this->request_params = isset( $args['params'] ) ? $args['params'] : null; 67 | $this->request_body = isset( $args['body'] ) ? $args['body'] : null; 68 | 69 | // set the top-level JSON object namespace if not already set, this is mainly 70 | // a convenience for client code so creating/updating resources doesn't need a 71 | // nested array like array( 'order_note' => array( 'note' => 'foo' ) ) and can instead 72 | // use array( 'note' => 'foo' ) ʘ‿ʘ 73 | if ( $this->request_body && ! isset( $args['body'][ $this->object_namespace ] ) ) { 74 | 75 | $this->request_body = array( 76 | $this->object_namespace => $this->request_body, 77 | ); 78 | } 79 | 80 | // convert bool true to string 'true', required for DELETE endpoints 81 | if ( isset( $this->request_params['force'] ) && $this->request_params['force'] ) { 82 | $this->request_params['force'] = 'true'; 83 | } 84 | } 85 | 86 | 87 | /** 88 | * Return the full endpoint path, e.g. given an endpoint of `orders` and a 89 | * path of `123`, return `orders/123`. For nested resources, this will return 90 | * the full path as well 91 | * 92 | * @since 2.0 93 | * @return string 94 | */ 95 | protected function get_endpoint_path() { 96 | 97 | return empty( $this->request_path ) ? $this->endpoint : $this->endpoint . '/' . implode( '/', (array) $this->request_path ); 98 | } 99 | 100 | 101 | /** 102 | * Return the request data, either query parameters (for GET/DELETE requests) 103 | * or the request body (for PUT/POST requests) 104 | * 105 | * @since 2.0 106 | * @return array 107 | */ 108 | protected function get_request_data() { 109 | 110 | return ( 'GET' === $this->request_method || 'DELETE' === $this->request_method ) ? $this->request_params : $this->request_body; 111 | } 112 | 113 | 114 | /** 115 | * Perform the request and return the response 116 | * 117 | * @since 2.0 118 | * @return array|object 119 | */ 120 | protected function do_request() { 121 | 122 | return $this->client->make_api_call( $this->request_method, $this->get_endpoint_path(), $this->get_request_data() ); 123 | } 124 | 125 | 126 | } 127 | 128 | 129 | -------------------------------------------------------------------------------- /lib/woocommerce-api/resources/class-wc-api-client-resource-coupons.php: -------------------------------------------------------------------------------- 1 | set_request_args( array( 36 | 'method' => 'GET', 37 | 'path' => $id, 38 | 'params' => $args, 39 | ) ); 40 | 41 | return $this->do_request(); 42 | } 43 | 44 | 45 | /** 46 | * Get coupon by code 47 | * 48 | * GET /coupons/code/{code} 49 | * 50 | * @since 2.0 51 | * @param string $code coupon code 52 | * @param array $args acceptable coupon code lookup endpoint args, currently only `fields` 53 | * @return array|object coupon! 54 | */ 55 | public function get_by_code( $code, $args = array() ) { 56 | 57 | $this->set_request_args( array( 58 | 'method' => 'GET', 59 | 'path' => array( 'code', urlencode( $code ) ), 60 | 'params' => $args, 61 | ) ); 62 | 63 | return $this->do_request(); 64 | } 65 | 66 | 67 | 68 | /** 69 | * Create a coupon 70 | * 71 | * POST /coupons 72 | * 73 | * @since 2.0 74 | * @param array $data valid coupon data 75 | * @return array|object your newly-created coupon 76 | */ 77 | public function create( $data ) { 78 | 79 | $this->set_request_args( array( 80 | 'method' => 'POST', 81 | 'body' => $data, 82 | ) ); 83 | 84 | return $this->do_request(); 85 | } 86 | 87 | 88 | /** 89 | * Update a coupon 90 | * 91 | * PUT /coupon/#{id} 92 | * 93 | * @since 2.0 94 | * @param int $id coupon ID 95 | * @param array $data coupon data to update 96 | * @return array|object your newly-updated coupon 97 | */ 98 | public function update( $id, $data ) { 99 | 100 | $this->set_request_args( array( 101 | 'method' => 'PUT', 102 | 'path' => $id, 103 | 'body' => $data, 104 | ) ); 105 | 106 | return $this->do_request(); 107 | } 108 | 109 | 110 | /** 111 | * Delete a coupon 112 | * 113 | * DELETE /coupons/#{id} 114 | * 115 | * @since 2.0 116 | * @param int $id coupon ID 117 | * @param bool $force true to permanently delete the coupon, false to trash it 118 | * @return array|object response 119 | */ 120 | public function delete( $id, $force = false ) { 121 | 122 | $this->set_request_args( array( 123 | 'method' => 'DELETE', 124 | 'path' => $id, 125 | 'params' => array( 'force' => $force ), 126 | ) ); 127 | 128 | return $this->do_request(); 129 | } 130 | 131 | 132 | /** 133 | * Get a count of coupons 134 | * 135 | * GET /coupons/count 136 | * 137 | * @since 2.0 138 | * @param array $args acceptable coupon endpoint args, like `filter[]` 139 | * @return array|object the count 140 | */ 141 | public function get_count( $args = array() ) { 142 | 143 | $this->set_request_args( array( 144 | 'method' => 'GET', 145 | 'path' => 'count', 146 | 'params' => $args, 147 | ) ); 148 | 149 | return $this->do_request(); 150 | } 151 | 152 | 153 | /** Convenience methods - these do not map directly to an endpoint ********/ 154 | 155 | 156 | // none yet 157 | 158 | 159 | } 160 | -------------------------------------------------------------------------------- /lib/woocommerce-api/resources/class-wc-api-client-resource-custom.php: -------------------------------------------------------------------------------- 1 | endpoint = $endpoint; 33 | $this->object_namespace = $object_namespace; 34 | } 35 | 36 | 37 | /** 38 | * Perform a GET request to the custom endpoint 39 | * 40 | * Path can either be: 41 | * 42 | * string (your_string) - GET /endpoint/your_string 43 | * array (1,2,3) - GET /endpoint/1/2/3 44 | * 45 | * Params are added after the endpoint 46 | * 47 | * @since 2.0 48 | * @param string|array $path request path 49 | * @param array $params request params 50 | * @return array|object custom resource 51 | */ 52 | public function get( $path, $params = array() ) { 53 | 54 | $this->set_request_args( array( 55 | 'method' => 'GET', 56 | 'path' => $path, 57 | 'params' => $params, 58 | ) ); 59 | 60 | return $this->do_request(); 61 | } 62 | 63 | 64 | /** 65 | * Perform a POST request to the custom endpoint 66 | * 67 | * Path can either be: 68 | * 69 | * string (your_string) - GET /endpoint/your_string 70 | * array (1,2,3) - GET /endpoint/1/2/3 71 | * 72 | * Params are added after the endpoint 73 | * 74 | * @since 2.0 75 | * @param string|array $path request path 76 | * @param array $data request body entity to be JSON encoded 77 | * @param array $params request params 78 | * @return array|object custom resource 79 | */ 80 | public function post( $path, $data, $params = array() ) { 81 | 82 | $this->set_request_args( array( 83 | 'method' => 'POST', 84 | 'path' => $path, 85 | 'params' => $params, 86 | 'body' => $data, 87 | ) ); 88 | 89 | return $this->do_request(); 90 | } 91 | 92 | 93 | /** 94 | * Perform a PUT request to the custom endpoint 95 | * 96 | * Path can either be: 97 | * 98 | * string (your_string) - GET /endpoint/your_string 99 | * array (1,2,3) - GET /endpoint/1/2/3 100 | * 101 | * Params are added after the endpoint 102 | * 103 | * @since 2.0 104 | * @param string|array $path request path 105 | * @param array $data request body entity to be JSON encoded 106 | * @param array $params request params 107 | * @return array|object custom resource 108 | */ 109 | public function put( $path, $data, $params = array() ) { 110 | 111 | $this->set_request_args( array( 112 | 'method' => 'PUT', 113 | 'path' => $path, 114 | 'params' => $params, 115 | 'body' => $data, 116 | ) ); 117 | 118 | return $this->do_request(); 119 | } 120 | 121 | 122 | /** 123 | * Perform a DELETE request to the custom endpoint 124 | * 125 | * Path can either be: 126 | * 127 | * string (your_string) - GET /endpoint/your_string 128 | * array (1,2,3) - GET /endpoint/1/2/3 129 | * 130 | * Params are added after the endpoint 131 | * 132 | * @since 2.0 133 | * @param string|array $path request path 134 | * @param array $params request params 135 | * @return array|object custom resource 136 | */ 137 | public function delete( $path, $params = array() ) { 138 | 139 | $this->set_request_args( array( 140 | 'method' => 'DELETE', 141 | 'path' => $path, 142 | 'params' => $params, 143 | ) ); 144 | 145 | return $this->do_request(); 146 | } 147 | 148 | 149 | } 150 | -------------------------------------------------------------------------------- /lib/woocommerce-api/resources/class-wc-api-client-resource-customers.php: -------------------------------------------------------------------------------- 1 | set_request_args( array( 36 | 'method' => 'GET', 37 | 'path' => $id, 38 | 'params' => $args, 39 | ) ); 40 | 41 | return $this->do_request(); 42 | } 43 | 44 | 45 | /** 46 | * Get customer by email 47 | * 48 | * GET /customers/email/{email} 49 | * 50 | * @since 2.0 51 | * @param string $email customer's email 52 | * @param array $args acceptable customer email lookup endpoint args, currently only `fields` 53 | * @return array|object customer! 54 | */ 55 | public function get_by_email( $email, $args = array() ) { 56 | 57 | $this->set_request_args( array( 58 | 'method' => 'GET', 59 | 'path' => array( 'email', urlencode( $email ) ), 60 | 'params' => $args, 61 | ) ); 62 | 63 | return $this->do_request(); 64 | } 65 | 66 | 67 | /** 68 | * Create a customer 69 | * 70 | * POST /customers 71 | * 72 | * @since 2.0 73 | * @param array $data valid customer data 74 | * @return array|object your newly-created customer 75 | */ 76 | public function create( $data ) { 77 | 78 | $this->set_request_args( array( 79 | 'method' => 'POST', 80 | 'body' => $data, 81 | ) ); 82 | 83 | return $this->do_request(); 84 | } 85 | 86 | 87 | /** 88 | * Update a customer 89 | * 90 | * PUT /customer/#{id} 91 | * 92 | * @since 2.0 93 | * @param int $id customer ID 94 | * @param array $data customer data to update 95 | * @return array|object your newly-updated customer 96 | */ 97 | public function update( $id, $data ) { 98 | 99 | $this->set_request_args( array( 100 | 'method' => 'PUT', 101 | 'path' => $id, 102 | 'body' => $data, 103 | ) ); 104 | 105 | return $this->do_request(); 106 | } 107 | 108 | 109 | /** 110 | * Delete a customer 111 | * 112 | * DELETE /customer/#{id} 113 | * 114 | * @since 2.0 115 | * @param int $id customer ID 116 | * @return array|object response 117 | */ 118 | public function delete( $id ) { 119 | 120 | $this->set_request_args( array( 121 | 'method' => 'DELETE', 122 | 'path' => $id, 123 | ) ); 124 | 125 | return $this->do_request(); 126 | } 127 | 128 | 129 | /** 130 | * Get a count of customers 131 | * 132 | * GET /customers/count 133 | * 134 | * @since 2.0 135 | * @param array $args acceptable customer endpoint args, like `filter[]` 136 | * @return array|object the count 137 | */ 138 | public function get_count( $args = array() ) { 139 | 140 | $this->set_request_args( array( 141 | 'method' => 'GET', 142 | 'path' => 'count', 143 | 'params' => $args, 144 | ) ); 145 | 146 | return $this->do_request(); 147 | } 148 | 149 | 150 | /** 151 | * Get customer orders 152 | * 153 | * GET /customers/#{customer_id}/orders 154 | * 155 | * @since 2.0 156 | * @param int $id customer ID 157 | * @param array $args acceptable customer orders endpoint args, currently only `fields` 158 | * @return array|object customer orders! 159 | */ 160 | public function get_orders( $id, $args = array() ) { 161 | 162 | $this->set_request_args( array( 163 | 'method' => 'GET', 164 | 'path' => array( $id, 'orders' ), 165 | 'params' => $args, 166 | ) ); 167 | 168 | return $this->do_request(); 169 | } 170 | 171 | 172 | /** 173 | * Get customer downloads 174 | * 175 | * GET /customers/#{customer_id}/downloads 176 | * 177 | * @since 2.0 178 | * @param int $id customer ID 179 | * @param array $args acceptable customer downloads endpoint args, currently only `fields` 180 | * @return array|object customer downloads! 181 | */ 182 | public function get_downloads( $id, $args = array() ) { 183 | 184 | $this->set_request_args( array( 185 | 'method' => 'GET', 186 | 'path' => array( $id, 'downloads' ), 187 | 'params' => $args, 188 | ) ); 189 | 190 | return $this->do_request(); 191 | } 192 | 193 | 194 | /** Convenience methods - these do not map directly to an endpoint ********/ 195 | 196 | 197 | // none yet 198 | 199 | 200 | } 201 | -------------------------------------------------------------------------------- /lib/woocommerce-api/resources/class-wc-api-client-resource-index.php: -------------------------------------------------------------------------------- 1 | set_request_args( array( 33 | 'method' => 'GET', 34 | 'path' => '', 35 | ) ); 36 | 37 | return $this->do_request(); 38 | } 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /lib/woocommerce-api/resources/class-wc-api-client-resource-order-notes.php: -------------------------------------------------------------------------------- 1 | set_request_args( array( 37 | 'method' => 'GET', 38 | 'path' => array( $order_id, 'notes', $id ), 39 | 'params' => $args, 40 | ) ); 41 | 42 | return $this->do_request(); 43 | } 44 | 45 | 46 | /** 47 | * Create an order note 48 | * 49 | * POST /orders/#{order_id}/notes 50 | * 51 | * @since 2.0 52 | * @param int $order_id order ID 53 | * @param array $data valid order note data 54 | * @return array|object your newly-created order note 55 | */ 56 | public function create( $order_id, $data ) { 57 | 58 | $this->set_request_args( array( 59 | 'method' => 'POST', 60 | 'path' => array( $order_id, 'notes' ), 61 | 'body' => $data, 62 | ) ); 63 | 64 | return $this->do_request(); 65 | } 66 | 67 | 68 | /** 69 | * Update an order note 70 | * 71 | * PUT /orders/#{order_id}/notes/#{id} 72 | * 73 | * @since 2.0 74 | * @param int $order_id order ID 75 | * @param int $id order note ID 76 | * @param array $data order note data to update 77 | * @return array|object your newly-updated order note 78 | */ 79 | public function update( $order_id, $id, $data ) { 80 | 81 | $this->set_request_args( array( 82 | 'method' => 'PUT', 83 | 'path' => array( $order_id, 'notes', $id ), 84 | 'body' => $data, 85 | ) ); 86 | 87 | return $this->do_request(); 88 | } 89 | 90 | 91 | /** 92 | * Delete an order note 93 | * 94 | * DELETE /orders/#{order_id}/notes/#{id} 95 | * 96 | * @since 2.0 97 | * @param int $order_id order ID 98 | * @param int $id order note ID 99 | * @return array|object response 100 | */ 101 | public function delete( $order_id, $id ) { 102 | 103 | $this->set_request_args( array( 104 | 'method' => 'DELETE', 105 | 'path' => array( $order_id, 'notes', $id ), 106 | ) ); 107 | 108 | return $this->do_request(); 109 | } 110 | 111 | 112 | /** Convenience methods - these do not map directly to an endpoint ********/ 113 | 114 | // none yet 115 | 116 | 117 | } 118 | -------------------------------------------------------------------------------- /lib/woocommerce-api/resources/class-wc-api-client-resource-order-refunds.php: -------------------------------------------------------------------------------- 1 | set_request_args( array( 37 | 'method' => 'GET', 38 | 'path' => array( $order_id, 'refunds', $id ), 39 | 'params' => $args, 40 | ) ); 41 | 42 | return $this->do_request(); 43 | } 44 | 45 | 46 | /** 47 | * Create an order refund 48 | * 49 | * POST /orders/#{order_id}/refunds 50 | * 51 | * @since 2.0 52 | * @param int $order_id order ID 53 | * @param array $data valid order refund data 54 | * @return array|object your newly-created order refund 55 | */ 56 | public function create( $order_id, $data ) { 57 | 58 | $this->set_request_args( array( 59 | 'method' => 'POST', 60 | 'path' => array( $order_id, 'refunds' ), 61 | 'body' => $data, 62 | ) ); 63 | 64 | return $this->do_request(); 65 | } 66 | 67 | 68 | /** 69 | * Update an order refund 70 | * 71 | * PUT /orders/#{order_id}/refunds/#{id} 72 | * 73 | * @since 2.0 74 | * @param int $order_id order ID 75 | * @param int $id order refund ID 76 | * @param array $data order refund data to update 77 | * @return array|object your newly-updated order refund 78 | */ 79 | public function update( $order_id, $id, $data ) { 80 | 81 | $this->set_request_args( array( 82 | 'method' => 'PUT', 83 | 'path' => array( $order_id, 'refunds', $id ), 84 | 'body' => $data, 85 | ) ); 86 | 87 | return $this->do_request(); 88 | } 89 | 90 | 91 | /** 92 | * Delete an order refund 93 | * 94 | * DELETE /orders/#{order_id}/refunds/#{id} 95 | * 96 | * @since 2.0 97 | * @param int $order_id order ID 98 | * @param int $id order refund ID 99 | * @return array|object response 100 | */ 101 | public function delete( $order_id, $id ) { 102 | 103 | $this->set_request_args( array( 104 | 'method' => 'DELETE', 105 | 'path' => array( $order_id, 'refunds', $id ), 106 | ) ); 107 | 108 | return $this->do_request(); 109 | } 110 | 111 | 112 | /** Convenience methods - these do not map directly to an endpoint ********/ 113 | 114 | // none yet 115 | 116 | 117 | } 118 | -------------------------------------------------------------------------------- /lib/woocommerce-api/resources/class-wc-api-client-resource-orders.php: -------------------------------------------------------------------------------- 1 | set_request_args( array( 36 | 'method' => 'GET', 37 | 'path' => $id, 38 | 'params' => $args, 39 | ) ); 40 | 41 | return $this->do_request(); 42 | } 43 | 44 | 45 | /** 46 | * Create an order 47 | * 48 | * POST /orders 49 | * 50 | * @since 2.0 51 | * @param array $data valid order data 52 | * @return array|object your newly-created order 53 | */ 54 | public function create( $data ) { 55 | 56 | $this->set_request_args( array( 57 | 'method' => 'POST', 58 | 'body' => $data, 59 | ) ); 60 | 61 | return $this->do_request(); 62 | } 63 | 64 | 65 | /** 66 | * Update an order 67 | * 68 | * PUT /orders/#{id} 69 | * 70 | * @since 2.0 71 | * @param int $id order ID 72 | * @param array $data order data to update 73 | * @return array|object your newly-updated order 74 | */ 75 | public function update( $id, $data ) { 76 | 77 | $this->set_request_args( array( 78 | 'method' => 'PUT', 79 | 'path' => $id, 80 | 'body' => $data, 81 | ) ); 82 | 83 | return $this->do_request(); 84 | } 85 | 86 | 87 | /** 88 | * Delete an order 89 | * 90 | * DELETE /orders/#{id} 91 | * 92 | * @since 2.0 93 | * @param int $id order ID 94 | * @param bool $force true to permanently delete the order, false to trash it 95 | * @return array|object response 96 | */ 97 | public function delete( $id, $force = false ) { 98 | 99 | $this->set_request_args( array( 100 | 'method' => 'DELETE', 101 | 'path' => $id, 102 | 'params' => array( 'force' => $force ), 103 | ) ); 104 | 105 | return $this->do_request(); 106 | } 107 | 108 | 109 | /** 110 | * Get a count of orders 111 | * 112 | * GET /orders/count 113 | * 114 | * @since 2.0 115 | * @param array $args acceptable order endpoint args, like `status` 116 | * @return array|object the count 117 | */ 118 | public function get_count( $args = array() ) { 119 | 120 | $this->set_request_args( array( 121 | 'method' => 'GET', 122 | 'path' => 'count', 123 | 'params' => $args, 124 | ) ); 125 | 126 | return $this->do_request(); 127 | } 128 | 129 | 130 | /** 131 | * Get a list of valid order statuses 132 | * 133 | * GET /orders/statuses 134 | * 135 | * @since 2.0 136 | * @return array|object order statuses 137 | */ 138 | public function get_statuses() { 139 | 140 | $this->set_request_args( array( 141 | 'method' => 'GET', 142 | 'path' => 'statuses', 143 | ) ); 144 | 145 | return $this->do_request(); 146 | } 147 | 148 | 149 | /** Convenience methods - these do not map directly to an endpoint ********/ 150 | 151 | 152 | /** 153 | * Update the status for an order 154 | * 155 | * PUT /orders/#{id} with status 156 | * 157 | * @param int $id order ID 158 | * @param string $status valid order status 159 | * @return array|object newly-updated order 160 | */ 161 | public function update_status( $id, $status ) { 162 | 163 | $this->set_request_args( array( 164 | 'method' => 'PUT', 165 | 'path' => $id, 166 | 'body' => array( 'status' => $status ), 167 | ) ); 168 | 169 | return $this->do_request(); 170 | } 171 | 172 | 173 | } 174 | -------------------------------------------------------------------------------- /lib/woocommerce-api/resources/class-wc-api-client-resource-products.php: -------------------------------------------------------------------------------- 1 | set_request_args( array( 36 | 'method' => 'GET', 37 | 'path' => $id, 38 | 'params' => $args, 39 | ) ); 40 | 41 | return $this->do_request(); 42 | } 43 | 44 | 45 | /** 46 | * Get product by SKU 47 | * 48 | * GET /products/sku/{sku} 49 | * 50 | * Note this will throw an exception if no products are found (404 not found) 51 | * 52 | * @since 2.0 53 | * @param string $sku product SKU 54 | * @param array $args acceptable product SKU lookup endpoint args, currently only `fields` 55 | * @return array|object product! 56 | */ 57 | public function get_by_sku( $sku, $args = array() ) { 58 | 59 | $this->set_request_args( array( 60 | 'method' => 'GET', 61 | 'path' => array( 'sku', urlencode( $sku ) ), 62 | 'params' => $args, 63 | ) ); 64 | 65 | return $this->do_request(); 66 | } 67 | 68 | 69 | /** 70 | * Create a product 71 | * 72 | * POST /products 73 | * 74 | * @since 2.0 75 | * @param array $data valid product data 76 | * @return array|object your newly-created product 77 | */ 78 | public function create( $data ) { 79 | 80 | $this->set_request_args( array( 81 | 'method' => 'POST', 82 | 'body' => $data, 83 | ) ); 84 | 85 | return $this->do_request(); 86 | } 87 | 88 | 89 | /** 90 | * Update a product 91 | * 92 | * PUT /product/#{id} 93 | * 94 | * @since 2.0 95 | * @param int $id product ID 96 | * @param array $data product data to update 97 | * @return array|object your newly-updated product 98 | */ 99 | public function update( $id, $data ) { 100 | 101 | $this->set_request_args( array( 102 | 'method' => 'PUT', 103 | 'path' => $id, 104 | 'body' => $data, 105 | ) ); 106 | 107 | return $this->do_request(); 108 | } 109 | 110 | 111 | /** 112 | * Delete a product 113 | * 114 | * DELETE /products/#{id} 115 | * 116 | * @since 2.0 117 | * @param int $id product ID 118 | * @param bool $force true to permanently delete the product, false to trash it 119 | * @return array|object response 120 | */ 121 | public function delete( $id, $force = false ) { 122 | 123 | $this->set_request_args( array( 124 | 'method' => 'DELETE', 125 | 'path' => $id, 126 | 'params' => array( 'force' => $force ), 127 | ) ); 128 | 129 | return $this->do_request(); 130 | } 131 | 132 | 133 | /** 134 | * Get a count of products 135 | * 136 | * GET /products/count 137 | * 138 | * @since 2.0 139 | * @param array $args acceptable product endpoint args, like `type` or `filter[]` 140 | * @return array|object the count 141 | */ 142 | public function get_count( $args = array() ) { 143 | 144 | $this->set_request_args( array( 145 | 'method' => 'GET', 146 | 'path' => 'count', 147 | 'params' => $args, 148 | ) ); 149 | 150 | return $this->do_request(); 151 | } 152 | 153 | 154 | /** 155 | * Get product reviews 156 | * 157 | * GET /products/#{product_id}/reviews 158 | * 159 | * @since 2.0 160 | * @param int $id product ID 161 | * @param array $args acceptable product reviews endpoint args, currently only `fields` 162 | * @return array|object product reviews! 163 | */ 164 | public function get_reviews( $id, $args = array() ) { 165 | 166 | $this->set_request_args( array( 167 | 'method' => 'GET', 168 | 'path' => array( $id, 'reviews' ), 169 | 'params' => $args, 170 | ) ); 171 | 172 | return $this->do_request(); 173 | } 174 | 175 | 176 | /** 177 | * Get a list of product categories or a single product category 178 | * 179 | * GET /products/categories 180 | * GET /products/categories/{#id} 181 | * 182 | * @since 2.0 183 | * @param int $id category ID or null to get all product categories 184 | * @param array $args acceptable product categories endpoint args, currently only `fields` 185 | * @return array|object product categories! 186 | */ 187 | public function get_categories( $id = null, $args = array() ) { 188 | 189 | $this->set_request_args( array( 190 | 'method' => 'GET', 191 | 'path' => array( 'categories', $id ), 192 | 'params' => $args, 193 | ) ); 194 | 195 | return $this->do_request(); 196 | } 197 | 198 | 199 | /** Convenience methods - these do not map directly to an endpoint ********/ 200 | 201 | 202 | /** 203 | * Update the stock quantity for a product 204 | * 205 | * PUT /products/#{id} with stock quantity 206 | * 207 | * @param int $id order ID 208 | * @param int|float $quantity new stock quantity 209 | * @return array|object newly-updated product 210 | */ 211 | public function update_stock( $id, $quantity ) { 212 | 213 | $this->set_request_args( array( 214 | 'method' => 'PUT', 215 | 'path' => $id, 216 | 'body' => array( 'stock_quantity' => $quantity ), 217 | ) ); 218 | 219 | return $this->do_request(); 220 | } 221 | 222 | 223 | } 224 | -------------------------------------------------------------------------------- /lib/woocommerce-api/resources/class-wc-api-client-resource-reports.php: -------------------------------------------------------------------------------- 1 | set_request_args( array( 33 | 'method' => 'GET', 34 | ) ); 35 | 36 | return $this->do_request(); 37 | } 38 | 39 | 40 | /** 41 | * Get Sales report 42 | * 43 | * GET /reports/sales 44 | * 45 | * @since 2.0 46 | * @param array $args acceptable reports endpoint args, like `filter[period]` 47 | * @return array|object sales report! 48 | */ 49 | public function get_sales( $args = array() ) { 50 | 51 | $this->set_request_args( array( 52 | 'method' => 'GET', 53 | 'path' => 'sales', 54 | 'params' => $args, 55 | ) ); 56 | 57 | return $this->do_request(); 58 | } 59 | 60 | 61 | /** 62 | * Get Top Sellers report 63 | * 64 | * GET /reports/sales/top_sellers 65 | * 66 | * @since 2.0 67 | * @param array $args acceptable reports endpoint args, like `filter[period]` 68 | * @return array|object sales report! 69 | */ 70 | public function get_top_sellers( $args = array() ) { 71 | 72 | $this->set_request_args( array( 73 | 'method' => 'GET', 74 | 'path' => array( 'sales', 'top_sellers' ), 75 | 'params' => $args, 76 | ) ); 77 | 78 | return $this->do_request(); 79 | } 80 | 81 | 82 | /** Convenience methods - these do not map directly to an endpoint ********/ 83 | 84 | 85 | // none yet 86 | 87 | 88 | } 89 | -------------------------------------------------------------------------------- /lib/woocommerce-api/resources/class-wc-api-client-resource-webhooks.php: -------------------------------------------------------------------------------- 1 | set_request_args( array( 36 | 'method' => 'GET', 37 | 'path' => $id, 38 | 'params' => $args, 39 | ) ); 40 | 41 | return $this->do_request(); 42 | } 43 | 44 | 45 | /** 46 | * Create a webhook 47 | * 48 | * POST /webhooks 49 | * 50 | * @since 2.0 51 | * @param array $data valid webhook data 52 | * @return array|object your newly-created webhook 53 | */ 54 | public function create( $data ) { 55 | 56 | $this->set_request_args( array( 57 | 'method' => 'POST', 58 | 'body' => $data, 59 | ) ); 60 | 61 | return $this->do_request(); 62 | } 63 | 64 | 65 | /** 66 | * Update a webhook 67 | * 68 | * PUT /webhook/#{id} 69 | * 70 | * @since 2.0 71 | * @param int $id webhook ID 72 | * @param array $data webhook data to update 73 | * @return array|object your newly-updated webhook 74 | */ 75 | public function update( $id, $data ) { 76 | 77 | $this->set_request_args( array( 78 | 'method' => 'PUT', 79 | 'path' => $id, 80 | 'body' => $data, 81 | ) ); 82 | 83 | return $this->do_request(); 84 | } 85 | 86 | 87 | /** 88 | * Delete a webhook 89 | * 90 | * DELETE /webhook/#{id} 91 | * 92 | * @since 2.0 93 | * @param int $id webhook ID 94 | * @return array|object response 95 | */ 96 | public function delete( $id ) { 97 | 98 | $this->set_request_args( array( 99 | 'method' => 'DELETE', 100 | 'path' => $id, 101 | ) ); 102 | 103 | return $this->do_request(); 104 | } 105 | 106 | 107 | /** 108 | * Get a count of webhooks 109 | * 110 | * GET /webhooks/count 111 | * 112 | * @since 2.0 113 | * @param array $args acceptable webhook endpoint args, like `status` 114 | * @return array|object the count 115 | */ 116 | public function get_count( $args = array() ) { 117 | 118 | $this->set_request_args( array( 119 | 'method' => 'GET', 120 | 'path' => 'count', 121 | 'params' => $args, 122 | ) ); 123 | 124 | return $this->do_request(); 125 | } 126 | 127 | 128 | /** 129 | * Get webhook deliveries 130 | * 131 | * GET /webhooks/#{webhook_id}/deliveries 132 | * 133 | * @since 2.0 134 | * @param int $id webhook ID 135 | * @param array $args acceptable webhook delivery endpoint args, currently only `fields` 136 | * @return array|object webhook deliveries! 137 | */ 138 | public function get_deliveries( $id, $args = array() ) { 139 | 140 | $this->set_request_args( array( 141 | 'method' => 'GET', 142 | 'path' => array( $id, 'deliveries' ), 143 | 'params' => $args, 144 | ) ); 145 | 146 | return $this->do_request(); 147 | } 148 | 149 | 150 | /** 151 | * Get a webhook delivery 152 | * 153 | * GET /webhooks/#{webhook_id}/deliveries/#{id} 154 | * 155 | * @since 2.0 156 | * @param int $webhook_id webhook ID 157 | * @param int $id webhook delivery ID 158 | * @param array $args acceptable webhook delivery endpoint args, currently only `fields` 159 | * @return array|object webhook delivery! 160 | */ 161 | public function get_delivery( $webhook_id, $id, $args = array() ) { 162 | 163 | $this->set_request_args( array( 164 | 'method' => 'GET', 165 | 'path' => array( $webhook_id, 'deliveries', $id ), 166 | 'params' => $args, 167 | ) ); 168 | 169 | return $this->do_request(); 170 | } 171 | 172 | 173 | /** Convenience methods - these do not map directly to an endpoint ********/ 174 | 175 | 176 | // none yet 177 | 178 | 179 | } 180 | --------------------------------------------------------------------------------