diff --git a/src/Events/EventFactory.php b/src/Events/EventFactory.php index 2d987ce..0545ac0 100644 --- a/src/Events/EventFactory.php +++ b/src/Events/EventFactory.php @@ -42,10 +42,14 @@ public function create(ServerNotification $notification): PurchaseEvent ->lower() ->studly() ->prepend(self::NAMESPACES[$provider].'\\'); - assert(class_exists($className), new LogicException("Class $className does not exist")); + + if (! class_exists($className)) { + return new FallbackEvent($notification); + } + assert( - is_subclass_of($className, PurchaseEvent::class), - new LogicException("Class $className is not a subclass of PurchaseEvent") + is_a($className, PurchaseEvent::class, true), + new LogicException("Invalid event class: $className") ); return new $className($notification); diff --git a/src/Events/FallbackEvent.php b/src/Events/FallbackEvent.php new file mode 100644 index 0000000..0e59ff7 --- /dev/null +++ b/src/Events/FallbackEvent.php @@ -0,0 +1,9 @@ +