MS_View_Member_Payment

Dialog: Member Payment Infos.

Defined (1)

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

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