Completed
Branch FET-11170-model-use-money-enti... (00bce3)
by
unknown
58:42 queued 45:24
created
core/domain/values/currency/Money.php 2 patches
Indentation   +297 added lines, -297 removed lines patch added patch discarded remove patch
@@ -21,301 +21,301 @@
 block discarded – undo
21 21
 class Money
22 22
 {
23 23
 
24
-    /**
25
-     * number of decimal places to be added to currencies for internal computations,
26
-     * but removed before any output or formatting is applied.
27
-     * This allows us to avoid rounding errors during calculations.
28
-     */
29
-    const EXTRA_PRECISION = 3;
30
-
31
-    /**
32
-     * @var int $amount
33
-     */
34
-    private $amount;
35
-
36
-    /**
37
-     * @var Currency $currency
38
-     */
39
-    private $currency;
40
-
41
-    /**
42
-     * @var Calculator $calculator
43
-     */
44
-    protected $calculator;
45
-
46
-
47
-
48
-    /**
49
-     * Money constructor.
50
-     *
51
-     * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
52
-     *                                 example: $12.5 USD would equate to a value amount of 12.50
53
-     * @param Currency         $currency
54
-     * @param Calculator       $calculator
55
-     * @throws InvalidDataTypeException
56
-     */
57
-    public function __construct($amount, Currency $currency, Calculator $calculator)
58
-    {
59
-        $this->currency   = $currency;
60
-        $this->amount     = $this->parseAmount($amount);
61
-        $this->calculator = $calculator;
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * @return Calculator
68
-     */
69
-    protected function calculator()
70
-    {
71
-        return $this->calculator;
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     * Convert's a standard unit amount into the subunits of the currency
78
-     *
79
-     * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
80
-     *                                 example: $12.5 USD would equate to a value amount of 12.50
81
-     * @return integer                 in the currency's subunit
82
-     * @throws InvalidDataTypeException
83
-     */
84
-    private function parseAmount($amount)
85
-    {
86
-        if (! in_array(gettype($amount), array('integer', 'double', 'string'), true)) {
87
-            throw new InvalidDataTypeException(
88
-                '$amount',
89
-                $amount,
90
-                'integer (or float or string)'
91
-            );
92
-        }
93
-        if ($this->currency->decimalMark() !== '.') {
94
-            // remove thousands separator and replace decimal place with standard decimal.
95
-            $amount = str_replace(
96
-                array(
97
-                    $this->currency->thousands(),
98
-                    $this->currency->decimalMark(),
99
-                ),
100
-                array(
101
-                    '',
102
-                    '.',
103
-                ),
104
-                $amount
105
-            );
106
-        }
107
-        // remove any non numeric values but leave the decimal
108
-        $amount = (float) preg_replace('/([^0-9\\.-])/', '', $amount);
109
-        // maybe convert the incoming  decimal amount to the currencies subunits
110
-        // ex: 12.5 for a currency with 100 subunits would become 1250
111
-        if ($this->currency()->subunits()) {
112
-            $amount *= $this->currency()->subunits();
113
-        }
114
-        // then shift the decimal position by the number of decimal places used internally
115
-        // so if our extra internal precision was 3, it would become 1250000
116
-        $amount *= pow(10, $this->precision());
117
-        // then round up the remaining value if there is still a fractional amount left
118
-        $amount = round($amount);
119
-        return (int)$amount;
120
-    }
121
-
122
-
123
-
124
-    /**
125
-     * adds or subtracts additional decimal places based on the value of the Money::EXTRA_PRECISION constant
126
-     *
127
-     * @param bool $adding_precision if true, will move the decimal to the right (increase amount)
128
-     *                               if false, will move the decimal to the left (decrease amount)
129
-     * @return integer
130
-     */
131
-    private function precision($adding_precision = true)
132
-    {
133
-        $sign = $adding_precision ? 1 : -1;
134
-        return Money::EXTRA_PRECISION * $sign;
135
-    }
136
-
137
-    /**
138
-     * Returns the money amount as an unformatted float
139
-     * @return float
140
-     */
141
-    public function floatAmount()
142
-    {
143
-        // shift the decimal position BACK by the number of decimal places used internally
144
-        // ex: if our extra internal precision was 3, then 1250000 would become 1250
145
-        $amount = $this->amount * pow(10, $this->precision(false));
146
-        // then maybe adjust for the currencies subunits
147
-        // ex: 1250 for a currency with 100 subunits would become 12.50
148
-        if ($this->currency()->subunits()) {
149
-            $amount /= $this->currency()->subunits();
150
-        }
151
-        // then shave off our extra internal precision using the number of decimal places for the currency
152
-        return $amount;
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     * Returns the money amount as an unformatted string
159
-     * IF YOU REQUIRE A FORMATTED STRING, THEN USE Money::format()
160
-     * In the currency's standard units
161
-     *
162
-     * @return string
163
-     */
164
-    public function amount()
165
-    {
166
-        return (string) round($this->floatAmount(), $this->currency()->decimalPlaces());
167
-    }
168
-
169
-
170
-
171
-    /**
172
-     * Returns the money SUBUNITS amount as an INTEGER
173
-     *
174
-     * @return integer
175
-     */
176
-    public function amountInSubunits()
177
-    {
178
-        // shift the decimal position BACK by the number of decimal places used internally
179
-        // for extra internal precision, but NOT for the number of decimals used by the currency
180
-        // ex: if our extra internal precision was 3, then 1250000 would become 1250
181
-        // and even if the currency used 100 subunits, we would return 1250 and NOT 12.50
182
-        $amount = (string) $this->amount * pow(10, $this->precision(false));
183
-        // then shave off anything after the decimal
184
-        $amount = round($amount);
185
-        return (int) $amount;
186
-    }
187
-
188
-
189
-
190
-    /**
191
-     * Returns the Currency object for this money
192
-     *
193
-     * @return Currency
194
-     */
195
-    public function currency()
196
-    {
197
-        return $this->currency;
198
-    }
199
-
200
-
201
-
202
-    /**
203
-     * adds the supplied Money amount to this Money amount
204
-     * and returns a new Money object
205
-     *
206
-     * @param Money $other
207
-     * @return Money
208
-     * @throws InvalidArgumentException
209
-     */
210
-    public function add(Money $other)
211
-    {
212
-        $this->verifySameCurrency($other->currency());
213
-        return new Money(
214
-            $this->calculator()->add(
215
-                $this->amount(),
216
-                $other->amount()
217
-            ),
218
-            $this->currency(),
219
-            $this->calculator()
220
-        );
221
-    }
222
-
223
-
224
-
225
-    /**
226
-     * subtracts the supplied Money amount from this Money amount
227
-     * and returns a new Money object
228
-     *
229
-     * @param Money $other
230
-     * @return Money
231
-     * @throws InvalidArgumentException
232
-     */
233
-    public function subtract(Money $other)
234
-    {
235
-        $this->verifySameCurrency($other->currency());
236
-        return new Money(
237
-            $this->calculator()->subtract(
238
-                $this->amount(),
239
-                $other->amount()
240
-            ),
241
-            $this->currency(),
242
-            $this->calculator()
243
-        );
244
-    }
245
-
246
-
247
-    /**
248
-     * multiplies this Money amount by the supplied $multiplier
249
-     * and returns a new Money object
250
-     *
251
-     * @param float|int|string $multiplier
252
-     * @param int              $rounding_mode
253
-     * @return Money
254
-     * @throws InvalidDataTypeException
255
-     */
256
-    public function multiply($multiplier, $rounding_mode = Calculator::ROUND_HALF_UP)
257
-    {
258
-        return new Money(
259
-            $this->calculator()->multiply(
260
-                $this->amount(),
261
-                $multiplier,
262
-                $this->precision(),
263
-                $rounding_mode
264
-            ),
265
-            $this->currency(),
266
-            $this->calculator()
267
-        );
268
-    }
269
-
270
-
271
-    /**
272
-     * divides this Money amount by the supplied $divisor
273
-     * and returns a new Money object
274
-     *
275
-     * @param float|int|string $divisor
276
-     * @param int              $rounding_mode
277
-     * @return Money
278
-     * @throws InvalidDataTypeException
279
-     */
280
-    public function divide($divisor, $rounding_mode = Calculator::ROUND_HALF_UP)
281
-    {
282
-        return new Money(
283
-            $this->calculator()->divide(
284
-                $this->amount(),
285
-                $divisor,
286
-                $this->precision(),
287
-                $rounding_mode
288
-            ),
289
-            $this->currency(),
290
-            $this->calculator()
291
-        );
292
-    }
293
-
294
-
295
-
296
-    /**
297
-     * @param Currency $other_currency
298
-     * @throws InvalidArgumentException
299
-     */
300
-    public function verifySameCurrency(Currency $other_currency)
301
-    {
302
-        if ($this->currency()->equals($other_currency) !== true) {
303
-            throw new InvalidArgumentException(
304
-                esc_html__(
305
-                    'Currencies must be the same in order to add or subtract their values.',
306
-                    'event_espresso'
307
-                )
308
-            );
309
-        }
310
-    }
311
-
312
-
313
-
314
-    /**
315
-     * @return string
316
-     */
317
-    public function __toString()
318
-    {
319
-        return $this->amount();
320
-    }
24
+	/**
25
+	 * number of decimal places to be added to currencies for internal computations,
26
+	 * but removed before any output or formatting is applied.
27
+	 * This allows us to avoid rounding errors during calculations.
28
+	 */
29
+	const EXTRA_PRECISION = 3;
30
+
31
+	/**
32
+	 * @var int $amount
33
+	 */
34
+	private $amount;
35
+
36
+	/**
37
+	 * @var Currency $currency
38
+	 */
39
+	private $currency;
40
+
41
+	/**
42
+	 * @var Calculator $calculator
43
+	 */
44
+	protected $calculator;
45
+
46
+
47
+
48
+	/**
49
+	 * Money constructor.
50
+	 *
51
+	 * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
52
+	 *                                 example: $12.5 USD would equate to a value amount of 12.50
53
+	 * @param Currency         $currency
54
+	 * @param Calculator       $calculator
55
+	 * @throws InvalidDataTypeException
56
+	 */
57
+	public function __construct($amount, Currency $currency, Calculator $calculator)
58
+	{
59
+		$this->currency   = $currency;
60
+		$this->amount     = $this->parseAmount($amount);
61
+		$this->calculator = $calculator;
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * @return Calculator
68
+	 */
69
+	protected function calculator()
70
+	{
71
+		return $this->calculator;
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 * Convert's a standard unit amount into the subunits of the currency
78
+	 *
79
+	 * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
80
+	 *                                 example: $12.5 USD would equate to a value amount of 12.50
81
+	 * @return integer                 in the currency's subunit
82
+	 * @throws InvalidDataTypeException
83
+	 */
84
+	private function parseAmount($amount)
85
+	{
86
+		if (! in_array(gettype($amount), array('integer', 'double', 'string'), true)) {
87
+			throw new InvalidDataTypeException(
88
+				'$amount',
89
+				$amount,
90
+				'integer (or float or string)'
91
+			);
92
+		}
93
+		if ($this->currency->decimalMark() !== '.') {
94
+			// remove thousands separator and replace decimal place with standard decimal.
95
+			$amount = str_replace(
96
+				array(
97
+					$this->currency->thousands(),
98
+					$this->currency->decimalMark(),
99
+				),
100
+				array(
101
+					'',
102
+					'.',
103
+				),
104
+				$amount
105
+			);
106
+		}
107
+		// remove any non numeric values but leave the decimal
108
+		$amount = (float) preg_replace('/([^0-9\\.-])/', '', $amount);
109
+		// maybe convert the incoming  decimal amount to the currencies subunits
110
+		// ex: 12.5 for a currency with 100 subunits would become 1250
111
+		if ($this->currency()->subunits()) {
112
+			$amount *= $this->currency()->subunits();
113
+		}
114
+		// then shift the decimal position by the number of decimal places used internally
115
+		// so if our extra internal precision was 3, it would become 1250000
116
+		$amount *= pow(10, $this->precision());
117
+		// then round up the remaining value if there is still a fractional amount left
118
+		$amount = round($amount);
119
+		return (int)$amount;
120
+	}
121
+
122
+
123
+
124
+	/**
125
+	 * adds or subtracts additional decimal places based on the value of the Money::EXTRA_PRECISION constant
126
+	 *
127
+	 * @param bool $adding_precision if true, will move the decimal to the right (increase amount)
128
+	 *                               if false, will move the decimal to the left (decrease amount)
129
+	 * @return integer
130
+	 */
131
+	private function precision($adding_precision = true)
132
+	{
133
+		$sign = $adding_precision ? 1 : -1;
134
+		return Money::EXTRA_PRECISION * $sign;
135
+	}
136
+
137
+	/**
138
+	 * Returns the money amount as an unformatted float
139
+	 * @return float
140
+	 */
141
+	public function floatAmount()
142
+	{
143
+		// shift the decimal position BACK by the number of decimal places used internally
144
+		// ex: if our extra internal precision was 3, then 1250000 would become 1250
145
+		$amount = $this->amount * pow(10, $this->precision(false));
146
+		// then maybe adjust for the currencies subunits
147
+		// ex: 1250 for a currency with 100 subunits would become 12.50
148
+		if ($this->currency()->subunits()) {
149
+			$amount /= $this->currency()->subunits();
150
+		}
151
+		// then shave off our extra internal precision using the number of decimal places for the currency
152
+		return $amount;
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 * Returns the money amount as an unformatted string
159
+	 * IF YOU REQUIRE A FORMATTED STRING, THEN USE Money::format()
160
+	 * In the currency's standard units
161
+	 *
162
+	 * @return string
163
+	 */
164
+	public function amount()
165
+	{
166
+		return (string) round($this->floatAmount(), $this->currency()->decimalPlaces());
167
+	}
168
+
169
+
170
+
171
+	/**
172
+	 * Returns the money SUBUNITS amount as an INTEGER
173
+	 *
174
+	 * @return integer
175
+	 */
176
+	public function amountInSubunits()
177
+	{
178
+		// shift the decimal position BACK by the number of decimal places used internally
179
+		// for extra internal precision, but NOT for the number of decimals used by the currency
180
+		// ex: if our extra internal precision was 3, then 1250000 would become 1250
181
+		// and even if the currency used 100 subunits, we would return 1250 and NOT 12.50
182
+		$amount = (string) $this->amount * pow(10, $this->precision(false));
183
+		// then shave off anything after the decimal
184
+		$amount = round($amount);
185
+		return (int) $amount;
186
+	}
187
+
188
+
189
+
190
+	/**
191
+	 * Returns the Currency object for this money
192
+	 *
193
+	 * @return Currency
194
+	 */
195
+	public function currency()
196
+	{
197
+		return $this->currency;
198
+	}
199
+
200
+
201
+
202
+	/**
203
+	 * adds the supplied Money amount to this Money amount
204
+	 * and returns a new Money object
205
+	 *
206
+	 * @param Money $other
207
+	 * @return Money
208
+	 * @throws InvalidArgumentException
209
+	 */
210
+	public function add(Money $other)
211
+	{
212
+		$this->verifySameCurrency($other->currency());
213
+		return new Money(
214
+			$this->calculator()->add(
215
+				$this->amount(),
216
+				$other->amount()
217
+			),
218
+			$this->currency(),
219
+			$this->calculator()
220
+		);
221
+	}
222
+
223
+
224
+
225
+	/**
226
+	 * subtracts the supplied Money amount from this Money amount
227
+	 * and returns a new Money object
228
+	 *
229
+	 * @param Money $other
230
+	 * @return Money
231
+	 * @throws InvalidArgumentException
232
+	 */
233
+	public function subtract(Money $other)
234
+	{
235
+		$this->verifySameCurrency($other->currency());
236
+		return new Money(
237
+			$this->calculator()->subtract(
238
+				$this->amount(),
239
+				$other->amount()
240
+			),
241
+			$this->currency(),
242
+			$this->calculator()
243
+		);
244
+	}
245
+
246
+
247
+	/**
248
+	 * multiplies this Money amount by the supplied $multiplier
249
+	 * and returns a new Money object
250
+	 *
251
+	 * @param float|int|string $multiplier
252
+	 * @param int              $rounding_mode
253
+	 * @return Money
254
+	 * @throws InvalidDataTypeException
255
+	 */
256
+	public function multiply($multiplier, $rounding_mode = Calculator::ROUND_HALF_UP)
257
+	{
258
+		return new Money(
259
+			$this->calculator()->multiply(
260
+				$this->amount(),
261
+				$multiplier,
262
+				$this->precision(),
263
+				$rounding_mode
264
+			),
265
+			$this->currency(),
266
+			$this->calculator()
267
+		);
268
+	}
269
+
270
+
271
+	/**
272
+	 * divides this Money amount by the supplied $divisor
273
+	 * and returns a new Money object
274
+	 *
275
+	 * @param float|int|string $divisor
276
+	 * @param int              $rounding_mode
277
+	 * @return Money
278
+	 * @throws InvalidDataTypeException
279
+	 */
280
+	public function divide($divisor, $rounding_mode = Calculator::ROUND_HALF_UP)
281
+	{
282
+		return new Money(
283
+			$this->calculator()->divide(
284
+				$this->amount(),
285
+				$divisor,
286
+				$this->precision(),
287
+				$rounding_mode
288
+			),
289
+			$this->currency(),
290
+			$this->calculator()
291
+		);
292
+	}
293
+
294
+
295
+
296
+	/**
297
+	 * @param Currency $other_currency
298
+	 * @throws InvalidArgumentException
299
+	 */
300
+	public function verifySameCurrency(Currency $other_currency)
301
+	{
302
+		if ($this->currency()->equals($other_currency) !== true) {
303
+			throw new InvalidArgumentException(
304
+				esc_html__(
305
+					'Currencies must be the same in order to add or subtract their values.',
306
+					'event_espresso'
307
+				)
308
+			);
309
+		}
310
+	}
311
+
312
+
313
+
314
+	/**
315
+	 * @return string
316
+	 */
317
+	public function __toString()
318
+	{
319
+		return $this->amount();
320
+	}
321 321
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
      */
84 84
     private function parseAmount($amount)
85 85
     {
86
-        if (! in_array(gettype($amount), array('integer', 'double', 'string'), true)) {
86
+        if ( ! in_array(gettype($amount), array('integer', 'double', 'string'), true)) {
87 87
             throw new InvalidDataTypeException(
88 88
                 '$amount',
89 89
                 $amount,
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
         $amount *= pow(10, $this->precision());
117 117
         // then round up the remaining value if there is still a fractional amount left
118 118
         $amount = round($amount);
119
-        return (int)$amount;
119
+        return (int) $amount;
120 120
     }
121 121
 
122 122
 
Please login to merge, or discard this patch.
core/domain/values/currency/Currency.php 1 patch
Indentation   +216 added lines, -216 removed lines patch added patch discarded remove patch
@@ -19,227 +19,227 @@
 block discarded – undo
19 19
 class Currency
20 20
 {
21 21
 
22
-    /**
23
-     * eg 'US'
24
-     *
25
-     * @var string $code
26
-     */
27
-    private $code;
28
-
29
-    /**
30
-     * @var Label $label
31
-     */
32
-    private $label;
33
-
34
-    /**
35
-     * currency sign
36
-     *
37
-     * @var string $sign
38
-     * eg '$'
39
-     */
40
-    private $sign;
41
-
42
-    /**
43
-     * Whether the currency sign should come before the number or not
44
-     *
45
-     * @var boolean $sign_b4
46
-     */
47
-    private $sign_b4;
48
-
49
-    /**
50
-     * How many digits should come after the decimal place
51
-     * Although not theoretically true, it can effectively
52
-     * be considered that all currencies are decimal based.
53
-     * Therefore the number of decimal places can be used
54
-     * to calculate number of subunits like so:
55
-     *  subunits = pow( 10, decimal places  )
56
-     *
57
-     * @var int $decimal_places
58
-     */
59
-    private $decimal_places;
60
-
61
-    /**
62
-     * Symbol to use for decimal mark
63
-     *
64
-     * @var string $decimal_mark
65
-     * eg '.'
66
-     */
67
-    private $decimal_mark;
68
-
69
-    /**
70
-     * Symbol to use for thousands
71
-     *
72
-     * @var string $thousands
73
-     * eg ','
74
-     */
75
-    private $thousands;
76
-
77
-    /**
78
-     * The number of fractional divisions of a currency's main unit
79
-     * Can be used to determine the number of decimal places used.
80
-     * Because
81
-     *  subunits = pow( 10, decimal places )
82
-     * then
83
-     *  decimal places = log( subunits )
84
-     * except that a result of 1 means there are zero decimal places
85
-     *
86
-     * @var int
87
-     */
88
-    private $subunits;
89
-
90
-
91
-
92
-    /**
93
-     * Currency constructor.
94
-     *
95
-     * @param string $code
96
-     * @param Label  $label
97
-     * @param string $sign
98
-     * @param bool   $sign_b4
99
-     * @param int    $decimal_places the number of decimal places to use when DISPLAYING the currency
100
-     * @param string $decimal_mark
101
-     * @param string $thousands
102
-     * @param int    $subunits number of fractional divisions of a currency's main unit
103
-     */
104
-    public function __construct(
105
-        $code,
106
-        Label $label,
107
-        $sign,
108
-        $sign_b4,
109
-        $decimal_places,
110
-        $decimal_mark,
111
-        $thousands,
112
-        $subunits
113
-    ) {
114
-        $this->code           = $code;
115
-        $this->label          = $label;
116
-        $this->sign           = $sign;
117
-        $this->sign_b4        = $sign_b4;
118
-        $this->decimal_places = $decimal_places;
119
-        $this->decimal_mark   = $decimal_mark;
120
-        $this->thousands      = $thousands;
121
-        $this->subunits       = $subunits;
122
-    }
123
-
124
-
125
-
126
-    /**
127
-     * returns true if this currency is the same as the supplied currency
128
-     *
129
-     * @param Currency $other
130
-     * @return bool
131
-     */
132
-    public function equals(Currency $other)
133
-    {
134
-        return $this->code() === $other->code();
135
-    }
136
-
137
-
138
-
139
-    /**
140
-     * @return string
141
-     */
142
-    public function code()
143
-    {
144
-        return $this->code;
145
-    }
146
-
147
-
148
-
149
-    /**
150
-     * @return string
151
-     */
152
-    public function name()
153
-    {
154
-        return $this->label->singular();
155
-    }
156
-
157
-
158
-
159
-    /**
160
-     * @return string
161
-     */
162
-    public function plural()
163
-    {
164
-        return $this->label->plural();
165
-    }
166
-
167
-
168
-
169
-    /**
170
-     * @return string
171
-     */
172
-    public function sign()
173
-    {
174
-        return $this->sign;
175
-    }
176
-
177
-
178
-
179
-    /**
180
-     * @return bool
181
-     */
182
-    public function signB4()
183
-    {
184
-        return $this->sign_b4;
185
-    }
186
-
187
-
188
-
189
-    /**
190
-     * @return int
191
-     */
192
-    public function decimalPlaces()
193
-    {
194
-        return $this->decimal_places;
195
-    }
196
-
197
-
198
-
199
-    /**
200
-     * @return string
201
-     */
202
-    public function decimalMark()
203
-    {
204
-        return $this->decimal_mark;
205
-    }
206
-
207
-
208
-
209
-    /**
210
-     * @return string
211
-     */
212
-    public function thousands()
213
-    {
214
-        return $this->thousands;
215
-    }
22
+	/**
23
+	 * eg 'US'
24
+	 *
25
+	 * @var string $code
26
+	 */
27
+	private $code;
28
+
29
+	/**
30
+	 * @var Label $label
31
+	 */
32
+	private $label;
33
+
34
+	/**
35
+	 * currency sign
36
+	 *
37
+	 * @var string $sign
38
+	 * eg '$'
39
+	 */
40
+	private $sign;
41
+
42
+	/**
43
+	 * Whether the currency sign should come before the number or not
44
+	 *
45
+	 * @var boolean $sign_b4
46
+	 */
47
+	private $sign_b4;
48
+
49
+	/**
50
+	 * How many digits should come after the decimal place
51
+	 * Although not theoretically true, it can effectively
52
+	 * be considered that all currencies are decimal based.
53
+	 * Therefore the number of decimal places can be used
54
+	 * to calculate number of subunits like so:
55
+	 *  subunits = pow( 10, decimal places  )
56
+	 *
57
+	 * @var int $decimal_places
58
+	 */
59
+	private $decimal_places;
60
+
61
+	/**
62
+	 * Symbol to use for decimal mark
63
+	 *
64
+	 * @var string $decimal_mark
65
+	 * eg '.'
66
+	 */
67
+	private $decimal_mark;
68
+
69
+	/**
70
+	 * Symbol to use for thousands
71
+	 *
72
+	 * @var string $thousands
73
+	 * eg ','
74
+	 */
75
+	private $thousands;
76
+
77
+	/**
78
+	 * The number of fractional divisions of a currency's main unit
79
+	 * Can be used to determine the number of decimal places used.
80
+	 * Because
81
+	 *  subunits = pow( 10, decimal places )
82
+	 * then
83
+	 *  decimal places = log( subunits )
84
+	 * except that a result of 1 means there are zero decimal places
85
+	 *
86
+	 * @var int
87
+	 */
88
+	private $subunits;
89
+
90
+
91
+
92
+	/**
93
+	 * Currency constructor.
94
+	 *
95
+	 * @param string $code
96
+	 * @param Label  $label
97
+	 * @param string $sign
98
+	 * @param bool   $sign_b4
99
+	 * @param int    $decimal_places the number of decimal places to use when DISPLAYING the currency
100
+	 * @param string $decimal_mark
101
+	 * @param string $thousands
102
+	 * @param int    $subunits number of fractional divisions of a currency's main unit
103
+	 */
104
+	public function __construct(
105
+		$code,
106
+		Label $label,
107
+		$sign,
108
+		$sign_b4,
109
+		$decimal_places,
110
+		$decimal_mark,
111
+		$thousands,
112
+		$subunits
113
+	) {
114
+		$this->code           = $code;
115
+		$this->label          = $label;
116
+		$this->sign           = $sign;
117
+		$this->sign_b4        = $sign_b4;
118
+		$this->decimal_places = $decimal_places;
119
+		$this->decimal_mark   = $decimal_mark;
120
+		$this->thousands      = $thousands;
121
+		$this->subunits       = $subunits;
122
+	}
123
+
124
+
125
+
126
+	/**
127
+	 * returns true if this currency is the same as the supplied currency
128
+	 *
129
+	 * @param Currency $other
130
+	 * @return bool
131
+	 */
132
+	public function equals(Currency $other)
133
+	{
134
+		return $this->code() === $other->code();
135
+	}
136
+
137
+
138
+
139
+	/**
140
+	 * @return string
141
+	 */
142
+	public function code()
143
+	{
144
+		return $this->code;
145
+	}
146
+
147
+
148
+
149
+	/**
150
+	 * @return string
151
+	 */
152
+	public function name()
153
+	{
154
+		return $this->label->singular();
155
+	}
156
+
157
+
158
+
159
+	/**
160
+	 * @return string
161
+	 */
162
+	public function plural()
163
+	{
164
+		return $this->label->plural();
165
+	}
166
+
167
+
168
+
169
+	/**
170
+	 * @return string
171
+	 */
172
+	public function sign()
173
+	{
174
+		return $this->sign;
175
+	}
176
+
177
+
178
+
179
+	/**
180
+	 * @return bool
181
+	 */
182
+	public function signB4()
183
+	{
184
+		return $this->sign_b4;
185
+	}
186
+
187
+
188
+
189
+	/**
190
+	 * @return int
191
+	 */
192
+	public function decimalPlaces()
193
+	{
194
+		return $this->decimal_places;
195
+	}
196
+
197
+
198
+
199
+	/**
200
+	 * @return string
201
+	 */
202
+	public function decimalMark()
203
+	{
204
+		return $this->decimal_mark;
205
+	}
206
+
207
+
208
+
209
+	/**
210
+	 * @return string
211
+	 */
212
+	public function thousands()
213
+	{
214
+		return $this->thousands;
215
+	}
216 216
 
217 217
 
218
-    /**
219
-     * The number of divisions of the currency's main unit that comprises the smallest units
220
-     * ex: 1 US Dollar has 100 Pennies, so USD subunits = 100
221
-     * **WARNING**
222
-     * Some currencies, such as the Japanese Yen have no subunits,
223
-     * ie: the main unit is the smallest division
224
-     * so you need to always check that subunits is not zero
225
-     * before performing multiplication or division with it
226
-     *
227
-     * @return int
228
-     */
229
-    public function subunits()
230
-    {
231
-        return $this->subunits;
232
-    }
218
+	/**
219
+	 * The number of divisions of the currency's main unit that comprises the smallest units
220
+	 * ex: 1 US Dollar has 100 Pennies, so USD subunits = 100
221
+	 * **WARNING**
222
+	 * Some currencies, such as the Japanese Yen have no subunits,
223
+	 * ie: the main unit is the smallest division
224
+	 * so you need to always check that subunits is not zero
225
+	 * before performing multiplication or division with it
226
+	 *
227
+	 * @return int
228
+	 */
229
+	public function subunits()
230
+	{
231
+		return $this->subunits;
232
+	}
233 233
 
234 234
 
235 235
 
236
-    /**
237
-     * @return string
238
-     */
239
-    public function __toString()
240
-    {
241
-        return $this->code();
242
-    }
236
+	/**
237
+	 * @return string
238
+	 */
239
+	public function __toString()
240
+	{
241
+		return $this->code();
242
+	}
243 243
 
244 244
 
245 245
 
Please login to merge, or discard this patch.
core/services/currency/MoneyFactory.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -186,7 +186,7 @@
 block discarded – undo
186 186
             )
187 187
         );
188 188
         foreach ($calculators as $calculator) {
189
-            if (! class_exists($calculator)) {
189
+            if ( ! class_exists($calculator)) {
190 190
                 continue;
191 191
             }
192 192
             $calculator = new $calculator();
Please login to merge, or discard this patch.
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -24,163 +24,163 @@
 block discarded – undo
24 24
 class MoneyFactory
25 25
 {
26 26
 
27
-    /**
28
-     * @var CurrencyFactory $currency_factory
29
-     */
30
-    protected $currency_factory;
31
-
32
-    /**
33
-     * @var Calculator $calculator
34
-     */
35
-    protected $calculator;
36
-
37
-
38
-    /**
39
-     * CreateMoney constructor.
40
-     *
41
-     * @param CurrencyFactory  $currency_factory
42
-     * @param Calculator       $calculator
43
-     */
44
-    public function __construct(
45
-        CurrencyFactory $currency_factory,
46
-        Calculator $calculator = null
47
-    ) {
48
-        $this->calculator = $calculator;
49
-        $this->currency_factory = $currency_factory;
50
-    }
51
-
52
-
53
-    /**
54
-     * factory method that returns a Money object using amount specified in the currency's subunits
55
-     * example: for $12.50 USD use CreateMoney::fromSubUnits(1250, 'USD')
56
-     *
57
-     * @param int    $subunits_amount money amount IN THE SUBUNITS FOR THE CURRENCY ie: cents
58
-     *                                example: $12.50 USD would equate to a subunits amount of 1250
59
-     * @param string $currency_code
60
-     * @return Money
61
-     * @throws EE_Error
62
-     * @throws InvalidArgumentException
63
-     * @throws InvalidDataTypeException
64
-     */
65
-    public function createFromSubUnits($subunits_amount, $currency_code = '')
66
-    {
67
-        $currency = $this->currency_factory->createFromCode($currency_code);
68
-        return new Money(
69
-            // shift decimal BACK by number of places for currency
70
-            $subunits_amount * pow(10, $currency->decimalPlaces() * -1),
71
-            $currency,
72
-            $this->calculator()
73
-        );
74
-    }
75
-
76
-
77
-
78
-    /**
79
-     * factory method that returns a Money object using the currency corresponding to the site's country
80
-     * example: CreateMoney::forSite(12.5)
81
-     *
82
-     * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
83
-     *                                 example: $12.5 USD would equate to a standard amount of 12.50
84
-     * @return Money
85
-     * @throws EE_Error
86
-     * @throws InvalidArgumentException
87
-     * @throws InvalidDataTypeException
88
-     */
89
-    public function createForSite($amount)
90
-    {
91
-        return new Money(
92
-            $amount,
93
-            $this->currency_factory->createFromCountryCode(),
94
-            $this->calculator()
95
-        );
96
-    }
97
-
98
-
99
-
100
-    /**
101
-     * factory method that returns a Money object using the currency as specified by the supplied ISO country code
102
-     * example: CreateMoney::forCountry(12.5,'US')
103
-     *
104
-     * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
105
-     *                                 example: $12.5 USD would equate to a value amount of 12.50
106
-     * @param string           $CNT_ISO
107
-     * @return Money
108
-     * @throws EE_Error
109
-     * @throws InvalidArgumentException
110
-     * @throws InvalidDataTypeException
111
-     */
112
-    public function createForCountry($amount, $CNT_ISO)
113
-    {
114
-        return new Money(
115
-            $amount,
116
-            $this->currency_factory->createFromCountryCode($CNT_ISO),
117
-            $this->calculator()
118
-        );
119
-    }
120
-
121
-
122
-
123
-    /**
124
-     * factory method that returns a Money object using the currency as specified by the supplied currency code
125
-     * example: CreateMoney::forCurrency(12.5, 'USD')
126
-     *
127
-     * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
128
-     *                                 example: $12.5 USD would equate to a value amount of 12.50
129
-     * @param string           $currency_code
130
-     * @return Money
131
-     * @throws EE_Error
132
-     * @throws InvalidArgumentException
133
-     * @throws InvalidDataTypeException
134
-     */
135
-    public function createForCurrency($amount, $currency_code)
136
-    {
137
-        return new Money(
138
-            $amount,
139
-            $this->currency_factory->createFromCode($currency_code),
140
-            $this->calculator()
141
-        );
142
-    }
143
-
144
-
145
-
146
-
147
-    /**
148
-     * @return Calculator
149
-     */
150
-    public function calculator()
151
-    {
152
-        $this->initializeCalculators();
153
-        return $this->calculator;
154
-    }
155
-
156
-
157
-
158
-    /**
159
-     * loops through a filterable array of Calculator services
160
-     * and selects the first one that is supported by the current server
161
-     */
162
-    protected function initializeCalculators()
163
-    {
164
-        if ($this->calculator instanceof Calculator) {
165
-            return;
166
-        }
167
-        $calculators = apply_filters(
168
-            'FHEE__EventEspresso_core_services_currency_MoneyFactory__initializeCalculators__Calculators_array',
169
-            array(
170
-                'EventEspresso\core\services\currency\DefaultCalculator',
171
-            )
172
-        );
173
-        foreach ($calculators as $calculator) {
174
-            if (! class_exists($calculator)) {
175
-                continue;
176
-            }
177
-            $calculator = new $calculator();
178
-            if ($calculator instanceof Calculator && $calculator->isSupported()) {
179
-                $this->calculator = $calculator;
180
-                break;
181
-            }
182
-        }
183
-    }
27
+	/**
28
+	 * @var CurrencyFactory $currency_factory
29
+	 */
30
+	protected $currency_factory;
31
+
32
+	/**
33
+	 * @var Calculator $calculator
34
+	 */
35
+	protected $calculator;
36
+
37
+
38
+	/**
39
+	 * CreateMoney constructor.
40
+	 *
41
+	 * @param CurrencyFactory  $currency_factory
42
+	 * @param Calculator       $calculator
43
+	 */
44
+	public function __construct(
45
+		CurrencyFactory $currency_factory,
46
+		Calculator $calculator = null
47
+	) {
48
+		$this->calculator = $calculator;
49
+		$this->currency_factory = $currency_factory;
50
+	}
51
+
52
+
53
+	/**
54
+	 * factory method that returns a Money object using amount specified in the currency's subunits
55
+	 * example: for $12.50 USD use CreateMoney::fromSubUnits(1250, 'USD')
56
+	 *
57
+	 * @param int    $subunits_amount money amount IN THE SUBUNITS FOR THE CURRENCY ie: cents
58
+	 *                                example: $12.50 USD would equate to a subunits amount of 1250
59
+	 * @param string $currency_code
60
+	 * @return Money
61
+	 * @throws EE_Error
62
+	 * @throws InvalidArgumentException
63
+	 * @throws InvalidDataTypeException
64
+	 */
65
+	public function createFromSubUnits($subunits_amount, $currency_code = '')
66
+	{
67
+		$currency = $this->currency_factory->createFromCode($currency_code);
68
+		return new Money(
69
+			// shift decimal BACK by number of places for currency
70
+			$subunits_amount * pow(10, $currency->decimalPlaces() * -1),
71
+			$currency,
72
+			$this->calculator()
73
+		);
74
+	}
75
+
76
+
77
+
78
+	/**
79
+	 * factory method that returns a Money object using the currency corresponding to the site's country
80
+	 * example: CreateMoney::forSite(12.5)
81
+	 *
82
+	 * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
83
+	 *                                 example: $12.5 USD would equate to a standard amount of 12.50
84
+	 * @return Money
85
+	 * @throws EE_Error
86
+	 * @throws InvalidArgumentException
87
+	 * @throws InvalidDataTypeException
88
+	 */
89
+	public function createForSite($amount)
90
+	{
91
+		return new Money(
92
+			$amount,
93
+			$this->currency_factory->createFromCountryCode(),
94
+			$this->calculator()
95
+		);
96
+	}
97
+
98
+
99
+
100
+	/**
101
+	 * factory method that returns a Money object using the currency as specified by the supplied ISO country code
102
+	 * example: CreateMoney::forCountry(12.5,'US')
103
+	 *
104
+	 * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
105
+	 *                                 example: $12.5 USD would equate to a value amount of 12.50
106
+	 * @param string           $CNT_ISO
107
+	 * @return Money
108
+	 * @throws EE_Error
109
+	 * @throws InvalidArgumentException
110
+	 * @throws InvalidDataTypeException
111
+	 */
112
+	public function createForCountry($amount, $CNT_ISO)
113
+	{
114
+		return new Money(
115
+			$amount,
116
+			$this->currency_factory->createFromCountryCode($CNT_ISO),
117
+			$this->calculator()
118
+		);
119
+	}
120
+
121
+
122
+
123
+	/**
124
+	 * factory method that returns a Money object using the currency as specified by the supplied currency code
125
+	 * example: CreateMoney::forCurrency(12.5, 'USD')
126
+	 *
127
+	 * @param float|int|string $amount money amount IN THE STANDARD UNIT FOR THE CURRENCY ie: dollars, Euros, etc
128
+	 *                                 example: $12.5 USD would equate to a value amount of 12.50
129
+	 * @param string           $currency_code
130
+	 * @return Money
131
+	 * @throws EE_Error
132
+	 * @throws InvalidArgumentException
133
+	 * @throws InvalidDataTypeException
134
+	 */
135
+	public function createForCurrency($amount, $currency_code)
136
+	{
137
+		return new Money(
138
+			$amount,
139
+			$this->currency_factory->createFromCode($currency_code),
140
+			$this->calculator()
141
+		);
142
+	}
143
+
144
+
145
+
146
+
147
+	/**
148
+	 * @return Calculator
149
+	 */
150
+	public function calculator()
151
+	{
152
+		$this->initializeCalculators();
153
+		return $this->calculator;
154
+	}
155
+
156
+
157
+
158
+	/**
159
+	 * loops through a filterable array of Calculator services
160
+	 * and selects the first one that is supported by the current server
161
+	 */
162
+	protected function initializeCalculators()
163
+	{
164
+		if ($this->calculator instanceof Calculator) {
165
+			return;
166
+		}
167
+		$calculators = apply_filters(
168
+			'FHEE__EventEspresso_core_services_currency_MoneyFactory__initializeCalculators__Calculators_array',
169
+			array(
170
+				'EventEspresso\core\services\currency\DefaultCalculator',
171
+			)
172
+		);
173
+		foreach ($calculators as $calculator) {
174
+			if (! class_exists($calculator)) {
175
+				continue;
176
+			}
177
+			$calculator = new $calculator();
178
+			if ($calculator instanceof Calculator && $calculator->isSupported()) {
179
+				$this->calculator = $calculator;
180
+				break;
181
+			}
182
+		}
183
+	}
184 184
 
185 185
 
186 186
 }
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_PMT_Base.lib.php 2 patches
Indentation   +718 added lines, -718 removed lines patch added patch discarded remove patch
@@ -21,724 +21,724 @@
 block discarded – undo
21 21
 abstract class EE_PMT_Base
22 22
 {
23 23
 
24
-    const onsite = 'on-site';
25
-    const offsite = 'off-site';
26
-    const offline = 'off-line';
27
-
28
-    /**
29
-     * @var EE_Payment_Method
30
-     */
31
-    protected $_pm_instance = NULL;
32
-
33
-    /**
34
-     * @var boolean
35
-     */
36
-    protected $_requires_https = FALSE;
37
-
38
-    /**
39
-     * @var boolean
40
-     */
41
-    protected $_has_billing_form;
42
-
43
-    /**
44
-     * @var EE_Gateway
45
-     */
46
-    protected $_gateway = NULL;
47
-
48
-    /**
49
-     * @var EE_Payment_Method_Form
50
-     */
51
-    protected $_settings_form = NULL;
52
-
53
-    /**
54
-     * @var EE_Form_Section_Proper
55
-     */
56
-    protected $_billing_form = NULL;
57
-
58
-    /**
59
-     * @var boolean
60
-     */
61
-    protected $_cache_billing_form = TRUE;
62
-
63
-    /**
64
-     * String of the absolute path to the folder containing this file, with a trailing slash.
65
-     * eg '/public_html/wp-site/wp-content/plugins/event-espresso/payment_methods/Invoice/'
66
-     * @var string
67
-     */
68
-    protected $_file_folder = NULL;
69
-
70
-    /**
71
-     * String to the absolute URL to this file (useful for getting its web-accessible resources
72
-     * like images, js, or css)
73
-     * @var string
74
-     */
75
-    protected $_file_url = NULL;
76
-
77
-    /**
78
-     * Pretty name for the payment method
79
-     * @var string
80
-     */
81
-    protected $_pretty_name = NULL;
82
-
83
-    /**
84
-     *
85
-     * @var string
86
-     */
87
-    protected $_default_button_url = NULL;
88
-
89
-    /**
90
-     *
91
-     * @var string
92
-     */
93
-    protected $_default_description = NULL;
94
-
95
-
96
-    /**
97
-     *
98
-     * @param EE_Payment_Method $pm_instance
99
-     * @throws EE_Error
100
-     * @return EE_PMT_Base
101
-     */
102
-    function __construct($pm_instance = NULL)
103
-    {
104
-        if ($pm_instance instanceof EE_Payment_Method) {
105
-            $this->set_instance($pm_instance);
106
-        }
107
-        if ($this->_gateway) {
108
-            $this->_gateway->set_payment_model(EEM_Payment::instance());
109
-            $this->_gateway->set_payment_log(EEM_Change_Log::instance());
110
-            $this->_gateway->set_template_helper(new EEH_Template());
111
-            $this->_gateway->set_line_item_helper(new EEH_Line_Item());
112
-            $this->_gateway->set_money_helper(new EEH_Money());
113
-            $this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter());
114
-            $this->_gateway->set_unsupported_character_remover(new AsciiOnly());
115
-            do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway);
116
-        }
117
-        if (!isset($this->_has_billing_form)) {
118
-            // by default, On Site gateways have a billing form
119
-            if ($this->payment_occurs() == EE_PMT_Base::onsite) {
120
-                $this->set_has_billing_form(true);
121
-            } else {
122
-                $this->set_has_billing_form(false);
123
-            }
124
-        }
125
-
126
-        if (!$this->_pretty_name) {
127
-            throw new EE_Error(sprintf(__("You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", "event_espresso")));
128
-        }
129
-        //if the child didn't specify a default button, use the credit card one
130
-        if ($this->_default_button_url === NULL) {
131
-            $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png';
132
-        }
133
-    }
134
-
135
-
136
-    /**
137
-     * @param boolean $has_billing_form
138
-     */
139
-    public function set_has_billing_form($has_billing_form)
140
-    {
141
-        $this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN);
142
-    }
143
-
144
-
145
-    /**
146
-     * sets the file_folder property
147
-     */
148
-    protected function _set_file_folder()
149
-    {
150
-        $reflector = new ReflectionClass(get_class($this));
151
-        $fn = $reflector->getFileName();
152
-        $this->_file_folder = dirname($fn) . DS;
153
-    }
154
-
155
-
156
-    /**
157
-     * sets the file URL with a trailing slash for this PMT
158
-     */
159
-    protected function _set_file_url()
160
-    {
161
-        $plugins_dir_fixed = str_replace('\\', DS, WP_PLUGIN_DIR);
162
-        $file_folder_fixed = str_replace('\\', DS, $this->file_folder());
163
-        $file_path = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed);
164
-        $this->_file_url = $file_path;
165
-    }
166
-
167
-    /**
168
-     * Gets the default description on all payment methods of this type
169
-     * @return string
170
-     */
171
-    public function default_description()
172
-    {
173
-        return $this->_default_description;
174
-    }
175
-
176
-
177
-    /**
178
-     * Returns the folder containing the PMT child class, with a trailing slash
179
-     * @return string
180
-     */
181
-    public function file_folder()
182
-    {
183
-        if (!$this->_file_folder) {
184
-            $this->_set_file_folder();
185
-        }
186
-        return $this->_file_folder;
187
-    }
188
-
189
-
190
-    /**
191
-     * @return string
192
-     */
193
-    public function file_url()
194
-    {
195
-        if (!$this->_file_url) {
196
-            $this->_set_file_url();
197
-        }
198
-        return $this->_file_url;
199
-    }
200
-
201
-
202
-    /**
203
-     * Sets the payment method instance this payment method type is for.
204
-     * Its important teh payment method instance is set before
205
-     * @param EE_Payment_Method $payment_method_instance
206
-     */
207
-    function set_instance($payment_method_instance)
208
-    {
209
-        $this->_pm_instance = $payment_method_instance;
210
-        //if they have already requested the settings form, make sure its
211
-        //data matches this model object
212
-        if ($this->_settings_form) {
213
-            $this->settings_form()->populate_model_obj($payment_method_instance);
214
-        }
215
-        if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
216
-            $this->_gateway->set_settings($payment_method_instance->settings_array());
217
-        }
218
-    }
219
-
220
-
221
-    /**
222
-     * Gets teh form for displaying to admins where they setup the payment method
223
-     * @return EE_Payment_Method_Form
224
-     */
225
-    function settings_form()
226
-    {
227
-        if (!$this->_settings_form) {
228
-            $this->_settings_form = $this->generate_new_settings_form();
229
-            $this->_settings_form->set_payment_method_type($this);
230
-            //if we have already assigned a model object to this pmt, make
231
-            //sure its reflected in teh form we just generated
232
-            if ($this->_pm_instance) {
233
-                $this->_settings_form->populate_model_obj($this->_pm_instance);
234
-            }
235
-        }
236
-        return $this->_settings_form;
237
-    }
238
-
239
-
240
-    /**
241
-     * Gets the form for all the settings related to this payment method type
242
-     * @return EE_Payment_Method_Form
243
-     */
244
-    abstract function generate_new_settings_form();
245
-
246
-
247
-    /**
248
-     * Sets the form for settings. This may be useful if we have already received
249
-     * a form submission and have form data it in, and want to use it anytime we're showing
250
-     * this payment method type's settings form later in the request
251
-     * @param EE_Payment_Method_Form $form
252
-     */
253
-    public function set_settings_form($form)
254
-    {
255
-        $this->_settings_form = $form;
256
-    }
257
-
258
-
259
-    /**
260
-     * @return boolean
261
-     */
262
-    public function has_billing_form()
263
-    {
264
-        return $this->_has_billing_form;
265
-    }
266
-
267
-
268
-    /**
269
-     * Gets the form for displaying to attendees where they can enter their billing info
270
-     * which will be sent to teh gateway (can be null)
271
-     *
272
-     * @param \EE_Transaction $transaction
273
-     * @param array $extra_args
274
-     * @return \EE_Billing_Attendee_Info_Form|\EE_Billing_Info_Form|null
275
-     */
276
-    public function billing_form(EE_Transaction $transaction = NULL, $extra_args = array())
277
-    {
278
-        // has billing form already been regenerated ? or overwrite cache?
279
-        if (!$this->_billing_form instanceof EE_Billing_Info_Form || !$this->_cache_billing_form) {
280
-            $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args);
281
-        }
282
-        //if we know who the attendee is, and this is a billing form
283
-        //that uses attendee info, populate it
284
-        if (
285
-        apply_filters(
286
-            'FHEE__populate_billing_form_fields_from_attendee',
287
-            (
288
-                $this->_billing_form instanceof EE_Billing_Attendee_Info_Form
289
-                && $transaction instanceof EE_Transaction
290
-                && $transaction->primary_registration() instanceof EE_Registration
291
-                && $transaction->primary_registration()->attendee() instanceof EE_Attendee
292
-            ),
293
-            $this->_billing_form,
294
-            $transaction
295
-        )
296
-        ) {
297
-            $this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee());
298
-        }
299
-        return $this->_billing_form;
300
-    }
301
-
302
-
303
-    /**
304
-     * Creates the billing form for this payment method type
305
-     * @param \EE_Transaction $transaction
306
-     * @return \EE_Billing_Info_Form
307
-     */
308
-    abstract function generate_new_billing_form(EE_Transaction $transaction = NULL);
309
-
310
-
311
-    /**
312
-     * apply_billing_form_debug_settings
313
-     * applies debug data to the form
314
-     *
315
-     * @param \EE_Billing_Info_Form $billing_form
316
-     * @return \EE_Billing_Info_Form
317
-     */
318
-    public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form)
319
-    {
320
-        return $billing_form;
321
-    }
322
-
323
-
324
-    /**
325
-     * Sets the billing form for this payment method type. You may want to use this
326
-     * if you have form
327
-     * @param EE_Payment_Method $form
328
-     */
329
-    public function set_billing_form($form)
330
-    {
331
-        $this->_billing_form = $form;
332
-    }
333
-
334
-
335
-    /**
336
-     * Returns whether or not this payment method requires HTTPS to be used
337
-     * @return boolean
338
-     */
339
-    function requires_https()
340
-    {
341
-        return $this->_requires_https;
342
-    }
343
-
344
-
345
-    /**
346
-     *
347
-     * @param EE_Transaction $transaction
348
-     * @param float $amount
349
-     * @param EE_Billing_Info_Form $billing_info
350
-     * @param string $return_url
351
-     * @param string $fail_url
352
-     * @param string $method
353
-     * @param bool $by_admin
354
-     * @return EE_Payment
355
-     * @throws EE_Error
356
-     */
357
-    function process_payment(EE_Transaction $transaction, $amount = null, $billing_info = null, $return_url = null, $fail_url = '', $method = 'CART', $by_admin = false)
358
-    {
359
-        // @todo: add surcharge for the payment method, if any
360
-        if ($this->_gateway) {
361
-            //there is a gateway, so we're going to make a payment object
362
-            //but wait! do they already have a payment in progress that we thought was failed?
363
-            $duplicate_properties = array(
364
-                'STS_ID' => EEM_Payment::status_id_failed,
365
-                'TXN_ID' => $transaction->ID(),
366
-                'PMD_ID' => $this->_pm_instance->ID(),
367
-                'PAY_source' => $method,
368
-                'PAY_amount' => $amount !== null ? $amount : $transaction->remaining(),
369
-                'PAY_gateway_response' => null,
370
-            );
371
-            $payment = EEM_Payment::instance()->get_one(array($duplicate_properties));
372
-            //if we didn't already have a payment in progress for the same thing,
373
-            //then we actually want to make a new payment
374
-            if (!$payment instanceof EE_Payment) {
375
-                $payment = EE_Payment::new_instance(
376
-                    array_merge(
377
-                        $duplicate_properties,
378
-                        array(
379
-                            'PAY_timestamp' => time(),
380
-                            'PAY_txn_id_chq_nmbr' => null,
381
-                            'PAY_po_number' => null,
382
-                            'PAY_extra_accntng' => null,
383
-                            'PAY_details' => null,
384
-                        )
385
-                    )
386
-                );
387
-            }
388
-            //make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it
389
-            $payment->save();
390
-            $billing_values = $this->_get_billing_values_from_form($billing_info);
391
-
392
-            //  Offsite Gateway
393
-            if ($this->_gateway instanceof EE_Offsite_Gateway) {
394
-
395
-                $payment = $this->_gateway->set_redirection_info(
396
-                    $payment,
397
-                    $billing_values,
398
-                    $return_url,
399
-                    EE_Config::instance()->core->txn_page_url(
400
-                        array(
401
-                            'e_reg_url_link' => $transaction->primary_registration()->reg_url_link(),
402
-                            'ee_payment_method' => $this->_pm_instance->slug()
403
-                        )
404
-                    ),
405
-                    $fail_url
406
-                );
407
-                $payment->save();
408
-                //  Onsite Gateway
409
-            } elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
410
-
411
-                $payment = $this->_gateway->do_direct_payment($payment, $billing_values);
412
-                $payment->save();
413
-
414
-            } else {
415
-                throw new EE_Error(
416
-                    sprintf(
417
-                        __('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', 'event_espresso'),
418
-                        get_class($this),
419
-                        gettype($this->_gateway)
420
-                    )
421
-                );
422
-            }
423
-
424
-        } else {
425
-            // no gateway provided
426
-            // there is no payment. Must be an offline gateway
427
-            // create a payment object anyways, but dont save it
428
-            $payment = EE_Payment::new_instance(
429
-                array(
430
-                    'STS_ID' => EEM_Payment::status_id_pending,
431
-                    'TXN_ID' => $transaction->ID(),
432
-                    'PMD_ID' => $transaction->payment_method_ID(),
433
-                    'PAY_amount' => 0.00,
434
-                    'PAY_timestamp' => time(),
435
-                )
436
-            );
437
-
438
-        }
439
-
440
-        // if there is billing info, clean it and save it now
441
-        if ($billing_info instanceof EE_Billing_Attendee_Info_Form) {
442
-            $this->_save_billing_info_to_attendee($billing_info, $transaction);
443
-        }
444
-
445
-        return $payment;
446
-    }
447
-
448
-    /**
449
-     * Gets the values we want to pass onto the gateway. Normally these
450
-     * are just the 'pretty' values, but there may be times the data may need
451
-     * a  little massaging. Proper subsections will become arrays of inputs
452
-     * @param EE_Billing_Info_Form $billing_form
453
-     * @return array
454
-     */
455
-    protected function _get_billing_values_from_form($billing_form)
456
-    {
457
-        if ($billing_form instanceof EE_Form_Section_Proper) {
458
-            return $billing_form->input_pretty_values(true);
459
-        } else {
460
-            return NULL;
461
-        }
462
-    }
463
-
464
-
465
-    /**
466
-     * Handles an instant payment notification when the transaction is known (by default).
467
-     * @param array $req_data
468
-     * @param EE_Transaction $transaction
469
-     * @return EE_Payment
470
-     * @throws EE_Error
471
-     */
472
-    public function handle_ipn($req_data, $transaction)
473
-    {
474
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
475
-        if (!$this->_gateway instanceof EE_Offsite_Gateway) {
476
-            throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r($this->_gateway, TRUE)));
477
-
478
-        }
479
-        $payment = $this->_gateway->handle_payment_update($req_data, $transaction);
480
-        return $payment;
481
-    }
482
-
483
-
484
-    /**
485
-     * Saves the billing info onto the attendee of the primary registrant on this transaction, and
486
-     * cleans it first.
487
-     * @param EE_Billing_Attendee_Info_Form $billing_form
488
-     * @param EE_Transaction $transaction
489
-     * @return boolean success
490
-     */
491
-    protected function _save_billing_info_to_attendee($billing_form, $transaction)
492
-    {
493
-        if (!$transaction || !$transaction instanceof EE_Transaction) {
494
-            EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
495
-            return false;
496
-        }
497
-        $primary_reg = $transaction->primary_registration();
498
-        if (!$primary_reg) {
499
-            EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
500
-            return false;
501
-        }
502
-        $attendee = $primary_reg->attendee();
503
-        if (!$attendee) {
504
-            EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
505
-            return false;
506
-        }
507
-        return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method());
508
-
509
-    }
510
-
511
-
512
-    /**
513
-     * Gets the payment this IPN is for. Children may often want to
514
-     * override this to inspect the request
515
-     * @param EE_Transaction $transaction
516
-     * @param array $req_data
517
-     * @return EE_Payment
518
-     */
519
-    protected function find_payment_for_ipn(EE_Transaction $transaction, $req_data = array())
520
-    {
521
-        return $transaction->last_payment();
522
-    }
523
-
524
-
525
-    /**
526
-     * In case generic code cannot provide the payment processor with a specific payment method
527
-     * and transaction, it will try calling this method on each activate payment method.
528
-     * If the payment method is able to identify the request as being for it, it should fetch
529
-     * the payment its for and return it. If not, it should throw an EE_Error to indicate it cannot
530
-     * handle the IPN
531
-     * @param array $req_data
532
-     * @return EE_Payment only if this payment method can find the info its needs from $req_data
533
-     * and identifies the IPN as being for this payment method (not just fo ra payment method of this type)
534
-     * @throws EE_Error
535
-     */
536
-    public function handle_unclaimed_ipn($req_data = array())
537
-    {
538
-        throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this)));
539
-    }
540
-
541
-
542
-    /**
543
-     * Logic to be accomplished when the payment attempt is complete.
544
-     * Most payment methods don't need to do anything at this point; but some, like Mijireh, do.
545
-     * (Mijireh is an offsite gateway which doesn't send an IPN. So when the user returns to EE from
546
-     * mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status
547
-     * of the payment). Fed a transaction because it's always assumed to be the last payment that
548
-     * we're dealing with. Returns that last payment (if there is one)
549
-     *
550
-     * @param EE_Transaction $transaction
551
-     * @return EE_Payment
552
-     */
553
-    public function finalize_payment_for($transaction)
554
-    {
555
-        return $transaction->last_payment();
556
-    }
557
-
558
-
559
-    /**
560
-     * Whether or not this payment method's gateway supports sending refund requests
561
-     * @return boolean
562
-     */
563
-    public function supports_sending_refunds()
564
-    {
565
-        if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
566
-            return $this->_gateway->supports_sending_refunds();
567
-        } else {
568
-            return false;
569
-        }
570
-    }
571
-
572
-
573
-    /**
574
-     *
575
-     * @param EE_Payment $payment
576
-     * @param array $refund_info
577
-     * @throws EE_Error
578
-     * @return EE_Payment
579
-     */
580
-    public function process_refund(EE_Payment $payment, $refund_info = array())
581
-    {
582
-        if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
583
-            return $this->_gateway->do_direct_refund($payment, $refund_info);
584
-        } else {
585
-            throw new EE_Error(
586
-                sprintf(
587
-                    __('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'),
588
-                    get_class($this)
589
-                )
590
-            );
591
-        }
592
-    }
593
-
594
-
595
-    /**
596
-     * Returns one the class's constants onsite,offsite, or offline, depending on this
597
-     * payment method's gateway.
598
-     * @return string
599
-     * @throws EE_Error
600
-     */
601
-    public function payment_occurs()
602
-    {
603
-        if (!$this->_gateway) {
604
-            return EE_PMT_Base::offline;
605
-        } elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
606
-            return EE_PMT_Base::onsite;
607
-        } elseif ($this->_gateway instanceof EE_Offsite_Gateway) {
608
-            return EE_PMT_Base::offsite;
609
-        } else {
610
-            throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"), get_class($this)));
611
-        }
612
-    }
613
-
614
-
615
-    /**
616
-     * For adding any html output ab ove the payment overview.
617
-     * Many gateways won't want ot display anything, so this function just returns an empty string.
618
-     * Other gateways may want to override this, such as offline gateways.
619
-     * @param EE_Payment $payment
620
-     * @return string
621
-     */
622
-    public function payment_overview_content(EE_Payment $payment)
623
-    {
624
-        return EEH_Template::display_template(EE_LIBRARIES . 'payment_methods' . DS . 'templates' . DS . 'payment_details_content.template.php', array('payment_method' => $this->_pm_instance, 'payment' => $payment), true);
625
-    }
626
-
627
-
628
-    /**
629
-     * @return array where keys are the help tab name,
630
-     * values are: array {
631
-     * @type string $title i18n name for the help tab
632
-     * @type string $filename name of the file located in ./help_tabs/ (ie, in a folder next to this file)
633
-     * @type array $template_args any arguments you want passed to the template file while rendering.
634
-     *                Keys will be variable names and values with be their values.
635
-     */
636
-    public function help_tabs_config()
637
-    {
638
-        return array();
639
-    }
640
-
641
-
642
-    /**
643
-     * The system name for this PMT (eg AIM, Paypal_Pro, Invoice... what gets put into
644
-     * the payment method's table's PMT_type column)
645
-     * @return string
646
-     */
647
-    public function system_name()
648
-    {
649
-        $classname = get_class($this);
650
-        return str_replace("EE_PMT_", '', $classname);
651
-    }
652
-
653
-
654
-    /**
655
-     * A pretty i18n version of the PMT name
656
-     * @return string
657
-     */
658
-    public function pretty_name()
659
-    {
660
-        return $this->_pretty_name;
661
-    }
662
-
663
-
664
-    /**
665
-     * Gets the default absolute URL to the payment method type's button
666
-     * @return string
667
-     */
668
-    public function default_button_url()
669
-    {
670
-        return $this->_default_button_url;
671
-    }
672
-
673
-
674
-    /**
675
-     * Gets the gateway used by this payment method (if any)
676
-     * @return EE_Gateway
677
-     */
678
-    public function get_gateway()
679
-    {
680
-        return $this->_gateway;
681
-    }
682
-
683
-
684
-    /**
685
-     * @return string html for the link to a help tab
686
-     */
687
-    public function get_help_tab_link()
688
-    {
689
-        return EEH_Template::get_help_tab_link($this->get_help_tab_name());
690
-    }
691
-
692
-
693
-    /**
694
-     * Returns the name of the help tab for this PMT
695
-     * @return string
696
-     */
697
-    public function get_help_tab_name()
698
-    {
699
-        return 'ee_' . strtolower($this->system_name()) . '_help_tab';
700
-    }
701
-
702
-    /**
703
-     * The name of the wp capability that should be associated with the usage of
704
-     * this PMT by an admin
705
-     * @return string
706
-     */
707
-    public function cap_name()
708
-    {
709
-        return 'ee_payment_method_' . strtolower($this->system_name());
710
-    }
711
-
712
-    /**
713
-     * Called by client code to tell the gateway that if it wants to change
714
-     * the transaction or line items or registrations related to teh payment it already
715
-     * processed (we think, but possibly not) that now's the time to do it.
716
-     * It is expected that gateways will store any info they need for this on the PAY_details,
717
-     * or maybe an extra meta value
718
-     * @param EE_Payment $payment
719
-     * @return void
720
-     */
721
-    public function update_txn_based_on_payment($payment)
722
-    {
723
-        if ($this->_gateway instanceof EE_Gateway) {
724
-            $this->_gateway->update_txn_based_on_payment($payment);
725
-        }
726
-    }
727
-
728
-    /**
729
-     * Returns a string of HTML describing this payment method type for an admin,
730
-     * primarily intended for them to read before activating it.
731
-     * The easiest way to set this is to create a folder 'templates' alongside
732
-     * your EE_PMT_{System_Name} file, and in it create a file named "{system_name}_intro.template.php".
733
-     * Eg, if your payment method file is named "EE_PMT_Foo_Bar.pm.php",
734
-     * then you'd create a file named "templates" in the same folder as it, and name the file
735
-     * "foo_bar_intro.template.php", and its content will be returned by this method
736
-     * @return string
737
-     */
738
-    public function introductory_html()
739
-    {
740
-        return EEH_Template::locate_template($this->file_folder() . 'templates' . DS . strtolower($this->system_name()) . '_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance));
741
-    }
24
+	const onsite = 'on-site';
25
+	const offsite = 'off-site';
26
+	const offline = 'off-line';
27
+
28
+	/**
29
+	 * @var EE_Payment_Method
30
+	 */
31
+	protected $_pm_instance = NULL;
32
+
33
+	/**
34
+	 * @var boolean
35
+	 */
36
+	protected $_requires_https = FALSE;
37
+
38
+	/**
39
+	 * @var boolean
40
+	 */
41
+	protected $_has_billing_form;
42
+
43
+	/**
44
+	 * @var EE_Gateway
45
+	 */
46
+	protected $_gateway = NULL;
47
+
48
+	/**
49
+	 * @var EE_Payment_Method_Form
50
+	 */
51
+	protected $_settings_form = NULL;
52
+
53
+	/**
54
+	 * @var EE_Form_Section_Proper
55
+	 */
56
+	protected $_billing_form = NULL;
57
+
58
+	/**
59
+	 * @var boolean
60
+	 */
61
+	protected $_cache_billing_form = TRUE;
62
+
63
+	/**
64
+	 * String of the absolute path to the folder containing this file, with a trailing slash.
65
+	 * eg '/public_html/wp-site/wp-content/plugins/event-espresso/payment_methods/Invoice/'
66
+	 * @var string
67
+	 */
68
+	protected $_file_folder = NULL;
69
+
70
+	/**
71
+	 * String to the absolute URL to this file (useful for getting its web-accessible resources
72
+	 * like images, js, or css)
73
+	 * @var string
74
+	 */
75
+	protected $_file_url = NULL;
76
+
77
+	/**
78
+	 * Pretty name for the payment method
79
+	 * @var string
80
+	 */
81
+	protected $_pretty_name = NULL;
82
+
83
+	/**
84
+	 *
85
+	 * @var string
86
+	 */
87
+	protected $_default_button_url = NULL;
88
+
89
+	/**
90
+	 *
91
+	 * @var string
92
+	 */
93
+	protected $_default_description = NULL;
94
+
95
+
96
+	/**
97
+	 *
98
+	 * @param EE_Payment_Method $pm_instance
99
+	 * @throws EE_Error
100
+	 * @return EE_PMT_Base
101
+	 */
102
+	function __construct($pm_instance = NULL)
103
+	{
104
+		if ($pm_instance instanceof EE_Payment_Method) {
105
+			$this->set_instance($pm_instance);
106
+		}
107
+		if ($this->_gateway) {
108
+			$this->_gateway->set_payment_model(EEM_Payment::instance());
109
+			$this->_gateway->set_payment_log(EEM_Change_Log::instance());
110
+			$this->_gateway->set_template_helper(new EEH_Template());
111
+			$this->_gateway->set_line_item_helper(new EEH_Line_Item());
112
+			$this->_gateway->set_money_helper(new EEH_Money());
113
+			$this->_gateway->set_gateway_data_formatter(new GatewayDataFormatter());
114
+			$this->_gateway->set_unsupported_character_remover(new AsciiOnly());
115
+			do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway);
116
+		}
117
+		if (!isset($this->_has_billing_form)) {
118
+			// by default, On Site gateways have a billing form
119
+			if ($this->payment_occurs() == EE_PMT_Base::onsite) {
120
+				$this->set_has_billing_form(true);
121
+			} else {
122
+				$this->set_has_billing_form(false);
123
+			}
124
+		}
125
+
126
+		if (!$this->_pretty_name) {
127
+			throw new EE_Error(sprintf(__("You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", "event_espresso")));
128
+		}
129
+		//if the child didn't specify a default button, use the credit card one
130
+		if ($this->_default_button_url === NULL) {
131
+			$this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png';
132
+		}
133
+	}
134
+
135
+
136
+	/**
137
+	 * @param boolean $has_billing_form
138
+	 */
139
+	public function set_has_billing_form($has_billing_form)
140
+	{
141
+		$this->_has_billing_form = filter_var($has_billing_form, FILTER_VALIDATE_BOOLEAN);
142
+	}
143
+
144
+
145
+	/**
146
+	 * sets the file_folder property
147
+	 */
148
+	protected function _set_file_folder()
149
+	{
150
+		$reflector = new ReflectionClass(get_class($this));
151
+		$fn = $reflector->getFileName();
152
+		$this->_file_folder = dirname($fn) . DS;
153
+	}
154
+
155
+
156
+	/**
157
+	 * sets the file URL with a trailing slash for this PMT
158
+	 */
159
+	protected function _set_file_url()
160
+	{
161
+		$plugins_dir_fixed = str_replace('\\', DS, WP_PLUGIN_DIR);
162
+		$file_folder_fixed = str_replace('\\', DS, $this->file_folder());
163
+		$file_path = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed);
164
+		$this->_file_url = $file_path;
165
+	}
166
+
167
+	/**
168
+	 * Gets the default description on all payment methods of this type
169
+	 * @return string
170
+	 */
171
+	public function default_description()
172
+	{
173
+		return $this->_default_description;
174
+	}
175
+
176
+
177
+	/**
178
+	 * Returns the folder containing the PMT child class, with a trailing slash
179
+	 * @return string
180
+	 */
181
+	public function file_folder()
182
+	{
183
+		if (!$this->_file_folder) {
184
+			$this->_set_file_folder();
185
+		}
186
+		return $this->_file_folder;
187
+	}
188
+
189
+
190
+	/**
191
+	 * @return string
192
+	 */
193
+	public function file_url()
194
+	{
195
+		if (!$this->_file_url) {
196
+			$this->_set_file_url();
197
+		}
198
+		return $this->_file_url;
199
+	}
200
+
201
+
202
+	/**
203
+	 * Sets the payment method instance this payment method type is for.
204
+	 * Its important teh payment method instance is set before
205
+	 * @param EE_Payment_Method $payment_method_instance
206
+	 */
207
+	function set_instance($payment_method_instance)
208
+	{
209
+		$this->_pm_instance = $payment_method_instance;
210
+		//if they have already requested the settings form, make sure its
211
+		//data matches this model object
212
+		if ($this->_settings_form) {
213
+			$this->settings_form()->populate_model_obj($payment_method_instance);
214
+		}
215
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
216
+			$this->_gateway->set_settings($payment_method_instance->settings_array());
217
+		}
218
+	}
219
+
220
+
221
+	/**
222
+	 * Gets teh form for displaying to admins where they setup the payment method
223
+	 * @return EE_Payment_Method_Form
224
+	 */
225
+	function settings_form()
226
+	{
227
+		if (!$this->_settings_form) {
228
+			$this->_settings_form = $this->generate_new_settings_form();
229
+			$this->_settings_form->set_payment_method_type($this);
230
+			//if we have already assigned a model object to this pmt, make
231
+			//sure its reflected in teh form we just generated
232
+			if ($this->_pm_instance) {
233
+				$this->_settings_form->populate_model_obj($this->_pm_instance);
234
+			}
235
+		}
236
+		return $this->_settings_form;
237
+	}
238
+
239
+
240
+	/**
241
+	 * Gets the form for all the settings related to this payment method type
242
+	 * @return EE_Payment_Method_Form
243
+	 */
244
+	abstract function generate_new_settings_form();
245
+
246
+
247
+	/**
248
+	 * Sets the form for settings. This may be useful if we have already received
249
+	 * a form submission and have form data it in, and want to use it anytime we're showing
250
+	 * this payment method type's settings form later in the request
251
+	 * @param EE_Payment_Method_Form $form
252
+	 */
253
+	public function set_settings_form($form)
254
+	{
255
+		$this->_settings_form = $form;
256
+	}
257
+
258
+
259
+	/**
260
+	 * @return boolean
261
+	 */
262
+	public function has_billing_form()
263
+	{
264
+		return $this->_has_billing_form;
265
+	}
266
+
267
+
268
+	/**
269
+	 * Gets the form for displaying to attendees where they can enter their billing info
270
+	 * which will be sent to teh gateway (can be null)
271
+	 *
272
+	 * @param \EE_Transaction $transaction
273
+	 * @param array $extra_args
274
+	 * @return \EE_Billing_Attendee_Info_Form|\EE_Billing_Info_Form|null
275
+	 */
276
+	public function billing_form(EE_Transaction $transaction = NULL, $extra_args = array())
277
+	{
278
+		// has billing form already been regenerated ? or overwrite cache?
279
+		if (!$this->_billing_form instanceof EE_Billing_Info_Form || !$this->_cache_billing_form) {
280
+			$this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args);
281
+		}
282
+		//if we know who the attendee is, and this is a billing form
283
+		//that uses attendee info, populate it
284
+		if (
285
+		apply_filters(
286
+			'FHEE__populate_billing_form_fields_from_attendee',
287
+			(
288
+				$this->_billing_form instanceof EE_Billing_Attendee_Info_Form
289
+				&& $transaction instanceof EE_Transaction
290
+				&& $transaction->primary_registration() instanceof EE_Registration
291
+				&& $transaction->primary_registration()->attendee() instanceof EE_Attendee
292
+			),
293
+			$this->_billing_form,
294
+			$transaction
295
+		)
296
+		) {
297
+			$this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee());
298
+		}
299
+		return $this->_billing_form;
300
+	}
301
+
302
+
303
+	/**
304
+	 * Creates the billing form for this payment method type
305
+	 * @param \EE_Transaction $transaction
306
+	 * @return \EE_Billing_Info_Form
307
+	 */
308
+	abstract function generate_new_billing_form(EE_Transaction $transaction = NULL);
309
+
310
+
311
+	/**
312
+	 * apply_billing_form_debug_settings
313
+	 * applies debug data to the form
314
+	 *
315
+	 * @param \EE_Billing_Info_Form $billing_form
316
+	 * @return \EE_Billing_Info_Form
317
+	 */
318
+	public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form)
319
+	{
320
+		return $billing_form;
321
+	}
322
+
323
+
324
+	/**
325
+	 * Sets the billing form for this payment method type. You may want to use this
326
+	 * if you have form
327
+	 * @param EE_Payment_Method $form
328
+	 */
329
+	public function set_billing_form($form)
330
+	{
331
+		$this->_billing_form = $form;
332
+	}
333
+
334
+
335
+	/**
336
+	 * Returns whether or not this payment method requires HTTPS to be used
337
+	 * @return boolean
338
+	 */
339
+	function requires_https()
340
+	{
341
+		return $this->_requires_https;
342
+	}
343
+
344
+
345
+	/**
346
+	 *
347
+	 * @param EE_Transaction $transaction
348
+	 * @param float $amount
349
+	 * @param EE_Billing_Info_Form $billing_info
350
+	 * @param string $return_url
351
+	 * @param string $fail_url
352
+	 * @param string $method
353
+	 * @param bool $by_admin
354
+	 * @return EE_Payment
355
+	 * @throws EE_Error
356
+	 */
357
+	function process_payment(EE_Transaction $transaction, $amount = null, $billing_info = null, $return_url = null, $fail_url = '', $method = 'CART', $by_admin = false)
358
+	{
359
+		// @todo: add surcharge for the payment method, if any
360
+		if ($this->_gateway) {
361
+			//there is a gateway, so we're going to make a payment object
362
+			//but wait! do they already have a payment in progress that we thought was failed?
363
+			$duplicate_properties = array(
364
+				'STS_ID' => EEM_Payment::status_id_failed,
365
+				'TXN_ID' => $transaction->ID(),
366
+				'PMD_ID' => $this->_pm_instance->ID(),
367
+				'PAY_source' => $method,
368
+				'PAY_amount' => $amount !== null ? $amount : $transaction->remaining(),
369
+				'PAY_gateway_response' => null,
370
+			);
371
+			$payment = EEM_Payment::instance()->get_one(array($duplicate_properties));
372
+			//if we didn't already have a payment in progress for the same thing,
373
+			//then we actually want to make a new payment
374
+			if (!$payment instanceof EE_Payment) {
375
+				$payment = EE_Payment::new_instance(
376
+					array_merge(
377
+						$duplicate_properties,
378
+						array(
379
+							'PAY_timestamp' => time(),
380
+							'PAY_txn_id_chq_nmbr' => null,
381
+							'PAY_po_number' => null,
382
+							'PAY_extra_accntng' => null,
383
+							'PAY_details' => null,
384
+						)
385
+					)
386
+				);
387
+			}
388
+			//make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it
389
+			$payment->save();
390
+			$billing_values = $this->_get_billing_values_from_form($billing_info);
391
+
392
+			//  Offsite Gateway
393
+			if ($this->_gateway instanceof EE_Offsite_Gateway) {
394
+
395
+				$payment = $this->_gateway->set_redirection_info(
396
+					$payment,
397
+					$billing_values,
398
+					$return_url,
399
+					EE_Config::instance()->core->txn_page_url(
400
+						array(
401
+							'e_reg_url_link' => $transaction->primary_registration()->reg_url_link(),
402
+							'ee_payment_method' => $this->_pm_instance->slug()
403
+						)
404
+					),
405
+					$fail_url
406
+				);
407
+				$payment->save();
408
+				//  Onsite Gateway
409
+			} elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
410
+
411
+				$payment = $this->_gateway->do_direct_payment($payment, $billing_values);
412
+				$payment->save();
413
+
414
+			} else {
415
+				throw new EE_Error(
416
+					sprintf(
417
+						__('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or null (to indicate NO gateway)', 'event_espresso'),
418
+						get_class($this),
419
+						gettype($this->_gateway)
420
+					)
421
+				);
422
+			}
423
+
424
+		} else {
425
+			// no gateway provided
426
+			// there is no payment. Must be an offline gateway
427
+			// create a payment object anyways, but dont save it
428
+			$payment = EE_Payment::new_instance(
429
+				array(
430
+					'STS_ID' => EEM_Payment::status_id_pending,
431
+					'TXN_ID' => $transaction->ID(),
432
+					'PMD_ID' => $transaction->payment_method_ID(),
433
+					'PAY_amount' => 0.00,
434
+					'PAY_timestamp' => time(),
435
+				)
436
+			);
437
+
438
+		}
439
+
440
+		// if there is billing info, clean it and save it now
441
+		if ($billing_info instanceof EE_Billing_Attendee_Info_Form) {
442
+			$this->_save_billing_info_to_attendee($billing_info, $transaction);
443
+		}
444
+
445
+		return $payment;
446
+	}
447
+
448
+	/**
449
+	 * Gets the values we want to pass onto the gateway. Normally these
450
+	 * are just the 'pretty' values, but there may be times the data may need
451
+	 * a  little massaging. Proper subsections will become arrays of inputs
452
+	 * @param EE_Billing_Info_Form $billing_form
453
+	 * @return array
454
+	 */
455
+	protected function _get_billing_values_from_form($billing_form)
456
+	{
457
+		if ($billing_form instanceof EE_Form_Section_Proper) {
458
+			return $billing_form->input_pretty_values(true);
459
+		} else {
460
+			return NULL;
461
+		}
462
+	}
463
+
464
+
465
+	/**
466
+	 * Handles an instant payment notification when the transaction is known (by default).
467
+	 * @param array $req_data
468
+	 * @param EE_Transaction $transaction
469
+	 * @return EE_Payment
470
+	 * @throws EE_Error
471
+	 */
472
+	public function handle_ipn($req_data, $transaction)
473
+	{
474
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
475
+		if (!$this->_gateway instanceof EE_Offsite_Gateway) {
476
+			throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r($this->_gateway, TRUE)));
477
+
478
+		}
479
+		$payment = $this->_gateway->handle_payment_update($req_data, $transaction);
480
+		return $payment;
481
+	}
482
+
483
+
484
+	/**
485
+	 * Saves the billing info onto the attendee of the primary registrant on this transaction, and
486
+	 * cleans it first.
487
+	 * @param EE_Billing_Attendee_Info_Form $billing_form
488
+	 * @param EE_Transaction $transaction
489
+	 * @return boolean success
490
+	 */
491
+	protected function _save_billing_info_to_attendee($billing_form, $transaction)
492
+	{
493
+		if (!$transaction || !$transaction instanceof EE_Transaction) {
494
+			EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
495
+			return false;
496
+		}
497
+		$primary_reg = $transaction->primary_registration();
498
+		if (!$primary_reg) {
499
+			EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
500
+			return false;
501
+		}
502
+		$attendee = $primary_reg->attendee();
503
+		if (!$attendee) {
504
+			EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
505
+			return false;
506
+		}
507
+		return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method());
508
+
509
+	}
510
+
511
+
512
+	/**
513
+	 * Gets the payment this IPN is for. Children may often want to
514
+	 * override this to inspect the request
515
+	 * @param EE_Transaction $transaction
516
+	 * @param array $req_data
517
+	 * @return EE_Payment
518
+	 */
519
+	protected function find_payment_for_ipn(EE_Transaction $transaction, $req_data = array())
520
+	{
521
+		return $transaction->last_payment();
522
+	}
523
+
524
+
525
+	/**
526
+	 * In case generic code cannot provide the payment processor with a specific payment method
527
+	 * and transaction, it will try calling this method on each activate payment method.
528
+	 * If the payment method is able to identify the request as being for it, it should fetch
529
+	 * the payment its for and return it. If not, it should throw an EE_Error to indicate it cannot
530
+	 * handle the IPN
531
+	 * @param array $req_data
532
+	 * @return EE_Payment only if this payment method can find the info its needs from $req_data
533
+	 * and identifies the IPN as being for this payment method (not just fo ra payment method of this type)
534
+	 * @throws EE_Error
535
+	 */
536
+	public function handle_unclaimed_ipn($req_data = array())
537
+	{
538
+		throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this)));
539
+	}
540
+
541
+
542
+	/**
543
+	 * Logic to be accomplished when the payment attempt is complete.
544
+	 * Most payment methods don't need to do anything at this point; but some, like Mijireh, do.
545
+	 * (Mijireh is an offsite gateway which doesn't send an IPN. So when the user returns to EE from
546
+	 * mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status
547
+	 * of the payment). Fed a transaction because it's always assumed to be the last payment that
548
+	 * we're dealing with. Returns that last payment (if there is one)
549
+	 *
550
+	 * @param EE_Transaction $transaction
551
+	 * @return EE_Payment
552
+	 */
553
+	public function finalize_payment_for($transaction)
554
+	{
555
+		return $transaction->last_payment();
556
+	}
557
+
558
+
559
+	/**
560
+	 * Whether or not this payment method's gateway supports sending refund requests
561
+	 * @return boolean
562
+	 */
563
+	public function supports_sending_refunds()
564
+	{
565
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
566
+			return $this->_gateway->supports_sending_refunds();
567
+		} else {
568
+			return false;
569
+		}
570
+	}
571
+
572
+
573
+	/**
574
+	 *
575
+	 * @param EE_Payment $payment
576
+	 * @param array $refund_info
577
+	 * @throws EE_Error
578
+	 * @return EE_Payment
579
+	 */
580
+	public function process_refund(EE_Payment $payment, $refund_info = array())
581
+	{
582
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
583
+			return $this->_gateway->do_direct_refund($payment, $refund_info);
584
+		} else {
585
+			throw new EE_Error(
586
+				sprintf(
587
+					__('Payment Method Type "%s" does not support sending refund requests', 'event_espresso'),
588
+					get_class($this)
589
+				)
590
+			);
591
+		}
592
+	}
593
+
594
+
595
+	/**
596
+	 * Returns one the class's constants onsite,offsite, or offline, depending on this
597
+	 * payment method's gateway.
598
+	 * @return string
599
+	 * @throws EE_Error
600
+	 */
601
+	public function payment_occurs()
602
+	{
603
+		if (!$this->_gateway) {
604
+			return EE_PMT_Base::offline;
605
+		} elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
606
+			return EE_PMT_Base::onsite;
607
+		} elseif ($this->_gateway instanceof EE_Offsite_Gateway) {
608
+			return EE_PMT_Base::offsite;
609
+		} else {
610
+			throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"), get_class($this)));
611
+		}
612
+	}
613
+
614
+
615
+	/**
616
+	 * For adding any html output ab ove the payment overview.
617
+	 * Many gateways won't want ot display anything, so this function just returns an empty string.
618
+	 * Other gateways may want to override this, such as offline gateways.
619
+	 * @param EE_Payment $payment
620
+	 * @return string
621
+	 */
622
+	public function payment_overview_content(EE_Payment $payment)
623
+	{
624
+		return EEH_Template::display_template(EE_LIBRARIES . 'payment_methods' . DS . 'templates' . DS . 'payment_details_content.template.php', array('payment_method' => $this->_pm_instance, 'payment' => $payment), true);
625
+	}
626
+
627
+
628
+	/**
629
+	 * @return array where keys are the help tab name,
630
+	 * values are: array {
631
+	 * @type string $title i18n name for the help tab
632
+	 * @type string $filename name of the file located in ./help_tabs/ (ie, in a folder next to this file)
633
+	 * @type array $template_args any arguments you want passed to the template file while rendering.
634
+	 *                Keys will be variable names and values with be their values.
635
+	 */
636
+	public function help_tabs_config()
637
+	{
638
+		return array();
639
+	}
640
+
641
+
642
+	/**
643
+	 * The system name for this PMT (eg AIM, Paypal_Pro, Invoice... what gets put into
644
+	 * the payment method's table's PMT_type column)
645
+	 * @return string
646
+	 */
647
+	public function system_name()
648
+	{
649
+		$classname = get_class($this);
650
+		return str_replace("EE_PMT_", '', $classname);
651
+	}
652
+
653
+
654
+	/**
655
+	 * A pretty i18n version of the PMT name
656
+	 * @return string
657
+	 */
658
+	public function pretty_name()
659
+	{
660
+		return $this->_pretty_name;
661
+	}
662
+
663
+
664
+	/**
665
+	 * Gets the default absolute URL to the payment method type's button
666
+	 * @return string
667
+	 */
668
+	public function default_button_url()
669
+	{
670
+		return $this->_default_button_url;
671
+	}
672
+
673
+
674
+	/**
675
+	 * Gets the gateway used by this payment method (if any)
676
+	 * @return EE_Gateway
677
+	 */
678
+	public function get_gateway()
679
+	{
680
+		return $this->_gateway;
681
+	}
682
+
683
+
684
+	/**
685
+	 * @return string html for the link to a help tab
686
+	 */
687
+	public function get_help_tab_link()
688
+	{
689
+		return EEH_Template::get_help_tab_link($this->get_help_tab_name());
690
+	}
691
+
692
+
693
+	/**
694
+	 * Returns the name of the help tab for this PMT
695
+	 * @return string
696
+	 */
697
+	public function get_help_tab_name()
698
+	{
699
+		return 'ee_' . strtolower($this->system_name()) . '_help_tab';
700
+	}
701
+
702
+	/**
703
+	 * The name of the wp capability that should be associated with the usage of
704
+	 * this PMT by an admin
705
+	 * @return string
706
+	 */
707
+	public function cap_name()
708
+	{
709
+		return 'ee_payment_method_' . strtolower($this->system_name());
710
+	}
711
+
712
+	/**
713
+	 * Called by client code to tell the gateway that if it wants to change
714
+	 * the transaction or line items or registrations related to teh payment it already
715
+	 * processed (we think, but possibly not) that now's the time to do it.
716
+	 * It is expected that gateways will store any info they need for this on the PAY_details,
717
+	 * or maybe an extra meta value
718
+	 * @param EE_Payment $payment
719
+	 * @return void
720
+	 */
721
+	public function update_txn_based_on_payment($payment)
722
+	{
723
+		if ($this->_gateway instanceof EE_Gateway) {
724
+			$this->_gateway->update_txn_based_on_payment($payment);
725
+		}
726
+	}
727
+
728
+	/**
729
+	 * Returns a string of HTML describing this payment method type for an admin,
730
+	 * primarily intended for them to read before activating it.
731
+	 * The easiest way to set this is to create a folder 'templates' alongside
732
+	 * your EE_PMT_{System_Name} file, and in it create a file named "{system_name}_intro.template.php".
733
+	 * Eg, if your payment method file is named "EE_PMT_Foo_Bar.pm.php",
734
+	 * then you'd create a file named "templates" in the same folder as it, and name the file
735
+	 * "foo_bar_intro.template.php", and its content will be returned by this method
736
+	 * @return string
737
+	 */
738
+	public function introductory_html()
739
+	{
740
+		return EEH_Template::locate_template($this->file_folder() . 'templates' . DS . strtolower($this->system_name()) . '_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance));
741
+	}
742 742
 
743 743
 
744 744
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
             $this->_gateway->set_unsupported_character_remover(new AsciiOnly());
115 115
             do_action('AHEE__EE_PMT_Base___construct__done_initializing_gateway_class', $this, $this->_gateway);
116 116
         }
