MS_Gateway_Stripe_View_Button

The Membership 2 MS Gateway Stripe View Button class.

Defined (1)

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

/app/gateway/stripe/view/class-ms-gateway-stripe-view-button.php  
  1. class MS_Gateway_Stripe_View_Button extends MS_View { 
  2.  
  3. public function to_html() { 
  4. $fields = $this->prepare_fields(); 
  5. $subscription = $this->data['ms_relationship']; 
  6. $invoice = $subscription->get_current_invoice(); 
  7. $member = MS_Model_Member::get_current_member(); 
  8. $gateway = $this->data['gateway']; 
  9.  
  10. // Stripe is using Ajax, so the URL is empty. 
  11. $action_url = apply_filters( 
  12. 'ms_gateway_stripe_view_button_form_action_url',  
  13. '' 
  14. ); 
  15.  
  16. $row_class = 'gateway_' . $gateway->id; 
  17. if ( ! $gateway->is_live_mode() ) { 
  18. $row_class .= ' sandbox-mode'; 
  19.  
  20. ob_start(); 
  21. ?> 
  22. <form action="<?php echo esc_url( $action_url ); ?>" method="post"> 
  23. <?php 
  24. foreach ( $fields as $field ) { 
  25. MS_Helper_Html::html_element( $field ); 
  26. ?> 
  27. <script 
  28. src="https://checkout.stripe.com/checkout.js" class="stripe-button" 
  29. data-key="<?php echo esc_attr( $gateway->get_publishable_key() ); ?>" 
  30. data-amount="<?php echo esc_attr( absint( $invoice->total * 100 ) ); //amount in cents ?>" 
  31. data-name="<?php echo esc_attr( bloginfo( 'name' ) ); ?>" 
  32. data-description="<?php echo esc_attr( strip_tags( $invoice->short_description ) ); ?>" 
  33. data-currency="<?php echo esc_attr( $invoice->currency ); ?>" 
  34. data-panel-label="<?php echo esc_attr( $gateway->pay_button_url ); ?>" 
  35. data-label="<?php echo esc_attr( $gateway->pay_button_url ); ?>" 
  36. data-email="<?php echo esc_attr( $member->email ); ?>" 
  37. </script> 
  38. </form> 
  39. <?php 
  40. $payment_form = apply_filters( 
  41. 'ms_gateway_form',  
  42. ob_get_clean(),  
  43. $gateway,  
  44. $invoice,  
  45. $this 
  46. ); 
  47.  
  48. ob_start(); 
  49. ?> 
  50. <tr class="<?php echo esc_attr( $row_class ); ?>"> 
  51. <td class="ms-buy-now-column" colspan="2"> 
  52. <?php echo $payment_form; ?> 
  53. </td> 
  54. </tr> 
  55. <?php 
  56. $html = ob_get_clean(); 
  57.  
  58. $html = apply_filters( 
  59. 'ms_gateway_button-' . $gateway->id,  
  60. $html,  
  61. $this 
  62. ); 
  63.  
  64. return $html; 
  65.  
  66. private function prepare_fields() { 
  67. $gateway = $this->data['gateway']; 
  68. $subscription = $this->data['ms_relationship']; 
  69.  
  70. $fields = array( 
  71. '_wpnonce' => array( 
  72. 'id' => '_wpnonce',  
  73. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  74. 'value' => wp_create_nonce( 
  75. $gateway->id . '_' . $subscription->id 
  76. ),  
  77. ),  
  78. 'gateway' => array( 
  79. 'id' => 'gateway',  
  80. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  81. 'value' => $gateway->id,  
  82. ),  
  83. 'ms_relationship_id' => array( 
  84. 'id' => 'ms_relationship_id',  
  85. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  86. 'value' => $subscription->id,  
  87. ),  
  88. 'step' => array( 
  89. 'id' => 'step',  
  90. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  91. 'value' => $this->data['step'],  
  92. ),  
  93. ); 
  94.  
  95. return $fields;