Handle Request URL Configuration & Verification

@param array $payload
@return JsonResponse
@see https://api.slack.com/events-api#request_url_configuration__amp__verification
425857
public function execute(array $payload): JsonResponse
    {
        $challenge = $payload['challenge'] ?? null;
        if ($challenge) {
            return new JsonResponse(['challenge' => $challenge]);
        }

        throw new RuntimeException();
    }
702309
protected function handlePayload(Request $request, Response $response, Payload $payload): Response
    {
        $handler = $this->getHandler($request);

        return $response
            ->withBody(Factory::newStream($handler->body($payload)))
            ->withHeader('Content-Type', $handler->type())
            ->withStatus($payload->getCode())
        ;
    }
805448
public function handle($event, $payload)
    {
        list($model) = $payload;
        
        if (!empty($model->locale)
            && empty($model->locale_group)
            && !is_a($model, Element::class) // Elements don't have groups
            && ($locales = Config::get('decoy.site.locales'))
            && count($locales) > 1) {
            $model->setAttribute('locale_group', Str::random());
        }
    }
689850
public function get(string $url, ?array $payload = null): TransportClientResponse {
        return $this->sendRequest($url . static::QUESTION_MARK . http_build_query($payload), array());
    }
1136456
public function process($payload) {
        $result = $this->convertToObject($payload, true);

        return $this->processPayload($result);
    }
78404
private function sendTransmission(array $payload)
    {
        try {
            /** @noinspection PhpUndefinedVariableInspection */
            $promise = $this->sparkpost->transmissions->post($payload);

            if ($promise instanceof SparkPostResponse) {
                $response = $promise;
            } else {
                $response = $promise->wait();
            }
        } catch (AnyException $exception) {
            throw $this->createAndDispatchTransportException(
                'Failed to send transmission to SparkPost',
                $exception
            );
        }

        if (!isset($response->getBody()['results'])) {
            throw $this->createAndDispatchTransportException(
                'Failed to send transmission to SparkPost',
                new Exception(json_encode($response->getBody()))
            );
        }

        return $response;
    }
985074
protected function handleCustomerSubscriptionDeleted(array $payload)
    {
        $user = $this->getUserByStripeId($payload['data']['object']['customer']);
        if ($user) {
            $subscriptions = $user->getSubscriptions()->all();
            /* @var $subscription SubscriptionModel */
            foreach ($subscriptions as $subscription) {
                if ($subscription->stripe_id === $payload['data']['object']['id']) {
                    $subscription->markAsCancelled();
                }
            }
        }

        return new Response([
            'statusCode' => 200,
            'statusText' => 'Webhook Handled',
        ]);
    }
772251
public function addContact(array $payload)
    {
        $query = [];
        $query['action_by'] = 'ACTION_BY_OWNER';

        $options = [
            'json'  => $payload,
            'query' => $query,
        ];

        return $response = $this->request('POST', 'contacts', $options);
    }
83402
public function bind(array $payload=null)
    {
        $bound = false;
        $this->_boundEntities = array();

        if (!is_null($payload)
            && isset($payload[$this->getName()])
            && $this->validateSynchronizerToken($payload)
        ) {
            $this->logger->debug('start binding form', array('name' => $this->getName(), 'payload' => $payload));

            $propertyMapper = new PropertyMapper();

            /**
             * @var $entityContainer    \Naucon\Form\Mapper\EntityContainerInterface
             */
            if ($this->getEntityContainerMap()->count() > 0) {
                if (!is_null($entityContainer = current($this->getEntityContainerMap()->getAll()))) {
                    $propertyMapper->mapFormToData($entityContainer->getEntity(), $payload[$this->getName()]);
                    $this->addBoundEntity($entityContainer->getEntity());

                    // postbind hook
                    $this->logger->debug('invoke form postbind hook', array('name' => $this->getName(), 'entity' => $entityContainer->getName()));
                    $entityContainer->invokeHook('postbindHook');

                    $bound = true;
                }
            }
        }


        $this->setBound($bound);

        $this->logger->debug('execute post binding form', array('name' => $this->getName()));
        $this->postBind();

        if ($this->isBound()) {
            $this->logger->debug('finished binding form successful', array('name' => $this->getName()));
        } else {
            $this->logger->debug('finished binding form failed', array('name' => $this->getName()));
        }
        return $this->isBound();
    }
692637
private function isValidResult($payload): bool
    {
        if (!is_array($payload)) {
            return false;
        }

        $headerValid = array_key_exists('jsonrpc', $payload) && $payload['jsonrpc'] === '2.0';
        $resultValid = array_key_exists('result', $payload);
        $idValid     = array_key_exists('id', $payload);

        return $headerValid && $resultValid && $idValid;
    }
347039
public function performApiRequest($endpoint, $payload)
    {
        $this->setupRequest($payload);
        $this->apiEndpoint = $endpoint;

        return $this->doDropboxApiRequest();
    }
885017
private function httpPost( $path, Array $payload ){

        $url = new Uri( $this->baseUrl . $path );

        $request = new Request(
            'POST',
            $url,
            $this->buildHeaders(),
            json_encode( $payload )
        );

        try {

            $response = $this->getHttpClient()->sendRequest( $request );

        } catch (\RuntimeException $e){
            throw new Exception\NotifyException( $e->getMessage(), $e->getCode(), $e );
        }

        //---

        switch( $response->getStatusCode() ){
            case 200:
            case 201:
                return $this->handleResponse( $response );
            default:
                return $this->handleErrorResponse( $response );
        }

    }
1259415
public function execute($action, array $payload)
    {
        $executor = $this->getExecutor($action);

        // dispatch pre event, listeners may change the payload here
        $event = new ExecutionEvent($executor, $action, $payload);
        $this->dispatcher->dispatch(WorkerEvents::PRE_EXECUTE_ACTION, $event);

        try {
            $resolver = $this->getPayloadResolver($executor);
            $payload  = $resolver->resolve($event->getPayload());
        } catch (ExceptionInterface $exception) {
            $this->logger->error(
                sprintf(
                    'Payload %s for "%s" is invalid: %s',
                    json_encode($payload, JSON_UNESCAPED_SLASHES),
                    $action,
                    $exception->getMessage()
                )
            );

            return false;
        }

        $result = $executor->execute($payload);
        // dispatch post event, listeners may change the result here
        $event->setResult($result);
        $this->dispatcher->dispatch(WorkerEvents::POST_EXECUTE_ACTION, $event);

        return $event->getResult();
    }
827791
public function handle($event, $payload)
    {
        list($model) = $payload;

        // Get the action from the event name
        preg_match('#\.(\w+)#', $event, $matches);
        $action = $matches[1];

        // If there is matching callback method on the model, call it, passing
        // any additional event arguments to it
        $method = 'on'.Str::studly($action);
        if (method_exists($model, $method)) {
            return call_user_func_array([$model, $method], array_slice($payload, 1));
        }
    }
124754
public function process($payload)
    {
        foreach ($this->stages as $stage) {
            $payload = call_user_func($stage, $payload);
        }
        return $payload;
    }
596681
public function update(array $payload): bool
    {
        $resourceType = static::resourceType();
        $response = null;

        try {
            $response = $this->getHttpClient()->request('PUT', $this->apiUrl(), [
                'json' => $payload,
            ]);
        } catch (RequestException $e) {
            $this->throwResourceException($e->getResponse(), 'update', UpdateResourceException::class);
        }

        $json = json_decode((string) $response->getBody(), true);

        if (empty($json[$resourceType])) {
            return false;
        }

        $this->data = $json[$resourceType];

        return true;
    }
1283516
protected function resolveAndHandle(array $payload)
    {
        list($class, $method) = Str::parseCallback($payload['job'], 'handle');

        $this->instance = $this->resolve($class);

        call_user_func(array($this->instance, $method), $this, $payload['data']);
    }