Creating Drivers

To get started creating a driver, first clone the driver-skeletonopen in new window repository.

Once this has been cloned, update any relevant details such as the package name, description, and namespace.

You can then rename the Skeletonopen in new window and SkeletonServiceProvideropen in new window classes to the name of your driver.

Inside the Skeleton class, there are multiple methods, here is an overview of what each does:

  • The public __construct method - this is where the class should be instantiated, and anything class properties derived from the configuration should be initialised.
  • The public find() method - this should return an instance of the Product DTOopen in new window, and is where the tracking details should be received from an API.
  • The private mapStatus() and getHeaders() methods - these two methods are utility helper methods for mapping delivery values from the API to a Status enumopen in new window instance, and for retrieving any relevant headers for the requests such as API Authorization headers.

Once the driver has been created, it's important to add testsopen in new window, these can be mocked via a MockHandler, but should reflect the result of the actual API.

Note: All custom exceptions should implement the ProductTrap\Contracts\ProductTrapException interface.

The driver can then be published to Packagist, make sure to use the producttrap-driver keywordopen in new window so that your driver can be discovered more easily.