@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * Checks if the current user cna view an invoice receipt. |
68 | 68 | */ |
69 | 69 | function wpinv_can_view_receipt( $invoice ) { |
70 | - return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice ); |
|
70 | + return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice ); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -556,37 +556,37 @@ discard block |
||
556 | 556 | $label = empty( $label ) ? __( 'Invoice', 'invoicing' ) : sanitize_text_field( $label ); |
557 | 557 | $columns = array( |
558 | 558 | |
559 | - 'invoice-number' => array( |
|
560 | - 'title' => $label, |
|
561 | - 'class' => 'text-left', |
|
562 | - ), |
|
559 | + 'invoice-number' => array( |
|
560 | + 'title' => $label, |
|
561 | + 'class' => 'text-left', |
|
562 | + ), |
|
563 | 563 | |
564 | - 'created-date' => array( |
|
565 | - 'title' => __( 'Created Date', 'invoicing' ), |
|
566 | - 'class' => 'text-left', |
|
567 | - ), |
|
564 | + 'created-date' => array( |
|
565 | + 'title' => __( 'Created Date', 'invoicing' ), |
|
566 | + 'class' => 'text-left', |
|
567 | + ), |
|
568 | 568 | |
569 | - 'payment-date' => array( |
|
570 | - 'title' => __( 'Payment Date', 'invoicing' ), |
|
571 | - 'class' => 'text-left', |
|
572 | - ), |
|
569 | + 'payment-date' => array( |
|
570 | + 'title' => __( 'Payment Date', 'invoicing' ), |
|
571 | + 'class' => 'text-left', |
|
572 | + ), |
|
573 | 573 | |
574 | - 'invoice-status' => array( |
|
575 | - 'title' => __( 'Status', 'invoicing' ), |
|
576 | - 'class' => 'text-center', |
|
577 | - ), |
|
574 | + 'invoice-status' => array( |
|
575 | + 'title' => __( 'Status', 'invoicing' ), |
|
576 | + 'class' => 'text-center', |
|
577 | + ), |
|
578 | 578 | |
579 | - 'invoice-total' => array( |
|
580 | - 'title' => __( 'Total', 'invoicing' ), |
|
581 | - 'class' => 'text-right', |
|
582 | - ), |
|
579 | + 'invoice-total' => array( |
|
580 | + 'title' => __( 'Total', 'invoicing' ), |
|
581 | + 'class' => 'text-right', |
|
582 | + ), |
|
583 | 583 | |
584 | - 'invoice-actions' => array( |
|
585 | - 'title' => ' ', |
|
586 | - 'class' => 'text-center', |
|
587 | - ), |
|
584 | + 'invoice-actions' => array( |
|
585 | + 'title' => ' ', |
|
586 | + 'class' => 'text-center', |
|
587 | + ), |
|
588 | 588 | |
589 | - ); |
|
589 | + ); |
|
590 | 590 | |
591 | 591 | return apply_filters( 'wpinv_user_invoices_columns', $columns, $post_type ); |
592 | 592 | } |
@@ -1274,22 +1274,22 @@ discard block |
||
1274 | 1274 | */ |
1275 | 1275 | function getpaid_get_invoice_status_classes() { |
1276 | 1276 | |
1277 | - return apply_filters( |
|
1278 | - 'getpaid_get_invoice_status_classes', |
|
1279 | - array( |
|
1277 | + return apply_filters( |
|
1278 | + 'getpaid_get_invoice_status_classes', |
|
1279 | + array( |
|
1280 | 1280 | 'wpi-quote-declined' => 'bg-danger', |
1281 | 1281 | 'wpi-failed' => 'bg-danger', |
1282 | - 'wpi-processing' => 'bg-info', |
|
1283 | - 'wpi-onhold' => 'bg-warning text-dark', |
|
1284 | - 'wpi-quote-accepted' => 'bg-success', |
|
1285 | - 'publish' => 'bg-success', |
|
1286 | - 'wpi-renewal' => 'bg-primary', |
|
1282 | + 'wpi-processing' => 'bg-info', |
|
1283 | + 'wpi-onhold' => 'bg-warning text-dark', |
|
1284 | + 'wpi-quote-accepted' => 'bg-success', |
|
1285 | + 'publish' => 'bg-success', |
|
1286 | + 'wpi-renewal' => 'bg-primary', |
|
1287 | 1287 | 'wpi-cancelled' => 'bg-secondary', |
1288 | 1288 | 'wpi-pending' => 'bg-dark', |
1289 | 1289 | 'wpi-quote-pending' => 'bg-dark', |
1290 | 1290 | 'wpi-refunded' => 'bg-secondary', |
1291 | - ) |
|
1292 | - ); |
|
1291 | + ) |
|
1292 | + ); |
|
1293 | 1293 | |
1294 | 1294 | } |
1295 | 1295 | |
@@ -1303,7 +1303,7 @@ discard block |
||
1303 | 1303 | function getpaid_get_invoice_tax_rate( $invoice, $item ) { |
1304 | 1304 | |
1305 | 1305 | $rates = getpaid_get_item_tax_rates( $item, $invoice->get_country(), $invoice->get_state() ); |
1306 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
1306 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
1307 | 1307 | $rates = wp_list_pluck( $rates, 'rate' ); |
1308 | 1308 | |
1309 | 1309 | return array_sum( $rates ); |
@@ -15,125 +15,125 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class WPInv_Subscription extends GetPaid_Data { |
17 | 17 | |
18 | - /** |
|
19 | - * Which data store to load. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $data_store_name = 'subscription'; |
|
24 | - |
|
25 | - /** |
|
26 | - * This is the name of this object type. |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $object_type = 'subscription'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Item Data array. This is the core item data exposed in APIs. |
|
34 | - * |
|
35 | - * @since 1.0.19 |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - protected $data = array( |
|
39 | - 'customer_id' => 0, |
|
40 | - 'frequency' => 1, |
|
41 | - 'period' => 'D', |
|
42 | - 'initial_amount' => null, |
|
43 | - 'recurring_amount' => null, |
|
44 | - 'bill_times' => 0, |
|
45 | - 'transaction_id' => '', |
|
46 | - 'parent_payment_id' => null, |
|
47 | - 'product_id' => 0, |
|
48 | - 'created' => '0000-00-00 00:00:00', |
|
49 | - 'expiration' => '0000-00-00 00:00:00', |
|
50 | - 'trial_period' => '', |
|
51 | - 'status' => 'pending', |
|
52 | - 'profile_id' => '', |
|
53 | - 'gateway' => '', |
|
54 | - 'customer' => '', |
|
55 | - ); |
|
56 | - |
|
57 | - /** |
|
58 | - * Stores the status transition information. |
|
59 | - * |
|
60 | - * @since 1.0.19 |
|
61 | - * @var bool |
|
62 | - */ |
|
63 | - protected $status_transition = false; |
|
64 | - |
|
65 | - /** |
|
66 | - * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
67 | - * |
|
68 | - * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
69 | - * @param bool $deprecated |
|
70 | - */ |
|
71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
72 | - |
|
73 | - parent::__construct( $subscription ); |
|
74 | - |
|
75 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
76 | - $this->set_id( $subscription ); |
|
77 | - } elseif ( $subscription instanceof self ) { |
|
78 | - $this->set_id( $subscription->get_id() ); |
|
79 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
80 | - $this->set_id( $subscription_id ); |
|
81 | - } elseif ( ! empty( $subscription->id ) ) { |
|
82 | - $this->set_id( $subscription->id ); |
|
83 | - } else { |
|
84 | - $this->set_object_read( true ); |
|
85 | - } |
|
86 | - |
|
87 | - // Load the datastore. |
|
88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
89 | - |
|
90 | - if ( $this->get_id() > 0 ) { |
|
91 | - $this->data_store->read( $this ); |
|
92 | - } |
|
93 | - |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
98 | - * |
|
99 | - * |
|
100 | - * @static |
|
101 | - * @param string $value |
|
102 | - * @param string $field Either invoice_id, transaction_id or profile_id. |
|
103 | - * @since 1.0.19 |
|
104 | - * @return int |
|
105 | - */ |
|
106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
18 | + /** |
|
19 | + * Which data store to load. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $data_store_name = 'subscription'; |
|
24 | + |
|
25 | + /** |
|
26 | + * This is the name of this object type. |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $object_type = 'subscription'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Item Data array. This is the core item data exposed in APIs. |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $data = array( |
|
39 | + 'customer_id' => 0, |
|
40 | + 'frequency' => 1, |
|
41 | + 'period' => 'D', |
|
42 | + 'initial_amount' => null, |
|
43 | + 'recurring_amount' => null, |
|
44 | + 'bill_times' => 0, |
|
45 | + 'transaction_id' => '', |
|
46 | + 'parent_payment_id' => null, |
|
47 | + 'product_id' => 0, |
|
48 | + 'created' => '0000-00-00 00:00:00', |
|
49 | + 'expiration' => '0000-00-00 00:00:00', |
|
50 | + 'trial_period' => '', |
|
51 | + 'status' => 'pending', |
|
52 | + 'profile_id' => '', |
|
53 | + 'gateway' => '', |
|
54 | + 'customer' => '', |
|
55 | + ); |
|
56 | + |
|
57 | + /** |
|
58 | + * Stores the status transition information. |
|
59 | + * |
|
60 | + * @since 1.0.19 |
|
61 | + * @var bool |
|
62 | + */ |
|
63 | + protected $status_transition = false; |
|
64 | + |
|
65 | + /** |
|
66 | + * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
67 | + * |
|
68 | + * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
69 | + * @param bool $deprecated |
|
70 | + */ |
|
71 | + function __construct( $subscription = 0, $deprecated = false ) { |
|
72 | + |
|
73 | + parent::__construct( $subscription ); |
|
74 | + |
|
75 | + if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
76 | + $this->set_id( $subscription ); |
|
77 | + } elseif ( $subscription instanceof self ) { |
|
78 | + $this->set_id( $subscription->get_id() ); |
|
79 | + } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
80 | + $this->set_id( $subscription_id ); |
|
81 | + } elseif ( ! empty( $subscription->id ) ) { |
|
82 | + $this->set_id( $subscription->id ); |
|
83 | + } else { |
|
84 | + $this->set_object_read( true ); |
|
85 | + } |
|
86 | + |
|
87 | + // Load the datastore. |
|
88 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
89 | + |
|
90 | + if ( $this->get_id() > 0 ) { |
|
91 | + $this->data_store->read( $this ); |
|
92 | + } |
|
93 | + |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
98 | + * |
|
99 | + * |
|
100 | + * @static |
|
101 | + * @param string $value |
|
102 | + * @param string $field Either invoice_id, transaction_id or profile_id. |
|
103 | + * @since 1.0.19 |
|
104 | + * @return int |
|
105 | + */ |
|
106 | + public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
107 | 107 | global $wpdb; |
108 | 108 | |
109 | - // Trim the value. |
|
110 | - $value = trim( $value ); |
|
109 | + // Trim the value. |
|
110 | + $value = trim( $value ); |
|
111 | 111 | |
112 | - if ( empty( $value ) ) { |
|
113 | - return 0; |
|
114 | - } |
|
112 | + if ( empty( $value ) ) { |
|
113 | + return 0; |
|
114 | + } |
|
115 | 115 | |
116 | - if ( 'invoice_id' == $field ) { |
|
117 | - $field = 'parent_payment_id'; |
|
118 | - } |
|
116 | + if ( 'invoice_id' == $field ) { |
|
117 | + $field = 'parent_payment_id'; |
|
118 | + } |
|
119 | 119 | |
120 | 120 | // Valid fields. |
121 | 121 | $fields = array( |
122 | - 'parent_payment_id', |
|
123 | - 'transaction_id', |
|
124 | - 'profile_id', |
|
125 | - ); |
|
126 | - |
|
127 | - // Ensure a field has been passed. |
|
128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
129 | - return 0; |
|
130 | - } |
|
131 | - |
|
132 | - // Maybe retrieve from the cache. |
|
133 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
134 | - if ( ! empty( $subscription_id ) ) { |
|
135 | - return $subscription_id; |
|
136 | - } |
|
122 | + 'parent_payment_id', |
|
123 | + 'transaction_id', |
|
124 | + 'profile_id', |
|
125 | + ); |
|
126 | + |
|
127 | + // Ensure a field has been passed. |
|
128 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
129 | + return 0; |
|
130 | + } |
|
131 | + |
|
132 | + // Maybe retrieve from the cache. |
|
133 | + $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
134 | + if ( ! empty( $subscription_id ) ) { |
|
135 | + return $subscription_id; |
|
136 | + } |
|
137 | 137 | |
138 | 138 | // Fetch from the db. |
139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
@@ -141,42 +141,42 @@ discard block |
||
141 | 141 | $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
142 | 142 | ); |
143 | 143 | |
144 | - if ( empty( $subscription_id ) ) { |
|
145 | - return 0; |
|
146 | - } |
|
144 | + if ( empty( $subscription_id ) ) { |
|
145 | + return 0; |
|
146 | + } |
|
147 | 147 | |
148 | - // Update the cache with our data. |
|
149 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
148 | + // Update the cache with our data. |
|
149 | + wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
150 | 150 | |
151 | - return $subscription_id; |
|
152 | - } |
|
151 | + return $subscription_id; |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
154 | + /** |
|
155 | 155 | * Clears the subscription's cache. |
156 | 156 | */ |
157 | 157 | public function clear_cache() { |
158 | - $caches = array( |
|
159 | - 'getpaid_subscription_parent_payment_ids_to_subscription_ids' => $this->get_parent_payment_id(), |
|
160 | - 'getpaid_subscription_transaction_ids_to_subscription_ids' => $this->get_transaction_id(), |
|
161 | - 'getpaid_subscription_profile_ids_to_subscription_ids' => $this->get_profile_id(), |
|
162 | - 'getpaid_subscriptions' => $this->get_id(), |
|
163 | - ); |
|
164 | - |
|
165 | - foreach ( $caches as $cache => $value ) { |
|
166 | - if ( '' !== $value && false !== $value ) { |
|
167 | - wp_cache_delete( $value, $cache ); |
|
168 | - } |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
158 | + $caches = array( |
|
159 | + 'getpaid_subscription_parent_payment_ids_to_subscription_ids' => $this->get_parent_payment_id(), |
|
160 | + 'getpaid_subscription_transaction_ids_to_subscription_ids' => $this->get_transaction_id(), |
|
161 | + 'getpaid_subscription_profile_ids_to_subscription_ids' => $this->get_profile_id(), |
|
162 | + 'getpaid_subscriptions' => $this->get_id(), |
|
163 | + ); |
|
164 | + |
|
165 | + foreach ( $caches as $cache => $value ) { |
|
166 | + if ( '' !== $value && false !== $value ) { |
|
167 | + wp_cache_delete( $value, $cache ); |
|
168 | + } |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | 173 | * Checks if a subscription key is set. |
174 | 174 | */ |
175 | 175 | public function _isset( $key ) { |
176 | 176 | return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" ); |
177 | - } |
|
177 | + } |
|
178 | 178 | |
179 | - /* |
|
179 | + /* |
|
180 | 180 | |-------------------------------------------------------------------------- |
181 | 181 | | CRUD methods |
182 | 182 | |-------------------------------------------------------------------------- |
@@ -185,544 +185,544 @@ discard block |
||
185 | 185 | | |
186 | 186 | */ |
187 | 187 | |
188 | - /* |
|
188 | + /* |
|
189 | 189 | |-------------------------------------------------------------------------- |
190 | 190 | | Getters |
191 | 191 | |-------------------------------------------------------------------------- |
192 | 192 | */ |
193 | 193 | |
194 | - /** |
|
195 | - * Get customer id. |
|
196 | - * |
|
197 | - * @since 1.0.19 |
|
198 | - * @param string $context View or edit context. |
|
199 | - * @return int |
|
200 | - */ |
|
201 | - public function get_customer_id( $context = 'view' ) { |
|
202 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Get customer information. |
|
207 | - * |
|
208 | - * @since 1.0.19 |
|
209 | - * @param string $context View or edit context. |
|
210 | - * @return WP_User|false WP_User object on success, false on failure. |
|
211 | - */ |
|
212 | - public function get_customer( $context = 'view' ) { |
|
213 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Get parent invoice id. |
|
218 | - * |
|
219 | - * @since 1.0.19 |
|
220 | - * @param string $context View or edit context. |
|
221 | - * @return int |
|
222 | - */ |
|
223 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
224 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Alias for self::get_parent_invoice_id(). |
|
229 | - * |
|
230 | - * @since 1.0.19 |
|
231 | - * @param string $context View or edit context. |
|
232 | - * @return int |
|
233 | - */ |
|
194 | + /** |
|
195 | + * Get customer id. |
|
196 | + * |
|
197 | + * @since 1.0.19 |
|
198 | + * @param string $context View or edit context. |
|
199 | + * @return int |
|
200 | + */ |
|
201 | + public function get_customer_id( $context = 'view' ) { |
|
202 | + return (int) $this->get_prop( 'customer_id', $context ); |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Get customer information. |
|
207 | + * |
|
208 | + * @since 1.0.19 |
|
209 | + * @param string $context View or edit context. |
|
210 | + * @return WP_User|false WP_User object on success, false on failure. |
|
211 | + */ |
|
212 | + public function get_customer( $context = 'view' ) { |
|
213 | + return get_userdata( $this->get_customer_id( $context ) ); |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Get parent invoice id. |
|
218 | + * |
|
219 | + * @since 1.0.19 |
|
220 | + * @param string $context View or edit context. |
|
221 | + * @return int |
|
222 | + */ |
|
223 | + public function get_parent_invoice_id( $context = 'view' ) { |
|
224 | + return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Alias for self::get_parent_invoice_id(). |
|
229 | + * |
|
230 | + * @since 1.0.19 |
|
231 | + * @param string $context View or edit context. |
|
232 | + * @return int |
|
233 | + */ |
|
234 | 234 | public function get_parent_payment_id( $context = 'view' ) { |
235 | 235 | return $this->get_parent_invoice_id( $context ); |
236 | - } |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Alias for self::get_parent_invoice_id(). |
|
240 | + * |
|
241 | + * @since 1.0.0 |
|
242 | + * @return int |
|
243 | + */ |
|
244 | + public function get_original_payment_id( $context = 'view' ) { |
|
245 | + return $this->get_parent_invoice_id( $context ); |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Get parent invoice. |
|
250 | + * |
|
251 | + * @since 1.0.19 |
|
252 | + * @param string $context View or edit context. |
|
253 | + * @return WPInv_Invoice |
|
254 | + */ |
|
255 | + public function get_parent_invoice( $context = 'view' ) { |
|
256 | + return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Alias for self::get_parent_invoice(). |
|
261 | + * |
|
262 | + * @since 1.0.19 |
|
263 | + * @param string $context View or edit context. |
|
264 | + * @return WPInv_Invoice |
|
265 | + */ |
|
266 | + public function get_parent_payment( $context = 'view' ) { |
|
267 | + return $this->get_parent_invoice( $context ); |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * Get subscription's product id. |
|
272 | + * |
|
273 | + * @since 1.0.19 |
|
274 | + * @param string $context View or edit context. |
|
275 | + * @return int |
|
276 | + */ |
|
277 | + public function get_product_id( $context = 'view' ) { |
|
278 | + return (int) $this->get_prop( 'product_id', $context ); |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * Get the subscription product. |
|
283 | + * |
|
284 | + * @since 1.0.19 |
|
285 | + * @param string $context View or edit context. |
|
286 | + * @return WPInv_Item |
|
287 | + */ |
|
288 | + public function get_product( $context = 'view' ) { |
|
289 | + return new WPInv_Item( $this->get_product_id( $context ) ); |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Get parent invoice's gateway. |
|
294 | + * |
|
295 | + * Here for backwards compatibility. |
|
296 | + * |
|
297 | + * @since 1.0.19 |
|
298 | + * @param string $context View or edit context. |
|
299 | + * @return string |
|
300 | + */ |
|
301 | + public function get_gateway( $context = 'view' ) { |
|
302 | + return $this->get_parent_invoice( $context )->get_gateway(); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Get the period of a renewal. |
|
307 | + * |
|
308 | + * @since 1.0.19 |
|
309 | + * @param string $context View or edit context. |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + public function get_period( $context = 'view' ) { |
|
313 | + return $this->get_prop( 'period', $context ); |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Get number of periods each renewal is valid for. |
|
318 | + * |
|
319 | + * @since 1.0.19 |
|
320 | + * @param string $context View or edit context. |
|
321 | + * @return int |
|
322 | + */ |
|
323 | + public function get_frequency( $context = 'view' ) { |
|
324 | + return (int) $this->get_prop( 'frequency', $context ); |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * Get the initial amount for the subscription. |
|
329 | + * |
|
330 | + * @since 1.0.19 |
|
331 | + * @param string $context View or edit context. |
|
332 | + * @return float |
|
333 | + */ |
|
334 | + public function get_initial_amount( $context = 'view' ) { |
|
335 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * Get the recurring amount for the subscription. |
|
340 | + * |
|
341 | + * @since 1.0.19 |
|
342 | + * @param string $context View or edit context. |
|
343 | + * @return float |
|
344 | + */ |
|
345 | + public function get_recurring_amount( $context = 'view' ) { |
|
346 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * Get number of times that this subscription can be renewed. |
|
351 | + * |
|
352 | + * @since 1.0.19 |
|
353 | + * @param string $context View or edit context. |
|
354 | + * @return int |
|
355 | + */ |
|
356 | + public function get_bill_times( $context = 'view' ) { |
|
357 | + return (int) $this->get_prop( 'bill_times', $context ); |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * Get transaction id of this subscription's parent invoice. |
|
362 | + * |
|
363 | + * @since 1.0.19 |
|
364 | + * @param string $context View or edit context. |
|
365 | + * @return string |
|
366 | + */ |
|
367 | + public function get_transaction_id( $context = 'view' ) { |
|
368 | + return $this->get_prop( 'transaction_id', $context ); |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Get the date that the subscription was created. |
|
373 | + * |
|
374 | + * @since 1.0.19 |
|
375 | + * @param string $context View or edit context. |
|
376 | + * @return string |
|
377 | + */ |
|
378 | + public function get_created( $context = 'view' ) { |
|
379 | + return $this->get_prop( 'created', $context ); |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Alias for self::get_created(). |
|
384 | + * |
|
385 | + * @since 1.0.19 |
|
386 | + * @param string $context View or edit context. |
|
387 | + * @return string |
|
388 | + */ |
|
389 | + public function get_date_created( $context = 'view' ) { |
|
390 | + return $this->get_created( $context ); |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Retrieves the creation date in a timestamp |
|
395 | + * |
|
396 | + * @since 1.0.0 |
|
397 | + * @return int |
|
398 | + */ |
|
399 | + public function get_time_created() { |
|
400 | + $created = $this->get_date_created(); |
|
401 | + return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Get GMT date when the subscription was created. |
|
406 | + * |
|
407 | + * @since 1.0.19 |
|
408 | + * @param string $context View or edit context. |
|
409 | + * @return string |
|
410 | + */ |
|
411 | + public function get_date_created_gmt( $context = 'view' ) { |
|
412 | + $date = $this->get_date_created( $context ); |
|
413 | + |
|
414 | + if ( $date ) { |
|
415 | + $date = get_gmt_from_date( $date ); |
|
416 | + } |
|
417 | + return $date; |
|
418 | + } |
|
419 | + |
|
420 | + /** |
|
421 | + * Get the date that the subscription will renew. |
|
422 | + * |
|
423 | + * @since 1.0.19 |
|
424 | + * @param string $context View or edit context. |
|
425 | + * @return string |
|
426 | + */ |
|
427 | + public function get_next_renewal_date( $context = 'view' ) { |
|
428 | + return $this->get_prop( 'expiration', $context ); |
|
429 | + } |
|
430 | + |
|
431 | + /** |
|
432 | + * Alias for self::get_next_renewal_date(). |
|
433 | + * |
|
434 | + * @since 1.0.19 |
|
435 | + * @param string $context View or edit context. |
|
436 | + * @return string |
|
437 | + */ |
|
438 | + public function get_expiration( $context = 'view' ) { |
|
439 | + return $this->get_next_renewal_date( $context ); |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * Retrieves the expiration date in a timestamp |
|
444 | + * |
|
445 | + * @since 1.0.0 |
|
446 | + * @return int |
|
447 | + */ |
|
448 | + public function get_expiration_time() { |
|
449 | + $expiration = $this->get_expiration(); |
|
450 | + |
|
451 | + if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
452 | + return current_time( 'timestamp' ); |
|
453 | + } |
|
454 | + |
|
455 | + $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
456 | + return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
457 | + } |
|
458 | + |
|
459 | + /** |
|
460 | + * Get GMT date when the subscription will renew. |
|
461 | + * |
|
462 | + * @since 1.0.19 |
|
463 | + * @param string $context View or edit context. |
|
464 | + * @return string |
|
465 | + */ |
|
466 | + public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
467 | + $date = $this->get_next_renewal_date( $context ); |
|
468 | + |
|
469 | + if ( $date ) { |
|
470 | + $date = get_gmt_from_date( $date ); |
|
471 | + } |
|
472 | + return $date; |
|
473 | + } |
|
474 | + |
|
475 | + /** |
|
476 | + * Get the subscription's trial period. |
|
477 | + * |
|
478 | + * @since 1.0.19 |
|
479 | + * @param string $context View or edit context. |
|
480 | + * @return string |
|
481 | + */ |
|
482 | + public function get_trial_period( $context = 'view' ) { |
|
483 | + return $this->get_prop( 'trial_period', $context ); |
|
484 | + } |
|
485 | + |
|
486 | + /** |
|
487 | + * Get the subscription's status. |
|
488 | + * |
|
489 | + * @since 1.0.19 |
|
490 | + * @param string $context View or edit context. |
|
491 | + * @return string |
|
492 | + */ |
|
493 | + public function get_status( $context = 'view' ) { |
|
494 | + return $this->get_prop( 'status', $context ); |
|
495 | + } |
|
496 | + |
|
497 | + /** |
|
498 | + * Get the subscription's profile id. |
|
499 | + * |
|
500 | + * @since 1.0.19 |
|
501 | + * @param string $context View or edit context. |
|
502 | + * @return string |
|
503 | + */ |
|
504 | + public function get_profile_id( $context = 'view' ) { |
|
505 | + return $this->get_prop( 'profile_id', $context ); |
|
506 | + } |
|
507 | + |
|
508 | + /* |
|
509 | + |-------------------------------------------------------------------------- |
|
510 | + | Setters |
|
511 | + |-------------------------------------------------------------------------- |
|
512 | + */ |
|
513 | + |
|
514 | + /** |
|
515 | + * Set customer id. |
|
516 | + * |
|
517 | + * @since 1.0.19 |
|
518 | + * @param int $value The customer's id. |
|
519 | + */ |
|
520 | + public function set_customer_id( $value ) { |
|
521 | + $this->set_prop( 'customer_id', (int) $value ); |
|
522 | + } |
|
523 | + |
|
524 | + /** |
|
525 | + * Set parent invoice id. |
|
526 | + * |
|
527 | + * @since 1.0.19 |
|
528 | + * @param int $value The parent invoice id. |
|
529 | + */ |
|
530 | + public function set_parent_invoice_id( $value ) { |
|
531 | + $this->set_prop( 'parent_payment_id', (int) $value ); |
|
532 | + } |
|
533 | + |
|
534 | + /** |
|
535 | + * Alias for self::set_parent_invoice_id(). |
|
536 | + * |
|
537 | + * @since 1.0.19 |
|
538 | + * @param int $value The parent invoice id. |
|
539 | + */ |
|
540 | + public function set_parent_payment_id( $value ) { |
|
541 | + $this->set_parent_invoice_id( $value ); |
|
542 | + } |
|
543 | + |
|
544 | + /** |
|
545 | + * Alias for self::set_parent_invoice_id(). |
|
546 | + * |
|
547 | + * @since 1.0.19 |
|
548 | + * @param int $value The parent invoice id. |
|
549 | + */ |
|
550 | + public function set_original_payment_id( $value ) { |
|
551 | + $this->set_parent_invoice_id( $value ); |
|
552 | + } |
|
553 | + |
|
554 | + /** |
|
555 | + * Set subscription's product id. |
|
556 | + * |
|
557 | + * @since 1.0.19 |
|
558 | + * @param int $value The subscription product id. |
|
559 | + */ |
|
560 | + public function set_product_id( $value ) { |
|
561 | + $this->set_prop( 'product_id', (int) $value ); |
|
562 | + } |
|
563 | + |
|
564 | + /** |
|
565 | + * Set the period of a renewal. |
|
566 | + * |
|
567 | + * @since 1.0.19 |
|
568 | + * @param string $value The renewal period. |
|
569 | + */ |
|
570 | + public function set_period( $value ) { |
|
571 | + $this->set_prop( 'period', $value ); |
|
572 | + } |
|
573 | + |
|
574 | + /** |
|
575 | + * Set number of periods each renewal is valid for. |
|
576 | + * |
|
577 | + * @since 1.0.19 |
|
578 | + * @param int $value The subscription frequency. |
|
579 | + */ |
|
580 | + public function set_frequency( $value ) { |
|
581 | + $value = empty( $value ) ? 1 : (int) $value; |
|
582 | + $this->set_prop( 'frequency', absint( $value ) ); |
|
583 | + } |
|
584 | + |
|
585 | + /** |
|
586 | + * Set the initial amount for the subscription. |
|
587 | + * |
|
588 | + * @since 1.0.19 |
|
589 | + * @param float $value The initial subcription amount. |
|
590 | + */ |
|
591 | + public function set_initial_amount( $value ) { |
|
592 | + $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * Set the recurring amount for the subscription. |
|
597 | + * |
|
598 | + * @since 1.0.19 |
|
599 | + * @param float $value The recurring subcription amount. |
|
600 | + */ |
|
601 | + public function set_recurring_amount( $value ) { |
|
602 | + $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
603 | + } |
|
604 | + |
|
605 | + /** |
|
606 | + * Set number of times that this subscription can be renewed. |
|
607 | + * |
|
608 | + * @since 1.0.19 |
|
609 | + * @param int $value Bill times. |
|
610 | + */ |
|
611 | + public function set_bill_times( $value ) { |
|
612 | + $this->set_prop( 'bill_times', (int) $value ); |
|
613 | + } |
|
614 | + |
|
615 | + /** |
|
616 | + * Get transaction id of this subscription's parent invoice. |
|
617 | + * |
|
618 | + * @since 1.0.19 |
|
619 | + * @param string $value Bill times. |
|
620 | + */ |
|
621 | + public function set_transaction_id( $value ) { |
|
622 | + $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
623 | + } |
|
624 | + |
|
625 | + /** |
|
626 | + * Set date when this subscription started. |
|
627 | + * |
|
628 | + * @since 1.0.19 |
|
629 | + * @param string $value strtotime compliant date. |
|
630 | + */ |
|
631 | + public function set_created( $value ) { |
|
632 | + $date = strtotime( $value ); |
|
633 | + |
|
634 | + if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
635 | + $this->set_prop( 'created', gmdate( 'Y-m-d H:i:s', $date ) ); |
|
636 | + return; |
|
637 | + } |
|
638 | + |
|
639 | + $this->set_prop( 'created', '' ); |
|
237 | 640 | |
238 | - /** |
|
239 | - * Alias for self::get_parent_invoice_id(). |
|
641 | + } |
|
642 | + |
|
643 | + /** |
|
644 | + * Alias for self::set_created(). |
|
240 | 645 | * |
241 | - * @since 1.0.0 |
|
242 | - * @return int |
|
646 | + * @since 1.0.19 |
|
647 | + * @param string $value strtotime compliant date. |
|
243 | 648 | */ |
244 | - public function get_original_payment_id( $context = 'view' ) { |
|
245 | - return $this->get_parent_invoice_id( $context ); |
|
649 | + public function set_date_created( $value ) { |
|
650 | + $this->set_created( $value ); |
|
246 | 651 | } |
247 | 652 | |
248 | - /** |
|
249 | - * Get parent invoice. |
|
250 | - * |
|
251 | - * @since 1.0.19 |
|
252 | - * @param string $context View or edit context. |
|
253 | - * @return WPInv_Invoice |
|
254 | - */ |
|
255 | - public function get_parent_invoice( $context = 'view' ) { |
|
256 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Alias for self::get_parent_invoice(). |
|
261 | - * |
|
262 | - * @since 1.0.19 |
|
263 | - * @param string $context View or edit context. |
|
264 | - * @return WPInv_Invoice |
|
265 | - */ |
|
266 | - public function get_parent_payment( $context = 'view' ) { |
|
267 | - return $this->get_parent_invoice( $context ); |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * Get subscription's product id. |
|
272 | - * |
|
273 | - * @since 1.0.19 |
|
274 | - * @param string $context View or edit context. |
|
275 | - * @return int |
|
276 | - */ |
|
277 | - public function get_product_id( $context = 'view' ) { |
|
278 | - return (int) $this->get_prop( 'product_id', $context ); |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * Get the subscription product. |
|
283 | - * |
|
284 | - * @since 1.0.19 |
|
285 | - * @param string $context View or edit context. |
|
286 | - * @return WPInv_Item |
|
287 | - */ |
|
288 | - public function get_product( $context = 'view' ) { |
|
289 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Get parent invoice's gateway. |
|
294 | - * |
|
295 | - * Here for backwards compatibility. |
|
296 | - * |
|
297 | - * @since 1.0.19 |
|
298 | - * @param string $context View or edit context. |
|
299 | - * @return string |
|
300 | - */ |
|
301 | - public function get_gateway( $context = 'view' ) { |
|
302 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Get the period of a renewal. |
|
307 | - * |
|
308 | - * @since 1.0.19 |
|
309 | - * @param string $context View or edit context. |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - public function get_period( $context = 'view' ) { |
|
313 | - return $this->get_prop( 'period', $context ); |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Get number of periods each renewal is valid for. |
|
318 | - * |
|
319 | - * @since 1.0.19 |
|
320 | - * @param string $context View or edit context. |
|
321 | - * @return int |
|
322 | - */ |
|
323 | - public function get_frequency( $context = 'view' ) { |
|
324 | - return (int) $this->get_prop( 'frequency', $context ); |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Get the initial amount for the subscription. |
|
329 | - * |
|
330 | - * @since 1.0.19 |
|
331 | - * @param string $context View or edit context. |
|
332 | - * @return float |
|
333 | - */ |
|
334 | - public function get_initial_amount( $context = 'view' ) { |
|
335 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * Get the recurring amount for the subscription. |
|
340 | - * |
|
341 | - * @since 1.0.19 |
|
342 | - * @param string $context View or edit context. |
|
343 | - * @return float |
|
344 | - */ |
|
345 | - public function get_recurring_amount( $context = 'view' ) { |
|
346 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * Get number of times that this subscription can be renewed. |
|
351 | - * |
|
352 | - * @since 1.0.19 |
|
353 | - * @param string $context View or edit context. |
|
354 | - * @return int |
|
355 | - */ |
|
356 | - public function get_bill_times( $context = 'view' ) { |
|
357 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * Get transaction id of this subscription's parent invoice. |
|
362 | - * |
|
363 | - * @since 1.0.19 |
|
364 | - * @param string $context View or edit context. |
|
365 | - * @return string |
|
366 | - */ |
|
367 | - public function get_transaction_id( $context = 'view' ) { |
|
368 | - return $this->get_prop( 'transaction_id', $context ); |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Get the date that the subscription was created. |
|
373 | - * |
|
374 | - * @since 1.0.19 |
|
375 | - * @param string $context View or edit context. |
|
376 | - * @return string |
|
377 | - */ |
|
378 | - public function get_created( $context = 'view' ) { |
|
379 | - return $this->get_prop( 'created', $context ); |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Alias for self::get_created(). |
|
384 | - * |
|
385 | - * @since 1.0.19 |
|
386 | - * @param string $context View or edit context. |
|
387 | - * @return string |
|
388 | - */ |
|
389 | - public function get_date_created( $context = 'view' ) { |
|
390 | - return $this->get_created( $context ); |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Retrieves the creation date in a timestamp |
|
395 | - * |
|
396 | - * @since 1.0.0 |
|
397 | - * @return int |
|
398 | - */ |
|
399 | - public function get_time_created() { |
|
400 | - $created = $this->get_date_created(); |
|
401 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Get GMT date when the subscription was created. |
|
406 | - * |
|
407 | - * @since 1.0.19 |
|
408 | - * @param string $context View or edit context. |
|
409 | - * @return string |
|
410 | - */ |
|
411 | - public function get_date_created_gmt( $context = 'view' ) { |
|
412 | - $date = $this->get_date_created( $context ); |
|
653 | + /** |
|
654 | + * Set the date that the subscription will renew. |
|
655 | + * |
|
656 | + * @since 1.0.19 |
|
657 | + * @param string $value strtotime compliant date. |
|
658 | + */ |
|
659 | + public function set_next_renewal_date( $value ) { |
|
660 | + $date = strtotime( $value ); |
|
413 | 661 | |
414 | - if ( $date ) { |
|
415 | - $date = get_gmt_from_date( $date ); |
|
662 | + if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
663 | + $this->set_prop( 'expiration', gmdate( 'Y-m-d H:i:s', $date ) ); |
|
664 | + return; |
|
416 | 665 | } |
417 | - return $date; |
|
418 | - } |
|
419 | - |
|
420 | - /** |
|
421 | - * Get the date that the subscription will renew. |
|
422 | - * |
|
423 | - * @since 1.0.19 |
|
424 | - * @param string $context View or edit context. |
|
425 | - * @return string |
|
426 | - */ |
|
427 | - public function get_next_renewal_date( $context = 'view' ) { |
|
428 | - return $this->get_prop( 'expiration', $context ); |
|
429 | - } |
|
430 | - |
|
431 | - /** |
|
432 | - * Alias for self::get_next_renewal_date(). |
|
433 | - * |
|
434 | - * @since 1.0.19 |
|
435 | - * @param string $context View or edit context. |
|
436 | - * @return string |
|
437 | - */ |
|
438 | - public function get_expiration( $context = 'view' ) { |
|
439 | - return $this->get_next_renewal_date( $context ); |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * Retrieves the expiration date in a timestamp |
|
444 | - * |
|
445 | - * @since 1.0.0 |
|
446 | - * @return int |
|
447 | - */ |
|
448 | - public function get_expiration_time() { |
|
449 | - $expiration = $this->get_expiration(); |
|
450 | - |
|
451 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
452 | - return current_time( 'timestamp' ); |
|
453 | - } |
|
454 | - |
|
455 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
456 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
457 | - } |
|
458 | - |
|
459 | - /** |
|
460 | - * Get GMT date when the subscription will renew. |
|
461 | - * |
|
462 | - * @since 1.0.19 |
|
463 | - * @param string $context View or edit context. |
|
464 | - * @return string |
|
465 | - */ |
|
466 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
467 | - $date = $this->get_next_renewal_date( $context ); |
|
468 | 666 | |
469 | - if ( $date ) { |
|
470 | - $date = get_gmt_from_date( $date ); |
|
471 | - } |
|
472 | - return $date; |
|
473 | - } |
|
474 | - |
|
475 | - /** |
|
476 | - * Get the subscription's trial period. |
|
477 | - * |
|
478 | - * @since 1.0.19 |
|
479 | - * @param string $context View or edit context. |
|
480 | - * @return string |
|
481 | - */ |
|
482 | - public function get_trial_period( $context = 'view' ) { |
|
483 | - return $this->get_prop( 'trial_period', $context ); |
|
484 | - } |
|
485 | - |
|
486 | - /** |
|
487 | - * Get the subscription's status. |
|
488 | - * |
|
489 | - * @since 1.0.19 |
|
490 | - * @param string $context View or edit context. |
|
491 | - * @return string |
|
492 | - */ |
|
493 | - public function get_status( $context = 'view' ) { |
|
494 | - return $this->get_prop( 'status', $context ); |
|
495 | - } |
|
496 | - |
|
497 | - /** |
|
498 | - * Get the subscription's profile id. |
|
499 | - * |
|
500 | - * @since 1.0.19 |
|
501 | - * @param string $context View or edit context. |
|
502 | - * @return string |
|
503 | - */ |
|
504 | - public function get_profile_id( $context = 'view' ) { |
|
505 | - return $this->get_prop( 'profile_id', $context ); |
|
506 | - } |
|
507 | - |
|
508 | - /* |
|
509 | - |-------------------------------------------------------------------------- |
|
510 | - | Setters |
|
511 | - |-------------------------------------------------------------------------- |
|
512 | - */ |
|
667 | + $this->set_prop( 'expiration', '' ); |
|
513 | 668 | |
514 | - /** |
|
515 | - * Set customer id. |
|
516 | - * |
|
517 | - * @since 1.0.19 |
|
518 | - * @param int $value The customer's id. |
|
519 | - */ |
|
520 | - public function set_customer_id( $value ) { |
|
521 | - $this->set_prop( 'customer_id', (int) $value ); |
|
522 | - } |
|
523 | - |
|
524 | - /** |
|
525 | - * Set parent invoice id. |
|
526 | - * |
|
527 | - * @since 1.0.19 |
|
528 | - * @param int $value The parent invoice id. |
|
529 | - */ |
|
530 | - public function set_parent_invoice_id( $value ) { |
|
531 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
532 | - } |
|
533 | - |
|
534 | - /** |
|
535 | - * Alias for self::set_parent_invoice_id(). |
|
536 | - * |
|
537 | - * @since 1.0.19 |
|
538 | - * @param int $value The parent invoice id. |
|
539 | - */ |
|
540 | - public function set_parent_payment_id( $value ) { |
|
541 | - $this->set_parent_invoice_id( $value ); |
|
542 | - } |
|
669 | + } |
|
543 | 670 | |
544 | - /** |
|
545 | - * Alias for self::set_parent_invoice_id(). |
|
671 | + /** |
|
672 | + * Alias for self::set_next_renewal_date(). |
|
546 | 673 | * |
547 | 674 | * @since 1.0.19 |
548 | - * @param int $value The parent invoice id. |
|
675 | + * @param string $value strtotime compliant date. |
|
549 | 676 | */ |
550 | - public function set_original_payment_id( $value ) { |
|
551 | - $this->set_parent_invoice_id( $value ); |
|
552 | - } |
|
553 | - |
|
554 | - /** |
|
555 | - * Set subscription's product id. |
|
556 | - * |
|
557 | - * @since 1.0.19 |
|
558 | - * @param int $value The subscription product id. |
|
559 | - */ |
|
560 | - public function set_product_id( $value ) { |
|
561 | - $this->set_prop( 'product_id', (int) $value ); |
|
562 | - } |
|
563 | - |
|
564 | - /** |
|
565 | - * Set the period of a renewal. |
|
566 | - * |
|
567 | - * @since 1.0.19 |
|
568 | - * @param string $value The renewal period. |
|
569 | - */ |
|
570 | - public function set_period( $value ) { |
|
571 | - $this->set_prop( 'period', $value ); |
|
572 | - } |
|
573 | - |
|
574 | - /** |
|
575 | - * Set number of periods each renewal is valid for. |
|
576 | - * |
|
577 | - * @since 1.0.19 |
|
578 | - * @param int $value The subscription frequency. |
|
579 | - */ |
|
580 | - public function set_frequency( $value ) { |
|
581 | - $value = empty( $value ) ? 1 : (int) $value; |
|
582 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
583 | - } |
|
584 | - |
|
585 | - /** |
|
586 | - * Set the initial amount for the subscription. |
|
587 | - * |
|
588 | - * @since 1.0.19 |
|
589 | - * @param float $value The initial subcription amount. |
|
590 | - */ |
|
591 | - public function set_initial_amount( $value ) { |
|
592 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
593 | - } |
|
594 | - |
|
595 | - /** |
|
596 | - * Set the recurring amount for the subscription. |
|
597 | - * |
|
598 | - * @since 1.0.19 |
|
599 | - * @param float $value The recurring subcription amount. |
|
600 | - */ |
|
601 | - public function set_recurring_amount( $value ) { |
|
602 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * Set number of times that this subscription can be renewed. |
|
607 | - * |
|
608 | - * @since 1.0.19 |
|
609 | - * @param int $value Bill times. |
|
610 | - */ |
|
611 | - public function set_bill_times( $value ) { |
|
612 | - $this->set_prop( 'bill_times', (int) $value ); |
|
613 | - } |
|
614 | - |
|
615 | - /** |
|
616 | - * Get transaction id of this subscription's parent invoice. |
|
617 | - * |
|
618 | - * @since 1.0.19 |
|
619 | - * @param string $value Bill times. |
|
620 | - */ |
|
621 | - public function set_transaction_id( $value ) { |
|
622 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
623 | - } |
|
624 | - |
|
625 | - /** |
|
626 | - * Set date when this subscription started. |
|
627 | - * |
|
628 | - * @since 1.0.19 |
|
629 | - * @param string $value strtotime compliant date. |
|
630 | - */ |
|
631 | - public function set_created( $value ) { |
|
632 | - $date = strtotime( $value ); |
|
677 | + public function set_expiration( $value ) { |
|
678 | + $this->set_next_renewal_date( $value ); |
|
679 | + } |
|
633 | 680 | |
634 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
635 | - $this->set_prop( 'created', gmdate( 'Y-m-d H:i:s', $date ) ); |
|
681 | + /** |
|
682 | + * Set the subscription's trial period. |
|
683 | + * |
|
684 | + * @since 1.0.19 |
|
685 | + * @param string $value trial period e.g 1 year. |
|
686 | + */ |
|
687 | + public function set_trial_period( $value ) { |
|
688 | + $this->set_prop( 'trial_period', $value ); |
|
689 | + } |
|
690 | + |
|
691 | + /** |
|
692 | + * Set the subscription's status. |
|
693 | + * |
|
694 | + * @since 1.0.19 |
|
695 | + * @param string $new_status New subscription status. |
|
696 | + */ |
|
697 | + public function set_status( $new_status ) { |
|
698 | + |
|
699 | + // Abort if this is not a valid status; |
|
700 | + if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
636 | 701 | return; |
637 | 702 | } |
638 | 703 | |
639 | - $this->set_prop( 'created', '' ); |
|
640 | - |
|
641 | - } |
|
704 | + $old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status(); |
|
705 | + if ( true === $this->object_read && $old_status !== $new_status ) { |
|
706 | + $this->status_transition = array( |
|
707 | + 'from' => $old_status, |
|
708 | + 'to' => $new_status, |
|
709 | + ); |
|
710 | + } |
|
642 | 711 | |
643 | - /** |
|
644 | - * Alias for self::set_created(). |
|
645 | - * |
|
646 | - * @since 1.0.19 |
|
647 | - * @param string $value strtotime compliant date. |
|
648 | - */ |
|
649 | - public function set_date_created( $value ) { |
|
650 | - $this->set_created( $value ); |
|
712 | + $this->set_prop( 'status', $new_status ); |
|
651 | 713 | } |
652 | 714 | |
653 | - /** |
|
654 | - * Set the date that the subscription will renew. |
|
655 | - * |
|
656 | - * @since 1.0.19 |
|
657 | - * @param string $value strtotime compliant date. |
|
658 | - */ |
|
659 | - public function set_next_renewal_date( $value ) { |
|
660 | - $date = strtotime( $value ); |
|
715 | + /** |
|
716 | + * Set the subscription's (remote) profile id. |
|
717 | + * |
|
718 | + * @since 1.0.19 |
|
719 | + * @param string $value the remote profile id. |
|
720 | + */ |
|
721 | + public function set_profile_id( $value ) { |
|
722 | + $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
723 | + } |
|
661 | 724 | |
662 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
663 | - $this->set_prop( 'expiration', gmdate( 'Y-m-d H:i:s', $date ) ); |
|
664 | - return; |
|
665 | - } |
|
666 | - |
|
667 | - $this->set_prop( 'expiration', '' ); |
|
668 | - |
|
669 | - } |
|
670 | - |
|
671 | - /** |
|
672 | - * Alias for self::set_next_renewal_date(). |
|
673 | - * |
|
674 | - * @since 1.0.19 |
|
675 | - * @param string $value strtotime compliant date. |
|
676 | - */ |
|
677 | - public function set_expiration( $value ) { |
|
678 | - $this->set_next_renewal_date( $value ); |
|
679 | - } |
|
680 | - |
|
681 | - /** |
|
682 | - * Set the subscription's trial period. |
|
683 | - * |
|
684 | - * @since 1.0.19 |
|
685 | - * @param string $value trial period e.g 1 year. |
|
686 | - */ |
|
687 | - public function set_trial_period( $value ) { |
|
688 | - $this->set_prop( 'trial_period', $value ); |
|
689 | - } |
|
690 | - |
|
691 | - /** |
|
692 | - * Set the subscription's status. |
|
693 | - * |
|
694 | - * @since 1.0.19 |
|
695 | - * @param string $new_status New subscription status. |
|
696 | - */ |
|
697 | - public function set_status( $new_status ) { |
|
698 | - |
|
699 | - // Abort if this is not a valid status; |
|
700 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
701 | - return; |
|
702 | - } |
|
703 | - |
|
704 | - $old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status(); |
|
705 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
706 | - $this->status_transition = array( |
|
707 | - 'from' => $old_status, |
|
708 | - 'to' => $new_status, |
|
709 | - ); |
|
710 | - } |
|
711 | - |
|
712 | - $this->set_prop( 'status', $new_status ); |
|
713 | - } |
|
714 | - |
|
715 | - /** |
|
716 | - * Set the subscription's (remote) profile id. |
|
717 | - * |
|
718 | - * @since 1.0.19 |
|
719 | - * @param string $value the remote profile id. |
|
720 | - */ |
|
721 | - public function set_profile_id( $value ) { |
|
722 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
723 | - } |
|
724 | - |
|
725 | - /* |
|
725 | + /* |
|
726 | 726 | |-------------------------------------------------------------------------- |
727 | 727 | | Boolean methods |
728 | 728 | |-------------------------------------------------------------------------- |
@@ -731,55 +731,55 @@ discard block |
||
731 | 731 | | |
732 | 732 | */ |
733 | 733 | |
734 | - /** |
|
734 | + /** |
|
735 | 735 | * Checks if the subscription has a given status. |
736 | - * |
|
737 | - * @param string|array String or array of strings to check for. |
|
738 | - * @return bool |
|
736 | + * |
|
737 | + * @param string|array String or array of strings to check for. |
|
738 | + * @return bool |
|
739 | 739 | */ |
740 | 740 | public function has_status( $status ) { |
741 | 741 | return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
742 | - } |
|
742 | + } |
|
743 | 743 | |
744 | - /** |
|
744 | + /** |
|
745 | 745 | * Checks if the subscription has a trial period. |
746 | - * |
|
747 | - * @return bool |
|
746 | + * |
|
747 | + * @return bool |
|
748 | 748 | */ |
749 | 749 | public function has_trial_period() { |
750 | - $period = $this->get_trial_period(); |
|
750 | + $period = $this->get_trial_period(); |
|
751 | 751 | return ! empty( $period ); |
752 | - } |
|
753 | - |
|
754 | - /** |
|
755 | - * Is the subscription active? |
|
756 | - * |
|
757 | - * @return bool |
|
758 | - */ |
|
759 | - public function is_active() { |
|
760 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
761 | - } |
|
762 | - |
|
763 | - /** |
|
764 | - * Is the subscription expired? |
|
765 | - * |
|
766 | - * @return bool |
|
767 | - */ |
|
768 | - public function is_expired() { |
|
769 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) ); |
|
770 | - } |
|
771 | - |
|
772 | - /** |
|
773 | - * Is this the last renewals? |
|
774 | - * |
|
775 | - * @return bool |
|
776 | - */ |
|
777 | - public function is_last_renewal() { |
|
778 | - $max_bills = $this->get_bill_times(); |
|
779 | - return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
780 | - } |
|
781 | - |
|
782 | - /* |
|
752 | + } |
|
753 | + |
|
754 | + /** |
|
755 | + * Is the subscription active? |
|
756 | + * |
|
757 | + * @return bool |
|
758 | + */ |
|
759 | + public function is_active() { |
|
760 | + return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
761 | + } |
|
762 | + |
|
763 | + /** |
|
764 | + * Is the subscription expired? |
|
765 | + * |
|
766 | + * @return bool |
|
767 | + */ |
|
768 | + public function is_expired() { |
|
769 | + return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) ); |
|
770 | + } |
|
771 | + |
|
772 | + /** |
|
773 | + * Is this the last renewals? |
|
774 | + * |
|
775 | + * @return bool |
|
776 | + */ |
|
777 | + public function is_last_renewal() { |
|
778 | + $max_bills = $this->get_bill_times(); |
|
779 | + return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
780 | + } |
|
781 | + |
|
782 | + /* |
|
783 | 783 | |-------------------------------------------------------------------------- |
784 | 784 | | Additional methods |
785 | 785 | |-------------------------------------------------------------------------- |
@@ -788,27 +788,27 @@ discard block |
||
788 | 788 | | |
789 | 789 | */ |
790 | 790 | |
791 | - /** |
|
792 | - * Backwards compatibilty. |
|
793 | - */ |
|
794 | - public function create( $data = array() ) { |
|
791 | + /** |
|
792 | + * Backwards compatibilty. |
|
793 | + */ |
|
794 | + public function create( $data = array() ) { |
|
795 | 795 | |
796 | - // Set the properties. |
|
797 | - if ( is_array( $data ) ) { |
|
798 | - $this->set_props( $data ); |
|
799 | - } |
|
796 | + // Set the properties. |
|
797 | + if ( is_array( $data ) ) { |
|
798 | + $this->set_props( $data ); |
|
799 | + } |
|
800 | 800 | |
801 | - // Save the item. |
|
802 | - return $this->save(); |
|
801 | + // Save the item. |
|
802 | + return $this->save(); |
|
803 | 803 | |
804 | - } |
|
804 | + } |
|
805 | 805 | |
806 | - /** |
|
807 | - * Backwards compatibilty. |
|
808 | - */ |
|
809 | - public function update( $args = array() ) { |
|
810 | - return $this->create( $args ); |
|
811 | - } |
|
806 | + /** |
|
807 | + * Backwards compatibilty. |
|
808 | + */ |
|
809 | + public function update( $args = array() ) { |
|
810 | + return $this->create( $args ); |
|
811 | + } |
|
812 | 812 | |
813 | 813 | /** |
814 | 814 | * Retrieve renewal payments for a subscription |
@@ -818,22 +818,22 @@ discard block |
||
818 | 818 | */ |
819 | 819 | public function get_child_payments( $hide_pending = true ) { |
820 | 820 | |
821 | - $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
821 | + $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
822 | 822 | |
823 | - if ( ! $hide_pending ) { |
|
824 | - $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
825 | - } |
|
823 | + if ( ! $hide_pending ) { |
|
824 | + $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
825 | + } |
|
826 | 826 | |
827 | 827 | return get_posts( |
828 | - array( |
|
829 | - 'post_parent' => $this->get_parent_payment_id(), |
|
830 | - 'numberposts' => -1, |
|
831 | - 'post_status' => $statuses, |
|
832 | - 'orderby' => 'ID', |
|
833 | - 'order' => 'ASC', |
|
834 | - 'post_type' => 'wpi_invoice', |
|
835 | - ) |
|
836 | - ); |
|
828 | + array( |
|
829 | + 'post_parent' => $this->get_parent_payment_id(), |
|
830 | + 'numberposts' => -1, |
|
831 | + 'post_status' => $statuses, |
|
832 | + 'orderby' => 'ID', |
|
833 | + 'order' => 'ASC', |
|
834 | + 'post_type' => 'wpi_invoice', |
|
835 | + ) |
|
836 | + ); |
|
837 | 837 | } |
838 | 838 | |
839 | 839 | /** |
@@ -843,7 +843,7 @@ discard block |
||
843 | 843 | * @return int |
844 | 844 | */ |
845 | 845 | public function get_total_payments() { |
846 | - return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() ); |
|
846 | + return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() ); |
|
847 | 847 | } |
848 | 848 | |
849 | 849 | /** |
@@ -867,187 +867,187 @@ discard block |
||
867 | 867 | * |
868 | 868 | * @since 2.4 |
869 | 869 | * @param array $args Array of values for the payment, including amount and transaction ID |
870 | - * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
870 | + * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
871 | 871 | * @return bool |
872 | 872 | */ |
873 | 873 | public function add_payment( $args = array(), $invoice = false ) { |
874 | 874 | |
875 | - // Process each payment once. |
|
875 | + // Process each payment once. |
|
876 | 876 | if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
877 | 877 | return false; |
878 | 878 | } |
879 | 879 | |
880 | - // Are we creating a new invoice? |
|
881 | - if ( empty( $invoice ) ) { |
|
882 | - $invoice = $this->create_payment( false ); |
|
880 | + // Are we creating a new invoice? |
|
881 | + if ( empty( $invoice ) ) { |
|
882 | + $invoice = $this->create_payment( false ); |
|
883 | 883 | |
884 | - if ( empty( $invoice ) ) { |
|
885 | - return false; |
|
886 | - } |
|
887 | - } |
|
884 | + if ( empty( $invoice ) ) { |
|
885 | + return false; |
|
886 | + } |
|
887 | + } |
|
888 | 888 | |
889 | - // Maybe set a transaction id. |
|
890 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
891 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
892 | - } |
|
889 | + // Maybe set a transaction id. |
|
890 | + if ( ! empty( $args['transaction_id'] ) ) { |
|
891 | + $invoice->set_transaction_id( $args['transaction_id'] ); |
|
892 | + } |
|
893 | 893 | |
894 | - // Set the completed date. |
|
895 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
894 | + // Set the completed date. |
|
895 | + $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
896 | 896 | |
897 | - // And the gateway. |
|
898 | - if ( ! empty( $args['gateway'] ) ) { |
|
899 | - $invoice->set_gateway( $args['gateway'] ); |
|
900 | - } |
|
897 | + // And the gateway. |
|
898 | + if ( ! empty( $args['gateway'] ) ) { |
|
899 | + $invoice->set_gateway( $args['gateway'] ); |
|
900 | + } |
|
901 | 901 | |
902 | - $invoice->set_status( 'wpi-renewal' ); |
|
903 | - $invoice->save(); |
|
902 | + $invoice->set_status( 'wpi-renewal' ); |
|
903 | + $invoice->save(); |
|
904 | 904 | |
905 | - if ( ! $invoice->exists() ) { |
|
906 | - return false; |
|
907 | - } |
|
905 | + if ( ! $invoice->exists() ) { |
|
906 | + return false; |
|
907 | + } |
|
908 | 908 | |
909 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
910 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
909 | + do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
910 | + do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
911 | 911 | do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
912 | 912 | |
913 | 913 | update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
914 | 914 | |
915 | 915 | return $invoice->get_id(); |
916 | - } |
|
916 | + } |
|
917 | 917 | |
918 | - /** |
|
918 | + /** |
|
919 | 919 | * Creates a new invoice and returns it. |
920 | 920 | * |
921 | 921 | * @since 1.0.19 |
922 | - * @param bool $save Whether we should save the invoice. |
|
922 | + * @param bool $save Whether we should save the invoice. |
|
923 | 923 | * @return WPInv_Invoice|bool |
924 | 924 | */ |
925 | 925 | public function create_payment( $save = true ) { |
926 | 926 | |
927 | - $parent_invoice = $this->get_parent_payment(); |
|
928 | - |
|
929 | - if ( ! $parent_invoice->exists() ) { |
|
930 | - return false; |
|
931 | - } |
|
932 | - |
|
933 | - // Duplicate the parent invoice. |
|
934 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
935 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
936 | - $invoice->set_subscription_id( $this->get_id() ); |
|
937 | - $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
938 | - |
|
939 | - // Set invoice items. |
|
940 | - $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
941 | - $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
942 | - $invoice_items = array(); |
|
943 | - |
|
944 | - foreach ( $invoice->get_items() as $item ) { |
|
945 | - if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
946 | - $invoice_items[] = $item; |
|
947 | - } |
|
948 | - } |
|
949 | - |
|
950 | - $invoice->set_items( $invoice_items ); |
|
951 | - |
|
952 | - if ( ! empty( $subscription_group['fees'] ) ) { |
|
953 | - $invoice->set_fees( $subscription_group['fees'] ); |
|
954 | - } |
|
955 | - |
|
956 | - // Maybe recalculate discount (Pre-GetPaid Fix). |
|
957 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
958 | - if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
959 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
960 | - } |
|
961 | - |
|
962 | - $invoice->recalculate_total(); |
|
963 | - $invoice->set_status( 'wpi-pending' ); |
|
964 | - |
|
965 | - if ( ! $save ) { |
|
966 | - return $invoice; |
|
967 | - } |
|
968 | - |
|
969 | - $invoice->save(); |
|
970 | - |
|
971 | - return $invoice->exists() ? $invoice : false; |
|
972 | - } |
|
973 | - |
|
974 | - /** |
|
975 | - * Renews or completes a subscription |
|
976 | - * |
|
977 | - * @since 1.0.0 |
|
978 | - * @return int The subscription's id |
|
979 | - */ |
|
980 | - public function renew( $calculate_from = null ) { |
|
981 | - |
|
982 | - // Complete subscription if applicable |
|
983 | - if ( $this->is_last_renewal() ) { |
|
984 | - return $this->complete(); |
|
985 | - } |
|
986 | - |
|
987 | - // Calculate new expiration |
|
988 | - $frequency = $this->get_frequency(); |
|
989 | - $period = $this->get_period(); |
|
990 | - $calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from; |
|
991 | - $new_expiration = strtotime( "+ $frequency $period", $calculate_from ); |
|
992 | - |
|
993 | - $this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) ); |
|
994 | - $this->set_status( 'active' ); |
|
995 | - $this->save(); |
|
996 | - |
|
997 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
998 | - |
|
999 | - return $this->get_id(); |
|
1000 | - } |
|
1001 | - |
|
1002 | - /** |
|
1003 | - * Marks a subscription as completed |
|
1004 | - * |
|
1005 | - * Subscription is completed when the number of payments matches the billing_times field |
|
1006 | - * |
|
1007 | - * @since 1.0.0 |
|
1008 | - * @return int|bool Subscription id or false if the subscription is cancelled. |
|
1009 | - */ |
|
1010 | - public function complete() { |
|
1011 | - |
|
1012 | - // Only mark a subscription as complete if it's not already cancelled. |
|
1013 | - if ( $this->has_status( 'cancelled' ) ) { |
|
1014 | - return false; |
|
1015 | - } |
|
1016 | - |
|
1017 | - $this->set_status( 'completed' ); |
|
1018 | - return $this->save(); |
|
1019 | - |
|
1020 | - } |
|
1021 | - |
|
1022 | - /** |
|
1023 | - * Marks a subscription as expired |
|
1024 | - * |
|
1025 | - * @since 1.0.0 |
|
1026 | - * @param bool $check_expiration |
|
1027 | - * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
1028 | - */ |
|
1029 | - public function expire( $check_expiration = false ) { |
|
1030 | - |
|
1031 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
1032 | - // Do not mark as expired since real expiration date is in the future |
|
1033 | - return false; |
|
1034 | - } |
|
1035 | - |
|
1036 | - $this->set_status( 'expired' ); |
|
1037 | - return $this->save(); |
|
1038 | - |
|
1039 | - } |
|
1040 | - |
|
1041 | - /** |
|
1042 | - * Marks a subscription as failing |
|
1043 | - * |
|
1044 | - * @since 2.4.2 |
|
1045 | - * @return int Subscription id. |
|
1046 | - */ |
|
1047 | - public function failing() { |
|
1048 | - $this->set_status( 'failing' ); |
|
1049 | - return $this->save(); |
|
1050 | - } |
|
927 | + $parent_invoice = $this->get_parent_payment(); |
|
928 | + |
|
929 | + if ( ! $parent_invoice->exists() ) { |
|
930 | + return false; |
|
931 | + } |
|
932 | + |
|
933 | + // Duplicate the parent invoice. |
|
934 | + $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
935 | + $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
936 | + $invoice->set_subscription_id( $this->get_id() ); |
|
937 | + $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
938 | + |
|
939 | + // Set invoice items. |
|
940 | + $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
941 | + $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
942 | + $invoice_items = array(); |
|
943 | + |
|
944 | + foreach ( $invoice->get_items() as $item ) { |
|
945 | + if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
946 | + $invoice_items[] = $item; |
|
947 | + } |
|
948 | + } |
|
949 | + |
|
950 | + $invoice->set_items( $invoice_items ); |
|
951 | + |
|
952 | + if ( ! empty( $subscription_group['fees'] ) ) { |
|
953 | + $invoice->set_fees( $subscription_group['fees'] ); |
|
954 | + } |
|
955 | + |
|
956 | + // Maybe recalculate discount (Pre-GetPaid Fix). |
|
957 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
958 | + if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
959 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
960 | + } |
|
961 | + |
|
962 | + $invoice->recalculate_total(); |
|
963 | + $invoice->set_status( 'wpi-pending' ); |
|
964 | + |
|
965 | + if ( ! $save ) { |
|
966 | + return $invoice; |
|
967 | + } |
|
968 | + |
|
969 | + $invoice->save(); |
|
970 | + |
|
971 | + return $invoice->exists() ? $invoice : false; |
|
972 | + } |
|
973 | + |
|
974 | + /** |
|
975 | + * Renews or completes a subscription |
|
976 | + * |
|
977 | + * @since 1.0.0 |
|
978 | + * @return int The subscription's id |
|
979 | + */ |
|
980 | + public function renew( $calculate_from = null ) { |
|
981 | + |
|
982 | + // Complete subscription if applicable |
|
983 | + if ( $this->is_last_renewal() ) { |
|
984 | + return $this->complete(); |
|
985 | + } |
|
986 | + |
|
987 | + // Calculate new expiration |
|
988 | + $frequency = $this->get_frequency(); |
|
989 | + $period = $this->get_period(); |
|
990 | + $calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from; |
|
991 | + $new_expiration = strtotime( "+ $frequency $period", $calculate_from ); |
|
992 | + |
|
993 | + $this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) ); |
|
994 | + $this->set_status( 'active' ); |
|
995 | + $this->save(); |
|
996 | + |
|
997 | + do_action( 'getpaid_subscription_renewed', $this ); |
|
998 | + |
|
999 | + return $this->get_id(); |
|
1000 | + } |
|
1001 | + |
|
1002 | + /** |
|
1003 | + * Marks a subscription as completed |
|
1004 | + * |
|
1005 | + * Subscription is completed when the number of payments matches the billing_times field |
|
1006 | + * |
|
1007 | + * @since 1.0.0 |
|
1008 | + * @return int|bool Subscription id or false if the subscription is cancelled. |
|
1009 | + */ |
|
1010 | + public function complete() { |
|
1011 | + |
|
1012 | + // Only mark a subscription as complete if it's not already cancelled. |
|
1013 | + if ( $this->has_status( 'cancelled' ) ) { |
|
1014 | + return false; |
|
1015 | + } |
|
1016 | + |
|
1017 | + $this->set_status( 'completed' ); |
|
1018 | + return $this->save(); |
|
1019 | + |
|
1020 | + } |
|
1021 | + |
|
1022 | + /** |
|
1023 | + * Marks a subscription as expired |
|
1024 | + * |
|
1025 | + * @since 1.0.0 |
|
1026 | + * @param bool $check_expiration |
|
1027 | + * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
1028 | + */ |
|
1029 | + public function expire( $check_expiration = false ) { |
|
1030 | + |
|
1031 | + if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
1032 | + // Do not mark as expired since real expiration date is in the future |
|
1033 | + return false; |
|
1034 | + } |
|
1035 | + |
|
1036 | + $this->set_status( 'expired' ); |
|
1037 | + return $this->save(); |
|
1038 | + |
|
1039 | + } |
|
1040 | + |
|
1041 | + /** |
|
1042 | + * Marks a subscription as failing |
|
1043 | + * |
|
1044 | + * @since 2.4.2 |
|
1045 | + * @return int Subscription id. |
|
1046 | + */ |
|
1047 | + public function failing() { |
|
1048 | + $this->set_status( 'failing' ); |
|
1049 | + return $this->save(); |
|
1050 | + } |
|
1051 | 1051 | |
1052 | 1052 | /** |
1053 | 1053 | * Marks a subscription as cancelled |
@@ -1056,19 +1056,19 @@ discard block |
||
1056 | 1056 | * @return int Subscription id. |
1057 | 1057 | */ |
1058 | 1058 | public function cancel() { |
1059 | - $this->set_status( 'cancelled' ); |
|
1060 | - return $this->save(); |
|
1059 | + $this->set_status( 'cancelled' ); |
|
1060 | + return $this->save(); |
|
1061 | 1061 | } |
1062 | 1062 | |
1063 | - /** |
|
1064 | - * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
1065 | - * |
|
1066 | - * @since 1.0.0 |
|
1067 | - * @return bool |
|
1068 | - */ |
|
1069 | - public function can_cancel() { |
|
1070 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1071 | - } |
|
1063 | + /** |
|
1064 | + * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
1065 | + * |
|
1066 | + * @since 1.0.0 |
|
1067 | + * @return bool |
|
1068 | + */ |
|
1069 | + public function can_cancel() { |
|
1070 | + return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1071 | + } |
|
1072 | 1072 | |
1073 | 1073 | /** |
1074 | 1074 | * Returns an array of subscription statuses that can be cancelled |
@@ -1081,109 +1081,109 @@ discard block |
||
1081 | 1081 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
1082 | 1082 | } |
1083 | 1083 | |
1084 | - /** |
|
1085 | - * Retrieves the URL to cancel subscription |
|
1086 | - * |
|
1087 | - * @since 1.0.0 |
|
1088 | - * @return string |
|
1089 | - */ |
|
1090 | - public function get_cancel_url() { |
|
1091 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
1092 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1093 | - } |
|
1094 | - |
|
1095 | - /** |
|
1096 | - * Retrieves the URL to view a subscription |
|
1097 | - * |
|
1098 | - * @since 1.0.19 |
|
1099 | - * @return string |
|
1100 | - */ |
|
1101 | - public function get_view_url() { |
|
1102 | - |
|
1103 | - $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
1104 | - $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
1105 | - |
|
1106 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
1107 | - } |
|
1108 | - |
|
1109 | - /** |
|
1110 | - * Determines if subscription can be manually renewed |
|
1111 | - * |
|
1112 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
1113 | - * that can be renewed manually |
|
1114 | - * |
|
1115 | - * @since 2.5 |
|
1116 | - * @return bool |
|
1117 | - */ |
|
1118 | - public function can_renew() { |
|
1119 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1120 | - } |
|
1121 | - |
|
1122 | - /** |
|
1123 | - * Retrieves the URL to renew a subscription |
|
1124 | - * |
|
1125 | - * @since 2.5 |
|
1126 | - * @return string |
|
1127 | - */ |
|
1128 | - public function get_renew_url() { |
|
1129 | - $url = wp_nonce_url( |
|
1084 | + /** |
|
1085 | + * Retrieves the URL to cancel subscription |
|
1086 | + * |
|
1087 | + * @since 1.0.0 |
|
1088 | + * @return string |
|
1089 | + */ |
|
1090 | + public function get_cancel_url() { |
|
1091 | + $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
1092 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1093 | + } |
|
1094 | + |
|
1095 | + /** |
|
1096 | + * Retrieves the URL to view a subscription |
|
1097 | + * |
|
1098 | + * @since 1.0.19 |
|
1099 | + * @return string |
|
1100 | + */ |
|
1101 | + public function get_view_url() { |
|
1102 | + |
|
1103 | + $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
1104 | + $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
1105 | + |
|
1106 | + return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
1107 | + } |
|
1108 | + |
|
1109 | + /** |
|
1110 | + * Determines if subscription can be manually renewed |
|
1111 | + * |
|
1112 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
1113 | + * that can be renewed manually |
|
1114 | + * |
|
1115 | + * @since 2.5 |
|
1116 | + * @return bool |
|
1117 | + */ |
|
1118 | + public function can_renew() { |
|
1119 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1120 | + } |
|
1121 | + |
|
1122 | + /** |
|
1123 | + * Retrieves the URL to renew a subscription |
|
1124 | + * |
|
1125 | + * @since 2.5 |
|
1126 | + * @return string |
|
1127 | + */ |
|
1128 | + public function get_renew_url() { |
|
1129 | + $url = wp_nonce_url( |
|
1130 | 1130 | add_query_arg( |
1131 | 1131 | array( |
1132 | - 'getpaid-action' => 'renew_subscription', |
|
1133 | - 'sub_id' => $this->get_id, |
|
1132 | + 'getpaid-action' => 'renew_subscription', |
|
1133 | + 'sub_id' => $this->get_id, |
|
1134 | 1134 | ) |
1135 | 1135 | ), |
1136 | 1136 | 'getpaid-nonce' |
1137 | 1137 | ); |
1138 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1139 | - } |
|
1140 | - |
|
1141 | - /** |
|
1142 | - * Determines if subscription can have their payment method updated |
|
1143 | - * |
|
1144 | - * @since 1.0.0 |
|
1145 | - * @return bool |
|
1146 | - */ |
|
1147 | - public function can_update() { |
|
1148 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1149 | - } |
|
1150 | - |
|
1151 | - /** |
|
1152 | - * Retrieves the URL to update subscription |
|
1153 | - * |
|
1154 | - * @since 1.0.0 |
|
1155 | - * @return string |
|
1156 | - */ |
|
1157 | - public function get_update_url() { |
|
1158 | - $url = add_query_arg( |
|
1138 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1139 | + } |
|
1140 | + |
|
1141 | + /** |
|
1142 | + * Determines if subscription can have their payment method updated |
|
1143 | + * |
|
1144 | + * @since 1.0.0 |
|
1145 | + * @return bool |
|
1146 | + */ |
|
1147 | + public function can_update() { |
|
1148 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1149 | + } |
|
1150 | + |
|
1151 | + /** |
|
1152 | + * Retrieves the URL to update subscription |
|
1153 | + * |
|
1154 | + * @since 1.0.0 |
|
1155 | + * @return string |
|
1156 | + */ |
|
1157 | + public function get_update_url() { |
|
1158 | + $url = add_query_arg( |
|
1159 | 1159 | array( |
1160 | - 'action' => 'update', |
|
1161 | - 'subscription_id' => $this->get_id(), |
|
1160 | + 'action' => 'update', |
|
1161 | + 'subscription_id' => $this->get_id(), |
|
1162 | 1162 | ) |
1163 | 1163 | ); |
1164 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1165 | - } |
|
1166 | - |
|
1167 | - /** |
|
1168 | - * Retrieves the subscription status label |
|
1169 | - * |
|
1170 | - * @since 1.0.0 |
|
1171 | - * @return string |
|
1172 | - */ |
|
1173 | - public function get_status_label() { |
|
1174 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1175 | - } |
|
1176 | - |
|
1177 | - /** |
|
1178 | - * Retrieves the subscription status class |
|
1179 | - * |
|
1180 | - * @since 1.0.19 |
|
1181 | - * @return string |
|
1182 | - */ |
|
1183 | - public function get_status_class() { |
|
1184 | - $statuses = getpaid_get_subscription_status_classes(); |
|
1185 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark'; |
|
1186 | - } |
|
1164 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1165 | + } |
|
1166 | + |
|
1167 | + /** |
|
1168 | + * Retrieves the subscription status label |
|
1169 | + * |
|
1170 | + * @since 1.0.0 |
|
1171 | + * @return string |
|
1172 | + */ |
|
1173 | + public function get_status_label() { |
|
1174 | + return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1175 | + } |
|
1176 | + |
|
1177 | + /** |
|
1178 | + * Retrieves the subscription status class |
|
1179 | + * |
|
1180 | + * @since 1.0.19 |
|
1181 | + * @return string |
|
1182 | + */ |
|
1183 | + public function get_status_class() { |
|
1184 | + $statuses = getpaid_get_subscription_status_classes(); |
|
1185 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark'; |
|
1186 | + } |
|
1187 | 1187 | |
1188 | 1188 | /** |
1189 | 1189 | * Retrieves the subscription status label |
@@ -1193,11 +1193,11 @@ discard block |
||
1193 | 1193 | */ |
1194 | 1194 | public function get_status_label_html() { |
1195 | 1195 | |
1196 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1197 | - $class = esc_attr( $this->get_status_class() ); |
|
1198 | - $status = sanitize_html_class( $this->get_status() ); |
|
1196 | + $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1197 | + $class = esc_attr( $this->get_status_class() ); |
|
1198 | + $status = sanitize_html_class( $this->get_status() ); |
|
1199 | 1199 | |
1200 | - return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
1200 | + return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
1201 | 1201 | } |
1202 | 1202 | |
1203 | 1203 | /** |
@@ -1208,75 +1208,75 @@ discard block |
||
1208 | 1208 | * @return bool |
1209 | 1209 | */ |
1210 | 1210 | public function payment_exists( $txn_id = '' ) { |
1211 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1211 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1212 | 1212 | return ! empty( $invoice_id ); |
1213 | - } |
|
1214 | - |
|
1215 | - /** |
|
1216 | - * Handle the status transition. |
|
1217 | - */ |
|
1218 | - protected function status_transition() { |
|
1219 | - $status_transition = $this->status_transition; |
|
1220 | - |
|
1221 | - // Reset status transition variable. |
|
1222 | - $this->status_transition = false; |
|
1223 | - |
|
1224 | - if ( $status_transition ) { |
|
1225 | - try { |
|
1226 | - |
|
1227 | - // Fire a hook for the status change. |
|
1228 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1229 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1230 | - |
|
1231 | - if ( ! empty( $status_transition['from'] ) ) { |
|
1232 | - |
|
1233 | - /* translators: 1: old subscription status 2: new subscription status */ |
|
1234 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1235 | - |
|
1236 | - // Note the transition occurred. |
|
1237 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1238 | - |
|
1239 | - // Fire another hook. |
|
1240 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1241 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1242 | - |
|
1243 | - } else { |
|
1244 | - /* translators: %s: new invoice status */ |
|
1245 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1246 | - |
|
1247 | - // Note the transition occurred. |
|
1248 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1249 | - |
|
1250 | - } |
|
1251 | - } catch ( Exception $e ) { |
|
1252 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1253 | - } |
|
1254 | - } |
|
1255 | - |
|
1256 | - } |
|
1257 | - |
|
1258 | - /** |
|
1259 | - * Save data to the database. |
|
1260 | - * |
|
1261 | - * @since 1.0.19 |
|
1262 | - * @return int subscription ID |
|
1263 | - */ |
|
1264 | - public function save() { |
|
1265 | - parent::save(); |
|
1266 | - $this->status_transition(); |
|
1267 | - return $this->get_id(); |
|
1268 | - } |
|
1269 | - |
|
1270 | - /** |
|
1271 | - * Activates a subscription. |
|
1272 | - * |
|
1273 | - * @since 1.0.19 |
|
1274 | - * @return int subscription ID |
|
1275 | - */ |
|
1276 | - public function activate() { |
|
1277 | - $status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active'; |
|
1278 | - $this->set_status( $status ); |
|
1279 | - return $this->save(); |
|
1280 | - } |
|
1213 | + } |
|
1214 | + |
|
1215 | + /** |
|
1216 | + * Handle the status transition. |
|
1217 | + */ |
|
1218 | + protected function status_transition() { |
|
1219 | + $status_transition = $this->status_transition; |
|
1220 | + |
|
1221 | + // Reset status transition variable. |
|
1222 | + $this->status_transition = false; |
|
1223 | + |
|
1224 | + if ( $status_transition ) { |
|
1225 | + try { |
|
1226 | + |
|
1227 | + // Fire a hook for the status change. |
|
1228 | + do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1229 | + do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1230 | + |
|
1231 | + if ( ! empty( $status_transition['from'] ) ) { |
|
1232 | + |
|
1233 | + /* translators: 1: old subscription status 2: new subscription status */ |
|
1234 | + $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1235 | + |
|
1236 | + // Note the transition occurred. |
|
1237 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1238 | + |
|
1239 | + // Fire another hook. |
|
1240 | + do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1241 | + do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1242 | + |
|
1243 | + } else { |
|
1244 | + /* translators: %s: new invoice status */ |
|
1245 | + $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1246 | + |
|
1247 | + // Note the transition occurred. |
|
1248 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1249 | + |
|
1250 | + } |
|
1251 | + } catch ( Exception $e ) { |
|
1252 | + $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1253 | + } |
|
1254 | + } |
|
1255 | + |
|
1256 | + } |
|
1257 | + |
|
1258 | + /** |
|
1259 | + * Save data to the database. |
|
1260 | + * |
|
1261 | + * @since 1.0.19 |
|
1262 | + * @return int subscription ID |
|
1263 | + */ |
|
1264 | + public function save() { |
|
1265 | + parent::save(); |
|
1266 | + $this->status_transition(); |
|
1267 | + return $this->get_id(); |
|
1268 | + } |
|
1269 | + |
|
1270 | + /** |
|
1271 | + * Activates a subscription. |
|
1272 | + * |
|
1273 | + * @since 1.0.19 |
|
1274 | + * @return int subscription ID |
|
1275 | + */ |
|
1276 | + public function activate() { |
|
1277 | + $status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active'; |
|
1278 | + $this->set_status( $status ); |
|
1279 | + return $this->save(); |
|
1280 | + } |
|
1281 | 1281 | |
1282 | 1282 | } |
@@ -12,144 +12,144 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Daily_Maintenance { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - */ |
|
18 | - public function __construct() { |
|
19 | - |
|
20 | - // Clear deprecated events. |
|
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | - |
|
23 | - // (Maybe) schedule a cron that runs daily. |
|
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | - |
|
26 | - // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
32 | - |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Schedules a cron to run every day at 7 a.m |
|
37 | - * |
|
38 | - */ |
|
39 | - public function maybe_create_scheduled_event() { |
|
40 | - |
|
41 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
44 | - } |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Clears deprecated events. |
|
50 | - * |
|
51 | - */ |
|
52 | - public function maybe_clear_deprecated_events() { |
|
53 | - |
|
54 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
58 | - } |
|
59 | - |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Fires the old hook for backwards compatibility. |
|
64 | - * |
|
65 | - */ |
|
66 | - public function backwards_compat() { |
|
67 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Checks for subscriptions that are scheduled to renew. |
|
72 | - * |
|
73 | - */ |
|
74 | - public function check_renewing_subscriptions() { |
|
75 | - |
|
76 | - // Fetch subscriptions that expire today. |
|
77 | - $args = array( |
|
78 | - 'number' => -1, |
|
79 | - 'count_total' => false, |
|
80 | - 'status' => 'trialling active', |
|
81 | - 'date_expires_query' => array( |
|
82 | - array( |
|
83 | - 'year' => gmdate( 'Y' ), |
|
84 | - 'month' => gmdate( 'n' ), |
|
85 | - 'day' => gmdate( 'j' ), |
|
86 | - 'compare' => '=', |
|
87 | - ), |
|
88 | - ), |
|
89 | - ); |
|
90 | - |
|
91 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
92 | - |
|
93 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
94 | - |
|
95 | - /** @var WPInv_Subscription $subscription */ |
|
96 | - if ( $subscription->is_last_renewal() ) { |
|
97 | - $subscription->complete(); |
|
98 | - } else { |
|
99 | - do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Expires expired subscriptions. |
|
107 | - * |
|
108 | - */ |
|
109 | - public function maybe_expire_subscriptions() { |
|
110 | - |
|
111 | - // Fetch expired subscriptions (skips those that expire today). |
|
112 | - $args = array( |
|
113 | - 'number' => -1, |
|
114 | - 'count_total' => false, |
|
115 | - 'status' => 'trialling active failing cancelled', |
|
116 | - 'date_expires_query' => array( |
|
117 | - 'before' => 'yesterday', |
|
118 | - 'inclusive' => false, |
|
119 | - ), |
|
120 | - ); |
|
121 | - |
|
122 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
123 | - |
|
124 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
125 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
126 | - $subscription->set_status( 'expired' ); |
|
127 | - $subscription->save(); |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Logs cron runs. |
|
135 | - * |
|
136 | - */ |
|
137 | - public function log_cron_run() { |
|
138 | - wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Updates GeoIP databases. |
|
143 | - * |
|
144 | - */ |
|
145 | - public function maybe_update_geoip_databases() { |
|
146 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
147 | - |
|
148 | - if ( false === $updated ) { |
|
149 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
150 | - do_action( 'getpaid_update_geoip_databases' ); |
|
151 | - } |
|
152 | - |
|
153 | - } |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + */ |
|
18 | + public function __construct() { |
|
19 | + |
|
20 | + // Clear deprecated events. |
|
21 | + add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | + |
|
23 | + // (Maybe) schedule a cron that runs daily. |
|
24 | + add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | + |
|
26 | + // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | + add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | + add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | + add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
32 | + |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Schedules a cron to run every day at 7 a.m |
|
37 | + * |
|
38 | + */ |
|
39 | + public function maybe_create_scheduled_event() { |
|
40 | + |
|
41 | + if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | + $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | + wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
44 | + } |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Clears deprecated events. |
|
50 | + * |
|
51 | + */ |
|
52 | + public function maybe_clear_deprecated_events() { |
|
53 | + |
|
54 | + if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | + update_option( 'wpinv_cleared_old_events', 1 ); |
|
58 | + } |
|
59 | + |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Fires the old hook for backwards compatibility. |
|
64 | + * |
|
65 | + */ |
|
66 | + public function backwards_compat() { |
|
67 | + do_action( 'wpinv_register_schedule_event_daily' ); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Checks for subscriptions that are scheduled to renew. |
|
72 | + * |
|
73 | + */ |
|
74 | + public function check_renewing_subscriptions() { |
|
75 | + |
|
76 | + // Fetch subscriptions that expire today. |
|
77 | + $args = array( |
|
78 | + 'number' => -1, |
|
79 | + 'count_total' => false, |
|
80 | + 'status' => 'trialling active', |
|
81 | + 'date_expires_query' => array( |
|
82 | + array( |
|
83 | + 'year' => gmdate( 'Y' ), |
|
84 | + 'month' => gmdate( 'n' ), |
|
85 | + 'day' => gmdate( 'j' ), |
|
86 | + 'compare' => '=', |
|
87 | + ), |
|
88 | + ), |
|
89 | + ); |
|
90 | + |
|
91 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
92 | + |
|
93 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
94 | + |
|
95 | + /** @var WPInv_Subscription $subscription */ |
|
96 | + if ( $subscription->is_last_renewal() ) { |
|
97 | + $subscription->complete(); |
|
98 | + } else { |
|
99 | + do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Expires expired subscriptions. |
|
107 | + * |
|
108 | + */ |
|
109 | + public function maybe_expire_subscriptions() { |
|
110 | + |
|
111 | + // Fetch expired subscriptions (skips those that expire today). |
|
112 | + $args = array( |
|
113 | + 'number' => -1, |
|
114 | + 'count_total' => false, |
|
115 | + 'status' => 'trialling active failing cancelled', |
|
116 | + 'date_expires_query' => array( |
|
117 | + 'before' => 'yesterday', |
|
118 | + 'inclusive' => false, |
|
119 | + ), |
|
120 | + ); |
|
121 | + |
|
122 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
123 | + |
|
124 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
125 | + if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
126 | + $subscription->set_status( 'expired' ); |
|
127 | + $subscription->save(); |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Logs cron runs. |
|
135 | + * |
|
136 | + */ |
|
137 | + public function log_cron_run() { |
|
138 | + wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Updates GeoIP databases. |
|
143 | + * |
|
144 | + */ |
|
145 | + public function maybe_update_geoip_databases() { |
|
146 | + $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
147 | + |
|
148 | + if ( false === $updated ) { |
|
149 | + set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
150 | + do_action( 'getpaid_update_geoip_databases' ); |
|
151 | + } |
|
152 | + |
|
153 | + } |
|
154 | 154 | |
155 | 155 | } |
@@ -19,16 +19,16 @@ discard block |
||
19 | 19 | |
20 | 20 | // Define constants. |
21 | 21 | if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) { |
22 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
22 | + define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | if ( ! defined( 'WPINV_VERSION' ) ) { |
26 | - define( 'WPINV_VERSION', '2.7.6' ); |
|
26 | + define( 'WPINV_VERSION', '2.7.6' ); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | // Include the main Invoicing class. |
30 | 30 | if ( ! class_exists( 'WPInv_Plugin', false ) ) { |
31 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
31 | + require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $GLOBALS['invoicing'] = new WPInv_Plugin(); |
44 | 44 | } |
45 | 45 | |
46 | - return $GLOBALS['invoicing']; |
|
46 | + return $GLOBALS['invoicing']; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -39,62 +39,62 @@ discard block |
||
39 | 39 | <td style="width: 65%"> |
40 | 40 | <?php |
41 | 41 | |
42 | - switch ( $key ) { |
|
42 | + switch ( $key ) { |
|
43 | 43 | |
44 | - case 'status': |
|
45 | - echo esc_html( $subscription->get_status_label() ); |
|
46 | - break; |
|
44 | + case 'status': |
|
45 | + echo esc_html( $subscription->get_status_label() ); |
|
46 | + break; |
|
47 | 47 | |
48 | - case 'start_date': |
|
49 | - echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
50 | - break; |
|
48 | + case 'start_date': |
|
49 | + echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
50 | + break; |
|
51 | 51 | |
52 | - case 'expiry_date': |
|
53 | - echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
54 | - break; |
|
52 | + case 'expiry_date': |
|
53 | + echo esc_html( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
54 | + break; |
|
55 | 55 | |
56 | - case 'initial_amount': |
|
57 | - echo wp_kses_post( wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ) ); |
|
56 | + case 'initial_amount': |
|
57 | + echo wp_kses_post( wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ) ); |
|
58 | 58 | |
59 | - if ( $subscription->has_trial_period() ) { |
|
59 | + if ( $subscription->has_trial_period() ) { |
|
60 | 60 | |
61 | - echo "<small class='text-muted'> "; |
|
62 | - printf( |
|
63 | - esc_html_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
64 | - esc_html( $subscription->get_trial_period() ) |
|
65 | - ); |
|
66 | - echo '</small>'; |
|
61 | + echo "<small class='text-muted'> "; |
|
62 | + printf( |
|
63 | + esc_html_x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
64 | + esc_html( $subscription->get_trial_period() ) |
|
65 | + ); |
|
66 | + echo '</small>'; |
|
67 | 67 | |
68 | - } |
|
68 | + } |
|
69 | 69 | |
70 | - break; |
|
70 | + break; |
|
71 | 71 | |
72 | - case 'recurring_amount': |
|
73 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
74 | - $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
75 | - echo wp_kses_post( strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ) ); |
|
76 | - break; |
|
72 | + case 'recurring_amount': |
|
73 | + $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
74 | + $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
75 | + echo wp_kses_post( strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ) ); |
|
76 | + break; |
|
77 | 77 | |
78 | - case 'item': |
|
79 | - if ( empty( $subscription_group ) ) { |
|
80 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
81 | - } else { |
|
82 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
83 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
84 | - } |
|
78 | + case 'item': |
|
79 | + if ( empty( $subscription_group ) ) { |
|
80 | + echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
81 | + } else { |
|
82 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
83 | + echo wp_kses_post( implode( ' | ', $markup ) ); |
|
84 | + } |
|
85 | 85 | |
86 | - break; |
|
86 | + break; |
|
87 | 87 | |
88 | - case 'payments': |
|
89 | - $max_activations = (int) $subscription->get_bill_times(); |
|
90 | - echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_activations ) ? '∞' : (int) $max_activations ); |
|
88 | + case 'payments': |
|
89 | + $max_activations = (int) $subscription->get_bill_times(); |
|
90 | + echo ( (int) $subscription->get_times_billed() ) . ' / ' . ( empty( $max_activations ) ? '∞' : (int) $max_activations ); |
|
91 | 91 | |
92 | - break; |
|
92 | + break; |
|
93 | 93 | |
94 | - } |
|
95 | - do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
94 | + } |
|
95 | + do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
96 | 96 | |
97 | - ?> |
|
97 | + ?> |
|
98 | 98 | </td> |
99 | 99 | |
100 | 100 | </tr> |
@@ -121,17 +121,17 @@ discard block |
||
121 | 121 | <span class="form-text"> |
122 | 122 | |
123 | 123 | <?php |
124 | - if ( $subscription->can_cancel() ) { |
|
125 | - printf( |
|
124 | + if ( $subscription->can_cancel() ) { |
|
125 | + printf( |
|
126 | 126 | '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
127 | 127 | esc_url( $subscription->get_cancel_url() ), |
128 | 128 | esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
129 | 129 | esc_html__( 'Cancel Subscription', 'invoicing' ) |
130 | 130 | ); |
131 | - } |
|
131 | + } |
|
132 | 132 | |
133 | - do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
134 | - ?> |
|
133 | + do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
134 | + ?> |
|
135 | 135 | |
136 | 136 | <a href="<?php echo esc_url( getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); ?>" class="btn btn-secondary btn-sm"><?php esc_html_e( 'Go Back', 'invoicing' ); ?></a> |
137 | 137 | </span> |
@@ -12,478 +12,478 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Paypal_Gateway_IPN_Handler { |
14 | 14 | |
15 | - /** |
|
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $id = 'paypal'; |
|
21 | - |
|
22 | - /** |
|
23 | - * Payment method object. |
|
24 | - * |
|
25 | - * @var GetPaid_Paypal_Gateway |
|
26 | - */ |
|
27 | - protected $gateway; |
|
28 | - |
|
29 | - /** |
|
30 | - * Class constructor. |
|
31 | - * |
|
32 | - * @param GetPaid_Paypal_Gateway $gateway |
|
33 | - */ |
|
34 | - public function __construct( $gateway ) { |
|
35 | - $this->gateway = $gateway; |
|
36 | - $this->verify_ipn(); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Processes ipns and marks payments as complete. |
|
41 | - * |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function verify_ipn() { |
|
45 | - |
|
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
47 | - |
|
48 | - // Validate the IPN. |
|
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | - } |
|
52 | - |
|
53 | - // Process the IPN. |
|
54 | - $posted = wp_unslash( $_POST ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | - |
|
57 | - // Abort if it was not paid by our gateway. |
|
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
61 | - } |
|
62 | - |
|
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | - |
|
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
68 | - |
|
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
73 | - } |
|
74 | - |
|
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
77 | - |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Retrieves IPN Invoice. |
|
82 | - * |
|
83 | - * @param array $posted |
|
84 | - * @return WPInv_Invoice |
|
85 | - */ |
|
86 | - protected function get_ipn_invoice( $posted ) { |
|
87 | - |
|
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
89 | - |
|
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
92 | - |
|
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
95 | - return $invoice; |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
100 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Check PayPal IPN validity. |
|
105 | - */ |
|
106 | - protected function validate_ipn() { |
|
107 | - |
|
108 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
109 | - |
|
110 | - // Retrieve the associated invoice. |
|
111 | - $posted = wp_unslash( $_POST ); |
|
112 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
113 | - |
|
114 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
115 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
116 | - } |
|
117 | - |
|
118 | - // Validate the IPN. |
|
119 | - $posted['cmd'] = '_notify-validate'; |
|
120 | - |
|
121 | - // Send back post vars to paypal. |
|
122 | - $params = array( |
|
123 | - 'body' => $posted, |
|
124 | - 'timeout' => 60, |
|
125 | - 'httpversion' => '1.1', |
|
126 | - 'compress' => false, |
|
127 | - 'decompress' => false, |
|
128 | - 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
129 | - ); |
|
130 | - |
|
131 | - // Post back to get a response. |
|
132 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
133 | - |
|
134 | - // Check to see if the request was valid. |
|
135 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
136 | - $invoice->add_note( 'Received valid response from PayPal IPN: ' . $response['body'], false, false, true ); |
|
137 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
138 | - return true; |
|
139 | - } |
|
140 | - |
|
141 | - $invoice->add_note( 'IPN message:' . wp_json_encode( $posted ), false, false, true ); |
|
142 | - |
|
143 | - if ( is_wp_error( $response ) ) { |
|
144 | - $invoice->add_note( 'Received invalid response from PayPal IPN: ' . $response->get_error_message(), false, false, true ); |
|
145 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
146 | - return false; |
|
147 | - } |
|
148 | - |
|
149 | - $invoice->add_note( 'Received invalid response from PayPal IPN: ' . $response['body'], false, false, true ); |
|
150 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
151 | - return false; |
|
152 | - |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Check currency from IPN matches the invoice. |
|
157 | - * |
|
158 | - * @param WPInv_Invoice $invoice Invoice object. |
|
159 | - * @param string $currency currency to validate. |
|
160 | - */ |
|
161 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
15 | + /** |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $id = 'paypal'; |
|
21 | + |
|
22 | + /** |
|
23 | + * Payment method object. |
|
24 | + * |
|
25 | + * @var GetPaid_Paypal_Gateway |
|
26 | + */ |
|
27 | + protected $gateway; |
|
28 | + |
|
29 | + /** |
|
30 | + * Class constructor. |
|
31 | + * |
|
32 | + * @param GetPaid_Paypal_Gateway $gateway |
|
33 | + */ |
|
34 | + public function __construct( $gateway ) { |
|
35 | + $this->gateway = $gateway; |
|
36 | + $this->verify_ipn(); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Processes ipns and marks payments as complete. |
|
41 | + * |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function verify_ipn() { |
|
45 | + |
|
46 | + wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
47 | + |
|
48 | + // Validate the IPN. |
|
49 | + if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | + wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | + } |
|
52 | + |
|
53 | + // Process the IPN. |
|
54 | + $posted = wp_unslash( $_POST ); |
|
55 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | + |
|
57 | + // Abort if it was not paid by our gateway. |
|
58 | + if ( $this->id != $invoice->get_gateway() ) { |
|
59 | + wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | + wp_die( 'Invoice not paid via PayPal', 200 ); |
|
61 | + } |
|
62 | + |
|
63 | + $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | + |
|
66 | + wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | + wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
68 | + |
|
69 | + if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | + call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | + wpinv_error_log( 'Done processing IPN', false ); |
|
72 | + wp_die( 'Processed', 200 ); |
|
73 | + } |
|
74 | + |
|
75 | + wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | + wp_die( 'Unsupported IPN type', 200 ); |
|
77 | + |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Retrieves IPN Invoice. |
|
82 | + * |
|
83 | + * @param array $posted |
|
84 | + * @return WPInv_Invoice |
|
85 | + */ |
|
86 | + protected function get_ipn_invoice( $posted ) { |
|
87 | + |
|
88 | + wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
89 | + |
|
90 | + if ( ! empty( $posted['custom'] ) ) { |
|
91 | + $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
92 | + |
|
93 | + if ( $invoice->exists() ) { |
|
94 | + wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
95 | + return $invoice; |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
100 | + wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Check PayPal IPN validity. |
|
105 | + */ |
|
106 | + protected function validate_ipn() { |
|
107 | + |
|
108 | + wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
109 | + |
|
110 | + // Retrieve the associated invoice. |
|
111 | + $posted = wp_unslash( $_POST ); |
|
112 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
113 | + |
|
114 | + if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
115 | + wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
116 | + } |
|
117 | + |
|
118 | + // Validate the IPN. |
|
119 | + $posted['cmd'] = '_notify-validate'; |
|
120 | + |
|
121 | + // Send back post vars to paypal. |
|
122 | + $params = array( |
|
123 | + 'body' => $posted, |
|
124 | + 'timeout' => 60, |
|
125 | + 'httpversion' => '1.1', |
|
126 | + 'compress' => false, |
|
127 | + 'decompress' => false, |
|
128 | + 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
129 | + ); |
|
130 | + |
|
131 | + // Post back to get a response. |
|
132 | + $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
133 | + |
|
134 | + // Check to see if the request was valid. |
|
135 | + if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
136 | + $invoice->add_note( 'Received valid response from PayPal IPN: ' . $response['body'], false, false, true ); |
|
137 | + wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
138 | + return true; |
|
139 | + } |
|
140 | + |
|
141 | + $invoice->add_note( 'IPN message:' . wp_json_encode( $posted ), false, false, true ); |
|
142 | + |
|
143 | + if ( is_wp_error( $response ) ) { |
|
144 | + $invoice->add_note( 'Received invalid response from PayPal IPN: ' . $response->get_error_message(), false, false, true ); |
|
145 | + wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
146 | + return false; |
|
147 | + } |
|
148 | + |
|
149 | + $invoice->add_note( 'Received invalid response from PayPal IPN: ' . $response['body'], false, false, true ); |
|
150 | + wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
151 | + return false; |
|
152 | + |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Check currency from IPN matches the invoice. |
|
157 | + * |
|
158 | + * @param WPInv_Invoice $invoice Invoice object. |
|
159 | + * @param string $currency currency to validate. |
|
160 | + */ |
|
161 | + protected function validate_ipn_currency( $invoice, $currency ) { |
|
162 | 162 | |
163 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
163 | + if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
164 | 164 | |
165 | - /* translators: %s: currency code. */ |
|
166 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
165 | + /* translators: %s: currency code. */ |
|
166 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
167 | 167 | |
168 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
169 | - } |
|
168 | + wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
169 | + } |
|
170 | 170 | |
171 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
172 | - } |
|
171 | + wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * Check payment amount from IPN matches the invoice. |
|
176 | - * |
|
177 | - * @param WPInv_Invoice $invoice Invoice object. |
|
178 | - * @param float $amount amount to validate. |
|
179 | - */ |
|
180 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
181 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
174 | + /** |
|
175 | + * Check payment amount from IPN matches the invoice. |
|
176 | + * |
|
177 | + * @param WPInv_Invoice $invoice Invoice object. |
|
178 | + * @param float $amount amount to validate. |
|
179 | + */ |
|
180 | + protected function validate_ipn_amount( $invoice, $amount ) { |
|
181 | + if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
182 | 182 | |
183 | - /* translators: %s: Amount. */ |
|
184 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
183 | + /* translators: %s: Amount. */ |
|
184 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
185 | 185 | |
186 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
187 | - } |
|
186 | + wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
187 | + } |
|
188 | 188 | |
189 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
190 | - } |
|
189 | + wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
190 | + } |
|
191 | 191 | |
192 | - /** |
|
193 | - * Verify receiver email from PayPal. |
|
194 | - * |
|
195 | - * @param WPInv_Invoice $invoice Invoice object. |
|
196 | - * @param string $receiver_email Email to validate. |
|
197 | - */ |
|
198 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
199 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
192 | + /** |
|
193 | + * Verify receiver email from PayPal. |
|
194 | + * |
|
195 | + * @param WPInv_Invoice $invoice Invoice object. |
|
196 | + * @param string $receiver_email Email to validate. |
|
197 | + */ |
|
198 | + protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
199 | + $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
200 | 200 | |
201 | - if ( $receiver_email && strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
202 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
201 | + if ( $receiver_email && strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
202 | + wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
203 | 203 | |
204 | - /* translators: %s: email address . */ |
|
205 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
204 | + /* translators: %s: email address . */ |
|
205 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
206 | 206 | |
207 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
208 | - } |
|
207 | + return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
208 | + } |
|
209 | 209 | |
210 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
211 | - } |
|
210 | + wpinv_error_log( 'Validated PayPal Email', false ); |
|
211 | + } |
|
212 | 212 | |
213 | - /** |
|
214 | - * Handles one time payments. |
|
215 | - * |
|
216 | - * @param WPInv_Invoice $invoice Invoice object. |
|
217 | - * @param array $posted Posted data. |
|
218 | - */ |
|
219 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
213 | + /** |
|
214 | + * Handles one time payments. |
|
215 | + * |
|
216 | + * @param WPInv_Invoice $invoice Invoice object. |
|
217 | + * @param array $posted Posted data. |
|
218 | + */ |
|
219 | + protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
220 | 220 | |
221 | - // Collect payment details |
|
222 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
223 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
221 | + // Collect payment details |
|
222 | + $payment_status = strtolower( $posted['payment_status'] ); |
|
223 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
224 | 224 | |
225 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
226 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
225 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
226 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
227 | 227 | |
228 | - // Update the transaction id. |
|
229 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
230 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
231 | - $invoice->save(); |
|
232 | - } |
|
228 | + // Update the transaction id. |
|
229 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
230 | + $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
231 | + $invoice->save(); |
|
232 | + } |
|
233 | 233 | |
234 | - $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
234 | + $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
235 | 235 | |
236 | - // Process a refund. |
|
237 | - if ( 'refunded' === $payment_status || 'reversed' === $payment_status ) { |
|
236 | + // Process a refund. |
|
237 | + if ( 'refunded' === $payment_status || 'reversed' === $payment_status ) { |
|
238 | 238 | |
239 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
239 | + update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
240 | 240 | |
241 | - if ( ! $invoice->is_refunded() ) { |
|
242 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
243 | - } |
|
241 | + if ( ! $invoice->is_refunded() ) { |
|
242 | + $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
243 | + } |
|
244 | 244 | |
245 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
246 | - } |
|
245 | + return wpinv_error_log( $posted['reason_code'], false ); |
|
246 | + } |
|
247 | 247 | |
248 | - // Process payments. |
|
249 | - if ( 'completed' === $payment_status ) { |
|
248 | + // Process payments. |
|
249 | + if ( 'completed' === $payment_status ) { |
|
250 | 250 | |
251 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
252 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
253 | - } |
|
251 | + if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
252 | + return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
253 | + } |
|
254 | 254 | |
255 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
255 | + $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
256 | 256 | |
257 | - $note = ''; |
|
257 | + $note = ''; |
|
258 | 258 | |
259 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
260 | - $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
261 | - } |
|
259 | + if ( ! empty( $posted['mc_fee'] ) ) { |
|
260 | + $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
261 | + } |
|
262 | 262 | |
263 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
264 | - $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
265 | - } |
|
263 | + if ( ! empty( $posted['payer_status'] ) ) { |
|
264 | + $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
265 | + } |
|
266 | 266 | |
267 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
268 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
267 | + $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
268 | + return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
269 | 269 | |
270 | - } |
|
270 | + } |
|
271 | 271 | |
272 | - // Pending payments. |
|
273 | - if ( 'pending' === $payment_status ) { |
|
272 | + // Pending payments. |
|
273 | + if ( 'pending' === $payment_status ) { |
|
274 | 274 | |
275 | - /* translators: %s: pending reason. */ |
|
276 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
275 | + /* translators: %s: pending reason. */ |
|
276 | + $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
277 | 277 | |
278 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
279 | - } |
|
278 | + return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
279 | + } |
|
280 | 280 | |
281 | - /* translators: %s: payment status. */ |
|
282 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
281 | + /* translators: %s: payment status. */ |
|
282 | + $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
283 | 283 | |
284 | - } |
|
284 | + } |
|
285 | 285 | |
286 | - /** |
|
287 | - * Handles one time payments. |
|
288 | - * |
|
289 | - * @param WPInv_Invoice $invoice Invoice object. |
|
290 | - * @param array $posted Posted data. |
|
291 | - */ |
|
292 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
293 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
294 | - } |
|
286 | + /** |
|
287 | + * Handles one time payments. |
|
288 | + * |
|
289 | + * @param WPInv_Invoice $invoice Invoice object. |
|
290 | + * @param array $posted Posted data. |
|
291 | + */ |
|
292 | + protected function ipn_txn_cart( $invoice, $posted ) { |
|
293 | + $this->ipn_txn_web_accept( $invoice, $posted ); |
|
294 | + } |
|
295 | 295 | |
296 | - /** |
|
297 | - * Handles subscription sign ups. |
|
298 | - * |
|
299 | - * @param WPInv_Invoice $invoice Invoice object. |
|
300 | - * @param array $posted Posted data. |
|
301 | - */ |
|
302 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
296 | + /** |
|
297 | + * Handles subscription sign ups. |
|
298 | + * |
|
299 | + * @param WPInv_Invoice $invoice Invoice object. |
|
300 | + * @param array $posted Posted data. |
|
301 | + */ |
|
302 | + protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
303 | 303 | |
304 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
304 | + wpinv_error_log( 'Processing subscription signup', false ); |
|
305 | 305 | |
306 | - // Make sure the invoice has a subscription. |
|
307 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
306 | + // Make sure the invoice has a subscription. |
|
307 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
308 | 308 | |
309 | - if ( empty( $subscription ) ) { |
|
310 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
311 | - } |
|
309 | + if ( empty( $subscription ) ) { |
|
310 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
311 | + } |
|
312 | 312 | |
313 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
313 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
314 | 314 | |
315 | - // Validate the IPN. |
|
316 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
317 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
318 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
315 | + // Validate the IPN. |
|
316 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
317 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
318 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
319 | 319 | |
320 | - // Activate the subscription. |
|
321 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
322 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
323 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
324 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
325 | - $subscription->activate(); |
|
320 | + // Activate the subscription. |
|
321 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
322 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
323 | + $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
324 | + $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
325 | + $subscription->activate(); |
|
326 | 326 | |
327 | - // Set the transaction id. |
|
328 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
329 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
330 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
331 | - } |
|
327 | + // Set the transaction id. |
|
328 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
329 | + $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
330 | + $invoice->set_transaction_id( $posted['txn_id'] ); |
|
331 | + } |
|
332 | 332 | |
333 | - // Update the payment status. |
|
334 | - $invoice->mark_paid(); |
|
333 | + // Update the payment status. |
|
334 | + $invoice->mark_paid(); |
|
335 | 335 | |
336 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
336 | + $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
337 | 337 | |
338 | - wpinv_error_log( 'Subscription started.', false ); |
|
339 | - } |
|
338 | + wpinv_error_log( 'Subscription started.', false ); |
|
339 | + } |
|
340 | 340 | |
341 | - /** |
|
342 | - * Handles subscription renewals. |
|
343 | - * |
|
344 | - * @param WPInv_Invoice $invoice Invoice object. |
|
345 | - * @param array $posted Posted data. |
|
346 | - */ |
|
347 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
341 | + /** |
|
342 | + * Handles subscription renewals. |
|
343 | + * |
|
344 | + * @param WPInv_Invoice $invoice Invoice object. |
|
345 | + * @param array $posted Posted data. |
|
346 | + */ |
|
347 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
348 | 348 | |
349 | - // Make sure the invoice has a subscription. |
|
350 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
349 | + // Make sure the invoice has a subscription. |
|
350 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
351 | 351 | |
352 | - if ( empty( $subscription ) ) { |
|
353 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
354 | - } |
|
352 | + if ( empty( $subscription ) ) { |
|
353 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
354 | + } |
|
355 | 355 | |
356 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
356 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
357 | 357 | |
358 | - // PayPal sends a subscr_payment for the first payment too. |
|
359 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
360 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
361 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
362 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
363 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
364 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
358 | + // PayPal sends a subscr_payment for the first payment too. |
|
359 | + $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
360 | + $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
361 | + $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
362 | + $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
363 | + $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
364 | + $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
365 | 365 | |
366 | - foreach ( $dates as $date ) { |
|
366 | + foreach ( $dates as $date ) { |
|
367 | 367 | |
368 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
369 | - continue; |
|
370 | - } |
|
368 | + if ( $date !== $today_date && $date !== $payment_date ) { |
|
369 | + continue; |
|
370 | + } |
|
371 | 371 | |
372 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
373 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
374 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
375 | - } |
|
372 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
373 | + $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
374 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
375 | + } |
|
376 | 376 | |
377 | - return $invoice->mark_paid(); |
|
378 | - |
|
379 | - } |
|
377 | + return $invoice->mark_paid(); |
|
378 | + |
|
379 | + } |
|
380 | 380 | |
381 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
382 | - |
|
383 | - // Abort if the payment is already recorded. |
|
384 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
385 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false ); |
|
386 | - } |
|
387 | - |
|
388 | - $args = array( |
|
389 | - 'transaction_id' => $posted['txn_id'], |
|
390 | - 'gateway' => $this->id, |
|
391 | - ); |
|
392 | - |
|
393 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
381 | + wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
382 | + |
|
383 | + // Abort if the payment is already recorded. |
|
384 | + if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
385 | + return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false ); |
|
386 | + } |
|
387 | + |
|
388 | + $args = array( |
|
389 | + 'transaction_id' => $posted['txn_id'], |
|
390 | + 'gateway' => $this->id, |
|
391 | + ); |
|
392 | + |
|
393 | + $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
394 | 394 | |
395 | - if ( empty( $invoice ) ) { |
|
396 | - return; |
|
397 | - } |
|
395 | + if ( empty( $invoice ) ) { |
|
396 | + return; |
|
397 | + } |
|
398 | 398 | |
399 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
400 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
399 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
400 | + $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
401 | 401 | |
402 | - $subscription->renew(); |
|
403 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
402 | + $subscription->renew(); |
|
403 | + wpinv_error_log( 'Subscription renewed.', false ); |
|
404 | 404 | |
405 | - } |
|
405 | + } |
|
406 | 406 | |
407 | - /** |
|
408 | - * Handles subscription cancelations. |
|
409 | - * |
|
410 | - * @param WPInv_Invoice $invoice Invoice object. |
|
411 | - */ |
|
412 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
407 | + /** |
|
408 | + * Handles subscription cancelations. |
|
409 | + * |
|
410 | + * @param WPInv_Invoice $invoice Invoice object. |
|
411 | + */ |
|
412 | + protected function ipn_txn_subscr_cancel( $invoice ) { |
|
413 | 413 | |
414 | - // Make sure the invoice has a subscription. |
|
415 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
416 | - |
|
417 | - if ( empty( $subscription ) ) { |
|
418 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
419 | - } |
|
420 | - |
|
421 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
422 | - $subscription->cancel(); |
|
423 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
414 | + // Make sure the invoice has a subscription. |
|
415 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
416 | + |
|
417 | + if ( empty( $subscription ) ) { |
|
418 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
419 | + } |
|
420 | + |
|
421 | + wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
422 | + $subscription->cancel(); |
|
423 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
424 | 424 | |
425 | - } |
|
425 | + } |
|
426 | 426 | |
427 | - /** |
|
428 | - * Handles subscription completions. |
|
429 | - * |
|
430 | - * @param WPInv_Invoice $invoice Invoice object. |
|
431 | - * @param array $posted Posted data. |
|
432 | - */ |
|
433 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
427 | + /** |
|
428 | + * Handles subscription completions. |
|
429 | + * |
|
430 | + * @param WPInv_Invoice $invoice Invoice object. |
|
431 | + * @param array $posted Posted data. |
|
432 | + */ |
|
433 | + protected function ipn_txn_subscr_eot( $invoice ) { |
|
434 | 434 | |
435 | - // Make sure the invoice has a subscription. |
|
436 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
435 | + // Make sure the invoice has a subscription. |
|
436 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
437 | 437 | |
438 | - if ( empty( $subscription ) ) { |
|
439 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
440 | - } |
|
438 | + if ( empty( $subscription ) ) { |
|
439 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
440 | + } |
|
441 | 441 | |
442 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
443 | - $subscription->complete(); |
|
444 | - wpinv_error_log( 'Subscription completed.', false ); |
|
442 | + wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
443 | + $subscription->complete(); |
|
444 | + wpinv_error_log( 'Subscription completed.', false ); |
|
445 | 445 | |
446 | - } |
|
446 | + } |
|
447 | 447 | |
448 | - /** |
|
449 | - * Handles subscription fails. |
|
450 | - * |
|
451 | - * @param WPInv_Invoice $invoice Invoice object. |
|
452 | - * @param array $posted Posted data. |
|
453 | - */ |
|
454 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
448 | + /** |
|
449 | + * Handles subscription fails. |
|
450 | + * |
|
451 | + * @param WPInv_Invoice $invoice Invoice object. |
|
452 | + * @param array $posted Posted data. |
|
453 | + */ |
|
454 | + protected function ipn_txn_subscr_failed( $invoice ) { |
|
455 | 455 | |
456 | - // Make sure the invoice has a subscription. |
|
457 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
456 | + // Make sure the invoice has a subscription. |
|
457 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
458 | 458 | |
459 | - if ( empty( $subscription ) ) { |
|
460 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
461 | - } |
|
459 | + if ( empty( $subscription ) ) { |
|
460 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
461 | + } |
|
462 | 462 | |
463 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
464 | - $subscription->failing(); |
|
465 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
463 | + wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
464 | + $subscription->failing(); |
|
465 | + wpinv_error_log( 'Subscription marked as failing.', false ); |
|
466 | 466 | |
467 | - } |
|
467 | + } |
|
468 | 468 | |
469 | - /** |
|
470 | - * Handles subscription suspensions. |
|
471 | - * |
|
472 | - * @param WPInv_Invoice $invoice Invoice object. |
|
473 | - * @param array $posted Posted data. |
|
474 | - */ |
|
475 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
469 | + /** |
|
470 | + * Handles subscription suspensions. |
|
471 | + * |
|
472 | + * @param WPInv_Invoice $invoice Invoice object. |
|
473 | + * @param array $posted Posted data. |
|
474 | + */ |
|
475 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
476 | 476 | |
477 | - // Make sure the invoice has a subscription. |
|
478 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
477 | + // Make sure the invoice has a subscription. |
|
478 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
479 | 479 | |
480 | - if ( empty( $subscription ) ) { |
|
481 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
482 | - } |
|
483 | - |
|
484 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
485 | - $subscription->cancel(); |
|
486 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
487 | - } |
|
480 | + if ( empty( $subscription ) ) { |
|
481 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
482 | + } |
|
483 | + |
|
484 | + wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
485 | + $subscription->cancel(); |
|
486 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
487 | + } |
|
488 | 488 | |
489 | 489 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -16,85 +16,85 @@ discard block |
||
16 | 16 | */ |
17 | 17 | class GetPaid_Meta_Box_Invoice_Address { |
18 | 18 | |
19 | - /** |
|
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
24 | - public static function output( $post ) { |
|
25 | - |
|
26 | - // Prepare the invoice. |
|
27 | - $invoice = new WPInv_Invoice( $post ); |
|
28 | - $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id(); |
|
29 | - $customer = new WP_User( $customer ); |
|
30 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ); |
|
31 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
32 | - |
|
33 | - // Address fields. |
|
34 | - $address_fields = array( |
|
35 | - 'first_name' => array( |
|
36 | - 'label' => __( 'First Name', 'invoicing' ), |
|
37 | - 'type' => 'text', |
|
38 | - ), |
|
39 | - 'last_name' => array( |
|
40 | - 'label' => __( 'Last Name', 'invoicing' ), |
|
41 | - 'type' => 'text', |
|
42 | - ), |
|
43 | - 'company' => array( |
|
44 | - 'label' => __( 'Company', 'invoicing' ), |
|
45 | - 'type' => 'text', |
|
46 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
47 | - ), |
|
48 | - 'vat_number' => array( |
|
49 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
50 | - 'type' => 'text', |
|
51 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
52 | - ), |
|
53 | - 'address' => array( |
|
54 | - 'label' => __( 'Address', 'invoicing' ), |
|
55 | - 'type' => 'text', |
|
56 | - ), |
|
57 | - 'city' => array( |
|
58 | - 'label' => __( 'City', 'invoicing' ), |
|
59 | - 'type' => 'text', |
|
60 | - ), |
|
61 | - 'country' => array( |
|
62 | - 'label' => __( 'Country', 'invoicing' ), |
|
63 | - 'type' => 'select', |
|
64 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
65 | - 'options' => wpinv_get_country_list(), |
|
66 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
67 | - ), |
|
68 | - 'state' => array( |
|
69 | - 'label' => __( 'State', 'invoicing' ), |
|
70 | - 'type' => 'text', |
|
71 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
72 | - ), |
|
73 | - 'zip' => array( |
|
74 | - 'label' => __( 'Zip', 'invoicing' ), |
|
75 | - 'type' => 'text', |
|
76 | - ), |
|
77 | - 'phone' => array( |
|
78 | - 'label' => __( 'Phone', 'invoicing' ), |
|
79 | - 'type' => 'text', |
|
80 | - ), |
|
81 | - ); |
|
82 | - |
|
83 | - $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) ); |
|
84 | - |
|
85 | - if ( ! empty( $states ) ) { |
|
86 | - $address_fields['state']['type'] = 'select'; |
|
87 | - $address_fields['state']['options'] = $states; |
|
88 | - $address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' ); |
|
89 | - } |
|
90 | - |
|
91 | - // Maybe remove the VAT field. |
|
92 | - if ( ! wpinv_use_taxes() ) { |
|
93 | - unset( $address_fields['vat_number'] ); |
|
94 | - } |
|
95 | - |
|
96 | - $address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice ); |
|
97 | - ?> |
|
19 | + /** |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | + public static function output( $post ) { |
|
25 | + |
|
26 | + // Prepare the invoice. |
|
27 | + $invoice = new WPInv_Invoice( $post ); |
|
28 | + $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id(); |
|
29 | + $customer = new WP_User( $customer ); |
|
30 | + $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ); |
|
31 | + wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
32 | + |
|
33 | + // Address fields. |
|
34 | + $address_fields = array( |
|
35 | + 'first_name' => array( |
|
36 | + 'label' => __( 'First Name', 'invoicing' ), |
|
37 | + 'type' => 'text', |
|
38 | + ), |
|
39 | + 'last_name' => array( |
|
40 | + 'label' => __( 'Last Name', 'invoicing' ), |
|
41 | + 'type' => 'text', |
|
42 | + ), |
|
43 | + 'company' => array( |
|
44 | + 'label' => __( 'Company', 'invoicing' ), |
|
45 | + 'type' => 'text', |
|
46 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
47 | + ), |
|
48 | + 'vat_number' => array( |
|
49 | + 'label' => __( 'VAT Number', 'invoicing' ), |
|
50 | + 'type' => 'text', |
|
51 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
52 | + ), |
|
53 | + 'address' => array( |
|
54 | + 'label' => __( 'Address', 'invoicing' ), |
|
55 | + 'type' => 'text', |
|
56 | + ), |
|
57 | + 'city' => array( |
|
58 | + 'label' => __( 'City', 'invoicing' ), |
|
59 | + 'type' => 'text', |
|
60 | + ), |
|
61 | + 'country' => array( |
|
62 | + 'label' => __( 'Country', 'invoicing' ), |
|
63 | + 'type' => 'select', |
|
64 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
65 | + 'options' => wpinv_get_country_list(), |
|
66 | + 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
67 | + ), |
|
68 | + 'state' => array( |
|
69 | + 'label' => __( 'State', 'invoicing' ), |
|
70 | + 'type' => 'text', |
|
71 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
72 | + ), |
|
73 | + 'zip' => array( |
|
74 | + 'label' => __( 'Zip', 'invoicing' ), |
|
75 | + 'type' => 'text', |
|
76 | + ), |
|
77 | + 'phone' => array( |
|
78 | + 'label' => __( 'Phone', 'invoicing' ), |
|
79 | + 'type' => 'text', |
|
80 | + ), |
|
81 | + ); |
|
82 | + |
|
83 | + $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) ); |
|
84 | + |
|
85 | + if ( ! empty( $states ) ) { |
|
86 | + $address_fields['state']['type'] = 'select'; |
|
87 | + $address_fields['state']['options'] = $states; |
|
88 | + $address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' ); |
|
89 | + } |
|
90 | + |
|
91 | + // Maybe remove the VAT field. |
|
92 | + if ( ! wpinv_use_taxes() ) { |
|
93 | + unset( $address_fields['vat_number'] ); |
|
94 | + } |
|
95 | + |
|
96 | + $address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice ); |
|
97 | + ?> |
|
98 | 98 | |
99 | 99 | <style> |
100 | 100 | #wpinv-address label { |
@@ -119,19 +119,19 @@ discard block |
||
119 | 119 | <div id="getpaid-invoice-email-wrapper" class="d-none"> |
120 | 120 | <input type="hidden" id="getpaid-invoice-create-new-user" name="wpinv_new_user" value="" /> |
121 | 121 | <?php |
122 | - aui()->input( |
|
123 | - array( |
|
124 | - 'type' => 'text', |
|
125 | - 'id' => 'getpaid-invoice-new-user-email', |
|
126 | - 'name' => 'wpinv_email', |
|
127 | - 'label' => __( 'Email', 'invoicing' ) . '<span class="required">*</span>', |
|
128 | - 'label_type' => 'vertical', |
|
129 | - 'placeholder' => '[email protected]', |
|
130 | - 'class' => 'form-control-sm', |
|
131 | - ), |
|
132 | - true |
|
133 | - ); |
|
134 | - ?> |
|
122 | + aui()->input( |
|
123 | + array( |
|
124 | + 'type' => 'text', |
|
125 | + 'id' => 'getpaid-invoice-new-user-email', |
|
126 | + 'name' => 'wpinv_email', |
|
127 | + 'label' => __( 'Email', 'invoicing' ) . '<span class="required">*</span>', |
|
128 | + 'label_type' => 'vertical', |
|
129 | + 'placeholder' => '[email protected]', |
|
130 | + 'class' => 'form-control-sm', |
|
131 | + ), |
|
132 | + true |
|
133 | + ); |
|
134 | + ?> |
|
135 | 135 | </div> |
136 | 136 | </div> |
137 | 137 | <div class="col-12 col-sm-6 form-group mb-3 mt-sm-4"> |
@@ -155,39 +155,39 @@ discard block |
||
155 | 155 | <div class="col-12 col-sm-6 getpaid-invoice-address-field__<?php echo esc_attr( $key ); ?>--wrapper"> |
156 | 156 | <?php |
157 | 157 | |
158 | - if ( 'select' === $field['type'] ) { |
|
159 | - aui()->select( |
|
160 | - array( |
|
161 | - 'id' => 'wpinv_' . $key, |
|
162 | - 'name' => 'wpinv_' . $key, |
|
163 | - 'label' => $field['label'], |
|
164 | - 'label_type' => 'vertical', |
|
165 | - 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
166 | - 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
167 | - 'value' => $invoice->get( $key, 'edit' ), |
|
168 | - 'options' => $field['options'], |
|
169 | - 'data-allow-clear' => 'false', |
|
170 | - 'select2' => true, |
|
171 | - ), |
|
172 | - true |
|
173 | - ); |
|
174 | - } else { |
|
175 | - aui()->input( |
|
176 | - array( |
|
177 | - 'type' => $field['type'], |
|
178 | - 'id' => 'wpinv_' . $key, |
|
179 | - 'name' => 'wpinv_' . $key, |
|
180 | - 'label' => $field['label'], |
|
181 | - 'label_type' => 'vertical', |
|
182 | - 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
183 | - 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
184 | - 'value' => $invoice->get( $key, 'edit' ), |
|
185 | - ), |
|
186 | - true |
|
187 | - ); |
|
188 | - } |
|
189 | - |
|
190 | - ?> |
|
158 | + if ( 'select' === $field['type'] ) { |
|
159 | + aui()->select( |
|
160 | + array( |
|
161 | + 'id' => 'wpinv_' . $key, |
|
162 | + 'name' => 'wpinv_' . $key, |
|
163 | + 'label' => $field['label'], |
|
164 | + 'label_type' => 'vertical', |
|
165 | + 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
166 | + 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
167 | + 'value' => $invoice->get( $key, 'edit' ), |
|
168 | + 'options' => $field['options'], |
|
169 | + 'data-allow-clear' => 'false', |
|
170 | + 'select2' => true, |
|
171 | + ), |
|
172 | + true |
|
173 | + ); |
|
174 | + } else { |
|
175 | + aui()->input( |
|
176 | + array( |
|
177 | + 'type' => $field['type'], |
|
178 | + 'id' => 'wpinv_' . $key, |
|
179 | + 'name' => 'wpinv_' . $key, |
|
180 | + 'label' => $field['label'], |
|
181 | + 'label_type' => 'vertical', |
|
182 | + 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
183 | + 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
184 | + 'value' => $invoice->get( $key, 'edit' ), |
|
185 | + ), |
|
186 | + true |
|
187 | + ); |
|
188 | + } |
|
189 | + |
|
190 | + ?> |
|
191 | 191 | </div> |
192 | 192 | <?php endforeach; ?> |
193 | 193 | </div> |
@@ -198,48 +198,48 @@ discard block |
||
198 | 198 | <div class="row"> |
199 | 199 | <div class="col-12 col-sm-6"> |
200 | 200 | <?php |
201 | - aui()->select( |
|
202 | - array( |
|
203 | - 'id' => 'wpinv_template', |
|
204 | - 'name' => 'wpinv_template', |
|
205 | - 'label' => __( 'Template', 'invoicing' ), |
|
206 | - 'label_type' => 'vertical', |
|
207 | - 'placeholder' => __( 'Choose a template', 'invoicing' ), |
|
208 | - 'class' => 'form-control-sm', |
|
209 | - 'value' => $invoice->get_template( 'edit' ), |
|
210 | - 'options' => array( |
|
211 | - 'quantity' => __( 'Quantity', 'invoicing' ), |
|
212 | - 'hours' => __( 'Hours', 'invoicing' ), |
|
213 | - ), |
|
214 | - 'data-allow-clear' => 'false', |
|
215 | - 'select2' => true, |
|
216 | - ), |
|
217 | - true |
|
218 | - ); |
|
219 | - ?> |
|
201 | + aui()->select( |
|
202 | + array( |
|
203 | + 'id' => 'wpinv_template', |
|
204 | + 'name' => 'wpinv_template', |
|
205 | + 'label' => __( 'Template', 'invoicing' ), |
|
206 | + 'label_type' => 'vertical', |
|
207 | + 'placeholder' => __( 'Choose a template', 'invoicing' ), |
|
208 | + 'class' => 'form-control-sm', |
|
209 | + 'value' => $invoice->get_template( 'edit' ), |
|
210 | + 'options' => array( |
|
211 | + 'quantity' => __( 'Quantity', 'invoicing' ), |
|
212 | + 'hours' => __( 'Hours', 'invoicing' ), |
|
213 | + ), |
|
214 | + 'data-allow-clear' => 'false', |
|
215 | + 'select2' => true, |
|
216 | + ), |
|
217 | + true |
|
218 | + ); |
|
219 | + ?> |
|
220 | 220 | </div> |
221 | 221 | <div class="col-12 col-sm-6"> |
222 | 222 | <?php |
223 | 223 | |
224 | - // Set currency. |
|
225 | - aui()->select( |
|
226 | - array( |
|
227 | - 'id' => 'wpinv_currency', |
|
228 | - 'name' => 'wpinv_currency', |
|
229 | - 'label' => __( 'Currency', 'invoicing' ), |
|
230 | - 'label_type' => 'vertical', |
|
231 | - 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
|
232 | - 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
|
233 | - 'value' => $invoice->get_currency( 'edit' ), |
|
234 | - 'required' => false, |
|
235 | - 'data-allow-clear' => 'false', |
|
236 | - 'select2' => true, |
|
237 | - 'options' => wpinv_get_currencies(), |
|
238 | - ), |
|
239 | - true |
|
240 | - ); |
|
241 | - |
|
242 | - ?> |
|
224 | + // Set currency. |
|
225 | + aui()->select( |
|
226 | + array( |
|
227 | + 'id' => 'wpinv_currency', |
|
228 | + 'name' => 'wpinv_currency', |
|
229 | + 'label' => __( 'Currency', 'invoicing' ), |
|
230 | + 'label_type' => 'vertical', |
|
231 | + 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
|
232 | + 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
|
233 | + 'value' => $invoice->get_currency( 'edit' ), |
|
234 | + 'required' => false, |
|
235 | + 'data-allow-clear' => 'false', |
|
236 | + 'select2' => true, |
|
237 | + 'options' => wpinv_get_currencies(), |
|
238 | + ), |
|
239 | + true |
|
240 | + ); |
|
241 | + |
|
242 | + ?> |
|
243 | 243 | </div> |
244 | 244 | </div> |
245 | 245 | |
@@ -249,123 +249,123 @@ discard block |
||
249 | 249 | <div class="row"> |
250 | 250 | <div class="col-12 col-sm-6"> |
251 | 251 | <?php |
252 | - aui()->input( |
|
253 | - array( |
|
254 | - 'type' => 'text', |
|
255 | - 'id' => 'wpinv_company_id', |
|
256 | - 'name' => 'wpinv_company_id', |
|
257 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
258 | - 'label_type' => 'vertical', |
|
259 | - 'placeholder' => '', |
|
260 | - 'class' => 'form-control-sm', |
|
261 | - 'value' => $invoice->get_company_id( 'edit' ), |
|
262 | - ), |
|
263 | - true |
|
264 | - ); |
|
265 | - ?> |
|
252 | + aui()->input( |
|
253 | + array( |
|
254 | + 'type' => 'text', |
|
255 | + 'id' => 'wpinv_company_id', |
|
256 | + 'name' => 'wpinv_company_id', |
|
257 | + 'label' => __( 'Company ID', 'invoicing' ), |
|
258 | + 'label_type' => 'vertical', |
|
259 | + 'placeholder' => '', |
|
260 | + 'class' => 'form-control-sm', |
|
261 | + 'value' => $invoice->get_company_id( 'edit' ), |
|
262 | + ), |
|
263 | + true |
|
264 | + ); |
|
265 | + ?> |
|
266 | 266 | </div> |
267 | 267 | </div> |
268 | 268 | |
269 | 269 | <?php do_action( 'getpaid_after_metabox_invoice_address', $invoice ); ?> |
270 | 270 | </div> |
271 | 271 | <?php |
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Save meta box data. |
|
276 | - * |
|
277 | - * @param int $post_id |
|
278 | - * @param array $posted the posted data. |
|
279 | - */ |
|
280 | - public static function save( $post_id, $posted ) { |
|
281 | - |
|
282 | - // Prepare the invoice. |
|
283 | - $invoice = new WPInv_Invoice( $post_id ); |
|
284 | - |
|
285 | - // Load new data. |
|
286 | - $invoice->set_props( |
|
287 | - array( |
|
288 | - 'template' => isset( $posted['wpinv_template'] ) ? wpinv_clean( $posted['wpinv_template'] ) : null, |
|
289 | - 'email_cc' => isset( $posted['wpinv_cc'] ) ? wpinv_clean( $posted['wpinv_cc'] ) : null, |
|
290 | - 'disable_taxes' => ! empty( $posted['disable_taxes'] ), |
|
291 | - 'currency' => isset( $posted['wpinv_currency'] ) ? wpinv_clean( $posted['wpinv_currency'] ) : null, |
|
292 | - 'gateway' => ( $invoice->needs_payment() && isset( $posted['wpinv_gateway'] ) ) ? wpinv_clean( $posted['wpinv_gateway'] ) : null, |
|
293 | - 'address' => isset( $posted['wpinv_address'] ) ? wpinv_clean( $posted['wpinv_address'] ) : null, |
|
294 | - 'vat_number' => isset( $posted['wpinv_vat_number'] ) ? wpinv_clean( $posted['wpinv_vat_number'] ) : null, |
|
295 | - 'company' => isset( $posted['wpinv_company'] ) ? wpinv_clean( $posted['wpinv_company'] ) : null, |
|
296 | - 'company_id' => isset( $posted['wpinv_company_id'] ) ? wpinv_clean( $posted['wpinv_company_id'] ) : null, |
|
297 | - 'zip' => isset( $posted['wpinv_zip'] ) ? wpinv_clean( $posted['wpinv_zip'] ) : null, |
|
298 | - 'state' => isset( $posted['wpinv_state'] ) ? wpinv_clean( $posted['wpinv_state'] ) : null, |
|
299 | - 'city' => isset( $posted['wpinv_city'] ) ? wpinv_clean( $posted['wpinv_city'] ) : null, |
|
300 | - 'country' => isset( $posted['wpinv_country'] ) ? wpinv_clean( $posted['wpinv_country'] ) : null, |
|
301 | - 'phone' => isset( $posted['wpinv_phone'] ) ? wpinv_clean( $posted['wpinv_phone'] ) : null, |
|
302 | - 'first_name' => isset( $posted['wpinv_first_name'] ) ? wpinv_clean( $posted['wpinv_first_name'] ) : null, |
|
303 | - 'last_name' => isset( $posted['wpinv_last_name'] ) ? wpinv_clean( $posted['wpinv_last_name'] ) : null, |
|
304 | - 'author' => isset( $posted['post_author_override'] ) ? wpinv_clean( $posted['post_author_override'] ) : null, |
|
305 | - 'date_created' => isset( $posted['date_created'] ) ? wpinv_clean( $posted['date_created'] ) : null, |
|
306 | - 'date_completed' => isset( $posted['wpinv_date_completed'] ) ? wpinv_clean( $posted['wpinv_date_completed'] ) : null, |
|
307 | - 'due_date' => isset( $posted['wpinv_due_date'] ) ? wpinv_clean( $posted['wpinv_due_date'] ) : null, |
|
308 | - 'number' => isset( $posted['wpinv_number'] ) ? wpinv_clean( $posted['wpinv_number'] ) : null, |
|
309 | - 'status' => isset( $posted['wpinv_status'] ) ? wpinv_clean( $posted['wpinv_status'] ) : null, |
|
310 | - ) |
|
311 | - ); |
|
312 | - |
|
313 | - // Discount code. |
|
314 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
315 | - |
|
316 | - if ( isset( $posted['wpinv_discount_code'] ) ) { |
|
317 | - $invoice->set_discount_code( wpinv_clean( $posted['wpinv_discount_code'] ) ); |
|
318 | - } |
|
319 | - |
|
320 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
321 | - if ( $discount->exists() ) { |
|
322 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
323 | - } else { |
|
324 | - $invoice->remove_discount( 'discount_code' ); |
|
325 | - } |
|
326 | - |
|
327 | - // Recalculate totals. |
|
328 | - $invoice->recalculate_total(); |
|
329 | - |
|
330 | - } |
|
331 | - |
|
332 | - // If we're creating a new user... |
|
333 | - if ( ! empty( $posted['wpinv_new_user'] ) && is_email( stripslashes( $posted['wpinv_email'] ) ) ) { |
|
334 | - |
|
335 | - // Attempt to create the user. |
|
336 | - $user = wpinv_create_user( sanitize_email( stripslashes( $posted['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() ); |
|
337 | - |
|
338 | - // If successful, update the invoice author. |
|
339 | - if ( is_numeric( $user ) ) { |
|
340 | - $invoice->set_author( $user ); |
|
341 | - } else { |
|
342 | - wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ ); |
|
343 | - } |
|
344 | - } |
|
345 | - |
|
346 | - // Do not send new invoice notifications. |
|
347 | - $GLOBALS['wpinv_skip_invoice_notification'] = true; |
|
348 | - |
|
349 | - // Save the invoice. |
|
350 | - $invoice->save(); |
|
351 | - |
|
352 | - // Save the user address. |
|
353 | - getpaid_save_invoice_user_address( $invoice ); |
|
354 | - |
|
355 | - // Undo do not send new invoice notifications. |
|
356 | - $GLOBALS['wpinv_skip_invoice_notification'] = false; |
|
357 | - |
|
358 | - // (Maybe) send new user notification. |
|
359 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
360 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) { |
|
361 | - wp_send_new_user_notifications( $user, 'user' ); |
|
362 | - } |
|
363 | - |
|
364 | - if ( ! empty( $posted['send_to_customer'] ) && ! $invoice->is_draft() ) { |
|
365 | - getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true ); |
|
366 | - } |
|
367 | - |
|
368 | - // Fires after an invoice is saved. |
|
369 | - do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
370 | - } |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Save meta box data. |
|
276 | + * |
|
277 | + * @param int $post_id |
|
278 | + * @param array $posted the posted data. |
|
279 | + */ |
|
280 | + public static function save( $post_id, $posted ) { |
|
281 | + |
|
282 | + // Prepare the invoice. |
|
283 | + $invoice = new WPInv_Invoice( $post_id ); |
|
284 | + |
|
285 | + // Load new data. |
|
286 | + $invoice->set_props( |
|
287 | + array( |
|
288 | + 'template' => isset( $posted['wpinv_template'] ) ? wpinv_clean( $posted['wpinv_template'] ) : null, |
|
289 | + 'email_cc' => isset( $posted['wpinv_cc'] ) ? wpinv_clean( $posted['wpinv_cc'] ) : null, |
|
290 | + 'disable_taxes' => ! empty( $posted['disable_taxes'] ), |
|
291 | + 'currency' => isset( $posted['wpinv_currency'] ) ? wpinv_clean( $posted['wpinv_currency'] ) : null, |
|
292 | + 'gateway' => ( $invoice->needs_payment() && isset( $posted['wpinv_gateway'] ) ) ? wpinv_clean( $posted['wpinv_gateway'] ) : null, |
|
293 | + 'address' => isset( $posted['wpinv_address'] ) ? wpinv_clean( $posted['wpinv_address'] ) : null, |
|
294 | + 'vat_number' => isset( $posted['wpinv_vat_number'] ) ? wpinv_clean( $posted['wpinv_vat_number'] ) : null, |
|
295 | + 'company' => isset( $posted['wpinv_company'] ) ? wpinv_clean( $posted['wpinv_company'] ) : null, |
|
296 | + 'company_id' => isset( $posted['wpinv_company_id'] ) ? wpinv_clean( $posted['wpinv_company_id'] ) : null, |
|
297 | + 'zip' => isset( $posted['wpinv_zip'] ) ? wpinv_clean( $posted['wpinv_zip'] ) : null, |
|
298 | + 'state' => isset( $posted['wpinv_state'] ) ? wpinv_clean( $posted['wpinv_state'] ) : null, |
|
299 | + 'city' => isset( $posted['wpinv_city'] ) ? wpinv_clean( $posted['wpinv_city'] ) : null, |
|
300 | + 'country' => isset( $posted['wpinv_country'] ) ? wpinv_clean( $posted['wpinv_country'] ) : null, |
|
301 | + 'phone' => isset( $posted['wpinv_phone'] ) ? wpinv_clean( $posted['wpinv_phone'] ) : null, |
|
302 | + 'first_name' => isset( $posted['wpinv_first_name'] ) ? wpinv_clean( $posted['wpinv_first_name'] ) : null, |
|
303 | + 'last_name' => isset( $posted['wpinv_last_name'] ) ? wpinv_clean( $posted['wpinv_last_name'] ) : null, |
|
304 | + 'author' => isset( $posted['post_author_override'] ) ? wpinv_clean( $posted['post_author_override'] ) : null, |
|
305 | + 'date_created' => isset( $posted['date_created'] ) ? wpinv_clean( $posted['date_created'] ) : null, |
|
306 | + 'date_completed' => isset( $posted['wpinv_date_completed'] ) ? wpinv_clean( $posted['wpinv_date_completed'] ) : null, |
|
307 | + 'due_date' => isset( $posted['wpinv_due_date'] ) ? wpinv_clean( $posted['wpinv_due_date'] ) : null, |
|
308 | + 'number' => isset( $posted['wpinv_number'] ) ? wpinv_clean( $posted['wpinv_number'] ) : null, |
|
309 | + 'status' => isset( $posted['wpinv_status'] ) ? wpinv_clean( $posted['wpinv_status'] ) : null, |
|
310 | + ) |
|
311 | + ); |
|
312 | + |
|
313 | + // Discount code. |
|
314 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
315 | + |
|
316 | + if ( isset( $posted['wpinv_discount_code'] ) ) { |
|
317 | + $invoice->set_discount_code( wpinv_clean( $posted['wpinv_discount_code'] ) ); |
|
318 | + } |
|
319 | + |
|
320 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
321 | + if ( $discount->exists() ) { |
|
322 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
323 | + } else { |
|
324 | + $invoice->remove_discount( 'discount_code' ); |
|
325 | + } |
|
326 | + |
|
327 | + // Recalculate totals. |
|
328 | + $invoice->recalculate_total(); |
|
329 | + |
|
330 | + } |
|
331 | + |
|
332 | + // If we're creating a new user... |
|
333 | + if ( ! empty( $posted['wpinv_new_user'] ) && is_email( stripslashes( $posted['wpinv_email'] ) ) ) { |
|
334 | + |
|
335 | + // Attempt to create the user. |
|
336 | + $user = wpinv_create_user( sanitize_email( stripslashes( $posted['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() ); |
|
337 | + |
|
338 | + // If successful, update the invoice author. |
|
339 | + if ( is_numeric( $user ) ) { |
|
340 | + $invoice->set_author( $user ); |
|
341 | + } else { |
|
342 | + wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ ); |
|
343 | + } |
|
344 | + } |
|
345 | + |
|
346 | + // Do not send new invoice notifications. |
|
347 | + $GLOBALS['wpinv_skip_invoice_notification'] = true; |
|
348 | + |
|
349 | + // Save the invoice. |
|
350 | + $invoice->save(); |
|
351 | + |
|
352 | + // Save the user address. |
|
353 | + getpaid_save_invoice_user_address( $invoice ); |
|
354 | + |
|
355 | + // Undo do not send new invoice notifications. |
|
356 | + $GLOBALS['wpinv_skip_invoice_notification'] = false; |
|
357 | + |
|
358 | + // (Maybe) send new user notification. |
|
359 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
360 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) { |
|
361 | + wp_send_new_user_notifications( $user, 'user' ); |
|
362 | + } |
|
363 | + |
|
364 | + if ( ! empty( $posted['send_to_customer'] ) && ! $invoice->is_draft() ) { |
|
365 | + getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true ); |
|
366 | + } |
|
367 | + |
|
368 | + // Fires after an invoice is saved. |
|
369 | + do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
370 | + } |
|
371 | 371 | } |
@@ -14,30 +14,30 @@ discard block |
||
14 | 14 | class WPInv_Invoice extends GetPaid_Data { |
15 | 15 | |
16 | 16 | /** |
17 | - * Which data store to load. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
17 | + * Which data store to load. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | 21 | protected $data_store_name = 'invoice'; |
22 | 22 | |
23 | 23 | /** |
24 | - * This is the name of this object type. |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
24 | + * This is the name of this object type. |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | 28 | protected $object_type = 'invoice'; |
29 | 29 | |
30 | 30 | /** |
31 | - * Item Data array. This is the core item data exposed in APIs. |
|
32 | - * |
|
33 | - * @since 1.0.19 |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - protected $data = array( |
|
37 | - 'parent_id' => 0, |
|
38 | - 'status' => 'wpi-pending', |
|
39 | - 'version' => '', |
|
40 | - 'date_created' => null, |
|
31 | + * Item Data array. This is the core item data exposed in APIs. |
|
32 | + * |
|
33 | + * @since 1.0.19 |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + protected $data = array( |
|
37 | + 'parent_id' => 0, |
|
38 | + 'status' => 'wpi-pending', |
|
39 | + 'version' => '', |
|
40 | + 'date_created' => null, |
|
41 | 41 | 'date_modified' => null, |
42 | 42 | 'due_date' => null, |
43 | 43 | 'completed_date' => null, |
@@ -60,17 +60,17 @@ discard block |
||
60 | 60 | 'state' => null, |
61 | 61 | 'zip' => null, |
62 | 62 | 'company' => null, |
63 | - 'company_id' => null, |
|
63 | + 'company_id' => null, |
|
64 | 64 | 'vat_number' => null, |
65 | 65 | 'vat_rate' => null, |
66 | 66 | 'address' => null, |
67 | 67 | 'address_confirmed' => false, |
68 | 68 | 'shipping' => null, |
69 | - 'subtotal' => 0, |
|
69 | + 'subtotal' => 0, |
|
70 | 70 | 'total_discount' => 0, |
71 | 71 | 'total_tax' => 0, |
72 | - 'total_fees' => 0, |
|
73 | - 'total' => 0, |
|
72 | + 'total_fees' => 0, |
|
73 | + 'total' => 0, |
|
74 | 74 | 'fees' => array(), |
75 | 75 | 'discounts' => array(), |
76 | 76 | 'taxes' => array(), |
@@ -82,22 +82,22 @@ discard block |
||
82 | 82 | 'transaction_id' => '', |
83 | 83 | 'currency' => '', |
84 | 84 | 'disable_taxes' => false, |
85 | - 'subscription_id' => null, |
|
86 | - 'remote_subscription_id' => null, |
|
87 | - 'is_viewed' => false, |
|
88 | - 'email_cc' => '', |
|
89 | - 'template' => 'quantity', // hours, amount only |
|
90 | - 'created_via' => null, |
|
85 | + 'subscription_id' => null, |
|
86 | + 'remote_subscription_id' => null, |
|
87 | + 'is_viewed' => false, |
|
88 | + 'email_cc' => '', |
|
89 | + 'template' => 'quantity', // hours, amount only |
|
90 | + 'created_via' => null, |
|
91 | 91 | ); |
92 | 92 | |
93 | 93 | /** |
94 | - * Stores meta in cache for future reads. |
|
95 | - * |
|
96 | - * A group must be set to to enable caching. |
|
97 | - * |
|
98 | - * @var string |
|
99 | - */ |
|
100 | - protected $cache_group = 'getpaid_invoices'; |
|
94 | + * Stores meta in cache for future reads. |
|
95 | + * |
|
96 | + * A group must be set to to enable caching. |
|
97 | + * |
|
98 | + * @var string |
|
99 | + */ |
|
100 | + protected $cache_group = 'getpaid_invoices'; |
|
101 | 101 | |
102 | 102 | /** |
103 | 103 | * Stores a reference to the original WP_Post object |
@@ -111,110 +111,110 @@ discard block |
||
111 | 111 | * |
112 | 112 | * @var int |
113 | 113 | */ |
114 | - protected $recurring_item = null; |
|
114 | + protected $recurring_item = null; |
|
115 | 115 | |
116 | - /** |
|
116 | + /** |
|
117 | 117 | * Stores an array of item totals. |
118 | - * |
|
119 | - * e.g $totals['discount'] = array( |
|
120 | - * 'initial' => 10, |
|
121 | - * 'recurring' => 10, |
|
122 | - * ) |
|
118 | + * |
|
119 | + * e.g $totals['discount'] = array( |
|
120 | + * 'initial' => 10, |
|
121 | + * 'recurring' => 10, |
|
122 | + * ) |
|
123 | 123 | * |
124 | 124 | * @var array |
125 | 125 | */ |
126 | - protected $totals = array(); |
|
126 | + protected $totals = array(); |
|
127 | 127 | |
128 | - /** |
|
128 | + /** |
|
129 | 129 | * Tax rate. |
130 | - * |
|
130 | + * |
|
131 | 131 | * @var float |
132 | 132 | */ |
133 | - protected $tax_rate = 0; |
|
133 | + protected $tax_rate = 0; |
|
134 | 134 | |
135 | - /** |
|
136 | - * Stores the status transition information. |
|
137 | - * |
|
138 | - * @since 1.0.19 |
|
139 | - * @var bool|array |
|
140 | - */ |
|
141 | - protected $status_transition = false; |
|
135 | + /** |
|
136 | + * Stores the status transition information. |
|
137 | + * |
|
138 | + * @since 1.0.19 |
|
139 | + * @var bool|array |
|
140 | + */ |
|
141 | + protected $status_transition = false; |
|
142 | 142 | |
143 | 143 | /** |
144 | - * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
145 | - * |
|
146 | - * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
147 | - */ |
|
144 | + * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
145 | + * |
|
146 | + * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
147 | + */ |
|
148 | 148 | public function __construct( $invoice = 0 ) { |
149 | 149 | |
150 | 150 | parent::__construct( $invoice ); |
151 | 151 | |
152 | - if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) { |
|
153 | - $this->set_id( (int) $invoice ); |
|
154 | - } elseif ( $invoice instanceof self ) { |
|
155 | - $this->set_id( $invoice->get_id() ); |
|
156 | - } elseif ( ! empty( $invoice->ID ) ) { |
|
157 | - $this->set_id( $invoice->ID ); |
|
158 | - } elseif ( is_array( $invoice ) ) { |
|
159 | - $this->set_props( $invoice ); |
|
160 | - |
|
161 | - if ( isset( $invoice['ID'] ) ) { |
|
162 | - $this->set_id( $invoice['ID'] ); |
|
163 | - } |
|
152 | + if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) { |
|
153 | + $this->set_id( (int) $invoice ); |
|
154 | + } elseif ( $invoice instanceof self ) { |
|
155 | + $this->set_id( $invoice->get_id() ); |
|
156 | + } elseif ( ! empty( $invoice->ID ) ) { |
|
157 | + $this->set_id( $invoice->ID ); |
|
158 | + } elseif ( is_array( $invoice ) ) { |
|
159 | + $this->set_props( $invoice ); |
|
160 | + |
|
161 | + if ( isset( $invoice['ID'] ) ) { |
|
162 | + $this->set_id( $invoice['ID'] ); |
|
163 | + } |
|
164 | 164 | } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
165 | - $this->set_id( $invoice_id ); |
|
166 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
167 | - $this->set_id( $invoice_id ); |
|
168 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
169 | - $this->set_id( $invoice_id ); |
|
170 | - } else { |
|
171 | - $this->set_object_read( true ); |
|
172 | - } |
|
165 | + $this->set_id( $invoice_id ); |
|
166 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
167 | + $this->set_id( $invoice_id ); |
|
168 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
169 | + $this->set_id( $invoice_id ); |
|
170 | + } else { |
|
171 | + $this->set_object_read( true ); |
|
172 | + } |
|
173 | 173 | |
174 | 174 | // Load the datastore. |
175 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
175 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
176 | 176 | |
177 | - if ( $this->get_id() > 0 ) { |
|
177 | + if ( $this->get_id() > 0 ) { |
|
178 | 178 | $this->post = get_post( $this->get_id() ); |
179 | 179 | $this->ID = $this->get_id(); |
180 | - $this->data_store->read( $this ); |
|
180 | + $this->data_store->read( $this ); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
186 | - * Given an invoice key/number, it returns its id. |
|
187 | - * |
|
188 | - * |
|
189 | - * @static |
|
190 | - * @param string $value The invoice key or number |
|
191 | - * @param string $field Either key, transaction_id or number. |
|
192 | - * @since 1.0.15 |
|
193 | - * @return int |
|
194 | - */ |
|
195 | - public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
186 | + * Given an invoice key/number, it returns its id. |
|
187 | + * |
|
188 | + * |
|
189 | + * @static |
|
190 | + * @param string $value The invoice key or number |
|
191 | + * @param string $field Either key, transaction_id or number. |
|
192 | + * @since 1.0.15 |
|
193 | + * @return int |
|
194 | + */ |
|
195 | + public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
196 | 196 | global $wpdb; |
197 | 197 | |
198 | - // Trim the value. |
|
199 | - $value = trim( $value ); |
|
198 | + // Trim the value. |
|
199 | + $value = trim( $value ); |
|
200 | 200 | |
201 | - if ( empty( $value ) ) { |
|
202 | - return 0; |
|
203 | - } |
|
201 | + if ( empty( $value ) ) { |
|
202 | + return 0; |
|
203 | + } |
|
204 | 204 | |
205 | 205 | // Valid fields. |
206 | 206 | $fields = array( 'key', 'number', 'transaction_id' ); |
207 | 207 | |
208 | - // Ensure a field has been passed. |
|
209 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
210 | - return 0; |
|
211 | - } |
|
208 | + // Ensure a field has been passed. |
|
209 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
210 | + return 0; |
|
211 | + } |
|
212 | 212 | |
213 | - // Maybe retrieve from the cache. |
|
214 | - $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
215 | - if ( false !== $invoice_id ) { |
|
216 | - return $invoice_id; |
|
217 | - } |
|
213 | + // Maybe retrieve from the cache. |
|
214 | + $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
215 | + if ( false !== $invoice_id ) { |
|
216 | + return $invoice_id; |
|
217 | + } |
|
218 | 218 | |
219 | 219 | // Fetch from the db. |
220 | 220 | $table = $wpdb->prefix . 'getpaid_invoices'; |
@@ -222,10 +222,10 @@ discard block |
||
222 | 222 | $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
223 | 223 | ); |
224 | 224 | |
225 | - // Update the cache with our data |
|
226 | - wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
225 | + // Update the cache with our data |
|
226 | + wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
227 | 227 | |
228 | - return $invoice_id; |
|
228 | + return $invoice_id; |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
@@ -251,83 +251,83 @@ discard block |
||
251 | 251 | */ |
252 | 252 | |
253 | 253 | /** |
254 | - * Get parent invoice ID. |
|
255 | - * |
|
256 | - * @since 1.0.19 |
|
257 | - * @param string $context View or edit context. |
|
258 | - * @return int |
|
259 | - */ |
|
260 | - public function get_parent_id( $context = 'view' ) { |
|
261 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
254 | + * Get parent invoice ID. |
|
255 | + * |
|
256 | + * @since 1.0.19 |
|
257 | + * @param string $context View or edit context. |
|
258 | + * @return int |
|
259 | + */ |
|
260 | + public function get_parent_id( $context = 'view' ) { |
|
261 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
265 | - * Get parent invoice. |
|
266 | - * |
|
267 | - * @since 1.0.19 |
|
268 | - * @return WPInv_Invoice |
|
269 | - */ |
|
265 | + * Get parent invoice. |
|
266 | + * |
|
267 | + * @since 1.0.19 |
|
268 | + * @return WPInv_Invoice |
|
269 | + */ |
|
270 | 270 | public function get_parent_payment() { |
271 | 271 | return new WPInv_Invoice( $this->get_parent_id() ); |
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
275 | - * Alias for self::get_parent_payment(). |
|
276 | - * |
|
277 | - * @since 1.0.19 |
|
278 | - * @return WPInv_Invoice |
|
279 | - */ |
|
275 | + * Alias for self::get_parent_payment(). |
|
276 | + * |
|
277 | + * @since 1.0.19 |
|
278 | + * @return WPInv_Invoice |
|
279 | + */ |
|
280 | 280 | public function get_parent() { |
281 | 281 | return $this->get_parent_payment(); |
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
285 | - * Get invoice status. |
|
286 | - * |
|
287 | - * @since 1.0.19 |
|
288 | - * @param string $context View or edit context. |
|
289 | - * @return string |
|
290 | - */ |
|
291 | - public function get_status( $context = 'view' ) { |
|
292 | - return $this->get_prop( 'status', $context ); |
|
293 | - } |
|
285 | + * Get invoice status. |
|
286 | + * |
|
287 | + * @since 1.0.19 |
|
288 | + * @param string $context View or edit context. |
|
289 | + * @return string |
|
290 | + */ |
|
291 | + public function get_status( $context = 'view' ) { |
|
292 | + return $this->get_prop( 'status', $context ); |
|
293 | + } |
|
294 | 294 | |
295 | - /** |
|
296 | - * Retrieves an array of possible invoice statuses. |
|
297 | - * |
|
298 | - * @since 1.0.19 |
|
299 | - * @return array |
|
300 | - */ |
|
301 | - public function get_all_statuses() { |
|
302 | - return wpinv_get_invoice_statuses( true, true, $this ); |
|
295 | + /** |
|
296 | + * Retrieves an array of possible invoice statuses. |
|
297 | + * |
|
298 | + * @since 1.0.19 |
|
299 | + * @return array |
|
300 | + */ |
|
301 | + public function get_all_statuses() { |
|
302 | + return wpinv_get_invoice_statuses( true, true, $this ); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
306 | - * Get invoice status nice name. |
|
307 | - * |
|
308 | - * @since 1.0.19 |
|
309 | - * @return string |
|
310 | - */ |
|
306 | + * Get invoice status nice name. |
|
307 | + * |
|
308 | + * @since 1.0.19 |
|
309 | + * @return string |
|
310 | + */ |
|
311 | 311 | public function get_status_nicename() { |
312 | - $statuses = $this->get_all_statuses(); |
|
312 | + $statuses = $this->get_all_statuses(); |
|
313 | 313 | |
314 | 314 | $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status(); |
315 | 315 | |
316 | 316 | return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this ); |
317 | 317 | } |
318 | 318 | |
319 | - /** |
|
320 | - * Retrieves the invoice status class |
|
321 | - * |
|
322 | - * @since 1.0.19 |
|
323 | - * @return string |
|
324 | - */ |
|
325 | - public function get_status_class() { |
|
326 | - $statuses = getpaid_get_invoice_status_classes(); |
|
327 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark'; |
|
328 | - } |
|
319 | + /** |
|
320 | + * Retrieves the invoice status class |
|
321 | + * |
|
322 | + * @since 1.0.19 |
|
323 | + * @return string |
|
324 | + */ |
|
325 | + public function get_status_class() { |
|
326 | + $statuses = getpaid_get_invoice_status_classes(); |
|
327 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark'; |
|
328 | + } |
|
329 | 329 | |
330 | - /** |
|
330 | + /** |
|
331 | 331 | * Retrieves the invoice status label html |
332 | 332 | * |
333 | 333 | * @since 1.0.0 |
@@ -335,263 +335,263 @@ discard block |
||
335 | 335 | */ |
336 | 336 | public function get_status_label_html() { |
337 | 337 | |
338 | - $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
339 | - $status = sanitize_html_class( $this->get_status() ); |
|
340 | - $class = esc_attr( $this->get_status_class() ); |
|
341 | - |
|
342 | - return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Get plugin version when the invoice was created. |
|
347 | - * |
|
348 | - * @since 1.0.19 |
|
349 | - * @param string $context View or edit context. |
|
350 | - * @return string |
|
351 | - */ |
|
352 | - public function get_version( $context = 'view' ) { |
|
353 | - return $this->get_prop( 'version', $context ); |
|
354 | - } |
|
355 | - |
|
356 | - /** |
|
357 | - * @deprecated |
|
358 | - */ |
|
359 | - public function get_invoice_date( $format = true ) { |
|
360 | - $date = getpaid_format_date( $this->get_date_completed() ); |
|
361 | - $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
362 | - $formatted = getpaid_format_date( $date ); |
|
363 | - |
|
364 | - if ( $format ) { |
|
365 | - return $formatted; |
|
366 | - } |
|
367 | - |
|
368 | - return empty( $formatted ) ? '' : $date; |
|
369 | - |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Get date when the invoice was created. |
|
374 | - * |
|
375 | - * @since 1.0.19 |
|
376 | - * @param string $context View or edit context. |
|
377 | - * @return string |
|
378 | - */ |
|
379 | - public function get_date_created( $context = 'view' ) { |
|
380 | - return $this->get_prop( 'date_created', $context ); |
|
381 | - } |
|
382 | - |
|
383 | - /** |
|
384 | - * Alias for self::get_date_created(). |
|
385 | - * |
|
386 | - * @since 1.0.19 |
|
387 | - * @param string $context View or edit context. |
|
388 | - * @return string |
|
389 | - */ |
|
390 | - public function get_created_date( $context = 'view' ) { |
|
391 | - return $this->get_date_created( $context ); |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * Get GMT date when the invoice was created. |
|
396 | - * |
|
397 | - * @since 1.0.19 |
|
398 | - * @param string $context View or edit context. |
|
399 | - * @return string |
|
400 | - */ |
|
401 | - public function get_date_created_gmt( $context = 'view' ) { |
|
338 | + $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
339 | + $status = sanitize_html_class( $this->get_status() ); |
|
340 | + $class = esc_attr( $this->get_status_class() ); |
|
341 | + |
|
342 | + return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Get plugin version when the invoice was created. |
|
347 | + * |
|
348 | + * @since 1.0.19 |
|
349 | + * @param string $context View or edit context. |
|
350 | + * @return string |
|
351 | + */ |
|
352 | + public function get_version( $context = 'view' ) { |
|
353 | + return $this->get_prop( 'version', $context ); |
|
354 | + } |
|
355 | + |
|
356 | + /** |
|
357 | + * @deprecated |
|
358 | + */ |
|
359 | + public function get_invoice_date( $format = true ) { |
|
360 | + $date = getpaid_format_date( $this->get_date_completed() ); |
|
361 | + $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
362 | + $formatted = getpaid_format_date( $date ); |
|
363 | + |
|
364 | + if ( $format ) { |
|
365 | + return $formatted; |
|
366 | + } |
|
367 | + |
|
368 | + return empty( $formatted ) ? '' : $date; |
|
369 | + |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Get date when the invoice was created. |
|
374 | + * |
|
375 | + * @since 1.0.19 |
|
376 | + * @param string $context View or edit context. |
|
377 | + * @return string |
|
378 | + */ |
|
379 | + public function get_date_created( $context = 'view' ) { |
|
380 | + return $this->get_prop( 'date_created', $context ); |
|
381 | + } |
|
382 | + |
|
383 | + /** |
|
384 | + * Alias for self::get_date_created(). |
|
385 | + * |
|
386 | + * @since 1.0.19 |
|
387 | + * @param string $context View or edit context. |
|
388 | + * @return string |
|
389 | + */ |
|
390 | + public function get_created_date( $context = 'view' ) { |
|
391 | + return $this->get_date_created( $context ); |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * Get GMT date when the invoice was created. |
|
396 | + * |
|
397 | + * @since 1.0.19 |
|
398 | + * @param string $context View or edit context. |
|
399 | + * @return string |
|
400 | + */ |
|
401 | + public function get_date_created_gmt( $context = 'view' ) { |
|
402 | 402 | $date = $this->get_date_created( $context ); |
403 | 403 | |
404 | 404 | if ( $date ) { |
405 | 405 | $date = get_gmt_from_date( $date ); |
406 | 406 | } |
407 | - return $date; |
|
407 | + return $date; |
|
408 | 408 | } |
409 | 409 | |
410 | 410 | /** |
411 | - * Get date when the invoice was last modified. |
|
412 | - * |
|
413 | - * @since 1.0.19 |
|
414 | - * @param string $context View or edit context. |
|
415 | - * @return string |
|
416 | - */ |
|
417 | - public function get_date_modified( $context = 'view' ) { |
|
418 | - return $this->get_prop( 'date_modified', $context ); |
|
419 | - } |
|
411 | + * Get date when the invoice was last modified. |
|
412 | + * |
|
413 | + * @since 1.0.19 |
|
414 | + * @param string $context View or edit context. |
|
415 | + * @return string |
|
416 | + */ |
|
417 | + public function get_date_modified( $context = 'view' ) { |
|
418 | + return $this->get_prop( 'date_modified', $context ); |
|
419 | + } |
|
420 | 420 | |
421 | - /** |
|
422 | - * Alias for self::get_date_modified(). |
|
423 | - * |
|
424 | - * @since 1.0.19 |
|
425 | - * @param string $context View or edit context. |
|
426 | - * @return string |
|
427 | - */ |
|
428 | - public function get_modified_date( $context = 'view' ) { |
|
429 | - return $this->get_date_modified( $context ); |
|
421 | + /** |
|
422 | + * Alias for self::get_date_modified(). |
|
423 | + * |
|
424 | + * @since 1.0.19 |
|
425 | + * @param string $context View or edit context. |
|
426 | + * @return string |
|
427 | + */ |
|
428 | + public function get_modified_date( $context = 'view' ) { |
|
429 | + return $this->get_date_modified( $context ); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | /** |
433 | - * Get GMT date when the invoice was last modified. |
|
434 | - * |
|
435 | - * @since 1.0.19 |
|
436 | - * @param string $context View or edit context. |
|
437 | - * @return string |
|
438 | - */ |
|
439 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
433 | + * Get GMT date when the invoice was last modified. |
|
434 | + * |
|
435 | + * @since 1.0.19 |
|
436 | + * @param string $context View or edit context. |
|
437 | + * @return string |
|
438 | + */ |
|
439 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
440 | 440 | $date = $this->get_date_modified( $context ); |
441 | 441 | |
442 | 442 | if ( $date ) { |
443 | 443 | $date = get_gmt_from_date( $date ); |
444 | 444 | } |
445 | - return $date; |
|
445 | + return $date; |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | /** |
449 | - * Get the invoice due date. |
|
450 | - * |
|
451 | - * @since 1.0.19 |
|
452 | - * @param string $context View or edit context. |
|
453 | - * @return string |
|
454 | - */ |
|
455 | - public function get_due_date( $context = 'view' ) { |
|
456 | - return $this->get_prop( 'due_date', $context ); |
|
449 | + * Get the invoice due date. |
|
450 | + * |
|
451 | + * @since 1.0.19 |
|
452 | + * @param string $context View or edit context. |
|
453 | + * @return string |
|
454 | + */ |
|
455 | + public function get_due_date( $context = 'view' ) { |
|
456 | + return $this->get_prop( 'due_date', $context ); |
|
457 | 457 | } |
458 | 458 | |
459 | 459 | /** |
460 | - * Alias for self::get_due_date(). |
|
461 | - * |
|
462 | - * @since 1.0.19 |
|
463 | - * @param string $context View or edit context. |
|
464 | - * @return string |
|
465 | - */ |
|
466 | - public function get_date_due( $context = 'view' ) { |
|
467 | - return $this->get_due_date( $context ); |
|
460 | + * Alias for self::get_due_date(). |
|
461 | + * |
|
462 | + * @since 1.0.19 |
|
463 | + * @param string $context View or edit context. |
|
464 | + * @return string |
|
465 | + */ |
|
466 | + public function get_date_due( $context = 'view' ) { |
|
467 | + return $this->get_due_date( $context ); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | /** |
471 | - * Get the invoice GMT due date. |
|
472 | - * |
|
473 | - * @since 1.0.19 |
|
474 | - * @param string $context View or edit context. |
|
475 | - * @return string |
|
476 | - */ |
|
477 | - public function get_due_date_gmt( $context = 'view' ) { |
|
471 | + * Get the invoice GMT due date. |
|
472 | + * |
|
473 | + * @since 1.0.19 |
|
474 | + * @param string $context View or edit context. |
|
475 | + * @return string |
|
476 | + */ |
|
477 | + public function get_due_date_gmt( $context = 'view' ) { |
|
478 | 478 | $date = $this->get_due_date( $context ); |
479 | 479 | |
480 | 480 | if ( $date ) { |
481 | 481 | $date = get_gmt_from_date( $date ); |
482 | 482 | } |
483 | - return $date; |
|
483 | + return $date; |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | /** |
487 | - * Alias for self::get_due_date_gmt(). |
|
488 | - * |
|
489 | - * @since 1.0.19 |
|
490 | - * @param string $context View or edit context. |
|
491 | - * @return string |
|
492 | - */ |
|
493 | - public function get_gmt_date_due( $context = 'view' ) { |
|
494 | - return $this->get_due_date_gmt( $context ); |
|
487 | + * Alias for self::get_due_date_gmt(). |
|
488 | + * |
|
489 | + * @since 1.0.19 |
|
490 | + * @param string $context View or edit context. |
|
491 | + * @return string |
|
492 | + */ |
|
493 | + public function get_gmt_date_due( $context = 'view' ) { |
|
494 | + return $this->get_due_date_gmt( $context ); |
|
495 | 495 | } |
496 | 496 | |
497 | 497 | /** |
498 | - * Get date when the invoice was completed. |
|
499 | - * |
|
500 | - * @since 1.0.19 |
|
501 | - * @param string $context View or edit context. |
|
502 | - * @return string |
|
503 | - */ |
|
504 | - public function get_completed_date( $context = 'view' ) { |
|
505 | - return $this->get_prop( 'completed_date', $context ); |
|
498 | + * Get date when the invoice was completed. |
|
499 | + * |
|
500 | + * @since 1.0.19 |
|
501 | + * @param string $context View or edit context. |
|
502 | + * @return string |
|
503 | + */ |
|
504 | + public function get_completed_date( $context = 'view' ) { |
|
505 | + return $this->get_prop( 'completed_date', $context ); |
|
506 | 506 | } |
507 | 507 | |
508 | 508 | /** |
509 | - * Alias for self::get_completed_date(). |
|
510 | - * |
|
511 | - * @since 1.0.19 |
|
512 | - * @param string $context View or edit context. |
|
513 | - * @return string |
|
514 | - */ |
|
515 | - public function get_date_completed( $context = 'view' ) { |
|
516 | - return $this->get_completed_date( $context ); |
|
509 | + * Alias for self::get_completed_date(). |
|
510 | + * |
|
511 | + * @since 1.0.19 |
|
512 | + * @param string $context View or edit context. |
|
513 | + * @return string |
|
514 | + */ |
|
515 | + public function get_date_completed( $context = 'view' ) { |
|
516 | + return $this->get_completed_date( $context ); |
|
517 | 517 | } |
518 | 518 | |
519 | 519 | /** |
520 | - * Get GMT date when the invoice was was completed. |
|
521 | - * |
|
522 | - * @since 1.0.19 |
|
523 | - * @param string $context View or edit context. |
|
524 | - * @return string |
|
525 | - */ |
|
526 | - public function get_completed_date_gmt( $context = 'view' ) { |
|
520 | + * Get GMT date when the invoice was was completed. |
|
521 | + * |
|
522 | + * @since 1.0.19 |
|
523 | + * @param string $context View or edit context. |
|
524 | + * @return string |
|
525 | + */ |
|
526 | + public function get_completed_date_gmt( $context = 'view' ) { |
|
527 | 527 | $date = $this->get_completed_date( $context ); |
528 | 528 | |
529 | 529 | if ( $date ) { |
530 | 530 | $date = get_gmt_from_date( $date ); |
531 | 531 | } |
532 | - return $date; |
|
532 | + return $date; |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | /** |
536 | - * Alias for self::get_completed_date_gmt(). |
|
537 | - * |
|
538 | - * @since 1.0.19 |
|
539 | - * @param string $context View or edit context. |
|
540 | - * @return string |
|
541 | - */ |
|
542 | - public function get_gmt_completed_date( $context = 'view' ) { |
|
543 | - return $this->get_completed_date_gmt( $context ); |
|
536 | + * Alias for self::get_completed_date_gmt(). |
|
537 | + * |
|
538 | + * @since 1.0.19 |
|
539 | + * @param string $context View or edit context. |
|
540 | + * @return string |
|
541 | + */ |
|
542 | + public function get_gmt_completed_date( $context = 'view' ) { |
|
543 | + return $this->get_completed_date_gmt( $context ); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
547 | - * Get the invoice number. |
|
548 | - * |
|
549 | - * @since 1.0.19 |
|
550 | - * @param string $context View or edit context. |
|
551 | - * @return string |
|
552 | - */ |
|
553 | - public function get_number( $context = 'view' ) { |
|
554 | - $number = $this->get_prop( 'number', $context ); |
|
547 | + * Get the invoice number. |
|
548 | + * |
|
549 | + * @since 1.0.19 |
|
550 | + * @param string $context View or edit context. |
|
551 | + * @return string |
|
552 | + */ |
|
553 | + public function get_number( $context = 'view' ) { |
|
554 | + $number = $this->get_prop( 'number', $context ); |
|
555 | 555 | |
556 | - if ( empty( $number ) ) { |
|
557 | - $number = $this->generate_number(); |
|
558 | - $this->set_number( $this->generate_number() ); |
|
559 | - } |
|
556 | + if ( empty( $number ) ) { |
|
557 | + $number = $this->generate_number(); |
|
558 | + $this->set_number( $this->generate_number() ); |
|
559 | + } |
|
560 | 560 | |
561 | - return $number; |
|
561 | + return $number; |
|
562 | 562 | } |
563 | 563 | |
564 | - /** |
|
565 | - * Set the invoice number. |
|
566 | - * |
|
567 | - * @since 1.0.19 |
|
568 | - */ |
|
569 | - public function maybe_set_number() { |
|
564 | + /** |
|
565 | + * Set the invoice number. |
|
566 | + * |
|
567 | + * @since 1.0.19 |
|
568 | + */ |
|
569 | + public function maybe_set_number() { |
|
570 | 570 | $number = $this->get_number(); |
571 | 571 | |
572 | 572 | if ( empty( $number ) || $this->get_id() == $number ) { |
573 | - $this->set_number( $this->generate_number() ); |
|
573 | + $this->set_number( $this->generate_number() ); |
|
574 | 574 | } |
575 | 575 | |
576 | - } |
|
576 | + } |
|
577 | 577 | |
578 | 578 | /** |
579 | - * Get the invoice key. |
|
580 | - * |
|
581 | - * @since 1.0.19 |
|
582 | - * @param string $context View or edit context. |
|
583 | - * @return string |
|
584 | - */ |
|
585 | - public function get_key( $context = 'view' ) { |
|
579 | + * Get the invoice key. |
|
580 | + * |
|
581 | + * @since 1.0.19 |
|
582 | + * @param string $context View or edit context. |
|
583 | + * @return string |
|
584 | + */ |
|
585 | + public function get_key( $context = 'view' ) { |
|
586 | 586 | return $this->get_prop( 'key', $context ); |
587 | - } |
|
588 | - |
|
589 | - /** |
|
590 | - * Set the invoice key. |
|
591 | - * |
|
592 | - * @since 1.0.19 |
|
593 | - */ |
|
594 | - public function maybe_set_key() { |
|
587 | + } |
|
588 | + |
|
589 | + /** |
|
590 | + * Set the invoice key. |
|
591 | + * |
|
592 | + * @since 1.0.19 |
|
593 | + */ |
|
594 | + public function maybe_set_key() { |
|
595 | 595 | $key = $this->get_key(); |
596 | 596 | |
597 | 597 | if ( empty( $key ) ) { |
@@ -602,140 +602,140 @@ discard block |
||
602 | 602 | } |
603 | 603 | |
604 | 604 | /** |
605 | - * Get the invoice type. |
|
606 | - * |
|
607 | - * @since 1.0.19 |
|
608 | - * @param string $context View or edit context. |
|
609 | - * @return string |
|
610 | - */ |
|
611 | - public function get_type( $context = 'view' ) { |
|
605 | + * Get the invoice type. |
|
606 | + * |
|
607 | + * @since 1.0.19 |
|
608 | + * @param string $context View or edit context. |
|
609 | + * @return string |
|
610 | + */ |
|
611 | + public function get_type( $context = 'view' ) { |
|
612 | 612 | return $this->get_prop( 'type', $context ); |
613 | - } |
|
614 | - |
|
615 | - /** |
|
616 | - * Returns the post type name. |
|
617 | - * |
|
618 | - * @since 1.0.19 |
|
619 | - * @return string |
|
620 | - */ |
|
621 | - public function get_invoice_quote_type() { |
|
613 | + } |
|
614 | + |
|
615 | + /** |
|
616 | + * Returns the post type name. |
|
617 | + * |
|
618 | + * @since 1.0.19 |
|
619 | + * @return string |
|
620 | + */ |
|
621 | + public function get_invoice_quote_type() { |
|
622 | 622 | return getpaid_get_post_type_label( $this->get_post_type(), false ); |
623 | 623 | } |
624 | 624 | |
625 | 625 | /** |
626 | - * Get the invoice post type label. |
|
627 | - * |
|
628 | - * @since 1.0.19 |
|
629 | - * @param string $context View or edit context. |
|
630 | - * @return string |
|
631 | - */ |
|
632 | - public function get_label( $context = 'view' ) { |
|
626 | + * Get the invoice post type label. |
|
627 | + * |
|
628 | + * @since 1.0.19 |
|
629 | + * @param string $context View or edit context. |
|
630 | + * @return string |
|
631 | + */ |
|
632 | + public function get_label( $context = 'view' ) { |
|
633 | 633 | return getpaid_get_post_type_label( $this->get_post_type( $context ), false ); |
634 | - } |
|
635 | - |
|
636 | - /** |
|
637 | - * Get the invoice post type. |
|
638 | - * |
|
639 | - * @since 1.0.19 |
|
640 | - * @param string $context View or edit context. |
|
641 | - * @return string |
|
642 | - */ |
|
643 | - public function get_post_type( $context = 'view' ) { |
|
634 | + } |
|
635 | + |
|
636 | + /** |
|
637 | + * Get the invoice post type. |
|
638 | + * |
|
639 | + * @since 1.0.19 |
|
640 | + * @param string $context View or edit context. |
|
641 | + * @return string |
|
642 | + */ |
|
643 | + public function get_post_type( $context = 'view' ) { |
|
644 | 644 | return $this->get_prop( 'post_type', $context ); |
645 | 645 | } |
646 | 646 | |
647 | 647 | /** |
648 | - * Get the invoice mode. |
|
649 | - * |
|
650 | - * @since 1.0.19 |
|
651 | - * @param string $context View or edit context. |
|
652 | - * @return string |
|
653 | - */ |
|
654 | - public function get_mode( $context = 'view' ) { |
|
648 | + * Get the invoice mode. |
|
649 | + * |
|
650 | + * @since 1.0.19 |
|
651 | + * @param string $context View or edit context. |
|
652 | + * @return string |
|
653 | + */ |
|
654 | + public function get_mode( $context = 'view' ) { |
|
655 | 655 | return $this->get_prop( 'mode', $context ); |
656 | 656 | } |
657 | 657 | |
658 | 658 | /** |
659 | - * Get the invoice path. |
|
660 | - * |
|
661 | - * @since 1.0.19 |
|
662 | - * @param string $context View or edit context. |
|
663 | - * @return string |
|
664 | - */ |
|
665 | - public function get_path( $context = 'view' ) { |
|
659 | + * Get the invoice path. |
|
660 | + * |
|
661 | + * @since 1.0.19 |
|
662 | + * @param string $context View or edit context. |
|
663 | + * @return string |
|
664 | + */ |
|
665 | + public function get_path( $context = 'view' ) { |
|
666 | 666 | $path = $this->get_prop( 'path', $context ); |
667 | - $prefix = $this->get_type(); |
|
667 | + $prefix = $this->get_type(); |
|
668 | 668 | |
669 | - if ( 0 !== strpos( $path, $prefix ) ) { |
|
670 | - $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
671 | - $this->set_path( $path ); |
|
672 | - } |
|
669 | + if ( 0 !== strpos( $path, $prefix ) ) { |
|
670 | + $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
671 | + $this->set_path( $path ); |
|
672 | + } |
|
673 | 673 | |
674 | - return $path; |
|
674 | + return $path; |
|
675 | 675 | } |
676 | 676 | |
677 | 677 | /** |
678 | - * Get the invoice name/title. |
|
679 | - * |
|
680 | - * @since 1.0.19 |
|
681 | - * @param string $context View or edit context. |
|
682 | - * @return string |
|
683 | - */ |
|
684 | - public function get_name( $context = 'view' ) { |
|
678 | + * Get the invoice name/title. |
|
679 | + * |
|
680 | + * @since 1.0.19 |
|
681 | + * @param string $context View or edit context. |
|
682 | + * @return string |
|
683 | + */ |
|
684 | + public function get_name( $context = 'view' ) { |
|
685 | 685 | return $this->get_prop( 'title', $context ); |
686 | 686 | } |
687 | 687 | |
688 | 688 | /** |
689 | - * Alias of self::get_name(). |
|
690 | - * |
|
691 | - * @since 1.0.19 |
|
692 | - * @param string $context View or edit context. |
|
693 | - * @return string |
|
694 | - */ |
|
695 | - public function get_title( $context = 'view' ) { |
|
696 | - return $this->get_name( $context ); |
|
689 | + * Alias of self::get_name(). |
|
690 | + * |
|
691 | + * @since 1.0.19 |
|
692 | + * @param string $context View or edit context. |
|
693 | + * @return string |
|
694 | + */ |
|
695 | + public function get_title( $context = 'view' ) { |
|
696 | + return $this->get_name( $context ); |
|
697 | 697 | } |
698 | 698 | |
699 | 699 | /** |
700 | - * Get the invoice description. |
|
701 | - * |
|
702 | - * @since 1.0.19 |
|
703 | - * @param string $context View or edit context. |
|
704 | - * @return string |
|
705 | - */ |
|
706 | - public function get_description( $context = 'view' ) { |
|
707 | - return $this->get_prop( 'description', $context ); |
|
700 | + * Get the invoice description. |
|
701 | + * |
|
702 | + * @since 1.0.19 |
|
703 | + * @param string $context View or edit context. |
|
704 | + * @return string |
|
705 | + */ |
|
706 | + public function get_description( $context = 'view' ) { |
|
707 | + return $this->get_prop( 'description', $context ); |
|
708 | 708 | } |
709 | 709 | |
710 | 710 | /** |
711 | - * Alias of self::get_description(). |
|
712 | - * |
|
713 | - * @since 1.0.19 |
|
714 | - * @param string $context View or edit context. |
|
715 | - * @return string |
|
716 | - */ |
|
717 | - public function get_excerpt( $context = 'view' ) { |
|
718 | - return $this->get_description( $context ); |
|
711 | + * Alias of self::get_description(). |
|
712 | + * |
|
713 | + * @since 1.0.19 |
|
714 | + * @param string $context View or edit context. |
|
715 | + * @return string |
|
716 | + */ |
|
717 | + public function get_excerpt( $context = 'view' ) { |
|
718 | + return $this->get_description( $context ); |
|
719 | 719 | } |
720 | 720 | |
721 | 721 | /** |
722 | - * Alias of self::get_description(). |
|
723 | - * |
|
724 | - * @since 1.0.19 |
|
725 | - * @param string $context View or edit context. |
|
726 | - * @return string |
|
727 | - */ |
|
728 | - public function get_summary( $context = 'view' ) { |
|
729 | - return $this->get_description( $context ); |
|
722 | + * Alias of self::get_description(). |
|
723 | + * |
|
724 | + * @since 1.0.19 |
|
725 | + * @param string $context View or edit context. |
|
726 | + * @return string |
|
727 | + */ |
|
728 | + public function get_summary( $context = 'view' ) { |
|
729 | + return $this->get_description( $context ); |
|
730 | 730 | } |
731 | 731 | |
732 | 732 | /** |
733 | - * Returns the user info. |
|
734 | - * |
|
735 | - * @since 1.0.19 |
|
733 | + * Returns the user info. |
|
734 | + * |
|
735 | + * @since 1.0.19 |
|
736 | 736 | * @param string $context View or edit context. |
737 | - * @return array |
|
738 | - */ |
|
737 | + * @return array |
|
738 | + */ |
|
739 | 739 | public function get_user_info( $context = 'view' ) { |
740 | 740 | |
741 | 741 | $user_info = array( |
@@ -750,683 +750,683 @@ discard block |
||
750 | 750 | 'state' => $this->get_state( $context ), |
751 | 751 | 'zip' => $this->get_zip( $context ), |
752 | 752 | 'company' => $this->get_company( $context ), |
753 | - 'company_id' => $this->get_company_id( $context ), |
|
753 | + 'company_id' => $this->get_company_id( $context ), |
|
754 | 754 | 'vat_number' => $this->get_vat_number( $context ), |
755 | 755 | 'discount' => $this->get_discount_code( $context ), |
756 | - ); |
|
756 | + ); |
|
757 | 757 | |
758 | - return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
758 | + return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
759 | 759 | |
760 | 760 | } |
761 | 761 | |
762 | 762 | /** |
763 | - * Get the customer id. |
|
764 | - * |
|
765 | - * @since 1.0.19 |
|
766 | - * @param string $context View or edit context. |
|
767 | - * @return int |
|
768 | - */ |
|
769 | - public function get_author( $context = 'view' ) { |
|
770 | - return (int) $this->get_prop( 'author', $context ); |
|
763 | + * Get the customer id. |
|
764 | + * |
|
765 | + * @since 1.0.19 |
|
766 | + * @param string $context View or edit context. |
|
767 | + * @return int |
|
768 | + */ |
|
769 | + public function get_author( $context = 'view' ) { |
|
770 | + return (int) $this->get_prop( 'author', $context ); |
|
771 | 771 | } |
772 | 772 | |
773 | 773 | /** |
774 | - * Alias of self::get_author(). |
|
775 | - * |
|
776 | - * @since 1.0.19 |
|
777 | - * @param string $context View or edit context. |
|
778 | - * @return int |
|
779 | - */ |
|
780 | - public function get_user_id( $context = 'view' ) { |
|
781 | - return $this->get_author( $context ); |
|
774 | + * Alias of self::get_author(). |
|
775 | + * |
|
776 | + * @since 1.0.19 |
|
777 | + * @param string $context View or edit context. |
|
778 | + * @return int |
|
779 | + */ |
|
780 | + public function get_user_id( $context = 'view' ) { |
|
781 | + return $this->get_author( $context ); |
|
782 | 782 | } |
783 | 783 | |
784 | - /** |
|
785 | - * Alias of self::get_author(). |
|
786 | - * |
|
787 | - * @since 1.0.19 |
|
788 | - * @param string $context View or edit context. |
|
789 | - * @return int |
|
790 | - */ |
|
791 | - public function get_customer_id( $context = 'view' ) { |
|
792 | - return $this->get_author( $context ); |
|
784 | + /** |
|
785 | + * Alias of self::get_author(). |
|
786 | + * |
|
787 | + * @since 1.0.19 |
|
788 | + * @param string $context View or edit context. |
|
789 | + * @return int |
|
790 | + */ |
|
791 | + public function get_customer_id( $context = 'view' ) { |
|
792 | + return $this->get_author( $context ); |
|
793 | 793 | } |
794 | 794 | |
795 | 795 | /** |
796 | - * Get the customer's ip. |
|
797 | - * |
|
798 | - * @since 1.0.19 |
|
799 | - * @param string $context View or edit context. |
|
800 | - * @return string |
|
801 | - */ |
|
802 | - public function get_ip( $context = 'view' ) { |
|
803 | - return $this->get_prop( 'user_ip', $context ); |
|
796 | + * Get the customer's ip. |
|
797 | + * |
|
798 | + * @since 1.0.19 |
|
799 | + * @param string $context View or edit context. |
|
800 | + * @return string |
|
801 | + */ |
|
802 | + public function get_ip( $context = 'view' ) { |
|
803 | + return $this->get_prop( 'user_ip', $context ); |
|
804 | 804 | } |
805 | 805 | |
806 | 806 | /** |
807 | - * Alias of self::get_ip(). |
|
808 | - * |
|
809 | - * @since 1.0.19 |
|
810 | - * @param string $context View or edit context. |
|
811 | - * @return string |
|
812 | - */ |
|
813 | - public function get_user_ip( $context = 'view' ) { |
|
814 | - return $this->get_ip( $context ); |
|
807 | + * Alias of self::get_ip(). |
|
808 | + * |
|
809 | + * @since 1.0.19 |
|
810 | + * @param string $context View or edit context. |
|
811 | + * @return string |
|
812 | + */ |
|
813 | + public function get_user_ip( $context = 'view' ) { |
|
814 | + return $this->get_ip( $context ); |
|
815 | 815 | } |
816 | 816 | |
817 | - /** |
|
818 | - * Alias of self::get_ip(). |
|
819 | - * |
|
820 | - * @since 1.0.19 |
|
821 | - * @param string $context View or edit context. |
|
822 | - * @return string |
|
823 | - */ |
|
824 | - public function get_customer_ip( $context = 'view' ) { |
|
825 | - return $this->get_ip( $context ); |
|
817 | + /** |
|
818 | + * Alias of self::get_ip(). |
|
819 | + * |
|
820 | + * @since 1.0.19 |
|
821 | + * @param string $context View or edit context. |
|
822 | + * @return string |
|
823 | + */ |
|
824 | + public function get_customer_ip( $context = 'view' ) { |
|
825 | + return $this->get_ip( $context ); |
|
826 | 826 | } |
827 | 827 | |
828 | 828 | /** |
829 | - * Get the customer's first name. |
|
830 | - * |
|
831 | - * @since 1.0.19 |
|
832 | - * @param string $context View or edit context. |
|
833 | - * @return string |
|
834 | - */ |
|
835 | - public function get_first_name( $context = 'view' ) { |
|
836 | - return $this->get_prop( 'first_name', $context ); |
|
829 | + * Get the customer's first name. |
|
830 | + * |
|
831 | + * @since 1.0.19 |
|
832 | + * @param string $context View or edit context. |
|
833 | + * @return string |
|
834 | + */ |
|
835 | + public function get_first_name( $context = 'view' ) { |
|
836 | + return $this->get_prop( 'first_name', $context ); |
|
837 | 837 | } |
838 | 838 | |
839 | 839 | /** |
840 | - * Alias of self::get_first_name(). |
|
841 | - * |
|
842 | - * @since 1.0.19 |
|
843 | - * @param string $context View or edit context. |
|
844 | - * @return string |
|
845 | - */ |
|
846 | - public function get_user_first_name( $context = 'view' ) { |
|
847 | - return $this->get_first_name( $context ); |
|
840 | + * Alias of self::get_first_name(). |
|
841 | + * |
|
842 | + * @since 1.0.19 |
|
843 | + * @param string $context View or edit context. |
|
844 | + * @return string |
|
845 | + */ |
|
846 | + public function get_user_first_name( $context = 'view' ) { |
|
847 | + return $this->get_first_name( $context ); |
|
848 | 848 | } |
849 | 849 | |
850 | - /** |
|
851 | - * Alias of self::get_first_name(). |
|
852 | - * |
|
853 | - * @since 1.0.19 |
|
854 | - * @param string $context View or edit context. |
|
855 | - * @return string |
|
856 | - */ |
|
857 | - public function get_customer_first_name( $context = 'view' ) { |
|
858 | - return $this->get_first_name( $context ); |
|
850 | + /** |
|
851 | + * Alias of self::get_first_name(). |
|
852 | + * |
|
853 | + * @since 1.0.19 |
|
854 | + * @param string $context View or edit context. |
|
855 | + * @return string |
|
856 | + */ |
|
857 | + public function get_customer_first_name( $context = 'view' ) { |
|
858 | + return $this->get_first_name( $context ); |
|
859 | 859 | } |
860 | 860 | |
861 | 861 | /** |
862 | - * Get the customer's last name. |
|
863 | - * |
|
864 | - * @since 1.0.19 |
|
865 | - * @param string $context View or edit context. |
|
866 | - * @return string |
|
867 | - */ |
|
868 | - public function get_last_name( $context = 'view' ) { |
|
869 | - return $this->get_prop( 'last_name', $context ); |
|
862 | + * Get the customer's last name. |
|
863 | + * |
|
864 | + * @since 1.0.19 |
|
865 | + * @param string $context View or edit context. |
|
866 | + * @return string |
|
867 | + */ |
|
868 | + public function get_last_name( $context = 'view' ) { |
|
869 | + return $this->get_prop( 'last_name', $context ); |
|
870 | 870 | } |
871 | 871 | |
872 | 872 | /** |
873 | - * Alias of self::get_last_name(). |
|
874 | - * |
|
875 | - * @since 1.0.19 |
|
876 | - * @param string $context View or edit context. |
|
877 | - * @return string |
|
878 | - */ |
|
879 | - public function get_user_last_name( $context = 'view' ) { |
|
880 | - return $this->get_last_name( $context ); |
|
873 | + * Alias of self::get_last_name(). |
|
874 | + * |
|
875 | + * @since 1.0.19 |
|
876 | + * @param string $context View or edit context. |
|
877 | + * @return string |
|
878 | + */ |
|
879 | + public function get_user_last_name( $context = 'view' ) { |
|
880 | + return $this->get_last_name( $context ); |
|
881 | 881 | } |
882 | 882 | |
883 | 883 | /** |
884 | - * Alias of self::get_last_name(). |
|
885 | - * |
|
886 | - * @since 1.0.19 |
|
887 | - * @param string $context View or edit context. |
|
888 | - * @return string |
|
889 | - */ |
|
890 | - public function get_customer_last_name( $context = 'view' ) { |
|
891 | - return $this->get_last_name( $context ); |
|
884 | + * Alias of self::get_last_name(). |
|
885 | + * |
|
886 | + * @since 1.0.19 |
|
887 | + * @param string $context View or edit context. |
|
888 | + * @return string |
|
889 | + */ |
|
890 | + public function get_customer_last_name( $context = 'view' ) { |
|
891 | + return $this->get_last_name( $context ); |
|
892 | 892 | } |
893 | 893 | |
894 | 894 | /** |
895 | - * Get the customer's full name. |
|
896 | - * |
|
897 | - * @since 1.0.19 |
|
898 | - * @param string $context View or edit context. |
|
899 | - * @return string |
|
900 | - */ |
|
901 | - public function get_full_name( $context = 'view' ) { |
|
902 | - $name = trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
895 | + * Get the customer's full name. |
|
896 | + * |
|
897 | + * @since 1.0.19 |
|
898 | + * @param string $context View or edit context. |
|
899 | + * @return string |
|
900 | + */ |
|
901 | + public function get_full_name( $context = 'view' ) { |
|
902 | + $name = trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
903 | 903 | |
904 | - if ( ! $name ) { |
|
905 | - $user = get_userdata( $this->get_author( $context ) ); |
|
904 | + if ( ! $name ) { |
|
905 | + $user = get_userdata( $this->get_author( $context ) ); |
|
906 | 906 | |
907 | - if ( $user ) { |
|
908 | - $name = $user->display_name; |
|
909 | - } |
|
910 | - } |
|
907 | + if ( $user ) { |
|
908 | + $name = $user->display_name; |
|
909 | + } |
|
910 | + } |
|
911 | 911 | |
912 | - if ( ! $name ) { |
|
913 | - $name = $this->get_email( $context ); |
|
914 | - } |
|
912 | + if ( ! $name ) { |
|
913 | + $name = $this->get_email( $context ); |
|
914 | + } |
|
915 | 915 | |
916 | - return apply_filters( 'wpinv_invoice_user_full_name', $name, $this ); |
|
916 | + return apply_filters( 'wpinv_invoice_user_full_name', $name, $this ); |
|
917 | 917 | } |
918 | 918 | |
919 | 919 | /** |
920 | - * Alias of self::get_full_name(). |
|
921 | - * |
|
922 | - * @since 1.0.19 |
|
923 | - * @param string $context View or edit context. |
|
924 | - * @return string |
|
925 | - */ |
|
926 | - public function get_user_full_name( $context = 'view' ) { |
|
927 | - return $this->get_full_name( $context ); |
|
920 | + * Alias of self::get_full_name(). |
|
921 | + * |
|
922 | + * @since 1.0.19 |
|
923 | + * @param string $context View or edit context. |
|
924 | + * @return string |
|
925 | + */ |
|
926 | + public function get_user_full_name( $context = 'view' ) { |
|
927 | + return $this->get_full_name( $context ); |
|
928 | 928 | } |
929 | 929 | |
930 | 930 | /** |
931 | - * Alias of self::get_full_name(). |
|
932 | - * |
|
933 | - * @since 1.0.19 |
|
934 | - * @param string $context View or edit context. |
|
935 | - * @return string |
|
936 | - */ |
|
937 | - public function get_customer_full_name( $context = 'view' ) { |
|
938 | - return $this->get_full_name( $context ); |
|
931 | + * Alias of self::get_full_name(). |
|
932 | + * |
|
933 | + * @since 1.0.19 |
|
934 | + * @param string $context View or edit context. |
|
935 | + * @return string |
|
936 | + */ |
|
937 | + public function get_customer_full_name( $context = 'view' ) { |
|
938 | + return $this->get_full_name( $context ); |
|
939 | 939 | } |
940 | 940 | |
941 | 941 | /** |
942 | - * Get the customer's phone number. |
|
943 | - * |
|
944 | - * @since 1.0.19 |
|
945 | - * @param string $context View or edit context. |
|
946 | - * @return string |
|
947 | - */ |
|
948 | - public function get_phone( $context = 'view' ) { |
|
949 | - return $this->get_prop( 'phone', $context ); |
|
942 | + * Get the customer's phone number. |
|
943 | + * |
|
944 | + * @since 1.0.19 |
|
945 | + * @param string $context View or edit context. |
|
946 | + * @return string |
|
947 | + */ |
|
948 | + public function get_phone( $context = 'view' ) { |
|
949 | + return $this->get_prop( 'phone', $context ); |
|
950 | 950 | } |
951 | 951 | |
952 | 952 | /** |
953 | - * Alias of self::get_phone(). |
|
954 | - * |
|
955 | - * @since 1.0.19 |
|
956 | - * @param string $context View or edit context. |
|
957 | - * @return string |
|
958 | - */ |
|
959 | - public function get_phone_number( $context = 'view' ) { |
|
960 | - return $this->get_phone( $context ); |
|
953 | + * Alias of self::get_phone(). |
|
954 | + * |
|
955 | + * @since 1.0.19 |
|
956 | + * @param string $context View or edit context. |
|
957 | + * @return string |
|
958 | + */ |
|
959 | + public function get_phone_number( $context = 'view' ) { |
|
960 | + return $this->get_phone( $context ); |
|
961 | 961 | } |
962 | 962 | |
963 | 963 | /** |
964 | - * Alias of self::get_phone(). |
|
965 | - * |
|
966 | - * @since 1.0.19 |
|
967 | - * @param string $context View or edit context. |
|
968 | - * @return string |
|
969 | - */ |
|
970 | - public function get_user_phone( $context = 'view' ) { |
|
971 | - return $this->get_phone( $context ); |
|
964 | + * Alias of self::get_phone(). |
|
965 | + * |
|
966 | + * @since 1.0.19 |
|
967 | + * @param string $context View or edit context. |
|
968 | + * @return string |
|
969 | + */ |
|
970 | + public function get_user_phone( $context = 'view' ) { |
|
971 | + return $this->get_phone( $context ); |
|
972 | 972 | } |
973 | 973 | |
974 | 974 | /** |
975 | - * Alias of self::get_phone(). |
|
976 | - * |
|
977 | - * @since 1.0.19 |
|
978 | - * @param string $context View or edit context. |
|
979 | - * @return string |
|
980 | - */ |
|
981 | - public function get_customer_phone( $context = 'view' ) { |
|
982 | - return $this->get_phone( $context ); |
|
975 | + * Alias of self::get_phone(). |
|
976 | + * |
|
977 | + * @since 1.0.19 |
|
978 | + * @param string $context View or edit context. |
|
979 | + * @return string |
|
980 | + */ |
|
981 | + public function get_customer_phone( $context = 'view' ) { |
|
982 | + return $this->get_phone( $context ); |
|
983 | 983 | } |
984 | 984 | |
985 | 985 | /** |
986 | - * Get the customer's email address. |
|
987 | - * |
|
988 | - * @since 1.0.19 |
|
989 | - * @param string $context View or edit context. |
|
990 | - * @return string |
|
991 | - */ |
|
992 | - public function get_email( $context = 'view' ) { |
|
993 | - return $this->get_prop( 'email', $context ); |
|
986 | + * Get the customer's email address. |
|
987 | + * |
|
988 | + * @since 1.0.19 |
|
989 | + * @param string $context View or edit context. |
|
990 | + * @return string |
|
991 | + */ |
|
992 | + public function get_email( $context = 'view' ) { |
|
993 | + return $this->get_prop( 'email', $context ); |
|
994 | 994 | } |
995 | 995 | |
996 | 996 | /** |
997 | - * Alias of self::get_email(). |
|
998 | - * |
|
999 | - * @since 1.0.19 |
|
1000 | - * @param string $context View or edit context. |
|
1001 | - * @return string |
|
1002 | - */ |
|
1003 | - public function get_email_address( $context = 'view' ) { |
|
1004 | - return $this->get_email( $context ); |
|
997 | + * Alias of self::get_email(). |
|
998 | + * |
|
999 | + * @since 1.0.19 |
|
1000 | + * @param string $context View or edit context. |
|
1001 | + * @return string |
|
1002 | + */ |
|
1003 | + public function get_email_address( $context = 'view' ) { |
|
1004 | + return $this->get_email( $context ); |
|
1005 | 1005 | } |
1006 | 1006 | |
1007 | 1007 | /** |
1008 | - * Alias of self::get_email(). |
|
1009 | - * |
|
1010 | - * @since 1.0.19 |
|
1011 | - * @param string $context View or edit context. |
|
1012 | - * @return string |
|
1013 | - */ |
|
1014 | - public function get_user_email( $context = 'view' ) { |
|
1015 | - return $this->get_email( $context ); |
|
1008 | + * Alias of self::get_email(). |
|
1009 | + * |
|
1010 | + * @since 1.0.19 |
|
1011 | + * @param string $context View or edit context. |
|
1012 | + * @return string |
|
1013 | + */ |
|
1014 | + public function get_user_email( $context = 'view' ) { |
|
1015 | + return $this->get_email( $context ); |
|
1016 | 1016 | } |
1017 | 1017 | |
1018 | 1018 | /** |
1019 | - * Alias of self::get_email(). |
|
1020 | - * |
|
1021 | - * @since 1.0.19 |
|
1022 | - * @param string $context View or edit context. |
|
1023 | - * @return string |
|
1024 | - */ |
|
1025 | - public function get_customer_email( $context = 'view' ) { |
|
1026 | - return $this->get_email( $context ); |
|
1019 | + * Alias of self::get_email(). |
|
1020 | + * |
|
1021 | + * @since 1.0.19 |
|
1022 | + * @param string $context View or edit context. |
|
1023 | + * @return string |
|
1024 | + */ |
|
1025 | + public function get_customer_email( $context = 'view' ) { |
|
1026 | + return $this->get_email( $context ); |
|
1027 | 1027 | } |
1028 | 1028 | |
1029 | 1029 | /** |
1030 | - * Get the customer's country. |
|
1031 | - * |
|
1032 | - * @since 1.0.19 |
|
1033 | - * @param string $context View or edit context. |
|
1034 | - * @return string |
|
1035 | - */ |
|
1036 | - public function get_country( $context = 'view' ) { |
|
1037 | - $country = $this->get_prop( 'country', $context ); |
|
1038 | - return empty( $country ) ? wpinv_get_default_country() : $country; |
|
1030 | + * Get the customer's country. |
|
1031 | + * |
|
1032 | + * @since 1.0.19 |
|
1033 | + * @param string $context View or edit context. |
|
1034 | + * @return string |
|
1035 | + */ |
|
1036 | + public function get_country( $context = 'view' ) { |
|
1037 | + $country = $this->get_prop( 'country', $context ); |
|
1038 | + return empty( $country ) ? wpinv_get_default_country() : $country; |
|
1039 | 1039 | } |
1040 | 1040 | |
1041 | 1041 | /** |
1042 | - * Alias of self::get_country(). |
|
1043 | - * |
|
1044 | - * @since 1.0.19 |
|
1045 | - * @param string $context View or edit context. |
|
1046 | - * @return string |
|
1047 | - */ |
|
1048 | - public function get_user_country( $context = 'view' ) { |
|
1049 | - return $this->get_country( $context ); |
|
1042 | + * Alias of self::get_country(). |
|
1043 | + * |
|
1044 | + * @since 1.0.19 |
|
1045 | + * @param string $context View or edit context. |
|
1046 | + * @return string |
|
1047 | + */ |
|
1048 | + public function get_user_country( $context = 'view' ) { |
|
1049 | + return $this->get_country( $context ); |
|
1050 | 1050 | } |
1051 | 1051 | |
1052 | 1052 | /** |
1053 | - * Alias of self::get_country(). |
|
1054 | - * |
|
1055 | - * @since 1.0.19 |
|
1056 | - * @param string $context View or edit context. |
|
1057 | - * @return string |
|
1058 | - */ |
|
1059 | - public function get_customer_country( $context = 'view' ) { |
|
1060 | - return $this->get_country( $context ); |
|
1053 | + * Alias of self::get_country(). |
|
1054 | + * |
|
1055 | + * @since 1.0.19 |
|
1056 | + * @param string $context View or edit context. |
|
1057 | + * @return string |
|
1058 | + */ |
|
1059 | + public function get_customer_country( $context = 'view' ) { |
|
1060 | + return $this->get_country( $context ); |
|
1061 | 1061 | } |
1062 | 1062 | |
1063 | 1063 | /** |
1064 | - * Get the customer's state. |
|
1065 | - * |
|
1066 | - * @since 1.0.19 |
|
1067 | - * @param string $context View or edit context. |
|
1068 | - * @return string |
|
1069 | - */ |
|
1070 | - public function get_state( $context = 'view' ) { |
|
1071 | - $state = $this->get_prop( 'state', $context ); |
|
1072 | - return empty( $state ) ? wpinv_get_default_state() : $state; |
|
1064 | + * Get the customer's state. |
|
1065 | + * |
|
1066 | + * @since 1.0.19 |
|
1067 | + * @param string $context View or edit context. |
|
1068 | + * @return string |
|
1069 | + */ |
|
1070 | + public function get_state( $context = 'view' ) { |
|
1071 | + $state = $this->get_prop( 'state', $context ); |
|
1072 | + return empty( $state ) ? wpinv_get_default_state() : $state; |
|
1073 | 1073 | } |
1074 | 1074 | |
1075 | 1075 | /** |
1076 | - * Alias of self::get_state(). |
|
1077 | - * |
|
1078 | - * @since 1.0.19 |
|
1079 | - * @param string $context View or edit context. |
|
1080 | - * @return string |
|
1081 | - */ |
|
1082 | - public function get_user_state( $context = 'view' ) { |
|
1083 | - return $this->get_state( $context ); |
|
1076 | + * Alias of self::get_state(). |
|
1077 | + * |
|
1078 | + * @since 1.0.19 |
|
1079 | + * @param string $context View or edit context. |
|
1080 | + * @return string |
|
1081 | + */ |
|
1082 | + public function get_user_state( $context = 'view' ) { |
|
1083 | + return $this->get_state( $context ); |
|
1084 | 1084 | } |
1085 | 1085 | |
1086 | 1086 | /** |
1087 | - * Alias of self::get_state(). |
|
1088 | - * |
|
1089 | - * @since 1.0.19 |
|
1090 | - * @param string $context View or edit context. |
|
1091 | - * @return string |
|
1092 | - */ |
|
1093 | - public function get_customer_state( $context = 'view' ) { |
|
1094 | - return $this->get_state( $context ); |
|
1087 | + * Alias of self::get_state(). |
|
1088 | + * |
|
1089 | + * @since 1.0.19 |
|
1090 | + * @param string $context View or edit context. |
|
1091 | + * @return string |
|
1092 | + */ |
|
1093 | + public function get_customer_state( $context = 'view' ) { |
|
1094 | + return $this->get_state( $context ); |
|
1095 | 1095 | } |
1096 | 1096 | |
1097 | 1097 | /** |
1098 | - * Get the customer's city. |
|
1099 | - * |
|
1100 | - * @since 1.0.19 |
|
1101 | - * @param string $context View or edit context. |
|
1102 | - * @return string |
|
1103 | - */ |
|
1104 | - public function get_city( $context = 'view' ) { |
|
1105 | - return $this->get_prop( 'city', $context ); |
|
1098 | + * Get the customer's city. |
|
1099 | + * |
|
1100 | + * @since 1.0.19 |
|
1101 | + * @param string $context View or edit context. |
|
1102 | + * @return string |
|
1103 | + */ |
|
1104 | + public function get_city( $context = 'view' ) { |
|
1105 | + return $this->get_prop( 'city', $context ); |
|
1106 | 1106 | } |
1107 | 1107 | |
1108 | 1108 | /** |
1109 | - * Alias of self::get_city(). |
|
1110 | - * |
|
1111 | - * @since 1.0.19 |
|
1112 | - * @param string $context View or edit context. |
|
1113 | - * @return string |
|
1114 | - */ |
|
1115 | - public function get_user_city( $context = 'view' ) { |
|
1116 | - return $this->get_city( $context ); |
|
1109 | + * Alias of self::get_city(). |
|
1110 | + * |
|
1111 | + * @since 1.0.19 |
|
1112 | + * @param string $context View or edit context. |
|
1113 | + * @return string |
|
1114 | + */ |
|
1115 | + public function get_user_city( $context = 'view' ) { |
|
1116 | + return $this->get_city( $context ); |
|
1117 | 1117 | } |
1118 | 1118 | |
1119 | 1119 | /** |
1120 | - * Alias of self::get_city(). |
|
1121 | - * |
|
1122 | - * @since 1.0.19 |
|
1123 | - * @param string $context View or edit context. |
|
1124 | - * @return string |
|
1125 | - */ |
|
1126 | - public function get_customer_city( $context = 'view' ) { |
|
1127 | - return $this->get_city( $context ); |
|
1120 | + * Alias of self::get_city(). |
|
1121 | + * |
|
1122 | + * @since 1.0.19 |
|
1123 | + * @param string $context View or edit context. |
|
1124 | + * @return string |
|
1125 | + */ |
|
1126 | + public function get_customer_city( $context = 'view' ) { |
|
1127 | + return $this->get_city( $context ); |
|
1128 | 1128 | } |
1129 | 1129 | |
1130 | 1130 | /** |
1131 | - * Get the customer's zip. |
|
1132 | - * |
|
1133 | - * @since 1.0.19 |
|
1134 | - * @param string $context View or edit context. |
|
1135 | - * @return string |
|
1136 | - */ |
|
1137 | - public function get_zip( $context = 'view' ) { |
|
1138 | - return $this->get_prop( 'zip', $context ); |
|
1131 | + * Get the customer's zip. |
|
1132 | + * |
|
1133 | + * @since 1.0.19 |
|
1134 | + * @param string $context View or edit context. |
|
1135 | + * @return string |
|
1136 | + */ |
|
1137 | + public function get_zip( $context = 'view' ) { |
|
1138 | + return $this->get_prop( 'zip', $context ); |
|
1139 | 1139 | } |
1140 | 1140 | |
1141 | 1141 | /** |
1142 | - * Alias of self::get_zip(). |
|
1143 | - * |
|
1144 | - * @since 1.0.19 |
|
1145 | - * @param string $context View or edit context. |
|
1146 | - * @return string |
|
1147 | - */ |
|
1148 | - public function get_user_zip( $context = 'view' ) { |
|
1149 | - return $this->get_zip( $context ); |
|
1142 | + * Alias of self::get_zip(). |
|
1143 | + * |
|
1144 | + * @since 1.0.19 |
|
1145 | + * @param string $context View or edit context. |
|
1146 | + * @return string |
|
1147 | + */ |
|
1148 | + public function get_user_zip( $context = 'view' ) { |
|
1149 | + return $this->get_zip( $context ); |
|
1150 | 1150 | } |
1151 | 1151 | |
1152 | 1152 | /** |
1153 | - * Alias of self::get_zip(). |
|
1154 | - * |
|
1155 | - * @since 1.0.19 |
|
1156 | - * @param string $context View or edit context. |
|
1157 | - * @return string |
|
1158 | - */ |
|
1159 | - public function get_customer_zip( $context = 'view' ) { |
|
1160 | - return $this->get_zip( $context ); |
|
1153 | + * Alias of self::get_zip(). |
|
1154 | + * |
|
1155 | + * @since 1.0.19 |
|
1156 | + * @param string $context View or edit context. |
|
1157 | + * @return string |
|
1158 | + */ |
|
1159 | + public function get_customer_zip( $context = 'view' ) { |
|
1160 | + return $this->get_zip( $context ); |
|
1161 | 1161 | } |
1162 | 1162 | |
1163 | 1163 | /** |
1164 | - * Get the customer's company. |
|
1165 | - * |
|
1166 | - * @since 1.0.19 |
|
1167 | - * @param string $context View or edit context. |
|
1168 | - * @return string |
|
1169 | - */ |
|
1170 | - public function get_company( $context = 'view' ) { |
|
1171 | - return $this->get_prop( 'company', $context ); |
|
1164 | + * Get the customer's company. |
|
1165 | + * |
|
1166 | + * @since 1.0.19 |
|
1167 | + * @param string $context View or edit context. |
|
1168 | + * @return string |
|
1169 | + */ |
|
1170 | + public function get_company( $context = 'view' ) { |
|
1171 | + return $this->get_prop( 'company', $context ); |
|
1172 | 1172 | } |
1173 | 1173 | |
1174 | 1174 | /** |
1175 | - * Alias of self::get_company(). |
|
1176 | - * |
|
1177 | - * @since 1.0.19 |
|
1178 | - * @param string $context View or edit context. |
|
1179 | - * @return string |
|
1180 | - */ |
|
1181 | - public function get_user_company( $context = 'view' ) { |
|
1182 | - return $this->get_company( $context ); |
|
1175 | + * Alias of self::get_company(). |
|
1176 | + * |
|
1177 | + * @since 1.0.19 |
|
1178 | + * @param string $context View or edit context. |
|
1179 | + * @return string |
|
1180 | + */ |
|
1181 | + public function get_user_company( $context = 'view' ) { |
|
1182 | + return $this->get_company( $context ); |
|
1183 | + } |
|
1184 | + |
|
1185 | + /** |
|
1186 | + * Alias of self::get_company(). |
|
1187 | + * |
|
1188 | + * @since 1.0.19 |
|
1189 | + * @param string $context View or edit context. |
|
1190 | + * @return string |
|
1191 | + */ |
|
1192 | + public function get_customer_company( $context = 'view' ) { |
|
1193 | + return $this->get_company( $context ); |
|
1183 | 1194 | } |
1184 | 1195 | |
1185 | 1196 | /** |
1186 | - * Alias of self::get_company(). |
|
1187 | - * |
|
1188 | - * @since 1.0.19 |
|
1189 | - * @param string $context View or edit context. |
|
1190 | - * @return string |
|
1191 | - */ |
|
1192 | - public function get_customer_company( $context = 'view' ) { |
|
1193 | - return $this->get_company( $context ); |
|
1197 | + * Get the customer's company id. |
|
1198 | + * |
|
1199 | + * @since 1.0.19 |
|
1200 | + * @param string $context View or edit context. |
|
1201 | + * @return string |
|
1202 | + */ |
|
1203 | + public function get_company_id( $context = 'view' ) { |
|
1204 | + return $this->get_prop( 'company_id', $context ); |
|
1205 | + } |
|
1206 | + |
|
1207 | + /** |
|
1208 | + * Get the customer's vat number. |
|
1209 | + * |
|
1210 | + * @since 1.0.19 |
|
1211 | + * @param string $context View or edit context. |
|
1212 | + * @return string |
|
1213 | + */ |
|
1214 | + public function get_vat_number( $context = 'view' ) { |
|
1215 | + return $this->get_prop( 'vat_number', $context ); |
|
1194 | 1216 | } |
1195 | 1217 | |
1196 | - /** |
|
1197 | - * Get the customer's company id. |
|
1198 | - * |
|
1199 | - * @since 1.0.19 |
|
1200 | - * @param string $context View or edit context. |
|
1201 | - * @return string |
|
1202 | - */ |
|
1203 | - public function get_company_id( $context = 'view' ) { |
|
1204 | - return $this->get_prop( 'company_id', $context ); |
|
1218 | + /** |
|
1219 | + * Alias of self::get_vat_number(). |
|
1220 | + * |
|
1221 | + * @since 1.0.19 |
|
1222 | + * @param string $context View or edit context. |
|
1223 | + * @return string |
|
1224 | + */ |
|
1225 | + public function get_user_vat_number( $context = 'view' ) { |
|
1226 | + return $this->get_vat_number( $context ); |
|
1205 | 1227 | } |
1206 | 1228 | |
1207 | 1229 | /** |
1208 | - * Get the customer's vat number. |
|
1209 | - * |
|
1210 | - * @since 1.0.19 |
|
1211 | - * @param string $context View or edit context. |
|
1212 | - * @return string |
|
1213 | - */ |
|
1214 | - public function get_vat_number( $context = 'view' ) { |
|
1215 | - return $this->get_prop( 'vat_number', $context ); |
|
1230 | + * Alias of self::get_vat_number(). |
|
1231 | + * |
|
1232 | + * @since 1.0.19 |
|
1233 | + * @param string $context View or edit context. |
|
1234 | + * @return string |
|
1235 | + */ |
|
1236 | + public function get_customer_vat_number( $context = 'view' ) { |
|
1237 | + return $this->get_vat_number( $context ); |
|
1216 | 1238 | } |
1217 | 1239 | |
1218 | 1240 | /** |
1219 | - * Alias of self::get_vat_number(). |
|
1220 | - * |
|
1221 | - * @since 1.0.19 |
|
1222 | - * @param string $context View or edit context. |
|
1223 | - * @return string |
|
1224 | - */ |
|
1225 | - public function get_user_vat_number( $context = 'view' ) { |
|
1226 | - return $this->get_vat_number( $context ); |
|
1241 | + * Get the customer's vat rate. |
|
1242 | + * |
|
1243 | + * @since 1.0.19 |
|
1244 | + * @param string $context View or edit context. |
|
1245 | + * @return string |
|
1246 | + */ |
|
1247 | + public function get_vat_rate( $context = 'view' ) { |
|
1248 | + return $this->get_prop( 'vat_rate', $context ); |
|
1227 | 1249 | } |
1228 | 1250 | |
1229 | 1251 | /** |
1230 | - * Alias of self::get_vat_number(). |
|
1231 | - * |
|
1232 | - * @since 1.0.19 |
|
1233 | - * @param string $context View or edit context. |
|
1234 | - * @return string |
|
1235 | - */ |
|
1236 | - public function get_customer_vat_number( $context = 'view' ) { |
|
1237 | - return $this->get_vat_number( $context ); |
|
1252 | + * Alias of self::get_vat_rate(). |
|
1253 | + * |
|
1254 | + * @since 1.0.19 |
|
1255 | + * @param string $context View or edit context. |
|
1256 | + * @return string |
|
1257 | + */ |
|
1258 | + public function get_user_vat_rate( $context = 'view' ) { |
|
1259 | + return $this->get_vat_rate( $context ); |
|
1238 | 1260 | } |
1239 | 1261 | |
1240 | - /** |
|
1241 | - * Get the customer's vat rate. |
|
1242 | - * |
|
1243 | - * @since 1.0.19 |
|
1244 | - * @param string $context View or edit context. |
|
1245 | - * @return string |
|
1246 | - */ |
|
1247 | - public function get_vat_rate( $context = 'view' ) { |
|
1248 | - return $this->get_prop( 'vat_rate', $context ); |
|
1249 | - } |
|
1250 | - |
|
1251 | - /** |
|
1252 | - * Alias of self::get_vat_rate(). |
|
1253 | - * |
|
1254 | - * @since 1.0.19 |
|
1255 | - * @param string $context View or edit context. |
|
1256 | - * @return string |
|
1257 | - */ |
|
1258 | - public function get_user_vat_rate( $context = 'view' ) { |
|
1259 | - return $this->get_vat_rate( $context ); |
|
1260 | - } |
|
1261 | - |
|
1262 | - /** |
|
1263 | - * Alias of self::get_vat_rate(). |
|
1264 | - * |
|
1265 | - * @since 1.0.19 |
|
1266 | - * @param string $context View or edit context. |
|
1267 | - * @return string |
|
1268 | - */ |
|
1269 | - public function get_customer_vat_rate( $context = 'view' ) { |
|
1270 | - return $this->get_vat_rate( $context ); |
|
1271 | - } |
|
1272 | - |
|
1273 | - /** |
|
1274 | - * Get the customer's address. |
|
1275 | - * |
|
1276 | - * @since 1.0.19 |
|
1277 | - * @param string $context View or edit context. |
|
1278 | - * @return string |
|
1279 | - */ |
|
1280 | - public function get_address( $context = 'view' ) { |
|
1281 | - return $this->get_prop( 'address', $context ); |
|
1282 | - } |
|
1283 | - |
|
1284 | - /** |
|
1285 | - * Alias of self::get_address(). |
|
1286 | - * |
|
1287 | - * @since 1.0.19 |
|
1288 | - * @param string $context View or edit context. |
|
1289 | - * @return string |
|
1290 | - */ |
|
1291 | - public function get_user_address( $context = 'view' ) { |
|
1292 | - return $this->get_address( $context ); |
|
1293 | - } |
|
1294 | - |
|
1295 | - /** |
|
1296 | - * Alias of self::get_address(). |
|
1297 | - * |
|
1298 | - * @since 1.0.19 |
|
1299 | - * @param string $context View or edit context. |
|
1300 | - * @return string |
|
1301 | - */ |
|
1302 | - public function get_customer_address( $context = 'view' ) { |
|
1303 | - return $this->get_address( $context ); |
|
1304 | - } |
|
1305 | - |
|
1306 | - /** |
|
1307 | - * Get whether the customer has viewed the invoice or not. |
|
1308 | - * |
|
1309 | - * @since 1.0.19 |
|
1310 | - * @param string $context View or edit context. |
|
1311 | - * @return bool |
|
1312 | - */ |
|
1313 | - public function get_is_viewed( $context = 'view' ) { |
|
1314 | - return (bool) $this->get_prop( 'is_viewed', $context ); |
|
1315 | - } |
|
1316 | - |
|
1317 | - /** |
|
1318 | - * Get other recipients for invoice communications. |
|
1319 | - * |
|
1320 | - * @since 1.0.19 |
|
1321 | - * @param string $context View or edit context. |
|
1322 | - * @return bool |
|
1323 | - */ |
|
1324 | - public function get_email_cc( $context = 'view' ) { |
|
1325 | - return $this->get_prop( 'email_cc', $context ); |
|
1326 | - } |
|
1327 | - |
|
1328 | - /** |
|
1329 | - * Get invoice template. |
|
1330 | - * |
|
1331 | - * @since 1.0.19 |
|
1332 | - * @param string $context View or edit context. |
|
1333 | - * @return bool |
|
1334 | - */ |
|
1335 | - public function get_template( $context = 'view' ) { |
|
1336 | - return $this->get_prop( 'template', $context ); |
|
1337 | - } |
|
1338 | - |
|
1339 | - /** |
|
1340 | - * Get invoice source. |
|
1341 | - * |
|
1342 | - * @since 1.0.19 |
|
1343 | - * @param string $context View or edit context. |
|
1344 | - * @return bool |
|
1345 | - */ |
|
1346 | - public function get_created_via( $context = 'view' ) { |
|
1347 | - return $this->get_prop( 'created_via', $context ); |
|
1348 | - } |
|
1349 | - |
|
1350 | - /** |
|
1351 | - * Get whether the customer has confirmed their address. |
|
1352 | - * |
|
1353 | - * @since 1.0.19 |
|
1354 | - * @param string $context View or edit context. |
|
1355 | - * @return bool |
|
1356 | - */ |
|
1357 | - public function get_address_confirmed( $context = 'view' ) { |
|
1358 | - return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
1359 | - } |
|
1360 | - |
|
1361 | - /** |
|
1362 | - * Alias of self::get_address_confirmed(). |
|
1363 | - * |
|
1364 | - * @since 1.0.19 |
|
1365 | - * @param string $context View or edit context. |
|
1366 | - * @return bool |
|
1367 | - */ |
|
1368 | - public function get_user_address_confirmed( $context = 'view' ) { |
|
1369 | - return $this->get_address_confirmed( $context ); |
|
1370 | - } |
|
1371 | - |
|
1372 | - /** |
|
1373 | - * Alias of self::get_address(). |
|
1374 | - * |
|
1375 | - * @since 1.0.19 |
|
1376 | - * @param string $context View or edit context. |
|
1377 | - * @return bool |
|
1378 | - */ |
|
1379 | - public function get_customer_address_confirmed( $context = 'view' ) { |
|
1380 | - return $this->get_address_confirmed( $context ); |
|
1381 | - } |
|
1382 | - |
|
1383 | - /** |
|
1384 | - * Get the shipping address. |
|
1385 | - * |
|
1386 | - * @since 1.0.19 |
|
1387 | - * @return array|false |
|
1388 | - */ |
|
1389 | - public function get_shipping_address() { |
|
1390 | - |
|
1391 | - $shipping_address = get_post_meta( $this->get_id(), 'shipping_address', true ); |
|
1392 | - return is_array( $shipping_address ) ? $shipping_address : false; |
|
1393 | - } |
|
1394 | - |
|
1395 | - /** |
|
1396 | - * Check if the invoice has a shipping address. |
|
1397 | - */ |
|
1398 | - public function has_shipping_address() { |
|
1399 | - return false !== $this->get_shipping_address(); |
|
1400 | - } |
|
1401 | - |
|
1402 | - /** |
|
1403 | - * Get the shipping amount. |
|
1404 | - * |
|
1405 | - * @since 1.0.19 |
|
1406 | - * @param string $context View or edit context. |
|
1407 | - * @return float |
|
1408 | - */ |
|
1409 | - public function get_shipping( $context = 'view' ) { |
|
1410 | - |
|
1411 | - if ( $context = 'view' ) { |
|
1412 | - return floatval( $this->get_prop( 'shipping', $context ) ); |
|
1413 | - } |
|
1414 | - |
|
1415 | - return $this->get_prop( 'shipping', $context ); |
|
1416 | - } |
|
1417 | - |
|
1418 | - public function has_shipping() { |
|
1419 | - return defined( 'GETPAID_SHIPPING_CALCULATOR_VERSION' ) && null !== $this->get_prop( 'shipping', 'edit' ); |
|
1420 | - } |
|
1421 | - |
|
1422 | - /** |
|
1423 | - * Get the invoice subtotal. |
|
1424 | - * |
|
1425 | - * @since 1.0.19 |
|
1426 | - * @param string $context View or edit context. |
|
1427 | - * @return float |
|
1428 | - */ |
|
1429 | - public function get_subtotal( $context = 'view' ) { |
|
1262 | + /** |
|
1263 | + * Alias of self::get_vat_rate(). |
|
1264 | + * |
|
1265 | + * @since 1.0.19 |
|
1266 | + * @param string $context View or edit context. |
|
1267 | + * @return string |
|
1268 | + */ |
|
1269 | + public function get_customer_vat_rate( $context = 'view' ) { |
|
1270 | + return $this->get_vat_rate( $context ); |
|
1271 | + } |
|
1272 | + |
|
1273 | + /** |
|
1274 | + * Get the customer's address. |
|
1275 | + * |
|
1276 | + * @since 1.0.19 |
|
1277 | + * @param string $context View or edit context. |
|
1278 | + * @return string |
|
1279 | + */ |
|
1280 | + public function get_address( $context = 'view' ) { |
|
1281 | + return $this->get_prop( 'address', $context ); |
|
1282 | + } |
|
1283 | + |
|
1284 | + /** |
|
1285 | + * Alias of self::get_address(). |
|
1286 | + * |
|
1287 | + * @since 1.0.19 |
|
1288 | + * @param string $context View or edit context. |
|
1289 | + * @return string |
|
1290 | + */ |
|
1291 | + public function get_user_address( $context = 'view' ) { |
|
1292 | + return $this->get_address( $context ); |
|
1293 | + } |
|
1294 | + |
|
1295 | + /** |
|
1296 | + * Alias of self::get_address(). |
|
1297 | + * |
|
1298 | + * @since 1.0.19 |
|
1299 | + * @param string $context View or edit context. |
|
1300 | + * @return string |
|
1301 | + */ |
|
1302 | + public function get_customer_address( $context = 'view' ) { |
|
1303 | + return $this->get_address( $context ); |
|
1304 | + } |
|
1305 | + |
|
1306 | + /** |
|
1307 | + * Get whether the customer has viewed the invoice or not. |
|
1308 | + * |
|
1309 | + * @since 1.0.19 |
|
1310 | + * @param string $context View or edit context. |
|
1311 | + * @return bool |
|
1312 | + */ |
|
1313 | + public function get_is_viewed( $context = 'view' ) { |
|
1314 | + return (bool) $this->get_prop( 'is_viewed', $context ); |
|
1315 | + } |
|
1316 | + |
|
1317 | + /** |
|
1318 | + * Get other recipients for invoice communications. |
|
1319 | + * |
|
1320 | + * @since 1.0.19 |
|
1321 | + * @param string $context View or edit context. |
|
1322 | + * @return bool |
|
1323 | + */ |
|
1324 | + public function get_email_cc( $context = 'view' ) { |
|
1325 | + return $this->get_prop( 'email_cc', $context ); |
|
1326 | + } |
|
1327 | + |
|
1328 | + /** |
|
1329 | + * Get invoice template. |
|
1330 | + * |
|
1331 | + * @since 1.0.19 |
|
1332 | + * @param string $context View or edit context. |
|
1333 | + * @return bool |
|
1334 | + */ |
|
1335 | + public function get_template( $context = 'view' ) { |
|
1336 | + return $this->get_prop( 'template', $context ); |
|
1337 | + } |
|
1338 | + |
|
1339 | + /** |
|
1340 | + * Get invoice source. |
|
1341 | + * |
|
1342 | + * @since 1.0.19 |
|
1343 | + * @param string $context View or edit context. |
|
1344 | + * @return bool |
|
1345 | + */ |
|
1346 | + public function get_created_via( $context = 'view' ) { |
|
1347 | + return $this->get_prop( 'created_via', $context ); |
|
1348 | + } |
|
1349 | + |
|
1350 | + /** |
|
1351 | + * Get whether the customer has confirmed their address. |
|
1352 | + * |
|
1353 | + * @since 1.0.19 |
|
1354 | + * @param string $context View or edit context. |
|
1355 | + * @return bool |
|
1356 | + */ |
|
1357 | + public function get_address_confirmed( $context = 'view' ) { |
|
1358 | + return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
1359 | + } |
|
1360 | + |
|
1361 | + /** |
|
1362 | + * Alias of self::get_address_confirmed(). |
|
1363 | + * |
|
1364 | + * @since 1.0.19 |
|
1365 | + * @param string $context View or edit context. |
|
1366 | + * @return bool |
|
1367 | + */ |
|
1368 | + public function get_user_address_confirmed( $context = 'view' ) { |
|
1369 | + return $this->get_address_confirmed( $context ); |
|
1370 | + } |
|
1371 | + |
|
1372 | + /** |
|
1373 | + * Alias of self::get_address(). |
|
1374 | + * |
|
1375 | + * @since 1.0.19 |
|
1376 | + * @param string $context View or edit context. |
|
1377 | + * @return bool |
|
1378 | + */ |
|
1379 | + public function get_customer_address_confirmed( $context = 'view' ) { |
|
1380 | + return $this->get_address_confirmed( $context ); |
|
1381 | + } |
|
1382 | + |
|
1383 | + /** |
|
1384 | + * Get the shipping address. |
|
1385 | + * |
|
1386 | + * @since 1.0.19 |
|
1387 | + * @return array|false |
|
1388 | + */ |
|
1389 | + public function get_shipping_address() { |
|
1390 | + |
|
1391 | + $shipping_address = get_post_meta( $this->get_id(), 'shipping_address', true ); |
|
1392 | + return is_array( $shipping_address ) ? $shipping_address : false; |
|
1393 | + } |
|
1394 | + |
|
1395 | + /** |
|
1396 | + * Check if the invoice has a shipping address. |
|
1397 | + */ |
|
1398 | + public function has_shipping_address() { |
|
1399 | + return false !== $this->get_shipping_address(); |
|
1400 | + } |
|
1401 | + |
|
1402 | + /** |
|
1403 | + * Get the shipping amount. |
|
1404 | + * |
|
1405 | + * @since 1.0.19 |
|
1406 | + * @param string $context View or edit context. |
|
1407 | + * @return float |
|
1408 | + */ |
|
1409 | + public function get_shipping( $context = 'view' ) { |
|
1410 | + |
|
1411 | + if ( $context = 'view' ) { |
|
1412 | + return floatval( $this->get_prop( 'shipping', $context ) ); |
|
1413 | + } |
|
1414 | + |
|
1415 | + return $this->get_prop( 'shipping', $context ); |
|
1416 | + } |
|
1417 | + |
|
1418 | + public function has_shipping() { |
|
1419 | + return defined( 'GETPAID_SHIPPING_CALCULATOR_VERSION' ) && null !== $this->get_prop( 'shipping', 'edit' ); |
|
1420 | + } |
|
1421 | + |
|
1422 | + /** |
|
1423 | + * Get the invoice subtotal. |
|
1424 | + * |
|
1425 | + * @since 1.0.19 |
|
1426 | + * @param string $context View or edit context. |
|
1427 | + * @return float |
|
1428 | + */ |
|
1429 | + public function get_subtotal( $context = 'view' ) { |
|
1430 | 1430 | $subtotal = (float) $this->get_prop( 'subtotal', $context ); |
1431 | 1431 | |
1432 | 1432 | // Backwards compatibility. |
@@ -1438,198 +1438,198 @@ discard block |
||
1438 | 1438 | } |
1439 | 1439 | |
1440 | 1440 | /** |
1441 | - * Get the invoice discount total. |
|
1442 | - * |
|
1443 | - * @since 1.0.19 |
|
1444 | - * @param string $context View or edit context. |
|
1445 | - * @return float |
|
1446 | - */ |
|
1447 | - public function get_total_discount( $context = 'view' ) { |
|
1448 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) ); |
|
1441 | + * Get the invoice discount total. |
|
1442 | + * |
|
1443 | + * @since 1.0.19 |
|
1444 | + * @param string $context View or edit context. |
|
1445 | + * @return float |
|
1446 | + */ |
|
1447 | + public function get_total_discount( $context = 'view' ) { |
|
1448 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) ); |
|
1449 | 1449 | } |
1450 | 1450 | |
1451 | 1451 | /** |
1452 | - * Get the invoice tax total. |
|
1453 | - * |
|
1454 | - * @since 1.0.19 |
|
1455 | - * @param string $context View or edit context. |
|
1456 | - * @return float |
|
1457 | - */ |
|
1458 | - public function get_total_tax( $context = 'view' ) { |
|
1459 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) ); |
|
1460 | - } |
|
1452 | + * Get the invoice tax total. |
|
1453 | + * |
|
1454 | + * @since 1.0.19 |
|
1455 | + * @param string $context View or edit context. |
|
1456 | + * @return float |
|
1457 | + */ |
|
1458 | + public function get_total_tax( $context = 'view' ) { |
|
1459 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) ); |
|
1460 | + } |
|
1461 | 1461 | |
1462 | - /** |
|
1463 | - * @deprecated |
|
1464 | - */ |
|
1465 | - public function get_final_tax( $currency = false ) { |
|
1466 | - $tax = $this->get_total_tax(); |
|
1462 | + /** |
|
1463 | + * @deprecated |
|
1464 | + */ |
|
1465 | + public function get_final_tax( $currency = false ) { |
|
1466 | + $tax = $this->get_total_tax(); |
|
1467 | 1467 | |
1468 | 1468 | if ( $currency ) { |
1469 | - return wpinv_price( $tax, $this->get_currency() ); |
|
1469 | + return wpinv_price( $tax, $this->get_currency() ); |
|
1470 | 1470 | } |
1471 | 1471 | |
1472 | 1472 | return $tax; |
1473 | 1473 | } |
1474 | 1474 | |
1475 | 1475 | /** |
1476 | - * Get the invoice fees total. |
|
1477 | - * |
|
1478 | - * @since 1.0.19 |
|
1479 | - * @param string $context View or edit context. |
|
1480 | - * @return float |
|
1481 | - */ |
|
1482 | - public function get_total_fees( $context = 'view' ) { |
|
1483 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) ); |
|
1476 | + * Get the invoice fees total. |
|
1477 | + * |
|
1478 | + * @since 1.0.19 |
|
1479 | + * @param string $context View or edit context. |
|
1480 | + * @return float |
|
1481 | + */ |
|
1482 | + public function get_total_fees( $context = 'view' ) { |
|
1483 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) ); |
|
1484 | + } |
|
1485 | + |
|
1486 | + /** |
|
1487 | + * Alias for self::get_total_fees(). |
|
1488 | + * |
|
1489 | + * @since 1.0.19 |
|
1490 | + * @param string $context View or edit context. |
|
1491 | + * @return float |
|
1492 | + */ |
|
1493 | + public function get_fees_total( $context = 'view' ) { |
|
1494 | + return $this->get_total_fees( $context ); |
|
1484 | 1495 | } |
1485 | 1496 | |
1486 | 1497 | /** |
1487 | - * Alias for self::get_total_fees(). |
|
1488 | - * |
|
1489 | - * @since 1.0.19 |
|
1490 | - * @param string $context View or edit context. |
|
1491 | - * @return float |
|
1492 | - */ |
|
1493 | - public function get_fees_total( $context = 'view' ) { |
|
1494 | - return $this->get_total_fees( $context ); |
|
1498 | + * Get the invoice total. |
|
1499 | + * |
|
1500 | + * @since 1.0.19 |
|
1501 | + * @return float |
|
1502 | + */ |
|
1503 | + public function get_total( $context = 'view' ) { |
|
1504 | + $total = $this->get_prop( 'total', $context ); |
|
1505 | + |
|
1506 | + if ( $this->has_shipping() && $context == 'view' ) { |
|
1507 | + $total = $this->get_prop( 'total', $context ) + $this->get_shipping( $context ); |
|
1508 | + } |
|
1509 | + |
|
1510 | + return wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1495 | 1511 | } |
1496 | 1512 | |
1497 | 1513 | /** |
1498 | - * Get the invoice total. |
|
1499 | - * |
|
1500 | - * @since 1.0.19 |
|
1514 | + * Retrieves the non-recurring total of items. |
|
1515 | + * |
|
1516 | + * @since 2.3.0 |
|
1501 | 1517 | * @return float |
1502 | - */ |
|
1503 | - public function get_total( $context = 'view' ) { |
|
1504 | - $total = $this->get_prop( 'total', $context ); |
|
1505 | - |
|
1506 | - if ( $this->has_shipping() && $context == 'view' ) { |
|
1507 | - $total = $this->get_prop( 'total', $context ) + $this->get_shipping( $context ); |
|
1508 | - } |
|
1509 | - |
|
1510 | - return wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1511 | - } |
|
1512 | - |
|
1513 | - /** |
|
1514 | - * Retrieves the non-recurring total of items. |
|
1515 | - * |
|
1516 | - * @since 2.3.0 |
|
1517 | - * @return float |
|
1518 | - */ |
|
1519 | - public function get_non_recurring_total() { |
|
1520 | - |
|
1521 | - $subtotal = 0; |
|
1522 | - foreach ( $this->get_items() as $item ) { |
|
1523 | - if ( ! $item->is_recurring() ) { |
|
1524 | - $subtotal += $item->get_sub_total(); |
|
1525 | - } |
|
1526 | - } |
|
1527 | - |
|
1528 | - foreach ( $this->get_fees() as $fee ) { |
|
1529 | - if ( empty( $fee['recurring_fee'] ) ) { |
|
1530 | - $subtotal += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
1531 | - } |
|
1532 | - } |
|
1533 | - |
|
1534 | - $subtotal = wpinv_round_amount( wpinv_sanitize_amount( $subtotal ) ); |
|
1518 | + */ |
|
1519 | + public function get_non_recurring_total() { |
|
1520 | + |
|
1521 | + $subtotal = 0; |
|
1522 | + foreach ( $this->get_items() as $item ) { |
|
1523 | + if ( ! $item->is_recurring() ) { |
|
1524 | + $subtotal += $item->get_sub_total(); |
|
1525 | + } |
|
1526 | + } |
|
1527 | + |
|
1528 | + foreach ( $this->get_fees() as $fee ) { |
|
1529 | + if ( empty( $fee['recurring_fee'] ) ) { |
|
1530 | + $subtotal += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
1531 | + } |
|
1532 | + } |
|
1533 | + |
|
1534 | + $subtotal = wpinv_round_amount( wpinv_sanitize_amount( $subtotal ) ); |
|
1535 | 1535 | return apply_filters( 'wpinv_get_non_recurring_invoice_total', $subtotal, $this ); |
1536 | 1536 | |
1537 | 1537 | } |
1538 | 1538 | |
1539 | - /** |
|
1540 | - * Get the invoice totals. |
|
1541 | - * |
|
1542 | - * @since 1.0.19 |
|
1539 | + /** |
|
1540 | + * Get the invoice totals. |
|
1541 | + * |
|
1542 | + * @since 1.0.19 |
|
1543 | 1543 | * @return array |
1544 | - */ |
|
1545 | - public function get_totals() { |
|
1546 | - return $this->totals; |
|
1544 | + */ |
|
1545 | + public function get_totals() { |
|
1546 | + return $this->totals; |
|
1547 | 1547 | } |
1548 | 1548 | |
1549 | 1549 | /** |
1550 | - * Get the initial invoice total. |
|
1551 | - * |
|
1552 | - * @since 1.0.19 |
|
1550 | + * Get the initial invoice total. |
|
1551 | + * |
|
1552 | + * @since 1.0.19 |
|
1553 | 1553 | * @param string $context View or edit context. |
1554 | 1554 | * @return float |
1555 | - */ |
|
1555 | + */ |
|
1556 | 1556 | public function get_initial_total() { |
1557 | 1557 | |
1558 | - if ( empty( $this->totals ) ) { |
|
1559 | - $this->recalculate_total(); |
|
1560 | - } |
|
1558 | + if ( empty( $this->totals ) ) { |
|
1559 | + $this->recalculate_total(); |
|
1560 | + } |
|
1561 | 1561 | |
1562 | - $tax = $this->totals['tax']['initial']; |
|
1563 | - $fee = $this->totals['fee']['initial']; |
|
1564 | - $discount = $this->totals['discount']['initial']; |
|
1565 | - $subtotal = $this->totals['subtotal']['initial']; |
|
1566 | - $total = $tax + $fee - $discount + $subtotal; |
|
1562 | + $tax = $this->totals['tax']['initial']; |
|
1563 | + $fee = $this->totals['fee']['initial']; |
|
1564 | + $discount = $this->totals['discount']['initial']; |
|
1565 | + $subtotal = $this->totals['subtotal']['initial']; |
|
1566 | + $total = $tax + $fee - $discount + $subtotal; |
|
1567 | 1567 | |
1568 | - if ( 0 > $total ) { |
|
1569 | - $total = 0; |
|
1570 | - } |
|
1568 | + if ( 0 > $total ) { |
|
1569 | + $total = 0; |
|
1570 | + } |
|
1571 | 1571 | |
1572 | - $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1572 | + $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1573 | 1573 | return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this ); |
1574 | - } |
|
1574 | + } |
|
1575 | 1575 | |
1576 | - /** |
|
1577 | - * Get the recurring invoice total. |
|
1578 | - * |
|
1579 | - * @since 1.0.19 |
|
1576 | + /** |
|
1577 | + * Get the recurring invoice total. |
|
1578 | + * |
|
1579 | + * @since 1.0.19 |
|
1580 | 1580 | * @param string $context View or edit context. |
1581 | 1581 | * @return float |
1582 | - */ |
|
1582 | + */ |
|
1583 | 1583 | public function get_recurring_total() { |
1584 | 1584 | |
1585 | - if ( empty( $this->totals ) ) { |
|
1586 | - $this->recalculate_total(); |
|
1587 | - } |
|
1585 | + if ( empty( $this->totals ) ) { |
|
1586 | + $this->recalculate_total(); |
|
1587 | + } |
|
1588 | 1588 | |
1589 | - $tax = $this->totals['tax']['recurring']; |
|
1590 | - $fee = $this->totals['fee']['recurring']; |
|
1591 | - $discount = $this->totals['discount']['recurring']; |
|
1592 | - $subtotal = $this->totals['subtotal']['recurring']; |
|
1593 | - $total = $tax + $fee - $discount + $subtotal; |
|
1589 | + $tax = $this->totals['tax']['recurring']; |
|
1590 | + $fee = $this->totals['fee']['recurring']; |
|
1591 | + $discount = $this->totals['discount']['recurring']; |
|
1592 | + $subtotal = $this->totals['subtotal']['recurring']; |
|
1593 | + $total = $tax + $fee - $discount + $subtotal; |
|
1594 | 1594 | |
1595 | - if ( 0 > $total ) { |
|
1596 | - $total = 0; |
|
1597 | - } |
|
1595 | + if ( 0 > $total ) { |
|
1596 | + $total = 0; |
|
1597 | + } |
|
1598 | 1598 | |
1599 | - $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1599 | + $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1600 | 1600 | return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this ); |
1601 | - } |
|
1601 | + } |
|
1602 | 1602 | |
1603 | - /** |
|
1604 | - * Returns recurring payment details. |
|
1605 | - * |
|
1606 | - * @since 1.0.19 |
|
1603 | + /** |
|
1604 | + * Returns recurring payment details. |
|
1605 | + * |
|
1606 | + * @since 1.0.19 |
|
1607 | 1607 | * @param string $field Optionally provide a field to return. |
1608 | - * @param string $currency Whether to include the currency. |
|
1608 | + * @param string $currency Whether to include the currency. |
|
1609 | 1609 | * @return float|string |
1610 | - */ |
|
1610 | + */ |
|
1611 | 1611 | public function get_recurring_details( $field = '', $currency = false ) { |
1612 | 1612 | |
1613 | - // Maybe recalculate totals. |
|
1614 | - if ( empty( $this->totals ) ) { |
|
1615 | - $this->recalculate_total(); |
|
1616 | - } |
|
1613 | + // Maybe recalculate totals. |
|
1614 | + if ( empty( $this->totals ) ) { |
|
1615 | + $this->recalculate_total(); |
|
1616 | + } |
|
1617 | 1617 | |
1618 | - // Prepare recurring totals. |
|
1618 | + // Prepare recurring totals. |
|
1619 | 1619 | $data = apply_filters( |
1620 | - 'wpinv_get_invoice_recurring_details', |
|
1621 | - array( |
|
1622 | - 'cart_details' => $this->get_cart_details(), |
|
1623 | - 'subtotal' => $this->totals['subtotal']['recurring'], |
|
1624 | - 'discount' => $this->totals['discount']['recurring'], |
|
1625 | - 'tax' => $this->totals['tax']['recurring'], |
|
1626 | - 'fee' => $this->totals['fee']['recurring'], |
|
1627 | - 'total' => $this->get_recurring_total(), |
|
1628 | - ), |
|
1629 | - $this, |
|
1630 | - $field, |
|
1631 | - $currency |
|
1632 | - ); |
|
1620 | + 'wpinv_get_invoice_recurring_details', |
|
1621 | + array( |
|
1622 | + 'cart_details' => $this->get_cart_details(), |
|
1623 | + 'subtotal' => $this->totals['subtotal']['recurring'], |
|
1624 | + 'discount' => $this->totals['discount']['recurring'], |
|
1625 | + 'tax' => $this->totals['tax']['recurring'], |
|
1626 | + 'fee' => $this->totals['fee']['recurring'], |
|
1627 | + 'total' => $this->get_recurring_total(), |
|
1628 | + ), |
|
1629 | + $this, |
|
1630 | + $field, |
|
1631 | + $currency |
|
1632 | + ); |
|
1633 | 1633 | |
1634 | 1634 | if ( isset( $data[ $field ] ) ) { |
1635 | 1635 | return ( $currency ? wpinv_price( $data[ $field ], $this->get_currency() ) : $data[ $field ] ); |
@@ -1639,166 +1639,166 @@ discard block |
||
1639 | 1639 | } |
1640 | 1640 | |
1641 | 1641 | /** |
1642 | - * Get the invoice fees. |
|
1643 | - * |
|
1644 | - * @since 1.0.19 |
|
1645 | - * @param string $context View or edit context. |
|
1646 | - * @return array |
|
1647 | - */ |
|
1648 | - public function get_fees( $context = 'view' ) { |
|
1649 | - return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
1642 | + * Get the invoice fees. |
|
1643 | + * |
|
1644 | + * @since 1.0.19 |
|
1645 | + * @param string $context View or edit context. |
|
1646 | + * @return array |
|
1647 | + */ |
|
1648 | + public function get_fees( $context = 'view' ) { |
|
1649 | + return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
1650 | 1650 | } |
1651 | 1651 | |
1652 | 1652 | /** |
1653 | - * Get the invoice discounts. |
|
1654 | - * |
|
1655 | - * @since 1.0.19 |
|
1656 | - * @param string $context View or edit context. |
|
1657 | - * @return array |
|
1658 | - */ |
|
1659 | - public function get_discounts( $context = 'view' ) { |
|
1660 | - return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
1653 | + * Get the invoice discounts. |
|
1654 | + * |
|
1655 | + * @since 1.0.19 |
|
1656 | + * @param string $context View or edit context. |
|
1657 | + * @return array |
|
1658 | + */ |
|
1659 | + public function get_discounts( $context = 'view' ) { |
|
1660 | + return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
1661 | 1661 | } |
1662 | 1662 | |
1663 | 1663 | /** |
1664 | - * Get the invoice taxes. |
|
1665 | - * |
|
1666 | - * @since 1.0.19 |
|
1667 | - * @param string $context View or edit context. |
|
1668 | - * @return array |
|
1669 | - */ |
|
1670 | - public function get_taxes( $context = 'view' ) { |
|
1671 | - return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
1664 | + * Get the invoice taxes. |
|
1665 | + * |
|
1666 | + * @since 1.0.19 |
|
1667 | + * @param string $context View or edit context. |
|
1668 | + * @return array |
|
1669 | + */ |
|
1670 | + public function get_taxes( $context = 'view' ) { |
|
1671 | + return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
1672 | 1672 | } |
1673 | 1673 | |
1674 | 1674 | /** |
1675 | - * Get the invoice items. |
|
1676 | - * |
|
1677 | - * @since 1.0.19 |
|
1678 | - * @param string $context View or edit context. |
|
1679 | - * @return GetPaid_Form_Item[] |
|
1680 | - */ |
|
1681 | - public function get_items( $context = 'view' ) { |
|
1675 | + * Get the invoice items. |
|
1676 | + * |
|
1677 | + * @since 1.0.19 |
|
1678 | + * @param string $context View or edit context. |
|
1679 | + * @return GetPaid_Form_Item[] |
|
1680 | + */ |
|
1681 | + public function get_items( $context = 'view' ) { |
|
1682 | 1682 | return $this->get_prop( 'items', $context ); |
1683 | - } |
|
1683 | + } |
|
1684 | 1684 | |
1685 | - /** |
|
1686 | - * Get the invoice item ids. |
|
1687 | - * |
|
1688 | - * @since 1.0.19 |
|
1689 | - * @return string |
|
1690 | - */ |
|
1691 | - public function get_item_ids() { |
|
1692 | - return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) ); |
|
1685 | + /** |
|
1686 | + * Get the invoice item ids. |
|
1687 | + * |
|
1688 | + * @since 1.0.19 |
|
1689 | + * @return string |
|
1690 | + */ |
|
1691 | + public function get_item_ids() { |
|
1692 | + return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) ); |
|
1693 | 1693 | } |
1694 | 1694 | |
1695 | 1695 | /** |
1696 | - * Get the invoice's payment form. |
|
1697 | - * |
|
1698 | - * @since 1.0.19 |
|
1699 | - * @param string $context View or edit context. |
|
1700 | - * @return int |
|
1701 | - */ |
|
1702 | - public function get_payment_form( $context = 'view' ) { |
|
1703 | - return intval( $this->get_prop( 'payment_form', $context ) ); |
|
1696 | + * Get the invoice's payment form. |
|
1697 | + * |
|
1698 | + * @since 1.0.19 |
|
1699 | + * @param string $context View or edit context. |
|
1700 | + * @return int |
|
1701 | + */ |
|
1702 | + public function get_payment_form( $context = 'view' ) { |
|
1703 | + return intval( $this->get_prop( 'payment_form', $context ) ); |
|
1704 | 1704 | } |
1705 | 1705 | |
1706 | 1706 | /** |
1707 | - * Get the invoice's submission id. |
|
1708 | - * |
|
1709 | - * @since 1.0.19 |
|
1710 | - * @param string $context View or edit context. |
|
1711 | - * @return string |
|
1712 | - */ |
|
1713 | - public function get_submission_id( $context = 'view' ) { |
|
1714 | - return $this->get_prop( 'submission_id', $context ); |
|
1707 | + * Get the invoice's submission id. |
|
1708 | + * |
|
1709 | + * @since 1.0.19 |
|
1710 | + * @param string $context View or edit context. |
|
1711 | + * @return string |
|
1712 | + */ |
|
1713 | + public function get_submission_id( $context = 'view' ) { |
|
1714 | + return $this->get_prop( 'submission_id', $context ); |
|
1715 | 1715 | } |
1716 | 1716 | |
1717 | 1717 | /** |
1718 | - * Get the invoice's discount code. |
|
1719 | - * |
|
1720 | - * @since 1.0.19 |
|
1721 | - * @param string $context View or edit context. |
|
1722 | - * @return string |
|
1723 | - */ |
|
1724 | - public function get_discount_code( $context = 'view' ) { |
|
1725 | - return $this->get_prop( 'discount_code', $context ); |
|
1718 | + * Get the invoice's discount code. |
|
1719 | + * |
|
1720 | + * @since 1.0.19 |
|
1721 | + * @param string $context View or edit context. |
|
1722 | + * @return string |
|
1723 | + */ |
|
1724 | + public function get_discount_code( $context = 'view' ) { |
|
1725 | + return $this->get_prop( 'discount_code', $context ); |
|
1726 | 1726 | } |
1727 | 1727 | |
1728 | 1728 | /** |
1729 | - * Get the invoice's gateway. |
|
1730 | - * |
|
1731 | - * @since 1.0.19 |
|
1732 | - * @param string $context View or edit context. |
|
1733 | - * @return string |
|
1734 | - */ |
|
1735 | - public function get_gateway( $context = 'view' ) { |
|
1736 | - return $this->get_prop( 'gateway', $context ); |
|
1729 | + * Get the invoice's gateway. |
|
1730 | + * |
|
1731 | + * @since 1.0.19 |
|
1732 | + * @param string $context View or edit context. |
|
1733 | + * @return string |
|
1734 | + */ |
|
1735 | + public function get_gateway( $context = 'view' ) { |
|
1736 | + return $this->get_prop( 'gateway', $context ); |
|
1737 | 1737 | } |
1738 | 1738 | |
1739 | 1739 | /** |
1740 | - * Get the invoice's gateway display title. |
|
1741 | - * |
|
1742 | - * @since 1.0.19 |
|
1743 | - * @return string |
|
1744 | - */ |
|
1740 | + * Get the invoice's gateway display title. |
|
1741 | + * |
|
1742 | + * @since 1.0.19 |
|
1743 | + * @return string |
|
1744 | + */ |
|
1745 | 1745 | public function get_gateway_title() { |
1746 | 1746 | $title = wpinv_get_gateway_checkout_label( $this->get_gateway() ); |
1747 | 1747 | return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this ); |
1748 | 1748 | } |
1749 | 1749 | |
1750 | 1750 | /** |
1751 | - * Get the invoice's transaction id. |
|
1752 | - * |
|
1753 | - * @since 1.0.19 |
|
1754 | - * @param string $context View or edit context. |
|
1755 | - * @return string |
|
1756 | - */ |
|
1757 | - public function get_transaction_id( $context = 'view' ) { |
|
1758 | - return $this->get_prop( 'transaction_id', $context ); |
|
1751 | + * Get the invoice's transaction id. |
|
1752 | + * |
|
1753 | + * @since 1.0.19 |
|
1754 | + * @param string $context View or edit context. |
|
1755 | + * @return string |
|
1756 | + */ |
|
1757 | + public function get_transaction_id( $context = 'view' ) { |
|
1758 | + return $this->get_prop( 'transaction_id', $context ); |
|
1759 | 1759 | } |
1760 | 1760 | |
1761 | 1761 | /** |
1762 | - * Get the invoice's currency. |
|
1763 | - * |
|
1764 | - * @since 1.0.19 |
|
1765 | - * @param string $context View or edit context. |
|
1766 | - * @return string |
|
1767 | - */ |
|
1768 | - public function get_currency( $context = 'view' ) { |
|
1762 | + * Get the invoice's currency. |
|
1763 | + * |
|
1764 | + * @since 1.0.19 |
|
1765 | + * @param string $context View or edit context. |
|
1766 | + * @return string |
|
1767 | + */ |
|
1768 | + public function get_currency( $context = 'view' ) { |
|
1769 | 1769 | $currency = $this->get_prop( 'currency', $context ); |
1770 | 1770 | return empty( $currency ) ? wpinv_get_currency() : $currency; |
1771 | 1771 | } |
1772 | 1772 | |
1773 | 1773 | /** |
1774 | - * Checks if we are charging taxes for this invoice. |
|
1775 | - * |
|
1776 | - * @since 1.0.19 |
|
1777 | - * @param string $context View or edit context. |
|
1778 | - * @return bool |
|
1779 | - */ |
|
1780 | - public function get_disable_taxes( $context = 'view' ) { |
|
1774 | + * Checks if we are charging taxes for this invoice. |
|
1775 | + * |
|
1776 | + * @since 1.0.19 |
|
1777 | + * @param string $context View or edit context. |
|
1778 | + * @return bool |
|
1779 | + */ |
|
1780 | + public function get_disable_taxes( $context = 'view' ) { |
|
1781 | 1781 | return (bool) $this->get_prop( 'disable_taxes', $context ); |
1782 | 1782 | } |
1783 | 1783 | |
1784 | 1784 | /** |
1785 | - * Retrieves the subscription id for an invoice. |
|
1786 | - * |
|
1787 | - * @since 1.0.19 |
|
1788 | - * @param string $context View or edit context. |
|
1789 | - * @return int |
|
1790 | - */ |
|
1785 | + * Retrieves the subscription id for an invoice. |
|
1786 | + * |
|
1787 | + * @since 1.0.19 |
|
1788 | + * @param string $context View or edit context. |
|
1789 | + * @return int |
|
1790 | + */ |
|
1791 | 1791 | public function get_subscription_id( $context = 'view' ) { |
1792 | - return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
1793 | - } |
|
1794 | - |
|
1795 | - /** |
|
1796 | - * Retrieves the remote subscription id for an invoice. |
|
1797 | - * |
|
1798 | - * @since 1.0.19 |
|
1799 | - * @param string $context View or edit context. |
|
1800 | - * @return int |
|
1801 | - */ |
|
1792 | + return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
1793 | + } |
|
1794 | + |
|
1795 | + /** |
|
1796 | + * Retrieves the remote subscription id for an invoice. |
|
1797 | + * |
|
1798 | + * @since 1.0.19 |
|
1799 | + * @param string $context View or edit context. |
|
1800 | + * @return int |
|
1801 | + */ |
|
1802 | 1802 | public function get_remote_subscription_id( $context = 'view' ) { |
1803 | 1803 | $subscription_id = $this->get_prop( 'remote_subscription_id', $context ); |
1804 | 1804 | |
@@ -1811,12 +1811,12 @@ discard block |
||
1811 | 1811 | } |
1812 | 1812 | |
1813 | 1813 | /** |
1814 | - * Retrieves the payment meta for an invoice. |
|
1815 | - * |
|
1816 | - * @since 1.0.19 |
|
1817 | - * @param string $context View or edit context. |
|
1818 | - * @return array |
|
1819 | - */ |
|
1814 | + * Retrieves the payment meta for an invoice. |
|
1815 | + * |
|
1816 | + * @since 1.0.19 |
|
1817 | + * @param string $context View or edit context. |
|
1818 | + * @return array |
|
1819 | + */ |
|
1820 | 1820 | public function get_payment_meta( $context = 'view' ) { |
1821 | 1821 | |
1822 | 1822 | return array( |
@@ -1836,31 +1836,31 @@ discard block |
||
1836 | 1836 | } |
1837 | 1837 | |
1838 | 1838 | /** |
1839 | - * Retrieves the cart details for an invoice. |
|
1840 | - * |
|
1841 | - * @since 1.0.19 |
|
1842 | - * @return array |
|
1843 | - */ |
|
1839 | + * Retrieves the cart details for an invoice. |
|
1840 | + * |
|
1841 | + * @since 1.0.19 |
|
1842 | + * @return array |
|
1843 | + */ |
|
1844 | 1844 | public function get_cart_details() { |
1845 | 1845 | $items = $this->get_items(); |
1846 | 1846 | $cart_details = array(); |
1847 | 1847 | |
1848 | 1848 | foreach ( $items as $item ) { |
1849 | - $item->invoice_id = $this->get_id(); |
|
1849 | + $item->invoice_id = $this->get_id(); |
|
1850 | 1850 | $cart_details[] = $item->prepare_data_for_saving(); |
1851 | 1851 | } |
1852 | 1852 | |
1853 | 1853 | return $cart_details; |
1854 | - } |
|
1854 | + } |
|
1855 | 1855 | |
1856 | - /** |
|
1857 | - * Retrieves the recurring item. |
|
1858 | - * |
|
1859 | - * @return null|GetPaid_Form_Item|int |
|
1860 | - */ |
|
1861 | - public function get_recurring( $object = false ) { |
|
1856 | + /** |
|
1857 | + * Retrieves the recurring item. |
|
1858 | + * |
|
1859 | + * @return null|GetPaid_Form_Item|int |
|
1860 | + */ |
|
1861 | + public function get_recurring( $object = false ) { |
|
1862 | 1862 | |
1863 | - // Are we returning an object? |
|
1863 | + // Are we returning an object? |
|
1864 | 1864 | if ( $object ) { |
1865 | 1865 | return $this->get_item( $this->recurring_item ); |
1866 | 1866 | } |
@@ -1868,130 +1868,130 @@ discard block |
||
1868 | 1868 | return $this->recurring_item; |
1869 | 1869 | } |
1870 | 1870 | |
1871 | - /** |
|
1872 | - * Retrieves the subscription name. |
|
1873 | - * |
|
1874 | - * @since 1.0.19 |
|
1875 | - * @return string |
|
1876 | - */ |
|
1877 | - public function get_subscription_name() { |
|
1871 | + /** |
|
1872 | + * Retrieves the subscription name. |
|
1873 | + * |
|
1874 | + * @since 1.0.19 |
|
1875 | + * @return string |
|
1876 | + */ |
|
1877 | + public function get_subscription_name() { |
|
1878 | 1878 | |
1879 | - // Retrieve the recurring name |
|
1879 | + // Retrieve the recurring name |
|
1880 | 1880 | $item = $this->get_recurring( true ); |
1881 | 1881 | |
1882 | - // Abort if it does not exist. |
|
1882 | + // Abort if it does not exist. |
|
1883 | 1883 | if ( empty( $item ) ) { |
1884 | 1884 | return ''; |
1885 | 1885 | } |
1886 | 1886 | |
1887 | - // Return the item name. |
|
1887 | + // Return the item name. |
|
1888 | 1888 | return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this ); |
1889 | - } |
|
1890 | - |
|
1891 | - /** |
|
1892 | - * Retrieves the view url. |
|
1893 | - * |
|
1894 | - * @since 1.0.19 |
|
1895 | - * @return string |
|
1896 | - */ |
|
1897 | - public function get_view_url() { |
|
1889 | + } |
|
1890 | + |
|
1891 | + /** |
|
1892 | + * Retrieves the view url. |
|
1893 | + * |
|
1894 | + * @since 1.0.19 |
|
1895 | + * @return string |
|
1896 | + */ |
|
1897 | + public function get_view_url() { |
|
1898 | 1898 | $invoice_url = get_permalink( $this->get_id() ); |
1899 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
1899 | + $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
1900 | 1900 | return apply_filters( 'wpinv_get_view_url', $invoice_url, $this ); |
1901 | - } |
|
1901 | + } |
|
1902 | 1902 | |
1903 | - /** |
|
1904 | - * Retrieves the payment url. |
|
1905 | - * |
|
1906 | - * @since 1.0.19 |
|
1907 | - * @return string |
|
1908 | - */ |
|
1909 | - public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
1903 | + /** |
|
1904 | + * Retrieves the payment url. |
|
1905 | + * |
|
1906 | + * @since 1.0.19 |
|
1907 | + * @return string |
|
1908 | + */ |
|
1909 | + public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
1910 | 1910 | |
1911 | - // Retrieve the checkout url. |
|
1911 | + // Retrieve the checkout url. |
|
1912 | 1912 | $pay_url = wpinv_get_checkout_uri(); |
1913 | 1913 | |
1914 | - // Maybe force ssl. |
|
1914 | + // Maybe force ssl. |
|
1915 | 1915 | if ( is_ssl() ) { |
1916 | 1916 | $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
1917 | 1917 | } |
1918 | 1918 | |
1919 | - // Add the invoice key. |
|
1920 | - $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
1919 | + // Add the invoice key. |
|
1920 | + $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
1921 | 1921 | |
1922 | - // (Maybe?) add a secret |
|
1922 | + // (Maybe?) add a secret |
|
1923 | 1923 | if ( $secret ) { |
1924 | 1924 | $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url ); |
1925 | 1925 | } |
1926 | 1926 | |
1927 | 1927 | return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret ); |
1928 | - } |
|
1928 | + } |
|
1929 | 1929 | |
1930 | - /** |
|
1931 | - * Retrieves the receipt url. |
|
1932 | - * |
|
1933 | - * @since 1.0.19 |
|
1934 | - * @return string |
|
1935 | - */ |
|
1936 | - public function get_receipt_url() { |
|
1930 | + /** |
|
1931 | + * Retrieves the receipt url. |
|
1932 | + * |
|
1933 | + * @since 1.0.19 |
|
1934 | + * @return string |
|
1935 | + */ |
|
1936 | + public function get_receipt_url() { |
|
1937 | 1937 | |
1938 | - // Retrieve the checkout url. |
|
1938 | + // Retrieve the checkout url. |
|
1939 | 1939 | $receipt_url = wpinv_get_success_page_uri(); |
1940 | 1940 | |
1941 | - // Maybe force ssl. |
|
1941 | + // Maybe force ssl. |
|
1942 | 1942 | if ( is_ssl() ) { |
1943 | 1943 | $receipt_url = str_replace( 'http:', 'https:', $receipt_url ); |
1944 | 1944 | } |
1945 | 1945 | |
1946 | - // Add the invoice key. |
|
1947 | - $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
1946 | + // Add the invoice key. |
|
1947 | + $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
1948 | 1948 | |
1949 | 1949 | return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this ); |
1950 | - } |
|
1951 | - |
|
1952 | - /** |
|
1953 | - * Retrieves the remote transaction url. |
|
1954 | - * |
|
1955 | - * @since 1.6.0 |
|
1956 | - * @return string |
|
1957 | - */ |
|
1958 | - public function get_transaction_url() { |
|
1959 | - return apply_filters( 'getpaid_gateway_' . $this->get_gateway() . '_transaction_url', '', $this ); |
|
1960 | - } |
|
1961 | - |
|
1962 | - /** |
|
1963 | - * Retrieves the default status. |
|
1964 | - * |
|
1965 | - * @since 1.0.19 |
|
1966 | - * @return string |
|
1967 | - */ |
|
1968 | - public function get_default_status() { |
|
1969 | - |
|
1970 | - $type = $this->get_type(); |
|
1971 | - $status = "wpi-$type-pending"; |
|
1972 | - return str_replace( '-invoice', '', $status ); |
|
1973 | - |
|
1974 | - } |
|
1975 | - |
|
1976 | - /** |
|
1977 | - * Magic method for accessing invoice properties. |
|
1978 | - * |
|
1979 | - * @since 1.0.15 |
|
1980 | - * @access public |
|
1981 | - * |
|
1982 | - * @param string $key Discount data to retrieve |
|
1983 | - * @param string $context View or edit context. |
|
1984 | - * @return mixed Value of the given invoice property (if set). |
|
1985 | - */ |
|
1986 | - public function get( $key, $context = 'view' ) { |
|
1987 | - $method = "get_$key"; |
|
1988 | - |
|
1989 | - if ( is_callable( array( $this, $method ) ) ) { |
|
1990 | - return $this->$method( $context ); |
|
1991 | - } |
|
1950 | + } |
|
1951 | + |
|
1952 | + /** |
|
1953 | + * Retrieves the remote transaction url. |
|
1954 | + * |
|
1955 | + * @since 1.6.0 |
|
1956 | + * @return string |
|
1957 | + */ |
|
1958 | + public function get_transaction_url() { |
|
1959 | + return apply_filters( 'getpaid_gateway_' . $this->get_gateway() . '_transaction_url', '', $this ); |
|
1960 | + } |
|
1961 | + |
|
1962 | + /** |
|
1963 | + * Retrieves the default status. |
|
1964 | + * |
|
1965 | + * @since 1.0.19 |
|
1966 | + * @return string |
|
1967 | + */ |
|
1968 | + public function get_default_status() { |
|
1969 | + |
|
1970 | + $type = $this->get_type(); |
|
1971 | + $status = "wpi-$type-pending"; |
|
1972 | + return str_replace( '-invoice', '', $status ); |
|
1973 | + |
|
1974 | + } |
|
1975 | + |
|
1976 | + /** |
|
1977 | + * Magic method for accessing invoice properties. |
|
1978 | + * |
|
1979 | + * @since 1.0.15 |
|
1980 | + * @access public |
|
1981 | + * |
|
1982 | + * @param string $key Discount data to retrieve |
|
1983 | + * @param string $context View or edit context. |
|
1984 | + * @return mixed Value of the given invoice property (if set). |
|
1985 | + */ |
|
1986 | + public function get( $key, $context = 'view' ) { |
|
1987 | + $method = "get_$key"; |
|
1988 | + |
|
1989 | + if ( is_callable( array( $this, $method ) ) ) { |
|
1990 | + return $this->$method( $context ); |
|
1991 | + } |
|
1992 | 1992 | |
1993 | 1993 | return $this->get_prop( $key, $context ); |
1994 | - } |
|
1994 | + } |
|
1995 | 1995 | |
1996 | 1996 | /* |
1997 | 1997 | |-------------------------------------------------------------------------- |
@@ -2004,129 +2004,129 @@ discard block |
||
2004 | 2004 | */ |
2005 | 2005 | |
2006 | 2006 | /** |
2007 | - * Magic method for setting invoice properties. |
|
2008 | - * |
|
2009 | - * @since 1.0.19 |
|
2010 | - * @access public |
|
2011 | - * |
|
2012 | - * @param string $key Discount data to retrieve |
|
2013 | - * @param mixed $value new value. |
|
2014 | - * @return mixed Value of the given invoice property (if set). |
|
2015 | - */ |
|
2016 | - public function set( $key, $value ) { |
|
2007 | + * Magic method for setting invoice properties. |
|
2008 | + * |
|
2009 | + * @since 1.0.19 |
|
2010 | + * @access public |
|
2011 | + * |
|
2012 | + * @param string $key Discount data to retrieve |
|
2013 | + * @param mixed $value new value. |
|
2014 | + * @return mixed Value of the given invoice property (if set). |
|
2015 | + */ |
|
2016 | + public function set( $key, $value ) { |
|
2017 | 2017 | |
2018 | 2018 | $setter = "set_$key"; |
2019 | 2019 | if ( is_callable( array( $this, $setter ) ) ) { |
2020 | 2020 | $this->{$setter}( $value ); |
2021 | 2021 | } |
2022 | 2022 | |
2023 | - } |
|
2024 | - |
|
2025 | - /** |
|
2026 | - * Sets item status. |
|
2027 | - * |
|
2028 | - * @since 1.0.19 |
|
2029 | - * @param string $new_status New status. |
|
2030 | - * @param string $note Optional note to add. |
|
2031 | - * @param bool $manual_update Is this a manual status change?. |
|
2032 | - * @return array details of change. |
|
2033 | - */ |
|
2034 | - public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
2035 | - $old_status = $this->get_status(); |
|
2036 | - |
|
2037 | - $statuses = $this->get_all_statuses(); |
|
2038 | - |
|
2039 | - if ( isset( $statuses['draft'] ) ) { |
|
2040 | - unset( $statuses['draft'] ); |
|
2041 | - } |
|
2042 | - |
|
2043 | - $this->set_prop( 'status', $new_status ); |
|
2044 | - |
|
2045 | - // If setting the status, ensure it's set to a valid status. |
|
2046 | - if ( true === $this->object_read ) { |
|
2047 | - |
|
2048 | - // Only allow valid new status. |
|
2049 | - if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
2050 | - $new_status = $this->get_default_status(); |
|
2051 | - } |
|
2052 | - |
|
2053 | - // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
2054 | - if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
2055 | - $old_status = $this->get_default_status(); |
|
2056 | - } |
|
2057 | - |
|
2058 | - // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
2059 | - if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
2060 | - $old_status = 'wpi-pending'; |
|
2061 | - } |
|
2062 | - |
|
2063 | - if ( $old_status !== $new_status ) { |
|
2064 | - $this->status_transition = array( |
|
2065 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
2066 | - 'to' => $new_status, |
|
2067 | - 'note' => $note, |
|
2068 | - 'manual' => (bool) $manual_update, |
|
2069 | - ); |
|
2070 | - |
|
2071 | - if ( $manual_update ) { |
|
2072 | - do_action( 'getpaid_' . $this->object_type . '_edit_status', $this->get_id(), $new_status ); |
|
2073 | - } |
|
2074 | - |
|
2075 | - $this->maybe_set_date_paid(); |
|
2076 | - |
|
2077 | - } |
|
2078 | - } |
|
2079 | - |
|
2080 | - return array( |
|
2081 | - 'from' => $old_status, |
|
2082 | - 'to' => $new_status, |
|
2083 | - ); |
|
2084 | - } |
|
2085 | - |
|
2086 | - /** |
|
2087 | - * Maybe set date paid. |
|
2088 | - * |
|
2089 | - * Sets the date paid variable when transitioning to the payment complete |
|
2090 | - * order status. |
|
2091 | - * |
|
2092 | - * @since 1.0.19 |
|
2093 | - */ |
|
2094 | - public function maybe_set_date_paid() { |
|
2095 | - |
|
2096 | - if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
2097 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
2098 | - } |
|
2099 | - } |
|
2100 | - |
|
2101 | - /** |
|
2102 | - * Set parent invoice ID. |
|
2103 | - * |
|
2104 | - * @since 1.0.19 |
|
2105 | - */ |
|
2106 | - public function set_parent_id( $value ) { |
|
2107 | - if ( $value && ( $value === $this->get_id() ) ) { |
|
2108 | - return; |
|
2109 | - } |
|
2110 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
2111 | - } |
|
2112 | - |
|
2113 | - /** |
|
2114 | - * Set plugin version when the invoice was created. |
|
2115 | - * |
|
2116 | - * @since 1.0.19 |
|
2117 | - */ |
|
2118 | - public function set_version( $value ) { |
|
2119 | - $this->set_prop( 'version', $value ); |
|
2120 | - } |
|
2121 | - |
|
2122 | - /** |
|
2123 | - * Set date when the invoice was created. |
|
2124 | - * |
|
2125 | - * @since 1.0.19 |
|
2126 | - * @param string $value Value to set. |
|
2023 | + } |
|
2024 | + |
|
2025 | + /** |
|
2026 | + * Sets item status. |
|
2027 | + * |
|
2028 | + * @since 1.0.19 |
|
2029 | + * @param string $new_status New status. |
|
2030 | + * @param string $note Optional note to add. |
|
2031 | + * @param bool $manual_update Is this a manual status change?. |
|
2032 | + * @return array details of change. |
|
2033 | + */ |
|
2034 | + public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
2035 | + $old_status = $this->get_status(); |
|
2036 | + |
|
2037 | + $statuses = $this->get_all_statuses(); |
|
2038 | + |
|
2039 | + if ( isset( $statuses['draft'] ) ) { |
|
2040 | + unset( $statuses['draft'] ); |
|
2041 | + } |
|
2042 | + |
|
2043 | + $this->set_prop( 'status', $new_status ); |
|
2044 | + |
|
2045 | + // If setting the status, ensure it's set to a valid status. |
|
2046 | + if ( true === $this->object_read ) { |
|
2047 | + |
|
2048 | + // Only allow valid new status. |
|
2049 | + if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
2050 | + $new_status = $this->get_default_status(); |
|
2051 | + } |
|
2052 | + |
|
2053 | + // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
2054 | + if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
2055 | + $old_status = $this->get_default_status(); |
|
2056 | + } |
|
2057 | + |
|
2058 | + // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
2059 | + if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
2060 | + $old_status = 'wpi-pending'; |
|
2061 | + } |
|
2062 | + |
|
2063 | + if ( $old_status !== $new_status ) { |
|
2064 | + $this->status_transition = array( |
|
2065 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
2066 | + 'to' => $new_status, |
|
2067 | + 'note' => $note, |
|
2068 | + 'manual' => (bool) $manual_update, |
|
2069 | + ); |
|
2070 | + |
|
2071 | + if ( $manual_update ) { |
|
2072 | + do_action( 'getpaid_' . $this->object_type . '_edit_status', $this->get_id(), $new_status ); |
|
2073 | + } |
|
2074 | + |
|
2075 | + $this->maybe_set_date_paid(); |
|
2076 | + |
|
2077 | + } |
|
2078 | + } |
|
2079 | + |
|
2080 | + return array( |
|
2081 | + 'from' => $old_status, |
|
2082 | + 'to' => $new_status, |
|
2083 | + ); |
|
2084 | + } |
|
2085 | + |
|
2086 | + /** |
|
2087 | + * Maybe set date paid. |
|
2088 | + * |
|
2089 | + * Sets the date paid variable when transitioning to the payment complete |
|
2090 | + * order status. |
|
2091 | + * |
|
2092 | + * @since 1.0.19 |
|
2093 | + */ |
|
2094 | + public function maybe_set_date_paid() { |
|
2095 | + |
|
2096 | + if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
2097 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
2098 | + } |
|
2099 | + } |
|
2100 | + |
|
2101 | + /** |
|
2102 | + * Set parent invoice ID. |
|
2103 | + * |
|
2104 | + * @since 1.0.19 |
|
2105 | + */ |
|
2106 | + public function set_parent_id( $value ) { |
|
2107 | + if ( $value && ( $value === $this->get_id() ) ) { |
|
2108 | + return; |
|
2109 | + } |
|
2110 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
2111 | + } |
|
2112 | + |
|
2113 | + /** |
|
2114 | + * Set plugin version when the invoice was created. |
|
2115 | + * |
|
2116 | + * @since 1.0.19 |
|
2117 | + */ |
|
2118 | + public function set_version( $value ) { |
|
2119 | + $this->set_prop( 'version', $value ); |
|
2120 | + } |
|
2121 | + |
|
2122 | + /** |
|
2123 | + * Set date when the invoice was created. |
|
2124 | + * |
|
2125 | + * @since 1.0.19 |
|
2126 | + * @param string $value Value to set. |
|
2127 | 2127 | * @return bool Whether or not the date was set. |
2128 | - */ |
|
2129 | - public function set_date_created( $value ) { |
|
2128 | + */ |
|
2129 | + public function set_date_created( $value ) { |
|
2130 | 2130 | $date = strtotime( $value ); |
2131 | 2131 | |
2132 | 2132 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2134,19 +2134,19 @@ discard block |
||
2134 | 2134 | return true; |
2135 | 2135 | } |
2136 | 2136 | |
2137 | - $this->set_prop( 'date_created', '' ); |
|
2138 | - return false; |
|
2137 | + $this->set_prop( 'date_created', '' ); |
|
2138 | + return false; |
|
2139 | 2139 | |
2140 | 2140 | } |
2141 | 2141 | |
2142 | 2142 | /** |
2143 | - * Set date invoice due date. |
|
2144 | - * |
|
2145 | - * @since 1.0.19 |
|
2146 | - * @param string $value Value to set. |
|
2143 | + * Set date invoice due date. |
|
2144 | + * |
|
2145 | + * @since 1.0.19 |
|
2146 | + * @param string $value Value to set. |
|
2147 | 2147 | * @return bool Whether or not the date was set. |
2148 | - */ |
|
2149 | - public function set_due_date( $value ) { |
|
2148 | + */ |
|
2149 | + public function set_due_date( $value ) { |
|
2150 | 2150 | $date = strtotime( $value ); |
2151 | 2151 | |
2152 | 2152 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2154,29 +2154,29 @@ discard block |
||
2154 | 2154 | return true; |
2155 | 2155 | } |
2156 | 2156 | |
2157 | - $this->set_prop( 'due_date', '' ); |
|
2157 | + $this->set_prop( 'due_date', '' ); |
|
2158 | 2158 | return false; |
2159 | 2159 | |
2160 | 2160 | } |
2161 | 2161 | |
2162 | 2162 | /** |
2163 | - * Alias of self::set_due_date(). |
|
2164 | - * |
|
2165 | - * @since 1.0.19 |
|
2166 | - * @param string $value New name. |
|
2167 | - */ |
|
2168 | - public function set_date_due( $value ) { |
|
2169 | - $this->set_due_date( $value ); |
|
2163 | + * Alias of self::set_due_date(). |
|
2164 | + * |
|
2165 | + * @since 1.0.19 |
|
2166 | + * @param string $value New name. |
|
2167 | + */ |
|
2168 | + public function set_date_due( $value ) { |
|
2169 | + $this->set_due_date( $value ); |
|
2170 | 2170 | } |
2171 | 2171 | |
2172 | 2172 | /** |
2173 | - * Set date invoice was completed. |
|
2174 | - * |
|
2175 | - * @since 1.0.19 |
|
2176 | - * @param string $value Value to set. |
|
2173 | + * Set date invoice was completed. |
|
2174 | + * |
|
2175 | + * @since 1.0.19 |
|
2176 | + * @param string $value Value to set. |
|
2177 | 2177 | * @return bool Whether or not the date was set. |
2178 | - */ |
|
2179 | - public function set_completed_date( $value ) { |
|
2178 | + */ |
|
2179 | + public function set_completed_date( $value ) { |
|
2180 | 2180 | $date = strtotime( $value ); |
2181 | 2181 | |
2182 | 2182 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2184,29 +2184,29 @@ discard block |
||
2184 | 2184 | return true; |
2185 | 2185 | } |
2186 | 2186 | |
2187 | - $this->set_prop( 'completed_date', '' ); |
|
2187 | + $this->set_prop( 'completed_date', '' ); |
|
2188 | 2188 | return false; |
2189 | 2189 | |
2190 | 2190 | } |
2191 | 2191 | |
2192 | 2192 | /** |
2193 | - * Alias of self::set_completed_date(). |
|
2194 | - * |
|
2195 | - * @since 1.0.19 |
|
2196 | - * @param string $value New name. |
|
2197 | - */ |
|
2198 | - public function set_date_completed( $value ) { |
|
2199 | - $this->set_completed_date( $value ); |
|
2193 | + * Alias of self::set_completed_date(). |
|
2194 | + * |
|
2195 | + * @since 1.0.19 |
|
2196 | + * @param string $value New name. |
|
2197 | + */ |
|
2198 | + public function set_date_completed( $value ) { |
|
2199 | + $this->set_completed_date( $value ); |
|
2200 | 2200 | } |
2201 | 2201 | |
2202 | 2202 | /** |
2203 | - * Set date when the invoice was last modified. |
|
2204 | - * |
|
2205 | - * @since 1.0.19 |
|
2206 | - * @param string $value Value to set. |
|
2203 | + * Set date when the invoice was last modified. |
|
2204 | + * |
|
2205 | + * @since 1.0.19 |
|
2206 | + * @param string $value Value to set. |
|
2207 | 2207 | * @return bool Whether or not the date was set. |
2208 | - */ |
|
2209 | - public function set_date_modified( $value ) { |
|
2208 | + */ |
|
2209 | + public function set_date_modified( $value ) { |
|
2210 | 2210 | $date = strtotime( $value ); |
2211 | 2211 | |
2212 | 2212 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2214,813 +2214,813 @@ discard block |
||
2214 | 2214 | return true; |
2215 | 2215 | } |
2216 | 2216 | |
2217 | - $this->set_prop( 'date_modified', '' ); |
|
2217 | + $this->set_prop( 'date_modified', '' ); |
|
2218 | 2218 | return false; |
2219 | 2219 | |
2220 | 2220 | } |
2221 | 2221 | |
2222 | 2222 | /** |
2223 | - * Set the invoice number. |
|
2224 | - * |
|
2225 | - * @since 1.0.19 |
|
2226 | - * @param string $value New number. |
|
2227 | - */ |
|
2228 | - public function set_number( $value ) { |
|
2223 | + * Set the invoice number. |
|
2224 | + * |
|
2225 | + * @since 1.0.19 |
|
2226 | + * @param string $value New number. |
|
2227 | + */ |
|
2228 | + public function set_number( $value ) { |
|
2229 | 2229 | $number = sanitize_text_field( $value ); |
2230 | - $this->set_prop( 'number', $number ); |
|
2230 | + $this->set_prop( 'number', $number ); |
|
2231 | 2231 | } |
2232 | 2232 | |
2233 | 2233 | /** |
2234 | - * Set the invoice type. |
|
2235 | - * |
|
2236 | - * @since 1.0.19 |
|
2237 | - * @param string $value Type. |
|
2238 | - */ |
|
2239 | - public function set_type( $value ) { |
|
2234 | + * Set the invoice type. |
|
2235 | + * |
|
2236 | + * @since 1.0.19 |
|
2237 | + * @param string $value Type. |
|
2238 | + */ |
|
2239 | + public function set_type( $value ) { |
|
2240 | 2240 | $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) ); |
2241 | - $this->set_prop( 'type', $type ); |
|
2242 | - } |
|
2241 | + $this->set_prop( 'type', $type ); |
|
2242 | + } |
|
2243 | 2243 | |
2244 | 2244 | /** |
2245 | - * Set the invoice post type. |
|
2246 | - * |
|
2247 | - * @since 1.0.19 |
|
2248 | - * @param string $value Post type. |
|
2249 | - */ |
|
2250 | - public function set_post_type( $value ) { |
|
2245 | + * Set the invoice post type. |
|
2246 | + * |
|
2247 | + * @since 1.0.19 |
|
2248 | + * @param string $value Post type. |
|
2249 | + */ |
|
2250 | + public function set_post_type( $value ) { |
|
2251 | 2251 | if ( getpaid_is_invoice_post_type( $value ) ) { |
2252 | - $this->set_type( $value ); |
|
2252 | + $this->set_type( $value ); |
|
2253 | 2253 | $this->set_prop( 'post_type', $value ); |
2254 | 2254 | } |
2255 | 2255 | } |
2256 | 2256 | |
2257 | 2257 | /** |
2258 | - * Set the invoice key. |
|
2259 | - * |
|
2260 | - * @since 1.0.19 |
|
2261 | - * @param string $value New key. |
|
2262 | - */ |
|
2263 | - public function set_key( $value ) { |
|
2258 | + * Set the invoice key. |
|
2259 | + * |
|
2260 | + * @since 1.0.19 |
|
2261 | + * @param string $value New key. |
|
2262 | + */ |
|
2263 | + public function set_key( $value ) { |
|
2264 | 2264 | $key = sanitize_text_field( $value ); |
2265 | - $this->set_prop( 'key', $key ); |
|
2265 | + $this->set_prop( 'key', $key ); |
|
2266 | 2266 | } |
2267 | 2267 | |
2268 | 2268 | /** |
2269 | - * Set the invoice mode. |
|
2270 | - * |
|
2271 | - * @since 1.0.19 |
|
2272 | - * @param string $value mode. |
|
2273 | - */ |
|
2274 | - public function set_mode( $value ) { |
|
2269 | + * Set the invoice mode. |
|
2270 | + * |
|
2271 | + * @since 1.0.19 |
|
2272 | + * @param string $value mode. |
|
2273 | + */ |
|
2274 | + public function set_mode( $value ) { |
|
2275 | 2275 | if ( in_array( $value, array( 'live', 'test' ) ) ) { |
2276 | 2276 | $this->set_prop( 'mode', $value ); |
2277 | 2277 | } |
2278 | 2278 | } |
2279 | 2279 | |
2280 | 2280 | /** |
2281 | - * Set the invoice path. |
|
2282 | - * |
|
2283 | - * @since 1.0.19 |
|
2284 | - * @param string $value path. |
|
2285 | - */ |
|
2286 | - public function set_path( $value ) { |
|
2281 | + * Set the invoice path. |
|
2282 | + * |
|
2283 | + * @since 1.0.19 |
|
2284 | + * @param string $value path. |
|
2285 | + */ |
|
2286 | + public function set_path( $value ) { |
|
2287 | 2287 | $this->set_prop( 'path', $value ); |
2288 | 2288 | } |
2289 | 2289 | |
2290 | 2290 | /** |
2291 | - * Set the invoice name. |
|
2292 | - * |
|
2293 | - * @since 1.0.19 |
|
2294 | - * @param string $value New name. |
|
2295 | - */ |
|
2296 | - public function set_name( $value ) { |
|
2291 | + * Set the invoice name. |
|
2292 | + * |
|
2293 | + * @since 1.0.19 |
|
2294 | + * @param string $value New name. |
|
2295 | + */ |
|
2296 | + public function set_name( $value ) { |
|
2297 | 2297 | $name = sanitize_text_field( $value ); |
2298 | - $this->set_prop( 'name', $name ); |
|
2298 | + $this->set_prop( 'name', $name ); |
|
2299 | 2299 | } |
2300 | 2300 | |
2301 | 2301 | /** |
2302 | - * Alias of self::set_name(). |
|
2303 | - * |
|
2304 | - * @since 1.0.19 |
|
2305 | - * @param string $value New name. |
|
2306 | - */ |
|
2307 | - public function set_title( $value ) { |
|
2308 | - $this->set_name( $value ); |
|
2302 | + * Alias of self::set_name(). |
|
2303 | + * |
|
2304 | + * @since 1.0.19 |
|
2305 | + * @param string $value New name. |
|
2306 | + */ |
|
2307 | + public function set_title( $value ) { |
|
2308 | + $this->set_name( $value ); |
|
2309 | 2309 | } |
2310 | 2310 | |
2311 | 2311 | /** |
2312 | - * Set the invoice description. |
|
2313 | - * |
|
2314 | - * @since 1.0.19 |
|
2315 | - * @param string $value New description. |
|
2316 | - */ |
|
2317 | - public function set_description( $value ) { |
|
2312 | + * Set the invoice description. |
|
2313 | + * |
|
2314 | + * @since 1.0.19 |
|
2315 | + * @param string $value New description. |
|
2316 | + */ |
|
2317 | + public function set_description( $value ) { |
|
2318 | 2318 | $description = wp_kses_post( $value ); |
2319 | - $this->set_prop( 'description', $description ); |
|
2319 | + $this->set_prop( 'description', $description ); |
|
2320 | + } |
|
2321 | + |
|
2322 | + /** |
|
2323 | + * Alias of self::set_description(). |
|
2324 | + * |
|
2325 | + * @since 1.0.19 |
|
2326 | + * @param string $value New description. |
|
2327 | + */ |
|
2328 | + public function set_excerpt( $value ) { |
|
2329 | + $this->set_description( $value ); |
|
2330 | + } |
|
2331 | + |
|
2332 | + /** |
|
2333 | + * Alias of self::set_description(). |
|
2334 | + * |
|
2335 | + * @since 1.0.19 |
|
2336 | + * @param string $value New description. |
|
2337 | + */ |
|
2338 | + public function set_summary( $value ) { |
|
2339 | + $this->set_description( $value ); |
|
2340 | + } |
|
2341 | + |
|
2342 | + /** |
|
2343 | + * Set the receiver of the invoice. |
|
2344 | + * |
|
2345 | + * @since 1.0.19 |
|
2346 | + * @param int $value New author. |
|
2347 | + */ |
|
2348 | + public function set_author( $value ) { |
|
2349 | + $user = get_user_by( 'id', (int) $value ); |
|
2350 | + |
|
2351 | + if ( $user && $user->ID ) { |
|
2352 | + $this->set_prop( 'author', $user->ID ); |
|
2353 | + $this->set_prop( 'email', $user->user_email ); |
|
2354 | + } |
|
2355 | + |
|
2356 | + } |
|
2357 | + |
|
2358 | + /** |
|
2359 | + * Alias of self::set_author(). |
|
2360 | + * |
|
2361 | + * @since 1.0.19 |
|
2362 | + * @param int $value New user id. |
|
2363 | + */ |
|
2364 | + public function set_user_id( $value ) { |
|
2365 | + $this->set_author( $value ); |
|
2366 | + } |
|
2367 | + |
|
2368 | + /** |
|
2369 | + * Alias of self::set_author(). |
|
2370 | + * |
|
2371 | + * @since 1.0.19 |
|
2372 | + * @param int $value New user id. |
|
2373 | + */ |
|
2374 | + public function set_customer_id( $value ) { |
|
2375 | + $this->set_author( $value ); |
|
2376 | + } |
|
2377 | + |
|
2378 | + /** |
|
2379 | + * Set the customer's ip. |
|
2380 | + * |
|
2381 | + * @since 1.0.19 |
|
2382 | + * @param string $value ip address. |
|
2383 | + */ |
|
2384 | + public function set_ip( $value ) { |
|
2385 | + $this->set_prop( 'ip', $value ); |
|
2386 | + } |
|
2387 | + |
|
2388 | + /** |
|
2389 | + * Alias of self::set_ip(). |
|
2390 | + * |
|
2391 | + * @since 1.0.19 |
|
2392 | + * @param string $value ip address. |
|
2393 | + */ |
|
2394 | + public function set_user_ip( $value ) { |
|
2395 | + $this->set_ip( $value ); |
|
2396 | + } |
|
2397 | + |
|
2398 | + /** |
|
2399 | + * Set the customer's first name. |
|
2400 | + * |
|
2401 | + * @since 1.0.19 |
|
2402 | + * @param string $value first name. |
|
2403 | + */ |
|
2404 | + public function set_first_name( $value ) { |
|
2405 | + $this->set_prop( 'first_name', $value ); |
|
2406 | + } |
|
2407 | + |
|
2408 | + /** |
|
2409 | + * Alias of self::set_first_name(). |
|
2410 | + * |
|
2411 | + * @since 1.0.19 |
|
2412 | + * @param string $value first name. |
|
2413 | + */ |
|
2414 | + public function set_user_first_name( $value ) { |
|
2415 | + $this->set_first_name( $value ); |
|
2416 | + } |
|
2417 | + |
|
2418 | + /** |
|
2419 | + * Alias of self::set_first_name(). |
|
2420 | + * |
|
2421 | + * @since 1.0.19 |
|
2422 | + * @param string $value first name. |
|
2423 | + */ |
|
2424 | + public function set_customer_first_name( $value ) { |
|
2425 | + $this->set_first_name( $value ); |
|
2426 | + } |
|
2427 | + |
|
2428 | + /** |
|
2429 | + * Set the customer's last name. |
|
2430 | + * |
|
2431 | + * @since 1.0.19 |
|
2432 | + * @param string $value last name. |
|
2433 | + */ |
|
2434 | + public function set_last_name( $value ) { |
|
2435 | + $this->set_prop( 'last_name', $value ); |
|
2436 | + } |
|
2437 | + |
|
2438 | + /** |
|
2439 | + * Alias of self::set_last_name(). |
|
2440 | + * |
|
2441 | + * @since 1.0.19 |
|
2442 | + * @param string $value last name. |
|
2443 | + */ |
|
2444 | + public function set_user_last_name( $value ) { |
|
2445 | + $this->set_last_name( $value ); |
|
2446 | + } |
|
2447 | + |
|
2448 | + /** |
|
2449 | + * Alias of self::set_last_name(). |
|
2450 | + * |
|
2451 | + * @since 1.0.19 |
|
2452 | + * @param string $value last name. |
|
2453 | + */ |
|
2454 | + public function set_customer_last_name( $value ) { |
|
2455 | + $this->set_last_name( $value ); |
|
2456 | + } |
|
2457 | + |
|
2458 | + /** |
|
2459 | + * Set the customer's phone number. |
|
2460 | + * |
|
2461 | + * @since 1.0.19 |
|
2462 | + * @param string $value phone. |
|
2463 | + */ |
|
2464 | + public function set_phone( $value ) { |
|
2465 | + $this->set_prop( 'phone', $value ); |
|
2320 | 2466 | } |
2321 | 2467 | |
2322 | 2468 | /** |
2323 | - * Alias of self::set_description(). |
|
2324 | - * |
|
2325 | - * @since 1.0.19 |
|
2326 | - * @param string $value New description. |
|
2327 | - */ |
|
2328 | - public function set_excerpt( $value ) { |
|
2329 | - $this->set_description( $value ); |
|
2469 | + * Alias of self::set_phone(). |
|
2470 | + * |
|
2471 | + * @since 1.0.19 |
|
2472 | + * @param string $value phone. |
|
2473 | + */ |
|
2474 | + public function set_user_phone( $value ) { |
|
2475 | + $this->set_phone( $value ); |
|
2330 | 2476 | } |
2331 | 2477 | |
2332 | 2478 | /** |
2333 | - * Alias of self::set_description(). |
|
2334 | - * |
|
2335 | - * @since 1.0.19 |
|
2336 | - * @param string $value New description. |
|
2337 | - */ |
|
2338 | - public function set_summary( $value ) { |
|
2339 | - $this->set_description( $value ); |
|
2479 | + * Alias of self::set_phone(). |
|
2480 | + * |
|
2481 | + * @since 1.0.19 |
|
2482 | + * @param string $value phone. |
|
2483 | + */ |
|
2484 | + public function set_customer_phone( $value ) { |
|
2485 | + $this->set_phone( $value ); |
|
2340 | 2486 | } |
2341 | 2487 | |
2342 | 2488 | /** |
2343 | - * Set the receiver of the invoice. |
|
2344 | - * |
|
2345 | - * @since 1.0.19 |
|
2346 | - * @param int $value New author. |
|
2347 | - */ |
|
2348 | - public function set_author( $value ) { |
|
2349 | - $user = get_user_by( 'id', (int) $value ); |
|
2489 | + * Alias of self::set_phone(). |
|
2490 | + * |
|
2491 | + * @since 1.0.19 |
|
2492 | + * @param string $value phone. |
|
2493 | + */ |
|
2494 | + public function set_phone_number( $value ) { |
|
2495 | + $this->set_phone( $value ); |
|
2496 | + } |
|
2350 | 2497 | |
2351 | - if ( $user && $user->ID ) { |
|
2352 | - $this->set_prop( 'author', $user->ID ); |
|
2353 | - $this->set_prop( 'email', $user->user_email ); |
|
2354 | - } |
|
2498 | + /** |
|
2499 | + * Set the customer's email address. |
|
2500 | + * |
|
2501 | + * @since 1.0.19 |
|
2502 | + * @param string $value email address. |
|
2503 | + */ |
|
2504 | + public function set_email( $value ) { |
|
2505 | + $this->set_prop( 'email', $value ); |
|
2506 | + } |
|
2355 | 2507 | |
2508 | + /** |
|
2509 | + * Alias of self::set_email(). |
|
2510 | + * |
|
2511 | + * @since 1.0.19 |
|
2512 | + * @param string $value email address. |
|
2513 | + */ |
|
2514 | + public function set_user_email( $value ) { |
|
2515 | + $this->set_email( $value ); |
|
2356 | 2516 | } |
2357 | 2517 | |
2358 | 2518 | /** |
2359 | - * Alias of self::set_author(). |
|
2360 | - * |
|
2361 | - * @since 1.0.19 |
|
2362 | - * @param int $value New user id. |
|
2363 | - */ |
|
2364 | - public function set_user_id( $value ) { |
|
2365 | - $this->set_author( $value ); |
|
2519 | + * Alias of self::set_email(). |
|
2520 | + * |
|
2521 | + * @since 1.0.19 |
|
2522 | + * @param string $value email address. |
|
2523 | + */ |
|
2524 | + public function set_email_address( $value ) { |
|
2525 | + $this->set_email( $value ); |
|
2366 | 2526 | } |
2367 | 2527 | |
2368 | 2528 | /** |
2369 | - * Alias of self::set_author(). |
|
2370 | - * |
|
2371 | - * @since 1.0.19 |
|
2372 | - * @param int $value New user id. |
|
2373 | - */ |
|
2374 | - public function set_customer_id( $value ) { |
|
2375 | - $this->set_author( $value ); |
|
2529 | + * Alias of self::set_email(). |
|
2530 | + * |
|
2531 | + * @since 1.0.19 |
|
2532 | + * @param string $value email address. |
|
2533 | + */ |
|
2534 | + public function set_customer_email( $value ) { |
|
2535 | + $this->set_email( $value ); |
|
2376 | 2536 | } |
2377 | 2537 | |
2378 | 2538 | /** |
2379 | - * Set the customer's ip. |
|
2380 | - * |
|
2381 | - * @since 1.0.19 |
|
2382 | - * @param string $value ip address. |
|
2383 | - */ |
|
2384 | - public function set_ip( $value ) { |
|
2385 | - $this->set_prop( 'ip', $value ); |
|
2539 | + * Set the customer's country. |
|
2540 | + * |
|
2541 | + * @since 1.0.19 |
|
2542 | + * @param string $value country. |
|
2543 | + */ |
|
2544 | + public function set_country( $value ) { |
|
2545 | + $this->set_prop( 'country', $value ); |
|
2386 | 2546 | } |
2387 | 2547 | |
2388 | 2548 | /** |
2389 | - * Alias of self::set_ip(). |
|
2390 | - * |
|
2391 | - * @since 1.0.19 |
|
2392 | - * @param string $value ip address. |
|
2393 | - */ |
|
2394 | - public function set_user_ip( $value ) { |
|
2395 | - $this->set_ip( $value ); |
|
2549 | + * Alias of self::set_country(). |
|
2550 | + * |
|
2551 | + * @since 1.0.19 |
|
2552 | + * @param string $value country. |
|
2553 | + */ |
|
2554 | + public function set_user_country( $value ) { |
|
2555 | + $this->set_country( $value ); |
|
2396 | 2556 | } |
2397 | 2557 | |
2398 | 2558 | /** |
2399 | - * Set the customer's first name. |
|
2400 | - * |
|
2401 | - * @since 1.0.19 |
|
2402 | - * @param string $value first name. |
|
2403 | - */ |
|
2404 | - public function set_first_name( $value ) { |
|
2405 | - $this->set_prop( 'first_name', $value ); |
|
2559 | + * Alias of self::set_country(). |
|
2560 | + * |
|
2561 | + * @since 1.0.19 |
|
2562 | + * @param string $value country. |
|
2563 | + */ |
|
2564 | + public function set_customer_country( $value ) { |
|
2565 | + $this->set_country( $value ); |
|
2406 | 2566 | } |
2407 | 2567 | |
2408 | 2568 | /** |
2409 | - * Alias of self::set_first_name(). |
|
2410 | - * |
|
2411 | - * @since 1.0.19 |
|
2412 | - * @param string $value first name. |
|
2413 | - */ |
|
2414 | - public function set_user_first_name( $value ) { |
|
2415 | - $this->set_first_name( $value ); |
|
2569 | + * Set the customer's state. |
|
2570 | + * |
|
2571 | + * @since 1.0.19 |
|
2572 | + * @param string $value state. |
|
2573 | + */ |
|
2574 | + public function set_state( $value ) { |
|
2575 | + $this->set_prop( 'state', $value ); |
|
2416 | 2576 | } |
2417 | 2577 | |
2418 | 2578 | /** |
2419 | - * Alias of self::set_first_name(). |
|
2420 | - * |
|
2421 | - * @since 1.0.19 |
|
2422 | - * @param string $value first name. |
|
2423 | - */ |
|
2424 | - public function set_customer_first_name( $value ) { |
|
2425 | - $this->set_first_name( $value ); |
|
2579 | + * Alias of self::set_state(). |
|
2580 | + * |
|
2581 | + * @since 1.0.19 |
|
2582 | + * @param string $value state. |
|
2583 | + */ |
|
2584 | + public function set_user_state( $value ) { |
|
2585 | + $this->set_state( $value ); |
|
2426 | 2586 | } |
2427 | 2587 | |
2428 | 2588 | /** |
2429 | - * Set the customer's last name. |
|
2430 | - * |
|
2431 | - * @since 1.0.19 |
|
2432 | - * @param string $value last name. |
|
2433 | - */ |
|
2434 | - public function set_last_name( $value ) { |
|
2435 | - $this->set_prop( 'last_name', $value ); |
|
2589 | + * Alias of self::set_state(). |
|
2590 | + * |
|
2591 | + * @since 1.0.19 |
|
2592 | + * @param string $value state. |
|
2593 | + */ |
|
2594 | + public function set_customer_state( $value ) { |
|
2595 | + $this->set_state( $value ); |
|
2436 | 2596 | } |
2437 | 2597 | |
2438 | 2598 | /** |
2439 | - * Alias of self::set_last_name(). |
|
2440 | - * |
|
2441 | - * @since 1.0.19 |
|
2442 | - * @param string $value last name. |
|
2443 | - */ |
|
2444 | - public function set_user_last_name( $value ) { |
|
2445 | - $this->set_last_name( $value ); |
|
2599 | + * Set the customer's city. |
|
2600 | + * |
|
2601 | + * @since 1.0.19 |
|
2602 | + * @param string $value city. |
|
2603 | + */ |
|
2604 | + public function set_city( $value ) { |
|
2605 | + $this->set_prop( 'city', $value ); |
|
2446 | 2606 | } |
2447 | 2607 | |
2448 | 2608 | /** |
2449 | - * Alias of self::set_last_name(). |
|
2450 | - * |
|
2451 | - * @since 1.0.19 |
|
2452 | - * @param string $value last name. |
|
2453 | - */ |
|
2454 | - public function set_customer_last_name( $value ) { |
|
2455 | - $this->set_last_name( $value ); |
|
2609 | + * Alias of self::set_city(). |
|
2610 | + * |
|
2611 | + * @since 1.0.19 |
|
2612 | + * @param string $value city. |
|
2613 | + */ |
|
2614 | + public function set_user_city( $value ) { |
|
2615 | + $this->set_city( $value ); |
|
2456 | 2616 | } |
2457 | 2617 | |
2458 | 2618 | /** |
2459 | - * Set the customer's phone number. |
|
2460 | - * |
|
2461 | - * @since 1.0.19 |
|
2462 | - * @param string $value phone. |
|
2463 | - */ |
|
2464 | - public function set_phone( $value ) { |
|
2465 | - $this->set_prop( 'phone', $value ); |
|
2619 | + * Alias of self::set_city(). |
|
2620 | + * |
|
2621 | + * @since 1.0.19 |
|
2622 | + * @param string $value city. |
|
2623 | + */ |
|
2624 | + public function set_customer_city( $value ) { |
|
2625 | + $this->set_city( $value ); |
|
2466 | 2626 | } |
2467 | 2627 | |
2468 | 2628 | /** |
2469 | - * Alias of self::set_phone(). |
|
2470 | - * |
|
2471 | - * @since 1.0.19 |
|
2472 | - * @param string $value phone. |
|
2473 | - */ |
|
2474 | - public function set_user_phone( $value ) { |
|
2475 | - $this->set_phone( $value ); |
|
2629 | + * Set the customer's zip code. |
|
2630 | + * |
|
2631 | + * @since 1.0.19 |
|
2632 | + * @param string $value zip. |
|
2633 | + */ |
|
2634 | + public function set_zip( $value ) { |
|
2635 | + $this->set_prop( 'zip', $value ); |
|
2476 | 2636 | } |
2477 | 2637 | |
2478 | 2638 | /** |
2479 | - * Alias of self::set_phone(). |
|
2480 | - * |
|
2481 | - * @since 1.0.19 |
|
2482 | - * @param string $value phone. |
|
2483 | - */ |
|
2484 | - public function set_customer_phone( $value ) { |
|
2485 | - $this->set_phone( $value ); |
|
2639 | + * Alias of self::set_zip(). |
|
2640 | + * |
|
2641 | + * @since 1.0.19 |
|
2642 | + * @param string $value zip. |
|
2643 | + */ |
|
2644 | + public function set_user_zip( $value ) { |
|
2645 | + $this->set_zip( $value ); |
|
2486 | 2646 | } |
2487 | 2647 | |
2488 | 2648 | /** |
2489 | - * Alias of self::set_phone(). |
|
2490 | - * |
|
2491 | - * @since 1.0.19 |
|
2492 | - * @param string $value phone. |
|
2493 | - */ |
|
2494 | - public function set_phone_number( $value ) { |
|
2495 | - $this->set_phone( $value ); |
|
2649 | + * Alias of self::set_zip(). |
|
2650 | + * |
|
2651 | + * @since 1.0.19 |
|
2652 | + * @param string $value zip. |
|
2653 | + */ |
|
2654 | + public function set_customer_zip( $value ) { |
|
2655 | + $this->set_zip( $value ); |
|
2496 | 2656 | } |
2497 | 2657 | |
2498 | 2658 | /** |
2499 | - * Set the customer's email address. |
|
2500 | - * |
|
2501 | - * @since 1.0.19 |
|
2502 | - * @param string $value email address. |
|
2503 | - */ |
|
2504 | - public function set_email( $value ) { |
|
2505 | - $this->set_prop( 'email', $value ); |
|
2659 | + * Set the customer's company. |
|
2660 | + * |
|
2661 | + * @since 1.0.19 |
|
2662 | + * @param string $value company. |
|
2663 | + */ |
|
2664 | + public function set_company( $value ) { |
|
2665 | + $this->set_prop( 'company', $value ); |
|
2506 | 2666 | } |
2507 | 2667 | |
2508 | 2668 | /** |
2509 | - * Alias of self::set_email(). |
|
2510 | - * |
|
2511 | - * @since 1.0.19 |
|
2512 | - * @param string $value email address. |
|
2513 | - */ |
|
2514 | - public function set_user_email( $value ) { |
|
2515 | - $this->set_email( $value ); |
|
2669 | + * Alias of self::set_company(). |
|
2670 | + * |
|
2671 | + * @since 1.0.19 |
|
2672 | + * @param string $value company. |
|
2673 | + */ |
|
2674 | + public function set_user_company( $value ) { |
|
2675 | + $this->set_company( $value ); |
|
2516 | 2676 | } |
2517 | 2677 | |
2518 | 2678 | /** |
2519 | - * Alias of self::set_email(). |
|
2520 | - * |
|
2521 | - * @since 1.0.19 |
|
2522 | - * @param string $value email address. |
|
2523 | - */ |
|
2524 | - public function set_email_address( $value ) { |
|
2525 | - $this->set_email( $value ); |
|
2679 | + * Alias of self::set_company(). |
|
2680 | + * |
|
2681 | + * @since 1.0.19 |
|
2682 | + * @param string $value company. |
|
2683 | + */ |
|
2684 | + public function set_customer_company( $value ) { |
|
2685 | + $this->set_company( $value ); |
|
2526 | 2686 | } |
2527 | 2687 | |
2528 | 2688 | /** |
2529 | - * Alias of self::set_email(). |
|
2530 | - * |
|
2531 | - * @since 1.0.19 |
|
2532 | - * @param string $value email address. |
|
2533 | - */ |
|
2534 | - public function set_customer_email( $value ) { |
|
2535 | - $this->set_email( $value ); |
|
2689 | + * Set the customer's company id. |
|
2690 | + * |
|
2691 | + * @since 1.0.19 |
|
2692 | + * @param string $value company id. |
|
2693 | + */ |
|
2694 | + public function set_company_id( $value ) { |
|
2695 | + $this->set_prop( 'company_id', $value ); |
|
2536 | 2696 | } |
2537 | 2697 | |
2538 | 2698 | /** |
2539 | - * Set the customer's country. |
|
2540 | - * |
|
2541 | - * @since 1.0.19 |
|
2542 | - * @param string $value country. |
|
2543 | - */ |
|
2544 | - public function set_country( $value ) { |
|
2545 | - $this->set_prop( 'country', $value ); |
|
2699 | + * Set the customer's var number. |
|
2700 | + * |
|
2701 | + * @since 1.0.19 |
|
2702 | + * @param string $value var number. |
|
2703 | + */ |
|
2704 | + public function set_vat_number( $value ) { |
|
2705 | + $this->set_prop( 'vat_number', $value ); |
|
2546 | 2706 | } |
2547 | 2707 | |
2548 | 2708 | /** |
2549 | - * Alias of self::set_country(). |
|
2550 | - * |
|
2551 | - * @since 1.0.19 |
|
2552 | - * @param string $value country. |
|
2553 | - */ |
|
2554 | - public function set_user_country( $value ) { |
|
2555 | - $this->set_country( $value ); |
|
2709 | + * Alias of self::set_vat_number(). |
|
2710 | + * |
|
2711 | + * @since 1.0.19 |
|
2712 | + * @param string $value var number. |
|
2713 | + */ |
|
2714 | + public function set_user_vat_number( $value ) { |
|
2715 | + $this->set_vat_number( $value ); |
|
2556 | 2716 | } |
2557 | 2717 | |
2558 | 2718 | /** |
2559 | - * Alias of self::set_country(). |
|
2560 | - * |
|
2561 | - * @since 1.0.19 |
|
2562 | - * @param string $value country. |
|
2563 | - */ |
|
2564 | - public function set_customer_country( $value ) { |
|
2565 | - $this->set_country( $value ); |
|
2719 | + * Alias of self::set_vat_number(). |
|
2720 | + * |
|
2721 | + * @since 1.0.19 |
|
2722 | + * @param string $value var number. |
|
2723 | + */ |
|
2724 | + public function set_customer_vat_number( $value ) { |
|
2725 | + $this->set_vat_number( $value ); |
|
2566 | 2726 | } |
2567 | 2727 | |
2568 | 2728 | /** |
2569 | - * Set the customer's state. |
|
2570 | - * |
|
2571 | - * @since 1.0.19 |
|
2572 | - * @param string $value state. |
|
2573 | - */ |
|
2574 | - public function set_state( $value ) { |
|
2575 | - $this->set_prop( 'state', $value ); |
|
2729 | + * Set the customer's vat rate. |
|
2730 | + * |
|
2731 | + * @since 1.0.19 |
|
2732 | + * @param string $value var rate. |
|
2733 | + */ |
|
2734 | + public function set_vat_rate( $value ) { |
|
2735 | + $this->set_prop( 'vat_rate', $value ); |
|
2576 | 2736 | } |
2577 | 2737 | |
2578 | 2738 | /** |
2579 | - * Alias of self::set_state(). |
|
2580 | - * |
|
2581 | - * @since 1.0.19 |
|
2582 | - * @param string $value state. |
|
2583 | - */ |
|
2584 | - public function set_user_state( $value ) { |
|
2585 | - $this->set_state( $value ); |
|
2739 | + * Alias of self::set_vat_rate(). |
|
2740 | + * |
|
2741 | + * @since 1.0.19 |
|
2742 | + * @param string $value var number. |
|
2743 | + */ |
|
2744 | + public function set_user_vat_rate( $value ) { |
|
2745 | + $this->set_vat_rate( $value ); |
|
2586 | 2746 | } |
2587 | 2747 | |
2588 | 2748 | /** |
2589 | - * Alias of self::set_state(). |
|
2590 | - * |
|
2591 | - * @since 1.0.19 |
|
2592 | - * @param string $value state. |
|
2593 | - */ |
|
2594 | - public function set_customer_state( $value ) { |
|
2595 | - $this->set_state( $value ); |
|
2749 | + * Alias of self::set_vat_rate(). |
|
2750 | + * |
|
2751 | + * @since 1.0.19 |
|
2752 | + * @param string $value var number. |
|
2753 | + */ |
|
2754 | + public function set_customer_vat_rate( $value ) { |
|
2755 | + $this->set_vat_rate( $value ); |
|
2596 | 2756 | } |
2597 | 2757 | |
2598 | 2758 | /** |
2599 | - * Set the customer's city. |
|
2600 | - * |
|
2601 | - * @since 1.0.19 |
|
2602 | - * @param string $value city. |
|
2603 | - */ |
|
2604 | - public function set_city( $value ) { |
|
2605 | - $this->set_prop( 'city', $value ); |
|
2759 | + * Set the customer's address. |
|
2760 | + * |
|
2761 | + * @since 1.0.19 |
|
2762 | + * @param string $value address. |
|
2763 | + */ |
|
2764 | + public function set_address( $value ) { |
|
2765 | + $this->set_prop( 'address', $value ); |
|
2606 | 2766 | } |
2607 | 2767 | |
2608 | 2768 | /** |
2609 | - * Alias of self::set_city(). |
|
2610 | - * |
|
2611 | - * @since 1.0.19 |
|
2612 | - * @param string $value city. |
|
2613 | - */ |
|
2614 | - public function set_user_city( $value ) { |
|
2615 | - $this->set_city( $value ); |
|
2769 | + * Alias of self::set_address(). |
|
2770 | + * |
|
2771 | + * @since 1.0.19 |
|
2772 | + * @param string $value address. |
|
2773 | + */ |
|
2774 | + public function set_user_address( $value ) { |
|
2775 | + $this->set_address( $value ); |
|
2616 | 2776 | } |
2617 | 2777 | |
2618 | 2778 | /** |
2619 | - * Alias of self::set_city(). |
|
2620 | - * |
|
2621 | - * @since 1.0.19 |
|
2622 | - * @param string $value city. |
|
2623 | - */ |
|
2624 | - public function set_customer_city( $value ) { |
|
2625 | - $this->set_city( $value ); |
|
2779 | + * Alias of self::set_address(). |
|
2780 | + * |
|
2781 | + * @since 1.0.19 |
|
2782 | + * @param string $value address. |
|
2783 | + */ |
|
2784 | + public function set_customer_address( $value ) { |
|
2785 | + $this->set_address( $value ); |
|
2626 | 2786 | } |
2627 | 2787 | |
2628 | 2788 | /** |
2629 | - * Set the customer's zip code. |
|
2630 | - * |
|
2631 | - * @since 1.0.19 |
|
2632 | - * @param string $value zip. |
|
2633 | - */ |
|
2634 | - public function set_zip( $value ) { |
|
2635 | - $this->set_prop( 'zip', $value ); |
|
2789 | + * Set whether the customer has viewed the invoice or not. |
|
2790 | + * |
|
2791 | + * @since 1.0.19 |
|
2792 | + * @param int|bool $value confirmed. |
|
2793 | + */ |
|
2794 | + public function set_is_viewed( $value ) { |
|
2795 | + $this->set_prop( 'is_viewed', $value ); |
|
2636 | 2796 | } |
2637 | 2797 | |
2638 | 2798 | /** |
2639 | - * Alias of self::set_zip(). |
|
2640 | - * |
|
2641 | - * @since 1.0.19 |
|
2642 | - * @param string $value zip. |
|
2643 | - */ |
|
2644 | - public function set_user_zip( $value ) { |
|
2645 | - $this->set_zip( $value ); |
|
2799 | + * Set extra email recipients. |
|
2800 | + * |
|
2801 | + * @since 1.0.19 |
|
2802 | + * @param string $value email recipients. |
|
2803 | + */ |
|
2804 | + public function set_email_cc( $value ) { |
|
2805 | + $this->set_prop( 'email_cc', $value ); |
|
2646 | 2806 | } |
2647 | 2807 | |
2648 | 2808 | /** |
2649 | - * Alias of self::set_zip(). |
|
2650 | - * |
|
2651 | - * @since 1.0.19 |
|
2652 | - * @param string $value zip. |
|
2653 | - */ |
|
2654 | - public function set_customer_zip( $value ) { |
|
2655 | - $this->set_zip( $value ); |
|
2809 | + * Set the invoice template. |
|
2810 | + * |
|
2811 | + * @since 1.0.19 |
|
2812 | + * @param string $value template. |
|
2813 | + */ |
|
2814 | + public function set_template( $value ) { |
|
2815 | + if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
2816 | + $this->set_prop( 'template', $value ); |
|
2817 | + } |
|
2656 | 2818 | } |
2657 | 2819 | |
2658 | 2820 | /** |
2659 | - * Set the customer's company. |
|
2660 | - * |
|
2661 | - * @since 1.0.19 |
|
2662 | - * @param string $value company. |
|
2663 | - */ |
|
2664 | - public function set_company( $value ) { |
|
2665 | - $this->set_prop( 'company', $value ); |
|
2821 | + * Set the invoice source. |
|
2822 | + * |
|
2823 | + * @since 1.0.19 |
|
2824 | + * @param string $value source. |
|
2825 | + * @deprecated |
|
2826 | + */ |
|
2827 | + public function created_via( $value ) { |
|
2828 | + $this->set_created_via( sanitize_text_field( $value ) ); |
|
2666 | 2829 | } |
2667 | 2830 | |
2668 | 2831 | /** |
2669 | - * Alias of self::set_company(). |
|
2670 | - * |
|
2671 | - * @since 1.0.19 |
|
2672 | - * @param string $value company. |
|
2673 | - */ |
|
2674 | - public function set_user_company( $value ) { |
|
2675 | - $this->set_company( $value ); |
|
2832 | + * Set the invoice source. |
|
2833 | + * |
|
2834 | + * @since 1.0.19 |
|
2835 | + * @param string $value source. |
|
2836 | + */ |
|
2837 | + public function set_created_via( $value ) { |
|
2838 | + $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
2676 | 2839 | } |
2677 | 2840 | |
2678 | 2841 | /** |
2679 | - * Alias of self::set_company(). |
|
2680 | - * |
|
2681 | - * @since 1.0.19 |
|
2682 | - * @param string $value company. |
|
2683 | - */ |
|
2684 | - public function set_customer_company( $value ) { |
|
2685 | - $this->set_company( $value ); |
|
2686 | - } |
|
2687 | - |
|
2688 | - /** |
|
2689 | - * Set the customer's company id. |
|
2690 | - * |
|
2691 | - * @since 1.0.19 |
|
2692 | - * @param string $value company id. |
|
2693 | - */ |
|
2694 | - public function set_company_id( $value ) { |
|
2695 | - $this->set_prop( 'company_id', $value ); |
|
2842 | + * Set the customer's address confirmed status. |
|
2843 | + * |
|
2844 | + * @since 1.0.19 |
|
2845 | + * @param int|bool $value confirmed. |
|
2846 | + */ |
|
2847 | + public function set_address_confirmed( $value ) { |
|
2848 | + $this->set_prop( 'address_confirmed', $value ); |
|
2696 | 2849 | } |
2697 | 2850 | |
2698 | 2851 | /** |
2699 | - * Set the customer's var number. |
|
2700 | - * |
|
2701 | - * @since 1.0.19 |
|
2702 | - * @param string $value var number. |
|
2703 | - */ |
|
2704 | - public function set_vat_number( $value ) { |
|
2705 | - $this->set_prop( 'vat_number', $value ); |
|
2852 | + * Alias of self::set_address_confirmed(). |
|
2853 | + * |
|
2854 | + * @since 1.0.19 |
|
2855 | + * @param int|bool $value confirmed. |
|
2856 | + */ |
|
2857 | + public function set_user_address_confirmed( $value ) { |
|
2858 | + $this->set_address_confirmed( $value ); |
|
2706 | 2859 | } |
2707 | 2860 | |
2708 | 2861 | /** |
2709 | - * Alias of self::set_vat_number(). |
|
2710 | - * |
|
2711 | - * @since 1.0.19 |
|
2712 | - * @param string $value var number. |
|
2713 | - */ |
|
2714 | - public function set_user_vat_number( $value ) { |
|
2715 | - $this->set_vat_number( $value ); |
|
2862 | + * Alias of self::set_address_confirmed(). |
|
2863 | + * |
|
2864 | + * @since 1.0.19 |
|
2865 | + * @param int|bool $value confirmed. |
|
2866 | + */ |
|
2867 | + public function set_customer_address_confirmed( $value ) { |
|
2868 | + $this->set_address_confirmed( $value ); |
|
2716 | 2869 | } |
2717 | 2870 | |
2718 | 2871 | /** |
2719 | - * Alias of self::set_vat_number(). |
|
2720 | - * |
|
2721 | - * @since 1.0.19 |
|
2722 | - * @param string $value var number. |
|
2723 | - */ |
|
2724 | - public function set_customer_vat_number( $value ) { |
|
2725 | - $this->set_vat_number( $value ); |
|
2872 | + * Set the shipping fee |
|
2873 | + * |
|
2874 | + * @since 1.0.19 |
|
2875 | + * @param float $value shipping amount. |
|
2876 | + */ |
|
2877 | + public function set_shipping( $value ) { |
|
2878 | + |
|
2879 | + if ( ! is_numeric( $value ) ) { |
|
2880 | + return $this->set_prop( 'shipping', null ); |
|
2881 | + } |
|
2882 | + |
|
2883 | + $this->set_prop( 'shipping', max( 0, floatval( $value ) ) ); |
|
2726 | 2884 | } |
2727 | 2885 | |
2728 | 2886 | /** |
2729 | - * Set the customer's vat rate. |
|
2730 | - * |
|
2731 | - * @since 1.0.19 |
|
2732 | - * @param string $value var rate. |
|
2733 | - */ |
|
2734 | - public function set_vat_rate( $value ) { |
|
2735 | - $this->set_prop( 'vat_rate', $value ); |
|
2887 | + * Set the invoice sub total. |
|
2888 | + * |
|
2889 | + * @since 1.0.19 |
|
2890 | + * @param float $value sub total. |
|
2891 | + */ |
|
2892 | + public function set_subtotal( $value ) { |
|
2893 | + $this->set_prop( 'subtotal', max( 0, $value ) ); |
|
2736 | 2894 | } |
2737 | 2895 | |
2738 | - /** |
|
2739 | - * Alias of self::set_vat_rate(). |
|
2740 | - * |
|
2741 | - * @since 1.0.19 |
|
2742 | - * @param string $value var number. |
|
2743 | - */ |
|
2744 | - public function set_user_vat_rate( $value ) { |
|
2745 | - $this->set_vat_rate( $value ); |
|
2746 | - } |
|
2747 | - |
|
2748 | - /** |
|
2749 | - * Alias of self::set_vat_rate(). |
|
2750 | - * |
|
2751 | - * @since 1.0.19 |
|
2752 | - * @param string $value var number. |
|
2753 | - */ |
|
2754 | - public function set_customer_vat_rate( $value ) { |
|
2755 | - $this->set_vat_rate( $value ); |
|
2756 | - } |
|
2757 | - |
|
2758 | - /** |
|
2759 | - * Set the customer's address. |
|
2760 | - * |
|
2761 | - * @since 1.0.19 |
|
2762 | - * @param string $value address. |
|
2763 | - */ |
|
2764 | - public function set_address( $value ) { |
|
2765 | - $this->set_prop( 'address', $value ); |
|
2766 | - } |
|
2767 | - |
|
2768 | - /** |
|
2769 | - * Alias of self::set_address(). |
|
2770 | - * |
|
2771 | - * @since 1.0.19 |
|
2772 | - * @param string $value address. |
|
2773 | - */ |
|
2774 | - public function set_user_address( $value ) { |
|
2775 | - $this->set_address( $value ); |
|
2776 | - } |
|
2777 | - |
|
2778 | - /** |
|
2779 | - * Alias of self::set_address(). |
|
2780 | - * |
|
2781 | - * @since 1.0.19 |
|
2782 | - * @param string $value address. |
|
2783 | - */ |
|
2784 | - public function set_customer_address( $value ) { |
|
2785 | - $this->set_address( $value ); |
|
2786 | - } |
|
2787 | - |
|
2788 | - /** |
|
2789 | - * Set whether the customer has viewed the invoice or not. |
|
2790 | - * |
|
2791 | - * @since 1.0.19 |
|
2792 | - * @param int|bool $value confirmed. |
|
2793 | - */ |
|
2794 | - public function set_is_viewed( $value ) { |
|
2795 | - $this->set_prop( 'is_viewed', $value ); |
|
2796 | - } |
|
2797 | - |
|
2798 | - /** |
|
2799 | - * Set extra email recipients. |
|
2800 | - * |
|
2801 | - * @since 1.0.19 |
|
2802 | - * @param string $value email recipients. |
|
2803 | - */ |
|
2804 | - public function set_email_cc( $value ) { |
|
2805 | - $this->set_prop( 'email_cc', $value ); |
|
2806 | - } |
|
2807 | - |
|
2808 | - /** |
|
2809 | - * Set the invoice template. |
|
2810 | - * |
|
2811 | - * @since 1.0.19 |
|
2812 | - * @param string $value template. |
|
2813 | - */ |
|
2814 | - public function set_template( $value ) { |
|
2815 | - if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
2816 | - $this->set_prop( 'template', $value ); |
|
2817 | - } |
|
2818 | - } |
|
2819 | - |
|
2820 | - /** |
|
2821 | - * Set the invoice source. |
|
2822 | - * |
|
2823 | - * @since 1.0.19 |
|
2824 | - * @param string $value source. |
|
2825 | - * @deprecated |
|
2826 | - */ |
|
2827 | - public function created_via( $value ) { |
|
2828 | - $this->set_created_via( sanitize_text_field( $value ) ); |
|
2829 | - } |
|
2830 | - |
|
2831 | - /** |
|
2832 | - * Set the invoice source. |
|
2833 | - * |
|
2834 | - * @since 1.0.19 |
|
2835 | - * @param string $value source. |
|
2836 | - */ |
|
2837 | - public function set_created_via( $value ) { |
|
2838 | - $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
2839 | - } |
|
2840 | - |
|
2841 | - /** |
|
2842 | - * Set the customer's address confirmed status. |
|
2843 | - * |
|
2844 | - * @since 1.0.19 |
|
2845 | - * @param int|bool $value confirmed. |
|
2846 | - */ |
|
2847 | - public function set_address_confirmed( $value ) { |
|
2848 | - $this->set_prop( 'address_confirmed', $value ); |
|
2849 | - } |
|
2850 | - |
|
2851 | - /** |
|
2852 | - * Alias of self::set_address_confirmed(). |
|
2853 | - * |
|
2854 | - * @since 1.0.19 |
|
2855 | - * @param int|bool $value confirmed. |
|
2856 | - */ |
|
2857 | - public function set_user_address_confirmed( $value ) { |
|
2858 | - $this->set_address_confirmed( $value ); |
|
2859 | - } |
|
2860 | - |
|
2861 | - /** |
|
2862 | - * Alias of self::set_address_confirmed(). |
|
2863 | - * |
|
2864 | - * @since 1.0.19 |
|
2865 | - * @param int|bool $value confirmed. |
|
2866 | - */ |
|
2867 | - public function set_customer_address_confirmed( $value ) { |
|
2868 | - $this->set_address_confirmed( $value ); |
|
2869 | - } |
|
2870 | - |
|
2871 | - /** |
|
2872 | - * Set the shipping fee |
|
2873 | - * |
|
2874 | - * @since 1.0.19 |
|
2875 | - * @param float $value shipping amount. |
|
2876 | - */ |
|
2877 | - public function set_shipping( $value ) { |
|
2878 | - |
|
2879 | - if ( ! is_numeric( $value ) ) { |
|
2880 | - return $this->set_prop( 'shipping', null ); |
|
2881 | - } |
|
2882 | - |
|
2883 | - $this->set_prop( 'shipping', max( 0, floatval( $value ) ) ); |
|
2884 | - } |
|
2885 | - |
|
2886 | - /** |
|
2887 | - * Set the invoice sub total. |
|
2888 | - * |
|
2889 | - * @since 1.0.19 |
|
2890 | - * @param float $value sub total. |
|
2891 | - */ |
|
2892 | - public function set_subtotal( $value ) { |
|
2893 | - $this->set_prop( 'subtotal', max( 0, $value ) ); |
|
2894 | - } |
|
2895 | - |
|
2896 | - /** |
|
2897 | - * Set the invoice total. |
|
2898 | - * |
|
2899 | - * @since 1.0.19 |
|
2900 | - * @param float $value sub total. |
|
2901 | - */ |
|
2902 | - public function set_total( $value ) { |
|
2903 | - $this->set_prop( 'total', max( 0, $value ) ); |
|
2896 | + /** |
|
2897 | + * Set the invoice total. |
|
2898 | + * |
|
2899 | + * @since 1.0.19 |
|
2900 | + * @param float $value sub total. |
|
2901 | + */ |
|
2902 | + public function set_total( $value ) { |
|
2903 | + $this->set_prop( 'total', max( 0, $value ) ); |
|
2904 | 2904 | } |
2905 | 2905 | |
2906 | 2906 | /** |
2907 | - * Set the invoice discount amount. |
|
2908 | - * |
|
2909 | - * @since 1.0.19 |
|
2910 | - * @param float $value discount total. |
|
2911 | - */ |
|
2912 | - public function set_total_discount( $value ) { |
|
2913 | - $this->set_prop( 'total_discount', max( 0, $value ) ); |
|
2907 | + * Set the invoice discount amount. |
|
2908 | + * |
|
2909 | + * @since 1.0.19 |
|
2910 | + * @param float $value discount total. |
|
2911 | + */ |
|
2912 | + public function set_total_discount( $value ) { |
|
2913 | + $this->set_prop( 'total_discount', max( 0, $value ) ); |
|
2914 | 2914 | } |
2915 | 2915 | |
2916 | 2916 | /** |
2917 | - * Alias of self::set_total_discount(). |
|
2918 | - * |
|
2919 | - * @since 1.0.19 |
|
2920 | - * @param float $value discount total. |
|
2921 | - */ |
|
2922 | - public function set_discount( $value ) { |
|
2923 | - $this->set_total_discount( $value ); |
|
2917 | + * Alias of self::set_total_discount(). |
|
2918 | + * |
|
2919 | + * @since 1.0.19 |
|
2920 | + * @param float $value discount total. |
|
2921 | + */ |
|
2922 | + public function set_discount( $value ) { |
|
2923 | + $this->set_total_discount( $value ); |
|
2924 | 2924 | } |
2925 | 2925 | |
2926 | 2926 | /** |
2927 | - * Set the invoice tax amount. |
|
2928 | - * |
|
2929 | - * @since 1.0.19 |
|
2930 | - * @param float $value tax total. |
|
2931 | - */ |
|
2932 | - public function set_total_tax( $value ) { |
|
2933 | - $this->set_prop( 'total_tax', max( 0, $value ) ); |
|
2927 | + * Set the invoice tax amount. |
|
2928 | + * |
|
2929 | + * @since 1.0.19 |
|
2930 | + * @param float $value tax total. |
|
2931 | + */ |
|
2932 | + public function set_total_tax( $value ) { |
|
2933 | + $this->set_prop( 'total_tax', max( 0, $value ) ); |
|
2934 | 2934 | } |
2935 | 2935 | |
2936 | 2936 | /** |
2937 | - * Alias of self::set_total_tax(). |
|
2938 | - * |
|
2939 | - * @since 1.0.19 |
|
2940 | - * @param float $value tax total. |
|
2941 | - */ |
|
2942 | - public function set_tax_total( $value ) { |
|
2943 | - $this->set_total_tax( $value ); |
|
2937 | + * Alias of self::set_total_tax(). |
|
2938 | + * |
|
2939 | + * @since 1.0.19 |
|
2940 | + * @param float $value tax total. |
|
2941 | + */ |
|
2942 | + public function set_tax_total( $value ) { |
|
2943 | + $this->set_total_tax( $value ); |
|
2944 | 2944 | } |
2945 | 2945 | |
2946 | 2946 | /** |
2947 | - * Set the invoice fees amount. |
|
2948 | - * |
|
2949 | - * @since 1.0.19 |
|
2950 | - * @param float $value fees total. |
|
2951 | - */ |
|
2952 | - public function set_total_fees( $value ) { |
|
2953 | - $this->set_prop( 'total_fees', max( 0, $value ) ); |
|
2947 | + * Set the invoice fees amount. |
|
2948 | + * |
|
2949 | + * @since 1.0.19 |
|
2950 | + * @param float $value fees total. |
|
2951 | + */ |
|
2952 | + public function set_total_fees( $value ) { |
|
2953 | + $this->set_prop( 'total_fees', max( 0, $value ) ); |
|
2954 | 2954 | } |
2955 | 2955 | |
2956 | 2956 | /** |
2957 | - * Alias of self::set_total_fees(). |
|
2958 | - * |
|
2959 | - * @since 1.0.19 |
|
2960 | - * @param float $value fees total. |
|
2961 | - */ |
|
2962 | - public function set_fees_total( $value ) { |
|
2963 | - $this->set_total_fees( $value ); |
|
2957 | + * Alias of self::set_total_fees(). |
|
2958 | + * |
|
2959 | + * @since 1.0.19 |
|
2960 | + * @param float $value fees total. |
|
2961 | + */ |
|
2962 | + public function set_fees_total( $value ) { |
|
2963 | + $this->set_total_fees( $value ); |
|
2964 | 2964 | } |
2965 | 2965 | |
2966 | 2966 | /** |
2967 | - * Set the invoice fees. |
|
2968 | - * |
|
2969 | - * @since 1.0.19 |
|
2970 | - * @param array $value fees. |
|
2971 | - */ |
|
2972 | - public function set_fees( $value ) { |
|
2967 | + * Set the invoice fees. |
|
2968 | + * |
|
2969 | + * @since 1.0.19 |
|
2970 | + * @param array $value fees. |
|
2971 | + */ |
|
2972 | + public function set_fees( $value ) { |
|
2973 | 2973 | |
2974 | - if ( ! is_array( $value ) ) { |
|
2975 | - $value = array(); |
|
2976 | - } |
|
2974 | + if ( ! is_array( $value ) ) { |
|
2975 | + $value = array(); |
|
2976 | + } |
|
2977 | 2977 | |
2978 | - $this->set_prop( 'fees', $value ); |
|
2978 | + $this->set_prop( 'fees', $value ); |
|
2979 | 2979 | |
2980 | 2980 | } |
2981 | 2981 | |
2982 | 2982 | /** |
2983 | - * Set the invoice taxes. |
|
2984 | - * |
|
2985 | - * @since 1.0.19 |
|
2986 | - * @param array $value taxes. |
|
2987 | - */ |
|
2988 | - public function set_taxes( $value ) { |
|
2983 | + * Set the invoice taxes. |
|
2984 | + * |
|
2985 | + * @since 1.0.19 |
|
2986 | + * @param array $value taxes. |
|
2987 | + */ |
|
2988 | + public function set_taxes( $value ) { |
|
2989 | 2989 | |
2990 | - if ( ! is_array( $value ) ) { |
|
2991 | - $value = array(); |
|
2992 | - } |
|
2990 | + if ( ! is_array( $value ) ) { |
|
2991 | + $value = array(); |
|
2992 | + } |
|
2993 | 2993 | |
2994 | - $this->set_prop( 'taxes', $value ); |
|
2994 | + $this->set_prop( 'taxes', $value ); |
|
2995 | 2995 | |
2996 | 2996 | } |
2997 | 2997 | |
2998 | 2998 | /** |
2999 | - * Set the invoice discounts. |
|
3000 | - * |
|
3001 | - * @since 1.0.19 |
|
3002 | - * @param array $value discounts. |
|
3003 | - */ |
|
3004 | - public function set_discounts( $value ) { |
|
2999 | + * Set the invoice discounts. |
|
3000 | + * |
|
3001 | + * @since 1.0.19 |
|
3002 | + * @param array $value discounts. |
|
3003 | + */ |
|
3004 | + public function set_discounts( $value ) { |
|
3005 | 3005 | |
3006 | - if ( ! is_array( $value ) ) { |
|
3007 | - $value = array(); |
|
3008 | - } |
|
3006 | + if ( ! is_array( $value ) ) { |
|
3007 | + $value = array(); |
|
3008 | + } |
|
3009 | 3009 | |
3010 | - $this->set_prop( 'discounts', $value ); |
|
3010 | + $this->set_prop( 'discounts', $value ); |
|
3011 | 3011 | } |
3012 | 3012 | |
3013 | 3013 | /** |
3014 | - * Set the invoice items. |
|
3015 | - * |
|
3016 | - * @since 1.0.19 |
|
3017 | - * @param GetPaid_Form_Item[] $value items. |
|
3018 | - */ |
|
3019 | - public function set_items( $value ) { |
|
3014 | + * Set the invoice items. |
|
3015 | + * |
|
3016 | + * @since 1.0.19 |
|
3017 | + * @param GetPaid_Form_Item[] $value items. |
|
3018 | + */ |
|
3019 | + public function set_items( $value ) { |
|
3020 | 3020 | |
3021 | 3021 | // Remove existing items. |
3022 | 3022 | $this->set_prop( 'items', array() ); |
3023 | - $this->recurring_item = null; |
|
3023 | + $this->recurring_item = null; |
|
3024 | 3024 | |
3025 | 3025 | // Ensure that we have an array. |
3026 | 3026 | if ( ! is_array( $value ) ) { |
@@ -3034,95 +3034,95 @@ discard block |
||
3034 | 3034 | } |
3035 | 3035 | |
3036 | 3036 | /** |
3037 | - * Set the payment form. |
|
3038 | - * |
|
3039 | - * @since 1.0.19 |
|
3040 | - * @param int $value payment form. |
|
3041 | - */ |
|
3042 | - public function set_payment_form( $value ) { |
|
3043 | - $this->set_prop( 'payment_form', $value ); |
|
3037 | + * Set the payment form. |
|
3038 | + * |
|
3039 | + * @since 1.0.19 |
|
3040 | + * @param int $value payment form. |
|
3041 | + */ |
|
3042 | + public function set_payment_form( $value ) { |
|
3043 | + $this->set_prop( 'payment_form', $value ); |
|
3044 | 3044 | } |
3045 | 3045 | |
3046 | 3046 | /** |
3047 | - * Set the submission id. |
|
3048 | - * |
|
3049 | - * @since 1.0.19 |
|
3050 | - * @param string $value submission id. |
|
3051 | - */ |
|
3052 | - public function set_submission_id( $value ) { |
|
3053 | - $this->set_prop( 'submission_id', $value ); |
|
3047 | + * Set the submission id. |
|
3048 | + * |
|
3049 | + * @since 1.0.19 |
|
3050 | + * @param string $value submission id. |
|
3051 | + */ |
|
3052 | + public function set_submission_id( $value ) { |
|
3053 | + $this->set_prop( 'submission_id', $value ); |
|
3054 | 3054 | } |
3055 | 3055 | |
3056 | 3056 | /** |
3057 | - * Set the discount code. |
|
3058 | - * |
|
3059 | - * @since 1.0.19 |
|
3060 | - * @param string $value discount code. |
|
3061 | - */ |
|
3062 | - public function set_discount_code( $value ) { |
|
3063 | - $this->set_prop( 'discount_code', sanitize_text_field( $value ) ); |
|
3057 | + * Set the discount code. |
|
3058 | + * |
|
3059 | + * @since 1.0.19 |
|
3060 | + * @param string $value discount code. |
|
3061 | + */ |
|
3062 | + public function set_discount_code( $value ) { |
|
3063 | + $this->set_prop( 'discount_code', sanitize_text_field( $value ) ); |
|
3064 | 3064 | } |
3065 | 3065 | |
3066 | 3066 | /** |
3067 | - * Set the gateway. |
|
3068 | - * |
|
3069 | - * @since 1.0.19 |
|
3070 | - * @param string $value gateway. |
|
3071 | - */ |
|
3072 | - public function set_gateway( $value ) { |
|
3073 | - $this->set_prop( 'gateway', $value ); |
|
3067 | + * Set the gateway. |
|
3068 | + * |
|
3069 | + * @since 1.0.19 |
|
3070 | + * @param string $value gateway. |
|
3071 | + */ |
|
3072 | + public function set_gateway( $value ) { |
|
3073 | + $this->set_prop( 'gateway', $value ); |
|
3074 | 3074 | } |
3075 | 3075 | |
3076 | 3076 | /** |
3077 | - * Set the transaction id. |
|
3078 | - * |
|
3079 | - * @since 1.0.19 |
|
3080 | - * @param string $value transaction id. |
|
3081 | - */ |
|
3082 | - public function set_transaction_id( $value ) { |
|
3083 | - if ( ! empty( $value ) ) { |
|
3084 | - $this->set_prop( 'transaction_id', $value ); |
|
3085 | - } |
|
3077 | + * Set the transaction id. |
|
3078 | + * |
|
3079 | + * @since 1.0.19 |
|
3080 | + * @param string $value transaction id. |
|
3081 | + */ |
|
3082 | + public function set_transaction_id( $value ) { |
|
3083 | + if ( ! empty( $value ) ) { |
|
3084 | + $this->set_prop( 'transaction_id', $value ); |
|
3085 | + } |
|
3086 | 3086 | } |
3087 | 3087 | |
3088 | 3088 | /** |
3089 | - * Set the currency id. |
|
3090 | - * |
|
3091 | - * @since 1.0.19 |
|
3092 | - * @param string $value currency id. |
|
3093 | - */ |
|
3094 | - public function set_currency( $value ) { |
|
3095 | - $this->set_prop( 'currency', $value ); |
|
3089 | + * Set the currency id. |
|
3090 | + * |
|
3091 | + * @since 1.0.19 |
|
3092 | + * @param string $value currency id. |
|
3093 | + */ |
|
3094 | + public function set_currency( $value ) { |
|
3095 | + $this->set_prop( 'currency', $value ); |
|
3096 | 3096 | } |
3097 | 3097 | |
3098 | - /** |
|
3099 | - * Set whether to disable taxes. |
|
3100 | - * |
|
3101 | - * @since 1.0.19 |
|
3102 | - * @param bool $value value. |
|
3103 | - */ |
|
3104 | - public function set_disable_taxes( $value ) { |
|
3105 | - $this->set_prop( 'disable_taxes', (bool) $value ); |
|
3106 | - } |
|
3098 | + /** |
|
3099 | + * Set whether to disable taxes. |
|
3100 | + * |
|
3101 | + * @since 1.0.19 |
|
3102 | + * @param bool $value value. |
|
3103 | + */ |
|
3104 | + public function set_disable_taxes( $value ) { |
|
3105 | + $this->set_prop( 'disable_taxes', (bool) $value ); |
|
3106 | + } |
|
3107 | 3107 | |
3108 | 3108 | /** |
3109 | - * Set the subscription id. |
|
3110 | - * |
|
3111 | - * @since 1.0.19 |
|
3112 | - * @param string $value subscription id. |
|
3113 | - */ |
|
3114 | - public function set_subscription_id( $value ) { |
|
3115 | - $this->set_prop( 'subscription_id', $value ); |
|
3116 | - } |
|
3109 | + * Set the subscription id. |
|
3110 | + * |
|
3111 | + * @since 1.0.19 |
|
3112 | + * @param string $value subscription id. |
|
3113 | + */ |
|
3114 | + public function set_subscription_id( $value ) { |
|
3115 | + $this->set_prop( 'subscription_id', $value ); |
|
3116 | + } |
|
3117 | 3117 | |
3118 | - /** |
|
3119 | - * Set the remote subscription id. |
|
3120 | - * |
|
3121 | - * @since 1.0.19 |
|
3122 | - * @param string $value subscription id. |
|
3123 | - */ |
|
3124 | - public function set_remote_subscription_id( $value ) { |
|
3125 | - $this->set_prop( 'remote_subscription_id', $value ); |
|
3118 | + /** |
|
3119 | + * Set the remote subscription id. |
|
3120 | + * |
|
3121 | + * @since 1.0.19 |
|
3122 | + * @param string $value subscription id. |
|
3123 | + */ |
|
3124 | + public function set_remote_subscription_id( $value ) { |
|
3125 | + $this->set_prop( 'remote_subscription_id', $value ); |
|
3126 | 3126 | } |
3127 | 3127 | |
3128 | 3128 | /* |
@@ -3161,24 +3161,24 @@ discard block |
||
3161 | 3161 | */ |
3162 | 3162 | public function is_taxable() { |
3163 | 3163 | return ! $this->get_disable_taxes(); |
3164 | - } |
|
3164 | + } |
|
3165 | 3165 | |
3166 | - /** |
|
3167 | - * @deprecated |
|
3168 | - */ |
|
3169 | - public function has_vat() { |
|
3166 | + /** |
|
3167 | + * @deprecated |
|
3168 | + */ |
|
3169 | + public function has_vat() { |
|
3170 | 3170 | return $this->is_taxable(); |
3171 | - } |
|
3171 | + } |
|
3172 | 3172 | |
3173 | - /** |
|
3174 | - * Checks to see if the invoice requires payment. |
|
3175 | - */ |
|
3176 | - public function is_free() { |
|
3173 | + /** |
|
3174 | + * Checks to see if the invoice requires payment. |
|
3175 | + */ |
|
3176 | + public function is_free() { |
|
3177 | 3177 | $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 ); |
3178 | 3178 | |
3179 | - if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
3180 | - $is_free = false; |
|
3181 | - } |
|
3179 | + if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
3180 | + $is_free = false; |
|
3181 | + } |
|
3182 | 3182 | |
3183 | 3183 | return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
3184 | 3184 | } |
@@ -3189,46 +3189,46 @@ discard block |
||
3189 | 3189 | public function is_paid() { |
3190 | 3190 | $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
3191 | 3191 | return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
3192 | - } |
|
3192 | + } |
|
3193 | 3193 | |
3194 | - /** |
|
3194 | + /** |
|
3195 | 3195 | * Checks if the invoice needs payment. |
3196 | 3196 | */ |
3197 | - public function needs_payment() { |
|
3198 | - $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
3197 | + public function needs_payment() { |
|
3198 | + $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
3199 | 3199 | return apply_filters( 'wpinv_needs_payment', $needs_payment, $this ); |
3200 | 3200 | } |
3201 | 3201 | |
3202 | - /** |
|
3202 | + /** |
|
3203 | 3203 | * Checks if the invoice is refunded. |
3204 | 3204 | */ |
3205 | - public function is_refunded() { |
|
3205 | + public function is_refunded() { |
|
3206 | 3206 | $is_refunded = $this->has_status( 'wpi-refunded' ); |
3207 | 3207 | return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
3208 | - } |
|
3208 | + } |
|
3209 | 3209 | |
3210 | - /** |
|
3210 | + /** |
|
3211 | 3211 | * Checks if the invoice is held. |
3212 | 3212 | */ |
3213 | - public function is_held() { |
|
3213 | + public function is_held() { |
|
3214 | 3214 | $is_held = $this->has_status( 'wpi-onhold' ); |
3215 | 3215 | return apply_filters( 'wpinv_invoice_is_held', $is_held, $this ); |
3216 | - } |
|
3216 | + } |
|
3217 | 3217 | |
3218 | - /** |
|
3218 | + /** |
|
3219 | 3219 | * Checks if the invoice is due. |
3220 | 3220 | */ |
3221 | - public function is_due() { |
|
3222 | - $due_date = $this->get_due_date(); |
|
3223 | - return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
3224 | - } |
|
3221 | + public function is_due() { |
|
3222 | + $due_date = $this->get_due_date(); |
|
3223 | + return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
3224 | + } |
|
3225 | 3225 | |
3226 | - /** |
|
3226 | + /** |
|
3227 | 3227 | * Checks if the invoice is draft. |
3228 | 3228 | */ |
3229 | - public function is_draft() { |
|
3229 | + public function is_draft() { |
|
3230 | 3230 | return $this->has_status( 'draft, auto-draft' ); |
3231 | - } |
|
3231 | + } |
|
3232 | 3232 | |
3233 | 3233 | /** |
3234 | 3234 | * Checks if the invoice has a given status. |
@@ -3236,9 +3236,9 @@ discard block |
||
3236 | 3236 | public function has_status( $status ) { |
3237 | 3237 | $status = wpinv_parse_list( $status ); |
3238 | 3238 | return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status ); |
3239 | - } |
|
3239 | + } |
|
3240 | 3240 | |
3241 | - /** |
|
3241 | + /** |
|
3242 | 3242 | * Checks if the invoice is of a given type. |
3243 | 3243 | */ |
3244 | 3244 | public function is_type( $type ) { |
@@ -3261,25 +3261,25 @@ discard block |
||
3261 | 3261 | */ |
3262 | 3262 | public function has_free_trial() { |
3263 | 3263 | return $this->is_recurring() && 0 == $this->get_initial_total(); |
3264 | - } |
|
3264 | + } |
|
3265 | 3265 | |
3266 | - /** |
|
3266 | + /** |
|
3267 | 3267 | * @deprecated |
3268 | 3268 | */ |
3269 | 3269 | public function is_free_trial() { |
3270 | 3270 | return $this->has_free_trial(); |
3271 | 3271 | } |
3272 | 3272 | |
3273 | - /** |
|
3273 | + /** |
|
3274 | 3274 | * Check if the initial payment if 0. |
3275 | 3275 | * |
3276 | 3276 | */ |
3277 | - public function is_initial_free() { |
|
3277 | + public function is_initial_free() { |
|
3278 | 3278 | $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 ); |
3279 | 3279 | return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this ); |
3280 | 3280 | } |
3281 | 3281 | |
3282 | - /** |
|
3282 | + /** |
|
3283 | 3283 | * Check if the recurring item has a free trial. |
3284 | 3284 | * |
3285 | 3285 | */ |
@@ -3292,21 +3292,21 @@ discard block |
||
3292 | 3292 | |
3293 | 3293 | $item = $this->get_recurring( true ); |
3294 | 3294 | return $item->has_free_trial(); |
3295 | - } |
|
3295 | + } |
|
3296 | 3296 | |
3297 | - /** |
|
3297 | + /** |
|
3298 | 3298 | * Check if the free trial is a result of a discount. |
3299 | 3299 | */ |
3300 | 3300 | public function is_free_trial_from_discount() { |
3301 | - return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
3302 | - } |
|
3301 | + return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
3302 | + } |
|
3303 | 3303 | |
3304 | - /** |
|
3304 | + /** |
|
3305 | 3305 | * @deprecated |
3306 | 3306 | */ |
3307 | 3307 | public function discount_first_payment_only() { |
3308 | 3308 | |
3309 | - $discount = wpinv_get_discount_obj( $this->get_discount_code() ); |
|
3309 | + $discount = wpinv_get_discount_obj( $this->get_discount_code() ); |
|
3310 | 3310 | if ( ! $discount->exists() || ! $this->is_recurring() ) { |
3311 | 3311 | return true; |
3312 | 3312 | } |
@@ -3331,146 +3331,146 @@ discard block |
||
3331 | 3331 | */ |
3332 | 3332 | public function add_item( $item ) { |
3333 | 3333 | |
3334 | - if ( is_array( $item ) ) { |
|
3335 | - $item = $this->process_array_item( $item ); |
|
3336 | - } |
|
3334 | + if ( is_array( $item ) ) { |
|
3335 | + $item = $this->process_array_item( $item ); |
|
3336 | + } |
|
3337 | 3337 | |
3338 | - if ( is_numeric( $item ) ) { |
|
3339 | - $item = new GetPaid_Form_Item( $item ); |
|
3340 | - } |
|
3338 | + if ( is_numeric( $item ) ) { |
|
3339 | + $item = new GetPaid_Form_Item( $item ); |
|
3340 | + } |
|
3341 | 3341 | |
3342 | 3342 | // Make sure that it is available for purchase. |
3343 | - if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
3344 | - return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
3343 | + if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
3344 | + return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
3345 | 3345 | } |
3346 | 3346 | |
3347 | 3347 | // Do we have a recurring item? |
3348 | - if ( $item->is_recurring() ) { |
|
3349 | - $this->recurring_item = $item->get_id(); |
|
3348 | + if ( $item->is_recurring() ) { |
|
3349 | + $this->recurring_item = $item->get_id(); |
|
3350 | 3350 | } |
3351 | 3351 | |
3352 | 3352 | // Invoice id. |
3353 | 3353 | $item->invoice_id = (int) $this->get_id(); |
3354 | 3354 | |
3355 | - // Remove duplicates. |
|
3356 | - $this->remove_item( $item->get_id() ); |
|
3355 | + // Remove duplicates. |
|
3356 | + $this->remove_item( $item->get_id() ); |
|
3357 | 3357 | |
3358 | - if ( 0 == $item->get_quantity() ) { |
|
3359 | - return; |
|
3360 | - } |
|
3358 | + if ( 0 == $item->get_quantity() ) { |
|
3359 | + return; |
|
3360 | + } |
|
3361 | 3361 | |
3362 | - // Retrieve all items. |
|
3362 | + // Retrieve all items. |
|
3363 | 3363 | $items = $this->get_items(); |
3364 | 3364 | |
3365 | - // Add new item. |
|
3365 | + // Add new item. |
|
3366 | 3366 | $items[] = $item; |
3367 | 3367 | |
3368 | 3368 | $this->set_prop( 'items', $items ); |
3369 | 3369 | |
3370 | - return true; |
|
3371 | - } |
|
3370 | + return true; |
|
3371 | + } |
|
3372 | 3372 | |
3373 | - /** |
|
3374 | - * Converts an array to an item. |
|
3375 | - * |
|
3376 | - * @since 1.0.19 |
|
3377 | - * @return GetPaid_Form_Item |
|
3378 | - */ |
|
3379 | - protected function process_array_item( $array ) { |
|
3373 | + /** |
|
3374 | + * Converts an array to an item. |
|
3375 | + * |
|
3376 | + * @since 1.0.19 |
|
3377 | + * @return GetPaid_Form_Item |
|
3378 | + */ |
|
3379 | + protected function process_array_item( $array ) { |
|
3380 | 3380 | |
3381 | - $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
3382 | - $item = new GetPaid_Form_Item( $item_id ); |
|
3381 | + $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
3382 | + $item = new GetPaid_Form_Item( $item_id ); |
|
3383 | 3383 | |
3384 | - // Set item data. |
|
3385 | - foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
3386 | - if ( isset( $array[ "item_$key" ] ) ) { |
|
3387 | - $method = "set_$key"; |
|
3388 | - $item->$method( $array[ "item_$key" ] ); |
|
3389 | - } |
|
3390 | - } |
|
3384 | + // Set item data. |
|
3385 | + foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
3386 | + if ( isset( $array[ "item_$key" ] ) ) { |
|
3387 | + $method = "set_$key"; |
|
3388 | + $item->$method( $array[ "item_$key" ] ); |
|
3389 | + } |
|
3390 | + } |
|
3391 | 3391 | |
3392 | - if ( isset( $array['quantity'] ) ) { |
|
3393 | - $item->set_quantity( $array['quantity'] ); |
|
3394 | - } |
|
3392 | + if ( isset( $array['quantity'] ) ) { |
|
3393 | + $item->set_quantity( $array['quantity'] ); |
|
3394 | + } |
|
3395 | 3395 | |
3396 | - // Set item meta. |
|
3397 | - if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
3398 | - $item->set_item_meta( $array['meta'] ); |
|
3399 | - } |
|
3396 | + // Set item meta. |
|
3397 | + if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
3398 | + $item->set_item_meta( $array['meta'] ); |
|
3399 | + } |
|
3400 | 3400 | |
3401 | - return $item; |
|
3401 | + return $item; |
|
3402 | 3402 | |
3403 | - } |
|
3403 | + } |
|
3404 | 3404 | |
3405 | 3405 | /** |
3406 | - * Retrieves a specific item. |
|
3407 | - * |
|
3408 | - * @since 1.0.19 |
|
3409 | - * @return GetPaid_Form_Item|null |
|
3410 | - */ |
|
3411 | - public function get_item( $item_id ) { |
|
3406 | + * Retrieves a specific item. |
|
3407 | + * |
|
3408 | + * @since 1.0.19 |
|
3409 | + * @return GetPaid_Form_Item|null |
|
3410 | + */ |
|
3411 | + public function get_item( $item_id ) { |
|
3412 | 3412 | |
3413 | - foreach ( $this->get_items() as $item ) { |
|
3414 | - if ( (int) $item_id == $item->get_id() ) { |
|
3415 | - return $item; |
|
3416 | - } |
|
3417 | - } |
|
3413 | + foreach ( $this->get_items() as $item ) { |
|
3414 | + if ( (int) $item_id == $item->get_id() ) { |
|
3415 | + return $item; |
|
3416 | + } |
|
3417 | + } |
|
3418 | 3418 | |
3419 | - return null; |
|
3419 | + return null; |
|
3420 | 3420 | } |
3421 | 3421 | |
3422 | 3422 | /** |
3423 | - * Removes a specific item. |
|
3424 | - * |
|
3425 | - * @since 1.0.19 |
|
3426 | - */ |
|
3427 | - public function remove_item( $item_id ) { |
|
3428 | - $items = $this->get_items(); |
|
3429 | - $item_id = (int) $item_id; |
|
3423 | + * Removes a specific item. |
|
3424 | + * |
|
3425 | + * @since 1.0.19 |
|
3426 | + */ |
|
3427 | + public function remove_item( $item_id ) { |
|
3428 | + $items = $this->get_items(); |
|
3429 | + $item_id = (int) $item_id; |
|
3430 | 3430 | |
3431 | - foreach ( $items as $index => $item ) { |
|
3432 | - if ( (int) $item_id == $item->get_id() ) { |
|
3433 | - unset( $items[ $index ] ); |
|
3434 | - $this->set_prop( 'items', $items ); |
|
3431 | + foreach ( $items as $index => $item ) { |
|
3432 | + if ( (int) $item_id == $item->get_id() ) { |
|
3433 | + unset( $items[ $index ] ); |
|
3434 | + $this->set_prop( 'items', $items ); |
|
3435 | 3435 | |
3436 | - if ( $item_id == $this->recurring_item ) { |
|
3437 | - $this->recurring_item = null; |
|
3438 | - } |
|
3436 | + if ( $item_id == $this->recurring_item ) { |
|
3437 | + $this->recurring_item = null; |
|
3438 | + } |
|
3439 | 3439 | } |
3440 | - } |
|
3440 | + } |
|
3441 | 3441 | |
3442 | 3442 | } |
3443 | 3443 | |
3444 | 3444 | /** |
3445 | - * Adds a fee to the invoice. |
|
3446 | - * |
|
3447 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
3448 | - * @since 1.0.19 |
|
3449 | - */ |
|
3445 | + * Adds a fee to the invoice. |
|
3446 | + * |
|
3447 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
3448 | + * @since 1.0.19 |
|
3449 | + */ |
|
3450 | 3450 | public function add_fee( $fee ) { |
3451 | 3451 | |
3452 | - $fees = $this->get_fees(); |
|
3453 | - $fees[ $fee['name'] ] = $fee; |
|
3454 | - $this->set_prop( 'fees', $fees ); |
|
3452 | + $fees = $this->get_fees(); |
|
3453 | + $fees[ $fee['name'] ] = $fee; |
|
3454 | + $this->set_prop( 'fees', $fees ); |
|
3455 | 3455 | |
3456 | 3456 | } |
3457 | 3457 | |
3458 | 3458 | /** |
3459 | - * Retrieves a specific fee. |
|
3460 | - * |
|
3461 | - * @since 1.0.19 |
|
3462 | - */ |
|
3463 | - public function get_fee( $fee ) { |
|
3459 | + * Retrieves a specific fee. |
|
3460 | + * |
|
3461 | + * @since 1.0.19 |
|
3462 | + */ |
|
3463 | + public function get_fee( $fee ) { |
|
3464 | 3464 | $fees = $this->get_fees(); |
3465 | - return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
3465 | + return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
3466 | 3466 | } |
3467 | 3467 | |
3468 | 3468 | /** |
3469 | - * Removes a specific fee. |
|
3470 | - * |
|
3471 | - * @since 1.0.19 |
|
3472 | - */ |
|
3473 | - public function remove_fee( $fee ) { |
|
3469 | + * Removes a specific fee. |
|
3470 | + * |
|
3471 | + * @since 1.0.19 |
|
3472 | + */ |
|
3473 | + public function remove_fee( $fee ) { |
|
3474 | 3474 | $fees = $this->get_fees(); |
3475 | 3475 | if ( isset( $fees[ $fee ] ) ) { |
3476 | 3476 | unset( $fees[ $fee ] ); |
@@ -3478,55 +3478,55 @@ discard block |
||
3478 | 3478 | } |
3479 | 3479 | } |
3480 | 3480 | |
3481 | - /** |
|
3482 | - * Adds a discount to the invoice. |
|
3483 | - * |
|
3484 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
3485 | - * @since 1.0.19 |
|
3486 | - */ |
|
3487 | - public function add_discount( $discount ) { |
|
3481 | + /** |
|
3482 | + * Adds a discount to the invoice. |
|
3483 | + * |
|
3484 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
3485 | + * @since 1.0.19 |
|
3486 | + */ |
|
3487 | + public function add_discount( $discount ) { |
|
3488 | 3488 | |
3489 | - $discounts = $this->get_discounts(); |
|
3490 | - $discounts[ $discount['name'] ] = $discount; |
|
3491 | - $this->set_prop( 'discounts', $discounts ); |
|
3489 | + $discounts = $this->get_discounts(); |
|
3490 | + $discounts[ $discount['name'] ] = $discount; |
|
3491 | + $this->set_prop( 'discounts', $discounts ); |
|
3492 | 3492 | |
3493 | - } |
|
3493 | + } |
|
3494 | 3494 | |
3495 | 3495 | /** |
3496 | - * Retrieves a specific discount. |
|
3497 | - * |
|
3498 | - * @since 1.0.19 |
|
3499 | - * @return float |
|
3500 | - */ |
|
3501 | - public function get_discount( $discount = false ) { |
|
3496 | + * Retrieves a specific discount. |
|
3497 | + * |
|
3498 | + * @since 1.0.19 |
|
3499 | + * @return float |
|
3500 | + */ |
|
3501 | + public function get_discount( $discount = false ) { |
|
3502 | 3502 | |
3503 | - // Backwards compatibilty. |
|
3504 | - if ( empty( $discount ) ) { |
|
3505 | - return $this->get_total_discount(); |
|
3506 | - } |
|
3503 | + // Backwards compatibilty. |
|
3504 | + if ( empty( $discount ) ) { |
|
3505 | + return $this->get_total_discount(); |
|
3506 | + } |
|
3507 | 3507 | |
3508 | 3508 | $discounts = $this->get_discounts(); |
3509 | - return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
3509 | + return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
3510 | 3510 | } |
3511 | 3511 | |
3512 | 3512 | /** |
3513 | - * Removes a specific discount. |
|
3514 | - * |
|
3515 | - * @since 1.0.19 |
|
3516 | - */ |
|
3517 | - public function remove_discount( $discount ) { |
|
3513 | + * Removes a specific discount. |
|
3514 | + * |
|
3515 | + * @since 1.0.19 |
|
3516 | + */ |
|
3517 | + public function remove_discount( $discount ) { |
|
3518 | 3518 | $discounts = $this->get_discounts(); |
3519 | 3519 | if ( isset( $discounts[ $discount ] ) ) { |
3520 | 3520 | unset( $discounts[ $discount ] ); |
3521 | 3521 | $this->set_prop( 'discounts', $discounts ); |
3522 | 3522 | } |
3523 | 3523 | |
3524 | - if ( 'discount_code' == $discount ) { |
|
3525 | - foreach ( $this->get_items() as $item ) { |
|
3526 | - $item->item_discount = 0; |
|
3527 | - $item->recurring_item_discount = 0; |
|
3528 | - } |
|
3529 | - } |
|
3524 | + if ( 'discount_code' == $discount ) { |
|
3525 | + foreach ( $this->get_items() as $item ) { |
|
3526 | + $item->item_discount = 0; |
|
3527 | + $item->recurring_item_discount = 0; |
|
3528 | + } |
|
3529 | + } |
|
3530 | 3530 | |
3531 | 3531 | } |
3532 | 3532 | |
@@ -3539,34 +3539,34 @@ discard block |
||
3539 | 3539 | if ( $this->is_taxable() ) { |
3540 | 3540 | |
3541 | 3541 | $taxes = $this->get_taxes(); |
3542 | - $taxes[ $tax['name'] ] = $tax; |
|
3543 | - $this->set_prop( 'taxes', $tax ); |
|
3542 | + $taxes[ $tax['name'] ] = $tax; |
|
3543 | + $this->set_prop( 'taxes', $tax ); |
|
3544 | 3544 | |
3545 | 3545 | } |
3546 | 3546 | } |
3547 | 3547 | |
3548 | 3548 | /** |
3549 | - * Retrieves a specific tax. |
|
3550 | - * |
|
3551 | - * @since 1.0.19 |
|
3552 | - */ |
|
3553 | - public function get_tax( $tax = null ) { |
|
3549 | + * Retrieves a specific tax. |
|
3550 | + * |
|
3551 | + * @since 1.0.19 |
|
3552 | + */ |
|
3553 | + public function get_tax( $tax = null ) { |
|
3554 | 3554 | |
3555 | - // Backwards compatility. |
|
3556 | - if ( empty( $tax ) ) { |
|
3557 | - return $this->get_total_tax(); |
|
3558 | - } |
|
3555 | + // Backwards compatility. |
|
3556 | + if ( empty( $tax ) ) { |
|
3557 | + return $this->get_total_tax(); |
|
3558 | + } |
|
3559 | 3559 | |
3560 | 3560 | $taxes = $this->get_taxes(); |
3561 | - return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
3561 | + return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
3562 | 3562 | } |
3563 | 3563 | |
3564 | 3564 | /** |
3565 | - * Removes a specific tax. |
|
3566 | - * |
|
3567 | - * @since 1.0.19 |
|
3568 | - */ |
|
3569 | - public function remove_tax( $tax ) { |
|
3565 | + * Removes a specific tax. |
|
3566 | + * |
|
3567 | + * @since 1.0.19 |
|
3568 | + */ |
|
3569 | + public function remove_tax( $tax ) { |
|
3570 | 3570 | $taxes = $this->get_taxes(); |
3571 | 3571 | if ( isset( $taxes[ $tax ] ) ) { |
3572 | 3572 | unset( $taxes[ $tax ] ); |
@@ -3575,184 +3575,184 @@ discard block |
||
3575 | 3575 | } |
3576 | 3576 | |
3577 | 3577 | /** |
3578 | - * Recalculates the invoice subtotal. |
|
3579 | - * |
|
3580 | - * @since 1.0.19 |
|
3581 | - * @return float The recalculated subtotal |
|
3582 | - */ |
|
3583 | - public function recalculate_subtotal() { |
|
3578 | + * Recalculates the invoice subtotal. |
|
3579 | + * |
|
3580 | + * @since 1.0.19 |
|
3581 | + * @return float The recalculated subtotal |
|
3582 | + */ |
|
3583 | + public function recalculate_subtotal() { |
|
3584 | 3584 | $items = $this->get_items(); |
3585 | - $subtotal = 0; |
|
3586 | - $recurring = 0; |
|
3585 | + $subtotal = 0; |
|
3586 | + $recurring = 0; |
|
3587 | 3587 | |
3588 | 3588 | foreach ( $items as $item ) { |
3589 | - $subtotal += $item->get_sub_total( 'edit' ); |
|
3590 | - $recurring += $item->get_recurring_sub_total( 'edit' ); |
|
3589 | + $subtotal += $item->get_sub_total( 'edit' ); |
|
3590 | + $recurring += $item->get_recurring_sub_total( 'edit' ); |
|
3591 | 3591 | } |
3592 | 3592 | |
3593 | - if ( wpinv_prices_include_tax() ) { |
|
3594 | - $subtotal = max( 0, $subtotal - $this->totals['tax']['initial'] ); |
|
3595 | - $recurring = max( 0, $recurring - $this->totals['tax']['recurring'] ); |
|
3596 | - } |
|
3593 | + if ( wpinv_prices_include_tax() ) { |
|
3594 | + $subtotal = max( 0, $subtotal - $this->totals['tax']['initial'] ); |
|
3595 | + $recurring = max( 0, $recurring - $this->totals['tax']['recurring'] ); |
|
3596 | + } |
|
3597 | 3597 | |
3598 | - $current = $this->is_renewal() ? $recurring : $subtotal; |
|
3599 | - $this->set_subtotal( $current ); |
|
3598 | + $current = $this->is_renewal() ? $recurring : $subtotal; |
|
3599 | + $this->set_subtotal( $current ); |
|
3600 | 3600 | |
3601 | - $this->totals['subtotal'] = array( |
|
3602 | - 'initial' => $subtotal, |
|
3603 | - 'recurring' => $recurring, |
|
3604 | - ); |
|
3601 | + $this->totals['subtotal'] = array( |
|
3602 | + 'initial' => $subtotal, |
|
3603 | + 'recurring' => $recurring, |
|
3604 | + ); |
|
3605 | 3605 | |
3606 | 3606 | return $current; |
3607 | 3607 | } |
3608 | 3608 | |
3609 | 3609 | /** |
3610 | - * Recalculates the invoice discount total. |
|
3611 | - * |
|
3612 | - * @since 1.0.19 |
|
3613 | - * @return float The recalculated discount |
|
3614 | - */ |
|
3615 | - public function recalculate_total_discount() { |
|
3610 | + * Recalculates the invoice discount total. |
|
3611 | + * |
|
3612 | + * @since 1.0.19 |
|
3613 | + * @return float The recalculated discount |
|
3614 | + */ |
|
3615 | + public function recalculate_total_discount() { |
|
3616 | 3616 | $discounts = $this->get_discounts(); |
3617 | - $discount = 0; |
|
3618 | - $recurring = 0; |
|
3617 | + $discount = 0; |
|
3618 | + $recurring = 0; |
|
3619 | 3619 | |
3620 | 3620 | foreach ( $discounts as $data ) { |
3621 | - $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
3622 | - $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
3623 | - } |
|
3621 | + $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
3622 | + $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
3623 | + } |
|
3624 | 3624 | |
3625 | - $current = $this->is_renewal() ? $recurring : $discount; |
|
3625 | + $current = $this->is_renewal() ? $recurring : $discount; |
|
3626 | 3626 | |
3627 | - $this->set_total_discount( $current ); |
|
3627 | + $this->set_total_discount( $current ); |
|
3628 | 3628 | |
3629 | - $this->totals['discount'] = array( |
|
3630 | - 'initial' => $discount, |
|
3631 | - 'recurring' => $recurring, |
|
3632 | - ); |
|
3629 | + $this->totals['discount'] = array( |
|
3630 | + 'initial' => $discount, |
|
3631 | + 'recurring' => $recurring, |
|
3632 | + ); |
|
3633 | 3633 | |
3634 | - return $current; |
|
3634 | + return $current; |
|
3635 | 3635 | |
3636 | 3636 | } |
3637 | 3637 | |
3638 | 3638 | /** |
3639 | - * Recalculates the invoice tax total. |
|
3640 | - * |
|
3641 | - * @since 1.0.19 |
|
3642 | - * @return float The recalculated tax |
|
3643 | - */ |
|
3644 | - public function recalculate_total_tax() { |
|
3639 | + * Recalculates the invoice tax total. |
|
3640 | + * |
|
3641 | + * @since 1.0.19 |
|
3642 | + * @return float The recalculated tax |
|
3643 | + */ |
|
3644 | + public function recalculate_total_tax() { |
|
3645 | 3645 | |
3646 | - // Maybe disable taxes. |
|
3647 | - $vat_number = $this->get_vat_number(); |
|
3648 | - $skip_tax = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number ); |
|
3646 | + // Maybe disable taxes. |
|
3647 | + $vat_number = $this->get_vat_number(); |
|
3648 | + $skip_tax = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number ); |
|
3649 | 3649 | |
3650 | - if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' === wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
3651 | - $skip_tax = false; |
|
3652 | - } |
|
3650 | + if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' === wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
3651 | + $skip_tax = false; |
|
3652 | + } |
|
3653 | 3653 | |
3654 | - if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax ) { |
|
3654 | + if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax ) { |
|
3655 | 3655 | |
3656 | - $this->totals['tax'] = array( |
|
3657 | - 'initial' => 0, |
|
3658 | - 'recurring' => 0, |
|
3659 | - ); |
|
3656 | + $this->totals['tax'] = array( |
|
3657 | + 'initial' => 0, |
|
3658 | + 'recurring' => 0, |
|
3659 | + ); |
|
3660 | 3660 | |
3661 | - $this->tax_rate = 0; |
|
3661 | + $this->tax_rate = 0; |
|
3662 | 3662 | |
3663 | - $this->set_taxes( array() ); |
|
3664 | - $current = 0; |
|
3665 | - } else { |
|
3663 | + $this->set_taxes( array() ); |
|
3664 | + $current = 0; |
|
3665 | + } else { |
|
3666 | 3666 | |
3667 | - $item_taxes = array(); |
|
3667 | + $item_taxes = array(); |
|
3668 | 3668 | |
3669 | - foreach ( $this->get_items() as $item ) { |
|
3670 | - $rates = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() ); |
|
3671 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
3672 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
3673 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
3674 | - foreach ( $taxes as $name => $amount ) { |
|
3675 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
3676 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
3669 | + foreach ( $this->get_items() as $item ) { |
|
3670 | + $rates = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() ); |
|
3671 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
3672 | + $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
3673 | + $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
3674 | + foreach ( $taxes as $name => $amount ) { |
|
3675 | + $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
3676 | + $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
3677 | 3677 | |
3678 | - if ( ! isset( $item_taxes[ $name ] ) ) { |
|
3679 | - $item_taxes[ $name ] = $tax; |
|
3680 | - continue; |
|
3681 | - } |
|
3678 | + if ( ! isset( $item_taxes[ $name ] ) ) { |
|
3679 | + $item_taxes[ $name ] = $tax; |
|
3680 | + continue; |
|
3681 | + } |
|
3682 | 3682 | |
3683 | - $item_taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
3684 | - $item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
3683 | + $item_taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
3684 | + $item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
3685 | 3685 | |
3686 | - } |
|
3687 | - } |
|
3686 | + } |
|
3687 | + } |
|
3688 | 3688 | |
3689 | - $item_taxes = array_replace( $this->get_taxes(), $item_taxes ); |
|
3690 | - $this->set_taxes( $item_taxes ); |
|
3689 | + $item_taxes = array_replace( $this->get_taxes(), $item_taxes ); |
|
3690 | + $this->set_taxes( $item_taxes ); |
|
3691 | 3691 | |
3692 | - $initial_tax = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) ); |
|
3693 | - $recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) ); |
|
3692 | + $initial_tax = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) ); |
|
3693 | + $recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) ); |
|
3694 | 3694 | |
3695 | - $current = $this->is_renewal() ? $recurring_tax : $initial_tax; |
|
3695 | + $current = $this->is_renewal() ? $recurring_tax : $initial_tax; |
|
3696 | 3696 | |
3697 | - $this->totals['tax'] = array( |
|
3698 | - 'initial' => $initial_tax, |
|
3699 | - 'recurring' => $recurring_tax, |
|
3700 | - ); |
|
3697 | + $this->totals['tax'] = array( |
|
3698 | + 'initial' => $initial_tax, |
|
3699 | + 'recurring' => $recurring_tax, |
|
3700 | + ); |
|
3701 | 3701 | |
3702 | - } |
|
3702 | + } |
|
3703 | 3703 | |
3704 | - $this->set_total_tax( $current ); |
|
3704 | + $this->set_total_tax( $current ); |
|
3705 | 3705 | |
3706 | - return $current; |
|
3706 | + return $current; |
|
3707 | 3707 | |
3708 | 3708 | } |
3709 | 3709 | |
3710 | 3710 | /** |
3711 | - * Recalculates the invoice fees total. |
|
3712 | - * |
|
3713 | - * @since 1.0.19 |
|
3714 | - * @return float The recalculated fee |
|
3715 | - */ |
|
3716 | - public function recalculate_total_fees() { |
|
3717 | - $fees = $this->get_fees(); |
|
3718 | - $fee = 0; |
|
3719 | - $recurring = 0; |
|
3711 | + * Recalculates the invoice fees total. |
|
3712 | + * |
|
3713 | + * @since 1.0.19 |
|
3714 | + * @return float The recalculated fee |
|
3715 | + */ |
|
3716 | + public function recalculate_total_fees() { |
|
3717 | + $fees = $this->get_fees(); |
|
3718 | + $fee = 0; |
|
3719 | + $recurring = 0; |
|
3720 | 3720 | |
3721 | 3721 | foreach ( $fees as $data ) { |
3722 | - $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
3723 | - $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
3724 | - } |
|
3722 | + $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
3723 | + $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
3724 | + } |
|
3725 | 3725 | |
3726 | - $current = $this->is_renewal() ? $recurring : $fee; |
|
3727 | - $this->set_total_fees( $current ); |
|
3726 | + $current = $this->is_renewal() ? $recurring : $fee; |
|
3727 | + $this->set_total_fees( $current ); |
|
3728 | 3728 | |
3729 | - $this->totals['fee'] = array( |
|
3730 | - 'initial' => $fee, |
|
3731 | - 'recurring' => $recurring, |
|
3732 | - ); |
|
3729 | + $this->totals['fee'] = array( |
|
3730 | + 'initial' => $fee, |
|
3731 | + 'recurring' => $recurring, |
|
3732 | + ); |
|
3733 | 3733 | |
3734 | 3734 | $this->set_total_fees( $fee ); |
3735 | 3735 | return $current; |
3736 | 3736 | } |
3737 | 3737 | |
3738 | 3738 | /** |
3739 | - * Recalculates the invoice total. |
|
3740 | - * |
|
3741 | - * @since 1.0.19 |
|
3739 | + * Recalculates the invoice total. |
|
3740 | + * |
|
3741 | + * @since 1.0.19 |
|
3742 | 3742 | * @return float The invoice total |
3743 | - */ |
|
3744 | - public function recalculate_total() { |
|
3743 | + */ |
|
3744 | + public function recalculate_total() { |
|
3745 | 3745 | $this->recalculate_total_fees(); |
3746 | 3746 | $this->recalculate_total_discount(); |
3747 | - $this->recalculate_total_tax(); |
|
3748 | - $this->recalculate_subtotal(); |
|
3749 | - $this->set_total( $this->get_total_tax( 'edit' ) + $this->get_total_fees( 'edit' ) + $this->get_subtotal( 'edit' ) - $this->get_total_discount( 'edit' ) ); |
|
3750 | - return $this->get_total(); |
|
3751 | - } |
|
3752 | - |
|
3753 | - /** |
|
3754 | - * @deprecated |
|
3755 | - */ |
|
3747 | + $this->recalculate_total_tax(); |
|
3748 | + $this->recalculate_subtotal(); |
|
3749 | + $this->set_total( $this->get_total_tax( 'edit' ) + $this->get_total_fees( 'edit' ) + $this->get_subtotal( 'edit' ) - $this->get_total_discount( 'edit' ) ); |
|
3750 | + return $this->get_total(); |
|
3751 | + } |
|
3752 | + |
|
3753 | + /** |
|
3754 | + * @deprecated |
|
3755 | + */ |
|
3756 | 3756 | public function recalculate_totals() { |
3757 | 3757 | $this->recalculate_total(); |
3758 | 3758 | $this->save( true ); |
@@ -3766,22 +3766,22 @@ discard block |
||
3766 | 3766 | return $this->get_data(); |
3767 | 3767 | } |
3768 | 3768 | |
3769 | - /** |
|
3769 | + /** |
|
3770 | 3770 | * Adds a system note to an invoice. |
3771 | 3771 | * |
3772 | 3772 | * @param string $note The note being added. |
3773 | - * @return int|false The new note's ID on success, false on failure. |
|
3773 | + * @return int|false The new note's ID on success, false on failure. |
|
3774 | 3774 | * |
3775 | 3775 | */ |
3776 | 3776 | public function add_system_note( $note ) { |
3777 | - return $this->add_note( $note, false, false, true ); |
|
3778 | - } |
|
3777 | + return $this->add_note( $note, false, false, true ); |
|
3778 | + } |
|
3779 | 3779 | |
3780 | 3780 | /** |
3781 | 3781 | * Adds a note to an invoice. |
3782 | 3782 | * |
3783 | 3783 | * @param string $note The note being added. |
3784 | - * @return int|false The new note's ID on success, false on failure. |
|
3784 | + * @return int|false The new note's ID on success, false on failure. |
|
3785 | 3785 | * |
3786 | 3786 | */ |
3787 | 3787 | public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
@@ -3791,21 +3791,21 @@ discard block |
||
3791 | 3791 | return false; |
3792 | 3792 | } |
3793 | 3793 | |
3794 | - $author = 'System'; |
|
3795 | - $author_email = '[email protected]'; |
|
3794 | + $author = 'System'; |
|
3795 | + $author_email = '[email protected]'; |
|
3796 | 3796 | |
3797 | - // If this is an admin comment or it has been added by the user. |
|
3798 | - if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
3799 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
3797 | + // If this is an admin comment or it has been added by the user. |
|
3798 | + if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
3799 | + $user = get_user_by( 'id', get_current_user_id() ); |
|
3800 | 3800 | $author = $user->display_name; |
3801 | 3801 | $author_email = $user->user_email; |
3802 | - } |
|
3802 | + } |
|
3803 | 3803 | |
3804 | - return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
3804 | + return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
3805 | 3805 | |
3806 | - } |
|
3806 | + } |
|
3807 | 3807 | |
3808 | - /** |
|
3808 | + /** |
|
3809 | 3809 | * Generates a unique key for the invoice. |
3810 | 3810 | */ |
3811 | 3811 | public function generate_key( $string = '' ) { |
@@ -3825,113 +3825,113 @@ discard block |
||
3825 | 3825 | $number = wpinv_get_next_invoice_number( $this->get_post_type() ); |
3826 | 3826 | } |
3827 | 3827 | |
3828 | - return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
3829 | - |
|
3830 | - } |
|
3831 | - |
|
3832 | - /** |
|
3833 | - * Handle the status transition. |
|
3834 | - */ |
|
3835 | - protected function status_transition() { |
|
3836 | - $status_transition = $this->status_transition; |
|
3837 | - |
|
3838 | - // Reset status transition variable. |
|
3839 | - $this->status_transition = false; |
|
3840 | - |
|
3841 | - if ( $status_transition ) { |
|
3842 | - try { |
|
3843 | - |
|
3844 | - // Fire a hook for the status change. |
|
3845 | - do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
3846 | - |
|
3847 | - // @deprecated this is deprecated and will be removed in the future. |
|
3848 | - do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3849 | - |
|
3850 | - if ( ! empty( $status_transition['from'] ) ) { |
|
3851 | - |
|
3852 | - /* translators: 1: old invoice status 2: new invoice status */ |
|
3853 | - $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
3854 | - |
|
3855 | - // Fire another hook. |
|
3856 | - do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
3857 | - do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
3828 | + return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
3858 | 3829 | |
3859 | - // @deprecated this is deprecated and will be removed in the future. |
|
3860 | - do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3861 | - |
|
3862 | - // Note the transition occurred. |
|
3863 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
3864 | - |
|
3865 | - // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
3866 | - if ( |
|
3867 | - in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
3868 | - && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3869 | - ) { |
|
3870 | - do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
3871 | - } |
|
3872 | - |
|
3873 | - // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
|
3874 | - if ( |
|
3875 | - in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3876 | - && in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
3877 | - ) { |
|
3878 | - do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
3879 | - } |
|
3880 | - } else { |
|
3881 | - /* translators: %s: new invoice status */ |
|
3882 | - $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
3883 | - |
|
3884 | - // Note the transition occurred. |
|
3885 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
3830 | + } |
|
3886 | 3831 | |
3887 | - } |
|
3888 | - } catch ( Exception $e ) { |
|
3889 | - $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
3890 | - } |
|
3891 | - } |
|
3892 | - } |
|
3832 | + /** |
|
3833 | + * Handle the status transition. |
|
3834 | + */ |
|
3835 | + protected function status_transition() { |
|
3836 | + $status_transition = $this->status_transition; |
|
3837 | + |
|
3838 | + // Reset status transition variable. |
|
3839 | + $this->status_transition = false; |
|
3840 | + |
|
3841 | + if ( $status_transition ) { |
|
3842 | + try { |
|
3843 | + |
|
3844 | + // Fire a hook for the status change. |
|
3845 | + do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
3846 | + |
|
3847 | + // @deprecated this is deprecated and will be removed in the future. |
|
3848 | + do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3849 | + |
|
3850 | + if ( ! empty( $status_transition['from'] ) ) { |
|
3851 | + |
|
3852 | + /* translators: 1: old invoice status 2: new invoice status */ |
|
3853 | + $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
3854 | + |
|
3855 | + // Fire another hook. |
|
3856 | + do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
3857 | + do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
3858 | + |
|
3859 | + // @deprecated this is deprecated and will be removed in the future. |
|
3860 | + do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3861 | + |
|
3862 | + // Note the transition occurred. |
|
3863 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
3864 | + |
|
3865 | + // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
3866 | + if ( |
|
3867 | + in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
3868 | + && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3869 | + ) { |
|
3870 | + do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
3871 | + } |
|
3872 | + |
|
3873 | + // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
|
3874 | + if ( |
|
3875 | + in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3876 | + && in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
3877 | + ) { |
|
3878 | + do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
3879 | + } |
|
3880 | + } else { |
|
3881 | + /* translators: %s: new invoice status */ |
|
3882 | + $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
3883 | + |
|
3884 | + // Note the transition occurred. |
|
3885 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
3886 | + |
|
3887 | + } |
|
3888 | + } catch ( Exception $e ) { |
|
3889 | + $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
3890 | + } |
|
3891 | + } |
|
3892 | + } |
|
3893 | 3893 | |
3894 | - /** |
|
3895 | - * Updates an invoice status. |
|
3896 | - */ |
|
3897 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
3894 | + /** |
|
3895 | + * Updates an invoice status. |
|
3896 | + */ |
|
3897 | + public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
3898 | 3898 | |
3899 | - // Fires before updating a status. |
|
3900 | - do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
3899 | + // Fires before updating a status. |
|
3900 | + do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
3901 | 3901 | |
3902 | - // Update the status. |
|
3903 | - $this->set_status( $new_status, $note, $manual ); |
|
3902 | + // Update the status. |
|
3903 | + $this->set_status( $new_status, $note, $manual ); |
|
3904 | 3904 | |
3905 | - // Save the order. |
|
3906 | - return $this->save(); |
|
3905 | + // Save the order. |
|
3906 | + return $this->save(); |
|
3907 | 3907 | |
3908 | - } |
|
3908 | + } |
|
3909 | 3909 | |
3910 | - /** |
|
3911 | - * @deprecated |
|
3912 | - */ |
|
3913 | - public function refresh_item_ids() { |
|
3910 | + /** |
|
3911 | + * @deprecated |
|
3912 | + */ |
|
3913 | + public function refresh_item_ids() { |
|
3914 | 3914 | $item_ids = implode( ',', array_unique( wp_list_pluck( $this->get_cart_details(), 'item_id' ) ) ); |
3915 | 3915 | update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids ); |
3916 | - } |
|
3916 | + } |
|
3917 | 3917 | |
3918 | - /** |
|
3919 | - * @deprecated |
|
3920 | - */ |
|
3921 | - public function update_items( $temp = false ) { |
|
3918 | + /** |
|
3919 | + * @deprecated |
|
3920 | + */ |
|
3921 | + public function update_items( $temp = false ) { |
|
3922 | 3922 | |
3923 | - $this->set_items( $this->get_items() ); |
|
3923 | + $this->set_items( $this->get_items() ); |
|
3924 | 3924 | |
3925 | - if ( ! $temp ) { |
|
3926 | - $this->save(); |
|
3927 | - } |
|
3925 | + if ( ! $temp ) { |
|
3926 | + $this->save(); |
|
3927 | + } |
|
3928 | 3928 | |
3929 | 3929 | return $this; |
3930 | - } |
|
3930 | + } |
|
3931 | 3931 | |
3932 | - /** |
|
3933 | - * @deprecated |
|
3934 | - */ |
|
3932 | + /** |
|
3933 | + * @deprecated |
|
3934 | + */ |
|
3935 | 3935 | public function validate_discount() { |
3936 | 3936 | |
3937 | 3937 | $discount_code = $this->get_discount_code(); |
@@ -3947,101 +3947,101 @@ discard block |
||
3947 | 3947 | |
3948 | 3948 | } |
3949 | 3949 | |
3950 | - /** |
|
3951 | - * Refunds an invoice. |
|
3952 | - */ |
|
3950 | + /** |
|
3951 | + * Refunds an invoice. |
|
3952 | + */ |
|
3953 | 3953 | public function refund() { |
3954 | - $this->set_status( 'wpi-refunded' ); |
|
3954 | + $this->set_status( 'wpi-refunded' ); |
|
3955 | 3955 | $this->save(); |
3956 | - } |
|
3956 | + } |
|
3957 | 3957 | |
3958 | - /** |
|
3959 | - * Marks an invoice as paid. |
|
3960 | - * |
|
3961 | - * @param string $transaction_id |
|
3962 | - */ |
|
3958 | + /** |
|
3959 | + * Marks an invoice as paid. |
|
3960 | + * |
|
3961 | + * @param string $transaction_id |
|
3962 | + */ |
|
3963 | 3963 | public function mark_paid( $transaction_id = null, $note = '' ) { |
3964 | 3964 | |
3965 | - // Set the transaction id. |
|
3966 | - if ( empty( $transaction_id ) ) { |
|
3967 | - $transaction_id = $this->generate_key( 'trans_' ); |
|
3968 | - } |
|
3965 | + // Set the transaction id. |
|
3966 | + if ( empty( $transaction_id ) ) { |
|
3967 | + $transaction_id = $this->generate_key( 'trans_' ); |
|
3968 | + } |
|
3969 | 3969 | |
3970 | - if ( ! $this->get_transaction_id() ) { |
|
3971 | - $this->set_transaction_id( $transaction_id ); |
|
3972 | - } |
|
3970 | + if ( ! $this->get_transaction_id() ) { |
|
3971 | + $this->set_transaction_id( $transaction_id ); |
|
3972 | + } |
|
3973 | 3973 | |
3974 | - if ( $this->is_paid() && 'wpi-processing' !== $this->get_status() ) { |
|
3975 | - return $this->save(); |
|
3976 | - } |
|
3974 | + if ( $this->is_paid() && 'wpi-processing' !== $this->get_status() ) { |
|
3975 | + return $this->save(); |
|
3976 | + } |
|
3977 | 3977 | |
3978 | - // Set the completed date. |
|
3979 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
3978 | + // Set the completed date. |
|
3979 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
3980 | 3980 | |
3981 | - // Set the new status. |
|
3982 | - $gateway = sanitize_text_field( $this->get_gateway_title() ); |
|
3983 | - if ( $this->is_renewal() || ! $this->is_parent() ) { |
|
3981 | + // Set the new status. |
|
3982 | + $gateway = sanitize_text_field( $this->get_gateway_title() ); |
|
3983 | + if ( $this->is_renewal() || ! $this->is_parent() ) { |
|
3984 | 3984 | |
3985 | - $_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway ); |
|
3986 | - $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
3985 | + $_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway ); |
|
3986 | + $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
3987 | 3987 | |
3988 | - if ( 'none' == $this->get_gateway() ) { |
|
3989 | - $_note = $note; |
|
3990 | - } |
|
3988 | + if ( 'none' == $this->get_gateway() ) { |
|
3989 | + $_note = $note; |
|
3990 | + } |
|
3991 | 3991 | |
3992 | - $this->set_status( 'wpi-renewal', $_note ); |
|
3992 | + $this->set_status( 'wpi-renewal', $_note ); |
|
3993 | 3993 | |
3994 | - } else { |
|
3994 | + } else { |
|
3995 | 3995 | |
3996 | - $_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway ); |
|
3997 | - $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
3996 | + $_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway ); |
|
3997 | + $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
3998 | 3998 | |
3999 | - if ( 'none' == $this->get_gateway() ) { |
|
4000 | - $_note = $note; |
|
4001 | - } |
|
3999 | + if ( 'none' == $this->get_gateway() ) { |
|
4000 | + $_note = $note; |
|
4001 | + } |
|
4002 | 4002 | |
4003 | - $this->set_status( 'publish', $_note ); |
|
4003 | + $this->set_status( 'publish', $_note ); |
|
4004 | 4004 | |
4005 | - } |
|
4005 | + } |
|
4006 | 4006 | |
4007 | - // Set checkout mode. |
|
4008 | - $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
4009 | - $this->set_mode( $mode ); |
|
4007 | + // Set checkout mode. |
|
4008 | + $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
4009 | + $this->set_mode( $mode ); |
|
4010 | 4010 | |
4011 | - // Save the invoice. |
|
4011 | + // Save the invoice. |
|
4012 | 4012 | $this->save(); |
4013 | - } |
|
4014 | - |
|
4015 | - /** |
|
4016 | - * Save data to the database. |
|
4017 | - * |
|
4018 | - * @since 1.0.19 |
|
4019 | - * @return int invoice ID |
|
4020 | - */ |
|
4021 | - public function save() { |
|
4022 | - $this->maybe_set_date_paid(); |
|
4023 | - $this->maybe_set_key(); |
|
4024 | - parent::save(); |
|
4025 | - $this->clear_cache(); |
|
4026 | - $this->status_transition(); |
|
4027 | - return $this->get_id(); |
|
4028 | - } |
|
4029 | - |
|
4030 | - /** |
|
4013 | + } |
|
4014 | + |
|
4015 | + /** |
|
4016 | + * Save data to the database. |
|
4017 | + * |
|
4018 | + * @since 1.0.19 |
|
4019 | + * @return int invoice ID |
|
4020 | + */ |
|
4021 | + public function save() { |
|
4022 | + $this->maybe_set_date_paid(); |
|
4023 | + $this->maybe_set_key(); |
|
4024 | + parent::save(); |
|
4025 | + $this->clear_cache(); |
|
4026 | + $this->status_transition(); |
|
4027 | + return $this->get_id(); |
|
4028 | + } |
|
4029 | + |
|
4030 | + /** |
|
4031 | 4031 | * Clears the subscription's cache. |
4032 | 4032 | */ |
4033 | 4033 | public function clear_cache() { |
4034 | - if ( $this->get_key() ) { |
|
4035 | - wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
4036 | - } |
|
4037 | - |
|
4038 | - if ( $this->get_number() ) { |
|
4039 | - wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
4040 | - } |
|
4041 | - |
|
4042 | - if ( $this->get_transaction_id() ) { |
|
4043 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
4044 | - } |
|
4045 | - } |
|
4034 | + if ( $this->get_key() ) { |
|
4035 | + wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
4036 | + } |
|
4037 | + |
|
4038 | + if ( $this->get_number() ) { |
|
4039 | + wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
4040 | + } |
|
4041 | + |
|
4042 | + if ( $this->get_transaction_id() ) { |
|
4043 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
4044 | + } |
|
4045 | + } |
|
4046 | 4046 | |
4047 | 4047 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | */ |
15 | 15 | function wpinv_subscriptions_page() { |
16 | 16 | |
17 | - ?> |
|
17 | + ?> |
|
18 | 18 | |
19 | 19 | <div class="wrap"> |
20 | 20 | <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
@@ -22,28 +22,28 @@ discard block |
||
22 | 22 | |
23 | 23 | <?php |
24 | 24 | |
25 | - // Verify user permissions. |
|
26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
25 | + // Verify user permissions. |
|
26 | + if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
27 | 27 | |
28 | - aui()->alert( |
|
28 | + aui()->alert( |
|
29 | 29 | array( |
30 | - 'type' => 'danger', |
|
31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
32 | - ), |
|
33 | - true |
|
30 | + 'type' => 'danger', |
|
31 | + 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
32 | + ), |
|
33 | + true |
|
34 | 34 | ); |
35 | 35 | |
36 | - } elseif ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
36 | + } elseif ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
37 | 37 | |
38 | - // Display a single subscription. |
|
39 | - wpinv_recurring_subscription_details(); |
|
40 | - } else { |
|
38 | + // Display a single subscription. |
|
39 | + wpinv_recurring_subscription_details(); |
|
40 | + } else { |
|
41 | 41 | |
42 | - // Display a list of available subscriptions. |
|
43 | - getpaid_print_subscriptions_list(); |
|
44 | - } |
|
42 | + // Display a list of available subscriptions. |
|
43 | + getpaid_print_subscriptions_list(); |
|
44 | + } |
|
45 | 45 | |
46 | - ?> |
|
46 | + ?> |
|
47 | 47 | |
48 | 48 | </div> |
49 | 49 | </div> |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | */ |
61 | 61 | function getpaid_print_subscriptions_list() { |
62 | 62 | |
63 | - $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
64 | - $subscribers_table->prepare_items(); |
|
63 | + $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
64 | + $subscribers_table->prepare_items(); |
|
65 | 65 | |
66 | - ?> |
|
66 | + ?> |
|
67 | 67 | <?php $subscribers_table->views(); ?> |
68 | 68 | <form id="subscribers-filter" class="bsui" method="get"> |
69 | 69 | <input type="hidden" name="page" value="wpinv-subscriptions" /> |
@@ -82,42 +82,42 @@ discard block |
||
82 | 82 | */ |
83 | 83 | function wpinv_recurring_subscription_details() { |
84 | 84 | |
85 | - // Fetch the subscription. |
|
86 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
87 | - if ( ! $sub->exists() ) { |
|
85 | + // Fetch the subscription. |
|
86 | + $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
87 | + if ( ! $sub->exists() ) { |
|
88 | 88 | |
89 | - aui()->alert( |
|
90 | - array( |
|
91 | - 'type' => 'danger', |
|
92 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
93 | - ), |
|
94 | - true |
|
95 | - ); |
|
89 | + aui()->alert( |
|
90 | + array( |
|
91 | + 'type' => 'danger', |
|
92 | + 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
93 | + ), |
|
94 | + true |
|
95 | + ); |
|
96 | 96 | |
97 | - return; |
|
98 | - } |
|
97 | + return; |
|
98 | + } |
|
99 | 99 | |
100 | - // Use metaboxes to display the subscription details. |
|
101 | - add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' ); |
|
102 | - add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
100 | + // Use metaboxes to display the subscription details. |
|
101 | + add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' ); |
|
102 | + add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
103 | 103 | |
104 | - $subscription_id = $sub->get_id(); |
|
105 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() ); |
|
106 | - $subscription_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
104 | + $subscription_id = $sub->get_id(); |
|
105 | + $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() ); |
|
106 | + $subscription_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
107 | 107 | |
108 | - if ( 1 < count( $subscription_groups ) ) { |
|
109 | - add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' ); |
|
110 | - } |
|
108 | + if ( 1 < count( $subscription_groups ) ) { |
|
109 | + add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' ); |
|
110 | + } |
|
111 | 111 | |
112 | - if ( ! empty( $subscription_group ) ) { |
|
113 | - add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' ); |
|
114 | - } |
|
112 | + if ( ! empty( $subscription_group ) ) { |
|
113 | + add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' ); |
|
114 | + } |
|
115 | 115 | |
116 | - add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
116 | + add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
117 | 117 | |
118 | - do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
118 | + do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
119 | 119 | |
120 | - ?> |
|
120 | + ?> |
|
121 | 121 | |
122 | 122 | <form method="post" action="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ) ); ?>"> |
123 | 123 | |
@@ -157,49 +157,49 @@ discard block |
||
157 | 157 | */ |
158 | 158 | function getpaid_admin_subscription_details_metabox( $sub ) { |
159 | 159 | |
160 | - // Subscription items. |
|
161 | - $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() ); |
|
162 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
163 | - |
|
164 | - // Prepare subscription detail columns. |
|
165 | - $fields = apply_filters( |
|
166 | - 'getpaid_subscription_admin_page_fields', |
|
167 | - array( |
|
168 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
169 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
170 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
171 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
172 | - 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
173 | - 'renewals' => __( 'Collected Payments', 'invoicing' ), |
|
174 | - 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
175 | - 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
176 | - 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
177 | - 'status' => __( 'Status', 'invoicing' ), |
|
178 | - ) |
|
179 | - ); |
|
180 | - |
|
181 | - if ( ! $sub->is_active() ) { |
|
182 | - |
|
183 | - if ( isset( $fields['renews_on'] ) ) { |
|
184 | - unset( $fields['renews_on'] ); |
|
185 | - } |
|
186 | - |
|
187 | - if ( isset( $fields['gateway'] ) ) { |
|
188 | - unset( $fields['gateway'] ); |
|
189 | - } |
|
190 | - } elseif ( $sub->is_last_renewal() ) { |
|
191 | - |
|
192 | - if ( isset( $fields['renews_on'] ) ) { |
|
193 | - $fields['renews_on'] = __( 'End Date', 'invoicing' ); |
|
194 | - } |
|
195 | - } |
|
196 | - |
|
197 | - $profile_id = $sub->get_profile_id(); |
|
198 | - if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
199 | - unset( $fields['profile_id'] ); |
|
200 | - } |
|
201 | - |
|
202 | - ?> |
|
160 | + // Subscription items. |
|
161 | + $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() ); |
|
162 | + $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
163 | + |
|
164 | + // Prepare subscription detail columns. |
|
165 | + $fields = apply_filters( |
|
166 | + 'getpaid_subscription_admin_page_fields', |
|
167 | + array( |
|
168 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
169 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
170 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
171 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
172 | + 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
173 | + 'renewals' => __( 'Collected Payments', 'invoicing' ), |
|
174 | + 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
175 | + 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
176 | + 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
177 | + 'status' => __( 'Status', 'invoicing' ), |
|
178 | + ) |
|
179 | + ); |
|
180 | + |
|
181 | + if ( ! $sub->is_active() ) { |
|
182 | + |
|
183 | + if ( isset( $fields['renews_on'] ) ) { |
|
184 | + unset( $fields['renews_on'] ); |
|
185 | + } |
|
186 | + |
|
187 | + if ( isset( $fields['gateway'] ) ) { |
|
188 | + unset( $fields['gateway'] ); |
|
189 | + } |
|
190 | + } elseif ( $sub->is_last_renewal() ) { |
|
191 | + |
|
192 | + if ( isset( $fields['renews_on'] ) ) { |
|
193 | + $fields['renews_on'] = __( 'End Date', 'invoicing' ); |
|
194 | + } |
|
195 | + } |
|
196 | + |
|
197 | + $profile_id = $sub->get_profile_id(); |
|
198 | + if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
199 | + unset( $fields['profile_id'] ); |
|
200 | + } |
|
201 | + |
|
202 | + ?> |
|
203 | 203 | |
204 | 204 | <table class="table table-borderless" style="font-size: 14px;"> |
205 | 205 | <tbody> |
@@ -233,20 +233,20 @@ discard block |
||
233 | 233 | */ |
234 | 234 | function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
235 | 235 | |
236 | - $username = __( '(Missing User)', 'invoicing' ); |
|
236 | + $username = __( '(Missing User)', 'invoicing' ); |
|
237 | 237 | |
238 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
239 | - if ( $user ) { |
|
238 | + $user = get_userdata( $subscription->get_customer_id() ); |
|
239 | + if ( $user ) { |
|
240 | 240 | |
241 | - $username = sprintf( |
|
242 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
243 | - absint( $user->ID ), |
|
244 | - ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
245 | - ); |
|
241 | + $username = sprintf( |
|
242 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
243 | + absint( $user->ID ), |
|
244 | + ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
245 | + ); |
|
246 | 246 | |
247 | - } |
|
247 | + } |
|
248 | 248 | |
249 | - echo wp_kses_post( $username ); |
|
249 | + echo wp_kses_post( $username ); |
|
250 | 250 | } |
251 | 251 | add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
252 | 252 | |
@@ -256,8 +256,8 @@ discard block |
||
256 | 256 | * @param WPInv_Subscription $subscription |
257 | 257 | */ |
258 | 258 | function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
259 | - $amount = getpaid_get_formatted_subscription_amount( $subscription ); |
|
260 | - echo wp_kses_post( "<span>$amount</span>" ); |
|
259 | + $amount = getpaid_get_formatted_subscription_amount( $subscription ); |
|
260 | + echo wp_kses_post( "<span>$amount</span>" ); |
|
261 | 261 | } |
262 | 262 | add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
263 | 263 | |
@@ -268,11 +268,11 @@ discard block |
||
268 | 268 | */ |
269 | 269 | function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
270 | 270 | |
271 | - printf( |
|
272 | - '<a href="%s">#%s</a>', |
|
273 | - esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $subscription->get_id() ) ) ), |
|
274 | - absint( $subscription->get_id() ) |
|
275 | - ); |
|
271 | + printf( |
|
272 | + '<a href="%s">#%s</a>', |
|
273 | + esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $subscription->get_id() ) ) ), |
|
274 | + absint( $subscription->get_id() ) |
|
275 | + ); |
|
276 | 276 | |
277 | 277 | } |
278 | 278 | add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
@@ -284,24 +284,24 @@ discard block |
||
284 | 284 | */ |
285 | 285 | function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
286 | 286 | |
287 | - if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_date_change' ) ) { |
|
288 | - aui()->input( |
|
289 | - array( |
|
290 | - 'type' => 'text', |
|
291 | - 'id' => 'wpinv_subscription_date_created', |
|
292 | - 'name' => 'wpinv_subscription_date_created', |
|
293 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
294 | - 'label_type' => 'hidden', |
|
295 | - 'placeholder' => 'YYYY-MM-DD', |
|
296 | - 'value' => esc_attr( $subscription->get_date_created( 'edit' ) ), |
|
297 | - 'no_wrap' => true, |
|
298 | - 'size' => 'sm', |
|
299 | - ), |
|
300 | - true |
|
301 | - ); |
|
302 | - } else { |
|
303 | - echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
304 | - } |
|
287 | + if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_date_change' ) ) { |
|
288 | + aui()->input( |
|
289 | + array( |
|
290 | + 'type' => 'text', |
|
291 | + 'id' => 'wpinv_subscription_date_created', |
|
292 | + 'name' => 'wpinv_subscription_date_created', |
|
293 | + 'label' => __( 'Start Date', 'invoicing' ), |
|
294 | + 'label_type' => 'hidden', |
|
295 | + 'placeholder' => 'YYYY-MM-DD', |
|
296 | + 'value' => esc_attr( $subscription->get_date_created( 'edit' ) ), |
|
297 | + 'no_wrap' => true, |
|
298 | + 'size' => 'sm', |
|
299 | + ), |
|
300 | + true |
|
301 | + ); |
|
302 | + } else { |
|
303 | + echo esc_html( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
304 | + } |
|
305 | 305 | |
306 | 306 | } |
307 | 307 | add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
@@ -313,24 +313,24 @@ discard block |
||
313 | 313 | */ |
314 | 314 | function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
315 | 315 | |
316 | - if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_date_change' ) ) { |
|
317 | - aui()->input( |
|
318 | - array( |
|
319 | - 'type' => 'text', |
|
320 | - 'id' => 'wpinv_subscription_expiration', |
|
321 | - 'name' => 'wpinv_subscription_expiration', |
|
322 | - 'label' => __( 'Renews On', 'invoicing' ), |
|
323 | - 'label_type' => 'hidden', |
|
324 | - 'placeholder' => 'YYYY-MM-DD', |
|
325 | - 'value' => esc_attr( $subscription->get_expiration( 'edit' ) ), |
|
326 | - 'no_wrap' => true, |
|
327 | - 'size' => 'sm', |
|
328 | - ), |
|
329 | - true |
|
330 | - ); |
|
331 | - } else { |
|
332 | - echo esc_html( getpaid_format_date_value( $subscription->get_expiration() ) ); |
|
333 | - } |
|
316 | + if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_date_change' ) ) { |
|
317 | + aui()->input( |
|
318 | + array( |
|
319 | + 'type' => 'text', |
|
320 | + 'id' => 'wpinv_subscription_expiration', |
|
321 | + 'name' => 'wpinv_subscription_expiration', |
|
322 | + 'label' => __( 'Renews On', 'invoicing' ), |
|
323 | + 'label_type' => 'hidden', |
|
324 | + 'placeholder' => 'YYYY-MM-DD', |
|
325 | + 'value' => esc_attr( $subscription->get_expiration( 'edit' ) ), |
|
326 | + 'no_wrap' => true, |
|
327 | + 'size' => 'sm', |
|
328 | + ), |
|
329 | + true |
|
330 | + ); |
|
331 | + } else { |
|
332 | + echo esc_html( getpaid_format_date_value( $subscription->get_expiration() ) ); |
|
333 | + } |
|
334 | 334 | } |
335 | 335 | add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
336 | 336 | |
@@ -341,32 +341,32 @@ discard block |
||
341 | 341 | */ |
342 | 342 | function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
343 | 343 | |
344 | - $max_bills = $subscription->get_bill_times(); |
|
345 | - $times_billed = (int) $subscription->get_times_billed(); |
|
346 | - |
|
347 | - if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_bill_times_change' ) ) { |
|
348 | - aui()->input( |
|
349 | - array( |
|
350 | - 'type' => 'number', |
|
351 | - 'id' => 'wpinv_subscription_max_bill_times', |
|
352 | - 'name' => 'wpinv_subscription_max_bill_times', |
|
353 | - 'label' => __( 'Maximum bill times', 'invoicing' ), |
|
354 | - 'label_type' => 'hidden', |
|
355 | - 'placeholder' => __( 'Unlimited', 'invoicing' ), |
|
356 | - 'value' => empty( $max_bills ) ? '' : (int) $max_bills, |
|
357 | - 'no_wrap' => true, |
|
358 | - 'size' => 'sm', |
|
359 | - 'input_group_left' => sprintf( |
|
360 | - // translators: %d: Number of times billed |
|
361 | - __( '%d of', 'invoicing' ), |
|
362 | - $times_billed |
|
363 | - ), |
|
364 | - ), |
|
365 | - true |
|
366 | - ); |
|
367 | - } else { |
|
368 | - echo esc_html( $times_billed ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
369 | - } |
|
344 | + $max_bills = $subscription->get_bill_times(); |
|
345 | + $times_billed = (int) $subscription->get_times_billed(); |
|
346 | + |
|
347 | + if ( $subscription->has_status( 'active trialling' ) && getpaid_payment_gateway_supports( $subscription->get_gateway(), 'subscription_bill_times_change' ) ) { |
|
348 | + aui()->input( |
|
349 | + array( |
|
350 | + 'type' => 'number', |
|
351 | + 'id' => 'wpinv_subscription_max_bill_times', |
|
352 | + 'name' => 'wpinv_subscription_max_bill_times', |
|
353 | + 'label' => __( 'Maximum bill times', 'invoicing' ), |
|
354 | + 'label_type' => 'hidden', |
|
355 | + 'placeholder' => __( 'Unlimited', 'invoicing' ), |
|
356 | + 'value' => empty( $max_bills ) ? '' : (int) $max_bills, |
|
357 | + 'no_wrap' => true, |
|
358 | + 'size' => 'sm', |
|
359 | + 'input_group_left' => sprintf( |
|
360 | + // translators: %d: Number of times billed |
|
361 | + __( '%d of', 'invoicing' ), |
|
362 | + $times_billed |
|
363 | + ), |
|
364 | + ), |
|
365 | + true |
|
366 | + ); |
|
367 | + } else { |
|
368 | + echo esc_html( $times_billed ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
369 | + } |
|
370 | 370 | } |
371 | 371 | add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
372 | 372 | |
@@ -378,13 +378,13 @@ discard block |
||
378 | 378 | */ |
379 | 379 | function getpaid_admin_subscription_metabox_display_item( $subscription, $subscription_group = false ) { |
380 | 380 | |
381 | - if ( empty( $subscription_group ) ) { |
|
382 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
383 | - return; |
|
384 | - } |
|
381 | + if ( empty( $subscription_group ) ) { |
|
382 | + echo wp_kses_post( WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ) ); |
|
383 | + return; |
|
384 | + } |
|
385 | 385 | |
386 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
387 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
386 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
387 | + echo wp_kses_post( implode( ' | ', $markup ) ); |
|
388 | 388 | |
389 | 389 | } |
390 | 390 | add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2 ); |
@@ -396,13 +396,13 @@ discard block |
||
396 | 396 | */ |
397 | 397 | function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
398 | 398 | |
399 | - $gateway = $subscription->get_gateway(); |
|
399 | + $gateway = $subscription->get_gateway(); |
|
400 | 400 | |
401 | - if ( ! empty( $gateway ) ) { |
|
402 | - echo esc_html( wpinv_get_gateway_admin_label( $gateway ) ); |
|
403 | - } else { |
|
404 | - echo '—'; |
|
405 | - } |
|
401 | + if ( ! empty( $gateway ) ) { |
|
402 | + echo esc_html( wpinv_get_gateway_admin_label( $gateway ) ); |
|
403 | + } else { |
|
404 | + echo '—'; |
|
405 | + } |
|
406 | 406 | |
407 | 407 | } |
408 | 408 | add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | * @param WPInv_Subscription $subscription |
414 | 414 | */ |
415 | 415 | function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
416 | - echo wp_kses_post( $subscription->get_status_label_html() ); |
|
416 | + echo wp_kses_post( $subscription->get_status_label_html() ); |
|
417 | 417 | } |
418 | 418 | add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
419 | 419 | |
@@ -424,28 +424,28 @@ discard block |
||
424 | 424 | */ |
425 | 425 | function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
426 | 426 | |
427 | - $profile_id = $subscription->get_profile_id(); |
|
428 | - |
|
429 | - aui()->input( |
|
430 | - array( |
|
431 | - 'type' => 'text', |
|
432 | - 'id' => 'wpinv_subscription_profile_id', |
|
433 | - 'name' => 'wpinv_subscription_profile_id', |
|
434 | - 'label' => __( 'Profile Id', 'invoicing' ), |
|
435 | - 'label_type' => 'hidden', |
|
436 | - 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
437 | - 'value' => esc_attr( $profile_id ), |
|
438 | - 'input_group_right' => '', |
|
439 | - 'no_wrap' => true, |
|
440 | - 'size' => 'sm', |
|
441 | - ), |
|
442 | - true |
|
443 | - ); |
|
444 | - |
|
445 | - $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
446 | - if ( ! empty( $url ) ) { |
|
447 | - echo ' <a href="' . esc_url_raw( $url ) . '" title="' . esc_attr__( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
448 | - } |
|
427 | + $profile_id = $subscription->get_profile_id(); |
|
428 | + |
|
429 | + aui()->input( |
|
430 | + array( |
|
431 | + 'type' => 'text', |
|
432 | + 'id' => 'wpinv_subscription_profile_id', |
|
433 | + 'name' => 'wpinv_subscription_profile_id', |
|
434 | + 'label' => __( 'Profile Id', 'invoicing' ), |
|
435 | + 'label_type' => 'hidden', |
|
436 | + 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
437 | + 'value' => esc_attr( $profile_id ), |
|
438 | + 'input_group_right' => '', |
|
439 | + 'no_wrap' => true, |
|
440 | + 'size' => 'sm', |
|
441 | + ), |
|
442 | + true |
|
443 | + ); |
|
444 | + |
|
445 | + $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
446 | + if ( ! empty( $url ) ) { |
|
447 | + echo ' <a href="' . esc_url_raw( $url ) . '" title="' . esc_attr__( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
448 | + } |
|
449 | 449 | |
450 | 450 | } |
451 | 451 | add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
@@ -457,40 +457,40 @@ discard block |
||
457 | 457 | */ |
458 | 458 | function getpaid_admin_subscription_update_metabox( $subscription ) { |
459 | 459 | |
460 | - ?> |
|
460 | + ?> |
|
461 | 461 | <div class="mt-3"> |
462 | 462 | |
463 | 463 | <?php |
464 | - aui()->select( |
|
465 | - array( |
|
466 | - 'options' => getpaid_get_subscription_statuses(), |
|
467 | - 'name' => 'subscription_status', |
|
468 | - 'id' => 'subscription_status_update_select', |
|
469 | - 'required' => true, |
|
470 | - 'no_wrap' => false, |
|
471 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
472 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
473 | - 'select2' => true, |
|
474 | - 'value' => $subscription->get_status( 'edit' ), |
|
475 | - ), |
|
476 | - true |
|
477 | - ); |
|
478 | - ?> |
|
464 | + aui()->select( |
|
465 | + array( |
|
466 | + 'options' => getpaid_get_subscription_statuses(), |
|
467 | + 'name' => 'subscription_status', |
|
468 | + 'id' => 'subscription_status_update_select', |
|
469 | + 'required' => true, |
|
470 | + 'no_wrap' => false, |
|
471 | + 'label' => __( 'Subscription Status', 'invoicing' ), |
|
472 | + 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
473 | + 'select2' => true, |
|
474 | + 'value' => $subscription->get_status( 'edit' ), |
|
475 | + ), |
|
476 | + true |
|
477 | + ); |
|
478 | + ?> |
|
479 | 479 | |
480 | 480 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
481 | 481 | |
482 | 482 | <?php |
483 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
483 | + submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
484 | 484 | |
485 | - $url = wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ); |
|
486 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
487 | - $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
485 | + $url = wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ); |
|
486 | + $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
487 | + $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
488 | 488 | |
489 | - if ( $subscription->is_active() ) { |
|
490 | - echo "<a href='" . esc_url( $url ) . "' class='float-right text-muted' onclick='return confirm(\"" . esc_attr( $title ) . "\")'>" . esc_html( $anchor ) . "</a>"; |
|
491 | - } |
|
489 | + if ( $subscription->is_active() ) { |
|
490 | + echo "<a href='" . esc_url( $url ) . "' class='float-right text-muted' onclick='return confirm(\"" . esc_attr( $title ) . "\")'>" . esc_html( $anchor ) . "</a>"; |
|
491 | + } |
|
492 | 492 | |
493 | - echo '</div></div>'; |
|
493 | + echo '</div></div>'; |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | /** |
@@ -501,33 +501,33 @@ discard block |
||
501 | 501 | */ |
502 | 502 | function getpaid_admin_subscription_invoice_details_metabox( $subscription, $strict = true ) { |
503 | 503 | |
504 | - $columns = apply_filters( |
|
505 | - 'getpaid_subscription_related_invoices_columns', |
|
506 | - array( |
|
507 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
508 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
509 | - 'date' => __( 'Date', 'invoicing' ), |
|
510 | - 'status' => __( 'Status', 'invoicing' ), |
|
511 | - 'total' => __( 'Total', 'invoicing' ), |
|
512 | - ), |
|
513 | - $subscription |
|
514 | - ); |
|
515 | - |
|
516 | - // Prepare the invoices. |
|
517 | - $payments = $subscription->get_child_payments( ! is_admin() ); |
|
518 | - $parent = $subscription->get_parent_invoice(); |
|
519 | - |
|
520 | - if ( $parent->exists() ) { |
|
521 | - $payments = array_merge( array( $parent ), $payments ); |
|
522 | - } |
|
523 | - |
|
524 | - $table_class = 'w-100 bg-white'; |
|
525 | - |
|
526 | - if ( ! is_admin() ) { |
|
527 | - $table_class = 'table table-bordered'; |
|
528 | - } |
|
529 | - |
|
530 | - ?> |
|
504 | + $columns = apply_filters( |
|
505 | + 'getpaid_subscription_related_invoices_columns', |
|
506 | + array( |
|
507 | + 'invoice' => __( 'Invoice', 'invoicing' ), |
|
508 | + 'relationship' => __( 'Relationship', 'invoicing' ), |
|
509 | + 'date' => __( 'Date', 'invoicing' ), |
|
510 | + 'status' => __( 'Status', 'invoicing' ), |
|
511 | + 'total' => __( 'Total', 'invoicing' ), |
|
512 | + ), |
|
513 | + $subscription |
|
514 | + ); |
|
515 | + |
|
516 | + // Prepare the invoices. |
|
517 | + $payments = $subscription->get_child_payments( ! is_admin() ); |
|
518 | + $parent = $subscription->get_parent_invoice(); |
|
519 | + |
|
520 | + if ( $parent->exists() ) { |
|
521 | + $payments = array_merge( array( $parent ), $payments ); |
|
522 | + } |
|
523 | + |
|
524 | + $table_class = 'w-100 bg-white'; |
|
525 | + |
|
526 | + if ( ! is_admin() ) { |
|
527 | + $table_class = 'table table-bordered'; |
|
528 | + } |
|
529 | + |
|
530 | + ?> |
|
531 | 531 | <div class="m-0" style="overflow: auto;"> |
532 | 532 | |
533 | 533 | <table class="<?php echo esc_attr( $table_class ); ?>"> |
@@ -535,10 +535,10 @@ discard block |
||
535 | 535 | <thead> |
536 | 536 | <tr> |
537 | 537 | <?php |
538 | - foreach ( $columns as $key => $label ) { |
|
539 | - echo "<th class='subscription-invoice-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
540 | - } |
|
541 | - ?> |
|
538 | + foreach ( $columns as $key => $label ) { |
|
539 | + echo "<th class='subscription-invoice-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
540 | + } |
|
541 | + ?> |
|
542 | 542 | </tr> |
543 | 543 | </thead> |
544 | 544 | |
@@ -554,72 +554,72 @@ discard block |
||
554 | 554 | |
555 | 555 | <?php |
556 | 556 | |
557 | - foreach ( $payments as $payment ) : |
|
557 | + foreach ( $payments as $payment ) : |
|
558 | 558 | |
559 | - // Ensure that we have an invoice. |
|
560 | - $payment = new WPInv_Invoice( $payment ); |
|
559 | + // Ensure that we have an invoice. |
|
560 | + $payment = new WPInv_Invoice( $payment ); |
|
561 | 561 | |
562 | - // Abort if the invoice is invalid... |
|
563 | - if ( ! $payment->exists() ) { |
|
564 | - continue; |
|
565 | - } |
|
562 | + // Abort if the invoice is invalid... |
|
563 | + if ( ! $payment->exists() ) { |
|
564 | + continue; |
|
565 | + } |
|
566 | 566 | |
567 | - // ... or belongs to a different subscription. |
|
568 | - if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) { |
|
569 | - continue; |
|
570 | - } |
|
567 | + // ... or belongs to a different subscription. |
|
568 | + if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) { |
|
569 | + continue; |
|
570 | + } |
|
571 | 571 | |
572 | - echo '<tr>'; |
|
572 | + echo '<tr>'; |
|
573 | 573 | |
574 | - foreach ( array_keys( $columns ) as $key ) { |
|
574 | + foreach ( array_keys( $columns ) as $key ) { |
|
575 | 575 | |
576 | - echo "<td class='p-2 text-left'>"; |
|
576 | + echo "<td class='p-2 text-left'>"; |
|
577 | 577 | |
578 | - switch ( $key ) { |
|
578 | + switch ( $key ) { |
|
579 | 579 | |
580 | - case 'total': |
|
581 | - echo '<strong>'; |
|
582 | - wpinv_the_price( $payment->get_total(), $payment->get_currency() ); |
|
583 | - echo '</strong>'; |
|
584 | - break; |
|
580 | + case 'total': |
|
581 | + echo '<strong>'; |
|
582 | + wpinv_the_price( $payment->get_total(), $payment->get_currency() ); |
|
583 | + echo '</strong>'; |
|
584 | + break; |
|
585 | 585 | |
586 | - case 'relationship': |
|
587 | - echo $payment->is_renewal() ? esc_html__( 'Renewal Invoice', 'invoicing' ) : esc_html__( 'Initial Invoice', 'invoicing' ); |
|
588 | - break; |
|
586 | + case 'relationship': |
|
587 | + echo $payment->is_renewal() ? esc_html__( 'Renewal Invoice', 'invoicing' ) : esc_html__( 'Initial Invoice', 'invoicing' ); |
|
588 | + break; |
|
589 | 589 | |
590 | - case 'date': |
|
591 | - echo esc_html( getpaid_format_date_value( $payment->get_date_created() ) ); |
|
592 | - break; |
|
590 | + case 'date': |
|
591 | + echo esc_html( getpaid_format_date_value( $payment->get_date_created() ) ); |
|
592 | + break; |
|
593 | 593 | |
594 | - case 'status': |
|
595 | - $status = $payment->get_status_nicename(); |
|
596 | - if ( is_admin() ) { |
|
597 | - $status = $payment->get_status_label_html(); |
|
598 | - } |
|
594 | + case 'status': |
|
595 | + $status = $payment->get_status_nicename(); |
|
596 | + if ( is_admin() ) { |
|
597 | + $status = $payment->get_status_label_html(); |
|
598 | + } |
|
599 | 599 | |
600 | - echo wp_kses_post( $status ); |
|
601 | - break; |
|
600 | + echo wp_kses_post( $status ); |
|
601 | + break; |
|
602 | 602 | |
603 | - case 'invoice': |
|
604 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
603 | + case 'invoice': |
|
604 | + $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
605 | 605 | |
606 | - if ( ! is_admin() ) { |
|
607 | - $link = esc_url( $payment->get_view_url() ); |
|
608 | - } |
|
606 | + if ( ! is_admin() ) { |
|
607 | + $link = esc_url( $payment->get_view_url() ); |
|
608 | + } |
|
609 | 609 | |
610 | - $invoice = esc_html( $payment->get_number() ); |
|
611 | - echo wp_kses_post( "<a href='$link'>$invoice</a>" ); |
|
612 | - break; |
|
613 | - } |
|
610 | + $invoice = esc_html( $payment->get_number() ); |
|
611 | + echo wp_kses_post( "<a href='$link'>$invoice</a>" ); |
|
612 | + break; |
|
613 | + } |
|
614 | 614 | |
615 | - echo '</td>'; |
|
615 | + echo '</td>'; |
|
616 | 616 | |
617 | - } |
|
617 | + } |
|
618 | 618 | |
619 | - echo '</tr>'; |
|
619 | + echo '</tr>'; |
|
620 | 620 | |
621 | - endforeach; |
|
622 | - ?> |
|
621 | + endforeach; |
|
622 | + ?> |
|
623 | 623 | |
624 | 624 | </tbody> |
625 | 625 | |
@@ -637,42 +637,42 @@ discard block |
||
637 | 637 | */ |
638 | 638 | function getpaid_admin_subscription_item_details_metabox( $subscription ) { |
639 | 639 | |
640 | - // Fetch the subscription group. |
|
641 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
640 | + // Fetch the subscription group. |
|
641 | + $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
642 | 642 | |
643 | - if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
644 | - return; |
|
645 | - } |
|
643 | + if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
644 | + return; |
|
645 | + } |
|
646 | 646 | |
647 | - // Prepare table columns. |
|
648 | - $columns = apply_filters( |
|
649 | - 'getpaid_subscription_item_details_columns', |
|
650 | - array( |
|
651 | - 'item_name' => __( 'Item', 'invoicing' ), |
|
652 | - 'price' => __( 'Price', 'invoicing' ), |
|
653 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
654 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
655 | - //'initial' => __( 'Initial Amount', 'invoicing' ), |
|
656 | - 'recurring' => __( 'Subtotal', 'invoicing' ), |
|
657 | - ), |
|
658 | - $subscription |
|
659 | - ); |
|
647 | + // Prepare table columns. |
|
648 | + $columns = apply_filters( |
|
649 | + 'getpaid_subscription_item_details_columns', |
|
650 | + array( |
|
651 | + 'item_name' => __( 'Item', 'invoicing' ), |
|
652 | + 'price' => __( 'Price', 'invoicing' ), |
|
653 | + 'tax' => __( 'Tax', 'invoicing' ), |
|
654 | + 'discount' => __( 'Discount', 'invoicing' ), |
|
655 | + //'initial' => __( 'Initial Amount', 'invoicing' ), |
|
656 | + 'recurring' => __( 'Subtotal', 'invoicing' ), |
|
657 | + ), |
|
658 | + $subscription |
|
659 | + ); |
|
660 | 660 | |
661 | - // Prepare the invoices. |
|
661 | + // Prepare the invoices. |
|
662 | 662 | |
663 | - $invoice = $subscription->get_parent_invoice(); |
|
663 | + $invoice = $subscription->get_parent_invoice(); |
|
664 | 664 | |
665 | - if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
666 | - unset( $columns['tax'] ); |
|
667 | - } |
|
665 | + if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
666 | + unset( $columns['tax'] ); |
|
667 | + } |
|
668 | 668 | |
669 | - $table_class = 'w-100 bg-white'; |
|
669 | + $table_class = 'w-100 bg-white'; |
|
670 | 670 | |
671 | - if ( ! is_admin() ) { |
|
672 | - $table_class = 'table table-bordered'; |
|
673 | - } |
|
671 | + if ( ! is_admin() ) { |
|
672 | + $table_class = 'table table-bordered'; |
|
673 | + } |
|
674 | 674 | |
675 | - ?> |
|
675 | + ?> |
|
676 | 676 | <div class="m-0" style="overflow: auto;"> |
677 | 677 | |
678 | 678 | <table class="<?php echo esc_attr( $table_class ); ?>"> |
@@ -681,10 +681,10 @@ discard block |
||
681 | 681 | <tr> |
682 | 682 | <?php |
683 | 683 | |
684 | - foreach ( $columns as $key => $label ) { |
|
685 | - echo "<th class='subscription-item-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
686 | - } |
|
687 | - ?> |
|
684 | + foreach ( $columns as $key => $label ) { |
|
685 | + echo "<th class='subscription-item-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
686 | + } |
|
687 | + ?> |
|
688 | 688 | </tr> |
689 | 689 | </thead> |
690 | 690 | |
@@ -692,106 +692,106 @@ discard block |
||
692 | 692 | |
693 | 693 | <?php |
694 | 694 | |
695 | - foreach ( $subscription_group['items'] as $subscription_group_item ) : |
|
695 | + foreach ( $subscription_group['items'] as $subscription_group_item ) : |
|
696 | 696 | |
697 | - echo '<tr>'; |
|
697 | + echo '<tr>'; |
|
698 | 698 | |
699 | - foreach ( array_keys( $columns ) as $key ) { |
|
699 | + foreach ( array_keys( $columns ) as $key ) { |
|
700 | 700 | |
701 | - $class = 'text-left'; |
|
701 | + $class = 'text-left'; |
|
702 | 702 | |
703 | - echo "<td class='p-2 text-left'>"; |
|
703 | + echo "<td class='p-2 text-left'>"; |
|
704 | 704 | |
705 | - switch ( $key ) { |
|
705 | + switch ( $key ) { |
|
706 | 706 | |
707 | - case 'item_name': |
|
708 | - $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
709 | - $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
707 | + case 'item_name': |
|
708 | + $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
709 | + $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
710 | 710 | |
711 | - if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) { |
|
712 | - echo esc_html( $item_name ); |
|
713 | - } else { |
|
714 | - printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] ); |
|
715 | - } |
|
711 | + if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) { |
|
712 | + echo esc_html( $item_name ); |
|
713 | + } else { |
|
714 | + printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] ); |
|
715 | + } |
|
716 | 716 | |
717 | - break; |
|
717 | + break; |
|
718 | 718 | |
719 | - case 'price': |
|
720 | - wpinv_the_price( $subscription_group_item['item_price'], $invoice->get_currency() ); |
|
721 | - break; |
|
719 | + case 'price': |
|
720 | + wpinv_the_price( $subscription_group_item['item_price'], $invoice->get_currency() ); |
|
721 | + break; |
|
722 | 722 | |
723 | - case 'tax': |
|
724 | - wpinv_the_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
725 | - break; |
|
723 | + case 'tax': |
|
724 | + wpinv_the_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
725 | + break; |
|
726 | 726 | |
727 | - case 'discount': |
|
728 | - wpinv_the_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
729 | - break; |
|
727 | + case 'discount': |
|
728 | + wpinv_the_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
729 | + break; |
|
730 | 730 | |
731 | - case 'initial': |
|
732 | - wpinv_the_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ); |
|
733 | - break; |
|
731 | + case 'initial': |
|
732 | + wpinv_the_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ); |
|
733 | + break; |
|
734 | 734 | |
735 | - case 'recurring': |
|
736 | - echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>' ); |
|
737 | - break; |
|
735 | + case 'recurring': |
|
736 | + echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>' ); |
|
737 | + break; |
|
738 | 738 | |
739 | - } |
|
739 | + } |
|
740 | 740 | |
741 | - echo '</td>'; |
|
741 | + echo '</td>'; |
|
742 | 742 | |
743 | - } |
|
743 | + } |
|
744 | 744 | |
745 | - echo '</tr>'; |
|
745 | + echo '</tr>'; |
|
746 | 746 | |
747 | - endforeach; |
|
747 | + endforeach; |
|
748 | 748 | |
749 | - foreach ( $subscription_group['fees'] as $subscription_group_fee ) : |
|
749 | + foreach ( $subscription_group['fees'] as $subscription_group_fee ) : |
|
750 | 750 | |
751 | - echo '<tr>'; |
|
751 | + echo '<tr>'; |
|
752 | 752 | |
753 | - foreach ( array_keys( $columns ) as $key ) { |
|
753 | + foreach ( array_keys( $columns ) as $key ) { |
|
754 | 754 | |
755 | - $class = 'text-left'; |
|
755 | + $class = 'text-left'; |
|
756 | 756 | |
757 | - echo "<td class='p-2 text-left'>"; |
|
757 | + echo "<td class='p-2 text-left'>"; |
|
758 | 758 | |
759 | - switch ( $key ) { |
|
759 | + switch ( $key ) { |
|
760 | 760 | |
761 | - case 'item_name': |
|
762 | - echo esc_html( $subscription_group_fee['name'] ); |
|
763 | - break; |
|
761 | + case 'item_name': |
|
762 | + echo esc_html( $subscription_group_fee['name'] ); |
|
763 | + break; |
|
764 | 764 | |
765 | - case 'price': |
|
766 | - wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
767 | - break; |
|
765 | + case 'price': |
|
766 | + wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
767 | + break; |
|
768 | 768 | |
769 | - case 'tax': |
|
770 | - echo '—'; |
|
771 | - break; |
|
769 | + case 'tax': |
|
770 | + echo '—'; |
|
771 | + break; |
|
772 | 772 | |
773 | - case 'discount': |
|
774 | - echo '—'; |
|
775 | - break; |
|
773 | + case 'discount': |
|
774 | + echo '—'; |
|
775 | + break; |
|
776 | 776 | |
777 | - case 'initial': |
|
778 | - wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
779 | - break; |
|
777 | + case 'initial': |
|
778 | + wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
779 | + break; |
|
780 | 780 | |
781 | - case 'recurring': |
|
782 | - echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>' ); |
|
783 | - break; |
|
781 | + case 'recurring': |
|
782 | + echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>' ); |
|
783 | + break; |
|
784 | 784 | |
785 | - } |
|
785 | + } |
|
786 | 786 | |
787 | - echo '</td>'; |
|
787 | + echo '</td>'; |
|
788 | 788 | |
789 | - } |
|
789 | + } |
|
790 | 790 | |
791 | - echo '</tr>'; |
|
791 | + echo '</tr>'; |
|
792 | 792 | |
793 | - endforeach; |
|
794 | - ?> |
|
793 | + endforeach; |
|
794 | + ?> |
|
795 | 795 | |
796 | 796 | </tbody> |
797 | 797 | |
@@ -810,38 +810,38 @@ discard block |
||
810 | 810 | */ |
811 | 811 | function getpaid_admin_subscription_related_subscriptions_metabox( $subscription, $skip_current = true ) { |
812 | 812 | |
813 | - // Fetch the subscription groups. |
|
814 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
815 | - |
|
816 | - if ( empty( $subscription_groups ) ) { |
|
817 | - return; |
|
818 | - } |
|
819 | - |
|
820 | - // Prepare table columns. |
|
821 | - $columns = apply_filters( |
|
822 | - 'getpaid_subscription_related_subscriptions_columns', |
|
823 | - array( |
|
824 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
825 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
826 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
827 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
828 | - 'item' => __( 'Items', 'invoicing' ), |
|
829 | - 'status' => __( 'Status', 'invoicing' ), |
|
830 | - ), |
|
831 | - $subscription |
|
832 | - ); |
|
833 | - |
|
834 | - if ( $subscription->get_status() == 'pending' ) { |
|
835 | - unset( $columns['start_date'], $columns['renewal_date'] ); |
|
836 | - } |
|
837 | - |
|
838 | - $table_class = 'w-100 bg-white'; |
|
839 | - |
|
840 | - if ( ! is_admin() ) { |
|
841 | - $table_class = 'table table-bordered'; |
|
842 | - } |
|
843 | - |
|
844 | - ?> |
|
813 | + // Fetch the subscription groups. |
|
814 | + $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
815 | + |
|
816 | + if ( empty( $subscription_groups ) ) { |
|
817 | + return; |
|
818 | + } |
|
819 | + |
|
820 | + // Prepare table columns. |
|
821 | + $columns = apply_filters( |
|
822 | + 'getpaid_subscription_related_subscriptions_columns', |
|
823 | + array( |
|
824 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
825 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
826 | + 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
827 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
828 | + 'item' => __( 'Items', 'invoicing' ), |
|
829 | + 'status' => __( 'Status', 'invoicing' ), |
|
830 | + ), |
|
831 | + $subscription |
|
832 | + ); |
|
833 | + |
|
834 | + if ( $subscription->get_status() == 'pending' ) { |
|
835 | + unset( $columns['start_date'], $columns['renewal_date'] ); |
|
836 | + } |
|
837 | + |
|
838 | + $table_class = 'w-100 bg-white'; |
|
839 | + |
|
840 | + if ( ! is_admin() ) { |
|
841 | + $table_class = 'table table-bordered'; |
|
842 | + } |
|
843 | + |
|
844 | + ?> |
|
845 | 845 | <div class="m-0" style="overflow: auto;"> |
846 | 846 | |
847 | 847 | <table class="<?php echo esc_attr( $table_class ); ?>"> |
@@ -850,10 +850,10 @@ discard block |
||
850 | 850 | <tr> |
851 | 851 | <?php |
852 | 852 | |
853 | - foreach ( $columns as $key => $label ) { |
|
854 | - echo "<th class='related-subscription-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
855 | - } |
|
856 | - ?> |
|
853 | + foreach ( $columns as $key => $label ) { |
|
854 | + echo "<th class='related-subscription-field-" . esc_attr( $key ) . " bg-light p-2 text-left color-dark font-weight-bold'>" . esc_html( $label ) . "</th>"; |
|
855 | + } |
|
856 | + ?> |
|
857 | 857 | </tr> |
858 | 858 | </thead> |
859 | 859 | |
@@ -861,74 +861,74 @@ discard block |
||
861 | 861 | |
862 | 862 | <?php |
863 | 863 | |
864 | - foreach ( $subscription_groups as $subscription_group ) : |
|
864 | + foreach ( $subscription_groups as $subscription_group ) : |
|
865 | 865 | |
866 | - // Do not list current subscription. |
|
867 | - if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
868 | - continue; |
|
869 | - } |
|
866 | + // Do not list current subscription. |
|
867 | + if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
868 | + continue; |
|
869 | + } |
|
870 | 870 | |
871 | - // Ensure the subscription exists. |
|
872 | - $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
871 | + // Ensure the subscription exists. |
|
872 | + $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
873 | 873 | |
874 | - if ( ! $_suscription->exists() ) { |
|
875 | - continue; |
|
876 | - } |
|
874 | + if ( ! $_suscription->exists() ) { |
|
875 | + continue; |
|
876 | + } |
|
877 | 877 | |
878 | - echo '<tr>'; |
|
878 | + echo '<tr>'; |
|
879 | 879 | |
880 | - foreach ( array_keys( $columns ) as $key ) { |
|
880 | + foreach ( array_keys( $columns ) as $key ) { |
|
881 | 881 | |
882 | - $class = 'text-left'; |
|
882 | + $class = 'text-left'; |
|
883 | 883 | |
884 | - echo "<td class='p-2 text-left'>"; |
|
884 | + echo "<td class='p-2 text-left'>"; |
|
885 | 885 | |
886 | - switch ( $key ) { |
|
886 | + switch ( $key ) { |
|
887 | 887 | |
888 | - case 'status': |
|
889 | - echo wp_kses_post( $_suscription->get_status_label_html() ); |
|
890 | - break; |
|
888 | + case 'status': |
|
889 | + echo wp_kses_post( $_suscription->get_status_label_html() ); |
|
890 | + break; |
|
891 | 891 | |
892 | - case 'item': |
|
893 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
894 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
895 | - break; |
|
892 | + case 'item': |
|
893 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
894 | + echo wp_kses_post( implode( ' | ', $markup ) ); |
|
895 | + break; |
|
896 | 896 | |
897 | - case 'renewals': |
|
898 | - $max_bills = $_suscription->get_bill_times(); |
|
899 | - echo ( (int) $_suscription->get_times_billed() ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
900 | - break; |
|
897 | + case 'renewals': |
|
898 | + $max_bills = $_suscription->get_bill_times(); |
|
899 | + echo ( (int) $_suscription->get_times_billed() ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
900 | + break; |
|
901 | 901 | |
902 | - case 'renewal_date': |
|
903 | - echo $_suscription->is_active() ? esc_html( getpaid_format_date_value( $_suscription->get_expiration() ) ) : '—'; |
|
904 | - break; |
|
902 | + case 'renewal_date': |
|
903 | + echo $_suscription->is_active() ? esc_html( getpaid_format_date_value( $_suscription->get_expiration() ) ) : '—'; |
|
904 | + break; |
|
905 | 905 | |
906 | - case 'start_date': |
|
907 | - echo 'pending' == $_suscription->get_status() ? '—' : esc_html( getpaid_format_date_value( $_suscription->get_date_created() ) ); |
|
908 | - break; |
|
906 | + case 'start_date': |
|
907 | + echo 'pending' == $_suscription->get_status() ? '—' : esc_html( getpaid_format_date_value( $_suscription->get_date_created() ) ); |
|
908 | + break; |
|
909 | 909 | |
910 | - case 'subscription': |
|
911 | - $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
912 | - printf( |
|
910 | + case 'subscription': |
|
911 | + $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
912 | + printf( |
|
913 | 913 | '%1$s#%2$s%3$s', |
914 | 914 | '<a href="' . esc_url( $url ) . '">', |
915 | 915 | '<strong>' . intval( $_suscription->get_id() ) . '</strong>', |
916 | - '</a>' |
|
916 | + '</a>' |
|
917 | 917 | ); |
918 | 918 | |
919 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::column_amount( $_suscription ) ); |
|
920 | - break; |
|
919 | + echo wp_kses_post( WPInv_Subscriptions_List_Table::column_amount( $_suscription ) ); |
|
920 | + break; |
|
921 | 921 | |
922 | - } |
|
922 | + } |
|
923 | 923 | |
924 | - echo '</td>'; |
|
924 | + echo '</td>'; |
|
925 | 925 | |
926 | - } |
|
926 | + } |
|
927 | 927 | |
928 | - echo '</tr>'; |
|
928 | + echo '</tr>'; |
|
929 | 929 | |
930 | - endforeach; |
|
931 | - ?> |
|
930 | + endforeach; |
|
931 | + ?> |
|
932 | 932 | |
933 | 933 | </tbody> |
934 | 934 |