Passed
Push — master ( e82094...e2c1d0 )
by Brian
06:14 queued 01:44
created
includes/data-stores/class-getpaid-data.php 1 patch
Indentation   +862 added lines, -862 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  */
10 10
 
11 11
 if ( ! defined( 'ABSPATH' ) ) {
12
-	exit;
12
+    exit;
13 13
 }
14 14
 
15 15
 /**
@@ -21,356 +21,356 @@  discard block
 block discarded – undo
21 21
  */
22 22
 abstract class GetPaid_Data {
23 23
 
24
-	/**
25
-	 * ID for this object.
26
-	 *
27
-	 * @since 1.0.19
28
-	 * @var int
29
-	 */
30
-	protected $id = 0;
31
-
32
-	/**
33
-	 * Core data for this object. Name value pairs (name + default value).
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array();
39
-
40
-	/**
41
-	 * Core data changes for this object.
42
-	 *
43
-	 * @since 1.0.19
44
-	 * @var array
45
-	 */
46
-	protected $changes = array();
47
-
48
-	/**
49
-	 * This is false until the object is read from the DB.
50
-	 *
51
-	 * @since 1.0.19
52
-	 * @var bool
53
-	 */
54
-	protected $object_read = false;
55
-
56
-	/**
57
-	 * This is the name of this object type.
58
-	 *
59
-	 * @since 1.0.19
60
-	 * @var string
61
-	 */
62
-	protected $object_type = 'data';
63
-
64
-	/**
65
-	 * Extra data for this object. Name value pairs (name + default value).
66
-	 * Used as a standard way for sub classes (like item types) to add
67
-	 * additional information to an inherited class.
68
-	 *
69
-	 * @since 1.0.19
70
-	 * @var array
71
-	 */
72
-	protected $extra_data = array();
73
-
74
-	/**
75
-	 * Set to _data on construct so we can track and reset data if needed.
76
-	 *
77
-	 * @since 1.0.19
78
-	 * @var array
79
-	 */
80
-	protected $default_data = array();
81
-
82
-	/**
83
-	 * Contains a reference to the data store for this class.
84
-	 *
85
-	 * @since 1.0.19
86
-	 * @var GetPaid_Data_Store
87
-	 */
88
-	protected $data_store;
89
-
90
-	/**
91
-	 * Stores meta in cache for future reads.
92
-	 * A group must be set to to enable caching.
93
-	 *
94
-	 * @since 1.0.19
95
-	 * @var string
96
-	 */
97
-	protected $cache_group = '';
98
-
99
-	/**
100
-	 * Stores the last error.
101
-	 *
102
-	 * @since 1.0.19
103
-	 * @var string
104
-	 */
105
-	public $last_error = '';
106
-
107
-	/**
108
-	 * Stores additional meta data.
109
-	 *
110
-	 * @since 1.0.19
111
-	 * @var array
112
-	 */
113
-	protected $meta_data = null;
114
-
115
-	/**
116
-	 * Default constructor.
117
-	 *
118
-	 * @param int|object|array|string $read ID to load from the DB (optional) or already queried data.
119
-	 */
120
-	public function __construct( $read = 0 ) {
121
-		$this->data         = array_merge( $this->data, $this->extra_data );
122
-		$this->default_data = $this->data;
123
-	}
124
-
125
-	/**
126
-	 * Only store the object ID to avoid serializing the data object instance.
127
-	 *
128
-	 * @return array
129
-	 */
130
-	public function __sleep() {
131
-		return array( 'id' );
132
-	}
133
-
134
-	/**
135
-	 * Re-run the constructor with the object ID.
136
-	 *
137
-	 * If the object no longer exists, remove the ID.
138
-	 */
139
-	public function __wakeup() {
140
-		$this->__construct( absint( $this->id ) );
141
-
142
-		if ( ! empty( $this->last_error ) ) {
143
-			$this->set_id( 0 );
144
-		}
145
-
146
-	}
147
-
148
-	/**
149
-	 * When the object is cloned, make sure meta is duplicated correctly.
150
-	 *
151
-	 * @since 1.0.19
152
-	 */
153
-	public function __clone() {
154
-		$this->maybe_read_meta_data();
155
-		if ( ! empty( $this->meta_data ) ) {
156
-			foreach ( $this->meta_data as $array_key => $meta ) {
157
-				$this->meta_data[ $array_key ] = clone $meta;
158
-				if ( ! empty( $meta->id ) ) {
159
-					$this->meta_data[ $array_key ]->id = null;
160
-				}
161
-			}
162
-		}
163
-	}
164
-
165
-	/**
166
-	 * Get the data store.
167
-	 *
168
-	 * @since  1.0.19
169
-	 * @return object
170
-	 */
171
-	public function get_data_store() {
172
-		return $this->data_store;
173
-	}
174
-
175
-	/**
176
-	 * Get the object type.
177
-	 *
178
-	 * @since  1.0.19
179
-	 * @return string
180
-	 */
181
-	public function get_object_type() {
182
-		return $this->object_type;
183
-	}
184
-
185
-	/**
186
-	 * Returns the unique ID for this object.
187
-	 *
188
-	 * @since  1.0.19
189
-	 * @return int
190
-	 */
191
-	public function get_id() {
192
-		return $this->id;
193
-	}
194
-
195
-	/**
196
-	 * Get form status.
197
-	 *
198
-	 * @since 1.0.19
199
-	 * @param  string $context View or edit context.
200
-	 * @return string
201
-	 */
202
-	public function get_status( $context = 'view' ) {
203
-		return $this->get_prop( 'status', $context );
204
-    }
205
-
206
-	/**
207
-	 * Delete an object, set the ID to 0, and return result.
208
-	 *
209
-	 * @since  1.0.19
210
-	 * @param  bool $force_delete Should the data be deleted permanently.
211
-	 * @return bool result
212
-	 */
213
-	public function delete( $force_delete = false ) {
214
-		if ( $this->data_store && $this->exists() ) {
215
-			$this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
-			$this->set_id( 0 );
217
-			return true;
218
-		}
219
-		return false;
220
-	}
221
-
222
-	/**
223
-	 * Save should create or update based on object existence.
224
-	 *
225
-	 * @since  1.0.19
226
-	 * @return int
227
-	 */
228
-	public function save() {
229
-		if ( ! $this->data_store ) {
230
-			return $this->get_id();
231
-		}
232
-
233
-		/**
234
-		 * Trigger action before saving to the DB. Allows you to adjust object props before save.
235
-		 *
236
-		 * @param GetPaid_Data          $this The object being saved.
237
-		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238
-		 */
239
-		do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
240
-
241
-		if ( $this->get_id() ) {
242
-			$this->data_store->update( $this );
243
-		} else {
244
-			$this->data_store->create( $this );
245
-		}
246
-
247
-		/**
248
-		 * Trigger action after saving to the DB.
249
-		 *
250
-		 * @param GetPaid_Data          $this The object being saved.
251
-		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252
-		 */
253
-		do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
254
-
255
-		return $this->get_id();
256
-	}
257
-
258
-	/**
259
-	 * Change data to JSON format.
260
-	 *
261
-	 * @since  1.0.19
262
-	 * @return string Data in JSON format.
263
-	 */
264
-	public function __toString() {
265
-		return wp_json_encode( $this->get_data() );
266
-	}
267
-
268
-	/**
269
-	 * Returns all data for this object.
270
-	 *
271
-	 * @since  1.0.19
272
-	 * @return array
273
-	 */
274
-	public function get_data() {
275
-		return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
276
-	}
277
-
278
-	/**
279
-	 * Returns array of expected data keys for this object.
280
-	 *
281
-	 * @since   1.0.19
282
-	 * @return array
283
-	 */
284
-	public function get_data_keys() {
285
-		return array_keys( $this->data );
286
-	}
287
-
288
-	/**
289
-	 * Returns all "extra" data keys for an object (for sub objects like item types).
290
-	 *
291
-	 * @since  1.0.19
292
-	 * @return array
293
-	 */
294
-	public function get_extra_data_keys() {
295
-		return array_keys( $this->extra_data );
296
-	}
297
-
298
-	/**
299
-	 * Filter null meta values from array.
300
-	 *
301
-	 * @since  1.0.19
302
-	 * @param mixed $meta Meta value to check.
303
-	 * @return bool
304
-	 */
305
-	protected function filter_null_meta( $meta ) {
306
-		return ! is_null( $meta->value );
307
-	}
308
-
309
-	/**
310
-	 * Get All Meta Data.
311
-	 *
312
-	 * @since 1.0.19
313
-	 * @return array of objects.
314
-	 */
315
-	public function get_meta_data() {
316
-		$this->maybe_read_meta_data();
317
-		return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
318
-	}
319
-
320
-	/**
321
-	 * Check if the key is an internal one.
322
-	 *
323
-	 * @since  1.0.19
324
-	 * @param  string $key Key to check.
325
-	 * @return bool   true if it's an internal key, false otherwise
326
-	 */
327
-	protected function is_internal_meta_key( $key ) {
328
-		$internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
329
-
330
-		if ( ! $internal_meta_key ) {
331
-			return false;
332
-		}
333
-
334
-		$has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
335
-
336
-		if ( ! $has_setter_or_getter ) {
337
-			return false;
338
-		}
339
-
340
-		/* translators: %s: $key Key to check */
341
-		getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'invoicing' ), $key ), '1.0.19' );
342
-
343
-		return true;
344
-	}
345
-
346
-	/**
347
-	 * Magic method for setting data fields.
348
-	 *
349
-	 * This method does not update custom fields in the database.
350
-	 *
351
-	 * @since 1.0.19
352
-	 * @access public
353
-	 *
354
-	 */
355
-	public function __set( $key, $value ) {
356
-
357
-		if ( 'id' == strtolower( $key ) ) {
358
-			return $this->set_id( $value );
359
-		}
360
-
361
-		if ( method_exists( $this, "set_$key") ) {
362
-
363
-			/* translators: %s: $key Key to set */
364
-			getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' );
365
-
366
-			call_user_func( array( $this, "set_$key" ), $value );
367
-		} else {
368
-			$this->set_prop( $key, $value );
369
-		}
370
-
371
-	}
372
-
373
-	/**
24
+    /**
25
+     * ID for this object.
26
+     *
27
+     * @since 1.0.19
28
+     * @var int
29
+     */
30
+    protected $id = 0;
31
+
32
+    /**
33
+     * Core data for this object. Name value pairs (name + default value).
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array();
39
+
40
+    /**
41
+     * Core data changes for this object.
42
+     *
43
+     * @since 1.0.19
44
+     * @var array
45
+     */
46
+    protected $changes = array();
47
+
48
+    /**
49
+     * This is false until the object is read from the DB.
50
+     *
51
+     * @since 1.0.19
52
+     * @var bool
53
+     */
54
+    protected $object_read = false;
55
+
56
+    /**
57
+     * This is the name of this object type.
58
+     *
59
+     * @since 1.0.19
60
+     * @var string
61
+     */
62
+    protected $object_type = 'data';
63
+
64
+    /**
65
+     * Extra data for this object. Name value pairs (name + default value).
66
+     * Used as a standard way for sub classes (like item types) to add
67
+     * additional information to an inherited class.
68
+     *
69
+     * @since 1.0.19
70
+     * @var array
71
+     */
72
+    protected $extra_data = array();
73
+
74
+    /**
75
+     * Set to _data on construct so we can track and reset data if needed.
76
+     *
77
+     * @since 1.0.19
78
+     * @var array
79
+     */
80
+    protected $default_data = array();
81
+
82
+    /**
83
+     * Contains a reference to the data store for this class.
84
+     *
85
+     * @since 1.0.19
86
+     * @var GetPaid_Data_Store
87
+     */
88
+    protected $data_store;
89
+
90
+    /**
91
+     * Stores meta in cache for future reads.
92
+     * A group must be set to to enable caching.
93
+     *
94
+     * @since 1.0.19
95
+     * @var string
96
+     */
97
+    protected $cache_group = '';
98
+
99
+    /**
100
+     * Stores the last error.
101
+     *
102
+     * @since 1.0.19
103
+     * @var string
104
+     */
105
+    public $last_error = '';
106
+
107
+    /**
108
+     * Stores additional meta data.
109
+     *
110
+     * @since 1.0.19
111
+     * @var array
112
+     */
113
+    protected $meta_data = null;
114
+
115
+    /**
116
+     * Default constructor.
117
+     *
118
+     * @param int|object|array|string $read ID to load from the DB (optional) or already queried data.
119
+     */
120
+    public function __construct( $read = 0 ) {
121
+        $this->data         = array_merge( $this->data, $this->extra_data );
122
+        $this->default_data = $this->data;
123
+    }
124
+
125
+    /**
126
+     * Only store the object ID to avoid serializing the data object instance.
127
+     *
128
+     * @return array
129
+     */
130
+    public function __sleep() {
131
+        return array( 'id' );
132
+    }
133
+
134
+    /**
135
+     * Re-run the constructor with the object ID.
136
+     *
137
+     * If the object no longer exists, remove the ID.
138
+     */
139
+    public function __wakeup() {
140
+        $this->__construct( absint( $this->id ) );
141
+
142
+        if ( ! empty( $this->last_error ) ) {
143
+            $this->set_id( 0 );
144
+        }
145
+
146
+    }
147
+
148
+    /**
149
+     * When the object is cloned, make sure meta is duplicated correctly.
150
+     *
151
+     * @since 1.0.19
152
+     */
153
+    public function __clone() {
154
+        $this->maybe_read_meta_data();
155
+        if ( ! empty( $this->meta_data ) ) {
156
+            foreach ( $this->meta_data as $array_key => $meta ) {
157
+                $this->meta_data[ $array_key ] = clone $meta;
158
+                if ( ! empty( $meta->id ) ) {
159
+                    $this->meta_data[ $array_key ]->id = null;
160
+                }
161
+            }
162
+        }
163
+    }
164
+
165
+    /**
166
+     * Get the data store.
167
+     *
168
+     * @since  1.0.19
169
+     * @return object
170
+     */
171
+    public function get_data_store() {
172
+        return $this->data_store;
173
+    }
174
+
175
+    /**
176
+     * Get the object type.
177
+     *
178
+     * @since  1.0.19
179
+     * @return string
180
+     */
181
+    public function get_object_type() {
182
+        return $this->object_type;
183
+    }
184
+
185
+    /**
186
+     * Returns the unique ID for this object.
187
+     *
188
+     * @since  1.0.19
189
+     * @return int
190
+     */
191
+    public function get_id() {
192
+        return $this->id;
193
+    }
194
+
195
+    /**
196
+     * Get form status.
197
+     *
198
+     * @since 1.0.19
199
+     * @param  string $context View or edit context.
200
+     * @return string
201
+     */
202
+    public function get_status( $context = 'view' ) {
203
+        return $this->get_prop( 'status', $context );
204
+    }
205
+
206
+    /**
207
+     * Delete an object, set the ID to 0, and return result.
208
+     *
209
+     * @since  1.0.19
210
+     * @param  bool $force_delete Should the data be deleted permanently.
211
+     * @return bool result
212
+     */
213
+    public function delete( $force_delete = false ) {
214
+        if ( $this->data_store && $this->exists() ) {
215
+            $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
+            $this->set_id( 0 );
217
+            return true;
218
+        }
219
+        return false;
220
+    }
221
+
222
+    /**
223
+     * Save should create or update based on object existence.
224
+     *
225
+     * @since  1.0.19
226
+     * @return int
227
+     */
228
+    public function save() {
229
+        if ( ! $this->data_store ) {
230
+            return $this->get_id();
231
+        }
232
+
233
+        /**
234
+         * Trigger action before saving to the DB. Allows you to adjust object props before save.
235
+         *
236
+         * @param GetPaid_Data          $this The object being saved.
237
+         * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238
+         */
239
+        do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
240
+
241
+        if ( $this->get_id() ) {
242
+            $this->data_store->update( $this );
243
+        } else {
244
+            $this->data_store->create( $this );
245
+        }
246
+
247
+        /**
248
+         * Trigger action after saving to the DB.
249
+         *
250
+         * @param GetPaid_Data          $this The object being saved.
251
+         * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252
+         */
253
+        do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
254
+
255
+        return $this->get_id();
256
+    }
257
+
258
+    /**
259
+     * Change data to JSON format.
260
+     *
261
+     * @since  1.0.19
262
+     * @return string Data in JSON format.
263
+     */
264
+    public function __toString() {
265
+        return wp_json_encode( $this->get_data() );
266
+    }
267
+
268
+    /**
269
+     * Returns all data for this object.
270
+     *
271
+     * @since  1.0.19
272
+     * @return array
273
+     */
274
+    public function get_data() {
275
+        return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
276
+    }
277
+
278
+    /**
279
+     * Returns array of expected data keys for this object.
280
+     *
281
+     * @since   1.0.19
282
+     * @return array
283
+     */
284
+    public function get_data_keys() {
285
+        return array_keys( $this->data );
286
+    }
287
+
288
+    /**
289
+     * Returns all "extra" data keys for an object (for sub objects like item types).
290
+     *
291
+     * @since  1.0.19
292
+     * @return array
293
+     */
294
+    public function get_extra_data_keys() {
295
+        return array_keys( $this->extra_data );
296
+    }
297
+
298
+    /**
299
+     * Filter null meta values from array.
300
+     *
301
+     * @since  1.0.19
302
+     * @param mixed $meta Meta value to check.
303
+     * @return bool
304
+     */
305
+    protected function filter_null_meta( $meta ) {
306
+        return ! is_null( $meta->value );
307
+    }
308
+
309
+    /**
310
+     * Get All Meta Data.
311
+     *
312
+     * @since 1.0.19
313
+     * @return array of objects.
314
+     */
315
+    public function get_meta_data() {
316
+        $this->maybe_read_meta_data();
317
+        return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
318
+    }
319
+
320
+    /**
321
+     * Check if the key is an internal one.
322
+     *
323
+     * @since  1.0.19
324
+     * @param  string $key Key to check.
325
+     * @return bool   true if it's an internal key, false otherwise
326
+     */
327
+    protected function is_internal_meta_key( $key ) {
328
+        $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
329
+
330
+        if ( ! $internal_meta_key ) {
331
+            return false;
332
+        }
333
+
334
+        $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
335
+
336
+        if ( ! $has_setter_or_getter ) {
337
+            return false;
338
+        }
339
+
340
+        /* translators: %s: $key Key to check */
341
+        getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'invoicing' ), $key ), '1.0.19' );
342
+
343
+        return true;
344
+    }
345
+
346
+    /**
347
+     * Magic method for setting data fields.
348
+     *
349
+     * This method does not update custom fields in the database.
350
+     *
351
+     * @since 1.0.19
352
+     * @access public
353
+     *
354
+     */
355
+    public function __set( $key, $value ) {
356
+
357
+        if ( 'id' == strtolower( $key ) ) {
358
+            return $this->set_id( $value );
359
+        }
360
+
361
+        if ( method_exists( $this, "set_$key") ) {
362
+
363
+            /* translators: %s: $key Key to set */
364
+            getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' );
365
+
366
+            call_user_func( array( $this, "set_$key" ), $value );
367
+        } else {
368
+            $this->set_prop( $key, $value );
369
+        }
370
+
371
+    }
372
+
373
+    /**
374 374
      * Margic method for retrieving a property.
375 375
      */
376 376
     public function __get( $key ) {
@@ -378,10 +378,10 @@  discard block
 block discarded – undo
378 378
         // Check if we have a helper method for that.
379 379
         if ( method_exists( $this, 'get_' . $key ) ) {
380 380
 
381
-			if ( 'post_type' != $key ) {
382
-				/* translators: %s: $key Key to set */
383
-				getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' );
384
-			}
381
+            if ( 'post_type' != $key ) {
382
+                /* translators: %s: $key Key to set */
383
+                getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' );
384
+            }
385 385
 
386 386
             return call_user_func( array( $this, 'get_' . $key ) );
387 387
         }
@@ -391,514 +391,514 @@  discard block
 block discarded – undo
391 391
             return $this->post->$key;
392 392
         }
393 393
 
