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. ob_start(); 
  44. ?> 
  45. <form action="<?php echo esc_url( $action_url ); ?>" method="post"> 
  46. <?php 
  47. foreach ( $fields as $field ) { 
  48. MS_Helper_Html::html_element( $field ); 
  49. ?> 
  50. <script 
  51. src="https://checkout.stripe.com/checkout.js" class="stripe-button" 
  52. <?php 
  53. foreach ( $stripe_data as $key => $value ) { 
  54. printf( 
  55. 'data-%s="%s" ',  
  56. esc_attr( $key ),  
  57. esc_attr( $value ) 
  58. ); 
  59. ?> 
  60. ></script> 
  61. </form> 
  62. <?php 
  63. $payment_form = apply_filters( 
  64. 'ms_gateway_form',  
  65. ob_get_clean(),  
  66. $gateway,  
  67. $invoice,  
  68. $this 
  69. ); 
  70.  
  71. ob_start(); 
  72. ?> 
  73. <tr class="<?php echo esc_attr( $row_class ); ?>"> 
  74. <td class="ms-buy-now-column" colspan="2"> 
  75. <?php echo $payment_form; ?> 
  76. </td> 
  77. </tr> 
  78. <?php 
  79. $html = ob_get_clean(); 
  80.  
  81. $html = apply_filters( 
  82. 'ms_gateway_button-' . $gateway->id,  
  83. $html,  
  84. $this 
  85. ); 
  86.  
  87. return $html; 
  88.  
  89. private function prepare_fields() { 
  90. $gateway = $this->data['gateway']; 
  91. $subscription = $this->data['ms_relationship']; 
  92.  
  93. $fields = array( 
  94. '_wpnonce' => array( 
  95. 'id' => '_wpnonce',  
  96. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  97. 'value' => wp_create_nonce( 
  98. $gateway->id . '_' . $subscription->id 
  99. ),  
  100. ),  
  101. 'gateway' => array( 
  102. 'id' => 'gateway',  
  103. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  104. 'value' => $gateway->id,  
  105. ),  
  106. 'ms_relationship_id' => array( 
  107. 'id' => 'ms_relationship_id',  
  108. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  109. 'value' => $subscription->id,  
  110. ),  
  111. 'step' => array( 
  112. 'id' => 'step',  
  113. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  114. 'value' => $this->data['step'],  
  115. ),  
  116. ); 
  117.  
  118. return $fields;