-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/verify custom templates (#502)
* Custom template methods, list iterators pending * Iterators completed * Add the template ID in sms and voice
- Loading branch information
Showing
21 changed files
with
951 additions
and
2 deletions.
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vonage\Verify2\Filters; | ||
|
||
use Vonage\Entity\Filter\FilterInterface; | ||
|
||
class TemplateFilter implements FilterInterface | ||
{ | ||
protected ?int $pageSize = null; | ||
protected ?int $page = null; | ||
|
||
public function getQuery(): array | ||
{ | ||
$return = []; | ||
|
||
if ($this->getPage()) { | ||
$return['page'] = $this->getPage(); | ||
} | ||
|
||
if ($this->getPageSize()) { | ||
$return['page_size'] = $this->getPageSize(); | ||
} | ||
|
||
return $return; | ||
} | ||
|
||
public function getPageSize(): ?int | ||
{ | ||
return $this->pageSize; | ||
} | ||
|
||
public function setPageSize(int $pageSize): self | ||
{ | ||
$this->pageSize = $pageSize; | ||
|
||
return $this; | ||
} | ||
|
||
public function getPage(): ?int | ||
{ | ||
return $this->page; | ||
} | ||
|
||
public function setPage(int $page): self | ||
{ | ||
$this->page = $page; | ||
|
||
return $this; | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/Verify2/Request/CreateCustomTemplateFragmentRequest.php
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,83 @@ | ||
<?php | ||
|
||
namespace Vonage\Verify2\Request; | ||
|
||
use Vonage\Entity\Hydrator\ArrayHydrateInterface; | ||
|
||
class CreateCustomTemplateFragmentRequest implements ArrayHydrateInterface | ||
{ | ||
protected const SMS_CHANNEL = 'sms'; | ||
protected const VOICE_CHANNEL = 'voice'; | ||
protected const EMAIL_CHANNEL = 'email'; | ||
|
||
protected array $permittedChannels = [ | ||
self::SMS_CHANNEL, | ||
self::VOICE_CHANNEL, | ||
self::EMAIL_CHANNEL, | ||
]; | ||
|
||
public function __construct( | ||
protected string $channel, | ||
protected string $locale, | ||
protected string $text, | ||
) { | ||
if (!in_array($channel, $this->permittedChannels)) { | ||
throw new \InvalidArgumentException('Given channel not supported'); | ||
} | ||
} | ||
|
||
public function getChannel(): string | ||
{ | ||
return $this->channel; | ||
} | ||
|
||
public function setChannel(string $channel): CreateCustomTemplateFragmentRequest | ||
{ | ||
if (!in_array($channel, $this->permittedChannels)) { | ||
throw new \InvalidArgumentException('Given channel not supported'); | ||
} | ||
|
||
$this->channel = $channel; | ||
return $this; | ||
} | ||
|
||
public function getLocale(): string | ||
{ | ||
return $this->locale; | ||
} | ||
|
||
public function setLocale(string $locale): CreateCustomTemplateFragmentRequest | ||
{ | ||
$this->locale = $locale; | ||
return $this; | ||
} | ||
|
||
public function getText(): string | ||
{ | ||
return $this->text; | ||
} | ||
|
||
public function setText(string $text): CreateCustomTemplateFragmentRequest | ||
{ | ||
$this->text = $text; | ||
return $this; | ||
} | ||
|
||
public function fromArray(array $data): static | ||
{ | ||
$this->setChannel($data['channel']); | ||
$this->setLocale($data['locale']); | ||
$this->setText($data['text']); | ||
|
||
return $this; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return [ | ||
'channel' => $this->getChannel(), | ||
'locale' => $this->getLocale(), | ||
'text' => $this->getText(), | ||
]; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Vonage\Verify2\Request; | ||
|
||
use InvalidArgumentException; | ||
use Vonage\Verify2\VerifyObjects\VerificationLocale; | ||
use Vonage\Verify2\VerifyObjects\VerificationWorkflow; | ||
|
||
class UpdateCustomTemplateRequest extends BaseVerifyRequest | ||
{ | ||
public function __construct( | ||
protected ?string $name = null, | ||
protected ?bool $isDefault = null, | ||
) { | ||
} | ||
|
||
public function getName(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName(?string $name): UpdateCustomTemplateRequest | ||
{ | ||
$this->name = $name; | ||
return $this; | ||
} | ||
|
||
public function getIsDefault(): ?bool | ||
{ | ||
return $this->isDefault; | ||
} | ||
|
||
public function setIsDefault(?bool $isDefault): UpdateCustomTemplateRequest | ||
{ | ||
$this->isDefault = $isDefault; | ||
return $this; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
$return = []; | ||
|
||
if ($this->getName()) { | ||
$return['name'] = $this->getName(); | ||
} | ||
|
||
if ($this->getIsDefault()) { | ||
$return['is_default'] = $this->getIsDefault(); | ||
} | ||
|
||
return $return; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Vonage\Verify2\Traits; | ||
|
||
trait CustomTemplateTrait | ||
{ | ||
protected ?string $templateId = null; | ||
|
||
public function getTemplateId(): ?string | ||
{ | ||
return $this->templateId; | ||
} | ||
|
||
public function setTemplateId(string $templateId): string | ||
{ | ||
return $this->templateId = $templateId; | ||
} | ||
} |
Oops, something went wrong.