394
-		return $this->get_prop( $key );
395
-
396
-    }
397
-
398
-	/**
399
-	 * Get Meta Data by Key.
400
-	 *
401
-	 * @since  1.0.19
402
-	 * @param  string $key Meta Key.
403
-	 * @param  bool   $single return first found meta with key, or all with $key.
404
-	 * @param  string $context What the value is for. Valid values are view and edit.
405
-	 * @return mixed
406
-	 */
407
-	public function get_meta( $key = '', $single = true, $context = 'view' ) {
408
-
409
-		// Check if this is an internal meta key.
410
-		$_key = str_replace( '_wpinv', '', $key );
411
-		$_key = str_replace( 'wpinv', '', $_key );
412
-		if ( $this->is_internal_meta_key( $key ) ) {
413
-			$function = 'get_' . $_key;
414
-
415
-			if ( is_callable( array( $this, $function ) ) ) {
416
-				return $this->{$function}();
417
-			}
418
-		}
419
-
420
-		// Read the meta data if not yet read.
421
-		$this->maybe_read_meta_data();
422
-		$meta_data  = $this->get_meta_data();
423
-		$array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
424
-		$value      = $single ? '' : array();
425
-
426
-		if ( ! empty( $array_keys ) ) {
427
-			// We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
428
-			if ( $single ) {
429
-				$value = $meta_data[ current( $array_keys ) ]->value;
430
-			} else {
431
-				$value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
432
-			}
433
-		}
434
-
435
-		if ( 'view' === $context ) {
436
-			$value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
437
-		}
438
-
439
-		return $value;
440
-	}
441
-
442
-	/**
443
-	 * See if meta data exists, since get_meta always returns a '' or array().
444
-	 *
445
-	 * @since  1.0.19
446
-	 * @param  string $key Meta Key.
447
-	 * @return boolean
448
-	 */
449
-	public function meta_exists( $key = '' ) {
450
-		$this->maybe_read_meta_data();
451
-		$array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
452
-		return in_array( $key, $array_keys, true );
453
-	}
454
-
455
-	/**
456
-	 * Set all meta data from array.
457
-	 *
458
-	 * @since 1.0.19
459
-	 * @param array $data Key/Value pairs.
460
-	 */
461
-	public function set_meta_data( $data ) {
462
-		if ( ! empty( $data ) && is_array( $data ) ) {
463
-			$this->maybe_read_meta_data();
464
-			foreach ( $data as $meta ) {
465
-				$meta = (array) $meta;
466
-				if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
467
-					$this->meta_data[] = new GetPaid_Meta_Data(
468
-						array(
469
-							'id'    => $meta['id'],
470
-							'key'   => $meta['key'],
471
-							'value' => $meta['value'],
472
-						)
473
-					);
474
-				}
475
-			}
476
-		}
477
-	}
478
-
479
-	/**
480
-	 * Add meta data.
481
-	 *
482
-	 * @since 1.0.19
483
-	 *
484
-	 * @param string       $key Meta key.
485
-	 * @param string|array $value Meta value.
486
-	 * @param bool         $unique Should this be a unique key?.
487
-	 */
488
-	public function add_meta_data( $key, $value, $unique = false ) {
489
-		if ( $this->is_internal_meta_key( $key ) ) {
490
-			$function = 'set_' . $key;
491
-
492
-			if ( is_callable( array( $this, $function ) ) ) {
493
-				return $this->{$function}( $value );
494
-			}
495
-		}
496
-
497
-		$this->maybe_read_meta_data();
498
-		if ( $unique ) {
499
-			$this->delete_meta_data( $key );
500
-		}
501
-		$this->meta_data[] = new GetPaid_Meta_Data(
502
-			array(
503
-				'key'   => $key,
504
-				'value' => $value,
505
-			)
506
-		);
507
-
508
-		$this->save();
509
-	}
510
-
511
-	/**
512
-	 * Update meta data by key or ID, if provided.
513
-	 *
514
-	 * @since  1.0.19
515
-	 *
516
-	 * @param  string       $key Meta key.
517
-	 * @param  string|array $value Meta value.
518
-	 * @param  int          $meta_id Meta ID.
519
-	 */
520
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
521
-		if ( $this->is_internal_meta_key( $key ) ) {
522
-			$function = 'set_' . $key;
523
-
524
-			if ( is_callable( array( $this, $function ) ) ) {
525
-				return $this->{$function}( $value );
526
-			}
527
-		}
528
-
529
-		$this->maybe_read_meta_data();
530
-
531
-		$array_key = false;
532
-
533
-		if ( $meta_id ) {
534
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
535
-			$array_key  = $array_keys ? current( $array_keys ) : false;
536
-		} else {
537
-			// Find matches by key.
538
-			$matches = array();
539
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
540
-				if ( $meta->key === $key ) {
541
-					$matches[] = $meta_data_array_key;
542
-				}
543
-			}
544
-
545
-			if ( ! empty( $matches ) ) {
546
-				// Set matches to null so only one key gets the new value.
547
-				foreach ( $matches as $meta_data_array_key ) {
548
-					$this->meta_data[ $meta_data_array_key ]->value = null;
549
-				}
550
-				$array_key = current( $matches );
551
-			}
552
-		}
553
-
554
-		if ( false !== $array_key ) {
555
-			$meta        = $this->meta_data[ $array_key ];
556
-			$meta->key   = $key;
557
-			$meta->value = $value;
558
-		} else {
559
-			$this->add_meta_data( $key, $value, true );
560
-		}
561
-	}
562
-
563
-	/**
564
-	 * Delete meta data.
565
-	 *
566
-	 * @since 1.0.19
567
-	 * @param string $key Meta key.
568
-	 */
569
-	public function delete_meta_data( $key ) {
570
-		$this->maybe_read_meta_data();
571
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
572
-
573
-		if ( $array_keys ) {
574
-			foreach ( $array_keys as $array_key ) {
575
-				$this->meta_data[ $array_key ]->value = null;
576
-			}
577
-		}
578
-	}
579
-
580
-	/**
581
-	 * Delete meta data.
582
-	 *
583
-	 * @since 1.0.19
584
-	 * @param int $mid Meta ID.
585
-	 */
586
-	public function delete_meta_data_by_mid( $mid ) {
587
-		$this->maybe_read_meta_data();
588
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
589
-
590
-		if ( $array_keys ) {
591
-			foreach ( $array_keys as $array_key ) {
592
-				$this->meta_data[ $array_key ]->value = null;
593
-			}
594
-		}
595
-	}
596
-
597
-	/**
598
-	 * Read meta data if null.
599
-	 *
600
-	 * @since 1.0.19
601
-	 */
602
-	protected function maybe_read_meta_data() {
603
-		if ( is_null( $this->meta_data ) ) {
604
-			$this->read_meta_data();
605
-		}
606
-	}
607
-
608
-	/**
609
-	 * Read Meta Data from the database. Ignore any internal properties.
610
-	 * Uses it's own caches because get_metadata does not provide meta_ids.
611
-	 *
612
-	 * @since 1.0.19
613
-	 * @param bool $force_read True to force a new DB read (and update cache).
614
-	 */
615
-	public function read_meta_data( $force_read = false ) {
616
-
617
-		// Reset meta data.
618
-		$this->meta_data = array();
619
-
620
-		// Maybe abort early.
621
-		if ( ! $this->get_id() || ! $this->data_store ) {
622
-			return;
623
-		}
624
-
625
-		// Only read from cache if the cache key is set.
626
-		$cache_key = null;
627
-		if ( ! $force_read && ! empty( $this->cache_group ) ) {
628
-			$cache_key     = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
629
-			$raw_meta_data = wp_cache_get( $cache_key, $this->cache_group );
630
-		}
631
-
632
-		// Should we force read?
633
-		if ( empty( $raw_meta_data ) ) {
634
-			$raw_meta_data = $this->data_store->read_meta( $this );
635
-
636
-			if ( ! empty( $cache_key ) ) {
637
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
638
-			}
639
-
640
-		}
641
-
642
-		// Set meta data.
643
-		if ( is_array( $raw_meta_data ) ) {
644
-
645
-			foreach ( $raw_meta_data as $meta ) {
646
-				$this->meta_data[] = new GetPaid_Meta_Data(
647
-					array(
648
-						'id'    => (int) $meta->meta_id,
649
-						'key'   => $meta->meta_key,
650
-						'value' => maybe_unserialize( $meta->meta_value ),
651
-					)
652
-				);
653
-			}
654
-
655
-		}
656
-
657
-	}
658
-
659
-	/**
660
-	 * Update Meta Data in the database.
661
-	 *
662
-	 * @since 1.0.19
663
-	 */
664
-	public function save_meta_data() {
665
-		if ( ! $this->data_store || is_null( $this->meta_data ) ) {
666
-			return;
667
-		}
668
-		foreach ( $this->meta_data as $array_key => $meta ) {
669
-			if ( is_null( $meta->value ) ) {
670
-				if ( ! empty( $meta->id ) ) {
671
-					$this->data_store->delete_meta( $this, $meta );
672
-					unset( $this->meta_data[ $array_key ] );
673
-				}
674
-			} elseif ( empty( $meta->id ) ) {
675
-				$meta->id = $this->data_store->add_meta( $this, $meta );
676
-				$meta->apply_changes();
677
-			} else {
678
-				if ( $meta->get_changes() ) {
679
-					$this->data_store->update_meta( $this, $meta );
680
-					$meta->apply_changes();
681
-				}
682
-			}
683
-		}
684
-		if ( ! empty( $this->cache_group ) ) {
685
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
686
-			wp_cache_delete( $cache_key, $this->cache_group );
687
-		}
688
-	}
689
-
690
-	/**
691
-	 * Set ID.
692
-	 *
693
-	 * @since 1.0.19
694
-	 * @param int $id ID.
695
-	 */
696
-	public function set_id( $id ) {
697
-		$this->id = absint( $id );
698
-	}
699
-
700
-	/**
701
-	 * Sets item status.
702
-	 *
703
-	 * @since 1.0.19
704
-	 * @param string $status New status.
705
-	 * @return array details of change.
706
-	 */
707
-	public function set_status( $status ) {
394
+        return $this->get_prop( $key );
395
+
396
+    }
397
+
398
+    /**
399
+     * Get Meta Data by Key.
400
+     *
401
+     * @since  1.0.19
402
+     * @param  string $key Meta Key.
403
+     * @param  bool   $single return first found meta with key, or all with $key.
404
+     * @param  string $context What the value is for. Valid values are view and edit.
405
+     * @return mixed
406
+     */
407
+    public function get_meta( $key = '', $single = true, $context = 'view' ) {
408
+
409
+        // Check if this is an internal meta key.
410
+        $_key = str_replace( '_wpinv', '', $key );
411
+        $_key = str_replace( 'wpinv', '', $_key );
412
+        if ( $this->is_internal_meta_key( $key ) ) {
413
+            $function = 'get_' . $_key;
414
+
415
+            if ( is_callable( array( $this, $function ) ) ) {
416
+                return $this->{$function}();
417
+            }
418
+        }
419
+
420
+        // Read the meta data if not yet read.
421
+        $this->maybe_read_meta_data();
422
+        $meta_data  = $this->get_meta_data();
423
+        $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
424
+        $value      = $single ? '' : array();
425
+
426
+        if ( ! empty( $array_keys ) ) {
427
+            // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
428
+            if ( $single ) {
429
+                $value = $meta_data[ current( $array_keys ) ]->value;
430
+            } else {
431
+                $value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
432
+            }
433
+        }
434
+
435
+        if ( 'view' === $context ) {
436
+            $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
437
+        }
438
+
439
+        return $value;
440
+    }
441
+
442
+    /**
443
+     * See if meta data exists, since get_meta always returns a '' or array().
444
+     *
445
+     * @since  1.0.19
446
+     * @param  string $key Meta Key.
447
+     * @return boolean
448
+     */
449
+    public function meta_exists( $key = '' ) {
450
+        $this->maybe_read_meta_data();
451
+        $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
452
+        return in_array( $key, $array_keys, true );
453
+    }
454
+
455
+    /**
456
+     * Set all meta data from array.
457
+     *
458
+     * @since 1.0.19
459
+     * @param array $data Key/Value pairs.
460
+     */
461
+    public function set_meta_data( $data ) {
462
+        if ( ! empty( $data ) && is_array( $data ) ) {
463
+            $this->maybe_read_meta_data();
464
+            foreach ( $data as $meta ) {
465
+                $meta = (array) $meta;
466
+                if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
467
+                    $this->meta_data[] = new GetPaid_Meta_Data(
468
+                        array(
469
+                            'id'    => $meta['id'],
470
+                            'key'   => $meta['key'],
471
+                            'value' => $meta['value'],
472
+                        )
473
+                    );
474
+                }
475
+            }
476
+        }
477
+    }
478
+
479
+    /**
480
+     * Add meta data.
481
+     *
482
+     * @since 1.0.19
483
+     *
484
+     * @param string       $key Meta key.
485
+     * @param string|array $value Meta value.
486
+     * @param bool         $unique Should this be a unique key?.
487
+     */
488
+    public function add_meta_data( $key, $value, $unique = false ) {
489
+        if ( $this->is_internal_meta_key( $key ) ) {
490
+            $function = 'set_' . $key;
491
+
492
+            if ( is_callable( array( $this, $function ) ) ) {
493
+                return $this->{$function}( $value );
494
+            }
495
+        }
496
+
497
+        $this->maybe_read_meta_data();
498
+        if ( $unique ) {
499
+            $this->delete_meta_data( $key );
500
+        }
501
+        $this->meta_data[] = new GetPaid_Meta_Data(
502
+            array(
503
+                'key'   => $key,
504
+                'value' => $value,
505
+            )
506
+        );
507
+
508
+        $this->save();
509
+    }
510
+
511
+    /**
512
+     * Update meta data by key or ID, if provided.
513
+     *
514
+     * @since  1.0.19
515
+     *
516
+     * @param  string       $key Meta key.
517
+     * @param  string|array $value Meta value.
518
+     * @param  int          $meta_id Meta ID.
519
+     */
520
+    public function update_meta_data( $key, $value, $meta_id = 0 ) {
521
+        if ( $this->is_internal_meta_key( $key ) ) {
522
+            $function = 'set_' . $key;
523
+
524
+            if ( is_callable( array( $this, $function ) ) ) {
525
+                return $this->{$function}( $value );
526
+            }
527
+        }
528
+
529
+        $this->maybe_read_meta_data();
530
+
531
+        $array_key = false;
532
+
533
+        if ( $meta_id ) {
534
+            $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
535
+            $array_key  = $array_keys ? current( $array_keys ) : false;
536
+        } else {
537
+            // Find matches by key.
538
+            $matches = array();
539
+            foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
540
+                if ( $meta->key === $key ) {
541
+                    $matches[] = $meta_data_array_key;
542
+                }
543
+            }
544
+
545
+            if ( ! empty( $matches ) ) {
546
+                // Set matches to null so only one key gets the new value.
547
+                foreach ( $matches as $meta_data_array_key ) {
548
+                    $this->meta_data[ $meta_data_array_key ]->value = null;
549
+                }
550
+                $array_key = current( $matches );
551
+            }
552
+        }
553
+
554
+        if ( false !== $array_key ) {
555
+            $meta        = $this->meta_data[ $array_key ];
556
+            $meta->key   = $key;
557
+            $meta->value = $value;
558
+        } else {
559
+            $this->add_meta_data( $key, $value, true );
560
+        }
561
+    }
562
+
563
+    /**
564
+     * Delete meta data.
565
+     *
566
+     * @since 1.0.19
567
+     * @param string $key Meta key.
568
+     */
569
+    public function delete_meta_data( $key ) {
570
+        $this->maybe_read_meta_data();
571
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
572
+
573
+        if ( $array_keys ) {
574
+            foreach ( $array_keys as $array_key ) {
575
+                $this->meta_data[ $array_key ]->value = null;
576
+            }
577
+        }
578
+    }
579
+
580
+    /**
581
+     * Delete meta data.
582
+     *
583
+     * @since 1.0.19
584
+     * @param int $mid Meta ID.
585
+     */
586
+    public function delete_meta_data_by_mid( $mid ) {
587
+        $this->maybe_read_meta_data();
588
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
589
+
590
+        if ( $array_keys ) {
591
+            foreach ( $array_keys as $array_key ) {
592
+                $this->meta_data[ $array_key ]->value = null;
593
+            }
594
+        }
595
+    }
596
+
597
+    /**
598
+     * Read meta data if null.
599
+     *
600
+     * @since 1.0.19
601
+     */
602
+    protected function maybe_read_meta_data() {
603
+        if ( is_null( $this->meta_data ) ) {
604
+            $this->read_meta_data();
605
+        }
606
+    }
607
+
608
+    /**
609
+     * Read Meta Data from the database. Ignore any internal properties.
610
+     * Uses it's own caches because get_metadata does not provide meta_ids.
611
+     *
612
+     * @since 1.0.19
613
+     * @param bool $force_read True to force a new DB read (and update cache).
614
+     */
615
+    public function read_meta_data( $force_read = false ) {
616
+
617
+        // Reset meta data.
618
+        $this->meta_data = array();
619
+
620
+        // Maybe abort early.
621
+        if ( ! $this->get_id() || ! $this->data_store ) {
622
+            return;
623
+        }
624
+
625
+        // Only read from cache if the cache key is set.
626
+        $cache_key = null;
627
+        if ( ! $force_read && ! empty( $this->cache_group ) ) {
628
+            $cache_key     = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
629
+            $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group );
630
+        }
631
+
632
+        // Should we force read?
633
+        if ( empty( $raw_meta_data ) ) {
634
+            $raw_meta_data = $this->data_store->read_meta( $this );
635
+
636
+            if ( ! empty( $cache_key ) ) {
637
+                wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
638
+            }
639
+
640
+        }
641
+
642
+        // Set meta data.
643
+        if ( is_array( $raw_meta_data ) ) {
644
+
645
+            foreach ( $raw_meta_data as $meta ) {
646
+                $this->meta_data[] = new GetPaid_Meta_Data(
647
+                    array(
648
+                        'id'    => (int) $meta->meta_id,
649
+                        'key'   => $meta->meta_key,
650
+                        'value' => maybe_unserialize( $meta->meta_value ),
651
+                    )
652
+                );
653
+            }
654
+
655
+        }
656
+
657
+    }
658
+
659
+    /**
660
+     * Update Meta Data in the database.
661
+     *
662
+     * @since 1.0.19
663
+     */
664
+    public function save_meta_data() {
665
+        if ( ! $this->data_store || is_null( $this->meta_data ) ) {
666
+            return;
667
+        }
668
+        foreach ( $this->meta_data as $array_key => $meta ) {
669
+            if ( is_null( $meta->value ) ) {
670
+                if ( ! empty( $meta->id ) ) {
671
+                    $this->data_store->delete_meta( $this, $meta );
672
+                    unset( $this->meta_data[ $array_key ] );
673
+                }
674
+            } elseif ( empty( $meta->id ) ) {
675
+                $meta->id = $this->data_store->add_meta( $this, $meta );
676
+                $meta->apply_changes();
677
+            } else {
678
+                if ( $meta->get_changes() ) {
679
+                    $this->data_store->update_meta( $this, $meta );
680
+                    $meta->apply_changes();
681
+                }
682
+            }
683
+        }
684
+        if ( ! empty( $this->cache_group ) ) {
685
+            $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
686
+            wp_cache_delete( $cache_key, $this->cache_group );
687
+        }
688
+    }
689
+
690
+    /**
691
+     * Set ID.
692
+     *
693
+     * @since 1.0.19
694
+     * @param int $id ID.
695
+     */
696
+    public function set_id( $id ) {
697
+        $this->id = absint( $id );
698
+    }
699
+
700
+    /**
701
+     * Sets item status.
702
+     *
703
+     * @since 1.0.19
704
+     * @param string $status New status.
705
+     * @return array details of change.
706
+     */
707
+    public function set_status( $status ) {
708 708
         $old_status = $this->get_status();
709 709
 
710
-		$this->set_prop( 'status', $status );
711
-
712
-		return array(
713
-			'from' => $old_status,
714
-			'to'   => $status,
715
-		);
716
-    }
717
-
718
-	/**
719
-	 * Set all props to default values.
720
-	 *
721
-	 * @since 1.0.19
722
-	 */
723
-	public function set_defaults() {
724
-		$this->data    = $this->default_data;
725
-		$this->changes = array();
726
-		$this->set_object_read( false );
727
-	}
728
-
729
-	/**
730
-	 * Set object read property.
731
-	 *
732
-	 * @since 1.0.19
733
-	 * @param boolean $read Should read?.
734
-	 */
735
-	public function set_object_read( $read = true ) {
736
-		$this->object_read = (bool) $read;
737
-	}
738
-
739
-	/**
740
-	 * Get object read property.
741
-	 *
742
-	 * @since  1.0.19
743
-	 * @return boolean
744
-	 */
745
-	public function get_object_read() {
746
-		return (bool) $this->object_read;
747
-	}
748
-
749
-	/**
750
-	 * Set a collection of props in one go, collect any errors, and return the result.
751
-	 * Only sets using public methods.
752
-	 *
753
-	 * @since  1.0.19
754
-	 *
755
-	 * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
756
-	 * @param string $context In what context to run this.
757
-	 *
758
-	 * @return bool|WP_Error
759
-	 */
760
-	public function set_props( $props, $context = 'set' ) {
761
-		$errors = false;
762
-
763
-		foreach ( $props as $prop => $value ) {
764
-			try {
765
-				/**
766
-				 * Checks if the prop being set is allowed, and the value is not null.
767
-				 */
768
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
769
-					continue;
770
-				}
771
-				$setter = "set_$prop";
772
-
773
-				if ( is_callable( array( $this, $setter ) ) ) {
774
-					$this->{$setter}( $value );
775
-				}
776
-			} catch ( Exception $e ) {
777
-				if ( ! $errors ) {
778
-					$errors = new WP_Error();
779
-				}
780
-				$errors->add( $e->getCode(), $e->getMessage() );
781
-				$this->last_error = $e->getMessage();
782
-			}
783
-		}
784
-
785
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
786
-	}
787
-
788
-	/**
789
-	 * Sets a prop for a setter method.
790
-	 *
791
-	 * This stores changes in a special array so we can track what needs saving
792
-	 * the the DB later.
793
-	 *
794
-	 * @since 1.0.19
795
-	 * @param string $prop Name of prop to set.
796
-	 * @param mixed  $value Value of the prop.
797
-	 */
798
-	protected function set_prop( $prop, $value ) {
799
-		if ( array_key_exists( $prop, $this->data ) ) {
800
-			if ( true === $this->object_read ) {
801
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
802
-					$this->changes[ $prop ] = $value;
803
-				}
804
-			} else {
805
-				$this->data[ $prop ] = $value;
806
-			}
807
-		}
808
-	}
809
-
810
-	/**
811
-	 * Return data changes only.
812
-	 *
813
-	 * @since 1.0.19
814
-	 * @return array
815
-	 */
816
-	public function get_changes() {
817
-		return $this->changes;
818
-	}
819
-
820
-	/**
821
-	 * Merge changes with data and clear.
822
-	 *
823
-	 * @since 1.0.19
824
-	 */
825
-	public function apply_changes() {
826
-		$this->data    = array_replace( $this->data, $this->changes );
827
-		$this->changes = array();
828
-	}
829
-
830
-	/**
831
-	 * Prefix for action and filter hooks on data.
832
-	 *
833
-	 * @since  1.0.19
834
-	 * @return string
835
-	 */
836
-	protected function get_hook_prefix() {
837
-		return 'wpinv_get_' . $this->object_type . '_';
838
-	}
839
-
840
-	/**
841
-	 * Gets a prop for a getter method.
842
-	 *
843
-	 * Gets the value from either current pending changes, or the data itself.
844
-	 * Context controls what happens to the value before it's returned.
845
-	 *
846
-	 * @since  1.0.19
847
-	 * @param  string $prop Name of prop to get.
848
-	 * @param  string $context What the value is for. Valid values are view and edit.
849
-	 * @return mixed
850
-	 */
851
-	protected function get_prop( $prop, $context = 'view' ) {
852
-		$value = null;
853
-
854
-		if ( array_key_exists( $prop, $this->data ) ) {
855
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
856
-
857
-			if ( 'view' === $context ) {
858
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
859
-			}
860
-		}
861
-
862
-		return $value;
863
-	}
864
-
865
-	/**
866
-	 * Sets a date prop whilst handling formatting and datetime objects.
867
-	 *
868
-	 * @since 1.0.19
869
-	 * @param string         $prop Name of prop to set.
870
-	 * @param string|integer $value Value of the prop.
871
-	 */
872
-	protected function set_date_prop( $prop, $value ) {
873
-
874
-		if ( empty( $value ) ) {
875
-			$this->set_prop( $prop, null );
876
-			return;
877
-		}
878
-		$this->set_prop( $prop, $value );
879
-
880
-	}
881
-
882
-	/**
883
-	 * When invalid data is found, throw an exception unless reading from the DB.
884
-	 *
885
-	 * @since 1.0.19
886
-	 * @param string $code             Error code.
887
-	 * @param string $message          Error message.
888
-	 */
889
-	protected function error( $code, $message ) {
890
-		$this->last_error = $message;
891
-	}
892
-
893
-	/**
894
-	 * Checks if the object is saved in the database
895
-	 *
896
-	 * @since 1.0.19
897
-	 * @return bool
898
-	 */
899
-	public function exists() {
900
-		$id = $this->get_id();
901
-		return ! empty( $id );
902
-	}
710
+        $this->set_prop( 'status', $status );
711
+
712
+        return array(
713
+            'from' => $old_status,
714
+            'to'   => $status,
715
+        );
716
+    }
717
+
718
+    /**
719
+     * Set all props to default values.
720
+     *
721
+     * @since 1.0.19
722
+     */
723
+    public function set_defaults() {
724
+        $this->data    = $this->default_data;
725
+        $this->changes = array();
726
+        $this->set_object_read( false );
727
+    }
728
+
729
+    /**
730
+     * Set object read property.
731
+     *
732
+     * @since 1.0.19
733
+     * @param boolean $read Should read?.
734
+     */
735
+    public function set_object_read( $read = true ) {
736
+        $this->object_read = (bool) $read;
737
+    }
738
+
739
+    /**
740
+     * Get object read property.
741
+     *
742
+     * @since  1.0.19
743
+     * @return boolean
744
+     */
745
+    public function get_object_read() {
746
+        return (bool) $this->object_read;
747
+    }
748
+
749
+    /**
750
+     * Set a collection of props in one go, collect any errors, and return the result.
751
+     * Only sets using public methods.
752
+     *
753
+     * @since  1.0.19
754
+     *
755
+     * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
756
+     * @param string $context In what context to run this.
757
+     *
758
+     * @return bool|WP_Error
759
+     */
760
+    public function set_props( $props, $context = 'set' ) {
761
+        $errors = false;
762
+
763
+        foreach ( $props as $prop => $value ) {
764
+            try {
765
+                /**
766
+                 * Checks if the prop being set is allowed, and the value is not null.
767
+                 */
768
+                if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
769
+                    continue;
770
+                }
771
+                $setter = "set_$prop";
772
+
773
+                if ( is_callable( array( $this, $setter ) ) ) {
774
+                    $this->{$setter}( $value );
775
+                }
776
+            } catch ( Exception $e ) {
777
+                if ( ! $errors ) {
778
+                    $errors = new WP_Error();
779
+                }
780
+                $errors->add( $e->getCode(), $e->getMessage() );
781
+                $this->last_error = $e->getMessage();
782
+            }
783
+        }
784
+
785
+        return $errors && count( $errors->get_error_codes() ) ? $errors : true;
786
+    }
787
+
788
+    /**
789
+     * Sets a prop for a setter method.
790
+     *
791
+     * This stores changes in a special array so we can track what needs saving
792
+     * the the DB later.
793
+     *
794
+     * @since 1.0.19
795
+     * @param string $prop Name of prop to set.
796
+     * @param mixed  $value Value of the prop.
797
+     */
798
+    protected function set_prop( $prop, $value ) {
799
+        if ( array_key_exists( $prop, $this->data ) ) {
800
+            if ( true === $this->object_read ) {
801
+                if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
802
+                    $this->changes[ $prop ] = $value;
803
+                }
804
+            } else {
805
+                $this->data[ $prop ] = $value;
806
+            }
807
+        }
808
+    }
809
+
810
+    /**
811
+     * Return data changes only.
812
+     *
813
+     * @since 1.0.19
814
+     * @return array
815
+     */
816
+    public function get_changes() {
817
+        return $this->changes;
818
+    }
819
+
820
+    /**
821
+     * Merge changes with data and clear.
822
+     *
823
+     * @since 1.0.19
824
+     */
825
+    public function apply_changes() {
826
+        $this->data    = array_replace( $this->data, $this->changes );
827
+        $this->changes = array();
828
+    }
829
+
830
+    /**
831
+     * Prefix for action and filter hooks on data.
832
+     *
833
+     * @since  1.0.19
834
+     * @return string
835
+     */
836
+    protected function get_hook_prefix() {
837
+        return 'wpinv_get_' . $this->object_type . '_';
838
+    }
839
+
840
+    /**
841
+     * Gets a prop for a getter method.
842
+     *
843
+     * Gets the value from either current pending changes, or the data itself.
844
+     * Context controls what happens to the value before it's returned.
845
+     *
846
+     * @since  1.0.19
847
+     * @param  string $prop Name of prop to get.
848
+     * @param  string $context What the value is for. Valid values are view and edit.
849
+     * @return mixed
850
+     */
851
+    protected function get_prop( $prop, $context = 'view' ) {
852
+        $value = null;
853
+
854
+        if ( array_key_exists( $prop, $this->data ) ) {
855
+            $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
856
+
857
+            if ( 'view' === $context ) {
858
+                $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
859
+            }
860
+        }
861
+
862
+        return $value;
863
+    }
864
+
865
+    /**
866
+     * Sets a date prop whilst handling formatting and datetime objects.
867
+     *
868
+     * @since 1.0.19
869
+     * @param string         $prop Name of prop to set.
870
+     * @param string|integer $value Value of the prop.
871
+     */
872
+    protected function set_date_prop( $prop, $value ) {
873
+
874
+        if ( empty( $value ) ) {
875
+            $this->set_prop( $prop, null );
876
+            return;
877
+        }
878
+        $this->set_prop( $prop, $value );
879
+
880
+    }
881
+
882
+    /**
883
+     * When invalid data is found, throw an exception unless reading from the DB.
884
+     *
885
+     * @since 1.0.19
886
+     * @param string $code             Error code.
887
+     * @param string $message          Error message.
888
+     */
889
+    protected function error( $code, $message ) {
890
+        $this->last_error = $message;
891
+    }
892
+
893
+    /**
894
+     * Checks if the object is saved in the database
895
+     *
896
+     * @since 1.0.19
897
+     * @return bool
898
+     */
899
+    public function exists() {
900
+        $id = $this->get_id();
901
+        return ! empty( $id );
902
+    }
903 903
 
