Download the PHP package webimpian/smsniaga-php without Composer

On this page you can find all versions of the php package webimpian/smsniaga-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package smsniaga-php

SMS Niaga PHP SDK

Latest version tests PHP 8.0+

A PHP client for the SMS Niaga API. Send SMS, track delivery, check your balance, and manage sender IDs, groups and subscribers.

[!IMPORTANT] There is no sandbox, so send() sends real, paid SMS. Test with preview().

Contents

Installation

You need PHP 8.0 or later and your API token, which is in the SMS Niaga dashboard under Profile > API Token.

Laravel: register one shared client in AppServiceProvider::register(). Then type-hint SmsNiaga wherever you need it.

Sending SMS

Preview for free

preview() takes the same arguments as send(), but sends nothing and charges nothing.

More than 50 numbers

sendBulk() sends to any number of recipients, 50 per request.

If the first batch fails, nothing has been sent, so the exception is thrown. After that, failed batches are recorded in $result->failures instead, so you always know who received the message.

What send() returns

Property Description
uuid Message UUID, for the delivery report. null for a preview.
numbers, totalNumbers The recipients.
message, charCount, messagePages The final text, its length and its credits per recipient.
totalCharge, balanceAfter The cost and your remaining balance, in RM.
senderId The sender ID that was used.

Message length and cost

Each credit costs RM0.10 per recipient.

Message type First credit Each credit after
ASCII 160 characters 153 characters
Unicode 70 characters 67 characters

SmsLength counts a message the same way SMS Niaga does, without calling the API. It's useful for a live counter in a form.

Delivery reports

You can also use pending(), deliveredRecipients() and recipient($phone). Each recipient has code, receivedAt and isDelivered(), isPending() and isFailed(). Operators can take up to 48 hours to return a final status, for example when the phone is off.

Balance

Sender IDs, groups and subscribers

For update(), pass only the fields you want to change, as named arguments. The SDK fills in the rest from the current record.

Sender IDs: $sms->senderIds()

Method What it does
all() Lists every sender ID.
find($uuid) Gets one sender ID.
findByName($name) Finds a sender ID by name. Case-insensitive.
default() Gets the account's default sender ID.
create($name, $description, $isDefault) Creates a sender ID. Only the name is required.
update($uuid, name:, description:, isDefault:) Changes the fields you pass.
setDefault($uuid) Makes this sender ID the default.
delete($uuid) Deletes a sender ID that has never been used to send.

Groups: $sms->groups()

Method What it does
all() Lists every group.
find($uuid) Gets one group.
findByName($name) Finds a group by name. Case-insensitive.
create($name) Creates a group.
firstOrCreate($name) Gets the group with this name, or creates it.
update($uuid, $name) Renames a group.
delete($uuid) Deletes a group.

Subscribers: $sms->subscribers()

Method What it does
find($uuid) Gets one subscriber, with their groups.
create($phone, $name, $email, $groupUuid) Adds a subscriber, optionally to a group. Only the phone is required.
update($uuid, phone:, name:, email:) Changes the fields you pass.
delete($uuid) Deletes a subscriber.

There is no method to list every subscriber. SMS Niaga returns them all in one unpaginated response, which times out on large accounts. Keep the UUID that create() returns.

Helpers

Static helpers in Webimpian\SmsNiaga\Support. They make no API calls, so you can use them anywhere, for example in form validation.

PhoneNumber

Call Result
PhoneNumber::normalize('012-345 6789') "60123456789"
PhoneNumber::normalizeMany('0123456789, 0198765432') ["60123456789", "60198765432"]
PhoneNumber::isValid('03-1234 5678') false. Never throws.
PhoneNumber::toLocal('60123456789') "0123456789"

normalize() returns the 60… format SMS Niaga expects, or throws InvalidArgumentException:

Accepted Rejected
012-345 6789, (012) 345-6789, 012.345.6789 Letters or symbols: 0123456789abc, O123456789
+60 12-345 6789, 0060123456789, 60123456789 Landlines: 03-1234 5678
A missing leading zero: 12-345 6789 Numbers outside Malaysia: +65 9123 4567
Numbers pasted from WhatsApp or Excel Too short or too long: 012-345

DeliveryReportCode

Code Meaning
000 Delivered
111 Waiting for the operator's status
001, 016, 017 Phone is off or out of coverage
005, 054 Number doesn't exist or is invalid
069, 076, 077 Problem with the sender ID
071 Recipient has opted out

Error handling

Every SDK exception implements SmsNiagaException, so one catch can handle them all.

Exception When it's thrown
InvalidArgumentException Your input was rejected before any API call: an invalid number, an empty message, or more than 50 numbers in send().
AuthenticationException The API token is missing, wrong or revoked.
AuthorizationException The token can't act on that record.
NotFoundException The record doesn't exist.
ValidationException SMS Niaga rejected the request. errors() returns field errors when the API sends them.
RateLimitException Too many requests.
ServerException SMS Niaga had an internal error.
ConnectionException SMS Niaga couldn't be reached, or the request timed out.

Every API error extends ApiException, which has getStatusCode() and getResponseData(). Errors that SMS Niaga returns with HTTP 200 are detected too. The SDK never retries on its own, because sending twice means paying twice.

Testing your app

Give the client a Guzzle mock so your tests never send a real SMS:

In Laravel, swap it in with $this->app->instance(SmsNiaga::class, $sms).

Development

API reference: smsniaga.stoplight.io. License: MIT.


All versions of smsniaga-php with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
guzzlehttp/guzzle Version ^7.15.2|^8.0.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package webimpian/smsniaga-php contains the following files

Loading the files please wait ...