MS_View_Settings_Page_Payment

The Membership 2 MS View Settings Page Payment class.

Defined (1)

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

/app/view/settings/page/class-ms-view-settings-page-payment.php  
  1. class MS_View_Settings_Page_Payment extends MS_View_Settings_Edit { 
  2.  
  3. /** 
  4. * Overrides parent's to_html() method. 
  5. * Creates an output buffer, outputs the HTML and grabs the buffer content before releasing it. 
  6. * HTML contains the list of available payment gateways. 
  7. * @since 1.0.0 
  8. * @return string 
  9. */ 
  10. public function to_html() { 
  11. $fields = $this->get_global_payment_fields(); 
  12.  
  13. ob_start(); 
  14. ?> 
  15. <div id="ms-payment-settings-wrapper"> 
  16. <div class="ms-global-payment-wrapper"> 
  17. <div class="ms-list-table-wrapper"> 
  18. <?php 
  19. MS_Helper_Html::settings_tab_header( 
  20. array( 
  21. 'title' => __( 'Global Payment Settings', 'membership2' ),  
  22. 'desc' => __( 'These are shared across all memberships.', 'membership2' ),  
  23. ); 
  24. ?> 
  25. <div class="ms-half space"> 
  26. <?php MS_Helper_Html::html_element( $fields['currency'] ); ?> 
  27. </div> 
  28. <div class="ms-half"> 
  29. <?php MS_Helper_Html::html_element( $fields['invoice_sender_name'] ); ?> 
  30. </div> 
  31.  
  32. <div class="ms-group-head"> 
  33. <div class="ms-bold"><?php _e( 'Payment Gateways', 'membership2' ); ?></div> 
  34. <div class="ms-description"><?php _e( 'You need to set-up at least one Payment Gateway to be able to process payments.', 'membership2' ); ?></div> 
  35. </div> 
  36.  
  37. <div class="gateways"> 
  38. <?php $this->gateway_settings(); ?> 
  39. </div> 
  40. </div> 
  41.  
  42. <?php MS_Helper_Html::settings_footer(); ?> 
  43. </div> 
  44. </div> 
  45. <?php 
  46. $html = ob_get_clean(); 
  47.  
  48. return $html; 
  49.  
  50. /** 
  51. * Prepares a list with field definitions that are required to render the 
  52. * payment list/global options (i.e. currency and sender name) 
  53. * @since 1.0.0 
  54. * @return array 
  55. */ 
  56. protected function get_global_payment_fields() { 
  57. $settings = MS_Factory::load( 'MS_Model_Settings' ); 
  58. $action = MS_Controller_Settings::AJAX_ACTION_UPDATE_SETTING; 
  59. $nonce = wp_create_nonce( $action ); 
  60.  
  61. $fields = array( 
  62. 'currency' => array( 
  63. 'id' => 'currency',  
  64. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  65. 'title' => __( 'Select payment currency', 'membership2' ),  
  66. 'value' => $settings->currency,  
  67. 'field_options' => $settings->get_currencies(),  
  68. 'class' => '',  
  69. 'class' => 'ms-select',  
  70. 'data_ms' => array( 
  71. 'field' => 'currency',  
  72. ),  
  73. ),  
  74.  
  75. 'invoice_sender_name' => array( 
  76. 'id' => 'invoice_sender_name',  
  77. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  78. 'title' => __( 'Invoice sender name', 'membership2' ),  
  79. 'value' => $settings->invoice_sender_name,  
  80. 'data_ms' => array( 
  81. 'field' => 'invoice_sender_name',  
  82. ),  
  83. ),  
  84. ); 
  85.  
  86. foreach ( $fields as $key => $field ) { 
  87. if ( is_array( $field['data_ms'] ) ) { 
  88. $fields[ $key ]['data_ms']['_wpnonce'] = $nonce; 
  89. $fields[ $key ]['data_ms']['action'] = $action; 
  90.  
  91. return apply_filters( 'ms_gateway_view_get_global_payment_fields', $fields ); 
  92.  
  93. /** 
  94. * Displays the edit form for all payment gateways. 
  95. * @since 1.0.0 
  96. */ 
  97. protected function gateway_settings() { 
  98. $gateways = MS_Model_Gateway::get_gateways(); 
  99. $groups = array(); 
  100.  
  101. foreach ( $gateways as $gateway ) { 
  102. $group = $gateway->group; 
  103. if ( empty( $group ) ) { continue; } 
  104. $groups[$group] = lib3()->array->get( $groups[$group] ); 
  105. $groups[$group][$gateway->id] = $gateway; 
  106.  
  107. foreach ( $groups as $label => $group ) : ?> 
  108. <div class="ms-gateway-group"> 
  109. <h4><?php echo $label; ?></h4> 
  110.  
  111. <?php 
  112. foreach ( $group as $gateway ) { 
  113. $this->gateway_item_settings( $gateway ); 
  114. ?> 
  115.  
  116. </div> 
  117. <?php endforeach; 
  118.  
  119. protected function gateway_item_settings( $gateway ) { 
  120. $is_online = lib3()->net->is_online( MS_Helper_Utility::home_url( '/' ) ); 
  121. $row_class = 'gateway-' . $gateway->id; 
  122. $active_class = 'ms-gateway-not-configured'; 
  123.  
  124. if ( $gateway->is_configured() ) { 
  125. $row_class .= ' is-configured'; 
  126. $active_class = 'ms-gateway-configured'; 
  127. } else { 
  128. $row_class .= ' not-configured'; 
  129.  
  130. if ( $gateway->is_live_mode() ) { 
  131. $row_class .= ' is-live'; 
  132. } else { 
  133. $row_class .= ' is-sandbox'; 
  134.  
  135. if ( ! $is_online ) { 
  136. $row_class .= ' is-offline'; 
  137. } else { 
  138. $row_class .= ' is-online'; 
  139.  
  140. $actions = array( 
  141. sprintf( 
  142. '<a href="%1$s">%2$s</a>',  
  143. MS_Controller_Plugin::get_admin_url( 
  144. 'billing',  
  145. array( 'gateway_id' => $gateway->id ) 
  146. ),  
  147. __( 'View Transactions', 'membership2' ) 
  148. ),  
  149. sprintf( 
  150. '<a href="%1$s">%2$s</a>',  
  151. MS_Controller_Plugin::get_admin_url( 
  152. 'billing',  
  153. array( 'show' => 'logs', 'gateway_id' => $gateway->id ) 
  154. ),  
  155. __( 'View Logs', 'membership2' ) 
  156. ),  
  157. ); 
  158.  
  159. $actions = apply_filters( 
  160. 'gateway_settings_actions',  
  161. $actions,  
  162. $gateway 
  163. ); 
  164.  
  165. $action_tag = array(); 
  166. foreach ( $actions as $action => $link ) { 
  167. $action_tag[] = "<span class='$action'>$link</span>"; 
  168.  
  169. $toggle = array( 
  170. 'id' => 'ms-toggle-' . $gateway->id,  
  171. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER,  
  172. 'value' => $gateway->active,  
  173. 'data_ms' => array( 
  174. 'action' => MS_Controller_Gateway::AJAX_ACTION_TOGGLE_GATEWAY,  
  175. 'gateway_id' => $gateway->id,  
  176. ),  
  177. ); 
  178.  
  179. $settings_class = 'MS_Gateway_' . ucwords( esc_attr( $gateway->id ) ) . '_View_Settings'; 
  180. $settings = MS_Factory::create( $settings_class ); 
  181. $settings->data = array( 'model' => $gateway ); 
  182.  
  183. // -- Output the form -- 
  184.  
  185. ?> 
  186. <div class="ms-gateway-item <?php echo esc_attr( $row_class ); ?>"> 
  187. <span class="gateway-title"> 
  188. <label class="gateway-toggle gateway-name" for="settings-<?php echo esc_attr( $gateway->id ); ?>"> 
  189. <i class="row-status-close wpmui-fa wpmui-fa-caret-right"></i> 
  190. <i class="row-status-open wpmui-fa wpmui-fa-caret-down"></i> 
  191. <?php echo esc_html( $gateway->name ); ?> 
  192. </label> 
  193. <span class="gateway-description"> 
  194. <?php echo esc_html( $gateway->description ); ?> 
  195. </span> 
  196. <span class="wpmui-fa offline-flag" title="<?php echo __( 'Website seems to be not publicly available. This payment method might not work.', 'membership2' ); ?>"> 
  197. </span> 
  198. </span> 
  199.  
  200. <span class="mode"> 
  201. <span class="mode-sandbox"><?php _e( 'Sandbox', 'membership2' ); ?></span> 
  202. <span class="mode-live"><?php _e( 'Live', 'membership2' ); ?></span> 
  203. </span> 
  204.  
  205. <div class="ms-gateway-status <?php echo esc_attr( $active_class ); ?> ms-active-wrapper-<?php echo esc_attr( $gateway->id ); ?>"> 
  206. <?php MS_Helper_Html::html_element( $toggle ); ?> 
  207. <div class="ms-gateway-setup-wrapper"> 
  208. <label for="settings-<?php echo esc_attr( $gateway->id ); ?>" class="button"> 
  209. <i class="wpmui-fa wpmui-fa-cog"></i> <?php _e( 'Configure', 'membership2' ); ?> 
  210. </label> 
  211. </div> 
  212.  
  213. </div> 
  214.  
  215. <div class="row-actions"><?php echo implode( ' | ', $action_tag ); ?></div> 
  216.  
  217. <input type="checkbox" class="show-settings" id="settings-<?php echo esc_attr( $gateway->id ); ?>"/> 
  218. <div class="ms-gateway-settings"> 
  219. <?php echo $settings->to_html(); ?> 
  220. </div> 
  221.  
  222. </div> 
  223. <?php 
  224.