904 904
 }
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 1 patch
Indentation   +400 added lines, -400 removed lines patch added patch discarded remove patch
@@ -12,455 +12,455 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Invoice_Notification_Emails {
14 14
 
15
-	/**
16
-	 * The array of invoice email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $invoice_actions;
21
-
22
-	/**
23
-	 * Class constructor
24
-	 *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->invoice_actions = apply_filters(
29
-			'getpaid_notification_email_invoice_triggers',
30
-			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
-				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
-				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
-				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
-				'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
-				'getpaid_invoice_status_publish'        => 'completed_invoice',
37
-				'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
-				'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
-				'getpaid_new_customer_note'             => 'user_note',
40
-				'getpaid_daily_maintenance'             => 'overdue',
41
-			)
42
-		);
43
-
44
-		$this->init_hooks();
45
-
46
-	}
47
-
48
-	/**
49
-	 * Registers email hooks.
50
-	 */
51
-	public function init_hooks() {
52
-
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
-
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
58
-		}
59
-	}
60
-
61
-	/**
62
-	 * Registers an email hook for an invoice action.
63
-	 * 
64
-	 * @param string $hook
65
-	 * @param string|array $email_type
66
-	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
68
-
69
-		$email_type = wpinv_parse_list( $email_type );
70
-
71
-		foreach ( $email_type as $type ) {
72
-
73
-			$email = new GetPaid_Notification_Email( $type );
74
-
75
-			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
77
-				continue;
78
-			}
79
-
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
82
-				continue;
83
-			}
84
-
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
-		}
87
-
88
-	}
89
-
90
-	/**
91
-	 * Filters invoice merge tags.
92
-	 *
93
-	 * @param array $merge_tags
94
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
-	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
97
-
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
-			return array_merge(
100
-				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
102
-			);
103
-		}
104
-
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
-			return array_merge(
107
-				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
109
-			);
110
-		}
111
-
112
-		return $merge_tags;
113
-
114
-	}
115
-
116
-	/**
117
-	 * Generates invoice merge tags.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return array
121
-	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
123
-
124
-		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
126
-			return array();
127
-		}
128
-
129
-		$merge_tags = array(
130
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'               => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
-		);
149
-
150
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
151
-	}
152
-
153
-	/**
154
-	 * Helper function to send an email.
155
-	 *
156
-	 * @param WPInv_Invoice $invoice
157
-	 * @param GetPaid_Notification_Email $email
158
-	 * @param string $type
159
-	 * @param string|array $recipients
160
-	 * @param array $extra_args Extra template args.
161
-	 */
162
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
163
-
164
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
165
-
166
-		if ( apply_filters( 'getpaid_skip_invoice_email', false, $type, $invoice ) ) {
167
-			return;
168
-		}
169
-
170
-		$mailer     = new GetPaid_Notification_Email_Sender();
171
-		$merge_tags = $email->get_merge_tags();
172
-
173
-		$result = $mailer->send(
174
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
175
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
176
-			$email->get_content( $merge_tags, $extra_args ),
177
-			$email->get_attachments()
178
-		);
179
-
180
-		// Maybe send a copy to the admin.
181
-		if ( $email->include_admin_bcc() ) {
182
-			$mailer->send(
183
-				wpinv_get_admin_email(),
184
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
185
-				$email->get_content( $merge_tags ),
186
-				$email->get_attachments()
187
-			);
188
-		}
189
-
190
-		if ( $result ) {
191
-			$invoice->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
192
-		} else {
193
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );	
194
-		}
195
-
196
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
197
-
198
-		return $result;
199
-	}
200
-
201
-	/**
202
-	 * Also send emails to any cc users.
203
-	 *
204
-	 * @param array $recipients
205
-	 * @param GetPaid_Notification_Email $email
206
-	 */
207
-	public function filter_email_recipients( $recipients, $email ) {
208
-
209
-		if ( ! $email->is_admin_email() ) {
210
-			$cc = $email->object->get_email_cc();
211
-
212
-			if ( ! empty( $cc ) ) {
213
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
214
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
215
-			}
216
-
217
-		}
218
-
219
-		return $recipients;
220
-
221
-	}
222
-
223
-	/**
224
-	 * Sends a new invoice notification.
225
-	 *
226
-	 * @param WPInv_Invoice $invoice
227
-	 */
228
-	public function new_invoice( $invoice ) {
229
-
230
-		// Only send this email for invoices created via the admin page.
231
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
232
-			return;
233
-		}
234
-
235
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
236
-		$recipient = wpinv_get_admin_email();
237
-
238
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
239
-
240
-	}
241
-
242
-	/**
243
-	 * Sends a cancelled invoice notification.
244
-	 *
245
-	 * @param WPInv_Invoice $invoice
246
-	 */
247
-	public function cancelled_invoice( $invoice ) {
15
+    /**
16
+     * The array of invoice email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $invoice_actions;
21
+
22
+    /**
23
+     * Class constructor
24
+     *
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->invoice_actions = apply_filters(
29
+            'getpaid_notification_email_invoice_triggers',
30
+            array(
31
+                'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
+                'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
+                'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
+                'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
+                'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
+                'getpaid_invoice_status_publish'        => 'completed_invoice',
37
+                'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
+                'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
+                'getpaid_new_customer_note'             => 'user_note',
40
+                'getpaid_daily_maintenance'             => 'overdue',
41
+            )
42
+        );
43
+
44
+        $this->init_hooks();
45
+
46
+    }
47
+
48
+    /**
49
+     * Registers email hooks.
50
+     */
51
+    public function init_hooks() {
52
+
53
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
+        add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
+
56
+        foreach ( $this->invoice_actions as $hook => $email_type ) {
57
+            $this->init_email_type_hook( $hook, $email_type );
58
+        }
59
+    }
60
+
61
+    /**
62
+     * Registers an email hook for an invoice action.
63
+     * 
64
+     * @param string $hook
65
+     * @param string|array $email_type
66
+     */
67
+    public function init_email_type_hook( $hook, $email_type ) {
68
+
69
+        $email_type = wpinv_parse_list( $email_type );
70
+
71
+        foreach ( $email_type as $type ) {
72
+
73
+            $email = new GetPaid_Notification_Email( $type );
74
+
75
+            // Abort if it is not active.
76
+            if ( ! $email->is_active() ) {
77
+                continue;
78
+            }
79
+
80
+            if ( method_exists( $this, $type ) ) {
81
+                add_action( $hook, array( $this, $type ), 100, 2 );
82
+                continue;
83
+            }
84
+
85
+            do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
+        }
87
+
88
+    }
89
+
90
+    /**
91
+     * Filters invoice merge tags.
92
+     *
93
+     * @param array $merge_tags
94
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
+     */
96
+    public function invoice_merge_tags( $merge_tags, $object ) {
97
+
98
+        if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
+            return array_merge(
100
+                $merge_tags,
101
+                $this->get_invoice_merge_tags( $object )
102
+            );
103
+        }
104
+
105
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
+            return array_merge(
107
+                $merge_tags,
108
+                $this->get_invoice_merge_tags( $object->get_parent_payment() )
109
+            );
110
+        }
111
+
112
+        return $merge_tags;
113
+
114
+    }
115
+
116
+    /**
117
+     * Generates invoice merge tags.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return array
121
+     */
122
+    public function get_invoice_merge_tags( $invoice ) {
123
+
124
+        // Abort if it does not exist.
125
+        if ( ! $invoice->get_id() ) {
126
+            return array();
127
+        }
128
+
129
+        $merge_tags = array(
130
+            '{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
+            '{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
+            '{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
+            '{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
+            '{email}'               => sanitize_email( $invoice->get_email() ),
135
+            '{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
+            '{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
+            '{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
+            '{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
+            '{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
+            '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
+            '{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
+            '{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
+            '{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
+            '{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
+            '{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
+            '{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
+            '{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
+        );
149
+
150
+        return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
151
+    }
152
+
153
+    /**
154
+     * Helper function to send an email.
155
+     *
156
+     * @param WPInv_Invoice $invoice
157
+     * @param GetPaid_Notification_Email $email
158
+     * @param string $type
159
+     * @param string|array $recipients
160
+     * @param array $extra_args Extra template args.
161
+     */
162
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
163
+
164
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
165
+
166
+        if ( apply_filters( 'getpaid_skip_invoice_email', false, $type, $invoice ) ) {
167
+            return;
168
+        }
169
+
170
+        $mailer     = new GetPaid_Notification_Email_Sender();
171
+        $merge_tags = $email->get_merge_tags();
172
+
173
+        $result = $mailer->send(
174
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
175
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
176
+            $email->get_content( $merge_tags, $extra_args ),
177
+            $email->get_attachments()
178
+        );
179
+
180
+        // Maybe send a copy to the admin.
181
+        if ( $email->include_admin_bcc() ) {
182
+            $mailer->send(
183
+                wpinv_get_admin_email(),
184
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
185
+                $email->get_content( $merge_tags ),
186
+                $email->get_attachments()
187
+            );
188
+        }
189
+
190
+        if ( $result ) {
191
+            $invoice->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
192
+        } else {
193
+            $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );	
194
+        }
195
+
196
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
197
+
198
+        return $result;
199
+    }
200
+
201
+    /**
202
+     * Also send emails to any cc users.
203
+     *
204
+     * @param array $recipients
205
+     * @param GetPaid_Notification_Email $email
206
+     */
207
+    public function filter_email_recipients( $recipients, $email ) {
208
+
209
+        if ( ! $email->is_admin_email() ) {
210
+            $cc = $email->object->get_email_cc();
211
+
212
+            if ( ! empty( $cc ) ) {
213
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
214
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
215
+            }
216
+
217
+        }
218
+
219
+        return $recipients;
220
+
221
+    }
222
+
223
+    /**
224
+     * Sends a new invoice notification.
225
+     *
226
+     * @param WPInv_Invoice $invoice
227
+     */
228
+    public function new_invoice( $invoice ) {
229
+
230
+        // Only send this email for invoices created via the admin page.
231
+        if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
232
+            return;
233
+        }
234
+
235
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
236
+        $recipient = wpinv_get_admin_email();
237
+
238
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
239
+
240
+    }
241
+
242
+    /**
243
+     * Sends a cancelled invoice notification.
244
+     *
245
+     * @param WPInv_Invoice $invoice
246
+     */
247
+    public function cancelled_invoice( $invoice ) {
248 248
 
249
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
250
-		$recipient = wpinv_get_admin_email();
249
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
250
+        $recipient = wpinv_get_admin_email();
251 251
 
252
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
252
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
253 253
 
254
-	}
254
+    }
255 255
 
256
-	/**
257
-	 * Sends a failed invoice notification.
258
-	 *
259
-	 * @param WPInv_Invoice $invoice
260
-	 */
261
-	public function failed_invoice( $invoice ) {
256
+    /**
257
+     * Sends a failed invoice notification.
258
+     *
259
+     * @param WPInv_Invoice $invoice
260
+     */
261
+    public function failed_invoice( $invoice ) {
262 262
 
263
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
264
-		$recipient = wpinv_get_admin_email();
263
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
264
+        $recipient = wpinv_get_admin_email();
265 265
 
266
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
266
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
267 267
 
268
-	}
268
+    }
269 269
 
270
-	/**
271
-	 * Sends a notification whenever an invoice is put on hold.
272
-	 *
273
-	 * @param WPInv_Invoice $invoice
274
-	 */
275
-	public function onhold_invoice( $invoice ) {
270
+    /**
271
+     * Sends a notification whenever an invoice is put on hold.
272
+     *
273
+     * @param WPInv_Invoice $invoice
274
+     */
275
+    public function onhold_invoice( $invoice ) {
276 276
 
277
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
278
-		$recipient = $invoice->get_email();
277
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
278
+        $recipient = $invoice->get_email();
279 279
 
280
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
280
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
281 281
 
282
-	}
282
+    }
283 283
 
284
-	/**
285
-	 * Sends a notification whenever an invoice is marked as processing payment.
286
-	 *
287
-	 * @param WPInv_Invoice $invoice
288
-	 */
289
-	public function processing_invoice( $invoice ) {
284
+    /**
285
+     * Sends a notification whenever an invoice is marked as processing payment.
286
+     *
287
+     * @param WPInv_Invoice $invoice
288
+     */
289
+    public function processing_invoice( $invoice ) {
290 290
 
291
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
292
-		$recipient = $invoice->get_email();
291
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
292
+        $recipient = $invoice->get_email();
293 293
 
294
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
294
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
295 295
 
296
-	}
296
+    }
297 297
 
298
-	/**
299
-	 * Sends a notification whenever an invoice is paid.
300
-	 *
301
-	 * @param WPInv_Invoice $invoice
302
-	 */
303
-	public function completed_invoice( $invoice ) {
298
+    /**
299
+     * Sends a notification whenever an invoice is paid.
300
+     *
301
+     * @param WPInv_Invoice $invoice
302
+     */
303
+    public function completed_invoice( $invoice ) {
304 304
 
305
-		// (Maybe) abort if it is a renewal invoice.
306
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
307
-			return;
308
-		}
305
+        // (Maybe) abort if it is a renewal invoice.
306
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
307
+            return;
308
+        }
309 309
 
310
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
311
-		$recipient = $invoice->get_email();
310
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
311
+        $recipient = $invoice->get_email();
312 312
 
313
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
313
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
314 314
 
315
-	}
315
+    }
316 316
 
317
-	/**
318
-	 * Sends a notification whenever an invoice is refunded.
319
-	 *
320
-	 * @param WPInv_Invoice $invoice
321
-	 */
322
-	public function refunded_invoice( $invoice ) {
317
+    /**
318
+     * Sends a notification whenever an invoice is refunded.
319
+     *
320
+     * @param WPInv_Invoice $invoice
321
+     */
322
+    public function refunded_invoice( $invoice ) {
323 323
 
324
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
325
-		$recipient = $invoice->get_email();
324
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
325
+        $recipient = $invoice->get_email();
326 326
 
327
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
327
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
328 328
 
329
-	}
329
+    }
330 330
 
331
-	/**
332
-	 * Notifies a user about new invoices
333
-	 *
334
-	 * @param WPInv_Invoice $invoice
335
-	 * @param bool $force
336
-	 */
337
-	public function user_invoice( $invoice, $force = false ) {
331
+    /**
332
+     * Notifies a user about new invoices
333
+     *
334
+     * @param WPInv_Invoice $invoice
335
+     * @param bool $force
336
+     */
337
+    public function user_invoice( $invoice, $force = false ) {
338 338
 
339
-		if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
340
-			return;
341
-		}
339
+        if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
340
+            return;
341
+        }
342 342
 
343
-		// Only send this email for invoices created via the admin page.
344
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
345
-			return;
346
-		}
343
+        // Only send this email for invoices created via the admin page.
344
+        if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
345
+            return;
346
+        }
347 347
 
348
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
349
-		$recipient = $invoice->get_email();
348
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
349
+        $recipient = $invoice->get_email();
350 350
 
351
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
351
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
352 352
 
353
-	}
353
+    }
354 354
 
355
-	/**
356
-	 * Checks if an invoice is a payment form invoice.
357
-	 *
358
-	 * @param int $invoice
359
-	 * @return bool
360
-	 */
361
-	public function is_payment_form_invoice( $invoice ) {
362
-		return empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
363
-	}
355
+    /**
356
+     * Checks if an invoice is a payment form invoice.
357
+     *
358
+     * @param int $invoice
359
+     * @return bool
360
+     */
361
+    public function is_payment_form_invoice( $invoice ) {
362
+        return empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
363
+    }
364 364
 
365
-	/**
366
-	 * Notifies admin about new invoice notes
367
-	 *
368
-	 * @param WPInv_Invoice $invoice
369
-	 * @param string $note
370
-	 */
371
-	public function user_note( $invoice, $note ) {
372
-
373
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
374
-		$recipient = $invoice->get_email();
365
+    /**
366
+     * Notifies admin about new invoice notes
367
+     *
368
+     * @param WPInv_Invoice $invoice
369
+     * @param string $note
370
+     */
371
+    public function user_note( $invoice, $note ) {
372
+
373
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
374
+        $recipient = $invoice->get_email();
375 375
 
376
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
377
-
378
-	}
376
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
377
+
378
+    }
379 379
 
380
-	/**
381
-	 * (Force) Sends overdue notices.
382
-	 *
383
-	 * @param WPInv_Invoice $invoice
384
-	 */
385
-	public function force_send_overdue_notice( $invoice ) {
386
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
387
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
388
-	}
389
-
390
-	/**
391
-	 * Sends overdue notices.
392
-	 *
393
-	 * @TODO: Create an invoices query class.
394
-	 */
395
-	public function overdue() {
396
-		global $wpdb;
397
-
398
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
399
-
400
-		// Fetch reminder days.
401
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
402
-
403
-		// Abort if non is set.
404
-		if ( empty( $reminder_days ) ) {
405
-			return;
406
-		}
407
-
408
-		// Retrieve date query.
409
-		$date_query = $this->get_date_query( $reminder_days );
410
-
411
-		// Invoices table.
412
-		$table = $wpdb->prefix . 'getpaid_invoices';
413
-
414
-		// Fetch invoices.
415
-		$invoices  = $wpdb->get_col(
416
-			"SELECT posts.ID FROM $wpdb->posts as posts
380
+    /**
381
+     * (Force) Sends overdue notices.
382
+     *
383
+     * @param WPInv_Invoice $invoice
384
+     */
385
+    public function force_send_overdue_notice( $invoice ) {
386
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
387
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
388
+    }
389
+
390
+    /**
391
+     * Sends overdue notices.
392
+     *
393
+     * @TODO: Create an invoices query class.
394
+     */
395
+    public function overdue() {
396
+        global $wpdb;
397
+
398
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
399
+
400
+        // Fetch reminder days.
401
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
402
+
403
+        // Abort if non is set.
404
+        if ( empty( $reminder_days ) ) {
405
+            return;
406
+        }
407
+
408
+        // Retrieve date query.
409
+        $date_query = $this->get_date_query( $reminder_days );
410
+
411
+        // Invoices table.
412
+        $table = $wpdb->prefix . 'getpaid_invoices';
413
+
414
+        // Fetch invoices.
415
+        $invoices  = $wpdb->get_col(
416
+            "SELECT posts.ID FROM $wpdb->posts as posts
417 417
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
418 418
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
419 419
 
420
-		foreach ( $invoices as $invoice ) {
420
+        foreach ( $invoices as $invoice ) {
421 421
 
422
-			// Only send this email for invoices created via the admin page.
423
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
424
-				$invoice       = new WPInv_Invoice( $invoice );
425
-				$email->object = $invoice;
422
+            // Only send this email for invoices created via the admin page.
423
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
424
+                $invoice       = new WPInv_Invoice( $invoice );
425
+                $email->object = $invoice;
426 426
 
427
-				if ( $invoice->needs_payment() ) {
428
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
429
-				}
427
+                if ( $invoice->needs_payment() ) {
428
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
429
+                }
430 430
 
431
-			}
431
+            }
432 432
 
433
-		}
433
+        }
434 434
 
435
-	}
435
+    }
436 436
 
437
-	/**
438
-	 * Calculates the date query for an invoices query
439
-	 *
440
-	 * @param array $reminder_days
441
-	 * @return string
442
-	 */
443
-	public function get_date_query( $reminder_days ) {
437
+    /**
438
+     * Calculates the date query for an invoices query
439
+     *
440
+     * @param array $reminder_days
441
+     * @return string
442
+     */
443
+    public function get_date_query( $reminder_days ) {
444 444
 
445
-		$date_query = array(
446
-			'relation'  => 'OR'
447
-		);
445
+        $date_query = array(
446
+            'relation'  => 'OR'
447
+        );
448 448
 
449
-		foreach ( $reminder_days as $days ) {
450
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
449
+        foreach ( $reminder_days as $days ) {
450
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
451 451
 
452
-			$date_query[] = array(
453
-				'year'  => $date['year'],
454
-				'month' => $date['month'],
455
-				'day'   => $date['day'],
456
-			);
452
+            $date_query[] = array(
453
+                'year'  => $date['year'],
454
+                'month' => $date['month'],
455
+                'day'   => $date['day'],
456
+            );
457 457
 
458
-		}
458
+        }
459 459
 
460
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
460
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
461 461
 
462
-		return $date_query->get_sql();
462
+        return $date_query->get_sql();
463 463
 
464
-	}
464
+    }
465 465
 
466 466
 }
Please login to merge, or discard this patch.
includes/class-getpaid-subscription-notification-emails.php 1 patch
Indentation   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -13,288 +13,288 @@
 block discarded – undo
