PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/membership/app/gateway/manual/class-ms-gateway-manual.php

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