WC_QuickPay_Subscription

WC_QuickPay_Subscription class.

Defined (1)

The class is defined in the following location(s).

/classes/woocommerce-quickpay-subscription.php  
  1. class WC_QuickPay_Subscription { 
  2. /** 
  3. * Gets a parent order of a subscription 
  4. * @param [type] $order [description] 
  5. * @return [type] [description] 
  6. */ 
  7. public static function get_parent_order( $order ) { 
  8. return wcs_get_subscriptions_for_renewal_order( $order ); 
  9.  
  10. /** 
  11. * Returns the transaction ID of the parent subscription. 
  12. * This ID is used to make all future renewal orders. 
  13. * @param [type] $order [description] 
  14. * @return [type] [description] 
  15. */ 
  16. public static function get_initial_subscription_transaction_id( $order ) { 
  17. $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(); 
  18. // Lets check if the current order IS the parent order. If so, return the subscription ID from current order. 
  19. $is_subscription = wcs_is_subscription( $order_id ); 
  20. if( $is_subscription ) { 
  21. $original_order = new WC_QuickPay_Order( $order->post->post_parent ); 
  22. return $original_order->get_transaction_id(); 
  23. }  
  24. else if( self::is_renewal( $order ) ) { 
  25. $subscriptions = self::get_parent_order( $order ); 
  26. $subscription = end( $subscriptions ); 
  27. $original_order = new WC_QuickPay_Order( $subscription->post->post_parent ); 
  28. return $original_order->get_transaction_id(); 
  29.  
  30. // Nothing found 
  31. return NULL; 
  32.  
  33. /** 
  34. * process_recurring_response function. 
  35. * Process a recurring response 
  36. * @access public static 
  37. * @param object $recurring_response 
  38. * @param WC_Order $order 
  39. * @return void 
  40. */ 
  41. public static function process_recurring_response( $recurring_response, $order ) 
  42. // Set transaction order ID 
  43. $order->set_transaction_order_id($recurring_response->order_id); 
  44.  
  45. // Complete payment 
  46. $order->payment_complete( $recurring_response->id ); 
  47.  
  48. $autocomplete_renewal_orders = WC_QP()->s('subscription_autocomplete_renewal_orders'); 
  49.  
  50. if (WC_QuickPay_Helper::option_is_enabled($autocomplete_renewal_orders)) { 
  51. $order->update_status( 'completed', __( 'Automatically completing order status due to succesful recurring payment', 'woo-quickpay' ), false ); 
  52.  
  53. /** 
  54. * Checks if a subscription is up for renewal. 
  55. * Ensures backwards compatability. 
  56. * @access public static 
  57. * @param [WC_QuickPay_Order] $order [description] 
  58. * @return boolean 
  59. */ 
  60. public static function is_renewal( $order ) { 
  61. if (function_exists('wcs_order_contains_renewal')) { 
  62. return wcs_order_contains_renewal( $order ); 
  63.  
  64. return FALSE; 
  65.  
  66. /** 
  67. * Checks if Woocommerce Subscriptions is enabled or not 
  68. * @access public static 
  69. * @return string 
  70. */ 
  71. public static function plugin_is_active() { 
  72. return class_exists( 'WC_Subscriptions' ) && WC_Subscriptions::$name = 'subscription'; 
  73.  
  74. /** 
  75. * Convenience wrapper for wcs_cart_contains_failed_renewal_order_payment 
  76. *  
  77. * @return bool 
  78. */ 
  79. public static function cart_contains_failed_renewal_order_payment() { 
  80. if( function_exists( 'wcs_cart_contains_failed_renewal_order_payment' )) { 
  81. return wcs_cart_contains_failed_renewal_order_payment(); 
  82.  
  83. return FALSE; 
  84.  
  85. /** 
  86. * Convenience wrapper for wcs_cart_contains_renewal 
  87. *  
  88. * @return bool 
  89. */ 
  90. public static function cart_contains_renewal() { 
  91. if( function_exists('wcs_cart_contains_renewal') ) { 
  92. return wcs_cart_contains_renewal(); 
  93.  
  94. return FALSE; 
  95.  
  96. /** 
  97. * Convenience wrapper for wcs_get_subscriptions_for_renewal_order 
  98. * @param $order 
  99. * @param bool - to return a single item or not 
  100. * @return array 
  101. */ 
  102. public static function get_subscriptions_for_renewal_order( $order, $single = FALSE ) { 
  103. if( function_exists('wcs_get_subscriptions_for_renewal_order') ) { 
  104. $subscriptions = wcs_get_subscriptions_for_renewal_order( $order ); 
  105. return $single ? end($subscriptions) : $subscriptions; 
  106. return array(); 
  107.  
  108. /** 
  109. * Convenience wrapper for wcs_get_subscriptions_for_order 
  110. * @param $order 
  111. * @return bool 
  112. */ 
  113. public static function get_subscriptions_for_order( $order ) { 
  114. if( function_exists('wcs_get_subscriptions_for_order') ) { 
  115. return wcs_get_subscriptions_for_order( $order ); 
  116. return FALSE; 
  117.  
  118. /** 
  119. * @param WC_QuickPay_Order $order The parent order 
  120. * @return bool 
  121. */ 
  122. public static function get_subscription_id(WC_QuickPay_Order $order) { 
  123. $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(); 
  124. if (WC_QuickPay_Subscription::is_subscription($order_id)) { 
  125. return $order_id; 
  126. else if ($order->contains_subscription()) { 
  127. // Find all subscriptions 
  128. $subscriptions = WC_QuickPay_Subscription::get_subscriptions_for_order($order_id); 
  129. // Get the last one and base the transaction on it. 
  130. $subscription = end($subscriptions); 
  131. // Fetch the post ID of the subscription, not the parent order. 
  132. return version_compare( WC_VERSION, '3.0', '<' ) ? $subscription->id : $subscription->get_id(); 
  133. return FALSE; 
  134.  
  135. /** 
  136. * Activates subscriptions on a parent order 
  137. * @param $order 
  138. */ 
  139. public static function activate_subscriptions_for_order( $order ) { 
  140. if (self::plugin_is_active()) { 
  141. WC_Subscriptions_Manager::activate_subscriptions_for_order( $order ); 
  142. return FALSE; 
  143.  
  144. /** 
  145. * Check if a given object is a WC_Subscription (or child class of WC_Subscription), or if a given ID 
  146. * belongs to a post with the subscription post type ('shop_subscription') 
  147. * @param $subscription 
  148. * @return bool 
  149. */ 
  150. public static function is_subscription( $subscription ) { 
  151. if (function_exists('wcs_is_subscription')) { 
  152. return wcs_is_subscription( $subscription ); 
  153. return FALSE; 
  154.  
  155. /** 
  156. * Checks if the current cart has a switch product 
  157. * @return bool 
  158. */ 
  159. public static function cart_contains_switches() { 
  160. if (class_exists('WC_Subscriptions_Switcher') && method_exists('WC_Subscriptions_Switcher', 'cart_contains_switches')) { 
  161. return WC_Subscriptions_Switcher::cart_contains_switches() !== false; 
  162. return false;