13 13
 class GetPaid_Subscription_Notification_Emails {
14 14
 
15 15
     /**
16
-	 * The array of subscription email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $subscription_actions;
16
+     * The array of subscription email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $subscription_actions;
21 21
 
22 22
     /**
23
-	 * Class constructor
23
+     * Class constructor
24 24
      *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->subscription_actions = apply_filters(
29
-			'getpaid_notification_email_subscription_triggers',
30
-			array(
31
-				'getpaid_subscription_trialling' => 'subscription_trial',
32
-				'getpaid_subscription_cancelled' => 'subscription_cancelled',
33
-				'getpaid_subscription_expired'   => 'subscription_expired',
34
-				'getpaid_subscription_completed' => 'subscription_complete',
35
-				'getpaid_daily_maintenance'      => 'renewal_reminder',
36
-			)
37
-		);
38
-
39
-		$this->init_hooks();
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->subscription_actions = apply_filters(
29
+            'getpaid_notification_email_subscription_triggers',
30
+            array(
31
+                'getpaid_subscription_trialling' => 'subscription_trial',
32
+                'getpaid_subscription_cancelled' => 'subscription_cancelled',
33
+                'getpaid_subscription_expired'   => 'subscription_expired',
34
+                'getpaid_subscription_completed' => 'subscription_complete',
35
+                'getpaid_daily_maintenance'      => 'renewal_reminder',
36
+            )
37
+        );
38
+
39
+        $this->init_hooks();
40 40
 
41 41
     }
42 42
 
43 43
     /**
44
-	 * Registers email hooks.
45
-	 */
46
-	public function init_hooks() {
47
-
48
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 );
49
-		foreach ( $this->subscription_actions as $hook => $email_type ) {
50
-
51
-			$email = new GetPaid_Notification_Email( $email_type );
52
-
53
-			if ( ! $email->is_active() ) {
54
-				continue;
55
-			}
56
-
57
-			if ( method_exists( $this, $email_type ) ) {
58
-				add_action( $hook, array( $this, $email_type ), 100, 2 );
59
-				continue;
60
-			}
61
-
62
-			do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook );
63
-
64
-		}
65
-
66
-	}
67
-
68
-	/**
69
-	 * Filters subscription merge tags.
70
-	 *
71
-	 * @param array $merge_tags
72
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
73
-	 */
74
-	public function subscription_merge_tags( $merge_tags, $object ) {
75
-
76
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
77
-			$merge_tags = array_merge(
78
-				$merge_tags,
79
-				$this->get_subscription_merge_tags( $object )
80
-			);
81
-		}
82
-
83
-		return $merge_tags;
84
-
85
-	}
86
-
87
-	/**
88
-	 * Generates subscription merge tags.
89
-	 *
90
-	 * @param WPInv_Subscription $subscription
91
-	 * @return array
92
-	 */
93
-	public function get_subscription_merge_tags( $subscription ) {
94
-
95
-		// Abort if it does not exist.
96
-		if ( ! $subscription->get_id() ) {
97
-			return array();
98
-		}
99
-
100
-		$invoice    = $subscription->get_parent_invoice();
101
-		return array(
102
-			'{subscription_renewal_date}'     => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ),
103
-			'{subscription_created}'          => getpaid_format_date_value( $subscription->get_date_created() ),
104
-			'{subscription_status}'           => sanitize_text_field( $subscription->get_status_label() ),
105
-			'{subscription_profile_id}'       => sanitize_text_field( $subscription->get_profile_id() ),
106
-			'{subscription_id}'               => absint( $subscription->get_id() ),
107
-			'{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ),
108
-			'{subscription_initial_amount}'   => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ),
109
-			'{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ),
110
-			'{subscription_bill_times}'       => $subscription->get_bill_times(),
111
-			'{subscription_url}'              => esc_url( $subscription->get_view_url() ),
112
-		);
113
-
114
-	}
115
-
116
-	/**
117
-	 * Checks if we should send a notification for a subscription.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return bool
121
-	 */
122
-	public function should_send_notification( $invoice ) {
123
-		return 0 != $invoice->get_id();
124
-	}
125
-
126
-	/**
127
-	 * Returns notification recipients.
128
-	 *
129
-	 * @param WPInv_Invoice $invoice
130
-	 * @return array
131
-	 */
132
-	public function get_recipients( $invoice ) {
133
-		$recipients = array( $invoice->get_email() );
134
-
135
-		$cc = $invoice->get_email_cc();
136
-
137
-		if ( ! empty( $cc ) ) {
138
-			$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
139
-			$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
140
-		}
141
-
142
-		return $recipients;
143
-	}
144
-
145
-	/**
146
-	 * Helper function to send an email.
147
-	 *
148
-	 * @param WPInv_Subscription $subscription
149
-	 * @param GetPaid_Notification_Email $email
150
-	 * @param string $type
151
-	 * @param array $extra_args Extra template args.
152
-	 */
153
-	public function send_email( $subscription, $email, $type, $extra_args = array() ) {
154
-
155
-		// Abort in case the parent invoice does not exist.
156
-		$invoice = $subscription->get_parent_invoice();
157
-		if ( ! $this->should_send_notification( $invoice ) ) {
158
-			return;
159
-		}
160
-
161
-		if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) {
162
-			return;
163
-		}
164
-
165
-		do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
166
-
167
-		$recipients  = $this->get_recipients( $invoice );
168
-		$mailer      = new GetPaid_Notification_Email_Sender();
169
-		$merge_tags  = $email->get_merge_tags();
170
-		$content     = $email->get_content( $merge_tags, $extra_args );
171
-		$subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
172
-		$attachments = $email->get_attachments();
173
-
174
-		$result = $mailer->send(
175
-			apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
176
-			$subject,
177
-			$content,
178
-			$attachments
179
-		);
180
-
181
-		// Maybe send a copy to the admin.
182
-		if ( $email->include_admin_bcc() ) {
183
-			$mailer->send(
184
-				wpinv_get_admin_email(),
185
-				$subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
186
-				$content,
187
-				$attachments
188
-			);
189
-		}
190
-
191
-		if ( $result ) {
192
-			$subscription->get_parent_invoice()->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
193
-		} else {
194
-			$subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
195
-		}
196
-
197
-		do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
198
-
199
-	}
44
+     * Registers email hooks.
45
+     */
46
+    public function init_hooks() {
47
+
48
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 );
49
+        foreach ( $this->subscription_actions as $hook => $email_type ) {
50
+
51
+            $email = new GetPaid_Notification_Email( $email_type );
52
+
53
+            if ( ! $email->is_active() ) {
54
+                continue;
55
+            }
56
+
57
+            if ( method_exists( $this, $email_type ) ) {
58
+                add_action( $hook, array( $this, $email_type ), 100, 2 );
59
+                continue;
60
+            }
61
+
62
+            do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook );
63
+
64
+        }
65
+
66
+    }
200 67
 
201 68
     /**
202
-	 * Sends a new trial notification.
203
-	 *
204
-	 * @param WPInv_Subscription $subscription
205
-	 */
206
-	public function subscription_trial( $subscription ) {
69
+     * Filters subscription merge tags.
70
+     *
71
+     * @param array $merge_tags
72
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
73
+     */
74
+    public function subscription_merge_tags( $merge_tags, $object ) {
207 75
 
208
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
209
-		$this->send_email( $subscription, $email, __FUNCTION__ );
76
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
77
+            $merge_tags = array_merge(
78
+                $merge_tags,
79
+                $this->get_subscription_merge_tags( $object )
80
+            );
81
+        }
210 82
 
211
-	}
83
+        return $merge_tags;
212 84
 
213
-	/**
214
-	 * Sends a cancelled subscription notification.
215
-	 *
216
-	 * @param WPInv_Subscription $subscription
217
-	 */
218
-	public function subscription_cancelled( $subscription ) {
85
+    }
219 86
 
220
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
221
-		$this->send_email( $subscription, $email, __FUNCTION__ );
87
+    /**
88
+     * Generates subscription merge tags.
89
+     *
90
+     * @param WPInv_Subscription $subscription
91
+     * @return array
92
+     */
93
+    public function get_subscription_merge_tags( $subscription ) {
94
+
95
+        // Abort if it does not exist.
96
+        if ( ! $subscription->get_id() ) {
97
+            return array();
98
+        }
99
+
100
+        $invoice    = $subscription->get_parent_invoice();
101
+        return array(
102
+            '{subscription_renewal_date}'     => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ),
103
+            '{subscription_created}'          => getpaid_format_date_value( $subscription->get_date_created() ),
104
+            '{subscription_status}'           => sanitize_text_field( $subscription->get_status_label() ),
105
+            '{subscription_profile_id}'       => sanitize_text_field( $subscription->get_profile_id() ),
106
+            '{subscription_id}'               => absint( $subscription->get_id() ),
107
+            '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ),
108
+            '{subscription_initial_amount}'   => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ),
109
+            '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ),
110
+            '{subscription_bill_times}'       => $subscription->get_bill_times(),
111
+            '{subscription_url}'              => esc_url( $subscription->get_view_url() ),
112
+        );
222 113
 
223
-	}
114
+    }
224 115
 
225
-	/**
226
-	 * Sends a subscription expired notification.
227
-	 *
228
-	 * @param WPInv_Subscription $subscription
229
-	 */
230
-	public function subscription_expired( $subscription ) {
116
+    /**
117
+     * Checks if we should send a notification for a subscription.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return bool
121
+     */
122
+    public function should_send_notification( $invoice ) {
123
+        return 0 != $invoice->get_id();
124
+    }
231 125
 
232
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
233
-		$this->send_email( $subscription, $email, __FUNCTION__ );
126
+    /**
127
+     * Returns notification recipients.
128
+     *
129
+     * @param WPInv_Invoice $invoice
130
+     * @return array
131
+     */
132
+    public function get_recipients( $invoice ) {
133
+        $recipients = array( $invoice->get_email() );
234 134
 
235
-	}
135
+        $cc = $invoice->get_email_cc();
236 136
 
237
-	/**
238
-	 * Sends a completed subscription notification.
239
-	 *
240
-	 * @param WPInv_Subscription $subscription
241
-	 */
242
-	public function subscription_complete( $subscription ) {
137
+        if ( ! empty( $cc ) ) {
138
+            $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
139
+            $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
140
+        }
243 141
 
244
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
245
-		$this->send_email( $subscription, $email, __FUNCTION__ );
142
+        return $recipients;
143
+    }
246 144
 
247
-	}
145
+    /**
146
+     * Helper function to send an email.
147
+     *
148
+     * @param WPInv_Subscription $subscription
149
+     * @param GetPaid_Notification_Email $email
150
+     * @param string $type
151
+     * @param array $extra_args Extra template args.
152
+     */
153
+    public function send_email( $subscription, $email, $type, $extra_args = array() ) {
154
+
155
+        // Abort in case the parent invoice does not exist.
156
+        $invoice = $subscription->get_parent_invoice();
157
+        if ( ! $this->should_send_notification( $invoice ) ) {
158
+            return;
159
+        }
160
+
161
+        if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) {
162
+            return;
163
+        }
164
+
165
+        do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
166
+
167
+        $recipients  = $this->get_recipients( $invoice );
168
+        $mailer      = new GetPaid_Notification_Email_Sender();
169
+        $merge_tags  = $email->get_merge_tags();
170
+        $content     = $email->get_content( $merge_tags, $extra_args );
171
+        $subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
172
+        $attachments = $email->get_attachments();
173
+
174
+        $result = $mailer->send(
175
+            apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
176
+            $subject,
177
+            $content,
178
+            $attachments
179
+        );
180
+
181
+        // Maybe send a copy to the admin.
182
+        if ( $email->include_admin_bcc() ) {
183
+            $mailer->send(
184
+                wpinv_get_admin_email(),
185
+                $subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
186
+                $content,
187
+                $attachments
188
+            );
189
+        }
190
+
191
+        if ( $result ) {
192
+            $subscription->get_parent_invoice()->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
193
+        } else {
194
+            $subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
195
+        }
196
+
197
+        do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
248 198
 
249
-	/**
250
-	 * Sends a subscription renewal reminder notification.
251
-	 *
252
-	 */
253
-	public function renewal_reminder() {
199
+    }
254 200
 
255
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
201
+    /**
202
+     * Sends a new trial notification.
203
+     *
204
+     * @param WPInv_Subscription $subscription
205
+     */
206
+    public function subscription_trial( $subscription ) {
256 207
 
257
-		// Fetch reminder days.
258
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
208
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
209
+        $this->send_email( $subscription, $email, __FUNCTION__ );
259 210
 
260
-		// Abort if non is set.
261
-		if ( empty( $reminder_days ) ) {
262
-			return;
263
-		}
211
+    }
264 212
 
265
-		// Fetch matching subscriptions.
213
+    /**
214
+     * Sends a cancelled subscription notification.
215
+     *
216
+     * @param WPInv_Subscription $subscription
217
+     */
218
+    public function subscription_cancelled( $subscription ) {
219
+
220
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
221
+        $this->send_email( $subscription, $email, __FUNCTION__ );
222
+
223
+    }
224
+
225
+    /**
226
+     * Sends a subscription expired notification.
227
+     *
228
+     * @param WPInv_Subscription $subscription
229
+     */
230
+    public function subscription_expired( $subscription ) {
231
+
232
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
233
+        $this->send_email( $subscription, $email, __FUNCTION__ );
234
+
235
+    }
236
+
237
+    /**
238
+     * Sends a completed subscription notification.
239
+     *
240
+     * @param WPInv_Subscription $subscription
241
+     */
242
+    public function subscription_complete( $subscription ) {
243
+
244
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
245
+        $this->send_email( $subscription, $email, __FUNCTION__ );
246
+
247
+    }
248
+
249
+    /**
250
+     * Sends a subscription renewal reminder notification.
251
+     *
252
+     */
253
+    public function renewal_reminder() {
254
+
255
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
256
+
257
+        // Fetch reminder days.
258
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
259
+
260
+        // Abort if non is set.
261
+        if ( empty( $reminder_days ) ) {
262
+            return;
263
+        }
264
+
265
+        // Fetch matching subscriptions.
266 266
         $args  = array(
267 267
             'number'             => -1,
268
-			'count_total'        => false,
269
-			'status'             => 'trialling active',
268
+            'count_total'        => false,
269
+            'status'             => 'trialling active',
270 270
             'date_expires_query' => array(
271
-				'relation'  => 'OR'
271
+                'relation'  => 'OR'
272 272
             ),
273
-		);
273
+        );
274 274
 
275
-		foreach ( $reminder_days as $days ) {
276
-			$date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
275
+        foreach ( $reminder_days as $days ) {
276
+            $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
277 277
 
278
-			$args['date_expires_query'][] = array(
279
-				'year'  => $date['year'],
280
-				'month' => $date['month'],
281
-				'day'   => $date['day'],
282
-			);
278
+            $args['date_expires_query'][] = array(
279
+                'year'  => $date['year'],
280
+                'month' => $date['month'],
281
+                'day'   => $date['day'],
282
+            );
283 283
 
284
-		}
284
+        }
285 285
 
286
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
286
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
287 287
 
288 288
         foreach ( $subscriptions as $subscription ) {
289 289
 
290
-			// Skip packages.
291
-			if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) {
292
-				$email->object = $subscription;
293
-            	$this->send_email( $subscription, $email, __FUNCTION__ );
294
-			}
290
+            // Skip packages.
291
+            if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) {
292
+                $email->object = $subscription;
293
+                $this->send_email( $subscription, $email, __FUNCTION__ );
294
+            }
295 295
 
296
-		}
296
+        }
297 297
 
298
-	}
298
+    }
299 299
 
300 300
 }
Please login to merge, or discard this patch.
includes/admin/subscriptions.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
  */
15 15
 function wpinv_subscriptions_page() {
16 16
 
17
-	?>
17
+    ?>
18 18
 
19 19
 	<div class="wrap">
20 20
 		<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
@@ -22,27 +22,27 @@  discard block
 block discarded – undo
22 22
 
23 23
 			<?php
24 24
 
25
-				// Verify user permissions.
26
-				if ( ! wpinv_current_user_can_manage_invoicing() ) {
25
+                // Verify user permissions.
26
+                if ( ! wpinv_current_user_can_manage_invoicing() ) {
27 27
 
28
-					echo aui()->alert(
29
-						array(
30
-							'type'    => 'danger',
31
-							'content' => __( 'You are not permitted to view this page.', 'invoicing' ),
32
-						)
33
-					);
28
+                    echo aui()->alert(
29
+                        array(
30
+                            'type'    => 'danger',
31
+                            'content' => __( 'You are not permitted to view this page.', 'invoicing' ),
32
+                        )
33
+                    );
34 34
 
35
-				} else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
35
+                } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
36 36
 
37
-					// Display a single subscription.
38
-					wpinv_recurring_subscription_details();
39
-				} else {
37
+                    // Display a single subscription.
38
+                    wpinv_recurring_subscription_details();
39
+                } else {
40 40
 
41
-					// Display a list of available subscriptions.
42
-					getpaid_print_subscriptions_list();
43
-				}
41
+                    // Display a list of available subscriptions.
42
+                    getpaid_print_subscriptions_list();
43
+                }
44 44
 
45
-			?>
45
+            ?>
46 46
 
47 47
 		</div>
48 48
 	</div>
@@ -59,10 +59,10 @@  discard block
 block discarded – undo
59 59
  */
60 60
 function getpaid_print_subscriptions_list() {
61 61
 
62
-	$subscribers_table = new WPInv_Subscriptions_List_Table();
63
-	$subscribers_table->prepare_items();
62
+    $subscribers_table = new WPInv_Subscriptions_List_Table();
63
+    $subscribers_table->prepare_items();
64 64
 
65
-	?>
65
+    ?>
66 66
 	<form id="subscribers-filter" class="bsui" method="get">
67 67
 		<input type="hidden" name="page" value="wpinv-subscriptions" />
68 68
 		<?php $subscribers_table->views(); ?>
@@ -80,27 +80,27 @@  discard block
 block discarded – undo
80 80
  */
81 81
 function wpinv_recurring_subscription_details() {
82 82
 
83
-	// Fetch the subscription.
84
-	$sub = new WPInv_Subscription( (int) $_GET['id'] );
85
-	if ( ! $sub->get_id() ) {
83
+    // Fetch the subscription.
84
+    $sub = new WPInv_Subscription( (int) $_GET['id'] );
85
+    if ( ! $sub->get_id() ) {
86 86
 
87
-		echo aui()->alert(
88
-			array(
89
-				'type'    => 'danger',
90
-				'content' => __( 'Subscription not found.', 'invoicing' ),
91
-			)
92
-		);
87
+        echo aui()->alert(
88
+            array(
89
+                'type'    => 'danger',
90
+                'content' => __( 'Subscription not found.', 'invoicing' ),
91
+            )
92
+        );
93 93
 
94
-		return;
95
-	}
94
+        return;
95
+    }
96 96
 
97
-	// Use metaboxes to display the subscription details.
98
-	add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' );
99
-	add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
100
-	add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
101
-	do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
97
+    // Use metaboxes to display the subscription details.
98
+    add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' );
99
+    add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
100
+    add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
101
+    do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
102 102
 
103
-	?>
103
+    ?>
104 104
 
105 105
 		<form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>">
106 106
 
@@ -140,41 +140,41 @@  discard block
 block discarded – undo
140 140
  */
141 141
 function getpaid_admin_subscription_details_metabox( $sub ) {
142 142
 
143
-	// Prepare subscription detail columns.
144
-	$fields = apply_filters(
145
-		'getpaid_subscription_admin_page_fields',
146
-		array(
147
-			'subscription'   => __( 'Subscription', 'invoicing' ),
148
-			'customer'       => __( 'Customer', 'invoicing' ),
149
-			'amount'         => __( 'Amount', 'invoicing' ),
150
-			'start_date'     => __( 'Start Date', 'invoicing' ),
151
-			'renews_on'      => __( 'Next Payment', 'invoicing' ),
152
-			'renewals'       => __( 'Payments', 'invoicing' ),
153
-			'item'           => __( 'Item', 'invoicing' ),
154
-			'gateway'        => __( 'Payment Method', 'invoicing' ),
155
-			'profile_id'     => __( 'Profile ID', 'invoicing' ),
156
-			'status'         => __( 'Status', 'invoicing' ),
157
-		)
158
-	);
159
-
160
-	if ( ! $sub->is_active() ) {
161
-
162
-		if ( isset( $fields['renews_on'] ) ) {
163
-			unset( $fields['renews_on'] );
164
-		}
165
-
166
-		if ( isset( $fields['gateway'] ) ) {
167
-			unset( $fields['gateway'] );
168
-		}
143
+    // Prepare subscription detail columns.
144
+    $fields = apply_filters(
145
+        'getpaid_subscription_admin_page_fields',
146
+        array(
147
+            'subscription'   => __( 'Subscription', 'invoicing' ),
148
+            'customer'       => __( 'Customer', 'invoicing' ),
149
+            'amount'         => __( 'Amount', 'invoicing' ),
150
+            'start_date'     => __( 'Start Date', 'invoicing' ),
151
+            'renews_on'      => __( 'Next Payment', 'invoicing' ),
152
+            'renewals'       => __( 'Payments', 'invoicing' ),
153
+            'item'           => __( 'Item', 'invoicing' ),
154
+            'gateway'        => __( 'Payment Method', 'invoicing' ),
155
+            'profile_id'     => __( 'Profile ID', 'invoicing' ),
156
+            'status'         => __( 'Status', 'invoicing' ),
157
+        )
158
+    );
159
+
160
+    if ( ! $sub->is_active() ) {
161
+
162
+        if ( isset( $fields['renews_on'] ) ) {
163
+            unset( $fields['renews_on'] );
164
+        }
165
+
166
+        if ( isset( $fields['gateway'] ) ) {
167
+            unset( $fields['gateway'] );
168
+        }
169 169
 		
170
-	}
170
+    }
171 171
 
172
-	$profile_id = $sub->get_profile_id();
173
-	if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
174
-		unset( $fields['profile_id'] );
175
-	}
172
+    $profile_id = $sub->get_profile_id();
173
+    if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
174
+        unset( $fields['profile_id'] );
175
+    }
176 176
 
177
-	?>
177
+    ?>
178 178
 
179 179
 		<table class="table table-borderless" style="font-size: 14px;">
180 180
 			<tbody>
@@ -208,20 +208,20 @@  discard block
 block discarded – undo
208 208
  */
209 209
 function getpaid_admin_subscription_metabox_display_customer( $subscription ) {
210 210
 
211
-	$username = __( '(Missing User)', 'invoicing' );
211
+    $username = __( '(Missing User)', 'invoicing' );
212 212
 
213
-	$user = get_userdata( $subscription->get_customer_id() );
214
-	if ( $user ) {
213
+    $user = get_userdata( $subscription->get_customer_id() );
214
+    if ( $user ) {
215 215
 
216
-		$username = sprintf(
217
-			'<a href="user-edit.php?user_id=%s">%s</a>',
218
-			absint( $user->ID ),
219
-			! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
220
-		);
216
+        $username = sprintf(
217
+            '<a href="user-edit.php?user_id=%s">%s</a>',
218
+            absint( $user->ID ),
219
+            ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
220
+        );
221 221
 
222
-	}
222
+    }
223 223
 
224
-	echo  $username;
224
+    echo  $username;
225 225
 }
226 226
 add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' );
227 227
 
@@ -231,8 +231,8 @@  discard block
 block discarded – undo
231 231
  * @param WPInv_Subscription $subscription
232 232
  */
233 233
 function getpaid_admin_subscription_metabox_display_amount( $subscription ) {
234
-	$amount    = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) );
235
-	echo "<span>$amount</span>";
234
+    $amount    = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) );
235
+    echo "<span>$amount</span>";
236 236
 }
237 237
 add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' );
238 238
 
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
  * @param WPInv_Subscription $subscription
243 243
  */
244 244
 function getpaid_admin_subscription_metabox_display_id( $subscription ) {
245
-	echo  '#' . absint( $subscription->get_id() );
245
+    echo  '#' . absint( $subscription->get_id() );
246 246
 }
247 247
 add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' );
248 248
 
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
  * @param WPInv_Subscription $subscription
253 253
  */
254 254
 function getpaid_admin_subscription_metabox_display_start_date( $subscription ) {
255
-	echo getpaid_format_date_value( $subscription->get_date_created() );
255
+    echo getpaid_format_date_value( $subscription->get_date_created() );
256 256
 }
257 257
 add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' );
258 258
 
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
  * @param WPInv_Subscription $subscription
263 263
  */
264 264
 function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) {
265
-	echo getpaid_format_date_value( $subscription->get_expiration() );
265
+    echo getpaid_format_date_value( $subscription->get_expiration() );
266 266
 }
267 267
 add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' );
268 268
 
@@ -272,8 +272,8 @@  discard block
 block discarded – undo
272 272
  * @param WPInv_Subscription $subscription
273 273
  */
274 274
 function getpaid_admin_subscription_metabox_display_renewals( $subscription ) {
275
-	$max_bills = $subscription->get_bill_times();
276
-	echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
275
+    $max_bills = $subscription->get_bill_times();
276
+    echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
277 277
 }
278 278
 add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' );
279 279
 /**
@@ -283,16 +283,16 @@  discard block
 block discarded – undo
283 283
  */
284 284
 function getpaid_admin_subscription_metabox_display_item( $subscription ) {
285 285
 
286
-	$item = get_post( $subscription->get_product_id() );
286
+    $item = get_post( $subscription->get_product_id() );
287 287
 
288
-	if ( ! empty( $item ) ) {
289
-		$link = get_edit_post_link( $item );
290
-		$link = esc_url( $link );
291
-		$name = esc_html( get_the_title( $item ) );
292
-		echo "<a href='$link'>$name</a>";
293
-	} else {
294
-		echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() );
295
-	}
288
+    if ( ! empty( $item ) ) {
289
+        $link = get_edit_post_link( $item );
290
+        $link = esc_url( $link );
291
+        $name = esc_html( get_the_title( $item ) );
292
+        echo "<a href='$link'>$name</a>";
293
+    } else {
294
+        echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() );
295
+    }
296 296
 
297 297
 }
298 298
 add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item' );
@@ -304,13 +304,13 @@  discard block
 block discarded – undo
304 304
  */
305 305
 function getpaid_admin_subscription_metabox_display_gateway( $subscription ) {
306 306
 
307
-	$gateway = $subscription->get_gateway();
307
+    $gateway = $subscription->get_gateway();
308 308
 
309
-	if ( ! empty( $gateway ) ) {
310
-		echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) );
311
-	} else {
312
-		echo "&mdash;";
313
-	}
309
+    if ( ! empty( $gateway ) ) {
310
+        echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) );
311
+    } else {
312
+        echo "&mdash;";
313
+    }
314 314
 
315 315
 }
316 316
 add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' );
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
  * @param WPInv_Subscription $subscription
322 322
  */
323 323
 function getpaid_admin_subscription_metabox_display_status( $subscription ) {
324
-	echo $subscription->get_status_label_html();
324
+    echo $subscription->get_status_label_html();
325 325
 }
326 326
 add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' );
327 327
 
@@ -332,29 +332,29 @@  discard block
 block discarded – undo
332 332
  */