117
-        if (!isset($this->_has_billing_form)) {
117
+        if ( ! isset($this->_has_billing_form)) {
118 118
             // by default, On Site gateways have a billing form
119 119
             if ($this->payment_occurs() == EE_PMT_Base::onsite) {
120 120
                 $this->set_has_billing_form(true);
@@ -123,12 +123,12 @@  discard block
 block discarded – undo
123 123
             }
124 124
         }
125 125
 
126
-        if (!$this->_pretty_name) {
126
+        if ( ! $this->_pretty_name) {
127 127
             throw new EE_Error(sprintf(__("You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", "event_espresso")));
128 128
         }
129 129
         //if the child didn't specify a default button, use the credit card one
130 130
         if ($this->_default_button_url === NULL) {
131
-            $this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png';
131
+            $this->_default_button_url = EE_PLUGIN_DIR_URL.'payment_methods'.DS.'pay-by-credit-card.png';
132 132
         }
133 133
     }
134 134
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
     {
150 150
         $reflector = new ReflectionClass(get_class($this));
151 151
         $fn = $reflector->getFileName();
152
-        $this->_file_folder = dirname($fn) . DS;
152
+        $this->_file_folder = dirname($fn).DS;
153 153
     }
154 154
 
155 155
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
      */
181 181
     public function file_folder()
182 182
     {
183
-        if (!$this->_file_folder) {
183
+        if ( ! $this->_file_folder) {
184 184
             $this->_set_file_folder();
185 185
         }
186 186
         return $this->_file_folder;
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
      */
193 193
     public function file_url()
194 194
     {
195
-        if (!$this->_file_url) {
195
+        if ( ! $this->_file_url) {
196 196
             $this->_set_file_url();
197 197
         }
198 198
         return $this->_file_url;
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
      */
225 225
     function settings_form()
226 226
     {
227
-        if (!$this->_settings_form) {
227
+        if ( ! $this->_settings_form) {
228 228
             $this->_settings_form = $this->generate_new_settings_form();
229 229
             $this->_settings_form->set_payment_method_type($this);
230 230
             //if we have already assigned a model object to this pmt, make
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
     public function billing_form(EE_Transaction $transaction = NULL, $extra_args = array())
277 277
     {
278 278
         // has billing form already been regenerated ? or overwrite cache?
279
-        if (!$this->_billing_form instanceof EE_Billing_Info_Form || !$this->_cache_billing_form) {
279
+        if ( ! $this->_billing_form instanceof EE_Billing_Info_Form || ! $this->_cache_billing_form) {
280 280
             $this->_billing_form = $this->generate_new_billing_form($transaction, $extra_args);
281 281
         }
282 282
         //if we know who the attendee is, and this is a billing form
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
             $payment = EEM_Payment::instance()->get_one(array($duplicate_properties));
372 372
             //if we didn't already have a payment in progress for the same thing,
373 373
             //then we actually want to make a new payment
374
-            if (!$payment instanceof EE_Payment) {
374
+            if ( ! $payment instanceof EE_Payment) {
375 375
                 $payment = EE_Payment::new_instance(
376 376
                     array_merge(
377 377
                         $duplicate_properties,
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
     public function handle_ipn($req_data, $transaction)
473 473
     {
474 474
         $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
475
-        if (!$this->_gateway instanceof EE_Offsite_Gateway) {
475
+        if ( ! $this->_gateway instanceof EE_Offsite_Gateway) {
476 476
             throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r($this->_gateway, TRUE)));
477 477
 
478 478
         }
@@ -490,17 +490,17 @@  discard block
 block discarded – undo
490 490
      */
491 491
     protected function _save_billing_info_to_attendee($billing_form, $transaction)
492 492
     {
493
-        if (!$transaction || !$transaction instanceof EE_Transaction) {
493
+        if ( ! $transaction || ! $transaction instanceof EE_Transaction) {
494 494
             EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
495 495
             return false;
496 496
         }
497 497
         $primary_reg = $transaction->primary_registration();
498
-        if (!$primary_reg) {
498
+        if ( ! $primary_reg) {
499 499
             EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
500 500
             return false;
501 501
         }
502 502
         $attendee = $primary_reg->attendee();
503
-        if (!$attendee) {
503
+        if ( ! $attendee) {
504 504
             EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
505 505
             return false;
506 506
         }
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
      */
601 601
     public function payment_occurs()
602 602
     {
603
-        if (!$this->_gateway) {
603
+        if ( ! $this->_gateway) {
604 604
             return EE_PMT_Base::offline;
605 605
         } elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
606 606
             return EE_PMT_Base::onsite;
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
      */
622 622
     public function payment_overview_content(EE_Payment $payment)
623 623
     {
624
-        return EEH_Template::display_template(EE_LIBRARIES . 'payment_methods' . DS . 'templates' . DS . 'payment_details_content.template.php', array('payment_method' => $this->_pm_instance, 'payment' => $payment), true);
624
+        return EEH_Template::display_template(EE_LIBRARIES.'payment_methods'.DS.'templates'.DS.'payment_details_content.template.php', array('payment_method' => $this->_pm_instance, 'payment' => $payment), true);
625 625
     }
626 626
 
627 627
 
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
      */
697 697
     public function get_help_tab_name()
698 698
     {
699
-        return 'ee_' . strtolower($this->system_name()) . '_help_tab';
699
+        return 'ee_'.strtolower($this->system_name()).'_help_tab';
700 700
     }
701 701
 
702 702
     /**
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
      */
707 707
     public function cap_name()
708 708
     {
709
-        return 'ee_payment_method_' . strtolower($this->system_name());
709
+        return 'ee_payment_method_'.strtolower($this->system_name());
710 710
     }
711 711
 
712 712
     /**
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
      */
738 738
     public function introductory_html()
739 739
     {
740
-        return EEH_Template::locate_template($this->file_folder() . 'templates' . DS . strtolower($this->system_name()) . '_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance));
740
+        return EEH_Template::locate_template($this->file_folder().'templates'.DS.strtolower($this->system_name()).'_intro.template.php', array('pmt_obj' => $this, 'pm_instance' => $this->_pm_instance));
741 741
     }
742 742
 
743 743
 
Please login to merge, or discard this patch.
acceptance_tests/tests/b-TestRegistrationSummaryCept.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -14,8 +14,8 @@  discard block
 block discarded – undo
14 14
 
15 15
 //need the MER plugin active for this test (we'll deactivate it after).
16 16
 $I->ensurePluginActive(
17
-    'event-espresso-mer-multi-event-registration',
18
-    'activated'
17
+	'event-espresso-mer-multi-event-registration',
18
+	'activated'
19 19
 );
20 20
 
21 21
 //k now we need to make sure the registration multi-status message type is active because it isn't by default
@@ -73,38 +73,38 @@  discard block
 block discarded – undo
73 73
 $I->loginAsAdmin();
74 74
 $I->amOnMessagesActivityListTablePage();
75 75
 $I->see(
76
-    '[email protected]',
77
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
78
-        'to',
79
-        'Registration Multi-status Summary',
80
-        MessagesAdmin::MESSAGE_STATUS_SENT,
81
-        '',
82
-        'Primary Registrant'
83
-    )
76
+	'[email protected]',
77
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
78
+		'to',
79
+		'Registration Multi-status Summary',
80
+		MessagesAdmin::MESSAGE_STATUS_SENT,
81
+		'',
82
+		'Primary Registrant'
83
+	)
84 84
 );
85 85
 $I->see(
86
-    '[email protected]',
87
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
88
-        'to',
89
-        'Registration Multi-status Summary',
90
-        MessagesAdmin::MESSAGE_STATUS_SENT
91
-    )
86
+	'[email protected]',
87
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
88
+		'to',
89
+		'Registration Multi-status Summary',
90
+		MessagesAdmin::MESSAGE_STATUS_SENT
91
+	)
92 92
 );
93 93
 //verify count
94 94
 $I->verifyMatchingCountofTextInMessageActivityListTableFor(
95
-    1,
96
-    '[email protected]',
97
-    'to',
98
-    'Registration Multi-status Summary',
99
-    MessagesAdmin::MESSAGE_STATUS_SENT,
100
-    'Email',
101
-    'Primary Registrant'
95
+	1,
96
+	'[email protected]',
97
+	'to',
98
+	'Registration Multi-status Summary',
99
+	MessagesAdmin::MESSAGE_STATUS_SENT,
100
+	'Email',
101
+	'Primary Registrant'
102 102
 );
103 103
 $I->verifyMatchingCountofTextInMessageActivityListTableFor(
104
-    1,
105
-    '[email protected]',
106
-    'to',
107
-    'Registration Multi-status Summary'
104
+	1,
105
+	'[email protected]',
106
+	'to',
107
+	'Registration Multi-status Summary'
108 108
 );
109 109
 
110 110
 //okay now let's do some registrations for just the first event and verify that registration multi-status summary is NOT
@@ -134,25 +134,25 @@  discard block
 block discarded – undo
134 134
 $I->loginAsAdmin();
135 135
 $I->amOnMessagesActivityListTablePage();
136 136
 $I->dontSee(
137
-    '[email protected]',
138
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
139
-        'to',
140
-        'Registration Multi-status Summary',
141
-        MessagesAdmin::MESSAGE_STATUS_SENT,
142
-        '',
143
-        'Primary Registrant'
144
-    )
137
+	'[email protected]',
138
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
139
+		'to',
140
+		'Registration Multi-status Summary',
141
+		MessagesAdmin::MESSAGE_STATUS_SENT,
142
+		'',
143
+		'Primary Registrant'
144
+	)
145 145
 );
146 146
 //there should still only be one admin multi-status summary thing.
147 147
 $I->verifyMatchingCountofTextInMessageActivityListTableFor(
148
-    1,
149
-    '[email protected]',
150
-    'to',
151
-    'Registration Multi-status Summary'
148
+	1,
149
+	'[email protected]',
150
+	'to',
151
+	'Registration Multi-status Summary'
152 152
 );
153 153
 
154 154
 //deactivate MER plugin so its not active for future tests
155 155
 $I->ensurePluginDeactivated(
156
-    'event-espresso-mer-multi-event-registration',
157
-    'plugins deactivated'
156
+	'event-espresso-mer-multi-event-registration',
157
+	'plugins deactivated'
158 158
 );
159 159
\ No newline at end of file
Please login to merge, or discard this patch.
acceptance_tests/tests/c-TestCustomMessageTemplateCept.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -18,14 +18,14 @@  discard block
 block discarded – undo
18 18
 $event_one_link = $event_two_link = $event_three_link = '';
19 19
 
20 20
 $I->wantTo(
21
-    'Test that when registrations for multiple events are completed, and those events share the same custom'
22
-    . 'template, that that custom template will be used.'
21
+	'Test that when registrations for multiple events are completed, and those events share the same custom'
22
+	. 'template, that that custom template will be used.'
23 23
 );
24 24
 
25 25
 //need the MER plugin active for this test (we'll deactivate it after).
26 26
 $I->ensurePluginActive(
27
-    'event-espresso-mer-multi-event-registration',
28
-    'activated'
27
+	'event-espresso-mer-multi-event-registration',
28
+	'activated'
29 29
 );
30 30
 
31 31
 $I->loginAsAdmin();
@@ -80,9 +80,9 @@  discard block
 block discarded – undo
80 80
 
81 81
 
82 82
 $test_registration_details = array(
83
-    'fname' => 'CTGuy',
84
-    'lname' => 'Dude',
85
-    'email' => '[email protected]'
83
+	'fname' => 'CTGuy',
84
+	'lname' => 'Dude',
85
+	'email' => '[email protected]'
86 86
 );
87 87
 
88 88
 $I->amGoingTo('Register for Event One and Event Two and verify Custom Template A was used.');
@@ -108,23 +108,23 @@  discard block
 block discarded – undo
108 108
 $I->loginAsAdmin();
109 109
 $I->amOnMessagesActivityListTablePage();
110 110
 $I->viewMessageInMessagesListTableFor(
111
-    'Registration Approved',
112
-    MessagesAdmin::MESSAGE_STATUS_SENT,
113
-    'Email',
114
-    'Registrant'
111
+	'Registration Approved',
112
+	MessagesAdmin::MESSAGE_STATUS_SENT,
113
+	'Email',
114
+	'Registrant'
115 115
 );
116 116
 $I->seeTextInViewMessageModal($custom_template_a_label);
117 117
 $I->dismissMessageModal();
118 118
 $I->deleteMessageInMessagesListTableFor(
119
-    'Registration Approved',
120
-    MessagesAdmin::MESSAGE_STATUS_SENT,
121
-    'Email',
122
-    'Registrant'
119
+	'Registration Approved',
120
+	MessagesAdmin::MESSAGE_STATUS_SENT,
121
+	'Email',
122
+	'Registrant'
123 123
 );
124 124
 
125 125
 //verify admin context
126 126
 $I->viewMessageInMessagesListTableFor(
127
-    'Registration Approved'
127
+	'Registration Approved'
128 128
 );
129 129
 $I->seeTextInViewMessageModal($custom_template_a_label);
130 130
 $I->dismissMessageModal();
@@ -153,25 +153,25 @@  discard block
 block discarded – undo
153 153
 $I->loginAsAdmin();
154 154
 $I->amOnMessagesActivityListTablePage();
155 155
 $I->viewMessageInMessagesListTableFor(
156
-    'Registration Approved',
157
-    MessagesAdmin::MESSAGE_STATUS_SENT,
158
-    'Email',
159
-    'Registrant'
156
+	'Registration Approved',
157
+	MessagesAdmin::MESSAGE_STATUS_SENT,
158
+	'Email',
159
+	'Registrant'
160 160
 );
161 161
 $I->waitForElementVisible(MessagesAdmin::MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR);
162 162
 $I->dontSeeTextInViewMessageModal($custom_template_a_label);
163 163
 $I->dontSeeTextInViewMessageModal($custom_template_b_label);
164 164
 $I->dismissMessageModal();
165 165
 $I->deleteMessageInMessagesListTableFor(
166
-    'Registration Approved',
167
-    MessagesAdmin::MESSAGE_STATUS_SENT,
168
-    'Email',
169
-    'Registrant'
166
+	'Registration Approved',
167
+	MessagesAdmin::MESSAGE_STATUS_SENT,
168
+	'Email',
169
+	'Registrant'
170 170
 );
171 171
 
172 172
 //verify admin context
173 173
 $I->viewMessageInMessagesListTableFor(
174
-    'Registration Approved'
174
+	'Registration Approved'
175 175
 );
176 176
 $I->waitForElementVisible(MessagesAdmin::MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR);
177 177
 $I->dontSee($custom_template_a_label);
@@ -183,6 +183,6 @@  discard block
 block discarded – undo
183 183
 
184 184
 //deactivate MER plugin so its not active for future tests
185 185
 $I->ensurePluginDeactivated(
186
-    'event-espresso-mer-multi-event-registration',
187
-    'plugins deactivated'
186
+	'event-espresso-mer-multi-event-registration',
187
+	'plugins deactivated'
188 188
 );
189 189
\ No newline at end of file
Please login to merge, or discard this patch.
acceptance_tests/Page/EventsAdmin.php 1 patch
Indentation   +263 added lines, -263 removed lines patch added patch discarded remove patch
@@ -14,267 +14,267 @@
 block discarded – undo
14 14
 class EventsAdmin extends CoreAdmin
15 15
 {
16 16
 
17
-    /**
18
-     * Selector for the Add new Event button in the admin.
19
-     * @var string
20
-     */
21
-    const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event';
22
-
23
-
24
-    /**
25
-     * Selector for the Event Title field in the event editor
26
-     * @var string
27
-     */
28
-    const EVENT_EDITOR_TITLE_FIELD_SELECTOR = ['xpath' => "//input[@id='title']"];
29
-
30
-    /**
31
-     * Selector for the publish submit button in the event editor.
32
-     * @var string
33
-     */
34
-    const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = ['xpath'=>"//div[@id='major-publishing-actions']//input[@id='publish']"];
35
-
36
-
37
-    /**
38
-     * Selector for the save button in the event editor
39
-     */
40
-    const EVENT_EDITOR_SAVE_BUTTON_SELECTOR = ['xpath' => "//div[@id='minor-publishing-actions']//input[@id='save-post']"];
41
-
42
-
43
-    /**
44
-     * @var string
45
-     */
46
-    const EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR = '#EVT_default_registration_status';
47
-
48
-    /**
49
-     * Selector for the view link after publishing an event.
50
-     * @var string
51
-     */
52
-    const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//span[@id='sample-permalink']/a";
53
-
54
-
55
-    /**
56
-     * Selector for the ID of the event in the event editor
57
-     * @var string
58
-     */
59
-    const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']";
60
-
61
-
62
-    /**
63
-     * Selector for the search input on the event list table page.
64
-     * @var string
65
-     */
66
-    const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input';
67
-
68
-
69
-
70
-
71
-    /**
72
-     * @param string $additional_params
73
-     * @return string
74
-     */
75
-    public static function defaultEventsListTableUrl($additional_params = '')
76
-    {
77
-        return self::adminUrl('espresso_events', 'default', $additional_params);
78
-    }
79
-
80
-
81
-    /**
82
-     * The selector for the DTTname field for the given row in the event editor.
83
-     * @param int $row_number
84
-     * @return string
85
-     */
86
-    public static function eventEditorDatetimeNameFieldSelector($row_number = 1)
87
-    {
88
-        return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number);
89
-    }
90
-
91
-
92
-    /**
93
-     * The selector for the DTT_EVT_start field for the given row in the event editor.d
94
-     * @param int $row_number
95
-     * @return string
96
-     */
97
-    public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1)
98
-    {
99
-        return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number);
100
-    }
101
-
102
-
103
-    /**
104
-     * Wrapper for getting the selector for a given field and given row of a datetime in the event editor.
105
-     *
106
-     * @param string $field_name
107
-     * @param int    $row_number
108
-     * @return string
109
-     */
110
-    public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1)
111
-    {
112
-        return "//input[@id='event-datetime-$field_name-$row_number']";
113
-    }
114
-
115
-
116
-    /**
117
-     * The selector for the TKT_name field for the given display row in the event editor.
118
-     * @param int $row_number
119
-     * @return string
120
-     */
121
-    public static function eventEditorTicketNameFieldSelector($row_number = 1)
122
-    {
123
-        return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number);
124
-    }
125
-
126
-
127
-    /**
128
-     * Selector for the TKT_base_price field for the given display row in the event editor.
129
-     * @param int $row_number
130
-     * @return string
131
-     */
132
-    public static function eventEditorTicketPriceFieldSelector($row_number = 1)
133
-    {
134
-        return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_base_price', $row_number);
135
-    }
136
-
137
-
138
-    /**
139
-     * Selector for the TKT_qty field for the given display row in the event editor.
140
-     * @param int $row_number
141
-     * @return string
142
-     */
143
-    public static function eventEditorTicketQuantityFieldSelector($row_number = 1)
144
-    {
145
-        return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_qty', $row_number);
146
-    }
147
-
148
-
149
-    /**
150
-     * Selector for the advanced details toggle for the ticket for the given display row in the event editor.
151
-     * @param int $row_number
152
-     * @return string
153
-     */
154
-    public static function eventEditorTicketAdvancedDetailsSelector($row_number = 1)
155
-    {
156
-        return "//tr[@id='display-ticketrow-$row_number']//span[contains(@class, 'gear-icon')]";
157
-    }
158
-
159
-
160
-    /**
161
-     * Selector for the subtotal amount for the given display row of the ticket in the event editor.
162
-     * @param int $row_number
163
-     * @return string
164
-     */
165
-    public static function eventEditorTicketAdvancedDetailsSubtotalSelector($row_number = 1)
166
-    {
167
-        return "//span[@id='price-total-amount-$row_number']";
168
-    }
169
-
170
-
171
-    /**
172
-     * Selector for the Total element for the given display row of the ticket in the event editor.
173
-     * @param int $row_number
174
-     * @return string
175
-     */
176
-    public static function eventEditorTicketAdvancedDetailsTotalSelector($row_number = 1)
177
-    {
178
-        return "//span[@id='price-total-amount-$row_number']";
179
-    }
180
-
181
-
182
-    /**
183
-     * Selector for the taxable selector for the ticket for the given display row in the event editor.
184
-     * @param int $row_number
185
-     * @return string
186
-     */
187
-    public static function eventEditorTicketTaxableCheckboxSelector($row_number = 1)
188
-    {
189
-        return "//input[@id='edit-ticket-TKT_taxable-$row_number']";
190
-    }
191
-
192
-
193
-    /**
194
-     * This returns the xpath locater for the Tax amount display container within the advanced settings view for the
195
-     * given ticket (row) and the given tax id (PRC_ID).
196
-     *
197
-     * @param int $tax_id     The PRC_ID for the tax you want the locater for.  Note, this defaults to the default tax
198
-     *                        setup on a fresh install.
199
-     * @param int $row_number What row representing the ticket you want the locator for.
200
-     * @return string
201
-     */
202
-    public static function eventEditorTicketTaxAmountDisplayForTaxIdAndTicketRowSelector($tax_id = 2, $row_number = 1)
203
-    {
204
-        return "//span[@id='TKT-tax-amount-display-$tax_id-$row_number']";
205
-    }
206
-
207
-
208
-    /**
209
-     * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor.
210
-     * @param     $field_name
211
-     * @param int $row_number
212
-     * @return string
213
-     */
214
-    public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1)
215
-    {
216
-        return "//tr[@id='display-ticketrow-$row_number']//input[contains(@class, 'edit-ticket-$field_name')]";
217
-    }
218
-
219
-
220
-    /**
221
-     * Returns the selector for the event title edit link in the events list table for the given Event Title.
222
-     * @param string $event_title
223
-     * @return string
224
-     */
225
-    public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title)
226
-    {
227
-        return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']";
228
-    }
229
-
230
-
231
-    /**
232
-     * Locator for for the ID column in the event list table for a given event title.
233
-     * @param string $event_title
234
-     * @return string
235
-     */
236
-    public static function eventListTableEventIdSelectorForTitle($event_title)
237
-    {
238
-        return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"
239
-               . "//ancestor::tr/th[contains(@class, 'check-column')]/input";
240
-    }
241
-
242
-
243
-    /**
244
-     * Locator for the view link in the row of an event list table for the given event title.
245
-     * @param string $event_title
246
-     * @return string
247
-     */
248
-    public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title)
249
-    {
250
-        return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"
251
-               . "//ancestor::td//span[@class='view']/a";
252
-    }
253
-
254
-
255
-    /**
256
-     * Locator for the messenger tab in the Notifications metabox in the event editor.
257
-     * @param string $messenger_slug  The slug for the messenger (it's reference slug).
258
-     * @return string
259
-     */
260
-    public static function eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug)
261
-    {
262
-        return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']"
263
-               . "//a[@rel='ee-tab-$messenger_slug']";
264
-    }
265
-
266
-
267
-    /**
268
-     * Locator for the select input within the notifications metabox.
269
-     * Note, this assumes the tab content for the related messenger is already visible.
270
-     * @param string $message_type_label The message type label (visible string in the table) you want the selector for.
271
-     * @return string
272
-     */
273
-    public static function eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label)
274
-    {
275
-        return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']"
276
-               . "//table[@class='messages-custom-template-switcher']"
277
-               . "//tr/td[contains(.,'Registration Approved')]"
278
-               . "//ancestor::tr//select[contains(@class,'message-template-selector')]";
279
-    }
17
+	/**
18
+	 * Selector for the Add new Event button in the admin.
19
+	 * @var string
20
+	 */
21
+	const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event';
22
+
23
+
24
+	/**
25
+	 * Selector for the Event Title field in the event editor
26
+	 * @var string
27
+	 */
28
+	const EVENT_EDITOR_TITLE_FIELD_SELECTOR = ['xpath' => "//input[@id='title']"];
29
+
30
+	/**
31
+	 * Selector for the publish submit button in the event editor.
32
+	 * @var string
33
+	 */
34
+	const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = ['xpath'=>"//div[@id='major-publishing-actions']//input[@id='publish']"];
35
+
36
+
37
+	/**
38
+	 * Selector for the save button in the event editor
39
+	 */
40
+	const EVENT_EDITOR_SAVE_BUTTON_SELECTOR = ['xpath' => "//div[@id='minor-publishing-actions']//input[@id='save-post']"];
41
+
42
+
43
+	/**
44
+	 * @var string
45
+	 */
46
+	const EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR = '#EVT_default_registration_status';
47
+
48
+	/**
49
+	 * Selector for the view link after publishing an event.
50
+	 * @var string
51
+	 */
52
+	const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//span[@id='sample-permalink']/a";
53
+
54
+
55
+	/**
56
+	 * Selector for the ID of the event in the event editor
57
+	 * @var string
58
+	 */
59
+	const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']";
60
+
61
+
62
+	/**
63
+	 * Selector for the search input on the event list table page.
64
+	 * @var string
65
+	 */
66
+	const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input';
67
+
68
+
69
+
70
+
71
+	/**
72
+	 * @param string $additional_params
73
+	 * @return string
74
+	 */
75
+	public static function defaultEventsListTableUrl($additional_params = '')
76
+	{
77
+		return self::adminUrl('espresso_events', 'default', $additional_params);
78
+	}
79
+
80
+
81
+	/**
82
+	 * The selector for the DTTname field for the given row in the event editor.
83
+	 * @param int $row_number
84
+	 * @return string
85
+	 */
86
+	public static function eventEditorDatetimeNameFieldSelector($row_number = 1)
87
+	{
88
+		return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number);
89
+	}
90
+
91
+
92
+	/**
93
+	 * The selector for the DTT_EVT_start field for the given row in the event editor.d
94
+	 * @param int $row_number
95
+	 * @return string
96
+	 */
97
+	public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1)
98
+	{
99
+		return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number);
100
+	}
101
+
102
+
103
+	/**
104
+	 * Wrapper for getting the selector for a given field and given row of a datetime in the event editor.
105
+	 *
106
+	 * @param string $field_name
107
+	 * @param int    $row_number
108
+	 * @return string
109
+	 */
110
+	public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1)
111
+	{
112
+		return "//input[@id='event-datetime-$field_name-$row_number']";
113
+	}
114
+
115
+
116
+	/**
117
+	 * The selector for the TKT_name field for the given display row in the event editor.
118
+	 * @param int $row_number
119
+	 * @return string
120
+	 */
121
+	public static function eventEditorTicketNameFieldSelector($row_number = 1)
122
+	{
123
+		return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number);
124
+	}
125
+
126
+
127
+	/**
128
+	 * Selector for the TKT_base_price field for the given display row in the event editor.
129
+	 * @param int $row_number
130
+	 * @return string
131
+	 */
132
+	public static function eventEditorTicketPriceFieldSelector($row_number = 1)
133
+	{
134
+		return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_base_price', $row_number);
135
+	}
136
+
137
+
138
+	/**
139
+	 * Selector for the TKT_qty field for the given display row in the event editor.
140
+	 * @param int $row_number
141
+	 * @return string
142
+	 */
143
+	public static function eventEditorTicketQuantityFieldSelector($row_number = 1)
144
+	{
145
+		return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_qty', $row_number);
146
+	}
147
+
148
+
149
+	/**
150
+	 * Selector for the advanced details toggle for the ticket for the given display row in the event editor.
151
+	 * @param int $row_number
152
+	 * @return string
153
+	 */
154
+	public static function eventEditorTicketAdvancedDetailsSelector($row_number = 1)
155
+	{
156
+		return "//tr[@id='display-ticketrow-$row_number']//span[contains(@class, 'gear-icon')]";
157
+	}
158
+
159
+
160
+	/**
161
+	 * Selector for the subtotal amount for the given display row of the ticket in the event editor.
162
+	 * @param int $row_number
163
+	 * @return string
164
+	 */
165
+	public static function eventEditorTicketAdvancedDetailsSubtotalSelector($row_number = 1)
166
+	{
167
+		return "//span[@id='price-total-amount-$row_number']";
168
+	}
169
+
170
+
171
+	/**
172
+	 * Selector for the Total element for the given display row of the ticket in the event editor.
173
+	 * @param int $row_number
174
+	 * @return string
175
+	 */
176
+	public static function eventEditorTicketAdvancedDetailsTotalSelector($row_number = 1)
177
+	{
178
+		return "//span[@id='price-total-amount-$row_number']";
179
+	}
180
+
181
+
182
+	/**
183
+	 * Selector for the taxable selector for the ticket for the given display row in the event editor.
184
+	 * @param int $row_number
185
+	 * @return string
186
+	 */
187
+	public static function eventEditorTicketTaxableCheckboxSelector($row_number = 1)
188
+	{
189
+		return "//input[@id='edit-ticket-TKT_taxable-$row_number']";
190
+	}
191
+
192
+
193
+	/**
194
+	 * This returns the xpath locater for the Tax amount display container within the advanced settings view for the
195
+	 * given ticket (row) and the given tax id (PRC_ID).
196
+	 *
197
+	 * @param int $tax_id     The PRC_ID for the tax you want the locater for.  Note, this defaults to the default tax
198
+	 *                        setup on a fresh install.
199
+	 * @param int $row_number What row representing the ticket you want the locator for.
200
+	 * @return string
201
+	 */
202
+	public static function eventEditorTicketTaxAmountDisplayForTaxIdAndTicketRowSelector($tax_id = 2, $row_number = 1)
203
+	{
204
+		return "//span[@id='TKT-tax-amount-display-$tax_id-$row_number']";
205
+	}
206
+
207
+
208
+	/**
209
+	 * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor.
210
+	 * @param     $field_name
211
+	 * @param int $row_number
212
+	 * @return string
213
+	 */
214
+	public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1)
215
+	{
216
+		return "//tr[@id='display-ticketrow-$row_number']//input[contains(@class, 'edit-ticket-$field_name')]";
217
+	}
218
+
219
+
220
+	/**
221
+	 * Returns the selector for the event title edit link in the events list table for the given Event Title.
222
+	 * @param string $event_title
223
+	 * @return string
224
+	 */
225
+	public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title)
226
+	{
227
+		return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']";
228
+	}
229
+
230
+
231
+	/**
232
+	 * Locator for for the ID column in the event list table for a given event title.
233
+	 * @param string $event_title
234
+	 * @return string
235
+	 */
236
+	public static function eventListTableEventIdSelectorForTitle($event_title)
237
+	{
238
+		return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"
239
+			   . "//ancestor::tr/th[contains(@class, 'check-column')]/input";
240
+	}
241
+
242
+
243
+	/**
244
+	 * Locator for the view link in the row of an event list table for the given event title.
245
+	 * @param string $event_title
246
+	 * @return string
247
+	 */
248
+	public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title)
249
+	{
250
+		return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"
251
+			   . "//ancestor::td//span[@class='view']/a";
252
+	}
253
+
254
+
255
+	/**
256
+	 * Locator for the messenger tab in the Notifications metabox in the event editor.
257
+	 * @param string $messenger_slug  The slug for the messenger (it's reference slug).
258
+	 * @return string
259
+	 */
260
+	public static function eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug)
261
+	{
262
+		return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']"
263
+			   . "//a[@rel='ee-tab-$messenger_slug']";
264
+	}
265
+
266
+
267
+	/**
268
+	 * Locator for the select input within the notifications metabox.
269
+	 * Note, this assumes the tab content for the related messenger is already visible.
270
+	 * @param string $message_type_label The message type label (visible string in the table) you want the selector for.
271
+	 * @return string
272
+	 */
273
+	public static function eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label)
274
+	{
275
+		return "//div[@id='espresso_events_Messages_Hooks_Extend_messages_metabox_metabox']"
276
+			   . "//table[@class='messages-custom-template-switcher']"
277
+			   . "//tr/td[contains(.,'Registration Approved')]"
278
+			   . "//ancestor::tr//select[contains(@class,'message-template-selector')]";
279
+	}
280 280
 }
