Installation
composer require silici0/rdstation:dev-master
php artisan vendor:publish --provider="silici0\RDStation\RDStationServiceProvider"
php artisan migrate
Configure API Credentials
client_id and client_secret in config/rdstation.php.yourdomain.com/rdstation) in the RDStation app settings.Authenticate
yourdomain.com/rdstation to authorize the app.code and auth_key in the database.First Use Case: Create/Update a Lead
$rdstation = resolve('rdstation');
$leadData = [
'name' => 'John Doe',
'email' => 'john@example.com',
'personal_phone' => '(11) 98765-4321'
];
$rdstation->createOrUpdate($leadData);
Lead Management
createOrUpdate() with an associative array of lead attributes.
$rdstation->createOrUpdate([
'email' => 'lead@example.com',
'first_name' => 'Lead',
'last_name' => 'User',
'company_name' => 'Test Co.'
]);
$lead = $rdstation->getLeadByEmail('lead@example.com');
Event Tracking
saveEvent().
$eventData = [
'email' => 'user@example.com',
'client_tracking_id' => Cookie::get('_rdtrk'),
'traffic_source' => Cookie::get('__trf.src')
];
$rdstation->saveEvent('PURCHASE_CONVERSION', $eventData);
$utmSource = request()->input('utm_source', Cookie::get('__trf.src'));
$eventData['traffic_source'] = $utmSource;
Funnel Updates
updateFunnel() to move leads through stages (e.g., "Lead," "Opportunity").
$rdstation->updateFunnel('lead@example.com', 'OPENED_TICKET');
Webhook Handling
POST /rdstation/webhook).
Route::post('/rdstation/webhook', function (Request $request) {
$rdstation = resolve('rdstation');
$rdstation->handleWebhook($request->all());
});
Route::middleware(['rdstation.auth'])->group(function () {
Route::post('/leads', 'LeadController@store');
});
$this->app->bind('rdstation', function ($app) {
return new \silici0\RDStation\RDStation($app['config']['rdstation']);
});
foreach ($leads as $lead) {
$rdstation->createOrUpdate($lead);
}
Authentication Flow
code and auth_key must be manually authorized via the callback URL (yourdomain.com/rdstation). Forgetting this step will result in 401 Unauthorized errors.Rate Limiting
try {
$rdstation->createOrUpdate($lead);
} catch (\silici0\RDStation\Exceptions\RateLimitException $e) {
sleep(10); // Wait before retrying
$rdstation->createOrUpdate($lead);
}
Lead Email as Key
email field is required for most operations (e.g., createOrUpdate, getLeadByEmail). Missing or invalid emails will fail silently or return errors.if (!filter_var($lead['email'], FILTER_VALIDATE_EMAIL)) {
throw new \InvalidArgumentException('Invalid email provided.');
}
Webhook Verification
handleWebhook() method and ensure the webhook_secret is set in config/rdstation.php.
$rdstation->handleWebhook($request->all(), $request->header('X-Signature'));
Database Dependencies
rdstation_codes and rdstation_auth_keys tables. Skipping migrations will cause TableNotFoundException.php artisan migrate
log_level in config/rdstation.php to debug API responses.
'log_level' => 'debug', // Options: 'debug', 'info', 'error'
dd() to inspect raw responses.
$response = $rdstation->getLeadByEmail('test@example.com');
\Log::debug('RDStation Response:', $response);
rdstation_codes table for stored code values during the auth flow.Custom Fields
custom_field_1). Extend the package by adding methods to handle them.$rdstation->setCustomField('lead@example.com', 'custom_field_1', 'Value');
createOrUpdate method or add a new one in a service class.Event Hooks
$rdstation->afterCreateOrUpdate(function ($leadData) {
\Log::info('Lead created/updated:', $leadData);
// Send Slack notification, etc.
});
API Versioning
class RDStationClient {
public function __call($method, $args) {
if (method_exists($this->client, $method)) {
return $this->client->$method(...$args);
}
// Fallback or custom logic
}
}
Testing
$mock = Mockery::mock('overload:' . \silici0\RDStation\RDStation::class);
$mock->shouldReceive('createOrUpdate')->andReturn(['success' => true]);
How can I help you explore Laravel packages today?