iTexMo API client for PHP.

v0.2.4 2021-01-15 01:57 UTC

This package is auto-updated.

Last update: 2024-10-15 10:14:18 UTC


README

Latest Stable Version Total Downloads License

iTexMo API client for PHP.

Requirements

To use the client library you'll need to have created an iTexmo account.

Installation

You can install the package via composer:

composer require creatvstudio/itexmo

Usage

use \CreatvStudio\Itexmo\Itexmo::class;

$itexmo = new Itexmo($apiCode);

// Send with our expressive API
$itexmo->to('09171234567')->content('Hello fellow humans!')->send();

// or just use a plain array
$itexmo->send([
    'to' => '09171234567',
    'content' => 'Hello fellow humans!',
]);

// Custom Sender ID
$itexmo->sender('MY-SENDER')->send();

Laravel

Add ItexmoServiceProvider to your config.

# config/app.php

'providers' => [
    ...

    /*
     * Package Service Providers...
     */

    ...

    CreatvStudio\Itexmo\ItexmoServiceProvider::class,
]

Add your Itexmo credentials to config/services.php and .env file.

# config/services.php

...

'ses' => [
    'key' => env('AWS_ACCESS_KEY_ID'),
    'secret' => env('AWS_SECRET_ACCESS_KEY'),
    'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
],

'itexmo' => [
    'code' => env('ITEXTMO_CODE'),
    'password' => env('ITEXMO_PASSWORD'),
    'sender_id' => env('ITEXMO_SENDER_ID'),
]

If you want to use the Itexmo Facade you can also add the alias to your config.

# config/app.php

'aliases' => [
    ...

    'Itexmo' => CreatvStudio\Itexmo\Facades\Itexmo::class,

]

Now you can just use the Facade to send SMS. Your API Code and API Password will be automatically injected to the Itexmo object.

Itexmo::to('09171234567')->content('Hello fellow humans!')->send();

Dependency Injection

You can also use Laravel's dependecy injection to your controllers or commands.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use CreatvStudio\Itexmo\Itexmo;

class SmsController extends Controller
{
    /**
     * Send an sms message
     *
     * @param  Request  $request
     * @param  Itexmo   $itexmo
     * @return Response
     */
    public function store(Request $request, Itexmo $itexmo)
    {
        $itexmo->to($request->to)
            ->content($request->content)
            ->send();

        //
    }
}

Error Codes

Testing

You need your Itexmo credentials to test the API. For this you have to create a phpunit.xml file. You can do this by copying the phpunit.xml.dist.

cp phpunit.xml.dist phpunit.xml

And replace the ITEXMO env variables with your credentials.

...

<php>
    <env name="ITEXMO_CODE" value="MY-CODE" />
    <env name="ITEXMO_PASSWORD" value="MY-PASSWORD" />
    <env name="ITEXMO_SENDER_ID" value="MY-SENDER" />
    <env name="TEST_SMS_RECEIVER" value="09171234567" />
</php>

...

To start the test.

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email jeff@creatvstudio.ph instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

PHP Package Boilerplate

This package was generated using the PHP Package Boilerplate.