/app/view/settings/page/class-ms-view-settings-page-payment.php

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