diff --git a/Api/AdyenAnalyticsRepositoryInterface.php b/Api/AdyenAnalyticsRepositoryInterface.php new file mode 100644 index 0000000000..d19d16887e --- /dev/null +++ b/Api/AdyenAnalyticsRepositoryInterface.php @@ -0,0 +1,15 @@ +_init('Adyen\Payment\Model\ResourceModel\AdyenAnalytics'); + } + + public function getCheckoutAttemptId() + { + return $this->getData('checkoutAttemptId'); + } + + public function setCheckoutAttemptId($checkoutAttemptId) + { + return $this->setData('checkoutAttemptId', $checkoutAttemptId); + } + + public function getEventType() + { + return $this->getData('eventType'); + } + + public function setEventType($eventType) + { + return $this->setData('eventType', $eventType); + } + + public function getTopic() + { + return $this->getData('topic'); + } + + public function setTopic($topic) + { + return $this->setData('topic', $topic); + } + + public function getMessage() + { + return $this->getData('message'); + } + + public function setMessage($message) + { + return $this->setData('message', $message); + } + + public function getErrorCount() + { + return $this->getData('errorCount'); + } + + public function setErrorCount($errorCount) + { + return $this->setData('errorCount', $errorCount); + } + + public function getDone() + { + return $this->getData('done'); + } + + public function setDone($done) + { + return $this->setData('done', $done); + } + + public function getCreatedAt() + { + return $this->getData('createdAt'); + } + + public function setCreatedAt($createdAt) + { + return $this->setData('createdAt', $createdAt); + } + + public function getUpdatedAt() + { + return $this->getData('updatedAt'); + } + + public function setUpdatedAt($updatedAt) + { + return $this->setData('updatedAt', $updatedAt); + } +} diff --git a/Model/AdyenAnalyticsRepository.php b/Model/AdyenAnalyticsRepository.php new file mode 100644 index 0000000000..9ca4758e7b --- /dev/null +++ b/Model/AdyenAnalyticsRepository.php @@ -0,0 +1,48 @@ +resourceModel = $resourceModel; + $this->analyticsFactory = $analyticsFactory; + } + + public function save(AdyenAnalyticsInterface $analytics) + { + $this->resourceModel->save($analytics); + } + + public function getById($id) + { + $analytics = $this->analyticsFactory->create(); + $this->resourceModel->load($analytics, $id); + if (!$analytics->getId()) { + throw new NoSuchEntityException(__('Unable to find analytics with ID "%1"', $id)); + } + return $analytics; + } + + public function delete(AdyenAnalyticsInterface $analytics) + { + $this->resourceModel->delete($analytics); + } + + public function deleteById($id) + { + $analytics = $this->getById($id); + $this->delete($analytics); + } +} diff --git a/Model/ResourceModel/AdyenAnalytics.php b/Model/ResourceModel/AdyenAnalytics.php new file mode 100644 index 0000000000..76a1068cec --- /dev/null +++ b/Model/ResourceModel/AdyenAnalytics.php @@ -0,0 +1,12 @@ +_init('adyen_analytics', 'id'); + } +} diff --git a/Observer/DispatchAnalyticsEvent.php b/Observer/DispatchAnalyticsEvent.php new file mode 100644 index 0000000000..de01f118f1 --- /dev/null +++ b/Observer/DispatchAnalyticsEvent.php @@ -0,0 +1,55 @@ +eventManager = $eventManager; + $this->adyenAnalyticsRepository = $adyenAnalyticsRepository; + $this->analyticsFactory = $analyticsFactory; + } + + public function execute(Observer $observer) + { + // Sample data for dispatching the event + $eventData = [ + 'checkoutAttemptId' => '12345', + 'eventType' => 'payment_attempt', + 'topic' => 'payment_method_adyen_analytics', + 'message' => 'Sample payment analytics message.', + 'errorCount' => 0, + 'done' => false, + ]; + + // Dispatch the event + $this->eventManager->dispatch('payment_method_adyen_analytics', ['data' => $eventData]); + + // Create an instance of AdyenAnalyticsInterface + $analytics = $this->analyticsFactory->create(); + + // Set data to the analytics object + $analytics->setCheckoutAttemptId($eventData['checkoutAttemptId']); + $analytics->setEventType($eventData['eventType']); + $analytics->setTopic($eventData['topic']); + $analytics->setMessage($eventData['message']); + $analytics->setErrorCount($eventData['errorCount']); + $analytics->setDone($eventData['done']); + + // Save the analytics data to the database + $this->adyenAnalyticsRepository->save($analytics); + } +} diff --git a/Observer/ProcessAnalyticsEvent.php b/Observer/ProcessAnalyticsEvent.php new file mode 100644 index 0000000000..02b2a8a2a8 --- /dev/null +++ b/Observer/ProcessAnalyticsEvent.php @@ -0,0 +1,54 @@ +adyenAnalyticsRepository = $adyenAnalyticsRepository; + $this->adyenAnalyticsFactory = $adyenAnalyticsFactory; + $this->logger = $logger; + } + + public function execute(Observer $observer) + { + try { + // Get the event data + $eventData = $observer->getEvent()->getData('data'); + + // Log the event data for debugging (optional) + $this->logger->info('Received event data for payment_method_adyen_analytics: ', $eventData); + + // Create a new instance of the AdyenAnalytics model + $analytics = $this->adyenAnalyticsFactory->create(); + + // Populate the model with event data + $analytics->setCheckoutAttemptId($eventData['checkoutAttemptId']); + $analytics->setEventType($eventData['eventType']); + $analytics->setTopic($eventData['topic']); + $analytics->setMessage($eventData['message']); + $analytics->setErrorCount($eventData['errorCount']); + $analytics->setDone($eventData['done']); + + // Save the event data to the database + $this->adyenAnalyticsRepository->save($analytics); + + } catch (\Exception $e) { + // Log any exceptions + $this->logger->error('Error processing payment_method_adyen_analytics event: ' . $e->getMessage()); + } + } +} diff --git a/etc/db_schema.xml b/etc/db_schema.xml index 6f61474813..471cda7b6c 100644 --- a/etc/db_schema.xml +++ b/etc/db_schema.xml @@ -126,4 +126,18 @@ + + + + + + + + + + + + + +
diff --git a/etc/db_schema_whitelist.json b/etc/db_schema_whitelist.json index d0067f852a..808a2a778b 100644 --- a/etc/db_schema_whitelist.json +++ b/etc/db_schema_whitelist.json @@ -110,5 +110,18 @@ "constraint": { "PRIMARY": true } + }, + "adyen_analytics": { + "columns": { + "id": {}, + "checkoutAttemptId": {}, + "eventType": {}, + "topic": {}, + "message": {}, + "errorCount": {}, + "done": {}, + "createdAt": {}, + "updatedAt": {} + } } } diff --git a/etc/di.xml b/etc/di.xml index b87676dffa..057c465518 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -1671,6 +1671,13 @@ + + + Adyen\Payment\Model\AdyenAnalytics + + + + diff --git a/etc/events.xml b/etc/events.xml index 1520613215..53bccea0ca 100644 --- a/etc/events.xml +++ b/etc/events.xml @@ -302,6 +302,9 @@ + + +