get_id(); if ( $sub_numeric <= 0 ) { return new WP_Error( 'aza_lb_bad_sub_id', 'Ungültige Subscription-ID.' ); } $api_url = rtrim( (string) get_option( 'aza_lb_api_url', 'https://api.aza-medwork.ch' ), '/' ); $wc_secret = (string) get_option( 'aza_lb_wc_secret', '' ); if ( $wc_secret === '' ) { return new WP_Error( 'aza_lb_no_secret', 'WC Provision Secret nicht konfiguriert.' ); } $order_id = 0; if ( function_exists( 'aza_lb_get_parent_order_id_from_subscription' ) ) { $order_id = (int) aza_lb_get_parent_order_id_from_subscription( $subscription ); } elseif ( method_exists( $subscription, 'get_parent_id' ) ) { $order_id = (int) $subscription->get_parent_id(); } $payload = array( 'wc_subscription_id' => $sub_numeric, 'wc_order_id' => $order_id, ); // WooCommerce Subscriptions: nächste Zahlung & Abrechnungsrhythmus if ( method_exists( $subscription, 'get_date' ) ) { $next = $subscription->get_date( 'next_payment' ); if ( is_string( $next ) && $next !== '' ) { $payload['next_payment_date'] = $next; } } if ( method_exists( $subscription, 'get_billing_period' ) ) { $payload['billing_period'] = (string) $subscription->get_billing_period(); } if ( method_exists( $subscription, 'get_billing_interval' ) ) { $payload['billing_interval'] = (int) $subscription->get_billing_interval(); } if ( method_exists( $subscription, 'get_status' ) ) { $payload['subscription_status'] = (string) $subscription->get_status(); } $url = $api_url . '/wc/subscription_period'; $response = wp_remote_post( $url, array( 'timeout' => 20, 'headers' => array( 'Content-Type' => 'application/json', 'X-WC-Secret' => $wc_secret, 'User-Agent' => 'AZA-License-Bridge-Period/1.0', ), 'body' => wp_json_encode( $payload ), ) ); if ( is_wp_error( $response ) ) { return $response; } $code = (int) wp_remote_retrieve_response_code( $response ); if ( $code >= 200 && $code < 300 ) { $data = json_decode( (string) wp_remote_retrieve_body( $response ), true ); return is_array( $data ) ? $data : array( 'ok' => true ); } return new WP_Error( 'aza_lb_period_failed', 'HTTP ' . $code ); } /** * Beispiel-Hook: nach Zahlung Perioden pushen. * Bei Bedarf Cron oder Admin-Aktion ergänzen. */ add_action( 'woocommerce_subscription_payment_complete', function ( $subscription ) { if ( function_exists( 'aza_lb_send_subscription_period' ) ) { aza_lb_send_subscription_period( $subscription ); } }, 10, 1 );