/**
  * Creates an address object
  *
  * @param OrderInterface $order
  *
  * @return Address
  */
 protected function createAddress(OrderInterface $order) : Address
 {
     $address = new Address();
     $address->setLine1($order->getBillingAddress()->getLine1());
     $address->setLine2($order->getBillingAddress()->getLine2());
     $address->setCity($order->getBillingAddress()->getCity());
     $address->setPostalCode($order->getBillingAddress()->getPostalCode());
     $address->setCountryCode($order->getBillingAddress()->getCountry());
     return $address;
 }
 private function autoRegisterClient(OrderInterface $order) : ClientInterface
 {
     /** @var $client ClientInterface */
     $client = $this->get('client.manager')->initResource();
     $client->setClientDetails($order->getClientDetails());
     $client->setContactDetails($order->getContactDetails());
     $client->setBillingAddress($order->getBillingAddress());
     $client->setShippingAddress($order->getShippingAddress());
     $this->get('client.manager')->createResource($client);
     $token = new UsernamePasswordToken($client, $client->getPassword(), "client", $client->getRoles());
     $this->container->get('security.token_storage')->setToken($token);
     $event = new InteractiveLoginEvent($this->getRequestHelper()->getCurrentRequest(), $token);
     $this->get("event_dispatcher")->dispatch('security.interactive_login', $event);
     return $client;
 }