Skip to content

Creating Drivers ‚Äč

To get started creating a driver, first clone the driver-skeleton repository.

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

You can then rename the Skeleton and SkeletonServiceProvider 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 DTO, 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 enum 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 tests, 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 keyword so that your driver can be discovered more easily.