333 333
 function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) {
334 334
 
335
-	$profile_id = $subscription->get_profile_id();
336
-
337
-	$input = aui()->input(
338
-		array(
339
-			'type'        => 'text',
340
-			'id'          => 'wpinv_subscription_profile_id',
341
-			'name'        => 'wpinv_subscription_profile_id',
342
-			'label'       => __( 'Profile Id', 'invoicing' ),
343
-			'label_type'  => 'hidden',
344
-			'placeholder' => __( 'Profile Id', 'invoicing' ),
345
-			'value'       => sanitize_text_field( $profile_id ),
346
-			'input_group_right' => '',
347
-			'no_wrap'     => true,
348
-		)
349
-	);
350
-
351
-	echo str_ireplace( 'form-control', 'regular-text', $input );
352
-
353
-	$url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription );
354
-	if ( ! empty( $url ) ) {
355
-		$url = esc_url_raw( $url );
356
-		echo '&nbsp;<a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>';
357
-	}
335
+    $profile_id = $subscription->get_profile_id();
336
+
337
+    $input = aui()->input(
338
+        array(
339
+            'type'        => 'text',
340
+            'id'          => 'wpinv_subscription_profile_id',
341
+            'name'        => 'wpinv_subscription_profile_id',
342
+            'label'       => __( 'Profile Id', 'invoicing' ),
343
+            'label_type'  => 'hidden',
344
+            'placeholder' => __( 'Profile Id', 'invoicing' ),
345
+            'value'       => sanitize_text_field( $profile_id ),
346
+            'input_group_right' => '',
347
+            'no_wrap'     => true,
348
+        )
349
+    );
350
+
351
+    echo str_ireplace( 'form-control', 'regular-text', $input );
352
+
353
+    $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription );
354
+    if ( ! empty( $url ) ) {
355
+        $url = esc_url_raw( $url );
356
+        echo '&nbsp;<a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>';
357
+    }
358 358
 
359 359
 }
360 360
 add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' );
@@ -366,39 +366,39 @@  discard block
 block discarded – undo
366 366
  */
367 367
 function getpaid_admin_subscription_update_metabox( $subscription ) {
368 368
 
369
-	?>
369
+    ?>
370 370
 	<div class="mt-3">
371 371
 
372 372
 		<?php
373
-			echo aui()->select(
374
-				array(
375
-					'options'          => getpaid_get_subscription_statuses(),
376
-					'name'             => 'subscription_status',
377
-					'id'               => 'subscription_status_update_select',
378
-					'required'         => true,
379
-					'no_wrap'          => false,
380
-					'label'            => __( 'Subscription Status', 'invoicing' ),
381
-					'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
382
-					'select2'          => true,
383
-					'value'            => $subscription->get_status( 'edit' ),
384
-				)
385
-			);
386
-		?>
373
+            echo aui()->select(
374
+                array(
375
+                    'options'          => getpaid_get_subscription_statuses(),
376
+                    'name'             => 'subscription_status',
377
+                    'id'               => 'subscription_status_update_select',
378
+                    'required'         => true,
379
+                    'no_wrap'          => false,
380
+                    'label'            => __( 'Subscription Status', 'invoicing' ),
381
+                    'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
382
+                    'select2'          => true,
383
+                    'value'            => $subscription->get_status( 'edit' ),
384
+                )
385
+            );
386
+        ?>
387 387
 
388 388
 		<div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;">
389 389
 	
390 390
 		<?php
391
-			submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
391
+            submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
392 392
 
393
-			$url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
394
-			$anchor = __( 'Renew Subscription', 'invoicing' );
395
-			$title  = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' );
393
+            $url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
394
+            $anchor = __( 'Renew Subscription', 'invoicing' );
395
+            $title  = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' );
396 396
 
397
-			if ( $subscription->is_active() ) {
398
-				echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
399
-			}
397
+            if ( $subscription->is_active() ) {
398
+                echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
399
+            }
400 400
 
401
-	echo '</div></div>';
401
+    echo '</div></div>';
402 402
 }
403 403
 
404 404
 /**
@@ -408,33 +408,33 @@  discard block
 block discarded – undo
408 408
  */
409 409
 function getpaid_admin_subscription_invoice_details_metabox( $subscription ) {
410 410
 
411
-	$columns = apply_filters(
412
-		'getpaid_subscription_related_invoices_columns',
413
-		array(
414
-			'invoice'      => __( 'Invoice', 'invoicing' ),
415
-			'relationship' => __( 'Relationship', 'invoicing' ),
416
-			'date'         => __( 'Date', 'invoicing' ),
417
-			'status'       => __( 'Status', 'invoicing' ),
418
-			'total'        => __( 'Total', 'invoicing' ),
419
-		),
420
-		$subscription
421
-	);
422
-
423
-	// Prepare the invoices.
424
-	$payments = $subscription->get_child_payments( ! is_admin() );
425
-	$parent   = $subscription->get_parent_invoice();
426
-
427
-	if ( $parent->get_id() ) {
428
-		$payments = array_merge( array( $parent ), $payments );
429
-	}
411
+    $columns = apply_filters(
412
+        'getpaid_subscription_related_invoices_columns',
413
+        array(
414
+            'invoice'      => __( 'Invoice', 'invoicing' ),
415
+            'relationship' => __( 'Relationship', 'invoicing' ),
416
+            'date'         => __( 'Date', 'invoicing' ),
417
+            'status'       => __( 'Status', 'invoicing' ),
418
+            'total'        => __( 'Total', 'invoicing' ),
419
+        ),
420
+        $subscription
421
+    );
422
+
423
+    // Prepare the invoices.
424
+    $payments = $subscription->get_child_payments( ! is_admin() );
425
+    $parent   = $subscription->get_parent_invoice();
426
+
427
+    if ( $parent->get_id() ) {
428
+        $payments = array_merge( array( $parent ), $payments );
429
+    }
430 430
 	
431
-	$table_class = 'w-100 bg-white';
431
+    $table_class = 'w-100 bg-white';
432 432
 
433
-	if ( ! is_admin() ) {
434
-		$table_class = 'table table-bordered table-striped';
435
-	}
433
+    if ( ! is_admin() ) {
434
+        $table_class = 'table table-bordered table-striped';
435
+    }
436 436
 
437
-	?>
437
+    ?>
438 438
 		<div class="m-0" style="overflow: auto;">
439 439
 
440 440
 			<table class="<?php echo $table_class; ?>">
@@ -442,13 +442,13 @@  discard block
 block discarded – undo
442 442
 				<thead>
443 443
 					<tr>
444 444
 						<?php
445
-							foreach ( $columns as $key => $label ) {
446
-								$key   = esc_attr( $key );
447
-								$label = sanitize_text_field( $label );
445
+                            foreach ( $columns as $key => $label ) {
446
+                                $key   = esc_attr( $key );
447
+                                $label = sanitize_text_field( $label );
448 448
 
449
-								echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark font-weight-bold'>$label</th>";
450
-							}
451
-						?>
449
+                                echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark font-weight-bold'>$label</th>";
450
+                            }
451
+                        ?>
452 452
 					</tr>
453 453
 				</thead>
454 454
 
@@ -464,66 +464,66 @@  discard block
 block discarded – undo
464 464
 
465 465
 					<?php
466 466
 
467
-						foreach( $payments as $payment ) :
467
+                        foreach( $payments as $payment ) :
468 468
 
469
-							// Ensure that we have an invoice.
470
-							$payment = new WPInv_Invoice( $payment );
469
+                            // Ensure that we have an invoice.
470
+                            $payment = new WPInv_Invoice( $payment );
471 471
 
472
-							// Abort if the invoice is invalid.
473
-							if ( ! $payment->get_id() ) {
474
-								continue;
475
-							}
472
+                            // Abort if the invoice is invalid.
473
+                            if ( ! $payment->get_id() ) {
474
+                                continue;
475
+                            }
476 476
 
477
-							echo '<tr>';
477
+                            echo '<tr>';
478 478
 
479
-								foreach ( array_keys( $columns ) as $key ) {
479
+                                foreach ( array_keys( $columns ) as $key ) {
480 480
 
481
-									echo '<td class="p-2 text-left">';
481
+                                    echo '<td class="p-2 text-left">';
482 482
 
483
-										switch( $key ) {
483
+                                        switch( $key ) {
484 484
 
485
-											case 'total':
486
-												echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>';
487
-												break;
485
+                                            case 'total':
486
+                                                echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>';
487
+                                                break;
488 488
 
489
-											case 'relationship':
490
-												echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
491
-												break;
489
+                                            case 'relationship':
490
+                                                echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
491
+                                                break;
492 492
 
493
-											case 'date':
494
-												echo getpaid_format_date_value( $payment->get_date_created() );
495
-												break;
493
+                                            case 'date':
494
+                                                echo getpaid_format_date_value( $payment->get_date_created() );
495
+                                                break;
496 496
 
497
-											case 'status':
497
+                                            case 'status':
498 498
 
499
-												$status = $payment->get_status_nicename();
500
-												if ( is_admin() ) {
501
-													$status = $payment->get_status_label_html();
502
-												}
499
+                                                $status = $payment->get_status_nicename();
500
+                                                if ( is_admin() ) {
501
+                                                    $status = $payment->get_status_label_html();
502
+                                                }
503 503
 
504
-												echo $status;
505
-												break;
504
+                                                echo $status;
505
+                                                break;
506 506
 
507
-											case 'invoice':
508
-												$link    = esc_url( get_edit_post_link( $payment->get_id() ) );
507
+                                            case 'invoice':
508
+                                                $link    = esc_url( get_edit_post_link( $payment->get_id() ) );
509 509
 
510
-												if ( ! is_admin() ) {
511
-													$link = esc_url( $payment->get_view_url() );
512
-												}
510
+                                                if ( ! is_admin() ) {
511
+                                                    $link = esc_url( $payment->get_view_url() );
512
+                                                }
513 513
 
514
-												$invoice = sanitize_text_field( $payment->get_number() );
515
-												echo "<a href='$link'>$invoice</a>";
516
-												break;
517
-										}
514
+                                                $invoice = sanitize_text_field( $payment->get_number() );
515
+                                                echo "<a href='$link'>$invoice</a>";
516
+                                                break;
517
+                                        }
518 518
 
519
-									echo '</td>';
519
+                                    echo '</td>';
520 520
 
521
-								}
521
+                                }
522 522
 
523
-							echo '</tr>';
523
+                            echo '</tr>';
524 524
 
525
-						endforeach;
526
-					?>
525
+                        endforeach;
526
+                    ?>
527 527
 
528 528
 				</tbody>
529 529
 
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-payment-gateway.php 1 patch
Indentation   +607 added lines, -607 removed lines patch added patch discarded remove patch
@@ -13,467 +13,467 @@  discard block
 block discarded – undo
13 13
  */
14 14
 abstract class GetPaid_Payment_Gateway {
15 15
 
16
-	/**
17
-	 * Set if the place checkout button should be renamed on selection.
18
-	 *
19
-	 * @var string
20
-	 */
21
-	public $checkout_button_text;
22
-
23
-	/**
24
-	 * Boolean whether the method is enabled.
25
-	 *
26
-	 * @var bool
27
-	 */
28
-	public $enabled = true;
29
-
30
-	/**
31
-	 * Payment method id.
32
-	 *
33
-	 * @var string
34
-	 */
35
-	public $id;
36
-
37
-	/**
38
-	 * Payment method order.
39
-	 *
40
-	 * @var int
41
-	 */
42
-	public $order = 10;
43
-
44
-	/**
45
-	 * Payment method title for the frontend.
46
-	 *
47
-	 * @var string
48
-	 */
49
-	public $title;
50
-
51
-	/**
52
-	 * Payment method description for the frontend.
53
-	 *
54
-	 * @var string
55
-	 */
56
-	public $description;
57
-
58
-	/**
59
-	 * Gateway title.
60
-	 *
61
-	 * @var string
62
-	 */
63
-	public $method_title = '';
64
-
65
-	/**
66
-	 * Gateway description.
67
-	 *
68
-	 * @var string
69
-	 */
70
-	public $method_description = '';
71
-
72
-	/**
73
-	 * Countries this gateway is allowed for.
74
-	 *
75
-	 * @var array
76
-	 */
77
-	public $countries;
78
-
79
-	/**
80
-	 * Currencies this gateway is allowed for.
81
-	 *
82
-	 * @var array
83
-	 */
84
-	public $currencies;
85
-
86
-	/**
87
-	 * Currencies this gateway is not allowed for.
88
-	 *
89
-	 * @var array
90
-	 */
91
-	public $exclude_currencies;
92
-
93
-	/**
94
-	 * Maximum transaction amount, zero does not define a maximum.
95
-	 *
96
-	 * @var int
97
-	 */
98
-	public $max_amount = 0;
99
-
100
-	/**
101
-	 * Optional URL to view a transaction.
102
-	 *
103
-	 * @var string
104
-	 */
105
-	public $view_transaction_url = '';
106
-
107
-	/**
108
-	 * Optional URL to view a subscription.
109
-	 *
110
-	 * @var string
111
-	 */
112
-	public $view_subscription_url = '';
113
-
114
-	/**
115
-	 * Optional label to show for "new payment method" in the payment
116
-	 * method/token selection radio selection.
117
-	 *
118
-	 * @var string
119
-	 */
120
-	public $new_method_label = '';
121
-
122
-	/**
123
-	 * Contains a user's saved tokens for this gateway.
124
-	 *
125
-	 * @var array
126
-	 */
127
-	protected $tokens = array();
128
-
129
-	/**
130
-	 * An array of features that this gateway supports.
131
-	 *
132
-	 * @var array
133
-	 */
134
-	protected $supports = array();
135
-
136
-	/**
137
-	 * Class constructor.
138
-	 */
139
-	public function __construct() {
140
-
141
-		// Register gateway.
142
-		add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
143
-
144
-		$this->enabled = wpinv_is_gateway_active( $this->id );
145
-
146
-		// Enable Subscriptions.
147
-		if ( $this->supports( 'subscription' ) ) {
148
-			add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' );
149
-		}
150
-
151
-		// Enable sandbox.
152
-		if ( $this->supports( 'sandbox' ) ) {
153
-			add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' );
154
-		}
155
-
156
-		// Invoice addons.
157
-		if ( $this->supports( 'addons' ) ) {
158
-			add_filter( "getpaid_{$this->id}_supports_addons", '__return_true' );
159
-			add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 );
160
-		}
161
-
162
-		// Gateway settings.
163
-		add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
16
+    /**
17
+     * Set if the place checkout button should be renamed on selection.
18
+     *
19
+     * @var string
20
+     */
21
+    public $checkout_button_text;
22
+
23
+    /**
24
+     * Boolean whether the method is enabled.
25
+     *
26
+     * @var bool
27
+     */
28
+    public $enabled = true;
29
+
30
+    /**
31
+     * Payment method id.
32
+     *
33
+     * @var string
34
+     */
35
+    public $id;
36
+
37
+    /**
38
+     * Payment method order.
39
+     *
40
+     * @var int
41
+     */
42
+    public $order = 10;
43
+
44
+    /**
45
+     * Payment method title for the frontend.
46
+     *
47
+     * @var string
48
+     */
49
+    public $title;
50
+
51
+    /**
52
+     * Payment method description for the frontend.
53
+     *
54
+     * @var string
55
+     */
56
+    public $description;
57
+
58
+    /**
59
+     * Gateway title.
60
+     *
61
+     * @var string
62
+     */
63
+    public $method_title = '';
64
+
65
+    /**
66
+     * Gateway description.
67
+     *
68
+     * @var string
69
+     */
70
+    public $method_description = '';
71
+
72
+    /**
73
+     * Countries this gateway is allowed for.
74
+     *
75
+     * @var array
76
+     */
77
+    public $countries;
78
+
79
+    /**
80
+     * Currencies this gateway is allowed for.
81
+     *
82
+     * @var array
83
+     */
84
+    public $currencies;
85
+
86
+    /**
87
+     * Currencies this gateway is not allowed for.
88
+     *
89
+     * @var array
90
+     */
91
+    public $exclude_currencies;
92
+
93
+    /**
94
+     * Maximum transaction amount, zero does not define a maximum.
95
+     *
96
+     * @var int
97
+     */
98
+    public $max_amount = 0;
99
+
100
+    /**
101
+     * Optional URL to view a transaction.
102
+     *
103
+     * @var string
104
+     */
105
+    public $view_transaction_url = '';
106
+
107
+    /**
108
+     * Optional URL to view a subscription.
109
+     *
110
+     * @var string
111
+     */
112
+    public $view_subscription_url = '';
113
+
114
+    /**
115
+     * Optional label to show for "new payment method" in the payment
116
+     * method/token selection radio selection.
117
+     *
118
+     * @var string
119
+     */
120
+    public $new_method_label = '';
121
+
122
+    /**
123
+     * Contains a user's saved tokens for this gateway.
124
+     *
125
+     * @var array
126
+     */
127
+    protected $tokens = array();
128
+
129
+    /**
130
+     * An array of features that this gateway supports.
131
+     *
132
+     * @var array
133
+     */
134
+    protected $supports = array();
135
+
136
+    /**
137
+     * Class constructor.
138
+     */
139
+    public function __construct() {
140
+
141
+        // Register gateway.
142
+        add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
143
+
144
+        $this->enabled = wpinv_is_gateway_active( $this->id );
145
+
146
+        // Enable Subscriptions.
147
+        if ( $this->supports( 'subscription' ) ) {
148
+            add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' );
149
+        }
150
+
151
+        // Enable sandbox.
152
+        if ( $this->supports( 'sandbox' ) ) {
153
+            add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' );
154
+        }
155
+
156
+        // Invoice addons.
157
+        if ( $this->supports( 'addons' ) ) {
158
+            add_filter( "getpaid_{$this->id}_supports_addons", '__return_true' );
159
+            add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 );
160
+        }
161
+
162
+        // Gateway settings.
163
+        add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
164 164
 		
165 165
 
166
-		// Gateway checkout fiellds.
167
-		add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
168
-
169
-		// Process payment.
170
-		add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
166
+        // Gateway checkout fiellds.
167
+        add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
168
+
169
+        // Process payment.
170
+        add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
171
+
172
+        // Change the checkout button text.
173
+        if ( ! empty( $this->checkout_button_text ) ) {
174
+            add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
175
+        }
176
+
177
+        // Check if a gateway is valid for a given currency.
178
+        add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
179
+
180
+        // Generate the transaction url.
181
+        add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
182
+
183
+        // Generate the subscription url.
184
+        add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 );
185
+
186
+        // Confirm payments.
187
+        add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
188
+
189
+        // Verify IPNs.
190
+        add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
191
+
192
+    }
193
+
194
+    /**
195
+     * Checks if this gateway is a given gateway.
196
+     *
197
+     * @since 1.0.19
198
+     * @return bool
199
+     */
200
+    public function is( $gateway ) {
201
+        return $gateway == $this->id;
202
+    }
203
+
204
+    /**
205
+     * Returns a users saved tokens for this gateway.
206
+     *
207
+     * @since 1.0.19
208
+     * @return array
209
+     */
210
+    public function get_tokens( $sandbox = null ) {
211
+
212
+        if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
213
+            $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
214
+
215
+            if ( is_array( $tokens ) ) {
216
+                $this->tokens = $tokens;
217
+            }
218
+
219
+        }
220
+
221
+        if ( ! is_bool( $sandbox ) ) {
222
+            return $this->tokens;
223
+        }
224
+
225
+        $args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
226
+        return wp_list_filter( $this->tokens, $args );
227
+
228
+    }
229
+
230
+    /**
231
+     * Saves a token for this gateway.
232
+     *
233
+     * @since 1.0.19
234
+     */
235
+    public function save_token( $token ) {
236
+
237
+        $tokens   = $this->get_tokens();
238
+        $tokens[] = $token;
239
+
240
+        update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
241
+
242
+        $this->tokens = $tokens;
243
+
244
+    }
245
+
246
+    /**
247
+     * Return the title for admin screens.
248
+     *
249
+     * @return string
250
+     */
251
+    public function get_method_title() {
252
+        return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
253
+    }
254
+
255
+    /**
256
+     * Return the description for admin screens.
257
+     *
258
+     * @return string
259
+     */
260
+    public function get_method_description() {
261
+        return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
262
+    }
263
+
264
+    /**
265
+     * Get the success url.
266
+     *
267
+     * @param WPInv_Invoice $invoice Invoice object.
268
+     * @return string
269
+     */
270
+    public function get_return_url( $invoice ) {
271
+
272
+        // Payment success url
273
+        $return_url = add_query_arg(
274
+            array(
275
+                'payment-confirm' => $this->id,
276
+                'invoice_key'     => $invoice->get_key(),
277
+                'utm_nooverride'  => 1
278
+            ),
279
+            wpinv_get_success_page_uri()
280
+        );
281
+
282
+        return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
283
+    }
284
+
285
+    /**
286
+     * Confirms payments when rendering the success page.
287
+     *
288
+     * @param string $content Success page content.
289
+     * @return string
290
+     */
291
+    public function confirm_payment( $content ) {
292
+
293
+        // Retrieve the invoice.
294
+        $invoice_id = getpaid_get_current_invoice_id();
295
+        $invoice    = wpinv_get_invoice( $invoice_id );
296
+
297
+        // Ensure that it exists and that it is pending payment.
298
+        if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
299
+            return $content;
300
+        }
301
+
302
+        // Can the user view this invoice??
303
+        if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
304
+            return $content;
305
+        }
306
+
307
+        // Show payment processing indicator.
308
+        return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
309
+    }
310
+
311
+    /**
312
+     * Processes ipns and marks payments as complete.
313
+     *
314
+     * @return void
315
+     */
316
+    public function verify_ipn() {}
317
+
318
+    /**
319
+     * Processes invoice addons.
320
+     *
321
+     * @param WPInv_Invoice $invoice
322
+     * @param GetPaid_Form_Item[] $items
323
+     * @return WPInv_Invoice
324
+     */
325
+    public function process_addons( $invoice, $items ) {
326
+
327
+    }
328
+
329
+    /**
330
+     * Get a link to the transaction on the 3rd party gateway site (if applicable).
331
+     *
332
+     * @param string $transaction_url transaction url.
333
+     * @param WPInv_Invoice $invoice Invoice object.
334
+     * @return string transaction URL, or empty string.
335
+     */
336
+    public function filter_transaction_url( $transaction_url, $invoice ) {
337
+
338
+        $transaction_id  = $invoice->get_transaction_id();
339
+
340
+        if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
341
+            $transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
342
+            $replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
343
+            $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
344
+        }
345
+
346
+        return $transaction_url;
347
+    }
348
+
349
+    /**
350
+     * Get a link to the subscription on the 3rd party gateway site (if applicable).
351
+     *
352
+     * @param string $subscription_url transaction url.
353
+     * @param WPInv_Subscription $subscription Subscription objectt.
354
+     * @return string subscription URL, or empty string.
355
+     */
356
+    public function generate_subscription_url( $subscription_url, $subscription ) {
171 357
 
172
-		// Change the checkout button text.
173
-		if ( ! empty( $this->checkout_button_text ) ) {
174
-			add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
175
-		}
176
-
177
-		// Check if a gateway is valid for a given currency.
178
-		add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
179
-
180
-		// Generate the transaction url.
181
-		add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
182
-
183
-		// Generate the subscription url.
184
-		add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 );
185
-
186
-		// Confirm payments.
187
-		add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
188
-
189
-		// Verify IPNs.
190
-		add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
191
-
192
-	}
193
-
194
-	/**
195
-	 * Checks if this gateway is a given gateway.
196
-	 *
197
-	 * @since 1.0.19
198
-	 * @return bool
199
-	 */
200
-	public function is( $gateway ) {
201
-		return $gateway == $this->id;
202
-	}
203
-
204
-	/**
205
-	 * Returns a users saved tokens for this gateway.
206
-	 *
207
-	 * @since 1.0.19
208
-	 * @return array
209
-	 */
210
-	public function get_tokens( $sandbox = null ) {
211
-
212
-		if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) {
213
-			$tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
214
-
215
-			if ( is_array( $tokens ) ) {
216
-				$this->tokens = $tokens;
217
-			}
218
-
219
-		}
220
-
221
-		if ( ! is_bool( $sandbox ) ) {
222
-			return $this->tokens;
223
-		}
224
-
225
-		$args = array( 'type' => $sandbox ? 'sandbox' : 'live' );
226
-		return wp_list_filter( $this->tokens, $args );
227
-
228
-	}
229
-
230
-	/**
231
-	 * Saves a token for this gateway.
232
-	 *
233
-	 * @since 1.0.19
234
-	 */
235
-	public function save_token( $token ) {
236
-
237
-		$tokens   = $this->get_tokens();
238
-		$tokens[] = $token;
239
-
240
-		update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens );
241
-
242
-		$this->tokens = $tokens;
243
-
244
-	}
245
-
246
-	/**
247
-	 * Return the title for admin screens.
248
-	 *
249
-	 * @return string
250
-	 */
251
-	public function get_method_title() {
252
-		return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
253
-	}
254
-
255
-	/**
256
-	 * Return the description for admin screens.
257
-	 *
258
-	 * @return string
259
-	 */
260
-	public function get_method_description() {
261
-		return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
262
-	}
263
-
264
-	/**
265
-	 * Get the success url.
266
-	 *
267
-	 * @param WPInv_Invoice $invoice Invoice object.
268
-	 * @return string
269
-	 */
270
-	public function get_return_url( $invoice ) {
271
-
272
-		// Payment success url
273
-		$return_url = add_query_arg(
274
-			array(
275
-				'payment-confirm' => $this->id,
276
-				'invoice_key'     => $invoice->get_key(),
277
-				'utm_nooverride'  => 1
278
-			),
279
-			wpinv_get_success_page_uri()
280
-		);
281
-
282
-		return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
283
-	}
284
-
285
-	/**
286
-	 * Confirms payments when rendering the success page.
287
-	 *
288
-	 * @param string $content Success page content.
289
-	 * @return string
290
-	 */
291
-	public function confirm_payment( $content ) {
292
-
293
-		// Retrieve the invoice.
294
-		$invoice_id = getpaid_get_current_invoice_id();
295
-		$invoice    = wpinv_get_invoice( $invoice_id );
296
-
297
-		// Ensure that it exists and that it is pending payment.
298
-		if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
299
-			return $content;
300
-		}
301
-
302
-		// Can the user view this invoice??
303
-		if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
304
-			return $content;
305
-		}
306
-
307
-		// Show payment processing indicator.
308
-		return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
309
-	}
310
-
311
-	/**
312
-	 * Processes ipns and marks payments as complete.
313
-	 *
314
-	 * @return void
315
-	 */
316
-	public function verify_ipn() {}
317
-
318
-	/**
319
-	 * Processes invoice addons.
320
-	 *
321
-	 * @param WPInv_Invoice $invoice
322
-	 * @param GetPaid_Form_Item[] $items
323
-	 * @return WPInv_Invoice
324
-	 */
325
-	public function process_addons( $invoice, $items ) {
326
-
327
-	}
328
-
329
-	/**
330
-	 * Get a link to the transaction on the 3rd party gateway site (if applicable).
331
-	 *
332
-	 * @param string $transaction_url transaction url.
333
-	 * @param WPInv_Invoice $invoice Invoice object.
334
-	 * @return string transaction URL, or empty string.
335
-	 */
336
-	public function filter_transaction_url( $transaction_url, $invoice ) {
337
-
338
-		$transaction_id  = $invoice->get_transaction_id();
339
-
340
-		if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
341
-			$transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
342
-			$replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
343
-			$transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
344
-		}
345
-
346
-		return $transaction_url;
347
-	}
348
-
349
-	/**
350
-	 * Get a link to the subscription on the 3rd party gateway site (if applicable).
351
-	 *
352
-	 * @param string $subscription_url transaction url.
353
-	 * @param WPInv_Subscription $subscription Subscription objectt.
354
-	 * @return string subscription URL, or empty string.
355
-	 */
356
-	public function generate_subscription_url( $subscription_url, $subscription ) {
357
-
358
-		$profile_id      = $subscription->get_profile_id();
359
-
360
-		if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
361
-
362
-			$subscription_url = sprintf( $this->view_subscription_url, $profile_id );
363
-			$replace          = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : '';
364
-			$subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
365
-
366
-		}
367
-
368
-		return $subscription_url;
369
-	}
370
-
371
-	/**
372
-	 * Check if the gateway is available for use.
373
-	 *
374
-	 * @return bool
375
-	 */
376
-	public function is_available() {
377
-		return ! empty( $this->enabled );
378
-	}
379
-
380
-	/**
381
-	 * Return the gateway's title.
382
-	 *
383
-	 * @return string
384
-	 */
385
-	public function get_title() {
386
-		return apply_filters( 'getpaid_gateway_title', $this->title, $this );
387
-	}
388
-
389
-	/**
390
-	 * Return the gateway's description.
391
-	 *
392
-	 * @return string
393
-	 */
394
-	public function get_description() {
395
-		return apply_filters( 'getpaid_gateway_description', $this->description, $this );
396
-	}
397
-
398
-	/**
399
-	 * Process Payment.
400
-	 *
401
-	 *
402
-	 * @param WPInv_Invoice $invoice Invoice.
403
-	 * @param array $submission_data Posted checkout fields.
404
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
405
-	 * @return void
406
-	 */
407
-	public function process_payment( $invoice, $submission_data, $submission ) {
408
-		// Process the payment then either redirect to the success page or the gateway.
409
-		do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
410
-	}
411
-
412
-	/**
413
-	 * Process refund.
414
-	 *
415
-	 * If the gateway declares 'refunds' support, this will allow it to refund.
416
-	 * a passed in amount.
417
-	 *
418
-	 * @param WPInv_Invoice $invoice Invoice.
419
-	 * @param  float  $amount Refund amount.
420
-	 * @param  string $reason Refund reason.
421
-	 * @return WP_Error|bool True or false based on success, or a WP_Error object.
422
-	 */
423
-	public function process_refund( $invoice, $amount = null, $reason = '' ) {
424
-		return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
425
-	}
426
-
427
-	/**
428
-	 * Displays the payment fields, credit cards etc.
429
-	 * 
430
-	 * @param int $invoice_id 0 or invoice id.
431
-	 * @param GetPaid_Payment_Form $form Current payment form.
432
-	 */
433
-	public function payment_fields( $invoice_id, $form ) {
434
-		do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
435
-	}
436
-
437
-	/**
438
-	 * Filters the gateway settings.
439
-	 * 
440
-	 * @param array $admin_settings
441
-	 */
442
-	public function admin_settings( $admin_settings ) {
443
-		return $admin_settings;
444
-	}
445
-
446
-	/**
447
-	 * Retrieves the value of a gateway setting.
448
-	 * 
449
-	 * @param string $option
450
-	 */
451
-	public function get_option( $option, $default = false ) {
452
-		return wpinv_get_option( $this->id . '_' . $option, $default );
453
-	}
454
-
455
-	/**
456
-	 * Check if a gateway supports a given feature.
457
-	 *
458
-	 * Gateways should override this to declare support (or lack of support) for a feature.
459
-	 * For backward compatibility, gateways support 'products' by default, but nothing else.
460
-	 *
461
-	 * @param string $feature string The name of a feature to test support for.
462
-	 * @return bool True if the gateway supports the feature, false otherwise.
463
-	 * @since 1.0.19
464
-	 */
465
-	public function supports( $feature ) {
466
-		return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this );
467
-	}
468
-
469
-	/**
470
-	 * Returns the credit card form html.
471
-	 * 
472
-	 * @param bool $save whether or not to display the save button.
473
-	 */
358
+        $profile_id      = $subscription->get_profile_id();
359
+
360
+        if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
361
+
362
+            $subscription_url = sprintf( $this->view_subscription_url, $profile_id );
363
+            $replace          = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : '';
364
+            $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
365
+
366
+        }
367
+
368
+        return $subscription_url;
369
+    }
370
+
371
+    /**
372
+     * Check if the gateway is available for use.
373
+     *
374
+     * @return bool
375
+     */
376
+    public function is_available() {
377
+        return ! empty( $this->enabled );
378
+    }
379
+
380
+    /**
381
+     * Return the gateway's title.
382
+     *
383
+     * @return string
384
+     */
385
+    public function get_title() {
386
+        return apply_filters( 'getpaid_gateway_title', $this->title, $this );
387
+    }
388
+
389
+    /**
390
+     * Return the gateway's description.
391
+     *
392
+     * @return string
393
+     */
394
+    public function get_description() {
395
+        return apply_filters( 'getpaid_gateway_description', $this->description, $this );
396
+    }
397
+
398
+    /**
399
+     * Process Payment.
400
+     *
401
+     *
402
+     * @param WPInv_Invoice $invoice Invoice.
403
+     * @param array $submission_data Posted checkout fields.
404
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
405
+     * @return void
406
+     */
407
+    public function process_payment( $invoice, $submission_data, $submission ) {
408
+        // Process the payment then either redirect to the success page or the gateway.
409
+        do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission );
410
+    }
411
+
412
+    /**
413
+     * Process refund.
414
+     *
415
+     * If the gateway declares 'refunds' support, this will allow it to refund.
416
+     * a passed in amount.
417
+     *
418
+     * @param WPInv_Invoice $invoice Invoice.
419
+     * @param  float  $amount Refund amount.
420
+     * @param  string $reason Refund reason.
421
+     * @return WP_Error|bool True or false based on success, or a WP_Error object.
422
+     */
423
+    public function process_refund( $invoice, $amount = null, $reason = '' ) {
424
+        return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason );
425
+    }
426
+
427
+    /**
428
+     * Displays the payment fields, credit cards etc.
429
+     * 
430
+     * @param int $invoice_id 0 or invoice id.
431
+     * @param GetPaid_Payment_Form $form Current payment form.
432
+     */
433
+    public function payment_fields( $invoice_id, $form ) {
434
+        do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form );
435
+    }
436
+
437
+    /**
438
+     * Filters the gateway settings.
439
+     * 
440
+     * @param array $admin_settings
441
+     */
442
+    public function admin_settings( $admin_settings ) {
443
+        return $admin_settings;
444
+    }
445
+
446
+    /**
447
+     * Retrieves the value of a gateway setting.
448
+     * 
449
+     * @param string $option
450
+     */
451
+    public function get_option( $option, $default = false ) {
452
+        return wpinv_get_option( $this->id . '_' . $option, $default );
453
+    }
454
+
455
+    /**
456
+     * Check if a gateway supports a given feature.
457
+     *
458
+     * Gateways should override this to declare support (or lack of support) for a feature.
459
+     * For backward compatibility, gateways support 'products' by default, but nothing else.
460
+     *
461
+     * @param string $feature string The name of a feature to test support for.
462
+     * @return bool True if the gateway supports the feature, false otherwise.
463
+     * @since 1.0.19
464
+     */
465
+    public function supports( $feature ) {
466
+        return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this );
467
+    }
468
+
469
+    /**
470
+     * Returns the credit card form html.
471
+     * 
472
+     * @param bool $save whether or not to display the save button.
473
+     */
474 474
     public function get_cc_form( $save = false ) {
475 475
 
476
-		ob_start();
476
+        ob_start();
477 477
 
478 478
         $id_prefix = esc_attr( uniqid( $this->id ) );
479 479
 
@@ -568,11 +568,11 @@  discard block
 block discarded – undo
568 568
                                         'name'              => $this->id . '[cc_cvv2]',
569 569
                                         'id'                => "$id_prefix-cc-cvv2",
570 570
                                         'label'             => __( 'CCV', 'invoicing' ),
571
-										'label_type'        => 'vertical',
572
-										'class'             => 'form-control-sm',
573
-										'extra_attributes'  => array(
574
-											'autocomplete'  => "cc-csc",
575
-										),
571
+                                        'label_type'        => 'vertical',
572
+                                        'class'             => 'form-control-sm',
573
+                                        'extra_attributes'  => array(
574
+                                            'autocomplete'  => "cc-csc",
575
+                                        ),
576 576
                                     )
