@@ -12,79 +12,79 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Items { |
14 | 14 | |
15 | - /** |
|
16 | - * Submission items. |
|
17 | - * @var GetPaid_Form_Item[] |
|
18 | - */ |
|
19 | - public $items = array(); |
|
20 | - |
|
21 | 15 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - */ |
|
26 | - public function __construct( $submission ) { |
|
27 | - |
|
28 | - $data = $submission->get_data(); |
|
29 | - $payment_form = $submission->get_payment_form(); |
|
30 | - |
|
31 | - // Prepare the selected items. |
|
32 | - $selected_items = array(); |
|
33 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
35 | - } |
|
36 | - |
|
37 | - // For default forms, ensure that an item has been set. |
|
38 | - if ( $payment_form->is_default() && ! $submission->has_invoice() && isset( $data['getpaid-form-items'] ) ) { |
|
39 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
40 | - $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) ); |
|
41 | - } |
|
16 | + * Submission items. |
|
17 | + * @var GetPaid_Form_Item[] |
|
18 | + */ |
|
19 | + public $items = array(); |
|
42 | 20 | |
43 | - // Process each individual item. |
|
44 | - foreach ( $payment_form->get_items() as $item ) { |
|
45 | - $this->process_item( $item, $selected_items ); |
|
46 | - } |
|
47 | - |
|
48 | - } |
|
21 | + /** |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + */ |
|
26 | + public function __construct( $submission ) { |
|
27 | + |
|
28 | + $data = $submission->get_data(); |
|
29 | + $payment_form = $submission->get_payment_form(); |
|
30 | + |
|
31 | + // Prepare the selected items. |
|
32 | + $selected_items = array(); |
|
33 | + if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | + $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
35 | + } |
|
36 | + |
|
37 | + // For default forms, ensure that an item has been set. |
|
38 | + if ( $payment_form->is_default() && ! $submission->has_invoice() && isset( $data['getpaid-form-items'] ) ) { |
|
39 | + $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
40 | + $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) ); |
|
41 | + } |
|
42 | + |
|
43 | + // Process each individual item. |
|
44 | + foreach ( $payment_form->get_items() as $item ) { |
|
45 | + $this->process_item( $item, $selected_items ); |
|
46 | + } |
|
47 | + |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Process a single item. |
|
52 | - * |
|
53 | - * @param GetPaid_Form_Item $item |
|
54 | - * @param array $selected_items |
|
55 | - */ |
|
56 | - public function process_item( $item, $selected_items ) { |
|
50 | + /** |
|
51 | + * Process a single item. |
|
52 | + * |
|
53 | + * @param GetPaid_Form_Item $item |
|
54 | + * @param array $selected_items |
|
55 | + */ |
|
56 | + public function process_item( $item, $selected_items ) { |
|
57 | 57 | |
58 | - // Abort if this is an optional item and it has not been selected. |
|
59 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
60 | - return; |
|
61 | - } |
|
58 | + // Abort if this is an optional item and it has not been selected. |
|
59 | + if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
60 | + return; |
|
61 | + } |
|
62 | 62 | |
63 | - // (maybe) let customers change the quantities and prices. |
|
64 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
63 | + // (maybe) let customers change the quantities and prices. |
|
64 | + if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
65 | 65 | |
66 | - // Maybe change the quantities. |
|
67 | - if ( $item->allows_quantities() ) { |
|
68 | - $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
69 | - } |
|
66 | + // Maybe change the quantities. |
|
67 | + if ( $item->allows_quantities() ) { |
|
68 | + $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
69 | + } |
|
70 | 70 | |
71 | - // Maybe change the price. |
|
72 | - if ( $item->user_can_set_their_price() ) { |
|
73 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
71 | + // Maybe change the price. |
|
72 | + if ( $item->user_can_set_their_price() ) { |
|
73 | + $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
74 | 74 | |
75 | - if ( $item->get_minimum_price() > $price ) { |
|
76 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), wpinv_sanitize_amount( $item->get_minimum_price() ) ) ); |
|
77 | - } |
|
75 | + if ( $item->get_minimum_price() > $price ) { |
|
76 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), wpinv_sanitize_amount( $item->get_minimum_price() ) ) ); |
|
77 | + } |
|
78 | 78 | |
79 | - $item->set_price( $price ); |
|
79 | + $item->set_price( $price ); |
|
80 | 80 | |
81 | - } |
|
81 | + } |
|
82 | 82 | |
83 | - } |
|
83 | + } |
|
84 | 84 | |
85 | - // Save the item. |
|
86 | - $this->items[] = $item; |
|
85 | + // Save the item. |
|
86 | + $this->items[] = $item; |
|
87 | 87 | |
88 | - } |
|
88 | + } |
|
89 | 89 | |
90 | 90 | } |
@@ -13,629 +13,629 @@ |
||
13 | 13 | |
14 | 14 | return array( |
15 | 15 | |
16 | - 'id' => array( |
|
17 | - 'description' => __( 'Unique identifier for the invoice.', 'invoicing' ), |
|
18 | - 'type' => 'integer', |
|
19 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
20 | - 'readonly' => true, |
|
21 | - ), |
|
22 | - |
|
23 | - 'parent_id' => array( |
|
24 | - 'description' => __( 'Parent invoice ID.', 'invoicing' ), |
|
25 | - 'type' => 'integer', |
|
26 | - 'minimum' => 0, |
|
27 | - 'default' => 0, |
|
28 | - 'context' => array( 'view', 'edit' ), |
|
29 | - ), |
|
30 | - |
|
31 | - 'key' => array( |
|
32 | - 'description' => __( 'A unique key for the invoice.', 'invoicing' ), |
|
33 | - 'type' => 'string', |
|
34 | - 'context' => array( 'view', 'edit' ), |
|
35 | - 'readonly' => true, |
|
36 | - ), |
|
37 | - |
|
38 | - 'number' => array( |
|
39 | - 'description' => __( 'A unique number for the invoice.', 'invoicing' ), |
|
40 | - 'type' => 'string', |
|
41 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
42 | - ), |
|
43 | - |
|
44 | - 'type' => array( |
|
45 | - 'description' => __( 'Get the invoice type (e.g invoice, quote etc).', 'invoicing' ), |
|
46 | - 'type' => 'string', |
|
47 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
48 | - 'readonly' => true, |
|
49 | - ), |
|
50 | - |
|
51 | - 'post_type' => array( |
|
52 | - 'description' => __( 'Get the invoice post type (e.g wpi_invoice, wpi_quote etc).', 'invoicing' ), |
|
53 | - 'type' => 'string', |
|
54 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
55 | - 'readonly' => true, |
|
56 | - ), |
|
57 | - |
|
58 | - 'version' => array( |
|
59 | - 'description' => __( 'Version of GetPaid/Invoicing which last updated the invoice.', 'invoicing' ), |
|
60 | - 'type' => 'integer', |
|
61 | - 'context' => array( 'view', 'edit' ), |
|
62 | - 'readonly' => true, |
|
63 | - ), |
|
64 | - |
|
65 | - 'template' => array( |
|
66 | - 'description' => __( 'The invoice template.', 'invoicing' ), |
|
67 | - 'type' => 'string', |
|
68 | - 'default' => 'quantity', |
|
69 | - 'enum' => array( 'quantity', 'hours', 'amount' ), |
|
70 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
71 | - ), |
|
72 | - |
|
73 | - 'status' => array( |
|
74 | - 'description' => __( 'Invoice status.', 'invoicing' ), |
|
75 | - 'type' => 'string', |
|
76 | - 'default' => 'wpi-pending', |
|
77 | - 'enum' => array_keys( wpinv_get_invoice_statuses( true ) ), |
|
78 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
79 | - ), |
|
80 | - |
|
81 | - 'status_nicename' => array( |
|
82 | - 'description' => __( 'A human readable name for the invoice status.', 'invoicing' ), |
|
83 | - 'type' => 'string', |
|
84 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
85 | - 'readonly' => true, |
|
86 | - ), |
|
87 | - |
|
88 | - 'currency' => array( |
|
89 | - 'description' => __( 'The invoice currency in ISO format.', 'invoicing' ), |
|
90 | - 'type' => 'string', |
|
91 | - 'default' => wpinv_get_currency(), |
|
92 | - 'enum' => array_keys( wpinv_get_currencies() ), |
|
93 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
94 | - ), |
|
95 | - |
|
96 | - 'date_created' => array( |
|
97 | - 'description' => __( "The date the invoice was created, in the site's timezone.", 'invoicing' ), |
|
98 | - 'type' => 'string', |
|
99 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
100 | - ), |
|
101 | - |
|
102 | - 'date_created_gmt' => array( |
|
103 | - 'description' => __( 'The GMT date the invoice was created.', 'invoicing' ), |
|
104 | - 'type' => 'string', |
|
105 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
106 | - 'readonly' => true, |
|
107 | - ), |
|
108 | - |
|
109 | - 'date_modified' => array( |
|
110 | - 'description' => __( "The date the invoice was last modified, in the site's timezone.", 'invoicing' ), |
|
111 | - 'type' => 'string', |
|
112 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
113 | - 'readonly' => true, |
|
114 | - ), |
|
115 | - |
|
116 | - 'date_modified_gmt' => array( |
|
117 | - 'description' => __( 'The GMT date the invoice was last modified.', 'invoicing' ), |
|
118 | - 'type' => 'string', |
|
119 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
120 | - 'readonly' => true, |
|
121 | - ), |
|
122 | - |
|
123 | - 'due_date' => array( |
|
124 | - 'description' => __( "The invoice's due date, in the site's timezone.", 'invoicing' ), |
|
125 | - 'type' => 'string', |
|
126 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
127 | - ), |
|
128 | - |
|
129 | - 'due_date_gmt' => array( |
|
130 | - 'description' => __( 'The GMT date the invoice is/was due.', 'invoicing' ), |
|
131 | - 'type' => 'string', |
|
132 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
133 | - 'readonly' => true, |
|
134 | - ), |
|
135 | - |
|
136 | - 'completed_date' => array( |
|
137 | - 'description' => __( "The date the invoice was paid, in the site's timezone.", 'invoicing' ), |
|
138 | - 'type' => 'string', |
|
139 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
140 | - 'readonly' => true, |
|
141 | - ), |
|
142 | - |
|
143 | - 'completed_date_gmt' => array( |
|
144 | - 'description' => __( 'The GMT date the invoice was paid.', 'invoicing' ), |
|
145 | - 'type' => 'string', |
|
146 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
147 | - 'readonly' => true, |
|
148 | - ), |
|
149 | - |
|
150 | - 'total_discount' => array( |
|
151 | - 'description' => __( 'Total discount amount for the invoice.', 'invoicing' ), |
|
152 | - 'type' => 'number', |
|
153 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
154 | - 'readonly' => true, |
|
155 | - ), |
|
156 | - |
|
157 | - 'total_tax' => array( |
|
158 | - 'description' => __( 'Total tax amount for the invoice.', 'invoicing' ), |
|
159 | - 'type' => 'number', |
|
160 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
161 | - 'readonly' => true, |
|
162 | - ), |
|
163 | - |
|
164 | - 'total_fees' => array( |
|
165 | - 'description' => __( 'Total fees amount for the invoice.', 'invoicing' ), |
|
166 | - 'type' => 'number', |
|
167 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
168 | - 'readonly' => true, |
|
169 | - ), |
|
170 | - |
|
171 | - 'subtotal' => array( |
|
172 | - 'description' => __( 'Invoice subtotal.', 'invoicing' ), |
|
173 | - 'type' => 'number', |
|
174 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
175 | - 'readonly' => true, |
|
176 | - ), |
|
177 | - |
|
178 | - 'total' => array( |
|
179 | - 'description' => __( 'Grand total.', 'invoicing' ), |
|
180 | - 'type' => 'number', |
|
181 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
182 | - 'readonly' => true, |
|
183 | - ), |
|
184 | - |
|
185 | - 'initial_total' => array( |
|
186 | - 'description' => __( 'Initial total (for recurring invoices).', 'invoicing' ), |
|
187 | - 'type' => 'number', |
|
188 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
189 | - 'readonly' => true, |
|
190 | - ), |
|
191 | - |
|
192 | - 'recurring_total' => array( |
|
193 | - 'description' => __( 'Recurring total (for recurring invoices).', 'invoicing' ), |
|
194 | - 'type' => 'number', |
|
195 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
196 | - 'readonly' => true, |
|
197 | - ), |
|
198 | - |
|
199 | - 'totals' => array( |
|
200 | - 'description' => __( 'Invoice totals.', 'invoicing' ), |
|
201 | - 'type' => 'object', |
|
202 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
203 | - 'readonly' => true, |
|
204 | - ), |
|
205 | - |
|
206 | - 'fees' => array( |
|
207 | - 'description' => __( 'Invoice fees (Name => properties).', 'invoicing' ), |
|
208 | - 'type' => 'object', |
|
209 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
210 | - 'items' => array( |
|
211 | - 'type' => 'object', |
|
212 | - 'required' => array( 'amount' ), |
|
213 | - 'properties' => array( |
|
214 | - 'amount' => array( |
|
215 | - 'description' => __( 'Fee amount.', 'invoicing' ), |
|
216 | - 'type' => 'string', |
|
217 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
218 | - ), |
|
219 | - 'recurring' => array( |
|
220 | - 'description' => __( 'Whether this is a recurring or one-time fee.', 'invoicing' ), |
|
221 | - 'type' => array( 'boolean', 'integer' ), |
|
222 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
223 | - ), |
|
224 | - ), |
|
225 | - ), |
|
226 | - ), |
|
227 | - |
|
228 | - 'discounts' => array( |
|
229 | - 'description' => __( 'Invoice discounts (Name => properties).', 'invoicing' ), |
|
230 | - 'type' => 'object', |
|
231 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
232 | - 'items' => array( |
|
233 | - 'type' => 'object', |
|
234 | - 'required' => array( 'amount' ), |
|
235 | - 'properties' => array( |
|
236 | - 'amount' => array( |
|
237 | - 'description' => __( 'Fee amount.', 'invoicing' ), |
|
238 | - 'type' => 'string', |
|
239 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
240 | - ), |
|
241 | - 'recurring' => array( |
|
242 | - 'description' => __( 'Whether this is a recurring or one-time discount.', 'invoicing' ), |
|
243 | - 'type' => array( 'boolean', 'integer' ), |
|
244 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
245 | - ), |
|
246 | - ), |
|
247 | - ), |
|
248 | - ), |
|
249 | - |
|
250 | - 'taxes' => array( |
|
251 | - 'description' => __( 'Invoice taxes (Name => properties).', 'invoicing' ), |
|
252 | - 'type' => 'object', |
|
253 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
254 | - 'items' => array( |
|
255 | - 'type' => 'object', |
|
256 | - 'required' => array( 'amount' ), |
|
257 | - 'properties' => array( |
|
258 | - 'amount' => array( |
|
259 | - 'description' => __( 'Fee amount.', 'invoicing' ), |
|
260 | - 'type' => 'string', |
|
261 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
262 | - ), |
|
263 | - 'recurring' => array( |
|
264 | - 'description' => __( 'Whether this is a recurring or one-time tax.', 'invoicing' ), |
|
265 | - 'type' => array( 'boolean', 'integer' ), |
|
266 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
267 | - ), |
|
268 | - ), |
|
269 | - ), |
|
270 | - ), |
|
271 | - |
|
272 | - 'items' => array( |
|
273 | - 'description' => __( 'Invoice items.', 'invoicing' ), |
|
274 | - 'type' => 'array', |
|
275 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
276 | - 'items' => array( |
|
277 | - 'type' => 'object', |
|
278 | - 'required' => array( 'item_id' ), |
|
279 | - 'properties' => array( |
|
280 | - 'item_id' => array( |
|
281 | - 'description' => __( 'Item ID.', 'invoicing' ), |
|
282 | - 'type' => 'integer', |
|
283 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
284 | - ), |
|
285 | - 'item_name' => array( |
|
286 | - 'description' => __( 'Item Name.', 'invoicing' ), |
|
287 | - 'type' => 'string', |
|
288 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
289 | - ), |
|
290 | - 'item_description' => array( |
|
291 | - 'description' => __( 'Item Description.', 'invoicing' ), |
|
292 | - 'type' => 'string', |
|
293 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
294 | - ), |
|
295 | - 'item_price' => array( |
|
296 | - 'description' => __( 'Item Price.', 'invoicing' ), |
|
297 | - 'type' => 'number', |
|
298 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
299 | - ), |
|
300 | - 'quantity' => array( |
|
301 | - 'description' => __( 'Item Quantity.', 'invoicing' ), |
|
302 | - 'type' => 'number', |
|
303 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
304 | - ), |
|
305 | - 'subtotal' => array( |
|
306 | - 'description' => __( 'Item Subtotal.', 'invoicing' ), |
|
307 | - 'type' => 'number', |
|
308 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
309 | - 'readonly' => true, |
|
310 | - ), |
|
311 | - 'meta' => array( |
|
312 | - 'description' => __( 'Item Meta.', 'invoicing' ), |
|
313 | - 'type' => 'object', |
|
314 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
315 | - ), |
|
316 | - ), |
|
317 | - ), |
|
318 | - ), |
|
319 | - |
|
320 | - 'mode' => array( |
|
321 | - 'description' => __( 'The invoice transaction mode.', 'invoicing' ), |
|
322 | - 'type' => 'string', |
|
323 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
324 | - 'enum' => array( 'live', 'test' ), |
|
325 | - 'readonly' => true, |
|
326 | - ), |
|
16 | + 'id' => array( |
|
17 | + 'description' => __( 'Unique identifier for the invoice.', 'invoicing' ), |
|
18 | + 'type' => 'integer', |
|
19 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
20 | + 'readonly' => true, |
|
21 | + ), |
|
22 | + |
|
23 | + 'parent_id' => array( |
|
24 | + 'description' => __( 'Parent invoice ID.', 'invoicing' ), |
|
25 | + 'type' => 'integer', |
|
26 | + 'minimum' => 0, |
|
27 | + 'default' => 0, |
|
28 | + 'context' => array( 'view', 'edit' ), |
|
29 | + ), |
|
30 | + |
|
31 | + 'key' => array( |
|
32 | + 'description' => __( 'A unique key for the invoice.', 'invoicing' ), |
|
33 | + 'type' => 'string', |
|
34 | + 'context' => array( 'view', 'edit' ), |
|
35 | + 'readonly' => true, |
|
36 | + ), |
|
37 | + |
|
38 | + 'number' => array( |
|
39 | + 'description' => __( 'A unique number for the invoice.', 'invoicing' ), |
|
40 | + 'type' => 'string', |
|
41 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
42 | + ), |
|
43 | + |
|
44 | + 'type' => array( |
|
45 | + 'description' => __( 'Get the invoice type (e.g invoice, quote etc).', 'invoicing' ), |
|
46 | + 'type' => 'string', |
|
47 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
48 | + 'readonly' => true, |
|
49 | + ), |
|
50 | + |
|
51 | + 'post_type' => array( |
|
52 | + 'description' => __( 'Get the invoice post type (e.g wpi_invoice, wpi_quote etc).', 'invoicing' ), |
|
53 | + 'type' => 'string', |
|
54 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
55 | + 'readonly' => true, |
|
56 | + ), |
|
57 | + |
|
58 | + 'version' => array( |
|
59 | + 'description' => __( 'Version of GetPaid/Invoicing which last updated the invoice.', 'invoicing' ), |
|
60 | + 'type' => 'integer', |
|
61 | + 'context' => array( 'view', 'edit' ), |
|
62 | + 'readonly' => true, |
|
63 | + ), |
|
64 | + |
|
65 | + 'template' => array( |
|
66 | + 'description' => __( 'The invoice template.', 'invoicing' ), |
|
67 | + 'type' => 'string', |
|
68 | + 'default' => 'quantity', |
|
69 | + 'enum' => array( 'quantity', 'hours', 'amount' ), |
|
70 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
71 | + ), |
|
72 | + |
|
73 | + 'status' => array( |
|
74 | + 'description' => __( 'Invoice status.', 'invoicing' ), |
|
75 | + 'type' => 'string', |
|
76 | + 'default' => 'wpi-pending', |
|
77 | + 'enum' => array_keys( wpinv_get_invoice_statuses( true ) ), |
|
78 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
79 | + ), |
|
80 | + |
|
81 | + 'status_nicename' => array( |
|
82 | + 'description' => __( 'A human readable name for the invoice status.', 'invoicing' ), |
|
83 | + 'type' => 'string', |
|
84 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
85 | + 'readonly' => true, |
|
86 | + ), |
|
87 | + |
|
88 | + 'currency' => array( |
|
89 | + 'description' => __( 'The invoice currency in ISO format.', 'invoicing' ), |
|
90 | + 'type' => 'string', |
|
91 | + 'default' => wpinv_get_currency(), |
|
92 | + 'enum' => array_keys( wpinv_get_currencies() ), |
|
93 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
94 | + ), |
|
95 | + |
|
96 | + 'date_created' => array( |
|
97 | + 'description' => __( "The date the invoice was created, in the site's timezone.", 'invoicing' ), |
|
98 | + 'type' => 'string', |
|
99 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
100 | + ), |
|
101 | + |
|
102 | + 'date_created_gmt' => array( |
|
103 | + 'description' => __( 'The GMT date the invoice was created.', 'invoicing' ), |
|
104 | + 'type' => 'string', |
|
105 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
106 | + 'readonly' => true, |
|
107 | + ), |
|
108 | + |
|
109 | + 'date_modified' => array( |
|
110 | + 'description' => __( "The date the invoice was last modified, in the site's timezone.", 'invoicing' ), |
|
111 | + 'type' => 'string', |
|
112 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
113 | + 'readonly' => true, |
|
114 | + ), |
|
115 | + |
|
116 | + 'date_modified_gmt' => array( |
|
117 | + 'description' => __( 'The GMT date the invoice was last modified.', 'invoicing' ), |
|
118 | + 'type' => 'string', |
|
119 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
120 | + 'readonly' => true, |
|
121 | + ), |
|
122 | + |
|
123 | + 'due_date' => array( |
|
124 | + 'description' => __( "The invoice's due date, in the site's timezone.", 'invoicing' ), |
|
125 | + 'type' => 'string', |
|
126 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
127 | + ), |
|
128 | + |
|
129 | + 'due_date_gmt' => array( |
|
130 | + 'description' => __( 'The GMT date the invoice is/was due.', 'invoicing' ), |
|
131 | + 'type' => 'string', |
|
132 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
133 | + 'readonly' => true, |
|
134 | + ), |
|
135 | + |
|
136 | + 'completed_date' => array( |
|
137 | + 'description' => __( "The date the invoice was paid, in the site's timezone.", 'invoicing' ), |
|
138 | + 'type' => 'string', |
|
139 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
140 | + 'readonly' => true, |
|
141 | + ), |
|
142 | + |
|
143 | + 'completed_date_gmt' => array( |
|
144 | + 'description' => __( 'The GMT date the invoice was paid.', 'invoicing' ), |
|
145 | + 'type' => 'string', |
|
146 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
147 | + 'readonly' => true, |
|
148 | + ), |
|
149 | + |
|
150 | + 'total_discount' => array( |
|
151 | + 'description' => __( 'Total discount amount for the invoice.', 'invoicing' ), |
|
152 | + 'type' => 'number', |
|
153 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
154 | + 'readonly' => true, |
|
155 | + ), |
|
156 | + |
|
157 | + 'total_tax' => array( |
|
158 | + 'description' => __( 'Total tax amount for the invoice.', 'invoicing' ), |
|
159 | + 'type' => 'number', |
|
160 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
161 | + 'readonly' => true, |
|
162 | + ), |
|
163 | + |
|
164 | + 'total_fees' => array( |
|
165 | + 'description' => __( 'Total fees amount for the invoice.', 'invoicing' ), |
|
166 | + 'type' => 'number', |
|
167 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
168 | + 'readonly' => true, |
|
169 | + ), |
|
170 | + |
|
171 | + 'subtotal' => array( |
|
172 | + 'description' => __( 'Invoice subtotal.', 'invoicing' ), |
|
173 | + 'type' => 'number', |
|
174 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
175 | + 'readonly' => true, |
|
176 | + ), |
|
177 | + |
|
178 | + 'total' => array( |
|
179 | + 'description' => __( 'Grand total.', 'invoicing' ), |
|
180 | + 'type' => 'number', |
|
181 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
182 | + 'readonly' => true, |
|
183 | + ), |
|
184 | + |
|
185 | + 'initial_total' => array( |
|
186 | + 'description' => __( 'Initial total (for recurring invoices).', 'invoicing' ), |
|
187 | + 'type' => 'number', |
|
188 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
189 | + 'readonly' => true, |
|
190 | + ), |
|
191 | + |
|
192 | + 'recurring_total' => array( |
|
193 | + 'description' => __( 'Recurring total (for recurring invoices).', 'invoicing' ), |
|
194 | + 'type' => 'number', |
|
195 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
196 | + 'readonly' => true, |
|
197 | + ), |
|
198 | + |
|
199 | + 'totals' => array( |
|
200 | + 'description' => __( 'Invoice totals.', 'invoicing' ), |
|
201 | + 'type' => 'object', |
|
202 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
203 | + 'readonly' => true, |
|
204 | + ), |
|
205 | + |
|
206 | + 'fees' => array( |
|
207 | + 'description' => __( 'Invoice fees (Name => properties).', 'invoicing' ), |
|
208 | + 'type' => 'object', |
|
209 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
210 | + 'items' => array( |
|
211 | + 'type' => 'object', |
|
212 | + 'required' => array( 'amount' ), |
|
213 | + 'properties' => array( |
|
214 | + 'amount' => array( |
|
215 | + 'description' => __( 'Fee amount.', 'invoicing' ), |
|
216 | + 'type' => 'string', |
|
217 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
218 | + ), |
|
219 | + 'recurring' => array( |
|
220 | + 'description' => __( 'Whether this is a recurring or one-time fee.', 'invoicing' ), |
|
221 | + 'type' => array( 'boolean', 'integer' ), |
|
222 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
223 | + ), |
|
224 | + ), |
|
225 | + ), |
|
226 | + ), |
|
227 | + |
|
228 | + 'discounts' => array( |
|
229 | + 'description' => __( 'Invoice discounts (Name => properties).', 'invoicing' ), |
|
230 | + 'type' => 'object', |
|
231 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
232 | + 'items' => array( |
|
233 | + 'type' => 'object', |
|
234 | + 'required' => array( 'amount' ), |
|
235 | + 'properties' => array( |
|
236 | + 'amount' => array( |
|
237 | + 'description' => __( 'Fee amount.', 'invoicing' ), |
|
238 | + 'type' => 'string', |
|
239 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
240 | + ), |
|
241 | + 'recurring' => array( |
|
242 | + 'description' => __( 'Whether this is a recurring or one-time discount.', 'invoicing' ), |
|
243 | + 'type' => array( 'boolean', 'integer' ), |
|
244 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
245 | + ), |
|
246 | + ), |
|
247 | + ), |
|
248 | + ), |
|
249 | + |
|
250 | + 'taxes' => array( |
|
251 | + 'description' => __( 'Invoice taxes (Name => properties).', 'invoicing' ), |
|
252 | + 'type' => 'object', |
|
253 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
254 | + 'items' => array( |
|
255 | + 'type' => 'object', |
|
256 | + 'required' => array( 'amount' ), |
|
257 | + 'properties' => array( |
|
258 | + 'amount' => array( |
|
259 | + 'description' => __( 'Fee amount.', 'invoicing' ), |
|
260 | + 'type' => 'string', |
|
261 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
262 | + ), |
|
263 | + 'recurring' => array( |
|
264 | + 'description' => __( 'Whether this is a recurring or one-time tax.', 'invoicing' ), |
|
265 | + 'type' => array( 'boolean', 'integer' ), |
|
266 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
267 | + ), |
|
268 | + ), |
|
269 | + ), |
|
270 | + ), |
|
271 | + |
|
272 | + 'items' => array( |
|
273 | + 'description' => __( 'Invoice items.', 'invoicing' ), |
|
274 | + 'type' => 'array', |
|
275 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
276 | + 'items' => array( |
|
277 | + 'type' => 'object', |
|
278 | + 'required' => array( 'item_id' ), |
|
279 | + 'properties' => array( |
|
280 | + 'item_id' => array( |
|
281 | + 'description' => __( 'Item ID.', 'invoicing' ), |
|
282 | + 'type' => 'integer', |
|
283 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
284 | + ), |
|
285 | + 'item_name' => array( |
|
286 | + 'description' => __( 'Item Name.', 'invoicing' ), |
|
287 | + 'type' => 'string', |
|
288 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
289 | + ), |
|
290 | + 'item_description' => array( |
|
291 | + 'description' => __( 'Item Description.', 'invoicing' ), |
|
292 | + 'type' => 'string', |
|
293 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
294 | + ), |
|
295 | + 'item_price' => array( |
|
296 | + 'description' => __( 'Item Price.', 'invoicing' ), |
|
297 | + 'type' => 'number', |
|
298 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
299 | + ), |
|
300 | + 'quantity' => array( |
|
301 | + 'description' => __( 'Item Quantity.', 'invoicing' ), |
|
302 | + 'type' => 'number', |
|
303 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
304 | + ), |
|
305 | + 'subtotal' => array( |
|
306 | + 'description' => __( 'Item Subtotal.', 'invoicing' ), |
|
307 | + 'type' => 'number', |
|
308 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
309 | + 'readonly' => true, |
|
310 | + ), |
|
311 | + 'meta' => array( |
|
312 | + 'description' => __( 'Item Meta.', 'invoicing' ), |
|
313 | + 'type' => 'object', |
|
314 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
315 | + ), |
|
316 | + ), |
|
317 | + ), |
|
318 | + ), |
|
319 | + |
|
320 | + 'mode' => array( |
|
321 | + 'description' => __( 'The invoice transaction mode.', 'invoicing' ), |
|
322 | + 'type' => 'string', |
|
323 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
324 | + 'enum' => array( 'live', 'test' ), |
|
325 | + 'readonly' => true, |
|
326 | + ), |
|
327 | 327 | |
328 | - 'discount_code' => array( |
|
329 | - 'description' => __( 'The discount code used on this invoice.', 'invoicing' ), |
|
330 | - 'type' => 'string', |
|
331 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
332 | - ), |
|
333 | - |
|
334 | - 'gateway' => array( |
|
335 | - 'description' => __( 'The gateway used to pay this invoice.', 'invoicing' ), |
|
336 | - 'type' => 'string', |
|
337 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
338 | - ), |
|
339 | - |
|
340 | - 'gateway_title' => array( |
|
341 | - 'description' => __( 'The title of the gateway used to pay this invoice.', 'invoicing' ), |
|
342 | - 'type' => 'string', |
|
343 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
344 | - 'readonly' => true, |
|
345 | - ), |
|
346 | - |
|
347 | - 'transaction_id' => array( |
|
348 | - 'description' => __( 'The transaction id for this invoice.', 'invoicing' ), |
|
349 | - 'type' => 'string', |
|
350 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
351 | - ), |
|
328 | + 'discount_code' => array( |
|
329 | + 'description' => __( 'The discount code used on this invoice.', 'invoicing' ), |
|
330 | + 'type' => 'string', |
|
331 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
332 | + ), |
|
333 | + |
|
334 | + 'gateway' => array( |
|
335 | + 'description' => __( 'The gateway used to pay this invoice.', 'invoicing' ), |
|
336 | + 'type' => 'string', |
|
337 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
338 | + ), |
|
339 | + |
|
340 | + 'gateway_title' => array( |
|
341 | + 'description' => __( 'The title of the gateway used to pay this invoice.', 'invoicing' ), |
|
342 | + 'type' => 'string', |
|
343 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
344 | + 'readonly' => true, |
|
345 | + ), |
|
346 | + |
|
347 | + 'transaction_id' => array( |
|
348 | + 'description' => __( 'The transaction id for this invoice.', 'invoicing' ), |
|
349 | + 'type' => 'string', |
|
350 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
351 | + ), |
|
352 | 352 | |
353 | - 'disable_taxes' => array( |
|
354 | - 'description' => __( 'Whether or not taxes should be disabled for this invoice.', 'invoicing' ), |
|
355 | - 'type' => 'boolean ', |
|
356 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
357 | - ), |
|
358 | - |
|
359 | - 'is_viewed' => array( |
|
360 | - 'description' => __( 'Whether or not this invoice has been viewed by the user.', 'invoicing' ), |
|
361 | - 'type' => 'boolean ', |
|
362 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
363 | - 'readonly' => true, |
|
364 | - ), |
|
365 | - |
|
366 | - 'email_cc' => array( |
|
367 | - 'description' => __( 'A comma separated list of other emails that should receive communications for this invoice.', 'invoicing' ), |
|
368 | - 'type' => 'string ', |
|
369 | - 'context' => array( 'view', 'edit' ), |
|
370 | - ), |
|
371 | - |
|
372 | - 'subscription_id' => array( |
|
373 | - 'description' => __( 'The ID of the subscription associated with this invoice.', 'invoicing' ), |
|
374 | - 'type' => 'string ', |
|
375 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
376 | - 'readonly' => true, |
|
377 | - ), |
|
378 | - |
|
379 | - 'subscription_name' => array( |
|
380 | - 'description' => __( 'The name of the subscription associated with this invoice.', 'invoicing' ), |
|
381 | - 'type' => 'string ', |
|
382 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
383 | - 'readonly' => true, |
|
384 | - ), |
|
385 | - |
|
386 | - 'subscription_name' => array( |
|
387 | - 'description' => __( 'The name of the subscription associated with this invoice.', 'invoicing' ), |
|
388 | - 'type' => 'string ', |
|
389 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
390 | - 'readonly' => true, |
|
391 | - ), |
|
392 | - |
|
393 | - 'is_parent' => array( |
|
394 | - 'description' => __( 'Whether or not this is a parent invoice.', 'invoicing' ), |
|
395 | - 'type' => 'boolean', |
|
396 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
397 | - 'readonly' => true, |
|
398 | - ), |
|
399 | - |
|
400 | - 'is_renewal' => array( |
|
401 | - 'description' => __( 'Whether or not this is a renewal invoice.', 'invoicing' ), |
|
402 | - 'type' => 'boolean', |
|
403 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
404 | - 'readonly' => true, |
|
405 | - ), |
|
406 | - |
|
407 | - 'is_recurring' => array( |
|
408 | - 'description' => __( 'Whether or not this is a recurring invoice.', 'invoicing' ), |
|
409 | - 'type' => 'boolean', |
|
410 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
411 | - 'readonly' => true, |
|
412 | - ), |
|
413 | - |
|
414 | - 'is_free' => array( |
|
415 | - 'description' => __( 'Whether or not this invoice is free.', 'invoicing' ), |
|
416 | - 'type' => 'boolean', |
|
417 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
418 | - 'readonly' => true, |
|
419 | - ), |
|
420 | - |
|
421 | - 'is_paid' => array( |
|
422 | - 'description' => __( 'Whether or not this invoice has been paid.', 'invoicing' ), |
|
423 | - 'type' => 'boolean', |
|
424 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
425 | - 'readonly' => true, |
|
426 | - ), |
|
427 | - |
|
428 | - 'needs_payment' => array( |
|
429 | - 'description' => __( 'Whether or not this invoice needs payment.', 'invoicing' ), |
|
430 | - 'type' => 'boolean', |
|
431 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
432 | - 'readonly' => true, |
|
433 | - ), |
|
434 | - |
|
435 | - 'is_refunded' => array( |
|
436 | - 'description' => __( 'Whether or not this invoice was refunded.', 'invoicing' ), |
|
437 | - 'type' => 'boolean', |
|
438 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
439 | - 'readonly' => true, |
|
440 | - ), |
|
441 | - |
|
442 | - 'is_due' => array( |
|
443 | - 'description' => __( 'Whether or not this invoice is due.', 'invoicing' ), |
|
444 | - 'type' => 'boolean', |
|
445 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
446 | - 'readonly' => true, |
|
447 | - ), |
|
448 | - |
|
449 | - 'is_held' => array( |
|
450 | - 'description' => __( 'Whether or not this invoice has been held for payment confirmation.', 'invoicing' ), |
|
451 | - 'type' => 'boolean', |
|
452 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
453 | - 'readonly' => true, |
|
454 | - ), |
|
455 | - |
|
456 | - 'is_draft' => array( |
|
457 | - 'description' => __( 'Whether or not this invoice is marked as draft (cannot be viewed on the frontend).', 'invoicing' ), |
|
458 | - 'type' => 'boolean', |
|
459 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
460 | - 'readonly' => true, |
|
461 | - ), |
|
462 | - |
|
463 | - 'path' => array( |
|
464 | - 'description' => __( 'The invoice path/slug/name.', 'invoicing' ), |
|
465 | - 'type' => 'string', |
|
466 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
467 | - 'readonly' => true, |
|
468 | - ), |
|
469 | - |
|
470 | - 'description' => array( |
|
471 | - 'description' => __( 'The invoice description.', 'invoicing' ), |
|
472 | - 'type' => 'string', |
|
473 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
474 | - ), |
|
475 | - |
|
476 | - 'payment_form' => array( |
|
477 | - 'description' => __( 'The id of the payment form used to pay for this invoice.', 'invoicing' ), |
|
478 | - 'type' => 'integer', |
|
479 | - 'context' => array( 'view', 'edit' ), |
|
480 | - 'readonly' => true, |
|
481 | - ), |
|
482 | - |
|
483 | - 'submission_id' => array( |
|
484 | - 'description' => __( 'A uniques ID of the submission details used to pay for this invoice.', 'invoicing' ), |
|
485 | - 'type' => 'string', |
|
486 | - 'context' => array( 'view', 'edit' ), |
|
487 | - 'readonly' => true, |
|
488 | - ), |
|
489 | - |
|
490 | - 'customer_id' => array( |
|
491 | - 'description' => __( 'The customer id.', 'invoicing' ), |
|
492 | - 'type' => 'integer', |
|
493 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
494 | - ), |
|
495 | - |
|
496 | - 'customer_ip' => array( |
|
497 | - 'description' => __( "The customer's ip address.", 'invoicing' ), |
|
498 | - 'type' => 'string', |
|
499 | - 'format' => 'ip', |
|
500 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
501 | - ), |
|
502 | - |
|
503 | - 'first_name' => array( |
|
504 | - 'description' => __( "The customer's first name.", 'invoicing' ), |
|
505 | - 'type' => 'string', |
|
506 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
507 | - ), |
|
508 | - |
|
509 | - 'last_name' => array( |
|
510 | - 'description' => __( "The customer's last name.", 'invoicing' ), |
|
511 | - 'type' => 'string', |
|
512 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
513 | - ), |
|
353 | + 'disable_taxes' => array( |
|
354 | + 'description' => __( 'Whether or not taxes should be disabled for this invoice.', 'invoicing' ), |
|
355 | + 'type' => 'boolean ', |
|
356 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
357 | + ), |
|
358 | + |
|
359 | + 'is_viewed' => array( |
|
360 | + 'description' => __( 'Whether or not this invoice has been viewed by the user.', 'invoicing' ), |
|
361 | + 'type' => 'boolean ', |
|
362 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
363 | + 'readonly' => true, |
|
364 | + ), |
|
365 | + |
|
366 | + 'email_cc' => array( |
|
367 | + 'description' => __( 'A comma separated list of other emails that should receive communications for this invoice.', 'invoicing' ), |
|
368 | + 'type' => 'string ', |
|
369 | + 'context' => array( 'view', 'edit' ), |
|
370 | + ), |
|
371 | + |
|
372 | + 'subscription_id' => array( |
|
373 | + 'description' => __( 'The ID of the subscription associated with this invoice.', 'invoicing' ), |
|
374 | + 'type' => 'string ', |
|
375 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
376 | + 'readonly' => true, |
|
377 | + ), |
|
378 | + |
|
379 | + 'subscription_name' => array( |
|
380 | + 'description' => __( 'The name of the subscription associated with this invoice.', 'invoicing' ), |
|
381 | + 'type' => 'string ', |
|
382 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
383 | + 'readonly' => true, |
|
384 | + ), |
|
385 | + |
|
386 | + 'subscription_name' => array( |
|
387 | + 'description' => __( 'The name of the subscription associated with this invoice.', 'invoicing' ), |
|
388 | + 'type' => 'string ', |
|
389 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
390 | + 'readonly' => true, |
|
391 | + ), |
|
392 | + |
|
393 | + 'is_parent' => array( |
|
394 | + 'description' => __( 'Whether or not this is a parent invoice.', 'invoicing' ), |
|
395 | + 'type' => 'boolean', |
|
396 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
397 | + 'readonly' => true, |
|
398 | + ), |
|
399 | + |
|
400 | + 'is_renewal' => array( |
|
401 | + 'description' => __( 'Whether or not this is a renewal invoice.', 'invoicing' ), |
|
402 | + 'type' => 'boolean', |
|
403 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
404 | + 'readonly' => true, |
|
405 | + ), |
|
406 | + |
|
407 | + 'is_recurring' => array( |
|
408 | + 'description' => __( 'Whether or not this is a recurring invoice.', 'invoicing' ), |
|
409 | + 'type' => 'boolean', |
|
410 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
411 | + 'readonly' => true, |
|
412 | + ), |
|
413 | + |
|
414 | + 'is_free' => array( |
|
415 | + 'description' => __( 'Whether or not this invoice is free.', 'invoicing' ), |
|
416 | + 'type' => 'boolean', |
|
417 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
418 | + 'readonly' => true, |
|
419 | + ), |
|
420 | + |
|
421 | + 'is_paid' => array( |
|
422 | + 'description' => __( 'Whether or not this invoice has been paid.', 'invoicing' ), |
|
423 | + 'type' => 'boolean', |
|
424 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
425 | + 'readonly' => true, |
|
426 | + ), |
|
427 | + |
|
428 | + 'needs_payment' => array( |
|
429 | + 'description' => __( 'Whether or not this invoice needs payment.', 'invoicing' ), |
|
430 | + 'type' => 'boolean', |
|
431 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
432 | + 'readonly' => true, |
|
433 | + ), |
|
434 | + |
|
435 | + 'is_refunded' => array( |
|
436 | + 'description' => __( 'Whether or not this invoice was refunded.', 'invoicing' ), |
|
437 | + 'type' => 'boolean', |
|
438 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
439 | + 'readonly' => true, |
|
440 | + ), |
|
441 | + |
|
442 | + 'is_due' => array( |
|
443 | + 'description' => __( 'Whether or not this invoice is due.', 'invoicing' ), |
|
444 | + 'type' => 'boolean', |
|
445 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
446 | + 'readonly' => true, |
|
447 | + ), |
|
448 | + |
|
449 | + 'is_held' => array( |
|
450 | + 'description' => __( 'Whether or not this invoice has been held for payment confirmation.', 'invoicing' ), |
|
451 | + 'type' => 'boolean', |
|
452 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
453 | + 'readonly' => true, |
|
454 | + ), |
|
455 | + |
|
456 | + 'is_draft' => array( |
|
457 | + 'description' => __( 'Whether or not this invoice is marked as draft (cannot be viewed on the frontend).', 'invoicing' ), |
|
458 | + 'type' => 'boolean', |
|
459 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
460 | + 'readonly' => true, |
|
461 | + ), |
|
462 | + |
|
463 | + 'path' => array( |
|
464 | + 'description' => __( 'The invoice path/slug/name.', 'invoicing' ), |
|
465 | + 'type' => 'string', |
|
466 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
467 | + 'readonly' => true, |
|
468 | + ), |
|
469 | + |
|
470 | + 'description' => array( |
|
471 | + 'description' => __( 'The invoice description.', 'invoicing' ), |
|
472 | + 'type' => 'string', |
|
473 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
474 | + ), |
|
475 | + |
|
476 | + 'payment_form' => array( |
|
477 | + 'description' => __( 'The id of the payment form used to pay for this invoice.', 'invoicing' ), |
|
478 | + 'type' => 'integer', |
|
479 | + 'context' => array( 'view', 'edit' ), |
|
480 | + 'readonly' => true, |
|
481 | + ), |
|
482 | + |
|
483 | + 'submission_id' => array( |
|
484 | + 'description' => __( 'A uniques ID of the submission details used to pay for this invoice.', 'invoicing' ), |
|
485 | + 'type' => 'string', |
|
486 | + 'context' => array( 'view', 'edit' ), |
|
487 | + 'readonly' => true, |
|
488 | + ), |
|
489 | + |
|
490 | + 'customer_id' => array( |
|
491 | + 'description' => __( 'The customer id.', 'invoicing' ), |
|
492 | + 'type' => 'integer', |
|
493 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
494 | + ), |
|
495 | + |
|
496 | + 'customer_ip' => array( |
|
497 | + 'description' => __( "The customer's ip address.", 'invoicing' ), |
|
498 | + 'type' => 'string', |
|
499 | + 'format' => 'ip', |
|
500 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
501 | + ), |
|
502 | + |
|
503 | + 'first_name' => array( |
|
504 | + 'description' => __( "The customer's first name.", 'invoicing' ), |
|
505 | + 'type' => 'string', |
|
506 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
507 | + ), |
|
508 | + |
|
509 | + 'last_name' => array( |
|
510 | + 'description' => __( "The customer's last name.", 'invoicing' ), |
|
511 | + 'type' => 'string', |
|
512 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
513 | + ), |
|
514 | 514 | |
515 | - 'full_name' => array( |
|
516 | - 'description' => __( "The customer's full name.", 'invoicing' ), |
|
517 | - 'type' => 'string', |
|
518 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
519 | - 'readonly' => true, |
|
520 | - ), |
|
521 | - |
|
522 | - 'phone_number' => array( |
|
523 | - 'description' => __( "The customer's phone number.", 'invoicing' ), |
|
524 | - 'type' => 'string', |
|
525 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
526 | - ), |
|
527 | - |
|
528 | - 'email_address' => array( |
|
529 | - 'description' => __( "The customer's email address.", 'invoicing' ), |
|
530 | - 'type' => 'string', |
|
531 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
532 | - 'readonly' => true, |
|
533 | - ), |
|
534 | - |
|
535 | - 'customer_country' => array( |
|
536 | - 'description' => __( "The customer's country.", 'invoicing' ), |
|
537 | - 'type' => 'string', |
|
538 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
539 | - 'default' => wpinv_get_default_country(), |
|
540 | - ), |
|
541 | - |
|
542 | - 'customer_state' => array( |
|
543 | - 'description' => __( "The customer's state.", 'invoicing' ), |
|
544 | - 'type' => 'string', |
|
545 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
546 | - ), |
|
547 | - |
|
548 | - 'customer_city' => array( |
|
549 | - 'description' => __( "The customer's city.", 'invoicing' ), |
|
550 | - 'type' => 'string', |
|
551 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
552 | - ), |
|
553 | - |
|
554 | - 'customer_zip' => array( |
|
555 | - 'description' => __( "The customer's zip/postal code.", 'invoicing' ), |
|
556 | - 'type' => 'string', |
|
557 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
558 | - ), |
|
559 | - |
|
560 | - 'customer_company' => array( |
|
561 | - 'description' => __( "The customer's company name.", 'invoicing' ), |
|
562 | - 'type' => 'string', |
|
563 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
564 | - ), |
|
565 | - |
|
566 | - 'vat_number' => array( |
|
567 | - 'description' => __( "The customer's VAT number.", 'invoicing' ), |
|
568 | - 'type' => 'string', |
|
569 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
570 | - ), |
|
571 | - |
|
572 | - 'vat_rate' => array( |
|
573 | - 'description' => __( "The customer's VAT rate.", 'invoicing' ), |
|
574 | - 'type' => 'number', |
|
575 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
576 | - 'readonly' => true, |
|
577 | - ), |
|
578 | - |
|
579 | - 'customer_address' => array( |
|
580 | - 'description' => __( "The customer's address.", 'invoicing' ), |
|
581 | - 'type' => 'string', |
|
582 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
583 | - ), |
|
584 | - |
|
585 | - 'address_confirmed' => array( |
|
586 | - 'description' => __( "Whether or not the customer's address is confirmed.", 'invoicing' ), |
|
587 | - 'type' => 'boolean', |
|
588 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
589 | - ), |
|
590 | - |
|
591 | - 'meta_data' => array( |
|
592 | - 'description' => __( 'Invoice meta data.', 'invoicing' ), |
|
593 | - 'type' => 'array', |
|
594 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
595 | - 'items' => array( |
|
596 | - 'type' => 'object', |
|
597 | - 'properties' => array( |
|
598 | - 'id' => array( |
|
599 | - 'description' => __( 'Meta ID.', 'invoicing' ), |
|
600 | - 'type' => 'string', |
|
601 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
602 | - ), |
|
603 | - 'key' => array( |
|
604 | - 'description' => __( 'Meta key.', 'invoicing' ), |
|
605 | - 'type' => 'string', |
|
606 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
607 | - ), |
|
608 | - 'value' => array( |
|
609 | - 'description' => __( 'Meta Value.', 'invoicing' ), |
|
610 | - 'type' => array( 'string', 'array', 'object', 'integer', 'null' ), |
|
611 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
612 | - ), |
|
613 | - ), |
|
614 | - ), |
|
615 | - ), |
|
616 | - |
|
617 | - 'view_url' => array( |
|
618 | - 'description' => __( 'URL to the invoice.', 'invoicing' ), |
|
619 | - 'type' => 'string', |
|
620 | - 'format' => 'uri', |
|
621 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
622 | - 'readonly' => true, |
|
623 | - ), |
|
624 | - |
|
625 | - 'checkout_payment_url' => array( |
|
626 | - 'description' => __( 'URL to the invoice checkout page.', 'invoicing' ), |
|
627 | - 'type' => 'string', |
|
628 | - 'format' => 'uri', |
|
629 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
630 | - 'readonly' => true, |
|
631 | - ), |
|
632 | - |
|
633 | - 'receipt_url' => array( |
|
634 | - 'description' => __( 'URL to the invoice receipt page.', 'invoicing' ), |
|
635 | - 'type' => 'string', |
|
636 | - 'format' => 'uri', |
|
637 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
638 | - 'readonly' => true, |
|
639 | - ), |
|
515 | + 'full_name' => array( |
|
516 | + 'description' => __( "The customer's full name.", 'invoicing' ), |
|
517 | + 'type' => 'string', |
|
518 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
519 | + 'readonly' => true, |
|
520 | + ), |
|
521 | + |
|
522 | + 'phone_number' => array( |
|
523 | + 'description' => __( "The customer's phone number.", 'invoicing' ), |
|
524 | + 'type' => 'string', |
|
525 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
526 | + ), |
|
527 | + |
|
528 | + 'email_address' => array( |
|
529 | + 'description' => __( "The customer's email address.", 'invoicing' ), |
|
530 | + 'type' => 'string', |
|
531 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
532 | + 'readonly' => true, |
|
533 | + ), |
|
534 | + |
|
535 | + 'customer_country' => array( |
|
536 | + 'description' => __( "The customer's country.", 'invoicing' ), |
|
537 | + 'type' => 'string', |
|
538 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
539 | + 'default' => wpinv_get_default_country(), |
|
540 | + ), |
|
541 | + |
|
542 | + 'customer_state' => array( |
|
543 | + 'description' => __( "The customer's state.", 'invoicing' ), |
|
544 | + 'type' => 'string', |
|
545 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
546 | + ), |
|
547 | + |
|
548 | + 'customer_city' => array( |
|
549 | + 'description' => __( "The customer's city.", 'invoicing' ), |
|
550 | + 'type' => 'string', |
|
551 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
552 | + ), |
|
553 | + |
|
554 | + 'customer_zip' => array( |
|
555 | + 'description' => __( "The customer's zip/postal code.", 'invoicing' ), |
|
556 | + 'type' => 'string', |
|
557 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
558 | + ), |
|
559 | + |
|
560 | + 'customer_company' => array( |
|
561 | + 'description' => __( "The customer's company name.", 'invoicing' ), |
|
562 | + 'type' => 'string', |
|
563 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
564 | + ), |
|
565 | + |
|
566 | + 'vat_number' => array( |
|
567 | + 'description' => __( "The customer's VAT number.", 'invoicing' ), |
|
568 | + 'type' => 'string', |
|
569 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
570 | + ), |
|
571 | + |
|
572 | + 'vat_rate' => array( |
|
573 | + 'description' => __( "The customer's VAT rate.", 'invoicing' ), |
|
574 | + 'type' => 'number', |
|
575 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
576 | + 'readonly' => true, |
|
577 | + ), |
|
578 | + |
|
579 | + 'customer_address' => array( |
|
580 | + 'description' => __( "The customer's address.", 'invoicing' ), |
|
581 | + 'type' => 'string', |
|
582 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
583 | + ), |
|
584 | + |
|
585 | + 'address_confirmed' => array( |
|
586 | + 'description' => __( "Whether or not the customer's address is confirmed.", 'invoicing' ), |
|
587 | + 'type' => 'boolean', |
|
588 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
589 | + ), |
|
590 | + |
|
591 | + 'meta_data' => array( |
|
592 | + 'description' => __( 'Invoice meta data.', 'invoicing' ), |
|
593 | + 'type' => 'array', |
|
594 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
595 | + 'items' => array( |
|
596 | + 'type' => 'object', |
|
597 | + 'properties' => array( |
|
598 | + 'id' => array( |
|
599 | + 'description' => __( 'Meta ID.', 'invoicing' ), |
|
600 | + 'type' => 'string', |
|
601 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
602 | + ), |
|
603 | + 'key' => array( |
|
604 | + 'description' => __( 'Meta key.', 'invoicing' ), |
|
605 | + 'type' => 'string', |
|
606 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
607 | + ), |
|
608 | + 'value' => array( |
|
609 | + 'description' => __( 'Meta Value.', 'invoicing' ), |
|
610 | + 'type' => array( 'string', 'array', 'object', 'integer', 'null' ), |
|
611 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
612 | + ), |
|
613 | + ), |
|
614 | + ), |
|
615 | + ), |
|
616 | + |
|
617 | + 'view_url' => array( |
|
618 | + 'description' => __( 'URL to the invoice.', 'invoicing' ), |
|
619 | + 'type' => 'string', |
|
620 | + 'format' => 'uri', |
|
621 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
622 | + 'readonly' => true, |
|
623 | + ), |
|
624 | + |
|
625 | + 'checkout_payment_url' => array( |
|
626 | + 'description' => __( 'URL to the invoice checkout page.', 'invoicing' ), |
|
627 | + 'type' => 'string', |
|
628 | + 'format' => 'uri', |
|
629 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
630 | + 'readonly' => true, |
|
631 | + ), |
|
632 | + |
|
633 | + 'receipt_url' => array( |
|
634 | + 'description' => __( 'URL to the invoice receipt page.', 'invoicing' ), |
|
635 | + 'type' => 'string', |
|
636 | + 'format' => 'uri', |
|
637 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
638 | + 'readonly' => true, |
|
639 | + ), |
|
640 | 640 | |
641 | 641 | ); |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,30 +10,30 @@ discard block |
||
10 | 10 | class WPInv_Item extends GetPaid_Data { |
11 | 11 | |
12 | 12 | /** |
13 | - * Which data store to load. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
13 | + * Which data store to load. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | 17 | protected $data_store_name = 'item'; |
18 | 18 | |
19 | 19 | /** |
20 | - * This is the name of this object type. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $object_type = 'item'; |
|
20 | + * This is the name of this object type. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $object_type = 'item'; |
|
25 | 25 | |
26 | 26 | /** |
27 | - * Item Data array. This is the core item data exposed in APIs. |
|
28 | - * |
|
29 | - * @since 1.0.19 |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $data = array( |
|
33 | - 'parent_id' => 0, |
|
34 | - 'status' => 'draft', |
|
35 | - 'version' => '', |
|
36 | - 'date_created' => null, |
|
27 | + * Item Data array. This is the core item data exposed in APIs. |
|
28 | + * |
|
29 | + * @since 1.0.19 |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $data = array( |
|
33 | + 'parent_id' => 0, |
|
34 | + 'status' => 'draft', |
|
35 | + 'version' => '', |
|
36 | + 'date_created' => null, |
|
37 | 37 | 'date_modified' => null, |
38 | 38 | 'name' => '', |
39 | 39 | 'description' => '', |
@@ -58,13 +58,13 @@ discard block |
||
58 | 58 | ); |
59 | 59 | |
60 | 60 | /** |
61 | - * Stores meta in cache for future reads. |
|
62 | - * |
|
63 | - * A group must be set to to enable caching. |
|
64 | - * |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - protected $cache_group = 'getpaid_items'; |
|
61 | + * Stores meta in cache for future reads. |
|
62 | + * |
|
63 | + * A group must be set to to enable caching. |
|
64 | + * |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + protected $cache_group = 'getpaid_items'; |
|
68 | 68 | |
69 | 69 | /** |
70 | 70 | * Stores a reference to the original WP_Post object |
@@ -74,37 +74,37 @@ discard block |
||
74 | 74 | protected $post = null; |
75 | 75 | |
76 | 76 | /** |
77 | - * Get the item if ID is passed, otherwise the item is new and empty. |
|
78 | - * |
|
79 | - * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
80 | - */ |
|
81 | - public function __construct( $item = 0 ) { |
|
82 | - parent::__construct( $item ); |
|
83 | - |
|
84 | - if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
85 | - $this->set_id( $item ); |
|
86 | - } elseif ( $item instanceof self ) { |
|
87 | - $this->set_id( $item->get_id() ); |
|
88 | - } elseif ( ! empty( $item->ID ) ) { |
|
89 | - $this->set_id( $item->ID ); |
|
90 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
91 | - $this->set_id( $item_id ); |
|
92 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
93 | - $this->set_id( $item_id ); |
|
94 | - } else { |
|
95 | - $this->set_object_read( true ); |
|
96 | - } |
|
77 | + * Get the item if ID is passed, otherwise the item is new and empty. |
|
78 | + * |
|
79 | + * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
80 | + */ |
|
81 | + public function __construct( $item = 0 ) { |
|
82 | + parent::__construct( $item ); |
|
83 | + |
|
84 | + if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
85 | + $this->set_id( $item ); |
|
86 | + } elseif ( $item instanceof self ) { |
|
87 | + $this->set_id( $item->get_id() ); |
|
88 | + } elseif ( ! empty( $item->ID ) ) { |
|
89 | + $this->set_id( $item->ID ); |
|
90 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
91 | + $this->set_id( $item_id ); |
|
92 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
93 | + $this->set_id( $item_id ); |
|
94 | + } else { |
|
95 | + $this->set_object_read( true ); |
|
96 | + } |
|
97 | 97 | |
98 | 98 | // Load the datastore. |
99 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
99 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
100 | 100 | |
101 | - if ( $this->get_id() > 0 ) { |
|
101 | + if ( $this->get_id() > 0 ) { |
|
102 | 102 | $this->post = get_post( $this->get_id() ); |
103 | 103 | $this->ID = $this->get_id(); |
104 | - $this->data_store->read( $this ); |
|
104 | + $this->data_store->read( $this ); |
|
105 | 105 | } |
106 | 106 | |
107 | - } |
|
107 | + } |
|
108 | 108 | |
109 | 109 | /* |
110 | 110 | |-------------------------------------------------------------------------- |
@@ -122,401 +122,401 @@ discard block |
||
122 | 122 | */ |
123 | 123 | |
124 | 124 | /** |
125 | - * Get parent item ID. |
|
126 | - * |
|
127 | - * @since 1.0.19 |
|
128 | - * @param string $context View or edit context. |
|
129 | - * @return int |
|
130 | - */ |
|
131 | - public function get_parent_id( $context = 'view' ) { |
|
132 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
125 | + * Get parent item ID. |
|
126 | + * |
|
127 | + * @since 1.0.19 |
|
128 | + * @param string $context View or edit context. |
|
129 | + * @return int |
|
130 | + */ |
|
131 | + public function get_parent_id( $context = 'view' ) { |
|
132 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
136 | - * Get item status. |
|
137 | - * |
|
138 | - * @since 1.0.19 |
|
139 | - * @param string $context View or edit context. |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public function get_status( $context = 'view' ) { |
|
143 | - return $this->get_prop( 'status', $context ); |
|
136 | + * Get item status. |
|
137 | + * |
|
138 | + * @since 1.0.19 |
|
139 | + * @param string $context View or edit context. |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public function get_status( $context = 'view' ) { |
|
143 | + return $this->get_prop( 'status', $context ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | - * Get plugin version when the item was created. |
|
148 | - * |
|
149 | - * @since 1.0.19 |
|
150 | - * @param string $context View or edit context. |
|
151 | - * @return string |
|
152 | - */ |
|
153 | - public function get_version( $context = 'view' ) { |
|
154 | - return $this->get_prop( 'version', $context ); |
|
147 | + * Get plugin version when the item was created. |
|
148 | + * |
|
149 | + * @since 1.0.19 |
|
150 | + * @param string $context View or edit context. |
|
151 | + * @return string |
|
152 | + */ |
|
153 | + public function get_version( $context = 'view' ) { |
|
154 | + return $this->get_prop( 'version', $context ); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
158 | - * Get date when the item was created. |
|
159 | - * |
|
160 | - * @since 1.0.19 |
|
161 | - * @param string $context View or edit context. |
|
162 | - * @return string |
|
163 | - */ |
|
164 | - public function get_date_created( $context = 'view' ) { |
|
165 | - return $this->get_prop( 'date_created', $context ); |
|
158 | + * Get date when the item was created. |
|
159 | + * |
|
160 | + * @since 1.0.19 |
|
161 | + * @param string $context View or edit context. |
|
162 | + * @return string |
|
163 | + */ |
|
164 | + public function get_date_created( $context = 'view' ) { |
|
165 | + return $this->get_prop( 'date_created', $context ); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
169 | - * Get GMT date when the item was created. |
|
170 | - * |
|
171 | - * @since 1.0.19 |
|
172 | - * @param string $context View or edit context. |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - public function get_date_created_gmt( $context = 'view' ) { |
|
169 | + * Get GMT date when the item was created. |
|
170 | + * |
|
171 | + * @since 1.0.19 |
|
172 | + * @param string $context View or edit context. |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + public function get_date_created_gmt( $context = 'view' ) { |
|
176 | 176 | $date = $this->get_date_created( $context ); |
177 | 177 | |
178 | 178 | if ( $date ) { |
179 | 179 | $date = get_gmt_from_date( $date ); |
180 | 180 | } |
181 | - return $date; |
|
181 | + return $date; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | - * Get date when the item was last modified. |
|
186 | - * |
|
187 | - * @since 1.0.19 |
|
188 | - * @param string $context View or edit context. |
|
189 | - * @return string |
|
190 | - */ |
|
191 | - public function get_date_modified( $context = 'view' ) { |
|
192 | - return $this->get_prop( 'date_modified', $context ); |
|
185 | + * Get date when the item was last modified. |
|
186 | + * |
|
187 | + * @since 1.0.19 |
|
188 | + * @param string $context View or edit context. |
|
189 | + * @return string |
|
190 | + */ |
|
191 | + public function get_date_modified( $context = 'view' ) { |
|
192 | + return $this->get_prop( 'date_modified', $context ); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
196 | - * Get GMT date when the item was last modified. |
|
197 | - * |
|
198 | - * @since 1.0.19 |
|
199 | - * @param string $context View or edit context. |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
196 | + * Get GMT date when the item was last modified. |
|
197 | + * |
|
198 | + * @since 1.0.19 |
|
199 | + * @param string $context View or edit context. |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
203 | 203 | $date = $this->get_date_modified( $context ); |
204 | 204 | |
205 | 205 | if ( $date ) { |
206 | 206 | $date = get_gmt_from_date( $date ); |
207 | 207 | } |
208 | - return $date; |
|
208 | + return $date; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
212 | - * Get the item name. |
|
213 | - * |
|
214 | - * @since 1.0.19 |
|
215 | - * @param string $context View or edit context. |
|
216 | - * @return string |
|
217 | - */ |
|
218 | - public function get_name( $context = 'view' ) { |
|
219 | - return $this->get_prop( 'name', $context ); |
|
212 | + * Get the item name. |
|
213 | + * |
|
214 | + * @since 1.0.19 |
|
215 | + * @param string $context View or edit context. |
|
216 | + * @return string |
|
217 | + */ |
|
218 | + public function get_name( $context = 'view' ) { |
|
219 | + return $this->get_prop( 'name', $context ); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
223 | - * Alias of self::get_name(). |
|
224 | - * |
|
225 | - * @since 1.0.19 |
|
226 | - * @param string $context View or edit context. |
|
227 | - * @return string |
|
228 | - */ |
|
229 | - public function get_title( $context = 'view' ) { |
|
230 | - return $this->get_name( $context ); |
|
223 | + * Alias of self::get_name(). |
|
224 | + * |
|
225 | + * @since 1.0.19 |
|
226 | + * @param string $context View or edit context. |
|
227 | + * @return string |
|
228 | + */ |
|
229 | + public function get_title( $context = 'view' ) { |
|
230 | + return $this->get_name( $context ); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
234 | - * Get the item description. |
|
235 | - * |
|
236 | - * @since 1.0.19 |
|
237 | - * @param string $context View or edit context. |
|
238 | - * @return string |
|
239 | - */ |
|
240 | - public function get_description( $context = 'view' ) { |
|
241 | - return $this->get_prop( 'description', $context ); |
|
234 | + * Get the item description. |
|
235 | + * |
|
236 | + * @since 1.0.19 |
|
237 | + * @param string $context View or edit context. |
|
238 | + * @return string |
|
239 | + */ |
|
240 | + public function get_description( $context = 'view' ) { |
|
241 | + return $this->get_prop( 'description', $context ); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
245 | - * Alias of self::get_description(). |
|
246 | - * |
|
247 | - * @since 1.0.19 |
|
248 | - * @param string $context View or edit context. |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public function get_excerpt( $context = 'view' ) { |
|
252 | - return $this->get_description( $context ); |
|
245 | + * Alias of self::get_description(). |
|
246 | + * |
|
247 | + * @since 1.0.19 |
|
248 | + * @param string $context View or edit context. |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public function get_excerpt( $context = 'view' ) { |
|
252 | + return $this->get_description( $context ); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
256 | - * Alias of self::get_description(). |
|
257 | - * |
|
258 | - * @since 1.0.19 |
|
259 | - * @param string $context View or edit context. |
|
260 | - * @return string |
|
261 | - */ |
|
262 | - public function get_summary( $context = 'view' ) { |
|
263 | - return $this->get_description( $context ); |
|
256 | + * Alias of self::get_description(). |
|
257 | + * |
|
258 | + * @since 1.0.19 |
|
259 | + * @param string $context View or edit context. |
|
260 | + * @return string |
|
261 | + */ |
|
262 | + public function get_summary( $context = 'view' ) { |
|
263 | + return $this->get_description( $context ); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
267 | - * Get the owner of the item. |
|
268 | - * |
|
269 | - * @since 1.0.19 |
|
270 | - * @param string $context View or edit context. |
|
271 | - * @return int |
|
272 | - */ |
|
273 | - public function get_author( $context = 'view' ) { |
|
274 | - return (int) $this->get_prop( 'author', $context ); |
|
275 | - } |
|
267 | + * Get the owner of the item. |
|
268 | + * |
|
269 | + * @since 1.0.19 |
|
270 | + * @param string $context View or edit context. |
|
271 | + * @return int |
|
272 | + */ |
|
273 | + public function get_author( $context = 'view' ) { |
|
274 | + return (int) $this->get_prop( 'author', $context ); |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
278 | - * Alias of self::get_author(). |
|
279 | - * |
|
280 | - * @since 1.0.19 |
|
281 | - * @param string $context View or edit context. |
|
282 | - * @return int |
|
283 | - */ |
|
284 | - public function get_owner( $context = 'view' ) { |
|
285 | - return $this->get_author( $context ); |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Get the price of the item. |
|
290 | - * |
|
291 | - * @since 1.0.19 |
|
292 | - * @param string $context View or edit context. |
|
293 | - * @return float |
|
294 | - */ |
|
295 | - public function get_price( $context = 'view' ) { |
|
277 | + /** |
|
278 | + * Alias of self::get_author(). |
|
279 | + * |
|
280 | + * @since 1.0.19 |
|
281 | + * @param string $context View or edit context. |
|
282 | + * @return int |
|
283 | + */ |
|
284 | + public function get_owner( $context = 'view' ) { |
|
285 | + return $this->get_author( $context ); |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Get the price of the item. |
|
290 | + * |
|
291 | + * @since 1.0.19 |
|
292 | + * @param string $context View or edit context. |
|
293 | + * @return float |
|
294 | + */ |
|
295 | + public function get_price( $context = 'view' ) { |
|
296 | 296 | return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
297 | - } |
|
297 | + } |
|
298 | 298 | |
299 | - /** |
|
300 | - * Get the inital price of the item. |
|
301 | - * |
|
302 | - * @since 1.0.19 |
|
303 | - * @param string $context View or edit context. |
|
304 | - * @return float |
|
305 | - */ |
|
306 | - public function get_initial_price( $context = 'view' ) { |
|
299 | + /** |
|
300 | + * Get the inital price of the item. |
|
301 | + * |
|
302 | + * @since 1.0.19 |
|
303 | + * @param string $context View or edit context. |
|
304 | + * @return float |
|
305 | + */ |
|
306 | + public function get_initial_price( $context = 'view' ) { |
|
307 | 307 | |
308 | - $price = (float) $this->get_price( $context ); |
|
308 | + $price = (float) $this->get_price( $context ); |
|
309 | 309 | |
310 | - if ( $this->has_free_trial() ) { |
|
311 | - $price = 0; |
|
312 | - } |
|
310 | + if ( $this->has_free_trial() ) { |
|
311 | + $price = 0; |
|
312 | + } |
|
313 | 313 | |
314 | 314 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) ); |
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
318 | - * Returns a formated price. |
|
319 | - * |
|
320 | - * @since 1.0.19 |
|
321 | - * @param string $context View or edit context. |
|
322 | - * @return string |
|
323 | - */ |
|
318 | + * Returns a formated price. |
|
319 | + * |
|
320 | + * @since 1.0.19 |
|
321 | + * @param string $context View or edit context. |
|
322 | + * @return string |
|
323 | + */ |
|
324 | 324 | public function get_the_price() { |
325 | 325 | return wpinv_price( $this->get_price() ); |
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * Returns the formated initial price. |
|
330 | - * |
|
331 | - * @since 1.0.19 |
|
332 | - * @param string $context View or edit context. |
|
333 | - * @return string |
|
334 | - */ |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * Returns the formated initial price. |
|
330 | + * |
|
331 | + * @since 1.0.19 |
|
332 | + * @param string $context View or edit context. |
|
333 | + * @return string |
|
334 | + */ |
|
335 | 335 | public function get_the_initial_price() { |
336 | 336 | return wpinv_price( $this->get_initial_price() ); |
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
340 | - * Get the VAT rule of the item. |
|
341 | - * |
|
342 | - * @since 1.0.19 |
|
343 | - * @param string $context View or edit context. |
|
344 | - * @return string |
|
345 | - */ |
|
346 | - public function get_vat_rule( $context = 'view' ) { |
|
340 | + * Get the VAT rule of the item. |
|
341 | + * |
|
342 | + * @since 1.0.19 |
|
343 | + * @param string $context View or edit context. |
|
344 | + * @return string |
|
345 | + */ |
|
346 | + public function get_vat_rule( $context = 'view' ) { |
|
347 | 347 | return $this->get_prop( 'vat_rule', $context ); |
348 | 348 | } |
349 | 349 | |
350 | 350 | /** |
351 | - * Get the VAT class of the item. |
|
352 | - * |
|
353 | - * @since 1.0.19 |
|
354 | - * @param string $context View or edit context. |
|
355 | - * @return string |
|
356 | - */ |
|
357 | - public function get_vat_class( $context = 'view' ) { |
|
351 | + * Get the VAT class of the item. |
|
352 | + * |
|
353 | + * @since 1.0.19 |
|
354 | + * @param string $context View or edit context. |
|
355 | + * @return string |
|
356 | + */ |
|
357 | + public function get_vat_class( $context = 'view' ) { |
|
358 | 358 | return $this->get_prop( 'vat_class', $context ); |
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
362 | - * Get the type of the item. |
|
363 | - * |
|
364 | - * @since 1.0.19 |
|
365 | - * @param string $context View or edit context. |
|
366 | - * @return string |
|
367 | - */ |
|
368 | - public function get_type( $context = 'view' ) { |
|
362 | + * Get the type of the item. |
|
363 | + * |
|
364 | + * @since 1.0.19 |
|
365 | + * @param string $context View or edit context. |
|
366 | + * @return string |
|
367 | + */ |
|
368 | + public function get_type( $context = 'view' ) { |
|
369 | 369 | return $this->get_prop( 'type', $context ); |
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
373 | - * Get the custom id of the item. |
|
374 | - * |
|
375 | - * @since 1.0.19 |
|
376 | - * @param string $context View or edit context. |
|
377 | - * @return string |
|
378 | - */ |
|
379 | - public function get_custom_id( $context = 'view' ) { |
|
373 | + * Get the custom id of the item. |
|
374 | + * |
|
375 | + * @since 1.0.19 |
|
376 | + * @param string $context View or edit context. |
|
377 | + * @return string |
|
378 | + */ |
|
379 | + public function get_custom_id( $context = 'view' ) { |
|
380 | 380 | return $this->get_prop( 'custom_id', $context ); |
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
384 | - * Get the custom name of the item. |
|
385 | - * |
|
386 | - * @since 1.0.19 |
|
387 | - * @param string $context View or edit context. |
|
388 | - * @return string |
|
389 | - */ |
|
390 | - public function get_custom_name( $context = 'view' ) { |
|
384 | + * Get the custom name of the item. |
|
385 | + * |
|
386 | + * @since 1.0.19 |
|
387 | + * @param string $context View or edit context. |
|
388 | + * @return string |
|
389 | + */ |
|
390 | + public function get_custom_name( $context = 'view' ) { |
|
391 | 391 | return $this->get_prop( 'custom_name', $context ); |
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
395 | - * Get the custom singular name of the item. |
|
396 | - * |
|
397 | - * @since 1.0.19 |
|
398 | - * @param string $context View or edit context. |
|
399 | - * @return string |
|
400 | - */ |
|
401 | - public function get_custom_singular_name( $context = 'view' ) { |
|
395 | + * Get the custom singular name of the item. |
|
396 | + * |
|
397 | + * @since 1.0.19 |
|
398 | + * @param string $context View or edit context. |
|
399 | + * @return string |
|
400 | + */ |
|
401 | + public function get_custom_singular_name( $context = 'view' ) { |
|
402 | 402 | return $this->get_prop( 'custom_singular_name', $context ); |
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
406 | - * Checks if an item is editable.. |
|
407 | - * |
|
408 | - * @since 1.0.19 |
|
409 | - * @param string $context View or edit context. |
|
410 | - * @return int |
|
411 | - */ |
|
412 | - public function get_is_editable( $context = 'view' ) { |
|
406 | + * Checks if an item is editable.. |
|
407 | + * |
|
408 | + * @since 1.0.19 |
|
409 | + * @param string $context View or edit context. |
|
410 | + * @return int |
|
411 | + */ |
|
412 | + public function get_is_editable( $context = 'view' ) { |
|
413 | 413 | return (int) $this->get_prop( 'is_editable', $context ); |
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
417 | - * Alias of self::get_is_editable(). |
|
418 | - * |
|
419 | - * @since 1.0.19 |
|
420 | - * @param string $context View or edit context. |
|
421 | - * @return int |
|
422 | - */ |
|
423 | - public function get_editable( $context = 'view' ) { |
|
424 | - return $this->get_is_editable( $context ); |
|
417 | + * Alias of self::get_is_editable(). |
|
418 | + * |
|
419 | + * @since 1.0.19 |
|
420 | + * @param string $context View or edit context. |
|
421 | + * @return int |
|
422 | + */ |
|
423 | + public function get_editable( $context = 'view' ) { |
|
424 | + return $this->get_is_editable( $context ); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
428 | - * Checks if dynamic pricing is enabled. |
|
429 | - * |
|
430 | - * @since 1.0.19 |
|
431 | - * @param string $context View or edit context. |
|
432 | - * @return int |
|
433 | - */ |
|
434 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
428 | + * Checks if dynamic pricing is enabled. |
|
429 | + * |
|
430 | + * @since 1.0.19 |
|
431 | + * @param string $context View or edit context. |
|
432 | + * @return int |
|
433 | + */ |
|
434 | + public function get_is_dynamic_pricing( $context = 'view' ) { |
|
435 | 435 | return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
439 | - * Returns the minimum price if dynamic pricing is enabled. |
|
440 | - * |
|
441 | - * @since 1.0.19 |
|
442 | - * @param string $context View or edit context. |
|
443 | - * @return float |
|
444 | - */ |
|
445 | - public function get_minimum_price( $context = 'view' ) { |
|
439 | + * Returns the minimum price if dynamic pricing is enabled. |
|
440 | + * |
|
441 | + * @since 1.0.19 |
|
442 | + * @param string $context View or edit context. |
|
443 | + * @return float |
|
444 | + */ |
|
445 | + public function get_minimum_price( $context = 'view' ) { |
|
446 | 446 | return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
450 | - * Checks if this is a recurring item. |
|
451 | - * |
|
452 | - * @since 1.0.19 |
|
453 | - * @param string $context View or edit context. |
|
454 | - * @return int |
|
455 | - */ |
|
456 | - public function get_is_recurring( $context = 'view' ) { |
|
450 | + * Checks if this is a recurring item. |
|
451 | + * |
|
452 | + * @since 1.0.19 |
|
453 | + * @param string $context View or edit context. |
|
454 | + * @return int |
|
455 | + */ |
|
456 | + public function get_is_recurring( $context = 'view' ) { |
|
457 | 457 | return (int) $this->get_prop( 'is_recurring', $context ); |
458 | - } |
|
458 | + } |
|
459 | 459 | |
460 | - /** |
|
461 | - * Get the recurring price of the item. |
|
462 | - * |
|
463 | - * @since 1.0.19 |
|
464 | - * @param string $context View or edit context. |
|
465 | - * @return float |
|
466 | - */ |
|
467 | - public function get_recurring_price( $context = 'view' ) { |
|
468 | - $price = $this->get_price( $context ); |
|
460 | + /** |
|
461 | + * Get the recurring price of the item. |
|
462 | + * |
|
463 | + * @since 1.0.19 |
|
464 | + * @param string $context View or edit context. |
|
465 | + * @return float |
|
466 | + */ |
|
467 | + public function get_recurring_price( $context = 'view' ) { |
|
468 | + $price = $this->get_price( $context ); |
|
469 | 469 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) ); |
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * Get the formatted recurring price of the item. |
|
474 | - * |
|
475 | - * @since 1.0.19 |
|
476 | - * @param string $context View or edit context. |
|
477 | - * @return string |
|
478 | - */ |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * Get the formatted recurring price of the item. |
|
474 | + * |
|
475 | + * @since 1.0.19 |
|
476 | + * @param string $context View or edit context. |
|
477 | + * @return string |
|
478 | + */ |
|
479 | 479 | public function get_the_recurring_price() { |
480 | 480 | return wpinv_price( $this->get_recurring_price() ); |
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * Get the first renewal date (in timestamps) of the item. |
|
485 | - * |
|
486 | - * @since 1.0.19 |
|
487 | - * @return int |
|
488 | - */ |
|
489 | - public function get_first_renewal_date() { |
|
490 | - |
|
491 | - $periods = array( |
|
492 | - 'D' => 'days', |
|
493 | - 'W' => 'weeks', |
|
494 | - 'M' => 'months', |
|
495 | - 'Y' => 'years', |
|
496 | - ); |
|
497 | - |
|
498 | - $period = $this->get_recurring_period(); |
|
499 | - $interval = $this->get_recurring_interval(); |
|
500 | - |
|
501 | - if ( $this->has_free_trial() ) { |
|
502 | - $period = $this->get_trial_period(); |
|
503 | - $interval = $this->get_trial_interval(); |
|
504 | - } |
|
505 | - |
|
506 | - $period = $periods[ $period ]; |
|
507 | - $interval = empty( $interval ) ? 1 : $interval; |
|
508 | - $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * Get the first renewal date (in timestamps) of the item. |
|
485 | + * |
|
486 | + * @since 1.0.19 |
|
487 | + * @return int |
|
488 | + */ |
|
489 | + public function get_first_renewal_date() { |
|
490 | + |
|
491 | + $periods = array( |
|
492 | + 'D' => 'days', |
|
493 | + 'W' => 'weeks', |
|
494 | + 'M' => 'months', |
|
495 | + 'Y' => 'years', |
|
496 | + ); |
|
497 | + |
|
498 | + $period = $this->get_recurring_period(); |
|
499 | + $interval = $this->get_recurring_interval(); |
|
500 | + |
|
501 | + if ( $this->has_free_trial() ) { |
|
502 | + $period = $this->get_trial_period(); |
|
503 | + $interval = $this->get_trial_interval(); |
|
504 | + } |
|
505 | + |
|
506 | + $period = $periods[ $period ]; |
|
507 | + $interval = empty( $interval ) ? 1 : $interval; |
|
508 | + $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
509 | 509 | return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this ); |
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
513 | - * Get the recurring period. |
|
514 | - * |
|
515 | - * @since 1.0.19 |
|
516 | - * @param bool $full Return abbreviation or in full. |
|
517 | - * @return string |
|
518 | - */ |
|
519 | - public function get_recurring_period( $full = false ) { |
|
513 | + * Get the recurring period. |
|
514 | + * |
|
515 | + * @since 1.0.19 |
|
516 | + * @param bool $full Return abbreviation or in full. |
|
517 | + * @return string |
|
518 | + */ |
|
519 | + public function get_recurring_period( $full = false ) { |
|
520 | 520 | $period = $this->get_prop( 'recurring_period', 'view' ); |
521 | 521 | |
522 | 522 | if ( $full && ! is_bool( $full ) ) { |
@@ -527,63 +527,63 @@ discard block |
||
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
530 | - * Get the recurring interval. |
|
531 | - * |
|
532 | - * @since 1.0.19 |
|
533 | - * @param string $context View or edit context. |
|
534 | - * @return int |
|
535 | - */ |
|
536 | - public function get_recurring_interval( $context = 'view' ) { |
|
537 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
530 | + * Get the recurring interval. |
|
531 | + * |
|
532 | + * @since 1.0.19 |
|
533 | + * @param string $context View or edit context. |
|
534 | + * @return int |
|
535 | + */ |
|
536 | + public function get_recurring_interval( $context = 'view' ) { |
|
537 | + $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
538 | 538 | |
539 | - if ( $interval < 1 ) { |
|
540 | - $interval = 1; |
|
541 | - } |
|
539 | + if ( $interval < 1 ) { |
|
540 | + $interval = 1; |
|
541 | + } |
|
542 | 542 | |
543 | 543 | return $interval; |
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
547 | - * Get the recurring limit. |
|
548 | - * |
|
549 | - * @since 1.0.19 |
|
550 | - * @param string $context View or edit context. |
|
551 | - * @return int |
|
552 | - */ |
|
553 | - public function get_recurring_limit( $context = 'view' ) { |
|
547 | + * Get the recurring limit. |
|
548 | + * |
|
549 | + * @since 1.0.19 |
|
550 | + * @param string $context View or edit context. |
|
551 | + * @return int |
|
552 | + */ |
|
553 | + public function get_recurring_limit( $context = 'view' ) { |
|
554 | 554 | return (int) $this->get_prop( 'recurring_limit', $context ); |
555 | 555 | } |
556 | 556 | |
557 | 557 | /** |
558 | - * Checks if we have a free trial. |
|
559 | - * |
|
560 | - * @since 1.0.19 |
|
561 | - * @param string $context View or edit context. |
|
562 | - * @return int |
|
563 | - */ |
|
564 | - public function get_is_free_trial( $context = 'view' ) { |
|
558 | + * Checks if we have a free trial. |
|
559 | + * |
|
560 | + * @since 1.0.19 |
|
561 | + * @param string $context View or edit context. |
|
562 | + * @return int |
|
563 | + */ |
|
564 | + public function get_is_free_trial( $context = 'view' ) { |
|
565 | 565 | return (int) $this->get_prop( 'is_free_trial', $context ); |
566 | 566 | } |
567 | 567 | |
568 | 568 | /** |
569 | - * Alias for self::get_is_free_trial(). |
|
570 | - * |
|
571 | - * @since 1.0.19 |
|
572 | - * @param string $context View or edit context. |
|
573 | - * @return int |
|
574 | - */ |
|
575 | - public function get_free_trial( $context = 'view' ) { |
|
569 | + * Alias for self::get_is_free_trial(). |
|
570 | + * |
|
571 | + * @since 1.0.19 |
|
572 | + * @param string $context View or edit context. |
|
573 | + * @return int |
|
574 | + */ |
|
575 | + public function get_free_trial( $context = 'view' ) { |
|
576 | 576 | return $this->get_is_free_trial( $context ); |
577 | 577 | } |
578 | 578 | |
579 | 579 | /** |
580 | - * Get the trial period. |
|
581 | - * |
|
582 | - * @since 1.0.19 |
|
583 | - * @param bool $full Return abbreviation or in full. |
|
584 | - * @return string |
|
585 | - */ |
|
586 | - public function get_trial_period( $full = false ) { |
|
580 | + * Get the trial period. |
|
581 | + * |
|
582 | + * @since 1.0.19 |
|
583 | + * @param bool $full Return abbreviation or in full. |
|
584 | + * @return string |
|
585 | + */ |
|
586 | + public function get_trial_period( $full = false ) { |
|
587 | 587 | $period = $this->get_prop( 'trial_period', 'view' ); |
588 | 588 | |
589 | 589 | if ( $full && ! is_bool( $full ) ) { |
@@ -594,104 +594,104 @@ discard block |
||
594 | 594 | } |
595 | 595 | |
596 | 596 | /** |
597 | - * Get the trial interval. |
|
598 | - * |
|
599 | - * @since 1.0.19 |
|
600 | - * @param string $context View or edit context. |
|
601 | - * @return int |
|
602 | - */ |
|
603 | - public function get_trial_interval( $context = 'view' ) { |
|
597 | + * Get the trial interval. |
|
598 | + * |
|
599 | + * @since 1.0.19 |
|
600 | + * @param string $context View or edit context. |
|
601 | + * @return int |
|
602 | + */ |
|
603 | + public function get_trial_interval( $context = 'view' ) { |
|
604 | 604 | return (int) $this->get_prop( 'trial_interval', $context ); |
605 | - } |
|
605 | + } |
|
606 | 606 | |
607 | - /** |
|
608 | - * Get the item's edit url. |
|
609 | - * |
|
610 | - * @since 1.0.19 |
|
611 | - * @return string |
|
612 | - */ |
|
613 | - public function get_edit_url() { |
|
607 | + /** |
|
608 | + * Get the item's edit url. |
|
609 | + * |
|
610 | + * @since 1.0.19 |
|
611 | + * @return string |
|
612 | + */ |
|
613 | + public function get_edit_url() { |
|
614 | 614 | return get_edit_post_link( $this->get_id() ); |
615 | - } |
|
616 | - |
|
617 | - /** |
|
618 | - * Given an item's name/custom id, it returns its id. |
|
619 | - * |
|
620 | - * |
|
621 | - * @static |
|
622 | - * @param string $value The item name or custom id. |
|
623 | - * @param string $field Either name or custom_id. |
|
624 | - * @param string $type in case you need to search for a given type. |
|
625 | - * @since 1.0.15 |
|
626 | - * @return int |
|
627 | - */ |
|
628 | - public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
629 | - |
|
630 | - // Trim the value. |
|
631 | - $value = sanitize_text_field( $value ); |
|
632 | - if ( empty( $value ) ) { |
|
633 | - return 0; |
|
634 | - } |
|
615 | + } |
|
616 | + |
|
617 | + /** |
|
618 | + * Given an item's name/custom id, it returns its id. |
|
619 | + * |
|
620 | + * |
|
621 | + * @static |
|
622 | + * @param string $value The item name or custom id. |
|
623 | + * @param string $field Either name or custom_id. |
|
624 | + * @param string $type in case you need to search for a given type. |
|
625 | + * @since 1.0.15 |
|
626 | + * @return int |
|
627 | + */ |
|
628 | + public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
629 | + |
|
630 | + // Trim the value. |
|
631 | + $value = sanitize_text_field( $value ); |
|
632 | + if ( empty( $value ) ) { |
|
633 | + return 0; |
|
634 | + } |
|
635 | 635 | |
636 | 636 | // Valid fields. |
637 | 637 | $fields = array( 'custom_id', 'name', 'slug' ); |
638 | 638 | |
639 | - // Ensure a field has been passed. |
|
640 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
641 | - return 0; |
|
642 | - } |
|
643 | - |
|
644 | - if ( $field == 'name' ) { |
|
645 | - $field = 'slug'; |
|
646 | - } |
|
647 | - |
|
648 | - // Maybe retrieve from the cache. |
|
649 | - $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
650 | - if ( ! empty( $item_id ) ) { |
|
651 | - return $item_id; |
|
652 | - } |
|
653 | - |
|
654 | - // Fetch from the db. |
|
655 | - $items = array(); |
|
656 | - if ( $field == 'slug' ) { |
|
657 | - $items = get_posts( |
|
658 | - array( |
|
659 | - 'post_type' => 'wpi_item', |
|
660 | - 'name' => $value, |
|
661 | - 'posts_per_page' => 1, |
|
662 | - 'post_status' => 'any', |
|
663 | - ) |
|
664 | - ); |
|
665 | - } |
|
666 | - |
|
667 | - if ( $field =='custom_id' ) { |
|
668 | - $items = get_posts( |
|
669 | - array( |
|
670 | - 'post_type' => 'wpi_item', |
|
671 | - 'posts_per_page' => 1, |
|
672 | - 'post_status' => 'any', |
|
673 | - 'meta_query' => array( |
|
674 | - array( |
|
675 | - 'key' => '_wpinv_type', |
|
676 | - 'value' => $type, |
|
677 | - ), |
|
678 | - array( |
|
679 | - 'key' => '_wpinv_custom_id', |
|
680 | - 'value' => $value, |
|
681 | - ) |
|
682 | - ) |
|
683 | - ) |
|
684 | - ); |
|
685 | - } |
|
686 | - |
|
687 | - if ( empty( $items ) ) { |
|
688 | - return 0; |
|
689 | - } |
|
690 | - |
|
691 | - // Update the cache with our data |
|
692 | - wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
693 | - |
|
694 | - return $items[0]->ID; |
|
639 | + // Ensure a field has been passed. |
|
640 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
641 | + return 0; |
|
642 | + } |
|
643 | + |
|
644 | + if ( $field == 'name' ) { |
|
645 | + $field = 'slug'; |
|
646 | + } |
|
647 | + |
|
648 | + // Maybe retrieve from the cache. |
|
649 | + $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
650 | + if ( ! empty( $item_id ) ) { |
|
651 | + return $item_id; |
|
652 | + } |
|
653 | + |
|
654 | + // Fetch from the db. |
|
655 | + $items = array(); |
|
656 | + if ( $field == 'slug' ) { |
|
657 | + $items = get_posts( |
|
658 | + array( |
|
659 | + 'post_type' => 'wpi_item', |
|
660 | + 'name' => $value, |
|
661 | + 'posts_per_page' => 1, |
|
662 | + 'post_status' => 'any', |
|
663 | + ) |
|
664 | + ); |
|
665 | + } |
|
666 | + |
|
667 | + if ( $field =='custom_id' ) { |
|
668 | + $items = get_posts( |
|
669 | + array( |
|
670 | + 'post_type' => 'wpi_item', |
|
671 | + 'posts_per_page' => 1, |
|
672 | + 'post_status' => 'any', |
|
673 | + 'meta_query' => array( |
|
674 | + array( |
|
675 | + 'key' => '_wpinv_type', |
|
676 | + 'value' => $type, |
|
677 | + ), |
|
678 | + array( |
|
679 | + 'key' => '_wpinv_custom_id', |
|
680 | + 'value' => $value, |
|
681 | + ) |
|
682 | + ) |
|
683 | + ) |
|
684 | + ); |
|
685 | + } |
|
686 | + |
|
687 | + if ( empty( $items ) ) { |
|
688 | + return 0; |
|
689 | + } |
|
690 | + |
|
691 | + // Update the cache with our data |
|
692 | + wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
693 | + |
|
694 | + return $items[0]->ID; |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | /** |
@@ -724,52 +724,52 @@ discard block |
||
724 | 724 | */ |
725 | 725 | |
726 | 726 | /** |
727 | - * Set parent order ID. |
|
728 | - * |
|
729 | - * @since 1.0.19 |
|
730 | - */ |
|
731 | - public function set_parent_id( $value ) { |
|
732 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
733 | - return; |
|
734 | - } |
|
735 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
736 | - } |
|
737 | - |
|
738 | - /** |
|
739 | - * Sets item status. |
|
740 | - * |
|
741 | - * @since 1.0.19 |
|
742 | - * @param string $status New status. |
|
743 | - * @return array details of change. |
|
744 | - */ |
|
745 | - public function set_status( $status ) { |
|
727 | + * Set parent order ID. |
|
728 | + * |
|
729 | + * @since 1.0.19 |
|
730 | + */ |
|
731 | + public function set_parent_id( $value ) { |
|
732 | + if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
733 | + return; |
|
734 | + } |
|
735 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
736 | + } |
|
737 | + |
|
738 | + /** |
|
739 | + * Sets item status. |
|
740 | + * |
|
741 | + * @since 1.0.19 |
|
742 | + * @param string $status New status. |
|
743 | + * @return array details of change. |
|
744 | + */ |
|
745 | + public function set_status( $status ) { |
|
746 | 746 | $old_status = $this->get_status(); |
747 | 747 | |
748 | 748 | $this->set_prop( 'status', $status ); |
749 | 749 | |
750 | - return array( |
|
751 | - 'from' => $old_status, |
|
752 | - 'to' => $status, |
|
753 | - ); |
|
750 | + return array( |
|
751 | + 'from' => $old_status, |
|
752 | + 'to' => $status, |
|
753 | + ); |
|
754 | 754 | } |
755 | 755 | |
756 | 756 | /** |
757 | - * Set plugin version when the item was created. |
|
758 | - * |
|
759 | - * @since 1.0.19 |
|
760 | - */ |
|
761 | - public function set_version( $value ) { |
|
762 | - $this->set_prop( 'version', $value ); |
|
757 | + * Set plugin version when the item was created. |
|
758 | + * |
|
759 | + * @since 1.0.19 |
|
760 | + */ |
|
761 | + public function set_version( $value ) { |
|
762 | + $this->set_prop( 'version', $value ); |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | /** |
766 | - * Set date when the item was created. |
|
767 | - * |
|
768 | - * @since 1.0.19 |
|
769 | - * @param string $value Value to set. |
|
766 | + * Set date when the item was created. |
|
767 | + * |
|
768 | + * @since 1.0.19 |
|
769 | + * @param string $value Value to set. |
|
770 | 770 | * @return bool Whether or not the date was set. |
771 | - */ |
|
772 | - public function set_date_created( $value ) { |
|
771 | + */ |
|
772 | + public function set_date_created( $value ) { |
|
773 | 773 | $date = strtotime( $value ); |
774 | 774 | |
775 | 775 | if ( $date ) { |
@@ -782,13 +782,13 @@ discard block |
||
782 | 782 | } |
783 | 783 | |
784 | 784 | /** |
785 | - * Set date when the item was last modified. |
|
786 | - * |
|
787 | - * @since 1.0.19 |
|
788 | - * @param string $value Value to set. |
|
785 | + * Set date when the item was last modified. |
|
786 | + * |
|
787 | + * @since 1.0.19 |
|
788 | + * @param string $value Value to set. |
|
789 | 789 | * @return bool Whether or not the date was set. |
790 | - */ |
|
791 | - public function set_date_modified( $value ) { |
|
790 | + */ |
|
791 | + public function set_date_modified( $value ) { |
|
792 | 792 | $date = strtotime( $value ); |
793 | 793 | |
794 | 794 | if ( $date ) { |
@@ -801,115 +801,115 @@ discard block |
||
801 | 801 | } |
802 | 802 | |
803 | 803 | /** |
804 | - * Set the item name. |
|
805 | - * |
|
806 | - * @since 1.0.19 |
|
807 | - * @param string $value New name. |
|
808 | - */ |
|
809 | - public function set_name( $value ) { |
|
804 | + * Set the item name. |
|
805 | + * |
|
806 | + * @since 1.0.19 |
|
807 | + * @param string $value New name. |
|
808 | + */ |
|
809 | + public function set_name( $value ) { |
|
810 | 810 | $name = sanitize_text_field( $value ); |
811 | - $this->set_prop( 'name', $name ); |
|
811 | + $this->set_prop( 'name', $name ); |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | /** |
815 | - * Alias of self::set_name(). |
|
816 | - * |
|
817 | - * @since 1.0.19 |
|
818 | - * @param string $value New name. |
|
819 | - */ |
|
820 | - public function set_title( $value ) { |
|
821 | - $this->set_name( $value ); |
|
815 | + * Alias of self::set_name(). |
|
816 | + * |
|
817 | + * @since 1.0.19 |
|
818 | + * @param string $value New name. |
|
819 | + */ |
|
820 | + public function set_title( $value ) { |
|
821 | + $this->set_name( $value ); |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | /** |
825 | - * Set the item description. |
|
826 | - * |
|
827 | - * @since 1.0.19 |
|
828 | - * @param string $value New description. |
|
829 | - */ |
|
830 | - public function set_description( $value ) { |
|
831 | - $description = wp_kses_post( $value ); |
|
832 | - return $this->set_prop( 'description', $description ); |
|
825 | + * Set the item description. |
|
826 | + * |
|
827 | + * @since 1.0.19 |
|
828 | + * @param string $value New description. |
|
829 | + */ |
|
830 | + public function set_description( $value ) { |
|
831 | + $description = wp_kses_post( $value ); |
|
832 | + return $this->set_prop( 'description', $description ); |
|
833 | 833 | } |
834 | 834 | |
835 | 835 | /** |
836 | - * Alias of self::set_description(). |
|
837 | - * |
|
838 | - * @since 1.0.19 |
|
839 | - * @param string $value New description. |
|
840 | - */ |
|
841 | - public function set_excerpt( $value ) { |
|
842 | - $this->set_description( $value ); |
|
836 | + * Alias of self::set_description(). |
|
837 | + * |
|
838 | + * @since 1.0.19 |
|
839 | + * @param string $value New description. |
|
840 | + */ |
|
841 | + public function set_excerpt( $value ) { |
|
842 | + $this->set_description( $value ); |
|
843 | 843 | } |
844 | 844 | |
845 | 845 | /** |
846 | - * Alias of self::set_description(). |
|
847 | - * |
|
848 | - * @since 1.0.19 |
|
849 | - * @param string $value New description. |
|
850 | - */ |
|
851 | - public function set_summary( $value ) { |
|
852 | - $this->set_description( $value ); |
|
846 | + * Alias of self::set_description(). |
|
847 | + * |
|
848 | + * @since 1.0.19 |
|
849 | + * @param string $value New description. |
|
850 | + */ |
|
851 | + public function set_summary( $value ) { |
|
852 | + $this->set_description( $value ); |
|
853 | 853 | } |
854 | 854 | |
855 | 855 | /** |
856 | - * Set the owner of the item. |
|
857 | - * |
|
858 | - * @since 1.0.19 |
|
859 | - * @param int $value New author. |
|
860 | - */ |
|
861 | - public function set_author( $value ) { |
|
862 | - $this->set_prop( 'author', (int) $value ); |
|
863 | - } |
|
856 | + * Set the owner of the item. |
|
857 | + * |
|
858 | + * @since 1.0.19 |
|
859 | + * @param int $value New author. |
|
860 | + */ |
|
861 | + public function set_author( $value ) { |
|
862 | + $this->set_prop( 'author', (int) $value ); |
|
863 | + } |
|
864 | 864 | |
865 | - /** |
|
866 | - * Alias of self::set_author(). |
|
867 | - * |
|
868 | - * @since 1.0.19 |
|
869 | - * @param int $value New author. |
|
870 | - */ |
|
871 | - public function set_owner( $value ) { |
|
872 | - $this->set_author( $value ); |
|
873 | - } |
|
874 | - |
|
875 | - /** |
|
876 | - * Set the price of the item. |
|
877 | - * |
|
878 | - * @since 1.0.19 |
|
879 | - * @param float $value New price. |
|
880 | - */ |
|
881 | - public function set_price( $value ) { |
|
865 | + /** |
|
866 | + * Alias of self::set_author(). |
|
867 | + * |
|
868 | + * @since 1.0.19 |
|
869 | + * @param int $value New author. |
|
870 | + */ |
|
871 | + public function set_owner( $value ) { |
|
872 | + $this->set_author( $value ); |
|
873 | + } |
|
874 | + |
|
875 | + /** |
|
876 | + * Set the price of the item. |
|
877 | + * |
|
878 | + * @since 1.0.19 |
|
879 | + * @param float $value New price. |
|
880 | + */ |
|
881 | + public function set_price( $value ) { |
|
882 | 882 | $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
883 | 883 | } |
884 | 884 | |
885 | 885 | /** |
886 | - * Set the VAT rule of the item. |
|
887 | - * |
|
888 | - * @since 1.0.19 |
|
889 | - * @param string $value new rule. |
|
890 | - */ |
|
891 | - public function set_vat_rule( $value ) { |
|
886 | + * Set the VAT rule of the item. |
|
887 | + * |
|
888 | + * @since 1.0.19 |
|
889 | + * @param string $value new rule. |
|
890 | + */ |
|
891 | + public function set_vat_rule( $value ) { |
|
892 | 892 | $this->set_prop( 'vat_rule', $value ); |
893 | 893 | } |
894 | 894 | |
895 | 895 | /** |
896 | - * Set the VAT class of the item. |
|
897 | - * |
|
898 | - * @since 1.0.19 |
|
899 | - * @param string $value new class. |
|
900 | - */ |
|
901 | - public function set_vat_class( $value ) { |
|
896 | + * Set the VAT class of the item. |
|
897 | + * |
|
898 | + * @since 1.0.19 |
|
899 | + * @param string $value new class. |
|
900 | + */ |
|
901 | + public function set_vat_class( $value ) { |
|
902 | 902 | $this->set_prop( 'vat_class', $value ); |
903 | 903 | } |
904 | 904 | |
905 | 905 | /** |
906 | - * Set the type of the item. |
|
907 | - * |
|
908 | - * @since 1.0.19 |
|
909 | - * @param string $value new item type. |
|
910 | - * @return string |
|
911 | - */ |
|
912 | - public function set_type( $value ) { |
|
906 | + * Set the type of the item. |
|
907 | + * |
|
908 | + * @since 1.0.19 |
|
909 | + * @param string $value new item type. |
|
910 | + * @return string |
|
911 | + */ |
|
912 | + public function set_type( $value ) { |
|
913 | 913 | |
914 | 914 | if ( empty( $value ) ) { |
915 | 915 | $value = 'custom'; |
@@ -919,132 +919,132 @@ discard block |
||
919 | 919 | } |
920 | 920 | |
921 | 921 | /** |
922 | - * Set the custom id of the item. |
|
923 | - * |
|
924 | - * @since 1.0.19 |
|
925 | - * @param string $value new custom id. |
|
926 | - */ |
|
927 | - public function set_custom_id( $value ) { |
|
922 | + * Set the custom id of the item. |
|
923 | + * |
|
924 | + * @since 1.0.19 |
|
925 | + * @param string $value new custom id. |
|
926 | + */ |
|
927 | + public function set_custom_id( $value ) { |
|
928 | 928 | $this->set_prop( 'custom_id', $value ); |
929 | 929 | } |
930 | 930 | |
931 | 931 | /** |
932 | - * Set the custom name of the item. |
|
933 | - * |
|
934 | - * @since 1.0.19 |
|
935 | - * @param string $value new custom name. |
|
936 | - */ |
|
937 | - public function set_custom_name( $value ) { |
|
932 | + * Set the custom name of the item. |
|
933 | + * |
|
934 | + * @since 1.0.19 |
|
935 | + * @param string $value new custom name. |
|
936 | + */ |
|
937 | + public function set_custom_name( $value ) { |
|
938 | 938 | $this->set_prop( 'custom_name', $value ); |
939 | 939 | } |
940 | 940 | |
941 | 941 | /** |
942 | - * Set the custom singular name of the item. |
|
943 | - * |
|
944 | - * @since 1.0.19 |
|
945 | - * @param string $value new custom singular name. |
|
946 | - */ |
|
947 | - public function set_custom_singular_name( $value ) { |
|
942 | + * Set the custom singular name of the item. |
|
943 | + * |
|
944 | + * @since 1.0.19 |
|
945 | + * @param string $value new custom singular name. |
|
946 | + */ |
|
947 | + public function set_custom_singular_name( $value ) { |
|
948 | 948 | $this->set_prop( 'custom_singular_name', $value ); |
949 | 949 | } |
950 | 950 | |
951 | 951 | /** |
952 | - * Sets if an item is editable.. |
|
953 | - * |
|
954 | - * @since 1.0.19 |
|
955 | - * @param int|bool $value whether or not the item is editable. |
|
956 | - */ |
|
957 | - public function set_is_editable( $value ) { |
|
958 | - $this->set_prop( 'is_editable', (int) $value ); |
|
952 | + * Sets if an item is editable.. |
|
953 | + * |
|
954 | + * @since 1.0.19 |
|
955 | + * @param int|bool $value whether or not the item is editable. |
|
956 | + */ |
|
957 | + public function set_is_editable( $value ) { |
|
958 | + $this->set_prop( 'is_editable', (int) $value ); |
|
959 | 959 | } |
960 | 960 | |
961 | 961 | /** |
962 | - * Sets if dynamic pricing is enabled. |
|
963 | - * |
|
964 | - * @since 1.0.19 |
|
965 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
966 | - */ |
|
967 | - public function set_is_dynamic_pricing( $value ) { |
|
962 | + * Sets if dynamic pricing is enabled. |
|
963 | + * |
|
964 | + * @since 1.0.19 |
|
965 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
966 | + */ |
|
967 | + public function set_is_dynamic_pricing( $value ) { |
|
968 | 968 | $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
969 | 969 | } |
970 | 970 | |
971 | 971 | /** |
972 | - * Sets the minimum price if dynamic pricing is enabled. |
|
973 | - * |
|
974 | - * @since 1.0.19 |
|
975 | - * @param float $value minimum price. |
|
976 | - */ |
|
977 | - public function set_minimum_price( $value ) { |
|
972 | + * Sets the minimum price if dynamic pricing is enabled. |
|
973 | + * |
|
974 | + * @since 1.0.19 |
|
975 | + * @param float $value minimum price. |
|
976 | + */ |
|
977 | + public function set_minimum_price( $value ) { |
|
978 | 978 | $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
979 | 979 | } |
980 | 980 | |
981 | 981 | /** |
982 | - * Sets if this is a recurring item. |
|
983 | - * |
|
984 | - * @since 1.0.19 |
|
985 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
986 | - */ |
|
987 | - public function set_is_recurring( $value ) { |
|
982 | + * Sets if this is a recurring item. |
|
983 | + * |
|
984 | + * @since 1.0.19 |
|
985 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
986 | + */ |
|
987 | + public function set_is_recurring( $value ) { |
|
988 | 988 | $this->set_prop( 'is_recurring', (int) $value ); |
989 | 989 | } |
990 | 990 | |
991 | 991 | /** |
992 | - * Set the recurring period. |
|
993 | - * |
|
994 | - * @since 1.0.19 |
|
995 | - * @param string $value new period. |
|
996 | - */ |
|
997 | - public function set_recurring_period( $value ) { |
|
992 | + * Set the recurring period. |
|
993 | + * |
|
994 | + * @since 1.0.19 |
|
995 | + * @param string $value new period. |
|
996 | + */ |
|
997 | + public function set_recurring_period( $value ) { |
|
998 | 998 | $this->set_prop( 'recurring_period', $value ); |
999 | 999 | } |
1000 | 1000 | |
1001 | 1001 | /** |
1002 | - * Set the recurring interval. |
|
1003 | - * |
|
1004 | - * @since 1.0.19 |
|
1005 | - * @param int $value recurring interval. |
|
1006 | - */ |
|
1007 | - public function set_recurring_interval( $value ) { |
|
1002 | + * Set the recurring interval. |
|
1003 | + * |
|
1004 | + * @since 1.0.19 |
|
1005 | + * @param int $value recurring interval. |
|
1006 | + */ |
|
1007 | + public function set_recurring_interval( $value ) { |
|
1008 | 1008 | return $this->set_prop( 'recurring_interval', (int) $value ); |
1009 | 1009 | } |
1010 | 1010 | |
1011 | 1011 | /** |
1012 | - * Get the recurring limit. |
|
1013 | - * @since 1.0.19 |
|
1014 | - * @param int $value The recurring limit. |
|
1015 | - * @return int |
|
1016 | - */ |
|
1017 | - public function set_recurring_limit( $value ) { |
|
1012 | + * Get the recurring limit. |
|
1013 | + * @since 1.0.19 |
|
1014 | + * @param int $value The recurring limit. |
|
1015 | + * @return int |
|
1016 | + */ |
|
1017 | + public function set_recurring_limit( $value ) { |
|
1018 | 1018 | $this->set_prop( 'recurring_limit', (int) $value ); |
1019 | 1019 | } |
1020 | 1020 | |
1021 | 1021 | /** |
1022 | - * Checks if we have a free trial. |
|
1023 | - * |
|
1024 | - * @since 1.0.19 |
|
1025 | - * @param int|bool $value whether or not it has a free trial. |
|
1026 | - */ |
|
1027 | - public function set_is_free_trial( $value ) { |
|
1022 | + * Checks if we have a free trial. |
|
1023 | + * |
|
1024 | + * @since 1.0.19 |
|
1025 | + * @param int|bool $value whether or not it has a free trial. |
|
1026 | + */ |
|
1027 | + public function set_is_free_trial( $value ) { |
|
1028 | 1028 | $this->set_prop( 'is_free_trial', (int) $value ); |
1029 | 1029 | } |
1030 | 1030 | |
1031 | 1031 | /** |
1032 | - * Set the trial period. |
|
1033 | - * |
|
1034 | - * @since 1.0.19 |
|
1035 | - * @param string $value trial period. |
|
1036 | - */ |
|
1037 | - public function set_trial_period( $value ) { |
|
1032 | + * Set the trial period. |
|
1033 | + * |
|
1034 | + * @since 1.0.19 |
|
1035 | + * @param string $value trial period. |
|
1036 | + */ |
|
1037 | + public function set_trial_period( $value ) { |
|
1038 | 1038 | $this->set_prop( 'trial_period', $value ); |
1039 | 1039 | } |
1040 | 1040 | |
1041 | 1041 | /** |
1042 | - * Set the trial interval. |
|
1043 | - * |
|
1044 | - * @since 1.0.19 |
|
1045 | - * @param int $value trial interval. |
|
1046 | - */ |
|
1047 | - public function set_trial_interval( $value ) { |
|
1042 | + * Set the trial interval. |
|
1043 | + * |
|
1044 | + * @since 1.0.19 |
|
1045 | + * @param int $value trial interval. |
|
1046 | + */ |
|
1047 | + public function set_trial_interval( $value ) { |
|
1048 | 1048 | $this->set_prop( 'trial_interval', $value ); |
1049 | 1049 | } |
1050 | 1050 | |
@@ -1052,17 +1052,17 @@ discard block |
||
1052 | 1052 | * Create an item. For backwards compatibilty. |
1053 | 1053 | * |
1054 | 1054 | * @deprecated |
1055 | - * @return int item id |
|
1055 | + * @return int item id |
|
1056 | 1056 | */ |
1057 | 1057 | public function create( $data = array() ) { |
1058 | 1058 | |
1059 | - // Set the properties. |
|
1060 | - if ( is_array( $data ) ) { |
|
1061 | - $this->set_props( $data ); |
|
1062 | - } |
|
1059 | + // Set the properties. |
|
1060 | + if ( is_array( $data ) ) { |
|
1061 | + $this->set_props( $data ); |
|
1062 | + } |
|
1063 | 1063 | |
1064 | - // Save the item. |
|
1065 | - return $this->save(); |
|
1064 | + // Save the item. |
|
1065 | + return $this->save(); |
|
1066 | 1066 | |
1067 | 1067 | } |
1068 | 1068 | |
@@ -1070,7 +1070,7 @@ discard block |
||
1070 | 1070 | * Updates an item. For backwards compatibilty. |
1071 | 1071 | * |
1072 | 1072 | * @deprecated |
1073 | - * @return int item id |
|
1073 | + * @return int item id |
|
1074 | 1074 | */ |
1075 | 1075 | public function update( $data = array() ) { |
1076 | 1076 | return $this->create( $data ); |
@@ -1086,93 +1086,93 @@ discard block |
||
1086 | 1086 | */ |
1087 | 1087 | |
1088 | 1088 | /** |
1089 | - * Checks whether the item has enabled dynamic pricing. |
|
1090 | - * |
|
1091 | - * @since 1.0.19 |
|
1092 | - * @return bool |
|
1093 | - */ |
|
1094 | - public function user_can_set_their_price() { |
|
1089 | + * Checks whether the item has enabled dynamic pricing. |
|
1090 | + * |
|
1091 | + * @since 1.0.19 |
|
1092 | + * @return bool |
|
1093 | + */ |
|
1094 | + public function user_can_set_their_price() { |
|
1095 | 1095 | return (bool) $this->get_is_dynamic_pricing(); |
1096 | - } |
|
1096 | + } |
|
1097 | 1097 | |
1098 | - /** |
|
1099 | - * Checks whether the item is recurring. |
|
1100 | - * |
|
1101 | - * @since 1.0.19 |
|
1102 | - * @return bool |
|
1103 | - */ |
|
1104 | - public function is_recurring() { |
|
1098 | + /** |
|
1099 | + * Checks whether the item is recurring. |
|
1100 | + * |
|
1101 | + * @since 1.0.19 |
|
1102 | + * @return bool |
|
1103 | + */ |
|
1104 | + public function is_recurring() { |
|
1105 | 1105 | return (bool) $this->get_is_recurring(); |
1106 | 1106 | } |
1107 | 1107 | |
1108 | 1108 | /** |
1109 | - * Checks whether the item has a free trial. |
|
1110 | - * |
|
1111 | - * @since 1.0.19 |
|
1112 | - * @return bool |
|
1113 | - */ |
|
1109 | + * Checks whether the item has a free trial. |
|
1110 | + * |
|
1111 | + * @since 1.0.19 |
|
1112 | + * @return bool |
|
1113 | + */ |
|
1114 | 1114 | public function has_free_trial() { |
1115 | 1115 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
1116 | 1116 | return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
1117 | 1117 | } |
1118 | 1118 | |
1119 | 1119 | /** |
1120 | - * Checks whether the item is free. |
|
1121 | - * |
|
1122 | - * @since 1.0.19 |
|
1123 | - * @return bool |
|
1124 | - */ |
|
1120 | + * Checks whether the item is free. |
|
1121 | + * |
|
1122 | + * @since 1.0.19 |
|
1123 | + * @return bool |
|
1124 | + */ |
|
1125 | 1125 | public function is_free() { |
1126 | 1126 | $is_free = $this->get_price() == 0; |
1127 | 1127 | return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
1128 | 1128 | } |
1129 | 1129 | |
1130 | 1130 | /** |
1131 | - * Checks the item status against a passed in status. |
|
1132 | - * |
|
1133 | - * @param array|string $status Status to check. |
|
1134 | - * @return bool |
|
1135 | - */ |
|
1136 | - public function has_status( $status ) { |
|
1137 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1138 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1131 | + * Checks the item status against a passed in status. |
|
1132 | + * |
|
1133 | + * @param array|string $status Status to check. |
|
1134 | + * @return bool |
|
1135 | + */ |
|
1136 | + public function has_status( $status ) { |
|
1137 | + $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1138 | + return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1139 | 1139 | } |
1140 | 1140 | |
1141 | 1141 | /** |
1142 | - * Checks the item type against a passed in types. |
|
1143 | - * |
|
1144 | - * @param array|string $type Type to check. |
|
1145 | - * @return bool |
|
1146 | - */ |
|
1147 | - public function is_type( $type ) { |
|
1148 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1149 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1150 | - } |
|
1142 | + * Checks the item type against a passed in types. |
|
1143 | + * |
|
1144 | + * @param array|string $type Type to check. |
|
1145 | + * @return bool |
|
1146 | + */ |
|
1147 | + public function is_type( $type ) { |
|
1148 | + $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1149 | + return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1150 | + } |
|
1151 | 1151 | |
1152 | 1152 | /** |
1153 | - * Checks whether the item is editable. |
|
1154 | - * |
|
1155 | - * @since 1.0.19 |
|
1156 | - * @return bool |
|
1157 | - */ |
|
1153 | + * Checks whether the item is editable. |
|
1154 | + * |
|
1155 | + * @since 1.0.19 |
|
1156 | + * @return bool |
|
1157 | + */ |
|
1158 | 1158 | public function is_editable() { |
1159 | 1159 | $is_editable = $this->get_is_editable(); |
1160 | 1160 | return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
1161 | - } |
|
1161 | + } |
|
1162 | 1162 | |
1163 | - /** |
|
1164 | - * Returns an array of cart fees. |
|
1165 | - */ |
|
1166 | - public function get_fees() { |
|
1163 | + /** |
|
1164 | + * Returns an array of cart fees. |
|
1165 | + */ |
|
1166 | + public function get_fees() { |
|
1167 | 1167 | return array(); |
1168 | 1168 | } |
1169 | 1169 | |
1170 | 1170 | /** |
1171 | - * Checks whether the item is purchasable. |
|
1172 | - * |
|
1173 | - * @since 1.0.19 |
|
1174 | - * @return bool |
|
1175 | - */ |
|
1171 | + * Checks whether the item is purchasable. |
|
1172 | + * |
|
1173 | + * @since 1.0.19 |
|
1174 | + * @return bool |
|
1175 | + */ |
|
1176 | 1176 | public function can_purchase() { |
1177 | 1177 | $can_purchase = $this->exists(); |
1178 | 1178 | |
@@ -1184,11 +1184,11 @@ discard block |
||
1184 | 1184 | } |
1185 | 1185 | |
1186 | 1186 | /** |
1187 | - * Checks whether the item supports dynamic pricing. |
|
1188 | - * |
|
1189 | - * @since 1.0.19 |
|
1190 | - * @return bool |
|
1191 | - */ |
|
1187 | + * Checks whether the item supports dynamic pricing. |
|
1188 | + * |
|
1189 | + * @since 1.0.19 |
|
1190 | + * @return bool |
|
1191 | + */ |
|
1192 | 1192 | public function supports_dynamic_pricing() { |
1193 | 1193 | return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
1194 | 1194 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
7 | - exit; |
|
7 | + exit; |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -14,228 +14,228 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class GetPaid_Item_Data_Store extends GetPaid_Data_Store_WP { |
16 | 16 | |
17 | - /** |
|
18 | - * Data stored in meta keys, but not considered "meta" for an item. |
|
19 | - * |
|
20 | - * @since 1.0.19 |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $internal_meta_keys = array( |
|
24 | - '_wpinv_price', |
|
25 | - '_wpinv_vat_rule', |
|
26 | - '_wpinv_vat_class', |
|
27 | - '_wpinv_type', |
|
28 | - '_wpinv_custom_id', |
|
29 | - '_wpinv_custom_name', |
|
30 | - '_wpinv_custom_singular_name', |
|
31 | - '_wpinv_editable', |
|
32 | - '_wpinv_dynamic_pricing', |
|
33 | - '_minimum_price', |
|
34 | - '_wpinv_is_recurring', |
|
35 | - '_wpinv_recurring_period', |
|
36 | - '_wpinv_recurring_interval', |
|
37 | - '_wpinv_recurring_limit', |
|
38 | - '_wpinv_free_trial', |
|
39 | - '_wpinv_trial_period', |
|
40 | - '_wpinv_trial_interval' |
|
41 | - ); |
|
42 | - |
|
43 | - /** |
|
44 | - * A map of meta keys to data props. |
|
45 | - * |
|
46 | - * @since 1.0.19 |
|
47 | - * |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - protected $meta_key_to_props = array( |
|
51 | - '_wpinv_price' => 'price', |
|
52 | - '_wpinv_vat_rule' => 'vat_rule', |
|
53 | - '_wpinv_vat_class' => 'vat_class', |
|
54 | - '_wpinv_type' => 'type', |
|
55 | - '_wpinv_custom_id' => 'custom_id', |
|
56 | - '_wpinv_custom_name' => 'custom_name', |
|
57 | - '_wpinv_custom_singular_name' => 'custom_singular_name', |
|
58 | - '_wpinv_editable' => 'is_editable', |
|
59 | - '_wpinv_dynamic_pricing' => 'is_dynamic_pricing', |
|
60 | - '_minimum_price' => 'minimum_price', |
|
61 | - '_wpinv_custom_name' => 'custom_name', |
|
62 | - '_wpinv_is_recurring' => 'is_recurring', |
|
63 | - '_wpinv_recurring_period' => 'recurring_period', |
|
64 | - '_wpinv_recurring_interval' => 'recurring_interval', |
|
65 | - '_wpinv_recurring_limit' => 'recurring_limit', |
|
66 | - '_wpinv_free_trial' => 'is_free_trial', |
|
67 | - '_wpinv_trial_period' => 'trial_period', |
|
68 | - '_wpinv_trial_interval' => 'trial_interval', |
|
69 | - '_wpinv_version' => 'version', |
|
70 | - ); |
|
71 | - |
|
72 | - /* |
|
17 | + /** |
|
18 | + * Data stored in meta keys, but not considered "meta" for an item. |
|
19 | + * |
|
20 | + * @since 1.0.19 |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $internal_meta_keys = array( |
|
24 | + '_wpinv_price', |
|
25 | + '_wpinv_vat_rule', |
|
26 | + '_wpinv_vat_class', |
|
27 | + '_wpinv_type', |
|
28 | + '_wpinv_custom_id', |
|
29 | + '_wpinv_custom_name', |
|
30 | + '_wpinv_custom_singular_name', |
|
31 | + '_wpinv_editable', |
|
32 | + '_wpinv_dynamic_pricing', |
|
33 | + '_minimum_price', |
|
34 | + '_wpinv_is_recurring', |
|
35 | + '_wpinv_recurring_period', |
|
36 | + '_wpinv_recurring_interval', |
|
37 | + '_wpinv_recurring_limit', |
|
38 | + '_wpinv_free_trial', |
|
39 | + '_wpinv_trial_period', |
|
40 | + '_wpinv_trial_interval' |
|
41 | + ); |
|
42 | + |
|
43 | + /** |
|
44 | + * A map of meta keys to data props. |
|
45 | + * |
|
46 | + * @since 1.0.19 |
|
47 | + * |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + protected $meta_key_to_props = array( |
|
51 | + '_wpinv_price' => 'price', |
|
52 | + '_wpinv_vat_rule' => 'vat_rule', |
|
53 | + '_wpinv_vat_class' => 'vat_class', |
|
54 | + '_wpinv_type' => 'type', |
|
55 | + '_wpinv_custom_id' => 'custom_id', |
|
56 | + '_wpinv_custom_name' => 'custom_name', |
|
57 | + '_wpinv_custom_singular_name' => 'custom_singular_name', |
|
58 | + '_wpinv_editable' => 'is_editable', |
|
59 | + '_wpinv_dynamic_pricing' => 'is_dynamic_pricing', |
|
60 | + '_minimum_price' => 'minimum_price', |
|
61 | + '_wpinv_custom_name' => 'custom_name', |
|
62 | + '_wpinv_is_recurring' => 'is_recurring', |
|
63 | + '_wpinv_recurring_period' => 'recurring_period', |
|
64 | + '_wpinv_recurring_interval' => 'recurring_interval', |
|
65 | + '_wpinv_recurring_limit' => 'recurring_limit', |
|
66 | + '_wpinv_free_trial' => 'is_free_trial', |
|
67 | + '_wpinv_trial_period' => 'trial_period', |
|
68 | + '_wpinv_trial_interval' => 'trial_interval', |
|
69 | + '_wpinv_version' => 'version', |
|
70 | + ); |
|
71 | + |
|
72 | + /* |
|
73 | 73 | |-------------------------------------------------------------------------- |
74 | 74 | | CRUD Methods |
75 | 75 | |-------------------------------------------------------------------------- |
76 | 76 | */ |
77 | 77 | |
78 | - /** |
|
79 | - * Method to create a new item in the database. |
|
80 | - * |
|
81 | - * @param WPInv_Item $item Item object. |
|
82 | - */ |
|
83 | - public function create( &$item ) { |
|
84 | - $item->set_version( WPINV_VERSION ); |
|
85 | - $item->set_date_created( current_time('mysql') ); |
|
86 | - |
|
87 | - // Create a new post. |
|
88 | - $id = wp_insert_post( |
|
89 | - apply_filters( |
|
90 | - 'getpaid_new_item_data', |
|
91 | - array( |
|
92 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
93 | - 'post_type' => 'wpi_item', |
|
94 | - 'post_status' => $this->get_post_status( $item ), |
|
95 | - 'ping_status' => 'closed', |
|
96 | - 'post_author' => $item->get_author( 'edit' ), |
|
97 | - 'post_title' => $item->get_name( 'edit' ), |
|
98 | - 'post_parent' => 0, |
|
99 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
100 | - ) |
|
101 | - ), |
|
102 | - true |
|
103 | - ); |
|
104 | - |
|
105 | - if ( $id && ! is_wp_error( $id ) ) { |
|
106 | - $item->set_id( $id ); |
|
107 | - $this->update_post_meta( $item ); |
|
108 | - $item->save_meta_data(); |
|
109 | - $item->apply_changes(); |
|
110 | - $this->clear_caches( $item ); |
|
111 | - do_action( 'getpaid_new_item', $item ); |
|
112 | - return true; |
|
113 | - } |
|
114 | - |
|
115 | - if ( is_wp_error( $id ) ) { |
|
116 | - $item->last_error = $id->get_error_message(); |
|
117 | - } |
|
78 | + /** |
|
79 | + * Method to create a new item in the database. |
|
80 | + * |
|
81 | + * @param WPInv_Item $item Item object. |
|
82 | + */ |
|
83 | + public function create( &$item ) { |
|
84 | + $item->set_version( WPINV_VERSION ); |
|
85 | + $item->set_date_created( current_time('mysql') ); |
|
86 | + |
|
87 | + // Create a new post. |
|
88 | + $id = wp_insert_post( |
|
89 | + apply_filters( |
|
90 | + 'getpaid_new_item_data', |
|
91 | + array( |
|
92 | + 'post_date' => $item->get_date_created( 'edit' ), |
|
93 | + 'post_type' => 'wpi_item', |
|
94 | + 'post_status' => $this->get_post_status( $item ), |
|
95 | + 'ping_status' => 'closed', |
|
96 | + 'post_author' => $item->get_author( 'edit' ), |
|
97 | + 'post_title' => $item->get_name( 'edit' ), |
|
98 | + 'post_parent' => 0, |
|
99 | + 'post_excerpt' => $item->get_description( 'edit' ), |
|
100 | + ) |
|
101 | + ), |
|
102 | + true |
|
103 | + ); |
|
104 | + |
|
105 | + if ( $id && ! is_wp_error( $id ) ) { |
|
106 | + $item->set_id( $id ); |
|
107 | + $this->update_post_meta( $item ); |
|
108 | + $item->save_meta_data(); |
|
109 | + $item->apply_changes(); |
|
110 | + $this->clear_caches( $item ); |
|
111 | + do_action( 'getpaid_new_item', $item ); |
|
112 | + return true; |
|
113 | + } |
|
114 | + |
|
115 | + if ( is_wp_error( $id ) ) { |
|
116 | + $item->last_error = $id->get_error_message(); |
|
117 | + } |
|
118 | 118 | |
119 | - return false; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Method to read an item from the database. |
|
124 | - * |
|
125 | - * @param WPInv_Item $item Item object. |
|
126 | - * |
|
127 | - */ |
|
128 | - public function read( &$item ) { |
|
129 | - |
|
130 | - $item->set_defaults(); |
|
131 | - $item_object = get_post( $item->get_id() ); |
|
132 | - |
|
133 | - if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
134 | - $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
135 | - $item->set_id( 0 ); |
|
136 | - return false; |
|
137 | - } |
|
138 | - |
|
139 | - $item->set_props( |
|
140 | - array( |
|
141 | - 'parent_id' => $item_object->post_parent, |
|
142 | - 'date_created' => 0 < $item_object->post_date ? $item_object->post_date : null, |
|
143 | - 'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null, |
|
144 | - 'status' => $item_object->post_status, |
|
145 | - 'name' => $item_object->post_title, |
|
146 | - 'description' => $item_object->post_excerpt, |
|
147 | - 'author' => $item_object->post_author, |
|
148 | - ) |
|
149 | - ); |
|
150 | - |
|
151 | - $this->read_object_data( $item, $item_object ); |
|
152 | - $item->read_meta_data(); |
|
153 | - $item->set_object_read( true ); |
|
154 | - do_action( 'getpaid_read_item', $item ); |
|
155 | - |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Method to update an item in the database. |
|
160 | - * |
|
161 | - * @param WPInv_Item $item Item object. |
|
162 | - */ |
|
163 | - public function update( &$item ) { |
|
164 | - $item->save_meta_data(); |
|
165 | - $item->set_version( WPINV_VERSION ); |
|
166 | - |
|
167 | - if ( null === $item->get_date_created( 'edit' ) ) { |
|
168 | - $item->set_date_created( current_time('mysql') ); |
|
169 | - } |
|
170 | - |
|
171 | - // Grab the current status so we can compare. |
|
172 | - $previous_status = get_post_status( $item->get_id() ); |
|
173 | - |
|
174 | - $changes = $item->get_changes(); |
|
175 | - |
|
176 | - // Only update the post when the post data changes. |
|
177 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
178 | - $post_data = array( |
|
179 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
180 | - 'post_status' => $item->get_status( 'edit' ), |
|
181 | - 'post_parent' => $item->get_parent_id( 'edit' ), |
|
182 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
183 | - 'post_modified' => $item->get_date_modified( 'edit' ), |
|
184 | - 'post_title' => $item->get_name( 'edit' ), |
|
185 | - 'post_author' => $item->get_author( 'edit' ), |
|
186 | - ); |
|
187 | - |
|
188 | - /** |
|
189 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
190 | - * to update data, since wp_update_post spawns more calls to the |
|
191 | - * save_post action. |
|
192 | - * |
|
193 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
194 | - * or an update purely from CRUD. |
|
195 | - */ |
|
196 | - if ( doing_action( 'save_post' ) ) { |
|
197 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
198 | - clean_post_cache( $item->get_id() ); |
|
199 | - } else { |
|
200 | - wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
201 | - } |
|
202 | - $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
203 | - } |
|
204 | - $this->update_post_meta( $item ); |
|
205 | - $item->apply_changes(); |
|
206 | - $this->clear_caches( $item ); |
|
207 | - |
|
208 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
209 | - $new_status = $item->get_status( 'edit' ); |
|
210 | - |
|
211 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
212 | - do_action( 'getpaid_new_item', $item ); |
|
213 | - } else { |
|
214 | - do_action( 'getpaid_update_item', $item ); |
|
215 | - } |
|
216 | - |
|
217 | - } |
|
218 | - |
|
219 | - /* |
|
119 | + return false; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Method to read an item from the database. |
|
124 | + * |
|
125 | + * @param WPInv_Item $item Item object. |
|
126 | + * |
|
127 | + */ |
|
128 | + public function read( &$item ) { |
|
129 | + |
|
130 | + $item->set_defaults(); |
|
131 | + $item_object = get_post( $item->get_id() ); |
|
132 | + |
|
133 | + if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
134 | + $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
135 | + $item->set_id( 0 ); |
|
136 | + return false; |
|
137 | + } |
|
138 | + |
|
139 | + $item->set_props( |
|
140 | + array( |
|
141 | + 'parent_id' => $item_object->post_parent, |
|
142 | + 'date_created' => 0 < $item_object->post_date ? $item_object->post_date : null, |
|
143 | + 'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null, |
|
144 | + 'status' => $item_object->post_status, |
|
145 | + 'name' => $item_object->post_title, |
|
146 | + 'description' => $item_object->post_excerpt, |
|
147 | + 'author' => $item_object->post_author, |
|
148 | + ) |
|
149 | + ); |
|
150 | + |
|
151 | + $this->read_object_data( $item, $item_object ); |
|
152 | + $item->read_meta_data(); |
|
153 | + $item->set_object_read( true ); |
|
154 | + do_action( 'getpaid_read_item', $item ); |
|
155 | + |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Method to update an item in the database. |
|
160 | + * |
|
161 | + * @param WPInv_Item $item Item object. |
|
162 | + */ |
|
163 | + public function update( &$item ) { |
|
164 | + $item->save_meta_data(); |
|
165 | + $item->set_version( WPINV_VERSION ); |
|
166 | + |
|
167 | + if ( null === $item->get_date_created( 'edit' ) ) { |
|
168 | + $item->set_date_created( current_time('mysql') ); |
|
169 | + } |
|
170 | + |
|
171 | + // Grab the current status so we can compare. |
|
172 | + $previous_status = get_post_status( $item->get_id() ); |
|
173 | + |
|
174 | + $changes = $item->get_changes(); |
|
175 | + |
|
176 | + // Only update the post when the post data changes. |
|
177 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
178 | + $post_data = array( |
|
179 | + 'post_date' => $item->get_date_created( 'edit' ), |
|
180 | + 'post_status' => $item->get_status( 'edit' ), |
|
181 | + 'post_parent' => $item->get_parent_id( 'edit' ), |
|
182 | + 'post_excerpt' => $item->get_description( 'edit' ), |
|
183 | + 'post_modified' => $item->get_date_modified( 'edit' ), |
|
184 | + 'post_title' => $item->get_name( 'edit' ), |
|
185 | + 'post_author' => $item->get_author( 'edit' ), |
|
186 | + ); |
|
187 | + |
|
188 | + /** |
|
189 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
190 | + * to update data, since wp_update_post spawns more calls to the |
|
191 | + * save_post action. |
|
192 | + * |
|
193 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
194 | + * or an update purely from CRUD. |
|
195 | + */ |
|
196 | + if ( doing_action( 'save_post' ) ) { |
|
197 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
198 | + clean_post_cache( $item->get_id() ); |
|
199 | + } else { |
|
200 | + wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
201 | + } |
|
202 | + $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
203 | + } |
|
204 | + $this->update_post_meta( $item ); |
|
205 | + $item->apply_changes(); |
|
206 | + $this->clear_caches( $item ); |
|
207 | + |
|
208 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
209 | + $new_status = $item->get_status( 'edit' ); |
|
210 | + |
|
211 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
212 | + do_action( 'getpaid_new_item', $item ); |
|
213 | + } else { |
|
214 | + do_action( 'getpaid_update_item', $item ); |
|
215 | + } |
|
216 | + |
|
217 | + } |
|
218 | + |
|
219 | + /* |
|
220 | 220 | |-------------------------------------------------------------------------- |
221 | 221 | | Additional Methods |
222 | 222 | |-------------------------------------------------------------------------- |
223 | 223 | */ |
224 | 224 | |
225 | - /** |
|
226 | - * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class. |
|
227 | - * |
|
228 | - * @param WPInv_Item $item WPInv_Item object. |
|
229 | - * @since 1.0.19 |
|
230 | - */ |
|
231 | - protected function update_post_meta( &$item ) { |
|
225 | + /** |
|
226 | + * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class. |
|
227 | + * |
|
228 | + * @param WPInv_Item $item WPInv_Item object. |
|
229 | + * @since 1.0.19 |
|
230 | + */ |
|
231 | + protected function update_post_meta( &$item ) { |
|
232 | 232 | |
233 | - // Ensure that we have a custom id. |
|
233 | + // Ensure that we have a custom id. |
|
234 | 234 | if ( ! $item->get_custom_id() ) { |
235 | 235 | $item->set_custom_id( $item->get_id() ); |
236 | - } |
|
236 | + } |
|
237 | 237 | |
238 | - parent::update_post_meta( $item ); |
|
239 | - } |
|
238 | + parent::update_post_meta( $item ); |
|
239 | + } |
|
240 | 240 | |
241 | 241 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,55 +10,55 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form extends GetPaid_Data { |
11 | 11 | |
12 | 12 | /** |
13 | - * Which data store to load. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
13 | + * Which data store to load. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | 17 | protected $data_store_name = 'payment_form'; |
18 | 18 | |
19 | 19 | /** |
20 | - * This is the name of this object type. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $object_type = 'payment_form'; |
|
20 | + * This is the name of this object type. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $object_type = 'payment_form'; |
|
25 | 25 | |
26 | 26 | /** |
27 | - * Form Data array. This is the core form data exposed in APIs. |
|
28 | - * |
|
29 | - * @since 1.0.19 |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $data = array( |
|
33 | - 'status' => 'draft', |
|
34 | - 'version' => '', |
|
35 | - 'date_created' => null, |
|
27 | + * Form Data array. This is the core form data exposed in APIs. |
|
28 | + * |
|
29 | + * @since 1.0.19 |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $data = array( |
|
33 | + 'status' => 'draft', |
|
34 | + 'version' => '', |
|
35 | + 'date_created' => null, |
|
36 | 36 | 'date_modified' => null, |
37 | 37 | 'name' => '', |
38 | 38 | 'author' => 1, |
39 | 39 | 'elements' => null, |
40 | - 'items' => null, |
|
41 | - 'earned' => 0, |
|
42 | - 'refunded' => 0, |
|
43 | - 'cancelled' => 0, |
|
44 | - 'failed' => 0, |
|
45 | - ); |
|
46 | - |
|
47 | - /** |
|
48 | - * Stores meta in cache for future reads. |
|
49 | - * |
|
50 | - * A group must be set to to enable caching. |
|
51 | - * |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - protected $cache_group = 'getpaid_forms'; |
|
55 | - |
|
56 | - /** |
|
57 | - * Stores a reference to the invoice if the form is for an invoice.. |
|
58 | - * |
|
59 | - * @var WPInv_Invoice |
|
60 | - */ |
|
61 | - public $invoice = 0; |
|
40 | + 'items' => null, |
|
41 | + 'earned' => 0, |
|
42 | + 'refunded' => 0, |
|
43 | + 'cancelled' => 0, |
|
44 | + 'failed' => 0, |
|
45 | + ); |
|
46 | + |
|
47 | + /** |
|
48 | + * Stores meta in cache for future reads. |
|
49 | + * |
|
50 | + * A group must be set to to enable caching. |
|
51 | + * |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + protected $cache_group = 'getpaid_forms'; |
|
55 | + |
|
56 | + /** |
|
57 | + * Stores a reference to the invoice if the form is for an invoice.. |
|
58 | + * |
|
59 | + * @var WPInv_Invoice |
|
60 | + */ |
|
61 | + public $invoice = 0; |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Stores a reference to the original WP_Post object |
@@ -68,35 +68,35 @@ discard block |
||
68 | 68 | protected $post = null; |
69 | 69 | |
70 | 70 | /** |
71 | - * Get the form if ID is passed, otherwise the form is new and empty. |
|
72 | - * |
|
73 | - * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
74 | - */ |
|
75 | - public function __construct( $form = 0 ) { |
|
76 | - parent::__construct( $form ); |
|
71 | + * Get the form if ID is passed, otherwise the form is new and empty. |
|
72 | + * |
|
73 | + * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
74 | + */ |
|
75 | + public function __construct( $form = 0 ) { |
|
76 | + parent::__construct( $form ); |
|
77 | 77 | |
78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | - $this->set_id( $form ); |
|
80 | - } elseif ( $form instanceof self ) { |
|
78 | + if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | + $this->set_id( $form ); |
|
80 | + } elseif ( $form instanceof self ) { |
|
81 | 81 | |
82 | - $this->set_id( $form->get_id() ); |
|
83 | - $this->invoice = $form->invoice; |
|
82 | + $this->set_id( $form->get_id() ); |
|
83 | + $this->invoice = $form->invoice; |
|
84 | 84 | |
85 | - } elseif ( ! empty( $form->ID ) ) { |
|
86 | - $this->set_id( $form->ID ); |
|
87 | - } else { |
|
88 | - $this->set_object_read( true ); |
|
89 | - } |
|
85 | + } elseif ( ! empty( $form->ID ) ) { |
|
86 | + $this->set_id( $form->ID ); |
|
87 | + } else { |
|
88 | + $this->set_object_read( true ); |
|
89 | + } |
|
90 | 90 | |
91 | 91 | // Load the datastore. |
92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
92 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
93 | 93 | |
94 | - if ( $this->get_id() > 0 ) { |
|
94 | + if ( $this->get_id() > 0 ) { |
|
95 | 95 | $this->post = get_post( $this->get_id() ); |
96 | - $this->data_store->read( $this ); |
|
96 | + $this->data_store->read( $this ); |
|
97 | 97 | } |
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | 101 | /* |
102 | 102 | |-------------------------------------------------------------------------- |
@@ -114,358 +114,358 @@ discard block |
||
114 | 114 | */ |
115 | 115 | |
116 | 116 | /** |
117 | - * Get plugin version when the form was created. |
|
118 | - * |
|
119 | - * @since 1.0.19 |
|
120 | - * @param string $context View or edit context. |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function get_version( $context = 'view' ) { |
|
124 | - return $this->get_prop( 'version', $context ); |
|
117 | + * Get plugin version when the form was created. |
|
118 | + * |
|
119 | + * @since 1.0.19 |
|
120 | + * @param string $context View or edit context. |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function get_version( $context = 'view' ) { |
|
124 | + return $this->get_prop( 'version', $context ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | - * Get date when the form was created. |
|
129 | - * |
|
130 | - * @since 1.0.19 |
|
131 | - * @param string $context View or edit context. |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function get_date_created( $context = 'view' ) { |
|
135 | - return $this->get_prop( 'date_created', $context ); |
|
128 | + * Get date when the form was created. |
|
129 | + * |
|
130 | + * @since 1.0.19 |
|
131 | + * @param string $context View or edit context. |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function get_date_created( $context = 'view' ) { |
|
135 | + return $this->get_prop( 'date_created', $context ); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | - * Get GMT date when the form was created. |
|
140 | - * |
|
141 | - * @since 1.0.19 |
|
142 | - * @param string $context View or edit context. |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
139 | + * Get GMT date when the form was created. |
|
140 | + * |
|
141 | + * @since 1.0.19 |
|
142 | + * @param string $context View or edit context. |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + public function get_date_created_gmt( $context = 'view' ) { |
|
146 | 146 | $date = $this->get_date_created( $context ); |
147 | 147 | |
148 | 148 | if ( $date ) { |
149 | 149 | $date = get_gmt_from_date( $date ); |
150 | 150 | } |
151 | - return $date; |
|
151 | + return $date; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | - * Get date when the form was last modified. |
|
156 | - * |
|
157 | - * @since 1.0.19 |
|
158 | - * @param string $context View or edit context. |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public function get_date_modified( $context = 'view' ) { |
|
162 | - return $this->get_prop( 'date_modified', $context ); |
|
155 | + * Get date when the form was last modified. |
|
156 | + * |
|
157 | + * @since 1.0.19 |
|
158 | + * @param string $context View or edit context. |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public function get_date_modified( $context = 'view' ) { |
|
162 | + return $this->get_prop( 'date_modified', $context ); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | - * Get GMT date when the form was last modified. |
|
167 | - * |
|
168 | - * @since 1.0.19 |
|
169 | - * @param string $context View or edit context. |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
166 | + * Get GMT date when the form was last modified. |
|
167 | + * |
|
168 | + * @since 1.0.19 |
|
169 | + * @param string $context View or edit context. |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
173 | 173 | $date = $this->get_date_modified( $context ); |
174 | 174 | |
175 | 175 | if ( $date ) { |
176 | 176 | $date = get_gmt_from_date( $date ); |
177 | 177 | } |
178 | - return $date; |
|
178 | + return $date; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
182 | - * Get the form name. |
|
183 | - * |
|
184 | - * @since 1.0.19 |
|
185 | - * @param string $context View or edit context. |
|
186 | - * @return string |
|
187 | - */ |
|
188 | - public function get_name( $context = 'view' ) { |
|
189 | - return $this->get_prop( 'name', $context ); |
|
182 | + * Get the form name. |
|
183 | + * |
|
184 | + * @since 1.0.19 |
|
185 | + * @param string $context View or edit context. |
|
186 | + * @return string |
|
187 | + */ |
|
188 | + public function get_name( $context = 'view' ) { |
|
189 | + return $this->get_prop( 'name', $context ); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
193 | - * Alias of self::get_name(). |
|
194 | - * |
|
195 | - * @since 1.0.19 |
|
196 | - * @param string $context View or edit context. |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - public function get_title( $context = 'view' ) { |
|
200 | - return $this->get_name( $context ); |
|
201 | - } |
|
193 | + * Alias of self::get_name(). |
|
194 | + * |
|
195 | + * @since 1.0.19 |
|
196 | + * @param string $context View or edit context. |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + public function get_title( $context = 'view' ) { |
|
200 | + return $this->get_name( $context ); |
|
201 | + } |
|
202 | 202 | |
203 | 203 | /** |
204 | - * Get the owner of the form. |
|
205 | - * |
|
206 | - * @since 1.0.19 |
|
207 | - * @param string $context View or edit context. |
|
208 | - * @return int |
|
209 | - */ |
|
210 | - public function get_author( $context = 'view' ) { |
|
211 | - return (int) $this->get_prop( 'author', $context ); |
|
204 | + * Get the owner of the form. |
|
205 | + * |
|
206 | + * @since 1.0.19 |
|
207 | + * @param string $context View or edit context. |
|
208 | + * @return int |
|
209 | + */ |
|
210 | + public function get_author( $context = 'view' ) { |
|
211 | + return (int) $this->get_prop( 'author', $context ); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
215 | - * Get the elements that make up the form. |
|
216 | - * |
|
217 | - * @since 1.0.19 |
|
218 | - * @param string $context View or edit context. |
|
219 | - * @return array |
|
220 | - */ |
|
221 | - public function get_elements( $context = 'view' ) { |
|
222 | - $elements = $this->get_prop( 'elements', $context ); |
|
215 | + * Get the elements that make up the form. |
|
216 | + * |
|
217 | + * @since 1.0.19 |
|
218 | + * @param string $context View or edit context. |
|
219 | + * @return array |
|
220 | + */ |
|
221 | + public function get_elements( $context = 'view' ) { |
|
222 | + $elements = $this->get_prop( 'elements', $context ); |
|
223 | 223 | |
224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
224 | + if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
225 | 225 | return wpinv_get_data( 'sample-payment-form' ); |
226 | - } |
|
226 | + } |
|
227 | 227 | |
228 | - // Ensure that all required elements exist. |
|
229 | - $_elements = array(); |
|
230 | - foreach ( $elements as $element ) { |
|
228 | + // Ensure that all required elements exist. |
|
229 | + $_elements = array(); |
|
230 | + foreach ( $elements as $element ) { |
|
231 | 231 | |
232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
232 | + if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
233 | 233 | |
234 | - $_elements[] = array( |
|
235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
236 | - 'id' => 'gtscicd', |
|
237 | - 'name' => 'gtscicd', |
|
238 | - 'type' => 'gateway_select', |
|
239 | - 'premade' => true |
|
234 | + $_elements[] = array( |
|
235 | + 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
236 | + 'id' => 'gtscicd', |
|
237 | + 'name' => 'gtscicd', |
|
238 | + 'type' => 'gateway_select', |
|
239 | + 'premade' => true |
|
240 | 240 | |
241 | - ); |
|
241 | + ); |
|
242 | 242 | |
243 | - } |
|
243 | + } |
|
244 | 244 | |
245 | - $_elements[] = $element; |
|
245 | + $_elements[] = $element; |
|
246 | 246 | |
247 | - } |
|
247 | + } |
|
248 | 248 | |
249 | 249 | return $_elements; |
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Get the items sold via the form. |
|
254 | - * |
|
255 | - * @since 1.0.19 |
|
256 | - * @param string $context View or edit context. |
|
257 | - * @param string $return objects or arrays. |
|
258 | - * @return GetPaid_Form_Item[] |
|
259 | - */ |
|
260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | - $items = $this->get_prop( 'items', $context ); |
|
262 | - |
|
263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Get the items sold via the form. |
|
254 | + * |
|
255 | + * @since 1.0.19 |
|
256 | + * @param string $context View or edit context. |
|
257 | + * @param string $return objects or arrays. |
|
258 | + * @return GetPaid_Form_Item[] |
|
259 | + */ |
|
260 | + public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | + $items = $this->get_prop( 'items', $context ); |
|
262 | + |
|
263 | + if ( empty( $items ) || ! is_array( $items ) ) { |
|
264 | 264 | $items = wpinv_get_data( 'sample-payment-form-items' ); |
265 | - } |
|
265 | + } |
|
266 | + |
|
267 | + // Convert the items. |
|
268 | + $prepared = array(); |
|
266 | 269 | |
267 | - // Convert the items. |
|
268 | - $prepared = array(); |
|
270 | + foreach ( $items as $key => $value ) { |
|
269 | 271 | |
270 | - foreach ( $items as $key => $value ) { |
|
272 | + // Form items. |
|
273 | + if ( $value instanceof GetPaid_Form_Item ) { |
|
271 | 274 | |
272 | - // Form items. |
|
273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
275 | + if ( $value->can_purchase() ) { |
|
276 | + $prepared[] = $value; |
|
277 | + } |
|
274 | 278 | |
275 | - if ( $value->can_purchase() ) { |
|
276 | - $prepared[] = $value; |
|
277 | - } |
|
279 | + continue; |
|
278 | 280 | |
279 | - continue; |
|
281 | + } |
|
280 | 282 | |
281 | - } |
|
283 | + // $item_id => $quantity (buy buttons) |
|
284 | + if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | + $item = new GetPaid_Form_Item( $key ); |
|
282 | 286 | |
283 | - // $item_id => $quantity (buy buttons) |
|
284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | - $item = new GetPaid_Form_Item( $key ); |
|
287 | + if ( $item->can_purchase() ) { |
|
286 | 288 | |
287 | - if ( $item->can_purchase() ) { |
|
289 | + $value = (float) $value; |
|
290 | + $item->set_quantity( $value ); |
|
291 | + if ( 0 == $value ) { |
|
292 | + $item->set_quantity( 1 ); |
|
293 | + $item->set_allow_quantities( true ); |
|
294 | + } |
|
288 | 295 | |
289 | - $value = (float) $value; |
|
290 | - $item->set_quantity( $value ); |
|
291 | - if ( 0 == $value ) { |
|
292 | - $item->set_quantity( 1 ); |
|
293 | - $item->set_allow_quantities( true ); |
|
294 | - } |
|
296 | + $prepared[] = $item; |
|
297 | + } |
|
295 | 298 | |
296 | - $prepared[] = $item; |
|
297 | - } |
|
299 | + continue; |
|
300 | + } |
|
298 | 301 | |
299 | - continue; |
|
300 | - } |
|
302 | + // Items saved via payment forms editor. |
|
303 | + if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
301 | 304 | |
302 | - // Items saved via payment forms editor. |
|
303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
305 | + $item = new GetPaid_Form_Item( $value['id'] ); |
|
304 | 306 | |
305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
307 | + if ( ! $item->can_purchase() ) { |
|
308 | + continue; |
|
309 | + } |
|
306 | 310 | |
307 | - if ( ! $item->can_purchase() ) { |
|
308 | - continue; |
|
309 | - } |
|
311 | + // Sub-total (Cart items). |
|
312 | + if ( isset( $value['subtotal'] ) ) { |
|
313 | + $item->set_price( $value['subtotal'] ); |
|
314 | + } |
|
310 | 315 | |
311 | - // Sub-total (Cart items). |
|
312 | - if ( isset( $value['subtotal'] ) ) { |
|
313 | - $item->set_price( $value['subtotal'] ); |
|
314 | - } |
|
316 | + if ( isset( $value['quantity'] ) ) { |
|
317 | + $item->set_quantity( $value['quantity'] ); |
|
318 | + } |
|
315 | 319 | |
316 | - if ( isset( $value['quantity'] ) ) { |
|
317 | - $item->set_quantity( $value['quantity'] ); |
|
318 | - } |
|
320 | + if ( isset( $value['allow_quantities'] ) ) { |
|
321 | + $item->set_allow_quantities( $value['allow_quantities'] ); |
|
322 | + } |
|
319 | 323 | |
320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
322 | - } |
|
324 | + if ( isset( $value['required'] ) ) { |
|
325 | + $item->set_is_required( $value['required'] ); |
|
326 | + } |
|
323 | 327 | |
324 | - if ( isset( $value['required'] ) ) { |
|
325 | - $item->set_is_required( $value['required'] ); |
|
326 | - } |
|
328 | + if ( isset( $value['description'] ) ) { |
|
329 | + $item->set_custom_description( $value['description'] ); |
|
330 | + } |
|
327 | 331 | |
328 | - if ( isset( $value['description'] ) ) { |
|
329 | - $item->set_custom_description( $value['description'] ); |
|
330 | - } |
|
332 | + $prepared[] = $item; |
|
333 | + continue; |
|
331 | 334 | |
332 | - $prepared[] = $item; |
|
333 | - continue; |
|
335 | + } |
|
336 | + |
|
337 | + // $item_id => array( 'price' => 10 ) (item variations) |
|
338 | + if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | + $item = new GetPaid_Form_Item( $key ); |
|
340 | + |
|
341 | + if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | + $item->set_price( $value['price'] ); |
|
343 | + } |
|
344 | + |
|
345 | + if ( $item->can_purchase() ) { |
|
346 | + $prepared[] = $item; |
|
347 | + } |
|
348 | + |
|
349 | + continue; |
|
350 | + } |
|
351 | + |
|
352 | + } |
|
353 | + |
|
354 | + if ( 'objects' == $return && 'view' == $context ) { |
|
355 | + return $prepared; |
|
356 | + } |
|
357 | + |
|
358 | + $items = array(); |
|
359 | + foreach ( $prepared as $item ) { |
|
360 | + $items[] = $item->prepare_data_for_use(); |
|
361 | + } |
|
362 | + |
|
363 | + return $items; |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Get a single item belonging to the form. |
|
368 | + * |
|
369 | + * @since 1.0.19 |
|
370 | + * @param int $item_id The item id to return. |
|
371 | + * @return GetPaid_Form_Item|bool |
|
372 | + */ |
|
373 | + public function get_item( $item_id ) { |
|
374 | + |
|
375 | + if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
376 | + return false; |
|
377 | + } |
|
378 | + |
|
379 | + foreach( $this->get_items() as $item ) { |
|
380 | + if ( $item->get_id() == (int) $item_id ) { |
|
381 | + return $item; |
|
382 | + } |
|
383 | + } |
|
384 | + |
|
385 | + return false; |
|
386 | + |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Gets a single element. |
|
391 | + * |
|
392 | + * @since 1.0.19 |
|
393 | + * @param string $element_type The element type to return. |
|
394 | + * @return array|bool |
|
395 | + */ |
|
396 | + public function get_element_type( $element_type ) { |
|
397 | + |
|
398 | + if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
399 | + return false; |
|
400 | + } |
|
401 | + |
|
402 | + foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
403 | + |
|
404 | + if ( $element['type'] == $element_type ) { |
|
405 | + return $element; |
|
406 | + } |
|
407 | + |
|
408 | + } |
|
409 | + |
|
410 | + return false; |
|
411 | + |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * Get the total amount earned via this form. |
|
416 | + * |
|
417 | + * @since 1.0.19 |
|
418 | + * @param string $context View or edit context. |
|
419 | + * @return float |
|
420 | + */ |
|
421 | + public function get_earned( $context = 'view' ) { |
|
422 | + return $this->get_prop( 'earned', $context ); |
|
423 | + } |
|
424 | + |
|
425 | + /** |
|
426 | + * Get the total amount refunded via this form. |
|
427 | + * |
|
428 | + * @since 1.0.19 |
|
429 | + * @param string $context View or edit context. |
|
430 | + * @return float |
|
431 | + */ |
|
432 | + public function get_refunded( $context = 'view' ) { |
|
433 | + return $this->get_prop( 'refunded', $context ); |
|
434 | + } |
|
334 | 435 | |
335 | - } |
|
436 | + /** |
|
437 | + * Get the total amount cancelled via this form. |
|
438 | + * |
|
439 | + * @since 1.0.19 |
|
440 | + * @param string $context View or edit context. |
|
441 | + * @return float |
|
442 | + */ |
|
443 | + public function get_cancelled( $context = 'view' ) { |
|
444 | + return $this->get_prop( 'cancelled', $context ); |
|
445 | + } |
|
336 | 446 | |
337 | - // $item_id => array( 'price' => 10 ) (item variations) |
|
338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | - $item = new GetPaid_Form_Item( $key ); |
|
447 | + /** |
|
448 | + * Get the total amount failed via this form. |
|
449 | + * |
|
450 | + * @since 1.0.19 |
|
451 | + * @param string $context View or edit context. |
|
452 | + * @return float |
|
453 | + */ |
|
454 | + public function get_failed( $context = 'view' ) { |
|
455 | + return $this->get_prop( 'failed', $context ); |
|
456 | + } |
|
340 | 457 | |
341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | - $item->set_price( $value['price'] ); |
|
343 | - } |
|
344 | - |
|
345 | - if ( $item->can_purchase() ) { |
|
346 | - $prepared[] = $item; |
|
347 | - } |
|
348 | - |
|
349 | - continue; |
|
350 | - } |
|
351 | - |
|
352 | - } |
|
353 | - |
|
354 | - if ( 'objects' == $return && 'view' == $context ) { |
|
355 | - return $prepared; |
|
356 | - } |
|
357 | - |
|
358 | - $items = array(); |
|
359 | - foreach ( $prepared as $item ) { |
|
360 | - $items[] = $item->prepare_data_for_use(); |
|
361 | - } |
|
362 | - |
|
363 | - return $items; |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Get a single item belonging to the form. |
|
368 | - * |
|
369 | - * @since 1.0.19 |
|
370 | - * @param int $item_id The item id to return. |
|
371 | - * @return GetPaid_Form_Item|bool |
|
372 | - */ |
|
373 | - public function get_item( $item_id ) { |
|
374 | - |
|
375 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
376 | - return false; |
|
377 | - } |
|
378 | - |
|
379 | - foreach( $this->get_items() as $item ) { |
|
380 | - if ( $item->get_id() == (int) $item_id ) { |
|
381 | - return $item; |
|
382 | - } |
|
383 | - } |
|
384 | - |
|
385 | - return false; |
|
386 | - |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Gets a single element. |
|
391 | - * |
|
392 | - * @since 1.0.19 |
|
393 | - * @param string $element_type The element type to return. |
|
394 | - * @return array|bool |
|
395 | - */ |
|
396 | - public function get_element_type( $element_type ) { |
|
397 | - |
|
398 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
399 | - return false; |
|
400 | - } |
|
401 | - |
|
402 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
403 | - |
|
404 | - if ( $element['type'] == $element_type ) { |
|
405 | - return $element; |
|
406 | - } |
|
407 | - |
|
408 | - } |
|
409 | - |
|
410 | - return false; |
|
411 | - |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * Get the total amount earned via this form. |
|
416 | - * |
|
417 | - * @since 1.0.19 |
|
418 | - * @param string $context View or edit context. |
|
419 | - * @return float |
|
420 | - */ |
|
421 | - public function get_earned( $context = 'view' ) { |
|
422 | - return $this->get_prop( 'earned', $context ); |
|
423 | - } |
|
424 | - |
|
425 | - /** |
|
426 | - * Get the total amount refunded via this form. |
|
427 | - * |
|
428 | - * @since 1.0.19 |
|
429 | - * @param string $context View or edit context. |
|
430 | - * @return float |
|
431 | - */ |
|
432 | - public function get_refunded( $context = 'view' ) { |
|
433 | - return $this->get_prop( 'refunded', $context ); |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * Get the total amount cancelled via this form. |
|
438 | - * |
|
439 | - * @since 1.0.19 |
|
440 | - * @param string $context View or edit context. |
|
441 | - * @return float |
|
442 | - */ |
|
443 | - public function get_cancelled( $context = 'view' ) { |
|
444 | - return $this->get_prop( 'cancelled', $context ); |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * Get the total amount failed via this form. |
|
449 | - * |
|
450 | - * @since 1.0.19 |
|
451 | - * @param string $context View or edit context. |
|
452 | - * @return float |
|
453 | - */ |
|
454 | - public function get_failed( $context = 'view' ) { |
|
455 | - return $this->get_prop( 'failed', $context ); |
|
456 | - } |
|
457 | - |
|
458 | - /** |
|
459 | - * Get the currency. |
|
460 | - * |
|
461 | - * @since 1.0.19 |
|
462 | - * @param string $context View or edit context. |
|
463 | - * @return string |
|
464 | - */ |
|
465 | - public function get_currency() { |
|
466 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
467 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
468 | - } |
|
458 | + /** |
|
459 | + * Get the currency. |
|
460 | + * |
|
461 | + * @since 1.0.19 |
|
462 | + * @param string $context View or edit context. |
|
463 | + * @return string |
|
464 | + */ |
|
465 | + public function get_currency() { |
|
466 | + $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
467 | + return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
468 | + } |
|
469 | 469 | |
470 | 470 | /* |
471 | 471 | |-------------------------------------------------------------------------- |
@@ -478,22 +478,22 @@ discard block |
||
478 | 478 | */ |
479 | 479 | |
480 | 480 | /** |
481 | - * Set plugin version when the item was created. |
|
482 | - * |
|
483 | - * @since 1.0.19 |
|
484 | - */ |
|
485 | - public function set_version( $value ) { |
|
486 | - $this->set_prop( 'version', $value ); |
|
481 | + * Set plugin version when the item was created. |
|
482 | + * |
|
483 | + * @since 1.0.19 |
|
484 | + */ |
|
485 | + public function set_version( $value ) { |
|
486 | + $this->set_prop( 'version', $value ); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
490 | - * Set date when the item was created. |
|
491 | - * |
|
492 | - * @since 1.0.19 |
|
493 | - * @param string $value Value to set. |
|
490 | + * Set date when the item was created. |
|
491 | + * |
|
492 | + * @since 1.0.19 |
|
493 | + * @param string $value Value to set. |
|
494 | 494 | * @return bool Whether or not the date was set. |
495 | - */ |
|
496 | - public function set_date_created( $value ) { |
|
495 | + */ |
|
496 | + public function set_date_created( $value ) { |
|
497 | 497 | $date = strtotime( $value ); |
498 | 498 | |
499 | 499 | if ( $date ) { |
@@ -506,13 +506,13 @@ discard block |
||
506 | 506 | } |
507 | 507 | |
508 | 508 | /** |
509 | - * Set date when the item was last modified. |
|
510 | - * |
|
511 | - * @since 1.0.19 |
|
512 | - * @param string $value Value to set. |
|
509 | + * Set date when the item was last modified. |
|
510 | + * |
|
511 | + * @since 1.0.19 |
|
512 | + * @param string $value Value to set. |
|
513 | 513 | * @return bool Whether or not the date was set. |
514 | - */ |
|
515 | - public function set_date_modified( $value ) { |
|
514 | + */ |
|
515 | + public function set_date_modified( $value ) { |
|
516 | 516 | $date = strtotime( $value ); |
517 | 517 | |
518 | 518 | if ( $date ) { |
@@ -525,118 +525,118 @@ discard block |
||
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
528 | - * Set the item name. |
|
529 | - * |
|
530 | - * @since 1.0.19 |
|
531 | - * @param string $value New name. |
|
532 | - */ |
|
533 | - public function set_name( $value ) { |
|
534 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
535 | - } |
|
536 | - |
|
537 | - /** |
|
538 | - * Alias of self::set_name(). |
|
539 | - * |
|
540 | - * @since 1.0.19 |
|
541 | - * @param string $value New name. |
|
542 | - */ |
|
543 | - public function set_title( $value ) { |
|
544 | - $this->set_name( $value ); |
|
545 | - } |
|
546 | - |
|
547 | - /** |
|
548 | - * Set the owner of the item. |
|
549 | - * |
|
550 | - * @since 1.0.19 |
|
551 | - * @param int $value New author. |
|
552 | - */ |
|
553 | - public function set_author( $value ) { |
|
554 | - $this->set_prop( 'author', (int) $value ); |
|
555 | - } |
|
556 | - |
|
557 | - /** |
|
558 | - * Set the form elements. |
|
559 | - * |
|
560 | - * @since 1.0.19 |
|
561 | - * @param array $value Form elements. |
|
562 | - */ |
|
563 | - public function set_elements( $value ) { |
|
564 | - if ( is_array( $value ) ) { |
|
565 | - $this->set_prop( 'elements', $value ); |
|
566 | - } |
|
567 | - } |
|
568 | - |
|
569 | - /** |
|
570 | - * Set the form items. |
|
571 | - * |
|
572 | - * @since 1.0.19 |
|
573 | - * @param array $value Form elements. |
|
574 | - */ |
|
575 | - public function set_items( $value ) { |
|
576 | - if ( is_array( $value ) ) { |
|
577 | - $this->set_prop( 'items', $value ); |
|
578 | - } |
|
579 | - } |
|
580 | - |
|
581 | - /** |
|
582 | - * Set the total amount earned via this form. |
|
583 | - * |
|
584 | - * @since 1.0.19 |
|
585 | - * @param float $value Amount earned. |
|
586 | - */ |
|
587 | - public function set_earned( $value ) { |
|
588 | - $value = max( (float) $value, 0 ); |
|
589 | - $this->set_prop( 'earned', $value ); |
|
590 | - } |
|
591 | - |
|
592 | - /** |
|
593 | - * Set the total amount refunded via this form. |
|
594 | - * |
|
595 | - * @since 1.0.19 |
|
596 | - * @param float $value Amount refunded. |
|
597 | - */ |
|
598 | - public function set_refunded( $value ) { |
|
599 | - $value = max( (float) $value, 0 ); |
|
600 | - $this->set_prop( 'refunded', $value ); |
|
601 | - } |
|
602 | - |
|
603 | - /** |
|
604 | - * Set the total amount cancelled via this form. |
|
605 | - * |
|
606 | - * @since 1.0.19 |
|
607 | - * @param float $value Amount cancelled. |
|
608 | - */ |
|
609 | - public function set_cancelled( $value ) { |
|
610 | - $value = max( (float) $value, 0 ); |
|
611 | - $this->set_prop( 'cancelled', $value ); |
|
612 | - } |
|
613 | - |
|
614 | - /** |
|
615 | - * Set the total amount failed via this form. |
|
616 | - * |
|
617 | - * @since 1.0.19 |
|
618 | - * @param float $value Amount cancelled. |
|
619 | - */ |
|
620 | - public function set_failed( $value ) { |
|
621 | - $value = max( (float) $value, 0 ); |
|
622 | - $this->set_prop( 'failed', $value ); |
|
623 | - } |
|
528 | + * Set the item name. |
|
529 | + * |
|
530 | + * @since 1.0.19 |
|
531 | + * @param string $value New name. |
|
532 | + */ |
|
533 | + public function set_name( $value ) { |
|
534 | + $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
535 | + } |
|
536 | + |
|
537 | + /** |
|
538 | + * Alias of self::set_name(). |
|
539 | + * |
|
540 | + * @since 1.0.19 |
|
541 | + * @param string $value New name. |
|
542 | + */ |
|
543 | + public function set_title( $value ) { |
|
544 | + $this->set_name( $value ); |
|
545 | + } |
|
546 | + |
|
547 | + /** |
|
548 | + * Set the owner of the item. |
|
549 | + * |
|
550 | + * @since 1.0.19 |
|
551 | + * @param int $value New author. |
|
552 | + */ |
|
553 | + public function set_author( $value ) { |
|
554 | + $this->set_prop( 'author', (int) $value ); |
|
555 | + } |
|
556 | + |
|
557 | + /** |
|
558 | + * Set the form elements. |
|
559 | + * |
|
560 | + * @since 1.0.19 |
|
561 | + * @param array $value Form elements. |
|
562 | + */ |
|
563 | + public function set_elements( $value ) { |
|
564 | + if ( is_array( $value ) ) { |
|
565 | + $this->set_prop( 'elements', $value ); |
|
566 | + } |
|
567 | + } |
|
568 | + |
|
569 | + /** |
|
570 | + * Set the form items. |
|
571 | + * |
|
572 | + * @since 1.0.19 |
|
573 | + * @param array $value Form elements. |
|
574 | + */ |
|
575 | + public function set_items( $value ) { |
|
576 | + if ( is_array( $value ) ) { |
|
577 | + $this->set_prop( 'items', $value ); |
|
578 | + } |
|
579 | + } |
|
580 | + |
|
581 | + /** |
|
582 | + * Set the total amount earned via this form. |
|
583 | + * |
|
584 | + * @since 1.0.19 |
|
585 | + * @param float $value Amount earned. |
|
586 | + */ |
|
587 | + public function set_earned( $value ) { |
|
588 | + $value = max( (float) $value, 0 ); |
|
589 | + $this->set_prop( 'earned', $value ); |
|
590 | + } |
|
591 | + |
|
592 | + /** |
|
593 | + * Set the total amount refunded via this form. |
|
594 | + * |
|
595 | + * @since 1.0.19 |
|
596 | + * @param float $value Amount refunded. |
|
597 | + */ |
|
598 | + public function set_refunded( $value ) { |
|
599 | + $value = max( (float) $value, 0 ); |
|
600 | + $this->set_prop( 'refunded', $value ); |
|
601 | + } |
|
602 | + |
|
603 | + /** |
|
604 | + * Set the total amount cancelled via this form. |
|
605 | + * |
|
606 | + * @since 1.0.19 |
|
607 | + * @param float $value Amount cancelled. |
|
608 | + */ |
|
609 | + public function set_cancelled( $value ) { |
|
610 | + $value = max( (float) $value, 0 ); |
|
611 | + $this->set_prop( 'cancelled', $value ); |
|
612 | + } |
|
613 | + |
|
614 | + /** |
|
615 | + * Set the total amount failed via this form. |
|
616 | + * |
|
617 | + * @since 1.0.19 |
|
618 | + * @param float $value Amount cancelled. |
|
619 | + */ |
|
620 | + public function set_failed( $value ) { |
|
621 | + $value = max( (float) $value, 0 ); |
|
622 | + $this->set_prop( 'failed', $value ); |
|
623 | + } |
|
624 | 624 | |
625 | 625 | /** |
626 | 626 | * Create an item. For backwards compatibilty. |
627 | 627 | * |
628 | 628 | * @deprecated |
629 | - * @return int item id |
|
629 | + * @return int item id |
|
630 | 630 | */ |
631 | 631 | public function create( $data = array() ) { |
632 | 632 | |
633 | - // Set the properties. |
|
634 | - if ( is_array( $data ) ) { |
|
635 | - $this->set_props( $data ); |
|
636 | - } |
|
633 | + // Set the properties. |
|
634 | + if ( is_array( $data ) ) { |
|
635 | + $this->set_props( $data ); |
|
636 | + } |
|
637 | 637 | |
638 | - // Save the item. |
|
639 | - return $this->save(); |
|
638 | + // Save the item. |
|
639 | + return $this->save(); |
|
640 | 640 | |
641 | 641 | } |
642 | 642 | |
@@ -644,7 +644,7 @@ discard block |
||
644 | 644 | * Updates an item. For backwards compatibilty. |
645 | 645 | * |
646 | 646 | * @deprecated |
647 | - * @return int item id |
|
647 | + * @return int item id |
|
648 | 648 | */ |
649 | 649 | public function update( $data = array() ) { |
650 | 650 | return $this->create( $data ); |
@@ -660,22 +660,22 @@ discard block |
||
660 | 660 | */ |
661 | 661 | |
662 | 662 | /** |
663 | - * Checks whether this is the default payment form. |
|
664 | - * |
|
665 | - * @since 1.0.19 |
|
666 | - * @return bool |
|
667 | - */ |
|
663 | + * Checks whether this is the default payment form. |
|
664 | + * |
|
665 | + * @since 1.0.19 |
|
666 | + * @return bool |
|
667 | + */ |
|
668 | 668 | public function is_default() { |
669 | 669 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
670 | 670 | return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
671 | - } |
|
671 | + } |
|
672 | 672 | |
673 | 673 | /** |
674 | - * Checks whether the form is active. |
|
675 | - * |
|
676 | - * @since 1.0.19 |
|
677 | - * @return bool |
|
678 | - */ |
|
674 | + * Checks whether the form is active. |
|
675 | + * |
|
676 | + * @since 1.0.19 |
|
677 | + * @return bool |
|
678 | + */ |
|
679 | 679 | public function is_active() { |
680 | 680 | $is_active = 0 !== (int) $this->get_id(); |
681 | 681 | |
@@ -684,76 +684,76 @@ discard block |
||
684 | 684 | } |
685 | 685 | |
686 | 686 | return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
687 | - } |
|
688 | - |
|
689 | - /** |
|
690 | - * Checks whether the form has a given item. |
|
691 | - * |
|
692 | - * @since 1.0.19 |
|
693 | - * @return bool |
|
694 | - */ |
|
687 | + } |
|
688 | + |
|
689 | + /** |
|
690 | + * Checks whether the form has a given item. |
|
691 | + * |
|
692 | + * @since 1.0.19 |
|
693 | + * @return bool |
|
694 | + */ |
|
695 | 695 | public function has_item( $item_id ) { |
696 | 696 | return false !== $this->get_item( $item_id ); |
697 | - } |
|
698 | - |
|
699 | - /** |
|
700 | - * Checks whether the form has a given element. |
|
701 | - * |
|
702 | - * @since 1.0.19 |
|
703 | - * @return bool |
|
704 | - */ |
|
697 | + } |
|
698 | + |
|
699 | + /** |
|
700 | + * Checks whether the form has a given element. |
|
701 | + * |
|
702 | + * @since 1.0.19 |
|
703 | + * @return bool |
|
704 | + */ |
|
705 | 705 | public function has_element_type( $element_type ) { |
706 | 706 | return false !== $this->get_element_type( $element_type ); |
707 | - } |
|
708 | - |
|
709 | - /** |
|
710 | - * Checks whether this form is recurring or not. |
|
711 | - * |
|
712 | - * @since 1.0.19 |
|
713 | - * @return bool |
|
714 | - */ |
|
707 | + } |
|
708 | + |
|
709 | + /** |
|
710 | + * Checks whether this form is recurring or not. |
|
711 | + * |
|
712 | + * @since 1.0.19 |
|
713 | + * @return bool |
|
714 | + */ |
|
715 | 715 | public function is_recurring() { |
716 | 716 | |
717 | - if ( ! empty( $this->invoice ) ) { |
|
718 | - return $this->invoice->is_recurring(); |
|
719 | - } |
|
717 | + if ( ! empty( $this->invoice ) ) { |
|
718 | + return $this->invoice->is_recurring(); |
|
719 | + } |
|
720 | 720 | |
721 | - foreach ( $this->get_items() as $item ) { |
|
721 | + foreach ( $this->get_items() as $item ) { |
|
722 | 722 | |
723 | - if ( $item->is_recurring() ) { |
|
724 | - return true; |
|
725 | - } |
|
723 | + if ( $item->is_recurring() ) { |
|
724 | + return true; |
|
725 | + } |
|
726 | 726 | |
727 | - } |
|
727 | + } |
|
728 | 728 | |
729 | 729 | return false; |
730 | - } |
|
730 | + } |
|
731 | 731 | |
732 | - /** |
|
733 | - * Retrieves the form's html. |
|
734 | - * |
|
735 | - * @since 1.0.19 |
|
736 | - */ |
|
732 | + /** |
|
733 | + * Retrieves the form's html. |
|
734 | + * |
|
735 | + * @since 1.0.19 |
|
736 | + */ |
|
737 | 737 | public function get_html( $extra_markup = '' ) { |
738 | 738 | |
739 | - // Return the HTML. |
|
740 | - return wpinv_get_template_html( |
|
741 | - 'payment-forms/form.php', |
|
742 | - array( |
|
743 | - 'form' => $this, |
|
744 | - 'extra_markup' => $extra_markup, |
|
745 | - ) |
|
746 | - ); |
|
747 | - |
|
748 | - } |
|
749 | - |
|
750 | - /** |
|
751 | - * Displays the payment form. |
|
752 | - * |
|
753 | - * @since 1.0.19 |
|
754 | - */ |
|
739 | + // Return the HTML. |
|
740 | + return wpinv_get_template_html( |
|
741 | + 'payment-forms/form.php', |
|
742 | + array( |
|
743 | + 'form' => $this, |
|
744 | + 'extra_markup' => $extra_markup, |
|
745 | + ) |
|
746 | + ); |
|
747 | + |
|
748 | + } |
|
749 | + |
|
750 | + /** |
|
751 | + * Displays the payment form. |
|
752 | + * |
|
753 | + * @since 1.0.19 |
|
754 | + */ |
|
755 | 755 | public function display( $extra_markup = '' ) { |
756 | - echo $this->get_html( $extra_markup ); |
|
756 | + echo $this->get_html( $extra_markup ); |
|
757 | 757 | } |
758 | 758 | |
759 | 759 | } |
@@ -13,467 +13,467 @@ discard block |
||
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_gateway_{$this->id}_subscription_url", array( $this, 'filter_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_Invoice $invoice Invoice object. |
|
354 | + * @return string subscription URL, or empty string. |
|
355 | + */ |
|
356 | + public function filter_subscription_url( $subscription_url, $invoice ) { |
|
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_gateway_{$this->id}_subscription_url", array( $this, 'filter_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_Invoice $invoice Invoice object. |
|
354 | - * @return string subscription URL, or empty string. |
|
355 | - */ |
|
356 | - public function filter_subscription_url( $subscription_url, $invoice ) { |
|
357 | - |
|
358 | - $profile_id = $invoice->get_subscription_id(); |
|
359 | - |
|
360 | - if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
361 | - |
|
362 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
363 | - $replace = $this->is_sandbox( $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 = $invoice->get_subscription_id(); |
|
359 | + |
|
360 | + if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
361 | + |
|
362 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
363 | + $replace = $this->is_sandbox( $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 |
||
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 |
||
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 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,60 +10,60 @@ discard block |
||
10 | 10 | class GetPaid_Form_Item extends WPInv_Item { |
11 | 11 | |
12 | 12 | /** |
13 | - * Stores a custom description for the item. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $custom_description = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * Stores the item quantity. |
|
21 | - * |
|
22 | - * @var float |
|
23 | - */ |
|
24 | - protected $quantity = 1; |
|
25 | - |
|
26 | - /** |
|
27 | - * Stores the item meta. |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $meta = array(); |
|
32 | - |
|
33 | - /** |
|
34 | - * Is this item required? |
|
35 | - * |
|
36 | - * @var int |
|
37 | - */ |
|
38 | - protected $is_required = true; |
|
39 | - |
|
40 | - /** |
|
41 | - * Are quantities allowed? |
|
42 | - * |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - protected $allow_quantities = false; |
|
46 | - |
|
47 | - /** |
|
48 | - * Associated invoice. |
|
49 | - * |
|
50 | - * @var int |
|
51 | - */ |
|
52 | - public $invoice_id = 0; |
|
53 | - |
|
54 | - /** |
|
55 | - * Item discount. |
|
56 | - * |
|
57 | - * @var float |
|
58 | - */ |
|
59 | - public $item_discount = 0; |
|
60 | - |
|
61 | - /** |
|
62 | - * Item tax. |
|
63 | - * |
|
64 | - * @var float |
|
65 | - */ |
|
66 | - public $item_tax = 0; |
|
13 | + * Stores a custom description for the item. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $custom_description = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * Stores the item quantity. |
|
21 | + * |
|
22 | + * @var float |
|
23 | + */ |
|
24 | + protected $quantity = 1; |
|
25 | + |
|
26 | + /** |
|
27 | + * Stores the item meta. |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $meta = array(); |
|
32 | + |
|
33 | + /** |
|
34 | + * Is this item required? |
|
35 | + * |
|
36 | + * @var int |
|
37 | + */ |
|
38 | + protected $is_required = true; |
|
39 | + |
|
40 | + /** |
|
41 | + * Are quantities allowed? |
|
42 | + * |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + protected $allow_quantities = false; |
|
46 | + |
|
47 | + /** |
|
48 | + * Associated invoice. |
|
49 | + * |
|
50 | + * @var int |
|
51 | + */ |
|
52 | + public $invoice_id = 0; |
|
53 | + |
|
54 | + /** |
|
55 | + * Item discount. |
|
56 | + * |
|
57 | + * @var float |
|
58 | + */ |
|
59 | + public $item_discount = 0; |
|
60 | + |
|
61 | + /** |
|
62 | + * Item tax. |
|
63 | + * |
|
64 | + * @var float |
|
65 | + */ |
|
66 | + public $item_tax = 0; |
|
67 | 67 | |
68 | 68 | /* |
69 | 69 | |-------------------------------------------------------------------------- |
@@ -81,234 +81,234 @@ discard block |
||
81 | 81 | */ |
82 | 82 | |
83 | 83 | /** |
84 | - * Get the item name. |
|
85 | - * |
|
86 | - * @since 1.0.19 |
|
87 | - * @param string $context View or edit context. |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function get_name( $context = 'view' ) { |
|
91 | - $name = parent::get_name( $context ); |
|
92 | - return $name . wpinv_get_item_suffix( $this ); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Get the item name without a suffix. |
|
97 | - * |
|
98 | - * @since 1.0.19 |
|
99 | - * @param string $context View or edit context. |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function get_raw_name( $context = 'view' ) { |
|
103 | - return parent::get_name( $context ); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Get the item description. |
|
108 | - * |
|
109 | - * @since 1.0.19 |
|
110 | - * @param string $context View or edit context. |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function get_description( $context = 'view' ) { |
|
114 | - |
|
115 | - if ( isset( $this->custom_description ) ) { |
|
116 | - return $this->custom_description; |
|
117 | - } |
|
118 | - |
|
119 | - return parent::get_description( $context ); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Returns the sub total. |
|
124 | - * |
|
125 | - * @since 1.0.19 |
|
126 | - * @param string $context View or edit context. |
|
127 | - * @return float |
|
128 | - */ |
|
129 | - public function get_sub_total( $context = 'view' ) { |
|
130 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Returns the recurring sub total. |
|
135 | - * |
|
136 | - * @since 1.0.19 |
|
137 | - * @param string $context View or edit context. |
|
138 | - * @return float |
|
139 | - */ |
|
140 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
141 | - |
|
142 | - if ( $this->is_recurring() ) { |
|
143 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
144 | - } |
|
145 | - |
|
146 | - return 0; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @deprecated |
|
151 | - */ |
|
152 | - public function get_qantity( $context = 'view' ) { |
|
153 | - return $this->get_quantity( $context ); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Get the item quantity. |
|
158 | - * |
|
159 | - * @since 1.0.19 |
|
160 | - * @param string $context View or edit context. |
|
161 | - * @return float |
|
162 | - */ |
|
163 | - public function get_quantity( $context = 'view' ) { |
|
164 | - $quantity = (float) $this->quantity; |
|
165 | - |
|
166 | - if ( empty( $quantity ) || 1 > $quantity ) { |
|
167 | - $quantity = 1; |
|
168 | - } |
|
169 | - |
|
170 | - if ( 'view' == $context ) { |
|
171 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
172 | - } |
|
173 | - |
|
174 | - return $quantity; |
|
175 | - |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Get the item meta data. |
|
180 | - * |
|
181 | - * @since 1.0.19 |
|
182 | - * @param string $context View or edit context. |
|
183 | - * @return meta |
|
184 | - */ |
|
185 | - public function get_item_meta( $context = 'view' ) { |
|
186 | - $meta = $this->meta; |
|
187 | - |
|
188 | - if ( 'view' == $context ) { |
|
189 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
190 | - } |
|
191 | - |
|
192 | - return $meta; |
|
193 | - |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Returns whether or not customers can update the item quantity. |
|
198 | - * |
|
199 | - * @since 1.0.19 |
|
200 | - * @param string $context View or edit context. |
|
201 | - * @return bool |
|
202 | - */ |
|
203 | - public function get_allow_quantities( $context = 'view' ) { |
|
204 | - $allow_quantities = (bool) $this->allow_quantities; |
|
205 | - |
|
206 | - if ( 'view' == $context ) { |
|
207 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
208 | - } |
|
209 | - |
|
210 | - return $allow_quantities; |
|
211 | - |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Returns whether or not the item is required. |
|
216 | - * |
|
217 | - * @since 1.0.19 |
|
218 | - * @param string $context View or edit context. |
|
219 | - * @return bool |
|
220 | - */ |
|
221 | - public function get_is_required( $context = 'view' ) { |
|
222 | - $is_required = (bool) $this->is_required; |
|
223 | - |
|
224 | - if ( 'view' == $context ) { |
|
225 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
226 | - } |
|
227 | - |
|
228 | - return $is_required; |
|
229 | - |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Prepares form data for use. |
|
234 | - * |
|
235 | - * @since 1.0.19 |
|
236 | - * @return array |
|
237 | - */ |
|
238 | - public function prepare_data_for_use( $required = null ) { |
|
239 | - |
|
240 | - $required = is_null( $required ) ? $this->is_required() : $required; |
|
241 | - return array( |
|
242 | - 'title' => strip_tags( $this->get_name() ), |
|
243 | - 'id' => $this->get_id(), |
|
244 | - 'price' => $this->get_price(), |
|
245 | - 'recurring' => $this->is_recurring(), |
|
246 | - 'description' => $this->get_description(), |
|
247 | - 'allow_quantities' => $this->allows_quantities(), |
|
248 | - 'required' => $required, |
|
249 | - ); |
|
250 | - |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Prepares form data for ajax use. |
|
255 | - * |
|
256 | - * @since 1.0.19 |
|
257 | - * @return array |
|
258 | - */ |
|
259 | - public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
260 | - |
|
261 | - $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
262 | - |
|
263 | - if ( $description ) { |
|
264 | - $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
265 | - } |
|
266 | - |
|
267 | - $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
268 | - $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
269 | - return array( |
|
270 | - 'id' => $this->get_id(), |
|
271 | - 'texts' => array( |
|
272 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
273 | - 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
274 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
275 | - 'item-price' => wpinv_price( $price, $currency ), |
|
276 | - 'item-total' => wpinv_price( $subtotal, $currency ), |
|
277 | - ), |
|
278 | - 'inputs' => array( |
|
279 | - 'item-id' => $this->get_id(), |
|
280 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
281 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
282 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
283 | - 'item-price' => $price, |
|
284 | - ) |
|
285 | - ); |
|
286 | - |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Prepares form data for saving (cart_details). |
|
291 | - * |
|
292 | - * @since 1.0.19 |
|
293 | - * @return array |
|
294 | - */ |
|
295 | - public function prepare_data_for_saving() { |
|
296 | - |
|
297 | - return array( |
|
298 | - 'post_id' => $this->invoice_id, |
|
299 | - 'item_id' => $this->get_id(), |
|
300 | - 'item_name' => sanitize_text_field( $this->get_raw_name() ), |
|
301 | - 'item_description' => $this->get_description(), |
|
302 | - 'tax' => $this->item_tax, |
|
303 | - 'item_price' => $this->get_price(), |
|
304 | - 'quantity' => (float) $this->get_quantity(), |
|
305 | - 'discount' => $this->item_discount, |
|
306 | - 'subtotal' => $this->get_sub_total(), |
|
307 | - 'price' => $this->get_sub_total() + $this->item_tax + $this->item_discount, |
|
308 | - 'meta' => $this->get_item_meta(), |
|
309 | - ); |
|
310 | - |
|
311 | - } |
|
84 | + * Get the item name. |
|
85 | + * |
|
86 | + * @since 1.0.19 |
|
87 | + * @param string $context View or edit context. |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function get_name( $context = 'view' ) { |
|
91 | + $name = parent::get_name( $context ); |
|
92 | + return $name . wpinv_get_item_suffix( $this ); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Get the item name without a suffix. |
|
97 | + * |
|
98 | + * @since 1.0.19 |
|
99 | + * @param string $context View or edit context. |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function get_raw_name( $context = 'view' ) { |
|
103 | + return parent::get_name( $context ); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Get the item description. |
|
108 | + * |
|
109 | + * @since 1.0.19 |
|
110 | + * @param string $context View or edit context. |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function get_description( $context = 'view' ) { |
|
114 | + |
|
115 | + if ( isset( $this->custom_description ) ) { |
|
116 | + return $this->custom_description; |
|
117 | + } |
|
118 | + |
|
119 | + return parent::get_description( $context ); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Returns the sub total. |
|
124 | + * |
|
125 | + * @since 1.0.19 |
|
126 | + * @param string $context View or edit context. |
|
127 | + * @return float |
|
128 | + */ |
|
129 | + public function get_sub_total( $context = 'view' ) { |
|
130 | + return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Returns the recurring sub total. |
|
135 | + * |
|
136 | + * @since 1.0.19 |
|
137 | + * @param string $context View or edit context. |
|
138 | + * @return float |
|
139 | + */ |
|
140 | + public function get_recurring_sub_total( $context = 'view' ) { |
|
141 | + |
|
142 | + if ( $this->is_recurring() ) { |
|
143 | + return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
144 | + } |
|
145 | + |
|
146 | + return 0; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @deprecated |
|
151 | + */ |
|
152 | + public function get_qantity( $context = 'view' ) { |
|
153 | + return $this->get_quantity( $context ); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Get the item quantity. |
|
158 | + * |
|
159 | + * @since 1.0.19 |
|
160 | + * @param string $context View or edit context. |
|
161 | + * @return float |
|
162 | + */ |
|
163 | + public function get_quantity( $context = 'view' ) { |
|
164 | + $quantity = (float) $this->quantity; |
|
165 | + |
|
166 | + if ( empty( $quantity ) || 1 > $quantity ) { |
|
167 | + $quantity = 1; |
|
168 | + } |
|
169 | + |
|
170 | + if ( 'view' == $context ) { |
|
171 | + return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
172 | + } |
|
173 | + |
|
174 | + return $quantity; |
|
175 | + |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Get the item meta data. |
|
180 | + * |
|
181 | + * @since 1.0.19 |
|
182 | + * @param string $context View or edit context. |
|
183 | + * @return meta |
|
184 | + */ |
|
185 | + public function get_item_meta( $context = 'view' ) { |
|
186 | + $meta = $this->meta; |
|
187 | + |
|
188 | + if ( 'view' == $context ) { |
|
189 | + return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
190 | + } |
|
191 | + |
|
192 | + return $meta; |
|
193 | + |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Returns whether or not customers can update the item quantity. |
|
198 | + * |
|
199 | + * @since 1.0.19 |
|
200 | + * @param string $context View or edit context. |
|
201 | + * @return bool |
|
202 | + */ |
|
203 | + public function get_allow_quantities( $context = 'view' ) { |
|
204 | + $allow_quantities = (bool) $this->allow_quantities; |
|
205 | + |
|
206 | + if ( 'view' == $context ) { |
|
207 | + return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
208 | + } |
|
209 | + |
|
210 | + return $allow_quantities; |
|
211 | + |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Returns whether or not the item is required. |
|
216 | + * |
|
217 | + * @since 1.0.19 |
|
218 | + * @param string $context View or edit context. |
|
219 | + * @return bool |
|
220 | + */ |
|
221 | + public function get_is_required( $context = 'view' ) { |
|
222 | + $is_required = (bool) $this->is_required; |
|
223 | + |
|
224 | + if ( 'view' == $context ) { |
|
225 | + return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
226 | + } |
|
227 | + |
|
228 | + return $is_required; |
|
229 | + |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Prepares form data for use. |
|
234 | + * |
|
235 | + * @since 1.0.19 |
|
236 | + * @return array |
|
237 | + */ |
|
238 | + public function prepare_data_for_use( $required = null ) { |
|
239 | + |
|
240 | + $required = is_null( $required ) ? $this->is_required() : $required; |
|
241 | + return array( |
|
242 | + 'title' => strip_tags( $this->get_name() ), |
|
243 | + 'id' => $this->get_id(), |
|
244 | + 'price' => $this->get_price(), |
|
245 | + 'recurring' => $this->is_recurring(), |
|
246 | + 'description' => $this->get_description(), |
|
247 | + 'allow_quantities' => $this->allows_quantities(), |
|
248 | + 'required' => $required, |
|
249 | + ); |
|
250 | + |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Prepares form data for ajax use. |
|
255 | + * |
|
256 | + * @since 1.0.19 |
|
257 | + * @return array |
|
258 | + */ |
|
259 | + public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
260 | + |
|
261 | + $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
262 | + |
|
263 | + if ( $description ) { |
|
264 | + $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
265 | + } |
|
266 | + |
|
267 | + $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
268 | + $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
269 | + return array( |
|
270 | + 'id' => $this->get_id(), |
|
271 | + 'texts' => array( |
|
272 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
273 | + 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
274 | + 'item-quantity' => floatval( $this->get_quantity() ), |
|
275 | + 'item-price' => wpinv_price( $price, $currency ), |
|
276 | + 'item-total' => wpinv_price( $subtotal, $currency ), |
|
277 | + ), |
|
278 | + 'inputs' => array( |
|
279 | + 'item-id' => $this->get_id(), |
|
280 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
281 | + 'item-description' => wp_kses_post( $this->get_description() ), |
|
282 | + 'item-quantity' => floatval( $this->get_quantity() ), |
|
283 | + 'item-price' => $price, |
|
284 | + ) |
|
285 | + ); |
|
286 | + |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Prepares form data for saving (cart_details). |
|
291 | + * |
|
292 | + * @since 1.0.19 |
|
293 | + * @return array |
|
294 | + */ |
|
295 | + public function prepare_data_for_saving() { |
|
296 | + |
|
297 | + return array( |
|
298 | + 'post_id' => $this->invoice_id, |
|
299 | + 'item_id' => $this->get_id(), |
|
300 | + 'item_name' => sanitize_text_field( $this->get_raw_name() ), |
|
301 | + 'item_description' => $this->get_description(), |
|
302 | + 'tax' => $this->item_tax, |
|
303 | + 'item_price' => $this->get_price(), |
|
304 | + 'quantity' => (float) $this->get_quantity(), |
|
305 | + 'discount' => $this->item_discount, |
|
306 | + 'subtotal' => $this->get_sub_total(), |
|
307 | + 'price' => $this->get_sub_total() + $this->item_tax + $this->item_discount, |
|
308 | + 'meta' => $this->get_item_meta(), |
|
309 | + ); |
|
310 | + |
|
311 | + } |
|
312 | 312 | |
313 | 313 | /* |
314 | 314 | |-------------------------------------------------------------------------- |
@@ -320,70 +320,70 @@ discard block |
||
320 | 320 | | object. |
321 | 321 | */ |
322 | 322 | |
323 | - /** |
|
324 | - * Set the item qantity. |
|
325 | - * |
|
326 | - * @since 1.0.19 |
|
327 | - * @param float $quantity The item quantity. |
|
328 | - */ |
|
329 | - public function set_quantity( $quantity ) { |
|
330 | - |
|
331 | - if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
332 | - $quantity = 1; |
|
333 | - } |
|
334 | - |
|
335 | - $this->quantity = (float) $quantity; |
|
336 | - |
|
337 | - } |
|
338 | - |
|
339 | - /** |
|
340 | - * Set the item meta data. |
|
341 | - * |
|
342 | - * @since 1.0.19 |
|
343 | - * @param array $meta The item meta data. |
|
344 | - */ |
|
345 | - public function set_item_meta( $meta ) { |
|
346 | - $this->meta = maybe_unserialize( $meta ); |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * Set whether or not the quantities are allowed. |
|
351 | - * |
|
352 | - * @since 1.0.19 |
|
353 | - * @param bool $allow_quantities |
|
354 | - */ |
|
355 | - public function set_allow_quantities( $allow_quantities ) { |
|
356 | - $this->allow_quantities = (bool) $allow_quantities; |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Set whether or not the item is required. |
|
361 | - * |
|
362 | - * @since 1.0.19 |
|
363 | - * @param bool $is_required |
|
364 | - */ |
|
365 | - public function set_is_required( $is_required ) { |
|
366 | - $this->is_required = (bool) $is_required; |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * Sets the custom item description. |
|
371 | - * |
|
372 | - * @since 1.0.19 |
|
373 | - * @param string $description |
|
374 | - */ |
|
375 | - public function set_custom_description( $description ) { |
|
376 | - $this->custom_description = $description; |
|
377 | - } |
|
323 | + /** |
|
324 | + * Set the item qantity. |
|
325 | + * |
|
326 | + * @since 1.0.19 |
|
327 | + * @param float $quantity The item quantity. |
|
328 | + */ |
|
329 | + public function set_quantity( $quantity ) { |
|
330 | + |
|
331 | + if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
332 | + $quantity = 1; |
|
333 | + } |
|
334 | + |
|
335 | + $this->quantity = (float) $quantity; |
|
336 | + |
|
337 | + } |
|
338 | + |
|
339 | + /** |
|
340 | + * Set the item meta data. |
|
341 | + * |
|
342 | + * @since 1.0.19 |
|
343 | + * @param array $meta The item meta data. |
|
344 | + */ |
|
345 | + public function set_item_meta( $meta ) { |
|
346 | + $this->meta = maybe_unserialize( $meta ); |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * Set whether or not the quantities are allowed. |
|
351 | + * |
|
352 | + * @since 1.0.19 |
|
353 | + * @param bool $allow_quantities |
|
354 | + */ |
|
355 | + public function set_allow_quantities( $allow_quantities ) { |
|
356 | + $this->allow_quantities = (bool) $allow_quantities; |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Set whether or not the item is required. |
|
361 | + * |
|
362 | + * @since 1.0.19 |
|
363 | + * @param bool $is_required |
|
364 | + */ |
|
365 | + public function set_is_required( $is_required ) { |
|
366 | + $this->is_required = (bool) $is_required; |
|
367 | + } |
|
368 | + |
|
369 | + /** |
|
370 | + * Sets the custom item description. |
|
371 | + * |
|
372 | + * @since 1.0.19 |
|
373 | + * @param string $description |
|
374 | + */ |
|
375 | + public function set_custom_description( $description ) { |
|
376 | + $this->custom_description = $description; |
|
377 | + } |
|
378 | 378 | |
379 | 379 | /** |
380 | 380 | * We do not want to save items to the database. |
381 | 381 | * |
382 | - * @return int item id |
|
382 | + * @return int item id |
|
383 | 383 | */ |
384 | 384 | public function save( $data = array() ) { |
385 | 385 | return $this->get_id(); |
386 | - } |
|
386 | + } |
|
387 | 387 | |
388 | 388 | /* |
389 | 389 | |-------------------------------------------------------------------------- |
@@ -395,23 +395,23 @@ discard block |
||
395 | 395 | */ |
396 | 396 | |
397 | 397 | /** |
398 | - * Checks whether the item has enabled dynamic pricing. |
|
399 | - * |
|
400 | - * @since 1.0.19 |
|
401 | - * @return bool |
|
402 | - */ |
|
403 | - public function is_required() { |
|
398 | + * Checks whether the item has enabled dynamic pricing. |
|
399 | + * |
|
400 | + * @since 1.0.19 |
|
401 | + * @return bool |
|
402 | + */ |
|
403 | + public function is_required() { |
|
404 | 404 | return (bool) $this->get_is_required(); |
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * Checks whether users can edit the quantities. |
|
409 | - * |
|
410 | - * @since 1.0.19 |
|
411 | - * @return bool |
|
412 | - */ |
|
413 | - public function allows_quantities() { |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * Checks whether users can edit the quantities. |
|
409 | + * |
|
410 | + * @since 1.0.19 |
|
411 | + * @return bool |
|
412 | + */ |
|
413 | + public function allows_quantities() { |
|
414 | 414 | return (bool) $this->get_allow_quantities(); |
415 | - } |
|
415 | + } |
|
416 | 416 | |
417 | 417 | } |
@@ -12,180 +12,180 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Checkout { |
14 | 14 | |
15 | - /** |
|
16 | - * @var GetPaid_Payment_Form_Submission |
|
17 | - */ |
|
18 | - protected $payment_form_submission; |
|
19 | - |
|
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - * @param GetPaid_Payment_Form_Submission $submission |
|
24 | - */ |
|
25 | - public function __construct( $submission ) { |
|
26 | - $this->payment_form_submission = $submission; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Processes the checkout. |
|
31 | - * |
|
32 | - */ |
|
33 | - public function process_checkout() { |
|
34 | - |
|
35 | - // Validate the submission. |
|
36 | - $this->validate_submission(); |
|
37 | - |
|
38 | - // Prepare the invoice. |
|
39 | - $items = $this->get_submission_items(); |
|
40 | - $invoice = $this->get_submission_invoice(); |
|
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | - $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | - |
|
44 | - $this->prepare_billing_info( $invoice ); |
|
45 | - |
|
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | - |
|
48 | - // Save the invoice. |
|
49 | - $invoice->set_is_viewed( true ); |
|
50 | - $invoice->recalculate_total(); |
|
15 | + /** |
|
16 | + * @var GetPaid_Payment_Form_Submission |
|
17 | + */ |
|
18 | + protected $payment_form_submission; |
|
19 | + |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + * @param GetPaid_Payment_Form_Submission $submission |
|
24 | + */ |
|
25 | + public function __construct( $submission ) { |
|
26 | + $this->payment_form_submission = $submission; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Processes the checkout. |
|
31 | + * |
|
32 | + */ |
|
33 | + public function process_checkout() { |
|
34 | + |
|
35 | + // Validate the submission. |
|
36 | + $this->validate_submission(); |
|
37 | + |
|
38 | + // Prepare the invoice. |
|
39 | + $items = $this->get_submission_items(); |
|
40 | + $invoice = $this->get_submission_invoice(); |
|
41 | + $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | + $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | + |
|
44 | + $this->prepare_billing_info( $invoice ); |
|
45 | + |
|
46 | + $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | + |
|
48 | + // Save the invoice. |
|
49 | + $invoice->set_is_viewed( true ); |
|
50 | + $invoice->recalculate_total(); |
|
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
54 | 54 | |
55 | - // Send to the gateway. |
|
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | - } |
|
55 | + // Send to the gateway. |
|
56 | + $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Validates the submission. |
|
61 | - * |
|
62 | - */ |
|
63 | - protected function validate_submission() { |
|
59 | + /** |
|
60 | + * Validates the submission. |
|
61 | + * |
|
62 | + */ |
|
63 | + protected function validate_submission() { |
|
64 | 64 | |
65 | - $submission = $this->payment_form_submission; |
|
66 | - $data = $submission->get_data(); |
|
65 | + $submission = $this->payment_form_submission; |
|
66 | + $data = $submission->get_data(); |
|
67 | 67 | |
68 | - // Do we have an error? |
|
68 | + // Do we have an error? |
|
69 | 69 | if ( ! empty( $submission->last_error ) ) { |
70 | - wp_send_json_error( $submission->last_error ); |
|
70 | + wp_send_json_error( $submission->last_error ); |
|
71 | 71 | } |
72 | 72 | |
73 | - // We need a billing email. |
|
73 | + // We need a billing email. |
|
74 | 74 | if ( ! $submission->has_billing_email() ) { |
75 | 75 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
76 | - } |
|
76 | + } |
|
77 | 77 | |
78 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | - } |
|
78 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | + if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | + } |
|
82 | 82 | |
83 | - // Ensure the gateway is active. |
|
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | - } |
|
83 | + // Ensure the gateway is active. |
|
84 | + if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | + wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | + } |
|
87 | 87 | |
88 | - // Clear any existing errors. |
|
89 | - wpinv_clear_errors(); |
|
88 | + // Clear any existing errors. |
|
89 | + wpinv_clear_errors(); |
|
90 | 90 | |
91 | - // Allow themes and plugins to hook to errors |
|
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
91 | + // Allow themes and plugins to hook to errors |
|
92 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
93 | 93 | |
94 | - // Do we have any errors? |
|
94 | + // Do we have any errors? |
|
95 | 95 | if ( wpinv_get_errors() ) { |
96 | 96 | wp_send_json_error( getpaid_get_errors_html() ); |
97 | - } |
|
97 | + } |
|
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Retrieves submission items. |
|
103 | - * |
|
104 | - * @return GetPaid_Form_Item[] |
|
105 | - */ |
|
106 | - protected function get_submission_items() { |
|
101 | + /** |
|
102 | + * Retrieves submission items. |
|
103 | + * |
|
104 | + * @return GetPaid_Form_Item[] |
|
105 | + */ |
|
106 | + protected function get_submission_items() { |
|
107 | 107 | |
108 | - $items = $this->payment_form_submission->get_items(); |
|
108 | + $items = $this->payment_form_submission->get_items(); |
|
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | 111 | if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
112 | 112 | wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
113 | - } |
|
114 | - |
|
115 | - return $items; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Retrieves submission invoice. |
|
120 | - * |
|
121 | - * @return WPInv_Invoice |
|
122 | - */ |
|
123 | - protected function get_submission_invoice() { |
|
124 | - $submission = $this->payment_form_submission; |
|
125 | - |
|
126 | - if ( ! $submission->has_invoice() ) { |
|
127 | - $invoice = new WPInv_Invoice(); |
|
128 | - $invoice->created_via( 'payment_form' ); |
|
129 | - return $invoice; |
|
130 | 113 | } |
131 | 114 | |
132 | - $invoice = $submission->get_invoice(); |
|
115 | + return $items; |
|
116 | + } |
|
133 | 117 | |
134 | - // Make sure that it is neither paid or refunded. |
|
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | - } |
|
118 | + /** |
|
119 | + * Retrieves submission invoice. |
|
120 | + * |
|
121 | + * @return WPInv_Invoice |
|
122 | + */ |
|
123 | + protected function get_submission_invoice() { |
|
124 | + $submission = $this->payment_form_submission; |
|
138 | 125 | |
139 | - return $invoice; |
|
140 | - } |
|
126 | + if ( ! $submission->has_invoice() ) { |
|
127 | + $invoice = new WPInv_Invoice(); |
|
128 | + $invoice->created_via( 'payment_form' ); |
|
129 | + return $invoice; |
|
130 | + } |
|
141 | 131 | |
142 | - /** |
|
143 | - * Processes the submission invoice. |
|
144 | - * |
|
145 | - * @param WPInv_Invoice $invoice |
|
146 | - * @param GetPaid_Form_Item[] $items |
|
147 | - * @return WPInv_Invoice |
|
148 | - */ |
|
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
132 | + $invoice = $submission->get_invoice(); |
|
150 | 133 | |
151 | - $submission = $this->payment_form_submission; |
|
152 | - $data = $submission->get_data(); |
|
134 | + // Make sure that it is neither paid or refunded. |
|
135 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | + } |
|
138 | + |
|
139 | + return $invoice; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Processes the submission invoice. |
|
144 | + * |
|
145 | + * @param WPInv_Invoice $invoice |
|
146 | + * @param GetPaid_Form_Item[] $items |
|
147 | + * @return WPInv_Invoice |
|
148 | + */ |
|
149 | + protected function process_submission_invoice( $invoice, $items ) { |
|
153 | 150 | |
154 | - // Set-up the invoice details. |
|
155 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
156 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
157 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
151 | + $submission = $this->payment_form_submission; |
|
152 | + $data = $submission->get_data(); |
|
153 | + |
|
154 | + // Set-up the invoice details. |
|
155 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
156 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
157 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
158 | 158 | $invoice->set_items( $items ); |
159 | 159 | $invoice->set_fees( $submission->get_fees() ); |
160 | 160 | $invoice->set_taxes( $submission->get_taxes() ); |
161 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
162 | - $invoice->set_gateway( $data['wpi-gateway'] ); |
|
161 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
162 | + $invoice->set_gateway( $data['wpi-gateway'] ); |
|
163 | 163 | |
164 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
165 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
164 | + $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
165 | + $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
166 | 166 | |
167 | - if ( $submission->has_discount_code() ) { |
|
167 | + if ( $submission->has_discount_code() ) { |
|
168 | 168 | $invoice->set_discount_code( $submission->get_discount_code() ); |
169 | - } |
|
170 | - |
|
171 | - getpaid_maybe_add_default_address( $invoice ); |
|
172 | - return $invoice; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Retrieves the submission's customer. |
|
177 | - * |
|
178 | - * @return int The customer id. |
|
179 | - */ |
|
180 | - protected function get_submission_customer() { |
|
181 | - $submission = $this->payment_form_submission; |
|
182 | - |
|
183 | - // If this is an existing invoice... |
|
184 | - if ( $submission->has_invoice() ) { |
|
185 | - return $submission->get_invoice()->get_user_id(); |
|
186 | - } |
|
187 | - |
|
188 | - // (Maybe) create the user. |
|
169 | + } |
|
170 | + |
|
171 | + getpaid_maybe_add_default_address( $invoice ); |
|
172 | + return $invoice; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Retrieves the submission's customer. |
|
177 | + * |
|
178 | + * @return int The customer id. |
|
179 | + */ |
|
180 | + protected function get_submission_customer() { |
|
181 | + $submission = $this->payment_form_submission; |
|
182 | + |
|
183 | + // If this is an existing invoice... |
|
184 | + if ( $submission->has_invoice() ) { |
|
185 | + return $submission->get_invoice()->get_user_id(); |
|
186 | + } |
|
187 | + |
|
188 | + // (Maybe) create the user. |
|
189 | 189 | $user = get_current_user_id(); |
190 | 190 | |
191 | 191 | if ( empty( $user ) ) { |
@@ -202,31 +202,31 @@ discard block |
||
202 | 202 | |
203 | 203 | if ( is_numeric( $user ) ) { |
204 | 204 | return $user; |
205 | - } |
|
205 | + } |
|
206 | 206 | |
207 | - return $user->ID; |
|
207 | + return $user->ID; |
|
208 | 208 | |
209 | - } |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
211 | + /** |
|
212 | 212 | * Prepares submission data for saving to the database. |
213 | 213 | * |
214 | - * @return array |
|
214 | + * @return array |
|
215 | 215 | */ |
216 | 216 | public function prepare_submission_data_for_saving() { |
217 | 217 | |
218 | - $submission = $this->payment_form_submission; |
|
218 | + $submission = $this->payment_form_submission; |
|
219 | 219 | |
220 | - // Prepared submission details. |
|
220 | + // Prepared submission details. |
|
221 | 221 | $prepared = array(); |
222 | 222 | |
223 | 223 | // Raw submission details. |
224 | - $data = $submission->get_data(); |
|
224 | + $data = $submission->get_data(); |
|
225 | 225 | |
226 | - // Loop through the submitted details. |
|
226 | + // Loop through the submitted details. |
|
227 | 227 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
228 | 228 | |
229 | - // Skip premade fields. |
|
229 | + // Skip premade fields. |
|
230 | 230 | if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) { |
231 | 231 | continue; |
232 | 232 | } |
@@ -244,176 +244,176 @@ discard block |
||
244 | 244 | $label = $field['label']; |
245 | 245 | } |
246 | 246 | |
247 | - $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] ); |
|
247 | + $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] ); |
|
248 | 248 | |
249 | 249 | } |
250 | 250 | |
251 | - } |
|
251 | + } |
|
252 | 252 | |
253 | - return $prepared; |
|
253 | + return $prepared; |
|
254 | 254 | |
255 | - } |
|
255 | + } |
|
256 | 256 | |
257 | - /** |
|
257 | + /** |
|
258 | 258 | * Retrieves address details. |
259 | 259 | * |
260 | - * @return array |
|
261 | - * @param WPInv_Invoice $invoice |
|
262 | - * @param string $type |
|
260 | + * @return array |
|
261 | + * @param WPInv_Invoice $invoice |
|
262 | + * @param string $type |
|
263 | 263 | */ |
264 | 264 | public function prepare_address_details( $invoice, $type = 'billing' ) { |
265 | 265 | |
266 | - $data = $this->payment_form_submission->get_data(); |
|
267 | - $type = sanitize_key( $type ); |
|
268 | - $address = array(); |
|
269 | - $prepared = array(); |
|
266 | + $data = $this->payment_form_submission->get_data(); |
|
267 | + $type = sanitize_key( $type ); |
|
268 | + $address = array(); |
|
269 | + $prepared = array(); |
|
270 | 270 | |
271 | - if ( ! empty( $data[ $type ] ) ) { |
|
272 | - $address = $data[ $type ]; |
|
273 | - } |
|
271 | + if ( ! empty( $data[ $type ] ) ) { |
|
272 | + $address = $data[ $type ]; |
|
273 | + } |
|
274 | 274 | |
275 | - // Clean address details. |
|
276 | - foreach ( $address as $key => $value ) { |
|
277 | - $key = sanitize_key( $key ); |
|
278 | - $key = str_replace( 'wpinv_', '', $key ); |
|
279 | - $value = wpinv_clean( $value ); |
|
280 | - $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
281 | - } |
|
275 | + // Clean address details. |
|
276 | + foreach ( $address as $key => $value ) { |
|
277 | + $key = sanitize_key( $key ); |
|
278 | + $key = str_replace( 'wpinv_', '', $key ); |
|
279 | + $value = wpinv_clean( $value ); |
|
280 | + $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
281 | + } |
|
282 | 282 | |
283 | - // Filter address details. |
|
284 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
283 | + // Filter address details. |
|
284 | + $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
285 | 285 | |
286 | - // Remove non-whitelisted values. |
|
287 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
286 | + // Remove non-whitelisted values. |
|
287 | + return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
288 | 288 | |
289 | - } |
|
289 | + } |
|
290 | 290 | |
291 | - /** |
|
291 | + /** |
|
292 | 292 | * Prepares the billing details. |
293 | 293 | * |
294 | - * @return array |
|
295 | - * @param WPInv_Invoice $invoice |
|
294 | + * @return array |
|
295 | + * @param WPInv_Invoice $invoice |
|
296 | 296 | */ |
297 | 297 | protected function prepare_billing_info( &$invoice ) { |
298 | 298 | |
299 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
299 | + $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
300 | 300 | |
301 | - // Update the invoice with the billing details. |
|
302 | - $invoice->set_props( $billing_address ); |
|
301 | + // Update the invoice with the billing details. |
|
302 | + $invoice->set_props( $billing_address ); |
|
303 | 303 | |
304 | - } |
|
304 | + } |
|
305 | 305 | |
306 | - /** |
|
306 | + /** |
|
307 | 307 | * Prepares the shipping details. |
308 | 308 | * |
309 | - * @return array |
|
310 | - * @param WPInv_Invoice $invoice |
|
309 | + * @return array |
|
310 | + * @param WPInv_Invoice $invoice |
|
311 | 311 | */ |
312 | 312 | protected function prepare_shipping_info( $invoice ) { |
313 | 313 | |
314 | - $data = $this->payment_form_submission->get_data(); |
|
314 | + $data = $this->payment_form_submission->get_data(); |
|
315 | 315 | |
316 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
317 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
318 | - } |
|
316 | + if ( empty( $data['same-shipping-address'] ) ) { |
|
317 | + return $this->prepare_address_details( $invoice, 'shipping' ); |
|
318 | + } |
|
319 | 319 | |
320 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
320 | + return $this->prepare_address_details( $invoice, 'billing' ); |
|
321 | 321 | |
322 | - } |
|
322 | + } |
|
323 | 323 | |
324 | - /** |
|
325 | - * Confirms the submission is valid and send users to the gateway. |
|
326 | - * |
|
327 | - * @param WPInv_Invoice $invoice |
|
328 | - * @param array $prepared_payment_form_data |
|
329 | - * @param array $shipping |
|
330 | - */ |
|
331 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
324 | + /** |
|
325 | + * Confirms the submission is valid and send users to the gateway. |
|
326 | + * |
|
327 | + * @param WPInv_Invoice $invoice |
|
328 | + * @param array $prepared_payment_form_data |
|
329 | + * @param array $shipping |
|
330 | + */ |
|
331 | + protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
332 | 332 | |
333 | - // Ensure the invoice exists. |
|
333 | + // Ensure the invoice exists. |
|
334 | 334 | if ( ! $invoice->exists() ) { |
335 | 335 | wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
336 | 336 | } |
337 | 337 | |
338 | - // Save payment form data. |
|
339 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
338 | + // Save payment form data. |
|
339 | + $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
340 | 340 | if ( ! empty( $prepared_payment_form_data ) ) { |
341 | 341 | update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data ); |
342 | - } |
|
342 | + } |
|
343 | 343 | |
344 | - // Save payment form data. |
|
344 | + // Save payment form data. |
|
345 | 345 | if ( ! empty( $shipping ) ) { |
346 | 346 | update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
347 | - } |
|
347 | + } |
|
348 | 348 | |
349 | - // Backwards compatibility. |
|
349 | + // Backwards compatibility. |
|
350 | 350 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
351 | 351 | |
352 | - $this->process_payment( $invoice ); |
|
352 | + $this->process_payment( $invoice ); |
|
353 | 353 | |
354 | 354 | // If we are here, there was an error. |
355 | - wpinv_send_back_to_checkout( $invoice ); |
|
355 | + wpinv_send_back_to_checkout( $invoice ); |
|
356 | 356 | |
357 | - } |
|
357 | + } |
|
358 | 358 | |
359 | - /** |
|
360 | - * Processes the actual payment. |
|
361 | - * |
|
362 | - * @param WPInv_Invoice $invoice |
|
363 | - */ |
|
364 | - protected function process_payment( $invoice ) { |
|
359 | + /** |
|
360 | + * Processes the actual payment. |
|
361 | + * |
|
362 | + * @param WPInv_Invoice $invoice |
|
363 | + */ |
|
364 | + protected function process_payment( $invoice ) { |
|
365 | 365 | |
366 | - // Clear any checkout errors. |
|
367 | - wpinv_clear_errors(); |
|
366 | + // Clear any checkout errors. |
|
367 | + wpinv_clear_errors(); |
|
368 | 368 | |
369 | - // No need to send free invoices to the gateway. |
|
370 | - if ( $invoice->is_free() ) { |
|
371 | - $this->process_free_payment( $invoice ); |
|
372 | - } |
|
369 | + // No need to send free invoices to the gateway. |
|
370 | + if ( $invoice->is_free() ) { |
|
371 | + $this->process_free_payment( $invoice ); |
|
372 | + } |
|
373 | 373 | |
374 | - $submission = $this->payment_form_submission; |
|
374 | + $submission = $this->payment_form_submission; |
|
375 | 375 | |
376 | - // Fires before sending to the gateway. |
|
377 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
376 | + // Fires before sending to the gateway. |
|
377 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
378 | 378 | |
379 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
380 | - $submission_data = $submission->get_data(); |
|
381 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
382 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
379 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
380 | + $submission_data = $submission->get_data(); |
|
381 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
382 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
383 | 383 | |
384 | - // Validate the currency. |
|
385 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
386 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
387 | - } |
|
384 | + // Validate the currency. |
|
385 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
386 | + wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
387 | + } |
|
388 | 388 | |
389 | - // Check to see if we have any errors. |
|
390 | - if ( wpinv_get_errors() ) { |
|
391 | - wpinv_send_back_to_checkout( $invoice ); |
|
392 | - } |
|
389 | + // Check to see if we have any errors. |
|
390 | + if ( wpinv_get_errors() ) { |
|
391 | + wpinv_send_back_to_checkout( $invoice ); |
|
392 | + } |
|
393 | 393 | |
394 | - // Send info to the gateway for payment processing |
|
395 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
394 | + // Send info to the gateway for payment processing |
|
395 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
396 | 396 | |
397 | - // Backwards compatibility. |
|
398 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
397 | + // Backwards compatibility. |
|
398 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
399 | 399 | |
400 | - } |
|
400 | + } |
|
401 | 401 | |
402 | - /** |
|
403 | - * Marks the invoice as paid in case the checkout is free. |
|
404 | - * |
|
405 | - * @param WPInv_Invoice $invoice |
|
406 | - */ |
|
407 | - protected function process_free_payment( $invoice ) { |
|
402 | + /** |
|
403 | + * Marks the invoice as paid in case the checkout is free. |
|
404 | + * |
|
405 | + * @param WPInv_Invoice $invoice |
|
406 | + */ |
|
407 | + protected function process_free_payment( $invoice ) { |
|
408 | 408 | |
409 | - $invoice->set_gateway( 'none' ); |
|
410 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
411 | - $invoice->mark_paid(); |
|
412 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
409 | + $invoice->set_gateway( 'none' ); |
|
410 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
411 | + $invoice->mark_paid(); |
|
412 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
413 | 413 | |
414 | - } |
|
414 | + } |
|
415 | 415 | |
416 | - /** |
|
416 | + /** |
|
417 | 417 | * Sends a redrect response to payment details. |
418 | 418 | * |
419 | 419 | */ |
@@ -20,214 +20,214 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class GetPaid_Installer { |
22 | 22 | |
23 | - /** |
|
24 | - * Upgrades the install. |
|
25 | - * |
|
26 | - * @param string $upgrade_from The current invoicing version. |
|
27 | - */ |
|
28 | - public function upgrade_db( $upgrade_from ) { |
|
29 | - |
|
30 | - // Save the current invoicing version. |
|
31 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
32 | - |
|
33 | - // Setup the invoice Custom Post Type. |
|
34 | - GetPaid_Post_Types::register_post_types(); |
|
35 | - |
|
36 | - // Clear the permalinks |
|
37 | - flush_rewrite_rules(); |
|
38 | - |
|
39 | - // Maybe create new/missing pages. |
|
40 | - $this->create_pages(); |
|
41 | - |
|
42 | - // Maybe re(add) admin capabilities. |
|
43 | - $this->add_capabilities(); |
|
44 | - |
|
45 | - // Maybe create the default payment form. |
|
46 | - wpinv_get_default_payment_form(); |
|
47 | - |
|
48 | - // Create any missing database tables. |
|
49 | - $method = "upgrade_from_$upgrade_from"; |
|
50 | - |
|
51 | - if ( method_exists( $this, $method ) ) { |
|
52 | - $this->$method(); |
|
53 | - } |
|
54 | - |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Do a fresh install. |
|
59 | - * |
|
60 | - */ |
|
61 | - public function upgrade_from_0() { |
|
62 | - $this->create_subscriptions_table(); |
|
63 | - $this->create_invoices_table(); |
|
64 | - $this->create_invoice_items_table(); |
|
65 | - |
|
66 | - // Save default tax rates. |
|
67 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Upgrade to 0.0.5 |
|
72 | - * |
|
73 | - */ |
|
74 | - public function upgrade_from_004() { |
|
75 | - global $wpdb; |
|
76 | - |
|
77 | - // Invoices. |
|
78 | - $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
79 | - if ( ! empty( $results ) ) { |
|
80 | - $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
81 | - |
|
82 | - // Clean post cache |
|
83 | - foreach ( $results as $row ) { |
|
84 | - clean_post_cache( $row->ID ); |
|
85 | - } |
|
86 | - |
|
87 | - } |
|
88 | - |
|
89 | - // Item meta key changes |
|
90 | - $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
91 | - $results = $wpdb->get_results( $query ); |
|
92 | - |
|
93 | - if ( ! empty( $results ) ) { |
|
94 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
95 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
96 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
97 | - |
|
98 | - foreach ( $results as $row ) { |
|
99 | - clean_post_cache( $row->post_id ); |
|
100 | - } |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - $this->upgrade_from_102(); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Upgrade to 1.0.3 |
|
109 | - * |
|
110 | - */ |
|
111 | - public function upgrade_from_102() { |
|
112 | - $this->create_subscriptions_table(); |
|
113 | - $this->upgrade_from_118(); |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Upgrade to version 2.0.0. |
|
118 | - * |
|
119 | - */ |
|
120 | - public function upgrade_from_118() { |
|
121 | - $this->create_invoices_table(); |
|
122 | - $this->create_invoice_items_table(); |
|
123 | - $this->migrate_old_invoices(); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Upgrade to version 2.0.8. |
|
128 | - * |
|
129 | - */ |
|
130 | - public function upgrade_from_207() { |
|
131 | - global $wpdb; |
|
132 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" ); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Give administrators the capability to manage GetPaid. |
|
137 | - * |
|
138 | - */ |
|
139 | - public function add_capabilities() { |
|
140 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Re-create GetPaid pages. |
|
145 | - * |
|
146 | - */ |
|
147 | - public function create_pages() { |
|
148 | - |
|
149 | - $pages = apply_filters( |
|
150 | - 'wpinv_create_pages', |
|
151 | - array( |
|
152 | - |
|
153 | - // Checkout page. |
|
154 | - 'checkout_page' => array( |
|
155 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
156 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
157 | - 'content' => ' |
|
23 | + /** |
|
24 | + * Upgrades the install. |
|
25 | + * |
|
26 | + * @param string $upgrade_from The current invoicing version. |
|
27 | + */ |
|
28 | + public function upgrade_db( $upgrade_from ) { |
|
29 | + |
|
30 | + // Save the current invoicing version. |
|
31 | + update_option( 'wpinv_version', WPINV_VERSION ); |
|
32 | + |
|
33 | + // Setup the invoice Custom Post Type. |
|
34 | + GetPaid_Post_Types::register_post_types(); |
|
35 | + |
|
36 | + // Clear the permalinks |
|
37 | + flush_rewrite_rules(); |
|
38 | + |
|
39 | + // Maybe create new/missing pages. |
|
40 | + $this->create_pages(); |
|
41 | + |
|
42 | + // Maybe re(add) admin capabilities. |
|
43 | + $this->add_capabilities(); |
|
44 | + |
|
45 | + // Maybe create the default payment form. |
|
46 | + wpinv_get_default_payment_form(); |
|
47 | + |
|
48 | + // Create any missing database tables. |
|
49 | + $method = "upgrade_from_$upgrade_from"; |
|
50 | + |
|
51 | + if ( method_exists( $this, $method ) ) { |
|
52 | + $this->$method(); |
|
53 | + } |
|
54 | + |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Do a fresh install. |
|
59 | + * |
|
60 | + */ |
|
61 | + public function upgrade_from_0() { |
|
62 | + $this->create_subscriptions_table(); |
|
63 | + $this->create_invoices_table(); |
|
64 | + $this->create_invoice_items_table(); |
|
65 | + |
|
66 | + // Save default tax rates. |
|
67 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Upgrade to 0.0.5 |
|
72 | + * |
|
73 | + */ |
|
74 | + public function upgrade_from_004() { |
|
75 | + global $wpdb; |
|
76 | + |
|
77 | + // Invoices. |
|
78 | + $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
79 | + if ( ! empty( $results ) ) { |
|
80 | + $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
81 | + |
|
82 | + // Clean post cache |
|
83 | + foreach ( $results as $row ) { |
|
84 | + clean_post_cache( $row->ID ); |
|
85 | + } |
|
86 | + |
|
87 | + } |
|
88 | + |
|
89 | + // Item meta key changes |
|
90 | + $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
91 | + $results = $wpdb->get_results( $query ); |
|
92 | + |
|
93 | + if ( ! empty( $results ) ) { |
|
94 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
95 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
96 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
97 | + |
|
98 | + foreach ( $results as $row ) { |
|
99 | + clean_post_cache( $row->post_id ); |
|
100 | + } |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + $this->upgrade_from_102(); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Upgrade to 1.0.3 |
|
109 | + * |
|
110 | + */ |
|
111 | + public function upgrade_from_102() { |
|
112 | + $this->create_subscriptions_table(); |
|
113 | + $this->upgrade_from_118(); |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Upgrade to version 2.0.0. |
|
118 | + * |
|
119 | + */ |
|
120 | + public function upgrade_from_118() { |
|
121 | + $this->create_invoices_table(); |
|
122 | + $this->create_invoice_items_table(); |
|
123 | + $this->migrate_old_invoices(); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Upgrade to version 2.0.8. |
|
128 | + * |
|
129 | + */ |
|
130 | + public function upgrade_from_207() { |
|
131 | + global $wpdb; |
|
132 | + $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" ); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Give administrators the capability to manage GetPaid. |
|
137 | + * |
|
138 | + */ |
|
139 | + public function add_capabilities() { |
|
140 | + $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Re-create GetPaid pages. |
|
145 | + * |
|
146 | + */ |
|
147 | + public function create_pages() { |
|
148 | + |
|
149 | + $pages = apply_filters( |
|
150 | + 'wpinv_create_pages', |
|
151 | + array( |
|
152 | + |
|
153 | + // Checkout page. |
|
154 | + 'checkout_page' => array( |
|
155 | + 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
156 | + 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
157 | + 'content' => ' |
|
158 | 158 | <!-- wp:shortcode --> |
159 | 159 | [wpinv_checkout] |
160 | 160 | <!-- /wp:shortcode --> |
161 | 161 | ', |
162 | - 'parent' => '', |
|
163 | - ), |
|
164 | - |
|
165 | - // Invoice history page. |
|
166 | - 'invoice_history_page' => array( |
|
167 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
168 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
169 | - 'content' => ' |
|
162 | + 'parent' => '', |
|
163 | + ), |
|
164 | + |
|
165 | + // Invoice history page. |
|
166 | + 'invoice_history_page' => array( |
|
167 | + 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
168 | + 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
169 | + 'content' => ' |
|
170 | 170 | <!-- wp:shortcode --> |
171 | 171 | [wpinv_history] |
172 | 172 | <!-- /wp:shortcode --> |
173 | 173 | ', |
174 | - 'parent' => '', |
|
175 | - ), |
|
176 | - |
|
177 | - // Success page content. |
|
178 | - 'success_page' => array( |
|
179 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
180 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
181 | - 'content' => ' |
|
174 | + 'parent' => '', |
|
175 | + ), |
|
176 | + |
|
177 | + // Success page content. |
|
178 | + 'success_page' => array( |
|
179 | + 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
180 | + 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
181 | + 'content' => ' |
|
182 | 182 | <!-- wp:shortcode --> |
183 | 183 | [wpinv_receipt] |
184 | 184 | <!-- /wp:shortcode --> |
185 | 185 | ', |
186 | - 'parent' => 'gp-checkout', |
|
187 | - ), |
|
188 | - |
|
189 | - // Failure page content. |
|
190 | - 'failure_page' => array( |
|
191 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
192 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
193 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
194 | - 'parent' => 'gp-checkout', |
|
195 | - ), |
|
196 | - |
|
197 | - // Subscriptions history page. |
|
198 | - 'invoice_subscription_page' => array( |
|
199 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
200 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
201 | - 'content' => ' |
|
186 | + 'parent' => 'gp-checkout', |
|
187 | + ), |
|
188 | + |
|
189 | + // Failure page content. |
|
190 | + 'failure_page' => array( |
|
191 | + 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
192 | + 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
193 | + 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
194 | + 'parent' => 'gp-checkout', |
|
195 | + ), |
|
196 | + |
|
197 | + // Subscriptions history page. |
|
198 | + 'invoice_subscription_page' => array( |
|
199 | + 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
200 | + 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
201 | + 'content' => ' |
|
202 | 202 | <!-- wp:shortcode --> |
203 | 203 | [wpinv_subscriptions] |
204 | 204 | <!-- /wp:shortcode --> |
205 | 205 | ', |
206 | - 'parent' => '', |
|
207 | - ), |
|
206 | + 'parent' => '', |
|
207 | + ), |
|
208 | 208 | |
209 | - ) |
|
210 | - ); |
|
209 | + ) |
|
210 | + ); |
|
211 | 211 | |
212 | - foreach ( $pages as $key => $page ) { |
|
213 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
214 | - } |
|
212 | + foreach ( $pages as $key => $page ) { |
|
213 | + wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
214 | + } |
|
215 | 215 | |
216 | - } |
|
216 | + } |
|
217 | 217 | |
218 | - /** |
|
219 | - * Create subscriptions table. |
|
220 | - * |
|
221 | - */ |
|
222 | - public function create_subscriptions_table() { |
|
218 | + /** |
|
219 | + * Create subscriptions table. |
|
220 | + * |
|
221 | + */ |
|
222 | + public function create_subscriptions_table() { |
|
223 | 223 | |
224 | - global $wpdb; |
|
224 | + global $wpdb; |
|
225 | 225 | |
226 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
226 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
227 | 227 | |
228 | - // Create tables. |
|
229 | - $charset_collate = $wpdb->get_charset_collate(); |
|
230 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions ( |
|
228 | + // Create tables. |
|
229 | + $charset_collate = $wpdb->get_charset_collate(); |
|
230 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions ( |
|
231 | 231 | id bigint(20) unsigned NOT NULL auto_increment, |
232 | 232 | customer_id bigint(20) NOT NULL, |
233 | 233 | frequency int(11) NOT NULL DEFAULT '1', |
@@ -250,22 +250,22 @@ discard block |
||
250 | 250 | KEY customer_and_status (customer_id, status) |
251 | 251 | ) $charset_collate;"; |
252 | 252 | |
253 | - dbDelta( $sql ); |
|
253 | + dbDelta( $sql ); |
|
254 | 254 | |
255 | - } |
|
255 | + } |
|
256 | 256 | |
257 | - /** |
|
258 | - * Create invoices table. |
|
259 | - * |
|
260 | - */ |
|
261 | - public function create_invoices_table() { |
|
262 | - global $wpdb; |
|
257 | + /** |
|
258 | + * Create invoices table. |
|
259 | + * |
|
260 | + */ |
|
261 | + public function create_invoices_table() { |
|
262 | + global $wpdb; |
|
263 | 263 | |
264 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
264 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
265 | 265 | |
266 | - // Create tables. |
|
267 | - $charset_collate = $wpdb->get_charset_collate(); |
|
268 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices ( |
|
266 | + // Create tables. |
|
267 | + $charset_collate = $wpdb->get_charset_collate(); |
|
268 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices ( |
|
269 | 269 | post_id BIGINT(20) NOT NULL, |
270 | 270 | `number` VARCHAR(100), |
271 | 271 | `key` VARCHAR(100), |
@@ -301,22 +301,22 @@ discard block |
||
301 | 301 | KEY `key` (`key`) |
302 | 302 | ) $charset_collate;"; |
303 | 303 | |
304 | - dbDelta( $sql ); |
|
304 | + dbDelta( $sql ); |
|
305 | 305 | |
306 | - } |
|
306 | + } |
|
307 | 307 | |
308 | - /** |
|
309 | - * Create invoice items table. |
|
310 | - * |
|
311 | - */ |
|
312 | - public function create_invoice_items_table() { |
|
313 | - global $wpdb; |
|
308 | + /** |
|
309 | + * Create invoice items table. |
|
310 | + * |
|
311 | + */ |
|
312 | + public function create_invoice_items_table() { |
|
313 | + global $wpdb; |
|
314 | 314 | |
315 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
315 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
316 | 316 | |
317 | - // Create tables. |
|
318 | - $charset_collate = $wpdb->get_charset_collate(); |
|
319 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items ( |
|
317 | + // Create tables. |
|
318 | + $charset_collate = $wpdb->get_charset_collate(); |
|
319 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items ( |
|
320 | 320 | ID BIGINT(20) NOT NULL AUTO_INCREMENT, |
321 | 321 | post_id BIGINT(20) NOT NULL, |
322 | 322 | item_id BIGINT(20) NOT NULL, |
@@ -338,139 +338,139 @@ discard block |
||
338 | 338 | KEY post_id (post_id) |
339 | 339 | ) $charset_collate;"; |
340 | 340 | |
341 | - dbDelta( $sql ); |
|
342 | - |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Migrates old invoices to new invoices. |
|
347 | - * |
|
348 | - */ |
|
349 | - public function migrate_old_invoices() { |
|
350 | - global $wpdb; |
|
351 | - |
|
352 | - $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
353 | - $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
354 | - $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
355 | - $invoices = array_unique( |
|
356 | - get_posts( |
|
357 | - array( |
|
358 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
359 | - 'posts_per_page' => -1, |
|
360 | - 'fields' => 'ids', |
|
361 | - 'post_status' => array_keys( get_post_stati() ), |
|
362 | - 'exclude' => (array) $migrated, |
|
363 | - ) |
|
364 | - ) |
|
365 | - ); |
|
366 | - |
|
367 | - // Abort if we do not have any invoices. |
|
368 | - if ( empty( $invoices ) ) { |
|
369 | - return; |
|
370 | - } |
|
371 | - |
|
372 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' ); |
|
373 | - |
|
374 | - $invoice_rows = array(); |
|
375 | - foreach ( $invoices as $invoice ) { |
|
376 | - |
|
377 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
378 | - |
|
379 | - if ( empty( $invoice->ID ) ) { |
|
380 | - return; |
|
381 | - } |
|
382 | - |
|
383 | - $fields = array ( |
|
384 | - 'post_id' => $invoice->ID, |
|
385 | - 'number' => $invoice->get_number(), |
|
386 | - 'key' => $invoice->get_key(), |
|
387 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
388 | - 'mode' => $invoice->mode, |
|
389 | - 'user_ip' => $invoice->get_ip(), |
|
390 | - 'first_name' => $invoice->get_first_name(), |
|
391 | - 'last_name' => $invoice->get_last_name(), |
|
392 | - 'address' => $invoice->get_address(), |
|
393 | - 'city' => $invoice->city, |
|
394 | - 'state' => $invoice->state, |
|
395 | - 'country' => $invoice->country, |
|
396 | - 'zip' => $invoice->zip, |
|
397 | - 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
398 | - 'gateway' => $invoice->get_gateway(), |
|
399 | - 'transaction_id' => $invoice->get_transaction_id(), |
|
400 | - 'currency' => $invoice->get_currency(), |
|
401 | - 'subtotal' => $invoice->get_subtotal(), |
|
402 | - 'tax' => $invoice->get_tax(), |
|
403 | - 'fees_total' => $invoice->get_fees_total(), |
|
404 | - 'total' => $invoice->get_total(), |
|
405 | - 'discount' => $invoice->get_discount(), |
|
406 | - 'discount_code' => $invoice->get_discount_code(), |
|
407 | - 'disable_taxes' => $invoice->disable_taxes, |
|
408 | - 'due_date' => $invoice->get_due_date(), |
|
409 | - 'completed_date' => $invoice->get_completed_date(), |
|
410 | - 'company' => $invoice->company, |
|
411 | - 'vat_number' => $invoice->vat_number, |
|
412 | - 'vat_rate' => $invoice->vat_rate, |
|
413 | - 'custom_meta' => $invoice->payment_meta |
|
414 | - ); |
|
415 | - |
|
416 | - foreach ( $fields as $key => $val ) { |
|
417 | - if ( is_null( $val ) ) { |
|
418 | - $val = ''; |
|
419 | - } |
|
420 | - $val = maybe_serialize( $val ); |
|
421 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
422 | - } |
|
423 | - |
|
424 | - $fields = implode( ', ', $fields ); |
|
425 | - $invoice_rows[] = "($fields)"; |
|
426 | - |
|
427 | - $item_rows = array(); |
|
428 | - $item_columns = array(); |
|
429 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
430 | - $fields = array( |
|
431 | - 'post_id' => $invoice->ID, |
|
432 | - 'item_id' => $details['id'], |
|
433 | - 'item_name' => $details['name'], |
|
434 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
435 | - 'vat_rate' => $details['vat_rate'], |
|
436 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
437 | - 'tax' => $details['tax'], |
|
438 | - 'item_price' => $details['item_price'], |
|
439 | - 'custom_price' => $details['custom_price'], |
|
440 | - 'quantity' => $details['quantity'], |
|
441 | - 'discount' => $details['discount'], |
|
442 | - 'subtotal' => $details['subtotal'], |
|
443 | - 'price' => $details['price'], |
|
444 | - 'meta' => $details['meta'], |
|
445 | - 'fees' => $details['fees'], |
|
446 | - ); |
|
447 | - |
|
448 | - $item_columns = array_keys ( $fields ); |
|
449 | - |
|
450 | - foreach ( $fields as $key => $val ) { |
|
451 | - if ( is_null( $val ) ) { |
|
452 | - $val = ''; |
|
453 | - } |
|
454 | - $val = maybe_serialize( $val ); |
|
455 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
456 | - } |
|
457 | - |
|
458 | - $fields = implode( ', ', $fields ); |
|
459 | - $item_rows[] = "($fields)"; |
|
460 | - } |
|
461 | - |
|
462 | - $item_rows = implode( ', ', $item_rows ); |
|
463 | - $item_columns = implode( ', ', $item_columns ); |
|
464 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
465 | - } |
|
466 | - |
|
467 | - if ( empty( $invoice_rows ) ) { |
|
468 | - return; |
|
469 | - } |
|
470 | - |
|
471 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
472 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
473 | - |
|
474 | - } |
|
341 | + dbDelta( $sql ); |
|
342 | + |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Migrates old invoices to new invoices. |
|
347 | + * |
|
348 | + */ |
|
349 | + public function migrate_old_invoices() { |
|
350 | + global $wpdb; |
|
351 | + |
|
352 | + $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
353 | + $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
354 | + $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
355 | + $invoices = array_unique( |
|
356 | + get_posts( |
|
357 | + array( |
|
358 | + 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
359 | + 'posts_per_page' => -1, |
|
360 | + 'fields' => 'ids', |
|
361 | + 'post_status' => array_keys( get_post_stati() ), |
|
362 | + 'exclude' => (array) $migrated, |
|
363 | + ) |
|
364 | + ) |
|
365 | + ); |
|
366 | + |
|
367 | + // Abort if we do not have any invoices. |
|
368 | + if ( empty( $invoices ) ) { |
|
369 | + return; |
|
370 | + } |
|
371 | + |
|
372 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' ); |
|
373 | + |
|
374 | + $invoice_rows = array(); |
|
375 | + foreach ( $invoices as $invoice ) { |
|
376 | + |
|
377 | + $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
378 | + |
|
379 | + if ( empty( $invoice->ID ) ) { |
|
380 | + return; |
|
381 | + } |
|
382 | + |
|
383 | + $fields = array ( |
|
384 | + 'post_id' => $invoice->ID, |
|
385 | + 'number' => $invoice->get_number(), |
|
386 | + 'key' => $invoice->get_key(), |
|
387 | + 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
388 | + 'mode' => $invoice->mode, |
|
389 | + 'user_ip' => $invoice->get_ip(), |
|
390 | + 'first_name' => $invoice->get_first_name(), |
|
391 | + 'last_name' => $invoice->get_last_name(), |
|
392 | + 'address' => $invoice->get_address(), |
|
393 | + 'city' => $invoice->city, |
|
394 | + 'state' => $invoice->state, |
|
395 | + 'country' => $invoice->country, |
|
396 | + 'zip' => $invoice->zip, |
|
397 | + 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
398 | + 'gateway' => $invoice->get_gateway(), |
|
399 | + 'transaction_id' => $invoice->get_transaction_id(), |
|
400 | + 'currency' => $invoice->get_currency(), |
|
401 | + 'subtotal' => $invoice->get_subtotal(), |
|
402 | + 'tax' => $invoice->get_tax(), |
|
403 | + 'fees_total' => $invoice->get_fees_total(), |
|
404 | + 'total' => $invoice->get_total(), |
|
405 | + 'discount' => $invoice->get_discount(), |
|
406 | + 'discount_code' => $invoice->get_discount_code(), |
|
407 | + 'disable_taxes' => $invoice->disable_taxes, |
|
408 | + 'due_date' => $invoice->get_due_date(), |
|
409 | + 'completed_date' => $invoice->get_completed_date(), |
|
410 | + 'company' => $invoice->company, |
|
411 | + 'vat_number' => $invoice->vat_number, |
|
412 | + 'vat_rate' => $invoice->vat_rate, |
|
413 | + 'custom_meta' => $invoice->payment_meta |
|
414 | + ); |
|
415 | + |
|
416 | + foreach ( $fields as $key => $val ) { |
|
417 | + if ( is_null( $val ) ) { |
|
418 | + $val = ''; |
|
419 | + } |
|
420 | + $val = maybe_serialize( $val ); |
|
421 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
422 | + } |
|
423 | + |
|
424 | + $fields = implode( ', ', $fields ); |
|
425 | + $invoice_rows[] = "($fields)"; |
|
426 | + |
|
427 | + $item_rows = array(); |
|
428 | + $item_columns = array(); |
|
429 | + foreach ( $invoice->get_cart_details() as $details ) { |
|
430 | + $fields = array( |
|
431 | + 'post_id' => $invoice->ID, |
|
432 | + 'item_id' => $details['id'], |
|
433 | + 'item_name' => $details['name'], |
|
434 | + 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
435 | + 'vat_rate' => $details['vat_rate'], |
|
436 | + 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
437 | + 'tax' => $details['tax'], |
|
438 | + 'item_price' => $details['item_price'], |
|
439 | + 'custom_price' => $details['custom_price'], |
|
440 | + 'quantity' => $details['quantity'], |
|
441 | + 'discount' => $details['discount'], |
|
442 | + 'subtotal' => $details['subtotal'], |
|
443 | + 'price' => $details['price'], |
|
444 | + 'meta' => $details['meta'], |
|
445 | + 'fees' => $details['fees'], |
|
446 | + ); |
|
447 | + |
|
448 | + $item_columns = array_keys ( $fields ); |
|
449 | + |
|
450 | + foreach ( $fields as $key => $val ) { |
|
451 | + if ( is_null( $val ) ) { |
|
452 | + $val = ''; |
|
453 | + } |
|
454 | + $val = maybe_serialize( $val ); |
|
455 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
456 | + } |
|
457 | + |
|
458 | + $fields = implode( ', ', $fields ); |
|
459 | + $item_rows[] = "($fields)"; |
|
460 | + } |
|
461 | + |
|
462 | + $item_rows = implode( ', ', $item_rows ); |
|
463 | + $item_columns = implode( ', ', $item_columns ); |
|
464 | + $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
465 | + } |
|
466 | + |
|
467 | + if ( empty( $invoice_rows ) ) { |
|
468 | + return; |
|
469 | + } |
|
470 | + |
|
471 | + $invoice_rows = implode( ', ', $invoice_rows ); |
|
472 | + $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
473 | + |
|
474 | + } |
|
475 | 475 | |
476 | 476 | } |