/app/view/member/class-ms-view-member-payment.php

  1. <?php 
  2.  
  3. /** 
  4. * Dialog: Member Payment Infos 
  5. * 
  6. * Extends MS_View for rendering methods and magic methods. 
  7. * 
  8. * @since 1.0.0 
  9. * @package Membership2 
  10. * @subpackage View 
  11. */ 
  12. class MS_View_Member_Payment extends MS_Dialog { 
  13.  
  14. /** 
  15. * Generate/Prepare the dialog attributes. 
  16. * 
  17. * @since 1.0.0 
  18. */ 
  19. public function prepare() { 
  20. $subscription_id = $_POST['subscription_id']; 
  21. $subscription = MS_Factory::load( 'MS_Model_Relationship', $subscription_id ); 
  22.  
  23. $data = array( 
  24. 'model' => $subscription,  
  25. ); 
  26.  
  27. $data = apply_filters( 'ms_view_member_payment_data', $data ); 
  28.  
  29. // Dialog Title 
  30. $this->title = sprintf( 
  31. __( 'Subscription Details: %1$s', 'membership2' ),  
  32. esc_html( $subscription->get_membership()->name ) 
  33. ); 
  34.  
  35. // Dialog Size 
  36. $this->width = 940; 
  37. $this->height = 600; 
  38.  
  39. // Contents 
  40. $this->content = $this->get_contents( $data ); 
  41.  
  42. // Make the dialog modal 
  43. $this->modal = true; 
  44.  
  45. /** 
  46. * Save the dialog details. 
  47. * 
  48. * @since 1.0.0 
  49. * @return string 
  50. */ 
  51. public function submit() { 
  52. // Does nothing... 
  53.  
  54. /** 
  55. * Returns the contens of the dialog 
  56. * 
  57. * @since 1.0.0 
  58. * 
  59. * @return object 
  60. */ 
  61. public function get_contents( $data ) { 
  62. $subscription = $data['model']; 
  63. $gateways = MS_Model_Gateway::get_gateway_names(); 
  64. $invoices = $subscription->get_invoices(); 
  65.  
  66. $pay_details = array(); 
  67. $inv_details = array(); 
  68.  
  69. foreach ( $subscription->get_payments() as $payment ) { 
  70. if ( isset( $gateways[ $payment['gateway'] ] ) ) { 
  71. $gateway = $gateways[ $payment['gateway'] ]; 
  72. } else { 
  73. $gateway = '(' . $payment['gateway'] . ')'; 
  74.  
  75. $pay_details[] = array( 
  76. 'title' => __( 'Recorded Payment', 'membership2' ),  
  77. 'type' => MS_Helper_Html::TYPE_HTML_TABLE,  
  78. 'value' => array( 
  79. 0 => array( 'Payment Date', $payment['date'] ),  
  80. 1 => array( 'Payment Gateway', $gateway ),  
  81. 2 => array( 'Amount', $payment['amount'] ),  
  82. 3 => array( 'External ID', $payment['external_id'] ),  
  83. ),  
  84. 'field_options' => array( 
  85. 'head_col' => true,  
  86. ),  
  87. ); 
  88.  
  89. $invoice_list = array(); 
  90. foreach ( $invoices as $invoice ) { 
  91. if ( isset( $gateways[ $invoice->gateway_id ] ) ) { 
  92. $gateway = $gateways[ $invoice->gateway_id ]; 
  93. } else { 
  94. $gateway = '(' . $invoice->gateway_id . ')'; 
  95.  
  96. $transaction_log = sprintf( 
  97. ' <small>- <a href="%s" target="_blank">%s</a></small>',  
  98. MS_Controller_Plugin::get_admin_url( 
  99. 'billing',  
  100. array( 'show' => 'logs', 'invoice' => $invoice->id ) 
  101. ),  
  102. __( 'Show Transaction', 'membership2' ) 
  103. ); 
  104. $invoice_list[] = $invoice->id; 
  105.  
  106. $inv_details[$invoice->id] = array( 
  107. 'title' => sprintf( __( 'Invoice %s', 'membership2' ), $invoice->id ),  
  108. 'type' => MS_Helper_Html::TYPE_HTML_TABLE,  
  109. 'value' => array( 
  110. 0 => array( 'Invoice ID', $invoice->id . $transaction_log ),  
  111. 2 => array( 'Create Date', $invoice->invoice_date ),  
  112. 1 => array( 'Payment Gateway', $gateway ),  
  113. 2 => array( 'Due Date', $invoice->due_date ),  
  114. 3 => array( 'Regular amount', $invoice->amount ),  
  115. 4 => array( 'Total billed', $invoice->total ),  
  116. 5 => array( 'Status', $invoice->status ),  
  117. 6 => array( 'Notes', $invoice->description ),  
  118. 7 => array( 'Checkout IP', $invoice->checkout_ip ),  
  119. 8 => array( 'Checkout Date', $invoice->checkout_date ),  
  120. ),  
  121. 'field_options' => array( 
  122. 'head_col' => true,  
  123. ),  
  124. ); 
  125.  
  126. if ( $invoice->amount == $invoice->total ) { 
  127. unset( $inv_details[$invoice->id]['value'][3] ); 
  128. $inv_details[$invoice->id]['value'] = array_values( $inv_details[$invoice->id]['value'] ); 
  129.  
  130. $transaction_url = MS_Controller_Plugin::get_admin_url( 
  131. 'billing',  
  132. array( 'show' => 'logs', 'invoice' => implode( ', ', $invoice_list ) ) 
  133. ); 
  134. $transaction_log = array( 
  135. 'type' => MS_Helper_Html::TYPE_HTML_LINK,  
  136. 'value' => __( 'Show all Transactions for this subscription', 'membership2' ),  
  137. 'url' => $transaction_url,  
  138. 'target' => '_blank',  
  139. ); 
  140.  
  141. ob_start(); 
  142. ?> 
  143. <div class="wpmui-grid-8 ms-payment-infos"> 
  144. <div class="col-5"> 
  145. <?php 
  146. foreach ( $inv_details as $detail ) { 
  147. MS_Helper_Html::html_element( $detail ); 
  148. ?> 
  149. </div> 
  150. <div class="col-3"> 
  151. <?php 
  152. MS_Helper_Html::html_element( $transaction_log ); 
  153. MS_Helper_Html::html_separator(); 
  154. foreach ( $pay_details as $detail ) { 
  155. MS_Helper_Html::html_element( $detail ); 
  156. ?> 
  157. </div> 
  158. </div> 
  159. <?php 
  160. $html = ob_get_clean(); 
  161. return apply_filters( 'ms_view_member_payment_to_html', $html ); 
  162.  
  163. }; 
.