Download the PHP package salavati/sapak-sms-php without Composer
On this page you can find all versions of the php package salavati/sapak-sms-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package sapak-sms-php
Sapak SMS PHP SDK
A modern, clean, and opinionated PHP SDK for interacting with the Sapak SMS API.
This SDK is built with developers in mind, focusing on clean code principles, strong typing, and a safe, ergonomic developer experience.
Note: This is an unofficial SDK.
The official Sapak API documentation can be found at: https://docs.sapak.me/
Table of Contents
- Features
- Installation
- Quick Start: Instantiation
- Error Handling
- Usage Examples
- A. Get Account Credit
- B. Send Message (One-to-Many)
- C. Send Messages (Peer-to-Peer)
- D. Get Message Statuses (The Safe Way)
- E. Find Received Messages (Smart Date Handling)
- Testing
Features
- Clean, Modern Interface: Uses typed DTOs (Data Transfer Objects) instead of messy arrays.
- Opinionated Design: Actively prevents unsafe operations (like N+1 queries).
- Smart Date Handling: Accepts standard DateTime objects and automatically handles the complex Jalali conversion required by the API.
- Robust Error Handling: Throws custom, catchable exceptions (
ValidationException,AuthenticationException) instead of generic Guzzle errors. - Helper Methods: Provides "value-add" features, like constants for status codes (
STATUS_DELIVERED) and text helpers (getStatusText()). - Fully Tested: High test coverage to ensure reliability.
Installation
Install the package via Composer:
Quick Start: Instantiation
You only need your API key to get started.
Error Handling
This SDK abstracts all HTTP errors into specific exceptions. Always wrap your calls in a try...catch block.
Usage Examples
A. Get Account Credit
Access account information via the account() resource.
B. Send Message (One-to-Many)
Use the SendMessage DTO to prepare your request. This provides client-side validation.
C. Send Messages (Peer-to-Peer)
Create an array of SendPeerToPeer DTOs.
D. Get Message Statuses
To prevent N+1 API requests, this SDK only supports checking statuses in a batch. If you need to check only one ID, pass it as an array: getStatuses([12345]).
E. Find Received Messages (Smart Date Handling)
Pass standard DateTimeInterface objects. The SDK handles the complex Jalali conversion for you.
Note on Date Handling:
The Sapak API requires a non-standard Jalali string format (YYYY-MM-DD HH:mm:ss). Instead of forcing you to handle this, the SDK does the work. It accepts standard PHPDateTimeInterfaceobjects (Gregorian) and automatically converts them to the required Jalali format for the request. It also converts the Jalali date strings in the response back to standardDateTimeImmutableobjects.
Testing
To run the test suite, clone the repository, install dependencies, and run PHPUnit: