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. $stripe_data = array( 
  21. 'name' => get_bloginfo( 'name' ),  
  22. 'description' => strip_tags( $invoice->short_description ),  
  23. 'label' => $gateway->pay_button_url,  
  24. ); 
  25.  
  26. /** 
  27. * Users can change details (like the title or description) of the 
  28. * stripe checkout popup. 
  29. * @since 1.0.2.4 
  30. * @var array 
  31. */ 
  32. $stripe_data = apply_filters( 
  33. 'ms_gateway_stripe_form_details',  
  34. $stripe_data,  
  35. $invoice 
  36. ); 
  37.  
  38. $stripe_data['email'] = $member->email; 
  39. $stripe_data['key'] = $gateway->get_publishable_key(); 
  40. $stripe_data['currency'] = $invoice->currency; 
  41. $stripe_data['amount'] = ceil(abs( $invoice->total * 100 )); // Amount in cents. 
  42.  
  43. $stripe_data = apply_filters( 
  44. 'ms_gateway_stripe_form_details_after',  
  45. $stripe_data,  
  46. $invoice 
  47. ); 
  48.  
  49. ob_start(); 
  50. ?> 
  51. <form action="<?php echo esc_url( $action_url ); ?>" method="post"> 
  52. <?php 
  53. foreach ( $fields as $field ) { 
  54. MS_Helper_Html::html_element( $field ); 
  55. ?> 
  56. <script 
  57. src="https://checkout.stripe.com/checkout.js" class="stripe-button" 
  58. <?php 
  59. foreach ( $stripe_data as $key => $value ) { 
  60. printf( 
  61. 'data-%s="%s" ',  
  62. esc_attr( $key ),  
  63. esc_attr( $value ) 
  64. ); 
  65. ?> 
  66. ></script> 
  67. </form> 
  68. <?php 
  69. $payment_form = apply_filters( 
  70. 'ms_gateway_form',  
  71. ob_get_clean(),  
  72. $gateway,  
  73. $invoice,  
  74. $this 
  75. ); 
  76.  
  77. ob_start(); 
  78. ?> 
  79. <tr class="<?php echo esc_attr( $row_class ); ?>"> 
  80. <td class="ms-buy-now-column" colspan="2"> 
  81. <?php echo $payment_form; ?> 
  82. </td> 
  83. </tr> 
  84. <?php 
  85. $html = ob_get_clean(); 
  86.  
  87. $html = apply_filters( 
  88. 'ms_gateway_button-' . $gateway->id,  
  89. $html,  
  90. $this 
  91. ); 
  92.  
  93. return $html; 
  94.  
  95. private function prepare_fields() { 
  96. $gateway = $this->data['gateway']; 
  97. $subscription = $this->data['ms_relationship']; 
  98.  
  99. $fields = array( 
  100. '_wpnonce' => array( 
  101. 'id' => '_wpnonce',  
  102. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  103. 'value' => wp_create_nonce( 
  104. $gateway->id . '_' . $subscription->id 
  105. ),  
  106. ),  
  107. 'gateway' => array( 
  108. 'id' => 'gateway',  
  109. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  110. 'value' => $gateway->id,  
  111. ),  
  112. 'ms_relationship_id' => array( 
  113. 'id' => 'ms_relationship_id',  
  114. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  115. 'value' => $subscription->id,  
  116. ),  
  117. 'step' => array( 
  118. 'id' => 'step',  
  119. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  120. 'value' => $this->data['step'],  
  121. ),  
  122. ); 
  123.  
  124. return $fields;