From 0e4b986e81f8132a44e61fa8df18860301cc3468 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Thu, 01 Jan 2026 20:31:10 +0000
Subject: [PATCH] =JakeVan preliminary additions

---
 inc/integrations/PostMark.php |   56 ++++++++++++++++++++++++++++++++------------------------
 1 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/inc/integrations/PostMark.php b/inc/integrations/PostMark.php
index 41f467c..f9e154c 100644
--- a/inc/integrations/PostMark.php
+++ b/inc/integrations/PostMark.php
@@ -15,6 +15,13 @@
  */
 class PostMark extends Integrations
 {
+	protected ?string $server_token = null;
+	protected string $message_stream = 'outbound';
+	protected string $from_email;
+	protected string $from_name;
+	protected bool $track_open;
+	protected bool $track_links;
+	protected ?string $lastMessageId = null;
 	/**
 	 * Constructor
 	 */
@@ -22,9 +29,10 @@
 	{
 		$this->service_name = 'postmark';
 		$this->title = 'PostMark';
-		$this->description = 'Professional transactional email delivery service';
 		$this->icon = 'envelope-simple';
 
+		$this->cacheName = ($userID)? 'gmb_'.$userID : 'postmark';
+
 		// PostMark API configuration
 		$this->apiBase = 'https://api.postmarkapp.com';
 		$this->apiVersion = 'v1';
@@ -48,12 +56,13 @@
 		];
 
 		// Required credentials
-		$this->requiredCredentials = [
+		$this->fields = [
 			'server_token' => [
 				'label' => 'Server API Token',
-				'type' => 'password',
+				'type' => 'text',
+				'subtype'=> 'password',
 				'placeholder' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
-				'description' => 'Your PostMark Server API Token'
+				'hint' => 'Your PostMark Server API Token'
 			],
 			'message_stream' => [
 				'label' => 'Message Stream ID',
@@ -101,7 +110,7 @@
 		parent::__construct($userID);
 
 		// Hook into WordPress mail system if integration is healthy
-		if ($this->is_healthy && $this->hasValidCredentials()) {
+		if ($this->is_healthy && $this->isSetUp()) {
 			$this->initializeMailHooks();
 		}
 	}
@@ -249,6 +258,9 @@
 	 */
 	protected function sendEmail(array $payload): bool|WP_Error
 	{
+		if (!$this->isSetUp()) {
+			return false;
+		}
 		try {
 			$response = $this->postRequest('email', $payload);
 
@@ -271,7 +283,7 @@
 			return true;
 
 		} catch (\Exception $e) {
-			$this->handleException($e, 'email');
+			$this->logError('[POSTMARK]', ['method' => 'sendEmail', 'error' => $e->getMessage()]);
 			return new WP_Error(
 				'postmark_send_failed',
 				$e->getMessage()
@@ -459,22 +471,15 @@
 	/**
 	 * Override makeRequest to add PostMark headers
 	 */
-	protected function makeRequest(
-		string $method,
-		string $endpoint,
-		array $params = [],
-		array $headers = []
-	): mixed {
+	protected function getRequestHeaders(): array {
 		$credentials = $this->getCredentials();
 
 		// Add PostMark specific headers
-		$headers = array_merge([
+		return [
 			'Accept' => 'application/json',
 			'Content-Type' => 'application/json',
 			'X-Postmark-Server-Token' => $credentials['server_token'] ?? ''
-		], $headers);
-
-		return parent::makeRequest($method, $endpoint, $params, $headers);
+		];
 	}
 
 	/**
@@ -500,7 +505,7 @@
 				return $stats;
 			}
 		} catch (\Exception $e) {
-			$this->handleException($e, 'stats/outbound');
+			$this->logError('stats/outbound', ['error' => $e->getMessage()]);
 		}
 
 		return [];
@@ -517,7 +522,7 @@
 				'offset' => $offset
 			]);
 		} catch (\Exception $e) {
-			$this->handleException($e, 'bounces');
+			$this->logError('[POSTMARK]', ['method' => 'getBounces', 'error' => $e->getMessage()]);
 			return [];
 		}
 	}
@@ -634,11 +639,14 @@
 
 	protected function initialize(): void
 	{
-		// TODO: Implement initialize() method.
-	}
-
-	protected function getRequestHeaders(): array
-	{
-		// TODO: Implement getRequestHeaders() method.
+		if (empty($this->credentials)) {
+			$this->loadCredentials();
+		}
+		$this->server_token = (array_key_exists('server_token', $this->credentials)) ? $this->credentials['server_token'] : null;
+		$this->from_email = (array_key_exists('from_email', $this->credentials)) ? $this->credentials['from_email'] : get_bloginfo('admin_email');
+		$this->from_name = (array_key_exists('from_name', $this->credentials)) ? $this->credentials['from_name'] : get_bloginfo('name');
+		$this->message_stream = (array_key_exists('message_stream', $this->credentials)) ? $this->credentials['message_stream'] : 'outbound';
+		$this->track_open = (array_key_exists('track_open', $this->credentials)) ? $this->credentials['track_open'] : false;
+		$this->track_links = (array_key_exists('track_links', $this->credentials)) ? $this->credentials['track_links'] : false;
 	}
 }

--
Gitblit v1.10.0