Download the PHP package moltin/php-sdk without Composer
On this page you can find all versions of the php package moltin/php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download moltin/php-sdk
More information about moltin/php-sdk
Files in moltin/php-sdk
Package php-sdk
Short Description The Moltin PHP SDK is a simple to use interface for the API to help you get off the ground quickly and efficiently
License
Informations about the package php-sdk
moltin PHP SDK
This official PHP SDK for interacting with moltin.
NOTE: master
is designed to access V2
of the API. If you want legacy access to V1
of the API, please use the most recent 1.x.x
tag
Installation
You can install the package manually or by adding it to your composer.json
:
Instantiating the SDK Client:
Pass in the configuration to the client:
Or configure after construct:
Note: if you are unsure what your client_id
or client_secret
are, please select the
store in your account and copy them.
Enterprise Customers
If you are an enterprise customer and have your own infrastructure with your own domain, you can configure the client to use your domain:
Or by adding the api_endpoint
field to the $config
array you pass to the constructor.
Using the client
Multiple Resources
To return a list of your resources (limited to 100 depending your store configuration):
Single Resource by ID
Fetch a Resource by ID:
Fetching the category/brand/collection tree
Categories, brands and collections can be nested to create a tree structure (see the CategoryRelationships example).
You can retrieve a full tree of the items rather than having to build them by using tree
method:
Limiting and Offsetting Results
Sorting Results
Filtering Results
To filter your results when calling resources which support it (e.g. /v2/products
).
A simple filter to get all products which are in stock may look like this:
A more advanced filter to find products which are digital, drafted and have a stock greater than 20 would look like this:
The array
passed to the filter
method should contain all of the conditions required to be met by the filter on the API and allow you to use several filters of the same type (as demostrated above).
For more information on the filter operations please read the API reference.
Including data
To include other data in your request (such as products when getting a category) call the with()
method on the resource:
Create Relationships
Requesting a Specific Currency
For calls that support the X-MOLTIN-CURRENCY
header, you can specifiy it on the client:
Working with files
A POST
request to the v2/files
endpoint allows you to upload a file and store it remotely.
To create a file using the SDK, you need to have the file on disk:
Integrations
Getting Logs
Gateways
Your payment gateways can be managed using the SDK.
Carts, Orders and Payments
To simplify the way you process carts, orders and payments, we provide some utility functions.
Carts
Adding items to a cart:
When no cart reference is supplied, we will get it from the $_COOKIE
. You can change the name used in the $_COOKIE
by passing it in the config when instantiating the client.
This is therefore a valid call (although the cart will be a new one if you follow on from the example above):
Get the cart items:
Update the quantity of an item in the cart:
Remove an item from the cart:
Orders
To convert a cart to an order (which can then be paid):
Payments
When you have a Moltin\Entities\Order
object from the checkout method you can take a payment for it:
You can now check the response ($payment
) to see what happened with your payment.
You can also setup test details for most payment gateways, please refer to them for their details and check out the example for more informatiom on cart -> order -> pay
.
Handling Exceptions
Aside from errors that may occur due to the call, there may be other Exceptions thrown. To handle them, simply wrap your call in a try catch block:
Internally, there are several custom Exceptions which may be raised - see the Exceptions directory for more information.
Examples
In the examples
directory there are command line implementations using the SDK. To use the examples you will need to:
- Install dependencies with
- Copy the
examples/.env.tmpl
toexamples/.env
and add your credentials to it. - Run the example file you want, for example:
By default, for successful calls, we will display the data in a table on the command line. You can, however, use a flag to view the response:
Test
Generate a coverage report: