company_key); $company_gateway = CompanyGateway::find($this->company_gateway_id); $this->checkout = $company_gateway->driver()->init(); $webhook = new Webhook($this->checkout); $workflows = $webhook->getWorkFlows(); $wf = collect($workflows['data'])->first(function ($workflow) { return $workflow['name'] == $this->authentication_webhook_name; }); if($wf) return; $this->createAuthenticationWorkflow(); } /** * Creates an authentication workflow for 3DS * and also a registration mechanism for payments that have been approved. * * @return void */ public function createAuthenticationWorkflow() { $signature = new WebhookSignature(); $signature->key = $this->checkout->company_gateway->company->company_key; $signature->method = "HMACSHA256"; $actionRequest = new WebhookWorkflowActionRequest(); $actionRequest->url = $this->checkout->company_gateway->webhookUrl(); $actionRequest->signature = $signature; $eventWorkflowConditionRequest = new EventWorkflowConditionRequest(); $eventWorkflowConditionRequest->events = [ "gateway" => ["payment_approved"], "issuing" => ["authorization_approved","authorization_declined"], ]; $request = new CreateWorkflowRequest(); $request->actions = [$actionRequest]; $request->conditions = [$eventWorkflowConditionRequest]; $request->name = $this->authentication_webhook_name; $request->active = true; try { $response = $this->checkout->gateway->getWorkflowsClient()->createWorkflow($request); } catch (CheckoutApiException $e) { // API error $error_details = $e->error_details; $http_status_code = isset($e->http_metadata) ? $e->http_metadata->getStatusCode() : null; nlog("Checkout WEBHOOK creation error"); nlog($error_details); } catch (CheckoutAuthorizationException $e) { // Bad Invalid authorization } } }