faytranevozter/zenziva-lib

Zenziva SMS Online Gateway Library

1.1.3 2022-04-27 04:39 UTC

This package is auto-updated.

Last update: 2022-11-27 05:45:45 UTC


README

Zenziva SMS Online Gateway Library based on Zenziva Documentation

Requirements

  • PHP with Curl Extension Support
  • Zenziva Account

How to use

Install with Composer

Recommended install via composer

composer require faytranevozter/zenziva-lib

Usage

All example below is placed under autoload composer

require 'vendor/autoload.php';
use Faytranevozter\Zenziva\Sms;
// your code here ...

Simple way

$sms = new Sms('faytranevozter', '123456');
// or
$sms = new Sms();
$sms->username('faytranevozter'); // chainable
$sms->password('123456'); // chainable
// send sms
$sms->send('089765432123', 'Helaw!'); // send(number, text, otp)

Default type is reguler if 3rd parameter not set.

Masking

$sms = new Sms('faytranevozter', '123456', 'masking');
$sms->send('089765432123', 'Helaw! this is masking sms');
// or
$sms = new Sms('faytranevozter', '123456');
$sms->type('masking'); // chainable
// send sms
$sms->send('089765432123', 'Helaw! this is masking sms'); // send(number, text, otp)

Default type is reguler if 3rd parameter not set.

SMS Center

$sms = new Sms('faytranevozter', '123456', 'sms_center');
$sms->subdomain('mysubdomain'); // chainable, [required for sms_center]
$sms->send('089765432123', 'Helaw! this is from sms_center');
// or
$sms = new Sms('faytranevozter', '123456');
$sms->type('sms_center'); // chainable
$sms->subdomain('mysubdomain'); // chainable, [required for sms_center]
// send sms
$sms->send('089765432123', 'Helaw! this is from sms_center'); // send(number, text, otp)

Default type is reguler if 3rd parameter not set.

OTP SMS

Zenziva now apply special treatment for SMS OTP. See #Zenziva Docs

Untuk mengirim SMS OTP, wajib menambahkan parameter type=otp

$sms = new Sms('faytranevozter', '123456', 'masking');
$sms->send('089765432123', 'Helaw! this is masking sms', TRUE);
// or
$sms = new Sms('faytranevozter', '123456');
$sms->otp(TRUE); // chainable
// send sms
$sms->send('089765432123', 'Helaw! this is masking sms'); // send(number, text, otp)

Chaining

$sms = new Sms();
$sms->username('faytranevozter')
    ->password('123456')
    ->type('masking')
    ->to('089765432123')
    ->message('Helaw!')
    ->send();

Handling Response

Checking SMS Status
$sms = new Sms('faytranevozter', '123456');
$is_send = $sms->send('089765432123', 'Helaw! this is my sms');
if ($is_send) {
    echo "Sms sent!";
} else {
    echo "Uh-oh! Failed to send sms";
}
Get Response
$sms = new Sms('faytranevozter', '123456');
$sms->send('089765432123', 'Helaw! this is my sms');
$sms->send('082341561273', 'Helaw! this is my second sms');

// get all response
print_r($sms->responses()); // return array of response

// get last response
print_r($sms->last_response()); // return last response
Get Error
$sms = new Sms('faytranevozter', '123456');
$sms->send('089765432123', 'Helaw! this is my sms');
$sms->send('082341561273', 'Helaw! this is my second sms');

// get all error
print_r($sms->errors()); // return array of error

// get last error
print_r($sms->last_error()); // return last error

Using Codeigniter Framework

Creating library Zenziva.php

use Faytranevozter\Zenziva\Sms;

class Zenziva extends Sms {
    function __construct($params=array()) {
        parent::__construct(...$params);
    }
}

Load Zenziva library from controller

...

$this->load->library('Zenziva', ['faytranevozter', '123456', 'reguler']);
$this->zenziva->send('089765432123', 'Helaw! this is my sms');

...

Credits and License

Author

Fahrur Rifai fahrur.dev
Twitter @faytranevozter

License

MIT License