| 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. The `section` key is the full sub-section heading; `label` is the short card badge. |
| 32 |
$category_config = [ |
| 33 |
'lms' => [ |
| 34 |
'label' => __( 'LMS', 'subscription' ), |
| 35 |
'section' => __( 'Learning Management System', 'subscription' ), |
| 36 |
'bg' => '#ede9fe', |
| 37 |
'color' => '#6d28d9', |
| 38 |
], |
| 39 |
'crm' => [ |
| 40 |
'label' => __( 'CRM', 'subscription' ), |
| 41 |
'section' => __( 'Customer Relationship Management', 'subscription' ), |
| 42 |
'bg' => '#fce7f3', |
| 43 |
'color' => '#9d174d', |
| 44 |
], |
| 45 |
'automation' => [ |
| 46 |
'label' => __( 'Automation', 'subscription' ), |
| 47 |
'section' => __( 'Automation', 'subscription' ), |
| 48 |
'bg' => '#e0f2fe', |
| 49 |
'color' => '#0369a1', |
| 50 |
], |
| 51 |
'email' => [ |
| 52 |
'label' => __( 'Email', 'subscription' ), |
| 53 |
'section' => __( 'Email Marketing', 'subscription' ), |
| 54 |
'bg' => '#dcfce7', |
| 55 |
'color' => '#166534', |
| 56 |
], |
| 57 |
'license' => [ |
| 58 |
'label' => __( 'License', 'subscription' ), |
| 59 |
'section' => __( 'License Management', 'subscription' ), |
| 60 |
'bg' => '#fef3c7', |
| 61 |
'color' => '#92400e', |
| 62 |
], |
| 63 |
]; |
| 64 |
|
| 65 |
// Group third-party integrations by category, preserving the config order above |
| 66 |
// and appending any uncategorised ones under "Other". |
| 67 |
$third_party_grouped = []; |
| 68 |
foreach ( array_keys( $category_config ) as $cat_key ) { |
| 69 |
$third_party_grouped[ $cat_key ] = []; |
| 70 |
} |
| 71 |
foreach ( $third_party as $integration ) { |
| 72 |
$cat_key = $integration['category'] ?? ''; |
| 73 |
$cat_key = isset( $category_config[ $cat_key ] ) ? $cat_key : 'other'; |
| 74 |
$third_party_grouped[ $cat_key ][] = $integration; |
| 75 |
} |
| 76 |
$third_party_grouped = array_filter( $third_party_grouped ); |
| 77 |
?> |
| 78 |
|
| 79 |
<div class="wp-subscription-admin-content list-page subscrpt-subs-list"> |
| 80 |
|
| 81 |
<!-- Page header --> |
| 82 |
<div style="margin-bottom:20px;"> |
| 83 |
<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> |
| 84 |
<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> |
| 85 |
<div style="border-top:1px dashed #d0d3d7;"></div> |
| 86 |
</div> |
| 87 |
|
| 88 |
<?php if ( ! empty( $_GET['subscrpt_installed'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?> |
| 89 |
<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> |
| 90 |
<?php endif; ?> |
| 91 |
|
| 92 |
<!-- Payment Gateways --> |
| 93 |
<div style="margin-bottom:32px;"> |
| 94 |
<div style="margin-bottom:12px;"> |
| 95 |
<h2 style="font-size:12px;font-weight:600;color:var(--wpsubs-text-muted);text-transform:uppercase;letter-spacing:0.06em;margin:0;line-height:1.4;margin-left:1px;"><?php esc_html_e( 'Payment Gateways', 'subscription' ); ?></h2> |
| 96 |
</div> |
| 97 |
<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(260px,1fr));gap:14px;"> |
| 98 |
<?php foreach ( $payment_gateways as $integration ) : ?> |
| 99 |
<?php |
| 100 |
$is_installed = ! empty( $integration['is_installed'] ); |
| 101 |
$is_active = ! empty( $integration['is_active'] ); |
| 102 |
$is_beta = ! empty( $integration['is_beta'] ); |
| 103 |
$is_pro = ! empty( $integration['is_pro'] ); |
| 104 |
$icon_url = $integration['icon_url'] ?? ''; |
| 105 |
$icon_initial = $integration['icon_initial'] ?? strtoupper( substr( $integration['title'], 0, 2 ) ); |
| 106 |
$icon_color = $integration['icon_color'] ?? '#64748b'; |
| 107 |
|
| 108 |
if ( $is_active ) { |
| 109 |
$status_dot = '#16a34a'; |
| 110 |
$status_text = __( 'Active', 'subscription' ); |
| 111 |
} elseif ( $is_installed ) { |
| 112 |
$status_dot = '#d97706'; |
| 113 |
$status_text = __( 'Inactive', 'subscription' ); |
| 114 |
} else { |
| 115 |
$status_dot = '#9ca3af'; |
| 116 |
$status_text = __( 'Not Installed', 'subscription' ); |
| 117 |
} |
| 118 |
?> |
| 119 |
<div class="wpsubs-table-card" style="padding:16px;display:flex;flex-direction:column;gap:12px;"> |
| 120 |
|
| 121 |
<!-- Header: icon + name + status --> |
| 122 |
<div style="display:flex;gap:10px;align-items:flex-start;"> |
| 123 |
<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;"> |
| 124 |
<?php if ( $icon_url ) : ?> |
| 125 |
<img src="<?php echo esc_url( $icon_url ); ?>" style="width:100%;height:100%;object-fit:contain;" alt="" /> |
| 126 |
<?php else : ?> |
| 127 |
<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> |
| 128 |
<?php endif; ?> |
| 129 |
</div> |
| 130 |
<div style="flex:1;min-width:0;"> |
| 131 |
<div style="display:flex;align-items:flex-start;justify-content:space-between;gap:6px;margin-bottom:5px;"> |
| 132 |
<span style="font-size:13px;font-weight:600;color:var(--wpsubs-text);line-height:1.3;"><?php echo esc_html( $integration['title'] ); ?></span> |
| 133 |
<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;"> |
| 134 |
<span style="width:7px;height:7px;border-radius:50%;background:<?php echo esc_attr( $status_dot ); ?>;flex-shrink:0;"></span> |
| 135 |
<?php echo esc_html( $status_text ); ?> |
| 136 |
</span> |
| 137 |
</div> |
| 138 |
<div style="display:flex;flex-wrap:wrap;gap:4px;"> |
| 139 |
<?php if ( $is_pro ) : ?> |
| 140 |
<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> |
| 141 |
<?php endif; ?> |
| 142 |
<?php if ( $is_beta ) : ?> |
| 143 |
<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> |
| 144 |
<?php endif; ?> |
| 145 |
<?php if ( ! empty( $integration['supports_recurring'] ) ) : ?> |
| 146 |
<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;"> |
| 147 |
<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> |
| 148 |
<?php esc_html_e( 'Automatic recurring', 'subscription' ); ?> |
| 149 |
</span> |
| 150 |
<?php else : ?> |
| 151 |
<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> |
| 152 |
<?php endif; ?> |
| 153 |
</div> |
| 154 |
</div> |
| 155 |
</div> |
| 156 |
|
| 157 |
<!-- Description --> |
| 158 |
<p style="font-size:13px;color:var(--wpsubs-text-muted);margin:0;line-height:1.5;"><?php echo esc_html( $integration['description'] ?? '' ); ?></p> |
| 159 |
|
| 160 |
<!-- Separator --> |
| 161 |
<div style="border-top:1px solid var(--wpsubs-border);margin:auto -16px 0;"></div> |
| 162 |
|
| 163 |
<!-- Actions --> |
| 164 |
<div style="display:flex;gap:6px;flex-wrap:wrap;"> |
| 165 |
<?php if ( $is_pro && ! defined( 'SUBSCRIPT_PRO_VERSION' ) ) : ?> |
| 166 |
<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;"> |
| 167 |
<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> |
| 168 |
<?php esc_html_e( 'WPSubscription Pro required', 'subscription' ); ?> |
| 169 |
</div> |
| 170 |
<?php else : ?> |
| 171 |
<?php |
| 172 |
foreach ( $integration['actions'] as $action ) : |
| 173 |
$is_primary = ( 'function' === $action['type'] ); |
| 174 |
$btn_class = $is_primary ? 'wpsubs-btn wpsubs-btn--primary wpsubs-btn--sm' : 'wpsubs-btn wpsubs-btn--outline wpsubs-btn--sm'; |
| 175 |
?> |
| 176 |
<?php if ( 'link' === $action['type'] ) : ?> |
| 177 |
<a href="<?php echo esc_url( $action['url'] ); ?>" class="<?php echo esc_attr( $btn_class ); ?>"><?php echo esc_html( $action['label'] ); ?></a> |
| 178 |
<?php elseif ( 'external_link' === $action['type'] ) : ?> |
| 179 |
<a href="<?php echo esc_url( $action['url'] ); ?>" target="_blank" rel="noopener noreferrer" class="<?php echo esc_attr( $btn_class ); ?>"> |
| 180 |
<?php echo esc_html( $action['label'] ); ?> |
| 181 |
<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> |
| 182 |
</a> |
| 183 |
<?php elseif ( 'function' === $action['type'] ) : ?> |
| 184 |
<button class="<?php echo esc_attr( $btn_class ); ?>" onclick="<?php echo esc_attr( $action['function'] ); ?>"><?php echo esc_html( $action['label'] ); ?></button> |
| 185 |
<?php endif; ?> |
| 186 |
<?php endforeach; ?> |
| 187 |
<?php endif; ?> |
| 188 |
</div> |
| 189 |
|
| 190 |
</div> |
| 191 |
<?php endforeach; ?> |
| 192 |
</div> |
| 193 |
</div> |
| 194 |
|
| 195 |
<!-- 3rd Party Integrations --> |
| 196 |
<?php foreach ( $third_party_grouped as $cat_key => $cat_integrations ) : ?> |
| 197 |
<div style="margin-bottom:32px;"> |
| 198 |
<div style="margin-bottom:12px;"> |
| 199 |
<h2 style="font-size:12px;font-weight:600;color:var(--wpsubs-text-muted);text-transform:uppercase;letter-spacing:0.06em;margin:0;line-height:1.4;margin-left:1px;"><?php echo esc_html( $category_config[ $cat_key ]['section'] ?? __( 'Other', 'subscription' ) ); ?></h2> |
| 200 |
</div> |
| 201 |
<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(260px,1fr));gap:14px;"> |
| 202 |
<?php foreach ( $cat_integrations as $integration ) : ?> |
| 203 |
<?php |
| 204 |
$is_active = ! empty( $integration['is_active'] ); |
| 205 |
$is_pro = ! empty( $integration['is_pro'] ); |
| 206 |
$icon_url = $integration['icon_url'] ?? ''; |
| 207 |
$icon_initial = $integration['icon_initial'] ?? strtoupper( substr( $integration['title'], 0, 2 ) ); |
| 208 |
$icon_color = $integration['icon_color'] ?? '#64748b'; |
| 209 |
$category = $integration['category'] ?? ''; |
| 210 |
$cat = $category_config[ $category ] ?? [ |
| 211 |
'label' => $category, |
| 212 |
'bg' => '#f1f5f9', |
| 213 |
'color' => '#475569', |
| 214 |
]; |
| 215 |
|
| 216 |
$status_dot = $is_active ? '#16a34a' : '#9ca3af'; |
| 217 |
$status_text = $is_active ? __( 'Active', 'subscription' ) : __( 'Not Installed', 'subscription' ); |
| 218 |
?> |
| 219 |
<div class="wpsubs-table-card" style="padding:16px;display:flex;flex-direction:column;gap:12px;"> |
| 220 |
|
| 221 |
<!-- Header: icon + name + status --> |
| 222 |
<div style="display:flex;gap:10px;align-items:flex-start;"> |
| 223 |
<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;"> |
| 224 |
<?php if ( $icon_url ) : ?> |
| 225 |
<img src="<?php echo esc_url( $icon_url ); ?>" style="width:100%;height:100%;object-fit:contain;" alt="" /> |
| 226 |
<?php else : ?> |
| 227 |
<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> |
| 228 |
<?php endif; ?> |
| 229 |
</div> |
| 230 |
<div style="flex:1;min-width:0;"> |
| 231 |
<div style="display:flex;align-items:flex-start;justify-content:space-between;gap:6px;margin-bottom:5px;"> |
| 232 |
<span style="font-size:13px;font-weight:600;color:var(--wpsubs-text);line-height:1.3;"><?php echo esc_html( $integration['title'] ); ?></span> |
| 233 |
<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;"> |
| 234 |
<span style="width:7px;height:7px;border-radius:50%;background:<?php echo esc_attr( $status_dot ); ?>;flex-shrink:0;"></span> |
| 235 |
<?php echo esc_html( $status_text ); ?> |
| 236 |
</span> |
| 237 |
</div> |
| 238 |
<?php if ( $cat['label'] || $is_pro ) : ?> |
| 239 |
<div style="display:flex;flex-wrap:wrap;gap:4px;"> |
| 240 |
<?php if ( $is_pro ) : ?> |
| 241 |
<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> |
| 242 |
<?php endif; ?> |
| 243 |
<?php if ( $cat['label'] ) : ?> |
| 244 |
<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> |
| 245 |
<?php endif; ?> |
| 246 |
</div> |
| 247 |
<?php endif; ?> |
| 248 |
</div> |
| 249 |
</div> |
| 250 |
|
| 251 |
<!-- Description --> |
| 252 |
<p style="font-size:13px;color:var(--wpsubs-text-muted);margin:0;line-height:1.5;"><?php echo esc_html( $integration['description'] ?? '' ); ?></p> |
| 253 |
|
| 254 |
<!-- Separator --> |
| 255 |
<div style="border-top:1px solid var(--wpsubs-border);margin:auto -16px 0;"></div> |
| 256 |
|
| 257 |
<!-- Actions --> |
| 258 |
<div style="display:flex;gap:6px;flex-wrap:wrap;"> |
| 259 |
<?php if ( $is_pro && ! defined( 'SUBSCRIPT_PRO_VERSION' ) ) : ?> |
| 260 |
<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;"> |
| 261 |
<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> |
| 262 |
<?php esc_html_e( 'WPSubscription Pro required', 'subscription' ); ?> |
| 263 |
</div> |
| 264 |
<?php else : ?> |
| 265 |
<?php |
| 266 |
foreach ( $integration['actions'] as $action ) : |
| 267 |
$is_primary = ( 'function' === $action['type'] ); |
| 268 |
$btn_class = $is_primary ? 'wpsubs-btn wpsubs-btn--primary wpsubs-btn--sm' : 'wpsubs-btn wpsubs-btn--outline wpsubs-btn--sm'; |
| 269 |
?> |
| 270 |
<?php if ( 'link' === $action['type'] ) : ?> |
| 271 |
<a href="<?php echo esc_url( $action['url'] ); ?>" class="<?php echo esc_attr( $btn_class ); ?>"><?php echo esc_html( $action['label'] ); ?></a> |
| 272 |
<?php elseif ( 'external_link' === $action['type'] ) : ?> |
| 273 |
<a href="<?php echo esc_url( $action['url'] ); ?>" target="_blank" rel="noopener noreferrer" class="<?php echo esc_attr( $btn_class ); ?>"> |
| 274 |
<?php echo esc_html( $action['label'] ); ?> |
| 275 |
<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> |
| 276 |
</a> |
| 277 |
<?php elseif ( 'function' === $action['type'] ) : ?> |
| 278 |
<button class="<?php echo esc_attr( $btn_class ); ?>" onclick="<?php echo esc_attr( $action['function'] ); ?>"><?php echo esc_html( $action['label'] ); ?></button> |
| 279 |
<?php endif; ?> |
| 280 |
<?php endforeach; ?> |
| 281 |
<?php endif; ?> |
| 282 |
</div> |
| 283 |
|
| 284 |
</div> |
| 285 |
<?php endforeach; ?> |
| 286 |
</div> |
| 287 |
</div> |
| 288 |
<?php endforeach; ?> |
| 289 |
|
| 290 |
</div> |
| 291 |
|