| 1 |
<?php |
| 2 |
/** |
| 3 |
* Main subscription class. |
| 4 |
* |
| 5 |
* TODO: Refactor and move all subscription related logic from Helper class into this class. |
| 6 |
* |
| 7 |
* @package Subscription |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace SpringDevs\Subscription\Illuminate\Subscription; |
| 11 |
|
| 12 |
use SpringDevs\Subscription\Illuminate\Helper; |
| 13 |
use SpringDevs\Subscription\Utils\Product; |
| 14 |
use SpringDevs\Subscription\Utils\ProductFactory; |
| 15 |
use WC_Product; |
| 16 |
|
| 17 |
/** |
| 18 |
* Class Subscription |
| 19 |
* |
| 20 |
* @package Illuminate\Subscription |
| 21 |
*/ |
| 22 |
class Subscription { |
| 23 |
/** |
| 24 |
* Get WC product in subscription wrapper. |
| 25 |
* |
| 26 |
* @param WC_Product|int $product Product. |
| 27 |
* @return Product|false |
| 28 |
*/ |
| 29 |
public static function get_subs_product( $product ) { |
| 30 |
if ( ! $product instanceof WC_Product ) { |
| 31 |
$product = wc_get_product( absint( $product ) ); |
| 32 |
} |
| 33 |
|
| 34 |
return $product ? ProductFactory::load( $product ) : false; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Get subscription endpoint. |
| 39 |
* |
| 40 |
* @param string $view View type. |
| 41 |
* @return string |
| 42 |
*/ |
| 43 |
public static function get_user_endpoint( string $view = 'subs_list' ) { |
| 44 |
$is_pro = subscrpt_pro_activated(); |
| 45 |
|
| 46 |
switch ( strtolower( $view ) ) { |
| 47 |
case 'view_subs': |
| 48 |
$default_endpoint = 'subscription'; |
| 49 |
$endpoint = $is_pro ? get_option( 'wpsubs_custom_view_subscription_endpoint', $default_endpoint ) : $default_endpoint; |
| 50 |
break; |
| 51 |
|
| 52 |
case 'subs_list': |
| 53 |
default: |
| 54 |
$default_endpoint = 'subscriptions'; |
| 55 |
$endpoint = $is_pro ? get_option( 'wpsubs_custom_subscriptions_endpoint', $default_endpoint ) : $default_endpoint; |
| 56 |
break; |
| 57 |
} |
| 58 |
|
| 59 |
return untrailingslashit( $endpoint ); |
| 60 |
} |
| 61 |
} |
| 62 |
|