| @@ -20,9 +20,12 @@ | ||
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | public function listenerUrl($args = []) |
| 23 | 23 | { |
| 24 | - $listener = '/?fct_payment_listener=1&method=' . $this->slug; | |
| 24 | + // Must match the WebRoutes dispatch contract: it reads $_REQUEST['fluent-cart'] | |
| 25 | + // as the routed page and fires do_action('fluent_cart_action_' . $page), and | |
| 26 | + // GlobalPaymentHandler listens on 'fluent_cart_action_fct_payment_listener_ipn'. | |
| 27 | + $listener = '/?fluent-cart=fct_payment_listener_ipn&method=' . $this->slug; | |
| 25 | 28 | $data = ['listener_url' => site_url($listener)]; |
| 26 | 29 | |
| 27 | 30 | return apply_filters('fluent_cart/ipn_url_' . $this->slug, $data); |
| 28 | 31 | } |
| @@ -262,14 +265,20 @@ | ||
| 262 | 265 | return $billingInfo; |
| 263 | 266 | } |
| 264 | 267 | |
| 265 | 268 | |
| 269 | + /** | |
| 270 | + * Days in one billing cycle. Returns 0 when the interval cannot be resolved — | |
| 271 | + * neither a core interval nor one a fluent_cart/subscription_interval_in_days | |
| 272 | + * callback resolved to a positive day count. Callers must treat < 1 as | |
| 273 | + * unresolvable, never as a one-day cycle. | |
| 274 | + */ | |
| 266 | 275 | public static function getIntervalDays($interval = ''): int |
| 267 | 276 | { |
| 268 | 277 | if ($interval === 'yearly') { |
| 269 | 278 | $days = 365; |
| 270 | 279 | } elseif ($interval === 'monthly') { |
| 271 | - $days = 30; | |
| 280 | + $days = (int) gmdate('t'); // exact days in current month (handles leap year) to avoid false remaining days calculation | |
| 272 | 281 | } elseif ($interval === 'weekly') { |
| 273 | 282 | $days = 7; |
| 274 | 283 | } elseif ($interval === 'quarterly') { |
| 275 | 284 | $days = 90; |
| @@ -274,14 +283,18 @@ | ||
| 274 | 283 | } elseif ($interval === 'quarterly') { |
| 275 | 284 | $days = 90; |
| 276 | 285 | } elseif ($interval === 'half_yearly') { |
| 277 | 286 | $days = 182; |
| 287 | + } elseif ($interval === 'daily') { | |
| 288 | + $days = 1; | |
| 278 | 289 | } else { |
| 279 | - $days = 1; | |
| 290 | + $days = 0; | |
| 280 | 291 | } |
| 281 | 292 | |
| 282 | - return apply_filters('fluent_cart/subscription_interval_in_days', $days, [ | |
| 293 | + $days = (int) apply_filters('fluent_cart/subscription_interval_in_days', $days, [ | |
| 283 | 294 | 'interval' => $interval |
| 284 | 295 | ]); |
| 296 | + | |
| 297 | + return $days > 0 ? $days : 0; | |
| 285 | 298 | } |
| 286 | 299 | |
| 287 | 300 | } |