├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── CONTRIBUTORS.md ├── LICENSE.txt ├── composer.json ├── phpstan-baseline.neon ├── phpstan.neon └── src ├── Account ├── Balance.php ├── Client.php ├── ClientFactory.php ├── Config.php ├── Network.php ├── PrefixPrice.php ├── Price.php ├── SmsPrice.php └── VoicePrice.php ├── Application ├── Application.php ├── ApplicationInterface.php ├── Client.php ├── ClientFactory.php ├── Hydrator.php ├── MessagesConfig.php ├── RtcConfig.php ├── VbcConfig.php ├── VoiceConfig.php └── Webhook.php ├── Client.php ├── Client ├── APIClient.php ├── APIExceptionHandler.php ├── APIResource.php ├── Callback │ ├── Callback.php │ └── CallbackInterface.php ├── ClientAwareInterface.php ├── ClientAwareTrait.php ├── Credentials │ ├── AbstractCredentials.php │ ├── Basic.php │ ├── Container.php │ ├── CredentialsInterface.php │ ├── Gnp.php │ ├── Handler │ │ ├── AbstractHandler.php │ │ ├── BasicHandler.php │ │ ├── BasicQueryHandler.php │ │ ├── GnpKeypairHandler.php │ │ ├── HandlerInterface.php │ │ ├── KeypairHandler.php │ │ ├── NumberVerificationGnpHandler.php │ │ ├── SignatureBodyFormHandler.php │ │ ├── SignatureBodyHandler.php │ │ ├── SignatureQueryHandler.php │ │ ├── SimSwapGnpHandler.php │ │ ├── TokenBodyFormHandler.php │ │ ├── TokenBodyHandler.php │ │ └── TokenQueryHandler.php │ ├── Keypair.php │ └── SignatureSecret.php ├── Exception │ ├── Conflict.php │ ├── Credentials.php │ ├── Exception.php │ ├── NotFound.php │ ├── Request.php │ ├── Server.php │ ├── ThrottleException.php │ ├── Transport.php │ └── Validation.php ├── Factory │ ├── FactoryInterface.php │ └── MapFactory.php ├── InvalidResponseException.php ├── Request │ ├── AbstractRequest.php │ ├── RequestInterface.php │ └── WrapResponseInterface.php ├── Response │ ├── AbstractResponse.php │ ├── Error.php │ ├── Response.php │ └── ResponseInterface.php ├── ScopeAwareTrait.php └── Signature.php ├── Conversation ├── Client.php ├── ClientFactory.php ├── ConversationObjects │ ├── Channel.php │ ├── Conversation.php │ ├── ConversationCallback.php │ ├── ConversationNumber.php │ ├── CreateConversationRequest.php │ ├── CreateMemberRequest.php │ ├── Event.php │ ├── EventRequest.php │ ├── Member.php │ ├── UpdateConversationRequest.php │ └── UpdateMemberRequest.php └── Filter │ ├── ListConversationFilter.php │ ├── ListEventsFilter.php │ ├── ListMembersFilter.php │ └── ListUserConversationsFilter.php ├── Conversion ├── Client.php └── ClientFactory.php ├── Entity ├── EntityInterface.php ├── Factory │ └── FactoryInterface.php ├── Filter │ ├── DateFilter.php │ ├── EmptyFilter.php │ ├── FilterInterface.php │ └── KeyValueFilter.php ├── HasEntityTrait.php ├── Hydrator │ ├── ArrayHydrateInterface.php │ ├── ArrayHydrator.php │ ├── ConstructorHydrator.php │ └── HydratorInterface.php ├── IterableAPICollection.php ├── JsonResponseTrait.php ├── JsonSerializableInterface.php ├── JsonSerializableTrait.php ├── JsonUnserializableInterface.php ├── NoRequestResponseTrait.php ├── Psr7Trait.php └── RequestArrayTrait.php ├── Insights ├── Advanced.php ├── AdvancedCnam.php ├── Basic.php ├── Client.php ├── ClientFactory.php ├── CnamTrait.php ├── Standard.php └── StandardCnam.php ├── Logger ├── LoggerAwareInterface.php └── LoggerTrait.php ├── Meetings ├── Application.php ├── ApplicationTheme.php ├── Client.php ├── ClientFactory.php ├── DialInNumber.php ├── ExceptionErrorHandler.php ├── Recording.php ├── Room.php └── UrlObject.php ├── Messages ├── Channel │ ├── BaseMessage.php │ ├── MMS │ │ ├── MMSAudio.php │ │ ├── MMSImage.php │ │ ├── MMSVideo.php │ │ └── MMSvCard.php │ ├── Message.php │ ├── Messenger │ │ ├── InvalidCategoryException.php │ │ ├── MessengerAudio.php │ │ ├── MessengerFile.php │ │ ├── MessengerImage.php │ │ ├── MessengerObjectTrait.php │ │ ├── MessengerText.php │ │ └── MessengerVideo.php │ ├── RCS │ │ ├── RcsCustom.php │ │ ├── RcsFile.php │ │ ├── RcsImage.php │ │ ├── RcsInvalidTtlException.php │ │ ├── RcsText.php │ │ └── RcsVideo.php │ ├── SMS │ │ └── SMSText.php │ ├── Viber │ │ ├── MessageObjects │ │ │ └── ViberActionObject.php │ │ ├── ViberFile.php │ │ ├── ViberImage.php │ │ ├── ViberServiceObjectTrait.php │ │ ├── ViberText.php │ │ └── ViberVideo.php │ └── WhatsApp │ │ ├── MessageObjects │ │ └── StickerObject.php │ │ ├── WhatsAppAudio.php │ │ ├── WhatsAppCustom.php │ │ ├── WhatsAppFile.php │ │ ├── WhatsAppImage.php │ │ ├── WhatsAppSticker.php │ │ ├── WhatsAppTemplate.php │ │ ├── WhatsAppText.php │ │ └── WhatsAppVideo.php ├── Client.php ├── ClientFactory.php ├── ExceptionErrorHandler.php ├── MessageObjects │ ├── AudioObject.php │ ├── FileObject.php │ ├── ImageObject.php │ ├── TemplateObject.php │ ├── VCardObject.php │ └── VideoObject.php ├── MessageTraits │ ├── ContextTrait.php │ ├── TextTrait.php │ └── TtlTrait.php └── Webhook │ ├── Factory.php │ ├── InboundMMS.php │ ├── InboundMessenger.php │ ├── InboundRCS.php │ ├── InboundSMS.php │ ├── InboundViber.php │ └── InboundWhatsApp.php ├── Network └── Number │ ├── Callback.php │ ├── Request.php │ └── Response.php ├── NumberVerification ├── Client.php └── ClientFactory.php ├── Numbers ├── Client.php ├── ClientFactory.php ├── Filter │ ├── AvailableNumbers.php │ └── OwnedNumbers.php ├── Hydrator.php └── Number.php ├── ProactiveConnect ├── Client.php ├── ClientFactory.php └── Objects │ ├── ListBaseObject.php │ ├── ListItem.php │ ├── ManualList.php │ └── SalesforceList.php ├── Redact ├── Client.php └── ClientFactory.php ├── SMS ├── Client.php ├── ClientFactory.php ├── Collection.php ├── ExceptionErrorHandler.php ├── Message │ ├── Binary.php │ ├── Message.php │ ├── OutboundMessage.php │ └── SMS.php ├── SentSMS.php └── Webhook │ ├── DeliveryReceipt.php │ ├── Factory.php │ └── InboundSMS.php ├── Secrets ├── Client.php ├── ClientFactory.php └── Secret.php ├── SimSwap ├── Client.php └── ClientFactory.php ├── Subaccount ├── Client.php ├── ClientFactory.php ├── Filter │ └── SubaccountFilter.php ├── Request │ ├── NumberTransferRequest.php │ ├── TransferBalanceRequest.php │ └── TransferCreditRequest.php └── SubaccountObjects │ ├── Account.php │ ├── BalanceTransfer.php │ └── CreditTransfer.php ├── Users ├── Client.php ├── ClientFactory.php ├── Filter │ └── UserFilter.php └── User.php ├── Verify ├── Check.php ├── Client.php ├── ClientFactory.php ├── ExceptionErrorHandler.php ├── Request.php ├── RequestPSD2.php ├── Verification.php └── VerificationInterface.php ├── Verify2 ├── Client.php ├── ClientFactory.php ├── Filters │ └── TemplateFilter.php ├── Request │ ├── BaseVerifyRequest.php │ ├── CreateCustomTemplateFragmentRequest.php │ ├── EmailRequest.php │ ├── RequestInterface.php │ ├── SMSRequest.php │ ├── SilentAuthRequest.php │ ├── UpdateCustomTemplateRequest.php │ ├── VoiceRequest.php │ ├── WhatsAppInteractiveRequest.php │ └── WhatsAppRequest.php ├── Traits │ └── CustomTemplateTrait.php ├── VerifyObjects │ ├── Template.php │ ├── TemplateFragment.php │ ├── VerificationLocale.php │ ├── VerificationWorkflow.php │ ├── VerifyEvent.php │ ├── VerifySilentAuthEvent.php │ ├── VerifyStatusUpdate.php │ └── VerifyWhatsAppInteractiveEvent.php └── Webhook │ └── Factory.php ├── Voice ├── Call.php ├── Call │ ├── Call.php │ └── Inbound.php ├── CallAction.php ├── CallFactory.php ├── Client.php ├── ClientFactory.php ├── Endpoint │ ├── App.php │ ├── EndpointFactory.php │ ├── EndpointInterface.php │ ├── Phone.php │ ├── SIP.php │ ├── VBC.php │ └── Websocket.php ├── Filter │ └── VoiceFilter.php ├── NCCO │ ├── Action │ │ ├── ActionInterface.php │ │ ├── Connect.php │ │ ├── Conversation.php │ │ ├── Input.php │ │ ├── Notify.php │ │ ├── Pay.php │ │ ├── Record.php │ │ ├── Stream.php │ │ └── Talk.php │ ├── NCCO.php │ └── NCCOFactory.php ├── OutboundCall.php ├── VoiceObjects │ └── AdvancedMachineDetection.php ├── Webhook.php └── Webhook │ ├── Answer.php │ ├── Error.php │ ├── Event.php │ ├── Factory.php │ ├── Input.php │ ├── Notification.php │ ├── Record.php │ └── Transfer.php └── Webhook └── Factory.php /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Getting Involved 2 | 3 | Thanks for your interest in the project, we'd love to have you involved! Check out the sections below to find out more about what to do next... 4 | 5 | ## Opening an Issue 6 | 7 | We always welcome issues, if you've seen something that isn't quite right, or you have a suggestion for a new feature, please go ahead and open an issue in this project. Include as much information as you have, it really helps. 8 | 9 | ## Making a Code Change 10 | 11 | We're always open to pull requests, but these should be small and clearly described so that we can understand what you're trying to do. Feel free to open an issue first and get some discussion going. 12 | 13 | When you're ready to start coding, fork this repository to your own GitHub account and make your changes in a new branch. Once you're happy, open a pull request and explain what the change is and why you think we should include it in our project. 14 | 15 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vonage/client-core", 3 | "type": "library", 4 | "description": "PHP Client for using Vonage's API.", 5 | "homepage": "https://developer.vonage.com", 6 | "license": "Apache-2.0", 7 | "authors": [ 8 | { 9 | "name": "James Seconde", 10 | "email": "jim.seconde@vonage.com", 11 | "role": "PHP Developer Advocate" 12 | } 13 | ], 14 | "require": { 15 | "php": "~8.1 || ~8.2 || ~8.3 || ~8.4", 16 | "ext-mbstring": "*", 17 | "laminas/laminas-diactoros": "^3.0", 18 | "lcobucci/jwt": "^4.0|^5.2.0", 19 | "psr/container": "^1.0 | ^2.0", 20 | "psr/http-client-implementation": "^1.0", 21 | "vonage/nexmo-bridge": "^0.1.0", 22 | "psr/log": "^1.1|^2.0|^3.0", 23 | "vonage/jwt": "^0.5.0" 24 | }, 25 | "require-dev": { 26 | "guzzlehttp/guzzle": ">=6", 27 | "helmich/phpunit-json-assert": "^3.3", 28 | "php-http/mock-client": "^1.4", 29 | "phpunit/phpunit": "^8.5|^9.4", 30 | "roave/security-advisories": "dev-latest", 31 | "squizlabs/php_codesniffer": "^3.5", 32 | "softcreatr/jsonpath": "^0.7 || ^0.8", 33 | "phpspec/prophecy-phpunit": "^2.0", 34 | "rector/rector": "^1.1", 35 | "phpstan/phpstan": "^1.10" 36 | }, 37 | "config": { 38 | "optimize-autoloader": true, 39 | "preferred-install": "dist", 40 | "allow-plugins": { 41 | "php-http/discovery": true 42 | } 43 | }, 44 | "autoload": { 45 | "psr-4": { 46 | "Vonage\\": "src/" 47 | } 48 | }, 49 | "autoload-dev": { 50 | "psr-4": { 51 | "VonageTest\\": "test/" 52 | } 53 | }, 54 | "minimum-stability": "stable", 55 | "scripts": { 56 | "cs-check": "phpcs", 57 | "cs-fix": "phpcbf", 58 | "test": "phpunit", 59 | "phpstan": "phpstan analyse -l 2 src" 60 | }, 61 | "support": { 62 | "email": "devrel@vonage.com", 63 | "issues": "https://github.com/Vonage/vonage-php-sdk-core/issues", 64 | "source": "https://github.com/Vonage/vonage-php-sdk-core", 65 | "docs": "https://developer.vonage.com" 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /phpstan-baseline.neon: -------------------------------------------------------------------------------- 1 | parameters: 2 | ignoreErrors: 3 | - 4 | message: "#^Access to an undefined property Vonage\\\\Account\\\\Price\\:\\:\\$priceMethod\\.$#" 5 | count: 1 6 | path: src/Account/Price.php 7 | 8 | - 9 | message: "#^Access to an undefined property Vonage\\\\Application\\\\Application\\:\\:\\$data\\.$#" 10 | count: 1 11 | path: src/Application/Application.php 12 | 13 | - 14 | message: "#^Call to an undefined method Vonage\\\\Application\\\\Client\\:\\:fromArray\\(\\)\\.$#" 15 | count: 1 16 | path: src/Application/Client.php 17 | 18 | - 19 | message: "#^Instantiated class Http\\\\Adapter\\\\Guzzle6\\\\Client not found\\.$#" 20 | count: 1 21 | path: src/Client.php 22 | 23 | - 24 | message: "#^Unsafe usage of new static\\(\\)\\.$#" 25 | count: 1 26 | path: src/Client/Callback/Callback.php 27 | 28 | - 29 | message: "#^Access to an undefined property Vonage\\\\Client\\\\Exception\\\\Request\\:\\:\\$data\\.$#" 30 | count: 1 31 | path: src/Client/Exception/Request.php 32 | 33 | - 34 | message: "#^Call to an undefined method \\$this\\(Vonage\\\\Client\\\\Exception\\\\Request\\)&Vonage\\\\Entity\\\\Hydrator\\\\ArrayHydrateInterface\\:\\:getResponseData\\(\\)\\.$#" 35 | count: 1 36 | path: src/Client/Exception/Request.php 37 | 38 | - 39 | message: "#^Access to an undefined property Vonage\\\\Client\\\\Exception\\\\Server\\:\\:\\$data\\.$#" 40 | count: 1 41 | path: src/Client/Exception/Server.php 42 | 43 | - 44 | message: "#^Call to an undefined method \\$this\\(Vonage\\\\Client\\\\Exception\\\\Server\\)&Vonage\\\\Entity\\\\Hydrator\\\\ArrayHydrateInterface\\:\\:getResponseData\\(\\)\\.$#" 45 | count: 1 46 | path: src/Client/Exception/Server.php 47 | 48 | - 49 | message: "#^Unsafe usage of new static\\(\\)\\.$#" 50 | count: 1 51 | path: src/Network/Number/Response.php 52 | 53 | - 54 | message: "#^Access to an undefined property Vonage\\\\Verify\\\\Verification\\:\\:\\$data\\.$#" 55 | count: 1 56 | path: src/Verify/Verification.php 57 | -------------------------------------------------------------------------------- /phpstan.neon: -------------------------------------------------------------------------------- 1 | includes: 2 | - phpstan-baseline.neon 3 | 4 | parameters: 5 | level: 0 6 | paths: 7 | - src -------------------------------------------------------------------------------- /src/Account/Balance.php: -------------------------------------------------------------------------------- 1 | data['balance'] = $balance; 17 | $this->data['auto_reload'] = $autoReload; 18 | } 19 | 20 | public function getBalance(): float 21 | { 22 | return $this->data['balance']; 23 | } 24 | 25 | public function getAutoReload(): bool 26 | { 27 | return $this->data['auto_reload']; 28 | } 29 | 30 | public function fromArray(array $data): void 31 | { 32 | $this->data = [ 33 | 'balance' => $data['value'], 34 | 'auto_reload' => $data['autoReload'] 35 | ]; 36 | } 37 | 38 | public function toArray(): array 39 | { 40 | return $this->data; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Account/ClientFactory.php: -------------------------------------------------------------------------------- 1 | make(APIResource::class); 17 | $accountApi 18 | ->setBaseUrl($accountApi->getClient()->getRestUrl()) 19 | ->setIsHAL(false) 20 | ->setBaseUri('/account') 21 | ->setAuthHandlers(new BasicHandler()) 22 | ; 23 | 24 | return new Client($accountApi); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Account/Network.php: -------------------------------------------------------------------------------- 1 | data['network_code'] = (string)$networkCode; 30 | $this->data['network_name'] = (string)$networkName; 31 | } 32 | 33 | public function getCode(): string 34 | { 35 | return $this->data['network_code']; 36 | } 37 | 38 | public function getName(): string 39 | { 40 | return $this->data['network_name']; 41 | } 42 | 43 | public function getOutboundSmsPrice(): mixed 44 | { 45 | return $this->data['sms_price'] ?? $this->data['price']; 46 | } 47 | 48 | public function getOutboundVoicePrice(): mixed 49 | { 50 | return $this->data['voice_price'] ?? $this->data['price']; 51 | } 52 | 53 | public function getPrefixPrice() 54 | { 55 | return $this->data['mt_price']; 56 | } 57 | 58 | public function getCurrency() 59 | { 60 | return $this->data['currency']; 61 | } 62 | 63 | public function fromArray(array $data): void 64 | { 65 | // Convert CamelCase to snake_case as that's how we use array access in every other object 66 | $storage = []; 67 | 68 | foreach ($data as $k => $v) { 69 | $k = strtolower(ltrim((string) preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '_$0', $k), '_')); 70 | $storage[$k] = $v; 71 | } 72 | 73 | $this->data = $storage; 74 | } 75 | 76 | public function toArray(): array 77 | { 78 | return $this->data; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Account/PrefixPrice.php: -------------------------------------------------------------------------------- 1 | make(APIResource::class); 17 | $api 18 | ->setBaseUri('/v2/applications') 19 | ->setCollectionName('applications') 20 | ->setAuthHandlers(new BasicHandler()); 21 | 22 | return new Client($api, new Hydrator()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Application/MessagesConfig.php: -------------------------------------------------------------------------------- 1 | webhooks[$type] = $url; 28 | 29 | return $this; 30 | } 31 | 32 | public function getWebhook($type) 33 | { 34 | return $this->webhooks[$type] ?? null; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Application/RtcConfig.php: -------------------------------------------------------------------------------- 1 | webhooks[$type] = $url; 27 | 28 | return $this; 29 | } 30 | 31 | public function getWebhook($type) 32 | { 33 | return $this->webhooks[$type] ?? null; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Application/VbcConfig.php: -------------------------------------------------------------------------------- 1 | enabled = true; 14 | } 15 | 16 | public function disable(): void 17 | { 18 | $this->enabled = false; 19 | } 20 | 21 | public function isEnabled(): bool 22 | { 23 | return $this->enabled; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Application/Webhook.php: -------------------------------------------------------------------------------- 1 | method; 21 | } 22 | 23 | public function getUrl(): ?string 24 | { 25 | return $this->url; 26 | } 27 | 28 | public function __toString(): string 29 | { 30 | return (string) $this->getUrl(); 31 | } 32 | 33 | public function getSocketTimeout(): ?string 34 | { 35 | return $this->socketTimeout; 36 | } 37 | 38 | public function setSocketTimeout(?string $socketTimeout): static 39 | { 40 | $this->socketTimeout = $socketTimeout; 41 | 42 | return $this; 43 | } 44 | 45 | public function getConnectionTimeout(): ?string 46 | { 47 | return $this->connectionTimeout; 48 | } 49 | 50 | public function setConnectionTimeout(?string $connectionTimeout): static 51 | { 52 | $this->connectionTimeout = $connectionTimeout; 53 | 54 | return $this; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Client/APIClient.php: -------------------------------------------------------------------------------- 1 | expected, $keys); 30 | 31 | if ($missing) { 32 | throw new RuntimeException('missing expected callback keys: ' . implode(', ', $missing)); 33 | } 34 | 35 | $this->data = $data; 36 | } 37 | 38 | public function getData(): array 39 | { 40 | return $this->data; 41 | } 42 | 43 | public static function fromEnv(string $source = self::ENV_ALL): callable|Callback 44 | { 45 | $data = match (strtolower($source)) { 46 | 'post' => $_POST, 47 | 'get' => $_GET, 48 | 'all' => array_merge($_GET, $_POST), 49 | default => throw new InvalidArgumentException('invalid source: ' . $source), 50 | }; 51 | 52 | return new static($data); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Client/Callback/CallbackInterface.php: -------------------------------------------------------------------------------- 1 | client = $client; 20 | 21 | return $this; 22 | } 23 | 24 | public function getClient(): ?Client 25 | { 26 | if (isset($this->client)) { 27 | return $this->client; 28 | } 29 | 30 | throw new RuntimeException('Vonage\Client not set'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Client/Credentials/AbstractCredentials.php: -------------------------------------------------------------------------------- 1 | credentials[$name]; 17 | } 18 | 19 | public function asArray(): array 20 | { 21 | return $this->credentials; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Client/Credentials/Basic.php: -------------------------------------------------------------------------------- 1 | credentials['api_key'] = (string)$key; 19 | $this->credentials['api_secret'] = (string)$secret; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Client/Credentials/Container.php: -------------------------------------------------------------------------------- 1 | addCredential($credential); 34 | } 35 | } 36 | 37 | protected function addCredential(CredentialsInterface $credential): void 38 | { 39 | $type = $this->getType($credential); 40 | 41 | if (isset($this->credentials[$type])) { 42 | throw new RuntimeException('can not use more than one of a single credential type'); 43 | } 44 | 45 | $this->credentials[$type] = $credential; 46 | } 47 | 48 | protected function getType(CredentialsInterface $credential): ?string 49 | { 50 | foreach ($this->types as $type) { 51 | if ($credential instanceof $type) { 52 | return $type; 53 | } 54 | } 55 | 56 | return null; 57 | } 58 | 59 | public function get($type) 60 | { 61 | if (!isset($this->credentials[$type])) { 62 | throw new RuntimeException('credential not set'); 63 | } 64 | 65 | return $this->credentials[$type]; 66 | } 67 | 68 | public function has($type): bool 69 | { 70 | return isset($this->credentials[$type]); 71 | } 72 | 73 | public function generateJwt($claims) 74 | { 75 | return $this->credentials[Keypair::class]->generateJwt($claims); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Client/Credentials/CredentialsInterface.php: -------------------------------------------------------------------------------- 1 | get($class); 21 | if (!is_null($creds)) { 22 | return $creds; 23 | } 24 | } 25 | 26 | throw new \RuntimeException('Requested auth type not found'); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Client/Credentials/Handler/BasicHandler.php: -------------------------------------------------------------------------------- 1 | extract(Basic::class, $credentials); 14 | 15 | $c = $credentials->asArray(); 16 | $cx = base64_encode($c['api_key'] . ':' . $c['api_secret']); 17 | 18 | return $request->withHeader('Authorization', 'Basic ' . $cx); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Client/Credentials/Handler/BasicQueryHandler.php: -------------------------------------------------------------------------------- 1 | extract(Basic::class, $credentials); 14 | parse_str($request->getUri()->getQuery(), $query); 15 | $query = array_merge($query, $credentials->asArray()); 16 | 17 | return $request->withUri($request->getUri()->withQuery(http_build_query($query))); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Client/Credentials/Handler/GnpKeypairHandler.php: -------------------------------------------------------------------------------- 1 | extract(Gnp::class, $credentials); 16 | $token = $credentials->generateJwt(); 17 | 18 | return $request->withHeader('Authorization', 'Bearer ' . $token->toString()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Client/Credentials/Handler/HandlerInterface.php: -------------------------------------------------------------------------------- 1 | extract(Keypair::class, $credentials); 15 | $token = $credentials->generateJwt(); 16 | 17 | return $request->withHeader('Authorization', 'Bearer ' . $token->toString()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Client/Credentials/Handler/NumberVerificationGnpHandler.php: -------------------------------------------------------------------------------- 1 | baseUrl; 25 | } 26 | 27 | public function setBaseUrl(?string $baseUrl): NumberVerificationGnpHandler 28 | { 29 | $this->baseUrl = $baseUrl; 30 | return $this; 31 | } 32 | 33 | public function getTokenUrl(): ?string 34 | { 35 | return $this->tokenUrl; 36 | } 37 | 38 | public function setTokenUrl(?string $tokenUrl): NumberVerificationGnpHandler 39 | { 40 | $this->tokenUrl = $tokenUrl; 41 | return $this; 42 | } 43 | 44 | public function __invoke(RequestInterface $request, CredentialsInterface $credentials): RequestInterface 45 | { 46 | /** @var Gnp $credentials */ 47 | $credentials = $this->extract(Gnp::class, $credentials); 48 | 49 | // submit the code to CAMARA endpoint 50 | $api = new APIResource(); 51 | $api->setAuthHandlers(new GnpKeypairHandler()); 52 | $api->setClient($this->getClient()); 53 | $api->setBaseUrl('https://api-eu.vonage.com/oauth2/token'); 54 | 55 | $tokenResponse = $api->submit([ 56 | 'grant_type' => 'authorization_code', 57 | 'code' => $credentials->getCode(), 58 | 'redirect_uri' => $credentials->getRedirectUri() 59 | ]); 60 | 61 | $payload = json_decode($tokenResponse, true); 62 | 63 | // Add CAMARA Access Token to request and return to make API call 64 | return $request->withHeader('Authorization', 'Bearer ' . $payload['access_token']); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Client/Credentials/Handler/SignatureBodyFormHandler.php: -------------------------------------------------------------------------------- 1 | extract(SignatureSecret::class, $credentials); 16 | $credentialsArray = $credentials->asArray(); 17 | 18 | $body = $request->getBody(); 19 | $body->rewind(); 20 | $content = $body->getContents(); 21 | 22 | $params = []; 23 | parse_str($content, $params); 24 | $params['api_key'] = $credentialsArray['api_key']; 25 | 26 | $signature = new Signature( 27 | $params, 28 | $credentialsArray['signature_secret'], 29 | $credentialsArray['signature_method'] 30 | ); 31 | 32 | $params = $signature->getSignedParams(); 33 | 34 | $newBody = Utils::streamFor(http_build_query($params, '', '&')); 35 | return $request->withBody($newBody); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Client/Credentials/Handler/SignatureBodyHandler.php: -------------------------------------------------------------------------------- 1 | extract(SignatureSecret::class, $credentials); 15 | $credentialsArray = $credentials->asArray(); 16 | 17 | $body = $request->getBody(); 18 | $body->rewind(); 19 | $content = $body->getContents(); 20 | $params = json_decode($content, true); 21 | $params['api_key'] = $credentialsArray['api_key']; 22 | 23 | $signature = new Signature( 24 | $params, 25 | $credentialsArray['signature_secret'], 26 | $credentialsArray['signature_method'] 27 | ); 28 | 29 | $body->rewind(); 30 | $body->write(json_encode($signature->getSignedParams())); 31 | 32 | return $request; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Client/Credentials/Handler/SignatureQueryHandler.php: -------------------------------------------------------------------------------- 1 | extract(SignatureSecret::class, $credentials); 15 | $credentialsArray = $credentials->asArray(); 16 | 17 | $query = []; 18 | parse_str($request->getUri()->getQuery(), $query); 19 | $query['api_key'] = $credentialsArray['api_key']; 20 | 21 | $signature = new Signature( 22 | $query, 23 | $credentialsArray['signature_secret'], 24 | $credentialsArray['signature_method'] 25 | ); 26 | 27 | return $request->withUri( 28 | $request->getUri()->withQuery(http_build_query($signature->getSignedParams())) 29 | ); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Client/Credentials/Handler/TokenBodyFormHandler.php: -------------------------------------------------------------------------------- 1 | extract(Basic::class, $credentials); 14 | $body = $request->getBody(); 15 | $body->rewind(); 16 | $content = $body->getContents(); 17 | $params = []; 18 | parse_str($content, $params); 19 | $params = array_merge($params, $credentials->asArray()); 20 | $body->rewind(); 21 | $body->write(http_build_query($params, '', '&')); 22 | 23 | return $request; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Client/Credentials/Handler/TokenBodyHandler.php: -------------------------------------------------------------------------------- 1 | extract(Basic::class, $credentials); 14 | 15 | // We have to do some clunky body pointer rewinding here 16 | $existingBody = $request->getBody(); 17 | $existingBody->rewind(); 18 | $existingBodyContent = $existingBody->getContents(); 19 | $existingBody->rewind(); 20 | $existingBodyArray = json_decode($existingBodyContent, true); 21 | 22 | // The request body will now be the existing body plus the basic creds 23 | $mergedBodyArray = array_merge($existingBodyArray, $credentials->asArray()); 24 | 25 | return $request->withBody(\GuzzleHttp\Psr7\Utils::streamFor(json_encode($mergedBodyArray))); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Client/Credentials/Handler/TokenQueryHandler.php: -------------------------------------------------------------------------------- 1 | extract(Basic::class, $credentials); 14 | $query = []; 15 | parse_str($request->getUri()->getQuery(), $query); 16 | $query = array_merge($query, $credentials->asArray()); 17 | 18 | $request = $request->withUri($request->getUri()->withQuery(http_build_query($query))); 19 | 20 | return $request; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Client/Credentials/SignatureSecret.php: -------------------------------------------------------------------------------- 1 | credentials['api_key'] = $key; 15 | $this->credentials['signature_secret'] = $signature_secret; 16 | $this->credentials['signature_method'] = $method; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Client/Exception/Conflict.php: -------------------------------------------------------------------------------- 1 | requestId = $requestId; 21 | } 22 | 23 | public function getRequestId(): string 24 | { 25 | return $this->requestId; 26 | } 27 | 28 | public function setNetworkId(string $networkId): void 29 | { 30 | $this->networkId = $networkId; 31 | } 32 | 33 | public function getNetworkId(): string 34 | { 35 | return $this->networkId; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Client/Exception/Server.php: -------------------------------------------------------------------------------- 1 | timeout = $seconds; 17 | } 18 | 19 | public function getTimeout(): int 20 | { 21 | return $this->timeout; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Client/Exception/Transport.php: -------------------------------------------------------------------------------- 1 | errors; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Client/Factory/FactoryInterface.php: -------------------------------------------------------------------------------- 1 | params, 'is_scalar'); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Client/Request/RequestInterface.php: -------------------------------------------------------------------------------- 1 | data; 17 | } 18 | 19 | public function isSuccess(): bool 20 | { 21 | return isset($this->data['status']) && (int)$this->data['status'] === 0; 22 | } 23 | 24 | public function isError(): bool 25 | { 26 | return !$this->isSuccess(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Client/Response/Error.php: -------------------------------------------------------------------------------- 1 | expected = ['status', 'error-text']; 17 | 18 | parent::__construct($data); 19 | } 20 | 21 | public function isError(): bool 22 | { 23 | return true; 24 | } 25 | 26 | public function isSuccess(): bool 27 | { 28 | return false; 29 | } 30 | 31 | public function getCode(): int 32 | { 33 | return (int)$this->data['status']; 34 | } 35 | 36 | public function getMessage(): string 37 | { 38 | return (string)$this->data['error-text']; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Client/Response/Response.php: -------------------------------------------------------------------------------- 1 | expected, $keys); 26 | 27 | if ($missing) { 28 | throw new RuntimeException('missing expected response keys: ' . implode(', ', $missing)); 29 | } 30 | 31 | $this->data = $data; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Client/Response/ResponseInterface.php: -------------------------------------------------------------------------------- 1 | scope = $scope; 17 | 18 | return $this; 19 | } 20 | 21 | public function getScope(): ?string 22 | { 23 | return $this->scope; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Conversation/ClientFactory.php: -------------------------------------------------------------------------------- 1 | make(APIResource::class); 15 | $api->setIsHAL(true) 16 | ->setErrorsOn200(false) 17 | ->setAuthHandlers(new KeypairHandler()) 18 | ->setBaseUrl('https://api.nexmo.com/v1/conversations'); 19 | 20 | return new Client($api); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Conversation/ConversationObjects/Conversation.php: -------------------------------------------------------------------------------- 1 | data = $data; 20 | } 21 | 22 | public function toArray(): array 23 | { 24 | return $this->data; 25 | } 26 | 27 | public function __get(string $name) 28 | { 29 | return $this->data[$name]; 30 | } 31 | 32 | public function __set(string $name, $value) 33 | { 34 | $this->data[$name] = $value; 35 | } 36 | 37 | public function __isset(string $name): bool 38 | { 39 | return isset($this->data[$name]); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Conversation/ConversationObjects/ConversationNumber.php: -------------------------------------------------------------------------------- 1 | type; 23 | } 24 | 25 | public function getNumber(): ?string 26 | { 27 | return $this->number; 28 | } 29 | 30 | public function setNumber(?string $number): ConversationNumber 31 | { 32 | $this->number = $number; 33 | 34 | return $this; 35 | } 36 | 37 | public function fromArray(array $data): static 38 | { 39 | if (isset($data['number'])) { 40 | $this->number = $data['number']; 41 | } 42 | 43 | return $this; 44 | } 45 | 46 | public function toArray(): array 47 | { 48 | return [ 49 | 'type' => $this->getType(), 50 | 'number' => $this->getNumber() 51 | ]; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Conversation/ConversationObjects/Event.php: -------------------------------------------------------------------------------- 1 | data = $data; 20 | } 21 | 22 | public function toArray(): array 23 | { 24 | return $this->data; 25 | } 26 | 27 | public function __get(string $name) 28 | { 29 | return $this->data[$name]; 30 | } 31 | 32 | public function __set(string $name, $value) 33 | { 34 | $this->data[$name] = $value; 35 | } 36 | 37 | public function __isset(string $name): bool 38 | { 39 | return isset($this->data[$name]); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Conversation/ConversationObjects/EventRequest.php: -------------------------------------------------------------------------------- 1 | $this->getEventType(), 23 | 'from' => $this->getFrom(), 24 | 'body' => $this->getBody() 25 | ]; 26 | } 27 | 28 | public function fromArray(array $data): EventRequest 29 | { 30 | $this->from = $data['from']; 31 | $this->eventType = $data['type']; 32 | $this->body = $data['body']; 33 | 34 | return $this; 35 | } 36 | 37 | public function getEventType(): string 38 | { 39 | return $this->eventType; 40 | } 41 | 42 | public function setEventType(string $eventType): EventRequest 43 | { 44 | $this->eventType = $eventType; 45 | 46 | return $this; 47 | } 48 | 49 | public function getFrom(): string 50 | { 51 | return $this->from; 52 | } 53 | 54 | public function setFrom(string $from): EventRequest 55 | { 56 | $this->from = $from; 57 | 58 | return $this; 59 | } 60 | 61 | public function getBody(): array 62 | { 63 | return $this->body; 64 | } 65 | 66 | public function setBody(array $body): EventRequest 67 | { 68 | $this->body = $body; 69 | 70 | return $this; 71 | } 72 | 73 | public function getConversationId(): string 74 | { 75 | return $this->conversationId; 76 | } 77 | 78 | public function setConversationId(string $conversationId): EventRequest 79 | { 80 | $this->conversationId = $conversationId; 81 | 82 | return $this; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Conversation/ConversationObjects/Member.php: -------------------------------------------------------------------------------- 1 | data = $data; 20 | } 21 | 22 | public function toArray(): array 23 | { 24 | return $this->data; 25 | } 26 | 27 | public function __get(string $name) 28 | { 29 | return $this->data[$name]; 30 | } 31 | 32 | public function __set(string $name, $value) 33 | { 34 | $this->data[$name] = $value; 35 | } 36 | 37 | public function __isset(string $name): bool 38 | { 39 | return isset($this->data[$name]); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Conversation/ConversationObjects/UpdateConversationRequest.php: -------------------------------------------------------------------------------- 1 | conversationRequest = new CreateConversationRequest(null, null, null); 18 | $this->conversationRequest->fromArray($this->data); 19 | } 20 | 21 | public function fromArray(array $data): static 22 | { 23 | $this->conversationRequest->fromArray($data); 24 | 25 | return $this; 26 | } 27 | 28 | public function toArray(): array 29 | { 30 | return $this->conversationRequest->toArray(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Conversation/Filter/ListMembersFilter.php: -------------------------------------------------------------------------------- 1 | pageSize; 28 | } 29 | 30 | public function setPageSize(?int $pageSize): ListMembersFilter 31 | { 32 | $this->pageSize = $pageSize; 33 | 34 | return $this; 35 | } 36 | 37 | public function getOrder(): string 38 | { 39 | return $this->order; 40 | } 41 | 42 | public function setOrder(string $order): ListMembersFilter 43 | { 44 | if (!in_array($order, self::VALID_ORDERS)) { 45 | throw new \InvalidArgumentException($order . ' is an invalid order value'); 46 | } 47 | 48 | $this->order = $order; 49 | 50 | return $this; 51 | } 52 | 53 | public function setCursor(?string $cursor): ListMembersFilter 54 | { 55 | $this->cursor = $cursor; 56 | 57 | return $this; 58 | } 59 | 60 | public function getQuery(): array 61 | { 62 | $query = []; 63 | 64 | if ($this->getPageSize()) { 65 | $query['page_size'] = $this->getPageSize(); 66 | } 67 | 68 | $query['order'] = $this->getOrder(); 69 | 70 | return $query; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Conversion/ClientFactory.php: -------------------------------------------------------------------------------- 1 | make(APIResource::class); 20 | $api->setBaseUri('/conversions/'); 21 | $api->setAuthHandlers(new BasicHandler()); 22 | 23 | return new Client($api); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Entity/EntityInterface.php: -------------------------------------------------------------------------------- 1 | start = $start; 23 | $this->end = $end; 24 | } else { 25 | $this->start = $end; 26 | $this->end = $start; 27 | } 28 | } 29 | 30 | public function getQuery(): array 31 | { 32 | return [ 33 | 'date' => $this->start->format(self::FORMAT) . '-' . $this->end->format(self::FORMAT) 34 | ]; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Entity/Filter/EmptyFilter.php: -------------------------------------------------------------------------------- 1 | $query 14 | */ 15 | public function __construct(protected array $query = []) 16 | { 17 | } 18 | 19 | public function getQuery(): array 20 | { 21 | return $this->query; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/HasEntityTrait.php: -------------------------------------------------------------------------------- 1 | entity = $entity; 14 | } 15 | 16 | public function getEntity() 17 | { 18 | return $this->entity; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Entity/Hydrator/ArrayHydrateInterface.php: -------------------------------------------------------------------------------- 1 | prototype; 14 | $object->fromArray($data); 15 | 16 | return $object; 17 | } 18 | 19 | public function hydrateObject(array $data, $object) 20 | { 21 | $object->fromArray($data); 22 | 23 | return $object; 24 | } 25 | 26 | public function setPrototype(ArrayHydrateInterface $prototype): void 27 | { 28 | $this->prototype = $prototype; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Entity/Hydrator/ConstructorHydrator.php: -------------------------------------------------------------------------------- 1 | prototype; 14 | return new $className($data); 15 | } 16 | 17 | public function hydrateObject(array $data, $object): never 18 | { 19 | throw new \RuntimeException('Constructor Hydration can not happen on an existing object'); 20 | } 21 | 22 | public function setPrototype(string $prototype): void 23 | { 24 | $this->prototype = $prototype; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Entity/Hydrator/HydratorInterface.php: -------------------------------------------------------------------------------- 1 | getResponse()) && ($response instanceof ResponseInterface)) { 40 | if ($response->getBody()->isSeekable()) { 41 | $response->getBody()->rewind(); 42 | } 43 | 44 | $body = $response->getBody()->getContents(); 45 | $this->responseJson = json_decode($body, true); 46 | 47 | return $this->responseJson; 48 | } 49 | 50 | return []; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Entity/JsonSerializableInterface.php: -------------------------------------------------------------------------------- 1 | getRequest(); 51 | 52 | return $this->jsonSerialize(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Entity/JsonUnserializableInterface.php: -------------------------------------------------------------------------------- 1 | data['valid_number']; 12 | } 13 | 14 | public function getReachable(): mixed 15 | { 16 | return $this->data['reachable']; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Insights/AdvancedCnam.php: -------------------------------------------------------------------------------- 1 | data['national_format_number'] = $number; 16 | } 17 | 18 | public function getRequestId(): string 19 | { 20 | return $this->data['request_id']; 21 | } 22 | 23 | public function getNationalFormatNumber(): string 24 | { 25 | return $this->data['national_format_number']; 26 | } 27 | 28 | public function getInternationalFormatNumber(): string 29 | { 30 | return $this->data['international_format_number']; 31 | } 32 | 33 | public function getCountryCode(): string 34 | { 35 | return $this->data['country_code']; 36 | } 37 | 38 | public function getCountryCodeISO3(): string 39 | { 40 | return $this->data['country_code_iso3']; 41 | } 42 | 43 | public function getCountryName(): string 44 | { 45 | return $this->data['country_name']; 46 | } 47 | 48 | public function getCountryPrefix(): string 49 | { 50 | return $this->data['country_prefix']; 51 | } 52 | 53 | public function fromArray(array $data): void 54 | { 55 | $this->data = $data; 56 | } 57 | 58 | public function toArray(): array 59 | { 60 | return $this->data; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Insights/ClientFactory.php: -------------------------------------------------------------------------------- 1 | make(APIResource::class); 18 | $api->setIsHAL(false); 19 | $api->setAuthHandlers(new BasicHandler()); 20 | 21 | return new Client($api); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Insights/CnamTrait.php: -------------------------------------------------------------------------------- 1 | data['caller_name'] ?? null; 12 | } 13 | 14 | public function getFirstName(): ?string 15 | { 16 | return $this->data['first_name'] ?? null; 17 | } 18 | 19 | public function getLastName(): ?string 20 | { 21 | return $this->data['last_name'] ?? null; 22 | } 23 | 24 | public function getCallerType(): ?string 25 | { 26 | return $this->data['caller_type'] ?? null; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Insights/Standard.php: -------------------------------------------------------------------------------- 1 | data['current_carrier']; 12 | } 13 | 14 | public function getOriginalCarrier(): mixed 15 | { 16 | return $this->data['original_carrier']; 17 | } 18 | 19 | public function getPorted(): mixed 20 | { 21 | return $this->data['ported']; 22 | } 23 | 24 | public function getRefundPrice(): mixed 25 | { 26 | return $this->data['refund_price']; 27 | } 28 | 29 | public function getRequestPrice(): mixed 30 | { 31 | return $this->data['request_price']; 32 | } 33 | 34 | public function getRemainingBalance(): mixed 35 | { 36 | return $this->data['remaining_balance']; 37 | } 38 | 39 | public function getRoaming(): mixed 40 | { 41 | return $this->data['roaming']; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Insights/StandardCnam.php: -------------------------------------------------------------------------------- 1 | $context Additional information for context 14 | */ 15 | public function log(int|string $level, string $message, array $context = []): void; 16 | 17 | public function setLogger(LoggerInterface $logger): void; 18 | } 19 | -------------------------------------------------------------------------------- /src/Logger/LoggerTrait.php: -------------------------------------------------------------------------------- 1 | logger; 17 | } 18 | 19 | /** 20 | * @param int|string $level Level of message that we are logging 21 | * @param array $context Additional information for context 22 | */ 23 | public function log(int|string $level, string $message, array $context = []): void 24 | { 25 | $logger = $this->getLogger(); 26 | if ($logger) { 27 | $logger->log($level, $message, $context); 28 | } 29 | } 30 | 31 | public function setLogger(LoggerInterface $logger): void 32 | { 33 | $this->logger = $logger; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Meetings/Application.php: -------------------------------------------------------------------------------- 1 | data = $data; 14 | } 15 | 16 | public function toArray(): array 17 | { 18 | return $this->data; 19 | } 20 | 21 | public function __get($name) 22 | { 23 | return $this->data[$name]; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Meetings/ApplicationTheme.php: -------------------------------------------------------------------------------- 1 | data = $data; 14 | } 15 | 16 | public function toArray(): array 17 | { 18 | return $this->data; 19 | } 20 | 21 | public function __get($name) 22 | { 23 | return $this->data[$name]; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Meetings/ClientFactory.php: -------------------------------------------------------------------------------- 1 | make(APIResource::class); 17 | $api 18 | ->setBaseUrl('https://api-eu.vonage.com/v1/meetings/') 19 | ->setExceptionErrorHandler(new ExceptionErrorHandler()) 20 | ->setAuthHandlers(new KeypairHandler()); 21 | 22 | return new Client($api); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Meetings/DialInNumber.php: -------------------------------------------------------------------------------- 1 | data = $data; 14 | } 15 | 16 | public function toArray(): array 17 | { 18 | return $this->data; 19 | } 20 | 21 | public function __get($name) 22 | { 23 | return $this->data[$name]; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Meetings/ExceptionErrorHandler.php: -------------------------------------------------------------------------------- 1 | getStatusCode()) { 19 | 400 => throw new Validation('The request data was invalid'), 20 | 403 => throw new Credentials('You are not authorised to perform this request'), 21 | 404 => throw new NotFound('No resource found'), 22 | 409 => throw new Conflict('Entity conflict') 23 | }; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Meetings/Recording.php: -------------------------------------------------------------------------------- 1 | data = $data; 14 | } 15 | 16 | public function toArray(): array 17 | { 18 | return $this->data; 19 | } 20 | 21 | public function __get($name) 22 | { 23 | return $this->data[$name]; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Meetings/Room.php: -------------------------------------------------------------------------------- 1 | data = $data; 18 | 19 | return $this; 20 | } 21 | 22 | public function toArray(): array 23 | { 24 | return array_filter($this->data, static fn ($value) => $value !== ''); 25 | } 26 | 27 | public function __get($value) 28 | { 29 | return $this->data[$value]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Meetings/UrlObject.php: -------------------------------------------------------------------------------- 1 | data = $data; 14 | } 15 | 16 | public function toArray(): array 17 | { 18 | return $this->data; 19 | } 20 | 21 | public function __get($name) 22 | { 23 | return $this->data[$name]; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Messages/Channel/MMS/MMSAudio.php: -------------------------------------------------------------------------------- 1 | to = $to; 23 | $this->from = $from; 24 | } 25 | 26 | public function validatesE164(): bool 27 | { 28 | return $this->validatesE164; 29 | } 30 | 31 | public function toArray(): array 32 | { 33 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 34 | $returnArray['audio'] = $this->audioObject->toArray(); 35 | 36 | if (!is_null($this->ttl)) { 37 | $returnArray['ttl'] = $this->ttl; 38 | } 39 | 40 | return $returnArray; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Messages/Channel/MMS/MMSImage.php: -------------------------------------------------------------------------------- 1 | to = $to; 23 | $this->from = $from; 24 | } 25 | 26 | public function validatesE164(): bool 27 | { 28 | return $this->validatesE164; 29 | } 30 | 31 | public function toArray(): array 32 | { 33 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 34 | $returnArray['image'] = $this->image->toArray(); 35 | 36 | if (!is_null($this->ttl)) { 37 | $returnArray['ttl'] = $this->ttl; 38 | } 39 | 40 | return $returnArray; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Messages/Channel/MMS/MMSVideo.php: -------------------------------------------------------------------------------- 1 | to = $to; 24 | $this->from = $from; 25 | } 26 | 27 | public function validatesE164(): bool 28 | { 29 | return $this->validatesE164; 30 | } 31 | 32 | public function toArray(): array 33 | { 34 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 35 | $returnArray['video'] = $this->videoObject->toArray(); 36 | 37 | if (!is_null($this->ttl)) { 38 | $returnArray['ttl'] = $this->ttl; 39 | } 40 | 41 | return $returnArray; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Messages/Channel/MMS/MMSvCard.php: -------------------------------------------------------------------------------- 1 | to = $to; 23 | $this->from = $from; 24 | } 25 | 26 | public function validatesE164(): bool 27 | { 28 | return $this->validatesE164; 29 | } 30 | 31 | public function toArray(): array 32 | { 33 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 34 | $returnArray['vcard'] = $this->vCard->toArray(); 35 | 36 | if (!is_null($this->ttl)) { 37 | $returnArray['ttl'] = $this->ttl; 38 | } 39 | 40 | return $returnArray; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Messages/Channel/Message.php: -------------------------------------------------------------------------------- 1 | to = $to; 24 | $this->from = $from; 25 | $this->category = $category; 26 | $this->tag = $tag; 27 | } 28 | 29 | public function validatesE164(): bool 30 | { 31 | return $this->validatesE164; 32 | } 33 | 34 | public function toArray(): array 35 | { 36 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 37 | $returnArray['audio'] = $this->audioObject->toArray(); 38 | 39 | if ($this->requiresMessengerObject()) { 40 | $returnArray['messenger'] = $this->getMessengerObject(); 41 | } 42 | 43 | return $returnArray; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Messages/Channel/Messenger/MessengerFile.php: -------------------------------------------------------------------------------- 1 | to = $to; 24 | $this->from = $from; 25 | $this->category = $category; 26 | $this->tag = $tag; 27 | } 28 | 29 | public function toArray(): array 30 | { 31 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 32 | $returnArray['file'] = $this->fileObject->toArray(); 33 | 34 | if ($this->requiresMessengerObject()) { 35 | $returnArray['messenger'] = $this->getMessengerObject(); 36 | } 37 | 38 | return $returnArray; 39 | } 40 | 41 | public function validatesE164(): bool 42 | { 43 | return $this->validatesE164; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Messages/Channel/Messenger/MessengerImage.php: -------------------------------------------------------------------------------- 1 | to = $to; 24 | $this->from = $from; 25 | $this->category = $category; 26 | $this->tag = $tag; 27 | } 28 | 29 | public function toArray(): array 30 | { 31 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 32 | $returnArray['image'] = $this->image->toArray(); 33 | 34 | if ($this->requiresMessengerObject()) { 35 | $returnArray['messenger'] = $this->getMessengerObject(); 36 | } 37 | 38 | return $returnArray; 39 | } 40 | 41 | public function validatesE164(): bool 42 | { 43 | return $this->validatesE164; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Messages/Channel/Messenger/MessengerObjectTrait.php: -------------------------------------------------------------------------------- 1 | category; 13 | } 14 | 15 | public function requiresMessengerObject(): bool 16 | { 17 | return $this->getTag() || $this->getCategory(); 18 | } 19 | 20 | public function setCategory(string $category): void 21 | { 22 | $this->category = $category; 23 | } 24 | 25 | public function getTag(): ?string 26 | { 27 | return $this->tag; 28 | } 29 | 30 | public function setTag(string $tag): void 31 | { 32 | $this->tag = $tag; 33 | } 34 | 35 | public function getMessengerObject(): array 36 | { 37 | $messengerObject = [ 38 | 'category' => $this->getCategory(), 39 | ]; 40 | 41 | if ($this->getTag()) { 42 | $messengerObject['tag'] = $this->getTag(); 43 | } 44 | 45 | return $messengerObject; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Messages/Channel/Messenger/MessengerText.php: -------------------------------------------------------------------------------- 1 | to = $to; 25 | $this->from = $from; 26 | $this->text = $text; 27 | $this->category = $category; 28 | $this->tag = $tag; 29 | } 30 | 31 | public function validatesE164(): bool 32 | { 33 | return $this->validatesE164; 34 | } 35 | 36 | public function toArray(): array 37 | { 38 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 39 | $returnArray['text'] = $this->getText(); 40 | 41 | if ($this->requiresMessengerObject()) { 42 | $returnArray['messenger'] = $this->getMessengerObject(); 43 | } 44 | 45 | return $returnArray; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Messages/Channel/Messenger/MessengerVideo.php: -------------------------------------------------------------------------------- 1 | to = $to; 24 | $this->from = $from; 25 | $this->category = $category; 26 | $this->tag = $tag; 27 | } 28 | 29 | public function validatesE164(): bool 30 | { 31 | return $this->validatesE164; 32 | } 33 | 34 | public function toArray(): array 35 | { 36 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 37 | $returnArray['video'] = $this->videoObject->toArray(); 38 | 39 | if ($this->requiresMessengerObject()) { 40 | $returnArray['messenger'] = $this->getMessengerObject(); 41 | } 42 | 43 | return $returnArray; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Messages/Channel/RCS/RcsInvalidTtlException.php: -------------------------------------------------------------------------------- 1 | to = $to; 27 | $this->from = $from; 28 | $this->text = $message; 29 | } 30 | 31 | public function validatesE164(): bool 32 | { 33 | return $this->validatesE164; 34 | } 35 | 36 | public function setTtl(?int $ttl): void 37 | { 38 | $range = [ 39 | 'options' => [ 40 | 'min_range' => self::RCS_TEXT_MIN_TTL, 41 | 'max_range' => self::RCS_TEXT_MAX_TTL 42 | ] 43 | ]; 44 | 45 | if (!filter_var($ttl, FILTER_VALIDATE_INT, $range)) { 46 | throw new RcsInvalidTtlException('Timeout ' . $ttl . ' is not valid'); 47 | } 48 | 49 | $this->ttl = $ttl; 50 | } 51 | 52 | public function toArray(): array 53 | { 54 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 55 | $returnArray['text'] = $this->getText(); 56 | 57 | if ($this->getClientRef()) { 58 | $returnArray['client_ref'] = $this->getClientRef(); 59 | } 60 | 61 | if ($this->getWebhookUrl()) { 62 | $returnArray['webhook_url'] = $this->getWebhookUrl(); 63 | } 64 | 65 | if ($this->getTtl()) { 66 | $returnArray['ttl'] = $this->getTtl(); 67 | } 68 | 69 | return $returnArray; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Messages/Channel/Viber/MessageObjects/ViberActionObject.php: -------------------------------------------------------------------------------- 1 | url = $data['url']; 16 | $this->text = $data['text']; 17 | 18 | return $this; 19 | } 20 | 21 | public function toArray(): array 22 | { 23 | return [ 24 | 'url' => $this->getUrl(), 25 | 'text' => $this->getText() 26 | ]; 27 | } 28 | 29 | public function getUrl(): string 30 | { 31 | return $this->url; 32 | } 33 | 34 | public function getText(): string 35 | { 36 | return $this->text; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Messages/Channel/Viber/ViberFile.php: -------------------------------------------------------------------------------- 1 | to = $to; 22 | $this->from = $from; 23 | } 24 | 25 | public function validatesE164(): bool 26 | { 27 | return $this->validatesE164; 28 | } 29 | 30 | public function toArray(): array 31 | { 32 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 33 | $returnArray['file'] = $this->fileObject->toArray(); 34 | 35 | if ($this->requiresViberServiceObject()) { 36 | $this->getCategory() ? $returnArray['viber_service']['category'] = $this->getCategory() : null; 37 | $this->getTtl() ? $returnArray['viber_service']['ttl'] = $this->getTtl() : null; 38 | $this->getType() ? $returnArray['viber_service']['type'] = $this->getType() : null; 39 | } 40 | 41 | return $returnArray; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Messages/Channel/Viber/ViberImage.php: -------------------------------------------------------------------------------- 1 | to = $to; 27 | $this->from = $from; 28 | $this->category = $category; 29 | $this->ttl = $ttl; 30 | $this->type = $type; 31 | $this->action = $viberActionObject; 32 | } 33 | 34 | public function validatesE164(): bool 35 | { 36 | return $this->validatesE164; 37 | } 38 | 39 | public function toArray(): array 40 | { 41 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 42 | $returnArray['image'] = $this->image->toArray(); 43 | 44 | if ($this->requiresViberServiceObject()) { 45 | $this->getCategory() ? $returnArray['viber_service']['category'] = $this->getCategory() : null; 46 | $this->getTtl() ? $returnArray['viber_service']['ttl'] = $this->getTtl() : null; 47 | $this->getType() ? $returnArray['viber_service']['type'] = $this->getType() : null; 48 | $this->getAction() ? $returnArray['viber_service']['action'] = $this->getAction()->toArray() : null; 49 | } 50 | 51 | return array_filter($returnArray); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Messages/Channel/Viber/ViberServiceObjectTrait.php: -------------------------------------------------------------------------------- 1 | getCategory() || $this->getTtl() || $this->getType() || $this->getAction(); 19 | } 20 | 21 | public function getCategory(): ?string 22 | { 23 | return $this->category; 24 | } 25 | 26 | public function setCategory(?string $category): static 27 | { 28 | $this->category = $category; 29 | 30 | return $this; 31 | } 32 | 33 | public function getTtl(): ?int 34 | { 35 | return $this->ttl; 36 | } 37 | 38 | public function setTtl(int $ttl): static 39 | { 40 | $this->ttl = $ttl; 41 | 42 | return $this; 43 | } 44 | 45 | public function getType(): ?string 46 | { 47 | return $this->type; 48 | } 49 | 50 | public function setType(string $type): static 51 | { 52 | $this->type = $type; 53 | 54 | return $this; 55 | } 56 | 57 | public function getAction(): ?ViberActionObject 58 | { 59 | return $this->action; 60 | } 61 | 62 | public function setAction(ViberActionObject $viberActionObject): static 63 | { 64 | $this->action = $viberActionObject; 65 | 66 | return $this; 67 | } 68 | 69 | public function getDuration(): string 70 | { 71 | return $this->duration; 72 | } 73 | 74 | public function setDuration(string $duration): void 75 | { 76 | $this->duration = $duration; 77 | } 78 | 79 | public function getFileSize(): string 80 | { 81 | return $this->fileSize; 82 | } 83 | 84 | public function setFileSize(string $fileSize): void 85 | { 86 | $this->fileSize = $fileSize; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/Messages/Channel/Viber/ViberText.php: -------------------------------------------------------------------------------- 1 | to = $to; 28 | $this->from = $from; 29 | $this->text = $message; 30 | $this->category = $category; 31 | $this->ttl = $ttl; 32 | $this->type = $type; 33 | $this->action = $viberActionObject; 34 | } 35 | 36 | public function validatesE164(): bool 37 | { 38 | return $this->validatesE164; 39 | } 40 | 41 | public function toArray(): array 42 | { 43 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 44 | $returnArray['text'] = $this->getText(); 45 | 46 | if ($this->requiresViberServiceObject()) { 47 | $this->getCategory() ? $returnArray['viber_service']['category'] = $this->getCategory() : null; 48 | $this->getTtl() ? $returnArray['viber_service']['ttl'] = $this->getTtl() : null; 49 | $this->getType() ? $returnArray['viber_service']['type'] = $this->getType() : null; 50 | $this->getAction() ? $returnArray['viber_service']['action'] = $this->getAction()->toArray() : null; 51 | } 52 | 53 | return array_filter($returnArray); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Messages/Channel/Viber/ViberVideo.php: -------------------------------------------------------------------------------- 1 | fileSize = $fileSize; 27 | $this->duration = $duration; 28 | $this->to = $to; 29 | $this->from = $from; 30 | } 31 | 32 | public function validatesE164(): bool 33 | { 34 | return $this->validatesE164; 35 | } 36 | 37 | public function toArray(): array 38 | { 39 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 40 | $videoArray = $this->videoObject->toArray(); 41 | $videoArray['thumb_url'] = $this->thumbUrl; 42 | $returnArray['video'] = $videoArray; 43 | 44 | $returnArray['viber_service']['duration'] = $this->getDuration(); 45 | $returnArray['viber_service']['file_size'] = $this->getFileSize(); 46 | 47 | $this->getCategory() ? $returnArray['viber_service']['category'] = $this->getCategory() : null; 48 | $this->getTtl() ? $returnArray['viber_service']['ttl'] = $this->getTtl() : null; 49 | $this->getType() ? $returnArray['viber_service']['type'] = $this->getType() : null; 50 | $this->getAction() ? $returnArray['viber_service']['action'] = $this->getAction()->toArray() : null; 51 | 52 | return $returnArray; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Messages/Channel/WhatsApp/MessageObjects/StickerObject.php: -------------------------------------------------------------------------------- 1 | allowedTypes, true)) { 20 | throw new \InvalidArgumentException($type . ' is an invalid type of Sticker'); 21 | } 22 | } 23 | 24 | public function fromArray(array $data): StickerObject 25 | { 26 | if (! in_array($data['type'], $this->allowedTypes, true)) { 27 | throw new \InvalidArgumentException($data['type'] . ' is an invalid type of Sticker'); 28 | } 29 | 30 | return $this; 31 | } 32 | 33 | /** 34 | * @return string 35 | */ 36 | public function getType(): string 37 | { 38 | return $this->type; 39 | } 40 | 41 | /** 42 | * @param string $type 43 | */ 44 | public function setType(string $type): void 45 | { 46 | $this->type = $type; 47 | } 48 | 49 | /** 50 | * @return string 51 | */ 52 | public function getValue(): string 53 | { 54 | return $this->value; 55 | } 56 | 57 | /** 58 | * @param string $value 59 | */ 60 | public function setValue(string $value): void 61 | { 62 | $this->value = $value; 63 | } 64 | 65 | public function toArray(): array 66 | { 67 | return [$this->getType() => $this->getValue()]; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Messages/Channel/WhatsApp/WhatsAppAudio.php: -------------------------------------------------------------------------------- 1 | to = $to; 23 | $this->from = $from; 24 | } 25 | 26 | public function validatesE164(): bool 27 | { 28 | return $this->validatesE164; 29 | } 30 | 31 | public function toArray(): array 32 | { 33 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 34 | $returnArray['audio'] = $this->audioObject->toArray(); 35 | $returnArray['context'] = $this->context ?? null; 36 | 37 | return $returnArray; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Messages/Channel/WhatsApp/WhatsAppCustom.php: -------------------------------------------------------------------------------- 1 | to = $to; 22 | $this->from = $from; 23 | } 24 | 25 | public function validatesE164(): bool 26 | { 27 | return $this->validatesE164; 28 | } 29 | 30 | public function setCustom(array $custom): void 31 | { 32 | $this->custom = $custom; 33 | } 34 | 35 | public function getCustom(): array 36 | { 37 | return $this->custom; 38 | } 39 | 40 | public function toArray(): array 41 | { 42 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 43 | $returnArray['custom'] = $this->getCustom(); 44 | $returnArray['context'] = $this->context ?? null; 45 | 46 | return $returnArray; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Messages/Channel/WhatsApp/WhatsAppFile.php: -------------------------------------------------------------------------------- 1 | to = $to; 23 | $this->from = $from; 24 | } 25 | 26 | public function validatesE164(): bool 27 | { 28 | return $this->validatesE164; 29 | } 30 | 31 | public function toArray(): array 32 | { 33 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 34 | $returnArray['file'] = $this->fileObject->toArray(); 35 | $returnArray['context'] = $this->context ?? null; 36 | 37 | return $returnArray; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Messages/Channel/WhatsApp/WhatsAppImage.php: -------------------------------------------------------------------------------- 1 | to = $to; 23 | $this->from = $from; 24 | } 25 | 26 | public function validatesE164(): bool 27 | { 28 | return $this->validatesE164; 29 | } 30 | 31 | public function toArray(): array 32 | { 33 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 34 | $returnArray['image'] = $this->image->toArray(); 35 | $returnArray['context'] = $this->context ?? null; 36 | 37 | return $returnArray; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Messages/Channel/WhatsApp/WhatsAppSticker.php: -------------------------------------------------------------------------------- 1 | to = $to; 23 | $this->from = $from; 24 | } 25 | 26 | public function validatesE164(): bool 27 | { 28 | return $this->validatesE164; 29 | } 30 | 31 | public function getSticker(): StickerObject 32 | { 33 | return $this->sticker; 34 | } 35 | 36 | public function setSticker(StickerObject $sticker): static 37 | { 38 | $this->sticker = $sticker; 39 | 40 | return $this; 41 | } 42 | 43 | public function toArray(): array 44 | { 45 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 46 | $returnArray['sticker'] = $this->getSticker()->toArray(); 47 | $returnArray['context'] = $this->context ?? null; 48 | 49 | return $returnArray; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Messages/Channel/WhatsApp/WhatsAppTemplate.php: -------------------------------------------------------------------------------- 1 | to = $to; 25 | $this->from = $from; 26 | } 27 | 28 | public function validatesE164(): bool 29 | { 30 | return $this->validatesE164; 31 | } 32 | 33 | public function toArray(): array 34 | { 35 | $returnArray = [ 36 | 'template' => $this->templateObject->toArray(), 37 | 'whatsapp' => [ 38 | 'policy' => 'deterministic', 39 | 'locale' => $this->getLocale() 40 | ] 41 | ]; 42 | 43 | $returnArray['context'] = $this->context ?? null; 44 | 45 | return array_merge($this->getBaseMessageUniversalOutputArray(), $returnArray); 46 | } 47 | 48 | public function getLocale(): string 49 | { 50 | return $this->locale; 51 | } 52 | 53 | public function setLocale($locale): void 54 | { 55 | $this->locale = $locale; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Messages/Channel/WhatsApp/WhatsAppText.php: -------------------------------------------------------------------------------- 1 | to = $to; 24 | $this->from = $from; 25 | $this->text = $text; 26 | } 27 | 28 | public function validatesE164(): bool 29 | { 30 | return $this->validatesE164; 31 | } 32 | 33 | public function toArray(): array 34 | { 35 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 36 | $returnArray['text'] = $this->getText(); 37 | $returnArray['context'] = $this->context ?? null; 38 | 39 | return $returnArray; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Messages/Channel/WhatsApp/WhatsAppVideo.php: -------------------------------------------------------------------------------- 1 | to = $to; 23 | $this->from = $from; 24 | } 25 | 26 | public function validatesE164(): bool 27 | { 28 | return $this->validatesE164; 29 | } 30 | 31 | public function toArray(): array 32 | { 33 | $returnArray = $this->getBaseMessageUniversalOutputArray(); 34 | $returnArray['video'] = $this->videoObject->toArray(); 35 | $returnArray['context'] = $this->context ?? null; 36 | 37 | return $returnArray; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Messages/ClientFactory.php: -------------------------------------------------------------------------------- 1 | make(APIResource::class); 16 | $api 17 | ->setBaseUrl($api->getClient()->getApiUrl() . '/v1/messages') 18 | ->setIsHAL(false) 19 | ->setErrorsOn200(false) 20 | ->setAuthHandlers([new KeypairHandler(), new BasicHandler()]) 21 | ->setExceptionErrorHandler(new ExceptionErrorHandler()); 22 | 23 | return new Client($api); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Messages/ExceptionErrorHandler.php: -------------------------------------------------------------------------------- 1 | getBody()->getContents(), 26 | true, 27 | 512, 28 | JSON_THROW_ON_ERROR 29 | ); 30 | $statusCode = (int)$response->getStatusCode(); 31 | 32 | if ($statusCode === 429) { 33 | throw new ThrottleException( 34 | $responseBody['title'] . ': ' . $responseBody['detail'], 35 | $response->getStatusCode() 36 | ); 37 | } 38 | 39 | if ($statusCode >= 500 && $statusCode <= 599) { 40 | throw new ClientException\Server($responseBody['title'] . ': ' . $responseBody['detail']); 41 | } 42 | 43 | $message = $responseBody['title'] ?? ''; 44 | 45 | if (isset($responseBody['detail'])) { 46 | $message .= ': ' . $responseBody['detail']; 47 | } 48 | 49 | throw new ClientException\Request($message); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Messages/MessageObjects/AudioObject.php: -------------------------------------------------------------------------------- 1 | url = $data['url']; 19 | 20 | return $this; 21 | } 22 | 23 | public function toArray(): array 24 | { 25 | return [ 26 | 'url' => $this->url 27 | ]; 28 | } 29 | 30 | public function getUrl(): string 31 | { 32 | return $this->url; 33 | } 34 | 35 | /** 36 | * @deprecated Unsupported 37 | * @return string 38 | */ 39 | public function getCaption(): string 40 | { 41 | trigger_error( 42 | 'Captions are not supported in this API, this will error at server level.', 43 | E_USER_DEPRECATED 44 | ); 45 | 46 | return $this->caption; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Messages/MessageObjects/FileObject.php: -------------------------------------------------------------------------------- 1 | url = $data['url']; 19 | 20 | if (isset($data['caption'])) { 21 | $this->caption = $data['caption']; 22 | } 23 | 24 | if (isset($data['name'])) { 25 | $this->name = $data['name']; 26 | } 27 | 28 | return $this; 29 | } 30 | 31 | public function toArray(): array 32 | { 33 | $returnArray = [ 34 | 'url' => $this->url 35 | ]; 36 | 37 | if ($this->getCaption()) { 38 | $returnArray['caption'] = $this->getCaption(); 39 | } 40 | 41 | if ($this->getName()) { 42 | $returnArray['name'] = $this->getName(); 43 | } 44 | 45 | return $returnArray; 46 | } 47 | 48 | public function getUrl(): string 49 | { 50 | return $this->url; 51 | } 52 | 53 | public function getCaption(): string 54 | { 55 | return $this->caption; 56 | } 57 | 58 | public function getName(): ?string 59 | { 60 | return $this->name; 61 | } 62 | 63 | public function setName(?string $name): void 64 | { 65 | $this->name = $name; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Messages/MessageObjects/ImageObject.php: -------------------------------------------------------------------------------- 1 | url = $data['url']; 18 | 19 | if (isset($data['caption'])) { 20 | $this->caption = $data['caption']; 21 | } 22 | 23 | return $this; 24 | } 25 | 26 | public function toArray(): array 27 | { 28 | $returnArray = [ 29 | 'url' => $this->url 30 | ]; 31 | 32 | if ($this->getCaption()) { 33 | $returnArray['caption'] = $this->getCaption(); 34 | } 35 | 36 | return $returnArray; 37 | } 38 | 39 | public function getUrl(): string 40 | { 41 | return $this->url; 42 | } 43 | 44 | public function getCaption(): string 45 | { 46 | return $this->caption; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Messages/MessageObjects/TemplateObject.php: -------------------------------------------------------------------------------- 1 | name = $data['name']; 16 | 17 | if (isset($data['parameters'])) { 18 | $this->parameters = $data['parameters']; 19 | } 20 | 21 | return $this; 22 | } 23 | 24 | public function toArray(): array 25 | { 26 | $returnArray = [ 27 | 'name' => $this->name 28 | ]; 29 | 30 | if ($this->parameters) { 31 | $returnArray['parameters'] = $this->parameters; 32 | } 33 | 34 | return $returnArray; 35 | } 36 | 37 | public function getName(): string 38 | { 39 | return $this->name; 40 | } 41 | 42 | public function getParameters(): array 43 | { 44 | return $this->parameters; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Messages/MessageObjects/VCardObject.php: -------------------------------------------------------------------------------- 1 | url = $data['url']; 18 | 19 | return $this; 20 | } 21 | 22 | public function toArray(): array 23 | { 24 | return [ 25 | 'url' => $this->url 26 | ]; 27 | } 28 | 29 | public function getUrl(): string 30 | { 31 | return $this->url; 32 | } 33 | 34 | public function getCaption(): ?string 35 | { 36 | return $this->caption; 37 | } 38 | 39 | public function setCaption(?string $caption): void 40 | { 41 | $this->caption = $caption; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Messages/MessageObjects/VideoObject.php: -------------------------------------------------------------------------------- 1 | url = $data['url']; 16 | 17 | if (isset($data['caption'])) { 18 | $this->caption = $data['caption']; 19 | } 20 | 21 | return $this; 22 | } 23 | 24 | public function toArray(): array 25 | { 26 | $returnArray = [ 27 | 'url' => $this->url 28 | ]; 29 | 30 | if ($this->getCaption()) { 31 | $returnArray['caption'] = $this->getCaption(); 32 | } 33 | 34 | return $returnArray; 35 | } 36 | 37 | public function getUrl(): string 38 | { 39 | return $this->url; 40 | } 41 | 42 | public function getCaption(): string 43 | { 44 | return $this->caption; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Messages/MessageTraits/ContextTrait.php: -------------------------------------------------------------------------------- 1 | context; 12 | } 13 | 14 | public function setContext(?array $context): static 15 | { 16 | $this->context = $context; 17 | 18 | return $this; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Messages/MessageTraits/TextTrait.php: -------------------------------------------------------------------------------- 1 | text; 12 | } 13 | 14 | public function setText(string $text): void 15 | { 16 | $this->text = $text; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Messages/MessageTraits/TtlTrait.php: -------------------------------------------------------------------------------- 1 | ttl; 12 | } 13 | 14 | public function setTTl(?int $ttl): static 15 | { 16 | $this->ttl = $ttl; 17 | 18 | return $this; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Messages/Webhook/Factory.php: -------------------------------------------------------------------------------- 1 | 'Vonage\Messages\Webhook\InboundSMS', 14 | 'mms' => 'Vonage\Messages\Webhook\InboundMMS', 15 | 'rcs' => 'Vonage\Messages\Webhook\InboundRCS', 16 | 'whatsapp' => 'Vonage\Messages\Webhook\InboundWhatsApp', 17 | 'messenger' => 'Vonage\Messages\Webhook\InboundMessenger', 18 | 'viber_service' => 'Vonage\Messages\Webhook\InboundViber' 19 | ]; 20 | 21 | public static function createFromArray(array $data): mixed 22 | { 23 | if (!isset($data['channel'])) { 24 | throw new InvalidArgumentException("The 'channel' key is missing in the incoming data."); 25 | } 26 | 27 | $channel = $data['channel']; 28 | 29 | if (!array_key_exists($channel, self::$classMap)) { 30 | throw new InvalidArgumentException("Unable to determine incoming webhook type for channel: {$channel}"); 31 | } 32 | 33 | return new self::$classMap[$channel](); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Messages/Webhook/InboundMMS.php: -------------------------------------------------------------------------------- 1 | data = $data; 16 | return $this; 17 | } 18 | 19 | public function toArray(): array 20 | { 21 | return $this->data; 22 | } 23 | 24 | public function __get($name) 25 | { 26 | return $this->data[$name]; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Messages/Webhook/InboundMessenger.php: -------------------------------------------------------------------------------- 1 | data = $data; 16 | return $this; 17 | } 18 | 19 | public function toArray(): array 20 | { 21 | return $this->data; 22 | } 23 | 24 | public function __get($name) 25 | { 26 | return $this->data[$name]; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Messages/Webhook/InboundRCS.php: -------------------------------------------------------------------------------- 1 | data = $data; 16 | return $this; 17 | } 18 | 19 | public function toArray(): array 20 | { 21 | return $this->data; 22 | } 23 | 24 | public function __get($name) 25 | { 26 | return $this->data[$name]; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Messages/Webhook/InboundSMS.php: -------------------------------------------------------------------------------- 1 | data = $data; 16 | return $this; 17 | } 18 | 19 | public function toArray(): array 20 | { 21 | return $this->data; 22 | } 23 | 24 | public function __get($name) 25 | { 26 | return $this->data[$name]; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Messages/Webhook/InboundViber.php: -------------------------------------------------------------------------------- 1 | data = $data; 16 | return $this; 17 | } 18 | 19 | public function toArray(): array 20 | { 21 | return $this->data; 22 | } 23 | 24 | public function __get($name) 25 | { 26 | return $this->data[$name]; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Messages/Webhook/InboundWhatsApp.php: -------------------------------------------------------------------------------- 1 | data = $data; 16 | return $this; 17 | } 18 | 19 | public function toArray(): array 20 | { 21 | return $this->data; 22 | } 23 | 24 | public function __get($name) 25 | { 26 | return $this->data[$name]; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Network/Number/Request.php: -------------------------------------------------------------------------------- 1 | params['number'] = $number; 32 | $this->params['callback'] = $callback; 33 | $this->params['callback_timeout'] = $timeout; 34 | $this->params['callback_method'] = $method; 35 | $this->params['client_ref'] = $ref; 36 | 37 | if (!empty($features)) { 38 | $this->params['features'] = implode(',', $features); 39 | } 40 | } 41 | 42 | public function getURI(): string 43 | { 44 | return '/ni/json'; 45 | } 46 | 47 | public function wrapResponse(ResponseInterface $response): ResponseInterface 48 | { 49 | if ($response->isError()) { 50 | return new Error($response->getData()); 51 | } 52 | 53 | return new Response($response->getData()); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/NumberVerification/ClientFactory.php: -------------------------------------------------------------------------------- 1 | setBaseUrl('https://oidc.idp.vonage.com/oauth2/auth'); 15 | $handler->setTokenUrl('https://api-eu.vonage.com/oauth2/token'); 16 | $handler->setScope('openid+dpv:FraudPreventionAndDetection#number-verification-verify-read'); 17 | 18 | $client = $container->get(\Vonage\Client::class); 19 | $handler->setClient($client); 20 | 21 | /** @var APIResource $api */ 22 | $api = $container->make(APIResource::class); 23 | $api 24 | ->setBaseUrl('https://api-eu.vonage.com/camara/number-verification/v031') 25 | ->setIsHAL(false) 26 | ->setClient($client) 27 | ->setErrorsOn200(false) 28 | ->setAuthHandlers($handler); 29 | 30 | return new Client($api); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Numbers/ClientFactory.php: -------------------------------------------------------------------------------- 1 | make(APIResource::class); 17 | $api 18 | ->setBaseUrl($api->getClient()->getRestUrl()) 19 | ->setIsHAL(false) 20 | ->setAuthHandlers(new BasicHandler()); 21 | 22 | return new Client($api); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Numbers/Hydrator.php: -------------------------------------------------------------------------------- 1 | hydrateObject($data, $number); 15 | } 16 | 17 | public function hydrateObject(array $data, $object) 18 | { 19 | $object->fromArray($data); 20 | return $object; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/ProactiveConnect/ClientFactory.php: -------------------------------------------------------------------------------- 1 | make(APIResource::class); 14 | $api->setIsHAL(false) 15 | ->setErrorsOn200(false) 16 | ->setAuthHandlers([new KeypairHandler()]) 17 | ->setBaseUrl('https://api-eu.vonage.com/v0.1/bulk/'); 18 | 19 | return new Client($api); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/ProactiveConnect/Objects/ListBaseObject.php: -------------------------------------------------------------------------------- 1 | data[$name] = $value; 16 | 17 | return $this; 18 | } 19 | 20 | public function get(string $name) 21 | { 22 | return $this->data[$name]; 23 | } 24 | 25 | public function fromArray(array $data): void 26 | { 27 | $this->data = $data; 28 | } 29 | 30 | public function toArray(): array 31 | { 32 | return [ 33 | 'data' => $this->data 34 | ]; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Redact/ClientFactory.php: -------------------------------------------------------------------------------- 1 | make(APIResource::class); 21 | $api 22 | ->setBaseUri('/v1/redact/transaction') 23 | ->setAuthHandlers(new BasicHandler()) 24 | ->setCollectionName(''); 25 | 26 | // This API has a slightly different format for the error message, so override 27 | $exceptionHandler = $api->getExceptionErrorHandler(); 28 | 29 | if ($exceptionHandler instanceof APIExceptionHandler) { 30 | $exceptionHandler->setRfc7807Format("%s - %s. See %s for more information"); 31 | } 32 | 33 | $api->setExceptionErrorHandler($exceptionHandler); 34 | 35 | return new Client($api); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/SMS/Client.php: -------------------------------------------------------------------------------- 1 | api; 29 | } 30 | 31 | /** 32 | * @throws ClientExceptionInterface 33 | * @throws ClientException 34 | */ 35 | public function send(Message $message): Collection 36 | { 37 | if ($warningMessage = $message->getWarningMessage()) { 38 | $this->log(LogLevel::WARNING, $warningMessage); 39 | } 40 | 41 | try { 42 | $response = $this->api->create($message->toArray(), '/sms/json'); 43 | 44 | return new Collection($response); 45 | } catch (ThrottleException $e) { 46 | sleep($e->getTimeout()); 47 | 48 | return $this->send($message); 49 | } 50 | } 51 | 52 | /** 53 | * @throws ClientExceptionInterface 54 | * @throws ClientException 55 | */ 56 | public function sendTwoFactor(string $number, int $pin): SentSMS 57 | { 58 | $response = $this->api->create( 59 | ['to' => $number, 'pin' => $pin], 60 | '/sc/us/2fa/json' 61 | ); 62 | 63 | return new SentSMS($response['messages'][0]); 64 | } 65 | 66 | /** 67 | * @throws ClientExceptionInterface 68 | * @throws ClientException 69 | */ 70 | public function sendAlert(string $number, array $templateReplacements): Collection 71 | { 72 | $response = $this->api->create( 73 | ['to' => $number] + $templateReplacements, 74 | '/sc/us/alert/json' 75 | ); 76 | return new Collection($response); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/SMS/ClientFactory.php: -------------------------------------------------------------------------------- 1 | make(APIResource::class); 18 | $api 19 | ->setBaseUrl($api->getClient()->getRestUrl()) 20 | ->setCollectionName('messages') 21 | ->setIsHAL(false) 22 | ->setErrorsOn200(true) 23 | ->setExceptionErrorHandler(new ExceptionErrorHandler()) 24 | ->setAuthHandlers([new BasicHandler(), new SignatureBodyHandler()]); 25 | 26 | return new Client($api); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/SMS/Collection.php: -------------------------------------------------------------------------------- 1 | > $data 16 | */ 17 | public function __construct(protected array $data) 18 | { 19 | } 20 | 21 | public function count(): int 22 | { 23 | return (int)$this->data['message-count']; 24 | } 25 | 26 | public function current(): SentSMS 27 | { 28 | return new SentSMS($this->data['messages'][$this->current]); 29 | } 30 | 31 | /** 32 | * @return bool|float|int|string|null 33 | */ 34 | #[\ReturnTypeWillChange] 35 | public function key() 36 | { 37 | return $this->current; 38 | } 39 | 40 | public function next(): void 41 | { 42 | $this->current++; 43 | } 44 | 45 | public function rewind(): void 46 | { 47 | $this->current = 0; 48 | } 49 | 50 | public function valid(): bool 51 | { 52 | return isset($this->data['messages'][$this->current]); 53 | } 54 | 55 | public function getAllMessagesRaw(): array 56 | { 57 | return $this->data; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/SMS/Message/Binary.php: -------------------------------------------------------------------------------- 1 | $this->getBody(), 26 | 'udh' => $this->getUdh(), 27 | ]; 28 | 29 | if ($this->getProtocolId()) { 30 | $data['protocol-id'] = $this->getProtocolId(); 31 | } 32 | 33 | $data = $this->appendUniversalOptions($data); 34 | 35 | return $data; 36 | } 37 | 38 | public function getBody(): string 39 | { 40 | return $this->body; 41 | } 42 | 43 | public function getUdh(): string 44 | { 45 | return $this->udh; 46 | } 47 | 48 | public function getProtocolId(): ?int 49 | { 50 | return $this->protocolId; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/SMS/Message/Message.php: -------------------------------------------------------------------------------- 1 | accountRef = $data['account-ref'] ?? null; 52 | $this->clientRef = $data['client-ref'] ?? null; 53 | $this->to = $data['to']; 54 | $this->messageId = $data['message-id']; 55 | $this->status = (int)$data['status']; 56 | $this->remainingBalance = $data['remaining-balance']; 57 | $this->messagePrice = $data['message-price']; 58 | $this->network = $data['network']; 59 | } 60 | 61 | public function getAccountRef(): ?string 62 | { 63 | return $this->accountRef; 64 | } 65 | 66 | public function getClientRef(): ?string 67 | { 68 | return $this->clientRef; 69 | } 70 | 71 | public function getMessageId(): string 72 | { 73 | return $this->messageId; 74 | } 75 | 76 | public function getMessagePrice(): string 77 | { 78 | return $this->messagePrice; 79 | } 80 | 81 | public function getNetwork(): string 82 | { 83 | return $this->network; 84 | } 85 | 86 | public function getRemainingBalance(): string 87 | { 88 | return $this->remainingBalance; 89 | } 90 | 91 | public function getStatus(): int 92 | { 93 | return $this->status; 94 | } 95 | 96 | public function getTo(): string 97 | { 98 | return $this->to; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/SMS/Webhook/Factory.php: -------------------------------------------------------------------------------- 1 | api; 19 | } 20 | 21 | public function get(string $accountId, string $id): Secret 22 | { 23 | $data = $this->api->get("{$accountId}/secrets/{$id}"); 24 | 25 | return new Secret($data); 26 | } 27 | 28 | public function list(string $accountId): IterableAPICollection 29 | { 30 | $collection = $this->api->search(null, "/accounts/{$accountId}/secrets"); 31 | $hydrator = new ArrayHydrator(); 32 | $hydrator->setPrototype(new Secret()); 33 | $collection->setHydrator($hydrator); 34 | 35 | return $collection; 36 | } 37 | 38 | public function create(string $accountId, string $secret): Secret 39 | { 40 | $response = $this->api->create(['secret' => $secret], "/{$accountId}/secrets"); 41 | return new Secret($response); 42 | } 43 | 44 | public function revoke(string $accountId, string $id) 45 | { 46 | $this->api->delete("{$accountId}/secrets/{$id}"); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Secrets/ClientFactory.php: -------------------------------------------------------------------------------- 1 | make(APIResource::class); 16 | $api->setBaseUri('/accounts') 17 | ->setAuthHandlers(new BasicHandler()) 18 | ->setCollectionName('secrets'); 19 | 20 | return new Client($api); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Secrets/Secret.php: -------------------------------------------------------------------------------- 1 | fromArray($data); 19 | } 20 | } 21 | 22 | public function getId(): string 23 | { 24 | return $this->id; 25 | } 26 | 27 | public function getCreatedAt(): DateTimeInterface 28 | { 29 | return $this->createdAt; 30 | } 31 | 32 | public function fromArray(array $data) 33 | { 34 | $this->id = $data['id']; 35 | $this->createdAt = new DateTimeImmutable($data['created_at']); 36 | } 37 | 38 | public function toArray(): array 39 | { 40 | return [ 41 | 'id' => $this->id, 42 | 'created_at' => $this->createdAt->format('Y-m-d\TH:i:s\Z'), 43 | ]; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/SimSwap/Client.php: -------------------------------------------------------------------------------- 1 | api; 20 | } 21 | 22 | public function checkSimSwap(string $number, ?int $maxAge = null) 23 | { 24 | /** @var SimSwapGnpHandler $handler */ 25 | $handler = $this->getAPIResource()->getAuthHandlers()[0]; 26 | $handler->setScope('dpv:FraudPreventionAndDetection#check-sim-swap'); 27 | 28 | if (!$handler instanceof SimSwapGnpHandler) { 29 | throw new \RuntimeException('SimSwap Client has been misconfigured. Only a GNP Handler can be used'); 30 | } 31 | 32 | $payload = [ 33 | 'phoneNumber' => $number 34 | ]; 35 | 36 | if (!is_null($maxAge)) { 37 | $payload['maxAge'] = $maxAge; 38 | } 39 | 40 | $response = $this->getAPIResource()->create($payload, 'check'); 41 | 42 | return $response['swapped']; 43 | } 44 | 45 | public function checkSimSwapDate(string $number): string 46 | { 47 | /** @var SimSwapGnpHandler $handler */ 48 | $handler = $this->getAPIResource()->getAuthHandlers()[0]; 49 | $handler->setScope('dpv:FraudPreventionAndDetection#retrieve-sim-swap-date'); 50 | 51 | if (!$handler instanceof SimSwapGnpHandler) { 52 | throw new \RuntimeException('SimSwap Client has been misconfigured. Only a GNP Handler can be used'); 53 | } 54 | 55 | $response = $this->getAPIResource()->create(['phoneNumber' => $number], 'retrieve-date'); 56 | 57 | return $response['latestSimChange']; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/SimSwap/ClientFactory.php: -------------------------------------------------------------------------------- 1 | setBaseUrl('https://api-eu.vonage.com/oauth2/bc-authorize'); 15 | $handler->setTokenUrl('https://api-eu.vonage.com/oauth2/token'); 16 | 17 | $client = $container->get(\Vonage\Client::class); 18 | $handler->setClient($client); 19 | 20 | /** @var APIResource $api */ 21 | $api = $container->make(APIResource::class); 22 | $api 23 | ->setBaseUrl('https://api-eu.vonage.com/camara/sim-swap/v040') 24 | ->setIsHAL(false) 25 | ->setClient($client) 26 | ->setErrorsOn200(false) 27 | ->setAuthHandlers($handler); 28 | 29 | return new Client($api); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Subaccount/ClientFactory.php: -------------------------------------------------------------------------------- 1 | make(APIResource::class); 13 | $api->setIsHAL(true) 14 | ->setErrorsOn200(false) 15 | ->setBaseUrl('https://api.nexmo.com/accounts'); 16 | 17 | return new Client($api); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Subaccount/Request/TransferBalanceRequest.php: -------------------------------------------------------------------------------- 1 | from; 20 | } 21 | 22 | public function setFrom(string $from): self 23 | { 24 | $this->from = $from; 25 | 26 | return $this; 27 | } 28 | 29 | public function getTo(): string 30 | { 31 | return $this->to; 32 | } 33 | 34 | public function setTo(string $to): self 35 | { 36 | $this->to = $to; 37 | 38 | return $this; 39 | } 40 | 41 | public function getAmount(): string 42 | { 43 | return $this->amount; 44 | } 45 | 46 | public function setAmount(string $amount): self 47 | { 48 | $this->amount = $amount; 49 | 50 | return $this; 51 | } 52 | 53 | public function getReference(): string 54 | { 55 | return $this->reference; 56 | } 57 | 58 | public function setReference(string $reference): self 59 | { 60 | $this->reference = $reference; 61 | 62 | return $this; 63 | } 64 | 65 | public function getApiKey(): string 66 | { 67 | return $this->apiKey; 68 | } 69 | 70 | public function setApiKey(string $apiKey): self 71 | { 72 | $this->apiKey = $apiKey; 73 | 74 | return $this; 75 | } 76 | 77 | public function fromArray(array $data): static 78 | { 79 | $this->from = $data['from']; 80 | $this->to = $data['to']; 81 | $this->amount = $data['amount']; 82 | $this->reference = $data['reference']; 83 | 84 | return $this; 85 | } 86 | 87 | public function toArray(): array 88 | { 89 | return [ 90 | 'from' => $this->getFrom(), 91 | 'to' => $this->getTo(), 92 | 'amount' => (float)$this->getAmount(), 93 | 'reference' => $this->getReference() 94 | ]; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/Users/ClientFactory.php: -------------------------------------------------------------------------------- 1 | make(APIResource::class); 17 | $api 18 | ->setBaseUri('/v1/users') 19 | ->setCollectionName('users') 20 | ->setAuthHandlers(new KeypairHandler()); 21 | 22 | $hydrator = new ArrayHydrator(); 23 | $hydrator->setPrototype(new User()); 24 | 25 | return new Client($api, $hydrator); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Users/Filter/UserFilter.php: -------------------------------------------------------------------------------- 1 | pageSize !== null) { 25 | $query['page_size'] = $this->getPageSize(); 26 | } 27 | 28 | if ($this->order !== null) { 29 | $query['order'] = $this->getOrder(); 30 | } 31 | 32 | if ($this->cursor !== null) { 33 | $query['cursor'] = $this->getCursor(); 34 | } 35 | 36 | return $query; 37 | } 38 | 39 | public function getPageSize(): int 40 | { 41 | return $this->pageSize; 42 | } 43 | 44 | public function setPageSize(int $pageSize): static 45 | { 46 | $this->pageSize = $pageSize; 47 | 48 | return $this; 49 | } 50 | 51 | public function getOrder(): string 52 | { 53 | return $this->order; 54 | } 55 | 56 | public function setOrder(string $order): static 57 | { 58 | if ($order !== self::ORDER_ASC && $order !== self::ORDER_DESC) { 59 | throw new InvalidArgumentException('Order must be `asc` or `desc`'); 60 | } 61 | 62 | $this->order = $order; 63 | 64 | return $this; 65 | } 66 | 67 | public function getCursor(): ?string 68 | { 69 | return $this->cursor; 70 | } 71 | 72 | public function setCursor(?string $cursor): static 73 | { 74 | $this->cursor = $cursor; 75 | 76 | return $this; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Verify/Check.php: -------------------------------------------------------------------------------- 1 | data['code']; 25 | } 26 | 27 | /** 28 | * @throws Exception 29 | */ 30 | public function getDate(): DateTime 31 | { 32 | return new DateTime($this->data['date_received']); 33 | } 34 | 35 | public function getStatus() 36 | { 37 | return $this->data['status']; 38 | } 39 | 40 | public function getIpAddress() 41 | { 42 | return $this->data['ip_address']; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Verify/ClientFactory.php: -------------------------------------------------------------------------------- 1 | make(APIResource::class); 17 | $api 18 | ->setIsHAL(false) 19 | ->setBaseUri('/verify') 20 | ->setErrorsOn200(true) 21 | ->setAuthHandlers(new TokenBodyHandler()) 22 | ->setExceptionErrorHandler(new ExceptionErrorHandler()); 23 | 24 | return new Client($api); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Verify/ExceptionErrorHandler.php: -------------------------------------------------------------------------------- 1 | getBody()->getContents(), true); 25 | $response->getBody()->rewind(); 26 | $e = null; 27 | 28 | if (!isset($data['status'])) { 29 | $e = new Request('unexpected response from API'); 30 | $e->setEntity($data); 31 | throw $e; 32 | } 33 | 34 | //normalize errors (client vrs server) 35 | switch ($data['status']) { 36 | // These exist because `status` is valid in both the error 37 | // response and a success response, but serve different purposes 38 | // in each case 39 | case 'IN PROGRESS': 40 | case 'SUCCESS': 41 | case 'FAILED': 42 | case 'EXPIRED': 43 | case 'CANCELLED': 44 | case '0': 45 | break; 46 | case '5': 47 | default: 48 | $e = new Request($data['error_text'], (int)$data['status']); 49 | $e->setEntity($data); 50 | throw $e; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Verify/VerificationInterface.php: -------------------------------------------------------------------------------- 1 | make(APIResource::class); 15 | $api->setIsHAL(false) 16 | ->setErrorsOn200(false) 17 | ->setAuthHandlers([new KeypairHandler(), new BasicHandler()]) 18 | ->setBaseUrl('https://api.nexmo.com/v2/verify'); 19 | 20 | return new Client($api); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Verify2/Filters/TemplateFilter.php: -------------------------------------------------------------------------------- 1 | getPage()) { 19 | $return['page'] = $this->getPage(); 20 | } 21 | 22 | if ($this->getPageSize()) { 23 | $return['page_size'] = $this->getPageSize(); 24 | } 25 | 26 | return $return; 27 | } 28 | 29 | public function getPageSize(): ?int 30 | { 31 | return $this->pageSize; 32 | } 33 | 34 | public function setPageSize(int $pageSize): self 35 | { 36 | $this->pageSize = $pageSize; 37 | 38 | return $this; 39 | } 40 | 41 | public function getPage(): ?int 42 | { 43 | return $this->page; 44 | } 45 | 46 | public function setPage(int $page): self 47 | { 48 | $this->page = $page; 49 | 50 | return $this; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Verify2/Request/EmailRequest.php: -------------------------------------------------------------------------------- 1 | brand)) { 18 | throw new InvalidArgumentException('The brand name cannot be longer than 16 characters.'); 19 | } 20 | 21 | if (!$this->locale) { 22 | $this->locale = new VerificationLocale(); 23 | } 24 | 25 | if ($this->code) { 26 | $this->setCode($this->code); 27 | } 28 | 29 | $workflow = new VerificationWorkflow(VerificationWorkflow::WORKFLOW_EMAIL, $to, $from); 30 | 31 | $this->addWorkflow($workflow); 32 | } 33 | 34 | public function toArray(): array 35 | { 36 | return $this->getBaseVerifyUniversalOutputArray(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Verify2/Request/RequestInterface.php: -------------------------------------------------------------------------------- 1 | brand)) { 23 | throw new InvalidArgumentException('The brand name cannot be longer than 16 characters.'); 24 | } 25 | 26 | if (!$this->locale) { 27 | $this->locale = new VerificationLocale(); 28 | } 29 | 30 | $customKeys = array_filter([ 31 | 'entity_id' => $this->entityId, 32 | 'content_id' => $this->contentId 33 | ]); 34 | 35 | $workflow = new VerificationWorkflow(VerificationWorkflow::WORKFLOW_SMS, $to, $from, $customKeys); 36 | 37 | $this->addWorkflow($workflow); 38 | } 39 | 40 | public function toArray(): array 41 | { 42 | $return = $this->getBaseVerifyUniversalOutputArray(); 43 | 44 | if (!is_null($this->getTemplateId())) { 45 | $return['template_id'] = $this->getTemplateId(); 46 | } 47 | 48 | return $return; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Verify2/Request/SilentAuthRequest.php: -------------------------------------------------------------------------------- 1 | brand)) { 16 | throw new InvalidArgumentException('The brand name cannot be longer than 16 characters.'); 17 | } 18 | 19 | $workflow = new VerificationWorkflow(VerificationWorkflow::WORKFLOW_SILENT_AUTH, $to); 20 | 21 | if ($this->redirectUrl) { 22 | $workflow->setCustomKeys(['redirect_url' => $this->redirectUrl]); 23 | } 24 | 25 | $this->addWorkflow($workflow); 26 | } 27 | 28 | public function toArray(): array 29 | { 30 | return [ 31 | 'brand' => $this->getBrand(), 32 | 'workflow' => $this->getWorkflows() 33 | ]; 34 | } 35 | 36 | public static function isValidWorkflow(array $workflows): bool 37 | { 38 | $firstWorkflow = $workflows[0]; 39 | 40 | if ($firstWorkflow['channel'] == VerificationWorkflow::WORKFLOW_SILENT_AUTH) { 41 | return true; 42 | } 43 | 44 | return false; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Verify2/Request/UpdateCustomTemplateRequest.php: -------------------------------------------------------------------------------- 1 | name; 20 | } 21 | 22 | public function setName(?string $name): UpdateCustomTemplateRequest 23 | { 24 | $this->name = $name; 25 | return $this; 26 | } 27 | 28 | public function getIsDefault(): ?bool 29 | { 30 | return $this->isDefault; 31 | } 32 | 33 | public function setIsDefault(?bool $isDefault): UpdateCustomTemplateRequest 34 | { 35 | $this->isDefault = $isDefault; 36 | return $this; 37 | } 38 | 39 | public function toArray(): array 40 | { 41 | $return = []; 42 | 43 | if ($this->getName()) { 44 | $return['name'] = $this->getName(); 45 | } 46 | 47 | if ($this->getIsDefault()) { 48 | $return['is_default'] = $this->getIsDefault(); 49 | } 50 | 51 | return $return; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Verify2/Request/VoiceRequest.php: -------------------------------------------------------------------------------- 1 | brand)) { 20 | throw new InvalidArgumentException('The brand name cannot be longer than 16 characters.'); 21 | } 22 | 23 | if (!$this->locale) { 24 | $this->locale = new VerificationLocale(); 25 | } 26 | 27 | $workflow = new VerificationWorkflow(VerificationWorkflow::WORKFLOW_VOICE, $to); 28 | 29 | if ($this->code) { 30 | $workflow->setCode($this->code); 31 | } 32 | 33 | $this->addWorkflow($workflow); 34 | } 35 | 36 | public function toArray(): array 37 | { 38 | return $this->getBaseVerifyUniversalOutputArray(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Verify2/Request/WhatsAppInteractiveRequest.php: -------------------------------------------------------------------------------- 1 | brand)) { 17 | throw new InvalidArgumentException('The brand name cannot be longer than 16 characters.'); 18 | } 19 | 20 | if (!$this->locale) { 21 | $this->locale = new VerificationLocale(); 22 | } 23 | 24 | $workflow = new VerificationWorkflow(VerificationWorkflow::WORKFLOW_WHATSAPP_INTERACTIVE, $to); 25 | $this->addWorkflow($workflow); 26 | } 27 | 28 | public function toArray(): array 29 | { 30 | return $this->getBaseVerifyUniversalOutputArray(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Verify2/Request/WhatsAppRequest.php: -------------------------------------------------------------------------------- 1 | brand)) { 18 | throw new InvalidArgumentException('The brand name cannot be longer than 16 characters.'); 19 | } 20 | 21 | if (!$this->locale) { 22 | $this->locale = new VerificationLocale(); 23 | } 24 | 25 | $workflow = new VerificationWorkflow(VerificationWorkflow::WORKFLOW_WHATSAPP, $to, $from); 26 | 27 | $this->addWorkflow($workflow); 28 | } 29 | 30 | public function toArray(): array 31 | { 32 | return $this->getBaseVerifyUniversalOutputArray(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Verify2/Traits/CustomTemplateTrait.php: -------------------------------------------------------------------------------- 1 | templateId; 12 | } 13 | 14 | public function setTemplateId(string $templateId): string 15 | { 16 | return $this->templateId = $templateId; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Verify2/VerifyObjects/Template.php: -------------------------------------------------------------------------------- 1 | data[$property] ?? null; 16 | } 17 | 18 | public function __set($property, $value) 19 | { 20 | $this->data[$property] = $value; 21 | 22 | return $this; 23 | } 24 | 25 | public function __isset(string $name): bool 26 | { 27 | return isset($this->data[$name]); 28 | } 29 | 30 | public function fromArray(array $data): static 31 | { 32 | $this->data = $data; 33 | 34 | return $this; 35 | } 36 | 37 | public function toArray(): array 38 | { 39 | return $this->data; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Verify2/VerifyObjects/TemplateFragment.php: -------------------------------------------------------------------------------- 1 | data[$property] ?? null; 16 | } 17 | 18 | public function __set($property, $value) 19 | { 20 | $this->data[$property] = $value; 21 | 22 | return $this; 23 | } 24 | 25 | public function __isset(string $name): bool 26 | { 27 | return isset($this->data[$name]); 28 | } 29 | 30 | public function fromArray(array $data): static 31 | { 32 | $this->data = $data; 33 | 34 | return $this; 35 | } 36 | 37 | public function toArray(): array 38 | { 39 | return $this->data; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Verify2/VerifyObjects/VerificationLocale.php: -------------------------------------------------------------------------------- 1 | code; 14 | } 15 | 16 | public function setCode(string $code): static 17 | { 18 | $this->code = $code; 19 | 20 | return $this; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Verify2/VerifyObjects/VerifyEvent.php: -------------------------------------------------------------------------------- 1 | data[$property] ?? null; 14 | } 15 | 16 | public function __set($property, $value) 17 | { 18 | $this->data[$property] = $value; 19 | 20 | return $this; 21 | } 22 | 23 | public function __isset(string $name): bool 24 | { 25 | return isset($this->data[$name]); 26 | } 27 | 28 | public function fromArray(array $data): static 29 | { 30 | $this->data = $data; 31 | 32 | return $this; 33 | } 34 | 35 | public function toArray(): array 36 | { 37 | return $this->data; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Verify2/VerifyObjects/VerifySilentAuthEvent.php: -------------------------------------------------------------------------------- 1 | data[$property] ?? null; 16 | } 17 | 18 | public function __set($property, $value) 19 | { 20 | $this->data[$property] = $value; 21 | 22 | return $this; 23 | } 24 | 25 | public function __isset(string $name): bool 26 | { 27 | return isset($this->data[$name]); 28 | } 29 | 30 | public function fromArray(array $data): static 31 | { 32 | $this->data = $data; 33 | 34 | return $this; 35 | } 36 | 37 | public function toArray(): array 38 | { 39 | return $this->data; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Verify2/VerifyObjects/VerifyStatusUpdate.php: -------------------------------------------------------------------------------- 1 | data[$property] ?? null; 14 | } 15 | 16 | public function __set($property, $value) 17 | { 18 | $this->data[$property] = $value; 19 | 20 | return $this; 21 | } 22 | 23 | public function __isset(string $name): bool 24 | { 25 | return isset($this->data[$name]); 26 | } 27 | 28 | public function fromArray(array $data): static 29 | { 30 | $this->data = $data; 31 | 32 | return $this; 33 | } 34 | 35 | public function toArray(): array 36 | { 37 | return $this->data; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Verify2/VerifyObjects/VerifyWhatsAppInteractiveEvent.php: -------------------------------------------------------------------------------- 1 | data[$property] ?? null; 16 | } 17 | 18 | public function __set($property, $value) 19 | { 20 | $this->data[$property] = $value; 21 | 22 | return $this; 23 | } 24 | 25 | public function __isset(string $name): bool 26 | { 27 | return isset($this->data[$name]); 28 | } 29 | 30 | public function fromArray(array $data): static 31 | { 32 | $this->data = $data; 33 | 34 | return $this; 35 | } 36 | 37 | public function toArray(): array 38 | { 39 | return $this->data; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Verify2/Webhook/Factory.php: -------------------------------------------------------------------------------- 1 | make(APIResource::class); 17 | $api 18 | ->setBaseUri('/v1/calls') 19 | ->setAuthHandlers(new KeypairHandler()) 20 | ->setCollectionName('calls'); 21 | 22 | return new Client($api); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Voice/Endpoint/App.php: -------------------------------------------------------------------------------- 1 | toArray(); 24 | } 25 | 26 | /** 27 | * @return array{type: string, user: string} 28 | */ 29 | public function toArray(): array 30 | { 31 | return [ 32 | 'type' => 'app', 33 | 'user' => $this->id, 34 | ]; 35 | } 36 | 37 | public function getId(): string 38 | { 39 | return $this->id; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Voice/Endpoint/EndpointFactory.php: -------------------------------------------------------------------------------- 1 | App::factory($data['user']), 16 | 'phone' => Phone::factory($data['number'], $data), 17 | 'sip' => SIP::factory($data['uri'], $data), 18 | 'vbc' => VBC::factory($data['extension']), 19 | 'websocket' => Websocket::factory($data['uri'], $data), 20 | default => throw new RuntimeException('Unknown endpoint type'), 21 | }; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Voice/Endpoint/EndpointInterface.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | public function toArray(): array; 17 | } 18 | -------------------------------------------------------------------------------- /src/Voice/Endpoint/SIP.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | protected array $headers = []; 13 | 14 | public function __construct(protected string $id, array $headers = []) 15 | { 16 | $this->setHeaders($headers); 17 | } 18 | 19 | public static function factory(string $uri, array $headers = []): SIP 20 | { 21 | return new SIP($uri, $headers); 22 | } 23 | 24 | /** 25 | * @return array{type: string, uri: string, headers?: array} 26 | */ 27 | public function jsonSerialize(): array 28 | { 29 | return $this->toArray(); 30 | } 31 | 32 | /** 33 | * @return array{type: string, uri: string, headers?: array} 34 | */ 35 | public function toArray(): array 36 | { 37 | $data = [ 38 | 'type' => 'sip', 39 | 'uri' => $this->id, 40 | ]; 41 | 42 | if (!empty($this->getHeaders())) { 43 | $data['headers'] = $this->getHeaders(); 44 | } 45 | 46 | return $data; 47 | } 48 | 49 | public function getId(): string 50 | { 51 | return $this->id; 52 | } 53 | 54 | public function getHeaders(): array 55 | { 56 | return $this->headers; 57 | } 58 | 59 | /** 60 | * @return $this 61 | */ 62 | public function addHeader(string $key, string $value): self 63 | { 64 | $this->headers[$key] = $value; 65 | 66 | return $this; 67 | } 68 | 69 | /** 70 | * @return $this 71 | */ 72 | public function setHeaders(array $headers): self 73 | { 74 | $this->headers = $headers; 75 | 76 | return $this; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Voice/Endpoint/VBC.php: -------------------------------------------------------------------------------- 1 | toArray(); 24 | } 25 | 26 | /** 27 | * @return array{type: string, user: string} 28 | */ 29 | public function toArray(): array 30 | { 31 | return [ 32 | 'type' => 'vbc', 33 | 'extension' => $this->id, 34 | ]; 35 | } 36 | 37 | public function getId(): string 38 | { 39 | return $this->id; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Voice/NCCO/Action/ActionInterface.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | public function toNCCOArray(): array; 15 | } 16 | -------------------------------------------------------------------------------- /src/Voice/NCCO/NCCO.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | protected array $actions = []; 17 | 18 | public function addAction(ActionInterface $action): self 19 | { 20 | $this->actions[] = $action; 21 | return $this; 22 | } 23 | 24 | public function fromArray(array $data): void 25 | { 26 | $factory = new NCCOFactory(); 27 | 28 | foreach ($data as $rawNCCO) { 29 | $action = $factory->build($rawNCCO); 30 | $this->addAction($action); 31 | } 32 | } 33 | 34 | /** 35 | * @return array> 36 | */ 37 | public function jsonSerialize(): array 38 | { 39 | return $this->toArray(); 40 | } 41 | 42 | /** 43 | * @return array> 44 | */ 45 | public function toArray(): array 46 | { 47 | $data = []; 48 | 49 | foreach ($this->actions as $action) { 50 | $data[] = $action->toNCCOArray(); 51 | } 52 | 53 | return $data; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Voice/NCCO/NCCOFactory.php: -------------------------------------------------------------------------------- 1 | create($data['endpoint'][0]); 26 | 27 | if (null !== $endpoint) { 28 | return Connect::factory($endpoint); 29 | } 30 | 31 | throw new InvalidArgumentException("Malformed NCCO Action " . $data['endpoint'][0]); 32 | case 'conversation': 33 | return Conversation::factory($data['name'], $data); 34 | case 'input': 35 | return Input::factory($data); 36 | case 'notify': 37 | return Notify::factory($data['payload'], $data); 38 | case 'record': 39 | return Record::factory($data); 40 | case 'stream': 41 | return Stream::factory($data['streamUrl'], $data); 42 | case 'talk': 43 | return Talk::factory($data['text'], $data); 44 | default: 45 | throw new InvalidArgumentException("Unknown NCCO Action " . $data['action']); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Voice/Webhook.php: -------------------------------------------------------------------------------- 1 | method; 19 | } 20 | 21 | public function getUrl(): string 22 | { 23 | return $this->url; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Voice/Webhook/Answer.php: -------------------------------------------------------------------------------- 1 | from = $event['from']; 20 | $this->to = $event['to']; 21 | $this->uuid = $event['uuid'] ?? $event['call_uuid']; 22 | $this->conversationUuid = $event['conversation_uuid']; 23 | } 24 | 25 | public function getConversationUuid(): string 26 | { 27 | return $this->conversationUuid; 28 | } 29 | 30 | public function getFrom(): string 31 | { 32 | return $this->from; 33 | } 34 | 35 | public function getTo(): string 36 | { 37 | return $this->to; 38 | } 39 | 40 | public function getUuid(): string 41 | { 42 | return $this->uuid; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Voice/Webhook/Error.php: -------------------------------------------------------------------------------- 1 | conversationUuid = $event['conversation_uuid']; 24 | $this->reason = $event['reason']; 25 | $this->timestamp = new DateTimeImmutable($event['timestamp']); 26 | } 27 | 28 | public function getConversationUuid(): string 29 | { 30 | return $this->conversationUuid; 31 | } 32 | 33 | public function getReason(): string 34 | { 35 | return $this->reason; 36 | } 37 | 38 | public function getTimestamp(): DateTimeImmutable 39 | { 40 | return $this->timestamp; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Voice/Webhook/Factory.php: -------------------------------------------------------------------------------- 1 | speech = $data['speech']; 40 | 41 | // GET requests push this in as a string 42 | if (is_string($data['dtmf'])) { 43 | $data['dtmf'] = json_decode($data['dtmf'], true); 44 | } 45 | 46 | $this->dtmf = $data['dtmf']; 47 | $this->to = $data['to']; 48 | $this->from = $data['from']; 49 | $this->uuid = $data['uuid']; 50 | $this->conversationUuid = $data['conversation_uuid']; 51 | $this->timestamp = new DateTimeImmutable($data['timestamp']); 52 | } 53 | 54 | public function getSpeech(): array 55 | { 56 | return $this->speech; 57 | } 58 | 59 | public function getDtmf(): array 60 | { 61 | return $this->dtmf; 62 | } 63 | 64 | public function getFrom(): string 65 | { 66 | return $this->from; 67 | } 68 | 69 | public function getTo(): string 70 | { 71 | return $this->to; 72 | } 73 | 74 | public function getUuid(): string 75 | { 76 | return $this->uuid; 77 | } 78 | 79 | public function getConversationUuid(): string 80 | { 81 | return $this->conversationUuid; 82 | } 83 | 84 | public function getTimestamp(): DateTimeImmutable 85 | { 86 | return $this->timestamp; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/Voice/Webhook/Notification.php: -------------------------------------------------------------------------------- 1 | 17 | */ 18 | protected ?array $payload = null; 19 | 20 | protected ?string $conversationUuid = null; 21 | 22 | protected ?DateTimeImmutable $timestamp = null; 23 | 24 | /** 25 | * @throws Exception 26 | */ 27 | public function __construct(array $data) 28 | { 29 | if (is_string($data['payload'])) { 30 | $data['payload'] = json_decode($data['payload'], true); 31 | } 32 | 33 | $this->payload = $data['payload']; 34 | $this->conversationUuid = $data['conversation_uuid']; 35 | $this->timestamp = new DateTimeImmutable($data['timestamp']); 36 | } 37 | 38 | public function getPayload(): array 39 | { 40 | return $this->payload; 41 | } 42 | 43 | public function getConversationUuid(): string 44 | { 45 | return $this->conversationUuid; 46 | } 47 | 48 | public function getTimestamp(): DateTimeImmutable 49 | { 50 | return $this->timestamp; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Voice/Webhook/Record.php: -------------------------------------------------------------------------------- 1 | startTime = new DateTimeImmutable($event['start_time']); 32 | $this->endTime = new DateTimeImmutable($event['end_time']); 33 | $this->timestamp = new DateTimeImmutable($event['timestamp']); 34 | $this->recordingUrl = $event['recording_url']; 35 | $this->recordingUuid = $event['recording_uuid']; 36 | $this->conversationUuid = $event['conversation_uuid']; 37 | $this->size = (int)$event['size']; 38 | } 39 | 40 | public function getStartTime(): DateTimeImmutable 41 | { 42 | return $this->startTime; 43 | } 44 | 45 | public function getRecordingUrl(): string 46 | { 47 | return $this->recordingUrl; 48 | } 49 | 50 | public function getSize(): int 51 | { 52 | return $this->size; 53 | } 54 | 55 | public function getRecordingUuid(): string 56 | { 57 | return $this->recordingUuid; 58 | } 59 | 60 | public function getEndTime(): DateTimeImmutable 61 | { 62 | return $this->endTime; 63 | } 64 | 65 | public function getConversationUuid(): string 66 | { 67 | return $this->conversationUuid; 68 | } 69 | 70 | public function getTimestamp(): DateTimeImmutable 71 | { 72 | return $this->timestamp; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Voice/Webhook/Transfer.php: -------------------------------------------------------------------------------- 1 | conversationUuidFrom = $event['conversation_uuid_from']; 26 | $this->conversationUuidTo = $event['conversation_uuid_to']; 27 | $this->uuid = $event['uuid']; 28 | $this->timestamp = new DateTimeImmutable($event['timestamp']); 29 | } 30 | 31 | public function getConversationUuidFrom(): string 32 | { 33 | return $this->conversationUuidFrom; 34 | } 35 | 36 | public function getConversationUuidTo(): string 37 | { 38 | return $this->conversationUuidTo; 39 | } 40 | 41 | public function getUuid(): string 42 | { 43 | return $this->uuid; 44 | } 45 | 46 | public function getTimestamp(): DateTimeImmutable 47 | { 48 | return $this->timestamp; 49 | } 50 | } 51 | --------------------------------------------------------------------------------