-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add transactional emails support (#8)
* Transactional emails * Send bulk custom emails
- Loading branch information
Showing
21 changed files
with
1,314 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,6 +255,114 @@ if ($customField = $api->customFields()->exists('name')) { | |
} | ||
``` | ||
|
||
### Send / Transactional emails | ||
The implementation of API call ``send/transactional-emails-bulk``: https://app.smartemailing.cz/docs/api/v3/index.html#api-Custom_campaigns-Send_transactional_emails | ||
## Full transactional email example | ||
```php | ||
$transactionEmail = new TransactionalEmails($api); | ||
|
||
$credentials = new SenderCredentials(); | ||
$credentials->setFrom('[email protected]'); | ||
$credentials->setReplyTo('[email protected]'); | ||
$credentials->setSenderName('Jean-Luc Picard'); | ||
|
||
$recipient = new Recipient(); | ||
$recipient->setEmailAddress('[email protected]'); | ||
|
||
$replace1 = new Replace(); | ||
$replace1->setKey('key1'); | ||
$replace1->setContent('content1'); | ||
|
||
$replace2 = new Replace(); | ||
$replace2->setKey('key2'); | ||
$replace2->setContent('content2'); | ||
|
||
$templateVariable = new TemplateVariable(); | ||
$templateVariable->setCustomData([ | ||
'foo' => 'bar', | ||
'products' => [ | ||
['name' => 'prod1', 'desc' => 'desc1'], | ||
['name' => 'prod1', 'desc' => 'desc2'] | ||
] | ||
]); | ||
|
||
$attachment1 = new Attachment(); | ||
$attachment1->setContentType('image/png'); | ||
$attachment1->setFileName('picture.png'); | ||
$attachment1->setDataBase64('data1'); | ||
|
||
$attachment2 = new Attachment(); | ||
$attachment2->setContentType('image/gif'); | ||
$attachment2->setFileName('sun.gif'); | ||
$attachment2->setDataBase64('data2'); | ||
|
||
$task = new Task(); | ||
$task->setRecipient($recipient); | ||
$task->addReplace($replace1); | ||
$task->addReplace($replace2); | ||
$task->setTemplateVariables($templateVariable); | ||
$task->addAttachment($attachment1); | ||
$task->addAttachment($attachment2); | ||
|
||
$messageContents = new MessageContents(); | ||
$messageContents->setTextBody('text_body'); | ||
$messageContents->setHtmlBody('html_body'); | ||
$messageContents->setSubject('subject'); | ||
|
||
$transactionEmail->setTag('tag_tag'); | ||
$transactionEmail->setEmailId(5); | ||
$transactionEmail->setSenderCredentials($credentials); | ||
$transactionEmail->addTask($task); | ||
$transactionEmail->setMessageContents($messageContents); | ||
|
||
$transactionEmail->send(); | ||
``` | ||
|
||
### Send / Bulk custom emails | ||
The implementation of API call ``send/custom-emails-bulk``: https://app.smartemailing.cz/docs/api/v3/index.html#api-Custom_campaigns-Send_bulk_custom_emails | ||
## Full transactional email example | ||
```php | ||
$transactionEmail = new BulkCustomEmails($api); | ||
|
||
$credentials = new SenderCredentials(); | ||
$credentials->setFrom('[email protected]'); | ||
$credentials->setReplyTo('[email protected]'); | ||
$credentials->setSenderName('Jean-Luc Picard'); | ||
|
||
$recipient = new Recipient(); | ||
$recipient->setEmailAddress('[email protected]'); | ||
|
||
$replace1 = new Replace(); | ||
$replace1->setKey('key1'); | ||
$replace1->setContent('content1'); | ||
|
||
$replace2 = new Replace(); | ||
$replace2->setKey('key2'); | ||
$replace2->setContent('content2'); | ||
|
||
$templateVariable = new TemplateVariable(); | ||
$templateVariable->setCustomData([ | ||
'foo' => 'bar', | ||
'products' => [ | ||
['name' => 'prod1', 'desc' => 'desc1'], | ||
['name' => 'prod1', 'desc' => 'desc2'] | ||
] | ||
]); | ||
|
||
$task = new Task(); | ||
$task->setRecipient($recipient); | ||
$task->addReplace($replace1); | ||
$task->addReplace($replace2); | ||
$task->setTemplateVariables($templateVariable); | ||
|
||
$transactionEmail->setTag('tag_tag'); | ||
$transactionEmail->setEmailId(5); | ||
$transactionEmail->setSenderCredentials($credentials); | ||
$transactionEmail->addTask($task); | ||
|
||
$transactionEmail->send(); | ||
``` | ||
|
||
## Changelog | ||
|
||
### 0.1.8 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SmartEmailing\v3\Request\Send; | ||
|
||
use JsonSerializable; | ||
use SmartEmailing\v3\Request\AbstractRequest; | ||
|
||
/** | ||
* Class TransactionEmails | ||
* | ||
* @link https://app.smartemailing.cz/docs/api/v3/index.html#api-Custom_campaigns-Send_transactional_emails | ||
*/ | ||
abstract class AbstractSend extends AbstractRequest implements JsonSerializable | ||
{ | ||
/** @var SenderCredentials */ | ||
protected $senderCredentials; | ||
/** @var int */ | ||
protected $emailId; | ||
/** @var string */ | ||
protected $tag; | ||
/** @var Task[] */ | ||
protected $tasks = []; | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getEmailId(): ?int | ||
{ | ||
return $this->emailId; | ||
} | ||
|
||
/** | ||
* @param int $emailId | ||
*/ | ||
public function setEmailId(int $emailId): void | ||
{ | ||
$this->emailId = $emailId; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getTag(): ?String | ||
{ | ||
return $this->tag; | ||
} | ||
|
||
/** | ||
* @param string $tag | ||
*/ | ||
public function setTag(string $tag): void | ||
{ | ||
$this->tag = $tag; | ||
} | ||
|
||
/** | ||
* @return SenderCredentials | ||
*/ | ||
public function getSenderCredentials(): ?SenderCredentials | ||
{ | ||
return $this->senderCredentials; | ||
} | ||
|
||
/** | ||
* @param SenderCredentials $senderCredentials | ||
*/ | ||
public function setSenderCredentials(SenderCredentials $senderCredentials): void | ||
{ | ||
$this->senderCredentials = $senderCredentials; | ||
} | ||
|
||
/** | ||
* @param Task $task | ||
*/ | ||
public function addTask(Task $task): void | ||
{ | ||
$this->tasks[] = $task; | ||
} | ||
|
||
/** | ||
* @return Task[] | ||
*/ | ||
public function getTasks(): array | ||
{ | ||
return $this->tasks; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function jsonSerialize() | ||
{ | ||
return $this->toArray(); | ||
} | ||
|
||
protected function options() | ||
{ | ||
return [ | ||
'json' => $this->jsonSerialize(), | ||
]; | ||
} | ||
|
||
protected function method() | ||
{ | ||
return 'POST'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SmartEmailing\v3\Request\Send; | ||
|
||
use SmartEmailing\v3\Exceptions\PropertyRequiredException; | ||
use SmartEmailing\v3\Models\Model; | ||
|
||
class Attachment extends Model | ||
{ | ||
/** @var string */ | ||
private $fileName; | ||
|
||
/** @var string */ | ||
private $contentType; | ||
|
||
/** @var string */ | ||
private $dataBase64; | ||
|
||
|
||
public function getFileName(): ?String | ||
{ | ||
return $this->fileName; | ||
} | ||
|
||
public function setFileName(String $fileName): void | ||
{ | ||
$this->fileName = $fileName; | ||
} | ||
|
||
public function getContentType(): ?String | ||
{ | ||
return $this->contentType; | ||
} | ||
|
||
public function setContentType(String $contentType): void | ||
{ | ||
$this->contentType = $contentType; | ||
} | ||
|
||
public function getDataBase64(): ?String | ||
{ | ||
return $this->dataBase64; | ||
} | ||
|
||
public function setDataBase64(String $dataBase64): void | ||
{ | ||
$this->dataBase64 = $dataBase64; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
PropertyRequiredException::throwIf('file_name', !empty($this->getFileName()), 'You must set file_name - missing file_name'); | ||
PropertyRequiredException::throwIf('content_type', !empty($this->getContentType()), 'You must set content_type - missing content_type'); | ||
PropertyRequiredException::throwIf('data_base64', !empty($this->getDataBase64()), 'You must set data_base64 - missing data_base64'); | ||
|
||
return [ | ||
'file_name' => $this->getFileName(), | ||
'content_type' => $this->getContentType(), | ||
'data_base64' => $this->getDataBase64(), | ||
]; | ||
} | ||
|
||
public function jsonSerialize(): array | ||
{ | ||
return $this->toArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SmartEmailing\v3\Request\Send; | ||
|
||
/** | ||
* Class BulkCustomEmails | ||
* | ||
* @link https://app.smartemailing.cz/docs/api/v3/index.html#api-Custom_campaigns-Send_bulk_custom_emails | ||
*/ | ||
class BulkCustomEmails extends AbstractSend | ||
{ | ||
/** | ||
* Converts data to array | ||
* | ||
* @return array | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return [ | ||
'sender_credentials' => $this->getSenderCredentials(), | ||
'tag' => $this->getTag(), | ||
'email_id' => $this->getEmailId(), | ||
'tasks' => $this->getTasks(), | ||
]; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function endpoint() | ||
{ | ||
return 'send/custom-emails-bulk'; | ||
} | ||
} |
Oops, something went wrong.