MS_Gateway_Stripe_View_Button

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