MS_View_Membership_Tab_Payment

Tab: Payment options (paid membership) Access options (free membership).

Defined (1)

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

/app/view/membership/tab/class-ms-view-membership-tab-payment.php  
  1. class MS_View_Membership_Tab_Payment extends MS_View { 
  2.  
  3. /** 
  4. * Create view output. 
  5. * @since 1.0.0 
  6. * @return string 
  7. */ 
  8. public function to_html() { 
  9. $membership = $this->data['membership']; 
  10. $fields = $this->get_fields(); 
  11.  
  12. $gateways_available = 0 != count( $fields['gateways'] ); 
  13.  
  14. if ( isset( $this->data['is_global_payments_set'] ) ) { 
  15. if ( ! $this->data['is_global_payments_set'] ) { 
  16. $gateways_available = false; 
  17.  
  18. ob_start(); 
  19. ?> 
  20. <div class="ms-payment-form"> 
  21. <?php if ( ! $membership->can_change_payment() ) : ?> 
  22. <div class="error below-h2"> 
  23. <p> 
  24. <?php _e( 'This membership already has some paying members.', 'membership2' ); ?> 
  25. </p> 
  26. <p> 
  27. <?php _e( 'Any changes will affect new invoices but not existing ones.', 'membership2' ); ?> 
  28. </p> 
  29. </div> 
  30. <?php endif; ?> 
  31. <div class="cf"> 
  32. <div class="ms-payment-structure-wrapper ms-half space"> 
  33. <?php 
  34. MS_Helper_Html::html_element( $fields['payment_type'] ); 
  35. MS_Helper_Html::html_element( $fields['price'] ); 
  36. if ( isset( $fields['payment_type_val' ] ) ) { 
  37. MS_Helper_Html::html_element( $fields['payment_type_val'] ); 
  38. ?> 
  39. </div> 
  40. <div class="ms-payment-types-wrapper ms-half"> 
  41. <div class="ms-payment-type-wrapper ms-payment-type-finite ms-period-wrapper"> 
  42. <?php 
  43. MS_Helper_Html::html_element( $fields['period_unit'] ); 
  44. MS_Helper_Html::html_element( $fields['period_type'] ); 
  45. ?> 
  46. </div> 
  47. <div class="ms-payment-type-wrapper ms-payment-type-recurring ms-period-wrapper"> 
  48. <?php 
  49. MS_Helper_Html::html_element( $fields['pay_cycle_period_unit'] ); 
  50. MS_Helper_Html::html_element( $fields['pay_cycle_period_type'] ); 
  51. MS_Helper_Html::html_element( $fields['pay_cycle_repetitions'] ); 
  52. ?> 
  53. </div> 
  54. <div class="ms-payment-type-wrapper ms-payment-type-date-range"> 
  55. <?php 
  56. MS_Helper_Html::html_element( $fields['period_date_start'] ); 
  57. MS_Helper_Html::html_element( $fields['period_date_end'] ); 
  58. ?> 
  59. </div> 
  60. <div class="ms-after-end-wrapper"> 
  61. <?php MS_Helper_Html::html_element( $fields['on_end_membership_id'] );?> 
  62. </div> 
  63. </div> 
  64. </div> 
  65.  
  66. <?php /** Only show the trial option for PAID memberships */ ?> 
  67. <?php if ( ! $membership->is_free ) : ?> 
  68. <div class="cf"> 
  69. <?php 
  70. $show_trial_note = MS_Plugin::instance()->settings->is_first_paid_membership; 
  71. if ( ! empty( $_GET['edit'] ) ) { $show_trial_note = false; } 
  72. if ( MS_Model_Addon::is_enabled( MS_Model_Addon::ADDON_TRIAL ) ) : 
  73. ?> 
  74. <div class="ms-trial-wrapper"> 
  75. <?php 
  76. MS_Helper_Html::html_separator(); 
  77. MS_Helper_Html::html_element( $fields['trial_period_enabled'] ); 
  78. $style = $membership->trial_period_enabled ? '' : 'style="display:none"'; 
  79. ?> 
  80. <div class="ms-trial-period-details" <?php echo '' . $style; ?>> 
  81. <?php 
  82. MS_Helper_Html::html_element( $fields['trial_period_unit'] ); 
  83. MS_Helper_Html::html_element( $fields['trial_period_type'] ); 
  84. ?> 
  85. </div> 
  86. </div> 
  87. <?php 
  88. else : if ( $show_trial_note ) : 
  89. ?> 
  90. <div class="ms-trial-wrapper"> 
  91. <?php MS_Helper_Html::html_separator(); ?> 
  92. <h4> 
  93. <?php _e( 'Well done, you just created your first paid membership!', 'membership2' ); ?> 
  94. </h4> 
  95. <p> 
  96. <?php _e( 'To give visitors an extra incentive to register for this Membership you can offer a free trial period for a limited time. Do you want to enable this feature now?', 'membership2' ); ?> 
  97. </p> 
  98. <p> 
  99. <?php MS_Helper_Html::html_element( $fields['enable_trial_addon'] ); ?><br /> 
  100. <em><?php _e( 'This message is only displayed once. Ignore it if you do not want to use trial memberships.', 'membership2' ); ?></em><br /> 
  101. <em><?php _e( 'You can change this feature anytime by visiting the Add-ons section.', 'membership2' ); ?></em> 
  102. </p> 
  103. </div> 
  104. <?php 
  105. endif; endif; 
  106. ?> 
  107. </div> 
  108.  
  109. <?php if ( $gateways_available ) : ?> 
  110. <div class="cf ms-payment-gateways"> 
  111. <?php MS_Helper_Html::html_separator(); ?> 
  112. <p><strong><?php _e( 'Allowed payment gateways', 'membership2' ); ?></strong></p> 
  113. <?php foreach ( $fields['gateways'] as $field ) { 
  114. MS_Helper_Html::html_element( $field ); 
  115. } ?> 
  116. </div> 
  117. <?php endif; ?> 
  118.  
  119. <?php endif; ?> 
  120.  
  121. <?php 
  122. /** 
  123. * This action allows other add-ons or plugins to display custom 
  124. * options in the payment dialog. 
  125. * @since 1.0.0 
  126. */ 
  127. do_action( 
  128. 'ms_view_membership_tab_payment_form',  
  129. $this,  
  130. $membership 
  131. ); 
  132.  
  133. // Legacy action. 
  134. do_action( 
  135. 'ms_view_membership_payment_form',  
  136. $this,  
  137. $membership 
  138. ); 
  139. ?> 
  140. </div> 
  141. <?php 
  142. $html = ob_get_clean(); 
  143.  
  144. echo $html; 
  145.  
  146. /** 
  147. * Returns field definitions to render the payment box for the specified 
  148. * membership. 
  149. * @since 1.0.0 
  150. * @return array An array containing all field definitions. 
  151. */ 
  152. private function get_fields() { 
  153. global $wp_locale; 
  154.  
  155. $membership = $this->data['membership']; 
  156. $action = MS_Controller_Membership::AJAX_ACTION_UPDATE_MEMBERSHIP; 
  157. $nonce = wp_create_nonce( $action ); 
  158.  
  159. $fields = array(); 
  160. $fields['price'] = array( 
  161. 'id' => 'price',  
  162. 'title' => __( 'Payment Amount', 'membership2' ),  
  163. 'type' => MS_Helper_Html::INPUT_TYPE_NUMBER,  
  164. 'before' => MS_Plugin::instance()->settings->currency_symbol,  
  165. 'value' => $membership->price, // Without taxes 
  166. 'class' => 'ms-text-smallish',  
  167. 'config' => array( 
  168. 'step' => 'any',  
  169. 'min' => 0,  
  170. ),  
  171. 'placeholder' => '0' . $wp_locale->number_format['decimal_point'] . '00',  
  172. 'ajax_data' => array( 1 ),  
  173. ); 
  174.  
  175. $fields['payment_type'] = array( 
  176. 'id' => 'payment_type',  
  177. 'title' => __( 'This Membership requires', 'membership2' ),  
  178. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  179. 'value' => $membership->payment_type,  
  180. 'field_options' => MS_Model_Membership::get_payment_types(),  
  181. 'ajax_data' => array( 1 ),  
  182. ); 
  183.  
  184. $fields['period_unit'] = array( 
  185. 'id' => 'period_unit',  
  186. 'title' => __( 'Grant access for', 'membership2' ),  
  187. 'name' => '[period][period_unit]',  
  188. 'type' => MS_Helper_Html::INPUT_TYPE_NUMBER,  
  189. 'value' => $membership->period_unit,  
  190. 'class' => 'ms-text-small',  
  191. 'config' => array( 
  192. 'step' => 1,  
  193. 'min' => 1,  
  194. ),  
  195. 'placeholder' => '1',  
  196. 'ajax_data' => array( 1 ),  
  197. ); 
  198.  
  199. $fields['period_type'] = array( 
  200. 'id' => 'period_type',  
  201. 'name' => '[period][period_type]',  
  202. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  203. 'value' => $membership->period_type,  
  204. 'field_options' => MS_Helper_Period::get_period_types( 'plural' ),  
  205. 'ajax_data' => array( 1 ),  
  206. ); 
  207.  
  208. $fields['pay_cycle_period_unit'] = array( 
  209. 'id' => 'pay_cycle_period_unit',  
  210. 'title' => __( 'Payment Frequency', 'membership2' ),  
  211. 'name' => '[pay_cycle_period][period_unit]',  
  212. 'type' => MS_Helper_Html::INPUT_TYPE_NUMBER,  
  213. 'value' => $membership->pay_cycle_period_unit,  
  214. 'class' => 'ms-text-small',  
  215. 'config' => array( 
  216. 'step' => 1,  
  217. 'min' => 1,  
  218. ),  
  219. 'placeholder' => '1',  
  220. 'ajax_data' => array( 1 ),  
  221. ); 
  222.  
  223. $fields['pay_cycle_period_type'] = array( 
  224. 'id' => 'pay_cycle_period_type',  
  225. 'name' => '[pay_cycle_period][period_type]',  
  226. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  227. 'value' => $membership->pay_cycle_period_type,  
  228. 'field_options' => MS_Helper_Period::get_period_types( 'plural' ),  
  229. 'ajax_data' => array( 1 ),  
  230. ); 
  231.  
  232. $fields['pay_cycle_repetitions'] = array( 
  233. 'id' => 'pay_cycle_repetitions',  
  234. 'title' => __( 'Total Payments', 'membership2' ),  
  235. 'name' => '[pay_cycle_repetitions]',  
  236. 'type' => MS_Helper_Html::INPUT_TYPE_NUMBER,  
  237. 'after' => __( 'payments (0 = unlimited)', 'membership2' ),  
  238. 'value' => $membership->pay_cycle_repetitions,  
  239. 'class' => 'ms-text-small',  
  240. 'config' => array( 
  241. 'step' => '1',  
  242. 'min' => 0,  
  243. ),  
  244. 'placeholder' => '0',  
  245. 'ajax_data' => array( 1 ),  
  246. ); 
  247.  
  248. $fields['period_date_start'] = array( 
  249. 'id' => 'period_date_start',  
  250. 'title' => __( 'Grant access from', 'membership2' ),  
  251. 'type' => MS_Helper_Html::INPUT_TYPE_DATEPICKER,  
  252. 'value' => $membership->period_date_start,  
  253. 'placeholder' => __( 'Start Date...', 'membership2' ),  
  254. 'ajax_data' => array( 1 ),  
  255. ); 
  256.  
  257. $fields['period_date_end'] = array( 
  258. 'id' => 'period_date_end',  
  259. 'type' => MS_Helper_Html::INPUT_TYPE_DATEPICKER,  
  260. 'value' => $membership->period_date_end,  
  261. 'before' => _x( 'to', 'date range', 'membership2' ),  
  262. 'placeholder' => __( 'End Date...', 'membership2' ),  
  263. 'ajax_data' => array( 1 ),  
  264. ); 
  265.  
  266. $fields['on_end_membership_id'] = array( 
  267. 'id' => 'on_end_membership_id',  
  268. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  269. 'title' => __( 'After this membership ends', 'membership2' ),  
  270. 'value' => $membership->on_end_membership_id,  
  271. 'field_options' => $membership->get_after_ms_ends_options(),  
  272. 'ajax_data' => array( 1 ),  
  273. ); 
  274.  
  275. $fields['enable_trial_addon'] = array( 
  276. 'id' => 'enable_trial_addon',  
  277. 'type' => MS_Helper_Html::INPUT_TYPE_BUTTON,  
  278. 'value' => __( 'Yes, enable Trial Memberships!', 'membership2' ),  
  279. 'button_value' => 1,  
  280. 'ajax_data' => array( 
  281. 'action' => MS_Controller_Addon::AJAX_ACTION_TOGGLE_ADDON,  
  282. '_wpnonce' => wp_create_nonce( MS_Controller_Addon::AJAX_ACTION_TOGGLE_ADDON ),  
  283. 'addon' => MS_Model_Addon::ADDON_TRIAL,  
  284. 'field' => 'active',  
  285. ),  
  286. ); 
  287.  
  288. $fields['trial_period_enabled'] = array( 
  289. 'id' => 'trial_period_enabled',  
  290. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER,  
  291. 'title' => '<strong>' . __( 'Trial Period', 'membership2' ) . '</strong>',  
  292. 'after' => __( 'Offer Free Trial', 'membership2' ),  
  293. 'value' => $membership->trial_period_enabled,  
  294. 'ajax_data' => array( 1 ),  
  295. ); 
  296.  
  297. $fields['trial_period_unit'] = array( 
  298. 'id' => 'trial_period_unit',  
  299. 'name' => '[trial_period][period_unit]',  
  300. 'before' => __( 'The Trial is free and lasts for', 'membership2' ),  
  301. 'type' => MS_Helper_Html::INPUT_TYPE_NUMBER,  
  302. 'value' => $membership->trial_period_unit,  
  303. 'class' => 'ms-text-small',  
  304. 'config' => array( 
  305. 'step' => 1,  
  306. 'min' => 1,  
  307. ),  
  308. 'placeholder' => '1',  
  309. 'ajax_data' => array( 1 ),  
  310. ); 
  311.  
  312. $fields['trial_period_type'] = array( 
  313. 'id' => 'trial_period_type',  
  314. 'name' => '[trial_period][period_type]',  
  315. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  316. 'value' => $membership->trial_period_type,  
  317. 'field_options' => MS_Helper_Period::get_period_types( 'plural' ),  
  318. 'ajax_data' => array( 1 ),  
  319. ); 
  320.  
  321. $fields['membership_id'] = array( 
  322. 'id' => 'membership_id',  
  323. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  324. 'value' => $membership->id,  
  325. ); 
  326.  
  327. $fields['action'] = array( 
  328. 'id' => 'action',  
  329. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  330. 'value' => $action,  
  331. ); 
  332.  
  333. // Get a list of all payment gateways. 
  334. $gateways = MS_Model_Gateway::get_gateways(); 
  335. $fields['gateways'] = array(); 
  336. foreach ( $gateways as $gateway ) { 
  337. if ( 'free' == $gateway->id ) { continue; } 
  338. if ( ! $gateway->active ) { continue; } 
  339.  
  340. $payment_types = $gateway->supported_payment_types(); 
  341. $wrapper_class = 'ms-payment-type-' . implode( ' ms-payment-type-', array_keys( $payment_types ) ); 
  342.  
  343. $fields['gateways'][$gateway->id] = array( 
  344. 'id' => 'disabled-gateway-' . $gateway->id,  
  345. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER,  
  346. 'title' => $gateway->name,  
  347. 'before' => __( 'Available', 'membership2' ),  
  348. 'after' => __( 'Not available', 'membership2' ),  
  349. 'value' => ! $membership->can_use_gateway( $gateway->id ),  
  350. 'class' => 'reverse',  
  351. 'wrapper_class' => 'ms-payment-type-wrapper ' . $wrapper_class,  
  352. 'ajax_data' => array( 
  353. 'field' => 'disabled_gateways[' . $gateway->id . ']',  
  354. '_wpnonce' => $nonce,  
  355. 'action' => $action,  
  356. 'membership_id' => $membership->id,  
  357. ),  
  358. ); 
  359.  
  360. // Modify some fields for free memberships. 
  361. if ( $membership->is_free ) { 
  362. $fields['price'] = ''; 
  363. $fields['payment_type'] = array( 
  364. 'id' => 'payment_type',  
  365. 'title' => __( 'Access Structure:', 'membership2' ),  
  366. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  367. 'value' => $membership->payment_type,  
  368. 'field_options' => MS_Model_Membership::get_payment_types( 'free' ),  
  369. 'ajax_data' => array( 1 ),  
  370. ); 
  371.  
  372. // Process the fields and add missing default attributes. 
  373. foreach ( $fields as $key => $field ) { 
  374. if ( ! empty( $field['ajax_data'] ) ) { 
  375. if ( ! empty( $field['ajax_data']['action'] ) ) { 
  376. continue; 
  377.  
  378. if ( ! isset( $fields[ $key ]['ajax_data']['field'] ) ) { 
  379. $fields[ $key ]['ajax_data']['field'] = $fields[ $key ]['id']; 
  380. $fields[ $key ]['ajax_data']['_wpnonce'] = $nonce; 
  381. $fields[ $key ]['ajax_data']['action'] = $action; 
  382. $fields[ $key ]['ajax_data']['membership_id'] = $membership->id; 
  383.  
  384. return apply_filters( 
  385. 'ms_view_membership_tab_payment_fields',  
  386. $fields 
  387. ); 
  388.