| 1 |
<?php |
| 2 |
|
| 3 |
namespace IvyForms\Services\Integrations; |
| 4 |
|
| 5 |
use IvyForms\Common\Exceptions\InvalidArgumentException; |
| 6 |
use IvyForms\Services\GoogleSheets\Hooks\InitializationHook as GoogleSheetsInitializationHook; |
| 7 |
|
| 8 |
/** |
| 9 |
* Integration Service |
| 10 |
* |
| 11 |
* Initializes the integration registry and registers default Lite integrations |
| 12 |
* |
| 13 |
* @since 1.0.0 |
| 14 |
*/ |
| 15 |
class IntegrationService |
| 16 |
{ |
| 17 |
private IntegrationRegistry $registry; |
| 18 |
private GoogleSheetsInitializationHook $googleSheetsInitializationHook; |
| 19 |
|
| 20 |
public function __construct( |
| 21 |
IntegrationRegistry $registry, |
| 22 |
GoogleSheetsInitializationHook $googleSheetsInitializationHook |
| 23 |
) { |
| 24 |
$this->registry = $registry; |
| 25 |
$this->googleSheetsInitializationHook = $googleSheetsInitializationHook; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Initialize integrations |
| 30 |
* |
| 31 |
* @return void |
| 32 |
* @throws InvalidArgumentException |
| 33 |
*/ |
| 34 |
public function init(): void |
| 35 |
{ |
| 36 |
// Register Lite integrations |
| 37 |
$this->registerLiteIntegrations(); |
| 38 |
|
| 39 |
/** |
| 40 |
* Allow Pro/addons to register their integrations |
| 41 |
* |
| 42 |
* @since 1.0.0 |
| 43 |
* |
| 44 |
* @param IntegrationRegistry $registry The integration registry instance |
| 45 |
*/ |
| 46 |
do_action('ivyforms/integrations/register', $this->registry); |
| 47 |
|
| 48 |
$this->initializeGoogleSheets(); |
| 49 |
} |
| 50 |
|
| 51 |
private function initializeGoogleSheets(): void |
| 52 |
{ |
| 53 |
$this->googleSheetsInitializationHook->initialize(); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Register default Lite integrations |
| 58 |
* |
| 59 |
* @return void |
| 60 |
* @throws InvalidArgumentException |
| 61 |
*/ |
| 62 |
private function registerLiteIntegrations(): void |
| 63 |
{ |
| 64 |
// wpDataTables Integration (Lite) |
| 65 |
$this->registry->register('wpdatatables', [ |
| 66 |
'label' => 'wpdatatables_label', |
| 67 |
'component' => 'WpDataTablesIntegrationSettings', |
| 68 |
'icon' => 'wpdatatables', |
| 69 |
'description' => 'wpdatatables_description', |
| 70 |
'category' => 'Data Management', |
| 71 |
'requiresAuth' => false, |
| 72 |
'plan' => 'lite', |
| 73 |
'settingsSchema' => [ |
| 74 |
'enabled' => [ |
| 75 |
'type' => 'boolean', |
| 76 |
'default' => false, |
| 77 |
], |
| 78 |
], |
| 79 |
]); |
| 80 |
|
| 81 |
// Amelia Booking Integration (Lite) |
| 82 |
$this->registry->register('ameliabooking', [ |
| 83 |
'label' => 'ameliabooking_label', |
| 84 |
'component' => 'AmeliaBookingIntegrationSettings', |
| 85 |
'icon' => 'ameliabooking', |
| 86 |
'description' => 'ameliabooking_description', |
| 87 |
'category' => 'Booking', |
| 88 |
'requiresAuth' => false, |
| 89 |
'hasFormSettings' => false, |
| 90 |
'plan' => 'lite', |
| 91 |
'settingsSchema' => [ |
| 92 |
'enabled' => [ |
| 93 |
'type' => 'boolean', |
| 94 |
'default' => false, |
| 95 |
], |
| 96 |
], |
| 97 |
]); |
| 98 |
|
| 99 |
// Register Pro integrations as placeholders |
| 100 |
// These will be shown with "Upgrade" button when Pro is not installed |
| 101 |
// When Pro is installed, these will be overwritten by Pro's registrar |
| 102 |
|
| 103 |
// MailChimp Integration (Pro - Essentials) |
| 104 |
$this->registry->register('mailchimp', [ |
| 105 |
'label' => 'mailchimp_label', |
| 106 |
'component' => 'MailChimpIntegrationSettings', |
| 107 |
'icon' => 'mailchimp', |
| 108 |
'description' => 'mailchimp_description', |
| 109 |
'category' => 'Email Marketing', |
| 110 |
'requiresAuth' => true, |
| 111 |
'hasGlobalSettings' => true, |
| 112 |
'plan' => 'essentials', |
| 113 |
]); |
| 114 |
|
| 115 |
// Webhooks Integration (Pro - Growth) |
| 116 |
$this->registry->register('webhooks', [ |
| 117 |
'label' => 'webhooks_label', |
| 118 |
'component' => 'WebhooksIntegrationSettings', |
| 119 |
'icon' => 'webhooks', |
| 120 |
'description' => 'webhooks_description', |
| 121 |
'category' => 'Developer Tools', |
| 122 |
'requiresAuth' => false, |
| 123 |
'hasGlobalSettings' => false, |
| 124 |
'plan' => 'growth', |
| 125 |
'learnMoreUrl' => 'https://ivyforms.com/documentation/webhooks-integration/', |
| 126 |
'settingsSchema' => [ |
| 127 |
'enabled' => [ |
| 128 |
'type' => 'boolean', |
| 129 |
'default' => false, |
| 130 |
], |
| 131 |
], |
| 132 |
]); |
| 133 |
|
| 134 |
// Zapier Integration (Pro - Growth) — hidden in Lite until ready; Pro re-registers as coming soon |
| 135 |
// $this->registry->register('zapier', [ |
| 136 |
// 'label' => 'zapier_label', |
| 137 |
// 'component' => 'ZapierIntegrationSettings', |
| 138 |
// 'icon' => 'zapier', |
| 139 |
// 'description' => 'zapier_description', |
| 140 |
// 'category' => 'Automation', |
| 141 |
// 'requiresAuth' => false, |
| 142 |
// 'hasGlobalSettings' => true, |
| 143 |
// 'plan' => 'growth', |
| 144 |
// ]); |
| 145 |
|
| 146 |
// Public API Integration (Pro - Agency) |
| 147 |
$this->registry->register('public-api', [ |
| 148 |
'label' => 'public_api_integration_label', |
| 149 |
'component' => 'PublicApiSettings', |
| 150 |
'icon' => 'public-api', |
| 151 |
'description' => 'public_api_integration_description', |
| 152 |
'category' => 'Developer Tools', |
| 153 |
'requiresAuth' => false, |
| 154 |
'hasGlobalSettings' => true, |
| 155 |
'hasFormSettings' => false, |
| 156 |
'plan' => 'agency', |
| 157 |
'learnMoreUrl' => 'https://ivyforms.com/documentation/public-rest-api/', |
| 158 |
'settingsSchema' => [ |
| 159 |
'enabled' => [ |
| 160 |
'type' => 'boolean', |
| 161 |
'default' => false, |
| 162 |
], |
| 163 |
], |
| 164 |
]); |
| 165 |
|
| 166 |
// Salesforce Integration (Pro - Agency) |
| 167 |
// $this->registry->register('salesforce', [ |
| 168 |
// 'label' => 'salesforce_label', |
| 169 |
// 'component' => 'SalesforceIntegrationSettings', |
| 170 |
// 'icon' => 'salesforce', |
| 171 |
// 'description' => 'salesforce_description', |
| 172 |
// 'category' => 'CRM', |
| 173 |
// 'requiresAuth' => true, |
| 174 |
// 'plan' => 'agency', |
| 175 |
// ]); |
| 176 |
|
| 177 |
// Google Sheets Integration (Lite) — registered last so it appears last in UI lists |
| 178 |
$this->registry->register('google_sheets', [ |
| 179 |
'label' => 'google_sheets_label', |
| 180 |
'component' => 'GoogleSheetsIntegrationSettings', |
| 181 |
'icon' => 'google_sheets', |
| 182 |
'description' => 'google_sheets_description', |
| 183 |
'category' => 'Data Management', |
| 184 |
'requiresAuth' => true, |
| 185 |
'hasGlobalSettings' => true, |
| 186 |
'plan' => 'lite', |
| 187 |
'learnMoreUrl' => 'https://ivyforms.com/documentation/integrations/google-sheets/', |
| 188 |
'settingsSchema' => [ |
| 189 |
'enabled' => [ |
| 190 |
'type' => 'boolean', |
| 191 |
'default' => false, |
| 192 |
], |
| 193 |
], |
| 194 |
]); |
| 195 |
} |
| 196 |
} |
| 197 |
|