577 577
                                 );
578 578
                             ?>
@@ -582,191 +582,191 @@  discard block
 block discarded – undo
582 582
 					
583 583
 					<?php
584 584
 
585
-						if ( $save ) {
586
-							echo $this->save_payment_method_checkbox();
587
-						}
585
+                        if ( $save ) {
586
+                            echo $this->save_payment_method_checkbox();
587
+                        }
588 588
 
589
-					?>
589
+                    ?>
590 590
                 </div>
591 591
 
592 592
             </div>
593 593
 		<?php
594 594
 		
595
-		return ob_get_clean();
595
+        return ob_get_clean();
596 596
 
597 597
     }
598 598
 
599
-	/**
600
-	 * Displays a new payment method entry form.
601
-	 *
602
-	 * @since 1.0.19
603
-	 */
604
-	public function new_payment_method_entry( $form ) {
605
-		echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>";
606
-	}
607
-
608
-	/**
609
-	 * Grab and display our saved payment methods.
610
-	 *
611
-	 * @since 1.0.19
612
-	 */
613
-	public function saved_payment_methods() {
614
-		$html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
615
-
616
-		foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
617
-			$html .= $this->get_saved_payment_method_option_html( $token );
618
-		}
619
-
620
-		$html .= $this->get_new_payment_method_option_html();
621
-		$html .= '</ul>';
622
-
623
-		echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this );
624
-	}
625
-
626
-	/**
627
-	 * Gets saved payment method HTML from a token.
628
-	 *
629
-	 * @since 1.0.19
630
-	 * @param  array $token Payment Token.
631
-	 * @return string Generated payment method HTML
632
-	 */
633
-	public function get_saved_payment_method_option_html( $token ) {
634
-
635
-		return sprintf(
636
-			'<li class="getpaid-payment-method form-group">
599
+    /**
600
+     * Displays a new payment method entry form.
601
+     *
602
+     * @since 1.0.19
603
+     */
604
+    public function new_payment_method_entry( $form ) {
605
+        echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>";
606
+    }
607
+
608
+    /**
609
+     * Grab and display our saved payment methods.
610
+     *
611
+     * @since 1.0.19
612
+     */
613
+    public function saved_payment_methods() {
614
+        $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">';
615
+
616
+        foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) {
617
+            $html .= $this->get_saved_payment_method_option_html( $token );
618
+        }
619
+
620
+        $html .= $this->get_new_payment_method_option_html();
621
+        $html .= '</ul>';
622
+
623
+        echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this );
624
+    }
625
+
626
+    /**
627
+     * Gets saved payment method HTML from a token.
628
+     *
629
+     * @since 1.0.19
630
+     * @param  array $token Payment Token.
631
+     * @return string Generated payment method HTML
632
+     */
633
+    public function get_saved_payment_method_option_html( $token ) {
634
+
635
+        return sprintf(
636
+            '<li class="getpaid-payment-method form-group">
637 637
 				<label>
638 638
 					<input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s />
639 639
 					<span>%3$s</span>
640 640
 				</label>
641 641
 			</li>',
642
-			esc_attr( $this->id ),
643
-			esc_attr( $token['id'] ),
644
-			esc_html( $token['name'] ),
645
-			checked( empty( $token['default'] ), false, false )
646
-		);
642
+            esc_attr( $this->id ),
643
+            esc_attr( $token['id'] ),
644
+            esc_html( $token['name'] ),
645
+            checked( empty( $token['default'] ), false, false )
646
+        );
647 647
 
648
-	}
648
+    }
649 649
 
650
-	/**
651
-	 * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
652
-	 *
653
-	 * @since 1.0.19
654
-	 */
655
-	public function get_new_payment_method_option_html() {
650
+    /**
651
+     * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
652
+     *
653
+     * @since 1.0.19
654
+     */
655
+    public function get_new_payment_method_option_html() {
656 656
 
657
-		$label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
657
+        $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
658 658
 
659
-		return sprintf(
660
-			'<li class="getpaid-new-payment-method">
659
+        return sprintf(
660
+            '<li class="getpaid-new-payment-method">
661 661
 				<label>
662 662
 					<input name="getpaid-%1$s-payment-method" type="radio" value="new" style="width:auto;" />
663 663
 					<span>%2$s</span>
664 664
 				</label>
665 665
 			</li>',
666
-			esc_attr( $this->id ),
667
-			esc_html( $label )
668
-		);
669
-
670
-	}
671
-
672
-	/**
673
-	 * Outputs a checkbox for saving a new payment method to the database.
674
-	 *
675
-	 * @since 1.0.19
676
-	 */
677
-	public function save_payment_method_checkbox() {
678
-
679
-		return aui()->input(
680
-			array(
681
-				'type'       => 'checkbox',
682
-				'name'       => esc_attr( "getpaid-$this->id-new-payment-method" ),
683
-				'id'         => esc_attr( uniqid( $this->id ) ),
684
-				'required'   => false,
685
-				'label'      => esc_html__( 'Save payment method', 'invoicing' ),
686
-				'value'      => 'true',
687
-				'checked'    => true,
688
-				'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1',
689
-			)
690
-		);
691
-
692
-	}
693
-
694
-	/**
695
-	 * Registers the gateway.
696
-	 *
697
-	 * @return array
698
-	 */
699
-	public function register_gateway( $gateways ) {
700
-
701
-		$gateways[ $this->id ] = array(
702
-
703
-			'admin_label'    => $this->method_title,
666
+            esc_attr( $this->id ),
667
+            esc_html( $label )
668
+        );
669
+
670
+    }
671
+
672
+    /**
673
+     * Outputs a checkbox for saving a new payment method to the database.
674
+     *
675
+     * @since 1.0.19
676
+     */
677
+    public function save_payment_method_checkbox() {
678
+
679
+        return aui()->input(
680
+            array(
681
+                'type'       => 'checkbox',
682
+                'name'       => esc_attr( "getpaid-$this->id-new-payment-method" ),
683
+                'id'         => esc_attr( uniqid( $this->id ) ),
684
+                'required'   => false,
685
+                'label'      => esc_html__( 'Save payment method', 'invoicing' ),
686
+                'value'      => 'true',
687
+                'checked'    => true,
688
+                'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1',
689
+            )
690
+        );
691
+
692
+    }
693
+
694
+    /**
695
+     * Registers the gateway.
696
+     *
697
+     * @return array
698
+     */
699
+    public function register_gateway( $gateways ) {
700
+
701
+        $gateways[ $this->id ] = array(
702
+
703
+            'admin_label'    => $this->method_title,
704 704
             'checkout_label' => $this->title,
705
-			'ordering'       => $this->order,
705
+            'ordering'       => $this->order,
706 706
 
707
-		);
707
+        );
708 708
 
709
-		return $gateways;
709
+        return $gateways;
710 710
 
711
-	}
711
+    }
712 712
 
713
-	/**
714
-	 * Checks whether or not this is a sandbox request.
715
-	 *
716
-	 * @param  WPInv_Invoice|null $invoice Invoice object or null.
717
-	 * @return bool
718
-	 */
719
-	public function is_sandbox( $invoice = null ) {
713
+    /**
714
+     * Checks whether or not this is a sandbox request.
715
+     *
716
+     * @param  WPInv_Invoice|null $invoice Invoice object or null.
717
+     * @return bool
718
+     */
719
+    public function is_sandbox( $invoice = null ) {
720 720
 
721
-		if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
722
-			return $invoice->get_mode() == 'test';
723
-		}
721
+        if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
722
+            return $invoice->get_mode() == 'test';
723
+        }
724 724
 
725
-		return wpinv_is_test_mode( $this->id );
725
+        return wpinv_is_test_mode( $this->id );
726 726
 
727
-	}
727
+    }
728 728
 
729
-	/**
730
-	 * Renames the checkout button
731
-	 *
732
-	 * @return string
733
-	 */
734
-	public function rename_checkout_button() {
735
-		return $this->checkout_button_text;
736
-	}
729
+    /**
730
+     * Renames the checkout button
731
+     *
732
+     * @return string
733
+     */
734
+    public function rename_checkout_button() {
735
+        return $this->checkout_button_text;
736
+    }
737 737
 
738
-	/**
739
-	 * Validate gateway currency
740
-	 *
741
-	 * @return bool
742
-	 */
743
-	public function validate_currency( $validation, $currency ) {
738
+    /**
739
+     * Validate gateway currency
740
+     *
741
+     * @return bool
742
+     */
743
+    public function validate_currency( $validation, $currency ) {
744 744
 
745
-		// Required currencies.
746
-		if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
747
-			return false;
748
-		}
745
+        // Required currencies.
746
+        if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
747
+            return false;
748
+        }
749 749
 
750
-		// Excluded currencies.
751
-		if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
752
-			return false;
753
-		}
750
+        // Excluded currencies.
751
+        if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
752
+            return false;
753
+        }
754 754
 
755
-		return $validation;
756
-	}
755
+        return $validation;
756
+    }
757 757
 
758
-	/**
759
-	 * Displays an error
760
-	 *
761
-	 */
762
-	public function show_error( $code, $message, $type ) {
758
+    /**
759
+     * Displays an error
760
+     *
761
+     */
762
+    public function show_error( $code, $message, $type ) {
763 763
 
764
-		if ( is_admin() ) {
765
-			getpaid_admin()->{"show_$type"}( $message );
766
-		}
764
+        if ( is_admin() ) {
765
+            getpaid_admin()->{"show_$type"}( $message );
766
+        }
767 767
 
768
-		wpinv_set_error( $code, $message, $type );
768
+        wpinv_set_error( $code, $message, $type );
769 769
 
770
-	}
770
+    }
771 771
 
772 772
 }
