onesend-gmbh / onesend-php-sdk
PHP SDK for OneSend messaging service
Requires
- php: >=8.2
- nyholm/psr7: ^1.8
- php-http/discovery: ^1.0
- php-http/httplug: ^2.0
- php-http/message-factory: ^1.0
- psr/http-client-implementation: ^1.0
- psr/http-message: ^1.0 | ^2.0
- symfony/http-client: ^7.0|^6.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.54
- php-http/message: ^1.0
- php-http/mock-client: ^1.0
- phpunit/phpunit: ^11.1
README
Requirements
To use the OneSend PHP SDK the following things are required:
- A free OneSend account (to actually send messages you're required to add balance to your account)
- PHP >= 8.2
- Optional: A PSR-18 compliant HTTP Client, by default it will use the Symfony Http Client
Installation
Using Composer
The best way to install the OneSend PHP SDK is by using Composer. You can require it with the following command:
composer require onesend-gmbh/onesend-php-sdk
Usage
Initialise the SDK by passing the Api Key from your Project Dashboard.
$oneSend = new \OnesendGmbh\OnesendPhpSdk\OneSendApi('YOUR KEY HERE');
Optionally you can also pass a PSR-18 compliant Client as second argument if you want to modify timeouts/retry behavior or for Testing.
Using the SDK you can now access the following endpoints:
You can find our full documentation here.
Short Messages
Sending Short Messages (SMS)
Create Short Message reference
$shortMessage = $oneSend->shortMessages->send([ 'to' => '+4915730955123', 'from' => 'TEST', 'message' => 'THIS IS A TEST', ]);
This will create a ShortMessage Resource with a message ID $shortMessage->getId()
you can and some other information about the sent short message.
Testing
By default, the SDK will set the Symfony Http Client as HTTP Client on initialisation, meaning should you not Mock calls to the SDK, it WILL send request to our service and your tests will most likely fail.
If you don't want to (or can't) mock the calls to the SDK you can also replace the HTTP Client with a Mock Client (PHP HTTP Mock Client for example) by passing it as the second constructor argument:
$mockClient = new Http\Mock\Client(); $oneSend = new \OnesendGmbh\OnesendPhpSdk\OneSendApi('I am a Test', $mockClient);
This will replace the default Http Client and will enable you to intercept and validate requests made by the SDK as well as mock responses with the desired outcome.
To see the expected responses please consult our API docs.