| 1 |
<?php |
| 2 |
/** |
| 3 |
* Integrations Admin Page |
| 4 |
* |
| 5 |
* Displays payment gateways and third-party integrations as cards. |
| 6 |
* |
| 7 |
* @package SpringDevs\Subscription\Admin |
| 8 |
* |
| 9 |
* @var array $integrations Filtered integrations list. |
| 10 |
*/ |
| 11 |
|
| 12 |
// Exit if accessed directly. |
| 13 |
defined( 'ABSPATH' ) || exit; |
| 14 |
|
| 15 |
wp_enqueue_style( 'wp-subscription-admin-components', SUBSCRPT_ASSETS . '/css/admin-components.css', [], SUBSCRPT_VERSION ); |
| 16 |
|
| 17 |
// Split by type. |
| 18 |
$payment_gateways = array_filter( |
| 19 |
$integrations, |
| 20 |
function ( $i ) { |
| 21 |
return ( $i['type'] ?? 'payment_gateway' ) === 'payment_gateway'; |
| 22 |
} |
| 23 |
); |
| 24 |
$third_party = array_filter( |
| 25 |
$integrations, |
| 26 |
function ( $i ) { |
| 27 |
return ( $i['type'] ?? '' ) === 'third_party'; |
| 28 |
} |
| 29 |
); |
| 30 |
|
| 31 |
// Category config. |
| 32 |
$category_config = [ |
| 33 |
'lms' => [ |
| 34 |
'label' => __( 'LMS', 'subscription' ), |
| 35 |
'bg' => '#ede9fe', |
| 36 |
'color' => '#6d28d9', |
| 37 |
], |
| 38 |
'crm' => [ |
| 39 |
'label' => __( 'CRM', 'subscription' ), |
| 40 |
'bg' => '#fce7f3', |
| 41 |
'color' => '#9d174d', |
| 42 |
], |
| 43 |
'automation' => [ |
| 44 |
'label' => __( 'Automation', 'subscription' ), |
| 45 |
'bg' => '#e0f2fe', |
| 46 |
'color' => '#0369a1', |
| 47 |
], |
| 48 |
'email' => [ |
| 49 |
'label' => __( 'Email', 'subscription' ), |
| 50 |
'bg' => '#dcfce7', |
| 51 |
'color' => '#166534', |
| 52 |
], |
| 53 |
'license' => [ |
| 54 |
'label' => __( 'License', 'subscription' ), |
| 55 |
'bg' => '#fef3c7', |
| 56 |
'color' => '#92400e', |
| 57 |
], |
| 58 |
]; |
| 59 |
?> |
| 60 |
|
| 61 |
<div class="wp-subscription-admin-content list-page subscrpt-subs-list"> |
| 62 |
|
| 63 |
<!-- Page header --> |
| 64 |
<div style="margin-bottom:20px;"> |
| 65 |
<h1 style="font-size:1.375rem;font-weight:700;color:var(--wpsubs-text);margin:0 0 6px;line-height:1.2;"><?php esc_html_e( 'Integrations', 'subscription' ); ?></h1> |
| 66 |
<p style="font-size:13px;color:var(--wpsubs-text-muted);margin:0 0 12px;line-height:1.5;"><?php esc_html_e( 'Connect your subscriptions with payment gateways and third-party plugins.', 'subscription' ); ?></p> |
| 67 |
<div style="border-top:1px dashed #d0d3d7;"></div> |
| 68 |
</div> |
| 69 |
|
| 70 |
<?php if ( ! empty( $_GET['subscrpt_installed'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?> |
| 71 |
<div class="notice notice-success is-dismissible" style="margin:0 0 16px;"><p><?php esc_html_e( 'Plugin installed and activated successfully.', 'subscription' ); ?></p></div> |
| 72 |
<?php endif; ?> |
| 73 |
|
| 74 |
<!-- Payment Gateways --> |
| 75 |
<div style="margin-bottom:32px;"> |
| 76 |
<div style="margin-bottom:12px;"> |
| 77 |
<h2 style="font-size:12px;font-weight:600;color:var(--wpsubs-text-muted);text-transform:uppercase;letter-spacing:0.06em;margin:0 0 3px;line-height:1.4;margin-left:1px;"><?php esc_html_e( 'Payment Gateways', 'subscription' ); ?></h2> |
| 78 |
<p style="font-size:12px;color:var(--wpsubs-text-muted);margin:0;line-height:1.5;margin-left:1px;"><?php esc_html_e( 'Enable and configure payment methods that support recurring billing for subscription products.', 'subscription' ); ?></p> |
| 79 |
</div> |
| 80 |
<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(260px,1fr));gap:14px;"> |
| 81 |
<?php foreach ( $payment_gateways as $integration ) : ?> |
| 82 |
<?php |
| 83 |
$is_installed = ! empty( $integration['is_installed'] ); |
| 84 |
$is_active = ! empty( $integration['is_active'] ); |
| 85 |
$is_beta = ! empty( $integration['is_beta'] ); |
| 86 |
$is_pro = ! empty( $integration['is_pro'] ); |
| 87 |
$icon_url = $integration['icon_url'] ?? ''; |
| 88 |
$icon_initial = $integration['icon_initial'] ?? strtoupper( substr( $integration['title'], 0, 2 ) ); |
| 89 |
$icon_color = $integration['icon_color'] ?? '#64748b'; |
| 90 |
|
| 91 |
if ( $is_active ) { |
| 92 |
$status_dot = '#16a34a'; |
| 93 |
$status_text = __( 'Active', 'subscription' ); |
| 94 |
} elseif ( $is_installed ) { |
| 95 |
$status_dot = '#d97706'; |
| 96 |
$status_text = __( 'Inactive', 'subscription' ); |
| 97 |
} else { |
| 98 |
$status_dot = '#9ca3af'; |
| 99 |
$status_text = __( 'Not Installed', 'subscription' ); |
| 100 |
} |
| 101 |
?> |
| 102 |
<div class="wpsubs-table-card" style="padding:16px;display:flex;flex-direction:column;gap:12px;"> |
| 103 |
|
| 104 |
<!-- Header: icon + name + status --> |
| 105 |
<div style="display:flex;gap:10px;align-items:flex-start;"> |
| 106 |
<div style="width:40px;height:40px;flex-shrink:0;border-radius:8px;overflow:hidden;border:1px solid var(--wpsubs-border);background:var(--wpsubs-surface-muted);display:flex;align-items:center;justify-content:center;"> |
| 107 |
<?php if ( $icon_url ) : ?> |
| 108 |
<img src="<?php echo esc_url( $icon_url ); ?>" style="width:100%;height:100%;object-fit:contain;" alt="" /> |
| 109 |
<?php else : ?> |
| 110 |
<span style="font-size:11px;font-weight:700;color:#fff;background:<?php echo esc_attr( $icon_color ); ?>;width:100%;height:100%;display:flex;align-items:center;justify-content:center;"><?php echo esc_html( $icon_initial ); ?></span> |
| 111 |
<?php endif; ?> |
| 112 |
</div> |
| 113 |
<div style="flex:1;min-width:0;"> |
| 114 |
<div style="display:flex;align-items:flex-start;justify-content:space-between;gap:6px;margin-bottom:5px;"> |
| 115 |
<span style="font-size:13px;font-weight:600;color:var(--wpsubs-text);line-height:1.3;"><?php echo esc_html( $integration['title'] ); ?></span> |
| 116 |
<span style="display:inline-flex;align-items:center;gap:4px;font-size:11px;font-weight:500;color:<?php echo esc_attr( $status_dot ); ?>;white-space:nowrap;flex-shrink:0;"> |
| 117 |
<span style="width:7px;height:7px;border-radius:50%;background:<?php echo esc_attr( $status_dot ); ?>;flex-shrink:0;"></span> |
| 118 |
<?php echo esc_html( $status_text ); ?> |
| 119 |
</span> |
| 120 |
</div> |
| 121 |
<div style="display:flex;flex-wrap:wrap;gap:4px;"> |
| 122 |
<?php if ( $is_pro ) : ?> |
| 123 |
<span style="display:inline-flex;align-items:center;font-size:10px;font-weight:600;padding:2px 7px;border-radius:10px;background:#f5f3ff;color:#7c3aed;line-height:1.6;"><?php esc_html_e( 'Pro', 'subscription' ); ?></span> |
| 124 |
<?php endif; ?> |
| 125 |
<?php if ( $is_beta ) : ?> |
| 126 |
<span style="display:inline-flex;align-items:center;font-size:10px;font-weight:500;padding:2px 7px;border-radius:10px;background:#fff7ed;color:#c2410c;line-height:1.6;"><?php esc_html_e( 'Beta', 'subscription' ); ?></span> |
| 127 |
<?php endif; ?> |
| 128 |
<?php if ( ! empty( $integration['supports_recurring'] ) ) : ?> |
| 129 |
<span style="display:inline-flex;align-items:center;gap:3px;font-size:10px;font-weight:500;padding:2px 7px;border-radius:10px;background:#dcfce7;color:#166534;line-height:1.6;"> |
| 130 |
<svg width="10" height="10" viewBox="0 0 24 24" fill="none"><path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z" fill="#166534"/></svg> |
| 131 |
<?php esc_html_e( 'Automatic recurring', 'subscription' ); ?> |
| 132 |
</span> |
| 133 |
<?php else : ?> |
| 134 |
<span style="display:inline-flex;align-items:center;font-size:10px;font-weight:500;padding:2px 7px;border-radius:10px;background:#fff3e0;color:#c2410c;line-height:1.6;"><?php esc_html_e( 'Manual renewals only', 'subscription' ); ?></span> |
| 135 |
<?php endif; ?> |
| 136 |
</div> |
| 137 |
</div> |
| 138 |
</div> |
| 139 |
|
| 140 |
<!-- Description --> |
| 141 |
<p style="font-size:13px;color:var(--wpsubs-text-muted);margin:0;line-height:1.5;"><?php echo esc_html( $integration['description'] ?? '' ); ?></p> |
| 142 |
|
| 143 |
<!-- Separator --> |
| 144 |
<div style="border-top:1px solid var(--wpsubs-border);margin:auto -16px 0;"></div> |
| 145 |
|
| 146 |
<!-- Actions --> |
| 147 |
<div style="display:flex;gap:6px;flex-wrap:wrap;"> |
| 148 |
<?php if ( $is_pro && ! defined( 'SUBSCRIPT_PRO_VERSION' ) ) : ?> |
| 149 |
<div style="width:100%;display:flex;align-items:center;gap:6px;background:#f5f3ff;border-radius:6px;padding:7px 10px;font-size:12px;font-weight:500;color:#7c3aed;line-height:1.4;"> |
| 150 |
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="flex-shrink:0;"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg> |
| 151 |
<?php esc_html_e( 'WPSubscription Pro required', 'subscription' ); ?> |
| 152 |
</div> |
| 153 |
<?php else : ?> |
| 154 |
<?php |
| 155 |
foreach ( $integration['actions'] as $action ) : |
| 156 |
$is_primary = ( 'function' === $action['type'] ); |
| 157 |
$btn_class = $is_primary ? 'wpsubs-btn wpsubs-btn--primary wpsubs-btn--sm' : 'wpsubs-btn wpsubs-btn--outline wpsubs-btn--sm'; |
| 158 |
?> |
| 159 |
<?php if ( 'link' === $action['type'] ) : ?> |
| 160 |
<a href="<?php echo esc_url( $action['url'] ); ?>" class="<?php echo esc_attr( $btn_class ); ?>"><?php echo esc_html( $action['label'] ); ?></a> |
| 161 |
<?php elseif ( 'external_link' === $action['type'] ) : ?> |
| 162 |
<a href="<?php echo esc_url( $action['url'] ); ?>" target="_blank" rel="noopener noreferrer" class="<?php echo esc_attr( $btn_class ); ?>"> |
| 163 |
<?php echo esc_html( $action['label'] ); ?> |
| 164 |
<svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg> |
| 165 |
</a> |
| 166 |
<?php elseif ( 'function' === $action['type'] ) : ?> |
| 167 |
<button class="<?php echo esc_attr( $btn_class ); ?>" onclick="<?php echo esc_attr( $action['function'] ); ?>"><?php echo esc_html( $action['label'] ); ?></button> |
| 168 |
<?php endif; ?> |
| 169 |
<?php endforeach; ?> |
| 170 |
<?php endif; ?> |
| 171 |
</div> |
| 172 |
|
| 173 |
</div> |
| 174 |
<?php endforeach; ?> |
| 175 |
</div> |
| 176 |
</div> |
| 177 |
|
| 178 |
<!-- 3rd Party Integrations --> |
| 179 |
<?php if ( ! empty( $third_party ) ) : ?> |
| 180 |
<div style="margin-bottom:32px;"> |
| 181 |
<div style="margin-bottom:12px;"> |
| 182 |
<h2 style="font-size:12px;font-weight:600;color:var(--wpsubs-text-muted);text-transform:uppercase;letter-spacing:0.06em;margin:0 0 3px;line-height:1.4;margin-left:1px;"><?php esc_html_e( '3rd Party Integrations', 'subscription' ); ?></h2> |
| 183 |
<p style="font-size:12px;color:var(--wpsubs-text-muted);margin:0;line-height:1.5;margin-left:1px;"><?php esc_html_e( 'Connect subscription events with your LMS, CRM, automation, email, and license management tools.', 'subscription' ); ?></p> |
| 184 |
</div> |
| 185 |
<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(260px,1fr));gap:14px;"> |
| 186 |
<?php foreach ( $third_party as $integration ) : ?> |
| 187 |
<?php |
| 188 |
$is_active = ! empty( $integration['is_active'] ); |
| 189 |
$is_pro = ! empty( $integration['is_pro'] ); |
| 190 |
$icon_url = $integration['icon_url'] ?? ''; |
| 191 |
$icon_initial = $integration['icon_initial'] ?? strtoupper( substr( $integration['title'], 0, 2 ) ); |
| 192 |
$icon_color = $integration['icon_color'] ?? '#64748b'; |
| 193 |
$category = $integration['category'] ?? ''; |
| 194 |
$cat = $category_config[ $category ] ?? [ |
| 195 |
'label' => $category, |
| 196 |
'bg' => '#f1f5f9', |
| 197 |
'color' => '#475569', |
| 198 |
]; |
| 199 |
|
| 200 |
$status_dot = $is_active ? '#16a34a' : '#9ca3af'; |
| 201 |
$status_text = $is_active ? __( 'Active', 'subscription' ) : __( 'Not Installed', 'subscription' ); |
| 202 |
?> |
| 203 |
<div class="wpsubs-table-card" style="padding:16px;display:flex;flex-direction:column;gap:12px;"> |
| 204 |
|
| 205 |
<!-- Header: icon + name + status --> |
| 206 |
<div style="display:flex;gap:10px;align-items:flex-start;"> |
| 207 |
<div style="width:40px;height:40px;flex-shrink:0;border-radius:8px;overflow:hidden;border:1px solid var(--wpsubs-border);background:var(--wpsubs-surface-muted);display:flex;align-items:center;justify-content:center;"> |
| 208 |
<?php if ( $icon_url ) : ?> |
| 209 |
<img src="<?php echo esc_url( $icon_url ); ?>" style="width:100%;height:100%;object-fit:contain;" alt="" /> |
| 210 |
<?php else : ?> |
| 211 |
<span style="font-size:11px;font-weight:700;color:#fff;background:<?php echo esc_attr( $icon_color ); ?>;width:100%;height:100%;display:flex;align-items:center;justify-content:center;"><?php echo esc_html( $icon_initial ); ?></span> |
| 212 |
<?php endif; ?> |
| 213 |
</div> |
| 214 |
<div style="flex:1;min-width:0;"> |
| 215 |
<div style="display:flex;align-items:flex-start;justify-content:space-between;gap:6px;margin-bottom:5px;"> |
| 216 |
<span style="font-size:13px;font-weight:600;color:var(--wpsubs-text);line-height:1.3;"><?php echo esc_html( $integration['title'] ); ?></span> |
| 217 |
<span style="display:inline-flex;align-items:center;gap:4px;font-size:11px;font-weight:500;color:<?php echo esc_attr( $status_dot ); ?>;white-space:nowrap;flex-shrink:0;"> |
| 218 |
<span style="width:7px;height:7px;border-radius:50%;background:<?php echo esc_attr( $status_dot ); ?>;flex-shrink:0;"></span> |
| 219 |
<?php echo esc_html( $status_text ); ?> |
| 220 |
</span> |
| 221 |
</div> |
| 222 |
<?php if ( $cat['label'] || $is_pro ) : ?> |
| 223 |
<div style="display:flex;flex-wrap:wrap;gap:4px;"> |
| 224 |
<?php if ( $is_pro ) : ?> |
| 225 |
<span style="display:inline-flex;align-items:center;font-size:10px;font-weight:600;padding:2px 7px;border-radius:10px;background:#f5f3ff;color:#7c3aed;line-height:1.6;"><?php esc_html_e( 'Pro', 'subscription' ); ?></span> |
| 226 |
<?php endif; ?> |
| 227 |
<?php if ( $cat['label'] ) : ?> |
| 228 |
<span style="display:inline-flex;align-items:center;font-size:10px;font-weight:500;padding:2px 7px;border-radius:10px;background:<?php echo esc_attr( $cat['bg'] ); ?>;color:<?php echo esc_attr( $cat['color'] ); ?>;line-height:1.6;"><?php echo esc_html( $cat['label'] ); ?></span> |
| 229 |
<?php endif; ?> |
| 230 |
</div> |
| 231 |
<?php endif; ?> |
| 232 |
</div> |
| 233 |
</div> |
| 234 |
|
| 235 |
<!-- Description --> |
| 236 |
<p style="font-size:13px;color:var(--wpsubs-text-muted);margin:0;line-height:1.5;"><?php echo esc_html( $integration['description'] ?? '' ); ?></p> |
| 237 |
|
| 238 |
<!-- Separator --> |
| 239 |
<div style="border-top:1px solid var(--wpsubs-border);margin:auto -16px 0;"></div> |
| 240 |
|
| 241 |
<!-- Actions --> |
| 242 |
<div style="display:flex;gap:6px;flex-wrap:wrap;"> |
| 243 |
<?php if ( $is_pro && ! defined( 'SUBSCRIPT_PRO_VERSION' ) ) : ?> |
| 244 |
<div style="width:100%;display:flex;align-items:center;gap:6px;background:#f5f3ff;border-radius:6px;padding:7px 10px;font-size:12px;font-weight:500;color:#7c3aed;line-height:1.4;"> |
| 245 |
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="flex-shrink:0;"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg> |
| 246 |
<?php esc_html_e( 'WPSubscription Pro required', 'subscription' ); ?> |
| 247 |
</div> |
| 248 |
<?php else : ?> |
| 249 |
<?php |
| 250 |
foreach ( $integration['actions'] as $action ) : |
| 251 |
$is_primary = ( 'function' === $action['type'] ); |
| 252 |
$btn_class = $is_primary ? 'wpsubs-btn wpsubs-btn--primary wpsubs-btn--sm' : 'wpsubs-btn wpsubs-btn--outline wpsubs-btn--sm'; |
| 253 |
?> |
| 254 |
<?php if ( 'link' === $action['type'] ) : ?> |
| 255 |
<a href="<?php echo esc_url( $action['url'] ); ?>" class="<?php echo esc_attr( $btn_class ); ?>"><?php echo esc_html( $action['label'] ); ?></a> |
| 256 |
<?php elseif ( 'external_link' === $action['type'] ) : ?> |
| 257 |
<a href="<?php echo esc_url( $action['url'] ); ?>" target="_blank" rel="noopener noreferrer" class="<?php echo esc_attr( $btn_class ); ?>"> |
| 258 |
<?php echo esc_html( $action['label'] ); ?> |
| 259 |
<svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg> |
| 260 |
</a> |
| 261 |
<?php elseif ( 'function' === $action['type'] ) : ?> |
| 262 |
<button class="<?php echo esc_attr( $btn_class ); ?>" onclick="<?php echo esc_attr( $action['function'] ); ?>"><?php echo esc_html( $action['label'] ); ?></button> |
| 263 |
<?php endif; ?> |
| 264 |
<?php endforeach; ?> |
| 265 |
<?php endif; ?> |
| 266 |
</div> |
| 267 |
|
| 268 |
</div> |
| 269 |
<?php endforeach; ?> |
| 270 |
</div> |
| 271 |
</div> |
| 272 |
<?php endif; ?> |
| 273 |
|
| 274 |
</div> |
| 275 |
|