Please login to merge, or discard this patch.
widgets/subscriptions.php 1 patch
Indentation   +332 added lines, -332 removed lines patch added patch discarded remove patch
@@ -14,144 +14,144 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class WPInv_Subscriptions_Widget extends WP_Super_Duper {
16 16
 
17
-	/**
18
-	 * Register the widget with WordPress.
19
-	 *
20
-	 */
21
-	public function __construct() {
22
-
23
-		$options = array(
24
-			'textdomain'    => 'invoicing',
25
-			'block-icon'    => 'controls-repeat',
26
-			'block-category'=> 'widgets',
27
-			'block-keywords'=> "['invoicing','subscriptions', 'getpaid']",
28
-			'class_name'     => __CLASS__,
29
-			'base_id'       => 'wpinv_subscriptions',
30
-			'name'          => __( 'GetPaid > Subscriptions', 'invoicing' ),
31
-			'widget_ops'    => array(
32
-				'classname'   => 'getpaid-subscriptions bsui',
33
-				'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ),
34
-			),
35
-			'arguments'     => array(
36
-				'title'  => array(
37
-					'title'       => __( 'Widget title', 'invoicing' ),
38
-					'desc'        => __( 'Enter widget title.', 'invoicing' ),
39
-					'type'        => 'text',
40
-					'desc_tip'    => true,
41
-					'default'     => '',
42
-					'advanced'    => false
43
-				),
44
-			)
45
-
46
-		);
47
-
48
-
49
-		parent::__construct( $options );
50
-	}
51
-
52
-	/**
53
-	 * Retrieves current user's subscriptions.
54
-	 *
55
-	 * @return GetPaid_Subscriptions_Query
56
-	 */
57
-	public function get_subscriptions() {
58
-
59
-		// Prepare license args.
60
-		$args  = array(
61
-			'customer_in' => get_current_user_id(),
62
-			'paged'       => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
63
-		);
64
-
65
-		return new GetPaid_Subscriptions_Query( $args );
66
-
67
-	}
68
-
69
-	/**
70
-	 * The Super block output function.
71
-	 *
72
-	 * @param array $args
73
-	 * @param array $widget_args
74
-	 * @param string $content
75
-	 *
76
-	 * @return mixed|string|bool
77
-	 */
78
-	public function output( $args = array(), $widget_args = array(), $content = '' ) {
79
-
80
-		// Ensure that the user is logged in.
81
-		if ( ! is_user_logged_in() ) {
82
-
83
-			return aui()->alert(
84
-				array(
85
-					'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ),
86
-					'type'    => 'error',
87
-				)
88
-			);
89
-
90
-		}
91
-
92
-		// Are we displaying a single subscription?
93
-		if ( isset( $_GET['subscription'] ) ) {
94
-			return $this->display_single_subscription( trim( $_GET['subscription'] ) );
95
-		}
96
-
97
-		// Retrieve the user's subscriptions.
98
-		$subscriptions = $this->get_subscriptions();
99
-
100
-		// Start the output buffer.
101
-		ob_start();
102
-
103
-		// Backwards compatibility.
104
-		do_action( 'wpinv_before_user_subscriptions' );
105
-
106
-		// Display errors and notices.
107
-		wpinv_print_errors();
108
-
109
-		do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions );
110
-
111
-		// Print the table header.
112
-		$this->print_table_header();
113
-
114
-		// Print table body.
115
-		$this->print_table_body( $subscriptions->get_results() );
116
-
117
-		// Print table footer.
118
-		$this->print_table_footer();
119
-
120
-		// Print the navigation.
121
-		$this->print_navigation( $subscriptions->get_total() );
122
-
123
-		// Backwards compatibility.
124
-		do_action( 'wpinv_after_user_subscriptions' );
125
-
126
-		// Return the output.
127
-		return ob_get_clean();
128
-
129
-	}
130
-
131
-	/**
132
-	 * Retrieves the subscription columns.
133
-	 *
134
-	 * @return array
135
-	 */
136
-	public function get_subscriptions_table_columns() {
17
+    /**
18
+     * Register the widget with WordPress.
19
+     *
20
+     */
21
+    public function __construct() {
22
+
23
+        $options = array(
24
+            'textdomain'    => 'invoicing',
25
+            'block-icon'    => 'controls-repeat',
26
+            'block-category'=> 'widgets',
27
+            'block-keywords'=> "['invoicing','subscriptions', 'getpaid']",
28
+            'class_name'     => __CLASS__,
29
+            'base_id'       => 'wpinv_subscriptions',
30
+            'name'          => __( 'GetPaid > Subscriptions', 'invoicing' ),
31
+            'widget_ops'    => array(
32
+                'classname'   => 'getpaid-subscriptions bsui',
33
+                'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ),
34
+            ),
35
+            'arguments'     => array(
36
+                'title'  => array(
37
+                    'title'       => __( 'Widget title', 'invoicing' ),
38
+                    'desc'        => __( 'Enter widget title.', 'invoicing' ),
39
+                    'type'        => 'text',
40
+                    'desc_tip'    => true,
41
+                    'default'     => '',
42
+                    'advanced'    => false
43
+                ),
44
+            )
45
+
46
+        );
47
+
48
+
49
+        parent::__construct( $options );
50
+    }
51
+
52
+    /**
53
+     * Retrieves current user's subscriptions.
54
+     *
55
+     * @return GetPaid_Subscriptions_Query
56
+     */
57
+    public function get_subscriptions() {
58
+
59
+        // Prepare license args.
60
+        $args  = array(
61
+            'customer_in' => get_current_user_id(),
62
+            'paged'       => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
63
+        );
64
+
65
+        return new GetPaid_Subscriptions_Query( $args );
66
+
67
+    }
68
+
69
+    /**
70
+     * The Super block output function.
71
+     *
72
+     * @param array $args
73
+     * @param array $widget_args
74
+     * @param string $content
75
+     *
76
+     * @return mixed|string|bool
77
+     */
78
+    public function output( $args = array(), $widget_args = array(), $content = '' ) {
79
+
80
+        // Ensure that the user is logged in.
81
+        if ( ! is_user_logged_in() ) {
82
+
83
+            return aui()->alert(
84
+                array(
85
+                    'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ),
86
+                    'type'    => 'error',
87
+                )
88
+            );
89
+
90
+        }
91
+
92
+        // Are we displaying a single subscription?
93
+        if ( isset( $_GET['subscription'] ) ) {
94
+            return $this->display_single_subscription( trim( $_GET['subscription'] ) );
95
+        }
96
+
97
+        // Retrieve the user's subscriptions.
98
+        $subscriptions = $this->get_subscriptions();
99
+
100
+        // Start the output buffer.
101
+        ob_start();
102
+
103
+        // Backwards compatibility.
104
+        do_action( 'wpinv_before_user_subscriptions' );
105
+
106
+        // Display errors and notices.
107
+        wpinv_print_errors();
108
+
109
+        do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions );
110
+
111
+        // Print the table header.
112
+        $this->print_table_header();
113
+
114
+        // Print table body.
115
+        $this->print_table_body( $subscriptions->get_results() );
116
+
117
+        // Print table footer.
118
+        $this->print_table_footer();
119
+
120
+        // Print the navigation.
121
+        $this->print_navigation( $subscriptions->get_total() );
122
+
123
+        // Backwards compatibility.
124
+        do_action( 'wpinv_after_user_subscriptions' );
125
+
126
+        // Return the output.
127
+        return ob_get_clean();
128
+
129
+    }
130
+
131
+    /**
132
+     * Retrieves the subscription columns.
133
+     *
134
+     * @return array
135
+     */
136
+    public function get_subscriptions_table_columns() {
137 137
 
138
-		$columns = array(
139
-			'subscription'   => __( 'Subscription', 'invoicing' ),
140
-			'amount'         => __( 'Amount', 'invoicing' ),
141
-			'renewal-date'   => __( 'Next payment', 'invoicing' ),
142
-			'status'         => __( 'Status', 'invoicing' ),
143
-		);
138
+        $columns = array(
139
+            'subscription'   => __( 'Subscription', 'invoicing' ),
140
+            'amount'         => __( 'Amount', 'invoicing' ),
141
+            'renewal-date'   => __( 'Next payment', 'invoicing' ),
142
+            'status'         => __( 'Status', 'invoicing' ),
143
+        );
144 144
 
145
-		return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns );
146
-	}
145
+        return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns );
146
+    }
147 147
 
148
-	/**
149
-	 * Displays the table header.
150
-	 *
151
-	 */
152
-	public function print_table_header() {
148
+    /**
149
+     * Displays the table header.
150
+     *
151
+     */
152
+    public function print_table_header() {
153 153
 
154
-		?>
154
+        ?>
155 155
 
156 156
 			<table class="table table-bordered table-striped">
157 157
 
@@ -167,121 +167,121 @@  discard block
 block discarded – undo
167 167
 
168 168
 		<?php
169 169
 
170
-	}
170
+    }
171 171
 
172
-	/**
173
-	 * Displays the table body.
174
-	 *
175
-	 * @param WPInv_Subscription[] $subscriptions
176
-	 */
177
-	public function print_table_body( $subscriptions ) {
172
+    /**
173
+     * Displays the table body.
174
+     *
175
+     * @param WPInv_Subscription[] $subscriptions
176
+     */
177
+    public function print_table_body( $subscriptions ) {
178 178
 
179
-		if ( empty( $subscriptions ) ) {
180
-			$this->print_table_body_no_subscriptions();
181
-		} else {
182
-			$this->print_table_body_subscriptions( $subscriptions );
183
-		}
179
+        if ( empty( $subscriptions ) ) {
180
+            $this->print_table_body_no_subscriptions();
181
+        } else {
182
+            $this->print_table_body_subscriptions( $subscriptions );
183
+        }
184 184
 
185
-	}
185
+    }
186 186
 
187
-	/**
188
-	 * Displays the table body if no subscriptions were found.
189
-	 *
190
-	 */
191
-	public function print_table_body_no_subscriptions() {
187
+    /**
188
+     * Displays the table body if no subscriptions were found.
189
+     *
190
+     */
191
+    public function print_table_body_no_subscriptions() {
192 192
 
193
-		?>
193
+        ?>
194 194
 		<tbody>
195 195
 
196 196
 			<tr>
197 197
 				<td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>">
198 198
 
199 199
 					<?php
200
-						echo aui()->alert(
201
-							array(
202
-								'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ),
203
-								'type'    => 'warning',
204
-							)
205
-						);
206
-					?>
200
+                        echo aui()->alert(
201
+                            array(
202
+                                'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ),
203
+                                'type'    => 'warning',
204
+                            )
205
+                        );
206
+                    ?>
207 207
 
208 208
 				</td>
209 209
 			</tr>
210 210
 
211 211
 		</tbody>
212 212
 		<?php
213
-	}
213
+    }
214 214
 
215
-	/**
216
-	 * Displays the table body if subscriptions were found.
217
-	 *
218
-	 * @param WPInv_Subscription[] $subscriptions
219
-	 */
220
-	public function print_table_body_subscriptions( $subscriptions ) {
215
+    /**
216
+     * Displays the table body if subscriptions were found.
217
+     *
218
+     * @param WPInv_Subscription[] $subscriptions
219
+     */
220
+    public function print_table_body_subscriptions( $subscriptions ) {
221 221
 
222
-		?>
222
+        ?>
223 223
 		<tbody>
224 224
 
225 225
 			<?php foreach ( $subscriptions as $subscription ) : ?>
226 226
 				<tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>">
227 227
 					<?php
228
-						wpinv_get_template(
229
-							'subscriptions/subscriptions-table-row.php',
230
-							array(
231
-								'subscription' => $subscription,
232
-								'widget'       => $this
233
-							)
234
-						);
235
-					?>
228
+                        wpinv_get_template(
229
+                            'subscriptions/subscriptions-table-row.php',
230
+                            array(
231
+                                'subscription' => $subscription,
232
+                                'widget'       => $this
233
+                            )
234
+                        );
235
+                    ?>
236 236
 				</tr>
237 237
 			<?php endforeach; ?>
238 238
 
239 239
 		</tbody>
240 240
 		<?php
241
-	}
242
-
243
-	/**
244
-	 * Adds row actions to a column
245
-	 *
246
-	 * @param string $content column content
247
-	 * @param WPInv_Subscription $subscription
248
-	 * @since       1.0.0
249
-	 * @return      string
250
-	 */
251
-	public function add_row_actions( $content, $subscription ) {
252
-
253
-		// Prepare row actions.
254
-		$actions = array();
255
-
256
-		// View subscription action.
257
-		$view_url        = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
258
-		$view_url        = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) );
259
-		$actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>';
260
-
261
-		// Filter the actions.
262
-		$actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription );
263
-
264
-		$sanitized  = array();
265
-		foreach ( $actions as $key => $action ) {
266
-			$key         = sanitize_html_class( $key );
267
-			$action      = wp_kses_post( $action );
268
-			$sanitized[] = "<span class='$key'>$action</span>";
269
-		}
270
-
271
-		$row_actions  = "<small class='form-text getpaid-subscription-item-actions'>";
272
-		$row_actions .= implode( ' | ', $sanitized );
273
-		$row_actions .= '</small>';
274
-
275
-		return $content . $row_actions;
276
-	}
277
-
278
-	/**
279
-	 * Displays the table footer.
280
-	 *
281
-	 */
282
-	public function print_table_footer() {
283
-
284
-		?>
241
+    }
242
+
243
+    /**
244
+     * Adds row actions to a column
245
+     *
246
+     * @param string $content column content
247
+     * @param WPInv_Subscription $subscription
248
+     * @since       1.0.0
249
+     * @return      string
250
+     */
251
+    public function add_row_actions( $content, $subscription ) {
252
+
253
+        // Prepare row actions.
254
+        $actions = array();
255
+
256
+        // View subscription action.
257
+        $view_url        = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
258
+        $view_url        = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) );
259
+        $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>';
260
+
261
+        // Filter the actions.
262
+        $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription );
263
+
264
+        $sanitized  = array();
265
+        foreach ( $actions as $key => $action ) {
266
+            $key         = sanitize_html_class( $key );
267
+            $action      = wp_kses_post( $action );
268
+            $sanitized[] = "<span class='$key'>$action</span>";
269
+        }
270
+
271
+        $row_actions  = "<small class='form-text getpaid-subscription-item-actions'>";
272
+        $row_actions .= implode( ' | ', $sanitized );
273
+        $row_actions .= '</small>';
274
+
275
+        return $content . $row_actions;
276
+    }
277
+
278
+    /**
279
+     * Displays the table footer.
280
+     *
281
+     */
282
+    public function print_table_footer() {
283
+
284
+        ?>
285 285
 
286 286
 				<tfoot>
287 287
 					<tr>
@@ -296,129 +296,129 @@  discard block
 block discarded – undo
296 296
 			</table>
297 297
 		<?php
298 298
 
299
-	}
299
+    }
300 300
 
301
-	/**
302
-	 * Displays the navigation.
303
-	 *
304
-	 * @param int $total
305
-	 */
306
-	public function print_navigation( $total ) {
301
+    /**
302
+     * Displays the navigation.
303
+     *
304
+     * @param int $total
305
+     */
306
+    public function print_navigation( $total ) {
307 307
 
308
-		if ( $total < 1 ) {
308
+        if ( $total < 1 ) {
309 309
 
310
-			// Out-of-bounds, run the query again without LIMIT for total count.
311
-			$args  = array(
312
-				'customer_in' => get_current_user_id(),
313
-				'fields'      => 'id',
314
-			);
310
+            // Out-of-bounds, run the query again without LIMIT for total count.
311
+            $args  = array(
312
+                'customer_in' => get_current_user_id(),
313
+                'fields'      => 'id',
314
+            );
315 315
 
316
-			$count_query = new GetPaid_Subscriptions_Query( $args );
317
-			$total       = $count_query->get_total();
318
-		}
316
+            $count_query = new GetPaid_Subscriptions_Query( $args );
317
+            $total       = $count_query->get_total();
318
+        }
319 319
 
320
-		// Abort if we do not have pages.
321
-		if ( 2 > $total ) {
322
-			return;
323
-		}
320
+        // Abort if we do not have pages.
321
+        if ( 2 > $total ) {
322
+            return;
323
+        }
324 324
 
325
-		?>
325
+        ?>
326 326
 
327 327
 		<div class="getpaid-subscriptions-pagination">
328 328
 			<?php
329
-				$big = 999999;
330
-
331
-				echo getpaid_paginate_links(
332
-					array(
333
-						'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
334
-						'format'  => '?paged=%#%',
335
-						'total'   => (int) ceil( $total / 10 ),
336
-					)
337
-				);
338
-			?>
329
+                $big = 999999;
330
+
331
+                echo getpaid_paginate_links(
332
+                    array(
333
+                        'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
334
+                        'format'  => '?paged=%#%',
335
+                        'total'   => (int) ceil( $total / 10 ),
336
+                    )
337
+                );
338
+            ?>
339 339
 		</div>
340 340
 
341 341
 		<?php
342
-	}
343
-
344
-	/**
345
-	 * Returns a single subscription's columns.
346
-	 *
347
-	 * @param WPInv_Subscription $subscription
348
-	 *
349
-	 * @return array
350
-	 */
351
-	public function get_single_subscription_columns( $subscription ) {
352
-
353
-		// Prepare subscription detail columns.
354
-		$fields = apply_filters(
355
-			'getpaid_single_subscription_details_fields',
356
-			array(
357
-				'status'           => __( 'Status', 'invoicing' ),
358
-				'initial_amount'   => __( 'Initial amount', 'invoicing' ),
359
-				'recurring_amount' => __( 'Recurring amount', 'invoicing' ),
360
-				'start_date'       => __( 'Start date', 'invoicing' ),
361
-				'expiry_date'      => __( 'Next payment', 'invoicing' ),
362
-				'payments'         => __( 'Payments', 'invoicing' ),
363
-				'item'             => __( 'Item', 'invoicing' ),
364
-			),
365
-			$subscription
366
-		);
367
-
368
-		if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) {
369
-			$fields['expiry_date'] = __( 'End date', 'invoicing' );
370
-		}
371
-
372
-		if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) {
373
-			unset( $fields['initial_amount'] );
374
-		}
375
-
376
-		return $fields;
377
-	}
378
-
379
-	/**
380
-	 * Displays a single subscription.
381
-	 *
382
-	 * @param string $subscription
383
-	 *
384
-	 * @return string
385
-	 */
386
-	public function display_single_subscription( $subscription ) {
387
-
388
-		// Fetch the subscription.
389
-		$subscription = new WPInv_Subscription( (int) $subscription );
390
-
391
-		if ( ! $subscription->get_id() ) {
392
-
393
-			return aui()->alert(
394
-				array(
395
-					'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ),
396
-					'type'    => 'error',
397
-				)
398
-			);
399
-
400
-		}
401
-
402
-		// Ensure that the user owns this subscription key.
403
-		if ( get_current_user_id() != $subscription->get_customer_id() && current_user_can( 'edit_options' ) ) {
404
-
405
-			return aui()->alert(
406
-				array(
407
-					'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ),
408
-					'type'    => 'error',
409
-				)
410
-			);
411
-
412
-		}
413
-
414
-		return wpinv_get_template_html(
415
-			'subscriptions/subscription-details.php',
416
-			array(
417
-				'subscription' => $subscription,
418
-				'widget'       => $this
419
-			)
420
-		);
421
-
422
-	}
342
+    }
343
+
344
+    /**
345
+     * Returns a single subscription's columns.
346
+     *
347
+     * @param WPInv_Subscription $subscription
348
+     *
349
+     * @return array
350
+     */
351
+    public function get_single_subscription_columns( $subscription ) {
352
+
353
+        // Prepare subscription detail columns.
354
+        $fields = apply_filters(
355
+            'getpaid_single_subscription_details_fields',
356
+            array(
357
+                'status'           => __( 'Status', 'invoicing' ),
358
+                'initial_amount'   => __( 'Initial amount', 'invoicing' ),
359
+                'recurring_amount' => __( 'Recurring amount', 'invoicing' ),
360
+                'start_date'       => __( 'Start date', 'invoicing' ),
361
+                'expiry_date'      => __( 'Next payment', 'invoicing' ),
362
+                'payments'         => __( 'Payments', 'invoicing' ),
363
+                'item'             => __( 'Item', 'invoicing' ),
364
+            ),
365
+            $subscription
366
+        );
367
+
368
+        if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) {
369
+            $fields['expiry_date'] = __( 'End date', 'invoicing' );
370
+        }
371
+
372
+        if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) {
373
+            unset( $fields['initial_amount'] );
374
+        }
375
+
376
+        return $fields;
377
+    }
378
+
379
+    /**
380
+     * Displays a single subscription.
381
+     *
382
+     * @param string $subscription
383
+     *
384
+     * @return string
385
+     */
386
+    public function display_single_subscription( $subscription ) {
387
+
388
+        // Fetch the subscription.
389
+        $subscription = new WPInv_Subscription( (int) $subscription );
390
+
391
+        if ( ! $subscription->get_id() ) {
392
+
393
+            return aui()->alert(
394
+                array(
395
+                    'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ),
396
+                    'type'    => 'error',
397
+                )
398
+            );
399
+
400
+        }
401
+
402
+        // Ensure that the user owns this subscription key.
403
+        if ( get_current_user_id() != $subscription->get_customer_id() && current_user_can( 'edit_options' ) ) {
404
+
405
+            return aui()->alert(
406
+                array(
407
+                    'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ),
408
+                    'type'    => 'error',
409
+                )
410
+            );
411
+
412
+        }
413
+
414
+        return wpinv_get_template_html(
415
+            'subscriptions/subscription-details.php',
416
+            array(
417
+                'subscription' => $subscription,
418
+                'widget'       => $this
419
+            )
420
+        );
421
+
422
+    }
423 423
 
424 424
 }
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -411,9 +411,9 @@
 block discarded – undo
411 411
     $bill_times      = $item->get_recurring_limit();
412 412
 
413 413
     if ( ! empty( $bill_times ) ) {
414
-		$bill_times = $item->get_recurring_interval() * $bill_times;
415
-		$bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times );
416
-	}
414
+        $bill_times = $item->get_recurring_interval() * $bill_times;
415
+        $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times );
416
+    }
417 417
 
418 418
     if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) {
419 419
         $initial_price   = wpinv_price( $item->get_sub_total(), $currency );
Please login to merge, or discard this patch.
includes/subscription-functions.php 1 patch
Indentation   +181 added lines, -181 removed lines patch added patch discarded remove patch
@@ -17,28 +17,28 @@  discard block
 block discarded – undo
17 17
  */
18 18
 function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
19 19
 
20
-	// Do not retrieve all fields if we just want the count.
21
-	if ( 'count' == $return ) {
22
-		$args['fields'] = 'id';
23
-		$args['number'] = 1;
24
-	}
20
+    // Do not retrieve all fields if we just want the count.
21
+    if ( 'count' == $return ) {
22
+        $args['fields'] = 'id';
23
+        $args['number'] = 1;
24
+    }
25 25
 
26
-	// Do not count all matches if we just want the results.
27
-	if ( 'results' == $return ) {
28
-		$args['count_total'] = false;
29
-	}
26
+    // Do not count all matches if we just want the results.
27
+    if ( 'results' == $return ) {
28
+        $args['count_total'] = false;
29
+    }
30 30
 
31
-	$query = new GetPaid_Subscriptions_Query( $args );
31
+    $query = new GetPaid_Subscriptions_Query( $args );
32 32
 
33
-	if ( 'results' == $return ) {
34
-		return $query->get_results();
35
-	}
33
+    if ( 'results' == $return ) {
34
+        return $query->get_results();
35
+    }
36 36
 
37
-	if ( 'count' == $return ) {
38
-		return $query->get_total();
39
-	}
37
+    if ( 'count' == $return ) {
38
+        return $query->get_total();
39
+    }
40 40
 
41
-	return $query;
41
+    return $query;
42 42
 }
43 43
 
44 44
 /**
@@ -48,18 +48,18 @@  discard block
 block discarded – undo
48 48
  */
49 49
 function getpaid_get_subscription_statuses() {
50 50
 
51
-	return apply_filters(
52
-		'getpaid_get_subscription_statuses',
53
-		array(
54
-			'pending'    => __( 'Pending', 'invoicing' ),
55
-			'trialling'  => __( 'Trialing', 'invoicing' ),
56
-			'active'     => __( 'Active', 'invoicing' ),
57
-			'failing'    => __( 'Failing', 'invoicing' ),
58
-			'expired'    => __( 'Expired', 'invoicing' ),
59
-			'completed'  => __( 'Complete', 'invoicing' ),
60
-			'cancelled'  => __( 'Cancelled', 'invoicing' ),
61
-		)
62
-	);
51
+    return apply_filters(
52
+        'getpaid_get_subscription_statuses',
53
+        array(
54
+            'pending'    => __( 'Pending', 'invoicing' ),
55
+            'trialling'  => __( 'Trialing', 'invoicing' ),
56
+            'active'     => __( 'Active', 'invoicing' ),
57
+            'failing'    => __( 'Failing', 'invoicing' ),
58
+            'expired'    => __( 'Expired', 'invoicing' ),
59
+            'completed'  => __( 'Complete', 'invoicing' ),
60
+            'cancelled'  => __( 'Cancelled', 'invoicing' ),
61
+        )
62
+    );
63 63
 
64 64
 }
65 65
 
@@ -69,8 +69,8 @@  discard block
 block discarded – undo
69 69
  * @return string
70 70
  */
71 71
 function getpaid_get_subscription_status_label( $status ) {
72
-	$statuses = getpaid_get_subscription_statuses();
73
-	return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
72
+    $statuses = getpaid_get_subscription_statuses();
73
+    return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
74 74
 }
75 75
 
76 76
 /**
@@ -80,18 +80,18 @@  discard block
 block discarded – undo
80 80
  */
81 81
 function getpaid_get_subscription_status_classes() {
82 82
 
83
-	return apply_filters(
84
-		'getpaid_get_subscription_status_classes',
85
-		array(
86
-			'pending'    => 'badge-dark',
87
-			'trialling'  => 'badge-info',
88
-			'active'     => 'badge-success',
89
-			'failing'    => 'badge-warning',
90
-			'expired'    => 'badge-danger',
91
-			'completed'  => 'badge-primary',
92
-			'cancelled'  => 'badge-secondary',
93
-		)
94
-	);
83
+    return apply_filters(
84
+        'getpaid_get_subscription_status_classes',
85
+        array(
86
+            'pending'    => 'badge-dark',
87
+            'trialling'  => 'badge-info',
88
+            'active'     => 'badge-success',
89
+            'failing'    => 'badge-warning',
90
+            'expired'    => 'badge-danger',
91
+            'completed'  => 'badge-primary',
92
+            'cancelled'  => 'badge-secondary',
93
+        )
94
+    );
95 95
 
96 96
 }
97 97
 
@@ -102,15 +102,15 @@  discard block
 block discarded – undo
102 102
  */
103 103
 function getpaid_get_subscription_status_counts( $args = array() ) {
104 104
 
105
-	$statuses = array_keys( getpaid_get_subscription_statuses() );
106
-	$counts   = array();
105
+    $statuses = array_keys( getpaid_get_subscription_statuses() );
106
+    $counts   = array();
107 107
 
108
-	foreach ( $statuses as $status ) {
109
-		$_args             = wp_parse_args( "status=$status", $args );
110
-		$counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
111
-	}
108
+    foreach ( $statuses as $status ) {
109
+        $_args             = wp_parse_args( "status=$status", $args );
110
+        $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
111
+    }
112 112
 
113
-	return $counts;
113
+    return $counts;
114 114
 
115 115
 }
116 116
 
@@ -121,32 +121,32 @@  discard block
 block discarded – undo
121 121
  */
122 122
 function getpaid_get_subscription_periods() {
123 123
 
124
-	return apply_filters(
125
-		'getpaid_get_subscription_periods',
126
-		array(
124
+    return apply_filters(
125
+        'getpaid_get_subscription_periods',
126
+        array(
127 127
 
128
-			'day'   => array(
129
-				'singular' => __( '%s day', 'invoicing' ),
130
-				'plural'   => __( '%d days', 'invoicing' ),
131
-			),
128
+            'day'   => array(
129
+                'singular' => __( '%s day', 'invoicing' ),
130
+                'plural'   => __( '%d days', 'invoicing' ),
131
+            ),
132 132
 
133
-			'week'   => array(
134
-				'singular' => __( '%s week', 'invoicing' ),
135
-				'plural'   => __( '%d weeks', 'invoicing' ),
136
-			),
133
+            'week'   => array(
134
+                'singular' => __( '%s week', 'invoicing' ),
135
+                'plural'   => __( '%d weeks', 'invoicing' ),
136
+            ),
137 137
 
138
-			'month'   => array(
139
-				'singular' => __( '%s month', 'invoicing' ),
140
-				'plural'   => __( '%d months', 'invoicing' ),
141
-			),
138
+            'month'   => array(
139
+                'singular' => __( '%s month', 'invoicing' ),
140
+                'plural'   => __( '%d months', 'invoicing' ),
141
+            ),
142 142
 
143
-			'year'   => array(
144
-				'singular' => __( '%s year', 'invoicing' ),
145
-				'plural'   => __( '%d years', 'invoicing' ),
146
-			),
143
+            'year'   => array(
144
+                'singular' => __( '%s year', 'invoicing' ),
145
+                'plural'   => __( '%d years', 'invoicing' ),
146
+            ),
147 147
 
148
-		)
149
-	);
148
+        )
149
+    );
150 150
 
151 151
 }
