Changeset 3432527
- Timestamp:
- 01/05/2026 08:27:53 AM (7 weeks ago)
- Location:
- inpipe-by-seresa/trunk
- Files:
-
- 4 edited
-
includes/core/api/class-inpipe-api-endpoints-free.php (modified) (3 diffs)
-
includes/free/premium-upgrade/class-inpipe-subscription-manager.php (modified) (3 diffs)
-
inpipe-by-seresa.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
inpipe-by-seresa/trunk/includes/core/api/class-inpipe-api-endpoints-free.php
r3406561 r3432527 340 340 * Handle subscription webhook 341 341 * 342 * @since 1.0.0 342 * Routes webhook requests to Premium plugin for processing. 343 * Authentication is done via HMAC signature verification in Premium handler, 344 * not via WordPress nonces (external webhooks don't have nonces). 345 * 346 * @since 1.0.0 343 347 * @since 1.0.1 Updated to use Status Manager for premium detection. 348 * @since 1.0.4 Simplified to use action hook pattern for Premium delegation. 344 349 * @param WP_REST_Request $request The request object. 345 350 * @return WP_REST_Response|WP_Error Response object. … … 351 356 $event_type = $request->get_header( 'X-Event-Type' ); 352 357 $payload_data = $request->get_json_params(); 353 354 // Use premium webhook handlers if available 355 if ( InPipe_Status_Manager::inpipe_is_premium_active() && class_exists( 'InPipe_Premium_Webhook_Handler' ) ) { 356 $webhook_handler = new InPipe_Premium_Webhook_Handler(); 357 $signature_valid = $webhook_handler->inpipe_premium_verify_subscription_webhook_signature( $payload, $signature ); 358 } else { 358 359 // debug log removed for production 360 361 // Check if Premium is active 362 if ( ! InPipe_Status_Manager::inpipe_is_premium_active() ) { 359 363 // debug log removed for production 360 return $this->create_response( 361 false, 362 null, 363 __( 'Webhook processing not available', 'inpipe-by-seresa' ), 364 365 return new WP_REST_Response( 366 array( 'error' => 'Premium not available' ), 364 367 503 365 368 ); 366 369 } 367 368 // Log webhook traffic for monitoring 369 inpipe_debug_log('Webhook traffic', array( 370 'signature_valid' => $signature_valid, 371 'event_type' => $event_type, 372 'timestamp' => time() 373 )); 374 375 if ( ! $signature_valid ) { 376 inpipe_debug_log( 'Webhook signature verification failed' ); 377 return $this->create_response( 378 false, 379 null, 380 __( 'Invalid webhook signature', 'inpipe-by-seresa' ), 381 401 382 ); 383 } 384 385 // Process webhook events using premium handlers 386 switch ( $event_type ) { 387 case 'subscription.activated': 388 case 'subscription.updated': 389 $result = $webhook_handler->inpipe_premium_handle_subscription_updated( $payload_data ); 390 break; 391 392 case 'subscription.cancelled': 393 $result = $webhook_handler->inpipe_premium_handle_subscription_cancelled( $payload_data ); 394 break; 395 396 case 'subscription.expired': 397 $result = $webhook_handler->inpipe_premium_handle_subscription_expired( $payload_data ); 398 break; 399 400 case 'customer.subscription.deleted': 401 $result = $webhook_handler->inpipe_premium_handle_subscription_deleted( $payload_data ); 402 break; 403 404 case 'invoice.payment_succeeded': 405 case 'invoice.payment_failed': 406 if ( InPipe_Status_Manager::inpipe_is_premium_active() && class_exists( 'InPipe_Premium_Payment_Handler' ) ) { 407 $payment_handler = new InPipe_Premium_Payment_Handler(); 408 if ( $event_type === 'invoice.payment_succeeded' ) { 409 $result = $payment_handler->inpipe_premium_handle_payment_succeeded( $payload_data ); 410 } else { 411 $result = $payment_handler->inpipe_premium_handle_payment_failed( $payload_data ); 412 } 413 } else { 414 // debug log removed for production 415 $result = new WP_Error( 'payment_handler_unavailable', 'Payment handler not available' ); 416 } 417 break; 418 419 default: 420 inpipe_debug_log( 'Unhandled webhook event type: ' . $event_type ); 421 return new WP_REST_Response( 422 array( 423 'success' => true, 424 'message' => __( 'Event type not handled', 'inpipe-by-seresa' ) 425 ), 426 200 427 ); 428 } 429 430 if ( is_wp_error( $result ) ) { 431 inpipe_debug_log( 'Webhook processing error: ' . $result->get_error_message() ); 432 return $result; 433 } 434 435 return new WP_REST_Response( 436 array( 437 'success' => true, 370 371 // Delegate to Premium via action hook 372 // Premium plugin hooks into this: add_action('inpipe_process_webhook', [$this, 'process_webhook'], 10, 3) 373 do_action( 'inpipe_process_webhook', $event_type, $payload_data, $signature ); 374 375 return new WP_REST_Response( 376 array( 377 'success' => true, 438 378 'message' => __( 'Webhook processed successfully', 'inpipe-by-seresa' ), 439 'event' => $event_type 440 ), 441 200 442 ); 443 444 } catch ( Exception $e ) { 445 inpipe_debug_log( 'Webhook processing error: ' . $e->getMessage() ); 446 return $this->create_response( 447 false, 448 null, 449 __( 'Failed to process webhook', 'inpipe-by-seresa' ), 379 'event' => $event_type, 380 ), 381 200 382 ); 383 384 } catch ( Exception $e ) { 385 // debug log removed for production 386 387 return new WP_REST_Response( 388 array( 'error' => 'Webhook processing failed' ), 450 389 500 451 390 ); … … 1755 1694 'methods' => 'POST', 1756 1695 'callback' => array( $this, 'handle_subscription_webhook' ), 1757 'permission_callback' => array( $this, 'check_admin_with_nonce' ),1696 'permission_callback' => '__return_true', // No WordPress auth - HMAC signature verifies instead 1758 1697 ), 1759 1698 ), -
inpipe-by-seresa/trunk/includes/free/premium-upgrade/class-inpipe-subscription-manager.php
r3406561 r3432527 28 28 * 29 29 * @since 1.0.0 30 * @since 1.0. 3 Updated to correctly map API response fields (metadata_plan_name → subscription_type, plan → plan_type).30 * @since 1.0.4 Updated to correctly map API response fields (plan_name → subscription_type, plan → plan_type). 31 31 * @param string $verification_code The subscription verification code. 32 32 * @return array|WP_Error Subscription data on success, WP_Error on failure. … … 199 199 200 200 // Safely extract details information from API response. 201 // API returns: data.details.plan, data.details. metadata_plan_name, data.details.status, etc.201 // API returns: data.details.plan, data.details.plan_name, data.details.status, etc. 202 202 $details_info = array(); 203 203 if ( isset( $verification_data['details'] ) && is_array( $verification_data['details'] ) ) { … … 208 208 } 209 209 210 // Extract subscription_type from metadata_plan_name (e.g., "Trial", "Pro", "Business").210 // Extract subscription_type from plan_name (e.g., "Trial", "Entry", "Premium", "Professional", "Enterprise"). 211 211 $subscription_type = 'free'; // default 212 if ( isset( $details_info[' metadata_plan_name'] ) && is_string( $details_info['metadata_plan_name'] ) ) {213 $subscription_type = sanitize_text_field( strtolower( $details_info[' metadata_plan_name'] ) );212 if ( isset( $details_info['plan_name'] ) && is_string( $details_info['plan_name'] ) ) { 213 $subscription_type = sanitize_text_field( strtolower( $details_info['plan_name'] ) ); 214 214 } 215 215 -
inpipe-by-seresa/trunk/inpipe-by-seresa.php
r3408790 r3432527 4 4 * Plugin URI: https://seresa.io/wordpress-plugin 5 5 * Description: Captures, stores, and decodes UTM parameters for enhanced results in Google Analytics, Facebook Ads, and other platforms. Integrates with the dataLayer and supports standard and encoded UTM codes. 6 * Version: 1.0. 36 * Version: 1.0.4 7 7 * Requires at least: 6.4 8 8 * Requires PHP: 8.3 -
inpipe-by-seresa/trunk/readme.txt
r3406561 r3432527 6 6 Requires PHP: 8.3 7 7 Tested up to: 6.9 8 Stable tag: 1.0. 38 Stable tag: 1.0.4 9 9 License: GPL-2.0+ 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 168 168 169 169 == Changelog == 170 171 = 1.0.4 - 2025-12-16 = 172 **Subscription Type Fix & Webhook Improvements** 173 174 = BUG FIXES = 175 * **Fixed Subscription Type Mapping**: Subscription type now correctly reads from API response 176 - Changed from `metadata_plan_name` to `plan_name` field to match actual API response 177 - Fixes issue where `subscription_type` was defaulting to "free" after premium upgrade 178 - Supported plan types: Trial, Entry, Premium, Professional, Enterprise 179 180 = IMPROVEMENTS = 181 * **Simplified Webhook Handler**: Refactored `handle_subscription_webhook()` to use action hook pattern 182 - Now delegates webhook processing to Premium plugin via `inpipe_process_webhook` action hook 183 - Cleaner separation between Free and Premium plugin responsibilities 184 - Premium plugin hooks in with: `add_action('inpipe_process_webhook', [$this, 'process_webhook'], 10, 3)` 170 185 171 186 = 1.0.3 - 2025-12-01 =
Note: See TracChangeset
for help on using the changeset viewer.