PHP code example of rstacode / otpiq

1. Go to this page and download the library: Download rstacode/otpiq library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rstacode / otpiq example snippets


return [
    'api_key' => env('OTPIQ_API_KEY', ''),
    'base_url' => env('OTPIQ_BASE_URL', 'https://api.otpiq.com/api/'),
];

use Rstacode\Otpiq\Facades\Otpiq;

$response = Otpiq::sendSms([
    'phoneNumber' => '9647501234567',
    'smsType' => 'verification',
    'verificationCode' => '123456',
    'provider' => 'auto' // Optional (default: auto)
]);

// Response:
// [
//     'message' => 'SMS task created successfully',
//     'smsId' => 'sms-1234567890',
//     'remainingCredit' => 920,
//     'provider' => 'telegram',
//     'status' => 'pending'
// ]

$response = Otpiq::sendSms([
    'phoneNumber' => '9647501234567',
    'smsType' => 'custom',
    'customMessage' => 'Special offer! 20% discount today!',
    'senderId' => 'MyStore',
    'provider' => 'sms' // Required for custom messages
]);

$status = Otpiq::trackSms('sms-1234567890');

// Response:
// [
//     'status' => 'delivered',
//     'phoneNumber' => '9647501234567',
//     'smsId' => 'sms-1234567890',
//     'cost' => 80
// ]

$projectInfo = Otpiq::getProjectInfo();

// Access project info:
echo $projectInfo['projectName']; // "My Project"
echo $projectInfo['credit']; // 1000

$senderIds = Otpiq::getSenderIds();

// Response:
// [
//     'senderIds' => [
//         [
//             'id' => 'sender-123',
//             'senderId' => 'MyBrand',
//             'status' => 'accepted',
//             'createdAt' => '2024-01-01T00:00:00.000Z'
//         ]
//     ]
// ]

use Rstacode\Otpiq\Exceptions\OtpiqApiException;

try {
    $response = Otpiq::sendSms([...]);
} catch (OtpiqApiException $e) {
    // Handle API errors
    logger()->error('OTPIQ Error: ' . $e->getMessage());

    // Access detailed errors
    if ($e->hasErrors()) {
        $errors = $e->getErrors();
    }

    // Check for insufficient credit
    if ($e->isCreditError()) {
        // Handle low credit
    }
}

Otpiq::fake([
    'info' => ['projectName' => 'Test Project', 'credit' => 5000],
    'sms' => ['smsId' => 'test-123', 'status' => 'queued']
]);
bash
   php artisan vendor:publish --provider="Rstacode\Otpiq\OtpiqServiceProvider" --tag="otpiq-config"
   
bash
./vendor/bin/phpunit tests/Unit/OtpiqServiceTest.php