152 152
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
  * @return int
158 158
  */
159 159
 function getpaid_get_subscription_trial_period_interval( $trial_period ) {
160
-	return (int) preg_replace( '/[^0-9]/', '', $trial_period );
160
+    return (int) preg_replace( '/[^0-9]/', '', $trial_period );
161 161
 }
162 162
 
163 163
 /**
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
  * @return string
168 168
  */
169 169
 function getpaid_get_subscription_trial_period_period( $trial_period ) {
170
-	return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
170
+    return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
171 171
 }
172 172
 
173 173
 /**
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
  * @return string
179 179
  */
180 180
 function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) {
181
-	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
182
-	return strtolower( sanitize_text_field( $label ) );
181
+    $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
182
+    return strtolower( sanitize_text_field( $label ) );
183 183
 }
184 184
 
185 185
 /**
@@ -190,22 +190,22 @@  discard block
 block discarded – undo
190 190
  */
191 191
 function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) {
192 192
 
193
-	$periods = getpaid_get_subscription_periods();
194
-	$period  = strtolower( $period );
193
+    $periods = getpaid_get_subscription_periods();
194
+    $period  = strtolower( $period );
195 195
 
196
-	if ( isset( $periods[ $period ] ) ) {
197
-		return sprintf( $periods[ $period ]['singular'], $singular_prefix );
198
-	}
196
+    if ( isset( $periods[ $period ] ) ) {
197
+        return sprintf( $periods[ $period ]['singular'], $singular_prefix );
198
+    }
199 199
 
200
-	// Backwards compatibility.
201
-	foreach ( $periods as $key => $data ) {
202
-		if ( strpos( $key, $period ) === 0 ) {
203
-			return sprintf( $data['singular'], $singular_prefix );
204
-		}
205
-	}
200
+    // Backwards compatibility.
201
+    foreach ( $periods as $key => $data ) {
202
+        if ( strpos( $key, $period ) === 0 ) {
203
+            return sprintf( $data['singular'], $singular_prefix );
204
+        }
205
+    }
206 206
 
207
-	// Invalid string.
208
-	return '';
207
+    // Invalid string.
208
+    return '';
209 209
 }
210 210
 
211 211
 /**
@@ -217,22 +217,22 @@  discard block
 block discarded – undo
217 217
  */
218 218
 function getpaid_get_plural_subscription_period_label( $period, $interval ) {
219 219
 
220
-	$periods = getpaid_get_subscription_periods();
221
-	$period  = strtolower( $period );
220
+    $periods = getpaid_get_subscription_periods();
221
+    $period  = strtolower( $period );
222 222
 
223
-	if ( isset( $periods[ $period ] ) ) {
224
-		return sprintf( $periods[ $period ]['plural'], $interval );
225
-	}
223
+    if ( isset( $periods[ $period ] ) ) {
224
+        return sprintf( $periods[ $period ]['plural'], $interval );
225
+    }
226 226
 
227
-	// Backwards compatibility.
228
-	foreach ( $periods as $key => $data ) {
229
-		if ( strpos( $key, $period ) === 0 ) {
230
-			return sprintf( $data['plural'], $interval );
231
-		}
232
-	}
227
+    // Backwards compatibility.
228
+    foreach ( $periods as $key => $data ) {
229
+        if ( strpos( $key, $period ) === 0 ) {
230
+            return sprintf( $data['plural'], $interval );
231
+        }
232
+    }
233 233
 
234
-	// Invalid string.
235
-	return '';
234
+    // Invalid string.
235
+    return '';
236 236
 }
237 237
 
238 238
 /**
@@ -243,101 +243,101 @@  discard block
 block discarded – undo
243 243
  */
244 244
 function getpaid_get_formatted_subscription_amount( $subscription ) {
245 245
 
246
-	$initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
247
-	$recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
248
-	$period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
249
-	$bill_times = $subscription->get_bill_times();
246
+    $initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
247
+    $recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
248
+    $period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
249
+    $bill_times = $subscription->get_bill_times();
250 250
 
251
-	if ( ! empty( $bill_times ) ) {
252
-		$bill_times = $subscription->get_frequency() * $bill_times;
253
-		$bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
254
-	}
251
+    if ( ! empty( $bill_times ) ) {
252
+        $bill_times = $subscription->get_frequency() * $bill_times;
253
+        $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
254
+    }
255 255
 
256
-	// Trial periods.
257
-	if ( $subscription->has_trial_period() ) {
256
+    // Trial periods.
257
+    if ( $subscription->has_trial_period() ) {
258 258
 
259
-		$trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
260
-		$trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
259
+        $trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
260
+        $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
261 261
 
262
-		if ( empty( $bill_times ) ) {
262
+        if ( empty( $bill_times ) ) {
263 263
 
264
-			return sprintf(
264
+            return sprintf(
265 265
 
266
-				// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
267
-				_x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
268
-				$initial,
269
-				getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
270
-				$recurring,
271
-				$period
266
+                // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
267
+                _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
268
+                $initial,
269
+                getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
270
+                $recurring,
271
+                $period
272 272
 	
273
-			);
273
+            );
274 274
 
275
-		}
275
+        }
276 276
 
277
-		return sprintf(
277
+        return sprintf(
278 278
 
279
-			// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
280
-			_x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
281
-			$initial,
282
-			getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
283
-			$recurring,
284
-			$period,
285
-			$bill_times
286
-		);
279
+            // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
280
+            _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
281
+            $initial,
282
+            getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
283
+            $recurring,
284
+            $period,
285
+            $bill_times
286
+        );
287 287
 
288
-	}
288
+    }
289 289
 
290
-	if ( $initial != $recurring ) {
290
+    if ( $initial != $recurring ) {
291 291
 
292
-		if ( empty( $bill_times ) ) {
292
+        if ( empty( $bill_times ) ) {
293 293
 
294
-			return sprintf(
294
+            return sprintf(
295 295
 
296
-				// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
297
-				_x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
298
-				$initial,
299
-				$recurring,
300
-				$period
296
+                // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
297
+                _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
298
+                $initial,
299
+                $recurring,
300
+                $period
301 301
 	
302
-			);
302
+            );
303 303
 
304
-		}
304
+        }
305 305
 
306
-		return sprintf(
306
+        return sprintf(
307 307
 
308
-			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
309
-			_x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
310
-			$initial,
311
-			$recurring,
312
-			$period,
313
-			$bill_times
308
+            // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
309
+            _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
310
+            $initial,
311
+            $recurring,
312
+            $period,
313
+            $bill_times
314 314
 
315
-		);
315
+        );
316 316
 
317
-	}
317
+    }
318 318
 
319
-	if ( empty( $bill_times ) ) {
319
+    if ( empty( $bill_times ) ) {
320 320
 
321
-		return sprintf(
321
+        return sprintf(
322 322
 
323
-			// translators: $1: is the recurring amount, $2: is the recurring period
324
-			_x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
325
-			$initial,
326
-			$period
323
+            // translators: $1: is the recurring amount, $2: is the recurring period
324
+            _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
325
+            $initial,
326
+            $period
327 327
 	
328
-		);
328
+        );
329 329
 
330
-	}
330
+    }
331 331
 
332
-	return sprintf(
332
+    return sprintf(
333 333
 
334
-		// translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
335
-		_x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
336
-		$bill_times,
337
-		$initial,
338
-		$period
334
+        // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
335
+        _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
336
+        $bill_times,
337
+        $initial,
338
+        $period
339 339
 
340
-	);
340
+    );
341 341
 
342 342
 }
343 343
 
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
  * @return WPInv_Subscription|bool
349 349
  */
350 350
 function getpaid_get_invoice_subscription( $invoice ) {
351
-	return getpaid_subscriptions()->get_invoice_subscription( $invoice );
351
+    return getpaid_subscriptions()->get_invoice_subscription( $invoice );
352 352
 }
353 353
 
354 354
 /**
@@ -357,10 +357,10 @@  discard block
 block discarded – undo
357 357
  * @param WPInv_Invoice $invoice
358 358
  */
359 359
 function getpaid_activate_invoice_subscription( $invoice ) {
360
-	$subscription = getpaid_get_invoice_subscription( $invoice );
361
-	if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
362
-		$subscription->activate();
363
-	}
360
+    $subscription = getpaid_get_invoice_subscription( $invoice );
361
+    if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
362
+        $subscription->activate();
363
+    }
364 364
 }
365 365
 
366 366
 /**
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
  * @return WPInv_Subscriptions
370 370
  */
371 371
 function getpaid_subscriptions() {
372
-	return getpaid()->get( 'subscriptions' );
372
+    return getpaid()->get( 'subscriptions' );
373 373
 }
374 374
 
375 375
 /**
@@ -387,14 +387,14 @@  discard block
 block discarded – undo
387 387
         return false;
388 388
     }
389 389
 
390
-	// Fetch the invoiec subscription.
391
-	$subscription = getpaid_get_subscriptions(
392
-		array(
393
-			'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(),
394
-			'number'     => 1,
395
-		)
396
-	);
390
+    // Fetch the invoiec subscription.
391
+    $subscription = getpaid_get_subscriptions(
392
+        array(
393
+            'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(),
394
+            'number'     => 1,
395
+        )
396
+    );
397 397
 
398
-	return empty( $subscription ) ? false : $subscription[0];
398
+    return empty( $subscription ) ? false : $subscription[0];
399 399
 
400 400
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 1 patch
Indentation   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -12,280 +12,280 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Refresh_Prices {
14 14
 
15
-	/**
16
-	 * Contains the response for refreshing prices.
17
-	 * @var array
18
-	 */
19
-	public $response = array();
15
+    /**
16
+     * Contains the response for refreshing prices.
17
+     * @var array
18
+     */
19
+    public $response = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$this->response = array(
29
-			'submission_id' => $submission->id,
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $this->response = array(
29
+            'submission_id' => $submission->id,
30 30
             'has_recurring' => $submission->has_recurring,
31 31
             'is_free'       => ! $submission->should_collect_payment_details(),
32
-		);
33
-
34
-		$this->add_totals( $submission );
35
-		$this->add_texts( $submission );
36
-		$this->add_items( $submission );
37
-		$this->add_fees( $submission );
38
-		$this->add_discounts( $submission );
39
-		$this->add_taxes( $submission );
40
-		$this->add_gateways( $submission );
41
-		$this->add_data( $submission );
42
-
43
-	}
44
-
45
-	/**
46
-	 * Adds totals to a response for submission refresh prices.
47
-	 *
48
-	 * @param GetPaid_Payment_Form_Submission $submission
49
-	 */
50
-	public function add_totals( $submission ) {
51
-
52
-		$this->response = array_merge(
53
-			$this->response,
54
-			array(
55
-
56
-				'totals'        => array(
57
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
58
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
59
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
60
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
61
-					'total'     => $submission->format_amount( $submission->get_total() ),
62
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
63
-				),
64
-
65
-				'recurring'     => array(
66
-					'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
67
-					'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
68
-					'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
69
-					'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
70
-					'total'     => $submission->format_amount( $submission->get_recurring_total() ),
71
-				),
72
-
73
-				'initial_amt'   => wpinv_round_amount( $submission->get_total(), null, true ),
74
-				'currency'      => $submission->get_currency(),
75
-
76
-			)
77
-		);
78
-
79
-	}
80
-
81
-	/**
82
-	 * Adds texts to a response for submission refresh prices.
83
-	 *
84
-	 * @param GetPaid_Payment_Form_Submission $submission
85
-	 */
86
-	public function add_texts( $submission ) {
87
-
88
-		$payable = $submission->format_amount( $submission->get_total() );
89
-
90
-		if ( $submission->has_recurring != 0 ) {
91
-
92
-			$recurring = new WPInv_Item( $submission->has_recurring );
93
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
94
-
95
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
96
-				$payable = "$payable / $period";
97
-			} else {
98
-				$payable = sprintf(
99
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
100
-					$submission->format_amount( $submission->get_total() ),
101
-					$submission->format_amount( $submission->get_recurring_total() ),
102
-					$period
103
-				);
104
-			}
105
-
106
-		}
107
-
108
-		$texts = array(
109
-			'.getpaid-checkout-total-payable' => $payable,
110
-		);
111
-
112
-		foreach ( $submission->get_items() as $item ) {
113
-			$item_id                                               = $item->get_id();
114
-			$initial_price                                         = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) );
115
-			$recurring_price                                       = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) );
116
-			$texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
117
-		}
118
-
119
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
120
-
121
-	}
122
-
123
-	/**
124
-	 * Adds items to a response for submission refresh prices.
125
-	 *
126
-	 * @param GetPaid_Payment_Form_Submission $submission
127
-	 */
128
-	public function add_items( $submission ) {
129
-
130
-		// Add items.
131
-		$items = array();
32
+        );
33
+
34
+        $this->add_totals( $submission );
35
+        $this->add_texts( $submission );
36
+        $this->add_items( $submission );
37
+        $this->add_fees( $submission );
38
+        $this->add_discounts( $submission );
39
+        $this->add_taxes( $submission );
40
+        $this->add_gateways( $submission );
41
+        $this->add_data( $submission );
42
+
43
+    }
44
+
45
+    /**
46
+     * Adds totals to a response for submission refresh prices.
47
+     *
48
+     * @param GetPaid_Payment_Form_Submission $submission
49
+     */
50
+    public function add_totals( $submission ) {
51
+
52
+        $this->response = array_merge(
53
+            $this->response,
54
+            array(
55
+
56
+                'totals'        => array(
57
+                    'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
58
+                    'discount'  => $submission->format_amount( $submission->get_discount() ),
59
+                    'fees'      => $submission->format_amount( $submission->get_fee() ),
60
+                    'tax'       => $submission->format_amount( $submission->get_tax() ),
61
+                    'total'     => $submission->format_amount( $submission->get_total() ),
62
+                    'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
63
+                ),
64
+
65
+                'recurring'     => array(
66
+                    'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
67
+                    'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
68
+                    'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
69
+                    'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
70
+                    'total'     => $submission->format_amount( $submission->get_recurring_total() ),
71
+                ),
72
+
73
+                'initial_amt'   => wpinv_round_amount( $submission->get_total(), null, true ),
74
+                'currency'      => $submission->get_currency(),
75
+
76
+            )
77
+        );
78
+
79
+    }
80
+
81
+    /**
82
+     * Adds texts to a response for submission refresh prices.
83
+     *
84
+     * @param GetPaid_Payment_Form_Submission $submission
85
+     */
86
+    public function add_texts( $submission ) {
87
+
88
+        $payable = $submission->format_amount( $submission->get_total() );
89
+
90
+        if ( $submission->has_recurring != 0 ) {
91
+
92
+            $recurring = new WPInv_Item( $submission->has_recurring );
93
+            $period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
94
+
95
+            if ( $submission->get_total() == $submission->get_recurring_total() ) {
96
+                $payable = "$payable / $period";
97
+            } else {
98
+                $payable = sprintf(
99
+                    __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
100
+                    $submission->format_amount( $submission->get_total() ),
101
+                    $submission->format_amount( $submission->get_recurring_total() ),
102
+                    $period
103
+                );
104
+            }
105
+
106
+        }
107
+
108
+        $texts = array(
109
+            '.getpaid-checkout-total-payable' => $payable,
110
+        );
132 111
 
133 112
         foreach ( $submission->get_items() as $item ) {
134
-			$item_id           = $item->get_id();
135
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
136
-		}
113
+            $item_id                                               = $item->get_id();
114
+            $initial_price                                         = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) );
115
+            $recurring_price                                       = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) );
116
+            $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
117
+        }
137 118
 
138
-		$this->response = array_merge(
139
-			$this->response,
140
-			array( 'items' => $items )
141
-		);
119
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
142 120
 
143
-	}
121
+    }
144 122
 
145
-	/**
146
-	 * Adds fees to a response for submission refresh prices.
147
-	 *
148
-	 * @param GetPaid_Payment_Form_Submission $submission
149
-	 */
150
-	public function add_fees( $submission ) {
123
+    /**
124
+     * Adds items to a response for submission refresh prices.
125
+     *
126
+     * @param GetPaid_Payment_Form_Submission $submission
127
+     */
128
+    public function add_items( $submission ) {
151 129
 
152
-		$fees = array();
130
+        // Add items.
131
+        $items = array();
153 132
 
154
-        foreach ( $submission->get_fees() as $name => $data ) {
155
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
156
-		}
133
+        foreach ( $submission->get_items() as $item ) {
134
+            $item_id           = $item->get_id();
135
+            $items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
136
+        }
157 137
 
158
-		$this->response = array_merge(
159
-			$this->response,
160
-			array( 'fees' => $fees )
161
-		);
138
+        $this->response = array_merge(
139
+            $this->response,
140
+            array( 'items' => $items )
141
+        );
162 142
 
163
-	}
143
+    }
164 144
 
165
-	/**
166
-	 * Adds discounts to a response for submission refresh prices.
167
-	 *
168
-	 * @param GetPaid_Payment_Form_Submission $submission
169
-	 */
170
-	public function add_discounts( $submission ) {
145
+    /**
146
+     * Adds fees to a response for submission refresh prices.
147
+     *
148
+     * @param GetPaid_Payment_Form_Submission $submission
149
+     */
150
+    public function add_fees( $submission ) {
171 151
 
172
-		$discounts = array();
152
+        $fees = array();
173 153
 
174
-        foreach ( $submission->get_discounts() as $name => $data ) {
175
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
176
-		}
154
+        foreach ( $submission->get_fees() as $name => $data ) {
155
+            $fees[$name] = $submission->format_amount( $data['initial_fee'] );
156
+        }
177 157
 
178
-		$this->response = array_merge(
179
-			$this->response,
180
-			array( 'discounts' => $discounts )
181
-		);
158
+        $this->response = array_merge(
159
+            $this->response,
160
+            array( 'fees' => $fees )
161
+        );
182 162
 
183
-	}
163
+    }
184 164
 
185
-	/**
186
-	 * Adds taxes to a response for submission refresh prices.
187
-	 *
188
-	 * @param GetPaid_Payment_Form_Submission $submission
189
-	 */
190
-	public function add_taxes( $submission ) {
165
+    /**
166
+     * Adds discounts to a response for submission refresh prices.
167
+     *
168
+     * @param GetPaid_Payment_Form_Submission $submission
169
+     */
170
+    public function add_discounts( $submission ) {
191 171
 
192
-		$taxes  = array();
193
-		$markup = '';
194
-        foreach ( $submission->get_taxes() as $name => $data ) {
195
-			$name          = sanitize_text_field( $name );
196
-			$amount        = $submission->format_amount( $data['initial_tax'] );
197
-			$taxes[$name]  = $amount;
198
-			$markup       .= "<small class='form-text'>$name : $amount</small>";
199
-		}
172
+        $discounts = array();
173
+
174
+        foreach ( $submission->get_discounts() as $name => $data ) {
175
+            $discounts[$name] = $submission->format_amount( $data['initial_discount'] );
176
+        }
200 177
 
201
-		if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) {
202
-			$this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
203
-		}
178
+        $this->response = array_merge(
179
+            $this->response,
180
+            array( 'discounts' => $discounts )
181
+        );
204 182
 
205
-		$this->response = array_merge(
206
-			$this->response,
207
-			array( 'taxes' => $taxes )
208
-		);
183
+    }
209 184
 
210
-	}
185
+    /**
186
+     * Adds taxes to a response for submission refresh prices.
187
+     *
188
+     * @param GetPaid_Payment_Form_Submission $submission
189
+     */
190
+    public function add_taxes( $submission ) {
191
+
192
+        $taxes  = array();
193
+        $markup = '';
194
+        foreach ( $submission->get_taxes() as $name => $data ) {
195
+            $name          = sanitize_text_field( $name );
196
+            $amount        = $submission->format_amount( $data['initial_tax'] );
197
+            $taxes[$name]  = $amount;
198
+            $markup       .= "<small class='form-text'>$name : $amount</small>";
199
+        }
211 200
 
212
-	/**
213
-	 * Adds gateways to a response for submission refresh prices.
214
-	 *
215
-	 * @param GetPaid_Payment_Form_Submission $submission
216
-	 */
217
-	public function add_gateways( $submission ) {
201
+        if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) {
202
+            $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
203
+        }
218 204
 
219
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
205
+        $this->response = array_merge(
206
+            $this->response,
207
+            array( 'taxes' => $taxes )
208
+        );
220 209
 
221
-		if ( $this->response['has_recurring'] ) {
210
+    }
222 211
 
223
-			foreach ( $gateways as $i => $gateway ) {
212
+    /**
213
+     * Adds gateways to a response for submission refresh prices.
214
+     *
215
+     * @param GetPaid_Payment_Form_Submission $submission
216
+     */
217
+    public function add_gateways( $submission ) {
224 218
 
225
-				if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
226
-					unset( $gateways[ $i ] );
227
-				}
219
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
228 220
 
229
-			}
221
+        if ( $this->response['has_recurring'] ) {
230 222
 
231
-		}
223
+            foreach ( $gateways as $i => $gateway ) {
232 224
 
225
+                if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
226
+                    unset( $gateways[ $i ] );
227
+                }
233 228
 
234
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
235
-		$this->response = array_merge(
236
-			$this->response,
237
-			array( 'gateways' => $gateways )
238
-		);
229
+            }
239 230
 
240
-	}
231
+        }
241 232
 
242
-	/**
243
-	 * Standardizes prices.
244
-	 *
245
-	 * @param int $item_id
246
-	 * @param float $item_total
247
-	 * @param string $discount_code
248
-	 * @param bool $recurring
249
-	 */
250
-	public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) {
251 233
 
252
-		$standardadized_price = $item_total;
234
+        $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
235
+        $this->response = array_merge(
236
+            $this->response,
237
+            array( 'gateways' => $gateways )
238
+        );
253 239
 
254
-		// Do we have a $discount_code?
255
-		if ( ! empty( $discount_code ) ) {
240
+    }
256 241
 
257
-			$discount = new WPInv_Discount( $discount_code );
242
+    /**
243
+     * Standardizes prices.
244
+     *
245
+     * @param int $item_id
246
+     * @param float $item_total
247
+     * @param string $discount_code
248
+     * @param bool $recurring
249
+     */
250
+    public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) {
251
+
252
+        $standardadized_price = $item_total;
258 253
 
259
-			if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) {
260
-				$standardadized_price = $item_total - $discount->get_discounted_amount( $item_total );
261
-			}
254
+        // Do we have a $discount_code?
255
+        if ( ! empty( $discount_code ) ) {
262 256
 
263
-		}
257
+            $discount = new WPInv_Discount( $discount_code );
264 258
 
265
-    	return max( 0, $standardadized_price );
259
+            if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) {
260
+                $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total );
261
+            }
266 262
 
267
-	}
263
+        }
268 264
 
269
-	/**
270
-	 * Adds data to a response for submission refresh prices.
271
-	 *
272
-	 * @param GetPaid_Payment_Form_Submission $submission
273
-	 */
274
-	public function add_data( $submission ) {
265
+        return max( 0, $standardadized_price );
275 266
 
276
-		$this->response = array_merge(
277
-			$this->response,
278
-			array(
279
-				'js_data' => apply_filters(
280
-					'getpaid_submission_js_data',
281
-					array(
282
-						'is_recurring' => $this->response['has_recurring'],
283
-					),
284
-					$submission
285
-				)
286
-			)
287
-		);
267
+    }
288 268
 
289
-	}
269
+    /**
270
+     * Adds data to a response for submission refresh prices.
271
+     *
272
+     * @param GetPaid_Payment_Form_Submission $submission
273
+     */
274
+    public function add_data( $submission ) {
275
+
276
+        $this->response = array_merge(
277
+            $this->response,
278
+            array(
279
+                'js_data' => apply_filters(
280
+                    'getpaid_submission_js_data',
281
+                    array(
282
+                        'is_recurring' => $this->response['has_recurring'],
283
+                    ),
284
+                    $submission
285
+                )
286
+            )
287
+        );
288
+
289
+    }
290 290
 
291 291
 }
Please login to merge, or discard this patch.