MS_Gateway_Manual

Manual Gateway.

Defined (1)

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

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