ding-live / ding-php
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
- jms/serializer: ^3.22
Requires (Dev)
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^10
- rector/rector: ^0.18.13
- roave/security-advisories: dev-latest
README
The Ding PHP library provides convenient access to the Ding API from applications written in the PHP language.
SDK Installation
Composer
composer require "ding/sdk"
SDK Example Usage
SDK Example Usage
Send a code
Send an OTP code to a user's phone number.
<?php declare(strict_types=1); require 'vendor/autoload.php'; use Ding\DingSDK; use Ding\DingSDK\Models\Shared; $security = new Shared\Security(); $security->apiKey = 'YOUR_API_KEY'; $sdk = DingSDK\Ding::builder() ->setSecurity($security) ->build(); try { $request = new Shared\CreateAuthenticationRequest(); $request->appRealm = '<value>'; $request->appVersion = '<value>'; $request->callbackUrl = 'https://piercing-volcano.name'; $request->customerUuid = '26e0deca-1ec4-471f-acd6-e8efeb46fdea'; $request->deviceId = '<value>'; $request->deviceModel = '<value>'; $request->deviceType = Shared\DeviceType::Android; $request->ip = '176.157.112.67'; $request->isReturningUser = false; $request->osVersion = '<value>'; $request->phoneNumber = '+1234567890'; $request->templateId = '<value>'; $response = $sdk->otp->createAuthentication($request); if ($response->createAuthenticationResponse !== null) { // handle response } } catch (Throwable $e) { // handle exception }
Check a code
Check that a code entered by a user is valid.
<?php declare(strict_types=1); require 'vendor/autoload.php'; use Ding\DingSDK; use Ding\DingSDK\Models\Shared; $security = new Shared\Security(); $security->apiKey = 'YOUR_API_KEY'; $sdk = DingSDK\Ding::builder() ->setSecurity($security) ->build(); try { $request = new Shared\CreateCheckRequest(); $request->authenticationUuid = 'e0e7b0e9-739d-424b-922f-1c2cb48ab077'; $request->checkCode = '123456'; $request->customerUuid = '8f1196d5-806e-4b71-9b24-5f96ec052808'; $response = $sdk->otp->check($request); if ($response->createCheckResponse !== null) { // handle response } } catch (Throwable $e) { // handle exception }
Perform a retry
Perform a retry if a user has not received the code.
<?php declare(strict_types=1); require 'vendor/autoload.php'; use Ding\DingSDK; use Ding\DingSDK\Models\Shared; $security = new Shared\Security(); $security->apiKey = 'YOUR_API_KEY'; $sdk = DingSDK\Ding::builder() ->setSecurity($security) ->build(); try { $request = new Shared\RetryAuthenticationRequest(); $request->authenticationUuid = 'a74ee547-564d-487a-91df-37fb25413a91'; $request->customerUuid = '3c8b3a46-881e-4cdd-93a6-f7f238bf020a'; $response = $sdk->otp->retry($request); if ($response->retryAuthenticationResponse !== null) { // handle response } } catch (Throwable $e) { // handle exception }
Available Resources and Operations
Otp
- check - Check a code
- createAuthentication - Send a code
- feedback - Send feedback
- retry - Perform a retry
Lookup
- lookup - Perform a phone number lookup
SDK Installation
Composer
composer require "ding-live/ding-php"
Server Selection
Server Selection
Select Server by Index
You can override the default server globally by passing a server index to the server_idx: int
optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
# | Server | Variables |
---|---|---|
0 | https://api.ding.live/v1 |
None |
Override Server URL Per-Client
The default server can also be overridden globally by passing a URL to the server_url: str
optional parameter when initializing the SDK client instance. For example:
Development
Maturity
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
Contributions
While we value open-source contributions to this SDK, this library is generated programmatically. Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!