@@ -12,180 +12,180 @@ |
||
| 12 | 12 | class EE_Currency extends EE_Base_Class |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** Currency COde @var CUR_code */ |
|
| 16 | - protected $_CUR_code = null; |
|
| 17 | - /** Currency Name Singular @var CUR_single */ |
|
| 18 | - protected $_CUR_single = null; |
|
| 19 | - /** Currency Name Plural @var CUR_plural */ |
|
| 20 | - protected $_CUR_plural = null; |
|
| 21 | - /** Currency Sign @var CUR_sign */ |
|
| 22 | - protected $_CUR_sign = null; |
|
| 23 | - /** Currency Decimal Places @var CUR_dec_plc */ |
|
| 24 | - protected $_CUR_dec_plc = null; |
|
| 25 | - /** Active? @var CUR_active */ |
|
| 26 | - protected $_CUR_active = null; |
|
| 27 | - protected $_Payment_Method; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * |
|
| 31 | - * @param array $props_n_values incoming values |
|
| 32 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 33 | - * used.) |
|
| 34 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 35 | - * date_format and the second value is the time format |
|
| 36 | - * @return EE_Attendee |
|
| 37 | - */ |
|
| 38 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 39 | - { |
|
| 40 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 41 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param array $props_n_values incoming values from the database |
|
| 47 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 48 | - * the website will be used. |
|
| 49 | - * @return EE_Attendee |
|
| 50 | - */ |
|
| 51 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 52 | - { |
|
| 53 | - return new self($props_n_values, true, $timezone); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Gets code |
|
| 58 | - * |
|
| 59 | - * @return string |
|
| 60 | - */ |
|
| 61 | - public function code() |
|
| 62 | - { |
|
| 63 | - return $this->get('CUR_code'); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Sets code |
|
| 68 | - * |
|
| 69 | - * @param string $code |
|
| 70 | - * @return boolean |
|
| 71 | - */ |
|
| 72 | - public function set_code($code) |
|
| 73 | - { |
|
| 74 | - return $this->set('CUR_code', $code); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Gets active |
|
| 79 | - * |
|
| 80 | - * @return boolean |
|
| 81 | - */ |
|
| 82 | - public function active() |
|
| 83 | - { |
|
| 84 | - return $this->get('CUR_active'); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Sets active |
|
| 89 | - * |
|
| 90 | - * @param boolean $active |
|
| 91 | - * @return boolean |
|
| 92 | - */ |
|
| 93 | - public function set_active($active) |
|
| 94 | - { |
|
| 95 | - return $this->set('CUR_active', $active); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Gets dec_plc |
|
| 100 | - * |
|
| 101 | - * @return int |
|
| 102 | - */ |
|
| 103 | - public function dec_plc() |
|
| 104 | - { |
|
| 105 | - return $this->get('CUR_dec_plc'); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Sets dec_plc |
|
| 110 | - * |
|
| 111 | - * @param int $dec_plc |
|
| 112 | - * @return boolean |
|
| 113 | - */ |
|
| 114 | - public function set_dec_plc($dec_plc) |
|
| 115 | - { |
|
| 116 | - return $this->set('CUR_dec_plc', $dec_plc); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Gets plural |
|
| 121 | - * |
|
| 122 | - * @return string |
|
| 123 | - */ |
|
| 124 | - public function plural_name() |
|
| 125 | - { |
|
| 126 | - return $this->get('CUR_plural'); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Sets plural |
|
| 131 | - * |
|
| 132 | - * @param string $plural |
|
| 133 | - * @return boolean |
|
| 134 | - */ |
|
| 135 | - public function set_plural_name($plural) |
|
| 136 | - { |
|
| 137 | - return $this->set('CUR_plural', $plural); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Gets sign |
|
| 142 | - * |
|
| 143 | - * @return string |
|
| 144 | - */ |
|
| 145 | - public function sign() |
|
| 146 | - { |
|
| 147 | - return $this->get('CUR_sign'); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Sets sign |
|
| 152 | - * |
|
| 153 | - * @param string $sign |
|
| 154 | - * @return boolean |
|
| 155 | - */ |
|
| 156 | - public function set_sign($sign) |
|
| 157 | - { |
|
| 158 | - return $this->set('CUR_sign', $sign); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Gets single |
|
| 163 | - * |
|
| 164 | - * @return string |
|
| 165 | - */ |
|
| 166 | - public function singular_name() |
|
| 167 | - { |
|
| 168 | - return $this->get('CUR_single'); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Sets single |
|
| 173 | - * |
|
| 174 | - * @param string $single |
|
| 175 | - * @return boolean |
|
| 176 | - */ |
|
| 177 | - public function set_singular_name($single) |
|
| 178 | - { |
|
| 179 | - return $this->set('CUR_single', $single); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Gets a prettier name |
|
| 184 | - * |
|
| 185 | - * @return string |
|
| 186 | - */ |
|
| 187 | - public function name() |
|
| 188 | - { |
|
| 189 | - return sprintf(__("%s (%s)", "event_espresso"), $this->code(), $this->plural_name()); |
|
| 190 | - } |
|
| 15 | + /** Currency COde @var CUR_code */ |
|
| 16 | + protected $_CUR_code = null; |
|
| 17 | + /** Currency Name Singular @var CUR_single */ |
|
| 18 | + protected $_CUR_single = null; |
|
| 19 | + /** Currency Name Plural @var CUR_plural */ |
|
| 20 | + protected $_CUR_plural = null; |
|
| 21 | + /** Currency Sign @var CUR_sign */ |
|
| 22 | + protected $_CUR_sign = null; |
|
| 23 | + /** Currency Decimal Places @var CUR_dec_plc */ |
|
| 24 | + protected $_CUR_dec_plc = null; |
|
| 25 | + /** Active? @var CUR_active */ |
|
| 26 | + protected $_CUR_active = null; |
|
| 27 | + protected $_Payment_Method; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * |
|
| 31 | + * @param array $props_n_values incoming values |
|
| 32 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 33 | + * used.) |
|
| 34 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 35 | + * date_format and the second value is the time format |
|
| 36 | + * @return EE_Attendee |
|
| 37 | + */ |
|
| 38 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 39 | + { |
|
| 40 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 41 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param array $props_n_values incoming values from the database |
|
| 47 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 48 | + * the website will be used. |
|
| 49 | + * @return EE_Attendee |
|
| 50 | + */ |
|
| 51 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 52 | + { |
|
| 53 | + return new self($props_n_values, true, $timezone); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Gets code |
|
| 58 | + * |
|
| 59 | + * @return string |
|
| 60 | + */ |
|
| 61 | + public function code() |
|
| 62 | + { |
|
| 63 | + return $this->get('CUR_code'); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Sets code |
|
| 68 | + * |
|
| 69 | + * @param string $code |
|
| 70 | + * @return boolean |
|
| 71 | + */ |
|
| 72 | + public function set_code($code) |
|
| 73 | + { |
|
| 74 | + return $this->set('CUR_code', $code); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Gets active |
|
| 79 | + * |
|
| 80 | + * @return boolean |
|
| 81 | + */ |
|
| 82 | + public function active() |
|
| 83 | + { |
|
| 84 | + return $this->get('CUR_active'); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Sets active |
|
| 89 | + * |
|
| 90 | + * @param boolean $active |
|
| 91 | + * @return boolean |
|
| 92 | + */ |
|
| 93 | + public function set_active($active) |
|
| 94 | + { |
|
| 95 | + return $this->set('CUR_active', $active); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Gets dec_plc |
|
| 100 | + * |
|
| 101 | + * @return int |
|
| 102 | + */ |
|
| 103 | + public function dec_plc() |
|
| 104 | + { |
|
| 105 | + return $this->get('CUR_dec_plc'); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Sets dec_plc |
|
| 110 | + * |
|
| 111 | + * @param int $dec_plc |
|
| 112 | + * @return boolean |
|
| 113 | + */ |
|
| 114 | + public function set_dec_plc($dec_plc) |
|
| 115 | + { |
|
| 116 | + return $this->set('CUR_dec_plc', $dec_plc); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Gets plural |
|
| 121 | + * |
|
| 122 | + * @return string |
|
| 123 | + */ |
|
| 124 | + public function plural_name() |
|
| 125 | + { |
|
| 126 | + return $this->get('CUR_plural'); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Sets plural |
|
| 131 | + * |
|
| 132 | + * @param string $plural |
|
| 133 | + * @return boolean |
|
| 134 | + */ |
|
| 135 | + public function set_plural_name($plural) |
|
| 136 | + { |
|
| 137 | + return $this->set('CUR_plural', $plural); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Gets sign |
|
| 142 | + * |
|
| 143 | + * @return string |
|
| 144 | + */ |
|
| 145 | + public function sign() |
|
| 146 | + { |
|
| 147 | + return $this->get('CUR_sign'); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Sets sign |
|
| 152 | + * |
|
| 153 | + * @param string $sign |
|
| 154 | + * @return boolean |
|
| 155 | + */ |
|
| 156 | + public function set_sign($sign) |
|
| 157 | + { |
|
| 158 | + return $this->set('CUR_sign', $sign); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Gets single |
|
| 163 | + * |
|
| 164 | + * @return string |
|
| 165 | + */ |
|
| 166 | + public function singular_name() |
|
| 167 | + { |
|
| 168 | + return $this->get('CUR_single'); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Sets single |
|
| 173 | + * |
|
| 174 | + * @param string $single |
|
| 175 | + * @return boolean |
|
| 176 | + */ |
|
| 177 | + public function set_singular_name($single) |
|
| 178 | + { |
|
| 179 | + return $this->set('CUR_single', $single); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Gets a prettier name |
|
| 184 | + * |
|
| 185 | + * @return string |
|
| 186 | + */ |
|
| 187 | + public function name() |
|
| 188 | + { |
|
| 189 | + return sprintf(__("%s (%s)", "event_espresso"), $this->code(), $this->plural_name()); |
|
| 190 | + } |
|
| 191 | 191 | } |
@@ -10,220 +10,220 @@ |
||
| 10 | 10 | class EE_Question_Option extends EE_Soft_Delete_Base_Class implements EEI_Duplicatable |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Question Option Opt Group Name |
|
| 15 | - * |
|
| 16 | - * @access protected |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - protected $_QSO_opt_group = null; |
|
| 20 | - |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * |
|
| 24 | - * @param array $props_n_values incoming values |
|
| 25 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 26 | - * used.) |
|
| 27 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 28 | - * date_format and the second value is the time format |
|
| 29 | - * @return EE_Attendee |
|
| 30 | - */ |
|
| 31 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 32 | - { |
|
| 33 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 34 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @param array $props_n_values incoming values from the database |
|
| 40 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 41 | - * the website will be used. |
|
| 42 | - * @return EE_Attendee |
|
| 43 | - */ |
|
| 44 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 45 | - { |
|
| 46 | - return new self($props_n_values, true, $timezone); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Sets the option's key value |
|
| 52 | - * |
|
| 53 | - * @param string $value |
|
| 54 | - * @return bool success |
|
| 55 | - */ |
|
| 56 | - public function set_value($value) |
|
| 57 | - { |
|
| 58 | - $this->set('QSO_value', $value); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Sets the option's Display Text |
|
| 64 | - * |
|
| 65 | - * @param string $text |
|
| 66 | - * @return bool success |
|
| 67 | - */ |
|
| 68 | - public function set_desc($text) |
|
| 69 | - { |
|
| 70 | - $this->set('QSO_desc', $text); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Sets the order for this option |
|
| 76 | - * |
|
| 77 | - * @access public |
|
| 78 | - * @param integer $order |
|
| 79 | - * @return bool $success |
|
| 80 | - */ |
|
| 81 | - public function set_order($order) |
|
| 82 | - { |
|
| 83 | - $this->set('QSO_order', $order); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Sets the ID of the related question |
|
| 89 | - * |
|
| 90 | - * @param int $question_ID |
|
| 91 | - * @return bool success |
|
| 92 | - */ |
|
| 93 | - public function set_question_ID($question_ID) |
|
| 94 | - { |
|
| 95 | - $this->set('QST_ID', $question_ID); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Sets the option's opt_group |
|
| 101 | - * |
|
| 102 | - * @param string $text |
|
| 103 | - * @return bool success |
|
| 104 | - */ |
|
| 105 | - public function set_opt_group($text) |
|
| 106 | - { |
|
| 107 | - return $this->_QSO_opt_group = $text; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Gets the option's key value |
|
| 113 | - * |
|
| 114 | - * @return string |
|
| 115 | - */ |
|
| 116 | - public function value() |
|
| 117 | - { |
|
| 118 | - return $this->get('QSO_value'); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Gets the option's display text |
|
| 124 | - * |
|
| 125 | - * @return string |
|
| 126 | - */ |
|
| 127 | - public function desc() |
|
| 128 | - { |
|
| 129 | - return $this->get('QSO_desc'); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Returns whether this option has been deleted or not |
|
| 135 | - * |
|
| 136 | - * @return boolean |
|
| 137 | - */ |
|
| 138 | - public function deleted() |
|
| 139 | - { |
|
| 140 | - return $this->get('QSO_deleted'); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Returns the order or the Question Option |
|
| 146 | - * |
|
| 147 | - * @access public |
|
| 148 | - * @return integer |
|
| 149 | - */ |
|
| 150 | - public function order() |
|
| 151 | - { |
|
| 152 | - return $this->get('QSO_option'); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Gets the related question's ID |
|
| 158 | - * |
|
| 159 | - * @return int |
|
| 160 | - */ |
|
| 161 | - public function question_ID() |
|
| 162 | - { |
|
| 163 | - return $this->get('QST_ID'); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Returns the question related to this question option |
|
| 169 | - * |
|
| 170 | - * @return EE_Question |
|
| 171 | - */ |
|
| 172 | - public function question() |
|
| 173 | - { |
|
| 174 | - return $this->get_first_related('Question'); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Gets the option's opt_group |
|
| 180 | - * |
|
| 181 | - * @return string |
|
| 182 | - */ |
|
| 183 | - public function opt_group() |
|
| 184 | - { |
|
| 185 | - return $this->_QSO_opt_group; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Duplicates this question option. By default the new question option will be for the same question, |
|
| 190 | - * but that can be overriden by setting the 'QST_ID' option |
|
| 191 | - * |
|
| 192 | - * @param array $options { |
|
| 193 | - * @type int $QST_ID the QST_ID attribute of this question option, otherwise it will be for the same question |
|
| 194 | - * as the original |
|
| 195 | - */ |
|
| 196 | - public function duplicate($options = array()) |
|
| 197 | - { |
|
| 198 | - $new_question_option = clone $this; |
|
| 199 | - $new_question_option->set('QSO_ID', null); |
|
| 200 | - if (array_key_exists( |
|
| 201 | - 'QST_ID', |
|
| 202 | - $options |
|
| 203 | - )) {// use array_key_exists instead of isset because NULL might be a valid value |
|
| 204 | - $new_question_option->set_question_ID($options['QST_ID']); |
|
| 205 | - } |
|
| 206 | - $new_question_option->save(); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Gets the QSO_system value |
|
| 211 | - * |
|
| 212 | - * @return string|null |
|
| 213 | - */ |
|
| 214 | - public function system() |
|
| 215 | - { |
|
| 216 | - return $this->get('QSO_system'); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Sets QSO_system |
|
| 221 | - * |
|
| 222 | - * @param string $QSO_system |
|
| 223 | - * @return bool |
|
| 224 | - */ |
|
| 225 | - public function set_system($QSO_system) |
|
| 226 | - { |
|
| 227 | - return $this->set('QSO_system', $QSO_system); |
|
| 228 | - } |
|
| 13 | + /** |
|
| 14 | + * Question Option Opt Group Name |
|
| 15 | + * |
|
| 16 | + * @access protected |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + protected $_QSO_opt_group = null; |
|
| 20 | + |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * |
|
| 24 | + * @param array $props_n_values incoming values |
|
| 25 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 26 | + * used.) |
|
| 27 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 28 | + * date_format and the second value is the time format |
|
| 29 | + * @return EE_Attendee |
|
| 30 | + */ |
|
| 31 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 32 | + { |
|
| 33 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 34 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @param array $props_n_values incoming values from the database |
|
| 40 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 41 | + * the website will be used. |
|
| 42 | + * @return EE_Attendee |
|
| 43 | + */ |
|
| 44 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 45 | + { |
|
| 46 | + return new self($props_n_values, true, $timezone); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Sets the option's key value |
|
| 52 | + * |
|
| 53 | + * @param string $value |
|
| 54 | + * @return bool success |
|
| 55 | + */ |
|
| 56 | + public function set_value($value) |
|
| 57 | + { |
|
| 58 | + $this->set('QSO_value', $value); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Sets the option's Display Text |
|
| 64 | + * |
|
| 65 | + * @param string $text |
|
| 66 | + * @return bool success |
|
| 67 | + */ |
|
| 68 | + public function set_desc($text) |
|
| 69 | + { |
|
| 70 | + $this->set('QSO_desc', $text); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Sets the order for this option |
|
| 76 | + * |
|
| 77 | + * @access public |
|
| 78 | + * @param integer $order |
|
| 79 | + * @return bool $success |
|
| 80 | + */ |
|
| 81 | + public function set_order($order) |
|
| 82 | + { |
|
| 83 | + $this->set('QSO_order', $order); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Sets the ID of the related question |
|
| 89 | + * |
|
| 90 | + * @param int $question_ID |
|
| 91 | + * @return bool success |
|
| 92 | + */ |
|
| 93 | + public function set_question_ID($question_ID) |
|
| 94 | + { |
|
| 95 | + $this->set('QST_ID', $question_ID); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Sets the option's opt_group |
|
| 101 | + * |
|
| 102 | + * @param string $text |
|
| 103 | + * @return bool success |
|
| 104 | + */ |
|
| 105 | + public function set_opt_group($text) |
|
| 106 | + { |
|
| 107 | + return $this->_QSO_opt_group = $text; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Gets the option's key value |
|
| 113 | + * |
|
| 114 | + * @return string |
|
| 115 | + */ |
|
| 116 | + public function value() |
|
| 117 | + { |
|
| 118 | + return $this->get('QSO_value'); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Gets the option's display text |
|
| 124 | + * |
|
| 125 | + * @return string |
|
| 126 | + */ |
|
| 127 | + public function desc() |
|
| 128 | + { |
|
| 129 | + return $this->get('QSO_desc'); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Returns whether this option has been deleted or not |
|
| 135 | + * |
|
| 136 | + * @return boolean |
|
| 137 | + */ |
|
| 138 | + public function deleted() |
|
| 139 | + { |
|
| 140 | + return $this->get('QSO_deleted'); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Returns the order or the Question Option |
|
| 146 | + * |
|
| 147 | + * @access public |
|
| 148 | + * @return integer |
|
| 149 | + */ |
|
| 150 | + public function order() |
|
| 151 | + { |
|
| 152 | + return $this->get('QSO_option'); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Gets the related question's ID |
|
| 158 | + * |
|
| 159 | + * @return int |
|
| 160 | + */ |
|
| 161 | + public function question_ID() |
|
| 162 | + { |
|
| 163 | + return $this->get('QST_ID'); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Returns the question related to this question option |
|
| 169 | + * |
|
| 170 | + * @return EE_Question |
|
| 171 | + */ |
|
| 172 | + public function question() |
|
| 173 | + { |
|
| 174 | + return $this->get_first_related('Question'); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Gets the option's opt_group |
|
| 180 | + * |
|
| 181 | + * @return string |
|
| 182 | + */ |
|
| 183 | + public function opt_group() |
|
| 184 | + { |
|
| 185 | + return $this->_QSO_opt_group; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Duplicates this question option. By default the new question option will be for the same question, |
|
| 190 | + * but that can be overriden by setting the 'QST_ID' option |
|
| 191 | + * |
|
| 192 | + * @param array $options { |
|
| 193 | + * @type int $QST_ID the QST_ID attribute of this question option, otherwise it will be for the same question |
|
| 194 | + * as the original |
|
| 195 | + */ |
|
| 196 | + public function duplicate($options = array()) |
|
| 197 | + { |
|
| 198 | + $new_question_option = clone $this; |
|
| 199 | + $new_question_option->set('QSO_ID', null); |
|
| 200 | + if (array_key_exists( |
|
| 201 | + 'QST_ID', |
|
| 202 | + $options |
|
| 203 | + )) {// use array_key_exists instead of isset because NULL might be a valid value |
|
| 204 | + $new_question_option->set_question_ID($options['QST_ID']); |
|
| 205 | + } |
|
| 206 | + $new_question_option->save(); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Gets the QSO_system value |
|
| 211 | + * |
|
| 212 | + * @return string|null |
|
| 213 | + */ |
|
| 214 | + public function system() |
|
| 215 | + { |
|
| 216 | + return $this->get('QSO_system'); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Sets QSO_system |
|
| 221 | + * |
|
| 222 | + * @param string $QSO_system |
|
| 223 | + * @return bool |
|
| 224 | + */ |
|
| 225 | + public function set_system($QSO_system) |
|
| 226 | + { |
|
| 227 | + return $this->set('QSO_system', $QSO_system); |
|
| 228 | + } |
|
| 229 | 229 | } |
@@ -11,578 +11,578 @@ |
||
| 11 | 11 | class EE_Payment_Method extends EE_Base_Class |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Payment Method type object, which has all the info about this type of payment method, |
|
| 16 | - * including functions for processing payments, to get settings forms, etc. |
|
| 17 | - * |
|
| 18 | - * @var EE_PMT_Base |
|
| 19 | - */ |
|
| 20 | - protected $_type_obj; |
|
| 21 | - |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @param array $props_n_values |
|
| 25 | - * @return EE_Payment_Method |
|
| 26 | - * @throws \EE_Error |
|
| 27 | - */ |
|
| 28 | - public static function new_instance($props_n_values = array()) |
|
| 29 | - { |
|
| 30 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 31 | - return $has_object ? $has_object : new self($props_n_values, false); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @param array $props_n_values |
|
| 37 | - * @return EE_Payment_Method |
|
| 38 | - * @throws \EE_Error |
|
| 39 | - */ |
|
| 40 | - public static function new_instance_from_db($props_n_values = array()) |
|
| 41 | - { |
|
| 42 | - return new self($props_n_values, true); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname. |
|
| 49 | - * Otherwise returns a normal EE_Payment_Method |
|
| 50 | - * |
|
| 51 | - * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically |
|
| 52 | - * the classname minus 'EEPM_') |
|
| 53 | - * @return string |
|
| 54 | - */ |
|
| 55 | - // private static function _payment_method_type($props_n_values) |
|
| 56 | - // { |
|
| 57 | - // EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 58 | - // $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null; |
|
| 59 | - // if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) { |
|
| 60 | - // return 'EEPM_' . $type_string; |
|
| 61 | - // } else { |
|
| 62 | - // return __CLASS__; |
|
| 63 | - // } |
|
| 64 | - // } |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc) |
|
| 69 | - * |
|
| 70 | - * @return boolean |
|
| 71 | - */ |
|
| 72 | - public function active() |
|
| 73 | - { |
|
| 74 | - return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope()); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Sets this PM as active by making it usable within the CART scope. Offline gateways |
|
| 80 | - * are also usable from the admin-scope as well. DOES NOT SAVE it |
|
| 81 | - * |
|
| 82 | - * @throws \EE_Error |
|
| 83 | - */ |
|
| 84 | - public function set_active() |
|
| 85 | - { |
|
| 86 | - $default_scopes = array(EEM_Payment_Method::scope_cart); |
|
| 87 | - if ($this->type_obj() && |
|
| 88 | - $this->type_obj()->payment_occurs() === EE_PMT_Base::offline) { |
|
| 89 | - $default_scopes[] = EEM_Payment_Method::scope_admin; |
|
| 90 | - } |
|
| 91 | - $this->set_scope($default_scopes); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it. |
|
| 97 | - */ |
|
| 98 | - public function deactivate() |
|
| 99 | - { |
|
| 100 | - $this->set_scope(array()); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Gets button_url |
|
| 106 | - * |
|
| 107 | - * @return string |
|
| 108 | - */ |
|
| 109 | - public function button_url() |
|
| 110 | - { |
|
| 111 | - return $this->get('PMD_button_url'); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Sets button_url |
|
| 117 | - * |
|
| 118 | - * @param string $button_url |
|
| 119 | - */ |
|
| 120 | - public function set_button_url($button_url) |
|
| 121 | - { |
|
| 122 | - $this->set('PMD_button_url', $button_url); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Gets debug_mode |
|
| 128 | - * |
|
| 129 | - * @return boolean |
|
| 130 | - */ |
|
| 131 | - public function debug_mode() |
|
| 132 | - { |
|
| 133 | - return $this->get('PMD_debug_mode'); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Sets debug_mode |
|
| 139 | - * |
|
| 140 | - * @param boolean $debug_mode |
|
| 141 | - */ |
|
| 142 | - public function set_debug_mode($debug_mode) |
|
| 143 | - { |
|
| 144 | - $this->set('PMD_debug_mode', $debug_mode); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Gets description |
|
| 150 | - * |
|
| 151 | - * @return string |
|
| 152 | - */ |
|
| 153 | - public function description() |
|
| 154 | - { |
|
| 155 | - return $this->get('PMD_desc'); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Sets description |
|
| 161 | - * |
|
| 162 | - * @param string $description |
|
| 163 | - */ |
|
| 164 | - public function set_description($description) |
|
| 165 | - { |
|
| 166 | - $this->set('PMD_desc', $description); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Gets name |
|
| 172 | - * |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 175 | - public function name() |
|
| 176 | - { |
|
| 177 | - return $this->get('PMD_name'); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Sets name |
|
| 183 | - * |
|
| 184 | - * @param string $name |
|
| 185 | - */ |
|
| 186 | - public function set_name($name) |
|
| 187 | - { |
|
| 188 | - $this->set('PMD_name', $name); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Gets open_by_default |
|
| 194 | - * |
|
| 195 | - * @return boolean |
|
| 196 | - */ |
|
| 197 | - public function open_by_default() |
|
| 198 | - { |
|
| 199 | - return $this->get('PMD_open_by_default'); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Sets open_by_default |
|
| 205 | - * |
|
| 206 | - * @param boolean $open_by_default |
|
| 207 | - */ |
|
| 208 | - public function set_open_by_default($open_by_default) |
|
| 209 | - { |
|
| 210 | - $this->set('PMD_open_by_default', $open_by_default); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Gets order |
|
| 216 | - * |
|
| 217 | - * @return int |
|
| 218 | - */ |
|
| 219 | - public function order() |
|
| 220 | - { |
|
| 221 | - return $this->get('PMD_order'); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * Sets order |
|
| 227 | - * |
|
| 228 | - * @param int $order |
|
| 229 | - */ |
|
| 230 | - public function set_order($order) |
|
| 231 | - { |
|
| 232 | - $this->set('PMD_order', $order); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * Gets slug |
|
| 238 | - * |
|
| 239 | - * @return string |
|
| 240 | - */ |
|
| 241 | - public function slug() |
|
| 242 | - { |
|
| 243 | - return $this->get('PMD_slug'); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Sets slug |
|
| 249 | - * |
|
| 250 | - * @param string $slug |
|
| 251 | - */ |
|
| 252 | - public function set_slug($slug) |
|
| 253 | - { |
|
| 254 | - $this->set('PMD_slug', $slug); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Gets type |
|
| 260 | - * |
|
| 261 | - * @return string |
|
| 262 | - */ |
|
| 263 | - public function type() |
|
| 264 | - { |
|
| 265 | - return $this->get('PMD_type'); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * Sets type |
|
| 271 | - * |
|
| 272 | - * @param string $type |
|
| 273 | - */ |
|
| 274 | - public function set_type($type) |
|
| 275 | - { |
|
| 276 | - $this->set('PMD_type', $type); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * Gets wp_user |
|
| 282 | - * |
|
| 283 | - * @return int |
|
| 284 | - */ |
|
| 285 | - public function wp_user() |
|
| 286 | - { |
|
| 287 | - return $this->get('PMD_wp_user'); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * Sets wp_user |
|
| 293 | - * |
|
| 294 | - * @param int $wp_user_id |
|
| 295 | - */ |
|
| 296 | - public function set_wp_user($wp_user_id) |
|
| 297 | - { |
|
| 298 | - $this->set('PMD_wp_user', $wp_user_id); |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Overrides parent so when PMD_type is changed we refresh the _type_obj |
|
| 303 | - * |
|
| 304 | - * @param string $field_name |
|
| 305 | - * @param mixed $field_value |
|
| 306 | - * @param boolean $use_default |
|
| 307 | - */ |
|
| 308 | - public function set($field_name, $field_value, $use_default = false) |
|
| 309 | - { |
|
| 310 | - if ($field_name === 'PMD_type') { |
|
| 311 | - // the type has probably changed, so forget about its old type object |
|
| 312 | - $this->_type_obj = null; |
|
| 313 | - } |
|
| 314 | - parent::set($field_name, $field_value, $use_default); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * Gets admin_name |
|
| 320 | - * |
|
| 321 | - * @return string |
|
| 322 | - */ |
|
| 323 | - public function admin_name() |
|
| 324 | - { |
|
| 325 | - return $this->get('PMD_admin_name'); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * Sets admin_name |
|
| 331 | - * |
|
| 332 | - * @param string $admin_name |
|
| 333 | - */ |
|
| 334 | - public function set_admin_name($admin_name) |
|
| 335 | - { |
|
| 336 | - $this->set('PMD_admin_name', $admin_name); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * Gets admin_desc |
|
| 342 | - * |
|
| 343 | - * @return string |
|
| 344 | - */ |
|
| 345 | - public function admin_desc() |
|
| 346 | - { |
|
| 347 | - return $this->get('PMD_admin_desc'); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * Sets admin_desc |
|
| 353 | - * |
|
| 354 | - * @param string $admin_desc |
|
| 355 | - */ |
|
| 356 | - public function set_admin_desc($admin_desc) |
|
| 357 | - { |
|
| 358 | - $this->set('PMD_admin_desc', $admin_desc); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * Gets scope |
|
| 364 | - * |
|
| 365 | - * @return array |
|
| 366 | - */ |
|
| 367 | - public function scope() |
|
| 368 | - { |
|
| 369 | - return $this->get('PMD_scope'); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * Sets scope |
|
| 375 | - * |
|
| 376 | - * @param array $scope |
|
| 377 | - */ |
|
| 378 | - public function set_scope($scope) |
|
| 379 | - { |
|
| 380 | - $this->set('PMD_scope', $scope); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * Gets the payment method type for this payment method instance |
|
| 386 | - * |
|
| 387 | - * @return EE_PMT_Base |
|
| 388 | - * @throws EE_Error |
|
| 389 | - */ |
|
| 390 | - public function type_obj() |
|
| 391 | - { |
|
| 392 | - if (! $this->_type_obj) { |
|
| 393 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 394 | - if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
|
| 395 | - $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
|
| 396 | - if (! class_exists($class_name)) { |
|
| 397 | - throw new EE_Error( |
|
| 398 | - sprintf( |
|
| 399 | - __( |
|
| 400 | - 'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s', |
|
| 401 | - 'event_espresso' |
|
| 402 | - ), |
|
| 403 | - $class_name, |
|
| 404 | - '<br />', |
|
| 405 | - '<a href="' . admin_url('plugins.php') . '">', |
|
| 406 | - '</a>' |
|
| 407 | - ) |
|
| 408 | - ); |
|
| 409 | - } |
|
| 410 | - $r = new ReflectionClass($class_name); |
|
| 411 | - $this->_type_obj = $r->newInstanceArgs(array($this)); |
|
| 412 | - } else { |
|
| 413 | - throw new EE_Error( |
|
| 414 | - sprintf( |
|
| 415 | - __( |
|
| 416 | - 'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s', |
|
| 417 | - 'event_espresso' |
|
| 418 | - ), |
|
| 419 | - $this->type(), |
|
| 420 | - implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names()) |
|
| 421 | - ) |
|
| 422 | - ); |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - return $this->_type_obj; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix) |
|
| 431 | - * and the extra meta. Mostly used for passing off ot gateways. * |
|
| 432 | - * |
|
| 433 | - * @return array |
|
| 434 | - */ |
|
| 435 | - public function settings_array() |
|
| 436 | - { |
|
| 437 | - $fields = $this->model_field_array(); |
|
| 438 | - $extra_meta = $this->all_extra_meta_array(); |
|
| 439 | - // remove the model's prefix from the fields |
|
| 440 | - $combined_settings_array = array(); |
|
| 441 | - foreach ($fields as $key => $value) { |
|
| 442 | - if (strpos($key, 'PMD_') === 0) { |
|
| 443 | - $key_sans_model_prefix = str_replace('PMD_', '', $key); |
|
| 444 | - $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
|
| 448 | - return $combined_settings_array; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * Gets the HTML for displaying the payment method on a page. |
|
| 454 | - * |
|
| 455 | - * @param string $url |
|
| 456 | - * @param string $css_class |
|
| 457 | - * @return string of HTML for displaying the button |
|
| 458 | - * @throws \EE_Error |
|
| 459 | - */ |
|
| 460 | - public function button_html($url = '', $css_class = '') |
|
| 461 | - { |
|
| 462 | - $payment_occurs = $this->type_obj()->payment_occurs(); |
|
| 463 | - return ' |
|
| 14 | + /** |
|
| 15 | + * Payment Method type object, which has all the info about this type of payment method, |
|
| 16 | + * including functions for processing payments, to get settings forms, etc. |
|
| 17 | + * |
|
| 18 | + * @var EE_PMT_Base |
|
| 19 | + */ |
|
| 20 | + protected $_type_obj; |
|
| 21 | + |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @param array $props_n_values |
|
| 25 | + * @return EE_Payment_Method |
|
| 26 | + * @throws \EE_Error |
|
| 27 | + */ |
|
| 28 | + public static function new_instance($props_n_values = array()) |
|
| 29 | + { |
|
| 30 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 31 | + return $has_object ? $has_object : new self($props_n_values, false); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @param array $props_n_values |
|
| 37 | + * @return EE_Payment_Method |
|
| 38 | + * @throws \EE_Error |
|
| 39 | + */ |
|
| 40 | + public static function new_instance_from_db($props_n_values = array()) |
|
| 41 | + { |
|
| 42 | + return new self($props_n_values, true); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname. |
|
| 49 | + * Otherwise returns a normal EE_Payment_Method |
|
| 50 | + * |
|
| 51 | + * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically |
|
| 52 | + * the classname minus 'EEPM_') |
|
| 53 | + * @return string |
|
| 54 | + */ |
|
| 55 | + // private static function _payment_method_type($props_n_values) |
|
| 56 | + // { |
|
| 57 | + // EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 58 | + // $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null; |
|
| 59 | + // if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) { |
|
| 60 | + // return 'EEPM_' . $type_string; |
|
| 61 | + // } else { |
|
| 62 | + // return __CLASS__; |
|
| 63 | + // } |
|
| 64 | + // } |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc) |
|
| 69 | + * |
|
| 70 | + * @return boolean |
|
| 71 | + */ |
|
| 72 | + public function active() |
|
| 73 | + { |
|
| 74 | + return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope()); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Sets this PM as active by making it usable within the CART scope. Offline gateways |
|
| 80 | + * are also usable from the admin-scope as well. DOES NOT SAVE it |
|
| 81 | + * |
|
| 82 | + * @throws \EE_Error |
|
| 83 | + */ |
|
| 84 | + public function set_active() |
|
| 85 | + { |
|
| 86 | + $default_scopes = array(EEM_Payment_Method::scope_cart); |
|
| 87 | + if ($this->type_obj() && |
|
| 88 | + $this->type_obj()->payment_occurs() === EE_PMT_Base::offline) { |
|
| 89 | + $default_scopes[] = EEM_Payment_Method::scope_admin; |
|
| 90 | + } |
|
| 91 | + $this->set_scope($default_scopes); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it. |
|
| 97 | + */ |
|
| 98 | + public function deactivate() |
|
| 99 | + { |
|
| 100 | + $this->set_scope(array()); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Gets button_url |
|
| 106 | + * |
|
| 107 | + * @return string |
|
| 108 | + */ |
|
| 109 | + public function button_url() |
|
| 110 | + { |
|
| 111 | + return $this->get('PMD_button_url'); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Sets button_url |
|
| 117 | + * |
|
| 118 | + * @param string $button_url |
|
| 119 | + */ |
|
| 120 | + public function set_button_url($button_url) |
|
| 121 | + { |
|
| 122 | + $this->set('PMD_button_url', $button_url); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Gets debug_mode |
|
| 128 | + * |
|
| 129 | + * @return boolean |
|
| 130 | + */ |
|
| 131 | + public function debug_mode() |
|
| 132 | + { |
|
| 133 | + return $this->get('PMD_debug_mode'); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Sets debug_mode |
|
| 139 | + * |
|
| 140 | + * @param boolean $debug_mode |
|
| 141 | + */ |
|
| 142 | + public function set_debug_mode($debug_mode) |
|
| 143 | + { |
|
| 144 | + $this->set('PMD_debug_mode', $debug_mode); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Gets description |
|
| 150 | + * |
|
| 151 | + * @return string |
|
| 152 | + */ |
|
| 153 | + public function description() |
|
| 154 | + { |
|
| 155 | + return $this->get('PMD_desc'); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Sets description |
|
| 161 | + * |
|
| 162 | + * @param string $description |
|
| 163 | + */ |
|
| 164 | + public function set_description($description) |
|
| 165 | + { |
|
| 166 | + $this->set('PMD_desc', $description); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Gets name |
|
| 172 | + * |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | + public function name() |
|
| 176 | + { |
|
| 177 | + return $this->get('PMD_name'); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Sets name |
|
| 183 | + * |
|
| 184 | + * @param string $name |
|
| 185 | + */ |
|
| 186 | + public function set_name($name) |
|
| 187 | + { |
|
| 188 | + $this->set('PMD_name', $name); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Gets open_by_default |
|
| 194 | + * |
|
| 195 | + * @return boolean |
|
| 196 | + */ |
|
| 197 | + public function open_by_default() |
|
| 198 | + { |
|
| 199 | + return $this->get('PMD_open_by_default'); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Sets open_by_default |
|
| 205 | + * |
|
| 206 | + * @param boolean $open_by_default |
|
| 207 | + */ |
|
| 208 | + public function set_open_by_default($open_by_default) |
|
| 209 | + { |
|
| 210 | + $this->set('PMD_open_by_default', $open_by_default); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Gets order |
|
| 216 | + * |
|
| 217 | + * @return int |
|
| 218 | + */ |
|
| 219 | + public function order() |
|
| 220 | + { |
|
| 221 | + return $this->get('PMD_order'); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * Sets order |
|
| 227 | + * |
|
| 228 | + * @param int $order |
|
| 229 | + */ |
|
| 230 | + public function set_order($order) |
|
| 231 | + { |
|
| 232 | + $this->set('PMD_order', $order); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * Gets slug |
|
| 238 | + * |
|
| 239 | + * @return string |
|
| 240 | + */ |
|
| 241 | + public function slug() |
|
| 242 | + { |
|
| 243 | + return $this->get('PMD_slug'); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Sets slug |
|
| 249 | + * |
|
| 250 | + * @param string $slug |
|
| 251 | + */ |
|
| 252 | + public function set_slug($slug) |
|
| 253 | + { |
|
| 254 | + $this->set('PMD_slug', $slug); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Gets type |
|
| 260 | + * |
|
| 261 | + * @return string |
|
| 262 | + */ |
|
| 263 | + public function type() |
|
| 264 | + { |
|
| 265 | + return $this->get('PMD_type'); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * Sets type |
|
| 271 | + * |
|
| 272 | + * @param string $type |
|
| 273 | + */ |
|
| 274 | + public function set_type($type) |
|
| 275 | + { |
|
| 276 | + $this->set('PMD_type', $type); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * Gets wp_user |
|
| 282 | + * |
|
| 283 | + * @return int |
|
| 284 | + */ |
|
| 285 | + public function wp_user() |
|
| 286 | + { |
|
| 287 | + return $this->get('PMD_wp_user'); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * Sets wp_user |
|
| 293 | + * |
|
| 294 | + * @param int $wp_user_id |
|
| 295 | + */ |
|
| 296 | + public function set_wp_user($wp_user_id) |
|
| 297 | + { |
|
| 298 | + $this->set('PMD_wp_user', $wp_user_id); |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Overrides parent so when PMD_type is changed we refresh the _type_obj |
|
| 303 | + * |
|
| 304 | + * @param string $field_name |
|
| 305 | + * @param mixed $field_value |
|
| 306 | + * @param boolean $use_default |
|
| 307 | + */ |
|
| 308 | + public function set($field_name, $field_value, $use_default = false) |
|
| 309 | + { |
|
| 310 | + if ($field_name === 'PMD_type') { |
|
| 311 | + // the type has probably changed, so forget about its old type object |
|
| 312 | + $this->_type_obj = null; |
|
| 313 | + } |
|
| 314 | + parent::set($field_name, $field_value, $use_default); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * Gets admin_name |
|
| 320 | + * |
|
| 321 | + * @return string |
|
| 322 | + */ |
|
| 323 | + public function admin_name() |
|
| 324 | + { |
|
| 325 | + return $this->get('PMD_admin_name'); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * Sets admin_name |
|
| 331 | + * |
|
| 332 | + * @param string $admin_name |
|
| 333 | + */ |
|
| 334 | + public function set_admin_name($admin_name) |
|
| 335 | + { |
|
| 336 | + $this->set('PMD_admin_name', $admin_name); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * Gets admin_desc |
|
| 342 | + * |
|
| 343 | + * @return string |
|
| 344 | + */ |
|
| 345 | + public function admin_desc() |
|
| 346 | + { |
|
| 347 | + return $this->get('PMD_admin_desc'); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * Sets admin_desc |
|
| 353 | + * |
|
| 354 | + * @param string $admin_desc |
|
| 355 | + */ |
|
| 356 | + public function set_admin_desc($admin_desc) |
|
| 357 | + { |
|
| 358 | + $this->set('PMD_admin_desc', $admin_desc); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * Gets scope |
|
| 364 | + * |
|
| 365 | + * @return array |
|
| 366 | + */ |
|
| 367 | + public function scope() |
|
| 368 | + { |
|
| 369 | + return $this->get('PMD_scope'); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * Sets scope |
|
| 375 | + * |
|
| 376 | + * @param array $scope |
|
| 377 | + */ |
|
| 378 | + public function set_scope($scope) |
|
| 379 | + { |
|
| 380 | + $this->set('PMD_scope', $scope); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * Gets the payment method type for this payment method instance |
|
| 386 | + * |
|
| 387 | + * @return EE_PMT_Base |
|
| 388 | + * @throws EE_Error |
|
| 389 | + */ |
|
| 390 | + public function type_obj() |
|
| 391 | + { |
|
| 392 | + if (! $this->_type_obj) { |
|
| 393 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 394 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
|
| 395 | + $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
|
| 396 | + if (! class_exists($class_name)) { |
|
| 397 | + throw new EE_Error( |
|
| 398 | + sprintf( |
|
| 399 | + __( |
|
| 400 | + 'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s', |
|
| 401 | + 'event_espresso' |
|
| 402 | + ), |
|
| 403 | + $class_name, |
|
| 404 | + '<br />', |
|
| 405 | + '<a href="' . admin_url('plugins.php') . '">', |
|
| 406 | + '</a>' |
|
| 407 | + ) |
|
| 408 | + ); |
|
| 409 | + } |
|
| 410 | + $r = new ReflectionClass($class_name); |
|
| 411 | + $this->_type_obj = $r->newInstanceArgs(array($this)); |
|
| 412 | + } else { |
|
| 413 | + throw new EE_Error( |
|
| 414 | + sprintf( |
|
| 415 | + __( |
|
| 416 | + 'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s', |
|
| 417 | + 'event_espresso' |
|
| 418 | + ), |
|
| 419 | + $this->type(), |
|
| 420 | + implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names()) |
|
| 421 | + ) |
|
| 422 | + ); |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + return $this->_type_obj; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix) |
|
| 431 | + * and the extra meta. Mostly used for passing off ot gateways. * |
|
| 432 | + * |
|
| 433 | + * @return array |
|
| 434 | + */ |
|
| 435 | + public function settings_array() |
|
| 436 | + { |
|
| 437 | + $fields = $this->model_field_array(); |
|
| 438 | + $extra_meta = $this->all_extra_meta_array(); |
|
| 439 | + // remove the model's prefix from the fields |
|
| 440 | + $combined_settings_array = array(); |
|
| 441 | + foreach ($fields as $key => $value) { |
|
| 442 | + if (strpos($key, 'PMD_') === 0) { |
|
| 443 | + $key_sans_model_prefix = str_replace('PMD_', '', $key); |
|
| 444 | + $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
|
| 448 | + return $combined_settings_array; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * Gets the HTML for displaying the payment method on a page. |
|
| 454 | + * |
|
| 455 | + * @param string $url |
|
| 456 | + * @param string $css_class |
|
| 457 | + * @return string of HTML for displaying the button |
|
| 458 | + * @throws \EE_Error |
|
| 459 | + */ |
|
| 460 | + public function button_html($url = '', $css_class = '') |
|
| 461 | + { |
|
| 462 | + $payment_occurs = $this->type_obj()->payment_occurs(); |
|
| 463 | + return ' |
|
| 464 | 464 | <div id="' |
| 465 | - . $this->slug() |
|
| 466 | - . '-payment-option-dv" class="' |
|
| 467 | - . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
| 465 | + . $this->slug() |
|
| 466 | + . '-payment-option-dv" class="' |
|
| 467 | + . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
| 468 | 468 | <a id="payment-gateway-button-' . $this->slug() |
| 469 | - . '" class="reg-page-payment-option-lnk" rel="' |
|
| 470 | - . $this->slug() . '" href="' . $url . '" > |
|
| 469 | + . '" class="reg-page-payment-option-lnk" rel="' |
|
| 470 | + . $this->slug() . '" href="' . $url . '" > |
|
| 471 | 471 | <img src="' . $this->button_url() . '" alt="' . sprintf( |
| 472 | - esc_attr__('Pay using %s', 'event_espresso'), |
|
| 473 | - $this->get_pretty('PMD_name', 'form_input') |
|
| 474 | - ) . '" /> |
|
| 472 | + esc_attr__('Pay using %s', 'event_espresso'), |
|
| 473 | + $this->get_pretty('PMD_name', 'form_input') |
|
| 474 | + ) . '" /> |
|
| 475 | 475 | </a> |
| 476 | 476 | </div> |
| 477 | 477 | '; |
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * Gets all the currencies which are an option for this payment method |
|
| 483 | - * (as defined by the gateway and the currently active currencies) |
|
| 484 | - * |
|
| 485 | - * @return EE_Currency[] |
|
| 486 | - * @throws \EE_Error |
|
| 487 | - */ |
|
| 488 | - public function get_all_usable_currencies() |
|
| 489 | - { |
|
| 490 | - return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj()); |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * Reports whether or not this payment method can be used for this payment method |
|
| 496 | - * |
|
| 497 | - * @param string $currency_code currency ID (code) |
|
| 498 | - * @return boolean |
|
| 499 | - * @throws \EE_Error |
|
| 500 | - */ |
|
| 501 | - public function usable_for_currency($currency_code) |
|
| 502 | - { |
|
| 503 | - foreach ($this->get_all_usable_currencies() as $currency_obj) { |
|
| 504 | - if ($currency_obj->ID() === $currency_code) { |
|
| 505 | - return true; |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - return false; |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway |
|
| 514 | - * |
|
| 515 | - * @return bool |
|
| 516 | - * @throws \EE_Error |
|
| 517 | - */ |
|
| 518 | - public function is_on_site() |
|
| 519 | - { |
|
| 520 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite; |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway |
|
| 526 | - * |
|
| 527 | - * @return bool |
|
| 528 | - * @throws \EE_Error |
|
| 529 | - */ |
|
| 530 | - public function is_off_site() |
|
| 531 | - { |
|
| 532 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite; |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - |
|
| 536 | - /** |
|
| 537 | - * Returns TRUE if this payment method does not utilize a gateway |
|
| 538 | - * |
|
| 539 | - * @return bool |
|
| 540 | - * @throws \EE_Error |
|
| 541 | - */ |
|
| 542 | - public function is_off_line() |
|
| 543 | - { |
|
| 544 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline; |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - /** |
|
| 548 | - * Overrides default __sleep so the object type is NOT cached. |
|
| 549 | - * This way we can rely on the normal EE_Payment_Method::type_obj() logic |
|
| 550 | - * to load the required classes, and don't need them at the time of unserialization |
|
| 551 | - * |
|
| 552 | - * @return array |
|
| 553 | - */ |
|
| 554 | - public function __sleep() |
|
| 555 | - { |
|
| 556 | - $properties = get_object_vars($this); |
|
| 557 | - unset($properties['_type_obj']); |
|
| 558 | - return array_keys($properties); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - |
|
| 562 | - /** |
|
| 563 | - * Overrides parent to add some logging for when payment methods get deactivated |
|
| 564 | - * |
|
| 565 | - * @param array $set_cols_n_values |
|
| 566 | - * @return int @see EE_Base_Class::save() |
|
| 567 | - * @throws \EE_Error |
|
| 568 | - */ |
|
| 569 | - public function save($set_cols_n_values = array()) |
|
| 570 | - { |
|
| 571 | - $results = parent::save($set_cols_n_values); |
|
| 572 | - if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) { |
|
| 573 | - EE_Log::instance()->log( |
|
| 574 | - __FILE__, |
|
| 575 | - __FUNCTION__, |
|
| 576 | - sprintf( |
|
| 577 | - __('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'), |
|
| 578 | - $this->name(), |
|
| 579 | - serialize($this->get_original('PMD_scope')), |
|
| 580 | - serialize($this->get('PMD_scope')), |
|
| 581 | - EE_Registry::instance()->REQ->get_current_page_permalink() |
|
| 582 | - ), |
|
| 583 | - 'payment_method_change' |
|
| 584 | - ); |
|
| 585 | - } |
|
| 586 | - return $results; |
|
| 587 | - } |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * Gets all the currencies which are an option for this payment method |
|
| 483 | + * (as defined by the gateway and the currently active currencies) |
|
| 484 | + * |
|
| 485 | + * @return EE_Currency[] |
|
| 486 | + * @throws \EE_Error |
|
| 487 | + */ |
|
| 488 | + public function get_all_usable_currencies() |
|
| 489 | + { |
|
| 490 | + return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj()); |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * Reports whether or not this payment method can be used for this payment method |
|
| 496 | + * |
|
| 497 | + * @param string $currency_code currency ID (code) |
|
| 498 | + * @return boolean |
|
| 499 | + * @throws \EE_Error |
|
| 500 | + */ |
|
| 501 | + public function usable_for_currency($currency_code) |
|
| 502 | + { |
|
| 503 | + foreach ($this->get_all_usable_currencies() as $currency_obj) { |
|
| 504 | + if ($currency_obj->ID() === $currency_code) { |
|
| 505 | + return true; |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + return false; |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway |
|
| 514 | + * |
|
| 515 | + * @return bool |
|
| 516 | + * @throws \EE_Error |
|
| 517 | + */ |
|
| 518 | + public function is_on_site() |
|
| 519 | + { |
|
| 520 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite; |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway |
|
| 526 | + * |
|
| 527 | + * @return bool |
|
| 528 | + * @throws \EE_Error |
|
| 529 | + */ |
|
| 530 | + public function is_off_site() |
|
| 531 | + { |
|
| 532 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite; |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * Returns TRUE if this payment method does not utilize a gateway |
|
| 538 | + * |
|
| 539 | + * @return bool |
|
| 540 | + * @throws \EE_Error |
|
| 541 | + */ |
|
| 542 | + public function is_off_line() |
|
| 543 | + { |
|
| 544 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + /** |
|
| 548 | + * Overrides default __sleep so the object type is NOT cached. |
|
| 549 | + * This way we can rely on the normal EE_Payment_Method::type_obj() logic |
|
| 550 | + * to load the required classes, and don't need them at the time of unserialization |
|
| 551 | + * |
|
| 552 | + * @return array |
|
| 553 | + */ |
|
| 554 | + public function __sleep() |
|
| 555 | + { |
|
| 556 | + $properties = get_object_vars($this); |
|
| 557 | + unset($properties['_type_obj']); |
|
| 558 | + return array_keys($properties); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * Overrides parent to add some logging for when payment methods get deactivated |
|
| 564 | + * |
|
| 565 | + * @param array $set_cols_n_values |
|
| 566 | + * @return int @see EE_Base_Class::save() |
|
| 567 | + * @throws \EE_Error |
|
| 568 | + */ |
|
| 569 | + public function save($set_cols_n_values = array()) |
|
| 570 | + { |
|
| 571 | + $results = parent::save($set_cols_n_values); |
|
| 572 | + if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) { |
|
| 573 | + EE_Log::instance()->log( |
|
| 574 | + __FILE__, |
|
| 575 | + __FUNCTION__, |
|
| 576 | + sprintf( |
|
| 577 | + __('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'), |
|
| 578 | + $this->name(), |
|
| 579 | + serialize($this->get_original('PMD_scope')), |
|
| 580 | + serialize($this->get('PMD_scope')), |
|
| 581 | + EE_Registry::instance()->REQ->get_current_page_permalink() |
|
| 582 | + ), |
|
| 583 | + 'payment_method_change' |
|
| 584 | + ); |
|
| 585 | + } |
|
| 586 | + return $results; |
|
| 587 | + } |
|
| 588 | 588 | } |
@@ -389,11 +389,11 @@ discard block |
||
| 389 | 389 | */ |
| 390 | 390 | public function type_obj() |
| 391 | 391 | { |
| 392 | - if (! $this->_type_obj) { |
|
| 392 | + if ( ! $this->_type_obj) { |
|
| 393 | 393 | EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
| 394 | 394 | if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
| 395 | 395 | $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
| 396 | - if (! class_exists($class_name)) { |
|
| 396 | + if ( ! class_exists($class_name)) { |
|
| 397 | 397 | throw new EE_Error( |
| 398 | 398 | sprintf( |
| 399 | 399 | __( |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | ), |
| 403 | 403 | $class_name, |
| 404 | 404 | '<br />', |
| 405 | - '<a href="' . admin_url('plugins.php') . '">', |
|
| 405 | + '<a href="'.admin_url('plugins.php').'">', |
|
| 406 | 406 | '</a>' |
| 407 | 407 | ) |
| 408 | 408 | ); |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | foreach ($fields as $key => $value) { |
| 442 | 442 | if (strpos($key, 'PMD_') === 0) { |
| 443 | 443 | $key_sans_model_prefix = str_replace('PMD_', '', $key); |
| 444 | - $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
| 444 | + $combined_settings_array [$key_sans_model_prefix] = $value; |
|
| 445 | 445 | } |
| 446 | 446 | } |
| 447 | 447 | $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
@@ -464,14 +464,14 @@ discard block |
||
| 464 | 464 | <div id="' |
| 465 | 465 | . $this->slug() |
| 466 | 466 | . '-payment-option-dv" class="' |
| 467 | - . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
| 467 | + . $payment_occurs.'-payment-gateway reg-page-payment-option-dv'.$css_class.'"> |
|
| 468 | 468 | <a id="payment-gateway-button-' . $this->slug() |
| 469 | 469 | . '" class="reg-page-payment-option-lnk" rel="' |
| 470 | - . $this->slug() . '" href="' . $url . '" > |
|
| 471 | - <img src="' . $this->button_url() . '" alt="' . sprintf( |
|
| 470 | + . $this->slug().'" href="'.$url.'" > |
|
| 471 | + <img src="' . $this->button_url().'" alt="'.sprintf( |
|
| 472 | 472 | esc_attr__('Pay using %s', 'event_espresso'), |
| 473 | 473 | $this->get_pretty('PMD_name', 'form_input') |
| 474 | - ) . '" /> |
|
| 474 | + ).'" /> |
|
| 475 | 475 | </a> |
| 476 | 476 | </div> |
| 477 | 477 | '; |
@@ -6,23 +6,23 @@ |
||
| 6 | 6 | class EE_Event_Venue extends EE_Base_Class |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * @param array $props_n_values |
|
| 11 | - * @return EE_Event_Venue|mixed |
|
| 12 | - */ |
|
| 13 | - public static function new_instance($props_n_values = array()) |
|
| 14 | - { |
|
| 15 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 16 | - return $has_object ? $has_object : new self($props_n_values); |
|
| 17 | - } |
|
| 9 | + /** |
|
| 10 | + * @param array $props_n_values |
|
| 11 | + * @return EE_Event_Venue|mixed |
|
| 12 | + */ |
|
| 13 | + public static function new_instance($props_n_values = array()) |
|
| 14 | + { |
|
| 15 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 16 | + return $has_object ? $has_object : new self($props_n_values); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @param array $props_n_values |
|
| 22 | - * @return EE_Event_Venue |
|
| 23 | - */ |
|
| 24 | - public static function new_instance_from_db($props_n_values = array()) |
|
| 25 | - { |
|
| 26 | - return new self($props_n_values, true); |
|
| 27 | - } |
|
| 20 | + /** |
|
| 21 | + * @param array $props_n_values |
|
| 22 | + * @return EE_Event_Venue |
|
| 23 | + */ |
|
| 24 | + public static function new_instance_from_db($props_n_values = array()) |
|
| 25 | + { |
|
| 26 | + return new self($props_n_values, true); |
|
| 27 | + } |
|
| 28 | 28 | } |
@@ -12,53 +12,53 @@ |
||
| 12 | 12 | { |
| 13 | 13 | |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Overrides parent _delete() so that we do soft deletes. |
|
| 17 | - * |
|
| 18 | - * @return bool|int |
|
| 19 | - */ |
|
| 20 | - protected function _delete() |
|
| 21 | - { |
|
| 22 | - return $this->delete_or_restore(); |
|
| 23 | - } |
|
| 15 | + /** |
|
| 16 | + * Overrides parent _delete() so that we do soft deletes. |
|
| 17 | + * |
|
| 18 | + * @return bool|int |
|
| 19 | + */ |
|
| 20 | + protected function _delete() |
|
| 21 | + { |
|
| 22 | + return $this->delete_or_restore(); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Deletes or restores this object. |
|
| 28 | - * |
|
| 29 | - * @param bool $delete true=>delete, false=>restore |
|
| 30 | - * @return bool|int |
|
| 31 | - */ |
|
| 32 | - public function delete_or_restore($delete = true) |
|
| 33 | - { |
|
| 34 | - /** |
|
| 35 | - * Called just before trashing (soft delete) or restoring a trashed item. |
|
| 36 | - * |
|
| 37 | - * @param EE_Base_Class $model_object about to be trashed or restored |
|
| 38 | - * @param bool $delete true the item is being trashed, false the item is being restored. |
|
| 39 | - */ |
|
| 40 | - do_action('AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__before', $this, $delete); |
|
| 41 | - $model = $this->get_model(); |
|
| 42 | - $result = $model->delete_or_restore_by_ID($delete, $this->ID()); |
|
| 43 | - /** |
|
| 44 | - * Called just after trashing (soft delete) or restoring a trashed item. |
|
| 45 | - * |
|
| 46 | - * @param EE_Base_Class $model_object that was just trashed or restored. |
|
| 47 | - * @param bool $delete true the item is being trashed, false the item is being restored. |
|
| 48 | - * @param bool|int $result |
|
| 49 | - */ |
|
| 50 | - do_action('AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__after', $this, $delete, $result); |
|
| 51 | - return $result; |
|
| 52 | - } |
|
| 26 | + /** |
|
| 27 | + * Deletes or restores this object. |
|
| 28 | + * |
|
| 29 | + * @param bool $delete true=>delete, false=>restore |
|
| 30 | + * @return bool|int |
|
| 31 | + */ |
|
| 32 | + public function delete_or_restore($delete = true) |
|
| 33 | + { |
|
| 34 | + /** |
|
| 35 | + * Called just before trashing (soft delete) or restoring a trashed item. |
|
| 36 | + * |
|
| 37 | + * @param EE_Base_Class $model_object about to be trashed or restored |
|
| 38 | + * @param bool $delete true the item is being trashed, false the item is being restored. |
|
| 39 | + */ |
|
| 40 | + do_action('AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__before', $this, $delete); |
|
| 41 | + $model = $this->get_model(); |
|
| 42 | + $result = $model->delete_or_restore_by_ID($delete, $this->ID()); |
|
| 43 | + /** |
|
| 44 | + * Called just after trashing (soft delete) or restoring a trashed item. |
|
| 45 | + * |
|
| 46 | + * @param EE_Base_Class $model_object that was just trashed or restored. |
|
| 47 | + * @param bool $delete true the item is being trashed, false the item is being restored. |
|
| 48 | + * @param bool|int $result |
|
| 49 | + */ |
|
| 50 | + do_action('AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__after', $this, $delete, $result); |
|
| 51 | + return $result; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Performs a restoration (un-deletes) this object |
|
| 57 | - * |
|
| 58 | - * @return bool|int |
|
| 59 | - */ |
|
| 60 | - public function restore() |
|
| 61 | - { |
|
| 62 | - return $this->delete_or_restore(false); |
|
| 63 | - } |
|
| 55 | + /** |
|
| 56 | + * Performs a restoration (un-deletes) this object |
|
| 57 | + * |
|
| 58 | + * @return bool|int |
|
| 59 | + */ |
|
| 60 | + public function restore() |
|
| 61 | + { |
|
| 62 | + return $this->delete_or_restore(false); |
|
| 63 | + } |
|
| 64 | 64 | } |
@@ -6,23 +6,23 @@ |
||
| 6 | 6 | class EE_Event_Question_Group extends EE_Base_Class |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * @param array $props_n_values |
|
| 11 | - * @return EE_Event_Question_Group|mixed |
|
| 12 | - */ |
|
| 13 | - public static function new_instance($props_n_values = array()) |
|
| 14 | - { |
|
| 15 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 16 | - return $has_object ? $has_object : new self($props_n_values); |
|
| 17 | - } |
|
| 9 | + /** |
|
| 10 | + * @param array $props_n_values |
|
| 11 | + * @return EE_Event_Question_Group|mixed |
|
| 12 | + */ |
|
| 13 | + public static function new_instance($props_n_values = array()) |
|
| 14 | + { |
|
| 15 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 16 | + return $has_object ? $has_object : new self($props_n_values); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @param array $props_n_values |
|
| 22 | - * @return EE_Event_Question_Group |
|
| 23 | - */ |
|
| 24 | - public static function new_instance_from_db($props_n_values = array()) |
|
| 25 | - { |
|
| 26 | - return new self($props_n_values, true); |
|
| 27 | - } |
|
| 20 | + /** |
|
| 21 | + * @param array $props_n_values |
|
| 22 | + * @return EE_Event_Question_Group |
|
| 23 | + */ |
|
| 24 | + public static function new_instance_from_db($props_n_values = array()) |
|
| 25 | + { |
|
| 26 | + return new self($props_n_values, true); |
|
| 27 | + } |
|
| 28 | 28 | } |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | */ |
| 297 | 297 | public function timestamp($dt_frmt = '', $tm_frmt = '') |
| 298 | 298 | { |
| 299 | - return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt)); |
|
| 299 | + return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt.' '.$tm_frmt)); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | : ''; |
| 482 | 482 | break; |
| 483 | 483 | } |
| 484 | - return $icon . $status[ $this->STS_ID() ]; |
|
| 484 | + return $icon.$status[$this->STS_ID()]; |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | |
@@ -627,7 +627,7 @@ discard block |
||
| 627 | 627 | public function redirect_form($inside_form_html = null) |
| 628 | 628 | { |
| 629 | 629 | $redirect_url = $this->redirect_url(); |
| 630 | - if (! empty($redirect_url)) { |
|
| 630 | + if ( ! empty($redirect_url)) { |
|
| 631 | 631 | // what ? no inner form content? |
| 632 | 632 | if ($inside_form_html === null) { |
| 633 | 633 | $inside_form_html = EEH_HTML::p( |
@@ -657,7 +657,7 @@ discard block |
||
| 657 | 657 | $get_params = null; |
| 658 | 658 | parse_str($querystring, $get_params); |
| 659 | 659 | $inside_form_html .= $this->_args_as_inputs($get_params); |
| 660 | - $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
| 660 | + $redirect_url = str_replace('?'.$querystring, '', $redirect_url); |
|
| 661 | 661 | } |
| 662 | 662 | $form = EEH_HTML::nl(1) |
| 663 | 663 | . '<form method="' |
@@ -665,9 +665,9 @@ discard block |
||
| 665 | 665 | . '" name="gateway_form" action="' |
| 666 | 666 | . $redirect_url |
| 667 | 667 | . '">'; |
| 668 | - $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
| 668 | + $form .= EEH_HTML::nl(1).$this->redirect_args_as_inputs(); |
|
| 669 | 669 | $form .= $inside_form_html; |
| 670 | - $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
| 670 | + $form .= EEH_HTML::nl(-1).'</form>'.EEH_HTML::nl(-1); |
|
| 671 | 671 | return $form; |
| 672 | 672 | } else { |
| 673 | 673 | return null; |
@@ -9,855 +9,855 @@ |
||
| 9 | 9 | class EE_Payment extends EE_Base_Class implements EEI_Payment |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @param array $props_n_values incoming values |
|
| 14 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 15 | - * used.) |
|
| 16 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 17 | - * date_format and the second value is the time format |
|
| 18 | - * @return EE_Payment |
|
| 19 | - * @throws \EE_Error |
|
| 20 | - */ |
|
| 21 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 22 | - { |
|
| 23 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 24 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @param array $props_n_values incoming values from the database |
|
| 30 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 31 | - * the website will be used. |
|
| 32 | - * @return EE_Payment |
|
| 33 | - * @throws \EE_Error |
|
| 34 | - */ |
|
| 35 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 36 | - { |
|
| 37 | - return new self($props_n_values, true, $timezone); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Set Transaction ID |
|
| 43 | - * |
|
| 44 | - * @access public |
|
| 45 | - * @param int $TXN_ID |
|
| 46 | - * @throws \EE_Error |
|
| 47 | - */ |
|
| 48 | - public function set_transaction_id($TXN_ID = 0) |
|
| 49 | - { |
|
| 50 | - $this->set('TXN_ID', $TXN_ID); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Gets the transaction related to this payment |
|
| 56 | - * |
|
| 57 | - * @return EE_Transaction |
|
| 58 | - * @throws \EE_Error |
|
| 59 | - */ |
|
| 60 | - public function transaction() |
|
| 61 | - { |
|
| 62 | - return $this->get_first_related('Transaction'); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Set Status |
|
| 68 | - * |
|
| 69 | - * @access public |
|
| 70 | - * @param string $STS_ID |
|
| 71 | - * @throws \EE_Error |
|
| 72 | - */ |
|
| 73 | - public function set_status($STS_ID = '') |
|
| 74 | - { |
|
| 75 | - $this->set('STS_ID', $STS_ID); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Set Payment Timestamp |
|
| 81 | - * |
|
| 82 | - * @access public |
|
| 83 | - * @param int $timestamp |
|
| 84 | - * @throws \EE_Error |
|
| 85 | - */ |
|
| 86 | - public function set_timestamp($timestamp = 0) |
|
| 87 | - { |
|
| 88 | - $this->set('PAY_timestamp', $timestamp); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Set Payment Method |
|
| 94 | - * |
|
| 95 | - * @access public |
|
| 96 | - * @param string $PAY_source |
|
| 97 | - * @throws \EE_Error |
|
| 98 | - */ |
|
| 99 | - public function set_source($PAY_source = '') |
|
| 100 | - { |
|
| 101 | - $this->set('PAY_source', $PAY_source); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Set Payment Amount |
|
| 107 | - * |
|
| 108 | - * @access public |
|
| 109 | - * @param float $amount |
|
| 110 | - * @throws \EE_Error |
|
| 111 | - */ |
|
| 112 | - public function set_amount($amount = 0.00) |
|
| 113 | - { |
|
| 114 | - $this->set('PAY_amount', (float) $amount); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Set Payment Gateway Response |
|
| 120 | - * |
|
| 121 | - * @access public |
|
| 122 | - * @param string $gateway_response |
|
| 123 | - * @throws \EE_Error |
|
| 124 | - */ |
|
| 125 | - public function set_gateway_response($gateway_response = '') |
|
| 126 | - { |
|
| 127 | - $this->set('PAY_gateway_response', $gateway_response); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Returns the name of the payment method used on this payment (previously known merely as 'gateway') |
|
| 133 | - * but since 4.6.0, payment methods are models and the payment keeps a foreign key to the payment method |
|
| 134 | - * used on it |
|
| 135 | - * |
|
| 136 | - * @deprecated |
|
| 137 | - * @return string |
|
| 138 | - * @throws \EE_Error |
|
| 139 | - */ |
|
| 140 | - public function gateway() |
|
| 141 | - { |
|
| 142 | - EE_Error::doing_it_wrong( |
|
| 143 | - 'EE_Payment::gateway', |
|
| 144 | - __( |
|
| 145 | - 'The method EE_Payment::gateway() has been deprecated. Consider instead using EE_Payment::payment_method()->name()', |
|
| 146 | - 'event_espresso' |
|
| 147 | - ), |
|
| 148 | - '4.6.0' |
|
| 149 | - ); |
|
| 150 | - return $this->payment_method() ? $this->payment_method()->name() : __('Unknown', 'event_espresso'); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Set Gateway Transaction ID |
|
| 156 | - * |
|
| 157 | - * @access public |
|
| 158 | - * @param string $txn_id_chq_nmbr |
|
| 159 | - * @throws \EE_Error |
|
| 160 | - */ |
|
| 161 | - public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '') |
|
| 162 | - { |
|
| 163 | - $this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Set Purchase Order Number |
|
| 169 | - * |
|
| 170 | - * @access public |
|
| 171 | - * @param string $po_number |
|
| 172 | - * @throws \EE_Error |
|
| 173 | - */ |
|
| 174 | - public function set_po_number($po_number = '') |
|
| 175 | - { |
|
| 176 | - $this->set('PAY_po_number', $po_number); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Set Extra Accounting Field |
|
| 182 | - * |
|
| 183 | - * @access public |
|
| 184 | - * @param string $extra_accntng |
|
| 185 | - * @throws \EE_Error |
|
| 186 | - */ |
|
| 187 | - public function set_extra_accntng($extra_accntng = '') |
|
| 188 | - { |
|
| 189 | - $this->set('PAY_extra_accntng', $extra_accntng); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Set Payment made via admin flag |
|
| 195 | - * |
|
| 196 | - * @access public |
|
| 197 | - * @param bool $via_admin |
|
| 198 | - * @throws \EE_Error |
|
| 199 | - */ |
|
| 200 | - public function set_payment_made_via_admin($via_admin = false) |
|
| 201 | - { |
|
| 202 | - if ($via_admin) { |
|
| 203 | - $this->set('PAY_source', EEM_Payment_Method::scope_admin); |
|
| 204 | - } else { |
|
| 205 | - $this->set('PAY_source', EEM_Payment_Method::scope_cart); |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Set Payment Details |
|
| 212 | - * |
|
| 213 | - * @access public |
|
| 214 | - * @param string|array $details |
|
| 215 | - * @throws \EE_Error |
|
| 216 | - */ |
|
| 217 | - public function set_details($details = '') |
|
| 218 | - { |
|
| 219 | - if (is_array($details)) { |
|
| 220 | - array_walk_recursive($details, array($this, '_strip_all_tags_within_array')); |
|
| 221 | - } else { |
|
| 222 | - $details = wp_strip_all_tags($details); |
|
| 223 | - } |
|
| 224 | - $this->set('PAY_details', $details); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Sets redirect_url |
|
| 230 | - * |
|
| 231 | - * @param string $redirect_url |
|
| 232 | - * @throws \EE_Error |
|
| 233 | - */ |
|
| 234 | - public function set_redirect_url($redirect_url) |
|
| 235 | - { |
|
| 236 | - $this->set('PAY_redirect_url', $redirect_url); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Sets redirect_args |
|
| 242 | - * |
|
| 243 | - * @param array $redirect_args |
|
| 244 | - * @throws \EE_Error |
|
| 245 | - */ |
|
| 246 | - public function set_redirect_args($redirect_args) |
|
| 247 | - { |
|
| 248 | - $this->set('PAY_redirect_args', $redirect_args); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * get Payment Transaction ID |
|
| 254 | - * |
|
| 255 | - * @access public |
|
| 256 | - * @throws \EE_Error |
|
| 257 | - */ |
|
| 258 | - public function TXN_ID() |
|
| 259 | - { |
|
| 260 | - return $this->get('TXN_ID'); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * get Payment Status |
|
| 266 | - * |
|
| 267 | - * @access public |
|
| 268 | - * @throws \EE_Error |
|
| 269 | - */ |
|
| 270 | - public function status() |
|
| 271 | - { |
|
| 272 | - return $this->get('STS_ID'); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * get Payment Status |
|
| 278 | - * |
|
| 279 | - * @access public |
|
| 280 | - * @throws \EE_Error |
|
| 281 | - */ |
|
| 282 | - public function STS_ID() |
|
| 283 | - { |
|
| 284 | - return $this->get('STS_ID'); |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * get Payment Timestamp |
|
| 290 | - * |
|
| 291 | - * @access public |
|
| 292 | - * @param string $dt_frmt |
|
| 293 | - * @param string $tm_frmt |
|
| 294 | - * @return string |
|
| 295 | - * @throws \EE_Error |
|
| 296 | - */ |
|
| 297 | - public function timestamp($dt_frmt = '', $tm_frmt = '') |
|
| 298 | - { |
|
| 299 | - return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt)); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * get Payment Source |
|
| 305 | - * |
|
| 306 | - * @access public |
|
| 307 | - * @throws \EE_Error |
|
| 308 | - */ |
|
| 309 | - public function source() |
|
| 310 | - { |
|
| 311 | - return $this->get('PAY_source'); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * get Payment Amount |
|
| 317 | - * |
|
| 318 | - * @access public |
|
| 319 | - * @return float |
|
| 320 | - * @throws \EE_Error |
|
| 321 | - */ |
|
| 322 | - public function amount() |
|
| 323 | - { |
|
| 324 | - return (float) $this->get('PAY_amount'); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * @return mixed |
|
| 330 | - * @throws \EE_Error |
|
| 331 | - */ |
|
| 332 | - public function amount_no_code() |
|
| 333 | - { |
|
| 334 | - return $this->get_pretty('PAY_amount', 'no_currency_code'); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * get Payment Gateway Response |
|
| 340 | - * |
|
| 341 | - * @access public |
|
| 342 | - * @throws \EE_Error |
|
| 343 | - */ |
|
| 344 | - public function gateway_response() |
|
| 345 | - { |
|
| 346 | - return $this->get('PAY_gateway_response'); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * get Payment Gateway Transaction ID |
|
| 352 | - * |
|
| 353 | - * @access public |
|
| 354 | - * @throws \EE_Error |
|
| 355 | - */ |
|
| 356 | - public function txn_id_chq_nmbr() |
|
| 357 | - { |
|
| 358 | - return $this->get('PAY_txn_id_chq_nmbr'); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * get Purchase Order Number |
|
| 364 | - * |
|
| 365 | - * @access public |
|
| 366 | - * @throws \EE_Error |
|
| 367 | - */ |
|
| 368 | - public function po_number() |
|
| 369 | - { |
|
| 370 | - return $this->get('PAY_po_number'); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * get Extra Accounting Field |
|
| 376 | - * |
|
| 377 | - * @access public |
|
| 378 | - * @throws \EE_Error |
|
| 379 | - */ |
|
| 380 | - public function extra_accntng() |
|
| 381 | - { |
|
| 382 | - return $this->get('PAY_extra_accntng'); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * get Payment made via admin source |
|
| 388 | - * |
|
| 389 | - * @access public |
|
| 390 | - * @throws \EE_Error |
|
| 391 | - */ |
|
| 392 | - public function payment_made_via_admin() |
|
| 393 | - { |
|
| 394 | - return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * get Payment Details |
|
| 400 | - * |
|
| 401 | - * @access public |
|
| 402 | - * @throws \EE_Error |
|
| 403 | - */ |
|
| 404 | - public function details() |
|
| 405 | - { |
|
| 406 | - return $this->get('PAY_details'); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Gets redirect_url |
|
| 412 | - * |
|
| 413 | - * @return string |
|
| 414 | - * @throws \EE_Error |
|
| 415 | - */ |
|
| 416 | - public function redirect_url() |
|
| 417 | - { |
|
| 418 | - return $this->get('PAY_redirect_url'); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Gets redirect_args |
|
| 424 | - * |
|
| 425 | - * @return array |
|
| 426 | - * @throws \EE_Error |
|
| 427 | - */ |
|
| 428 | - public function redirect_args() |
|
| 429 | - { |
|
| 430 | - return $this->get('PAY_redirect_args'); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * echoes $this->pretty_status() |
|
| 436 | - * |
|
| 437 | - * @param bool $show_icons |
|
| 438 | - * @return void |
|
| 439 | - * @throws \EE_Error |
|
| 440 | - */ |
|
| 441 | - public function e_pretty_status($show_icons = false) |
|
| 442 | - { |
|
| 443 | - echo $this->pretty_status($show_icons); |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * returns a pretty version of the status, good for displaying to users |
|
| 449 | - * |
|
| 450 | - * @param bool $show_icons |
|
| 451 | - * @return string |
|
| 452 | - * @throws \EE_Error |
|
| 453 | - */ |
|
| 454 | - public function pretty_status($show_icons = false) |
|
| 455 | - { |
|
| 456 | - $status = EEM_Status::instance()->localized_status( |
|
| 457 | - array($this->STS_ID() => __('unknown', 'event_espresso')), |
|
| 458 | - false, |
|
| 459 | - 'sentence' |
|
| 460 | - ); |
|
| 461 | - $icon = ''; |
|
| 462 | - switch ($this->STS_ID()) { |
|
| 463 | - case EEM_Payment::status_id_approved: |
|
| 464 | - $icon = $show_icons |
|
| 465 | - ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' |
|
| 466 | - : ''; |
|
| 467 | - break; |
|
| 468 | - case EEM_Payment::status_id_pending: |
|
| 469 | - $icon = $show_icons |
|
| 470 | - ? '<span class="dashicons dashicons-clock ee-icon-size-16 orange-text"></span>' |
|
| 471 | - : ''; |
|
| 472 | - break; |
|
| 473 | - case EEM_Payment::status_id_cancelled: |
|
| 474 | - $icon = $show_icons |
|
| 475 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
| 476 | - : ''; |
|
| 477 | - break; |
|
| 478 | - case EEM_Payment::status_id_declined: |
|
| 479 | - $icon = $show_icons |
|
| 480 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
| 481 | - : ''; |
|
| 482 | - break; |
|
| 483 | - } |
|
| 484 | - return $icon . $status[ $this->STS_ID() ]; |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - |
|
| 488 | - /** |
|
| 489 | - * For determining the status of the payment |
|
| 490 | - * |
|
| 491 | - * @return boolean whether the payment is approved or not |
|
| 492 | - * @throws \EE_Error |
|
| 493 | - */ |
|
| 494 | - public function is_approved() |
|
| 495 | - { |
|
| 496 | - return $this->status_is(EEM_Payment::status_id_approved); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * Generally determines if the status of this payment equals |
|
| 502 | - * the $STS_ID string |
|
| 503 | - * |
|
| 504 | - * @param string $STS_ID an ID from the esp_status table/ |
|
| 505 | - * one of the status_id_* on the EEM_Payment model |
|
| 506 | - * @return boolean whether the status of this payment equals the status id |
|
| 507 | - * @throws \EE_Error |
|
| 508 | - */ |
|
| 509 | - protected function status_is($STS_ID) |
|
| 510 | - { |
|
| 511 | - return $STS_ID === $this->STS_ID() ? true : false; |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * For determining the status of the payment |
|
| 517 | - * |
|
| 518 | - * @return boolean whether the payment is pending or not |
|
| 519 | - * @throws \EE_Error |
|
| 520 | - */ |
|
| 521 | - public function is_pending() |
|
| 522 | - { |
|
| 523 | - return $this->status_is(EEM_Payment::status_id_pending); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * For determining the status of the payment |
|
| 529 | - * |
|
| 530 | - * @return boolean |
|
| 531 | - * @throws \EE_Error |
|
| 532 | - */ |
|
| 533 | - public function is_cancelled() |
|
| 534 | - { |
|
| 535 | - return $this->status_is(EEM_Payment::status_id_cancelled); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * For determining the status of the payment |
|
| 541 | - * |
|
| 542 | - * @return boolean |
|
| 543 | - * @throws \EE_Error |
|
| 544 | - */ |
|
| 545 | - public function is_declined() |
|
| 546 | - { |
|
| 547 | - return $this->status_is(EEM_Payment::status_id_declined); |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * For determining the status of the payment |
|
| 553 | - * |
|
| 554 | - * @return boolean |
|
| 555 | - * @throws \EE_Error |
|
| 556 | - */ |
|
| 557 | - public function is_failed() |
|
| 558 | - { |
|
| 559 | - return $this->status_is(EEM_Payment::status_id_failed); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - |
|
| 563 | - /** |
|
| 564 | - * For determining if the payment is actually a refund ( ie: has a negative value ) |
|
| 565 | - * |
|
| 566 | - * @return boolean |
|
| 567 | - * @throws \EE_Error |
|
| 568 | - */ |
|
| 569 | - public function is_a_refund() |
|
| 570 | - { |
|
| 571 | - return $this->amount() < 0 ? true : false; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * Get the status object of this object |
|
| 577 | - * |
|
| 578 | - * @return EE_Status |
|
| 579 | - * @throws \EE_Error |
|
| 580 | - */ |
|
| 581 | - public function status_obj() |
|
| 582 | - { |
|
| 583 | - return $this->get_first_related('Status'); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * Gets all the extra meta info on this payment |
|
| 589 | - * |
|
| 590 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 591 | - * @return EE_Extra_Meta |
|
| 592 | - * @throws \EE_Error |
|
| 593 | - */ |
|
| 594 | - public function extra_meta($query_params = array()) |
|
| 595 | - { |
|
| 596 | - return $this->get_many_related('Extra_Meta', $query_params); |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - |
|
| 600 | - /** |
|
| 601 | - * Gets the last-used payment method on this transaction |
|
| 602 | - * (we COULD just use the last-made payment, but some payment methods, namely |
|
| 603 | - * offline ones, dont' create payments) |
|
| 604 | - * |
|
| 605 | - * @return EE_Payment_Method |
|
| 606 | - * @throws \EE_Error |
|
| 607 | - */ |
|
| 608 | - public function payment_method() |
|
| 609 | - { |
|
| 610 | - return $this->get_first_related('Payment_Method'); |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * Gets the HTML for redirecting the user to an offsite gateway |
|
| 616 | - * You can pass it special content to put inside the form, or use |
|
| 617 | - * the default inner content (or possibly generate this all yourself using |
|
| 618 | - * redirect_url() and redirect_args() or redirect_args_as_inputs()). |
|
| 619 | - * Creates a POST request by default, but if no redirect args are specified, creates a GET request instead |
|
| 620 | - * (and any querystring variables in the redirect_url are converted into html inputs |
|
| 621 | - * so browsers submit them properly) |
|
| 622 | - * |
|
| 623 | - * @param string $inside_form_html |
|
| 624 | - * @return string html |
|
| 625 | - * @throws \EE_Error |
|
| 626 | - */ |
|
| 627 | - public function redirect_form($inside_form_html = null) |
|
| 628 | - { |
|
| 629 | - $redirect_url = $this->redirect_url(); |
|
| 630 | - if (! empty($redirect_url)) { |
|
| 631 | - // what ? no inner form content? |
|
| 632 | - if ($inside_form_html === null) { |
|
| 633 | - $inside_form_html = EEH_HTML::p( |
|
| 634 | - sprintf( |
|
| 635 | - __( |
|
| 636 | - 'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s', |
|
| 637 | - 'event_espresso' |
|
| 638 | - ), |
|
| 639 | - EEH_HTML::br(2), |
|
| 640 | - '<input type="submit" value="', |
|
| 641 | - '">' |
|
| 642 | - ), |
|
| 643 | - '', |
|
| 644 | - '', |
|
| 645 | - 'text-align:center;' |
|
| 646 | - ); |
|
| 647 | - } |
|
| 648 | - $method = apply_filters( |
|
| 649 | - 'FHEE__EE_Payment__redirect_form__method', |
|
| 650 | - $this->redirect_args() ? 'POST' : 'GET', |
|
| 651 | - $this |
|
| 652 | - ); |
|
| 653 | - // if it's a GET request, we need to remove all the GET params in the querystring |
|
| 654 | - // and put them into the form instead |
|
| 655 | - if ($method === 'GET') { |
|
| 656 | - $querystring = parse_url($redirect_url, PHP_URL_QUERY); |
|
| 657 | - $get_params = null; |
|
| 658 | - parse_str($querystring, $get_params); |
|
| 659 | - $inside_form_html .= $this->_args_as_inputs($get_params); |
|
| 660 | - $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
| 661 | - } |
|
| 662 | - $form = EEH_HTML::nl(1) |
|
| 663 | - . '<form method="' |
|
| 664 | - . $method |
|
| 665 | - . '" name="gateway_form" action="' |
|
| 666 | - . $redirect_url |
|
| 667 | - . '">'; |
|
| 668 | - $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
| 669 | - $form .= $inside_form_html; |
|
| 670 | - $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
| 671 | - return $form; |
|
| 672 | - } else { |
|
| 673 | - return null; |
|
| 674 | - } |
|
| 675 | - } |
|
| 676 | - |
|
| 677 | - |
|
| 678 | - /** |
|
| 679 | - * Changes all the name-value pairs of the redirect args into html inputs |
|
| 680 | - * and returns the html as a string |
|
| 681 | - * |
|
| 682 | - * @return string |
|
| 683 | - * @throws \EE_Error |
|
| 684 | - */ |
|
| 685 | - public function redirect_args_as_inputs() |
|
| 686 | - { |
|
| 687 | - return $this->_args_as_inputs($this->redirect_args()); |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * Converts a 1d array of key-value pairs into html hidden inputs |
|
| 693 | - * and returns the string of html |
|
| 694 | - * |
|
| 695 | - * @param array $args key-value pairs |
|
| 696 | - * @return string |
|
| 697 | - */ |
|
| 698 | - protected function _args_as_inputs($args) |
|
| 699 | - { |
|
| 700 | - $html = ''; |
|
| 701 | - if ($args !== null && is_array($args)) { |
|
| 702 | - foreach ($args as $name => $value) { |
|
| 703 | - $html .= EEH_HTML::nl(0) |
|
| 704 | - . '<input type="hidden" name="' |
|
| 705 | - . $name |
|
| 706 | - . '" value="' |
|
| 707 | - . esc_attr($value) |
|
| 708 | - . '"/>'; |
|
| 709 | - } |
|
| 710 | - } |
|
| 711 | - return $html; |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - |
|
| 715 | - /** |
|
| 716 | - * Returns the currency of the payment. |
|
| 717 | - * (At the time of writing, this will always be the currency in the configuration; |
|
| 718 | - * however in the future it is anticipated that this will be stored on the payment |
|
| 719 | - * object itself) |
|
| 720 | - * |
|
| 721 | - * @return string for the currency code |
|
| 722 | - */ |
|
| 723 | - public function currency_code() |
|
| 724 | - { |
|
| 725 | - return EE_Config::instance()->currency->code; |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - |
|
| 729 | - /** |
|
| 730 | - * apply wp_strip_all_tags to all elements within an array |
|
| 731 | - * |
|
| 732 | - * @access private |
|
| 733 | - * @param mixed $item |
|
| 734 | - */ |
|
| 735 | - private function _strip_all_tags_within_array(&$item) |
|
| 736 | - { |
|
| 737 | - if (is_object($item)) { |
|
| 738 | - $item = (array) $item; |
|
| 739 | - } |
|
| 740 | - if (is_array($item)) { |
|
| 741 | - array_walk_recursive($item, array($this, '_strip_all_tags_within_array')); |
|
| 742 | - } else { |
|
| 743 | - $item = wp_strip_all_tags($item); |
|
| 744 | - } |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - |
|
| 748 | - /** |
|
| 749 | - * Returns TRUE is this payment was set to approved during this request (or |
|
| 750 | - * is approved and was created during this request). False otherwise. |
|
| 751 | - * |
|
| 752 | - * @return boolean |
|
| 753 | - * @throws \EE_Error |
|
| 754 | - */ |
|
| 755 | - public function just_approved() |
|
| 756 | - { |
|
| 757 | - $original_status = EEH_Array::is_set( |
|
| 758 | - $this->_props_n_values_provided_in_constructor, |
|
| 759 | - 'STS_ID', |
|
| 760 | - $this->get_model()->field_settings_for('STS_ID')->get_default_value() |
|
| 761 | - ); |
|
| 762 | - $current_status = $this->status(); |
|
| 763 | - if ($original_status !== EEM_Payment::status_id_approved |
|
| 764 | - && $current_status === EEM_Payment::status_id_approved |
|
| 765 | - ) { |
|
| 766 | - return true; |
|
| 767 | - } else { |
|
| 768 | - return false; |
|
| 769 | - } |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - |
|
| 773 | - /** |
|
| 774 | - * Overrides parents' get_pretty() function just for legacy reasons |
|
| 775 | - * (to allow ticket https://events.codebasehq.com/projects/event-espresso/tickets/7420) |
|
| 776 | - * |
|
| 777 | - * @param string $field_name |
|
| 778 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 779 | - * (in cases where the same property may be used for different outputs |
|
| 780 | - * - i.e. datetime, money etc.) |
|
| 781 | - * @return mixed |
|
| 782 | - * @throws \EE_Error |
|
| 783 | - */ |
|
| 784 | - public function get_pretty($field_name, $extra_cache_ref = null) |
|
| 785 | - { |
|
| 786 | - if ($field_name === 'PAY_gateway') { |
|
| 787 | - return $this->payment_method() ? $this->payment_method()->name() : __('Unknown', 'event_espresso'); |
|
| 788 | - } |
|
| 789 | - return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
| 790 | - } |
|
| 791 | - |
|
| 792 | - |
|
| 793 | - /** |
|
| 794 | - * Gets details regarding which registrations this payment was applied to |
|
| 795 | - * |
|
| 796 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 797 | - * @return EE_Registration_Payment[] |
|
| 798 | - * @throws \EE_Error |
|
| 799 | - */ |
|
| 800 | - public function registration_payments($query_params = array()) |
|
| 801 | - { |
|
| 802 | - return $this->get_many_related('Registration_Payment', $query_params); |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - |
|
| 806 | - /** |
|
| 807 | - * Gets the first event for this payment (it's possible that it could be for multiple) |
|
| 808 | - * |
|
| 809 | - * @return EE_Event|null |
|
| 810 | - */ |
|
| 811 | - public function get_first_event() |
|
| 812 | - { |
|
| 813 | - $transaction = $this->transaction(); |
|
| 814 | - if ($transaction instanceof EE_Transaction) { |
|
| 815 | - $primary_registrant = $transaction->primary_registration(); |
|
| 816 | - if ($primary_registrant instanceof EE_Registration) { |
|
| 817 | - return $primary_registrant->event_obj(); |
|
| 818 | - } |
|
| 819 | - } |
|
| 820 | - return null; |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - |
|
| 824 | - /** |
|
| 825 | - * Gets the name of the first event for which is being paid |
|
| 826 | - * |
|
| 827 | - * @return string |
|
| 828 | - */ |
|
| 829 | - public function get_first_event_name() |
|
| 830 | - { |
|
| 831 | - $event = $this->get_first_event(); |
|
| 832 | - return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso'); |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - |
|
| 836 | - /** |
|
| 837 | - * Returns the payment's transaction's primary registration |
|
| 838 | - * |
|
| 839 | - * @return EE_Registration|null |
|
| 840 | - */ |
|
| 841 | - public function get_primary_registration() |
|
| 842 | - { |
|
| 843 | - if ($this->transaction() instanceof EE_Transaction) { |
|
| 844 | - return $this->transaction()->primary_registration(); |
|
| 845 | - } |
|
| 846 | - return null; |
|
| 847 | - } |
|
| 848 | - |
|
| 849 | - |
|
| 850 | - /** |
|
| 851 | - * Gets the payment's transaction's primary registration's attendee, or null |
|
| 852 | - * |
|
| 853 | - * @return EE_Attendee|null |
|
| 854 | - */ |
|
| 855 | - public function get_primary_attendee() |
|
| 856 | - { |
|
| 857 | - $primary_reg = $this->get_primary_registration(); |
|
| 858 | - if ($primary_reg instanceof EE_Registration) { |
|
| 859 | - return $primary_reg->attendee(); |
|
| 860 | - } |
|
| 861 | - return null; |
|
| 862 | - } |
|
| 12 | + /** |
|
| 13 | + * @param array $props_n_values incoming values |
|
| 14 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 15 | + * used.) |
|
| 16 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 17 | + * date_format and the second value is the time format |
|
| 18 | + * @return EE_Payment |
|
| 19 | + * @throws \EE_Error |
|
| 20 | + */ |
|
| 21 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 22 | + { |
|
| 23 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 24 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @param array $props_n_values incoming values from the database |
|
| 30 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 31 | + * the website will be used. |
|
| 32 | + * @return EE_Payment |
|
| 33 | + * @throws \EE_Error |
|
| 34 | + */ |
|
| 35 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 36 | + { |
|
| 37 | + return new self($props_n_values, true, $timezone); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Set Transaction ID |
|
| 43 | + * |
|
| 44 | + * @access public |
|
| 45 | + * @param int $TXN_ID |
|
| 46 | + * @throws \EE_Error |
|
| 47 | + */ |
|
| 48 | + public function set_transaction_id($TXN_ID = 0) |
|
| 49 | + { |
|
| 50 | + $this->set('TXN_ID', $TXN_ID); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Gets the transaction related to this payment |
|
| 56 | + * |
|
| 57 | + * @return EE_Transaction |
|
| 58 | + * @throws \EE_Error |
|
| 59 | + */ |
|
| 60 | + public function transaction() |
|
| 61 | + { |
|
| 62 | + return $this->get_first_related('Transaction'); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Set Status |
|
| 68 | + * |
|
| 69 | + * @access public |
|
| 70 | + * @param string $STS_ID |
|
| 71 | + * @throws \EE_Error |
|
| 72 | + */ |
|
| 73 | + public function set_status($STS_ID = '') |
|
| 74 | + { |
|
| 75 | + $this->set('STS_ID', $STS_ID); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Set Payment Timestamp |
|
| 81 | + * |
|
| 82 | + * @access public |
|
| 83 | + * @param int $timestamp |
|
| 84 | + * @throws \EE_Error |
|
| 85 | + */ |
|
| 86 | + public function set_timestamp($timestamp = 0) |
|
| 87 | + { |
|
| 88 | + $this->set('PAY_timestamp', $timestamp); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Set Payment Method |
|
| 94 | + * |
|
| 95 | + * @access public |
|
| 96 | + * @param string $PAY_source |
|
| 97 | + * @throws \EE_Error |
|
| 98 | + */ |
|
| 99 | + public function set_source($PAY_source = '') |
|
| 100 | + { |
|
| 101 | + $this->set('PAY_source', $PAY_source); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Set Payment Amount |
|
| 107 | + * |
|
| 108 | + * @access public |
|
| 109 | + * @param float $amount |
|
| 110 | + * @throws \EE_Error |
|
| 111 | + */ |
|
| 112 | + public function set_amount($amount = 0.00) |
|
| 113 | + { |
|
| 114 | + $this->set('PAY_amount', (float) $amount); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Set Payment Gateway Response |
|
| 120 | + * |
|
| 121 | + * @access public |
|
| 122 | + * @param string $gateway_response |
|
| 123 | + * @throws \EE_Error |
|
| 124 | + */ |
|
| 125 | + public function set_gateway_response($gateway_response = '') |
|
| 126 | + { |
|
| 127 | + $this->set('PAY_gateway_response', $gateway_response); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Returns the name of the payment method used on this payment (previously known merely as 'gateway') |
|
| 133 | + * but since 4.6.0, payment methods are models and the payment keeps a foreign key to the payment method |
|
| 134 | + * used on it |
|
| 135 | + * |
|
| 136 | + * @deprecated |
|
| 137 | + * @return string |
|
| 138 | + * @throws \EE_Error |
|
| 139 | + */ |
|
| 140 | + public function gateway() |
|
| 141 | + { |
|
| 142 | + EE_Error::doing_it_wrong( |
|
| 143 | + 'EE_Payment::gateway', |
|
| 144 | + __( |
|
| 145 | + 'The method EE_Payment::gateway() has been deprecated. Consider instead using EE_Payment::payment_method()->name()', |
|
| 146 | + 'event_espresso' |
|
| 147 | + ), |
|
| 148 | + '4.6.0' |
|
| 149 | + ); |
|
| 150 | + return $this->payment_method() ? $this->payment_method()->name() : __('Unknown', 'event_espresso'); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Set Gateway Transaction ID |
|
| 156 | + * |
|
| 157 | + * @access public |
|
| 158 | + * @param string $txn_id_chq_nmbr |
|
| 159 | + * @throws \EE_Error |
|
| 160 | + */ |
|
| 161 | + public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '') |
|
| 162 | + { |
|
| 163 | + $this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Set Purchase Order Number |
|
| 169 | + * |
|
| 170 | + * @access public |
|
| 171 | + * @param string $po_number |
|
| 172 | + * @throws \EE_Error |
|
| 173 | + */ |
|
| 174 | + public function set_po_number($po_number = '') |
|
| 175 | + { |
|
| 176 | + $this->set('PAY_po_number', $po_number); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Set Extra Accounting Field |
|
| 182 | + * |
|
| 183 | + * @access public |
|
| 184 | + * @param string $extra_accntng |
|
| 185 | + * @throws \EE_Error |
|
| 186 | + */ |
|
| 187 | + public function set_extra_accntng($extra_accntng = '') |
|
| 188 | + { |
|
| 189 | + $this->set('PAY_extra_accntng', $extra_accntng); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Set Payment made via admin flag |
|
| 195 | + * |
|
| 196 | + * @access public |
|
| 197 | + * @param bool $via_admin |
|
| 198 | + * @throws \EE_Error |
|
| 199 | + */ |
|
| 200 | + public function set_payment_made_via_admin($via_admin = false) |
|
| 201 | + { |
|
| 202 | + if ($via_admin) { |
|
| 203 | + $this->set('PAY_source', EEM_Payment_Method::scope_admin); |
|
| 204 | + } else { |
|
| 205 | + $this->set('PAY_source', EEM_Payment_Method::scope_cart); |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Set Payment Details |
|
| 212 | + * |
|
| 213 | + * @access public |
|
| 214 | + * @param string|array $details |
|
| 215 | + * @throws \EE_Error |
|
| 216 | + */ |
|
| 217 | + public function set_details($details = '') |
|
| 218 | + { |
|
| 219 | + if (is_array($details)) { |
|
| 220 | + array_walk_recursive($details, array($this, '_strip_all_tags_within_array')); |
|
| 221 | + } else { |
|
| 222 | + $details = wp_strip_all_tags($details); |
|
| 223 | + } |
|
| 224 | + $this->set('PAY_details', $details); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Sets redirect_url |
|
| 230 | + * |
|
| 231 | + * @param string $redirect_url |
|
| 232 | + * @throws \EE_Error |
|
| 233 | + */ |
|
| 234 | + public function set_redirect_url($redirect_url) |
|
| 235 | + { |
|
| 236 | + $this->set('PAY_redirect_url', $redirect_url); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Sets redirect_args |
|
| 242 | + * |
|
| 243 | + * @param array $redirect_args |
|
| 244 | + * @throws \EE_Error |
|
| 245 | + */ |
|
| 246 | + public function set_redirect_args($redirect_args) |
|
| 247 | + { |
|
| 248 | + $this->set('PAY_redirect_args', $redirect_args); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * get Payment Transaction ID |
|
| 254 | + * |
|
| 255 | + * @access public |
|
| 256 | + * @throws \EE_Error |
|
| 257 | + */ |
|
| 258 | + public function TXN_ID() |
|
| 259 | + { |
|
| 260 | + return $this->get('TXN_ID'); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * get Payment Status |
|
| 266 | + * |
|
| 267 | + * @access public |
|
| 268 | + * @throws \EE_Error |
|
| 269 | + */ |
|
| 270 | + public function status() |
|
| 271 | + { |
|
| 272 | + return $this->get('STS_ID'); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * get Payment Status |
|
| 278 | + * |
|
| 279 | + * @access public |
|
| 280 | + * @throws \EE_Error |
|
| 281 | + */ |
|
| 282 | + public function STS_ID() |
|
| 283 | + { |
|
| 284 | + return $this->get('STS_ID'); |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * get Payment Timestamp |
|
| 290 | + * |
|
| 291 | + * @access public |
|
| 292 | + * @param string $dt_frmt |
|
| 293 | + * @param string $tm_frmt |
|
| 294 | + * @return string |
|
| 295 | + * @throws \EE_Error |
|
| 296 | + */ |
|
| 297 | + public function timestamp($dt_frmt = '', $tm_frmt = '') |
|
| 298 | + { |
|
| 299 | + return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt)); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * get Payment Source |
|
| 305 | + * |
|
| 306 | + * @access public |
|
| 307 | + * @throws \EE_Error |
|
| 308 | + */ |
|
| 309 | + public function source() |
|
| 310 | + { |
|
| 311 | + return $this->get('PAY_source'); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * get Payment Amount |
|
| 317 | + * |
|
| 318 | + * @access public |
|
| 319 | + * @return float |
|
| 320 | + * @throws \EE_Error |
|
| 321 | + */ |
|
| 322 | + public function amount() |
|
| 323 | + { |
|
| 324 | + return (float) $this->get('PAY_amount'); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * @return mixed |
|
| 330 | + * @throws \EE_Error |
|
| 331 | + */ |
|
| 332 | + public function amount_no_code() |
|
| 333 | + { |
|
| 334 | + return $this->get_pretty('PAY_amount', 'no_currency_code'); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * get Payment Gateway Response |
|
| 340 | + * |
|
| 341 | + * @access public |
|
| 342 | + * @throws \EE_Error |
|
| 343 | + */ |
|
| 344 | + public function gateway_response() |
|
| 345 | + { |
|
| 346 | + return $this->get('PAY_gateway_response'); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * get Payment Gateway Transaction ID |
|
| 352 | + * |
|
| 353 | + * @access public |
|
| 354 | + * @throws \EE_Error |
|
| 355 | + */ |
|
| 356 | + public function txn_id_chq_nmbr() |
|
| 357 | + { |
|
| 358 | + return $this->get('PAY_txn_id_chq_nmbr'); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * get Purchase Order Number |
|
| 364 | + * |
|
| 365 | + * @access public |
|
| 366 | + * @throws \EE_Error |
|
| 367 | + */ |
|
| 368 | + public function po_number() |
|
| 369 | + { |
|
| 370 | + return $this->get('PAY_po_number'); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * get Extra Accounting Field |
|
| 376 | + * |
|
| 377 | + * @access public |
|
| 378 | + * @throws \EE_Error |
|
| 379 | + */ |
|
| 380 | + public function extra_accntng() |
|
| 381 | + { |
|
| 382 | + return $this->get('PAY_extra_accntng'); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * get Payment made via admin source |
|
| 388 | + * |
|
| 389 | + * @access public |
|
| 390 | + * @throws \EE_Error |
|
| 391 | + */ |
|
| 392 | + public function payment_made_via_admin() |
|
| 393 | + { |
|
| 394 | + return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * get Payment Details |
|
| 400 | + * |
|
| 401 | + * @access public |
|
| 402 | + * @throws \EE_Error |
|
| 403 | + */ |
|
| 404 | + public function details() |
|
| 405 | + { |
|
| 406 | + return $this->get('PAY_details'); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Gets redirect_url |
|
| 412 | + * |
|
| 413 | + * @return string |
|
| 414 | + * @throws \EE_Error |
|
| 415 | + */ |
|
| 416 | + public function redirect_url() |
|
| 417 | + { |
|
| 418 | + return $this->get('PAY_redirect_url'); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Gets redirect_args |
|
| 424 | + * |
|
| 425 | + * @return array |
|
| 426 | + * @throws \EE_Error |
|
| 427 | + */ |
|
| 428 | + public function redirect_args() |
|
| 429 | + { |
|
| 430 | + return $this->get('PAY_redirect_args'); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * echoes $this->pretty_status() |
|
| 436 | + * |
|
| 437 | + * @param bool $show_icons |
|
| 438 | + * @return void |
|
| 439 | + * @throws \EE_Error |
|
| 440 | + */ |
|
| 441 | + public function e_pretty_status($show_icons = false) |
|
| 442 | + { |
|
| 443 | + echo $this->pretty_status($show_icons); |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * returns a pretty version of the status, good for displaying to users |
|
| 449 | + * |
|
| 450 | + * @param bool $show_icons |
|
| 451 | + * @return string |
|
| 452 | + * @throws \EE_Error |
|
| 453 | + */ |
|
| 454 | + public function pretty_status($show_icons = false) |
|
| 455 | + { |
|
| 456 | + $status = EEM_Status::instance()->localized_status( |
|
| 457 | + array($this->STS_ID() => __('unknown', 'event_espresso')), |
|
| 458 | + false, |
|
| 459 | + 'sentence' |
|
| 460 | + ); |
|
| 461 | + $icon = ''; |
|
| 462 | + switch ($this->STS_ID()) { |
|
| 463 | + case EEM_Payment::status_id_approved: |
|
| 464 | + $icon = $show_icons |
|
| 465 | + ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' |
|
| 466 | + : ''; |
|
| 467 | + break; |
|
| 468 | + case EEM_Payment::status_id_pending: |
|
| 469 | + $icon = $show_icons |
|
| 470 | + ? '<span class="dashicons dashicons-clock ee-icon-size-16 orange-text"></span>' |
|
| 471 | + : ''; |
|
| 472 | + break; |
|
| 473 | + case EEM_Payment::status_id_cancelled: |
|
| 474 | + $icon = $show_icons |
|
| 475 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
| 476 | + : ''; |
|
| 477 | + break; |
|
| 478 | + case EEM_Payment::status_id_declined: |
|
| 479 | + $icon = $show_icons |
|
| 480 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
| 481 | + : ''; |
|
| 482 | + break; |
|
| 483 | + } |
|
| 484 | + return $icon . $status[ $this->STS_ID() ]; |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + |
|
| 488 | + /** |
|
| 489 | + * For determining the status of the payment |
|
| 490 | + * |
|
| 491 | + * @return boolean whether the payment is approved or not |
|
| 492 | + * @throws \EE_Error |
|
| 493 | + */ |
|
| 494 | + public function is_approved() |
|
| 495 | + { |
|
| 496 | + return $this->status_is(EEM_Payment::status_id_approved); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * Generally determines if the status of this payment equals |
|
| 502 | + * the $STS_ID string |
|
| 503 | + * |
|
| 504 | + * @param string $STS_ID an ID from the esp_status table/ |
|
| 505 | + * one of the status_id_* on the EEM_Payment model |
|
| 506 | + * @return boolean whether the status of this payment equals the status id |
|
| 507 | + * @throws \EE_Error |
|
| 508 | + */ |
|
| 509 | + protected function status_is($STS_ID) |
|
| 510 | + { |
|
| 511 | + return $STS_ID === $this->STS_ID() ? true : false; |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * For determining the status of the payment |
|
| 517 | + * |
|
| 518 | + * @return boolean whether the payment is pending or not |
|
| 519 | + * @throws \EE_Error |
|
| 520 | + */ |
|
| 521 | + public function is_pending() |
|
| 522 | + { |
|
| 523 | + return $this->status_is(EEM_Payment::status_id_pending); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * For determining the status of the payment |
|
| 529 | + * |
|
| 530 | + * @return boolean |
|
| 531 | + * @throws \EE_Error |
|
| 532 | + */ |
|
| 533 | + public function is_cancelled() |
|
| 534 | + { |
|
| 535 | + return $this->status_is(EEM_Payment::status_id_cancelled); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * For determining the status of the payment |
|
| 541 | + * |
|
| 542 | + * @return boolean |
|
| 543 | + * @throws \EE_Error |
|
| 544 | + */ |
|
| 545 | + public function is_declined() |
|
| 546 | + { |
|
| 547 | + return $this->status_is(EEM_Payment::status_id_declined); |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * For determining the status of the payment |
|
| 553 | + * |
|
| 554 | + * @return boolean |
|
| 555 | + * @throws \EE_Error |
|
| 556 | + */ |
|
| 557 | + public function is_failed() |
|
| 558 | + { |
|
| 559 | + return $this->status_is(EEM_Payment::status_id_failed); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + |
|
| 563 | + /** |
|
| 564 | + * For determining if the payment is actually a refund ( ie: has a negative value ) |
|
| 565 | + * |
|
| 566 | + * @return boolean |
|
| 567 | + * @throws \EE_Error |
|
| 568 | + */ |
|
| 569 | + public function is_a_refund() |
|
| 570 | + { |
|
| 571 | + return $this->amount() < 0 ? true : false; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * Get the status object of this object |
|
| 577 | + * |
|
| 578 | + * @return EE_Status |
|
| 579 | + * @throws \EE_Error |
|
| 580 | + */ |
|
| 581 | + public function status_obj() |
|
| 582 | + { |
|
| 583 | + return $this->get_first_related('Status'); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * Gets all the extra meta info on this payment |
|
| 589 | + * |
|
| 590 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 591 | + * @return EE_Extra_Meta |
|
| 592 | + * @throws \EE_Error |
|
| 593 | + */ |
|
| 594 | + public function extra_meta($query_params = array()) |
|
| 595 | + { |
|
| 596 | + return $this->get_many_related('Extra_Meta', $query_params); |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + |
|
| 600 | + /** |
|
| 601 | + * Gets the last-used payment method on this transaction |
|
| 602 | + * (we COULD just use the last-made payment, but some payment methods, namely |
|
| 603 | + * offline ones, dont' create payments) |
|
| 604 | + * |
|
| 605 | + * @return EE_Payment_Method |
|
| 606 | + * @throws \EE_Error |
|
| 607 | + */ |
|
| 608 | + public function payment_method() |
|
| 609 | + { |
|
| 610 | + return $this->get_first_related('Payment_Method'); |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * Gets the HTML for redirecting the user to an offsite gateway |
|
| 616 | + * You can pass it special content to put inside the form, or use |
|
| 617 | + * the default inner content (or possibly generate this all yourself using |
|
| 618 | + * redirect_url() and redirect_args() or redirect_args_as_inputs()). |
|
| 619 | + * Creates a POST request by default, but if no redirect args are specified, creates a GET request instead |
|
| 620 | + * (and any querystring variables in the redirect_url are converted into html inputs |
|
| 621 | + * so browsers submit them properly) |
|
| 622 | + * |
|
| 623 | + * @param string $inside_form_html |
|
| 624 | + * @return string html |
|
| 625 | + * @throws \EE_Error |
|
| 626 | + */ |
|
| 627 | + public function redirect_form($inside_form_html = null) |
|
| 628 | + { |
|
| 629 | + $redirect_url = $this->redirect_url(); |
|
| 630 | + if (! empty($redirect_url)) { |
|
| 631 | + // what ? no inner form content? |
|
| 632 | + if ($inside_form_html === null) { |
|
| 633 | + $inside_form_html = EEH_HTML::p( |
|
| 634 | + sprintf( |
|
| 635 | + __( |
|
| 636 | + 'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s', |
|
| 637 | + 'event_espresso' |
|
| 638 | + ), |
|
| 639 | + EEH_HTML::br(2), |
|
| 640 | + '<input type="submit" value="', |
|
| 641 | + '">' |
|
| 642 | + ), |
|
| 643 | + '', |
|
| 644 | + '', |
|
| 645 | + 'text-align:center;' |
|
| 646 | + ); |
|
| 647 | + } |
|
| 648 | + $method = apply_filters( |
|
| 649 | + 'FHEE__EE_Payment__redirect_form__method', |
|
| 650 | + $this->redirect_args() ? 'POST' : 'GET', |
|
| 651 | + $this |
|
| 652 | + ); |
|
| 653 | + // if it's a GET request, we need to remove all the GET params in the querystring |
|
| 654 | + // and put them into the form instead |
|
| 655 | + if ($method === 'GET') { |
|
| 656 | + $querystring = parse_url($redirect_url, PHP_URL_QUERY); |
|
| 657 | + $get_params = null; |
|
| 658 | + parse_str($querystring, $get_params); |
|
| 659 | + $inside_form_html .= $this->_args_as_inputs($get_params); |
|
| 660 | + $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
| 661 | + } |
|
| 662 | + $form = EEH_HTML::nl(1) |
|
| 663 | + . '<form method="' |
|
| 664 | + . $method |
|
| 665 | + . '" name="gateway_form" action="' |
|
| 666 | + . $redirect_url |
|
| 667 | + . '">'; |
|
| 668 | + $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
| 669 | + $form .= $inside_form_html; |
|
| 670 | + $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
| 671 | + return $form; |
|
| 672 | + } else { |
|
| 673 | + return null; |
|
| 674 | + } |
|
| 675 | + } |
|
| 676 | + |
|
| 677 | + |
|
| 678 | + /** |
|
| 679 | + * Changes all the name-value pairs of the redirect args into html inputs |
|
| 680 | + * and returns the html as a string |
|
| 681 | + * |
|
| 682 | + * @return string |
|
| 683 | + * @throws \EE_Error |
|
| 684 | + */ |
|
| 685 | + public function redirect_args_as_inputs() |
|
| 686 | + { |
|
| 687 | + return $this->_args_as_inputs($this->redirect_args()); |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * Converts a 1d array of key-value pairs into html hidden inputs |
|
| 693 | + * and returns the string of html |
|
| 694 | + * |
|
| 695 | + * @param array $args key-value pairs |
|
| 696 | + * @return string |
|
| 697 | + */ |
|
| 698 | + protected function _args_as_inputs($args) |
|
| 699 | + { |
|
| 700 | + $html = ''; |
|
| 701 | + if ($args !== null && is_array($args)) { |
|
| 702 | + foreach ($args as $name => $value) { |
|
| 703 | + $html .= EEH_HTML::nl(0) |
|
| 704 | + . '<input type="hidden" name="' |
|
| 705 | + . $name |
|
| 706 | + . '" value="' |
|
| 707 | + . esc_attr($value) |
|
| 708 | + . '"/>'; |
|
| 709 | + } |
|
| 710 | + } |
|
| 711 | + return $html; |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + |
|
| 715 | + /** |
|
| 716 | + * Returns the currency of the payment. |
|
| 717 | + * (At the time of writing, this will always be the currency in the configuration; |
|
| 718 | + * however in the future it is anticipated that this will be stored on the payment |
|
| 719 | + * object itself) |
|
| 720 | + * |
|
| 721 | + * @return string for the currency code |
|
| 722 | + */ |
|
| 723 | + public function currency_code() |
|
| 724 | + { |
|
| 725 | + return EE_Config::instance()->currency->code; |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + |
|
| 729 | + /** |
|
| 730 | + * apply wp_strip_all_tags to all elements within an array |
|
| 731 | + * |
|
| 732 | + * @access private |
|
| 733 | + * @param mixed $item |
|
| 734 | + */ |
|
| 735 | + private function _strip_all_tags_within_array(&$item) |
|
| 736 | + { |
|
| 737 | + if (is_object($item)) { |
|
| 738 | + $item = (array) $item; |
|
| 739 | + } |
|
| 740 | + if (is_array($item)) { |
|
| 741 | + array_walk_recursive($item, array($this, '_strip_all_tags_within_array')); |
|
| 742 | + } else { |
|
| 743 | + $item = wp_strip_all_tags($item); |
|
| 744 | + } |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + |
|
| 748 | + /** |
|
| 749 | + * Returns TRUE is this payment was set to approved during this request (or |
|
| 750 | + * is approved and was created during this request). False otherwise. |
|
| 751 | + * |
|
| 752 | + * @return boolean |
|
| 753 | + * @throws \EE_Error |
|
| 754 | + */ |
|
| 755 | + public function just_approved() |
|
| 756 | + { |
|
| 757 | + $original_status = EEH_Array::is_set( |
|
| 758 | + $this->_props_n_values_provided_in_constructor, |
|
| 759 | + 'STS_ID', |
|
| 760 | + $this->get_model()->field_settings_for('STS_ID')->get_default_value() |
|
| 761 | + ); |
|
| 762 | + $current_status = $this->status(); |
|
| 763 | + if ($original_status !== EEM_Payment::status_id_approved |
|
| 764 | + && $current_status === EEM_Payment::status_id_approved |
|
| 765 | + ) { |
|
| 766 | + return true; |
|
| 767 | + } else { |
|
| 768 | + return false; |
|
| 769 | + } |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + |
|
| 773 | + /** |
|
| 774 | + * Overrides parents' get_pretty() function just for legacy reasons |
|
| 775 | + * (to allow ticket https://events.codebasehq.com/projects/event-espresso/tickets/7420) |
|
| 776 | + * |
|
| 777 | + * @param string $field_name |
|
| 778 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 779 | + * (in cases where the same property may be used for different outputs |
|
| 780 | + * - i.e. datetime, money etc.) |
|
| 781 | + * @return mixed |
|
| 782 | + * @throws \EE_Error |
|
| 783 | + */ |
|
| 784 | + public function get_pretty($field_name, $extra_cache_ref = null) |
|
| 785 | + { |
|
| 786 | + if ($field_name === 'PAY_gateway') { |
|
| 787 | + return $this->payment_method() ? $this->payment_method()->name() : __('Unknown', 'event_espresso'); |
|
| 788 | + } |
|
| 789 | + return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
| 790 | + } |
|
| 791 | + |
|
| 792 | + |
|
| 793 | + /** |
|
| 794 | + * Gets details regarding which registrations this payment was applied to |
|
| 795 | + * |
|
| 796 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 797 | + * @return EE_Registration_Payment[] |
|
| 798 | + * @throws \EE_Error |
|
| 799 | + */ |
|
| 800 | + public function registration_payments($query_params = array()) |
|
| 801 | + { |
|
| 802 | + return $this->get_many_related('Registration_Payment', $query_params); |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + |
|
| 806 | + /** |
|
| 807 | + * Gets the first event for this payment (it's possible that it could be for multiple) |
|
| 808 | + * |
|
| 809 | + * @return EE_Event|null |
|
| 810 | + */ |
|
| 811 | + public function get_first_event() |
|
| 812 | + { |
|
| 813 | + $transaction = $this->transaction(); |
|
| 814 | + if ($transaction instanceof EE_Transaction) { |
|
| 815 | + $primary_registrant = $transaction->primary_registration(); |
|
| 816 | + if ($primary_registrant instanceof EE_Registration) { |
|
| 817 | + return $primary_registrant->event_obj(); |
|
| 818 | + } |
|
| 819 | + } |
|
| 820 | + return null; |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + |
|
| 824 | + /** |
|
| 825 | + * Gets the name of the first event for which is being paid |
|
| 826 | + * |
|
| 827 | + * @return string |
|
| 828 | + */ |
|
| 829 | + public function get_first_event_name() |
|
| 830 | + { |
|
| 831 | + $event = $this->get_first_event(); |
|
| 832 | + return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso'); |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + |
|
| 836 | + /** |
|
| 837 | + * Returns the payment's transaction's primary registration |
|
| 838 | + * |
|
| 839 | + * @return EE_Registration|null |
|
| 840 | + */ |
|
| 841 | + public function get_primary_registration() |
|
| 842 | + { |
|
| 843 | + if ($this->transaction() instanceof EE_Transaction) { |
|
| 844 | + return $this->transaction()->primary_registration(); |
|
| 845 | + } |
|
| 846 | + return null; |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + |
|
| 850 | + /** |
|
| 851 | + * Gets the payment's transaction's primary registration's attendee, or null |
|
| 852 | + * |
|
| 853 | + * @return EE_Attendee|null |
|
| 854 | + */ |
|
| 855 | + public function get_primary_attendee() |
|
| 856 | + { |
|
| 857 | + $primary_reg = $this->get_primary_registration(); |
|
| 858 | + if ($primary_reg instanceof EE_Registration) { |
|
| 859 | + return $primary_reg->attendee(); |
|
| 860 | + } |
|
| 861 | + return null; |
|
| 862 | + } |
|
| 863 | 863 | } |
@@ -12,142 +12,142 @@ |
||
| 12 | 12 | class EE_Status extends EE_Base_Class |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @param array $props_n_values |
|
| 17 | - * @return EE_Status |
|
| 18 | - */ |
|
| 19 | - public static function new_instance($props_n_values = array()) |
|
| 20 | - { |
|
| 21 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 22 | - return $has_object ? $has_object : new self($props_n_values); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @param array $props_n_values |
|
| 28 | - * @return EE_Status |
|
| 29 | - */ |
|
| 30 | - public static function new_instance_from_db($props_n_values = array()) |
|
| 31 | - { |
|
| 32 | - return new self($props_n_values, true); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Gets code |
|
| 38 | - * |
|
| 39 | - * @param bool $plural |
|
| 40 | - * @param string $schema |
|
| 41 | - * @return string |
|
| 42 | - */ |
|
| 43 | - public function code($plural = false, $schema = 'upper') |
|
| 44 | - { |
|
| 45 | - $id = $this->get('STS_ID'); |
|
| 46 | - $code = EEM_Status::instance()->localized_status(array($id => $this->get('STS_code')), $plural, $schema); |
|
| 47 | - return $code[ $id ]; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Sets code |
|
| 53 | - * |
|
| 54 | - * @param string $code |
|
| 55 | - * @return boolean |
|
| 56 | - */ |
|
| 57 | - public function set_code($code) |
|
| 58 | - { |
|
| 59 | - $this->set('STS_code', $code); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Gets desc |
|
| 65 | - * |
|
| 66 | - * @return string |
|
| 67 | - */ |
|
| 68 | - public function desc() |
|
| 69 | - { |
|
| 70 | - return $this->get('STS_desc'); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Sets desc |
|
| 76 | - * |
|
| 77 | - * @param string $desc |
|
| 78 | - * @return boolean |
|
| 79 | - */ |
|
| 80 | - public function set_desc($desc) |
|
| 81 | - { |
|
| 82 | - $this->set('STS_desc', $desc); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Gets type |
|
| 88 | - * |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 91 | - public function type() |
|
| 92 | - { |
|
| 93 | - return $this->get('STS_type'); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Sets type |
|
| 99 | - * |
|
| 100 | - * @param string $type |
|
| 101 | - * @return boolean |
|
| 102 | - */ |
|
| 103 | - public function set_type($type) |
|
| 104 | - { |
|
| 105 | - $this->set('STS_type', $type); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Gets can_edit |
|
| 111 | - * |
|
| 112 | - * @return boolean |
|
| 113 | - */ |
|
| 114 | - public function can_edit() |
|
| 115 | - { |
|
| 116 | - return $this->get('STS_can_edit'); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Sets can_edit |
|
| 122 | - * |
|
| 123 | - * @param boolean $can_edit |
|
| 124 | - * @return boolean |
|
| 125 | - */ |
|
| 126 | - public function set_can_edit($can_edit) |
|
| 127 | - { |
|
| 128 | - $this->set('STS_can_edit', $can_edit); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Gets open |
|
| 134 | - * |
|
| 135 | - * @return boolean |
|
| 136 | - */ |
|
| 137 | - public function open() |
|
| 138 | - { |
|
| 139 | - return $this->get('STS_open'); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Sets open |
|
| 145 | - * |
|
| 146 | - * @param boolean $open |
|
| 147 | - * @return boolean |
|
| 148 | - */ |
|
| 149 | - public function set_open($open) |
|
| 150 | - { |
|
| 151 | - $this->set('STS_open', $open); |
|
| 152 | - } |
|
| 15 | + /** |
|
| 16 | + * @param array $props_n_values |
|
| 17 | + * @return EE_Status |
|
| 18 | + */ |
|
| 19 | + public static function new_instance($props_n_values = array()) |
|
| 20 | + { |
|
| 21 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 22 | + return $has_object ? $has_object : new self($props_n_values); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @param array $props_n_values |
|
| 28 | + * @return EE_Status |
|
| 29 | + */ |
|
| 30 | + public static function new_instance_from_db($props_n_values = array()) |
|
| 31 | + { |
|
| 32 | + return new self($props_n_values, true); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Gets code |
|
| 38 | + * |
|
| 39 | + * @param bool $plural |
|
| 40 | + * @param string $schema |
|
| 41 | + * @return string |
|
| 42 | + */ |
|
| 43 | + public function code($plural = false, $schema = 'upper') |
|
| 44 | + { |
|
| 45 | + $id = $this->get('STS_ID'); |
|
| 46 | + $code = EEM_Status::instance()->localized_status(array($id => $this->get('STS_code')), $plural, $schema); |
|
| 47 | + return $code[ $id ]; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Sets code |
|
| 53 | + * |
|
| 54 | + * @param string $code |
|
| 55 | + * @return boolean |
|
| 56 | + */ |
|
| 57 | + public function set_code($code) |
|
| 58 | + { |
|
| 59 | + $this->set('STS_code', $code); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Gets desc |
|
| 65 | + * |
|
| 66 | + * @return string |
|
| 67 | + */ |
|
| 68 | + public function desc() |
|
| 69 | + { |
|
| 70 | + return $this->get('STS_desc'); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Sets desc |
|
| 76 | + * |
|
| 77 | + * @param string $desc |
|
| 78 | + * @return boolean |
|
| 79 | + */ |
|
| 80 | + public function set_desc($desc) |
|
| 81 | + { |
|
| 82 | + $this->set('STS_desc', $desc); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Gets type |
|
| 88 | + * |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | + public function type() |
|
| 92 | + { |
|
| 93 | + return $this->get('STS_type'); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Sets type |
|
| 99 | + * |
|
| 100 | + * @param string $type |
|
| 101 | + * @return boolean |
|
| 102 | + */ |
|
| 103 | + public function set_type($type) |
|
| 104 | + { |
|
| 105 | + $this->set('STS_type', $type); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Gets can_edit |
|
| 111 | + * |
|
| 112 | + * @return boolean |
|
| 113 | + */ |
|
| 114 | + public function can_edit() |
|
| 115 | + { |
|
| 116 | + return $this->get('STS_can_edit'); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Sets can_edit |
|
| 122 | + * |
|
| 123 | + * @param boolean $can_edit |
|
| 124 | + * @return boolean |
|
| 125 | + */ |
|
| 126 | + public function set_can_edit($can_edit) |
|
| 127 | + { |
|
| 128 | + $this->set('STS_can_edit', $can_edit); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Gets open |
|
| 134 | + * |
|
| 135 | + * @return boolean |
|
| 136 | + */ |
|
| 137 | + public function open() |
|
| 138 | + { |
|
| 139 | + return $this->get('STS_open'); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Sets open |
|
| 145 | + * |
|
| 146 | + * @param boolean $open |
|
| 147 | + * @return boolean |
|
| 148 | + */ |
|
| 149 | + public function set_open($open) |
|
| 150 | + { |
|
| 151 | + $this->set('STS_open', $open); |
|
| 152 | + } |
|
| 153 | 153 | } |
@@ -44,7 +44,7 @@ |
||
| 44 | 44 | { |
| 45 | 45 | $id = $this->get('STS_ID'); |
| 46 | 46 | $code = EEM_Status::instance()->localized_status(array($id => $this->get('STS_code')), $plural, $schema); |
| 47 | - return $code[ $id ]; |
|
| 47 | + return $code[$id]; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | |
@@ -12,87 +12,87 @@ |
||
| 12 | 12 | class EE_Term extends EE_Base_Class |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - public $post_type; |
|
| 15 | + public $post_type; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Sets some dynamic defaults |
|
| 19 | - * |
|
| 20 | - * @param array $fieldValues |
|
| 21 | - * @param bool $bydb |
|
| 22 | - * @param string $timezone |
|
| 23 | - */ |
|
| 24 | - protected function __construct($fieldValues = array(), $bydb = false, $timezone = '') |
|
| 25 | - { |
|
| 26 | - if (! isset($fieldValues['slug'])) { |
|
| 27 | - $fieldValues['slug'] = $fieldValues['name']; |
|
| 28 | - } |
|
| 29 | - parent::__construct($fieldValues, $bydb, $timezone); |
|
| 30 | - } |
|
| 17 | + /** |
|
| 18 | + * Sets some dynamic defaults |
|
| 19 | + * |
|
| 20 | + * @param array $fieldValues |
|
| 21 | + * @param bool $bydb |
|
| 22 | + * @param string $timezone |
|
| 23 | + */ |
|
| 24 | + protected function __construct($fieldValues = array(), $bydb = false, $timezone = '') |
|
| 25 | + { |
|
| 26 | + if (! isset($fieldValues['slug'])) { |
|
| 27 | + $fieldValues['slug'] = $fieldValues['name']; |
|
| 28 | + } |
|
| 29 | + parent::__construct($fieldValues, $bydb, $timezone); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @param array $props_n_values |
|
| 35 | - * @return EE_Term|mixed |
|
| 36 | - */ |
|
| 37 | - public static function new_instance($props_n_values = array()) |
|
| 38 | - { |
|
| 39 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 40 | - return $has_object ? $has_object : new self($props_n_values); |
|
| 41 | - } |
|
| 33 | + /** |
|
| 34 | + * @param array $props_n_values |
|
| 35 | + * @return EE_Term|mixed |
|
| 36 | + */ |
|
| 37 | + public static function new_instance($props_n_values = array()) |
|
| 38 | + { |
|
| 39 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 40 | + return $has_object ? $has_object : new self($props_n_values); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @param array $props_n_values |
|
| 46 | - * @return EE_Term |
|
| 47 | - */ |
|
| 48 | - public static function new_instance_from_db($props_n_values = array()) |
|
| 49 | - { |
|
| 50 | - return new self($props_n_values, true); |
|
| 51 | - } |
|
| 44 | + /** |
|
| 45 | + * @param array $props_n_values |
|
| 46 | + * @return EE_Term |
|
| 47 | + */ |
|
| 48 | + public static function new_instance_from_db($props_n_values = array()) |
|
| 49 | + { |
|
| 50 | + return new self($props_n_values, true); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Gets name |
|
| 56 | - * |
|
| 57 | - * @return string |
|
| 58 | - */ |
|
| 59 | - public function name() |
|
| 60 | - { |
|
| 61 | - return $this->get('name'); |
|
| 62 | - } |
|
| 54 | + /** |
|
| 55 | + * Gets name |
|
| 56 | + * |
|
| 57 | + * @return string |
|
| 58 | + */ |
|
| 59 | + public function name() |
|
| 60 | + { |
|
| 61 | + return $this->get('name'); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Sets name |
|
| 67 | - * |
|
| 68 | - * @param string $name |
|
| 69 | - * @return boolean |
|
| 70 | - */ |
|
| 71 | - public function set_name($name) |
|
| 72 | - { |
|
| 73 | - $this->set('name', $name); |
|
| 74 | - } |
|
| 65 | + /** |
|
| 66 | + * Sets name |
|
| 67 | + * |
|
| 68 | + * @param string $name |
|
| 69 | + * @return boolean |
|
| 70 | + */ |
|
| 71 | + public function set_name($name) |
|
| 72 | + { |
|
| 73 | + $this->set('name', $name); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Gets slug |
|
| 79 | - * |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public function slug() |
|
| 83 | - { |
|
| 84 | - return $this->get('slug'); |
|
| 85 | - } |
|
| 77 | + /** |
|
| 78 | + * Gets slug |
|
| 79 | + * |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public function slug() |
|
| 83 | + { |
|
| 84 | + return $this->get('slug'); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Sets slug |
|
| 90 | - * |
|
| 91 | - * @param string $slug |
|
| 92 | - * @return boolean |
|
| 93 | - */ |
|
| 94 | - public function set_slug($slug) |
|
| 95 | - { |
|
| 96 | - $this->set('slug', $slug); |
|
| 97 | - } |
|
| 88 | + /** |
|
| 89 | + * Sets slug |
|
| 90 | + * |
|
| 91 | + * @param string $slug |
|
| 92 | + * @return boolean |
|
| 93 | + */ |
|
| 94 | + public function set_slug($slug) |
|
| 95 | + { |
|
| 96 | + $this->set('slug', $slug); |
|
| 97 | + } |
|
| 98 | 98 | } |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | protected function __construct($fieldValues = array(), $bydb = false, $timezone = '') |
| 25 | 25 | { |
| 26 | - if (! isset($fieldValues['slug'])) { |
|
| 26 | + if ( ! isset($fieldValues['slug'])) { |
|
| 27 | 27 | $fieldValues['slug'] = $fieldValues['name']; |
| 28 | 28 | } |
| 29 | 29 | parent::__construct($fieldValues, $bydb, $timezone); |