MS_Gateway_Paypalsingle_View_Button

The Membership 2 MS Gateway Paypalsingle View Button class.

Defined (1)

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

/app/gateway/paypalsingle/view/class-ms-gateway-paypalsingle-view-button.php  
  1. class MS_Gateway_Paypalsingle_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. $gateway = $this->data['gateway']; 
  8.  
  9. $action_url = apply_filters( 
  10. 'ms_gateway_paypalsingle_view_button_form_action_url',  
  11. $this->data['action_url'] 
  12. ); 
  13.  
  14. $row_class = 'gateway_' . $gateway->id; 
  15. if ( ! $gateway->is_live_mode() ) { 
  16. $row_class .= ' sandbox-mode'; 
  17.  
  18. ob_start(); 
  19. ?> 
  20. <form action="<?php echo esc_url( $action_url ); ?>" method="post"> 
  21. <?php 
  22. foreach ( $fields as $field ) { 
  23. MS_Helper_Html::html_element( $field ); 
  24. ?> 
  25. <img alt="" border="0" width="1" height="1" src="https://www.paypal.com/en_US/i/scr/pixel.gif" > 
  26. </form> 
  27. <?php 
  28. $payment_form = apply_filters( 
  29. 'ms_gateway_form',  
  30. ob_get_clean(),  
  31. $gateway,  
  32. $invoice,  
  33. $this 
  34. ); 
  35.  
  36. ob_start(); 
  37. ?> 
  38. <tr class="<?php echo esc_attr( $row_class ); ?>"> 
  39. <td class="ms-buy-now-column" colspan="2"> 
  40. <?php echo $payment_form; ?> 
  41. </td> 
  42. </tr> 
  43. <?php 
  44. $html = ob_get_clean(); 
  45.  
  46. $html = apply_filters( 
  47. 'ms_gateway_button-' . $gateway->id,  
  48. $html,  
  49. $this 
  50. ); 
  51.  
  52. $html = apply_filters( 
  53. 'ms_gateway_button',  
  54. $html,  
  55. $gateway->id,  
  56. $this 
  57. ); 
  58.  
  59. return $html; 
  60.  
  61. /** 
  62. * Prepare the PayPal IPN fields 
  63. * Details here: 
  64. * https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/ 
  65. * @since 1.0.0 
  66. * @return array 
  67. */ 
  68. private function prepare_fields() { 
  69. $subscription = $this->data['ms_relationship']; 
  70. $membership = $subscription->get_membership(); 
  71.  
  72. if ( 0 === $membership->price ) { 
  73. return; 
  74.  
  75. $gateway = $this->data['gateway']; 
  76. $invoice = $subscription->get_current_invoice(); 
  77.  
  78. $fields = array( 
  79. 'business' => array( 
  80. 'id' => 'business',  
  81. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  82. 'value' => $gateway->paypal_email,  
  83. ),  
  84. 'cmd' => array( 
  85. 'id' => 'cmd',  
  86. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  87. 'value' => '_xclick',  
  88. ),  
  89. 'bn' => array( 
  90. 'id' => 'bn',  
  91. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  92. 'value' => 'incsub_SP',  
  93. ),  
  94. 'item_number' => array( 
  95. 'id' => 'item_number',  
  96. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  97. 'value' => $subscription->membership_id,  
  98. ),  
  99. 'item_name' => array( 
  100. 'id' => 'item_name',  
  101. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  102. 'value' => $membership->name,  
  103. ),  
  104. 'amount' => array( 
  105. 'id' => 'amount',  
  106. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  107. 'value' => MS_Helper_Billing::format_price( $invoice->total ),  
  108. ),  
  109. 'currency_code' => array( 
  110. 'id' => 'currency_code',  
  111. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  112. 'value' => $invoice->currency,  
  113. ),  
  114. 'return' => array( 
  115. 'id' => 'return',  
  116. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  117. 'value' => esc_url_raw( 
  118. add_query_arg( 
  119. array( 'ms_relationship_id' => $subscription->id ),  
  120. MS_Model_Pages::get_page_url( MS_Model_Pages::MS_PAGE_REG_COMPLETE, false ) 
  121. ),  
  122. ),  
  123. 'cancel_return' => array( 
  124. 'id' => 'cancel_return',  
  125. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  126. 'value' => MS_Model_Pages::get_page_url( MS_Model_Pages::MS_PAGE_REGISTER ),  
  127. ),  
  128. 'notify_url' => array( 
  129. 'id' => 'notify_url',  
  130. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  131. 'value' => $gateway->get_return_url(),  
  132. ),  
  133. 'lc' => array( 
  134. 'id' => 'lc',  
  135. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  136. 'value' => $gateway->paypal_site,  
  137. ),  
  138. 'invoice' => array( 
  139. 'id' => 'invoice',  
  140. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  141. 'value' => $invoice->id,  
  142. ),  
  143. ); 
  144.  
  145. // Don't send to paypal if free 
  146. if ( 0 === $invoice->total ) { 
  147. $fields = array( 
  148. 'gateway' => array( 
  149. 'id' => 'gateway',  
  150. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  151. 'value' => $gateway->id,  
  152. ),  
  153. 'ms_relationship_id' => array( 
  154. 'id' => 'ms_relationship_id',  
  155. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  156. 'value' => $subscription->id,  
  157. ),  
  158. 'step' => array( 
  159. 'id' => 'step',  
  160. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  161. 'value' => MS_Controller_Frontend::STEP_PROCESS_PURCHASE,  
  162. ),  
  163. '_wpnonce' => array( 
  164. 'id' => '_wpnonce',  
  165. 'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,  
  166. 'value' => wp_create_nonce( 
  167. $gateway->id . '_' .$subscription->id 
  168. ),  
  169. ),  
  170. ); 
  171. $this->data['action_url'] = null; 
  172. } else { 
  173. if ( $gateway->is_live_mode() ) { 
  174. $this->data['action_url'] = 'https://www.paypal.com/cgi-bin/webscr'; 
  175. } else { 
  176. $this->data['action_url'] = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; 
  177.  
  178. $fields['submit'] = array( 
  179. 'id' => 'submit',  
  180. 'type' => MS_Helper_Html::INPUT_TYPE_IMAGE,  
  181. 'value' => 'https://www.paypalobjects.com/en_US/i/btn/x-click-but06.gif',  
  182. 'alt' => __( 'PayPal - The safer, easier way to pay online', 'membership2' ),  
  183. ); 
  184.  
  185. // custom pay button defined in gateway settings 
  186. $custom_label = $gateway->pay_button_url; 
  187. if ( ! empty( $custom_label ) ) { 
  188. if ( false !== strpos( $custom_label, '://' ) ) { 
  189. $fields['submit']['value'] = $custom_label; 
  190. } else { 
  191. $fields['submit'] = array( 
  192. 'id' => 'submit',  
  193. 'type' => MS_Helper_Html::INPUT_TYPE_SUBMIT,  
  194. 'value' => $custom_label,  
  195. ); 
  196.  
  197. return apply_filters( 
  198. 'ms_gateway_paypalsingle_view_prepare_fields',  
  199. $fields 
  200. );