diff --git a/src/Data/HasData.php b/src/Data/HasData.php index 508bae599..8b5081274 100644 --- a/src/Data/HasData.php +++ b/src/Data/HasData.php @@ -46,6 +46,13 @@ public function merge($data): self return $this; } + public function remove(string $key): self + { + unset($this->data[$key]); + + return $this; + } + public function toArray(): array { return $this->data()->toArray(); diff --git a/src/Gateways/Builtin/MollieGateway.php b/src/Gateways/Builtin/MollieGateway.php index 076f74382..98cf0af98 100644 --- a/src/Gateways/Builtin/MollieGateway.php +++ b/src/Gateways/Builtin/MollieGateway.php @@ -124,6 +124,19 @@ public function webhook(Request $request) event(new OrderPaymentFailed($order)); } + + if ($payment->status === MolliePaymentStatus::STATUS_EXPIRED) { + $order = $this->getOrderFromWebhookRequest($request); + + if (! $order) { + throw new OrderNotFound("Order related to Mollie transaction [{$mollieId}] could not be found."); + } + + $order + ->remove('mollie') + ->clearGatewayData() + ->save(); + } } public function fieldtypeDisplay($value): array diff --git a/src/Orders/Order.php b/src/Orders/Order.php index d6b771282..92618b131 100644 --- a/src/Orders/Order.php +++ b/src/Orders/Order.php @@ -227,6 +227,13 @@ public function gatewayData(?string $gateway = null, ?array $data = null, ?array return new GatewayData($this->gateway); } + public function clearGatewayData(): self + { + $this->gateway = null; + + return $this; + } + public function resource($resource = null) { return $this