MS_Gateway_Authorize_View_Form

The Membership 2 MS Gateway Authorize View Form class.

Defined (1)

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

/app/gateway/authorize/view/class-ms-gateway-authorize-view-form.php  
  1. class MS_Gateway_Authorize_View_Form extends MS_View { 
  2.  
  3. public function to_html() { 
  4. // let 3rd party themes/plugins use their own form 
  5. if ( ! apply_filters( 'ms_gateway_authorize_view_form_to_html', true, $this ) ) { 
  6. return; 
  7.  
  8. $fields = $this->prepare_fields(); 
  9. ob_start(); 
  10. // Render tabbed interface. 
  11. ?> 
  12. <div class="ms-wrap"> 
  13. <?php if ( $this->data['auth_error'] ): ?> 
  14. <div class="ms-validation-error"><p><?php echo $this->data['auth_error']; ?></p></div> 
  15. <?php endif; ?> 
  16.  
  17. <?php $this->render_cim_profiles( $fields ); ?> 
  18.  
  19. <form id="ms-authorize-extra-form" method="post" class="ms-form"> 
  20. <?php foreach ( $fields['hidden'] as $field ): ?> 
  21. <?php MS_Helper_Html::html_element( $field ); ?> 
  22. <?php endforeach;?> 
  23.  
  24. <div id="ms-authorize-card-wrapper"> 
  25. <table class="form-table ms-form-table"> 
  26. <tr> 
  27. <td class="ms-title-row" colspan="2"> 
  28. <?php _e( 'Credit Card Information', 'membership2' ); ?> 
  29. </td> 
  30. </tr> 
  31. <tr> 
  32. <td class="ms-card-info" colspan="2"> 
  33. <table border="0" width="100%" cellspacing="0" cellpadding="0"> 
  34. <tr> 
  35. <td class="ms-col-card_num"> 
  36. <?php MS_Helper_Html::html_element( $fields['card']['card_num'] ); ?> 
  37. </td> 
  38. <td class="ms-col-card_code"> 
  39. <?php MS_Helper_Html::html_element( $fields['card']['card_code'] ); ?> 
  40. </td> 
  41. </tr> 
  42. </table> 
  43. </td> 
  44. </tr> 
  45. <tr> 
  46. <td class="ms-col-expire" colspan="2"> 
  47. <?php MS_Helper_Html::html_element( $fields['card']['exp_month'] ); ?> 
  48. <?php MS_Helper_Html::html_element( $fields['card']['exp_year'] ); ?> 
  49. </td> 
  50. </tr> 
  51. <tr> 
  52. <td class="ms-title-row" colspan="2"> 
  53. <?php _e( 'Billing Information', 'membership2' ); ?> 
  54. </td> 
  55. </tr> 
  56. <tr> 
  57. <td class="ms-col-first_name"> 
  58. <?php MS_Helper_Html::html_element( $fields['billing']['first_name'] ); ?> 
  59. </td> 
  60. <td class="ms-col-last_name"> 
  61. <?php MS_Helper_Html::html_element( $fields['billing']['last_name'] ); ?> 
  62. </td> 
  63. </tr> 
  64. <tr> 
  65. <td class="ms-col-country" colspan="2"> 
  66. <?php MS_Helper_Html::html_element( $fields['billing']['country'] ); ?> 
  67. </td> 
  68. </tr> 
  69. <?php if ( ! empty( $fields['extra'] ) ) : ?> 
  70. <?php foreach ( $fields['extra'] as $field ) : ?> 
  71. <tr> 
  72. <td class="ms-col-<?php echo esc_attr( $field['id'] ); ?>" colspan="2"> 
  73. <?php MS_Helper_Html::html_element( $field ); ?> 
  74. </td> 
  75. </tr> 
  76. <?php endforeach; ?> 
  77. <?php endif; ?> 
  78. <tr> 
  79. <td class="ms-col-submit" colspan="2"> 
  80. <?php MS_Helper_Html::html_element( $fields['submit'] ); ?> 
  81. </td> 
  82. </tr> 
  83. </table> 
  84. </div> 
  85. </form> 
  86. <div class="clear"></div> 
  87. </div> 
  88. <?php 
  89. $html = ob_get_clean(); 
  90.  
  91. echo $html; 
  92.  
  93. public function prepare_fields() { 
  94. $currency = MS_Plugin::instance()->settings->currency; 
  95. $fields['hidden'] = array( 
  96. 'gateway' => array( 
  97. 'id' => 'gateway',  
  98. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  99. 'value' => $this->data['gateway'],  
  100. ),  
  101. 'ms_relationship_id' => array( 
  102. 'id' => 'ms_relationship_id',  
  103. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  104. 'value' => $this->data['ms_relationship_id'],  
  105. ),  
  106. '_wpnonce' => array( 
  107. 'id' => '_wpnonce',  
  108. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  109. 'value' => wp_create_nonce( "{$this->data['gateway']}_{$this->data['ms_relationship_id']}" ),  
  110. ),  
  111. 'action' => array( 
  112. 'id' => 'action',  
  113. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  114. 'value' => $this->data['action'],  
  115. ),  
  116. 'step' => array( 
  117. 'id' => 'step',  
  118. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  119. 'value' => MS_Controller_Frontend::STEP_PROCESS_PURCHASE,  
  120. ),  
  121. ); 
  122.  
  123. $months = array( '' => __( 'Month', 'membership2' ) ); 
  124. for ( $i = 1, $date = new DateTime( '01-01-1970' ); $i <= 12; $date->setDate( 2013, ++$i, 1 ) ) { 
  125. $months[ $i ] = $date->format( 'm - M' ); 
  126.  
  127. $years = array( '' => __( 'Year', 'membership2' ) ); 
  128. for ( $i = gmdate( 'Y' ), $maxYear = $i + 15; $i <= $maxYear; $i++ ) { 
  129. $years[ $i ] = $i; 
  130.  
  131. $fields['card'] = array( 
  132. 'card_num' => array( 
  133. 'id' => 'card_num',  
  134. 'title' => __( 'Card Number', 'membership2' ),  
  135. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  136. 'placeholder' => '**** **** **** ****',  
  137. 'maxlength' => 24, // 20 digits + 4 spaces 
  138. ),  
  139. 'card_code' => array( 
  140. 'id' => 'card_code',  
  141. 'title' => __( 'Card Code', 'membership2' ),  
  142. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  143. 'placeholder' => 'CVC',  
  144. 'maxlength' => 4,  
  145. ),  
  146. 'exp_month' => array( 
  147. 'id' => 'exp_month',  
  148. 'title' => __( 'Expires', 'membership2' ),  
  149. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  150. 'field_options' => $months,  
  151. 'class' => 'ms-select',  
  152. ),  
  153. 'exp_year' => array( 
  154. 'id' => 'exp_year',  
  155. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  156. 'field_options' => $years,  
  157. 'class' => 'ms-select',  
  158. ),  
  159. ); 
  160. $fields['billing'] = array( 
  161. 'first_name' => array( 
  162. 'id' => 'first_name',  
  163. 'title' => __( 'First Name', 'membership2' ),  
  164. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  165. 'placeholder' => __( 'First Name', 'membership2' ),  
  166. ),  
  167. 'last_name' => array( 
  168. 'id' => 'last_name',  
  169. 'title' => __( 'Last Name', 'membership2' ),  
  170. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  171. 'placeholder' => __( 'Last Name', 'membership2' ),  
  172. ),  
  173. 'country' => array( 
  174. 'id' => 'country',  
  175. 'title' => __( 'Country', 'membership2' ),  
  176. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  177. 'field_options' => $this->data['countries'],  
  178. 'class' => 'ms-select',  
  179. ),  
  180. ); 
  181. $fields['submit'] = array( 
  182. 'id' => 'submit',  
  183. 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT,  
  184. 'value' => __( 'Pay now', 'membership2' ),  
  185. ); 
  186.  
  187. // Can be populated via the filter to add extra fields to the form. 
  188. $fields['extra'] = array(); 
  189.  
  190. if ( 'update_card' == $this->data['action'] ) { 
  191. $fields['submit']['value'] = __( 'Change card', 'membership2' ); 
  192.  
  193. return apply_filters( 
  194. 'ms_gateway_authorize_view_form_prepare_fields',  
  195. $fields 
  196. ); 
  197.  
  198. /** 
  199. * Renders Authorize.net CIM profiles. 
  200. * @since 1.0.0 
  201. * @access protected 
  202. */ 
  203. protected function render_cim_profiles( $fields ) { 
  204. // if profile is empty, then return 
  205. if ( empty( $this->data['cim_profiles'] ) ) { 
  206. return; 
  207.  
  208. $gateway = MS_Model_Gateway::factory( MS_Gateway_Authorize::ID ); 
  209. $cim_profiles = $this->data['cim_profiles']; 
  210.  
  211. // if we have one record in profile, then wrap it into array to make it 
  212. // compatible with case when we have more then one payment methods added 
  213. if ( isset( $cim_profiles['billTo'] ) ) { 
  214. $cim_profiles = array( $cim_profiles ); 
  215.  
  216. $first_key = null; 
  217. foreach ( $cim_profiles as $index => $profile ) { 
  218. if ( is_array( $profile ) && ! empty( $profile['customerPaymentProfileId'] ) ) { 
  219. $options[ $profile['customerPaymentProfileId'] ] = esc_html( 
  220. sprintf( 
  221. "%s %s's - **** **** **** %s ",  
  222. $profile['billTo']['firstName'],  
  223. $profile['billTo']['lastName'],  
  224. str_replace( 'XXXX', '', $profile['payment']['creditCard']['cardNumber'] ) 
  225. ); 
  226. if ( ! $first_key ) { 
  227. $first_key = $profile['customerPaymentProfileId']; 
  228. $options[ 0 ] = __( 'Enter a new credit card', 'membership2' ); 
  229. $cim = array( 
  230. 'id' => 'profile',  
  231. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO,  
  232. 'field_options' => $options,  
  233. 'value' => $first_key,  
  234. ); 
  235. if ( $this->data['cim_payment_profile_id'] ) { 
  236. $cim['value'] = $this->data['cim_payment_profile_id']; 
  237. $card_cvc = array( 
  238. 'id' => 'card_code',  
  239. 'title' => __( 'Enter the credit cards CVC code to verify the payment', 'membership2' ),  
  240. 'type' => MS_Helper_Html::INPUT_TYPE_TEXT,  
  241. 'placeholder' => 'CVC',  
  242. 'maxlength' => 4,  
  243. ); 
  244. ?> 
  245. <form id="ms-authorize-extra-form" method="post" class="ms-form"> 
  246. <?php foreach ( $fields['hidden'] as $field ): ?> 
  247. <?php MS_Helper_Html::html_element( $field ); ?> 
  248. <?php endforeach;?> 
  249.  
  250. <div id="ms-authorize-cim-profiles-wrapper" class="authorize-form-block"> 
  251. <table> 
  252. <tr> 
  253. <td class="ms-title-row"><?php _e( 'Stored Credit Cards', 'membership2' ); ?></td> 
  254. </tr> 
  255. <tr> 
  256. <td class="ms-col-cim_profiles"> 
  257. <?php MS_Helper_Html::html_element( $cim );?> 
  258. </td> 
  259. </tr> 
  260. <?php if ( lib3()->is_true( $gateway->secure_cc ) ) : ?> 
  261. <tr class="ms-row-card_cvc"> 
  262. <td> 
  263. <?php MS_Helper_Html::html_element( $card_cvc ); ?> 
  264. </td> 
  265. </tr> 
  266. <?php endif; ?> 
  267. <tr class="ms-row-submit"> 
  268. <td class="ms-col-submit"> 
  269. <?php MS_Helper_Html::html_element( $fields['submit'] ); ?> 
  270. </td> 
  271. </tr> 
  272. </table> 
  273. </div> 
  274. </form> 
  275. <?php