kevinpurwito/laravel-zenziva

Zenziva integration for Laravel

1.0.0 2021-08-11 06:58 UTC

This package is auto-updated.

Last update: 2024-04-27 19:51:05 UTC


README

Tests Code Style Psalm Latest Version on Packagist Total Downloads

Laravel Zenziva is a package that integrates Zenziva for Laravel.

Installation

You can install the package via composer:

composer require kevinpurwito/laravel-zenziva

Configuration

The vendor:publish command will publish a file named kp_zenziva.php within your laravel project config folder config/kp_zenziva.php.

Published Config File Contents

[
    'type' => strtolower(env('KP_ZENZIVA_TYPE', 'console')), // gsm or console

    'userkey' => env('KP_ZENZIVA_USERKEY'),
    
    'passkey' => env('KP_ZENZIVA_PASSKEY'),
];

Alternatively you can ignore the above publish command and add this following variables to your .env file.

KP_ZENZIVA_TYPE=console
KP_ZENZIVA_USERKEY=user
KP_ZENZIVA_PASSKEY=secret

Auto Discovery

If you're using Laravel 5.5+ you don't need to manually add the service provider or facade. This will be Auto-Discovered. For all versions of Laravel below 5.5, you must manually add the ServiceProvider & Facade to the appropriate arrays within your Laravel project config/app.php

Provider

[
    Kevinpurwito\LaravelZenziva\ZenzivaServiceProvider::class,
];

Alias / Facade

[
    'Zenziva' => Kevinpurwito\LaravelZenziva\ZenzivaFacade::class,
];

Usage

use Kevinpurwito\LaravelZenziva\ZenzivaFacade as Zenziva;

// returns the balance/credit that you have
Zenziva::getBalance();

// returns the balance/credit that you have, including the expiry date of the balance
Zenziva::balance();

// send SMS
Zenziva::sendSms('+62xxx', 'message');

// send Whatsapp message
Zenziva::sendWa('+62xxx', 'message');

// send Whatsapp file from URL, including a caption/message
Zenziva::sendWaFile('+62xxx', 'message', 'https://image.com/image.png');

// GSM only feature to send SMS OTP
Zenziva::sendOtp('+62xxx', '123xxx');

// Console only feature to send voice message
Zenziva::sendWa('+62xxx', 'message');

Accepted file types for sendWaFile() are: .doc .pdf .xls .xlsx .csv .gif .jpg .mp4 .mp3

Handling the response

use Kevinpurwito\LaravelZenziva\ZenzivaFacade as Zenziva;

// returns the balance/credit that you have
$response = Zenziva::sendWa('+62xxx', 'message');

if ($response->getStatusCode() == 201) {
    // if you want to check the response body, such as `messageId` you can do this:
    $content = json_decode($response->getBody()->getContents());
    dump($content);
//    {
//        "messageId":"157365",
//        "to":"+62xxx",
//        "status":"1",
//        "text":"Success"
//    }
}

Testing

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 kevin.purwito@gmail.com instead of using the issue tracker.

Credits

License

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

Laravel Package Boilerplate

This package was generated using the PHP Package Boilerplate by Beyond Code with some modifications inspired from PHP Package Skeleton by spatie.