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.', 'membership2' 
  17. ); 
  18.  
  19. if ( ! empty( $this->data['error'] ) ) { 
  20. $class = 'ms-alert-error'; 
  21. $msg = $this->data['error']; 
  22.  
  23. /** 
  24. * Log the users IP and current timestamp inside the invoice. 
  25. * @since 1.0.2.0 
  26. */ 
  27. $invoice->checkout_ip = lib3()->net->current_ip()->ip; 
  28. $invoice->checkout_date = date( 'Y-m-d H:i:s' ); 
  29. $invoice->save(); 
  30.  
  31. $cancel_warning = false; 
  32. if ( ! MS_Model_Member::is_admin_user() ) { 
  33. if ( ! MS_Model_Addon::is_enabled( MS_Model_Addon::ADDON_MULTI_MEMBERSHIPS ) ) { 
  34. // Member can only sign up to one membership. 
  35. $valid_status = array( 
  36. MS_Model_Relationship::STATUS_TRIAL,  
  37. MS_Model_Relationship::STATUS_ACTIVE,  
  38. MS_Model_Relationship::STATUS_PENDING,  
  39. ); 
  40.  
  41. foreach ( $this->data['member']->subscriptions as $tmp_subscription ) { 
  42. if ( $tmp_subscription->is_system() ) { continue; } 
  43. if ( in_array( $tmp_subscription->status, $valid_status ) ) { 
  44. $cancel_warning = __( 
  45. 'Your other Memberships will be cancelled when you complete this payment.',  
  46. 'membership2' 
  47. ); 
  48. break; 
  49. } elseif ( $subscription->move_from_id ) { 
  50. $move_from_ids = explode( ', ', $subscription->move_from_id ); 
  51. $names = array(); 
  52. foreach ( $move_from_ids as $id ) { 
  53. $ms = MS_Factory::load( 'MS_Model_Membership', $id ); 
  54. if ( $ms->is_system() ) { continue; } 
  55. $names[] = $ms->name; 
  56.  
  57. if ( 1 == count( $names ) ) { 
  58. $cancel_warning = sprintf( 
  59. __( 'When you complete this payment your Membership "%s" will be cancelled.', 'membership2' ),  
  60. $names[0] 
  61. ); 
  62. } elseif ( 1 < count( $names ) ) { 
  63. $cancel_warning = sprintf( 
  64. __( 'When you complete this payment the following Memberships will be cancelled: %s.', 'membership2' ),  
  65. implode( ', ', $names ) 
  66. ); 
  67.  
  68. // Check if the user goes through a trial period before first payment. 
  69. $is_trial = $invoice->uses_trial; 
  70.  
  71. $skip_form = ! MS_Model_Member::is_admin_user() 
  72. && ! $cancel_warning 
  73. && $membership->is_free(); 
  74.  
  75. /** 
  76. * Filter the flag to allow Add-ons like "Invitation codes" to override 
  77. * the state and force the form to display. 
  78. * @var bool 
  79. */ 
  80. $skip_form = apply_filters( 
  81. 'ms_view_frontend_payment_skip_form',  
  82. $skip_form,  
  83. $invoice,  
  84. $this 
  85. ); 
  86.  
  87. if ( $skip_form ) { 
  88. // No confirmation required. Simply register for this membership! 
  89. $args = array(); 
  90. $args['ms_relationship_id'] = $subscription->id; 
  91. $args['gateway'] = MS_Gateway_Free::ID; 
  92. $args['step'] = MS_Controller_Frontend::STEP_PROCESS_PURCHASE; 
  93. $args['_wpnonce'] = wp_create_nonce( $args['gateway'] . '_' . $args['ms_relationship_id'] ); 
  94. $url = esc_url_raw( add_query_arg( $args ) ); 
  95.  
  96. /** 
  97. * Very likely the html output has already began. 
  98. * So we redirect by using javascript. 
  99. */ 
  100. ?> 
  101. <script>window.location.href = '<?php echo $url; ?>';</script> 
  102. <?php 
  103. exit; 
  104.  
  105. $show_tax = MS_Model_Addon::is_enabled( MS_Addon_Taxamo::ID ); 
  106.  
  107. /** 
  108. * Trigger an action before the payment form is displayed. This hook 
  109. * can be used by Add-ons or plugins to initialize payment settings or 
  110. * add custom code. 
  111. */ 
  112. do_action( 'ms_view_frontend_payment_form_start', $invoice, $this ); 
  113.  
  114. $classes = array( 
  115. 'ms-membership-form-wrapper',  
  116. 'ms-subscription-' . $subscription->id,  
  117. 'ms-invoice-' . $invoice->id,  
  118. ); 
  119.  
  120. ob_start(); 
  121. ?> 
  122. <div class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>"> 
  123. <legend><?php _e( 'Join Membership', 'membership2' ) ?></legend> 
  124. <p class="ms-alert-box <?php echo esc_attr( $class ); ?>"> 
  125. <?php echo $msg; ?> 
  126. </p> 
  127. <table class="ms-purchase-table"> 
  128. <tr> 
  129. <td class="ms-title-column"> 
  130. <?php _e( 'Name', 'membership2' ); ?> 
  131. </td> 
  132. <td class="ms-details-column"> 
  133. <?php echo esc_html( $membership->name ); ?> 
  134. </td> 
  135. </tr> 
  136.  
  137. <?php if ( $membership->description ) : ?> 
  138. <tr> 
  139. <td class="ms-title-column"> 
  140. <?php _e( 'Description', 'membership2' ); ?> 
  141. </td> 
  142. <td class="ms-desc-column"> 
  143. <span class="ms-membership-description"><?php 
  144. echo $membership->get_description(); 
  145. ?></span> 
  146. </td> 
  147. </tr> 
  148. <?php endif; ?> 
  149.  
  150. <?php if ( ! $membership->is_free() ) : ?> 
  151. <?php if ( $invoice->discount || $invoice->pro_rate || $invoice->tax_rate ) : ?> 
  152. <tr> 
  153. <td class="ms-title-column"> 
  154. <?php _e( 'Price', 'membership2' ); ?> 
  155. </td> 
  156. <td class="ms-details-column"> 
  157. <?php 
  158. if ( $membership->price > 0 ) { 
  159. printf( 
  160. '<span class="price">%s %s</span>',  
  161. $invoice->currency,  
  162. MS_Helper_Billing::format_price( $membership->price ) 
  163. ); 
  164. } else { 
  165. _e( 'Free', 'membership2' ); 
  166. ?> 
  167. </td> 
  168. </tr> 
  169. <?php endif; ?> 
  170.  
  171. <?php if ( $invoice->discount ) : ?> 
  172. <tr> 
  173. <td class="ms-title-column"> 
  174. <?php _e( 'Coupon Discount', 'membership2' ); ?> 
  175. </td> 
  176. <td class="ms-price-column"> 
  177. <?php 
  178. printf( 
  179. '%s -%s',  
  180. $invoice->currency,  
  181. MS_Helper_Billing::format_price( $invoice->discount ) 
  182. ); 
  183. ?> 
  184. </td> 
  185. </tr> 
  186. <?php endif; ?> 
  187.  
  188. <?php if ( $invoice->pro_rate ) : ?> 
  189. <tr> 
  190. <td class="ms-title-column"> 
  191. <?php _e( 'Pro-Rate Discount', 'membership2' ); ?> 
  192. </td> 
  193. <td class="ms-price-column"> 
  194. <?php 
  195. printf( 
  196. '%s -%s',  
  197. $invoice->currency,  
  198. MS_Helper_Billing::format_price( $invoice->pro_rate ) 
  199. ); 
  200. ?> 
  201. </td> 
  202. </tr> 
  203. <?php endif; ?> 
  204.  
  205. <?php if ( $show_tax ) : ?> 
  206. <tr> 
  207. <td class="ms-title-column"> 
  208. <?php 
  209. printf( 
  210. __( 'Taxes %s', 'membership2' ),  
  211. '<a href="#" class="ms-tax-editor"><small>(' . $invoice->tax_name . ')</small></a>' 
  212. ); 
  213. ?> 
  214. </td> 
  215. <td class="ms-price-column"> 
  216. <?php 
  217. printf( 
  218. '%s %s',  
  219. $invoice->currency,  
  220. MS_Helper_Billing::format_price( $invoice->tax ) 
  221. ); 
  222. ?> 
  223. </td> 
  224. </tr> 
  225. <?php endif; ?> 
  226.  
  227. <tr> 
  228. <td class="ms-title-column"> 
  229. <?php _e( 'Total', 'membership2' ); ?> 
  230. </td> 
  231. <td class="ms-price-column ms-total"> 
  232. <?php 
  233. if ( $invoice->total > 0 ) { 
  234. printf( 
  235. '<span class="price">%s %s</span>',  
  236. $invoice->currency,  
  237. MS_Helper_Billing::format_price( $invoice->total ) 
  238. ); 
  239. } else { 
  240. _e( 'Free', 'membership2' ); 
  241. ?> 
  242. </td> 
  243. </tr> 
  244.  
  245. <?php if ( $is_trial ) : ?> 
  246. <tr> 
  247. <td class="ms-title-column"> 
  248. <?php _e( 'Payment due', 'membership2' ); ?> 
  249. </td> 
  250. <td class="ms-desc-column"><?php 
  251. echo MS_Helper_Period::format_date( $invoice->due_date ); 
  252. ?></td> 
  253. </tr> 
  254. <tr> 
  255. <td class="ms-title-column"> 
  256. <?php _e( 'Trial price', 'membership2' ); ?> 
  257. </td> 
  258. <td class="ms-desc-column"> 
  259. <?php 
  260. if ( $invoice->trial_price > 0 ) { 
  261. printf( 
  262. '<span class="price">%s %s</span>',  
  263. $invoice->currency,  
  264. MS_Helper_Billing::format_price( $invoice->trial_price ) 
  265. ); 
  266. } else { 
  267. _e( 'Free', 'membership2' ); 
  268. ?> 
  269. </td> 
  270. </tr> 
  271. <?php endif; ?> 
  272.  
  273. <?php 
  274. do_action( 
  275. 'ms_view_frontend_payment_after_total_row',  
  276. $subscription,  
  277. $invoice,  
  278. $this 
  279. ); 
  280. ?> 
  281.  
  282. <tr> 
  283. <td class="ms-desc-column" colspan="2"> 
  284. <span class="ms-membership-description"><?php 
  285. echo $subscription->get_payment_description( $invoice ); 
  286. ?></span> 
  287. </td> 
  288. </tr> 
  289. <?php endif; ?> 
  290.  
  291. <?php if ( $cancel_warning ) : ?> 
  292. <tr> 
  293. <td class="ms-desc-warning" colspan="2"> 
  294. <span class="ms-cancel-other-memberships"><?php 
  295. echo $cancel_warning; 
  296. ?></span> 
  297. </td> 
  298. </tr> 
  299. <?php endif; 
  300.  
  301. if ( MS_Model_Member::is_admin_user() ) : ?> 
  302. <tr> 
  303. <td class="ms-desc-adminnote" colspan="2"> 
  304. <em><?php 
  305. _e( 'As admin user you already have access to this membership', 'membership2' ); 
  306. ?></em> 
  307. </td> 
  308. </tr> 
  309. <?php else : 
  310. do_action( 
  311. 'ms_view_frontend_payment_purchase_button',  
  312. $subscription,  
  313. $invoice,  
  314. $this 
  315. ); 
  316. endif; 
  317. ?> 
  318. </table> 
  319. </div> 
  320. <?php 
  321. do_action( 'ms_view_frontend_payment_after', $this->data, $this ); 
  322. do_action( 'ms_show_prices' ); 
  323.  
  324. if ( $show_tax ) { 
  325. do_action( 'ms_tax_editor', $invoice ); 
  326. ?> 
  327. <div style="clear:both;"></div> 
  328. <?php 
  329.  
  330. $html = ob_get_clean(); 
  331. $html = apply_filters( 'ms_compact_code', $html ); 
  332.  
  333. $html = apply_filters( 
  334. 'ms_view_frontend_payment_form',  
  335. $html,  
  336. $this 
  337. ); 
  338. return $html; 
  339.