PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 2.4.0
Subscriptions for WooCommerce with Stripe Recurring Payments v2.4.0
2.4.0 2.3.0 2.2.0 2.1.0 2.0.0 1.11.2 1.11.1 1.11.0 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.6 1.9.5 trunk 1.3.0 1.3.1 1.3.2 1.4.0 All 65 releases
subscription / includes / Admin / Integrations.php

Integrations.php in Subscriptions for WooCommerce with Stripe Recurring Payments 2.4.0, at includes/Admin/Integrations.php

806 lines 28.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SpringDevs\Subscription\Admin;
4
5 // Exit if accessed directly.
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit;
8 }
9
10 /**
11 * Integrations class
12 *
13 * @package SpringDevs\Subscription\Admin
14 */
15 class Integrations {
16 /**
17 * Integrations list.
18 *
19 * @var array
20 */
21 protected $integrations = [];
22
23 /**
24 * Initialize the class
25 */
26 public function __construct() {
27 // Initialize.
28 add_action( 'init', [ $this, 'init' ], 10 );
29
30 // Admin menu (sidebar).
31 add_action( 'admin_menu', array( $this, 'register_admin_menu' ), 20 );
32
33 // WPSubscription navbar.
34 add_filter( 'subscrpt_admin_header_menu_items', [ $this, 'add_integrations_menu_item' ], 10, 2 );
35
36 // Enqueue integrations scripts.
37 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_integrations_scripts' ] );
38
39 // Integrations AJAX handler.
40 // add_action( 'admin_ajax_integrations_handler', [ $this,'integrations_handler_callback' ] );
41 // add_action( 'admin_ajax_nopriv_integrations_handler', [ $this,'integrations_handler_callback' ] );
42 }
43
44 /**
45 * Initialize the integrations.
46 */
47 public function init() {
48 // Set integrations.
49 $this->integrations = $this->get_integrations();
50 }
51
52 /**
53 * Register submenu under `subscriptions` menu.
54 *
55 * @return void
56 */
57 public function register_admin_menu() {
58 $parent_slug = 'wp-subscription';
59 add_submenu_page(
60 $parent_slug,
61 __( 'Integrations', 'subscription' ),
62 __( 'Integrations', 'subscription' ),
63 'manage_options',
64 'wp-subscription-integrations',
65 [ $this, 'render_integrations_page' ],
66 );
67 }
68
69 /**
70 * Add Integrations link to the WPSubscription admin header menu.
71 *
72 * @param array $menu_items Array of menu items.
73 * @param string $current Current active menu item slug.
74 */
75 public function add_integrations_menu_item( $menu_items, $current ) {
76 $menu_items[] = [
77 'slug' => 'wp-subscription-integrations',
78 'label' => __( 'Integrations', 'subscription' ),
79 'url' => admin_url( 'admin.php?page=wp-subscription-integrations' ),
80 ];
81 return $menu_items;
82 }
83
84 /**
85 * Enqueue scripts for integrations page.
86 */
87 public function enqueue_integrations_scripts() {
88 $screen = get_current_screen();
89 if ( ! $screen || false === strpos( $screen->id, 'wp-subscription-integrations' ) ) {
90 return;
91 }
92
93 wp_enqueue_script( 'subscrpt-integrations', SUBSCRPT_ASSETS . '/js/integration_settings.js', [ 'wp-i18n' ], SUBSCRPT_VERSION, true );
94 wp_set_script_translations( 'subscrpt-integrations', 'subscription', SUBSCRPT_PATH . '/languages' );
95
96 wp_localize_script(
97 'subscrpt-integrations',
98 'subscrptIntegrations',
99 array(
100 'nonce' => wp_create_nonce( 'subscrpt_integration_install_nonce' ),
101 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
102 )
103 );
104
105 // Browser-side filter rail. Enqueued on this hook, not in the render
106 // callback, so it always loads.
107 wp_enqueue_script( 'subscrpt-integrations-filter', SUBSCRPT_ASSETS . '/js/admin/integrations-filter.js', [], SUBSCRPT_VERSION, true );
108 }
109
110 /**
111 * Handle AJAX request for integrations.
112 */
113 public function integrations_handler_callback() {
114 check_ajax_referer( 'wp_subs_integrations_nonce', 'nonce' );
115
116 $action_callback = ! empty( $_POST['action_callback'] ) ? sanitize_text_field( wp_unslash( $_POST['action_callback'] ) ) : '';
117
118 dd( '🔽 action_callback', $action_callback );
119 }
120
121 /**
122 * Check if a payment gateway is installed and active.
123 *
124 * @param string $gateway_id Gateway ID.
125 * @param bool $partial_match Whether to allow partial match of gateway ID.
126 * @return bool
127 */
128 public static function is_gateway_installed( $gateway_id, $partial_match = false ) {
129 $installed_gateways = WC()->payment_gateways()->payment_gateways();
130
131 // Partial match check. For gateways with dynamic IDs.
132 if ( $partial_match ) {
133 foreach ( $installed_gateways as $key => $gateway ) {
134 if ( strpos( $key, $gateway_id ) !== false ) {
135 return true;
136 }
137 }
138 return false;
139 }
140
141 return isset( $installed_gateways[ $gateway_id ] );
142 }
143
144 /**
145 * Check if a payment gateway is enabled.
146 *
147 * @param string $gateway_id Gateway ID.
148 * @param bool $partial_match Whether to allow partial match of gateway ID.
149 * @return bool
150 */
151 public static function is_gateway_enabled( $gateway_id, $partial_match = false ) {
152 $installed_gateways = WC()->payment_gateways()->payment_gateways();
153
154 // Partial match check. For gateways with dynamic IDs.
155 if ( $partial_match ) {
156 foreach ( $installed_gateways as $key => $gateway ) {
157 if ( strpos( $key, $gateway_id ) !== false ) {
158 return $gateway->is_available();
159 }
160 }
161 return false;
162 }
163
164 if ( ! isset( $installed_gateways[ $gateway_id ] ) ) {
165 return false;
166 }
167 return $installed_gateways[ $gateway_id ]->is_available();
168 }
169
170
171
172 /**
173 * Check if a gateway is installed by plugin file.
174 *
175 * @param string $plugin_file Plugin file path.
176 * @return bool
177 */
178 protected function is_plugin_installed( $plugin_file ) {
179 if ( ! function_exists( 'get_plugins' ) ) {
180 require_once ABSPATH . 'wp-admin/includes/plugin.php';
181 }
182 $plugins = get_plugins();
183 return isset( $plugins[ $plugin_file ] );
184 }
185
186 /**
187 * Check if a gateway plugin is active.
188 *
189 * @param string $plugin_file Plugin file path.
190 * @return bool
191 */
192 protected function is_plugin_active( $plugin_file ) {
193 return is_plugin_active( $plugin_file );
194 }
195
196 /**
197 * Find the basename of an installed plugin from its wp.org slug.
198 *
199 * @param string $slug The wp.org plugin slug, which is also its directory.
200 * @return string The plugin basename, or an empty string when not installed.
201 */
202 protected function find_plugin_file( $slug ) {
203 if ( ! function_exists( 'get_plugins' ) ) {
204 require_once ABSPATH . 'wp-admin/includes/plugin.php';
205 }
206 foreach ( array_keys( get_plugins() ) as $plugin_file ) {
207 if ( 0 === strpos( $plugin_file, $slug . '/' ) ) {
208 return $plugin_file;
209 }
210 }
211 return '';
212 }
213
214 /**
215 * Mark a gateway card installed when its plugin is on disk, and give it an
216 * Activate action for when that plugin is inactive.
217 *
218 * Gateway cards otherwise detect installation by a class the plugin declares,
219 * which only exists while it is active, so an installed-but-inactive gateway
220 * offered "Install Now" and the install failed on the existing folder.
221 *
222 * @param array $integration The integration card.
223 * @param string $slug The wp.org plugin slug.
224 * @return array
225 */
226 protected function with_gateway_plugin_state( array $integration, $slug ) {
227 $plugin_file = $this->find_plugin_file( $slug );
228 if ( '' === $plugin_file ) {
229 return $integration;
230 }
231
232 $integration['is_installed'] = true;
233 $integration['plugin_file'] = $plugin_file;
234 $integration['actions'][] = [
235 'action' => 'activate',
236 'label' => __( 'Activate', 'subscription' ),
237 'type' => 'function',
238 'function' => "subscrptActivatePlugin(this, '" . esc_js( $plugin_file ) . "')",
239 ];
240 return $integration;
241 }
242
243 /**
244 * Check if a payment gateway is enabled.
245 *
246 * @param string $gateway_id Gateway ID.
247 */
248 public function is_payment_gateway_enabled( $gateway_id ) {
249 $gateways = WC()->payment_gateways->get_available_payment_gateways();
250 return isset( $gateways[ $gateway_id ] );
251 }
252
253 /**
254 * Get the list of integrations.
255 *
256 * @return array
257 */
258 protected function get_integrations(): array {
259 $integrations = [
260 'paypal' => [
261 'title' => 'PayPal',
262 'description' => __( 'Accept recurring subscription payments directly through PayPal.', 'subscription' ),
263 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/paypal.svg',
264 'type' => 'payment_gateway',
265 'is_installed' => 'on' === get_option( 'wp_subs_paypal_integration_enabled', 'off' ),
266 'is_active' => self::is_gateway_enabled( 'wp_subscription_paypal' ),
267 'supports_recurring' => true,
268 'actions' => [
269 // [
270 // 'action' => 'install',
271 // 'label' => 'Install Now',
272 // 'type' => 'function',
273 // 'function' => 'wpSubsInstallPaypalIntegration()',
274 // ],
275 [
276 'action' => 'settings',
277 'label' => __( 'Settings', 'subscription' ),
278 'type' => 'link',
279 'url' => admin_url( 'admin.php?page=wc-settings&tab=checkout&section=wp_subscription_paypal' ),
280 ],
281 // [
282 // 'action' => 'uninstall',
283 // 'label' => 'Uninstall',
284 // 'type' => 'function',
285 // 'function' => 'wpSubsUninstallPaypalIntegration()',
286 // 'class' => 'button button-primary wp-subs-button-danger',
287 // ],
288 ],
289 ],
290 'stripe' => [
291 'title' => 'Stripe',
292 'description' => __( 'Process subscription payments securely with Stripe.', 'subscription' ),
293 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/stripe.png',
294 'type' => 'payment_gateway',
295 'is_installed' => class_exists( 'WC_Stripe' ),
296 'is_active' => self::is_gateway_enabled( 'stripe' ),
297 'supports_recurring' => true,
298 'actions' => [
299 [
300 'action' => 'install',
301 'label' => __( 'Install Now', 'subscription' ),
302 'type' => 'function',
303 'function' => "subscrptInstallPlugin(this, 'woocommerce-gateway-stripe')",
304 ],
305 [
306 'action' => 'settings',
307 'label' => __( 'Settings', 'subscription' ),
308 'type' => 'link',
309 'url' => admin_url( 'admin.php?page=wc-settings&tab=checkout&section=stripe&panel=settings' ),
310 ],
311 ],
312 ],
313 'paddle' => [
314 'title' => 'Paddle',
315 'description' => __( 'Process subscription payments securely with Paddle.', 'subscription' ),
316 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/paddle.svg',
317 'type' => 'payment_gateway',
318 'is_installed' => class_exists( 'SmartPayWoo\Gateways\Paddle\SmartPay_Paddle' ),
319 'is_active' => self::is_gateway_enabled( 'smartpay_paddle' ),
320 'supports_recurring' => true,
321 'actions' => [
322 [
323 'action' => 'install',
324 'label' => __( 'Get Paddle', 'subscription' ),
325 'type' => 'external_link',
326 'url' => 'https://wpsmartpay.com/paddle-for-woocommerce/',
327 ],
328 [
329 'action' => 'enable',
330 'label' => __( 'Enable Gateway', 'subscription' ),
331 'type' => 'toggle_option',
332 'option_key' => 'woocommerce_enable_paddle_gateway',
333 'value' => true,
334 ],
335 [
336 'action' => 'settings',
337 'label' => __( 'Settings', 'subscription' ),
338 'type' => 'link',
339 'url' => admin_url( 'admin.php?page=wc-settings&tab=checkout&section=smartpay_paddle&from=WCADMIN_PAYMENT_SETTINGS' ),
340 ],
341 [
342 'label' => __( 'More Details', 'subscription' ),
343 'type' => 'external_link',
344 'url' => 'https://wpsmartpay.com/paddle-for-woocommerce/',
345 ],
346 ],
347 ],
348 'mollie' => [
349 'title' => 'Mollie',
350 'description' => __( 'Pay for subscriptions with Mollie Payments for WooCommerce.', 'subscription' ),
351 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/mollie.png',
352 'type' => 'payment_gateway',
353 'is_pro' => true,
354 'is_installed' => class_exists( 'Mollie\WooCommerce\Activation\ActivationModule' ),
355 'is_active' => self::is_gateway_enabled( 'mollie_wc_gateway', true ),
356 'supports_recurring' => true,
357 'actions' => [
358 [
359 'action' => 'install',
360 'label' => __( 'Install Now', 'subscription' ),
361 'type' => 'function',
362 'function' => "subscrptInstallPlugin(this, 'mollie-payments-for-woocommerce')",
363 ],
364 [
365 'action' => 'settings',
366 'label' => __( 'Settings', 'subscription' ),
367 'type' => 'link',
368 'url' => admin_url( 'admin.php?page=wc-settings&tab=mollie_settings' ),
369 ],
370 [
371 'label' => __( 'More Details', 'subscription' ),
372 'type' => 'external_link',
373 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-payment-with-mollie?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
374 ],
375 ],
376 ],
377 'razorpay' => [
378 'title' => 'Razorpay',
379 'description' => __( 'Pay for subscriptions securely with Razorpay for WooCommerce.', 'subscription' ),
380 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/razorpay.png',
381 'type' => 'payment_gateway',
382 'is_pro' => true,
383 'is_beta' => true,
384 'is_installed' => class_exists( 'WC_Razorpay' ),
385 'is_active' => self::is_gateway_enabled( 'razorpay' ),
386 'supports_recurring' => true,
387 'actions' => [
388 [
389 'action' => 'install',
390 'label' => __( 'Install Now', 'subscription' ),
391 'type' => 'function',
392 'function' => "subscrptInstallPlugin(this, 'woo-razorpay')",
393 ],
394 [
395 'action' => 'settings',
396 'label' => __( 'Settings', 'subscription' ),
397 'type' => 'link',
398 'url' => admin_url( 'admin.php?page=wc-settings&tab=checkout&section=razorpay' ),
399 ],
400 [
401 'label' => __( 'More Details', 'subscription' ),
402 'type' => 'external_link',
403 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-payment-with-razorpay?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
404 ],
405 ],
406 ],
407 'xendit' => [
408 'title' => 'Xendit',
409 'description' => __( 'Pay for subscriptions securely with Xendit for WooCommerce.', 'subscription' ),
410 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/xendit.png',
411 'type' => 'payment_gateway',
412 'is_pro' => true,
413 'is_beta' => true,
414 'is_installed' => class_exists( 'WC_Xendit_CC' ),
415 'is_active' => self::is_gateway_enabled( 'xendit' ),
416 'supports_recurring' => true,
417 'actions' => [
418 [
419 'action' => 'install',
420 'label' => __( 'Install Now', 'subscription' ),
421 'type' => 'function',
422 'function' => "subscrptInstallPlugin(this, 'woo-xendit-virtual-accounts')",
423 ],
424 [
425 'action' => 'settings',
426 'label' => __( 'Settings', 'subscription' ),
427 'type' => 'link',
428 'url' => admin_url( 'admin.php?page=wc-settings&tab=checkout&section=xendit_gateway' ),
429 ],
430 [
431 'label' => __( 'More Details', 'subscription' ),
432 'type' => 'external_link',
433 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-payment-with-xendit?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
434 ],
435 ],
436 ],
437 ];
438
439 $integrations['stripe'] = $this->with_gateway_plugin_state( $integrations['stripe'], 'woocommerce-gateway-stripe' );
440 $integrations['mollie'] = $this->with_gateway_plugin_state( $integrations['mollie'], 'mollie-payments-for-woocommerce' );
441 $integrations['razorpay'] = $this->with_gateway_plugin_state( $integrations['razorpay'], 'woo-razorpay' );
442 $integrations['xendit'] = $this->with_gateway_plugin_state( $integrations['xendit'], 'woo-xendit-virtual-accounts' );
443
444 // Third-party integrations (requires Pro plugin to function).
445 $third_party = [
446 // LMS.
447 'tutor_lms' => [
448 'title' => 'Tutor LMS',
449 'description' => __( 'Restrict course access based on subscription status. Enroll and unenroll students automatically.', 'subscription' ),
450 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/tutor-lms.jpeg',
451 'type' => 'third_party',
452 'is_pro' => true,
453 'category' => 'lms',
454 'is_installed' => $this->is_plugin_installed( 'tutor/tutor.php' ),
455 'is_active' => is_plugin_active( 'tutor/tutor.php' ) && class_exists( 'TUTOR\Tutor' ),
456 'actions' => [
457 [
458 'action' => 'install',
459 'label' => __( 'Install Now', 'subscription' ),
460 'type' => 'function',
461 'function' => "subscrptInstallPlugin(this, 'tutor')",
462 ],
463 [
464 'action' => 'activate',
465 'label' => __( 'Activate', 'subscription' ),
466 'type' => 'function',
467 'function' => "subscrptActivatePlugin(this, 'tutor/tutor.php')",
468 ],
469 [
470 'label' => __( 'Learn More', 'subscription' ),
471 'type' => 'external_link',
472 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-tutor-lms?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
473 ],
474 ],
475 ],
476 'learnpress' => [
477 'title' => 'LearnPress',
478 'description' => __( 'Connect subscriptions with LearnPress courses. Enroll users automatically when subscriptions are active.', 'subscription' ),
479 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/learnpress.png',
480 'type' => 'third_party',
481 'is_pro' => true,
482 'category' => 'lms',
483 'is_installed' => $this->is_plugin_installed( 'learnpress/learnpress.php' ),
484 'is_active' => is_plugin_active( 'learnpress/learnpress.php' ) && class_exists( 'LearnPress' ),
485 'actions' => [
486 [
487 'action' => 'install',
488 'label' => __( 'Install Now', 'subscription' ),
489 'type' => 'function',
490 'function' => "subscrptInstallPlugin(this, 'learnpress')",
491 ],
492 [
493 'action' => 'activate',
494 'label' => __( 'Activate', 'subscription' ),
495 'type' => 'function',
496 'function' => "subscrptActivatePlugin(this, 'learnpress/learnpress.php')",
497 ],
498 [
499 'label' => __( 'Learn More', 'subscription' ),
500 'type' => 'external_link',
501 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-learnpress-lms?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
502 ],
503 ],
504 ],
505 'learndash' => [
506 'title' => 'LearnDash',
507 'description' => __( 'Sync subscription status with LearnDash group enrollment and course access.', 'subscription' ),
508 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/learndash.jpeg',
509 'type' => 'third_party',
510 'is_pro' => true,
511 'category' => 'lms',
512 'is_installed' => $this->is_plugin_installed( 'sfwd-lms/sfwd_lms.php' ),
513 'is_active' => is_plugin_active( 'sfwd-lms/sfwd_lms.php' ) && class_exists( 'LearnDash\Core\App' ),
514 'actions' => [
515 [
516 'action' => 'install',
517 'label' => __( 'Get LearnDash', 'subscription' ),
518 'type' => 'external_link',
519 'url' => 'https://www.learndash.com/',
520 ],
521 [
522 'action' => 'activate',
523 'label' => __( 'Activate', 'subscription' ),
524 'type' => 'function',
525 'function' => "subscrptActivatePlugin(this, 'sfwd-lms/sfwd_lms.php')",
526 ],
527 [
528 'label' => __( 'Learn More', 'subscription' ),
529 'type' => 'external_link',
530 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-learndash-lms?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
531 ],
532 ],
533 ],
534 // CRM.
535 'fluentcrm' => [
536 'title' => 'FluentCRM',
537 'description' => __( 'Trigger email sequences and manage contacts based on subscription events and status changes.', 'subscription' ),
538 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/fluentcrm.png',
539 'type' => 'third_party',
540 'is_pro' => true,
541 'category' => 'crm',
542 'is_installed' => $this->is_plugin_installed( 'fluent-crm/fluent-crm.php' ),
543 'is_active' => class_exists( 'FluentCrm\App\Services\Funnel\BaseTrigger' ),
544 'actions' => [
545 [
546 'action' => 'install',
547 'label' => __( 'Install Now', 'subscription' ),
548 'type' => 'function',
549 'function' => "subscrptInstallPlugin(this, 'fluent-crm')",
550 ],
551 [
552 'action' => 'activate',
553 'label' => __( 'Activate', 'subscription' ),
554 'type' => 'function',
555 'function' => "subscrptActivatePlugin(this, 'fluent-crm/fluent-crm.php')",
556 ],
557 [
558 'label' => __( 'Learn More', 'subscription' ),
559 'type' => 'external_link',
560 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-fluent-crm?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
561 ],
562 ],
563 ],
564 // Automation.
565 'automatorwp' => [
566 'title' => 'AutomatorWP',
567 'description' => __( 'Build powerful automations triggered by subscription events without writing any code.', 'subscription' ),
568 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/automatorwp.png',
569 'type' => 'third_party',
570 'is_pro' => true,
571 'category' => 'automation',
572 'is_installed' => $this->is_plugin_installed( 'automatorwp/automatorwp.php' ),
573 'is_active' => is_plugin_active( 'automatorwp/automatorwp.php' ) && class_exists( 'AutomatorWP' ),
574 'actions' => [
575 [
576 'action' => 'install',
577 'label' => __( 'Install Now', 'subscription' ),
578 'type' => 'function',
579 'function' => "subscrptInstallPlugin(this, 'automatorwp')",
580 ],
581 [
582 'action' => 'activate',
583 'label' => __( 'Activate', 'subscription' ),
584 'type' => 'function',
585 'function' => "subscrptActivatePlugin(this, 'automatorwp/automatorwp.php')",
586 ],
587 // [
588 // 'label' => __( 'Learn More', 'subscription' ),
589 // 'type' => 'external_link',
590 // 'url' => 'https://docs.wpsubscription.co/en/',
591 // ],
592 ],
593 ],
594 'wpfusion' => [
595 'title' => 'WP Fusion',
596 'description' => __( 'Sync subscription data with your CRM and marketing platforms through WP Fusion.', 'subscription' ),
597 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/wp-fusion.png',
598 'type' => 'third_party',
599 'is_pro' => true,
600 'category' => 'automation',
601 'is_installed' => $this->is_plugin_installed( 'wp-fusion/wp-fusion.php' ) || class_exists( 'WPF_Integrations_Base' ),
602 'is_active' => class_exists( 'WPF_Integrations_Base' ),
603 'actions' => [
604 [
605 'action' => 'install',
606 'label' => __( 'Get WP Fusion', 'subscription' ),
607 'type' => 'external_link',
608 'url' => 'https://wpfusion.com/',
609 ],
610 [
611 'action' => 'activate',
612 'label' => __( 'Activate', 'subscription' ),
613 'type' => 'function',
614 'function' => "subscrptActivatePlugin(this, 'wp-fusion/wp-fusion.php')",
615 ],
616 // [
617 // 'label' => __( 'Learn More', 'subscription' ),
618 // 'type' => 'external_link',
619 // 'url' => 'https://docs.wpsubscription.co/en/',
620 // ],
621 ],
622 ],
623 // Email Marketing.
624 'mailpoet' => [
625 'title' => 'MailPoet',
626 'description' => __( 'Add subscribers to MailPoet lists and trigger email automations based on subscription lifecycle events.', 'subscription' ),
627 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/mailpoet.png',
628 'type' => 'third_party',
629 'is_pro' => true,
630 'category' => 'email',
631 'is_installed' => $this->is_plugin_installed( 'mailpoet/mailpoet.php' ) || is_plugin_active( 'mailpoet-premium/mailpoet-premium.php' ),
632 'is_active' => is_plugin_active( 'mailpoet/mailpoet.php' ) || is_plugin_active( 'mailpoet-premium/mailpoet-premium.php' ),
633 'actions' => [
634 [
635 'action' => 'install',
636 'label' => __( 'Install Now', 'subscription' ),
637 'type' => 'function',
638 'function' => "subscrptInstallPlugin(this, 'mailpoet')",
639 ],
640 [
641 'action' => 'activate',
642 'label' => __( 'Activate', 'subscription' ),
643 'type' => 'function',
644 'function' => "subscrptActivatePlugin(this, 'mailpoet/mailpoet.php')",
645 ],
646 [
647 'label' => __( 'Learn More', 'subscription' ),
648 'type' => 'external_link',
649 'url' => 'https://docs.wpsubscription.co/en/wpsubscription-mailpoet?utm_source=plugin&utm_medium=admin&utm_campaign=docs',
650 ],
651 ],
652 ],
653 // License Management.
654 'wp_soft_lic' => [
655 'title' => 'WP Software License',
656 'description' => __( 'Issue and validate software licenses for subscription-based digital products.', 'subscription' ),
657 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/wp-software-license.png',
658 'type' => 'third_party',
659 'is_pro' => true,
660 'category' => 'license',
661 'is_installed' => $this->is_plugin_installed( 'software-license/software-license.php' ),
662 'is_active' => is_plugin_active( 'software-license/software-license.php' ) && class_exists( 'WOO_SL' ),
663 'actions' => [
664 [
665 'action' => 'install',
666 'label' => __( 'Get Plugin', 'subscription' ),
667 'type' => 'external_link',
668 'url' => 'https://wpsoftwarelicense.com/',
669 ],
670 [
671 'action' => 'activate',
672 'label' => __( 'Activate', 'subscription' ),
673 'type' => 'function',
674 'function' => "subscrptActivatePlugin(this, 'software-license/software-license.php')",
675 ],
676 // [
677 // 'label' => __( 'Learn More', 'subscription' ),
678 // 'type' => 'external_link',
679 // 'url' => 'https://docs.wpsubscription.co/en/',
680 // ],
681 ],
682 ],
683 'license_mgr' => [
684 'title' => 'License Manager for WooCommerce',
685 'description' => __( 'Generate and manage software license keys that are automatically tied to active subscriptions.', 'subscription' ),
686 'icon_url' => SUBSCRPT_ASSETS . '/images/integrations/license-manager.png',
687 'type' => 'third_party',
688 'is_pro' => true,
689 'category' => 'license',
690 'is_installed' => $this->is_plugin_installed( 'license-manager-for-woocommerce/license-manager-for-woocommerce.php' ),
691 'is_active' => is_plugin_active( 'license-manager-for-woocommerce/license-manager-for-woocommerce.php' ) && class_exists( 'LicenseManagerForWooCommerce\Models\Resources\License' ),
692 'actions' => [
693 [
694 'action' => 'install',
695 'label' => __( 'Install Now', 'subscription' ),
696 'type' => 'function',
697 'function' => "subscrptInstallPlugin(this, 'license-manager-for-woocommerce')",
698 ],
699 [
700 'action' => 'activate',
701 'label' => __( 'Activate', 'subscription' ),
702 'type' => 'function',
703 'function' => "subscrptActivatePlugin(this, 'license-manager-for-woocommerce/license-manager-for-woocommerce.php')",
704 ],
705 // [
706 // 'label' => __( 'Learn More', 'subscription' ),
707 // 'type' => 'external_link',
708 // 'url' => 'https://docs.wpsubscription.co/en/',
709 // ],
710 ],
711 ],
712 ];
713 $integrations = array_merge( $integrations, $third_party );
714
715 // Add more integrations as needed.
716 $integrations = apply_filters( 'wpsubs_integrations', $integrations );
717
718 return $integrations;
719 }
720
721 /**
722 * Filter actions.
723 *
724 * @param array $integrations Integrations array.
725 */
726 protected function filter_integration_actions( array $integrations ): array {
727 $cleaned_integrations = [];
728
729 foreach ( $integrations as $integration ) {
730 $is_installed = $integration['is_installed'] ?? false;
731 $is_active = $integration['is_active'] ?? false;
732
733 // A gateway card is "active" when its gateway is enabled, which is not
734 // the same as its plugin being active; read the plugin itself.
735 $plugin_file = $integration['plugin_file'] ?? '';
736 $plugin_active = '' !== $plugin_file ? is_plugin_active( $plugin_file ) : $is_active;
737
738 $cleaned_actions = [];
739 $shown_install_url = null;
740
741 foreach ( $integration['actions'] as $integration_action ) {
742 $action_tag = $integration_action['action'] ?? null;
743
744 if ( 'install' === $action_tag ) {
745 if ( ! $is_installed ) {
746 $cleaned_actions[] = $integration_action;
747 $shown_install_url = $integration_action['url'] ?? null;
748 }
749 continue;
750 }
751 if ( 'uninstall' === $action_tag ) {
752 if ( $is_installed ) {
753 $cleaned_actions[] = $integration_action;
754 }
755 continue;
756 }
757 if ( 'activate' === $action_tag ) {
758 if ( $is_installed && ! $plugin_active ) {
759 $cleaned_actions[] = $integration_action;
760 }
761 continue;
762 }
763 if ( 'enable' === $action_tag ) {
764 if ( $is_installed && ! $is_active ) {
765 $cleaned_actions[] = $integration_action;
766 }
767 continue;
768 }
769 if ( 'settings' === $action_tag ) {
770 if ( $is_installed && ( '' === $plugin_file || $plugin_active ) ) {
771 $cleaned_actions[] = $integration_action;
772 }
773 continue;
774 }
775
776 // Default. Skip a "More Details"-style link that just repeats the
777 // install/"Get X" link already shown (e.g. Paddle), so the card
778 // does not carry the same URL twice.
779 if ( null !== $shown_install_url && ( $integration_action['url'] ?? null ) === $shown_install_url ) {
780 continue;
781 }
782 $cleaned_actions[] = $integration_action;
783 }
784
785 // Overwrite.
786 $integration['actions'] = $cleaned_actions;
787 $cleaned_integrations[] = $integration;
788 }
789
790 return $cleaned_integrations;
791 }
792
793 /**
794 * Render the Integrations admin page.
795 */
796 public function render_integrations_page() {
797 $integrations = $this->integrations;
798 $integrations = $this->filter_integration_actions( $integrations );
799
800 $menu = new \SpringDevs\Subscription\Admin\Menu();
801 $menu->render_admin_header( __( 'Integrations', 'subscription' ) );
802 include 'views/integrations.php';
803 $menu->render_admin_footer();
804 }
805 }
806