Please login to merge, or discard this patch.
acceptance_tests/Helpers/EventsAdmin.php 1 patch
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -14,133 +14,133 @@
 block discarded – undo
14 14
 trait EventsAdmin
15 15
 {
16 16
 
17
-    /**
18
-     * @param string $additional_params
19
-     */
20
-    public function amOnDefaultEventsListTablePage($additional_params = '')
21
-    {
22
-        $this->actor()->amOnAdminPage(EventsPage::defaultEventsListTableUrl($additional_params));
23
-    }
24
-
25
-
26
-    /**
27
-     * Triggers the publishing of the Event.
28
-     */
29
-    public function publishEvent()
30
-    {
31
-        $this->actor()->scrollTo(EventsPage::EVENT_EDITOR_TITLE_FIELD_SELECTOR);
32
-        $this->actor()->wait(2);
33
-        $this->actor()->click(EventsPage::EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR);
34
-        $this->actor()->waitForText('Event published.', 30);
35
-    }
36
-
37
-
38
-    /**
39
-     * Triggers saving the Event.
40
-     */
41
-    public function saveEvent()
42
-    {
43
-        $this->actor()->scrollTo(EventsPage::EVENT_EDITOR_TITLE_FIELD_SELECTOR);
44
-        $this->actor()->wait(2);
45
-        $this->actor()->click(EventsPage::EVENT_EDITOR_SAVE_BUTTON_SELECTOR);
46
-    }
47
-
48
-
49
-    /**
50
-     * Navigates the actor to the event list table page and will attempt to edit the event for the given title.
51
-     * First this will search using the given title and then attempt to edit from the results of the search.
52
-     *
53
-     * Assumes actor is already logged in.
54
-     * @param $event_title
55
-     */
56
-    public function amEditingTheEventWithTitle($event_title)
57
-    {
58
-        $this->amOnDefaultEventsListTablePage();
59
-        $this->actor()->fillField(EventsPage::EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR, $event_title);
60
-        $this->actor()->click(CoreAdmin::LIST_TABLE_SEARCH_SUBMIT_SELECTOR);
61
-        $this->actor()->waitForText($event_title, 15);
62
-        $this->actor()->click(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title));
63
-    }
64
-
65
-
66
-    /**
67
-     * Navigates the user to the single event page (frontend view) for the given event title via clicking the "View"
68
-     * link for the event in the event list table.
69
-     * Assumes the actor is already logged in and on the Event list table page.
70
-     *
71
-     * @param string $event_title
72
-     */
73
-    public function amOnEventPageAfterClickingViewLinkInListTableForEvent($event_title)
74
-    {
75
-        $this->actor()->moveMouseOver(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title));
76
-        $this->actor()->click(EventsPage::eventListTableEventTitleViewLinkSelectorForTitle($event_title));
77
-    }
78
-
79
-
80
-    /**
81
-     * Used to retrieve the event id for the event via the list table and for the given event.
82
-     * @param string $event_title
83
-     */
84
-    public function observeEventIdInListTableForEvent($event_title)
85
-    {
86
-        return $this->actor()->observeValueFromInputAt(EventsPage::eventListTableEventIdSelectorForTitle($event_title));
87
-    }
88
-
89
-
90
-    /**
91
-     * This performs the click action on the gear icon that triggers the advanced settings view state.
92
-     * Assumes the actor is already logged in and editing an event.
93
-     *
94
-     * @param int $row_number  What ticket row to toggle open/close.
95
-     */
96
-    public function toggleAdvancedSettingsViewForTicketRow($row_number = 1)
97
-    {
98
-        $this->actor()->click(EventsPage::eventEditorTicketAdvancedDetailsSelector($row_number));
99
-    }
100
-
101
-
102
-    /**
103
-     * Toggles the TKT_is_taxable checkbox for the ticket in the given row.
104
-     * Assumes the actor is already logged in and editing an event and that the advanced settings view state for that
105
-     * ticket is "open".
106
-     *
107
-     * @param int $row_number  What ticket row to toggle the checkbox for.
108
-     */
109
-    public function toggleTicketIsTaxableForTicketRow($row_number = 1)
110
-    {
111
-        $this->actor()->click(EventsPage::eventEditorTicketTaxableCheckboxSelector($row_number));
112
-    }
113
-
114
-
115
-    /**
116
-     * Use to change the default registration status for the event.
117
-     * Assumes the view is already on the event editor.
118
-     * @param $registration_status
119
-     */
120
-    public function changeDefaultRegistrationStatusTo($registration_status)
121
-    {
122
-        $this->actor()->selectOption(
123
-            EventsPage::EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR,
124
-            $registration_status
125
-        );
126
-    }
127
-
128
-
129
-    /**
130
-     * Use this from the context of the event editor to select the given custom template for a given message type and
131
-     * messenger.
132
-     *
133
-     * @param string $message_type_label  The visible label for the message type (eg Registration Approved)
134
-     * @param string $messenger_slug      The slug for the messenger (eg 'email')
135
-     * @param string $custom_template_label The visible label in the select input for the custom template you want
136
-     *                                      selected.
137
-     */
138
-    public function selectCustomTemplateFor($message_type_label, $messenger_slug, $custom_template_label)
139
-    {
140
-        $this->actor()->click(EventsPage::eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug));
141
-        $this->actor()->selectOption(
142
-            EventsPage::eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label),
143
-            $custom_template_label
144
-        );
145
-    }
17
+	/**
18
+	 * @param string $additional_params
19
+	 */
20
+	public function amOnDefaultEventsListTablePage($additional_params = '')
21
+	{
22
+		$this->actor()->amOnAdminPage(EventsPage::defaultEventsListTableUrl($additional_params));
23
+	}
24
+
25
+
26
+	/**
27
+	 * Triggers the publishing of the Event.
28
+	 */
29
+	public function publishEvent()
30
+	{
31
+		$this->actor()->scrollTo(EventsPage::EVENT_EDITOR_TITLE_FIELD_SELECTOR);
32
+		$this->actor()->wait(2);
33
+		$this->actor()->click(EventsPage::EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR);
34
+		$this->actor()->waitForText('Event published.', 30);
35
+	}
36
+
37
+
38
+	/**
39
+	 * Triggers saving the Event.
40
+	 */
41
+	public function saveEvent()
42
+	{
43
+		$this->actor()->scrollTo(EventsPage::EVENT_EDITOR_TITLE_FIELD_SELECTOR);
44
+		$this->actor()->wait(2);
45
+		$this->actor()->click(EventsPage::EVENT_EDITOR_SAVE_BUTTON_SELECTOR);
46
+	}
47
+
48
+
49
+	/**
50
+	 * Navigates the actor to the event list table page and will attempt to edit the event for the given title.
51
+	 * First this will search using the given title and then attempt to edit from the results of the search.
52
+	 *
53
+	 * Assumes actor is already logged in.
54
+	 * @param $event_title
55
+	 */
56
+	public function amEditingTheEventWithTitle($event_title)
57
+	{
58
+		$this->amOnDefaultEventsListTablePage();
59
+		$this->actor()->fillField(EventsPage::EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR, $event_title);
60
+		$this->actor()->click(CoreAdmin::LIST_TABLE_SEARCH_SUBMIT_SELECTOR);
61
+		$this->actor()->waitForText($event_title, 15);
62
+		$this->actor()->click(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title));
63
+	}
64
+
65
+
66
+	/**
67
+	 * Navigates the user to the single event page (frontend view) for the given event title via clicking the "View"
68
+	 * link for the event in the event list table.
69
+	 * Assumes the actor is already logged in and on the Event list table page.
70
+	 *
71
+	 * @param string $event_title
72
+	 */
73
+	public function amOnEventPageAfterClickingViewLinkInListTableForEvent($event_title)
74
+	{
75
+		$this->actor()->moveMouseOver(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title));
76
+		$this->actor()->click(EventsPage::eventListTableEventTitleViewLinkSelectorForTitle($event_title));
77
+	}
78
+
79
+
80
+	/**
81
+	 * Used to retrieve the event id for the event via the list table and for the given event.
82
+	 * @param string $event_title
83
+	 */
84
+	public function observeEventIdInListTableForEvent($event_title)
85
+	{
86
+		return $this->actor()->observeValueFromInputAt(EventsPage::eventListTableEventIdSelectorForTitle($event_title));
87
+	}
88
+
89
+
90
+	/**
91
+	 * This performs the click action on the gear icon that triggers the advanced settings view state.
92
+	 * Assumes the actor is already logged in and editing an event.
93
+	 *
94
+	 * @param int $row_number  What ticket row to toggle open/close.
95
+	 */
96
+	public function toggleAdvancedSettingsViewForTicketRow($row_number = 1)
97
+	{
98
+		$this->actor()->click(EventsPage::eventEditorTicketAdvancedDetailsSelector($row_number));
99
+	}
100
+
101
+
102
+	/**
103
+	 * Toggles the TKT_is_taxable checkbox for the ticket in the given row.
104
+	 * Assumes the actor is already logged in and editing an event and that the advanced settings view state for that
105
+	 * ticket is "open".
106
+	 *
107
+	 * @param int $row_number  What ticket row to toggle the checkbox for.
108
+	 */
109
+	public function toggleTicketIsTaxableForTicketRow($row_number = 1)
110
+	{
111
+		$this->actor()->click(EventsPage::eventEditorTicketTaxableCheckboxSelector($row_number));
112
+	}
113
+
114
+
115
+	/**
116
+	 * Use to change the default registration status for the event.
117
+	 * Assumes the view is already on the event editor.
118
+	 * @param $registration_status
119
+	 */
120
+	public function changeDefaultRegistrationStatusTo($registration_status)
121
+	{
122
+		$this->actor()->selectOption(
123
+			EventsPage::EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR,
124
+			$registration_status
125
+		);
126
+	}
127
+
128
+
129
+	/**
130
+	 * Use this from the context of the event editor to select the given custom template for a given message type and
131
+	 * messenger.
132
+	 *
133
+	 * @param string $message_type_label  The visible label for the message type (eg Registration Approved)
134
+	 * @param string $messenger_slug      The slug for the messenger (eg 'email')
135
+	 * @param string $custom_template_label The visible label in the select input for the custom template you want
136
+	 *                                      selected.
137
+	 */
138
+	public function selectCustomTemplateFor($message_type_label, $messenger_slug, $custom_template_label)
139
+	{
140
+		$this->actor()->click(EventsPage::eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug));
141
+		$this->actor()->selectOption(
142
+			EventsPage::eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label),
143
+			$custom_template_label
144
+		);
145
+	}
146 146
 }
147 147
\ No newline at end of file
Please login to merge, or discard this patch.
acceptance_tests/Helpers/MessagesAdmin.php 1 patch
Indentation   +292 added lines, -292 removed lines patch added patch discarded remove patch
@@ -10,296 +10,296 @@
 block discarded – undo
10 10
  */
11 11
 trait MessagesAdmin
12 12
 {
13
-    /**
14
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
15
-     *                                  a string.
16
-     */
17
-    public function amOnMessagesActivityListTablePage($additional_params = '')
18
-    {
19
-        $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params));
20
-    }
21
-
22
-    /**
23
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
24
-     *                                  a string.
25
-     */
26
-    public function amOnDefaultMessageTemplateListTablePage($additional_params = '')
27
-    {
28
-        $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params));
29
-    }
30
-
31
-
32
-    /**
33
-     * @param string $additional_params Any additional request parameters for the generated url should be included as
34
-     *                                  a string.
35
-     */
36
-    public function amOnCustomMessageTemplateListTablePage($additional_params = '')
37
-    {
38
-        $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params));
39
-    }
40
-
41
-
42
-    /**
43
-     * Directs to message settings page
44
-     */
45
-    public function amOnMessageSettingsPage()
46
-    {
47
-        $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl());
48
-    }
49
-
50
-
51
-    public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email')
52
-    {
53
-        $this->actor()->dragAndDrop(
54
-            MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug),
55
-            MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR
56
-        );
57
-    }
58
-
59
-
60
-    /**
61
-     * Assumes you are already on the list table page that has the ui for editing the template.
62
-     * @param string $message_type_slug
63
-     * @param string $context [optional] if you want to click directly to the given context in the editor
64
-     */
65
-    public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '')
66
-    {
67
-        $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context));
68
-    }
69
-
70
-
71
-    /**
72
-     * Use this action to verify that the count for the given text in the specified field is as expected.  For example
73
-     * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column.
74
-     *
75
-     * @param int    $expected_occurence_count
76
-     * @param string $text_to_check_for
77
-     * @param string $field
78
-     * @param string $message_type_label
79
-     * @param string $message_status
80
-     * @param string $messenger
81
-     * @param string $context
82
-     */
83
-    public function verifyMatchingCountofTextInMessageActivityListTableFor(
84
-        $expected_occurence_count,
85
-        $text_to_check_for,
86
-        $field,
87
-        $message_type_label,
88
-        $message_status = MessagesPage::MESSAGE_STATUS_SENT,
89
-        $messenger = 'Email',
90
-        $context = 'Event Admin'
91
-    ) {
92
-        $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor(
93
-            $field,
94
-            $message_type_label,
95
-            $message_status,
96
-            $messenger,
97
-            $context,
98
-            $text_to_check_for,
99
-            0
100
-        ));
101
-        $actual_count = count($elements);
102
-        $this->actor()->assertEquals(
103
-            $expected_occurence_count,
104
-            $actual_count,
105
-            sprintf(
106
-                'Expected %s of the %s text for the %s field but there were actually %s counted.',
107
-                $expected_occurence_count,
108
-                $text_to_check_for,
109
-                $field,
110
-                $actual_count
111
-            )
112
-        );
113
-    }
114
-
115
-
116
-    /**
117
-     * This will create a custom message template for the given messenger and message type from the context of the
118
-     * default (global) message template list table.
119
-     * Also takes care of verifying the template was created.
120
-     * @param string $message_type_label
121
-     * @param string $messenger_label
122
-     */
123
-    public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label)
124
-    {
125
-        $this->amOnDefaultMessageTemplateListTablePage();
126
-        $this->actor()->click(
127
-            MessagesPage::createCustomButtonForMessageTypeAndMessenger(
128
-                $message_type_label,
129
-                $messenger_label
130
-            )
131
-        );
132
-        $this->actor()->seeInField('#title', 'New Custom Template');
133
-    }
134
-
135
-
136
-    /**
137
-     * This switches the context of the current messages template to the given reference.
138
-     * @param string $context_reference  This should be the visible label for the option.
139
-     */
140
-    public function switchContextTo($context_reference)
141
-    {
142
-        $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference);
143
-        $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR);
144
-        $this->actor()->waitForText($context_reference, 10, 'h1');
145
-    }
146
-
147
-
148
-    /**
149
-     * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after
150
-     * toggling.
151
-     *
152
-     * @param string $context_string           What context is being switched (used for the expected state text)
153
-     * @param bool   $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive
154
-     *                                         (false)
155
-     */
156
-    public function toggleContextState($context_string, $expected_state_is_active = true)
157
-    {
158
-        $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE);
159
-        if ($expected_state_is_active) {
160
-            $this->actor()->waitForText("The template for $context_string is currently active.");
161
-        } else {
162
-            $this->actor()->waitForText("The template for $context_string is currently inactive");
163
-        }
164
-    }
165
-
166
-
167
-    /**
168
-     * Triggers saving the message template.
169
-     * @param bool $and_close   Use to indicate to click the Save and Close button.
170
-     */
171
-    public function saveMessageTemplate($and_close = false)
172
-    {
173
-        $this->actor()->scrollTo(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR);
174
-        if ($and_close) {
175
-            $this->actor()->click('Save and Close');
176
-        } else {
177
-            $this->actor()->click('Save');
178
-        }
179
-        $this->actor()->waitForText('successfully updated');
180
-    }
181
-
182
-
183
-    /**
184
-     * This takes care of clicking the View Message icon for the given parameters.
185
-     * Assumes you are already viewing the messages activity list table.
186
-     * @param        $message_type_label
187
-     * @param        $message_status
188
-     * @param string $messenger
189
-     * @param string $context
190
-     * @param int    $number_in_set
191
-     */
192
-    public function viewMessageInMessagesListTableFor(
193
-        $message_type_label,
194
-        $message_status = MessagesPage::MESSAGE_STATUS_SENT,
195
-        $messenger = 'Email',
196
-        $context = 'Event Admin',
197
-        $number_in_set = 1
198
-    ) {
199
-        $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor(
200
-            $message_type_label,
201
-            $message_status,
202
-            $messenger,
203
-            $context,
204
-            $number_in_set
205
-        ));
206
-    }
207
-
208
-
209
-    /**
210
-     * Takes care of deleting a message matching the given parameters via the message activity list table.
211
-     * Assumes you are already viewing the messages activity list table.
212
-     * @param        $message_type_label
213
-     * @param        $message_status
214
-     * @param string $messenger
215
-     * @param string $context
216
-     * @param int    $number_in_set
217
-     */
218
-    public function deleteMessageInMessagesListTableFor(
219
-        $message_type_label,
220
-        $message_status = MessagesPage::MESSAGE_STATUS_SENT,
221
-        $messenger = 'Email',
222
-        $context = 'Event Admin',
223
-        $number_in_set = 1
224
-    ) {
225
-        $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor(
226
-            $message_type_label,
227
-            $message_status,
228
-            $messenger,
229
-            $context,
230
-            $number_in_set
231
-        );
232
-        $cell_selector = MessagesPage::messagesActivityListTableCellSelectorFor(
233
-            'to',
234
-            $message_type_label,
235
-            $message_status,
236
-            $messenger,
237
-            $context,
238
-            '',
239
-            $number_in_set
240
-        );
241
-        $this->actor()->scrollTo($cell_selector, 0, -30);
242
-        $this->actor()->moveMouseOver(
243
-            $cell_selector,
244
-            5,
245
-            5
246
-        );
247
-        $this->actor()->waitForElementVisible(
248
-            $delete_action_selector
249
-        );
250
-        $this->actor()->click(
251
-            $delete_action_selector
252
-        );
253
-        $this->actor()->waitForText('successfully deleted', 20);
254
-    }
255
-
256
-
257
-    /**
258
-     * Assuming you have already triggered the view modal for a single message from the context of the message activity
259
-     * list table, this will take care of validating the given text is in that window.
260
-     * @param string $text_to_view
261
-     */
262
-    public function seeTextInViewMessageModal($text_to_view, $should_not_see = false)
263
-    {
264
-        $this->actor()->wait(2);
265
-        $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content');
266
-        $this->actor()->switchToIframe('message-view-window');
267
-        $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view);
268
-        $this->actor()->switchToIframe();
269
-    }
270
-
271
-
272
-    /**
273
-     * This returns the value for the link at the given selector in the message modal.
274
-     * @param string $selector (any selector string accepted by WebDriver)
275
-     */
276
-    public function observeLinkAtSelectorInMessageModal($selector)
277
-    {
278
-        $this->actor()->wait(2);
279
-        $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content');
280
-        $this->actor()->switchToIframe('message-view-window');
281
-        $link = $this->actor()->observeLinkUrlAt($selector);
282
-        $this->actor()->switchToIframe();
283
-        return $link;
284
-    }
285
-
286
-
287
-    /**
288
-     * Assuming you have already triggered the view modal for a single message from the context of the message activity
289
-     * list table, this will take care of validating the given text is NOT that window.
290
-     * @param string $text_to_view
291
-     */
292
-    public function dontSeeTextInViewMessageModal($text_to_view)
293
-    {
294
-        $this->seeTextInViewMessageModal($text_to_view, true);
295
-    }
296
-
297
-
298
-    public function dismissMessageModal()
299
-    {
300
-        $this->actor()->executeJs('window.dialogHelper.closeModal()');
301
-        //this is needed otherwise phantom js gets stuck in the wrong context and any future element events will fail.
302
-        $this->actor()->scrollTo('form#EE_Message_List_Table-table-frm');
303
-        $this->actor()->click('form#EE_Message_List_Table-table-frm');
304
-    }
13
+	/**
14
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
15
+	 *                                  a string.
16
+	 */
17
+	public function amOnMessagesActivityListTablePage($additional_params = '')
18
+	{
19
+		$this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params));
20
+	}
21
+
22
+	/**
23
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
24
+	 *                                  a string.
25
+	 */
26
+	public function amOnDefaultMessageTemplateListTablePage($additional_params = '')
27
+	{
28
+		$this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params));
29
+	}
30
+
31
+
32
+	/**
33
+	 * @param string $additional_params Any additional request parameters for the generated url should be included as
34
+	 *                                  a string.
35
+	 */
36
+	public function amOnCustomMessageTemplateListTablePage($additional_params = '')
37
+	{
38
+		$this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params));
39
+	}
40
+
41
+
42
+	/**
43
+	 * Directs to message settings page
44
+	 */
45
+	public function amOnMessageSettingsPage()
46
+	{
47
+		$this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl());
48
+	}
49
+
50
+
51
+	public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email')
52
+	{
53
+		$this->actor()->dragAndDrop(
54
+			MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug),
55
+			MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR
56
+		);
57
+	}
58
+
59
+
60
+	/**
61
+	 * Assumes you are already on the list table page that has the ui for editing the template.
62
+	 * @param string $message_type_slug
63
+	 * @param string $context [optional] if you want to click directly to the given context in the editor
64
+	 */
65
+	public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '')
66
+	{
67
+		$this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context));
68
+	}
69
+
70
+
71
+	/**
72
+	 * Use this action to verify that the count for the given text in the specified field is as expected.  For example
73
+	 * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column.
74
+	 *
75
+	 * @param int    $expected_occurence_count
76
+	 * @param string $text_to_check_for
77
+	 * @param string $field
78
+	 * @param string $message_type_label
79
+	 * @param string $message_status
80
+	 * @param string $messenger
81
+	 * @param string $context
82
+	 */
83
+	public function verifyMatchingCountofTextInMessageActivityListTableFor(
84
+		$expected_occurence_count,
85
+		$text_to_check_for,
86
+		$field,
87
+		$message_type_label,
88
+		$message_status = MessagesPage::MESSAGE_STATUS_SENT,
89
+		$messenger = 'Email',
90
+		$context = 'Event Admin'
91
+	) {
92
+		$elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor(
93
+			$field,
94
+			$message_type_label,
95
+			$message_status,
96
+			$messenger,
97
+			$context,
98
+			$text_to_check_for,
99
+			0
100
+		));
101
+		$actual_count = count($elements);
102
+		$this->actor()->assertEquals(
103
+			$expected_occurence_count,
104
+			$actual_count,
105
+			sprintf(
106
+				'Expected %s of the %s text for the %s field but there were actually %s counted.',
107
+				$expected_occurence_count,
108
+				$text_to_check_for,
109
+				$field,
110
+				$actual_count
111
+			)
112
+		);
113
+	}
114
+
115
+
116
+	/**
117
+	 * This will create a custom message template for the given messenger and message type from the context of the
118
+	 * default (global) message template list table.
119
+	 * Also takes care of verifying the template was created.
120
+	 * @param string $message_type_label
121
+	 * @param string $messenger_label
122
+	 */
123
+	public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label)
124
+	{
125
+		$this->amOnDefaultMessageTemplateListTablePage();
126
+		$this->actor()->click(
127
+			MessagesPage::createCustomButtonForMessageTypeAndMessenger(
128
+				$message_type_label,
129
+				$messenger_label
130
+			)
131
+		);
132
+		$this->actor()->seeInField('#title', 'New Custom Template');
133
+	}
134
+
135
+
136
+	/**
137
+	 * This switches the context of the current messages template to the given reference.
138
+	 * @param string $context_reference  This should be the visible label for the option.
139
+	 */
140
+	public function switchContextTo($context_reference)
141
+	{
142
+		$this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference);
143
+		$this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR);
144
+		$this->actor()->waitForText($context_reference, 10, 'h1');
145
+	}
146
+
147
+
148
+	/**
149
+	 * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after
150
+	 * toggling.
151
+	 *
152
+	 * @param string $context_string           What context is being switched (used for the expected state text)
153
+	 * @param bool   $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive
154
+	 *                                         (false)
155
+	 */
156
+	public function toggleContextState($context_string, $expected_state_is_active = true)
157
+	{
158
+		$this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE);
159
+		if ($expected_state_is_active) {
160
+			$this->actor()->waitForText("The template for $context_string is currently active.");
161
+		} else {
162
+			$this->actor()->waitForText("The template for $context_string is currently inactive");
163
+		}
164
+	}
165
+
166
+
167
+	/**
168
+	 * Triggers saving the message template.
169
+	 * @param bool $and_close   Use to indicate to click the Save and Close button.
170
+	 */
171
+	public function saveMessageTemplate($and_close = false)
172
+	{
173
+		$this->actor()->scrollTo(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR);
174
+		if ($and_close) {
175
+			$this->actor()->click('Save and Close');
176
+		} else {
177
+			$this->actor()->click('Save');
178
+		}
179
+		$this->actor()->waitForText('successfully updated');
180
+	}
181
+
182
+
183
+	/**
184
+	 * This takes care of clicking the View Message icon for the given parameters.
185
+	 * Assumes you are already viewing the messages activity list table.
186
+	 * @param        $message_type_label
187
+	 * @param        $message_status
188
+	 * @param string $messenger
189
+	 * @param string $context
190
+	 * @param int    $number_in_set
191
+	 */
192
+	public function viewMessageInMessagesListTableFor(
193
+		$message_type_label,
194
+		$message_status = MessagesPage::MESSAGE_STATUS_SENT,
195
+		$messenger = 'Email',
196
+		$context = 'Event Admin',
197
+		$number_in_set = 1
198
+	) {
199
+		$this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor(
200
+			$message_type_label,
201
+			$message_status,
202
+			$messenger,
203
+			$context,
204
+			$number_in_set
205
+		));
206
+	}
207
+
208
+
209
+	/**
210
+	 * Takes care of deleting a message matching the given parameters via the message activity list table.
211
+	 * Assumes you are already viewing the messages activity list table.
212
+	 * @param        $message_type_label
213
+	 * @param        $message_status
214
+	 * @param string $messenger
215
+	 * @param string $context
216
+	 * @param int    $number_in_set
217
+	 */
218
+	public function deleteMessageInMessagesListTableFor(
219
+		$message_type_label,
220
+		$message_status = MessagesPage::MESSAGE_STATUS_SENT,
221
+		$messenger = 'Email',
222
+		$context = 'Event Admin',
223
+		$number_in_set = 1
224
+	) {
225
+		$delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor(
226
+			$message_type_label,
227
+			$message_status,
228
+			$messenger,
229
+			$context,
230
+			$number_in_set
231
+		);
232
+		$cell_selector = MessagesPage::messagesActivityListTableCellSelectorFor(
233
+			'to',
234
+			$message_type_label,
235
+			$message_status,
236
+			$messenger,
237
+			$context,
238
+			'',
239
+			$number_in_set
240
+		);
241
+		$this->actor()->scrollTo($cell_selector, 0, -30);
242
+		$this->actor()->moveMouseOver(
243
+			$cell_selector,
244
+			5,
245
+			5
246
+		);
247
+		$this->actor()->waitForElementVisible(
248
+			$delete_action_selector
249
+		);
250
+		$this->actor()->click(
251
+			$delete_action_selector
252
+		);
253
+		$this->actor()->waitForText('successfully deleted', 20);
254
+	}
255
+
256
+
257
+	/**
258
+	 * Assuming you have already triggered the view modal for a single message from the context of the message activity
259
+	 * list table, this will take care of validating the given text is in that window.
260
+	 * @param string $text_to_view
261
+	 */
262
+	public function seeTextInViewMessageModal($text_to_view, $should_not_see = false)
263
+	{
264
+		$this->actor()->wait(2);
265
+		$this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content');
266
+		$this->actor()->switchToIframe('message-view-window');
267
+		$should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view);
268
+		$this->actor()->switchToIframe();
269
+	}
270
+
271
+
272
+	/**
273
+	 * This returns the value for the link at the given selector in the message modal.
274
+	 * @param string $selector (any selector string accepted by WebDriver)
275
+	 */
276
+	public function observeLinkAtSelectorInMessageModal($selector)
277
+	{
278
+		$this->actor()->wait(2);
279
+		$this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content');
280
+		$this->actor()->switchToIframe('message-view-window');
281
+		$link = $this->actor()->observeLinkUrlAt($selector);
282
+		$this->actor()->switchToIframe();
283
+		return $link;
284
+	}
285
+
286
+
287
+	/**
288
+	 * Assuming you have already triggered the view modal for a single message from the context of the message activity
289
+	 * list table, this will take care of validating the given text is NOT that window.
290
+	 * @param string $text_to_view
291
+	 */
292
+	public function dontSeeTextInViewMessageModal($text_to_view)
293
+	{
294
+		$this->seeTextInViewMessageModal($text_to_view, true);
295
+	}
296
+
297
+
298
+	public function dismissMessageModal()
299
+	{
300
+		$this->actor()->executeJs('window.dialogHelper.closeModal()');
301
+		//this is needed otherwise phantom js gets stuck in the wrong context and any future element events will fail.
302
+		$this->actor()->scrollTo('form#EE_Message_List_Table-table-frm');
303
+		$this->actor()->click('form#EE_Message_List_Table-table-frm');
304
+	}
305 305
 }
Please login to merge, or discard this patch.