Skip to content

Latest commit

History

31 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

checkmobi-php

The official SDK for integrating with the CheckMobi API. CheckMobi is a service that provides affordable services like:

  • Two-factor authentication via SMS, Missed Call, and IVR
  • SMS API for marketing and transactional notifications.
  • Voice API for creating custom IVRs.

This PHP SDK makes it easy for developers to add CheckMobi's features like SMS and Voice to their PHP apps without much hassle.

Requirements

In order to use the library you need to have available one of CURL or HTTP_Request2 extension:

Using CURL

php-curl
php-openssl

Using HTTP_Request2 :

pear install HTTP_Request2

The SDK initially checks for the CURL extension and then falls back to HTTP_Request2 if necessary. You can set the transport method using the constructor's options parameter.

Installation

The SDK can be installed using Composer:

composer require checkmobi/checkmobi-php

Get started

Create the CheckMobiRest client

usecheckmobi\CheckMobiRest;
$client = newCheckMobiRest("secret key here");

In case you want to change the default behaviours of the library you can use the options array properties:

PropertyDefaultDescription
api.base_urlhttps://api.checkmobi.comAPI endpoint.
api.versionv1API endpoint version.
net.transportRequestInterface::HANDLER_DEFAULTTransport engine: RequestInterface::HANDLER_DEFAULT - will try to use CURL if available otherwise fallbacks to HTTP_Request2, RequestInterface::HANDLER_CURL will force to use CURL, if fails will trigger an exception, RequestInterface::HANDLER_HTTP2 will force HTTP_Request2 instantiation, if fails will trigger an exception.
net.timeout30Connection and request timeout in seconds.
net.ssl_verify_peertrueIndicates if the server certificate is verified or not before transmitting any data.

Example

$client = newCheckMobiRest("secret key here", [
"net.timeout" => 10, "net.ssl_verify_peer" => false
]);

Resources

The SDK is a wrapper over the REST API described here. For all properties accepted by the following methods check the documentation.

// get list of countries & flags$response = $client->GetCountriesList();
// get account details$response = $client->GetAccountDetails();
// get prefixes$response = $client->GetPrefixes();
// checking a number for being valid$response = $client->CheckNumber(array("number" => "+number_here"));
// validate a number using "Missed call method". (type can be : sms, ivr, reverse_cli)$response = $client->RequestValidation(array("type" => "reverse_cli", "number" => "+number_here"));
// verify a pin for a certain request$response = $client->VerifyPin(array("id" => "request id here", "pin" => "5659"));
// check validation status for a certain request$response = $client->ValidationStatus(array("id" => "request id here"));
// get remote config profile$response = $client->GetRemoteConfigProfile(array("number" => "+number_here", "platform" => "android"));
// send a custom sms$response = $client->SendSMS(array("to" => "+number_here", "text" => "message here"));
// get sms details$response = $client->GetSmsDetails(array("id" => "sms id here"));
// place call$params = [
"from" => "+source_number_here", "to" => "+destination_number_here", "events" => [
["action" => "speak", "text" => "Hello world", "loop" => 2, "language" => "en-US"]
]
];
$response = $client->PlaceCall($params);
// get call details$response = $client->GetCallDetails(array("id" => "call id here"));
// hangup call$response = $client->HangUpCall(array("id" => "call id here"));
// perform HLR Lookup$response = $client->HLRLookup(["number"=> "+number here"]);
// perform MNP Lookup$response = $client->MNPLookup(["number"=> "+number here"]);
// perform number verification$response = $client->VerifyLookup(["number"=> "+number here"]);

Response handling

The response it's an object of the CheckMobiResponse type which exposes the following methods:

MethodDescription
is_successboolean - returns if the response represents an error or not.
status_codeinteger - the HTTP status code received.
payloadarray or NULL - The json decoded response payload as received from the server.

Example

if($response->is_success()) {
// success print_r($response->payload());
}
else
{
// failureprint"error code: ".$response->payload()["code"]." error message: ".$response->payload()["error"];
}

Releases

Packages

Used by

Contributors

Languages