MS_View_Frontend_Payment

The Membership 2 MS View Frontend Payment class.

Defined (1)

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

/app/view/frontend/class-ms-view-frontend-payment.php  
  1. class MS_View_Frontend_Payment extends MS_View { 
  2.  
  3. /** 
  4. * Returns the HTML code for the Purchase-Membership form. 
  5. * @since 1.0.0 
  6. * @return string 
  7. */ 
  8. public function to_html() { 
  9. $membership = $this->data['membership']; 
  10. $invoice = $this->data['invoice']; 
  11. $subscription = $this->data['ms_relationship']; 
  12.  
  13. $class = 'ms-alert-success'; 
  14. $msg = __( 
  15. 'Please check the details of the membership below and click ' . 
  16. 'on the relevant button to complete the signup.', MS_TEXT_DOMAIN 
  17. ); 
  18.  
  19. if ( ! empty( $this->data['error'] ) ) { 
  20. $class = 'ms-alert-error'; 
  21. $msg = $this->data['error']; 
  22.  
  23. $cancel_warning = false; 
  24. if ( ! MS_Model_Member::is_admin_user() 
  25. && ! MS_Model_Addon::is_enabled( MS_Model_Addon::ADDON_MULTI_MEMBERSHIPS ) 
  26. ) { 
  27. // Member can only sign up to one membership. 
  28. $valid_status = array( 
  29. MS_Model_Relationship::STATUS_TRIAL,  
  30. MS_Model_Relationship::STATUS_ACTIVE,  
  31. MS_Model_Relationship::STATUS_PENDING,  
  32. ); 
  33.  
  34. foreach ( $this->data['member']->subscriptions as $tmp_relationship ) { 
  35. if ( $tmp_relationship->is_system() ) { continue; } 
  36. if ( in_array( $tmp_relationship->status, $valid_status ) ) { 
  37. $cancel_warning = true; 
  38. break; 
  39.  
  40. // Check if the user goes through a trial period before first payment. 
  41. $is_trial = $invoice->uses_trial; 
  42.  
  43. if ( ! MS_Model_Member::is_admin_user() 
  44. && ! $cancel_warning 
  45. && $membership->is_free() 
  46. ) { 
  47. // No confirmation required. Simply register for this membership! 
  48.  
  49. $args = array(); 
  50. $args['ms_relationship_id'] = $subscription->id; 
  51. $args['gateway'] = MS_Gateway_Free::ID; 
  52. $args['step'] = MS_Controller_Frontend::STEP_PROCESS_PURCHASE; 
  53. $args['_wpnonce'] = wp_create_nonce( $args['gateway'] . '_' . $args['ms_relationship_id'] ); 
  54. $url = esc_url_raw( add_query_arg( $args ) ); 
  55.  
  56. /** 
  57. * Very likely the html output has already began. 
  58. * So we redirect by using javascript. 
  59. */ 
  60. ?> 
  61. <script>window.location.href = '<?php echo $url; ?>';</script> 
  62. <?php 
  63. exit; 
  64.  
  65. $show_tax = MS_Model_Addon::is_enabled( MS_Addon_Taxamo::ID ); 
  66.  
  67. ob_start(); 
  68. ?> 
  69. <div class="ms-membership-form-wrapper"> 
  70. <legend><?php _e( 'Join Membership', MS_TEXT_DOMAIN ) ?></legend> 
  71. <p class="ms-alert-box <?php echo esc_attr( $class ); ?>"> 
  72. <?php echo '' . $msg; ?> 
  73. </p> 
  74. <table class="ms-purchase-table"> 
  75. <tr> 
  76. <td class="ms-title-column"> 
  77. <?php _e( 'Name', MS_TEXT_DOMAIN ); ?> 
  78. </td> 
  79. <td class="ms-details-column"> 
  80. <?php echo esc_html( $membership->name ); ?> 
  81. </td> 
  82. </tr> 
  83.  
  84. <?php if ( $membership->description ) : ?> 
  85. <tr> 
  86. <td class="ms-title-column"> 
  87. <?php _e( 'Description', MS_TEXT_DOMAIN ); ?> 
  88. </td> 
  89. <td class="ms-desc-column"> 
  90. <span class="ms-membership-description"><?php 
  91. echo '' . $membership->description; 
  92. ?></span> 
  93. </td> 
  94. </tr> 
  95. <?php endif; ?> 
  96.  
  97. <?php if ( ! $membership->is_free() ) : ?> 
  98. <?php if ( $invoice->discount || $invoice->pro_rate || $invoice->tax_rate ) : ?> 
  99. <tr> 
  100. <td class="ms-title-column"> 
  101. <?php _e( 'Price', MS_TEXT_DOMAIN ); ?> 
  102. </td> 
  103. <td class="ms-details-column"> 
  104. <?php 
  105. if ( $membership->price > 0 ) { 
  106. printf( 
  107. '<span class="price">%s %s</span>',  
  108. $invoice->currency,  
  109. MS_Helper_Billing::format_price( $membership->price ) 
  110. ); 
  111. } else { 
  112. _e( 'Free', MS_TEXT_DOMAIN ); 
  113. ?> 
  114. </td> 
  115. </tr> 
  116. <?php endif; ?> 
  117.  
  118. <?php if ( $invoice->discount ) : ?> 
  119. <tr> 
  120. <td class="ms-title-column"> 
  121. <?php _e( 'Coupon discount', MS_TEXT_DOMAIN ); ?> 
  122. </td> 
  123. <td class="ms-price-column"> 
  124. <?php printf( '%s -%s', $invoice->currency, MS_Helper_Billing::format_price( $invoice->discount ) ); ?> 
  125. </td> 
  126. </tr> 
  127. <?php endif; ?> 
  128.  
  129. <?php if ( $invoice->pro_rate ) : ?> 
  130. <tr> 
  131. <td class="ms-title-column"> 
  132. <?php _e( 'Pro rate discount', MS_TEXT_DOMAIN ); ?> 
  133. </td> 
  134. <td class="ms-price-column"> 
  135. <?php printf( '%s -%s', $invoice->currency, MS_Helper_Billing::format_price( $invoice->pro_rate ) ); ?> 
  136. </td> 
  137. </tr> 
  138. <?php endif; ?> 
  139.  
  140. <?php if ( $show_tax ) : ?> 
  141. <tr> 
  142. <td class="ms-title-column"> 
  143. <?php 
  144. printf( 
  145. __( 'Taxes %s', MS_TEXT_DOMAIN ),  
  146. '<a href="#" class="ms-tax-editor"><small>(' . $invoice->tax_name . ')</small></a>' 
  147. ); 
  148. ?> 
  149. </td> 
  150. <td class="ms-price-column"> 
  151. <?php 
  152. printf( 
  153. '%s %s',  
  154. $invoice->currency,  
  155. MS_Helper_Billing::format_price( $invoice->tax ) 
  156. ); 
  157. ?> 
  158. </td> 
  159. </tr> 
  160. <?php endif; ?> 
  161.  
  162. <tr> 
  163. <td class="ms-title-column"> 
  164. <?php _e( 'Total', MS_TEXT_DOMAIN ); ?> 
  165. </td> 
  166. <td class="ms-price-column ms-total"> 
  167. <?php 
  168. if ( $invoice->total > 0 ) { 
  169. printf( 
  170. '<span class="price">%s %s</span>',  
  171. $invoice->currency,  
  172. MS_Helper_Billing::format_price( $invoice->total ) 
  173. ); 
  174. } else { 
  175. _e( 'Free', MS_TEXT_DOMAIN ); 
  176. ?> 
  177. </td> 
  178. </tr> 
  179.  
  180. <?php if ( $is_trial ) : ?> 
  181. <tr> 
  182. <td class="ms-title-column"> 
  183. <?php _e( 'Payment due', MS_TEXT_DOMAIN ); ?> 
  184. </td> 
  185. <td class="ms-desc-column"><?php 
  186. echo MS_Helper_Period::format_date( $invoice->due_date ); 
  187. ?></td> 
  188. </tr> 
  189. <tr> 
  190. <td class="ms-title-column"> 
  191. <?php _e( 'Trial price', MS_TEXT_DOMAIN ); ?> 
  192. </td> 
  193. <td class="ms-desc-column"> 
  194. <?php 
  195. if ( $invoice->trial_price > 0 ) { 
  196. printf( 
  197. '<span class="price">%s %s</span>',  
  198. $invoice->currency,  
  199. MS_Helper_Billing::format_price( $invoice->trial_price ) 
  200. ); 
  201. } else { 
  202. _e( 'Free', MS_TEXT_DOMAIN ); 
  203. ?> 
  204. </td> 
  205. </tr> 
  206. <?php endif; ?> 
  207. <tr> 
  208. <td class="ms-desc-column" colspan="2"> 
  209. <span class="ms-membership-description"><?php 
  210. echo '' . $subscription->get_payment_description( $invoice ); 
  211. ?></span> 
  212. </td> 
  213. </tr> 
  214. <?php endif; ?> 
  215.  
  216. <?php if ( $cancel_warning ) : ?> 
  217. <tr> 
  218. <td class="ms-desc-warning" colspan="2"> 
  219. <span class="ms-cancel-other-memberships"><?php 
  220. _e( 
  221. 'Your other Memberships will be cancelled when you complete this payment.',  
  222. MS_TEXT_DOMAIN 
  223. ); 
  224. ?></span> 
  225. </td> 
  226. </tr> 
  227. <?php endif; 
  228.  
  229. if ( MS_Model_Member::is_admin_user() ) : ?> 
  230. <tr> 
  231. <td class="ms-desc-adminnote" colspan="2"> 
  232. <em><?php 
  233. _e( 'As admin user you already have access to this membership', MS_TEXT_DOMAIN ); 
  234. ?></em> 
  235. </td> 
  236. </tr> 
  237. <?php else : 
  238. do_action( 
  239. 'ms_view_frontend_payment_purchase_button',  
  240. $subscription,  
  241. $invoice 
  242. ); 
  243. endif; 
  244. ?> 
  245. </table> 
  246. </div> 
  247. <?php 
  248. do_action( 'ms_view_frontend_payment_after', $this->data, $this ); 
  249. do_action( 'ms_show_prices' ); 
  250.  
  251. if ( $show_tax ) { 
  252. do_action( 'ms_tax_editor', $invoice ); 
  253. ?> 
  254. <div style="clear:both;"></div> 
  255. <?php 
  256.  
  257. return ob_get_clean(); 
  258.