/app/gateway/authorize/view/class-ms-gateway-authorize-view-form.php

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