MS_View_Frontend_Payment

The WordPress Core 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 on the relevant button to complete the signup.', 'membership2' 
  16. ); 
  17.  
  18. if ( ! empty( $this->data['error'] ) ) { 
  19. $class = 'ms-alert-error'; 
  20. $msg = $this->data['error']; 
  21.  
  22. /** 
  23. * Log the users IP and current timestamp inside the invoice. 
  24. * @since 1.0.2.0 
  25. */ 
  26. $invoice->checkout_ip = lib3()->net->current_ip()->ip; 
  27. $invoice->checkout_date = date( 'Y-m-d H:i:s' ); 
  28. $invoice->save(); 
  29.  
  30. $cancel_warning = false; 
  31.  
  32. if ( ! MS_Model_Member::is_admin_user() ) { 
  33.  
  34. if ( ! MS_Model_Addon::is_enabled( MS_Model_Addon::ADDON_MULTI_MEMBERSHIPS ) ) { 
  35. // Member can only sign up to one membership. 
  36. $valid_status = array( 
  37. MS_Model_Relationship::STATUS_TRIAL,  
  38. MS_Model_Relationship::STATUS_ACTIVE,  
  39. MS_Model_Relationship::STATUS_PENDING,  
  40. ); 
  41.  
  42. foreach ( $this->data['member']->subscriptions as $tmp_subscription ) { 
  43. if ( $tmp_subscription->is_system() ) { continue; } 
  44. if ( in_array( $tmp_subscription->status, $valid_status ) ) { 
  45. $cancel_warning = __( 
  46. 'Your other Memberships will be cancelled when you complete this payment.',  
  47. 'membership2' 
  48. ); 
  49. break; 
  50. } elseif ( $subscription->move_from_id ) { 
  51. $move_from_ids = explode( ', ', $subscription->move_from_id ); 
  52. $names = array(); 
  53. foreach ( $move_from_ids as $id ) { 
  54. $ms = MS_Factory::load( 'MS_Model_Membership', $id ); 
  55. if ( $ms->is_system() ) { continue; } 
  56. $names[] = $ms->name; 
  57.  
  58. if ( 1 == count( $names ) ) { 
  59. $cancel_warning = sprintf( 
  60. __( 'When you complete this payment your Membership "%s" will be cancelled.', 'membership2' ),  
  61. $names[0] 
  62. ); 
  63. } elseif ( 1 < count( $names ) ) { 
  64. $cancel_warning = sprintf( 
  65. __( 'When you complete this payment the following Memberships will be cancelled: %s.', 'membership2' ),  
  66. implode( ', ', $names ) 
  67. ); 
  68.  
  69. // Check if the user goes through a trial period before first payment. 
  70. $is_trial = $invoice->uses_trial; 
  71.  
  72. $skip_form = ! MS_Model_Member::is_admin_user() 
  73. && ! $cancel_warning 
  74. && $membership->is_free(); 
  75.  
  76. /** 
  77. * Filter the flag to allow Add-ons like "Invitation codes" to override 
  78. * the state and force the form to display. 
  79. * @var bool 
  80. */ 
  81. $skip_form = apply_filters( 
  82. 'ms_view_frontend_payment_skip_form',  
  83. $skip_form,  
  84. $invoice,  
  85. $this 
  86. ); 
  87.  
  88. if ( $skip_form ) { 
  89. // No confirmation required. Simply register for this membership! 
  90. $args = array(); 
  91. $args['ms_relationship_id'] = $subscription->id; 
  92. $args['gateway'] = MS_Gateway_Free::ID; 
  93. $args['step'] = MS_Controller_Frontend::STEP_PROCESS_PURCHASE; 
  94. $args['_wpnonce'] = wp_create_nonce( $args['gateway'] . '_' . $args['ms_relationship_id'] ); 
  95. $url = esc_url_raw( add_query_arg( $args ) ); 
  96.  
  97. /** 
  98. * Very likely the html output has already began. 
  99. * So we redirect by using javascript. 
  100. */ 
  101. ?> 
  102. <script>window.location.href = '<?php echo $url; ?>';</script> 
  103. <?php 
  104. exit; 
  105.  
  106. $show_tax = MS_Model_Addon::is_enabled( MS_Addon_Taxamo::ID ); 
  107.  
  108. /** 
  109. * Trigger an action before the payment form is displayed. This hook 
  110. * can be used by Add-ons or plugins to initialize payment settings or 
  111. * add custom code. 
  112. */ 
  113. do_action( 'ms_view_frontend_payment_form_start', $invoice, $this ); 
  114.  
  115. $classes = array( 
  116. 'ms-membership-form-wrapper',  
  117. 'ms-subscription-' . $subscription->id,  
  118. 'ms-invoice-' . $invoice->id,  
  119. ); 
  120.  
  121. ob_start(); 
  122.  
  123. $membership_wrapper_class = esc_attr( implode( ' ', $classes ) ); 
  124. $alert_box_class = esc_attr( $class ); 
  125. $membership_name = esc_html( $membership->name ); 
  126. $is_membership_description = $membership->description; 
  127. $membership_description = $membership->get_description(); 
  128. $is_membership_free = $membership->is_free(); 
  129. $invoice_discount = $invoice->discount; 
  130. $invoice_pro_rate = $invoice->pro_rate; 
  131. $invoice_tax_rate = $invoice->tax_rate; 
  132. $invoice_discount = $invoice->discount; 
  133. $invoice_formatted_discount = sprintf( 
  134. '%s -%s',  
  135. $invoice->currency,  
  136. MS_Helper_Billing::format_price( $invoice->discount ) 
  137. ); 
  138. $invoice_formatted_pro_rate = sprintf( 
  139. '%s -%s',  
  140. $invoice->currency,  
  141. MS_Helper_Billing::format_price( $invoice->pro_rate ) 
  142. ); 
  143. $invoice_tax_name = sprintf( 
  144. __( 'Taxes %s', 'membership2' ),  
  145. '<a href="#" class="ms-tax-editor"><small>(' . $invoice->tax_name . ')</small></a>' 
  146. ); 
  147. $invoice_formatted_tax = sprintf( 
  148. '%s %s',  
  149. $invoice->currency,  
  150. MS_Helper_Billing::format_price( $invoice->tax ) 
  151. ); 
  152. $invoice_total = $invoice->total; 
  153. $is_ms_admin_user = MS_Model_Member::is_admin_user(); 
  154. $invoice_formatted_total_for_admin = sprintf( 
  155. '<span class="price">%s %s</span>',  
  156. $invoice->currency,  
  157. MS_Helper_Billing::format_price( $membership->price - $invoice->discount + $invoice->pro_rate + $invoice->tax ) 
  158. ); 
  159. $invoice_formatted_total = sprintf( 
  160. '<span class="price">%s %s</span>',  
  161. $invoice->currency,  
  162. MS_Helper_Billing::format_price( $invoice->total ) 
  163. ); 
  164. $membership_price = $membership->price; 
  165. $membership_formatted_price = sprintf( 
  166. '<span class="price">%s %s</span>',  
  167. $invoice->currency,  
  168. MS_Helper_Billing::format_price( $membership->price ) 
  169. ); 
  170.  
  171. $invoice_formatted_due_date = MS_Helper_Period::format_date( $invoice->due_date ); 
  172. $invoice_trial_price = $invoice->trial_price; 
  173. $invoice_formatted_trial_price = sprintf( 
  174. '<span class="price">%s %s</span>',  
  175. $invoice->currency,  
  176. MS_Helper_Billing::format_price( $invoice->trial_price ) 
  177. ); 
  178. $invoice_payment_description = $subscription->get_payment_description( $invoice ); 
  179.  
  180. $template_data = array( 
  181. 'membership_wrapper_class' => $membership_wrapper_class,  
  182. 'alert_box_class' => $alert_box_class,  
  183. 'msg' => $msg,  
  184. 'membership_name' => $membership_name,  
  185. 'is_membership_description' => $is_membership_description,  
  186. 'membership_description' => $membership_description,  
  187. 'is_membership_free' => $is_membership_free,  
  188. 'invoice_discount' => $invoice_discount,  
  189. 'invoice_pro_rate' => $invoice_pro_rate,  
  190. 'invoice_tax_rate' => $invoice_tax_rate,  
  191. 'membership_price' => $membership_price,  
  192. 'membership_formatted_price' => $membership_formatted_price,  
  193. 'invoice_formatted_discount' => $invoice_formatted_discount,  
  194. 'invoice_formatted_pro_rate' => $invoice_formatted_pro_rate,  
  195. 'show_tax' => $show_tax,  
  196. 'invoice_tax_name' => $invoice_tax_name,  
  197. 'invoice_formatted_tax' => $invoice_formatted_tax,  
  198. 'invoice_total' => $invoice_total,  
  199. 'is_ms_admin_user' => $is_ms_admin_user,  
  200. 'invoice_formatted_total_for_admin' => $invoice_formatted_total_for_admin,  
  201. 'invoice_formatted_total' => $invoice_formatted_total,  
  202. 'is_trial' => $is_trial,  
  203. 'invoice_formatted_due_date' => $invoice_formatted_due_date,  
  204. 'invoice_trial_price' => $invoice_trial_price,  
  205. 'invoice_formatted_trial_price' => $invoice_formatted_trial_price,  
  206. 'invoice_payment_description' => $invoice_payment_description,  
  207. 'cancel_warning' => $cancel_warning,  
  208. 'm2_payment_obj' => $this,  
  209. 'subscription' => $subscription,  
  210. 'invoice' => $invoice,  
  211. ); 
  212.  
  213. MS_Helper_Template::$ms_front_payment = $template_data; 
  214. if ( $path = MS_Helper_Template::template_exists( 'membership_frontend_payment.php' ) ) { 
  215. require $path; 
  216.  
  217. $html = ob_get_clean(); 
  218. $html = apply_filters( 'ms_compact_code', $html ); 
  219.  
  220. $html = apply_filters( 
  221. 'ms_view_frontend_payment_form',  
  222. $html,  
  223. $this 
  224. ); 
  225. return $html;