WC_QuickPay_API_Subscription

WC_QuickPay_API_Subscription class.

Defined (1)

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

/classes/api/woocommerce-quickpay-api-subscription.php  
  1. class WC_QuickPay_API_Subscription extends WC_QuickPay_API_Transaction 
  2. /** 
  3. * __construct function. 
  4. * @access public 
  5. * @return void 
  6. */ 
  7. public function __construct( $resource_data = NULL ) 
  8. // Run the parent construct 
  9. parent::__construct(); 
  10.  
  11. // Set the resource data to an object passed in on object instantiation. 
  12. // Usually done when we want to perform actions on an object returned from 
  13. // the API sent to the plugin callback handler. 
  14. if( is_object( $resource_data ) ) 
  15. $this->resource_data = $resource_data; 
  16.  
  17. // Append the main API url 
  18. $this->api_url = $this->api_url . 'subscriptions/'; 
  19.  
  20.  
  21. /** 
  22. * create function. 
  23. * Creates a new subscription via the API 
  24. * @access public 
  25. * @param WC_QuickPay_Order $order 
  26. * @return object 
  27. * @throws QuickPay_API_Exception 
  28. */ 
  29. public function create( WC_QuickPay_Order $order ) 
  30. return parent::create( $order ); 
  31.  
  32.  
  33. /** 
  34. * recurring function. 
  35. * Sends a 'recurring' request to the QuickPay API 
  36. * @access public 
  37. * @param int $transaction_id 
  38. * @param int $amount 
  39. * @return $request 
  40. * @throws QuickPay_API_Exception 
  41. */ 
  42. public function recurring( $subscription_id, $order, $amount = NULL) 
  43. // Check if a custom amount ha been set 
  44. if( $amount === NULL ) 
  45. // No custom amount set. Default to the order total 
  46. $amount = WC_Subscriptions_Order::get_recurring_total( $order ); 
  47.  
  48. if( ! $order instanceof WC_QuickPay_Order ) { 
  49. $order_id = version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(); 
  50. $order = new WC_QuickPay_Order( $order_id ); 
  51.  
  52. $order_number = $order->get_order_number_for_api( $is_recurring = TRUE ); 
  53.  
  54. $request = $this->post( sprintf( '%d/%s?synchronized', $subscription_id, "recurring" ), array( 
  55. 'amount' => WC_QuickPay_Helper::price_multiply( $amount ),  
  56. 'order_id' => sprintf('%s', $order_number ),  
  57. 'auto_capture' => $order->get_autocapture_setting(),  
  58. 'autofee' => WC_QuickPay_Helper::option_is_enabled( WC_QP()->s( 'quickpay_autofee' ) ),  
  59. 'text_on_statement' => WC_QP()->s('quickpay_text_on_statement'),  
  60. 'order_post_id' => version_compare( WC_VERSION, '3.0', '<' ) ? $order->id : $order->get_id(),  
  61. ), TRUE ); 
  62.  
  63. return $request; 
  64.  
  65.  
  66. /** 
  67. * cancel function. 
  68. * Sends a 'cancel' request to the QuickPay API 
  69. * @access public 
  70. * @param int $subscription_id 
  71. * @return void 
  72. * @throws QuickPay_API_Exception 
  73. */ 
  74. public function cancel( $subscription_id ) 
  75. $this->post( sprintf( '%d/%s', $subscription_id, "cancel" ) ); 
  76.  
  77.  
  78. /** 
  79. * is_action_allowed function. 
  80. * Check if the action we are about to perform is allowed according to the current transaction state. 
  81. * @access public 
  82. * @return boolean 
  83. */ 
  84. public function is_action_allowed( $action ) 
  85. $state = $this->get_current_type(); 
  86.  
  87. $allowed_states = array( 
  88. 'cancel' => array( 'authorize' ),  
  89. 'standard_actions' => array( 'authorize' ) 
  90. ); 
  91.  
  92. return array_key_exists( $action, $allowed_states ) AND in_array( $state, $allowed_states[$action] );