/app/gateway/manual/class-ms-gateway-manual.php

  1. <?php 
  2. /** 
  3. * Manual Gateway. 
  4. * 
  5. * Process manual payments (Eg. check, bank transfer) 
  6. * 
  7. * Persisted by parent class MS_Model_Option. Singleton. 
  8. * 
  9. * @since 1.0.0 
  10. * @package Membership2 
  11. * @subpackage Model 
  12. */ 
  13. class MS_Gateway_Manual extends MS_Gateway { 
  14.  
  15. const ID = 'manual'; 
  16.  
  17. /** 
  18. * Gateway singleton instance. 
  19. * 
  20. * @since 1.0.0 
  21. * @var string $instance 
  22. */ 
  23. public static $instance; 
  24.  
  25. /** 
  26. * Payment information for customer. 
  27. * 
  28. * The payment procedures like bank account, agency, etc. 
  29. * 
  30. * @since 1.0.0 
  31. * @var string $payment_info 
  32. */ 
  33. protected $payment_info; 
  34.  
  35.  
  36. /** 
  37. * Hook to show payment info. 
  38. * This is called by the MS_Factory 
  39. * 
  40. * @since 1.0.0 
  41. */ 
  42. public function after_load() { 
  43. parent::after_load(); 
  44.  
  45. $this->id = self::ID; 
  46. $this->name = __( 'Manual Payment Gateway', 'membership2' ); 
  47. $this->description = __( '(Bank orders, cash, etc)', 'membership2' ); 
  48. $this->group = __( 'Manual Payment', 'membership2' ); 
  49. $this->manual_payment = true; // Recurring billed/paid manually 
  50. $this->pro_rate = true; 
  51.  
  52. if ( $this->active ) { 
  53. $this->add_action( 
  54. 'ms_controller_gateway_purchase_info_content',  
  55. 'purchase_info_content' 
  56. ); 
  57.  
  58. /** 
  59. * Show manual purchase/payment information. 
  60. * 
  61. * Returns a default messsage if gateway is not configured. 
  62. * 
  63. * @hook ms_controller_gateway_purchase_info_content 
  64. * 
  65. * @since 1.0.0 
  66. * @return string The payment info. 
  67. */ 
  68. public function purchase_info_content() { 
  69. static $Processed = false; 
  70.  
  71. /** 
  72. * If some plugin calls `the_content()` multiple times then this 
  73. * function will also run multiple times. 
  74. * We want to process the details only once, so we have this condition! 
  75. */ 
  76. if ( ! $Processed ) { 
  77. $Processed = true; 
  78.  
  79. do_action( 
  80. 'ms_gateway_manual_purchase_info_content_before',  
  81. $this 
  82. ); 
  83.  
  84. if ( empty( $this->payment_info ) ) { 
  85. $link = MS_Controller_Plugin::get_admin_url( 'settings' ); 
  86. ob_start(); 
  87. ?> 
  88. <?php _e( 'This is only an example of manual payment gateway instructions', 'membership2' ); ?> 
  89. <br /> 
  90. <?php 
  91. printf( 
  92. __( 'Edit it %shere%s', 'membership2' ),  
  93. '<a href="' . $link . '">',  
  94. '</a>' 
  95. ); 
  96. ?> 
  97. <br /><br /> 
  98. <?php _e( 'Name: Example name.', 'membership2' ); ?> 
  99. <br /> 
  100. <?php _e( 'Bank: Example bank.', 'membership2' ); ?> 
  101. <br /> 
  102. <?php _e( 'Bank account: Example bank account 1234.', 'membership2' ); ?> 
  103. <br /> 
  104. <?php 
  105. $this->payment_info = ob_get_clean(); 
  106.  
  107. $this->payment_info = wpautop( $this->payment_info ); 
  108.  
  109. if ( ! empty( $_POST['ms_relationship_id'] ) ) { 
  110. $subscription = MS_Factory::load( 
  111. 'MS_Model_Relationship',  
  112. $_POST['ms_relationship_id'] 
  113. ); 
  114. $invoice = $subscription->get_current_invoice(); 
  115. $this->payment_info .= sprintf( 
  116. '<div class="ms-manual-price">%s: <span class="ms-price">%s%s</span></div>',  
  117. __( 'Total value', 'membership2' ),  
  118. $invoice->currency,  
  119. $invoice->total 
  120. ); 
  121.  
  122. // The user did make his intention to pay the invoice. Set status 
  123. // to billed. 
  124. $invoice->status = MS_Model_Invoice::STATUS_BILLED; 
  125. $invoice->save(); 
  126.  
  127. return apply_filters( 
  128. 'ms_gateway_manual_purchase_info_content',  
  129. $this->payment_info 
  130. ); 
  131.  
  132. /** 
  133. * Verify required fields. 
  134. * 
  135. * @since 1.0.0 
  136. * @return boolean True if configured. 
  137. */ 
  138. public function is_configured() { 
  139. $is_configured = true; 
  140. $required = array( 'payment_info' ); 
  141.  
  142. foreach ( $required as $field ) { 
  143. if ( empty( $this->$field ) ) { 
  144. $is_configured = false; 
  145. break; 
  146.  
  147. return apply_filters( 
  148. 'ms_gateway_manual_is_configured',  
  149. $is_configured 
  150. ); 
  151.  
  152. /** 
  153. * Validate specific property before set. 
  154. * 
  155. * @since 1.0.0 
  156. * 
  157. * @access public 
  158. * @param string $property The name of a property to associate. 
  159. * @param mixed $value The value of a property. 
  160. */ 
  161. public function __set( $property, $value ) { 
  162. if ( property_exists( $this, $property ) ) { 
  163. switch ( $property ) { 
  164. case 'payment_info': 
  165. $this->$property = wp_kses_post( $value ); 
  166. break; 
  167.  
  168. default: 
  169. parent::__set( $property, $value ); 
  170. break; 
  171.  
  172. do_action( 
  173. 'ms_gateway_manual__set_after',  
  174. $property,  
  175. $value,  
  176. $this 
  177. ); 
  178.  
.