ddb/stuart-api-bundle

Bundle to communicate with the stuart API

Installs: 76

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:symfony-bundle

1.1.10 2019-05-29 09:23 UTC

This package is auto-updated.

Last update: 2024-03-29 03:44:53 UTC


README

Simple bundle using the stuart php library to integrate with symfony

Configuration

stuart_api:
  private_key: "stuart super private key"
  public_key: "stuart public key"
  environment: "SANDBOX" // OR "PRODUCTION"
  vat_rate: 20
    authorized_webhook_ips:
      sandbox:
        - "34.254.62.41"
        - "54.194.139.211"
      production:
        - "108.128.110.19"
        - "54.171.243.90"
        - "52.51.60.65"

Functions

StuartApi

Used to create and dispatch jobs

  • public function createJobObjectFromRequest(Request $request)
  • public function createJobObject(
  • public function addJob(Job $job)

StuartApiController

These function have routes exposed and return a JSONResponse

  • nextPickupSlot($city = "Bordeaux") : Get the next available pickup slot for the city
  • validateJob(Request $request)
  • priceJob(Request $request)

Events

StuartApiEvents.php defines constants for the event names

WebhookEvent.php

This event redispatches any requests on the /webhook route. You can register an EventSubscriberInterface in your application to listen to these events and update your orders accordingly.

Only Request coming from the whitelisted ips in the configuration will be allowed through and only for the corresponding environment.

namespace App\EventSubscriber;

use DdB\StuartApiBundle\Event\StuartApiEvents;
use DdB\StuartApiBundle\Event\WebhookEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class StuartWebhookSubscriber implements EventSubscriberInterface
{
    public function onStuartApiWebhook(WebhookEvent $event)
    {
        $request = $event->getRequest();
        //Do something with the request
    }

    public static function getSubscribedEvents()
    {
        return [
           StuartApiEvents::WEBHOOK_API => 'onStuartApiWebhook',
        ];
    }
}

Translations

All the errors returned by the Stuart API can be translated using the Errors.(lang).yaml files inside Resources/translations