Files
opnform-host-nginx/api/app/Integrations/Handlers/GoogleSheetsIntegration.php
Chirag Chhatrala 504c7a0f2f Custom SMTP Settings (#561)
* Custom SMTP Settings

* Fix lint

* Custom SMTP add in Pricing plan

* Allow reset email settings

* improve custom SMTP using seprate abstract class

* test case for custom SMTP

* fix test case

* UI improvement

* add CASHIER_KEY in phpunit for testcase

* Attempt to fix tests

* Run pint and attempt to fix cache tests

* Fix user management tests

* Fix code linters

* Merged main & fix linting

---------

Co-authored-by: Julien Nahum <julien@nahum.net>
2024-09-24 12:16:20 +02:00

73 lines
1.7 KiB
PHP

<?php
namespace App\Integrations\Handlers;
use App\Events\Forms\FormSubmitted;
use App\Integrations\Google\Google;
use App\Models\Integration\FormIntegration;
use Exception;
use Illuminate\Support\Facades\Log;
class GoogleSheetsIntegration extends AbstractIntegrationHandler
{
protected Google $client;
public function __construct(
protected FormSubmitted $event,
protected FormIntegration $formIntegration,
protected array $integration
) {
parent::__construct($event, $formIntegration, $integration);
$this->client = new Google($formIntegration);
}
public static function getValidationRules(): array
{
return [
];
}
public static function isOAuthRequired(): bool
{
return true;
}
public static function getValidationAttributes(): array
{
return [
'oauth_id' => 'Google Account',
];
}
public function handle(): void
{
if (!$this->shouldRun()) {
return;
}
Log::debug('Creating Google Spreadsheet record', [
'spreadsheet_id' => $this->getSpreadsheetId(),
'form_id' => $this->form->id,
'form_slug' => $this->form->slug,
]);
$this->client->sheets()->submit($this->submissionData);
}
protected function getSpreadsheetId(): string
{
if (!isset($this->integrationData->spreadsheet_id)) {
throw new Exception('The spreadsheed is not instantiated');
}
return $this->integrationData->spreadsheet_id;
}
protected function shouldRun(): bool
{
return parent::shouldRun() && $this->formIntegration->oauth_id && $this->getSpreadsheetId();
}
}