koteeki/yii2-clearoutphone

There is no license information available for the latest version (1.0.0) of this package.

Yii2 ClearoutPhone extension

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:yii2-extension

1.0.0 2020-01-28 04:25 UTC

This package is auto-updated.

Last update: 2024-03-28 21:16:07 UTC


README

A Yii2 extension to use the ClearoutPhone API. Supported countries: https://clearoutphone.io/supported-countries/

Installation

The preferred way to install this extension is through composer.

Either run:

php composer.phar require --prefer-dist "koteeki/yii2-clearoutphone":"@dev"

or add:

"koteeki/yii2-clearoutphone": "@dev"

to the require section of your composer.json file.

Usage

return [
    'components' => [
        'clearoutphone' => [
            'class' => \koteeki\clearoutphone\ClearoutPhone::class,
            'token' => 'YOUR_TOKEN_HERE',
            'timeout' => 5000,
        ],
    ],
];
  • You can now access the extension via \Yii::$app->clearoutphone

Methods

  • getCredits() - get to know the available credits.

  • getPhoneDetails(string $number, string $countryCode = null) - validates phone the number, returns PhoneNumberDetails.

Exceptions

The methods above throw exception due to a phone number validation failed:

  • BadRequestException - validation failed due to a request error,
  • PaymentRequiredException - you have exhausted your credits,
  • ServiceUnavailable - the service is unavailable,
  • TimeoutException - timeout occurred,
  • UnauthorizedException - token is invalid,
  • ClearoutPhoneException - an unknown error.

Example

use koteeki\clearoutphone\ClearoutPhone;
use koteeki\clearoutphone\exceptions\ClearoutPhoneException;

try {
    /** @var ClearoutPhone $clearout */ 
    $clearout = \Yii::$app->clearoutphone;
    $phoneDetails = $clearout->getPhoneDetails('+13024401582');
    if ($phoneDetails->isValid) {
        // your magic here
    }
} catch (ClearoutPhoneException $e) {
    Yii::error($e->getMessage());
}