Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add complete order call #269

Merged
merged 5 commits into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Model/Order/PlaceOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
*/
class PlaceOrder implements PlaceOrderInterface
{
private const COMPLETE_ORDER_URL = '/checkout_sidekick/{{shopId}}/order/%s/state';

/**
* @var ResultInterfaceFactory
*/
Expand Down Expand Up @@ -373,6 +375,24 @@ function (array $error): ErrorInterface {

$this->updateCheckoutSession($quote, $order);

try {
$this->postCompleteOrder($publicOrderId, $websiteId, $order);
} catch (Exception $e) {
return $this->responseFactory->create(
[
'errors' => [
$this->errorFactory->create(
[
'message' => $e->getMessage(),
'code' => 500,
'type' => 'server.bold_checkout_api_error'
]
)
]
]
);
}

return $this->responseFactory->create(
[
'order' => $order
Expand Down Expand Up @@ -540,4 +560,19 @@ private function buildOrderData(array $firstTransaction, int $quoteId, string $p

return $orderData;
}

JosephLeedy marked this conversation as resolved.
Show resolved Hide resolved
private function postCompleteOrder(string $publicOrderId, int $websiteId, OrderInterface $order): void
{
$url = sprintf(self::COMPLETE_ORDER_URL, $publicOrderId);

$params = [
'state' => 'order_complete',
'platform_order_id' => $order->getIncrementId(),
'platform_friendly_id' => $order->getEntityId()
];
$response = $this->client->put($websiteId, $url, $params);
if ($response->getStatus() !== 201) {
throw new LocalizedException(__('Failed to post order completion'));
}
}
}