/app/gateway/free/view/class-ms-gateway-free-view-button.php

  1. <?php 
  2.  
  3. class MS_Gateway_Free_View_Button extends MS_View { 
  4.  
  5. public function to_html() { 
  6. $fields = $this->prepare_fields(); 
  7. $subscription = $this->data['ms_relationship']; 
  8. $invoice = $subscription->get_current_invoice(); 
  9. $gateway = $this->data['gateway']; 
  10.  
  11. $action_url = MS_Model_Pages::get_page_url( MS_Model_Pages::MS_PAGE_REGISTER ); 
  12. $action_url = apply_filters( 
  13. 'ms_gateway_free_view_button_form_action_url',  
  14. $action_url 
  15. ); 
  16.  
  17. $row_class = 'gateway_' . $gateway->id; 
  18. if ( ! $gateway->is_live_mode() ) { 
  19. $row_class .= ' sandbox-mode'; 
  20.  
  21. ob_start(); 
  22. ?> 
  23. <form action="<?php echo esc_url( $action_url ); ?>" method="post"> 
  24. <?php 
  25. foreach ( $fields as $field ) { 
  26. MS_Helper_Html::html_element( $field ); 
  27. ?> 
  28. </form> 
  29. <?php 
  30. $payment_form = apply_filters( 
  31. 'ms_gateway_form',  
  32. ob_get_clean(),  
  33. $gateway,  
  34. $invoice,  
  35. $this 
  36. ); 
  37.  
  38. ob_start(); 
  39. ?> 
  40. <tr class="<?php echo esc_attr( $row_class ); ?>"> 
  41. <td class="ms-buy-now-column" colspan="2"> 
  42. <?php echo $payment_form; ?> 
  43. </td> 
  44. </tr> 
  45. <?php 
  46. $html = ob_get_clean(); 
  47.  
  48. $html = apply_filters( 
  49. 'ms_gateway_button-' . $gateway->id,  
  50. $html,  
  51. $this 
  52. ); 
  53.  
  54. $html = apply_filters( 
  55. 'ms_gateway_button',  
  56. $html,  
  57. $gateway->id,  
  58. $this 
  59. ); 
  60.  
  61. return $html; 
  62.  
  63. private function prepare_fields() { 
  64. $gateway = $this->data['gateway']; 
  65. $subscription = $this->data['ms_relationship']; 
  66.  
  67. $fields = array( 
  68. '_wpnonce' => array( 
  69. 'id' => '_wpnonce',  
  70. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  71. 'value' => wp_create_nonce( "{$gateway->id}_{$subscription->id}" ),  
  72. ),  
  73. 'gateway' => array( 
  74. 'id' => 'gateway',  
  75. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  76. 'value' => $gateway->id,  
  77. ),  
  78. 'ms_relationship_id' => array( 
  79. 'id' => 'ms_relationship_id',  
  80. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  81. 'value' => $subscription->id,  
  82. ),  
  83. 'step' => array( 
  84. 'id' => 'step',  
  85. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  86. 'value' => $this->data['step'],  
  87. ),  
  88. ); 
  89.  
  90. if ( false !== strpos( $gateway->pay_button_url, '://' ) ) { 
  91. $fields['submit'] = array( 
  92. 'id' => 'submit',  
  93. 'type' => MS_Helper_Html::INPUT_TYPE_IMAGE,  
  94. 'value' => $gateway->pay_button_url,  
  95. ); 
  96. } else { 
  97. $fields['submit'] = array( 
  98. 'id' => 'submit',  
  99. 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT,  
  100. 'value' => $gateway->pay_button_url 
  101. ? $gateway->pay_button_url 
  102. : __( 'Signup', 'membership2' ),  
  103. ); 
  104.  
  105. return $fields; 
.