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

PISHPS-371: Return empty data instead of 500 #877

Merged
Merged
Show file tree
Hide file tree
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
16 changes: 15 additions & 1 deletion src/Components/RefundManager/RefundManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Kiener\MolliePayments\Components\RefundManager\Request\RefundRequestItem;
use Kiener\MolliePayments\Components\RefundManager\Request\RefundRequestItemRoundingDiff;
use Kiener\MolliePayments\Exception\CouldNotCreateMollieRefundException;
use Kiener\MolliePayments\Exception\CouldNotFetchMollieOrderException;
use Kiener\MolliePayments\Service\MollieApi\Fixer\RoundingDifferenceFixer;
use Kiener\MolliePayments\Service\MollieApi\Order;
use Kiener\MolliePayments\Service\OrderServiceInterface;
Expand Down Expand Up @@ -115,7 +116,20 @@ public function __construct(RefundDataBuilder $refundDataBuilder, OrderServiceIn
*/
public function getData(OrderEntity $order, Context $context): RefundData
{
return $this->builderData->buildRefundData($order, $context);
try {
return $this->builderData->buildRefundData($order, $context);
} catch (CouldNotFetchMollieOrderException $e) {
return new RefundData(
[],
[],
0.0,
0.0,
0.0,
0.0,
0.0,
$order->getTaxStatus(),
);
}
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/Components/ShipmentManager/ShipmentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ public function getStatus(string $orderId, Context $context): array
return $this->shipmentService->getStatus($mollieOrderId, $order->getSalesChannelId());
}

/**
* @param string $orderId
* @param Context $context
* @return array<mixed>
*/
public function getShopwareStatus(string $orderId, Context $context): array
{
$order = $this->orderService->getOrder($orderId, $context);

return $this->orderService->getStatus($order);
}

/**
* @param string $orderId
* @param Context $context
Expand Down
7 changes: 6 additions & 1 deletion src/Controller/Api/Order/CancelLineController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use Kiener\MolliePayments\Components\CancelManager\CancelItemFacade;
use Kiener\MolliePayments\Factory\MollieApiFactory;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\OrderLine;
use Shopware\Core\Framework\Context;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand All @@ -28,7 +29,11 @@ public function statusAction(Request $request, Context $context): Response
$orderId = $request->get('mollieOrderId');
$result = [];
$client = $this->clientFactory->getClient();
$mollieOrder = $client->orders->get($orderId);
try {
$mollieOrder = $client->orders->get($orderId);
} catch (ApiException $e) {
return new JsonResponse($result);
}

$lines = $mollieOrder->lines();
if ($lines->count() > 0) {
Expand Down
3 changes: 3 additions & 0 deletions src/Controller/Api/Order/ShippingControllerBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Kiener\MolliePayments\Components\ShipmentManager\Models\ShipmentLineItem;
use Kiener\MolliePayments\Components\ShipmentManager\Models\TrackingData;
use Kiener\MolliePayments\Components\ShipmentManager\ShipmentManager;
use Kiener\MolliePayments\Exception\CouldNotFetchMollieOrderException;
use Kiener\MolliePayments\Service\OrderService;
use Kiener\MolliePayments\Struct\OrderLineItemEntity\OrderLineItemEntityAttributes;
use Kiener\MolliePayments\Traits\Api\ApiTrait;
Expand Down Expand Up @@ -580,6 +581,8 @@ private function getStatusResponse(string $orderId, Context $context): JsonRespo
{
try {
$status = $this->shipment->getStatus($orderId, $context);
} catch (CouldNotFetchMollieOrderException $e) {
$status = $this->shipment->getShopwareStatus($orderId, $context);
} catch (ShopwareHttpException $e) {
$this->logger->error($e->getMessage());
return $this->json(['message' => $e->getMessage()], $e->getStatusCode());
Expand Down
6 changes: 5 additions & 1 deletion src/Service/MollieApi/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,11 @@ private function createNewOrderPayment(MollieOrder $mollieOrder, string $payment

public function getPaymentUrl(string $mollieOrderId, string $salesChannelId): ?string
{
$mollieOrder = $this->getMollieOrder($mollieOrderId, $salesChannelId);
try {
$mollieOrder = $this->getMollieOrder($mollieOrderId, $salesChannelId);
} catch (CouldNotFetchMollieOrderException $e) {
return null;
}

return $mollieOrder->status === 'created' ? $mollieOrder->getCheckoutUrl() : null;
}
Expand Down
10 changes: 9 additions & 1 deletion src/Service/MollieApi/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Kiener\MolliePayments\Service\MollieApi;

use Kiener\MolliePayments\Exception\CouldNotFetchMollieOrderException;
use Kiener\MolliePayments\Exception\MollieOrderCouldNotBeShippedException;
use Kiener\MolliePayments\Service\MollieApi\Models\MollieShippingItem;
use Kiener\MolliePayments\Struct\MollieApi\ShipmentTrackingInfoStruct;
Expand Down Expand Up @@ -174,7 +175,14 @@ public function getStatus(string $mollieOrderId, string $salesChannelId): array
*/
public function getTotals(string $mollieOrderId, string $salesChannelId): array
{
$mollieOrder = $this->orderApiService->getMollieOrder($mollieOrderId, $salesChannelId);
try {
$mollieOrder = $this->orderApiService->getMollieOrder($mollieOrderId, $salesChannelId);
} catch (CouldNotFetchMollieOrderException $e) {
return [
'amount' => 0.0,
'quantity' => 0,
];
}

$totalAmount = 0.0;
$totalQuantity = 0;
Expand Down
27 changes: 27 additions & 0 deletions src/Service/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,31 @@ public function updateMollieData(OrderEntity $order, string $orderTransactionId,
$context
);
}

/**
* @param OrderEntity $order
* @return array<string,array<string,mixed>>
*/
public function getStatus(OrderEntity $order): array
{
$lineItems = [];

$orderLineItems = $order->getLineItems();

if ($orderLineItems === null) {
return $lineItems;
}

foreach ($orderLineItems as $lineItem) {
$lineItems[$lineItem->getId()] = [
'id' => $lineItem->getId(),
'mollieOrderLineId' => null,
'quantity' => $lineItem->getQuantity(),
'quantityShippable' => 0,
'quantityShipped' => 0,
];
}

return $lineItems;
}
}
Loading