PHP code example of ahmedghanem00 / tempnumber-api-client
1. Go to this page and download the library: Download ahmedghanem00/tempnumber-api-client 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/ */
ahmedghanem00 / tempnumber-api-client example snippets
use ahmedghanem00\TempNumberClient\Client;
$client = new Client('YOUR_API_TOKEN');
use ahmedghanem00\TempNumberClient\Enum\Country;
use ahmedghanem00\TempNumberClient\Enum\Service;
try {
# You can either use Service & Country enums as arguments or use the ids directly ( 'facebook', 'us' )
# If the activation price is higher than the given expected, the 'ExpectedPriceException' will be thrown
$newActivation = $client->requestNewActivation(Service::Facebook, Country::United_States, $expectedPrice = 2.5);
[$countryCode, $numberOnly, $formattedPhoneNumberWithCountryCode] = [
$newActivation->getPhoneNumberCountryCode(),
$newActivation->getPhoneNumberWithoutCountryCode(),
$newActivation->getFormattedPhoneNumberWithCountryCode()
];
# Will continuously polling the activation data from server until the specified condition is met.
# Otherwise, the appropriate exception will be thrown
$fulfilledActivationWithSmsMessage = $client->waitForActivationStatus($newActivation->getId(), ActivationStatus::SMS_RECEIVED, $pollingInterval = 2, $maxDuration = 100);
echo $fulfilledActivationWithSmsMessage->getReceivedSMS(); ## "Thanks for activation. Your activation code is: 5678"
echo $fulfilledActivationWithSmsMessage->getDetectedOtpCodeFromReceivedSMS(); ## "5678"
} catch (Exception $e) {
echo $e->getMessage();
}