1. Go to this page and download the library: Download jithvar/yii2-ringcentral 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/ */
jithvar / yii2-ringcentral example snippets
'components' => [
'ringcentralFax' => [
'class' => 'ringcentral\fax\RingCentralFax',
'clientId' => 'YOUR_CLIENT_ID',
'clientSecret' => 'YOUR_CLIENT_SECRET',
'serverUrl' => 'https://platform.ringcentral.com', // Use 'https://platform.devtest.ringcentral.com' for sandbox
'redirectUrl' => 'https://your-app.com/ringcentral/callback',
'tokenRefreshCallback' => function($tokens) {
// Save new tokens to your storage
Yii::$app->cache->set('ringcentral_access_token', $tokens['access_token']);
Yii::$app->cache->set('ringcentral_refresh_token', $tokens['refresh_token']);
}
],
]
namespace app\controllers;
use Yii;
use yii\web\Controller;
class RingCentralController extends Controller
{
/**
* Initiates OAuth flow
*/
public function actionAuth()
{
// Generate a random state for CSRF protection
$state = Yii::$app->security->generateRandomString();
Yii::$app->session->set('ringcentral_state', $state);
// Get authorization URL and redirect
$authUrl = Yii::$app->ringcentralFax->getAuthorizationUrl($state);
return $this->redirect($authUrl);
}
/**
* Handles OAuth callback
*/
public function actionCallback()
{
// Verify state parameter
$state = Yii::$app->request->get('state');
$savedState = Yii::$app->session->get('ringcentral_state');
if (!$state || $state !== $savedState) {
throw new \yii\web\BadRequestHttpException('Invalid state parameter');
}
// Exchange authorization code for tokens
$code = Yii::$app->request->get('code');
try {
$tokens = Yii::$app->ringcentralFax->handleOAuthCallback($code);
// Tokens are automatically saved via tokenRefreshCallback
Yii::$app->session->setFlash('success', 'Successfully connected to RingCentral');
return $this->redirect(['site/index']);
} catch (\Exception $e) {
Yii::$app->session->setFlash('error', 'Failed to connect to RingCentral: ' . $e->getMessage());
return $this->redirect(['site/index']);
}
}
}