diff --git a/src/Postmark/Models/PostmarkBounce.php b/src/Postmark/Models/PostmarkBounce.php
index 28a9cc09..dd443b0c 100644
--- a/src/Postmark/Models/PostmarkBounce.php
+++ b/src/Postmark/Models/PostmarkBounce.php
@@ -4,6 +4,7 @@
class PostmarkBounce
{
+ public string $RecordType;
public int $ID;
public string $Type;
public int $TypeCode;
@@ -25,6 +26,7 @@ class PostmarkBounce
public function __construct(array $values)
{
+ $this->RecordType = !empty($values['RecordType']) ? $values['RecordType'] : '';
$this->ID = !empty($values['ID']) ? $values['ID'] : 0;
$this->Type = !empty($values['Type']) ? $values['Type'] : 0;
$this->TypeCode = !empty($values['TypeCode']) ? $values['TypeCode'] : '';
@@ -45,6 +47,17 @@ public function __construct(array $values)
$this->Content = !empty($values['Content']) ? $values['Content'] : '';
}
+ public function getRecordType(): mixed
+ {
+ return $this->RecordType;
+ }
+
+ public function setRecordType(mixed $RecordType): PostmarkBounce
+ {
+ $this->RecordType = $RecordType;
+ return $this;
+ }
+
public function getID(): int
{
return $this->ID;
diff --git a/src/Postmark/Models/PostmarkBounceActivation.php b/src/Postmark/Models/PostmarkBounceActivation.php
index e9dd90ec..d41327ef 100644
--- a/src/Postmark/Models/PostmarkBounceActivation.php
+++ b/src/Postmark/Models/PostmarkBounceActivation.php
@@ -10,7 +10,7 @@ class PostmarkBounceActivation
public function __construct(array $values)
{
$this->Message = !empty($values['Message']) ? $values['Message'] : '';
- $this->Bounce = !empty($values['Bounce']) ? $values['Bounce'] : new PostmarkBounce([]);
+ $this->setBounce(!empty($values['Bounce']) ? $values['Bounce'] : array());
}
/**
@@ -40,11 +40,12 @@ public function getBounce(): mixed
}
/**
- * @param mixed|PostmarkBounce $Bounce
+ * @param array $Bounce
+ * @return PostmarkBounceActivation
*/
- public function setBounce(mixed $Bounce): PostmarkBounceActivation
+ public function setBounce(array $Bounce): PostmarkBounceActivation
{
- $this->Bounce = $Bounce;
+ $this->Bounce = new PostmarkBounce($Bounce);
return $this;
}
diff --git a/tests/PostmarkClientBounceTest.php b/tests/PostmarkClientBounceTest.php
index f435ce1b..c6331eed 100644
--- a/tests/PostmarkClientBounceTest.php
+++ b/tests/PostmarkClientBounceTest.php
@@ -4,7 +4,9 @@
require_once __DIR__ . '/PostmarkClientBaseTest.php';
+use Postmark\Models;
use Postmark\PostmarkClient;
+use Postmark\tests;
/**
* @internal
@@ -13,6 +15,11 @@
*/
class PostmarkClientBounceTest extends PostmarkClientBaseTest
{
+ public static function setUpBeforeClass(): void
+ {
+ PostmarkClientSuppressionsTest::tearDownAfterClass();
+ }
+
public function testClientCanGetDeliveryStatistics()
{
$tk = parent::$testKeys;
@@ -41,6 +48,7 @@ public function testClientCanGetBounce()
$id = $bounces->getBounces()[0]->getID();
$bounce = $client->getBounce($id);
$this->assertNotEmpty($bounce);
+ $this->assertEquals($id, $bounce->getID());
}
public function testClientCanGetBounceDump()
@@ -51,5 +59,71 @@ public function testClientCanGetBounceDump()
$id = $bounces->Bounces[0]->getID();
$dump = $client->getBounceDump($id);
$this->assertNotEmpty($dump);
+ $this->assertNotEmpty($dump->getBody());
+ }
+
+ public function testClientCanActivateBounce()
+ {
+ $tk = parent::$testKeys;
+ $client = new PostmarkClient($tk->WRITE_TEST_SERVER_TOKEN, $tk->TEST_TIMEOUT);
+
+ // make sure that this email is not suppressed
+ // generate a bounces
+ $fromEmail = $tk->WRITE_TEST_SENDER_EMAIL_ADDRESS;
+ $toEmail = "hardbounce@bounce-testing.postmarkapp.com"; // special email to generate bounce
+ $subject = "Hello from Postmark!";
+ $htmlBody = "Hello dear Postmark user.";
+ $textBody = "Hello dear Postmark user.";
+ $tag = "example-email-tag";
+ $trackOpens = true;
+ $trackLinks = "None";
+
+ $sendResult = $client->sendEmail(
+ $fromEmail,
+ $toEmail,
+ $subject,
+ $htmlBody,
+ $textBody,
+ $tag,
+ $trackOpens,
+ NULL, // Reply To
+ NULL, // CC
+ NULL, // BCC
+ NULL, // Header array
+ NULL, // Attachment array
+ $trackLinks,
+ NULL // Metadata array
+ );
+
+ // make sure there is enough time for the bounce to take place.
+ sleep(180);
+
+ $bounceList = $client->getBounces(20, 0);
+ $id = 0;
+ $sentId = $sendResult->getMessageID();
+ $bounces = $bounceList->getBounces();
+
+ $this->assertNotEmpty($bounces);
+ $this->assertNotEmpty($sentId);
+
+ foreach ($bounces as $bounce)
+ {
+ $bmid = $bounce->getMessageID();
+ echo "\n Bounce ID: $bmid Sent id: $sentId";
+ if ($sentId === $bmid)
+ {
+ $id = $bounce->getID();
+ echo "Made it!! $id";
+ break;
+ }
+ }
+
+ $this->assertGreaterThan(0, $id);
+
+ $bounceActivation = $client->activateBounce($id);
+ $actBounce = $bounceActivation->getBounce();
+
+ $this->assertNotEmpty($actBounce);
+ $this->assertEquals($id, $actBounce->getID());
}
}
diff --git a/tests/PostmarkClientSuppressionsTest.php b/tests/PostmarkClientSuppressionsTest.php
index bdbca4ed..991a4258 100644
--- a/tests/PostmarkClientSuppressionsTest.php
+++ b/tests/PostmarkClientSuppressionsTest.php
@@ -19,6 +19,15 @@ public static function tearDownAfterClass(): void
{
$tk = parent::$testKeys;
$client = new PostmarkClient($tk->WRITE_TEST_SERVER_TOKEN, $tk->TEST_TIMEOUT);
+
+ // remove all suppressions on the default stream
+ $sups = $client->getSuppressions();
+ foreach ($sups->getSuppressions() as $sup)
+ {
+ $suppressionChanges = [new SuppressionChangeRequest($sup->getEmailAddress())];
+ $messageStream = 'outbound';
+ $client->deleteSuppressions($suppressionChanges, $messageStream);
+ }
}
// create suppression
diff --git a/tests/PostmarkClientTemplatesTest.php b/tests/PostmarkClientTemplatesTest.php
index 0510542c..5a4cac0d 100644
--- a/tests/PostmarkClientTemplatesTest.php
+++ b/tests/PostmarkClientTemplatesTest.php
@@ -4,6 +4,7 @@
require_once __DIR__ . '/PostmarkClientBaseTest.php';
+use Postmark\Models\MessageStream\PostmarkMessageStream;
use Postmark\Models\PostmarkAttachment;
use Postmark\Models\TemplatedPostmarkMessage;
use Postmark\PostmarkClient;
@@ -156,12 +157,41 @@ public function testClientCanSendMailWithTemplate()
{
$tk = parent::$testKeys;
$client = new PostmarkClient($tk->WRITE_TEST_SERVER_TOKEN, $tk->TEST_TIMEOUT);
+
+ // make sure the message stream exists
+ $id = 'php-test';
+ $messageStreamType = 'Transactional';
+ $name = 'PHP Test';
+ $description = 'Test Stream Description';
+ $createdStream = new PostmarkMessageStream(array());
+ try
+ {
+ $createdStream = $client->getMessageStream($id);
+ }
+ catch (\Exception $ex)
+ {
+ $createdStream = $client->createMessageStream($id, $messageStreamType, $name, $description);
+ }
+
+ $this->assertEquals($id, $createdStream->getID());
+
$result = $client->createTemplate('test-php-template-' . date('c'), '{{subject}}', 'Hello {{name}}!', 'Hello {{name}}!');
$emailResult = $client->sendEmailWithTemplate(
$tk->WRITE_TEST_SENDER_EMAIL_ADDRESS,
$tk->WRITE_TEST_EMAIL_RECIPIENT_ADDRESS,
$result->getTemplateId(),
- ['subjectValue' => 'Hello!']
+ ['subjectValue' => 'Hello!'],
+ false,
+ "TestTag",
+ true,
+ $tk->WRITE_TEST_SENDER_EMAIL_ADDRESS,
+ null, //cc
+ null, //bcc
+ null, // headers
+ null, // attachments
+ null, // tracklinks
+ null, // metadata
+ "php-test" // stream name
);
$this->assertEquals(0, $emailResult->getErrorCode());