Skip to content

Commit

Permalink
Add complete order call (#269)
Browse files Browse the repository at this point in the history
* Initial call attempt setup

* Add error handling for call

* Clean up call

* handle errors better

* Code clean up
  • Loading branch information
mwraich authored Jun 17, 2024
1 parent e679e84 commit 4fdeb0b
Showing 1 changed file with 35 additions and 0 deletions.
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 @@ -403,6 +405,24 @@ static function (array $transaction): bool {

$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 @@ -570,4 +590,19 @@ private function buildOrderData(array $firstTransaction, int $quoteId, string $p

return $orderData;
}

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'));
}
}
}

0 comments on commit 4fdeb0b

Please sign in to comment.