diff --git a/src/Entity/Sylius/Order.php b/src/Entity/Sylius/Order.php index b8e835198c..3783164ef2 100644 --- a/src/Entity/Sylius/Order.php +++ b/src/Entity/Sylius/Order.php @@ -56,7 +56,6 @@ use AppBundle\Entity\ReusablePackaging; use AppBundle\Entity\Task\RecurrenceRule; use AppBundle\Entity\Vendor; -use AppBundle\LoopEat\OAuthCredentialsInterface as LoopeatOAuthCredentialsInterface; use AppBundle\Payment\MercadopagoPreferenceResponse; use AppBundle\Sylius\Order\AdjustmentInterface; use AppBundle\Sylius\Order\OrderInterface; @@ -628,15 +627,6 @@ public function getCustomer(): ?CustomerInterface public function setCustomer(?CustomerInterface $customer): void { $this->customer = $customer; - - if (null !== $customer && $this->hasLoopEatCredentials()) { - - WMAssert::isInstanceOf($this->customer, LoopeatOAuthCredentialsInterface::class); - - $this->customer->setLoopeatAccessToken($this->loopeatCredentials->getLoopeatAccessToken()); - $this->customer->setLoopeatRefreshToken($this->loopeatCredentials->getLoopeatRefreshToken()); - $this->clearLoopEatCredentials(); - } } public function getTaxTotal(): int @@ -1753,11 +1743,23 @@ public function getLoopeatAccessToken() return null; } - return $this->loopeatCredentials->getLoopeatAccessToken(); + $accessToken = $this->loopeatCredentials->getLoopeatAccessToken(); + + // Guest checkout + if (null !== $accessToken) { + + return $accessToken; + } + + return $this->customer->getLoopeatAccessToken(); } public function setLoopeatAccessToken($accessToken) { + if (null !== $this->customer) { + $this->customer->setLoopeatAccessToken($accessToken); + } + if (null === $this->loopeatCredentials) { $this->loopeatCredentials = new OrderCredentials(); @@ -1774,11 +1776,23 @@ public function getLoopeatRefreshToken() return null; } - return $this->loopeatCredentials->getLoopeatRefreshToken(); + $refreshToken = $this->loopeatCredentials->getLoopeatRefreshToken(); + + // Guest checkout + if (null !== $refreshToken) { + + return $refreshToken; + } + + return $this->customer->getLoopeatRefreshToken(); } public function setLoopeatRefreshToken($refreshToken) { + if (null !== $this->customer) { + $this->customer->setLoopeatRefreshToken($refreshToken); + } + if (null === $this->loopeatCredentials) { $this->loopeatCredentials = new OrderCredentials(); diff --git a/src/LoopEat/Client.php b/src/LoopEat/Client.php index d948b667de..acdaa6d3cc 100644 --- a/src/LoopEat/Client.php +++ b/src/LoopEat/Client.php @@ -323,14 +323,13 @@ public function createOrder(OrderInterface $order) $currentRestaurant = $this->currentRestaurant($restaurant); - // Assert::isInstanceOf($order->getCustomer(), CustomerInterface::class); - Assert::isInstanceOf($order->getCustomer(), OAuthCredentialsInterface::class); + Assert::isInstanceOf($order, OAuthCredentialsInterface::class); $response = $this->client->request('POST', sprintf('/api/v1/partners/restaurants/%s/orders', $currentRestaurant['id']), [ 'headers' => [ - 'Authorization' => sprintf('Bearer %s', $order->getCustomer()->getLoopeatAccessToken()) + 'Authorization' => sprintf('Bearer %s', $order->getLoopeatAccessToken()) ], - 'oauth_credentials' => $order->getCustomer(), + 'oauth_credentials' => $order, 'json' => [ 'order' => [ 'external_id' => $order->getId(), diff --git a/tests/AppBundle/LoopEat/ClientTest.php b/tests/AppBundle/LoopEat/ClientTest.php index 5adb3a776c..200d17195d 100644 --- a/tests/AppBundle/LoopEat/ClientTest.php +++ b/tests/AppBundle/LoopEat/ClientTest.php @@ -60,11 +60,6 @@ public function testCreateOrder() { $restaurant = new Restaurant(); - $customer = $this->prophesize(CustomerInterface::class); - $customer - ->getLoopeatAccessToken() - ->willReturn('123456abcdef'); - $order = $this->prophesize(OrderInterface::class); $order @@ -76,8 +71,8 @@ public function testCreateOrder() ->willReturn($restaurant); $order - ->getCustomer() - ->willReturn($customer->reveal()); + ->getLoopeatAccessToken() + ->willReturn('123456abcdef'); $order ->getFormatsToDeliverForLoopeat()