Download the PHP package preluigi/ontraport without Composer
On this page you can find all versions of the php package preluigi/ontraport. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download preluigi/ontraport
More information about preluigi/ontraport
Files in preluigi/ontraport
Package ontraport
Short Description Ontraport PHP Rest API library
License Apache 2.0
Homepage https://github.com/preluigi/OntraportPHP
Informations about the package ontraport
OntraportPHP
PHP Library for Ontraport REST API
Installation - Using Composer
in order to use the library you need to update your require config in composer.json like this
Simple overview and usage
First you need to instantiate a new Ontraport object instance with your AppId and Key credentials
Then you can access OP objects and their CRUD functions like this
Supported Ontraport Object Types
Currently the following Ontraport Object Types are supported:
- Contacts
- Notes
- Objects
- Products
- Purchases
- Shippings
- Staff
- Tags
- Taxes
You can access them using the already seen syntax
Object Types methods
Every Object Type has the following default methods
Changing the API version
By default the library uses the version 1 of the REST API (which is the only one available at this moment). You can change the version to fit your needs (???) by using the Ontraport\Ontraport->set_version method:
Changing the default endpoints
By default the library initializes the following endpoints:
You can change one or all of those endpoints by using the Ontraport\Ontraport->set_endpoint method:
Note that custom defined endpoints will not use the API version attribute to generate the called endpoint, so you need to pass the complete endpoint URI.
How the library works
Before you start diving into more advanced OntraportPHP usages I bet you want to see in detail how the library works. So here's the answer: The library itself is composed by a set of classes organized by that pattern:
class Ontraport --calls--> class Contacts which extends class Objects
at the moment the library supports only operations on Ontraport Object Types; base CRUD methods are defined in the Ontraport\Objects class which is extended by object specific classes like Contacts or Products. So when you call ->Contacts->read() on an Ontraport\Ontraport object you're simply receiving the results from the Ontraport\Contacts->read() method which is inherited from the Ontraport\Objects class. Behind the scenes is going on a dependency injection from the class Ontraport\Ontraport object to the called class (eg: Ontraport\Contacts), in fact here there are two working examples:
Extend the library
I suggest you to read the preceding section: How the library works to better understand the following instructions.
There are basically two ways to extend the library with you own classes:
1) By using a custom namespace (Recommended)
The Ontraport\Ontraport class exposes a method called set_namespace which you can use to modify the namespace of the called Object Type classes, I think is better have an example:
Using this approach you can override any Object Type class and define your own while mantain the $ontraport->ClassName clear and compact syntax.
2) By using dependency injection
This method works the same as the first mentioned but instead of changing the base namespace used for inclusion you've got to extend Object Type classes and use dependency injection to pass the Ontraport\Ontraport object to the class constructor. Example: