Completed
Branch FET-10619-money-entity (c56734)
by
unknown
157:04 queued 143:03
created
core/services/currency/DefaultCalculator.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -21,82 +21,82 @@
 block discarded – undo
21 21
 
22 22
 
23 23
 
24
-    /**
25
-     * returns true if a calculator is supported as determined by loaded server extensions
26
-     *
27
-     * @return bool
28
-     */
29
-    public function isSupported()
30
-    {
31
-        return true;
32
-    }
33
-
34
-
35
-
36
-    /**
37
-     * adds the supplied Money amount to this Money amount
38
-     * and returns a new Money object
39
-     *
40
-     * @param float|int|string $amount
41
-     * @param float|int|string $amount_to_add
42
-     * @return string
43
-     */
44
-    public function add($amount, $amount_to_add)
45
-    {
46
-        return (string) ($amount + $amount_to_add);
47
-    }
48
-
49
-
50
-
51
-    /**
52
-     * subtracts the supplied Money amount from this Money amount
53
-     * and returns a new Money object
54
-     *
55
-     * @param float|int|string $amount
56
-     * @param float|int|string $amount_to_subtract
57
-     * @return string
58
-     */
59
-    public function subtract($amount, $amount_to_subtract)
60
-    {
61
-        return (string) ($amount - $amount_to_subtract);
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * multiplies this Money amount by the supplied $multiplier
68
-     * and returns a new Money object
69
-     *
70
-     * @param float|int|string $amount
71
-     * @param float|int|string $multiplier
72
-     * @param int              $precision
73
-     * @param int              $rounding_mode
74
-     * @return string
75
-     * @throws InvalidArgumentException
76
-     */
77
-    public function multiply($amount, $multiplier, $precision = 3, $rounding_mode = Calculator::ROUND_HALF_UP)
78
-    {
79
-        return $this->round(($amount * $multiplier), $precision, $rounding_mode);
80
-    }
81
-
82
-
83
-
84
-    /**
85
-     * divides this Money amount by the supplied $divisor
86
-     * and returns a new Money object
87
-     *
88
-     * @param float|int|string $amount
89
-     * @param float|int|string $divisor
90
-     * @param int              $precision
91
-     * @param int              $rounding_mode
92
-     * @return string
93
-     * @throws InvalidArgumentException
94
-     */
95
-    public function divide($amount, $divisor, $precision = 3, $rounding_mode = Calculator::ROUND_HALF_UP)
96
-    {
97
-        $this->validateDivisor($divisor);
98
-        return $this->round(($amount / $divisor), $precision, $rounding_mode);
99
-    }
24
+	/**
25
+	 * returns true if a calculator is supported as determined by loaded server extensions
26
+	 *
27
+	 * @return bool
28
+	 */
29
+	public function isSupported()
30
+	{
31
+		return true;
32
+	}
33
+
34
+
35
+
36
+	/**
37
+	 * adds the supplied Money amount to this Money amount
38
+	 * and returns a new Money object
39
+	 *
40
+	 * @param float|int|string $amount
41
+	 * @param float|int|string $amount_to_add
42
+	 * @return string
43
+	 */
44
+	public function add($amount, $amount_to_add)
45
+	{
46
+		return (string) ($amount + $amount_to_add);
47
+	}
48
+
49
+
50
+
51
+	/**
52
+	 * subtracts the supplied Money amount from this Money amount
53
+	 * and returns a new Money object
54
+	 *
55
+	 * @param float|int|string $amount
56
+	 * @param float|int|string $amount_to_subtract
57
+	 * @return string
58
+	 */
59
+	public function subtract($amount, $amount_to_subtract)
60
+	{
61
+		return (string) ($amount - $amount_to_subtract);
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * multiplies this Money amount by the supplied $multiplier
68
+	 * and returns a new Money object
69
+	 *
70
+	 * @param float|int|string $amount
71
+	 * @param float|int|string $multiplier
72
+	 * @param int              $precision
73
+	 * @param int              $rounding_mode
74
+	 * @return string
75
+	 * @throws InvalidArgumentException
76
+	 */
77
+	public function multiply($amount, $multiplier, $precision = 3, $rounding_mode = Calculator::ROUND_HALF_UP)
78
+	{
79
+		return $this->round(($amount * $multiplier), $precision, $rounding_mode);
80
+	}
81
+
82
+
83
+
84
+	/**
85
+	 * divides this Money amount by the supplied $divisor
86
+	 * and returns a new Money object
87
+	 *
88
+	 * @param float|int|string $amount
89
+	 * @param float|int|string $divisor
90
+	 * @param int              $precision
91
+	 * @param int              $rounding_mode
92
+	 * @return string
93
+	 * @throws InvalidArgumentException
94
+	 */
95
+	public function divide($amount, $divisor, $precision = 3, $rounding_mode = Calculator::ROUND_HALF_UP)
96
+	{
97
+		$this->validateDivisor($divisor);
98
+		return $this->round(($amount / $divisor), $precision, $rounding_mode);
99
+	}
100 100
 
101 101
 
102 102
 
Please login to merge, or discard this patch.
core/services/currency/InternationalMoneyFormatter.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -21,15 +21,15 @@
 block discarded – undo
21 21
 
22 22
 
23 23
 
24
-    /**
25
-     * @param string   $money_amount
26
-     * @param Currency $currency
27
-     * @return string
28
-     */
29
-    public function format($money_amount, Currency $currency)
30
-    {
31
-        return $money_amount . ' <span class="currency-code">(' . $currency->code() . ')</span>';
32
-    }
24
+	/**
25
+	 * @param string   $money_amount
26
+	 * @param Currency $currency
27
+	 * @return string
28
+	 */
29
+	public function format($money_amount, Currency $currency)
30
+	{
31
+		return $money_amount . ' <span class="currency-code">(' . $currency->code() . ')</span>';
32
+	}
33 33
 
34 34
 
35 35
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@
 block discarded – undo
28 28
      */
29 29
     public function format($money_amount, Currency $currency)
30 30
     {
31
-        return $money_amount . ' <span class="currency-code">(' . $currency->code() . ')</span>';
31
+        return $money_amount.' <span class="currency-code">('.$currency->code().')</span>';
32 32
     }
33 33
 
34 34
 
Please login to merge, or discard this patch.
core/entities/Label.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -17,49 +17,49 @@
 block discarded – undo
17 17
 class Label
18 18
 {
19 19
 
20
-    /**
21
-     * @var string $singular
22
-     */
23
-    public $singular;
20
+	/**
21
+	 * @var string $singular
22
+	 */
23
+	public $singular;
24 24
 
25
-    /**
26
-     * @var string $plural
27
-     */
28
-    public $plural;
25
+	/**
26
+	 * @var string $plural
27
+	 */
28
+	public $plural;
29 29
 
30 30
 
31 31
 
32
-    /**
33
-     * Label constructor.
34
-     *
35
-     * @param string $singular
36
-     * @param string $plural
37
-     */
38
-    public function __construct($singular, $plural)
39
-    {
40
-        $this->singular = $singular;
41
-        $this->plural = $plural;
42
-    }
32
+	/**
33
+	 * Label constructor.
34
+	 *
35
+	 * @param string $singular
36
+	 * @param string $plural
37
+	 */
38
+	public function __construct($singular, $plural)
39
+	{
40
+		$this->singular = $singular;
41
+		$this->plural = $plural;
42
+	}
43 43
 
44 44
 
45 45
 
46
-    /**
47
-     * @return string
48
-     */
49
-    public function singular()
50
-    {
51
-        return $this->singular;
52
-    }
46
+	/**
47
+	 * @return string
48
+	 */
49
+	public function singular()
50
+	{
51
+		return $this->singular;
52
+	}
53 53
 
54 54
 
55 55
 
56
-    /**
57
-     * @return string
58
-     */
59
-    public function plural()
60
-    {
61
-        return $this->plural;
62
-    }
56
+	/**
57
+	 * @return string
58
+	 */
59
+	public function plural()
60
+	{
61
+		return $this->plural;
62
+	}
63 63
 
64 64
 
65 65
 
Please login to merge, or discard this patch.
core/entities/money/Currency.php 2 patches
Indentation   +248 added lines, -248 removed lines patch added patch discarded remove patch
@@ -23,260 +23,260 @@
 block discarded – undo
23 23
 class Currency
24 24
 {
25 25
 
26
-    /**
27
-     * eg 'US'
28
-     *
29
-     * @var string $code
30
-     */
31
-    private $code;
32
-
33
-    /**
34
-     * @var Label $label
35
-     */
36
-    private $label;
37
-
38
-    /**
39
-     * currency sign
40
-     *
41
-     * @var string $sign
42
-     * eg '$'
43
-     */
44
-    private $sign;
45
-
46
-    /**
47
-     * Whether the currency sign should come before the number or not
48
-     *
49
-     * @var boolean $sign_b4
50
-     */
51
-    private $sign_b4;
52
-
53
-    /**
54
-     * How many digits should come after the decimal place
55
-     *
56
-     * @var int $decimal_places
57
-     */
58
-    private $decimal_places;
59
-
60
-    /**
61
-     * Symbol to use for decimal mark
62
-     *
63
-     * @var string $decimal_mark
64
-     * eg '.'
65
-     */
66
-    private $decimal_mark;
67
-
68
-    /**
69
-     * Symbol to use for thousands
70
-     *
71
-     * @var string $thousands
72
-     * eg ','
73
-     */
74
-    private $thousands;
75
-
76
-
77
-
78
-    /**
79
-     * Currency constructor.
80
-     *
81
-     * @param string $code
82
-     * @param Label  $label
83
-     * @param string $sign
84
-     * @param bool   $sign_b4
85
-     * @param int    $decimal_places
86
-     * @param string $decimal_mark
87
-     * @param string $thousands
88
-     */
89
-    private function __construct($code, Label $label, $sign, $sign_b4, $decimal_places, $decimal_mark, $thousands)
90
-    {
91
-        $this->code = $code;
92
-        $this->label = $label;
93
-        $this->sign = $sign;
94
-        $this->sign_b4 = $sign_b4;
95
-        $this->decimal_places = $decimal_places;
96
-        $this->decimal_mark = $decimal_mark;
97
-        $this->thousands = $thousands;
98
-    }
99
-
100
-
101
-
102
-    /**
103
-     * returns a Currency object for the supplied country code
104
-     *
105
-     * @param string $CNT_ISO
106
-     * @return Currency
107
-     * @throws InvalidArgumentException
108
-     */
109
-    public static function createFromCountryCode($CNT_ISO)
110
-    {
111
-        /** @var EE_Country $country */
112
-        $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
113
-        if (! $country instanceof EE_Country){
114
-            throw new InvalidArgumentException(
115
-                sprintf(
116
-                    esc_html__(
117
-                        'A valid country could not be found for the "%1$s" country code;',
118
-                        'event_espresso'
119
-                    ),
120
-                    $CNT_ISO
121
-                )
122
-            );
123
-        }
124
-        return new Currency(
125
-            $country->currency_code(),
126
-            new Label(
127
-                $country->currency_name_single(),
128
-                $country->currency_name_plural()
129
-            ),
130
-            $country->currency_sign(),
131
-            $country->currency_sign_before(),
132
-            $country->currency_decimal_places(),
133
-            $country->currency_decimal_mark(),
134
-            $country->currency_thousands_separator()
135
-        );
136
-    }
137
-
138
-
139
-
140
-    /**
141
-     * returns a Currency object for the supplied currency code
142
-     * PLZ NOTE: variations may exist between how different countries display the same currency,
143
-     * so it may be necessary to use Currency::createFromCountryCode() to achieve the desired results
144
-     *
145
-     * @param string $code
146
-     * @return Currency
147
-     * @throws InvalidArgumentException
148
-     * @throws EE_Error
149
-     */
150
-    public static function createFromCode($code)
151
-    {
152
-        /** @var EE_Country $country */
153
-        $country = EEM_Country::instance()->get_one(array(array('CNT_cur_code' => $code)));
154
-        if (! $country instanceof EE_Country) {
155
-            throw new InvalidArgumentException(
156
-                sprintf(
157
-                    esc_html__(
158
-                        'A valid currency could not be found for the "%1$s" currency code;',
159
-                        'event_espresso'
160
-                    ),
161
-                    $code
162
-                )
163
-            );
164
-        }
165
-        return new Currency(
166
-            $country->currency_code(),
167
-            new Label(
168
-                $country->currency_name_single(),
169
-                $country->currency_name_plural()
170
-            ),
171
-            $country->currency_sign(),
172
-            $country->currency_sign_before(),
173
-            $country->currency_decimal_places(),
174
-            $country->currency_decimal_mark(),
175
-            $country->currency_thousands_separator()
176
-        );
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     * returns true if this currency is the same as the supplied currency
183
-     *
184
-     * @param Currency $other
185
-     * @return bool
186
-     */
187
-    public function equals(Currency $other){
188
-        return $this->code() === $other->code();
189
-    }
190
-
191
-
192
-
193
-    /**
194
-     * @return string
195
-     */
196
-    public function code()
197
-    {
198
-        return $this->code;
199
-    }
200
-
201
-
202
-
203
-    /**
204
-     * @return string
205
-     */
206
-    public function name()
207
-    {
208
-        return $this->label->singular();
209
-    }
210
-
211
-
212
-
213
-    /**
214
-     * @return string
215
-     */
216
-    public function plural()
217
-    {
218
-        return $this->label->plural();
219
-    }
220
-
221
-
222
-
223
-    /**
224
-     * @return string
225
-     */
226
-    public function sign()
227
-    {
228
-        return $this->sign;
229
-    }
230
-
231
-
232
-
233
-    /**
234
-     * @return bool
235
-     */
236
-    public function signB4()
237
-    {
238
-        return $this->sign_b4;
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * @return int
245
-     */
246
-    public function decimalPlaces()
247
-    {
248
-        return $this->decimal_places;
249
-    }
250
-
251
-
252
-
253
-    /**
254
-     * @return string
255
-     */
256
-    public function decimalMark()
257
-    {
258
-        return $this->decimal_mark;
259
-    }
26
+	/**
27
+	 * eg 'US'
28
+	 *
29
+	 * @var string $code
30
+	 */
31
+	private $code;
32
+
33
+	/**
34
+	 * @var Label $label
35
+	 */
36
+	private $label;
37
+
38
+	/**
39
+	 * currency sign
40
+	 *
41
+	 * @var string $sign
42
+	 * eg '$'
43
+	 */
44
+	private $sign;
45
+
46
+	/**
47
+	 * Whether the currency sign should come before the number or not
48
+	 *
49
+	 * @var boolean $sign_b4
50
+	 */
51
+	private $sign_b4;
52
+
53
+	/**
54
+	 * How many digits should come after the decimal place
55
+	 *
56
+	 * @var int $decimal_places
57
+	 */
58
+	private $decimal_places;
59
+
60
+	/**
61
+	 * Symbol to use for decimal mark
62
+	 *
63
+	 * @var string $decimal_mark
64
+	 * eg '.'
65
+	 */
66
+	private $decimal_mark;
67
+
68
+	/**
69
+	 * Symbol to use for thousands
70
+	 *
71
+	 * @var string $thousands
72
+	 * eg ','
73
+	 */
74
+	private $thousands;
75
+
76
+
77
+
78
+	/**
79
+	 * Currency constructor.
80
+	 *
81
+	 * @param string $code
82
+	 * @param Label  $label
83
+	 * @param string $sign
84
+	 * @param bool   $sign_b4
85
+	 * @param int    $decimal_places
86
+	 * @param string $decimal_mark
87
+	 * @param string $thousands
88
+	 */
89
+	private function __construct($code, Label $label, $sign, $sign_b4, $decimal_places, $decimal_mark, $thousands)
90
+	{
91
+		$this->code = $code;
92
+		$this->label = $label;
93
+		$this->sign = $sign;
94
+		$this->sign_b4 = $sign_b4;
95
+		$this->decimal_places = $decimal_places;
96
+		$this->decimal_mark = $decimal_mark;
97
+		$this->thousands = $thousands;
98
+	}
99
+
100
+
101
+
102
+	/**
103
+	 * returns a Currency object for the supplied country code
104
+	 *
105
+	 * @param string $CNT_ISO
106
+	 * @return Currency
107
+	 * @throws InvalidArgumentException
108
+	 */
109
+	public static function createFromCountryCode($CNT_ISO)
110
+	{
111
+		/** @var EE_Country $country */
112
+		$country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
113
+		if (! $country instanceof EE_Country){
114
+			throw new InvalidArgumentException(
115
+				sprintf(
116
+					esc_html__(
117
+						'A valid country could not be found for the "%1$s" country code;',
118
+						'event_espresso'
119
+					),
120
+					$CNT_ISO
121
+				)
122
+			);
123
+		}
124
+		return new Currency(
125
+			$country->currency_code(),
126
+			new Label(
127
+				$country->currency_name_single(),
128
+				$country->currency_name_plural()
129
+			),
130
+			$country->currency_sign(),
131
+			$country->currency_sign_before(),
132
+			$country->currency_decimal_places(),
133
+			$country->currency_decimal_mark(),
134
+			$country->currency_thousands_separator()
135
+		);
136
+	}
137
+
138
+
139
+
140
+	/**
141
+	 * returns a Currency object for the supplied currency code
142
+	 * PLZ NOTE: variations may exist between how different countries display the same currency,
143
+	 * so it may be necessary to use Currency::createFromCountryCode() to achieve the desired results
144
+	 *
145
+	 * @param string $code
146
+	 * @return Currency
147
+	 * @throws InvalidArgumentException
148
+	 * @throws EE_Error
149
+	 */
150
+	public static function createFromCode($code)
151
+	{
152
+		/** @var EE_Country $country */
153
+		$country = EEM_Country::instance()->get_one(array(array('CNT_cur_code' => $code)));
154
+		if (! $country instanceof EE_Country) {
155
+			throw new InvalidArgumentException(
156
+				sprintf(
157
+					esc_html__(
158
+						'A valid currency could not be found for the "%1$s" currency code;',
159
+						'event_espresso'
160
+					),
161
+					$code
162
+				)
163
+			);
164
+		}
165
+		return new Currency(
166
+			$country->currency_code(),
167
+			new Label(
168
+				$country->currency_name_single(),
169
+				$country->currency_name_plural()
170
+			),
171
+			$country->currency_sign(),
172
+			$country->currency_sign_before(),
173
+			$country->currency_decimal_places(),
174
+			$country->currency_decimal_mark(),
175
+			$country->currency_thousands_separator()
176
+		);
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 * returns true if this currency is the same as the supplied currency
183
+	 *
184
+	 * @param Currency $other
185
+	 * @return bool
186
+	 */
187
+	public function equals(Currency $other){
188
+		return $this->code() === $other->code();
189
+	}
190
+
191
+
192
+
193
+	/**
194
+	 * @return string
195
+	 */
196
+	public function code()
197
+	{
198
+		return $this->code;
199
+	}
200
+
201
+
202
+
203
+	/**
204
+	 * @return string
205
+	 */
206
+	public function name()
207
+	{
208
+		return $this->label->singular();
209
+	}
210
+
211
+
212
+
213
+	/**
214
+	 * @return string
215
+	 */
216
+	public function plural()
217
+	{
218
+		return $this->label->plural();
219
+	}
220
+
221
+
222
+
223
+	/**
224
+	 * @return string
225
+	 */
226
+	public function sign()
227
+	{
228
+		return $this->sign;
229
+	}
230
+
231
+
232
+
233
+	/**
234
+	 * @return bool
235
+	 */
236
+	public function signB4()
237
+	{
238
+		return $this->sign_b4;
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * @return int
245
+	 */
246
+	public function decimalPlaces()
247
+	{
248
+		return $this->decimal_places;
249
+	}
250
+
251
+
252
+
253
+	/**
254
+	 * @return string
255
+	 */
256
+	public function decimalMark()
257
+	{
258
+		return $this->decimal_mark;
259
+	}
260 260
 
261 261
 
262 262
 
263
-    /**
264
-     * @return string
265
-     */
266
-    public function thousands()
267
-    {
268
-        return $this->thousands;
269
-    }
263
+	/**
264
+	 * @return string
265
+	 */
266
+	public function thousands()
267
+	{
268
+		return $this->thousands;
269
+	}
270 270
 
271 271
 
272 272
 
273
-    /**
274
-     * @return string
275
-     */
276
-    public function __toString()
277
-    {
278
-        return $this->code();
279
-    }
273
+	/**
274
+	 * @return string
275
+	 */
276
+	public function __toString()
277
+	{
278
+		return $this->code();
279
+	}
280 280
 
281 281
 
282 282
 
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
     {
111 111
         /** @var EE_Country $country */
112 112
         $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
113
-        if (! $country instanceof EE_Country){
113
+        if ( ! $country instanceof EE_Country) {
114 114
             throw new InvalidArgumentException(
115 115
                 sprintf(
116 116
                     esc_html__(
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
     {
152 152
         /** @var EE_Country $country */
153 153
         $country = EEM_Country::instance()->get_one(array(array('CNT_cur_code' => $code)));
154
-        if (! $country instanceof EE_Country) {
154
+        if ( ! $country instanceof EE_Country) {
155 155
             throw new InvalidArgumentException(
156 156
                 sprintf(
157 157
                     esc_html__(
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
      * @param Currency $other
185 185
      * @return bool
186 186
      */
187
-    public function equals(Currency $other){
187
+    public function equals(Currency $other) {
188 188
         return $this->code() === $other->code();
189 189
     }
190 190
 
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Transaction_Shortcodes.lib.php 2 patches
Indentation   +604 added lines, -604 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -28,612 +28,612 @@  discard block
 block discarded – undo
28 28
 class EE_Transaction_Shortcodes extends EE_Shortcodes
29 29
 {
30 30
 
31
-    /**
32
-     * @var EE_Payment_Method $_invoice_pm the invoiec payment method for use in invoices etc
33
-     */
34
-    protected $_invoice_pm;
35
-
36
-
37
-
38
-    /**
39
-     * EE_Transaction_Shortcodes constructor.
40
-     */
41
-    public function __construct()
42
-    {
43
-        parent::__construct();
44
-    }
45
-
46
-
47
-
48
-    protected function _init_props()
49
-    {
50
-        $this->label = esc_html__('Transaction Shortcodes', 'event_espresso');
51
-        $this->description = esc_html__('All shortcodes specific to transaction related data', 'event_espresso');
52
-        $this->_shortcodes = array(
53
-            '[TXN_ID]'                          => esc_html__('The transaction id for the purchase.', 'event_espresso'),
54
-            '[PAYMENT_URL]'                     => esc_html__('This is a link to make a payment for the event',
55
-                'event_espresso'),
56
-            '[PAYMENT_LINK_IF_NEEDED_*]'        => esc_html__('This is a special dynamic shortcode that allows one to insert a payment link conditional on there being amount owing on the transaction. Three params are available on this shortcode:',
57
-                    'event_espresso')
58
-                                                   . '<ul>'
59
-                                                   . '<li>'
60
-                                                   . sprintf(esc_html__('%sclass:%s This can be used to indicate css class is given to the containing css element (default is "callout").',
61
-                    'event_espresso'), '<strong>', '</strong>')
62
-                                                   . '</li>'
63
-                                                   . '<li>'
64
-                                                   . sprintf(esc_html__('%scustom_text:%s This should be a sprintf format text string (with %%s for where the hyperlink tags go) that is used for the generated link text (The default is "You can %%smake a payment here »%%s.)',
65
-                    'event_espresso'), '<strong>', '</strong>')
66
-                                                   . '</li>'
67
-                                                   . '<li>'
68
-                                                   . sprintf(esc_html__('%scontainer_tag:%s Use this to indicate what container tag you want surrounding the payment link (default is "p").',
69
-                    'event_espresso'), '<strong>', '</strong>')
70
-                                                   . '</li>'
71
-                                                   . '</ul>',
72
-            '[PAYMENT_DUE_DATE_*]'              => esc_html__('This is a special dynamic shortcode that allows one to output a payment due date.  It will only result in a date shown if there is money owing.  Three parameters are available on this shortcode:',
73
-                    'event_espresso')
74
-                                                   . '<ul>'
75
-                                                   . '<li>'
76
-                                                   . sprintf(esc_html__('%sformat:%s This is used to indicate what format the date is in.  Default is whatever is set as date formats for your website.',
77
-                    'event_espresso'), '<strong>', '</strong>')
78
-                                                   . '</li>'
79
-                                                   . '<li>'
80
-                                                   . sprintf(esc_html__('%sdays_until_due:%s This is the number of days form the transaction creation date that the payment is due.  Defaults to 30.',
81
-                    'event_espresso'), '<strong>', '</strong>')
82
-                                                   . '</li>'
83
-                                                   . '<li>'
84
-                                                   . sprintf(esc_html__('%sprefix_text:%s You can use this to indicate what text will prefix the date string.  Defaults to "Payment in full due by:"',
85
-                    'event_espresso'), '<strong>', '</strong>')
86
-                                                   . '</li>',
87
-            '[INVOICE_LINK]'                    => esc_html__('This is a full html link to the invoice',
88
-                'event_espresso'),
89
-            '[INVOICE_URL]'                     => esc_html__('This is just the url for the invoice', 'event_espresso'),
90
-            '[INVOICE_LOGO_URL]'                => esc_html__('This returns the url for the logo uploaded via the invoice settings page.',
91
-                'event_espresso'),
92
-            '[INVOICE_LOGO]'                    => esc_html__('This returns the logo uploaded via the invoice settings page wrapped in img_tags and with a "logo screen" classes. The image size is also set in the img tags automatically to match the uploaded logo.',
93
-                'event_espresso'),
94
-            '[INVOICE_PAYEE_NAME]'              => esc_html__('This will parse to either: the value of the "Company Name" field in the invoice payment method settings; if that is blank, then the value of the Company Name in the "Your Organization Settings", if that is blank then an empty string.',
95
-                'event_espresso'),
96
-            '[INVOICE_PAYEE_ADDRESS]'           => esc_html__('This will parse to either: the value of the "Company Address" field in the invoice payment method settings; if that is blank, then the value of the Company Address in the "Your Organization Settings", if that is blank then an empty string.',
97
-                'event_espresso'),
98
-            '[INVOICE_PAYMENT_INSTRUCTIONS]'    => esc_html__('This will parse to the value of the "Payment Instructions" field found on the Invoice payment methods settings page',
99
-                'event_espresso'),
100
-            '[INVOICE_PAYEE_EMAIL]'             => esc_html__('This will parse to either: the value of the "Company Email" field in the invoice payment method settings; if that is blank, then the value of the Company Email in the "Your Organization Settings", if that is blank then an empty string.',
101
-                'event_espresso'),
102
-            '[INVOICE_PAYEE_TAX_NUMBER_*]'      => sprintf(esc_html__('This will parse to either: the value of the "Company Tax Number" field in the invoice payment method settings; if that is blank, then the value of the Company Tax Number in the "Your Organization Settings", if that is blank then an empty string. Note this is also a special dynamic shortcode. You can use the "prefix" parameter to indicate what text you want to use as a prefix before this tax number.  It defaults to "VAT/Tax Number:". To change this prefix you do the following format for this shortcode: %1$s[INVOICE_PAYEE_TAX_NUMBER_* prefix="GST:"]%2$s and that will output: GST: 12345t56.  If you have no tax number in your settings, then no prefix will be output either.',
103
-                'event_espresso'), '<code>', '</code>'),
104
-            '[TOTAL_COST]'                      => esc_html__('The total cost for the transaction', 'event_espresso'),
105
-            '[TXN_STATUS]'                      => esc_html__('The transaction status for the transaction.',
106
-                'event_espresso'),
107
-            '[TXN_STATUS_ID]'                   => esc_html__('The ID representing the transaction status as saved in the db.  This tends to be useful for including with css classes for styling certain statuses differently from others.',
108
-                'event_espresso'),
109
-            '[PAYMENT_STATUS]'                  => esc_html__('The transaction status for the transaction. This parses to the same value as the [TXN_STATUS] shortcode and still remains here for legacy support.',
110
-                'event_espresso'),
111
-            '[PAYMENT_GATEWAY]'                 => esc_html__('The payment gateway used for the transaction',
112
-                'event_espresso'),
113
-            '[AMOUNT_PAID]'                     => esc_html__('The amount paid or refunded.  This will only have a value if there was a payment or refund at the time of generating the message.',
114
-                'event_espresso'),
115
-            '[LAST_AMOUNT_PAID]'                => esc_html__('This is the last payment or refund made on the transaction related to the message being generated.',
116
-                'event_espresso'),
117
-            '[TOTAL_AMOUNT_PAID]'               => esc_html__('This parses to the total amount paid over all payments',
118
-                'event_espresso'),
119
-            '[TOTAL_OWING]'                     => esc_html__('The total owing on a transaction with no attributes.',
120
-                'event_espresso'),
121
-            '[TXN_SUBTOTAL]'                    => esc_html__('The subtotal for all txn line items.', 'event_espresso'),
122
-            '[TXN_TAX_SUBTOTAL]'                => esc_html__('The subtotal for all tax line items.', 'event_espresso'),
123
-            '[OWING_STATUS_MESSAGE_*]'          => esc_html__('A dynamic shortcode for adjusting how total owing gets shown. The acceptable attributes on the shortcode are:',
124
-                    'event_espresso')
125
-                                                   . '<p></ul>'
126
-                                                   .
127
-                                                   '<li><strong>still_owing</strong>:'
128
-                                                   . esc_html__('If the transaction is not paid in full, then whatever is set for this attribute is shown (otherwise its just the amount owing). The default is:',
129
-                    'event_espresso')
130
-                                                   . sprintf(esc_html__('%sPlease make a payment.%s', 'event_espresso'),
131
-                    '<a href="[PAYMENT_URL]" class="noPrint">', '</a>')
132
-                                                   . '</li>'
133
-                                                   .
134
-                                                   '<li><strong>none_owing</strong>:'
135
-                                                   . esc_html__('If the transaction is paid in full, then you can indicate how this gets displayed.  Note, that it defaults to just be the total owing.',
136
-                    'event_espresso')
137
-                                                   . '</li></ul></p>',
138
-            '[TXN_TOTAL_TICKETS]'               => esc_html__('The total number of all tickets purchased in a transaction',
139
-                'event_espresso'),
140
-            '[TKT_QTY_PURCHASED]'               => sprintf(esc_html__('The total number of all tickets purchased in a transaction. %1$sNOTE: This shortcode is good to use in the "[TICKET_LIST]" field but has been deprecated from all other contexts in favor of the more explicit [TXN_TOTAL_TICKETS] shortcode.%2$s',
141
-                'event_espresso'), '<strong>', '</strong>'),
142
-            '[TRANSACTION_ADMIN_URL]'           => esc_html__('The url to the admin page for this transaction',
143
-                'event_espresso'),
144
-            '[RECEIPT_URL]'                     => esc_html__('This parses to the generated url for retrieving the receipt for the transaction',
145
-                'event_espresso'),
146
-            '[INVOICE_RECEIPT_SWITCHER_URL]'    => esc_html__('This parses to the url that will switch to the receipt if an invoice is displayed, and switch to the invoice if receipt is displayed. If a message type OTHER than invoice or receipt is displayed then this will just return the url for the invoice. If the related message type is not active  then will parse to an empty string.',
147
-                'event_espresso'),
148
-            '[INVOICE_RECEIPT_SWITCHER_BUTTON]' => sprintf(esc_html__('The same as %1$s[INVOICE_RECEIPT_SWITCHER_URL]%2$s except this returns the html for a button linked to the invoice or receipt.',
149
-                'event_espresso'), '<code>', '</code>'),
150
-        );
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * @access protected
157
-     * @param  string $shortcode the shortcode to be parsed.
158
-     * @return string parsed shortcode
159
-     */
160
-    protected function _parser($shortcode)
161
-    {
162
-        //attempt to get the transaction.  Since this is potentially used in more fields, we may have to look in the _extra_data for the transaction.
163
-        $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
164
-        $transaction = ! $transaction instanceof EE_Transaction
165
-                       && is_array($this->_extra_data)
166
-                       && isset($this->_extra_data['data'])
167
-                       && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->txn
168
-            : $transaction;
169
-        //payment
170
-        $payment = $this->_data->payment instanceof EE_Payment ? $this->_data->payment : null;
171
-        $payment = ! $payment instanceof EE_Payment
172
-                   && is_array($this->_extra_data)
173
-                   && isset($this->_extra_data['data'])
174
-                   && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment
175
-            : $payment;
176
-        if (! $transaction instanceof EE_Transaction) {
177
-            return '';
178
-        }
179
-        switch ($shortcode) {
180
-            case '[TXN_ID]' :
181
-                return $transaction->ID();
182
-                break;
183
-            case '[PAYMENT_URL]' :
184
-                $payment_url = $transaction->payment_overview_url();
185
-                return empty($payment_url) ? esc_html__('http://dummypaymenturlforpreview.com', 'event_espresso')
186
-                    : $payment_url;
187
-                break;
188
-            case '[INVOICE_LINK]' :
189
-                $invoice_url = $transaction->invoice_url();
190
-                $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
191
-                return sprintf(esc_html__('%sClick here for Invoice%s', 'event_espresso'),
192
-                    '<a href="' . $invoice_url . '">', '</a>');
193
-                break; /**/
194
-            case '[INVOICE_URL]' :
195
-                $invoice_url = $transaction->invoice_url();
196
-                return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
197
-                break;
198
-            case '[INVOICE_LOGO_URL]' :
199
-                return $this->_get_invoice_logo();
200
-                break;
201
-            case '[INVOICE_LOGO]' :
202
-                return $this->_get_invoice_logo(true);
203
-                break;
204
-            case '[INVOICE_PAYEE_NAME]' :
205
-                return $this->_get_invoice_payee_name();
206
-                break;
207
-            case '[INVOICE_PAYEE_ADDRESS]' :
208
-                return $this->_get_invoice_payee_address();
209
-                break;
210
-            case '[INVOICE_PAYMENT_INSTRUCTIONS]' :
211
-                return $this->_get_invoice_payment_instructions();
212
-                break;
213
-            case '[INVOICE_PAYEE_EMAIL]' :
214
-                return $this->_get_invoice_payee_email();
215
-                break;
216
-            case '[TOTAL_COST]' :
217
-                $total = $transaction->total();
218
-                return ! empty($total) ? EEH_Template::format_currency($total) : '';
219
-                break;
220
-            case '[PAYMENT_STATUS]' :
221
-                $status = $transaction->pretty_status();
222
-                return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso');
223
-                break; /**/
224
-            // note the [payment_status] shortcode is kind of misleading because payment status might be different from txn status so I'm adding this here for clarity.
225
-            case '[TXN_STATUS]':
226
-                $status = $transaction->pretty_status();
227
-                return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso');
228
-                break;
229
-            case '[TXN_STATUS_ID]' :
230
-                return $transaction->status_ID();
231
-                break;
232
-            case '[PAYMENT_GATEWAY]' :
233
-                return $this->_get_payment_gateway($transaction);
234
-                break;
235
-            case '[AMOUNT_PAID]' :
236
-                return $payment instanceof EE_Payment
237
-                    ? EEH_Template::format_currency($payment->amount())
238
-                    : EEH_Template::format_currency(0);
239
-                break;
240
-            case '[LAST_AMOUNT_PAID]' :
241
-                $last_payment = $transaction->last_payment();
242
-                return $last_payment instanceof EE_Payment
243
-                    ? EEH_Template::format_currency($last_payment->amount())
244
-                    : EEH_Template::format_currency(0);
245
-            case '[TOTAL_AMOUNT_PAID]' :
246
-                return EEH_Template::format_currency($transaction->paid());
247
-                break;
248
-            case '[TOTAL_OWING]' :
249
-                $total_owing = $transaction->remaining();
250
-                return EEH_Template::format_currency($total_owing);
251
-                break;
252
-            case '[TXN_SUBTOTAL]' :
253
-                return EEH_Template::format_currency($this->_get_subtotal());
254
-                break;
255
-            case '[TXN_TAX_SUBTOTAL]' :
256
-                return EEH_Template::format_currency($this->_get_subtotal(true));
257
-                break;
258
-            case '[TKT_QTY_PURCHASED]' :
259
-            case '[TXN_TOTAL_TICKETS]' :
260
-                return $this->_data->total_ticket_count;
261
-                break;
262
-            case '[TRANSACTION_ADMIN_URL]' :
263
-                require_once EE_CORE . 'admin/EE_Admin_Page.core.php';
264
-                $query_args = array(
265
-                    'page'   => 'espresso_transactions',
266
-                    'action' => 'view_transaction',
267
-                    'TXN_ID' => $transaction->ID(),
268
-                );
269
-                $url = EE_Admin_Page::add_query_args_and_nonce($query_args, admin_url('admin.php'));
270
-                return $url;
271
-                break;
272
-            case '[RECEIPT_URL]' :
273
-                //get primary_registration
274
-                $reg = $this->_data->primary_reg_obj;
275
-                if (! $reg instanceof EE_Registration) {
276
-                    return '';
277
-                }
278
-                return $reg->receipt_url();
279
-                break;
280
-            case '[INVOICE_RECEIPT_SWITCHER_URL]' :
281
-                return $this->_get_invoice_receipt_switcher(false);
282
-                break;
283
-            case '[INVOICE_RECEIPT_SWITCHER_BUTTON]' :
284
-                return $this->_get_invoice_receipt_switcher();
285
-                break;
286
-        }
287
-        if (strpos($shortcode, '[OWING_STATUS_MESSAGE_*') !== false) {
288
-            return $this->_get_custom_total_owing($shortcode);
289
-        }
290
-        if (strpos($shortcode, '[INVOICE_PAYEE_TAX_NUMBER_*') !== false) {
291
-            return $this->_get_invoice_payee_tax_number($shortcode);
292
-        }
293
-        if (strpos($shortcode, '[PAYMENT_LINK_IF_NEEDED_*') !== false) {
294
-            return $this->_get_payment_link_if_needed($shortcode);
295
-        }
296
-        if (strpos($shortcode, '[PAYMENT_DUE_DATE_*') !== false) {
297
-            return $this->_get_payment_due_date($shortcode, $transaction);
298
-        }
299
-        return '';
300
-    }
301
-
302
-
303
-
304
-    /**
305
-     * parser for the [OWING_STATUS_MESSAGE_*] attribute type shortcode
306
-     *
307
-     * @since 4.5.0
308
-     * @param string $shortcode the incoming shortcode
309
-     * @return string parsed.
310
-     */
311
-    private function _get_custom_total_owing($shortcode)
312
-    {
313
-        $valid_shortcodes = array('transaction');
314
-        $attrs = $this->_get_shortcode_attrs($shortcode);
315
-        //ensure default is set.
316
-        $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
317
-        $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction
318
-            ? $addressee->txn->remaining() : 0;
319
-        if ($total_owing > 0) {
320
-            $owing_content = ! empty($attrs['still_owing'])
321
-                ? $attrs['still_owing']
322
-                : sprintf(esc_html__('%sPlease make a payment.%s', 'event_espresso'),
323
-                    '<a href="[PAYMENT_URL]" class="noPrint">', '</a>');
324
-            $owing_content = $this->_shortcode_helper->parse_message_template($owing_content, $addressee,
325
-                $valid_shortcodes, $this->_message_type, $this->_messenger, $this->_message);
326
-        } else {
327
-            $owing_content = ! empty($attrs['none_owing']) ? $attrs['none_owing'] : '';
328
-        }
329
-        return $owing_content;
330
-    }
331
-
332
-
333
-
334
-    /**
335
-     * @param EE_Transaction $transaction
336
-     * @return string
337
-     */
338
-    private function _get_payment_gateway($transaction)
339
-    {
340
-        $pm = $this->_get_invoice_payment_method($transaction);
341
-        return $pm instanceof EE_Payment_Method ? $pm->name() : '';
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     * This retrieves a logo to be used for the invoice from whatever is set on the invoice logo settings page.  If its
348
-     * not present then the organization logo is used if its found (set on the organization settings page).
349
-     *
350
-     * @since 4.5.0
351
-     * @param bool $img_tags TRUE means to return with the img tag wrappers.  False just returns the url to the image.
352
-     * @return string url or html
353
-     */
354
-    private function _get_invoice_logo($img_tags = false)
355
-    {
356
-        //try to get the invoice payment method's logo for this transaction image first
357
-        $pm = $this->_get_invoice_payment_method();
358
-        if ($pm instanceof EE_Payment_Method) {
359
-            $invoice_logo_url = $pm->get_extra_meta('pdf_logo_image', true);
360
-        } else {
361
-            $invoice_logo_url = null;
362
-        }
363
-        if (empty($invoice_logo_url)) {
364
-            $invoice_logo_url = EE_Registry::instance()->CFG->organization->logo_url;
365
-        }
366
-        if (empty($invoice_logo_url)) {
367
-            return '';
368
-        }
369
-        if (! $img_tags) {
370
-            return $invoice_logo_url;
371
-        }
372
-        //image tags have been requested.
373
-        $image_size = getimagesize($invoice_logo_url);
374
-        //if image is wider than 300px, set the width to 300
375
-        if ($image_size[0] > 300) {
376
-            $image_width = 300;
377
-        } else {
378
-            $image_width = $image_size[0];
379
-        }
380
-        return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />';
381
-    }
382
-
383
-
384
-
385
-    /**
386
-     * Used to retrieve the appropriate content for the invoice payee name shortcode
387
-     *
388
-     * @since 4.5.0
389
-     * @return string
390
-     */
391
-    private function _get_invoice_payee_name()
392
-    {
393
-        $payee_name = null;
394
-        $pm = $this->_get_invoice_payment_method();
395
-        if ($pm instanceof EE_Payment_Method) {
396
-            $payee_name = $pm->get_extra_meta('pdf_payee_name', true);
397
-        }
398
-        $payee_name = empty($payee_name) ? EE_Registry::instance()->CFG->organization->get_pretty('name') : $payee_name;
399
-        return $payee_name;
400
-    }
401
-
402
-
403
-
404
-    /**
405
-     * gets the default invoice payment method, but has a filter so it can be overridden
406
-     *
407
-     * @return \EE_Payment_Method|null
408
-     */
409
-    private function _get_invoice_payment_method()
410
-    {
411
-        if (! $this->_invoice_pm instanceof EE_Payment_Method) {
412
-            $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
413
-            $transaction = ! $transaction instanceof EE_Transaction
414
-                           && is_array($this->_extra_data)
415
-                           && isset($this->_extra_data['data'])
416
-                           && $this->_extra_data['data'] instanceof EE_Messages_Addressee
417
-                ? $this->_extra_data['data']->txn : $transaction;
418
-            //get the invoice payment method, and remember it for the next call too
419
-            $this->_invoice_pm = apply_filters('FHEE__EE_Transaction_Shortcodes__get_payment_method__default',
420
-                EEM_Payment_Method::instance()->get_one_of_type('Invoice'), $transaction);
421
-        }
422
-        return $this->_invoice_pm;
423
-    }
424
-
425
-
426
-
427
-    /**
428
-     * Used to retrieve the appropriate content for the invoice payee email shortcode
429
-     *
430
-     * @since 4.5.0
431
-     * @return string
432
-     */
433
-    private function _get_invoice_payee_email()
434
-    {
435
-        $payee_email = null;
436
-        $pm = $this->_get_invoice_payment_method();
437
-        if ($pm instanceof EE_Payment_Method) {
438
-            $payee_email = $pm->get_extra_meta('pdf_payee_email', true);
439
-        }
440
-        $payee_email = empty($payee_email) ? EE_Registry::instance()->CFG->organization->get_pretty('email')
441
-            : $payee_email;
442
-        return $payee_email;
443
-    }
444
-
445
-
446
-
447
-    /**
448
-     * Used to retrieve the appropriate content for the invoice payee tax number shortcode
449
-     *
450
-     * @since 4.5.0
451
-     * @param string $shortcode
452
-     * @return string
453
-     */
454
-    private function _get_invoice_payee_tax_number($shortcode)
455
-    {
456
-        $payee_tax_number = null;
457
-        $pm = $this->_get_invoice_payment_method();
458
-        if ($pm instanceof EE_Payment_Method) {
459
-            $payee_tax_number = $pm->get_extra_meta('pdf_payee_tax_number', true);
460
-        }
461
-        $payee_tax_number = empty($payee_tax_number) ? EE_Registry::instance()->CFG->organization->vat
462
-            : $payee_tax_number;
463
-        if (empty($payee_tax_number)) {
464
-            return '';
465
-        }
466
-        //any attributes?
467
-        $attrs = $this->_get_shortcode_attrs($shortcode);
468
-        //prefix?
469
-        $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso');
470
-        return $prefix . $payee_tax_number;
471
-    }
472
-
473
-
474
-
475
-    /**
476
-     * Used to retrieve the appropriate content for the invoice payee address shortcode.
477
-     *
478
-     * @since 4.5.0
479
-     * @return string
480
-     */
481
-    private function _get_invoice_payee_address()
482
-    {
483
-        $payee_address = null;
484
-        $pm = $this->_get_invoice_payment_method();
485
-        if ($pm instanceof EE_Payment_Method) {
486
-            $payee_address = $pm->get_extra_meta('pdf_payee_address', true);
487
-        }
488
-        if (empty($payee_address)) {
489
-            $organization = EE_Registry::instance()->CFG->organization;
490
-            $payee_address = $organization->get_pretty('address_1') . '<br>';
491
-            $payee_address .= ! empty($organization->address_2) ? $organization->get_pretty('address_2') . '<br>' : '';
492
-            $payee_address .= $organization->get_pretty('city') . '<br>';
493
-            //state
494
-            $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID);
495
-            $payee_address .= $state instanceof EE_State ? $state->name() : '';
496
-            //Country
497
-            $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : '';
498
-            $payee_address .= ! empty($organization->zip) ? $organization->zip : '';
499
-        }
500
-        return $payee_address;
501
-    }
502
-
503
-
504
-
505
-    /**
506
-     * Used to retrieve the appropriate content for the invoice payment instructions shortcode.
507
-     *
508
-     * @since 4.5.0
509
-     * @return string
510
-     */
511
-    private function _get_invoice_payment_instructions()
512
-    {
513
-        $instructions = null;
514
-        $pm = $this->_get_invoice_payment_method();
515
-        return ($pm instanceof EE_Payment_Method) ? $pm->get_extra_meta('pdf_instructions', true) : '';
516
-    }
517
-
518
-
519
-
520
-    /**
521
-     * get invoice/receipt switch button or url.
522
-     *
523
-     * @param bool $button true (default) returns the html for a button, false just returns the url.
524
-     * @return string
525
-     */
526
-    protected function _get_invoice_receipt_switcher($button = true)
527
-    {
528
-        $reg = $this->_data->primary_reg_obj;
529
-        $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : '';
530
-        if (! $reg instanceof EE_Registration || empty($message_type)) {
531
-            return '';
532
-        }
533
-        $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false;
534
-        $switch_to_label = $switch_to_invoice && ! $message_type instanceof EE_Receipt_message_type
535
-            ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso');
536
-        $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label;
537
-        $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url();
538
-        if (! $button) {
539
-            return $switch_to_url;
540
-        }
541
-        if (! empty($switch_to_url)) {
542
-            return '
31
+	/**
32
+	 * @var EE_Payment_Method $_invoice_pm the invoiec payment method for use in invoices etc
33
+	 */
34
+	protected $_invoice_pm;
35
+
36
+
37
+
38
+	/**
39
+	 * EE_Transaction_Shortcodes constructor.
40
+	 */
41
+	public function __construct()
42
+	{
43
+		parent::__construct();
44
+	}
45
+
46
+
47
+
48
+	protected function _init_props()
49
+	{
50
+		$this->label = esc_html__('Transaction Shortcodes', 'event_espresso');
51
+		$this->description = esc_html__('All shortcodes specific to transaction related data', 'event_espresso');
52
+		$this->_shortcodes = array(
53
+			'[TXN_ID]'                          => esc_html__('The transaction id for the purchase.', 'event_espresso'),
54
+			'[PAYMENT_URL]'                     => esc_html__('This is a link to make a payment for the event',
55
+				'event_espresso'),
56
+			'[PAYMENT_LINK_IF_NEEDED_*]'        => esc_html__('This is a special dynamic shortcode that allows one to insert a payment link conditional on there being amount owing on the transaction. Three params are available on this shortcode:',
57
+					'event_espresso')
58
+												   . '<ul>'
59
+												   . '<li>'
60
+												   . sprintf(esc_html__('%sclass:%s This can be used to indicate css class is given to the containing css element (default is "callout").',
61
+					'event_espresso'), '<strong>', '</strong>')
62
+												   . '</li>'
63
+												   . '<li>'
64
+												   . sprintf(esc_html__('%scustom_text:%s This should be a sprintf format text string (with %%s for where the hyperlink tags go) that is used for the generated link text (The default is "You can %%smake a payment here »%%s.)',
65
+					'event_espresso'), '<strong>', '</strong>')
66
+												   . '</li>'
67
+												   . '<li>'
68
+												   . sprintf(esc_html__('%scontainer_tag:%s Use this to indicate what container tag you want surrounding the payment link (default is "p").',
69
+					'event_espresso'), '<strong>', '</strong>')
70
+												   . '</li>'
71
+												   . '</ul>',
72
+			'[PAYMENT_DUE_DATE_*]'              => esc_html__('This is a special dynamic shortcode that allows one to output a payment due date.  It will only result in a date shown if there is money owing.  Three parameters are available on this shortcode:',
73
+					'event_espresso')
74
+												   . '<ul>'
75
+												   . '<li>'
76
+												   . sprintf(esc_html__('%sformat:%s This is used to indicate what format the date is in.  Default is whatever is set as date formats for your website.',
77
+					'event_espresso'), '<strong>', '</strong>')
78
+												   . '</li>'
79
+												   . '<li>'
80
+												   . sprintf(esc_html__('%sdays_until_due:%s This is the number of days form the transaction creation date that the payment is due.  Defaults to 30.',
81
+					'event_espresso'), '<strong>', '</strong>')
82
+												   . '</li>'
83
+												   . '<li>'
84
+												   . sprintf(esc_html__('%sprefix_text:%s You can use this to indicate what text will prefix the date string.  Defaults to "Payment in full due by:"',
85
+					'event_espresso'), '<strong>', '</strong>')
86
+												   . '</li>',
87
+			'[INVOICE_LINK]'                    => esc_html__('This is a full html link to the invoice',
88
+				'event_espresso'),
89
+			'[INVOICE_URL]'                     => esc_html__('This is just the url for the invoice', 'event_espresso'),
90
+			'[INVOICE_LOGO_URL]'                => esc_html__('This returns the url for the logo uploaded via the invoice settings page.',
91
+				'event_espresso'),
92
+			'[INVOICE_LOGO]'                    => esc_html__('This returns the logo uploaded via the invoice settings page wrapped in img_tags and with a "logo screen" classes. The image size is also set in the img tags automatically to match the uploaded logo.',
93
+				'event_espresso'),
94
+			'[INVOICE_PAYEE_NAME]'              => esc_html__('This will parse to either: the value of the "Company Name" field in the invoice payment method settings; if that is blank, then the value of the Company Name in the "Your Organization Settings", if that is blank then an empty string.',
95
+				'event_espresso'),
96
+			'[INVOICE_PAYEE_ADDRESS]'           => esc_html__('This will parse to either: the value of the "Company Address" field in the invoice payment method settings; if that is blank, then the value of the Company Address in the "Your Organization Settings", if that is blank then an empty string.',
97
+				'event_espresso'),
98
+			'[INVOICE_PAYMENT_INSTRUCTIONS]'    => esc_html__('This will parse to the value of the "Payment Instructions" field found on the Invoice payment methods settings page',
99
+				'event_espresso'),
100
+			'[INVOICE_PAYEE_EMAIL]'             => esc_html__('This will parse to either: the value of the "Company Email" field in the invoice payment method settings; if that is blank, then the value of the Company Email in the "Your Organization Settings", if that is blank then an empty string.',
101
+				'event_espresso'),
102
+			'[INVOICE_PAYEE_TAX_NUMBER_*]'      => sprintf(esc_html__('This will parse to either: the value of the "Company Tax Number" field in the invoice payment method settings; if that is blank, then the value of the Company Tax Number in the "Your Organization Settings", if that is blank then an empty string. Note this is also a special dynamic shortcode. You can use the "prefix" parameter to indicate what text you want to use as a prefix before this tax number.  It defaults to "VAT/Tax Number:". To change this prefix you do the following format for this shortcode: %1$s[INVOICE_PAYEE_TAX_NUMBER_* prefix="GST:"]%2$s and that will output: GST: 12345t56.  If you have no tax number in your settings, then no prefix will be output either.',
103
+				'event_espresso'), '<code>', '</code>'),
104
+			'[TOTAL_COST]'                      => esc_html__('The total cost for the transaction', 'event_espresso'),
105
+			'[TXN_STATUS]'                      => esc_html__('The transaction status for the transaction.',
106
+				'event_espresso'),
107
+			'[TXN_STATUS_ID]'                   => esc_html__('The ID representing the transaction status as saved in the db.  This tends to be useful for including with css classes for styling certain statuses differently from others.',
108
+				'event_espresso'),
109
+			'[PAYMENT_STATUS]'                  => esc_html__('The transaction status for the transaction. This parses to the same value as the [TXN_STATUS] shortcode and still remains here for legacy support.',
110
+				'event_espresso'),
111
+			'[PAYMENT_GATEWAY]'                 => esc_html__('The payment gateway used for the transaction',
112
+				'event_espresso'),
113
+			'[AMOUNT_PAID]'                     => esc_html__('The amount paid or refunded.  This will only have a value if there was a payment or refund at the time of generating the message.',
114
+				'event_espresso'),
115
+			'[LAST_AMOUNT_PAID]'                => esc_html__('This is the last payment or refund made on the transaction related to the message being generated.',
116
+				'event_espresso'),
117
+			'[TOTAL_AMOUNT_PAID]'               => esc_html__('This parses to the total amount paid over all payments',
118
+				'event_espresso'),
119
+			'[TOTAL_OWING]'                     => esc_html__('The total owing on a transaction with no attributes.',
120
+				'event_espresso'),
121
+			'[TXN_SUBTOTAL]'                    => esc_html__('The subtotal for all txn line items.', 'event_espresso'),
122
+			'[TXN_TAX_SUBTOTAL]'                => esc_html__('The subtotal for all tax line items.', 'event_espresso'),
123
+			'[OWING_STATUS_MESSAGE_*]'          => esc_html__('A dynamic shortcode for adjusting how total owing gets shown. The acceptable attributes on the shortcode are:',
124
+					'event_espresso')
125
+												   . '<p></ul>'
126
+												   .
127
+												   '<li><strong>still_owing</strong>:'
128
+												   . esc_html__('If the transaction is not paid in full, then whatever is set for this attribute is shown (otherwise its just the amount owing). The default is:',
129
+					'event_espresso')
130
+												   . sprintf(esc_html__('%sPlease make a payment.%s', 'event_espresso'),
131
+					'<a href="[PAYMENT_URL]" class="noPrint">', '</a>')
132
+												   . '</li>'
133
+												   .
134
+												   '<li><strong>none_owing</strong>:'
135
+												   . esc_html__('If the transaction is paid in full, then you can indicate how this gets displayed.  Note, that it defaults to just be the total owing.',
136
+					'event_espresso')
137
+												   . '</li></ul></p>',
138
+			'[TXN_TOTAL_TICKETS]'               => esc_html__('The total number of all tickets purchased in a transaction',
139
+				'event_espresso'),
140
+			'[TKT_QTY_PURCHASED]'               => sprintf(esc_html__('The total number of all tickets purchased in a transaction. %1$sNOTE: This shortcode is good to use in the "[TICKET_LIST]" field but has been deprecated from all other contexts in favor of the more explicit [TXN_TOTAL_TICKETS] shortcode.%2$s',
141
+				'event_espresso'), '<strong>', '</strong>'),
142
+			'[TRANSACTION_ADMIN_URL]'           => esc_html__('The url to the admin page for this transaction',
143
+				'event_espresso'),
144
+			'[RECEIPT_URL]'                     => esc_html__('This parses to the generated url for retrieving the receipt for the transaction',
145
+				'event_espresso'),
146
+			'[INVOICE_RECEIPT_SWITCHER_URL]'    => esc_html__('This parses to the url that will switch to the receipt if an invoice is displayed, and switch to the invoice if receipt is displayed. If a message type OTHER than invoice or receipt is displayed then this will just return the url for the invoice. If the related message type is not active  then will parse to an empty string.',
147
+				'event_espresso'),
148
+			'[INVOICE_RECEIPT_SWITCHER_BUTTON]' => sprintf(esc_html__('The same as %1$s[INVOICE_RECEIPT_SWITCHER_URL]%2$s except this returns the html for a button linked to the invoice or receipt.',
149
+				'event_espresso'), '<code>', '</code>'),
150
+		);
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * @access protected
157
+	 * @param  string $shortcode the shortcode to be parsed.
158
+	 * @return string parsed shortcode
159
+	 */
160
+	protected function _parser($shortcode)
161
+	{
162
+		//attempt to get the transaction.  Since this is potentially used in more fields, we may have to look in the _extra_data for the transaction.
163
+		$transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
164
+		$transaction = ! $transaction instanceof EE_Transaction
165
+					   && is_array($this->_extra_data)
166
+					   && isset($this->_extra_data['data'])
167
+					   && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->txn
168
+			: $transaction;
169
+		//payment
170
+		$payment = $this->_data->payment instanceof EE_Payment ? $this->_data->payment : null;
171
+		$payment = ! $payment instanceof EE_Payment
172
+				   && is_array($this->_extra_data)
173
+				   && isset($this->_extra_data['data'])
174
+				   && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment
175
+			: $payment;
176
+		if (! $transaction instanceof EE_Transaction) {
177
+			return '';
178
+		}
179
+		switch ($shortcode) {
180
+			case '[TXN_ID]' :
181
+				return $transaction->ID();
182
+				break;
183
+			case '[PAYMENT_URL]' :
184
+				$payment_url = $transaction->payment_overview_url();
185
+				return empty($payment_url) ? esc_html__('http://dummypaymenturlforpreview.com', 'event_espresso')
186
+					: $payment_url;
187
+				break;
188
+			case '[INVOICE_LINK]' :
189
+				$invoice_url = $transaction->invoice_url();
190
+				$invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
191
+				return sprintf(esc_html__('%sClick here for Invoice%s', 'event_espresso'),
192
+					'<a href="' . $invoice_url . '">', '</a>');
193
+				break; /**/
194
+			case '[INVOICE_URL]' :
195
+				$invoice_url = $transaction->invoice_url();
196
+				return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
197
+				break;
198
+			case '[INVOICE_LOGO_URL]' :
199
+				return $this->_get_invoice_logo();
200
+				break;
201
+			case '[INVOICE_LOGO]' :
202
+				return $this->_get_invoice_logo(true);
203
+				break;
204
+			case '[INVOICE_PAYEE_NAME]' :
205
+				return $this->_get_invoice_payee_name();
206
+				break;
207
+			case '[INVOICE_PAYEE_ADDRESS]' :
208
+				return $this->_get_invoice_payee_address();
209
+				break;
210
+			case '[INVOICE_PAYMENT_INSTRUCTIONS]' :
211
+				return $this->_get_invoice_payment_instructions();
212
+				break;
213
+			case '[INVOICE_PAYEE_EMAIL]' :
214
+				return $this->_get_invoice_payee_email();
215
+				break;
216
+			case '[TOTAL_COST]' :
217
+				$total = $transaction->total();
218
+				return ! empty($total) ? EEH_Template::format_currency($total) : '';
219
+				break;
220
+			case '[PAYMENT_STATUS]' :
221
+				$status = $transaction->pretty_status();
222
+				return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso');
223
+				break; /**/
224
+			// note the [payment_status] shortcode is kind of misleading because payment status might be different from txn status so I'm adding this here for clarity.
225
+			case '[TXN_STATUS]':
226
+				$status = $transaction->pretty_status();
227
+				return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso');
228
+				break;
229
+			case '[TXN_STATUS_ID]' :
230
+				return $transaction->status_ID();
231
+				break;
232
+			case '[PAYMENT_GATEWAY]' :
233
+				return $this->_get_payment_gateway($transaction);
234
+				break;
235
+			case '[AMOUNT_PAID]' :
236
+				return $payment instanceof EE_Payment
237
+					? EEH_Template::format_currency($payment->amount())
238
+					: EEH_Template::format_currency(0);
239
+				break;
240
+			case '[LAST_AMOUNT_PAID]' :
241
+				$last_payment = $transaction->last_payment();
242
+				return $last_payment instanceof EE_Payment
243
+					? EEH_Template::format_currency($last_payment->amount())
244
+					: EEH_Template::format_currency(0);
245
+			case '[TOTAL_AMOUNT_PAID]' :
246
+				return EEH_Template::format_currency($transaction->paid());
247
+				break;
248
+			case '[TOTAL_OWING]' :
249
+				$total_owing = $transaction->remaining();
250
+				return EEH_Template::format_currency($total_owing);
251
+				break;
252
+			case '[TXN_SUBTOTAL]' :
253
+				return EEH_Template::format_currency($this->_get_subtotal());
254
+				break;
255
+			case '[TXN_TAX_SUBTOTAL]' :
256
+				return EEH_Template::format_currency($this->_get_subtotal(true));
257
+				break;
258
+			case '[TKT_QTY_PURCHASED]' :
259
+			case '[TXN_TOTAL_TICKETS]' :
260
+				return $this->_data->total_ticket_count;
261
+				break;
262
+			case '[TRANSACTION_ADMIN_URL]' :
263
+				require_once EE_CORE . 'admin/EE_Admin_Page.core.php';
264
+				$query_args = array(
265
+					'page'   => 'espresso_transactions',
266
+					'action' => 'view_transaction',
267
+					'TXN_ID' => $transaction->ID(),
268
+				);
269
+				$url = EE_Admin_Page::add_query_args_and_nonce($query_args, admin_url('admin.php'));
270
+				return $url;
271
+				break;
272
+			case '[RECEIPT_URL]' :
273
+				//get primary_registration
274
+				$reg = $this->_data->primary_reg_obj;
275
+				if (! $reg instanceof EE_Registration) {
276
+					return '';
277
+				}
278
+				return $reg->receipt_url();
279
+				break;
280
+			case '[INVOICE_RECEIPT_SWITCHER_URL]' :
281
+				return $this->_get_invoice_receipt_switcher(false);
282
+				break;
283
+			case '[INVOICE_RECEIPT_SWITCHER_BUTTON]' :
284
+				return $this->_get_invoice_receipt_switcher();
285
+				break;
286
+		}
287
+		if (strpos($shortcode, '[OWING_STATUS_MESSAGE_*') !== false) {
288
+			return $this->_get_custom_total_owing($shortcode);
289
+		}
290
+		if (strpos($shortcode, '[INVOICE_PAYEE_TAX_NUMBER_*') !== false) {
291
+			return $this->_get_invoice_payee_tax_number($shortcode);
292
+		}
293
+		if (strpos($shortcode, '[PAYMENT_LINK_IF_NEEDED_*') !== false) {
294
+			return $this->_get_payment_link_if_needed($shortcode);
295
+		}
296
+		if (strpos($shortcode, '[PAYMENT_DUE_DATE_*') !== false) {
297
+			return $this->_get_payment_due_date($shortcode, $transaction);
298
+		}
299
+		return '';
300
+	}
301
+
302
+
303
+
304
+	/**
305
+	 * parser for the [OWING_STATUS_MESSAGE_*] attribute type shortcode
306
+	 *
307
+	 * @since 4.5.0
308
+	 * @param string $shortcode the incoming shortcode
309
+	 * @return string parsed.
310
+	 */
311
+	private function _get_custom_total_owing($shortcode)
312
+	{
313
+		$valid_shortcodes = array('transaction');
314
+		$attrs = $this->_get_shortcode_attrs($shortcode);
315
+		//ensure default is set.
316
+		$addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
317
+		$total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction
318
+			? $addressee->txn->remaining() : 0;
319
+		if ($total_owing > 0) {
320
+			$owing_content = ! empty($attrs['still_owing'])
321
+				? $attrs['still_owing']
322
+				: sprintf(esc_html__('%sPlease make a payment.%s', 'event_espresso'),
323
+					'<a href="[PAYMENT_URL]" class="noPrint">', '</a>');
324
+			$owing_content = $this->_shortcode_helper->parse_message_template($owing_content, $addressee,
325
+				$valid_shortcodes, $this->_message_type, $this->_messenger, $this->_message);
326
+		} else {
327
+			$owing_content = ! empty($attrs['none_owing']) ? $attrs['none_owing'] : '';
328
+		}
329
+		return $owing_content;
330
+	}
331
+
332
+
333
+
334
+	/**
335
+	 * @param EE_Transaction $transaction
336
+	 * @return string
337
+	 */
338
+	private function _get_payment_gateway($transaction)
339
+	{
340
+		$pm = $this->_get_invoice_payment_method($transaction);
341
+		return $pm instanceof EE_Payment_Method ? $pm->name() : '';
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 * This retrieves a logo to be used for the invoice from whatever is set on the invoice logo settings page.  If its
348
+	 * not present then the organization logo is used if its found (set on the organization settings page).
349
+	 *
350
+	 * @since 4.5.0
351
+	 * @param bool $img_tags TRUE means to return with the img tag wrappers.  False just returns the url to the image.
352
+	 * @return string url or html
353
+	 */
354
+	private function _get_invoice_logo($img_tags = false)
355
+	{
356
+		//try to get the invoice payment method's logo for this transaction image first
357
+		$pm = $this->_get_invoice_payment_method();
358
+		if ($pm instanceof EE_Payment_Method) {
359
+			$invoice_logo_url = $pm->get_extra_meta('pdf_logo_image', true);
360
+		} else {
361
+			$invoice_logo_url = null;
362
+		}
363
+		if (empty($invoice_logo_url)) {
364
+			$invoice_logo_url = EE_Registry::instance()->CFG->organization->logo_url;
365
+		}
366
+		if (empty($invoice_logo_url)) {
367
+			return '';
368
+		}
369
+		if (! $img_tags) {
370
+			return $invoice_logo_url;
371
+		}
372
+		//image tags have been requested.
373
+		$image_size = getimagesize($invoice_logo_url);
374
+		//if image is wider than 300px, set the width to 300
375
+		if ($image_size[0] > 300) {
376
+			$image_width = 300;
377
+		} else {
378
+			$image_width = $image_size[0];
379
+		}
380
+		return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />';
381
+	}
382
+
383
+
384
+
385
+	/**
386
+	 * Used to retrieve the appropriate content for the invoice payee name shortcode
387
+	 *
388
+	 * @since 4.5.0
389
+	 * @return string
390
+	 */
391
+	private function _get_invoice_payee_name()
392
+	{
393
+		$payee_name = null;
394
+		$pm = $this->_get_invoice_payment_method();
395
+		if ($pm instanceof EE_Payment_Method) {
396
+			$payee_name = $pm->get_extra_meta('pdf_payee_name', true);
397
+		}
398
+		$payee_name = empty($payee_name) ? EE_Registry::instance()->CFG->organization->get_pretty('name') : $payee_name;
399
+		return $payee_name;
400
+	}
401
+
402
+
403
+
404
+	/**
405
+	 * gets the default invoice payment method, but has a filter so it can be overridden
406
+	 *
407
+	 * @return \EE_Payment_Method|null
408
+	 */
409
+	private function _get_invoice_payment_method()
410
+	{
411
+		if (! $this->_invoice_pm instanceof EE_Payment_Method) {
412
+			$transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
413
+			$transaction = ! $transaction instanceof EE_Transaction
414
+						   && is_array($this->_extra_data)
415
+						   && isset($this->_extra_data['data'])
416
+						   && $this->_extra_data['data'] instanceof EE_Messages_Addressee
417
+				? $this->_extra_data['data']->txn : $transaction;
418
+			//get the invoice payment method, and remember it for the next call too
419
+			$this->_invoice_pm = apply_filters('FHEE__EE_Transaction_Shortcodes__get_payment_method__default',
420
+				EEM_Payment_Method::instance()->get_one_of_type('Invoice'), $transaction);
421
+		}
422
+		return $this->_invoice_pm;
423
+	}
424
+
425
+
426
+
427
+	/**
428
+	 * Used to retrieve the appropriate content for the invoice payee email shortcode
429
+	 *
430
+	 * @since 4.5.0
431
+	 * @return string
432
+	 */
433
+	private function _get_invoice_payee_email()
434
+	{
435
+		$payee_email = null;
436
+		$pm = $this->_get_invoice_payment_method();
437
+		if ($pm instanceof EE_Payment_Method) {
438
+			$payee_email = $pm->get_extra_meta('pdf_payee_email', true);
439
+		}
440
+		$payee_email = empty($payee_email) ? EE_Registry::instance()->CFG->organization->get_pretty('email')
441
+			: $payee_email;
442
+		return $payee_email;
443
+	}
444
+
445
+
446
+
447
+	/**
448
+	 * Used to retrieve the appropriate content for the invoice payee tax number shortcode
449
+	 *
450
+	 * @since 4.5.0
451
+	 * @param string $shortcode
452
+	 * @return string
453
+	 */
454
+	private function _get_invoice_payee_tax_number($shortcode)
455
+	{
456
+		$payee_tax_number = null;
457
+		$pm = $this->_get_invoice_payment_method();
458
+		if ($pm instanceof EE_Payment_Method) {
459
+			$payee_tax_number = $pm->get_extra_meta('pdf_payee_tax_number', true);
460
+		}
461
+		$payee_tax_number = empty($payee_tax_number) ? EE_Registry::instance()->CFG->organization->vat
462
+			: $payee_tax_number;
463
+		if (empty($payee_tax_number)) {
464
+			return '';
465
+		}
466
+		//any attributes?
467
+		$attrs = $this->_get_shortcode_attrs($shortcode);
468
+		//prefix?
469
+		$prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso');
470
+		return $prefix . $payee_tax_number;
471
+	}
472
+
473
+
474
+
475
+	/**
476
+	 * Used to retrieve the appropriate content for the invoice payee address shortcode.
477
+	 *
478
+	 * @since 4.5.0
479
+	 * @return string
480
+	 */
481
+	private function _get_invoice_payee_address()
482
+	{
483
+		$payee_address = null;
484
+		$pm = $this->_get_invoice_payment_method();
485
+		if ($pm instanceof EE_Payment_Method) {
486
+			$payee_address = $pm->get_extra_meta('pdf_payee_address', true);
487
+		}
488
+		if (empty($payee_address)) {
489
+			$organization = EE_Registry::instance()->CFG->organization;
490
+			$payee_address = $organization->get_pretty('address_1') . '<br>';
491
+			$payee_address .= ! empty($organization->address_2) ? $organization->get_pretty('address_2') . '<br>' : '';
492
+			$payee_address .= $organization->get_pretty('city') . '<br>';
493
+			//state
494
+			$state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID);
495
+			$payee_address .= $state instanceof EE_State ? $state->name() : '';
496
+			//Country
497
+			$payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : '';
498
+			$payee_address .= ! empty($organization->zip) ? $organization->zip : '';
499
+		}
500
+		return $payee_address;
501
+	}
502
+
503
+
504
+
505
+	/**
506
+	 * Used to retrieve the appropriate content for the invoice payment instructions shortcode.
507
+	 *
508
+	 * @since 4.5.0
509
+	 * @return string
510
+	 */
511
+	private function _get_invoice_payment_instructions()
512
+	{
513
+		$instructions = null;
514
+		$pm = $this->_get_invoice_payment_method();
515
+		return ($pm instanceof EE_Payment_Method) ? $pm->get_extra_meta('pdf_instructions', true) : '';
516
+	}
517
+
518
+
519
+
520
+	/**
521
+	 * get invoice/receipt switch button or url.
522
+	 *
523
+	 * @param bool $button true (default) returns the html for a button, false just returns the url.
524
+	 * @return string
525
+	 */
526
+	protected function _get_invoice_receipt_switcher($button = true)
527
+	{
528
+		$reg = $this->_data->primary_reg_obj;
529
+		$message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : '';
530
+		if (! $reg instanceof EE_Registration || empty($message_type)) {
531
+			return '';
532
+		}
533
+		$switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false;
534
+		$switch_to_label = $switch_to_invoice && ! $message_type instanceof EE_Receipt_message_type
535
+			? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso');
536
+		$switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label;
537
+		$switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url();
538
+		if (! $button) {
539
+			return $switch_to_url;
540
+		}
541
+		if (! empty($switch_to_url)) {
542
+			return '
543 543
 	<form method="post" action="' . $switch_to_url . '" >
544 544
 		<input class="print_button" type="submit" value="' . $switch_to_label . '" />
545 545
 	</form>
546 546
 			';
547
-        }
548
-        return '';
549
-    }
550
-
551
-
552
-
553
-    /**
554
-     * This returns a subtotal.
555
-     *
556
-     * @param bool $tax if true then return the subtotal for tax otherwise return subtotal.
557
-     * @return int
558
-     */
559
-    private function _get_subtotal($tax = false)
560
-    {
561
-        $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null;
562
-        if (! $grand_total instanceof EE_Line_Item) {
563
-            return 0;
564
-        }
565
-        return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total();
566
-    }
567
-
568
-
569
-
570
-    /**
571
-     * parser for the [PAYMENT_LINK_IF_NEEDED_*] attribute type shortcode
572
-     *
573
-     * @since 4.7.0
574
-     * @param string $shortcode the incoming shortcode
575
-     * @return string parsed.
576
-     */
577
-    private function _get_payment_link_if_needed($shortcode)
578
-    {
579
-        $valid_shortcodes = array('transaction');
580
-        $attrs = $this->_get_shortcode_attrs($shortcode);
581
-        //ensure default is set.
582
-        $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
583
-        $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction
584
-            ? $addressee->txn->remaining() : 0;
585
-        if ($total_owing > 0) {
586
-            $class = isset($attrs['class']) ? $attrs['class'] : 'callout';
587
-            $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.';
588
-            $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p';
589
-            $opening_tag = ! empty($container_tag) ? '<' . $container_tag : '';
590
-            $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag;
591
-            $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag;
592
-            $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : '';
593
-            $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag;
594
-            //we need to re run this string through the parser to catch any shortcodes that are in it.
595
-            $owing_content = $this->_shortcode_helper->parse_message_template($content, $addressee, $valid_shortcodes,
596
-                $this->_message_type, $this->_messenger, $this->_message);
597
-        } else {
598
-            return '';
599
-        }
600
-        return $owing_content;
601
-    }
602
-
603
-
604
-
605
-    /**
606
-     * Parser for the [PAYMENT_DUE_DATE_*] attribute type shortcode
607
-     *
608
-     * @since 4.8.28.rc.011
609
-     * @param string         $shortcode The shortcode being parsed.
610
-     * @param EE_Transaction $transaction
611
-     * @return string
612
-     */
613
-    protected function _get_payment_due_date($shortcode, EE_Transaction $transaction)
614
-    {
615
-        //if transaction is paid in full then we can just return an empty string
616
-        if ($transaction->remaining() === 0) {
617
-            return '';
618
-        }
619
-        $attrs = $this->_get_shortcode_attrs($shortcode);
620
-        $format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format');
621
-        $days_until_due = isset($attrs['days_until_due']) ? (int)$attrs['days_until_due'] : 30;
622
-        $prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text']
623
-            : esc_html__('Payment in full due by: ', 'event_espresso');
624
-        $transaction_created = $transaction->get_DateTime_object('TXN_timestamp');
625
-        //setup date due:
626
-        try {
627
-            if ($transaction_created instanceof DateTime) {
628
-                $date_due = $transaction_created->add(new DateInterval('P' . $days_until_due . 'D'))->format($format);
629
-            } else {
630
-                throw new Exception();
631
-            }
632
-        } catch (Exception $e) {
633
-            //format was likely invalid.
634
-            $date_due = 'Unable to calculate date due, likely the format string is invalid.';
635
-        }
636
-        return $prefix_text . $date_due;
637
-    }
547
+		}
548
+		return '';
549
+	}
550
+
551
+
552
+
553
+	/**
554
+	 * This returns a subtotal.
555
+	 *
556
+	 * @param bool $tax if true then return the subtotal for tax otherwise return subtotal.
557
+	 * @return int
558
+	 */
559
+	private function _get_subtotal($tax = false)
560
+	{
561
+		$grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null;
562
+		if (! $grand_total instanceof EE_Line_Item) {
563
+			return 0;
564
+		}
565
+		return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total();
566
+	}
567
+
568
+
569
+
570
+	/**
571
+	 * parser for the [PAYMENT_LINK_IF_NEEDED_*] attribute type shortcode
572
+	 *
573
+	 * @since 4.7.0
574
+	 * @param string $shortcode the incoming shortcode
575
+	 * @return string parsed.
576
+	 */
577
+	private function _get_payment_link_if_needed($shortcode)
578
+	{
579
+		$valid_shortcodes = array('transaction');
580
+		$attrs = $this->_get_shortcode_attrs($shortcode);
581
+		//ensure default is set.
582
+		$addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
583
+		$total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction
584
+			? $addressee->txn->remaining() : 0;
585
+		if ($total_owing > 0) {
586
+			$class = isset($attrs['class']) ? $attrs['class'] : 'callout';
587
+			$custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.';
588
+			$container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p';
589
+			$opening_tag = ! empty($container_tag) ? '<' . $container_tag : '';
590
+			$opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag;
591
+			$opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag;
592
+			$closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : '';
593
+			$content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag;
594
+			//we need to re run this string through the parser to catch any shortcodes that are in it.
595
+			$owing_content = $this->_shortcode_helper->parse_message_template($content, $addressee, $valid_shortcodes,
596
+				$this->_message_type, $this->_messenger, $this->_message);
597
+		} else {
598
+			return '';
599
+		}
600
+		return $owing_content;
601
+	}
602
+
603
+
604
+
605
+	/**
606
+	 * Parser for the [PAYMENT_DUE_DATE_*] attribute type shortcode
607
+	 *
608
+	 * @since 4.8.28.rc.011
609
+	 * @param string         $shortcode The shortcode being parsed.
610
+	 * @param EE_Transaction $transaction
611
+	 * @return string
612
+	 */
613
+	protected function _get_payment_due_date($shortcode, EE_Transaction $transaction)
614
+	{
615
+		//if transaction is paid in full then we can just return an empty string
616
+		if ($transaction->remaining() === 0) {
617
+			return '';
618
+		}
619
+		$attrs = $this->_get_shortcode_attrs($shortcode);
620
+		$format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format');
621
+		$days_until_due = isset($attrs['days_until_due']) ? (int)$attrs['days_until_due'] : 30;
622
+		$prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text']
623
+			: esc_html__('Payment in full due by: ', 'event_espresso');
624
+		$transaction_created = $transaction->get_DateTime_object('TXN_timestamp');
625
+		//setup date due:
626
+		try {
627
+			if ($transaction_created instanceof DateTime) {
628
+				$date_due = $transaction_created->add(new DateInterval('P' . $days_until_due . 'D'))->format($format);
629
+			} else {
630
+				throw new Exception();
631
+			}
632
+		} catch (Exception $e) {
633
+			//format was likely invalid.
634
+			$date_due = 'Unable to calculate date due, likely the format string is invalid.';
635
+		}
636
+		return $prefix_text . $date_due;
637
+	}
638 638
 
639 639
 } //end EE_Transaction Shortcodes library
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('NO direct script access allowed');
4 4
 }
5 5
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
                    && isset($this->_extra_data['data'])
174 174
                    && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment
175 175
             : $payment;
176
-        if (! $transaction instanceof EE_Transaction) {
176
+        if ( ! $transaction instanceof EE_Transaction) {
177 177
             return '';
178 178
         }
179 179
         switch ($shortcode) {
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
                 $invoice_url = $transaction->invoice_url();
190 190
                 $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url;
191 191
                 return sprintf(esc_html__('%sClick here for Invoice%s', 'event_espresso'),
192
-                    '<a href="' . $invoice_url . '">', '</a>');
192
+                    '<a href="'.$invoice_url.'">', '</a>');
193 193
                 break; /**/
194 194
             case '[INVOICE_URL]' :
195 195
                 $invoice_url = $transaction->invoice_url();
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
                 return $this->_data->total_ticket_count;
261 261
                 break;
262 262
             case '[TRANSACTION_ADMIN_URL]' :
263
-                require_once EE_CORE . 'admin/EE_Admin_Page.core.php';
263
+                require_once EE_CORE.'admin/EE_Admin_Page.core.php';
264 264
                 $query_args = array(
265 265
                     'page'   => 'espresso_transactions',
266 266
                     'action' => 'view_transaction',
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
             case '[RECEIPT_URL]' :
273 273
                 //get primary_registration
274 274
                 $reg = $this->_data->primary_reg_obj;
275
-                if (! $reg instanceof EE_Registration) {
275
+                if ( ! $reg instanceof EE_Registration) {
276 276
                     return '';
277 277
                 }
278 278
                 return $reg->receipt_url();
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
         if (empty($invoice_logo_url)) {
367 367
             return '';
368 368
         }
369
-        if (! $img_tags) {
369
+        if ( ! $img_tags) {
370 370
             return $invoice_logo_url;
371 371
         }
372 372
         //image tags have been requested.
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
         } else {
378 378
             $image_width = $image_size[0];
379 379
         }
380
-        return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />';
380
+        return '<img class="logo screen" src="'.$invoice_logo_url.'" width="'.$image_width.'" alt="logo" />';
381 381
     }
382 382
 
383 383
 
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
      */
409 409
     private function _get_invoice_payment_method()
410 410
     {
411
-        if (! $this->_invoice_pm instanceof EE_Payment_Method) {
411
+        if ( ! $this->_invoice_pm instanceof EE_Payment_Method) {
412 412
             $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null;
413 413
             $transaction = ! $transaction instanceof EE_Transaction
414 414
                            && is_array($this->_extra_data)
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
         $attrs = $this->_get_shortcode_attrs($shortcode);
468 468
         //prefix?
469 469
         $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso');
470
-        return $prefix . $payee_tax_number;
470
+        return $prefix.$payee_tax_number;
471 471
     }
472 472
 
473 473
 
@@ -487,14 +487,14 @@  discard block
 block discarded – undo
487 487
         }
488 488
         if (empty($payee_address)) {
489 489
             $organization = EE_Registry::instance()->CFG->organization;
490
-            $payee_address = $organization->get_pretty('address_1') . '<br>';
491
-            $payee_address .= ! empty($organization->address_2) ? $organization->get_pretty('address_2') . '<br>' : '';
492
-            $payee_address .= $organization->get_pretty('city') . '<br>';
490
+            $payee_address = $organization->get_pretty('address_1').'<br>';
491
+            $payee_address .= ! empty($organization->address_2) ? $organization->get_pretty('address_2').'<br>' : '';
492
+            $payee_address .= $organization->get_pretty('city').'<br>';
493 493
             //state
494 494
             $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID);
495 495
             $payee_address .= $state instanceof EE_State ? $state->name() : '';
496 496
             //Country
497
-            $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : '';
497
+            $payee_address .= ! empty($organization->CNT_ISO) ? ', '.$organization->CNT_ISO.'<br>' : '';
498 498
             $payee_address .= ! empty($organization->zip) ? $organization->zip : '';
499 499
         }
500 500
         return $payee_address;
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
     {
528 528
         $reg = $this->_data->primary_reg_obj;
529 529
         $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : '';
530
-        if (! $reg instanceof EE_Registration || empty($message_type)) {
530
+        if ( ! $reg instanceof EE_Registration || empty($message_type)) {
531 531
             return '';
532 532
         }
533 533
         $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false;
@@ -535,13 +535,13 @@  discard block
 block discarded – undo
535 535
             ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso');
536 536
         $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label;
537 537
         $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url();
538
-        if (! $button) {
538
+        if ( ! $button) {
539 539
             return $switch_to_url;
540 540
         }
541
-        if (! empty($switch_to_url)) {
541
+        if ( ! empty($switch_to_url)) {
542 542
             return '
543
-	<form method="post" action="' . $switch_to_url . '" >
544
-		<input class="print_button" type="submit" value="' . $switch_to_label . '" />
543
+	<form method="post" action="' . $switch_to_url.'" >
544
+		<input class="print_button" type="submit" value="' . $switch_to_label.'" />
545 545
 	</form>
546 546
 			';
547 547
         }
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
     private function _get_subtotal($tax = false)
560 560
     {
561 561
         $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null;
562
-        if (! $grand_total instanceof EE_Line_Item) {
562
+        if ( ! $grand_total instanceof EE_Line_Item) {
563 563
             return 0;
564 564
         }
565 565
         return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total();
@@ -586,11 +586,11 @@  discard block
 block discarded – undo
586 586
             $class = isset($attrs['class']) ? $attrs['class'] : 'callout';
587 587
             $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.';
588 588
             $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p';
589
-            $opening_tag = ! empty($container_tag) ? '<' . $container_tag : '';
590
-            $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag;
589
+            $opening_tag = ! empty($container_tag) ? '<'.$container_tag : '';
590
+            $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="'.$class.'"' : $opening_tag;
591 591
             $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag;
592
-            $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : '';
593
-            $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag;
592
+            $closing_tag = ! empty($container_tag) ? '</'.$container_tag.'>' : '';
593
+            $content = $opening_tag.sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>').$closing_tag;
594 594
             //we need to re run this string through the parser to catch any shortcodes that are in it.
595 595
             $owing_content = $this->_shortcode_helper->parse_message_template($content, $addressee, $valid_shortcodes,
596 596
                 $this->_message_type, $this->_messenger, $this->_message);
@@ -618,14 +618,14 @@  discard block
 block discarded – undo
618 618
         }
619 619
         $attrs = $this->_get_shortcode_attrs($shortcode);
620 620
         $format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format');
621
-        $days_until_due = isset($attrs['days_until_due']) ? (int)$attrs['days_until_due'] : 30;
621
+        $days_until_due = isset($attrs['days_until_due']) ? (int) $attrs['days_until_due'] : 30;
622 622
         $prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text']
623 623
             : esc_html__('Payment in full due by: ', 'event_espresso');
624 624
         $transaction_created = $transaction->get_DateTime_object('TXN_timestamp');
625 625
         //setup date due:
626 626
         try {
627 627
             if ($transaction_created instanceof DateTime) {
628
-                $date_due = $transaction_created->add(new DateInterval('P' . $days_until_due . 'D'))->format($format);
628
+                $date_due = $transaction_created->add(new DateInterval('P'.$days_until_due.'D'))->format($format);
629 629
             } else {
630 630
                 throw new Exception();
631 631
             }
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
             //format was likely invalid.
634 634
             $date_due = 'Unable to calculate date due, likely the format string is invalid.';
635 635
         }
636
-        return $prefix_text . $date_due;
636
+        return $prefix_text.$date_due;
637 637
     }
638 638
 
639 639
 } //end EE_Transaction Shortcodes library
Please login to merge, or discard this patch.