@@ -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.5.10' ); |
|
26 | + define( 'WPINV_VERSION', '2.5.10' ); |
|
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 | /** |
@@ -12,474 +12,474 @@ |
||
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_kses_post_deep( 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 | - |
|
100 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
101 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Check PayPal IPN validity. |
|
106 | - */ |
|
107 | - protected function validate_ipn() { |
|
108 | - |
|
109 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
110 | - |
|
111 | - // Retrieve the associated invoice. |
|
112 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
113 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
114 | - |
|
115 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
116 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
117 | - } |
|
118 | - |
|
119 | - // Validate the IPN. |
|
120 | - $posted['cmd'] = '_notify-validate'; |
|
121 | - |
|
122 | - // Send back post vars to paypal. |
|
123 | - $params = array( |
|
124 | - 'body' => $posted, |
|
125 | - 'timeout' => 60, |
|
126 | - 'httpversion' => '1.1', |
|
127 | - 'compress' => false, |
|
128 | - 'decompress' => false, |
|
129 | - 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
130 | - ); |
|
131 | - |
|
132 | - // Post back to get a response. |
|
133 | - $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 ); |
|
134 | - |
|
135 | - // Check to see if the request was valid. |
|
136 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
138 | - return true; |
|
139 | - } |
|
140 | - |
|
141 | - if ( is_wp_error( $response ) ) { |
|
142 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
143 | - return false; |
|
144 | - } |
|
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_kses_post_deep( 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 | + |
|
100 | + wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
101 | + wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Check PayPal IPN validity. |
|
106 | + */ |
|
107 | + protected function validate_ipn() { |
|
108 | + |
|
109 | + wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
110 | + |
|
111 | + // Retrieve the associated invoice. |
|
112 | + $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
113 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
114 | + |
|
115 | + if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
116 | + wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
117 | + } |
|
118 | + |
|
119 | + // Validate the IPN. |
|
120 | + $posted['cmd'] = '_notify-validate'; |
|
121 | + |
|
122 | + // Send back post vars to paypal. |
|
123 | + $params = array( |
|
124 | + 'body' => $posted, |
|
125 | + 'timeout' => 60, |
|
126 | + 'httpversion' => '1.1', |
|
127 | + 'compress' => false, |
|
128 | + 'decompress' => false, |
|
129 | + 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
130 | + ); |
|
131 | + |
|
132 | + // Post back to get a response. |
|
133 | + $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 ); |
|
134 | + |
|
135 | + // Check to see if the request was valid. |
|
136 | + if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | + wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
138 | + return true; |
|
139 | + } |
|
140 | + |
|
141 | + if ( is_wp_error( $response ) ) { |
|
142 | + wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
143 | + return false; |
|
144 | + } |
|
145 | 145 | |
146 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
147 | - return false; |
|
148 | - |
|
149 | - } |
|
146 | + wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
147 | + return false; |
|
148 | + |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * Check currency from IPN matches the invoice. |
|
153 | - * |
|
154 | - * @param WPInv_Invoice $invoice Invoice object. |
|
155 | - * @param string $currency currency to validate. |
|
156 | - */ |
|
157 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
151 | + /** |
|
152 | + * Check currency from IPN matches the invoice. |
|
153 | + * |
|
154 | + * @param WPInv_Invoice $invoice Invoice object. |
|
155 | + * @param string $currency currency to validate. |
|
156 | + */ |
|
157 | + protected function validate_ipn_currency( $invoice, $currency ) { |
|
158 | 158 | |
159 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
159 | + if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
160 | 160 | |
161 | - /* translators: %s: currency code. */ |
|
162 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
161 | + /* translators: %s: currency code. */ |
|
162 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
163 | 163 | |
164 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
165 | - } |
|
164 | + wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
165 | + } |
|
166 | 166 | |
167 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
168 | - } |
|
167 | + wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * Check payment amount from IPN matches the invoice. |
|
172 | - * |
|
173 | - * @param WPInv_Invoice $invoice Invoice object. |
|
174 | - * @param float $amount amount to validate. |
|
175 | - */ |
|
176 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
170 | + /** |
|
171 | + * Check payment amount from IPN matches the invoice. |
|
172 | + * |
|
173 | + * @param WPInv_Invoice $invoice Invoice object. |
|
174 | + * @param float $amount amount to validate. |
|
175 | + */ |
|
176 | + protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | + if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
178 | 178 | |
179 | - /* translators: %s: Amount. */ |
|
180 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
179 | + /* translators: %s: Amount. */ |
|
180 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
181 | 181 | |
182 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
183 | - } |
|
182 | + wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
183 | + } |
|
184 | 184 | |
185 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
186 | - } |
|
185 | + wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * Verify receiver email from PayPal. |
|
190 | - * |
|
191 | - * @param WPInv_Invoice $invoice Invoice object. |
|
192 | - * @param string $receiver_email Email to validate. |
|
193 | - */ |
|
194 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
188 | + /** |
|
189 | + * Verify receiver email from PayPal. |
|
190 | + * |
|
191 | + * @param WPInv_Invoice $invoice Invoice object. |
|
192 | + * @param string $receiver_email Email to validate. |
|
193 | + */ |
|
194 | + protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | + $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
196 | 196 | |
197 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
197 | + if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | + wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
199 | 199 | |
200 | - /* translators: %s: email address . */ |
|
201 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
200 | + /* translators: %s: email address . */ |
|
201 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
202 | 202 | |
203 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
204 | - } |
|
203 | + return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
204 | + } |
|
205 | 205 | |
206 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
207 | - } |
|
206 | + wpinv_error_log( 'Validated PayPal Email', false ); |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * Handles one time payments. |
|
211 | - * |
|
212 | - * @param WPInv_Invoice $invoice Invoice object. |
|
213 | - * @param array $posted Posted data. |
|
214 | - */ |
|
215 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
209 | + /** |
|
210 | + * Handles one time payments. |
|
211 | + * |
|
212 | + * @param WPInv_Invoice $invoice Invoice object. |
|
213 | + * @param array $posted Posted data. |
|
214 | + */ |
|
215 | + protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
216 | 216 | |
217 | - // Collect payment details |
|
218 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
217 | + // Collect payment details |
|
218 | + $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
220 | 220 | |
221 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
221 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
223 | 223 | |
224 | - // Update the transaction id. |
|
225 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
227 | - $invoice->save(); |
|
228 | - } |
|
224 | + // Update the transaction id. |
|
225 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | + $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
227 | + $invoice->save(); |
|
228 | + } |
|
229 | 229 | |
230 | - $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
230 | + $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
231 | 231 | |
232 | - // Process a refund. |
|
233 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
232 | + // Process a refund. |
|
233 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
234 | 234 | |
235 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
235 | + update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
236 | 236 | |
237 | - if ( ! $invoice->is_refunded() ) { |
|
238 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
239 | - } |
|
237 | + if ( ! $invoice->is_refunded() ) { |
|
238 | + $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
239 | + } |
|
240 | 240 | |
241 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
242 | - } |
|
241 | + return wpinv_error_log( $posted['reason_code'], false ); |
|
242 | + } |
|
243 | 243 | |
244 | - // Process payments. |
|
245 | - if ( $payment_status == 'completed' ) { |
|
244 | + // Process payments. |
|
245 | + if ( $payment_status == 'completed' ) { |
|
246 | 246 | |
247 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
248 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
249 | - } |
|
247 | + if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
248 | + return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
249 | + } |
|
250 | 250 | |
251 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
251 | + $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
252 | 252 | |
253 | - $note = ''; |
|
253 | + $note = ''; |
|
254 | 254 | |
255 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
256 | - $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
257 | - } |
|
255 | + if ( ! empty( $posted['mc_fee'] ) ) { |
|
256 | + $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
257 | + } |
|
258 | 258 | |
259 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
260 | - $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
261 | - } |
|
259 | + if ( ! empty( $posted['payer_status'] ) ) { |
|
260 | + $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
261 | + } |
|
262 | 262 | |
263 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
264 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
263 | + $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
264 | + return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
265 | 265 | |
266 | - } |
|
266 | + } |
|
267 | 267 | |
268 | - // Pending payments. |
|
269 | - if ( $payment_status == 'pending' ) { |
|
268 | + // Pending payments. |
|
269 | + if ( $payment_status == 'pending' ) { |
|
270 | 270 | |
271 | - /* translators: %s: pending reason. */ |
|
272 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
271 | + /* translators: %s: pending reason. */ |
|
272 | + $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
273 | 273 | |
274 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
275 | - } |
|
274 | + return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
275 | + } |
|
276 | 276 | |
277 | - /* translators: %s: payment status. */ |
|
278 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
277 | + /* translators: %s: payment status. */ |
|
278 | + $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
279 | 279 | |
280 | - } |
|
280 | + } |
|
281 | 281 | |
282 | - /** |
|
283 | - * Handles one time payments. |
|
284 | - * |
|
285 | - * @param WPInv_Invoice $invoice Invoice object. |
|
286 | - * @param array $posted Posted data. |
|
287 | - */ |
|
288 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
289 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
290 | - } |
|
282 | + /** |
|
283 | + * Handles one time payments. |
|
284 | + * |
|
285 | + * @param WPInv_Invoice $invoice Invoice object. |
|
286 | + * @param array $posted Posted data. |
|
287 | + */ |
|
288 | + protected function ipn_txn_cart( $invoice, $posted ) { |
|
289 | + $this->ipn_txn_web_accept( $invoice, $posted ); |
|
290 | + } |
|
291 | 291 | |
292 | - /** |
|
293 | - * Handles subscription sign ups. |
|
294 | - * |
|
295 | - * @param WPInv_Invoice $invoice Invoice object. |
|
296 | - * @param array $posted Posted data. |
|
297 | - */ |
|
298 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
292 | + /** |
|
293 | + * Handles subscription sign ups. |
|
294 | + * |
|
295 | + * @param WPInv_Invoice $invoice Invoice object. |
|
296 | + * @param array $posted Posted data. |
|
297 | + */ |
|
298 | + protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
299 | 299 | |
300 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
300 | + wpinv_error_log( 'Processing subscription signup', false ); |
|
301 | 301 | |
302 | - // Make sure the invoice has a subscription. |
|
303 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
302 | + // Make sure the invoice has a subscription. |
|
303 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
304 | 304 | |
305 | - if ( empty( $subscription ) ) { |
|
306 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
307 | - } |
|
305 | + if ( empty( $subscription ) ) { |
|
306 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
307 | + } |
|
308 | 308 | |
309 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
309 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
310 | 310 | |
311 | - // Validate the IPN. |
|
312 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
313 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
314 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
311 | + // Validate the IPN. |
|
312 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
313 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
314 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
315 | 315 | |
316 | - // Activate the subscription. |
|
317 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
318 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
319 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
320 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
321 | - $subscription->activate(); |
|
316 | + // Activate the subscription. |
|
317 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
318 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
319 | + $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
320 | + $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
321 | + $subscription->activate(); |
|
322 | 322 | |
323 | - // Set the transaction id. |
|
324 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
325 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
326 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
327 | - } |
|
323 | + // Set the transaction id. |
|
324 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
325 | + $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
326 | + $invoice->set_transaction_id( $posted['txn_id'] ); |
|
327 | + } |
|
328 | 328 | |
329 | - // Update the payment status. |
|
330 | - $invoice->mark_paid(); |
|
329 | + // Update the payment status. |
|
330 | + $invoice->mark_paid(); |
|
331 | 331 | |
332 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
332 | + $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
333 | 333 | |
334 | - wpinv_error_log( 'Subscription started.', false ); |
|
335 | - } |
|
334 | + wpinv_error_log( 'Subscription started.', false ); |
|
335 | + } |
|
336 | 336 | |
337 | - /** |
|
338 | - * Handles subscription renewals. |
|
339 | - * |
|
340 | - * @param WPInv_Invoice $invoice Invoice object. |
|
341 | - * @param array $posted Posted data. |
|
342 | - */ |
|
343 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
337 | + /** |
|
338 | + * Handles subscription renewals. |
|
339 | + * |
|
340 | + * @param WPInv_Invoice $invoice Invoice object. |
|
341 | + * @param array $posted Posted data. |
|
342 | + */ |
|
343 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
344 | 344 | |
345 | - // Make sure the invoice has a subscription. |
|
346 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
345 | + // Make sure the invoice has a subscription. |
|
346 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
347 | 347 | |
348 | - if ( empty( $subscription ) ) { |
|
349 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
350 | - } |
|
348 | + if ( empty( $subscription ) ) { |
|
349 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
350 | + } |
|
351 | 351 | |
352 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
352 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
353 | 353 | |
354 | - // PayPal sends a subscr_payment for the first payment too. |
|
355 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
356 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
357 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
358 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
359 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
360 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
354 | + // PayPal sends a subscr_payment for the first payment too. |
|
355 | + $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
356 | + $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
357 | + $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
358 | + $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
359 | + $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
360 | + $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
361 | 361 | |
362 | - foreach( $dates as $date ) { |
|
362 | + foreach( $dates as $date ) { |
|
363 | 363 | |
364 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
365 | - continue; |
|
366 | - } |
|
364 | + if ( $date !== $today_date && $date !== $payment_date ) { |
|
365 | + continue; |
|
366 | + } |
|
367 | 367 | |
368 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
369 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
370 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
371 | - } |
|
368 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
369 | + $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
370 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
371 | + } |
|
372 | 372 | |
373 | - return $invoice->mark_paid(); |
|
374 | - |
|
375 | - } |
|
373 | + return $invoice->mark_paid(); |
|
374 | + |
|
375 | + } |
|
376 | 376 | |
377 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
378 | - |
|
379 | - // Abort if the payment is already recorded. |
|
380 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
381 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false ); |
|
382 | - } |
|
383 | - |
|
384 | - $args = array( |
|
385 | - 'transaction_id' => $posted['txn_id'], |
|
386 | - 'gateway' => $this->id, |
|
387 | - ); |
|
388 | - |
|
389 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
377 | + wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
378 | + |
|
379 | + // Abort if the payment is already recorded. |
|
380 | + if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
381 | + return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false ); |
|
382 | + } |
|
383 | + |
|
384 | + $args = array( |
|
385 | + 'transaction_id' => $posted['txn_id'], |
|
386 | + 'gateway' => $this->id, |
|
387 | + ); |
|
388 | + |
|
389 | + $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
390 | 390 | |
391 | - if ( empty( $invoice ) ) { |
|
392 | - return; |
|
393 | - } |
|
391 | + if ( empty( $invoice ) ) { |
|
392 | + return; |
|
393 | + } |
|
394 | 394 | |
395 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
396 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
395 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
396 | + $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
397 | 397 | |
398 | - $subscription->renew(); |
|
399 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
398 | + $subscription->renew(); |
|
399 | + wpinv_error_log( 'Subscription renewed.', false ); |
|
400 | 400 | |
401 | - } |
|
401 | + } |
|
402 | 402 | |
403 | - /** |
|
404 | - * Handles subscription cancelations. |
|
405 | - * |
|
406 | - * @param WPInv_Invoice $invoice Invoice object. |
|
407 | - */ |
|
408 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
403 | + /** |
|
404 | + * Handles subscription cancelations. |
|
405 | + * |
|
406 | + * @param WPInv_Invoice $invoice Invoice object. |
|
407 | + */ |
|
408 | + protected function ipn_txn_subscr_cancel( $invoice ) { |
|
409 | 409 | |
410 | - // Make sure the invoice has a subscription. |
|
411 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
412 | - |
|
413 | - if ( empty( $subscription ) ) { |
|
414 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
415 | - } |
|
416 | - |
|
417 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
418 | - $subscription->cancel(); |
|
419 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
410 | + // Make sure the invoice has a subscription. |
|
411 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
412 | + |
|
413 | + if ( empty( $subscription ) ) { |
|
414 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
415 | + } |
|
416 | + |
|
417 | + wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
418 | + $subscription->cancel(); |
|
419 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
420 | 420 | |
421 | - } |
|
421 | + } |
|
422 | 422 | |
423 | - /** |
|
424 | - * Handles subscription completions. |
|
425 | - * |
|
426 | - * @param WPInv_Invoice $invoice Invoice object. |
|
427 | - * @param array $posted Posted data. |
|
428 | - */ |
|
429 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
423 | + /** |
|
424 | + * Handles subscription completions. |
|
425 | + * |
|
426 | + * @param WPInv_Invoice $invoice Invoice object. |
|
427 | + * @param array $posted Posted data. |
|
428 | + */ |
|
429 | + protected function ipn_txn_subscr_eot( $invoice ) { |
|
430 | 430 | |
431 | - // Make sure the invoice has a subscription. |
|
432 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
431 | + // Make sure the invoice has a subscription. |
|
432 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
433 | 433 | |
434 | - if ( empty( $subscription ) ) { |
|
435 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
436 | - } |
|
434 | + if ( empty( $subscription ) ) { |
|
435 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
436 | + } |
|
437 | 437 | |
438 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
439 | - $subscription->complete(); |
|
440 | - wpinv_error_log( 'Subscription completed.', false ); |
|
438 | + wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
439 | + $subscription->complete(); |
|
440 | + wpinv_error_log( 'Subscription completed.', false ); |
|
441 | 441 | |
442 | - } |
|
442 | + } |
|
443 | 443 | |
444 | - /** |
|
445 | - * Handles subscription fails. |
|
446 | - * |
|
447 | - * @param WPInv_Invoice $invoice Invoice object. |
|
448 | - * @param array $posted Posted data. |
|
449 | - */ |
|
450 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
444 | + /** |
|
445 | + * Handles subscription fails. |
|
446 | + * |
|
447 | + * @param WPInv_Invoice $invoice Invoice object. |
|
448 | + * @param array $posted Posted data. |
|
449 | + */ |
|
450 | + protected function ipn_txn_subscr_failed( $invoice ) { |
|
451 | 451 | |
452 | - // Make sure the invoice has a subscription. |
|
453 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
452 | + // Make sure the invoice has a subscription. |
|
453 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
454 | 454 | |
455 | - if ( empty( $subscription ) ) { |
|
456 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
457 | - } |
|
455 | + if ( empty( $subscription ) ) { |
|
456 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
457 | + } |
|
458 | 458 | |
459 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
460 | - $subscription->failing(); |
|
461 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
459 | + wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
460 | + $subscription->failing(); |
|
461 | + wpinv_error_log( 'Subscription marked as failing.', false ); |
|
462 | 462 | |
463 | - } |
|
463 | + } |
|
464 | 464 | |
465 | - /** |
|
466 | - * Handles subscription suspensions. |
|
467 | - * |
|
468 | - * @param WPInv_Invoice $invoice Invoice object. |
|
469 | - * @param array $posted Posted data. |
|
470 | - */ |
|
471 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
465 | + /** |
|
466 | + * Handles subscription suspensions. |
|
467 | + * |
|
468 | + * @param WPInv_Invoice $invoice Invoice object. |
|
469 | + * @param array $posted Posted data. |
|
470 | + */ |
|
471 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
472 | 472 | |
473 | - // Make sure the invoice has a subscription. |
|
474 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
473 | + // Make sure the invoice has a subscription. |
|
474 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
475 | 475 | |
476 | - if ( empty( $subscription ) ) { |
|
477 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
478 | - } |
|
479 | - |
|
480 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
481 | - $subscription->cancel(); |
|
482 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
483 | - } |
|
476 | + if ( empty( $subscription ) ) { |
|
477 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
478 | + } |
|
479 | + |
|
480 | + wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
481 | + $subscription->cancel(); |
|
482 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
483 | + } |
|
484 | 484 | |
485 | 485 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | if ( ! defined( 'ABSPATH' ) ) exit; |
7 | 7 | |
8 | 8 | if ( ! class_exists( 'WP_List_Table' ) ) { |
9 | - include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
9 | + include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | /** |
@@ -14,446 +14,446 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Subscriptions_List_Table extends WP_List_Table { |
16 | 16 | |
17 | - /** |
|
18 | - * URL of this page |
|
19 | - * |
|
20 | - * @var string |
|
21 | - * @since 1.0.19 |
|
22 | - */ |
|
23 | - public $base_url; |
|
24 | - |
|
25 | - /** |
|
26 | - * Query |
|
27 | - * |
|
28 | - * @var GetPaid_Subscriptions_Query |
|
29 | - * @since 1.0.19 |
|
30 | - */ |
|
31 | - public $query; |
|
32 | - |
|
33 | - /** |
|
34 | - * Total subscriptions |
|
35 | - * |
|
36 | - * @var string |
|
37 | - * @since 1.0.0 |
|
38 | - */ |
|
39 | - public $total_count; |
|
40 | - |
|
41 | - /** |
|
42 | - * Current status subscriptions |
|
43 | - * |
|
44 | - * @var string |
|
45 | - * @since 1.0.0 |
|
46 | - */ |
|
47 | - public $current_total_count; |
|
48 | - |
|
49 | - /** |
|
50 | - * Status counts |
|
51 | - * |
|
52 | - * @var array |
|
53 | - * @since 1.0.19 |
|
54 | - */ |
|
55 | - public $status_counts; |
|
56 | - |
|
57 | - /** |
|
58 | - * Number of results to show per page |
|
59 | - * |
|
60 | - * @var int |
|
61 | - * @since 1.0.0 |
|
62 | - */ |
|
63 | - public $per_page = 10; |
|
64 | - |
|
65 | - /** |
|
66 | - * Constructor function. |
|
67 | - */ |
|
68 | - public function __construct() { |
|
69 | - |
|
70 | - parent::__construct( |
|
71 | - array( |
|
72 | - 'singular' => 'subscription', |
|
73 | - 'plural' => 'subscriptions', |
|
74 | - ) |
|
75 | - ); |
|
76 | - |
|
77 | - $this->process_bulk_action(); |
|
78 | - |
|
79 | - $this->prepare_query(); |
|
80 | - |
|
81 | - $this->base_url = remove_query_arg( 'status' ); |
|
82 | - |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Prepares the display query |
|
87 | - */ |
|
88 | - public function prepare_query() { |
|
89 | - |
|
90 | - // Prepare query args. |
|
91 | - $query = array( |
|
92 | - 'number' => $this->per_page, |
|
93 | - 'paged' => $this->get_paged(), |
|
94 | - 'status' => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all', |
|
95 | - 'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id', |
|
96 | - 'order' => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC', |
|
97 | - 'customer_in' => $this->get_user_in(), |
|
98 | - ); |
|
99 | - |
|
100 | - if ( is_array( $query['customer_in'] ) && empty( $query['customer_in'] ) ) { |
|
101 | - $this->total_count = 0; |
|
102 | - $this->current_total_count = 0; |
|
103 | - $this->items = array(); |
|
104 | - $this->status_counts = array(); |
|
105 | - return; |
|
106 | - } |
|
107 | - |
|
108 | - // Prepare class properties. |
|
109 | - $this->query = new GetPaid_Subscriptions_Query( $query ); |
|
110 | - $this->total_count = $this->query->get_total(); |
|
111 | - $this->current_total_count = $this->query->get_total(); |
|
112 | - $this->items = $this->query->get_results(); |
|
113 | - $this->status_counts = getpaid_get_subscription_status_counts( $query ); |
|
114 | - |
|
115 | - if ( 'all' != $query['status'] ) { |
|
116 | - unset( $query['status'] ); |
|
117 | - $this->total_count = getpaid_get_subscriptions( $query, 'count' ); |
|
118 | - } |
|
119 | - |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Get user in. |
|
124 | - * |
|
125 | - */ |
|
126 | - public function get_user_in() { |
|
127 | - |
|
128 | - // Abort if no user. |
|
129 | - if ( empty( $_GET['s'] ) ) { |
|
130 | - return null; |
|
131 | - } |
|
132 | - |
|
133 | - // Or invalid user. |
|
134 | - $user = wp_unslash( sanitize_text_field( $_REQUEST['s'] ) ); |
|
135 | - |
|
136 | - if ( empty( $user ) ) { |
|
137 | - return null; |
|
138 | - } |
|
139 | - |
|
140 | - // Search matching users. |
|
141 | - $user = '*' . $user . '*'; |
|
142 | - $users = new WP_User_Query( |
|
143 | - array( |
|
144 | - 'fields' => 'ID', |
|
145 | - 'search' => $user, |
|
146 | - 'count_total' => false, |
|
147 | - ) |
|
148 | - ); |
|
149 | - |
|
150 | - return $users->get_results(); |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Gets the list of views available on this table. |
|
155 | - * |
|
156 | - * The format is an associative array: |
|
157 | - * - `'id' => 'link'` |
|
158 | - * |
|
159 | - * @since 1.0.0 |
|
160 | - * |
|
161 | - * @return array |
|
162 | - */ |
|
163 | - public function get_views() { |
|
164 | - |
|
165 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : 'all'; |
|
166 | - $views = array( |
|
167 | - |
|
168 | - 'all' => sprintf( |
|
169 | - '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
170 | - esc_url( add_query_arg( 'status', false, $this->base_url ) ), |
|
171 | - $current === 'all' ? ' class="current"' : '', |
|
172 | - __('All','invoicing' ), |
|
173 | - $this->total_count |
|
174 | - ) |
|
175 | - |
|
176 | - ); |
|
177 | - |
|
178 | - foreach ( array_filter( $this->status_counts ) as $status => $count ) { |
|
179 | - |
|
180 | - $views[ $status ] = sprintf( |
|
181 | - '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
182 | - esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ), |
|
183 | - $current === $status ? ' class="current"' : '', |
|
184 | - esc_html( getpaid_get_subscription_status_label( $status ) ), |
|
185 | - $count |
|
186 | - ); |
|
187 | - |
|
188 | - } |
|
189 | - |
|
190 | - return $views; |
|
191 | - |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Render most columns |
|
196 | - * |
|
197 | - * @access private |
|
198 | - * @since 1.0.0 |
|
199 | - * @return string |
|
200 | - */ |
|
201 | - public function column_default( $item, $column_name ) { |
|
202 | - return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name ); |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * This is how checkbox column renders. |
|
207 | - * |
|
208 | - * @param WPInv_Subscription $item |
|
209 | - * @return string |
|
210 | - */ |
|
211 | - public function column_cb( $item ) { |
|
212 | - return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) ); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Status column |
|
217 | - * |
|
218 | - * @param WPInv_Subscription $item |
|
219 | - * @since 1.0.0 |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - public function column_status( $item ) { |
|
223 | - return $item->get_status_label_html(); |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Subscription column |
|
228 | - * |
|
229 | - * @param WPInv_Subscription $item |
|
230 | - * @since 1.0.0 |
|
231 | - * @return string |
|
232 | - */ |
|
233 | - public function column_subscription( $item ) { |
|
234 | - |
|
235 | - $username = __( '(Missing User)', 'invoicing' ); |
|
236 | - |
|
237 | - $user = get_userdata( $item->get_customer_id() ); |
|
238 | - if ( $user ) { |
|
239 | - |
|
240 | - $username = sprintf( |
|
241 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
242 | - absint( $user->ID ), |
|
243 | - ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
244 | - ); |
|
245 | - |
|
246 | - } |
|
247 | - |
|
248 | - // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name |
|
249 | - $column_content = sprintf( |
|
250 | - _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ), |
|
251 | - '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">', |
|
252 | - '<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>', |
|
253 | - $username |
|
254 | - ); |
|
255 | - |
|
256 | - $row_actions = array(); |
|
257 | - |
|
258 | - // View subscription. |
|
259 | - $view_url = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) )); |
|
260 | - $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>'; |
|
261 | - |
|
262 | - // View invoice. |
|
263 | - $invoice = get_post( $item->get_parent_invoice_id() ); |
|
264 | - |
|
265 | - if ( ! empty( $invoice ) ) { |
|
266 | - $invoice_url = get_edit_post_link( $invoice ); |
|
267 | - $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
268 | - } |
|
269 | - |
|
270 | - $delete_url = esc_url( |
|
271 | - wp_nonce_url( |
|
272 | - add_query_arg( |
|
273 | - array( |
|
274 | - 'getpaid-admin-action' => 'subscription_manual_delete', |
|
275 | - 'id' => $item->get_id(), |
|
276 | - ) |
|
277 | - ), |
|
278 | - 'getpaid-nonce', |
|
279 | - 'getpaid-nonce' |
|
280 | - ) |
|
281 | - ); |
|
282 | - $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>'; |
|
283 | - |
|
284 | - $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) ); |
|
285 | - |
|
286 | - return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions; |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Renewal date column |
|
291 | - * |
|
292 | - * @param WPInv_Subscription $item |
|
293 | - * @since 1.0.0 |
|
294 | - * @return string |
|
295 | - */ |
|
296 | - public function column_renewal_date( $item ) { |
|
297 | - return getpaid_format_date_value( $item->get_expiration() ); |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * Start date column |
|
302 | - * |
|
303 | - * @param WPInv_Subscription $item |
|
304 | - * @since 1.0.0 |
|
305 | - * @return string |
|
306 | - */ |
|
307 | - public function column_start_date( $item ) { |
|
308 | - return getpaid_format_date_value( $item->get_date_created() ); |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * Amount column |
|
313 | - * |
|
314 | - * @param WPInv_Subscription $item |
|
315 | - * @since 1.0.19 |
|
316 | - * @return string |
|
317 | - */ |
|
318 | - public static function column_amount( $item ) { |
|
319 | - $amount = getpaid_get_formatted_subscription_amount( $item ); |
|
320 | - return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>"; |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * Billing Times column |
|
325 | - * |
|
326 | - * @param WPInv_Subscription $item |
|
327 | - * @since 1.0.0 |
|
328 | - * @return string |
|
329 | - */ |
|
330 | - public function column_renewals( $item ) { |
|
331 | - $max_bills = $item->get_bill_times(); |
|
332 | - return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Product ID column |
|
337 | - * |
|
338 | - * @param WPInv_Subscription $item |
|
339 | - * @since 1.0.0 |
|
340 | - * @return string |
|
341 | - */ |
|
342 | - public function column_item( $item ) { |
|
343 | - $subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() ); |
|
344 | - |
|
345 | - if ( empty( $subscription_group ) ) { |
|
346 | - return $this->generate_item_markup( $item->get_product_id() ); |
|
347 | - } |
|
348 | - |
|
349 | - $markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
350 | - return implode( ' | ', $markup ); |
|
351 | - |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * Generates the items markup. |
|
356 | - * |
|
357 | - * @param int $item_id |
|
358 | - * @since 1.0.0 |
|
359 | - * @return string |
|
360 | - */ |
|
361 | - public static function generate_item_markup( $item_id ) { |
|
362 | - $item = get_post( $item_id ); |
|
363 | - |
|
364 | - if ( ! empty( $item ) ) { |
|
365 | - $link = get_edit_post_link( $item ); |
|
366 | - $link = esc_url( $link ); |
|
367 | - $name = esc_html( get_the_title( $item ) ); |
|
368 | - return wpinv_current_user_can_manage_invoicing() ? "<a href='$link'>$name</a>" : $name; |
|
369 | - } else { |
|
370 | - return sprintf( __( 'Item #%s', 'invoicing' ), $item_id ); |
|
371 | - } |
|
372 | - |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Retrieve the current page number |
|
377 | - * |
|
378 | - * @return int |
|
379 | - */ |
|
380 | - public function get_paged() { |
|
381 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * Setup the final data for the table |
|
386 | - * |
|
387 | - */ |
|
388 | - public function prepare_items() { |
|
389 | - |
|
390 | - $columns = $this->get_columns(); |
|
391 | - $hidden = array(); |
|
392 | - $sortable = $this->get_sortable_columns(); |
|
393 | - |
|
394 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
395 | - |
|
396 | - $this->set_pagination_args( |
|
397 | - array( |
|
398 | - 'total_items' => $this->current_total_count, |
|
399 | - 'per_page' => $this->per_page, |
|
400 | - 'total_pages' => ceil( $this->current_total_count / $this->per_page ) |
|
401 | - ) |
|
402 | - ); |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * Table columns |
|
407 | - * |
|
408 | - * @return array |
|
409 | - */ |
|
410 | - public function get_columns(){ |
|
411 | - $columns = array( |
|
412 | - 'cb' => '<input type="checkbox" />', |
|
413 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
414 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
415 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
416 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
417 | - 'item' => __( 'Items', 'invoicing' ), |
|
418 | - 'status' => __( 'Status', 'invoicing' ), |
|
419 | - ); |
|
420 | - |
|
421 | - return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns ); |
|
422 | - } |
|
423 | - |
|
424 | - /** |
|
425 | - * Sortable table columns. |
|
426 | - * |
|
427 | - * @return array |
|
428 | - */ |
|
429 | - public function get_sortable_columns() { |
|
430 | - $sortable = array( |
|
431 | - 'subscription' => array( 'id', true ), |
|
432 | - 'start_date' => array( 'created', true ), |
|
433 | - 'renewal_date' => array( 'expiration', true ), |
|
434 | - 'renewals' => array( 'bill_times', true ), |
|
435 | - 'item' => array( 'product_id', true ), |
|
436 | - 'status' => array( 'status', true ), |
|
437 | - ); |
|
438 | - |
|
439 | - return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable ); |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * Whether the table has items to display or not |
|
444 | - * |
|
445 | - * @return bool |
|
446 | - */ |
|
447 | - public function has_items() { |
|
448 | - return ! empty( $this->current_total_count ); |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * Processes bulk actions. |
|
453 | - * |
|
454 | - */ |
|
455 | - public function process_bulk_action() { |
|
456 | - |
|
457 | - } |
|
17 | + /** |
|
18 | + * URL of this page |
|
19 | + * |
|
20 | + * @var string |
|
21 | + * @since 1.0.19 |
|
22 | + */ |
|
23 | + public $base_url; |
|
24 | + |
|
25 | + /** |
|
26 | + * Query |
|
27 | + * |
|
28 | + * @var GetPaid_Subscriptions_Query |
|
29 | + * @since 1.0.19 |
|
30 | + */ |
|
31 | + public $query; |
|
32 | + |
|
33 | + /** |
|
34 | + * Total subscriptions |
|
35 | + * |
|
36 | + * @var string |
|
37 | + * @since 1.0.0 |
|
38 | + */ |
|
39 | + public $total_count; |
|
40 | + |
|
41 | + /** |
|
42 | + * Current status subscriptions |
|
43 | + * |
|
44 | + * @var string |
|
45 | + * @since 1.0.0 |
|
46 | + */ |
|
47 | + public $current_total_count; |
|
48 | + |
|
49 | + /** |
|
50 | + * Status counts |
|
51 | + * |
|
52 | + * @var array |
|
53 | + * @since 1.0.19 |
|
54 | + */ |
|
55 | + public $status_counts; |
|
56 | + |
|
57 | + /** |
|
58 | + * Number of results to show per page |
|
59 | + * |
|
60 | + * @var int |
|
61 | + * @since 1.0.0 |
|
62 | + */ |
|
63 | + public $per_page = 10; |
|
64 | + |
|
65 | + /** |
|
66 | + * Constructor function. |
|
67 | + */ |
|
68 | + public function __construct() { |
|
69 | + |
|
70 | + parent::__construct( |
|
71 | + array( |
|
72 | + 'singular' => 'subscription', |
|
73 | + 'plural' => 'subscriptions', |
|
74 | + ) |
|
75 | + ); |
|
76 | + |
|
77 | + $this->process_bulk_action(); |
|
78 | + |
|
79 | + $this->prepare_query(); |
|
80 | + |
|
81 | + $this->base_url = remove_query_arg( 'status' ); |
|
82 | + |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Prepares the display query |
|
87 | + */ |
|
88 | + public function prepare_query() { |
|
89 | + |
|
90 | + // Prepare query args. |
|
91 | + $query = array( |
|
92 | + 'number' => $this->per_page, |
|
93 | + 'paged' => $this->get_paged(), |
|
94 | + 'status' => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all', |
|
95 | + 'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id', |
|
96 | + 'order' => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC', |
|
97 | + 'customer_in' => $this->get_user_in(), |
|
98 | + ); |
|
99 | + |
|
100 | + if ( is_array( $query['customer_in'] ) && empty( $query['customer_in'] ) ) { |
|
101 | + $this->total_count = 0; |
|
102 | + $this->current_total_count = 0; |
|
103 | + $this->items = array(); |
|
104 | + $this->status_counts = array(); |
|
105 | + return; |
|
106 | + } |
|
107 | + |
|
108 | + // Prepare class properties. |
|
109 | + $this->query = new GetPaid_Subscriptions_Query( $query ); |
|
110 | + $this->total_count = $this->query->get_total(); |
|
111 | + $this->current_total_count = $this->query->get_total(); |
|
112 | + $this->items = $this->query->get_results(); |
|
113 | + $this->status_counts = getpaid_get_subscription_status_counts( $query ); |
|
114 | + |
|
115 | + if ( 'all' != $query['status'] ) { |
|
116 | + unset( $query['status'] ); |
|
117 | + $this->total_count = getpaid_get_subscriptions( $query, 'count' ); |
|
118 | + } |
|
119 | + |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Get user in. |
|
124 | + * |
|
125 | + */ |
|
126 | + public function get_user_in() { |
|
127 | + |
|
128 | + // Abort if no user. |
|
129 | + if ( empty( $_GET['s'] ) ) { |
|
130 | + return null; |
|
131 | + } |
|
132 | + |
|
133 | + // Or invalid user. |
|
134 | + $user = wp_unslash( sanitize_text_field( $_REQUEST['s'] ) ); |
|
135 | + |
|
136 | + if ( empty( $user ) ) { |
|
137 | + return null; |
|
138 | + } |
|
139 | + |
|
140 | + // Search matching users. |
|
141 | + $user = '*' . $user . '*'; |
|
142 | + $users = new WP_User_Query( |
|
143 | + array( |
|
144 | + 'fields' => 'ID', |
|
145 | + 'search' => $user, |
|
146 | + 'count_total' => false, |
|
147 | + ) |
|
148 | + ); |
|
149 | + |
|
150 | + return $users->get_results(); |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Gets the list of views available on this table. |
|
155 | + * |
|
156 | + * The format is an associative array: |
|
157 | + * - `'id' => 'link'` |
|
158 | + * |
|
159 | + * @since 1.0.0 |
|
160 | + * |
|
161 | + * @return array |
|
162 | + */ |
|
163 | + public function get_views() { |
|
164 | + |
|
165 | + $current = isset( $_GET['status'] ) ? $_GET['status'] : 'all'; |
|
166 | + $views = array( |
|
167 | + |
|
168 | + 'all' => sprintf( |
|
169 | + '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
170 | + esc_url( add_query_arg( 'status', false, $this->base_url ) ), |
|
171 | + $current === 'all' ? ' class="current"' : '', |
|
172 | + __('All','invoicing' ), |
|
173 | + $this->total_count |
|
174 | + ) |
|
175 | + |
|
176 | + ); |
|
177 | + |
|
178 | + foreach ( array_filter( $this->status_counts ) as $status => $count ) { |
|
179 | + |
|
180 | + $views[ $status ] = sprintf( |
|
181 | + '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
182 | + esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ), |
|
183 | + $current === $status ? ' class="current"' : '', |
|
184 | + esc_html( getpaid_get_subscription_status_label( $status ) ), |
|
185 | + $count |
|
186 | + ); |
|
187 | + |
|
188 | + } |
|
189 | + |
|
190 | + return $views; |
|
191 | + |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Render most columns |
|
196 | + * |
|
197 | + * @access private |
|
198 | + * @since 1.0.0 |
|
199 | + * @return string |
|
200 | + */ |
|
201 | + public function column_default( $item, $column_name ) { |
|
202 | + return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name ); |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * This is how checkbox column renders. |
|
207 | + * |
|
208 | + * @param WPInv_Subscription $item |
|
209 | + * @return string |
|
210 | + */ |
|
211 | + public function column_cb( $item ) { |
|
212 | + return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) ); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Status column |
|
217 | + * |
|
218 | + * @param WPInv_Subscription $item |
|
219 | + * @since 1.0.0 |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + public function column_status( $item ) { |
|
223 | + return $item->get_status_label_html(); |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * Subscription column |
|
228 | + * |
|
229 | + * @param WPInv_Subscription $item |
|
230 | + * @since 1.0.0 |
|
231 | + * @return string |
|
232 | + */ |
|
233 | + public function column_subscription( $item ) { |
|
234 | + |
|
235 | + $username = __( '(Missing User)', 'invoicing' ); |
|
236 | + |
|
237 | + $user = get_userdata( $item->get_customer_id() ); |
|
238 | + if ( $user ) { |
|
239 | + |
|
240 | + $username = sprintf( |
|
241 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
242 | + absint( $user->ID ), |
|
243 | + ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
244 | + ); |
|
245 | + |
|
246 | + } |
|
247 | + |
|
248 | + // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name |
|
249 | + $column_content = sprintf( |
|
250 | + _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ), |
|
251 | + '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">', |
|
252 | + '<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>', |
|
253 | + $username |
|
254 | + ); |
|
255 | + |
|
256 | + $row_actions = array(); |
|
257 | + |
|
258 | + // View subscription. |
|
259 | + $view_url = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) )); |
|
260 | + $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>'; |
|
261 | + |
|
262 | + // View invoice. |
|
263 | + $invoice = get_post( $item->get_parent_invoice_id() ); |
|
264 | + |
|
265 | + if ( ! empty( $invoice ) ) { |
|
266 | + $invoice_url = get_edit_post_link( $invoice ); |
|
267 | + $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
268 | + } |
|
269 | + |
|
270 | + $delete_url = esc_url( |
|
271 | + wp_nonce_url( |
|
272 | + add_query_arg( |
|
273 | + array( |
|
274 | + 'getpaid-admin-action' => 'subscription_manual_delete', |
|
275 | + 'id' => $item->get_id(), |
|
276 | + ) |
|
277 | + ), |
|
278 | + 'getpaid-nonce', |
|
279 | + 'getpaid-nonce' |
|
280 | + ) |
|
281 | + ); |
|
282 | + $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>'; |
|
283 | + |
|
284 | + $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) ); |
|
285 | + |
|
286 | + return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions; |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Renewal date column |
|
291 | + * |
|
292 | + * @param WPInv_Subscription $item |
|
293 | + * @since 1.0.0 |
|
294 | + * @return string |
|
295 | + */ |
|
296 | + public function column_renewal_date( $item ) { |
|
297 | + return getpaid_format_date_value( $item->get_expiration() ); |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * Start date column |
|
302 | + * |
|
303 | + * @param WPInv_Subscription $item |
|
304 | + * @since 1.0.0 |
|
305 | + * @return string |
|
306 | + */ |
|
307 | + public function column_start_date( $item ) { |
|
308 | + return getpaid_format_date_value( $item->get_date_created() ); |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * Amount column |
|
313 | + * |
|
314 | + * @param WPInv_Subscription $item |
|
315 | + * @since 1.0.19 |
|
316 | + * @return string |
|
317 | + */ |
|
318 | + public static function column_amount( $item ) { |
|
319 | + $amount = getpaid_get_formatted_subscription_amount( $item ); |
|
320 | + return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>"; |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * Billing Times column |
|
325 | + * |
|
326 | + * @param WPInv_Subscription $item |
|
327 | + * @since 1.0.0 |
|
328 | + * @return string |
|
329 | + */ |
|
330 | + public function column_renewals( $item ) { |
|
331 | + $max_bills = $item->get_bill_times(); |
|
332 | + return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Product ID column |
|
337 | + * |
|
338 | + * @param WPInv_Subscription $item |
|
339 | + * @since 1.0.0 |
|
340 | + * @return string |
|
341 | + */ |
|
342 | + public function column_item( $item ) { |
|
343 | + $subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() ); |
|
344 | + |
|
345 | + if ( empty( $subscription_group ) ) { |
|
346 | + return $this->generate_item_markup( $item->get_product_id() ); |
|
347 | + } |
|
348 | + |
|
349 | + $markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
350 | + return implode( ' | ', $markup ); |
|
351 | + |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Generates the items markup. |
|
356 | + * |
|
357 | + * @param int $item_id |
|
358 | + * @since 1.0.0 |
|
359 | + * @return string |
|
360 | + */ |
|
361 | + public static function generate_item_markup( $item_id ) { |
|
362 | + $item = get_post( $item_id ); |
|
363 | + |
|
364 | + if ( ! empty( $item ) ) { |
|
365 | + $link = get_edit_post_link( $item ); |
|
366 | + $link = esc_url( $link ); |
|
367 | + $name = esc_html( get_the_title( $item ) ); |
|
368 | + return wpinv_current_user_can_manage_invoicing() ? "<a href='$link'>$name</a>" : $name; |
|
369 | + } else { |
|
370 | + return sprintf( __( 'Item #%s', 'invoicing' ), $item_id ); |
|
371 | + } |
|
372 | + |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Retrieve the current page number |
|
377 | + * |
|
378 | + * @return int |
|
379 | + */ |
|
380 | + public function get_paged() { |
|
381 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * Setup the final data for the table |
|
386 | + * |
|
387 | + */ |
|
388 | + public function prepare_items() { |
|
389 | + |
|
390 | + $columns = $this->get_columns(); |
|
391 | + $hidden = array(); |
|
392 | + $sortable = $this->get_sortable_columns(); |
|
393 | + |
|
394 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
395 | + |
|
396 | + $this->set_pagination_args( |
|
397 | + array( |
|
398 | + 'total_items' => $this->current_total_count, |
|
399 | + 'per_page' => $this->per_page, |
|
400 | + 'total_pages' => ceil( $this->current_total_count / $this->per_page ) |
|
401 | + ) |
|
402 | + ); |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * Table columns |
|
407 | + * |
|
408 | + * @return array |
|
409 | + */ |
|
410 | + public function get_columns(){ |
|
411 | + $columns = array( |
|
412 | + 'cb' => '<input type="checkbox" />', |
|
413 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
414 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
415 | + 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
416 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
417 | + 'item' => __( 'Items', 'invoicing' ), |
|
418 | + 'status' => __( 'Status', 'invoicing' ), |
|
419 | + ); |
|
420 | + |
|
421 | + return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns ); |
|
422 | + } |
|
423 | + |
|
424 | + /** |
|
425 | + * Sortable table columns. |
|
426 | + * |
|
427 | + * @return array |
|
428 | + */ |
|
429 | + public function get_sortable_columns() { |
|
430 | + $sortable = array( |
|
431 | + 'subscription' => array( 'id', true ), |
|
432 | + 'start_date' => array( 'created', true ), |
|
433 | + 'renewal_date' => array( 'expiration', true ), |
|
434 | + 'renewals' => array( 'bill_times', true ), |
|
435 | + 'item' => array( 'product_id', true ), |
|
436 | + 'status' => array( 'status', true ), |
|
437 | + ); |
|
438 | + |
|
439 | + return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable ); |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * Whether the table has items to display or not |
|
444 | + * |
|
445 | + * @return bool |
|
446 | + */ |
|
447 | + public function has_items() { |
|
448 | + return ! empty( $this->current_total_count ); |
|
449 | + } |
|
450 | + |
|
451 | + /** |
|
452 | + * Processes bulk actions. |
|
453 | + * |
|
454 | + */ |
|
455 | + public function process_bulk_action() { |
|
456 | + |
|
457 | + } |
|
458 | 458 | |
459 | 459 | } |
@@ -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,27 +22,27 @@ 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 | - echo aui()->alert( |
|
29 | - array( |
|
30 | - 'type' => 'danger', |
|
31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
32 | - ) |
|
33 | - ); |
|
28 | + echo aui()->alert( |
|
29 | + array( |
|
30 | + 'type' => 'danger', |
|
31 | + 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
32 | + ) |
|
33 | + ); |
|
34 | 34 | |
35 | - } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
35 | + } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
36 | 36 | |
37 | - // Display a single subscription. |
|
38 | - wpinv_recurring_subscription_details(); |
|
39 | - } else { |
|
37 | + // Display a single subscription. |
|
38 | + wpinv_recurring_subscription_details(); |
|
39 | + } else { |
|
40 | 40 | |
41 | - // Display a list of available subscriptions. |
|
42 | - getpaid_print_subscriptions_list(); |
|
43 | - } |
|
41 | + // Display a list of available subscriptions. |
|
42 | + getpaid_print_subscriptions_list(); |
|
43 | + } |
|
44 | 44 | |
45 | - ?> |
|
45 | + ?> |
|
46 | 46 | |
47 | 47 | </div> |
48 | 48 | </div> |
@@ -59,10 +59,10 @@ discard block |
||
59 | 59 | */ |
60 | 60 | function getpaid_print_subscriptions_list() { |
61 | 61 | |
62 | - $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
63 | - $subscribers_table->prepare_items(); |
|
62 | + $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
63 | + $subscribers_table->prepare_items(); |
|
64 | 64 | |
65 | - ?> |
|
65 | + ?> |
|
66 | 66 | <?php $subscribers_table->views(); ?> |
67 | 67 | <form id="subscribers-filter" class="bsui" method="get"> |
68 | 68 | <input type="hidden" name="page" value="wpinv-subscriptions" /> |
@@ -81,41 +81,41 @@ discard block |
||
81 | 81 | */ |
82 | 82 | function wpinv_recurring_subscription_details() { |
83 | 83 | |
84 | - // Fetch the subscription. |
|
85 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
86 | - if ( ! $sub->exists() ) { |
|
84 | + // Fetch the subscription. |
|
85 | + $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
86 | + if ( ! $sub->exists() ) { |
|
87 | 87 | |
88 | - echo aui()->alert( |
|
89 | - array( |
|
90 | - 'type' => 'danger', |
|
91 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
92 | - ) |
|
93 | - ); |
|
88 | + echo aui()->alert( |
|
89 | + array( |
|
90 | + 'type' => 'danger', |
|
91 | + 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
92 | + ) |
|
93 | + ); |
|
94 | 94 | |
95 | - return; |
|
96 | - } |
|
95 | + return; |
|
96 | + } |
|
97 | 97 | |
98 | - // Use metaboxes to display the subscription details. |
|
99 | - add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' ); |
|
100 | - add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
98 | + // Use metaboxes to display the subscription details. |
|
99 | + add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' ); |
|
100 | + add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
101 | 101 | |
102 | - $subscription_id = $sub->get_id(); |
|
103 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() ); |
|
104 | - $subscription_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
102 | + $subscription_id = $sub->get_id(); |
|
103 | + $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() ); |
|
104 | + $subscription_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
105 | 105 | |
106 | - if ( 1 < count( $subscription_groups ) ) { |
|
107 | - add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' ); |
|
108 | - } |
|
106 | + if ( 1 < count( $subscription_groups ) ) { |
|
107 | + add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' ); |
|
108 | + } |
|
109 | 109 | |
110 | - if ( ! empty( $subscription_group ) ) { |
|
111 | - add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' ); |
|
112 | - } |
|
110 | + if ( ! empty( $subscription_group ) ) { |
|
111 | + add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' ); |
|
112 | + } |
|
113 | 113 | |
114 | - add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
114 | + add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
115 | 115 | |
116 | - do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
116 | + do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
117 | 117 | |
118 | - ?> |
|
118 | + ?> |
|
119 | 119 | |
120 | 120 | <form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>"> |
121 | 121 | |
@@ -155,45 +155,45 @@ discard block |
||
155 | 155 | */ |
156 | 156 | function getpaid_admin_subscription_details_metabox( $sub ) { |
157 | 157 | |
158 | - // Subscription items. |
|
159 | - $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() ); |
|
160 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
161 | - |
|
162 | - // Prepare subscription detail columns. |
|
163 | - $fields = apply_filters( |
|
164 | - 'getpaid_subscription_admin_page_fields', |
|
165 | - array( |
|
166 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
167 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
168 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
169 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
170 | - 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
171 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
172 | - 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
173 | - 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
174 | - 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
175 | - 'status' => __( 'Status', 'invoicing' ), |
|
176 | - ) |
|
177 | - ); |
|
178 | - |
|
179 | - if ( ! $sub->is_active() ) { |
|
180 | - |
|
181 | - if ( isset( $fields['renews_on'] ) ) { |
|
182 | - unset( $fields['renews_on'] ); |
|
183 | - } |
|
184 | - |
|
185 | - if ( isset( $fields['gateway'] ) ) { |
|
186 | - unset( $fields['gateway'] ); |
|
187 | - } |
|
188 | - |
|
189 | - } |
|
190 | - |
|
191 | - $profile_id = $sub->get_profile_id(); |
|
192 | - if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
193 | - unset( $fields['profile_id'] ); |
|
194 | - } |
|
195 | - |
|
196 | - ?> |
|
158 | + // Subscription items. |
|
159 | + $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() ); |
|
160 | + $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
161 | + |
|
162 | + // Prepare subscription detail columns. |
|
163 | + $fields = apply_filters( |
|
164 | + 'getpaid_subscription_admin_page_fields', |
|
165 | + array( |
|
166 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
167 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
168 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
169 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
170 | + 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
171 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
172 | + 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
173 | + 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
174 | + 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
175 | + 'status' => __( 'Status', 'invoicing' ), |
|
176 | + ) |
|
177 | + ); |
|
178 | + |
|
179 | + if ( ! $sub->is_active() ) { |
|
180 | + |
|
181 | + if ( isset( $fields['renews_on'] ) ) { |
|
182 | + unset( $fields['renews_on'] ); |
|
183 | + } |
|
184 | + |
|
185 | + if ( isset( $fields['gateway'] ) ) { |
|
186 | + unset( $fields['gateway'] ); |
|
187 | + } |
|
188 | + |
|
189 | + } |
|
190 | + |
|
191 | + $profile_id = $sub->get_profile_id(); |
|
192 | + if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
193 | + unset( $fields['profile_id'] ); |
|
194 | + } |
|
195 | + |
|
196 | + ?> |
|
197 | 197 | |
198 | 198 | <table class="table table-borderless" style="font-size: 14px;"> |
199 | 199 | <tbody> |
@@ -227,20 +227,20 @@ discard block |
||
227 | 227 | */ |
228 | 228 | function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
229 | 229 | |
230 | - $username = __( '(Missing User)', 'invoicing' ); |
|
230 | + $username = __( '(Missing User)', 'invoicing' ); |
|
231 | 231 | |
232 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
233 | - if ( $user ) { |
|
232 | + $user = get_userdata( $subscription->get_customer_id() ); |
|
233 | + if ( $user ) { |
|
234 | 234 | |
235 | - $username = sprintf( |
|
236 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
237 | - absint( $user->ID ), |
|
238 | - ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
239 | - ); |
|
235 | + $username = sprintf( |
|
236 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
237 | + absint( $user->ID ), |
|
238 | + ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
239 | + ); |
|
240 | 240 | |
241 | - } |
|
241 | + } |
|
242 | 242 | |
243 | - echo $username; |
|
243 | + echo $username; |
|
244 | 244 | } |
245 | 245 | add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
246 | 246 | |
@@ -250,8 +250,8 @@ discard block |
||
250 | 250 | * @param WPInv_Subscription $subscription |
251 | 251 | */ |
252 | 252 | function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
253 | - $amount = wp_kses_post( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
254 | - echo "<span>$amount</span>"; |
|
253 | + $amount = wp_kses_post( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
254 | + echo "<span>$amount</span>"; |
|
255 | 255 | } |
256 | 256 | add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
257 | 257 | |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | * @param WPInv_Subscription $subscription |
262 | 262 | */ |
263 | 263 | function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
264 | - echo '#' . absint( $subscription->get_id() ); |
|
264 | + echo '#' . absint( $subscription->get_id() ); |
|
265 | 265 | } |
266 | 266 | add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
267 | 267 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | * @param WPInv_Subscription $subscription |
272 | 272 | */ |
273 | 273 | function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
274 | - echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
274 | + echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
275 | 275 | } |
276 | 276 | add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
277 | 277 | |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | * @param WPInv_Subscription $subscription |
282 | 282 | */ |
283 | 283 | function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
284 | - echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
284 | + echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
285 | 285 | } |
286 | 286 | add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
287 | 287 | |
@@ -291,8 +291,8 @@ discard block |
||
291 | 291 | * @param WPInv_Subscription $subscription |
292 | 292 | */ |
293 | 293 | function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
294 | - $max_bills = $subscription->get_bill_times(); |
|
295 | - echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
294 | + $max_bills = $subscription->get_bill_times(); |
|
295 | + echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
296 | 296 | } |
297 | 297 | add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
298 | 298 | /** |
@@ -303,13 +303,13 @@ discard block |
||
303 | 303 | */ |
304 | 304 | function getpaid_admin_subscription_metabox_display_item( $subscription, $subscription_group = false ) { |
305 | 305 | |
306 | - if ( empty( $subscription_group ) ) { |
|
307 | - echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ); |
|
308 | - return; |
|
309 | - } |
|
306 | + if ( empty( $subscription_group ) ) { |
|
307 | + echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ); |
|
308 | + return; |
|
309 | + } |
|
310 | 310 | |
311 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
312 | - echo implode( ' | ', $markup ); |
|
311 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
312 | + echo implode( ' | ', $markup ); |
|
313 | 313 | |
314 | 314 | } |
315 | 315 | add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2 ); |
@@ -321,13 +321,13 @@ discard block |
||
321 | 321 | */ |
322 | 322 | function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
323 | 323 | |
324 | - $gateway = $subscription->get_gateway(); |
|
324 | + $gateway = $subscription->get_gateway(); |
|
325 | 325 | |
326 | - if ( ! empty( $gateway ) ) { |
|
327 | - echo esc_html( wpinv_get_gateway_admin_label( $gateway ) ); |
|
328 | - } else { |
|
329 | - echo "—"; |
|
330 | - } |
|
326 | + if ( ! empty( $gateway ) ) { |
|
327 | + echo esc_html( wpinv_get_gateway_admin_label( $gateway ) ); |
|
328 | + } else { |
|
329 | + echo "—"; |
|
330 | + } |
|
331 | 331 | |
332 | 332 | } |
333 | 333 | add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | * @param WPInv_Subscription $subscription |
339 | 339 | */ |
340 | 340 | function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
341 | - echo $subscription->get_status_label_html(); |
|
341 | + echo $subscription->get_status_label_html(); |
|
342 | 342 | } |
343 | 343 | add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
344 | 344 | |
@@ -349,29 +349,29 @@ discard block |
||
349 | 349 | */ |
350 | 350 | function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
351 | 351 | |
352 | - $profile_id = $subscription->get_profile_id(); |
|
353 | - |
|
354 | - $input = aui()->input( |
|
355 | - array( |
|
356 | - 'type' => 'text', |
|
357 | - 'id' => 'wpinv_subscription_profile_id', |
|
358 | - 'name' => 'wpinv_subscription_profile_id', |
|
359 | - 'label' => __( 'Profile Id', 'invoicing' ), |
|
360 | - 'label_type' => 'hidden', |
|
361 | - 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
362 | - 'value' => esc_attr( $profile_id ), |
|
363 | - 'input_group_right' => '', |
|
364 | - 'no_wrap' => true, |
|
365 | - ) |
|
366 | - ); |
|
367 | - |
|
368 | - echo str_ireplace( 'form-control', 'regular-text', $input ); |
|
369 | - |
|
370 | - $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
371 | - if ( ! empty( $url ) ) { |
|
372 | - $url = esc_url_raw( $url ); |
|
373 | - echo ' <a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
374 | - } |
|
352 | + $profile_id = $subscription->get_profile_id(); |
|
353 | + |
|
354 | + $input = aui()->input( |
|
355 | + array( |
|
356 | + 'type' => 'text', |
|
357 | + 'id' => 'wpinv_subscription_profile_id', |
|
358 | + 'name' => 'wpinv_subscription_profile_id', |
|
359 | + 'label' => __( 'Profile Id', 'invoicing' ), |
|
360 | + 'label_type' => 'hidden', |
|
361 | + 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
362 | + 'value' => esc_attr( $profile_id ), |
|
363 | + 'input_group_right' => '', |
|
364 | + 'no_wrap' => true, |
|
365 | + ) |
|
366 | + ); |
|
367 | + |
|
368 | + echo str_ireplace( 'form-control', 'regular-text', $input ); |
|
369 | + |
|
370 | + $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
371 | + if ( ! empty( $url ) ) { |
|
372 | + $url = esc_url_raw( $url ); |
|
373 | + echo ' <a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
374 | + } |
|
375 | 375 | |
376 | 376 | } |
377 | 377 | add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
@@ -383,39 +383,39 @@ discard block |
||
383 | 383 | */ |
384 | 384 | function getpaid_admin_subscription_update_metabox( $subscription ) { |
385 | 385 | |
386 | - ?> |
|
386 | + ?> |
|
387 | 387 | <div class="mt-3"> |
388 | 388 | |
389 | 389 | <?php |
390 | - echo aui()->select( |
|
391 | - array( |
|
392 | - 'options' => getpaid_get_subscription_statuses(), |
|
393 | - 'name' => 'subscription_status', |
|
394 | - 'id' => 'subscription_status_update_select', |
|
395 | - 'required' => true, |
|
396 | - 'no_wrap' => false, |
|
397 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
398 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
399 | - 'select2' => true, |
|
400 | - 'value' => $subscription->get_status( 'edit' ), |
|
401 | - ) |
|
402 | - ); |
|
403 | - ?> |
|
390 | + echo aui()->select( |
|
391 | + array( |
|
392 | + 'options' => getpaid_get_subscription_statuses(), |
|
393 | + 'name' => 'subscription_status', |
|
394 | + 'id' => 'subscription_status_update_select', |
|
395 | + 'required' => true, |
|
396 | + 'no_wrap' => false, |
|
397 | + 'label' => __( 'Subscription Status', 'invoicing' ), |
|
398 | + 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
399 | + 'select2' => true, |
|
400 | + 'value' => $subscription->get_status( 'edit' ), |
|
401 | + ) |
|
402 | + ); |
|
403 | + ?> |
|
404 | 404 | |
405 | 405 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
406 | 406 | |
407 | 407 | <?php |
408 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
408 | + submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
409 | 409 | |
410 | - $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
411 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
412 | - $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' ); |
|
410 | + $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
411 | + $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
412 | + $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' ); |
|
413 | 413 | |
414 | - if ( $subscription->is_active() ) { |
|
415 | - echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
416 | - } |
|
414 | + if ( $subscription->is_active() ) { |
|
415 | + echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
416 | + } |
|
417 | 417 | |
418 | - echo '</div></div>'; |
|
418 | + echo '</div></div>'; |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | /** |
@@ -426,33 +426,33 @@ discard block |
||
426 | 426 | */ |
427 | 427 | function getpaid_admin_subscription_invoice_details_metabox( $subscription, $strict = true ) { |
428 | 428 | |
429 | - $columns = apply_filters( |
|
430 | - 'getpaid_subscription_related_invoices_columns', |
|
431 | - array( |
|
432 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
433 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
434 | - 'date' => __( 'Date', 'invoicing' ), |
|
435 | - 'status' => __( 'Status', 'invoicing' ), |
|
436 | - 'total' => __( 'Total', 'invoicing' ), |
|
437 | - ), |
|
438 | - $subscription |
|
439 | - ); |
|
440 | - |
|
441 | - // Prepare the invoices. |
|
442 | - $payments = $subscription->get_child_payments( ! is_admin() ); |
|
443 | - $parent = $subscription->get_parent_invoice(); |
|
444 | - |
|
445 | - if ( $parent->exists() ) { |
|
446 | - $payments = array_merge( array( $parent ), $payments ); |
|
447 | - } |
|
448 | - |
|
449 | - $table_class = 'w-100 bg-white'; |
|
450 | - |
|
451 | - if ( ! is_admin() ) { |
|
452 | - $table_class = 'table table-bordered'; |
|
453 | - } |
|
454 | - |
|
455 | - ?> |
|
429 | + $columns = apply_filters( |
|
430 | + 'getpaid_subscription_related_invoices_columns', |
|
431 | + array( |
|
432 | + 'invoice' => __( 'Invoice', 'invoicing' ), |
|
433 | + 'relationship' => __( 'Relationship', 'invoicing' ), |
|
434 | + 'date' => __( 'Date', 'invoicing' ), |
|
435 | + 'status' => __( 'Status', 'invoicing' ), |
|
436 | + 'total' => __( 'Total', 'invoicing' ), |
|
437 | + ), |
|
438 | + $subscription |
|
439 | + ); |
|
440 | + |
|
441 | + // Prepare the invoices. |
|
442 | + $payments = $subscription->get_child_payments( ! is_admin() ); |
|
443 | + $parent = $subscription->get_parent_invoice(); |
|
444 | + |
|
445 | + if ( $parent->exists() ) { |
|
446 | + $payments = array_merge( array( $parent ), $payments ); |
|
447 | + } |
|
448 | + |
|
449 | + $table_class = 'w-100 bg-white'; |
|
450 | + |
|
451 | + if ( ! is_admin() ) { |
|
452 | + $table_class = 'table table-bordered'; |
|
453 | + } |
|
454 | + |
|
455 | + ?> |
|
456 | 456 | <div class="m-0" style="overflow: auto;"> |
457 | 457 | |
458 | 458 | <table class="<?php echo $table_class; ?>"> |
@@ -460,14 +460,14 @@ discard block |
||
460 | 460 | <thead> |
461 | 461 | <tr> |
462 | 462 | <?php |
463 | - foreach ( $columns as $key => $label ) { |
|
464 | - $key = esc_attr( $key ); |
|
465 | - $label = esc_html( $label ); |
|
466 | - $class = 'text-left'; |
|
467 | - |
|
468 | - echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
469 | - } |
|
470 | - ?> |
|
463 | + foreach ( $columns as $key => $label ) { |
|
464 | + $key = esc_attr( $key ); |
|
465 | + $label = esc_html( $label ); |
|
466 | + $class = 'text-left'; |
|
467 | + |
|
468 | + echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
469 | + } |
|
470 | + ?> |
|
471 | 471 | </tr> |
472 | 472 | </thead> |
473 | 473 | |
@@ -483,73 +483,73 @@ discard block |
||
483 | 483 | |
484 | 484 | <?php |
485 | 485 | |
486 | - foreach( $payments as $payment ) : |
|
486 | + foreach( $payments as $payment ) : |
|
487 | 487 | |
488 | - // Ensure that we have an invoice. |
|
489 | - $payment = new WPInv_Invoice( $payment ); |
|
488 | + // Ensure that we have an invoice. |
|
489 | + $payment = new WPInv_Invoice( $payment ); |
|
490 | 490 | |
491 | - // Abort if the invoice is invalid... |
|
492 | - if ( ! $payment->exists() ) { |
|
493 | - continue; |
|
494 | - } |
|
491 | + // Abort if the invoice is invalid... |
|
492 | + if ( ! $payment->exists() ) { |
|
493 | + continue; |
|
494 | + } |
|
495 | 495 | |
496 | - // ... or belongs to a different subscription. |
|
497 | - if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) { |
|
498 | - continue; |
|
499 | - } |
|
496 | + // ... or belongs to a different subscription. |
|
497 | + if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) { |
|
498 | + continue; |
|
499 | + } |
|
500 | 500 | |
501 | - echo '<tr>'; |
|
501 | + echo '<tr>'; |
|
502 | 502 | |
503 | - foreach ( array_keys( $columns ) as $key ) { |
|
503 | + foreach ( array_keys( $columns ) as $key ) { |
|
504 | 504 | |
505 | - $class = 'text-left'; |
|
505 | + $class = 'text-left'; |
|
506 | 506 | |
507 | - echo "<td class='p-2 $class'>"; |
|
507 | + echo "<td class='p-2 $class'>"; |
|
508 | 508 | |
509 | - switch( $key ) { |
|
509 | + switch( $key ) { |
|
510 | 510 | |
511 | - case 'total': |
|
512 | - echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>'; |
|
513 | - break; |
|
511 | + case 'total': |
|
512 | + echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>'; |
|
513 | + break; |
|
514 | 514 | |
515 | - case 'relationship': |
|
516 | - echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
517 | - break; |
|
515 | + case 'relationship': |
|
516 | + echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
517 | + break; |
|
518 | 518 | |
519 | - case 'date': |
|
520 | - echo getpaid_format_date_value( $payment->get_date_created() ); |
|
521 | - break; |
|
519 | + case 'date': |
|
520 | + echo getpaid_format_date_value( $payment->get_date_created() ); |
|
521 | + break; |
|
522 | 522 | |
523 | - case 'status': |
|
523 | + case 'status': |
|
524 | 524 | |
525 | - $status = $payment->get_status_nicename(); |
|
526 | - if ( is_admin() ) { |
|
527 | - $status = $payment->get_status_label_html(); |
|
528 | - } |
|
525 | + $status = $payment->get_status_nicename(); |
|
526 | + if ( is_admin() ) { |
|
527 | + $status = $payment->get_status_label_html(); |
|
528 | + } |
|
529 | 529 | |
530 | - echo $status; |
|
531 | - break; |
|
530 | + echo $status; |
|
531 | + break; |
|
532 | 532 | |
533 | - case 'invoice': |
|
534 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
533 | + case 'invoice': |
|
534 | + $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
535 | 535 | |
536 | - if ( ! is_admin() ) { |
|
537 | - $link = esc_url( $payment->get_view_url() ); |
|
538 | - } |
|
536 | + if ( ! is_admin() ) { |
|
537 | + $link = esc_url( $payment->get_view_url() ); |
|
538 | + } |
|
539 | 539 | |
540 | - $invoice = esc_html( $payment->get_number() ); |
|
541 | - echo "<a href='$link'>$invoice</a>"; |
|
542 | - break; |
|
543 | - } |
|
540 | + $invoice = esc_html( $payment->get_number() ); |
|
541 | + echo "<a href='$link'>$invoice</a>"; |
|
542 | + break; |
|
543 | + } |
|
544 | 544 | |
545 | - echo '</td>'; |
|
545 | + echo '</td>'; |
|
546 | 546 | |
547 | - } |
|
547 | + } |
|
548 | 548 | |
549 | - echo '</tr>'; |
|
549 | + echo '</tr>'; |
|
550 | 550 | |
551 | - endforeach; |
|
552 | - ?> |
|
551 | + endforeach; |
|
552 | + ?> |
|
553 | 553 | |
554 | 554 | </tbody> |
555 | 555 | |
@@ -567,42 +567,42 @@ discard block |
||
567 | 567 | */ |
568 | 568 | function getpaid_admin_subscription_item_details_metabox( $subscription ) { |
569 | 569 | |
570 | - // Fetch the subscription group. |
|
571 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
570 | + // Fetch the subscription group. |
|
571 | + $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
572 | 572 | |
573 | - if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
574 | - return; |
|
575 | - } |
|
573 | + if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
574 | + return; |
|
575 | + } |
|
576 | 576 | |
577 | - // Prepare table columns. |
|
578 | - $columns = apply_filters( |
|
579 | - 'getpaid_subscription_item_details_columns', |
|
580 | - array( |
|
581 | - 'item_name' => __( 'Item', 'invoicing' ), |
|
582 | - 'price' => __( 'Price', 'invoicing' ), |
|
583 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
584 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
585 | - //'initial' => __( 'Initial Amount', 'invoicing' ), |
|
586 | - 'recurring' => __( 'Subtotal', 'invoicing' ), |
|
587 | - ), |
|
588 | - $subscription |
|
589 | - ); |
|
577 | + // Prepare table columns. |
|
578 | + $columns = apply_filters( |
|
579 | + 'getpaid_subscription_item_details_columns', |
|
580 | + array( |
|
581 | + 'item_name' => __( 'Item', 'invoicing' ), |
|
582 | + 'price' => __( 'Price', 'invoicing' ), |
|
583 | + 'tax' => __( 'Tax', 'invoicing' ), |
|
584 | + 'discount' => __( 'Discount', 'invoicing' ), |
|
585 | + //'initial' => __( 'Initial Amount', 'invoicing' ), |
|
586 | + 'recurring' => __( 'Subtotal', 'invoicing' ), |
|
587 | + ), |
|
588 | + $subscription |
|
589 | + ); |
|
590 | 590 | |
591 | - // Prepare the invoices. |
|
591 | + // Prepare the invoices. |
|
592 | 592 | |
593 | - $invoice = $subscription->get_parent_invoice(); |
|
593 | + $invoice = $subscription->get_parent_invoice(); |
|
594 | 594 | |
595 | - if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
596 | - unset( $columns['tax'] ); |
|
597 | - } |
|
595 | + if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
596 | + unset( $columns['tax'] ); |
|
597 | + } |
|
598 | 598 | |
599 | - $table_class = 'w-100 bg-white'; |
|
599 | + $table_class = 'w-100 bg-white'; |
|
600 | 600 | |
601 | - if ( ! is_admin() ) { |
|
602 | - $table_class = 'table table-bordered'; |
|
603 | - } |
|
601 | + if ( ! is_admin() ) { |
|
602 | + $table_class = 'table table-bordered'; |
|
603 | + } |
|
604 | 604 | |
605 | - ?> |
|
605 | + ?> |
|
606 | 606 | <div class="m-0" style="overflow: auto;"> |
607 | 607 | |
608 | 608 | <table class="<?php echo $table_class; ?>"> |
@@ -611,14 +611,14 @@ discard block |
||
611 | 611 | <tr> |
612 | 612 | <?php |
613 | 613 | |
614 | - foreach ( $columns as $key => $label ) { |
|
615 | - $key = esc_attr( $key ); |
|
616 | - $label = esc_html( $label ); |
|
617 | - $class = 'text-left'; |
|
614 | + foreach ( $columns as $key => $label ) { |
|
615 | + $key = esc_attr( $key ); |
|
616 | + $label = esc_html( $label ); |
|
617 | + $class = 'text-left'; |
|
618 | 618 | |
619 | - echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
620 | - } |
|
621 | - ?> |
|
619 | + echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
620 | + } |
|
621 | + ?> |
|
622 | 622 | </tr> |
623 | 623 | </thead> |
624 | 624 | |
@@ -626,106 +626,106 @@ discard block |
||
626 | 626 | |
627 | 627 | <?php |
628 | 628 | |
629 | - foreach( $subscription_group['items'] as $subscription_group_item ) : |
|
629 | + foreach( $subscription_group['items'] as $subscription_group_item ) : |
|
630 | 630 | |
631 | - echo '<tr>'; |
|
631 | + echo '<tr>'; |
|
632 | 632 | |
633 | - foreach ( array_keys( $columns ) as $key ) { |
|
633 | + foreach ( array_keys( $columns ) as $key ) { |
|
634 | 634 | |
635 | - $class = 'text-left'; |
|
635 | + $class = 'text-left'; |
|
636 | 636 | |
637 | - echo "<td class='p-2 $class'>"; |
|
637 | + echo "<td class='p-2 $class'>"; |
|
638 | 638 | |
639 | - switch( $key ) { |
|
639 | + switch( $key ) { |
|
640 | 640 | |
641 | - case 'item_name': |
|
642 | - $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
643 | - $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
641 | + case 'item_name': |
|
642 | + $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
643 | + $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
644 | 644 | |
645 | - if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) { |
|
646 | - echo esc_html( $item_name ); |
|
647 | - } else { |
|
648 | - printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] ); |
|
649 | - } |
|
645 | + if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) { |
|
646 | + echo esc_html( $item_name ); |
|
647 | + } else { |
|
648 | + printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] ); |
|
649 | + } |
|
650 | 650 | |
651 | - break; |
|
651 | + break; |
|
652 | 652 | |
653 | - case 'price': |
|
654 | - echo wpinv_price( $subscription_group_item['item_price'], $invoice->get_currency() ); |
|
655 | - break; |
|
653 | + case 'price': |
|
654 | + echo wpinv_price( $subscription_group_item['item_price'], $invoice->get_currency() ); |
|
655 | + break; |
|
656 | 656 | |
657 | - case 'tax': |
|
658 | - echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
659 | - break; |
|
657 | + case 'tax': |
|
658 | + echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
659 | + break; |
|
660 | 660 | |
661 | - case 'discount': |
|
662 | - echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
663 | - break; |
|
661 | + case 'discount': |
|
662 | + echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
663 | + break; |
|
664 | 664 | |
665 | - case 'initial': |
|
666 | - echo wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ); |
|
667 | - break; |
|
665 | + case 'initial': |
|
666 | + echo wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ); |
|
667 | + break; |
|
668 | 668 | |
669 | - case 'recurring': |
|
670 | - echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>'; |
|
671 | - break; |
|
669 | + case 'recurring': |
|
670 | + echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>'; |
|
671 | + break; |
|
672 | 672 | |
673 | - } |
|
673 | + } |
|
674 | 674 | |
675 | - echo '</td>'; |
|
675 | + echo '</td>'; |
|
676 | 676 | |
677 | - } |
|
677 | + } |
|
678 | 678 | |
679 | - echo '</tr>'; |
|
679 | + echo '</tr>'; |
|
680 | 680 | |
681 | - endforeach; |
|
681 | + endforeach; |
|
682 | 682 | |
683 | - foreach( $subscription_group['fees'] as $subscription_group_fee ) : |
|
683 | + foreach( $subscription_group['fees'] as $subscription_group_fee ) : |
|
684 | 684 | |
685 | - echo '<tr>'; |
|
685 | + echo '<tr>'; |
|
686 | 686 | |
687 | - foreach ( array_keys( $columns ) as $key ) { |
|
687 | + foreach ( array_keys( $columns ) as $key ) { |
|
688 | 688 | |
689 | - $class = 'text-left'; |
|
689 | + $class = 'text-left'; |
|
690 | 690 | |
691 | - echo "<td class='p-2 $class'>"; |
|
691 | + echo "<td class='p-2 $class'>"; |
|
692 | 692 | |
693 | - switch( $key ) { |
|
693 | + switch( $key ) { |
|
694 | 694 | |
695 | - case 'item_name': |
|
696 | - echo esc_html( $subscription_group_fee['name'] ); |
|
697 | - break; |
|
695 | + case 'item_name': |
|
696 | + echo esc_html( $subscription_group_fee['name'] ); |
|
697 | + break; |
|
698 | 698 | |
699 | - case 'price': |
|
700 | - echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
701 | - break; |
|
699 | + case 'price': |
|
700 | + echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
701 | + break; |
|
702 | 702 | |
703 | - case 'tax': |
|
704 | - echo "—"; |
|
705 | - break; |
|
703 | + case 'tax': |
|
704 | + echo "—"; |
|
705 | + break; |
|
706 | 706 | |
707 | - case 'discount': |
|
708 | - echo "—"; |
|
709 | - break; |
|
707 | + case 'discount': |
|
708 | + echo "—"; |
|
709 | + break; |
|
710 | 710 | |
711 | - case 'initial': |
|
712 | - echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
713 | - break; |
|
711 | + case 'initial': |
|
712 | + echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
713 | + break; |
|
714 | 714 | |
715 | - case 'recurring': |
|
716 | - echo '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>'; |
|
717 | - break; |
|
715 | + case 'recurring': |
|
716 | + echo '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>'; |
|
717 | + break; |
|
718 | 718 | |
719 | - } |
|
719 | + } |
|
720 | 720 | |
721 | - echo '</td>'; |
|
721 | + echo '</td>'; |
|
722 | 722 | |
723 | - } |
|
723 | + } |
|
724 | 724 | |
725 | - echo '</tr>'; |
|
725 | + echo '</tr>'; |
|
726 | 726 | |
727 | - endforeach; |
|
728 | - ?> |
|
727 | + endforeach; |
|
728 | + ?> |
|
729 | 729 | |
730 | 730 | </tbody> |
731 | 731 | |
@@ -744,38 +744,38 @@ discard block |
||
744 | 744 | */ |
745 | 745 | function getpaid_admin_subscription_related_subscriptions_metabox( $subscription, $skip_current = true ) { |
746 | 746 | |
747 | - // Fetch the subscription groups. |
|
748 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
749 | - |
|
750 | - if ( empty( $subscription_groups ) ) { |
|
751 | - return; |
|
752 | - } |
|
753 | - |
|
754 | - // Prepare table columns. |
|
755 | - $columns = apply_filters( |
|
756 | - 'getpaid_subscription_related_subscriptions_columns', |
|
757 | - array( |
|
758 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
759 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
760 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
761 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
762 | - 'item' => __( 'Items', 'invoicing' ), |
|
763 | - 'status' => __( 'Status', 'invoicing' ), |
|
764 | - ), |
|
765 | - $subscription |
|
766 | - ); |
|
767 | - |
|
768 | - if ( $subscription->get_status() == 'pending' ) { |
|
769 | - unset( $columns['start_date'], $columns['renewal_date'] ); |
|
770 | - } |
|
771 | - |
|
772 | - $table_class = 'w-100 bg-white'; |
|
773 | - |
|
774 | - if ( ! is_admin() ) { |
|
775 | - $table_class = 'table table-bordered'; |
|
776 | - } |
|
777 | - |
|
778 | - ?> |
|
747 | + // Fetch the subscription groups. |
|
748 | + $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
749 | + |
|
750 | + if ( empty( $subscription_groups ) ) { |
|
751 | + return; |
|
752 | + } |
|
753 | + |
|
754 | + // Prepare table columns. |
|
755 | + $columns = apply_filters( |
|
756 | + 'getpaid_subscription_related_subscriptions_columns', |
|
757 | + array( |
|
758 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
759 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
760 | + 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
761 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
762 | + 'item' => __( 'Items', 'invoicing' ), |
|
763 | + 'status' => __( 'Status', 'invoicing' ), |
|
764 | + ), |
|
765 | + $subscription |
|
766 | + ); |
|
767 | + |
|
768 | + if ( $subscription->get_status() == 'pending' ) { |
|
769 | + unset( $columns['start_date'], $columns['renewal_date'] ); |
|
770 | + } |
|
771 | + |
|
772 | + $table_class = 'w-100 bg-white'; |
|
773 | + |
|
774 | + if ( ! is_admin() ) { |
|
775 | + $table_class = 'table table-bordered'; |
|
776 | + } |
|
777 | + |
|
778 | + ?> |
|
779 | 779 | <div class="m-0" style="overflow: auto;"> |
780 | 780 | |
781 | 781 | <table class="<?php echo $table_class; ?>"> |
@@ -784,14 +784,14 @@ discard block |
||
784 | 784 | <tr> |
785 | 785 | <?php |
786 | 786 | |
787 | - foreach ( $columns as $key => $label ) { |
|
788 | - $key = esc_attr( $key ); |
|
789 | - $label = esc_html( $label ); |
|
790 | - $class = 'text-left'; |
|
787 | + foreach ( $columns as $key => $label ) { |
|
788 | + $key = esc_attr( $key ); |
|
789 | + $label = esc_html( $label ); |
|
790 | + $class = 'text-left'; |
|
791 | 791 | |
792 | - echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
793 | - } |
|
794 | - ?> |
|
792 | + echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
793 | + } |
|
794 | + ?> |
|
795 | 795 | </tr> |
796 | 796 | </thead> |
797 | 797 | |
@@ -799,74 +799,74 @@ discard block |
||
799 | 799 | |
800 | 800 | <?php |
801 | 801 | |
802 | - foreach( $subscription_groups as $subscription_group ) : |
|
802 | + foreach( $subscription_groups as $subscription_group ) : |
|
803 | 803 | |
804 | - // Do not list current subscription. |
|
805 | - if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
806 | - continue; |
|
807 | - } |
|
804 | + // Do not list current subscription. |
|
805 | + if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
806 | + continue; |
|
807 | + } |
|
808 | 808 | |
809 | - // Ensure the subscription exists. |
|
810 | - $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
809 | + // Ensure the subscription exists. |
|
810 | + $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
811 | 811 | |
812 | - if ( ! $_suscription->exists() ) { |
|
813 | - continue; |
|
814 | - } |
|
812 | + if ( ! $_suscription->exists() ) { |
|
813 | + continue; |
|
814 | + } |
|
815 | 815 | |
816 | - echo '<tr>'; |
|
816 | + echo '<tr>'; |
|
817 | 817 | |
818 | - foreach ( array_keys( $columns ) as $key ) { |
|
818 | + foreach ( array_keys( $columns ) as $key ) { |
|
819 | 819 | |
820 | - $class = 'text-left'; |
|
820 | + $class = 'text-left'; |
|
821 | 821 | |
822 | - echo "<td class='p-2 $class'>"; |
|
822 | + echo "<td class='p-2 $class'>"; |
|
823 | 823 | |
824 | - switch( $key ) { |
|
824 | + switch( $key ) { |
|
825 | 825 | |
826 | - case 'status': |
|
827 | - echo $_suscription->get_status_label_html(); |
|
828 | - break; |
|
826 | + case 'status': |
|
827 | + echo $_suscription->get_status_label_html(); |
|
828 | + break; |
|
829 | 829 | |
830 | - case 'item': |
|
831 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
832 | - echo implode( ' | ', $markup ); |
|
833 | - break; |
|
830 | + case 'item': |
|
831 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
832 | + echo implode( ' | ', $markup ); |
|
833 | + break; |
|
834 | 834 | |
835 | - case 'renewals': |
|
836 | - $max_bills = $_suscription->get_bill_times(); |
|
837 | - echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
838 | - break; |
|
835 | + case 'renewals': |
|
836 | + $max_bills = $_suscription->get_bill_times(); |
|
837 | + echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
838 | + break; |
|
839 | 839 | |
840 | - case 'renewal_date': |
|
841 | - echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "—"; |
|
842 | - break; |
|
840 | + case 'renewal_date': |
|
841 | + echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "—"; |
|
842 | + break; |
|
843 | 843 | |
844 | - case 'start_date': |
|
845 | - echo 'pending' == $_suscription->get_status() ? "—" : getpaid_format_date_value( $_suscription->get_date_created() ); |
|
846 | - break; |
|
844 | + case 'start_date': |
|
845 | + echo 'pending' == $_suscription->get_status() ? "—" : getpaid_format_date_value( $_suscription->get_date_created() ); |
|
846 | + break; |
|
847 | 847 | |
848 | - case 'subscription': |
|
849 | - $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
850 | - printf( |
|
851 | - '%1$s#%2$s%3$s', |
|
852 | - '<a href="' . esc_url( $url ) . '">', |
|
853 | - '<strong>' . intval( $_suscription->get_id() ) . '</strong>', |
|
854 | - '</a>' |
|
855 | - ); |
|
848 | + case 'subscription': |
|
849 | + $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
850 | + printf( |
|
851 | + '%1$s#%2$s%3$s', |
|
852 | + '<a href="' . esc_url( $url ) . '">', |
|
853 | + '<strong>' . intval( $_suscription->get_id() ) . '</strong>', |
|
854 | + '</a>' |
|
855 | + ); |
|
856 | 856 | |
857 | - echo WPInv_Subscriptions_List_Table::column_amount( $_suscription ); |
|
858 | - break; |
|
857 | + echo WPInv_Subscriptions_List_Table::column_amount( $_suscription ); |
|
858 | + break; |
|
859 | 859 | |
860 | - } |
|
860 | + } |
|
861 | 861 | |
862 | - echo '</td>'; |
|
862 | + echo '</td>'; |
|
863 | 863 | |
864 | - } |
|
864 | + } |
|
865 | 865 | |
866 | - echo '</tr>'; |
|
866 | + echo '</tr>'; |
|
867 | 867 | |
868 | - endforeach; |
|
869 | - ?> |
|
868 | + endforeach; |
|
869 | + ?> |
|
870 | 870 | |
871 | 871 | </tbody> |
872 | 872 |
@@ -12,47 +12,47 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Export { |
14 | 14 | |
15 | - /** |
|
16 | - * Displays the reports tab. |
|
17 | - * |
|
18 | - */ |
|
19 | - public function display() { |
|
20 | - |
|
21 | - echo "<div class='row mt-4' style='max-width: 920px;' >"; |
|
22 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
23 | - $this->display_post_type_export( $post_type ); |
|
24 | - } |
|
25 | - $this->display_subscription_export(); |
|
26 | - echo "</div>"; |
|
27 | - |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * Retrieves the download url. |
|
32 | - * |
|
33 | - */ |
|
34 | - public function get_download_url( $post_type ) { |
|
35 | - |
|
36 | - return wp_nonce_url( |
|
37 | - add_query_arg( |
|
38 | - array( |
|
39 | - 'getpaid-admin-action' => 'export_invoices', |
|
40 | - 'post_type' => urlencode( $post_type ), |
|
41 | - ) |
|
42 | - ), |
|
43 | - 'getpaid-nonce', |
|
44 | - 'getpaid-nonce' |
|
45 | - ); |
|
46 | - |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Displays a single post type export card. |
|
51 | - * |
|
52 | - */ |
|
53 | - public function display_post_type_export( $post_type ) { |
|
54 | - |
|
55 | - ?> |
|
15 | + /** |
|
16 | + * Displays the reports tab. |
|
17 | + * |
|
18 | + */ |
|
19 | + public function display() { |
|
20 | + |
|
21 | + echo "<div class='row mt-4' style='max-width: 920px;' >"; |
|
22 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
23 | + $this->display_post_type_export( $post_type ); |
|
24 | + } |
|
25 | + $this->display_subscription_export(); |
|
26 | + echo "</div>"; |
|
27 | + |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * Retrieves the download url. |
|
32 | + * |
|
33 | + */ |
|
34 | + public function get_download_url( $post_type ) { |
|
35 | + |
|
36 | + return wp_nonce_url( |
|
37 | + add_query_arg( |
|
38 | + array( |
|
39 | + 'getpaid-admin-action' => 'export_invoices', |
|
40 | + 'post_type' => urlencode( $post_type ), |
|
41 | + ) |
|
42 | + ), |
|
43 | + 'getpaid-nonce', |
|
44 | + 'getpaid-nonce' |
|
45 | + ); |
|
46 | + |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Displays a single post type export card. |
|
51 | + * |
|
52 | + */ |
|
53 | + public function display_post_type_export( $post_type ) { |
|
54 | + |
|
55 | + ?> |
|
56 | 56 | |
57 | 57 | <div class="col-12 col-md-6"> |
58 | 58 | <div class="card m-0 p-0" style="max-width:100%"> |
@@ -60,11 +60,11 @@ discard block |
||
60 | 60 | <div class="card-header"> |
61 | 61 | <strong> |
62 | 62 | <?php |
63 | - printf( |
|
64 | - __( 'Export %s', 'invoicing' ), |
|
65 | - sanitize_text_field( getpaid_get_post_type_label( $post_type ) ) |
|
66 | - ); |
|
67 | - ?> |
|
63 | + printf( |
|
64 | + __( 'Export %s', 'invoicing' ), |
|
65 | + sanitize_text_field( getpaid_get_post_type_label( $post_type ) ) |
|
66 | + ); |
|
67 | + ?> |
|
68 | 68 | </strong> |
69 | 69 | </div> |
70 | 70 | |
@@ -73,12 +73,12 @@ discard block |
||
73 | 73 | <form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>"> |
74 | 74 | |
75 | 75 | <?php |
76 | - $this->display_markup( $this->generate_from_date( $post_type ) ); |
|
77 | - $this->display_markup( $this->generate_to_date( $post_type ) ); |
|
78 | - $this->display_markup( $this->generate_post_status_select( $post_type ) ); |
|
79 | - $this->display_markup( $this->generate_file_type_select( $post_type ) ); |
|
80 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
81 | - ?> |
|
76 | + $this->display_markup( $this->generate_from_date( $post_type ) ); |
|
77 | + $this->display_markup( $this->generate_to_date( $post_type ) ); |
|
78 | + $this->display_markup( $this->generate_post_status_select( $post_type ) ); |
|
79 | + $this->display_markup( $this->generate_file_type_select( $post_type ) ); |
|
80 | + submit_button( __( 'Download', 'invoicing' ) ); |
|
81 | + ?> |
|
82 | 82 | |
83 | 83 | </form> |
84 | 84 | |
@@ -89,122 +89,122 @@ discard block |
||
89 | 89 | |
90 | 90 | <?php |
91 | 91 | |
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Generates the from date input field. |
|
96 | - * |
|
97 | - */ |
|
98 | - public function generate_from_date( $post_type ) { |
|
99 | - |
|
100 | - return aui()->input( |
|
101 | - array( |
|
102 | - 'name' => 'from_date', |
|
103 | - 'id' => esc_attr( "$post_type-from_date" ), |
|
104 | - 'placeholder'=> 'yy-mm-dd', |
|
105 | - 'label' => __( 'From Date', 'invoicing' ), |
|
106 | - 'label_type' => 'vertical', |
|
107 | - 'label_class' => 'd-block', |
|
108 | - 'type' => 'datepicker', |
|
109 | - ) |
|
110 | - ); |
|
111 | - |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Generates the to date input field. |
|
116 | - * |
|
117 | - */ |
|
118 | - public function generate_to_date( $post_type ) { |
|
119 | - |
|
120 | - return aui()->input( |
|
121 | - array( |
|
122 | - 'name' => 'to_date', |
|
123 | - 'id' => esc_attr( "$post_type-to_date" ), |
|
124 | - 'placeholder'=> 'yy-mm-dd', |
|
125 | - 'label' => __( 'To Date', 'invoicing' ), |
|
126 | - 'label_type' => 'vertical', |
|
127 | - 'label_class' => 'd-block', |
|
128 | - 'type' => 'datepicker', |
|
129 | - ) |
|
130 | - ); |
|
131 | - |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Generates the to post status select field. |
|
136 | - * |
|
137 | - */ |
|
138 | - public function generate_post_status_select( $post_type ) { |
|
139 | - |
|
140 | - if ( 'subscriptions' === $post_type ) { |
|
141 | - $options = getpaid_get_subscription_statuses(); |
|
142 | - } else { |
|
143 | - $options = wpinv_get_invoice_statuses( true, false, $post_type ); |
|
144 | - } |
|
145 | - |
|
146 | - return aui()->select( |
|
147 | - array( |
|
148 | - 'name' => 'status', |
|
149 | - 'id' => esc_attr( "$post_type-status" ), |
|
150 | - 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
151 | - 'label' => __( 'Status', 'invoicing' ), |
|
152 | - 'label_type' => 'vertical', |
|
153 | - 'label_class' => 'd-block', |
|
154 | - 'options' => $options, |
|
155 | - ) |
|
156 | - ); |
|
157 | - |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Generates the to file type select field. |
|
162 | - * |
|
163 | - */ |
|
164 | - public function generate_file_type_select( $post_type ) { |
|
165 | - |
|
166 | - return aui()->select( |
|
167 | - array( |
|
168 | - 'name' => 'file_type', |
|
169 | - 'id' => esc_attr( "$post_type-file_type" ), |
|
170 | - 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
171 | - 'label' => __( 'Export File', 'invoicing' ), |
|
172 | - 'label_type' => 'vertical', |
|
173 | - 'label_class' => 'd-block', |
|
174 | - 'options' => array( |
|
175 | - 'csv' => __( 'CSV', 'invoicing' ), |
|
176 | - 'xml' => __( 'XML', 'invoicing' ), |
|
177 | - 'json' => __( 'JSON', 'invoicing' ), |
|
178 | - ), |
|
179 | - ) |
|
180 | - ); |
|
181 | - |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Displays a field's markup. |
|
186 | - * |
|
187 | - */ |
|
188 | - public function display_markup( $markup ) { |
|
189 | - |
|
190 | - echo str_replace( |
|
191 | - array( |
|
192 | - 'form-control', |
|
193 | - 'custom-select' |
|
194 | - ), |
|
195 | - 'regular-text', |
|
196 | - $markup |
|
197 | - ); |
|
198 | - |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Displays a subscription export card. |
|
203 | - * |
|
204 | - */ |
|
205 | - public function display_subscription_export() { |
|
206 | - |
|
207 | - ?> |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Generates the from date input field. |
|
96 | + * |
|
97 | + */ |
|
98 | + public function generate_from_date( $post_type ) { |
|
99 | + |
|
100 | + return aui()->input( |
|
101 | + array( |
|
102 | + 'name' => 'from_date', |
|
103 | + 'id' => esc_attr( "$post_type-from_date" ), |
|
104 | + 'placeholder'=> 'yy-mm-dd', |
|
105 | + 'label' => __( 'From Date', 'invoicing' ), |
|
106 | + 'label_type' => 'vertical', |
|
107 | + 'label_class' => 'd-block', |
|
108 | + 'type' => 'datepicker', |
|
109 | + ) |
|
110 | + ); |
|
111 | + |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Generates the to date input field. |
|
116 | + * |
|
117 | + */ |
|
118 | + public function generate_to_date( $post_type ) { |
|
119 | + |
|
120 | + return aui()->input( |
|
121 | + array( |
|
122 | + 'name' => 'to_date', |
|
123 | + 'id' => esc_attr( "$post_type-to_date" ), |
|
124 | + 'placeholder'=> 'yy-mm-dd', |
|
125 | + 'label' => __( 'To Date', 'invoicing' ), |
|
126 | + 'label_type' => 'vertical', |
|
127 | + 'label_class' => 'd-block', |
|
128 | + 'type' => 'datepicker', |
|
129 | + ) |
|
130 | + ); |
|
131 | + |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Generates the to post status select field. |
|
136 | + * |
|
137 | + */ |
|
138 | + public function generate_post_status_select( $post_type ) { |
|
139 | + |
|
140 | + if ( 'subscriptions' === $post_type ) { |
|
141 | + $options = getpaid_get_subscription_statuses(); |
|
142 | + } else { |
|
143 | + $options = wpinv_get_invoice_statuses( true, false, $post_type ); |
|
144 | + } |
|
145 | + |
|
146 | + return aui()->select( |
|
147 | + array( |
|
148 | + 'name' => 'status', |
|
149 | + 'id' => esc_attr( "$post_type-status" ), |
|
150 | + 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
151 | + 'label' => __( 'Status', 'invoicing' ), |
|
152 | + 'label_type' => 'vertical', |
|
153 | + 'label_class' => 'd-block', |
|
154 | + 'options' => $options, |
|
155 | + ) |
|
156 | + ); |
|
157 | + |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Generates the to file type select field. |
|
162 | + * |
|
163 | + */ |
|
164 | + public function generate_file_type_select( $post_type ) { |
|
165 | + |
|
166 | + return aui()->select( |
|
167 | + array( |
|
168 | + 'name' => 'file_type', |
|
169 | + 'id' => esc_attr( "$post_type-file_type" ), |
|
170 | + 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
171 | + 'label' => __( 'Export File', 'invoicing' ), |
|
172 | + 'label_type' => 'vertical', |
|
173 | + 'label_class' => 'd-block', |
|
174 | + 'options' => array( |
|
175 | + 'csv' => __( 'CSV', 'invoicing' ), |
|
176 | + 'xml' => __( 'XML', 'invoicing' ), |
|
177 | + 'json' => __( 'JSON', 'invoicing' ), |
|
178 | + ), |
|
179 | + ) |
|
180 | + ); |
|
181 | + |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Displays a field's markup. |
|
186 | + * |
|
187 | + */ |
|
188 | + public function display_markup( $markup ) { |
|
189 | + |
|
190 | + echo str_replace( |
|
191 | + array( |
|
192 | + 'form-control', |
|
193 | + 'custom-select' |
|
194 | + ), |
|
195 | + 'regular-text', |
|
196 | + $markup |
|
197 | + ); |
|
198 | + |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Displays a subscription export card. |
|
203 | + * |
|
204 | + */ |
|
205 | + public function display_subscription_export() { |
|
206 | + |
|
207 | + ?> |
|
208 | 208 | |
209 | 209 | <div class="col-12 col-md-6"> |
210 | 210 | <div class="card m-0 p-0" style="max-width:100%"> |
@@ -220,12 +220,12 @@ discard block |
||
220 | 220 | <form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>"> |
221 | 221 | |
222 | 222 | <?php |
223 | - $this->display_markup( $this->generate_from_date( 'subscriptions' ) ); |
|
224 | - $this->display_markup( $this->generate_to_date( 'subscriptions' ) ); |
|
225 | - $this->display_markup( $this->generate_post_status_select( 'subscriptions' ) ); |
|
226 | - $this->display_markup( $this->generate_file_type_select( 'subscriptions' ) ); |
|
227 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
228 | - ?> |
|
223 | + $this->display_markup( $this->generate_from_date( 'subscriptions' ) ); |
|
224 | + $this->display_markup( $this->generate_to_date( 'subscriptions' ) ); |
|
225 | + $this->display_markup( $this->generate_post_status_select( 'subscriptions' ) ); |
|
226 | + $this->display_markup( $this->generate_file_type_select( 'subscriptions' ) ); |
|
227 | + submit_button( __( 'Download', 'invoicing' ) ); |
|
228 | + ?> |
|
229 | 229 | |
230 | 230 | </form> |
231 | 231 | |
@@ -236,6 +236,6 @@ discard block |
||
236 | 236 | |
237 | 237 | <?php |
238 | 238 | |
239 | - } |
|
239 | + } |
|
240 | 240 | |
241 | 241 | } |
@@ -12,177 +12,177 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Subscription_Exporter extends GetPaid_Graph_Downloader { |
14 | 14 | |
15 | - /** |
|
16 | - * Retrieves subscription query args. |
|
17 | - * |
|
18 | - * @param array $args Args to search for. |
|
19 | - * @return array |
|
20 | - */ |
|
21 | - public function get_subscription_query_args( $args ) { |
|
22 | - |
|
23 | - $query_args = array( |
|
24 | - 'status' => 'all', |
|
25 | - 'number' => -1, |
|
26 | - 'count_total' => false, |
|
27 | - 'fields' => 'all', |
|
28 | - ); |
|
29 | - |
|
30 | - if ( ! empty( $args['status'] ) && in_array( $args['status'], array_keys( getpaid_get_subscription_statuses() ), true ) ) { |
|
31 | - $query_args['status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
32 | - } |
|
33 | - |
|
34 | - $date_query = array(); |
|
35 | - if ( ! empty( $args['to_date'] ) ) { |
|
36 | - $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
37 | - } |
|
38 | - |
|
39 | - if ( ! empty( $args['from_date'] ) ) { |
|
40 | - $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
41 | - } |
|
42 | - |
|
43 | - if ( ! empty( $date_query ) ) { |
|
44 | - $date_query['inclusive'] = true; |
|
45 | - $query_args['date_created_query'] = array( $date_query ); |
|
46 | - } |
|
47 | - |
|
48 | - return $query_args; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Retrieves subscriptions. |
|
53 | - * |
|
54 | - * @param array $query_args GetPaid_Subscriptions_Query args. |
|
55 | - * @return WPInv_Subscription[] |
|
56 | - */ |
|
57 | - public function get_subscriptions( $query_args ) { |
|
58 | - |
|
59 | - // Get subscriptions. |
|
60 | - $subscriptions = new GetPaid_Subscriptions_Query( $query_args ); |
|
61 | - |
|
62 | - // Prepare the results. |
|
63 | - return $subscriptions->get_results(); |
|
64 | - |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Handles the actual download. |
|
69 | - * |
|
70 | - */ |
|
71 | - public function export( $post_type, $args ) { |
|
72 | - |
|
73 | - $subscriptions = $this->get_subscriptions( $this->get_subscription_query_args( $args ) ); |
|
74 | - $stream = $this->prepare_output(); |
|
75 | - $headers = $this->get_export_fields(); |
|
76 | - $file_type = $this->prepare_file_type( 'subscriptions' ); |
|
77 | - |
|
78 | - if ( 'csv' == $file_type ) { |
|
79 | - $this->download_csv( $subscriptions, $stream, $headers ); |
|
80 | - } else if( 'xml' == $file_type ) { |
|
81 | - $this->download_xml( $subscriptions, $stream, $headers ); |
|
82 | - } else { |
|
83 | - $this->download_json( $subscriptions, $stream, $headers ); |
|
84 | - } |
|
85 | - |
|
86 | - fclose( $stream ); |
|
87 | - exit; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Prepares a single subscription for download. |
|
92 | - * |
|
93 | - * @param WPInv_Subscription $subscription The subscription to prepare.. |
|
94 | - * @param array $fields The fields to stream. |
|
95 | - * @since 1.0.19 |
|
96 | - * @return array |
|
97 | - */ |
|
98 | - public function prepare_row( $subscription, $fields ) { |
|
99 | - |
|
100 | - $prepared = array(); |
|
101 | - $amount_fields = $this->get_amount_fields(); |
|
102 | - $invoice = $subscription->get_parent_payment(); |
|
103 | - |
|
104 | - foreach ( $fields as $field ) { |
|
105 | - |
|
106 | - $value = ''; |
|
107 | - $method = "get_$field"; |
|
108 | - |
|
109 | - if ( 0 === stripos( $field, 'customer' ) || 'currency' === $field ) { |
|
110 | - |
|
111 | - if ( method_exists( $invoice, $method ) ) { |
|
112 | - $value = $invoice->$method(); |
|
113 | - } |
|
114 | - |
|
115 | - } else if ( method_exists( $subscription, $method ) ) { |
|
116 | - $value = $subscription->$method(); |
|
117 | - } |
|
118 | - |
|
119 | - if ( in_array( $field, $amount_fields ) ) { |
|
120 | - $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
121 | - } |
|
122 | - |
|
123 | - $prepared[ $field ] = wpinv_clean( $value ); |
|
124 | - |
|
125 | - } |
|
126 | - |
|
127 | - return $prepared; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Retrieves export fields. |
|
132 | - * |
|
133 | - * @since 1.0.19 |
|
134 | - * @return array |
|
135 | - */ |
|
136 | - public function get_export_fields() { |
|
137 | - |
|
138 | - $fields = array( |
|
139 | - 'id', |
|
140 | - 'currency', |
|
141 | - 'initial_amount', |
|
142 | - 'recurring_amount', |
|
143 | - 'trial_period', |
|
144 | - 'frequency', |
|
145 | - 'period', |
|
146 | - 'bill_times', |
|
147 | - 'parent_payment_id', |
|
148 | - 'profile_id', |
|
149 | - 'product_id', |
|
150 | - 'status', |
|
151 | - 'date_created', |
|
152 | - 'date_expires', |
|
153 | - |
|
154 | - 'customer_id', |
|
155 | - 'customer_first_name', |
|
156 | - 'customer_last_name', |
|
157 | - 'customer_phone', |
|
158 | - 'customer_email', |
|
159 | - 'customer_country', |
|
160 | - 'customer_city', |
|
161 | - 'customer_state', |
|
162 | - 'customer_zip', |
|
163 | - 'customer_company', |
|
164 | - 'customer_vat_number', |
|
165 | - 'customer_address', |
|
166 | - |
|
167 | - ); |
|
168 | - |
|
169 | - return apply_filters( 'getpaid_subscription_exporter_get_fields', $fields ); |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Retrieves amount fields. |
|
174 | - * |
|
175 | - * @since 1.0.19 |
|
176 | - * @return array |
|
177 | - */ |
|
178 | - public function get_amount_fields() { |
|
179 | - |
|
180 | - $fields = array( |
|
181 | - 'initial_amount', |
|
182 | - 'recurring_amount' |
|
183 | - ); |
|
184 | - |
|
185 | - return apply_filters( 'getpaid_subscription_exporter_get_amount_fields', $fields ); |
|
186 | - } |
|
15 | + /** |
|
16 | + * Retrieves subscription query args. |
|
17 | + * |
|
18 | + * @param array $args Args to search for. |
|
19 | + * @return array |
|
20 | + */ |
|
21 | + public function get_subscription_query_args( $args ) { |
|
22 | + |
|
23 | + $query_args = array( |
|
24 | + 'status' => 'all', |
|
25 | + 'number' => -1, |
|
26 | + 'count_total' => false, |
|
27 | + 'fields' => 'all', |
|
28 | + ); |
|
29 | + |
|
30 | + if ( ! empty( $args['status'] ) && in_array( $args['status'], array_keys( getpaid_get_subscription_statuses() ), true ) ) { |
|
31 | + $query_args['status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
32 | + } |
|
33 | + |
|
34 | + $date_query = array(); |
|
35 | + if ( ! empty( $args['to_date'] ) ) { |
|
36 | + $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
37 | + } |
|
38 | + |
|
39 | + if ( ! empty( $args['from_date'] ) ) { |
|
40 | + $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
41 | + } |
|
42 | + |
|
43 | + if ( ! empty( $date_query ) ) { |
|
44 | + $date_query['inclusive'] = true; |
|
45 | + $query_args['date_created_query'] = array( $date_query ); |
|
46 | + } |
|
47 | + |
|
48 | + return $query_args; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Retrieves subscriptions. |
|
53 | + * |
|
54 | + * @param array $query_args GetPaid_Subscriptions_Query args. |
|
55 | + * @return WPInv_Subscription[] |
|
56 | + */ |
|
57 | + public function get_subscriptions( $query_args ) { |
|
58 | + |
|
59 | + // Get subscriptions. |
|
60 | + $subscriptions = new GetPaid_Subscriptions_Query( $query_args ); |
|
61 | + |
|
62 | + // Prepare the results. |
|
63 | + return $subscriptions->get_results(); |
|
64 | + |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Handles the actual download. |
|
69 | + * |
|
70 | + */ |
|
71 | + public function export( $post_type, $args ) { |
|
72 | + |
|
73 | + $subscriptions = $this->get_subscriptions( $this->get_subscription_query_args( $args ) ); |
|
74 | + $stream = $this->prepare_output(); |
|
75 | + $headers = $this->get_export_fields(); |
|
76 | + $file_type = $this->prepare_file_type( 'subscriptions' ); |
|
77 | + |
|
78 | + if ( 'csv' == $file_type ) { |
|
79 | + $this->download_csv( $subscriptions, $stream, $headers ); |
|
80 | + } else if( 'xml' == $file_type ) { |
|
81 | + $this->download_xml( $subscriptions, $stream, $headers ); |
|
82 | + } else { |
|
83 | + $this->download_json( $subscriptions, $stream, $headers ); |
|
84 | + } |
|
85 | + |
|
86 | + fclose( $stream ); |
|
87 | + exit; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Prepares a single subscription for download. |
|
92 | + * |
|
93 | + * @param WPInv_Subscription $subscription The subscription to prepare.. |
|
94 | + * @param array $fields The fields to stream. |
|
95 | + * @since 1.0.19 |
|
96 | + * @return array |
|
97 | + */ |
|
98 | + public function prepare_row( $subscription, $fields ) { |
|
99 | + |
|
100 | + $prepared = array(); |
|
101 | + $amount_fields = $this->get_amount_fields(); |
|
102 | + $invoice = $subscription->get_parent_payment(); |
|
103 | + |
|
104 | + foreach ( $fields as $field ) { |
|
105 | + |
|
106 | + $value = ''; |
|
107 | + $method = "get_$field"; |
|
108 | + |
|
109 | + if ( 0 === stripos( $field, 'customer' ) || 'currency' === $field ) { |
|
110 | + |
|
111 | + if ( method_exists( $invoice, $method ) ) { |
|
112 | + $value = $invoice->$method(); |
|
113 | + } |
|
114 | + |
|
115 | + } else if ( method_exists( $subscription, $method ) ) { |
|
116 | + $value = $subscription->$method(); |
|
117 | + } |
|
118 | + |
|
119 | + if ( in_array( $field, $amount_fields ) ) { |
|
120 | + $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
121 | + } |
|
122 | + |
|
123 | + $prepared[ $field ] = wpinv_clean( $value ); |
|
124 | + |
|
125 | + } |
|
126 | + |
|
127 | + return $prepared; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Retrieves export fields. |
|
132 | + * |
|
133 | + * @since 1.0.19 |
|
134 | + * @return array |
|
135 | + */ |
|
136 | + public function get_export_fields() { |
|
137 | + |
|
138 | + $fields = array( |
|
139 | + 'id', |
|
140 | + 'currency', |
|
141 | + 'initial_amount', |
|
142 | + 'recurring_amount', |
|
143 | + 'trial_period', |
|
144 | + 'frequency', |
|
145 | + 'period', |
|
146 | + 'bill_times', |
|
147 | + 'parent_payment_id', |
|
148 | + 'profile_id', |
|
149 | + 'product_id', |
|
150 | + 'status', |
|
151 | + 'date_created', |
|
152 | + 'date_expires', |
|
153 | + |
|
154 | + 'customer_id', |
|
155 | + 'customer_first_name', |
|
156 | + 'customer_last_name', |
|
157 | + 'customer_phone', |
|
158 | + 'customer_email', |
|
159 | + 'customer_country', |
|
160 | + 'customer_city', |
|
161 | + 'customer_state', |
|
162 | + 'customer_zip', |
|
163 | + 'customer_company', |
|
164 | + 'customer_vat_number', |
|
165 | + 'customer_address', |
|
166 | + |
|
167 | + ); |
|
168 | + |
|
169 | + return apply_filters( 'getpaid_subscription_exporter_get_fields', $fields ); |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Retrieves amount fields. |
|
174 | + * |
|
175 | + * @since 1.0.19 |
|
176 | + * @return array |
|
177 | + */ |
|
178 | + public function get_amount_fields() { |
|
179 | + |
|
180 | + $fields = array( |
|
181 | + 'initial_amount', |
|
182 | + 'recurring_amount' |
|
183 | + ); |
|
184 | + |
|
185 | + return apply_filters( 'getpaid_subscription_exporter_get_amount_fields', $fields ); |
|
186 | + } |
|
187 | 187 | |
188 | 188 | } |
@@ -12,49 +12,49 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - * |
|
18 | - */ |
|
19 | - public function __construct() { |
|
20 | - add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
21 | - add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
22 | - add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
23 | - add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
24 | - add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) ); |
|
25 | - |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Registers the reports page. |
|
30 | - * |
|
31 | - */ |
|
32 | - public function register_reports_page() { |
|
33 | - |
|
34 | - add_submenu_page( |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + * |
|
18 | + */ |
|
19 | + public function __construct() { |
|
20 | + add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
21 | + add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
22 | + add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
23 | + add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
24 | + add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) ); |
|
25 | + |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Registers the reports page. |
|
30 | + * |
|
31 | + */ |
|
32 | + public function register_reports_page() { |
|
33 | + |
|
34 | + add_submenu_page( |
|
35 | 35 | 'wpinv', |
36 | 36 | __( 'Reports', 'invoicing' ), |
37 | 37 | __( 'Reports', 'invoicing' ), |
38 | 38 | wpinv_get_capability(), |
39 | 39 | 'wpinv-reports', |
40 | 40 | array( $this, 'display_reports_page' ) |
41 | - ); |
|
41 | + ); |
|
42 | 42 | |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Displays the reports page. |
|
47 | - * |
|
48 | - */ |
|
49 | - public function display_reports_page() { |
|
45 | + /** |
|
46 | + * Displays the reports page. |
|
47 | + * |
|
48 | + */ |
|
49 | + public function display_reports_page() { |
|
50 | 50 | |
51 | - // Prepare variables. |
|
52 | - $tabs = $this->get_tabs(); |
|
53 | - $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
54 | - $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
51 | + // Prepare variables. |
|
52 | + $tabs = $this->get_tabs(); |
|
53 | + $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
54 | + $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
55 | 55 | |
56 | - // Display the current tab. |
|
57 | - ?> |
|
56 | + // Display the current tab. |
|
57 | + ?> |
|
58 | 58 | |
59 | 59 | <div class="wrap"> |
60 | 60 | |
@@ -63,19 +63,19 @@ discard block |
||
63 | 63 | <nav class="nav-tab-wrapper"> |
64 | 64 | |
65 | 65 | <?php |
66 | - foreach( $tabs as $key => $label ) { |
|
66 | + foreach( $tabs as $key => $label ) { |
|
67 | 67 | |
68 | - $key = sanitize_text_field( $key ); |
|
69 | - $label = sanitize_text_field( $label ); |
|
70 | - $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
|
71 | - $url = esc_url( |
|
72 | - add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) ) |
|
73 | - ); |
|
68 | + $key = sanitize_text_field( $key ); |
|
69 | + $label = sanitize_text_field( $label ); |
|
70 | + $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
|
71 | + $url = esc_url( |
|
72 | + add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) ) |
|
73 | + ); |
|
74 | 74 | |
75 | - echo "\n\t\t\t<a href='$url' class='$class'>$label</a>"; |
|
75 | + echo "\n\t\t\t<a href='$url' class='$class'>$label</a>"; |
|
76 | 76 | |
77 | - } |
|
78 | - ?> |
|
77 | + } |
|
78 | + ?> |
|
79 | 79 | |
80 | 80 | </nav> |
81 | 81 | |
@@ -86,83 +86,83 @@ discard block |
||
86 | 86 | </div> |
87 | 87 | <?php |
88 | 88 | |
89 | - // Wordfence loads an unsupported version of chart js on our page. |
|
90 | - wp_deregister_style( 'chart-js' ); |
|
91 | - wp_deregister_script( 'chart-js' ); |
|
92 | - wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true ); |
|
93 | - wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' ); |
|
89 | + // Wordfence loads an unsupported version of chart js on our page. |
|
90 | + wp_deregister_style( 'chart-js' ); |
|
91 | + wp_deregister_script( 'chart-js' ); |
|
92 | + wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true ); |
|
93 | + wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' ); |
|
94 | 94 | |
95 | - } |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Retrieves reports page tabs. |
|
99 | - * |
|
100 | - * @return array |
|
101 | - */ |
|
102 | - public function get_tabs() { |
|
97 | + /** |
|
98 | + * Retrieves reports page tabs. |
|
99 | + * |
|
100 | + * @return array |
|
101 | + */ |
|
102 | + public function get_tabs() { |
|
103 | 103 | |
104 | - $tabs = array( |
|
105 | - 'reports' => __( 'Reports', 'invoicing' ), |
|
106 | - 'export' => __( 'Export', 'invoicing' ), |
|
107 | - ); |
|
104 | + $tabs = array( |
|
105 | + 'reports' => __( 'Reports', 'invoicing' ), |
|
106 | + 'export' => __( 'Export', 'invoicing' ), |
|
107 | + ); |
|
108 | 108 | |
109 | - return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
110 | - } |
|
109 | + return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Displays the reports tab. |
|
114 | - * |
|
115 | - */ |
|
116 | - public function display_reports_tab() { |
|
112 | + /** |
|
113 | + * Displays the reports tab. |
|
114 | + * |
|
115 | + */ |
|
116 | + public function display_reports_tab() { |
|
117 | 117 | |
118 | - $reports = new GetPaid_Reports_Report(); |
|
119 | - $reports->display(); |
|
118 | + $reports = new GetPaid_Reports_Report(); |
|
119 | + $reports->display(); |
|
120 | 120 | |
121 | - } |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * Displays the exports tab. |
|
125 | - * |
|
126 | - */ |
|
127 | - public function display_exports_tab() { |
|
123 | + /** |
|
124 | + * Displays the exports tab. |
|
125 | + * |
|
126 | + */ |
|
127 | + public function display_exports_tab() { |
|
128 | 128 | |
129 | - $exports = new GetPaid_Reports_Export(); |
|
130 | - $exports->display(); |
|
129 | + $exports = new GetPaid_Reports_Export(); |
|
130 | + $exports->display(); |
|
131 | 131 | |
132 | - } |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * Donwnloads a graph. |
|
136 | - * |
|
137 | - * @param array $args |
|
138 | - */ |
|
139 | - public function download_graph( $args ) { |
|
134 | + /** |
|
135 | + * Donwnloads a graph. |
|
136 | + * |
|
137 | + * @param array $args |
|
138 | + */ |
|
139 | + public function download_graph( $args ) { |
|
140 | 140 | |
141 | - if ( ! empty( $args['graph'] ) ) { |
|
142 | - $downloader = new GetPaid_Graph_Downloader(); |
|
143 | - $downloader->download( $args['graph'] ); |
|
144 | - } |
|
141 | + if ( ! empty( $args['graph'] ) ) { |
|
142 | + $downloader = new GetPaid_Graph_Downloader(); |
|
143 | + $downloader->download( $args['graph'] ); |
|
144 | + } |
|
145 | 145 | |
146 | - } |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * Exports invoices. |
|
150 | - * |
|
151 | - * @param array $args |
|
152 | - */ |
|
153 | - public function export_invoices( $args ) { |
|
148 | + /** |
|
149 | + * Exports invoices. |
|
150 | + * |
|
151 | + * @param array $args |
|
152 | + */ |
|
153 | + public function export_invoices( $args ) { |
|
154 | 154 | |
155 | - if ( ! empty( $args['post_type'] ) ) { |
|
155 | + if ( ! empty( $args['post_type'] ) ) { |
|
156 | 156 | |
157 | - if ( 'subscriptions' === $args['post_type'] ) { |
|
158 | - $downloader = new GetPaid_Subscription_Exporter(); |
|
159 | - } else { |
|
160 | - $downloader = new GetPaid_Invoice_Exporter(); |
|
161 | - } |
|
157 | + if ( 'subscriptions' === $args['post_type'] ) { |
|
158 | + $downloader = new GetPaid_Subscription_Exporter(); |
|
159 | + } else { |
|
160 | + $downloader = new GetPaid_Invoice_Exporter(); |
|
161 | + } |
|
162 | 162 | |
163 | - $downloader->export( $args['post_type'], $args ); |
|
164 | - } |
|
163 | + $downloader->export( $args['post_type'], $args ); |
|
164 | + } |
|
165 | 165 | |
166 | - } |
|
166 | + } |
|
167 | 167 | |
168 | 168 | } |
@@ -12,265 +12,265 @@ |
||
12 | 12 | |
13 | 13 | return array( |
14 | 14 | |
15 | - array( |
|
16 | - 'country' => 'AT', // Austria |
|
17 | - 'state' => '', |
|
18 | - 'global' => true, |
|
19 | - 'rate' => 20, |
|
20 | - 'reduced_rate' => 13, |
|
21 | - 'name' => __( 'VAT', 'invoicing' ), |
|
22 | - ), |
|
23 | - |
|
24 | - array( |
|
25 | - 'country' => 'BE', // Belgium |
|
26 | - 'state' => '', |
|
27 | - 'global' => true, |
|
28 | - 'rate' => 21, |
|
29 | - 'reduced_rate' => 12, |
|
30 | - 'name' => __( 'VAT', 'invoicing' ), |
|
31 | - ), |
|
32 | - |
|
33 | - array( |
|
34 | - 'country' => 'BG', // Bulgaria |
|
35 | - 'state' => '', |
|
36 | - 'global' => true, |
|
37 | - 'rate' => 20, |
|
38 | - 'reduced_rate' => 9, |
|
39 | - 'name' => __( 'VAT', 'invoicing' ), |
|
40 | - ), |
|
41 | - |
|
42 | - array( |
|
43 | - 'country' => 'HR', // Croatia |
|
44 | - 'state' => '', |
|
45 | - 'global' => true, |
|
46 | - 'rate' => 25, |
|
47 | - 'reduced_rate' => 13, |
|
48 | - 'name' => __( 'VAT', 'invoicing' ), |
|
49 | - ), |
|
50 | - |
|
51 | - array( |
|
52 | - 'country' => 'CY', // Cyprus |
|
53 | - 'state' => '', |
|
54 | - 'global' => true, |
|
55 | - 'rate' => 19, |
|
56 | - 'reduced_rate' => 9, |
|
57 | - 'name' => __( 'VAT', 'invoicing' ), |
|
58 | - ), |
|
59 | - |
|
60 | - array( |
|
61 | - 'country' => 'CZ', // Czech Republic |
|
62 | - 'state' => '', |
|
63 | - 'global' => true, |
|
64 | - 'rate' => 21, |
|
65 | - 'reduced_rate' => 15, |
|
66 | - 'name' => __( 'VAT', 'invoicing' ), |
|
67 | - ), |
|
68 | - |
|
69 | - array( |
|
70 | - 'country' => 'DK', // Denmark |
|
71 | - 'state' => '', |
|
72 | - 'global' => true, |
|
73 | - 'rate' => 25, |
|
74 | - 'reduced_rate' => 0, |
|
75 | - 'name' => __( 'VAT', 'invoicing' ), |
|
76 | - ), |
|
77 | - |
|
78 | - array( |
|
79 | - 'country' => 'EE', // Estonia |
|
80 | - 'state' => '', |
|
81 | - 'global' => true, |
|
82 | - 'rate' => 20, |
|
83 | - 'reduced_rate' => 9, |
|
84 | - 'name' => __( 'VAT', 'invoicing' ), |
|
85 | - ), |
|
86 | - |
|
87 | - array( |
|
88 | - 'country' => 'FI', // Finland |
|
89 | - 'state' => '', |
|
90 | - 'global' => true, |
|
91 | - 'rate' => 24, |
|
92 | - 'reduced_rate' => 14, |
|
93 | - 'name' => __( 'VAT', 'invoicing' ), |
|
94 | - ), |
|
95 | - |
|
96 | - array( |
|
97 | - 'country' => 'FR', // France |
|
98 | - 'state' => '', |
|
99 | - 'global' => true, |
|
100 | - 'rate' => 20, |
|
101 | - 'reduced_rate' => 5.5, |
|
102 | - 'name' => __( 'VAT', 'invoicing' ), |
|
103 | - ), |
|
104 | - |
|
105 | - array( |
|
106 | - 'country' => 'DE', // Germany |
|
107 | - 'state' => '', |
|
108 | - 'global' => true, |
|
109 | - 'rate' => 19, |
|
110 | - 'reduced_rate' => 7, |
|
111 | - 'name' => __( 'VAT', 'invoicing' ), |
|
112 | - ), |
|
113 | - |
|
114 | - array( |
|
115 | - 'country' => 'GR', // Greece |
|
116 | - 'state' => '', |
|
117 | - 'global' => true, |
|
118 | - 'rate' => 24, |
|
119 | - 'reduced_rate' => 13, |
|
120 | - 'name' => __( 'VAT', 'invoicing' ), |
|
121 | - ), |
|
122 | - |
|
123 | - array( |
|
124 | - 'country' => 'HU', // Hungary |
|
125 | - 'state' => '', |
|
126 | - 'global' => true, |
|
127 | - 'rate' => 27, |
|
128 | - 'reduced_rate' => 18, |
|
129 | - 'name' => __( 'VAT', 'invoicing' ), |
|
130 | - ), |
|
131 | - |
|
132 | - array( |
|
133 | - 'country' => 'IE', // Ireland |
|
134 | - 'state' => '', |
|
135 | - 'global' => true, |
|
136 | - 'rate' => 23, |
|
137 | - 'reduced_rate' => 13.5, |
|
138 | - 'name' => __( 'VAT', 'invoicing' ), |
|
139 | - ), |
|
140 | - |
|
141 | - array( |
|
142 | - 'country' => 'IT', // Italy |
|
143 | - 'state' => '', |
|
144 | - 'global' => true, |
|
145 | - 'rate' => 22, |
|
146 | - 'reduced_rate' => 10, |
|
147 | - 'name' => __( 'VAT', 'invoicing' ), |
|
148 | - ), |
|
149 | - |
|
150 | - array( |
|
151 | - 'country' => 'LV', // Latvia |
|
152 | - 'state' => '', |
|
153 | - 'global' => true, |
|
154 | - 'rate' => 21, |
|
155 | - 'reduced_rate' => 12, |
|
156 | - 'name' => __( 'VAT', 'invoicing' ), |
|
157 | - ), |
|
158 | - |
|
159 | - array( |
|
160 | - 'country' => 'LT', // Lithuania |
|
161 | - 'state' => '', |
|
162 | - 'global' => true, |
|
163 | - 'rate' => 21, |
|
164 | - 'reduced_rate' => 9, |
|
165 | - 'name' => __( 'VAT', 'invoicing' ), |
|
166 | - ), |
|
167 | - |
|
168 | - array( |
|
169 | - 'country' => 'LU', // Luxembourg |
|
170 | - 'state' => '', |
|
171 | - 'global' => true, |
|
172 | - 'rate' => 17, |
|
173 | - 'reduced_rate' => 14, |
|
174 | - 'name' => __( 'VAT', 'invoicing' ), |
|
175 | - ), |
|
176 | - |
|
177 | - array( |
|
178 | - 'country' => 'MT', // Malta |
|
179 | - 'state' => '', |
|
180 | - 'global' => true, |
|
181 | - 'rate' => 18, |
|
182 | - 'reduced_rate' => 7, |
|
183 | - 'name' => __( 'VAT', 'invoicing' ), |
|
184 | - ), |
|
185 | - |
|
186 | - array( |
|
187 | - 'country' => 'MC', // Monaco |
|
188 | - 'state' => '', |
|
189 | - 'global' => true, |
|
190 | - 'rate' => 20, |
|
191 | - 'reduced_rate' => 10, |
|
192 | - 'name' => __( 'VAT', 'invoicing' ), |
|
193 | - ), |
|
194 | - |
|
195 | - array( |
|
196 | - 'country' => 'NL', // Netherlands |
|
197 | - 'state' => '', |
|
198 | - 'global' => true, |
|
199 | - 'rate' => 21, |
|
200 | - 'reduced_rate' => 9, |
|
201 | - 'name' => __( 'VAT', 'invoicing' ), |
|
202 | - ), |
|
203 | - |
|
204 | - array( |
|
205 | - 'country' => 'PL', // Poland |
|
206 | - 'state' => '', |
|
207 | - 'global' => true, |
|
208 | - 'rate' => 23, |
|
209 | - 'reduced_rate' => 8, |
|
210 | - 'name' => __( 'VAT', 'invoicing' ), |
|
211 | - ), |
|
212 | - |
|
213 | - array( |
|
214 | - 'country' => 'PT', // Portugal |
|
215 | - 'state' => '', |
|
216 | - 'global' => true, |
|
217 | - 'rate' => 23, |
|
218 | - 'reduced_rate' => 13, |
|
219 | - 'name' => __( 'VAT', 'invoicing' ), |
|
220 | - ), |
|
221 | - |
|
222 | - array( |
|
223 | - 'country' => 'RO', // Romania |
|
224 | - 'state' => '', |
|
225 | - 'global' => true, |
|
226 | - 'rate' => 19, |
|
227 | - 'reduced_rate' => 9, |
|
228 | - 'name' => __( 'VAT', 'invoicing' ), |
|
229 | - ), |
|
230 | - |
|
231 | - array( |
|
232 | - 'country' => 'SK', // Slovakia |
|
233 | - 'state' => '', |
|
234 | - 'global' => true, |
|
235 | - 'rate' => 20, |
|
236 | - 'reduced_rate' => 10, |
|
237 | - 'name' => __( 'VAT', 'invoicing' ), |
|
238 | - ), |
|
239 | - |
|
240 | - array( |
|
241 | - 'country' => 'SI', // Slovenia |
|
242 | - 'state' => '', |
|
243 | - 'global' => true, |
|
244 | - 'rate' => 22, |
|
245 | - 'reduced_rate' => 9.5, |
|
246 | - 'name' => __( 'VAT', 'invoicing' ), |
|
247 | - ), |
|
248 | - |
|
249 | - array( |
|
250 | - 'country' => 'ES', // Spain |
|
251 | - 'state' => '', |
|
252 | - 'global' => true, |
|
253 | - 'rate' => 21, |
|
254 | - 'reduced_rate' => 10, |
|
255 | - 'name' => __( 'VAT', 'invoicing' ), |
|
256 | - ), |
|
257 | - |
|
258 | - array( |
|
259 | - 'country' => 'SE', // Sweden |
|
260 | - 'state' => '', |
|
261 | - 'global' => true, |
|
262 | - 'rate' => 25, |
|
263 | - 'reduced_rate' => 12, |
|
264 | - 'name' => __( 'VAT', 'invoicing' ), |
|
265 | - ), |
|
266 | - |
|
267 | - array( |
|
268 | - 'country' => 'GB', // UK |
|
269 | - 'state' => '', |
|
270 | - 'global' => true, |
|
271 | - 'rate' => 20, |
|
272 | - 'reduced_rate' => 5, |
|
273 | - 'name' => __( 'VAT', 'invoicing' ), |
|
274 | - ) |
|
15 | + array( |
|
16 | + 'country' => 'AT', // Austria |
|
17 | + 'state' => '', |
|
18 | + 'global' => true, |
|
19 | + 'rate' => 20, |
|
20 | + 'reduced_rate' => 13, |
|
21 | + 'name' => __( 'VAT', 'invoicing' ), |
|
22 | + ), |
|
23 | + |
|
24 | + array( |
|
25 | + 'country' => 'BE', // Belgium |
|
26 | + 'state' => '', |
|
27 | + 'global' => true, |
|
28 | + 'rate' => 21, |
|
29 | + 'reduced_rate' => 12, |
|
30 | + 'name' => __( 'VAT', 'invoicing' ), |
|
31 | + ), |
|
32 | + |
|
33 | + array( |
|
34 | + 'country' => 'BG', // Bulgaria |
|
35 | + 'state' => '', |
|
36 | + 'global' => true, |
|
37 | + 'rate' => 20, |
|
38 | + 'reduced_rate' => 9, |
|
39 | + 'name' => __( 'VAT', 'invoicing' ), |
|
40 | + ), |
|
41 | + |
|
42 | + array( |
|
43 | + 'country' => 'HR', // Croatia |
|
44 | + 'state' => '', |
|
45 | + 'global' => true, |
|
46 | + 'rate' => 25, |
|
47 | + 'reduced_rate' => 13, |
|
48 | + 'name' => __( 'VAT', 'invoicing' ), |
|
49 | + ), |
|
50 | + |
|
51 | + array( |
|
52 | + 'country' => 'CY', // Cyprus |
|
53 | + 'state' => '', |
|
54 | + 'global' => true, |
|
55 | + 'rate' => 19, |
|
56 | + 'reduced_rate' => 9, |
|
57 | + 'name' => __( 'VAT', 'invoicing' ), |
|
58 | + ), |
|
59 | + |
|
60 | + array( |
|
61 | + 'country' => 'CZ', // Czech Republic |
|
62 | + 'state' => '', |
|
63 | + 'global' => true, |
|
64 | + 'rate' => 21, |
|
65 | + 'reduced_rate' => 15, |
|
66 | + 'name' => __( 'VAT', 'invoicing' ), |
|
67 | + ), |
|
68 | + |
|
69 | + array( |
|
70 | + 'country' => 'DK', // Denmark |
|
71 | + 'state' => '', |
|
72 | + 'global' => true, |
|
73 | + 'rate' => 25, |
|
74 | + 'reduced_rate' => 0, |
|
75 | + 'name' => __( 'VAT', 'invoicing' ), |
|
76 | + ), |
|
77 | + |
|
78 | + array( |
|
79 | + 'country' => 'EE', // Estonia |
|
80 | + 'state' => '', |
|
81 | + 'global' => true, |
|
82 | + 'rate' => 20, |
|
83 | + 'reduced_rate' => 9, |
|
84 | + 'name' => __( 'VAT', 'invoicing' ), |
|
85 | + ), |
|
86 | + |
|
87 | + array( |
|
88 | + 'country' => 'FI', // Finland |
|
89 | + 'state' => '', |
|
90 | + 'global' => true, |
|
91 | + 'rate' => 24, |
|
92 | + 'reduced_rate' => 14, |
|
93 | + 'name' => __( 'VAT', 'invoicing' ), |
|
94 | + ), |
|
95 | + |
|
96 | + array( |
|
97 | + 'country' => 'FR', // France |
|
98 | + 'state' => '', |
|
99 | + 'global' => true, |
|
100 | + 'rate' => 20, |
|
101 | + 'reduced_rate' => 5.5, |
|
102 | + 'name' => __( 'VAT', 'invoicing' ), |
|
103 | + ), |
|
104 | + |
|
105 | + array( |
|
106 | + 'country' => 'DE', // Germany |
|
107 | + 'state' => '', |
|
108 | + 'global' => true, |
|
109 | + 'rate' => 19, |
|
110 | + 'reduced_rate' => 7, |
|
111 | + 'name' => __( 'VAT', 'invoicing' ), |
|
112 | + ), |
|
113 | + |
|
114 | + array( |
|
115 | + 'country' => 'GR', // Greece |
|
116 | + 'state' => '', |
|
117 | + 'global' => true, |
|
118 | + 'rate' => 24, |
|
119 | + 'reduced_rate' => 13, |
|
120 | + 'name' => __( 'VAT', 'invoicing' ), |
|
121 | + ), |
|
122 | + |
|
123 | + array( |
|
124 | + 'country' => 'HU', // Hungary |
|
125 | + 'state' => '', |
|
126 | + 'global' => true, |
|
127 | + 'rate' => 27, |
|
128 | + 'reduced_rate' => 18, |
|
129 | + 'name' => __( 'VAT', 'invoicing' ), |
|
130 | + ), |
|
131 | + |
|
132 | + array( |
|
133 | + 'country' => 'IE', // Ireland |
|
134 | + 'state' => '', |
|
135 | + 'global' => true, |
|
136 | + 'rate' => 23, |
|
137 | + 'reduced_rate' => 13.5, |
|
138 | + 'name' => __( 'VAT', 'invoicing' ), |
|
139 | + ), |
|
140 | + |
|
141 | + array( |
|
142 | + 'country' => 'IT', // Italy |
|
143 | + 'state' => '', |
|
144 | + 'global' => true, |
|
145 | + 'rate' => 22, |
|
146 | + 'reduced_rate' => 10, |
|
147 | + 'name' => __( 'VAT', 'invoicing' ), |
|
148 | + ), |
|
149 | + |
|
150 | + array( |
|
151 | + 'country' => 'LV', // Latvia |
|
152 | + 'state' => '', |
|
153 | + 'global' => true, |
|
154 | + 'rate' => 21, |
|
155 | + 'reduced_rate' => 12, |
|
156 | + 'name' => __( 'VAT', 'invoicing' ), |
|
157 | + ), |
|
158 | + |
|
159 | + array( |
|
160 | + 'country' => 'LT', // Lithuania |
|
161 | + 'state' => '', |
|
162 | + 'global' => true, |
|
163 | + 'rate' => 21, |
|
164 | + 'reduced_rate' => 9, |
|
165 | + 'name' => __( 'VAT', 'invoicing' ), |
|
166 | + ), |
|
167 | + |
|
168 | + array( |
|
169 | + 'country' => 'LU', // Luxembourg |
|
170 | + 'state' => '', |
|
171 | + 'global' => true, |
|
172 | + 'rate' => 17, |
|
173 | + 'reduced_rate' => 14, |
|
174 | + 'name' => __( 'VAT', 'invoicing' ), |
|
175 | + ), |
|
176 | + |
|
177 | + array( |
|
178 | + 'country' => 'MT', // Malta |
|
179 | + 'state' => '', |
|
180 | + 'global' => true, |
|
181 | + 'rate' => 18, |
|
182 | + 'reduced_rate' => 7, |
|
183 | + 'name' => __( 'VAT', 'invoicing' ), |
|
184 | + ), |
|
185 | + |
|
186 | + array( |
|
187 | + 'country' => 'MC', // Monaco |
|
188 | + 'state' => '', |
|
189 | + 'global' => true, |
|
190 | + 'rate' => 20, |
|
191 | + 'reduced_rate' => 10, |
|
192 | + 'name' => __( 'VAT', 'invoicing' ), |
|
193 | + ), |
|
194 | + |
|
195 | + array( |
|
196 | + 'country' => 'NL', // Netherlands |
|
197 | + 'state' => '', |
|
198 | + 'global' => true, |
|
199 | + 'rate' => 21, |
|
200 | + 'reduced_rate' => 9, |
|
201 | + 'name' => __( 'VAT', 'invoicing' ), |
|
202 | + ), |
|
203 | + |
|
204 | + array( |
|
205 | + 'country' => 'PL', // Poland |
|
206 | + 'state' => '', |
|
207 | + 'global' => true, |
|
208 | + 'rate' => 23, |
|
209 | + 'reduced_rate' => 8, |
|
210 | + 'name' => __( 'VAT', 'invoicing' ), |
|
211 | + ), |
|
212 | + |
|
213 | + array( |
|
214 | + 'country' => 'PT', // Portugal |
|
215 | + 'state' => '', |
|
216 | + 'global' => true, |
|
217 | + 'rate' => 23, |
|
218 | + 'reduced_rate' => 13, |
|
219 | + 'name' => __( 'VAT', 'invoicing' ), |
|
220 | + ), |
|
221 | + |
|
222 | + array( |
|
223 | + 'country' => 'RO', // Romania |
|
224 | + 'state' => '', |
|
225 | + 'global' => true, |
|
226 | + 'rate' => 19, |
|
227 | + 'reduced_rate' => 9, |
|
228 | + 'name' => __( 'VAT', 'invoicing' ), |
|
229 | + ), |
|
230 | + |
|
231 | + array( |
|
232 | + 'country' => 'SK', // Slovakia |
|
233 | + 'state' => '', |
|
234 | + 'global' => true, |
|
235 | + 'rate' => 20, |
|
236 | + 'reduced_rate' => 10, |
|
237 | + 'name' => __( 'VAT', 'invoicing' ), |
|
238 | + ), |
|
239 | + |
|
240 | + array( |
|
241 | + 'country' => 'SI', // Slovenia |
|
242 | + 'state' => '', |
|
243 | + 'global' => true, |
|
244 | + 'rate' => 22, |
|
245 | + 'reduced_rate' => 9.5, |
|
246 | + 'name' => __( 'VAT', 'invoicing' ), |
|
247 | + ), |
|
248 | + |
|
249 | + array( |
|
250 | + 'country' => 'ES', // Spain |
|
251 | + 'state' => '', |
|
252 | + 'global' => true, |
|
253 | + 'rate' => 21, |
|
254 | + 'reduced_rate' => 10, |
|
255 | + 'name' => __( 'VAT', 'invoicing' ), |
|
256 | + ), |
|
257 | + |
|
258 | + array( |
|
259 | + 'country' => 'SE', // Sweden |
|
260 | + 'state' => '', |
|
261 | + 'global' => true, |
|
262 | + 'rate' => 25, |
|
263 | + 'reduced_rate' => 12, |
|
264 | + 'name' => __( 'VAT', 'invoicing' ), |
|
265 | + ), |
|
266 | + |
|
267 | + array( |
|
268 | + 'country' => 'GB', // UK |
|
269 | + 'state' => '', |
|
270 | + 'global' => true, |
|
271 | + 'rate' => 20, |
|
272 | + 'reduced_rate' => 5, |
|
273 | + 'name' => __( 'VAT', 'invoicing' ), |
|
274 | + ) |
|
275 | 275 | |
276 | 276 | ); |
@@ -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,111 +111,111 @@ 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 | - } |
|
164 | - |
|
165 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
|
166 | - $this->set_id( $invoice_id ); |
|
167 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
168 | - $this->set_id( $invoice_id ); |
|
169 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
170 | - $this->set_id( $invoice_id ); |
|
171 | - } else { |
|
172 | - $this->set_object_read( true ); |
|
173 | - } |
|
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 | + |
|
165 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
|
166 | + $this->set_id( $invoice_id ); |
|
167 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
168 | + $this->set_id( $invoice_id ); |
|
169 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
170 | + $this->set_id( $invoice_id ); |
|
171 | + } else { |
|
172 | + $this->set_object_read( true ); |
|
173 | + } |
|
174 | 174 | |
175 | 175 | // Load the datastore. |
176 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
176 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
177 | 177 | |
178 | - if ( $this->get_id() > 0 ) { |
|
178 | + if ( $this->get_id() > 0 ) { |
|
179 | 179 | $this->post = get_post( $this->get_id() ); |
180 | 180 | $this->ID = $this->get_id(); |
181 | - $this->data_store->read( $this ); |
|
181 | + $this->data_store->read( $this ); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
187 | - * Given an invoice key/number, it returns its id. |
|
188 | - * |
|
189 | - * |
|
190 | - * @static |
|
191 | - * @param string $value The invoice key or number |
|
192 | - * @param string $field Either key, transaction_id or number. |
|
193 | - * @since 1.0.15 |
|
194 | - * @return int |
|
195 | - */ |
|
196 | - public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
187 | + * Given an invoice key/number, it returns its id. |
|
188 | + * |
|
189 | + * |
|
190 | + * @static |
|
191 | + * @param string $value The invoice key or number |
|
192 | + * @param string $field Either key, transaction_id or number. |
|
193 | + * @since 1.0.15 |
|
194 | + * @return int |
|
195 | + */ |
|
196 | + public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
197 | 197 | global $wpdb; |
198 | 198 | |
199 | - // Trim the value. |
|
200 | - $value = trim( $value ); |
|
199 | + // Trim the value. |
|
200 | + $value = trim( $value ); |
|
201 | 201 | |
202 | - if ( empty( $value ) ) { |
|
203 | - return 0; |
|
204 | - } |
|
202 | + if ( empty( $value ) ) { |
|
203 | + return 0; |
|
204 | + } |
|
205 | 205 | |
206 | 206 | // Valid fields. |
207 | 207 | $fields = array( 'key', 'number', 'transaction_id' ); |
208 | 208 | |
209 | - // Ensure a field has been passed. |
|
210 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
211 | - return 0; |
|
212 | - } |
|
209 | + // Ensure a field has been passed. |
|
210 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
211 | + return 0; |
|
212 | + } |
|
213 | 213 | |
214 | - // Maybe retrieve from the cache. |
|
215 | - $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
216 | - if ( false !== $invoice_id ) { |
|
217 | - return $invoice_id; |
|
218 | - } |
|
214 | + // Maybe retrieve from the cache. |
|
215 | + $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
216 | + if ( false !== $invoice_id ) { |
|
217 | + return $invoice_id; |
|
218 | + } |
|
219 | 219 | |
220 | 220 | // Fetch from the db. |
221 | 221 | $table = $wpdb->prefix . 'getpaid_invoices'; |
@@ -223,10 +223,10 @@ discard block |
||
223 | 223 | $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
224 | 224 | ); |
225 | 225 | |
226 | - // Update the cache with our data |
|
227 | - wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
226 | + // Update the cache with our data |
|
227 | + wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
228 | 228 | |
229 | - return $invoice_id; |
|
229 | + return $invoice_id; |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -252,83 +252,83 @@ discard block |
||
252 | 252 | */ |
253 | 253 | |
254 | 254 | /** |
255 | - * Get parent invoice ID. |
|
256 | - * |
|
257 | - * @since 1.0.19 |
|
258 | - * @param string $context View or edit context. |
|
259 | - * @return int |
|
260 | - */ |
|
261 | - public function get_parent_id( $context = 'view' ) { |
|
262 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
255 | + * Get parent invoice ID. |
|
256 | + * |
|
257 | + * @since 1.0.19 |
|
258 | + * @param string $context View or edit context. |
|
259 | + * @return int |
|
260 | + */ |
|
261 | + public function get_parent_id( $context = 'view' ) { |
|
262 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
266 | - * Get parent invoice. |
|
267 | - * |
|
268 | - * @since 1.0.19 |
|
269 | - * @return WPInv_Invoice |
|
270 | - */ |
|
266 | + * Get parent invoice. |
|
267 | + * |
|
268 | + * @since 1.0.19 |
|
269 | + * @return WPInv_Invoice |
|
270 | + */ |
|
271 | 271 | public function get_parent_payment() { |
272 | 272 | return new WPInv_Invoice( $this->get_parent_id() ); |
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
276 | - * Alias for self::get_parent_payment(). |
|
277 | - * |
|
278 | - * @since 1.0.19 |
|
279 | - * @return WPInv_Invoice |
|
280 | - */ |
|
276 | + * Alias for self::get_parent_payment(). |
|
277 | + * |
|
278 | + * @since 1.0.19 |
|
279 | + * @return WPInv_Invoice |
|
280 | + */ |
|
281 | 281 | public function get_parent() { |
282 | 282 | return $this->get_parent_payment(); |
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
286 | - * Get invoice status. |
|
287 | - * |
|
288 | - * @since 1.0.19 |
|
289 | - * @param string $context View or edit context. |
|
290 | - * @return string |
|
291 | - */ |
|
292 | - public function get_status( $context = 'view' ) { |
|
293 | - return $this->get_prop( 'status', $context ); |
|
294 | - } |
|
286 | + * Get invoice status. |
|
287 | + * |
|
288 | + * @since 1.0.19 |
|
289 | + * @param string $context View or edit context. |
|
290 | + * @return string |
|
291 | + */ |
|
292 | + public function get_status( $context = 'view' ) { |
|
293 | + return $this->get_prop( 'status', $context ); |
|
294 | + } |
|
295 | 295 | |
296 | - /** |
|
297 | - * Retrieves an array of possible invoice statuses. |
|
298 | - * |
|
299 | - * @since 1.0.19 |
|
300 | - * @return array |
|
301 | - */ |
|
302 | - public function get_all_statuses() { |
|
303 | - return wpinv_get_invoice_statuses( true, true, $this ); |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Get invoice status nice name. |
|
308 | - * |
|
309 | - * @since 1.0.19 |
|
310 | - * @return string |
|
311 | - */ |
|
296 | + /** |
|
297 | + * Retrieves an array of possible invoice statuses. |
|
298 | + * |
|
299 | + * @since 1.0.19 |
|
300 | + * @return array |
|
301 | + */ |
|
302 | + public function get_all_statuses() { |
|
303 | + return wpinv_get_invoice_statuses( true, true, $this ); |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Get invoice status nice name. |
|
308 | + * |
|
309 | + * @since 1.0.19 |
|
310 | + * @return string |
|
311 | + */ |
|
312 | 312 | public function get_status_nicename() { |
313 | - $statuses = $this->get_all_statuses(); |
|
313 | + $statuses = $this->get_all_statuses(); |
|
314 | 314 | |
315 | 315 | $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status(); |
316 | 316 | |
317 | 317 | return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this ); |
318 | 318 | } |
319 | 319 | |
320 | - /** |
|
321 | - * Retrieves the invoice status class |
|
322 | - * |
|
323 | - * @since 1.0.19 |
|
324 | - * @return string |
|
325 | - */ |
|
326 | - public function get_status_class() { |
|
327 | - $statuses = getpaid_get_invoice_status_classes(); |
|
328 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
329 | - } |
|
320 | + /** |
|
321 | + * Retrieves the invoice status class |
|
322 | + * |
|
323 | + * @since 1.0.19 |
|
324 | + * @return string |
|
325 | + */ |
|
326 | + public function get_status_class() { |
|
327 | + $statuses = getpaid_get_invoice_status_classes(); |
|
328 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
329 | + } |
|
330 | 330 | |
331 | - /** |
|
331 | + /** |
|
332 | 332 | * Retrieves the invoice status label html |
333 | 333 | * |
334 | 334 | * @since 1.0.0 |
@@ -336,263 +336,263 @@ discard block |
||
336 | 336 | */ |
337 | 337 | public function get_status_label_html() { |
338 | 338 | |
339 | - $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
340 | - $status = sanitize_html_class( $this->get_status() ); |
|
341 | - $class = esc_attr( $this->get_status_class() ); |
|
339 | + $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
340 | + $status = sanitize_html_class( $this->get_status() ); |
|
341 | + $class = esc_attr( $this->get_status_class() ); |
|
342 | 342 | |
343 | - return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
344 | - } |
|
343 | + return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
344 | + } |
|
345 | 345 | |
346 | 346 | /** |
347 | - * Get plugin version when the invoice was created. |
|
348 | - * |
|
349 | - * @since 1.0.19 |
|
350 | - * @param string $context View or edit context. |
|
351 | - * @return string |
|
352 | - */ |
|
353 | - public function get_version( $context = 'view' ) { |
|
354 | - return $this->get_prop( 'version', $context ); |
|
355 | - } |
|
347 | + * Get plugin version when the invoice was created. |
|
348 | + * |
|
349 | + * @since 1.0.19 |
|
350 | + * @param string $context View or edit context. |
|
351 | + * @return string |
|
352 | + */ |
|
353 | + public function get_version( $context = 'view' ) { |
|
354 | + return $this->get_prop( 'version', $context ); |
|
355 | + } |
|
356 | 356 | |
357 | - /** |
|
358 | - * @deprecated |
|
359 | - */ |
|
360 | - public function get_invoice_date( $format = true ) { |
|
361 | - $date = getpaid_format_date( $this->get_date_completed() ); |
|
362 | - $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
363 | - $formatted = getpaid_format_date( $date ); |
|
357 | + /** |
|
358 | + * @deprecated |
|
359 | + */ |
|
360 | + public function get_invoice_date( $format = true ) { |
|
361 | + $date = getpaid_format_date( $this->get_date_completed() ); |
|
362 | + $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
363 | + $formatted = getpaid_format_date( $date ); |
|
364 | 364 | |
365 | - if ( $format ) { |
|
366 | - return $formatted; |
|
367 | - } |
|
365 | + if ( $format ) { |
|
366 | + return $formatted; |
|
367 | + } |
|
368 | 368 | |
369 | - return empty( $formatted ) ? '' : $date; |
|
369 | + return empty( $formatted ) ? '' : $date; |
|
370 | 370 | |
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
374 | - * Get date when the invoice was created. |
|
375 | - * |
|
376 | - * @since 1.0.19 |
|
377 | - * @param string $context View or edit context. |
|
378 | - * @return string |
|
379 | - */ |
|
380 | - public function get_date_created( $context = 'view' ) { |
|
381 | - return $this->get_prop( 'date_created', $context ); |
|
382 | - } |
|
374 | + * Get date when the invoice was created. |
|
375 | + * |
|
376 | + * @since 1.0.19 |
|
377 | + * @param string $context View or edit context. |
|
378 | + * @return string |
|
379 | + */ |
|
380 | + public function get_date_created( $context = 'view' ) { |
|
381 | + return $this->get_prop( 'date_created', $context ); |
|
382 | + } |
|
383 | 383 | |
384 | - /** |
|
385 | - * Alias for self::get_date_created(). |
|
386 | - * |
|
387 | - * @since 1.0.19 |
|
388 | - * @param string $context View or edit context. |
|
389 | - * @return string |
|
390 | - */ |
|
391 | - public function get_created_date( $context = 'view' ) { |
|
392 | - return $this->get_date_created( $context ); |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Get GMT date when the invoice was created. |
|
397 | - * |
|
398 | - * @since 1.0.19 |
|
399 | - * @param string $context View or edit context. |
|
400 | - * @return string |
|
401 | - */ |
|
402 | - public function get_date_created_gmt( $context = 'view' ) { |
|
384 | + /** |
|
385 | + * Alias for self::get_date_created(). |
|
386 | + * |
|
387 | + * @since 1.0.19 |
|
388 | + * @param string $context View or edit context. |
|
389 | + * @return string |
|
390 | + */ |
|
391 | + public function get_created_date( $context = 'view' ) { |
|
392 | + return $this->get_date_created( $context ); |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Get GMT date when the invoice was created. |
|
397 | + * |
|
398 | + * @since 1.0.19 |
|
399 | + * @param string $context View or edit context. |
|
400 | + * @return string |
|
401 | + */ |
|
402 | + public function get_date_created_gmt( $context = 'view' ) { |
|
403 | 403 | $date = $this->get_date_created( $context ); |
404 | 404 | |
405 | 405 | if ( $date ) { |
406 | 406 | $date = get_gmt_from_date( $date ); |
407 | 407 | } |
408 | - return $date; |
|
408 | + return $date; |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |
412 | - * Get date when the invoice was last modified. |
|
413 | - * |
|
414 | - * @since 1.0.19 |
|
415 | - * @param string $context View or edit context. |
|
416 | - * @return string |
|
417 | - */ |
|
418 | - public function get_date_modified( $context = 'view' ) { |
|
419 | - return $this->get_prop( 'date_modified', $context ); |
|
420 | - } |
|
412 | + * Get date when the invoice was last modified. |
|
413 | + * |
|
414 | + * @since 1.0.19 |
|
415 | + * @param string $context View or edit context. |
|
416 | + * @return string |
|
417 | + */ |
|
418 | + public function get_date_modified( $context = 'view' ) { |
|
419 | + return $this->get_prop( 'date_modified', $context ); |
|
420 | + } |
|
421 | 421 | |
422 | - /** |
|
423 | - * Alias for self::get_date_modified(). |
|
424 | - * |
|
425 | - * @since 1.0.19 |
|
426 | - * @param string $context View or edit context. |
|
427 | - * @return string |
|
428 | - */ |
|
429 | - public function get_modified_date( $context = 'view' ) { |
|
430 | - return $this->get_date_modified( $context ); |
|
422 | + /** |
|
423 | + * Alias for self::get_date_modified(). |
|
424 | + * |
|
425 | + * @since 1.0.19 |
|
426 | + * @param string $context View or edit context. |
|
427 | + * @return string |
|
428 | + */ |
|
429 | + public function get_modified_date( $context = 'view' ) { |
|
430 | + return $this->get_date_modified( $context ); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
434 | - * Get GMT date when the invoice was last modified. |
|
435 | - * |
|
436 | - * @since 1.0.19 |
|
437 | - * @param string $context View or edit context. |
|
438 | - * @return string |
|
439 | - */ |
|
440 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
434 | + * Get GMT date when the invoice was last modified. |
|
435 | + * |
|
436 | + * @since 1.0.19 |
|
437 | + * @param string $context View or edit context. |
|
438 | + * @return string |
|
439 | + */ |
|
440 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
441 | 441 | $date = $this->get_date_modified( $context ); |
442 | 442 | |
443 | 443 | if ( $date ) { |
444 | 444 | $date = get_gmt_from_date( $date ); |
445 | 445 | } |
446 | - return $date; |
|
446 | + return $date; |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
450 | - * Get the invoice due date. |
|
451 | - * |
|
452 | - * @since 1.0.19 |
|
453 | - * @param string $context View or edit context. |
|
454 | - * @return string |
|
455 | - */ |
|
456 | - public function get_due_date( $context = 'view' ) { |
|
457 | - return $this->get_prop( 'due_date', $context ); |
|
450 | + * Get the invoice due date. |
|
451 | + * |
|
452 | + * @since 1.0.19 |
|
453 | + * @param string $context View or edit context. |
|
454 | + * @return string |
|
455 | + */ |
|
456 | + public function get_due_date( $context = 'view' ) { |
|
457 | + return $this->get_prop( 'due_date', $context ); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | /** |
461 | - * Alias for self::get_due_date(). |
|
462 | - * |
|
463 | - * @since 1.0.19 |
|
464 | - * @param string $context View or edit context. |
|
465 | - * @return string |
|
466 | - */ |
|
467 | - public function get_date_due( $context = 'view' ) { |
|
468 | - return $this->get_due_date( $context ); |
|
461 | + * Alias for self::get_due_date(). |
|
462 | + * |
|
463 | + * @since 1.0.19 |
|
464 | + * @param string $context View or edit context. |
|
465 | + * @return string |
|
466 | + */ |
|
467 | + public function get_date_due( $context = 'view' ) { |
|
468 | + return $this->get_due_date( $context ); |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | /** |
472 | - * Get the invoice GMT due date. |
|
473 | - * |
|
474 | - * @since 1.0.19 |
|
475 | - * @param string $context View or edit context. |
|
476 | - * @return string |
|
477 | - */ |
|
478 | - public function get_due_date_gmt( $context = 'view' ) { |
|
472 | + * Get the invoice GMT due date. |
|
473 | + * |
|
474 | + * @since 1.0.19 |
|
475 | + * @param string $context View or edit context. |
|
476 | + * @return string |
|
477 | + */ |
|
478 | + public function get_due_date_gmt( $context = 'view' ) { |
|
479 | 479 | $date = $this->get_due_date( $context ); |
480 | 480 | |
481 | 481 | if ( $date ) { |
482 | 482 | $date = get_gmt_from_date( $date ); |
483 | 483 | } |
484 | - return $date; |
|
484 | + return $date; |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
488 | - * Alias for self::get_due_date_gmt(). |
|
489 | - * |
|
490 | - * @since 1.0.19 |
|
491 | - * @param string $context View or edit context. |
|
492 | - * @return string |
|
493 | - */ |
|
494 | - public function get_gmt_date_due( $context = 'view' ) { |
|
495 | - return $this->get_due_date_gmt( $context ); |
|
488 | + * Alias for self::get_due_date_gmt(). |
|
489 | + * |
|
490 | + * @since 1.0.19 |
|
491 | + * @param string $context View or edit context. |
|
492 | + * @return string |
|
493 | + */ |
|
494 | + public function get_gmt_date_due( $context = 'view' ) { |
|
495 | + return $this->get_due_date_gmt( $context ); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | /** |
499 | - * Get date when the invoice was completed. |
|
500 | - * |
|
501 | - * @since 1.0.19 |
|
502 | - * @param string $context View or edit context. |
|
503 | - * @return string |
|
504 | - */ |
|
505 | - public function get_completed_date( $context = 'view' ) { |
|
506 | - return $this->get_prop( 'completed_date', $context ); |
|
499 | + * Get date when the invoice was completed. |
|
500 | + * |
|
501 | + * @since 1.0.19 |
|
502 | + * @param string $context View or edit context. |
|
503 | + * @return string |
|
504 | + */ |
|
505 | + public function get_completed_date( $context = 'view' ) { |
|
506 | + return $this->get_prop( 'completed_date', $context ); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | /** |
510 | - * Alias for self::get_completed_date(). |
|
511 | - * |
|
512 | - * @since 1.0.19 |
|
513 | - * @param string $context View or edit context. |
|
514 | - * @return string |
|
515 | - */ |
|
516 | - public function get_date_completed( $context = 'view' ) { |
|
517 | - return $this->get_completed_date( $context ); |
|
510 | + * Alias for self::get_completed_date(). |
|
511 | + * |
|
512 | + * @since 1.0.19 |
|
513 | + * @param string $context View or edit context. |
|
514 | + * @return string |
|
515 | + */ |
|
516 | + public function get_date_completed( $context = 'view' ) { |
|
517 | + return $this->get_completed_date( $context ); |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | /** |
521 | - * Get GMT date when the invoice was was completed. |
|
522 | - * |
|
523 | - * @since 1.0.19 |
|
524 | - * @param string $context View or edit context. |
|
525 | - * @return string |
|
526 | - */ |
|
527 | - public function get_completed_date_gmt( $context = 'view' ) { |
|
521 | + * Get GMT date when the invoice was was completed. |
|
522 | + * |
|
523 | + * @since 1.0.19 |
|
524 | + * @param string $context View or edit context. |
|
525 | + * @return string |
|
526 | + */ |
|
527 | + public function get_completed_date_gmt( $context = 'view' ) { |
|
528 | 528 | $date = $this->get_completed_date( $context ); |
529 | 529 | |
530 | 530 | if ( $date ) { |
531 | 531 | $date = get_gmt_from_date( $date ); |
532 | 532 | } |
533 | - return $date; |
|
533 | + return $date; |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | /** |
537 | - * Alias for self::get_completed_date_gmt(). |
|
538 | - * |
|
539 | - * @since 1.0.19 |
|
540 | - * @param string $context View or edit context. |
|
541 | - * @return string |
|
542 | - */ |
|
543 | - public function get_gmt_completed_date( $context = 'view' ) { |
|
544 | - return $this->get_completed_date_gmt( $context ); |
|
537 | + * Alias for self::get_completed_date_gmt(). |
|
538 | + * |
|
539 | + * @since 1.0.19 |
|
540 | + * @param string $context View or edit context. |
|
541 | + * @return string |
|
542 | + */ |
|
543 | + public function get_gmt_completed_date( $context = 'view' ) { |
|
544 | + return $this->get_completed_date_gmt( $context ); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
548 | - * Get the invoice number. |
|
549 | - * |
|
550 | - * @since 1.0.19 |
|
551 | - * @param string $context View or edit context. |
|
552 | - * @return string |
|
553 | - */ |
|
554 | - public function get_number( $context = 'view' ) { |
|
555 | - $number = $this->get_prop( 'number', $context ); |
|
548 | + * Get the invoice number. |
|
549 | + * |
|
550 | + * @since 1.0.19 |
|
551 | + * @param string $context View or edit context. |
|
552 | + * @return string |
|
553 | + */ |
|
554 | + public function get_number( $context = 'view' ) { |
|
555 | + $number = $this->get_prop( 'number', $context ); |
|
556 | 556 | |
557 | - if ( empty( $number ) ) { |
|
558 | - $number = $this->generate_number(); |
|
559 | - $this->set_number( $this->generate_number() ); |
|
560 | - } |
|
557 | + if ( empty( $number ) ) { |
|
558 | + $number = $this->generate_number(); |
|
559 | + $this->set_number( $this->generate_number() ); |
|
560 | + } |
|
561 | 561 | |
562 | - return $number; |
|
562 | + return $number; |
|
563 | 563 | } |
564 | 564 | |
565 | - /** |
|
566 | - * Set the invoice number. |
|
567 | - * |
|
568 | - * @since 1.0.19 |
|
569 | - */ |
|
570 | - public function maybe_set_number() { |
|
565 | + /** |
|
566 | + * Set the invoice number. |
|
567 | + * |
|
568 | + * @since 1.0.19 |
|
569 | + */ |
|
570 | + public function maybe_set_number() { |
|
571 | 571 | $number = $this->get_number(); |
572 | 572 | |
573 | 573 | if ( empty( $number ) || $this->get_id() == $number ) { |
574 | - $this->set_number( $this->generate_number() ); |
|
574 | + $this->set_number( $this->generate_number() ); |
|
575 | 575 | } |
576 | 576 | |
577 | - } |
|
577 | + } |
|
578 | 578 | |
579 | 579 | /** |
580 | - * Get the invoice key. |
|
581 | - * |
|
582 | - * @since 1.0.19 |
|
583 | - * @param string $context View or edit context. |
|
584 | - * @return string |
|
585 | - */ |
|
586 | - public function get_key( $context = 'view' ) { |
|
580 | + * Get the invoice key. |
|
581 | + * |
|
582 | + * @since 1.0.19 |
|
583 | + * @param string $context View or edit context. |
|
584 | + * @return string |
|
585 | + */ |
|
586 | + public function get_key( $context = 'view' ) { |
|
587 | 587 | return $this->get_prop( 'key', $context ); |
588 | - } |
|
589 | - |
|
590 | - /** |
|
591 | - * Set the invoice key. |
|
592 | - * |
|
593 | - * @since 1.0.19 |
|
594 | - */ |
|
595 | - public function maybe_set_key() { |
|
588 | + } |
|
589 | + |
|
590 | + /** |
|
591 | + * Set the invoice key. |
|
592 | + * |
|
593 | + * @since 1.0.19 |
|
594 | + */ |
|
595 | + public function maybe_set_key() { |
|
596 | 596 | $key = $this->get_key(); |
597 | 597 | |
598 | 598 | if ( empty( $key ) ) { |
@@ -603,140 +603,140 @@ discard block |
||
603 | 603 | } |
604 | 604 | |
605 | 605 | /** |
606 | - * Get the invoice type. |
|
607 | - * |
|
608 | - * @since 1.0.19 |
|
609 | - * @param string $context View or edit context. |
|
610 | - * @return string |
|
611 | - */ |
|
612 | - public function get_type( $context = 'view' ) { |
|
606 | + * Get the invoice type. |
|
607 | + * |
|
608 | + * @since 1.0.19 |
|
609 | + * @param string $context View or edit context. |
|
610 | + * @return string |
|
611 | + */ |
|
612 | + public function get_type( $context = 'view' ) { |
|
613 | 613 | return $this->get_prop( 'type', $context ); |
614 | - } |
|
615 | - |
|
616 | - /** |
|
617 | - * Returns the post type name. |
|
618 | - * |
|
619 | - * @since 1.0.19 |
|
620 | - * @return string |
|
621 | - */ |
|
622 | - public function get_invoice_quote_type() { |
|
614 | + } |
|
615 | + |
|
616 | + /** |
|
617 | + * Returns the post type name. |
|
618 | + * |
|
619 | + * @since 1.0.19 |
|
620 | + * @return string |
|
621 | + */ |
|
622 | + public function get_invoice_quote_type() { |
|
623 | 623 | return getpaid_get_post_type_label( $this->get_post_type(), false ); |
624 | 624 | } |
625 | 625 | |
626 | 626 | /** |
627 | - * Get the invoice post type label. |
|
628 | - * |
|
629 | - * @since 1.0.19 |
|
630 | - * @param string $context View or edit context. |
|
631 | - * @return string |
|
632 | - */ |
|
633 | - public function get_label( $context = 'view' ) { |
|
627 | + * Get the invoice post type label. |
|
628 | + * |
|
629 | + * @since 1.0.19 |
|
630 | + * @param string $context View or edit context. |
|
631 | + * @return string |
|
632 | + */ |
|
633 | + public function get_label( $context = 'view' ) { |
|
634 | 634 | return getpaid_get_post_type_label( $this->get_post_type( $context ), false ); |
635 | - } |
|
636 | - |
|
637 | - /** |
|
638 | - * Get the invoice post type. |
|
639 | - * |
|
640 | - * @since 1.0.19 |
|
641 | - * @param string $context View or edit context. |
|
642 | - * @return string |
|
643 | - */ |
|
644 | - public function get_post_type( $context = 'view' ) { |
|
635 | + } |
|
636 | + |
|
637 | + /** |
|
638 | + * Get the invoice post type. |
|
639 | + * |
|
640 | + * @since 1.0.19 |
|
641 | + * @param string $context View or edit context. |
|
642 | + * @return string |
|
643 | + */ |
|
644 | + public function get_post_type( $context = 'view' ) { |
|
645 | 645 | return $this->get_prop( 'post_type', $context ); |
646 | 646 | } |
647 | 647 | |
648 | 648 | /** |
649 | - * Get the invoice mode. |
|
650 | - * |
|
651 | - * @since 1.0.19 |
|
652 | - * @param string $context View or edit context. |
|
653 | - * @return string |
|
654 | - */ |
|
655 | - public function get_mode( $context = 'view' ) { |
|
649 | + * Get the invoice mode. |
|
650 | + * |
|
651 | + * @since 1.0.19 |
|
652 | + * @param string $context View or edit context. |
|
653 | + * @return string |
|
654 | + */ |
|
655 | + public function get_mode( $context = 'view' ) { |
|
656 | 656 | return $this->get_prop( 'mode', $context ); |
657 | 657 | } |
658 | 658 | |
659 | 659 | /** |
660 | - * Get the invoice path. |
|
661 | - * |
|
662 | - * @since 1.0.19 |
|
663 | - * @param string $context View or edit context. |
|
664 | - * @return string |
|
665 | - */ |
|
666 | - public function get_path( $context = 'view' ) { |
|
660 | + * Get the invoice path. |
|
661 | + * |
|
662 | + * @since 1.0.19 |
|
663 | + * @param string $context View or edit context. |
|
664 | + * @return string |
|
665 | + */ |
|
666 | + public function get_path( $context = 'view' ) { |
|
667 | 667 | $path = $this->get_prop( 'path', $context ); |
668 | - $prefix = $this->get_type(); |
|
668 | + $prefix = $this->get_type(); |
|
669 | 669 | |
670 | - if ( 0 !== strpos( $path, $prefix ) ) { |
|
671 | - $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
672 | - $this->set_path( $path ); |
|
673 | - } |
|
670 | + if ( 0 !== strpos( $path, $prefix ) ) { |
|
671 | + $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
672 | + $this->set_path( $path ); |
|
673 | + } |
|
674 | 674 | |
675 | - return $path; |
|
675 | + return $path; |
|
676 | 676 | } |
677 | 677 | |
678 | 678 | /** |
679 | - * Get the invoice name/title. |
|
680 | - * |
|
681 | - * @since 1.0.19 |
|
682 | - * @param string $context View or edit context. |
|
683 | - * @return string |
|
684 | - */ |
|
685 | - public function get_name( $context = 'view' ) { |
|
679 | + * Get the invoice name/title. |
|
680 | + * |
|
681 | + * @since 1.0.19 |
|
682 | + * @param string $context View or edit context. |
|
683 | + * @return string |
|
684 | + */ |
|
685 | + public function get_name( $context = 'view' ) { |
|
686 | 686 | return $this->get_prop( 'title', $context ); |
687 | 687 | } |
688 | 688 | |
689 | 689 | /** |
690 | - * Alias of self::get_name(). |
|
691 | - * |
|
692 | - * @since 1.0.19 |
|
693 | - * @param string $context View or edit context. |
|
694 | - * @return string |
|
695 | - */ |
|
696 | - public function get_title( $context = 'view' ) { |
|
697 | - return $this->get_name( $context ); |
|
690 | + * Alias of self::get_name(). |
|
691 | + * |
|
692 | + * @since 1.0.19 |
|
693 | + * @param string $context View or edit context. |
|
694 | + * @return string |
|
695 | + */ |
|
696 | + public function get_title( $context = 'view' ) { |
|
697 | + return $this->get_name( $context ); |
|
698 | 698 | } |
699 | 699 | |
700 | 700 | /** |
701 | - * Get the invoice description. |
|
702 | - * |
|
703 | - * @since 1.0.19 |
|
704 | - * @param string $context View or edit context. |
|
705 | - * @return string |
|
706 | - */ |
|
707 | - public function get_description( $context = 'view' ) { |
|
708 | - return $this->get_prop( 'description', $context ); |
|
701 | + * Get the invoice description. |
|
702 | + * |
|
703 | + * @since 1.0.19 |
|
704 | + * @param string $context View or edit context. |
|
705 | + * @return string |
|
706 | + */ |
|
707 | + public function get_description( $context = 'view' ) { |
|
708 | + return $this->get_prop( 'description', $context ); |
|
709 | 709 | } |
710 | 710 | |
711 | 711 | /** |
712 | - * Alias of self::get_description(). |
|
713 | - * |
|
714 | - * @since 1.0.19 |
|
715 | - * @param string $context View or edit context. |
|
716 | - * @return string |
|
717 | - */ |
|
718 | - public function get_excerpt( $context = 'view' ) { |
|
719 | - return $this->get_description( $context ); |
|
712 | + * Alias of self::get_description(). |
|
713 | + * |
|
714 | + * @since 1.0.19 |
|
715 | + * @param string $context View or edit context. |
|
716 | + * @return string |
|
717 | + */ |
|
718 | + public function get_excerpt( $context = 'view' ) { |
|
719 | + return $this->get_description( $context ); |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | /** |
723 | - * Alias of self::get_description(). |
|
724 | - * |
|
725 | - * @since 1.0.19 |
|
726 | - * @param string $context View or edit context. |
|
727 | - * @return string |
|
728 | - */ |
|
729 | - public function get_summary( $context = 'view' ) { |
|
730 | - return $this->get_description( $context ); |
|
723 | + * Alias of self::get_description(). |
|
724 | + * |
|
725 | + * @since 1.0.19 |
|
726 | + * @param string $context View or edit context. |
|
727 | + * @return string |
|
728 | + */ |
|
729 | + public function get_summary( $context = 'view' ) { |
|
730 | + return $this->get_description( $context ); |
|
731 | 731 | } |
732 | 732 | |
733 | 733 | /** |
734 | - * Returns the user info. |
|
735 | - * |
|
736 | - * @since 1.0.19 |
|
734 | + * Returns the user info. |
|
735 | + * |
|
736 | + * @since 1.0.19 |
|
737 | 737 | * @param string $context View or edit context. |
738 | - * @return array |
|
739 | - */ |
|
738 | + * @return array |
|
739 | + */ |
|
740 | 740 | public function get_user_info( $context = 'view' ) { |
741 | 741 | |
742 | 742 | $user_info = array( |
@@ -751,650 +751,650 @@ discard block |
||
751 | 751 | 'state' => $this->get_state( $context ), |
752 | 752 | 'zip' => $this->get_zip( $context ), |
753 | 753 | 'company' => $this->get_company( $context ), |
754 | - 'company_id' => $this->get_company_id( $context ), |
|
754 | + 'company_id' => $this->get_company_id( $context ), |
|
755 | 755 | 'vat_number' => $this->get_vat_number( $context ), |
756 | 756 | 'discount' => $this->get_discount_code( $context ), |
757 | - ); |
|
757 | + ); |
|
758 | 758 | |
759 | - return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
759 | + return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
760 | 760 | |
761 | 761 | } |
762 | 762 | |
763 | 763 | /** |
764 | - * Get the customer id. |
|
765 | - * |
|
766 | - * @since 1.0.19 |
|
767 | - * @param string $context View or edit context. |
|
768 | - * @return int |
|
769 | - */ |
|
770 | - public function get_author( $context = 'view' ) { |
|
771 | - return (int) $this->get_prop( 'author', $context ); |
|
764 | + * Get the customer id. |
|
765 | + * |
|
766 | + * @since 1.0.19 |
|
767 | + * @param string $context View or edit context. |
|
768 | + * @return int |
|
769 | + */ |
|
770 | + public function get_author( $context = 'view' ) { |
|
771 | + return (int) $this->get_prop( 'author', $context ); |
|
772 | 772 | } |
773 | 773 | |
774 | 774 | /** |
775 | - * Alias of self::get_author(). |
|
776 | - * |
|
777 | - * @since 1.0.19 |
|
778 | - * @param string $context View or edit context. |
|
779 | - * @return int |
|
780 | - */ |
|
781 | - public function get_user_id( $context = 'view' ) { |
|
782 | - return $this->get_author( $context ); |
|
775 | + * Alias of self::get_author(). |
|
776 | + * |
|
777 | + * @since 1.0.19 |
|
778 | + * @param string $context View or edit context. |
|
779 | + * @return int |
|
780 | + */ |
|
781 | + public function get_user_id( $context = 'view' ) { |
|
782 | + return $this->get_author( $context ); |
|
783 | 783 | } |
784 | 784 | |
785 | - /** |
|
786 | - * Alias of self::get_author(). |
|
787 | - * |
|
788 | - * @since 1.0.19 |
|
789 | - * @param string $context View or edit context. |
|
790 | - * @return int |
|
791 | - */ |
|
792 | - public function get_customer_id( $context = 'view' ) { |
|
793 | - return $this->get_author( $context ); |
|
785 | + /** |
|
786 | + * Alias of self::get_author(). |
|
787 | + * |
|
788 | + * @since 1.0.19 |
|
789 | + * @param string $context View or edit context. |
|
790 | + * @return int |
|
791 | + */ |
|
792 | + public function get_customer_id( $context = 'view' ) { |
|
793 | + return $this->get_author( $context ); |
|
794 | 794 | } |
795 | 795 | |
796 | 796 | /** |
797 | - * Get the customer's ip. |
|
798 | - * |
|
799 | - * @since 1.0.19 |
|
800 | - * @param string $context View or edit context. |
|
801 | - * @return string |
|
802 | - */ |
|
803 | - public function get_ip( $context = 'view' ) { |
|
804 | - return $this->get_prop( 'user_ip', $context ); |
|
797 | + * Get the customer's ip. |
|
798 | + * |
|
799 | + * @since 1.0.19 |
|
800 | + * @param string $context View or edit context. |
|
801 | + * @return string |
|
802 | + */ |
|
803 | + public function get_ip( $context = 'view' ) { |
|
804 | + return $this->get_prop( 'user_ip', $context ); |
|
805 | 805 | } |
806 | 806 | |
807 | 807 | /** |
808 | - * Alias of self::get_ip(). |
|
809 | - * |
|
810 | - * @since 1.0.19 |
|
811 | - * @param string $context View or edit context. |
|
812 | - * @return string |
|
813 | - */ |
|
814 | - public function get_user_ip( $context = 'view' ) { |
|
815 | - return $this->get_ip( $context ); |
|
808 | + * Alias of self::get_ip(). |
|
809 | + * |
|
810 | + * @since 1.0.19 |
|
811 | + * @param string $context View or edit context. |
|
812 | + * @return string |
|
813 | + */ |
|
814 | + public function get_user_ip( $context = 'view' ) { |
|
815 | + return $this->get_ip( $context ); |
|
816 | 816 | } |
817 | 817 | |
818 | - /** |
|
819 | - * Alias of self::get_ip(). |
|
820 | - * |
|
821 | - * @since 1.0.19 |
|
822 | - * @param string $context View or edit context. |
|
823 | - * @return string |
|
824 | - */ |
|
825 | - public function get_customer_ip( $context = 'view' ) { |
|
826 | - return $this->get_ip( $context ); |
|
818 | + /** |
|
819 | + * Alias of self::get_ip(). |
|
820 | + * |
|
821 | + * @since 1.0.19 |
|
822 | + * @param string $context View or edit context. |
|
823 | + * @return string |
|
824 | + */ |
|
825 | + public function get_customer_ip( $context = 'view' ) { |
|
826 | + return $this->get_ip( $context ); |
|
827 | 827 | } |
828 | 828 | |
829 | 829 | /** |
830 | - * Get the customer's first name. |
|
831 | - * |
|
832 | - * @since 1.0.19 |
|
833 | - * @param string $context View or edit context. |
|
834 | - * @return string |
|
835 | - */ |
|
836 | - public function get_first_name( $context = 'view' ) { |
|
837 | - return $this->get_prop( 'first_name', $context ); |
|
830 | + * Get the customer's first name. |
|
831 | + * |
|
832 | + * @since 1.0.19 |
|
833 | + * @param string $context View or edit context. |
|
834 | + * @return string |
|
835 | + */ |
|
836 | + public function get_first_name( $context = 'view' ) { |
|
837 | + return $this->get_prop( 'first_name', $context ); |
|
838 | 838 | } |
839 | 839 | |
840 | 840 | /** |
841 | - * Alias of self::get_first_name(). |
|
842 | - * |
|
843 | - * @since 1.0.19 |
|
844 | - * @param string $context View or edit context. |
|
845 | - * @return string |
|
846 | - */ |
|
847 | - public function get_user_first_name( $context = 'view' ) { |
|
848 | - return $this->get_first_name( $context ); |
|
841 | + * Alias of self::get_first_name(). |
|
842 | + * |
|
843 | + * @since 1.0.19 |
|
844 | + * @param string $context View or edit context. |
|
845 | + * @return string |
|
846 | + */ |
|
847 | + public function get_user_first_name( $context = 'view' ) { |
|
848 | + return $this->get_first_name( $context ); |
|
849 | 849 | } |
850 | 850 | |
851 | - /** |
|
852 | - * Alias of self::get_first_name(). |
|
853 | - * |
|
854 | - * @since 1.0.19 |
|
855 | - * @param string $context View or edit context. |
|
856 | - * @return string |
|
857 | - */ |
|
858 | - public function get_customer_first_name( $context = 'view' ) { |
|
859 | - return $this->get_first_name( $context ); |
|
851 | + /** |
|
852 | + * Alias of self::get_first_name(). |
|
853 | + * |
|
854 | + * @since 1.0.19 |
|
855 | + * @param string $context View or edit context. |
|
856 | + * @return string |
|
857 | + */ |
|
858 | + public function get_customer_first_name( $context = 'view' ) { |
|
859 | + return $this->get_first_name( $context ); |
|
860 | 860 | } |
861 | 861 | |
862 | 862 | /** |
863 | - * Get the customer's last name. |
|
864 | - * |
|
865 | - * @since 1.0.19 |
|
866 | - * @param string $context View or edit context. |
|
867 | - * @return string |
|
868 | - */ |
|
869 | - public function get_last_name( $context = 'view' ) { |
|
870 | - return $this->get_prop( 'last_name', $context ); |
|
863 | + * Get the customer's last name. |
|
864 | + * |
|
865 | + * @since 1.0.19 |
|
866 | + * @param string $context View or edit context. |
|
867 | + * @return string |
|
868 | + */ |
|
869 | + public function get_last_name( $context = 'view' ) { |
|
870 | + return $this->get_prop( 'last_name', $context ); |
|
871 | 871 | } |
872 | 872 | |
873 | 873 | /** |
874 | - * Alias of self::get_last_name(). |
|
875 | - * |
|
876 | - * @since 1.0.19 |
|
877 | - * @param string $context View or edit context. |
|
878 | - * @return string |
|
879 | - */ |
|
880 | - public function get_user_last_name( $context = 'view' ) { |
|
881 | - return $this->get_last_name( $context ); |
|
874 | + * Alias of self::get_last_name(). |
|
875 | + * |
|
876 | + * @since 1.0.19 |
|
877 | + * @param string $context View or edit context. |
|
878 | + * @return string |
|
879 | + */ |
|
880 | + public function get_user_last_name( $context = 'view' ) { |
|
881 | + return $this->get_last_name( $context ); |
|
882 | 882 | } |
883 | 883 | |
884 | 884 | /** |
885 | - * Alias of self::get_last_name(). |
|
886 | - * |
|
887 | - * @since 1.0.19 |
|
888 | - * @param string $context View or edit context. |
|
889 | - * @return string |
|
890 | - */ |
|
891 | - public function get_customer_last_name( $context = 'view' ) { |
|
892 | - return $this->get_last_name( $context ); |
|
885 | + * Alias of self::get_last_name(). |
|
886 | + * |
|
887 | + * @since 1.0.19 |
|
888 | + * @param string $context View or edit context. |
|
889 | + * @return string |
|
890 | + */ |
|
891 | + public function get_customer_last_name( $context = 'view' ) { |
|
892 | + return $this->get_last_name( $context ); |
|
893 | 893 | } |
894 | 894 | |
895 | 895 | /** |
896 | - * Get the customer's full name. |
|
897 | - * |
|
898 | - * @since 1.0.19 |
|
899 | - * @param string $context View or edit context. |
|
900 | - * @return string |
|
901 | - */ |
|
902 | - public function get_full_name( $context = 'view' ) { |
|
903 | - return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
896 | + * Get the customer's full name. |
|
897 | + * |
|
898 | + * @since 1.0.19 |
|
899 | + * @param string $context View or edit context. |
|
900 | + * @return string |
|
901 | + */ |
|
902 | + public function get_full_name( $context = 'view' ) { |
|
903 | + return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
904 | 904 | } |
905 | 905 | |
906 | 906 | /** |
907 | - * Alias of self::get_full_name(). |
|
908 | - * |
|
909 | - * @since 1.0.19 |
|
910 | - * @param string $context View or edit context. |
|
911 | - * @return string |
|
912 | - */ |
|
913 | - public function get_user_full_name( $context = 'view' ) { |
|
914 | - return $this->get_full_name( $context ); |
|
907 | + * Alias of self::get_full_name(). |
|
908 | + * |
|
909 | + * @since 1.0.19 |
|
910 | + * @param string $context View or edit context. |
|
911 | + * @return string |
|
912 | + */ |
|
913 | + public function get_user_full_name( $context = 'view' ) { |
|
914 | + return $this->get_full_name( $context ); |
|
915 | 915 | } |
916 | 916 | |
917 | 917 | /** |
918 | - * Alias of self::get_full_name(). |
|
919 | - * |
|
920 | - * @since 1.0.19 |
|
921 | - * @param string $context View or edit context. |
|
922 | - * @return string |
|
923 | - */ |
|
924 | - public function get_customer_full_name( $context = 'view' ) { |
|
925 | - return $this->get_full_name( $context ); |
|
918 | + * Alias of self::get_full_name(). |
|
919 | + * |
|
920 | + * @since 1.0.19 |
|
921 | + * @param string $context View or edit context. |
|
922 | + * @return string |
|
923 | + */ |
|
924 | + public function get_customer_full_name( $context = 'view' ) { |
|
925 | + return $this->get_full_name( $context ); |
|
926 | 926 | } |
927 | 927 | |
928 | 928 | /** |
929 | - * Get the customer's phone number. |
|
930 | - * |
|
931 | - * @since 1.0.19 |
|
932 | - * @param string $context View or edit context. |
|
933 | - * @return string |
|
934 | - */ |
|
935 | - public function get_phone( $context = 'view' ) { |
|
936 | - return $this->get_prop( 'phone', $context ); |
|
929 | + * Get the customer's phone number. |
|
930 | + * |
|
931 | + * @since 1.0.19 |
|
932 | + * @param string $context View or edit context. |
|
933 | + * @return string |
|
934 | + */ |
|
935 | + public function get_phone( $context = 'view' ) { |
|
936 | + return $this->get_prop( 'phone', $context ); |
|
937 | 937 | } |
938 | 938 | |
939 | 939 | /** |
940 | - * Alias of self::get_phone(). |
|
941 | - * |
|
942 | - * @since 1.0.19 |
|
943 | - * @param string $context View or edit context. |
|
944 | - * @return string |
|
945 | - */ |
|
946 | - public function get_phone_number( $context = 'view' ) { |
|
947 | - return $this->get_phone( $context ); |
|
940 | + * Alias of self::get_phone(). |
|
941 | + * |
|
942 | + * @since 1.0.19 |
|
943 | + * @param string $context View or edit context. |
|
944 | + * @return string |
|
945 | + */ |
|
946 | + public function get_phone_number( $context = 'view' ) { |
|
947 | + return $this->get_phone( $context ); |
|
948 | 948 | } |
949 | 949 | |
950 | 950 | /** |
951 | - * Alias of self::get_phone(). |
|
952 | - * |
|
953 | - * @since 1.0.19 |
|
954 | - * @param string $context View or edit context. |
|
955 | - * @return string |
|
956 | - */ |
|
957 | - public function get_user_phone( $context = 'view' ) { |
|
958 | - return $this->get_phone( $context ); |
|
959 | - } |
|
960 | - |
|
951 | + * Alias of self::get_phone(). |
|
952 | + * |
|
953 | + * @since 1.0.19 |
|
954 | + * @param string $context View or edit context. |
|
955 | + * @return string |
|
956 | + */ |
|
957 | + public function get_user_phone( $context = 'view' ) { |
|
958 | + return $this->get_phone( $context ); |
|
959 | + } |
|
960 | + |
|
961 | + /** |
|
962 | + * Alias of self::get_phone(). |
|
963 | + * |
|
964 | + * @since 1.0.19 |
|
965 | + * @param string $context View or edit context. |
|
966 | + * @return string |
|
967 | + */ |
|
968 | + public function get_customer_phone( $context = 'view' ) { |
|
969 | + return $this->get_phone( $context ); |
|
970 | + } |
|
971 | + |
|
972 | + /** |
|
973 | + * Get the customer's email address. |
|
974 | + * |
|
975 | + * @since 1.0.19 |
|
976 | + * @param string $context View or edit context. |
|
977 | + * @return string |
|
978 | + */ |
|
979 | + public function get_email( $context = 'view' ) { |
|
980 | + return $this->get_prop( 'email', $context ); |
|
981 | + } |
|
982 | + |
|
983 | + /** |
|
984 | + * Alias of self::get_email(). |
|
985 | + * |
|
986 | + * @since 1.0.19 |
|
987 | + * @param string $context View or edit context. |
|
988 | + * @return string |
|
989 | + */ |
|
990 | + public function get_email_address( $context = 'view' ) { |
|
991 | + return $this->get_email( $context ); |
|
992 | + } |
|
993 | + |
|
994 | + /** |
|
995 | + * Alias of self::get_email(). |
|
996 | + * |
|
997 | + * @since 1.0.19 |
|
998 | + * @param string $context View or edit context. |
|
999 | + * @return string |
|
1000 | + */ |
|
1001 | + public function get_user_email( $context = 'view' ) { |
|
1002 | + return $this->get_email( $context ); |
|
1003 | + } |
|
1004 | + |
|
1005 | + /** |
|
1006 | + * Alias of self::get_email(). |
|
1007 | + * |
|
1008 | + * @since 1.0.19 |
|
1009 | + * @param string $context View or edit context. |
|
1010 | + * @return string |
|
1011 | + */ |
|
1012 | + public function get_customer_email( $context = 'view' ) { |
|
1013 | + return $this->get_email( $context ); |
|
1014 | + } |
|
1015 | + |
|
1016 | + /** |
|
1017 | + * Get the customer's country. |
|
1018 | + * |
|
1019 | + * @since 1.0.19 |
|
1020 | + * @param string $context View or edit context. |
|
1021 | + * @return string |
|
1022 | + */ |
|
1023 | + public function get_country( $context = 'view' ) { |
|
1024 | + $country = $this->get_prop( 'country', $context ); |
|
1025 | + return empty( $country ) ? wpinv_get_default_country() : $country; |
|
1026 | + } |
|
1027 | + |
|
1028 | + /** |
|
1029 | + * Alias of self::get_country(). |
|
1030 | + * |
|
1031 | + * @since 1.0.19 |
|
1032 | + * @param string $context View or edit context. |
|
1033 | + * @return string |
|
1034 | + */ |
|
1035 | + public function get_user_country( $context = 'view' ) { |
|
1036 | + return $this->get_country( $context ); |
|
1037 | + } |
|
1038 | + |
|
1039 | + /** |
|
1040 | + * Alias of self::get_country(). |
|
1041 | + * |
|
1042 | + * @since 1.0.19 |
|
1043 | + * @param string $context View or edit context. |
|
1044 | + * @return string |
|
1045 | + */ |
|
1046 | + public function get_customer_country( $context = 'view' ) { |
|
1047 | + return $this->get_country( $context ); |
|
1048 | + } |
|
1049 | + |
|
1050 | + /** |
|
1051 | + * Get the customer's state. |
|
1052 | + * |
|
1053 | + * @since 1.0.19 |
|
1054 | + * @param string $context View or edit context. |
|
1055 | + * @return string |
|
1056 | + */ |
|
1057 | + public function get_state( $context = 'view' ) { |
|
1058 | + $state = $this->get_prop( 'state', $context ); |
|
1059 | + return empty( $state ) ? wpinv_get_default_state() : $state; |
|
1060 | + } |
|
1061 | + |
|
961 | 1062 | /** |
962 | - * Alias of self::get_phone(). |
|
963 | - * |
|
964 | - * @since 1.0.19 |
|
965 | - * @param string $context View or edit context. |
|
966 | - * @return string |
|
967 | - */ |
|
968 | - public function get_customer_phone( $context = 'view' ) { |
|
969 | - return $this->get_phone( $context ); |
|
1063 | + * Alias of self::get_state(). |
|
1064 | + * |
|
1065 | + * @since 1.0.19 |
|
1066 | + * @param string $context View or edit context. |
|
1067 | + * @return string |
|
1068 | + */ |
|
1069 | + public function get_user_state( $context = 'view' ) { |
|
1070 | + return $this->get_state( $context ); |
|
970 | 1071 | } |
971 | 1072 | |
972 | 1073 | /** |
973 | - * Get the customer's email address. |
|
974 | - * |
|
975 | - * @since 1.0.19 |
|
976 | - * @param string $context View or edit context. |
|
977 | - * @return string |
|
978 | - */ |
|
979 | - public function get_email( $context = 'view' ) { |
|
980 | - return $this->get_prop( 'email', $context ); |
|
1074 | + * Alias of self::get_state(). |
|
1075 | + * |
|
1076 | + * @since 1.0.19 |
|
1077 | + * @param string $context View or edit context. |
|
1078 | + * @return string |
|
1079 | + */ |
|
1080 | + public function get_customer_state( $context = 'view' ) { |
|
1081 | + return $this->get_state( $context ); |
|
981 | 1082 | } |
982 | 1083 | |
983 | 1084 | /** |
984 | - * Alias of self::get_email(). |
|
985 | - * |
|
986 | - * @since 1.0.19 |
|
987 | - * @param string $context View or edit context. |
|
988 | - * @return string |
|
989 | - */ |
|
990 | - public function get_email_address( $context = 'view' ) { |
|
991 | - return $this->get_email( $context ); |
|
1085 | + * Get the customer's city. |
|
1086 | + * |
|
1087 | + * @since 1.0.19 |
|
1088 | + * @param string $context View or edit context. |
|
1089 | + * @return string |
|
1090 | + */ |
|
1091 | + public function get_city( $context = 'view' ) { |
|
1092 | + return $this->get_prop( 'city', $context ); |
|
992 | 1093 | } |
993 | 1094 | |
994 | 1095 | /** |
995 | - * Alias of self::get_email(). |
|
996 | - * |
|
997 | - * @since 1.0.19 |
|
998 | - * @param string $context View or edit context. |
|
999 | - * @return string |
|
1000 | - */ |
|
1001 | - public function get_user_email( $context = 'view' ) { |
|
1002 | - return $this->get_email( $context ); |
|
1096 | + * Alias of self::get_city(). |
|
1097 | + * |
|
1098 | + * @since 1.0.19 |
|
1099 | + * @param string $context View or edit context. |
|
1100 | + * @return string |
|
1101 | + */ |
|
1102 | + public function get_user_city( $context = 'view' ) { |
|
1103 | + return $this->get_city( $context ); |
|
1003 | 1104 | } |
1004 | 1105 | |
1005 | 1106 | /** |
1006 | - * Alias of self::get_email(). |
|
1007 | - * |
|
1008 | - * @since 1.0.19 |
|
1009 | - * @param string $context View or edit context. |
|
1010 | - * @return string |
|
1011 | - */ |
|
1012 | - public function get_customer_email( $context = 'view' ) { |
|
1013 | - return $this->get_email( $context ); |
|
1107 | + * Alias of self::get_city(). |
|
1108 | + * |
|
1109 | + * @since 1.0.19 |
|
1110 | + * @param string $context View or edit context. |
|
1111 | + * @return string |
|
1112 | + */ |
|
1113 | + public function get_customer_city( $context = 'view' ) { |
|
1114 | + return $this->get_city( $context ); |
|
1014 | 1115 | } |
1015 | 1116 | |
1016 | 1117 | /** |
1017 | - * Get the customer's country. |
|
1018 | - * |
|
1019 | - * @since 1.0.19 |
|
1020 | - * @param string $context View or edit context. |
|
1021 | - * @return string |
|
1022 | - */ |
|
1023 | - public function get_country( $context = 'view' ) { |
|
1024 | - $country = $this->get_prop( 'country', $context ); |
|
1025 | - return empty( $country ) ? wpinv_get_default_country() : $country; |
|
1118 | + * Get the customer's zip. |
|
1119 | + * |
|
1120 | + * @since 1.0.19 |
|
1121 | + * @param string $context View or edit context. |
|
1122 | + * @return string |
|
1123 | + */ |
|
1124 | + public function get_zip( $context = 'view' ) { |
|
1125 | + return $this->get_prop( 'zip', $context ); |
|
1026 | 1126 | } |
1027 | 1127 | |
1028 | 1128 | /** |
1029 | - * Alias of self::get_country(). |
|
1030 | - * |
|
1031 | - * @since 1.0.19 |
|
1032 | - * @param string $context View or edit context. |
|
1033 | - * @return string |
|
1034 | - */ |
|
1035 | - public function get_user_country( $context = 'view' ) { |
|
1036 | - return $this->get_country( $context ); |
|
1129 | + * Alias of self::get_zip(). |
|
1130 | + * |
|
1131 | + * @since 1.0.19 |
|
1132 | + * @param string $context View or edit context. |
|
1133 | + * @return string |
|
1134 | + */ |
|
1135 | + public function get_user_zip( $context = 'view' ) { |
|
1136 | + return $this->get_zip( $context ); |
|
1037 | 1137 | } |
1038 | 1138 | |
1039 | 1139 | /** |
1040 | - * Alias of self::get_country(). |
|
1041 | - * |
|
1042 | - * @since 1.0.19 |
|
1043 | - * @param string $context View or edit context. |
|
1044 | - * @return string |
|
1045 | - */ |
|
1046 | - public function get_customer_country( $context = 'view' ) { |
|
1047 | - return $this->get_country( $context ); |
|
1140 | + * Alias of self::get_zip(). |
|
1141 | + * |
|
1142 | + * @since 1.0.19 |
|
1143 | + * @param string $context View or edit context. |
|
1144 | + * @return string |
|
1145 | + */ |
|
1146 | + public function get_customer_zip( $context = 'view' ) { |
|
1147 | + return $this->get_zip( $context ); |
|
1048 | 1148 | } |
1049 | 1149 | |
1050 | 1150 | /** |
1051 | - * Get the customer's state. |
|
1052 | - * |
|
1053 | - * @since 1.0.19 |
|
1054 | - * @param string $context View or edit context. |
|
1055 | - * @return string |
|
1056 | - */ |
|
1057 | - public function get_state( $context = 'view' ) { |
|
1058 | - $state = $this->get_prop( 'state', $context ); |
|
1059 | - return empty( $state ) ? wpinv_get_default_state() : $state; |
|
1151 | + * Get the customer's company. |
|
1152 | + * |
|
1153 | + * @since 1.0.19 |
|
1154 | + * @param string $context View or edit context. |
|
1155 | + * @return string |
|
1156 | + */ |
|
1157 | + public function get_company( $context = 'view' ) { |
|
1158 | + return $this->get_prop( 'company', $context ); |
|
1159 | + } |
|
1160 | + |
|
1161 | + /** |
|
1162 | + * Alias of self::get_company(). |
|
1163 | + * |
|
1164 | + * @since 1.0.19 |
|
1165 | + * @param string $context View or edit context. |
|
1166 | + * @return string |
|
1167 | + */ |
|
1168 | + public function get_user_company( $context = 'view' ) { |
|
1169 | + return $this->get_company( $context ); |
|
1170 | + } |
|
1171 | + |
|
1172 | + /** |
|
1173 | + * Alias of self::get_company(). |
|
1174 | + * |
|
1175 | + * @since 1.0.19 |
|
1176 | + * @param string $context View or edit context. |
|
1177 | + * @return string |
|
1178 | + */ |
|
1179 | + public function get_customer_company( $context = 'view' ) { |
|
1180 | + return $this->get_company( $context ); |
|
1181 | + } |
|
1182 | + |
|
1183 | + /** |
|
1184 | + * Get the customer's company id. |
|
1185 | + * |
|
1186 | + * @since 1.0.19 |
|
1187 | + * @param string $context View or edit context. |
|
1188 | + * @return string |
|
1189 | + */ |
|
1190 | + public function get_company_id( $context = 'view' ) { |
|
1191 | + return $this->get_prop( 'company_id', $context ); |
|
1060 | 1192 | } |
1061 | 1193 | |
1062 | 1194 | /** |
1063 | - * Alias of self::get_state(). |
|
1064 | - * |
|
1065 | - * @since 1.0.19 |
|
1066 | - * @param string $context View or edit context. |
|
1067 | - * @return string |
|
1068 | - */ |
|
1069 | - public function get_user_state( $context = 'view' ) { |
|
1070 | - return $this->get_state( $context ); |
|
1195 | + * Get the customer's vat number. |
|
1196 | + * |
|
1197 | + * @since 1.0.19 |
|
1198 | + * @param string $context View or edit context. |
|
1199 | + * @return string |
|
1200 | + */ |
|
1201 | + public function get_vat_number( $context = 'view' ) { |
|
1202 | + return $this->get_prop( 'vat_number', $context ); |
|
1071 | 1203 | } |
1072 | 1204 | |
1073 | 1205 | /** |
1074 | - * Alias of self::get_state(). |
|
1075 | - * |
|
1076 | - * @since 1.0.19 |
|
1077 | - * @param string $context View or edit context. |
|
1078 | - * @return string |
|
1079 | - */ |
|
1080 | - public function get_customer_state( $context = 'view' ) { |
|
1081 | - return $this->get_state( $context ); |
|
1206 | + * Alias of self::get_vat_number(). |
|
1207 | + * |
|
1208 | + * @since 1.0.19 |
|
1209 | + * @param string $context View or edit context. |
|
1210 | + * @return string |
|
1211 | + */ |
|
1212 | + public function get_user_vat_number( $context = 'view' ) { |
|
1213 | + return $this->get_vat_number( $context ); |
|
1214 | + } |
|
1215 | + |
|
1216 | + /** |
|
1217 | + * Alias of self::get_vat_number(). |
|
1218 | + * |
|
1219 | + * @since 1.0.19 |
|
1220 | + * @param string $context View or edit context. |
|
1221 | + * @return string |
|
1222 | + */ |
|
1223 | + public function get_customer_vat_number( $context = 'view' ) { |
|
1224 | + return $this->get_vat_number( $context ); |
|
1082 | 1225 | } |
1083 | 1226 | |
1084 | 1227 | /** |
1085 | - * Get the customer's city. |
|
1086 | - * |
|
1087 | - * @since 1.0.19 |
|
1088 | - * @param string $context View or edit context. |
|
1089 | - * @return string |
|
1090 | - */ |
|
1091 | - public function get_city( $context = 'view' ) { |
|
1092 | - return $this->get_prop( 'city', $context ); |
|
1228 | + * Get the customer's vat rate. |
|
1229 | + * |
|
1230 | + * @since 1.0.19 |
|
1231 | + * @param string $context View or edit context. |
|
1232 | + * @return string |
|
1233 | + */ |
|
1234 | + public function get_vat_rate( $context = 'view' ) { |
|
1235 | + return $this->get_prop( 'vat_rate', $context ); |
|
1093 | 1236 | } |
1094 | 1237 | |
1095 | 1238 | /** |
1096 | - * Alias of self::get_city(). |
|
1097 | - * |
|
1098 | - * @since 1.0.19 |
|
1099 | - * @param string $context View or edit context. |
|
1100 | - * @return string |
|
1101 | - */ |
|
1102 | - public function get_user_city( $context = 'view' ) { |
|
1103 | - return $this->get_city( $context ); |
|
1239 | + * Alias of self::get_vat_rate(). |
|
1240 | + * |
|
1241 | + * @since 1.0.19 |
|
1242 | + * @param string $context View or edit context. |
|
1243 | + * @return string |
|
1244 | + */ |
|
1245 | + public function get_user_vat_rate( $context = 'view' ) { |
|
1246 | + return $this->get_vat_rate( $context ); |
|
1104 | 1247 | } |
1105 | 1248 | |
1106 | 1249 | /** |
1107 | - * Alias of self::get_city(). |
|
1108 | - * |
|
1109 | - * @since 1.0.19 |
|
1110 | - * @param string $context View or edit context. |
|
1111 | - * @return string |
|
1112 | - */ |
|
1113 | - public function get_customer_city( $context = 'view' ) { |
|
1114 | - return $this->get_city( $context ); |
|
1250 | + * Alias of self::get_vat_rate(). |
|
1251 | + * |
|
1252 | + * @since 1.0.19 |
|
1253 | + * @param string $context View or edit context. |
|
1254 | + * @return string |
|
1255 | + */ |
|
1256 | + public function get_customer_vat_rate( $context = 'view' ) { |
|
1257 | + return $this->get_vat_rate( $context ); |
|
1115 | 1258 | } |
1116 | 1259 | |
1117 | 1260 | /** |
1118 | - * Get the customer's zip. |
|
1119 | - * |
|
1120 | - * @since 1.0.19 |
|
1121 | - * @param string $context View or edit context. |
|
1122 | - * @return string |
|
1123 | - */ |
|
1124 | - public function get_zip( $context = 'view' ) { |
|
1125 | - return $this->get_prop( 'zip', $context ); |
|
1261 | + * Get the customer's address. |
|
1262 | + * |
|
1263 | + * @since 1.0.19 |
|
1264 | + * @param string $context View or edit context. |
|
1265 | + * @return string |
|
1266 | + */ |
|
1267 | + public function get_address( $context = 'view' ) { |
|
1268 | + return $this->get_prop( 'address', $context ); |
|
1126 | 1269 | } |
1127 | 1270 | |
1128 | 1271 | /** |
1129 | - * Alias of self::get_zip(). |
|
1130 | - * |
|
1131 | - * @since 1.0.19 |
|
1132 | - * @param string $context View or edit context. |
|
1133 | - * @return string |
|
1134 | - */ |
|
1135 | - public function get_user_zip( $context = 'view' ) { |
|
1136 | - return $this->get_zip( $context ); |
|
1272 | + * Alias of self::get_address(). |
|
1273 | + * |
|
1274 | + * @since 1.0.19 |
|
1275 | + * @param string $context View or edit context. |
|
1276 | + * @return string |
|
1277 | + */ |
|
1278 | + public function get_user_address( $context = 'view' ) { |
|
1279 | + return $this->get_address( $context ); |
|
1137 | 1280 | } |
1138 | 1281 | |
1139 | 1282 | /** |
1140 | - * Alias of self::get_zip(). |
|
1141 | - * |
|
1142 | - * @since 1.0.19 |
|
1143 | - * @param string $context View or edit context. |
|
1144 | - * @return string |
|
1145 | - */ |
|
1146 | - public function get_customer_zip( $context = 'view' ) { |
|
1147 | - return $this->get_zip( $context ); |
|
1283 | + * Alias of self::get_address(). |
|
1284 | + * |
|
1285 | + * @since 1.0.19 |
|
1286 | + * @param string $context View or edit context. |
|
1287 | + * @return string |
|
1288 | + */ |
|
1289 | + public function get_customer_address( $context = 'view' ) { |
|
1290 | + return $this->get_address( $context ); |
|
1148 | 1291 | } |
1149 | 1292 | |
1150 | 1293 | /** |
1151 | - * Get the customer's company. |
|
1152 | - * |
|
1153 | - * @since 1.0.19 |
|
1154 | - * @param string $context View or edit context. |
|
1155 | - * @return string |
|
1156 | - */ |
|
1157 | - public function get_company( $context = 'view' ) { |
|
1158 | - return $this->get_prop( 'company', $context ); |
|
1294 | + * Get whether the customer has viewed the invoice or not. |
|
1295 | + * |
|
1296 | + * @since 1.0.19 |
|
1297 | + * @param string $context View or edit context. |
|
1298 | + * @return bool |
|
1299 | + */ |
|
1300 | + public function get_is_viewed( $context = 'view' ) { |
|
1301 | + return (bool) $this->get_prop( 'is_viewed', $context ); |
|
1159 | 1302 | } |
1160 | 1303 | |
1161 | 1304 | /** |
1162 | - * Alias of self::get_company(). |
|
1163 | - * |
|
1164 | - * @since 1.0.19 |
|
1165 | - * @param string $context View or edit context. |
|
1166 | - * @return string |
|
1167 | - */ |
|
1168 | - public function get_user_company( $context = 'view' ) { |
|
1169 | - return $this->get_company( $context ); |
|
1305 | + * Get other recipients for invoice communications. |
|
1306 | + * |
|
1307 | + * @since 1.0.19 |
|
1308 | + * @param string $context View or edit context. |
|
1309 | + * @return bool |
|
1310 | + */ |
|
1311 | + public function get_email_cc( $context = 'view' ) { |
|
1312 | + return $this->get_prop( 'email_cc', $context ); |
|
1170 | 1313 | } |
1171 | 1314 | |
1172 | 1315 | /** |
1173 | - * Alias of self::get_company(). |
|
1174 | - * |
|
1175 | - * @since 1.0.19 |
|
1176 | - * @param string $context View or edit context. |
|
1177 | - * @return string |
|
1178 | - */ |
|
1179 | - public function get_customer_company( $context = 'view' ) { |
|
1180 | - return $this->get_company( $context ); |
|
1316 | + * Get invoice template. |
|
1317 | + * |
|
1318 | + * @since 1.0.19 |
|
1319 | + * @param string $context View or edit context. |
|
1320 | + * @return bool |
|
1321 | + */ |
|
1322 | + public function get_template( $context = 'view' ) { |
|
1323 | + return $this->get_prop( 'template', $context ); |
|
1181 | 1324 | } |
1182 | 1325 | |
1183 | - /** |
|
1184 | - * Get the customer's company id. |
|
1185 | - * |
|
1186 | - * @since 1.0.19 |
|
1187 | - * @param string $context View or edit context. |
|
1188 | - * @return string |
|
1189 | - */ |
|
1190 | - public function get_company_id( $context = 'view' ) { |
|
1191 | - return $this->get_prop( 'company_id', $context ); |
|
1326 | + /** |
|
1327 | + * Get invoice source. |
|
1328 | + * |
|
1329 | + * @since 1.0.19 |
|
1330 | + * @param string $context View or edit context. |
|
1331 | + * @return bool |
|
1332 | + */ |
|
1333 | + public function get_created_via( $context = 'view' ) { |
|
1334 | + return $this->get_prop( 'created_via', $context ); |
|
1192 | 1335 | } |
1193 | 1336 | |
1194 | 1337 | /** |
1195 | - * Get the customer's vat number. |
|
1196 | - * |
|
1197 | - * @since 1.0.19 |
|
1198 | - * @param string $context View or edit context. |
|
1199 | - * @return string |
|
1200 | - */ |
|
1201 | - public function get_vat_number( $context = 'view' ) { |
|
1202 | - return $this->get_prop( 'vat_number', $context ); |
|
1338 | + * Get whether the customer has confirmed their address. |
|
1339 | + * |
|
1340 | + * @since 1.0.19 |
|
1341 | + * @param string $context View or edit context. |
|
1342 | + * @return bool |
|
1343 | + */ |
|
1344 | + public function get_address_confirmed( $context = 'view' ) { |
|
1345 | + return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
1203 | 1346 | } |
1204 | 1347 | |
1205 | 1348 | /** |
1206 | - * Alias of self::get_vat_number(). |
|
1207 | - * |
|
1208 | - * @since 1.0.19 |
|
1209 | - * @param string $context View or edit context. |
|
1210 | - * @return string |
|
1211 | - */ |
|
1212 | - public function get_user_vat_number( $context = 'view' ) { |
|
1213 | - return $this->get_vat_number( $context ); |
|
1349 | + * Alias of self::get_address_confirmed(). |
|
1350 | + * |
|
1351 | + * @since 1.0.19 |
|
1352 | + * @param string $context View or edit context. |
|
1353 | + * @return bool |
|
1354 | + */ |
|
1355 | + public function get_user_address_confirmed( $context = 'view' ) { |
|
1356 | + return $this->get_address_confirmed( $context ); |
|
1214 | 1357 | } |
1215 | 1358 | |
1216 | 1359 | /** |
1217 | - * Alias of self::get_vat_number(). |
|
1218 | - * |
|
1219 | - * @since 1.0.19 |
|
1220 | - * @param string $context View or edit context. |
|
1221 | - * @return string |
|
1222 | - */ |
|
1223 | - public function get_customer_vat_number( $context = 'view' ) { |
|
1224 | - return $this->get_vat_number( $context ); |
|
1360 | + * Alias of self::get_address(). |
|
1361 | + * |
|
1362 | + * @since 1.0.19 |
|
1363 | + * @param string $context View or edit context. |
|
1364 | + * @return bool |
|
1365 | + */ |
|
1366 | + public function get_customer_address_confirmed( $context = 'view' ) { |
|
1367 | + return $this->get_address_confirmed( $context ); |
|
1225 | 1368 | } |
1226 | 1369 | |
1227 | - /** |
|
1228 | - * Get the customer's vat rate. |
|
1229 | - * |
|
1230 | - * @since 1.0.19 |
|
1231 | - * @param string $context View or edit context. |
|
1232 | - * @return string |
|
1233 | - */ |
|
1234 | - public function get_vat_rate( $context = 'view' ) { |
|
1235 | - return $this->get_prop( 'vat_rate', $context ); |
|
1236 | - } |
|
1237 | - |
|
1238 | - /** |
|
1239 | - * Alias of self::get_vat_rate(). |
|
1240 | - * |
|
1241 | - * @since 1.0.19 |
|
1242 | - * @param string $context View or edit context. |
|
1243 | - * @return string |
|
1244 | - */ |
|
1245 | - public function get_user_vat_rate( $context = 'view' ) { |
|
1246 | - return $this->get_vat_rate( $context ); |
|
1247 | - } |
|
1248 | - |
|
1249 | - /** |
|
1250 | - * Alias of self::get_vat_rate(). |
|
1251 | - * |
|
1252 | - * @since 1.0.19 |
|
1253 | - * @param string $context View or edit context. |
|
1254 | - * @return string |
|
1255 | - */ |
|
1256 | - public function get_customer_vat_rate( $context = 'view' ) { |
|
1257 | - return $this->get_vat_rate( $context ); |
|
1258 | - } |
|
1259 | - |
|
1260 | - /** |
|
1261 | - * Get the customer's address. |
|
1262 | - * |
|
1263 | - * @since 1.0.19 |
|
1264 | - * @param string $context View or edit context. |
|
1265 | - * @return string |
|
1266 | - */ |
|
1267 | - public function get_address( $context = 'view' ) { |
|
1268 | - return $this->get_prop( 'address', $context ); |
|
1269 | - } |
|
1270 | - |
|
1271 | - /** |
|
1272 | - * Alias of self::get_address(). |
|
1273 | - * |
|
1274 | - * @since 1.0.19 |
|
1275 | - * @param string $context View or edit context. |
|
1276 | - * @return string |
|
1277 | - */ |
|
1278 | - public function get_user_address( $context = 'view' ) { |
|
1279 | - return $this->get_address( $context ); |
|
1280 | - } |
|
1281 | - |
|
1282 | - /** |
|
1283 | - * Alias of self::get_address(). |
|
1284 | - * |
|
1285 | - * @since 1.0.19 |
|
1286 | - * @param string $context View or edit context. |
|
1287 | - * @return string |
|
1288 | - */ |
|
1289 | - public function get_customer_address( $context = 'view' ) { |
|
1290 | - return $this->get_address( $context ); |
|
1291 | - } |
|
1292 | - |
|
1293 | - /** |
|
1294 | - * Get whether the customer has viewed the invoice or not. |
|
1295 | - * |
|
1296 | - * @since 1.0.19 |
|
1297 | - * @param string $context View or edit context. |
|
1298 | - * @return bool |
|
1299 | - */ |
|
1300 | - public function get_is_viewed( $context = 'view' ) { |
|
1301 | - return (bool) $this->get_prop( 'is_viewed', $context ); |
|
1302 | - } |
|
1303 | - |
|
1304 | - /** |
|
1305 | - * Get other recipients for invoice communications. |
|
1306 | - * |
|
1307 | - * @since 1.0.19 |
|
1308 | - * @param string $context View or edit context. |
|
1309 | - * @return bool |
|
1310 | - */ |
|
1311 | - public function get_email_cc( $context = 'view' ) { |
|
1312 | - return $this->get_prop( 'email_cc', $context ); |
|
1313 | - } |
|
1314 | - |
|
1315 | - /** |
|
1316 | - * Get invoice template. |
|
1317 | - * |
|
1318 | - * @since 1.0.19 |
|
1319 | - * @param string $context View or edit context. |
|
1320 | - * @return bool |
|
1321 | - */ |
|
1322 | - public function get_template( $context = 'view' ) { |
|
1323 | - return $this->get_prop( 'template', $context ); |
|
1324 | - } |
|
1325 | - |
|
1326 | - /** |
|
1327 | - * Get invoice source. |
|
1328 | - * |
|
1329 | - * @since 1.0.19 |
|
1330 | - * @param string $context View or edit context. |
|
1331 | - * @return bool |
|
1332 | - */ |
|
1333 | - public function get_created_via( $context = 'view' ) { |
|
1334 | - return $this->get_prop( 'created_via', $context ); |
|
1335 | - } |
|
1336 | - |
|
1337 | - /** |
|
1338 | - * Get whether the customer has confirmed their address. |
|
1339 | - * |
|
1340 | - * @since 1.0.19 |
|
1341 | - * @param string $context View or edit context. |
|
1342 | - * @return bool |
|
1343 | - */ |
|
1344 | - public function get_address_confirmed( $context = 'view' ) { |
|
1345 | - return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
1346 | - } |
|
1347 | - |
|
1348 | - /** |
|
1349 | - * Alias of self::get_address_confirmed(). |
|
1350 | - * |
|
1351 | - * @since 1.0.19 |
|
1352 | - * @param string $context View or edit context. |
|
1353 | - * @return bool |
|
1354 | - */ |
|
1355 | - public function get_user_address_confirmed( $context = 'view' ) { |
|
1356 | - return $this->get_address_confirmed( $context ); |
|
1357 | - } |
|
1358 | - |
|
1359 | - /** |
|
1360 | - * Alias of self::get_address(). |
|
1361 | - * |
|
1362 | - * @since 1.0.19 |
|
1363 | - * @param string $context View or edit context. |
|
1364 | - * @return bool |
|
1365 | - */ |
|
1366 | - public function get_customer_address_confirmed( $context = 'view' ) { |
|
1367 | - return $this->get_address_confirmed( $context ); |
|
1368 | - } |
|
1369 | - |
|
1370 | - /** |
|
1371 | - * Get the shipping amount. |
|
1372 | - * |
|
1373 | - * @since 1.0.19 |
|
1374 | - * @param string $context View or edit context. |
|
1375 | - * @return float |
|
1376 | - */ |
|
1377 | - public function get_shipping( $context = 'view' ) { |
|
1378 | - |
|
1379 | - if ( $context = 'view' ) { |
|
1380 | - return floatval( $this->get_prop( 'shipping', $context ) ); |
|
1381 | - } |
|
1370 | + /** |
|
1371 | + * Get the shipping amount. |
|
1372 | + * |
|
1373 | + * @since 1.0.19 |
|
1374 | + * @param string $context View or edit context. |
|
1375 | + * @return float |
|
1376 | + */ |
|
1377 | + public function get_shipping( $context = 'view' ) { |
|
1378 | + |
|
1379 | + if ( $context = 'view' ) { |
|
1380 | + return floatval( $this->get_prop( 'shipping', $context ) ); |
|
1381 | + } |
|
1382 | 1382 | |
1383 | - return $this->get_prop( 'shipping', $context ); |
|
1383 | + return $this->get_prop( 'shipping', $context ); |
|
1384 | 1384 | } |
1385 | 1385 | |
1386 | - public function has_shipping() { |
|
1387 | - return defined( 'GETPAID_SHIPPING_CALCULATOR_VERSION' ) && null !== $this->get_prop( 'shipping', 'edit' ); |
|
1386 | + public function has_shipping() { |
|
1387 | + return defined( 'GETPAID_SHIPPING_CALCULATOR_VERSION' ) && null !== $this->get_prop( 'shipping', 'edit' ); |
|
1388 | 1388 | } |
1389 | 1389 | |
1390 | 1390 | /** |
1391 | - * Get the invoice subtotal. |
|
1392 | - * |
|
1393 | - * @since 1.0.19 |
|
1394 | - * @param string $context View or edit context. |
|
1395 | - * @return float |
|
1396 | - */ |
|
1397 | - public function get_subtotal( $context = 'view' ) { |
|
1391 | + * Get the invoice subtotal. |
|
1392 | + * |
|
1393 | + * @since 1.0.19 |
|
1394 | + * @param string $context View or edit context. |
|
1395 | + * @return float |
|
1396 | + */ |
|
1397 | + public function get_subtotal( $context = 'view' ) { |
|
1398 | 1398 | $subtotal = (float) $this->get_prop( 'subtotal', $context ); |
1399 | 1399 | |
1400 | 1400 | // Backwards compatibility. |
@@ -1406,198 +1406,198 @@ discard block |
||
1406 | 1406 | } |
1407 | 1407 | |
1408 | 1408 | /** |
1409 | - * Get the invoice discount total. |
|
1410 | - * |
|
1411 | - * @since 1.0.19 |
|
1412 | - * @param string $context View or edit context. |
|
1413 | - * @return float |
|
1414 | - */ |
|
1415 | - public function get_total_discount( $context = 'view' ) { |
|
1416 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) ); |
|
1409 | + * Get the invoice discount total. |
|
1410 | + * |
|
1411 | + * @since 1.0.19 |
|
1412 | + * @param string $context View or edit context. |
|
1413 | + * @return float |
|
1414 | + */ |
|
1415 | + public function get_total_discount( $context = 'view' ) { |
|
1416 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) ); |
|
1417 | 1417 | } |
1418 | 1418 | |
1419 | 1419 | /** |
1420 | - * Get the invoice tax total. |
|
1421 | - * |
|
1422 | - * @since 1.0.19 |
|
1423 | - * @param string $context View or edit context. |
|
1424 | - * @return float |
|
1425 | - */ |
|
1426 | - public function get_total_tax( $context = 'view' ) { |
|
1427 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) ); |
|
1428 | - } |
|
1420 | + * Get the invoice tax total. |
|
1421 | + * |
|
1422 | + * @since 1.0.19 |
|
1423 | + * @param string $context View or edit context. |
|
1424 | + * @return float |
|
1425 | + */ |
|
1426 | + public function get_total_tax( $context = 'view' ) { |
|
1427 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) ); |
|
1428 | + } |
|
1429 | 1429 | |
1430 | - /** |
|
1431 | - * @deprecated |
|
1432 | - */ |
|
1433 | - public function get_final_tax( $currency = false ) { |
|
1434 | - $tax = $this->get_total_tax(); |
|
1430 | + /** |
|
1431 | + * @deprecated |
|
1432 | + */ |
|
1433 | + public function get_final_tax( $currency = false ) { |
|
1434 | + $tax = $this->get_total_tax(); |
|
1435 | 1435 | |
1436 | 1436 | if ( $currency ) { |
1437 | - return wpinv_price( $tax, $this->get_currency() ); |
|
1437 | + return wpinv_price( $tax, $this->get_currency() ); |
|
1438 | 1438 | } |
1439 | 1439 | |
1440 | 1440 | return $tax; |
1441 | 1441 | } |
1442 | 1442 | |
1443 | 1443 | /** |
1444 | - * Get the invoice fees total. |
|
1445 | - * |
|
1446 | - * @since 1.0.19 |
|
1447 | - * @param string $context View or edit context. |
|
1448 | - * @return float |
|
1449 | - */ |
|
1450 | - public function get_total_fees( $context = 'view' ) { |
|
1451 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) ); |
|
1444 | + * Get the invoice fees total. |
|
1445 | + * |
|
1446 | + * @since 1.0.19 |
|
1447 | + * @param string $context View or edit context. |
|
1448 | + * @return float |
|
1449 | + */ |
|
1450 | + public function get_total_fees( $context = 'view' ) { |
|
1451 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) ); |
|
1452 | 1452 | } |
1453 | 1453 | |
1454 | 1454 | /** |
1455 | - * Alias for self::get_total_fees(). |
|
1456 | - * |
|
1457 | - * @since 1.0.19 |
|
1458 | - * @param string $context View or edit context. |
|
1459 | - * @return float |
|
1460 | - */ |
|
1461 | - public function get_fees_total( $context = 'view' ) { |
|
1462 | - return $this->get_total_fees( $context ); |
|
1455 | + * Alias for self::get_total_fees(). |
|
1456 | + * |
|
1457 | + * @since 1.0.19 |
|
1458 | + * @param string $context View or edit context. |
|
1459 | + * @return float |
|
1460 | + */ |
|
1461 | + public function get_fees_total( $context = 'view' ) { |
|
1462 | + return $this->get_total_fees( $context ); |
|
1463 | 1463 | } |
1464 | 1464 | |
1465 | 1465 | /** |
1466 | - * Get the invoice total. |
|
1467 | - * |
|
1468 | - * @since 1.0.19 |
|
1466 | + * Get the invoice total. |
|
1467 | + * |
|
1468 | + * @since 1.0.19 |
|
1469 | 1469 | * @return float |
1470 | - */ |
|
1471 | - public function get_total( $context = 'view' ) { |
|
1472 | - $total = $this->get_prop( 'total', $context ); |
|
1473 | - |
|
1474 | - if ( $this->has_shipping() && $context == 'view' ) { |
|
1475 | - $total = $this->get_prop( 'total', $context ) + $this->get_shipping( $context ); |
|
1476 | - } |
|
1477 | - |
|
1478 | - return wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1479 | - } |
|
1480 | - |
|
1481 | - /** |
|
1482 | - * Retrieves the non-recurring total of items. |
|
1483 | - * |
|
1484 | - * @since 2.3.0 |
|
1485 | - * @return float |
|
1486 | - */ |
|
1487 | - public function get_non_recurring_total() { |
|
1488 | - |
|
1489 | - $subtotal = 0; |
|
1490 | - foreach ( $this->get_items() as $item ) { |
|
1491 | - if ( ! $item->is_recurring() ) { |
|
1492 | - $subtotal += $item->get_sub_total(); |
|
1493 | - } |
|
1494 | - } |
|
1495 | - |
|
1496 | - foreach ( $this->get_fees() as $fee ) { |
|
1497 | - if ( empty( $fee['recurring_fee'] ) ) { |
|
1498 | - $subtotal += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
1499 | - } |
|
1500 | - } |
|
1501 | - |
|
1502 | - $subtotal = wpinv_round_amount( wpinv_sanitize_amount( $subtotal ) ); |
|
1470 | + */ |
|
1471 | + public function get_total( $context = 'view' ) { |
|
1472 | + $total = $this->get_prop( 'total', $context ); |
|
1473 | + |
|
1474 | + if ( $this->has_shipping() && $context == 'view' ) { |
|
1475 | + $total = $this->get_prop( 'total', $context ) + $this->get_shipping( $context ); |
|
1476 | + } |
|
1477 | + |
|
1478 | + return wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1479 | + } |
|
1480 | + |
|
1481 | + /** |
|
1482 | + * Retrieves the non-recurring total of items. |
|
1483 | + * |
|
1484 | + * @since 2.3.0 |
|
1485 | + * @return float |
|
1486 | + */ |
|
1487 | + public function get_non_recurring_total() { |
|
1488 | + |
|
1489 | + $subtotal = 0; |
|
1490 | + foreach ( $this->get_items() as $item ) { |
|
1491 | + if ( ! $item->is_recurring() ) { |
|
1492 | + $subtotal += $item->get_sub_total(); |
|
1493 | + } |
|
1494 | + } |
|
1495 | + |
|
1496 | + foreach ( $this->get_fees() as $fee ) { |
|
1497 | + if ( empty( $fee['recurring_fee'] ) ) { |
|
1498 | + $subtotal += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
1499 | + } |
|
1500 | + } |
|
1501 | + |
|
1502 | + $subtotal = wpinv_round_amount( wpinv_sanitize_amount( $subtotal ) ); |
|
1503 | 1503 | return apply_filters( 'wpinv_get_non_recurring_invoice_total', $subtotal, $this ); |
1504 | 1504 | |
1505 | 1505 | } |
1506 | 1506 | |
1507 | - /** |
|
1508 | - * Get the invoice totals. |
|
1509 | - * |
|
1510 | - * @since 1.0.19 |
|
1507 | + /** |
|
1508 | + * Get the invoice totals. |
|
1509 | + * |
|
1510 | + * @since 1.0.19 |
|
1511 | 1511 | * @return array |
1512 | - */ |
|
1513 | - public function get_totals() { |
|
1514 | - return $this->totals; |
|
1512 | + */ |
|
1513 | + public function get_totals() { |
|
1514 | + return $this->totals; |
|
1515 | 1515 | } |
1516 | 1516 | |
1517 | 1517 | /** |
1518 | - * Get the initial invoice total. |
|
1519 | - * |
|
1520 | - * @since 1.0.19 |
|
1518 | + * Get the initial invoice total. |
|
1519 | + * |
|
1520 | + * @since 1.0.19 |
|
1521 | 1521 | * @param string $context View or edit context. |
1522 | 1522 | * @return float |
1523 | - */ |
|
1523 | + */ |
|
1524 | 1524 | public function get_initial_total() { |
1525 | 1525 | |
1526 | - if ( empty( $this->totals ) ) { |
|
1527 | - $this->recalculate_total(); |
|
1528 | - } |
|
1526 | + if ( empty( $this->totals ) ) { |
|
1527 | + $this->recalculate_total(); |
|
1528 | + } |
|
1529 | 1529 | |
1530 | - $tax = $this->totals['tax']['initial']; |
|
1531 | - $fee = $this->totals['fee']['initial']; |
|
1532 | - $discount = $this->totals['discount']['initial']; |
|
1533 | - $subtotal = $this->totals['subtotal']['initial']; |
|
1534 | - $total = $tax + $fee - $discount + $subtotal; |
|
1530 | + $tax = $this->totals['tax']['initial']; |
|
1531 | + $fee = $this->totals['fee']['initial']; |
|
1532 | + $discount = $this->totals['discount']['initial']; |
|
1533 | + $subtotal = $this->totals['subtotal']['initial']; |
|
1534 | + $total = $tax + $fee - $discount + $subtotal; |
|
1535 | 1535 | |
1536 | - if ( 0 > $total ) { |
|
1537 | - $total = 0; |
|
1538 | - } |
|
1536 | + if ( 0 > $total ) { |
|
1537 | + $total = 0; |
|
1538 | + } |
|
1539 | 1539 | |
1540 | - $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1540 | + $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1541 | 1541 | return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this ); |
1542 | - } |
|
1542 | + } |
|
1543 | 1543 | |
1544 | - /** |
|
1545 | - * Get the recurring invoice total. |
|
1546 | - * |
|
1547 | - * @since 1.0.19 |
|
1544 | + /** |
|
1545 | + * Get the recurring invoice total. |
|
1546 | + * |
|
1547 | + * @since 1.0.19 |
|
1548 | 1548 | * @param string $context View or edit context. |
1549 | 1549 | * @return float |
1550 | - */ |
|
1550 | + */ |
|
1551 | 1551 | public function get_recurring_total() { |
1552 | 1552 | |
1553 | - if ( empty( $this->totals ) ) { |
|
1554 | - $this->recalculate_total(); |
|
1555 | - } |
|
1553 | + if ( empty( $this->totals ) ) { |
|
1554 | + $this->recalculate_total(); |
|
1555 | + } |
|
1556 | 1556 | |
1557 | - $tax = $this->totals['tax']['recurring']; |
|
1558 | - $fee = $this->totals['fee']['recurring']; |
|
1559 | - $discount = $this->totals['discount']['recurring']; |
|
1560 | - $subtotal = $this->totals['subtotal']['recurring']; |
|
1561 | - $total = $tax + $fee - $discount + $subtotal; |
|
1557 | + $tax = $this->totals['tax']['recurring']; |
|
1558 | + $fee = $this->totals['fee']['recurring']; |
|
1559 | + $discount = $this->totals['discount']['recurring']; |
|
1560 | + $subtotal = $this->totals['subtotal']['recurring']; |
|
1561 | + $total = $tax + $fee - $discount + $subtotal; |
|
1562 | 1562 | |
1563 | - if ( 0 > $total ) { |
|
1564 | - $total = 0; |
|
1565 | - } |
|
1563 | + if ( 0 > $total ) { |
|
1564 | + $total = 0; |
|
1565 | + } |
|
1566 | 1566 | |
1567 | - $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1567 | + $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
1568 | 1568 | return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this ); |
1569 | - } |
|
1569 | + } |
|
1570 | 1570 | |
1571 | - /** |
|
1572 | - * Returns recurring payment details. |
|
1573 | - * |
|
1574 | - * @since 1.0.19 |
|
1571 | + /** |
|
1572 | + * Returns recurring payment details. |
|
1573 | + * |
|
1574 | + * @since 1.0.19 |
|
1575 | 1575 | * @param string $field Optionally provide a field to return. |
1576 | - * @param string $currency Whether to include the currency. |
|
1576 | + * @param string $currency Whether to include the currency. |
|
1577 | 1577 | * @return float|string |
1578 | - */ |
|
1578 | + */ |
|
1579 | 1579 | public function get_recurring_details( $field = '', $currency = false ) { |
1580 | 1580 | |
1581 | - // Maybe recalculate totals. |
|
1582 | - if ( empty( $this->totals ) ) { |
|
1583 | - $this->recalculate_total(); |
|
1584 | - } |
|
1581 | + // Maybe recalculate totals. |
|
1582 | + if ( empty( $this->totals ) ) { |
|
1583 | + $this->recalculate_total(); |
|
1584 | + } |
|
1585 | 1585 | |
1586 | - // Prepare recurring totals. |
|
1586 | + // Prepare recurring totals. |
|
1587 | 1587 | $data = apply_filters( |
1588 | - 'wpinv_get_invoice_recurring_details', |
|
1589 | - array( |
|
1590 | - 'cart_details' => $this->get_cart_details(), |
|
1591 | - 'subtotal' => $this->totals['subtotal']['recurring'], |
|
1592 | - 'discount' => $this->totals['discount']['recurring'], |
|
1593 | - 'tax' => $this->totals['tax']['recurring'], |
|
1594 | - 'fee' => $this->totals['fee']['recurring'], |
|
1595 | - 'total' => $this->get_recurring_total(), |
|
1596 | - ), |
|
1597 | - $this, |
|
1598 | - $field, |
|
1599 | - $currency |
|
1600 | - ); |
|
1588 | + 'wpinv_get_invoice_recurring_details', |
|
1589 | + array( |
|
1590 | + 'cart_details' => $this->get_cart_details(), |
|
1591 | + 'subtotal' => $this->totals['subtotal']['recurring'], |
|
1592 | + 'discount' => $this->totals['discount']['recurring'], |
|
1593 | + 'tax' => $this->totals['tax']['recurring'], |
|
1594 | + 'fee' => $this->totals['fee']['recurring'], |
|
1595 | + 'total' => $this->get_recurring_total(), |
|
1596 | + ), |
|
1597 | + $this, |
|
1598 | + $field, |
|
1599 | + $currency |
|
1600 | + ); |
|
1601 | 1601 | |
1602 | 1602 | if ( isset( $data[$field] ) ) { |
1603 | 1603 | return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
@@ -1607,166 +1607,166 @@ discard block |
||
1607 | 1607 | } |
1608 | 1608 | |
1609 | 1609 | /** |
1610 | - * Get the invoice fees. |
|
1611 | - * |
|
1612 | - * @since 1.0.19 |
|
1613 | - * @param string $context View or edit context. |
|
1614 | - * @return array |
|
1615 | - */ |
|
1616 | - public function get_fees( $context = 'view' ) { |
|
1617 | - return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
1610 | + * Get the invoice fees. |
|
1611 | + * |
|
1612 | + * @since 1.0.19 |
|
1613 | + * @param string $context View or edit context. |
|
1614 | + * @return array |
|
1615 | + */ |
|
1616 | + public function get_fees( $context = 'view' ) { |
|
1617 | + return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
1618 | 1618 | } |
1619 | 1619 | |
1620 | 1620 | /** |
1621 | - * Get the invoice discounts. |
|
1622 | - * |
|
1623 | - * @since 1.0.19 |
|
1624 | - * @param string $context View or edit context. |
|
1625 | - * @return array |
|
1626 | - */ |
|
1627 | - public function get_discounts( $context = 'view' ) { |
|
1628 | - return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
1621 | + * Get the invoice discounts. |
|
1622 | + * |
|
1623 | + * @since 1.0.19 |
|
1624 | + * @param string $context View or edit context. |
|
1625 | + * @return array |
|
1626 | + */ |
|
1627 | + public function get_discounts( $context = 'view' ) { |
|
1628 | + return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
1629 | 1629 | } |
1630 | 1630 | |
1631 | 1631 | /** |
1632 | - * Get the invoice taxes. |
|
1633 | - * |
|
1634 | - * @since 1.0.19 |
|
1635 | - * @param string $context View or edit context. |
|
1636 | - * @return array |
|
1637 | - */ |
|
1638 | - public function get_taxes( $context = 'view' ) { |
|
1639 | - return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
1632 | + * Get the invoice taxes. |
|
1633 | + * |
|
1634 | + * @since 1.0.19 |
|
1635 | + * @param string $context View or edit context. |
|
1636 | + * @return array |
|
1637 | + */ |
|
1638 | + public function get_taxes( $context = 'view' ) { |
|
1639 | + return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
1640 | 1640 | } |
1641 | 1641 | |
1642 | 1642 | /** |
1643 | - * Get the invoice items. |
|
1644 | - * |
|
1645 | - * @since 1.0.19 |
|
1646 | - * @param string $context View or edit context. |
|
1647 | - * @return GetPaid_Form_Item[] |
|
1648 | - */ |
|
1649 | - public function get_items( $context = 'view' ) { |
|
1643 | + * Get the invoice items. |
|
1644 | + * |
|
1645 | + * @since 1.0.19 |
|
1646 | + * @param string $context View or edit context. |
|
1647 | + * @return GetPaid_Form_Item[] |
|
1648 | + */ |
|
1649 | + public function get_items( $context = 'view' ) { |
|
1650 | 1650 | return $this->get_prop( 'items', $context ); |
1651 | - } |
|
1651 | + } |
|
1652 | 1652 | |
1653 | - /** |
|
1654 | - * Get the invoice item ids. |
|
1655 | - * |
|
1656 | - * @since 1.0.19 |
|
1657 | - * @return string |
|
1658 | - */ |
|
1659 | - public function get_item_ids() { |
|
1660 | - return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) ); |
|
1653 | + /** |
|
1654 | + * Get the invoice item ids. |
|
1655 | + * |
|
1656 | + * @since 1.0.19 |
|
1657 | + * @return string |
|
1658 | + */ |
|
1659 | + public function get_item_ids() { |
|
1660 | + return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) ); |
|
1661 | 1661 | } |
1662 | 1662 | |
1663 | 1663 | /** |
1664 | - * Get the invoice's payment form. |
|
1665 | - * |
|
1666 | - * @since 1.0.19 |
|
1667 | - * @param string $context View or edit context. |
|
1668 | - * @return int |
|
1669 | - */ |
|
1670 | - public function get_payment_form( $context = 'view' ) { |
|
1671 | - return intval( $this->get_prop( 'payment_form', $context ) ); |
|
1664 | + * Get the invoice's payment form. |
|
1665 | + * |
|
1666 | + * @since 1.0.19 |
|
1667 | + * @param string $context View or edit context. |
|
1668 | + * @return int |
|
1669 | + */ |
|
1670 | + public function get_payment_form( $context = 'view' ) { |
|
1671 | + return intval( $this->get_prop( 'payment_form', $context ) ); |
|
1672 | 1672 | } |
1673 | 1673 | |
1674 | 1674 | /** |
1675 | - * Get the invoice's submission id. |
|
1676 | - * |
|
1677 | - * @since 1.0.19 |
|
1678 | - * @param string $context View or edit context. |
|
1679 | - * @return string |
|
1680 | - */ |
|
1681 | - public function get_submission_id( $context = 'view' ) { |
|
1682 | - return $this->get_prop( 'submission_id', $context ); |
|
1675 | + * Get the invoice's submission id. |
|
1676 | + * |
|
1677 | + * @since 1.0.19 |
|
1678 | + * @param string $context View or edit context. |
|
1679 | + * @return string |
|
1680 | + */ |
|
1681 | + public function get_submission_id( $context = 'view' ) { |
|
1682 | + return $this->get_prop( 'submission_id', $context ); |
|
1683 | 1683 | } |
1684 | 1684 | |
1685 | 1685 | /** |
1686 | - * Get the invoice's discount code. |
|
1687 | - * |
|
1688 | - * @since 1.0.19 |
|
1689 | - * @param string $context View or edit context. |
|
1690 | - * @return string |
|
1691 | - */ |
|
1692 | - public function get_discount_code( $context = 'view' ) { |
|
1693 | - return $this->get_prop( 'discount_code', $context ); |
|
1686 | + * Get the invoice's discount code. |
|
1687 | + * |
|
1688 | + * @since 1.0.19 |
|
1689 | + * @param string $context View or edit context. |
|
1690 | + * @return string |
|
1691 | + */ |
|
1692 | + public function get_discount_code( $context = 'view' ) { |
|
1693 | + return $this->get_prop( 'discount_code', $context ); |
|
1694 | 1694 | } |
1695 | 1695 | |
1696 | 1696 | /** |
1697 | - * Get the invoice's gateway. |
|
1698 | - * |
|
1699 | - * @since 1.0.19 |
|
1700 | - * @param string $context View or edit context. |
|
1701 | - * @return string |
|
1702 | - */ |
|
1703 | - public function get_gateway( $context = 'view' ) { |
|
1704 | - return $this->get_prop( 'gateway', $context ); |
|
1697 | + * Get the invoice's gateway. |
|
1698 | + * |
|
1699 | + * @since 1.0.19 |
|
1700 | + * @param string $context View or edit context. |
|
1701 | + * @return string |
|
1702 | + */ |
|
1703 | + public function get_gateway( $context = 'view' ) { |
|
1704 | + return $this->get_prop( 'gateway', $context ); |
|
1705 | 1705 | } |
1706 | 1706 | |
1707 | 1707 | /** |
1708 | - * Get the invoice's gateway display title. |
|
1709 | - * |
|
1710 | - * @since 1.0.19 |
|
1711 | - * @return string |
|
1712 | - */ |
|
1708 | + * Get the invoice's gateway display title. |
|
1709 | + * |
|
1710 | + * @since 1.0.19 |
|
1711 | + * @return string |
|
1712 | + */ |
|
1713 | 1713 | public function get_gateway_title() { |
1714 | 1714 | $title = wpinv_get_gateway_checkout_label( $this->get_gateway() ); |
1715 | 1715 | return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this ); |
1716 | 1716 | } |
1717 | 1717 | |
1718 | 1718 | /** |
1719 | - * Get the invoice's transaction id. |
|
1720 | - * |
|
1721 | - * @since 1.0.19 |
|
1722 | - * @param string $context View or edit context. |
|
1723 | - * @return string |
|
1724 | - */ |
|
1725 | - public function get_transaction_id( $context = 'view' ) { |
|
1726 | - return $this->get_prop( 'transaction_id', $context ); |
|
1719 | + * Get the invoice's transaction id. |
|
1720 | + * |
|
1721 | + * @since 1.0.19 |
|
1722 | + * @param string $context View or edit context. |
|
1723 | + * @return string |
|
1724 | + */ |
|
1725 | + public function get_transaction_id( $context = 'view' ) { |
|
1726 | + return $this->get_prop( 'transaction_id', $context ); |
|
1727 | 1727 | } |
1728 | 1728 | |
1729 | 1729 | /** |
1730 | - * Get the invoice's currency. |
|
1731 | - * |
|
1732 | - * @since 1.0.19 |
|
1733 | - * @param string $context View or edit context. |
|
1734 | - * @return string |
|
1735 | - */ |
|
1736 | - public function get_currency( $context = 'view' ) { |
|
1730 | + * Get the invoice's currency. |
|
1731 | + * |
|
1732 | + * @since 1.0.19 |
|
1733 | + * @param string $context View or edit context. |
|
1734 | + * @return string |
|
1735 | + */ |
|
1736 | + public function get_currency( $context = 'view' ) { |
|
1737 | 1737 | $currency = $this->get_prop( 'currency', $context ); |
1738 | 1738 | return empty( $currency ) ? wpinv_get_currency() : $currency; |
1739 | 1739 | } |
1740 | 1740 | |
1741 | 1741 | /** |
1742 | - * Checks if we are charging taxes for this invoice. |
|
1743 | - * |
|
1744 | - * @since 1.0.19 |
|
1745 | - * @param string $context View or edit context. |
|
1746 | - * @return bool |
|
1747 | - */ |
|
1748 | - public function get_disable_taxes( $context = 'view' ) { |
|
1742 | + * Checks if we are charging taxes for this invoice. |
|
1743 | + * |
|
1744 | + * @since 1.0.19 |
|
1745 | + * @param string $context View or edit context. |
|
1746 | + * @return bool |
|
1747 | + */ |
|
1748 | + public function get_disable_taxes( $context = 'view' ) { |
|
1749 | 1749 | return (bool) $this->get_prop( 'disable_taxes', $context ); |
1750 | 1750 | } |
1751 | 1751 | |
1752 | 1752 | /** |
1753 | - * Retrieves the subscription id for an invoice. |
|
1754 | - * |
|
1755 | - * @since 1.0.19 |
|
1756 | - * @param string $context View or edit context. |
|
1757 | - * @return int |
|
1758 | - */ |
|
1753 | + * Retrieves the subscription id for an invoice. |
|
1754 | + * |
|
1755 | + * @since 1.0.19 |
|
1756 | + * @param string $context View or edit context. |
|
1757 | + * @return int |
|
1758 | + */ |
|
1759 | 1759 | public function get_subscription_id( $context = 'view' ) { |
1760 | - return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
1761 | - } |
|
1762 | - |
|
1763 | - /** |
|
1764 | - * Retrieves the remote subscription id for an invoice. |
|
1765 | - * |
|
1766 | - * @since 1.0.19 |
|
1767 | - * @param string $context View or edit context. |
|
1768 | - * @return int |
|
1769 | - */ |
|
1760 | + return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
1761 | + } |
|
1762 | + |
|
1763 | + /** |
|
1764 | + * Retrieves the remote subscription id for an invoice. |
|
1765 | + * |
|
1766 | + * @since 1.0.19 |
|
1767 | + * @param string $context View or edit context. |
|
1768 | + * @return int |
|
1769 | + */ |
|
1770 | 1770 | public function get_remote_subscription_id( $context = 'view' ) { |
1771 | 1771 | $subscription_id = $this->get_prop( 'remote_subscription_id', $context ); |
1772 | 1772 | |
@@ -1779,12 +1779,12 @@ discard block |
||
1779 | 1779 | } |
1780 | 1780 | |
1781 | 1781 | /** |
1782 | - * Retrieves the payment meta for an invoice. |
|
1783 | - * |
|
1784 | - * @since 1.0.19 |
|
1785 | - * @param string $context View or edit context. |
|
1786 | - * @return array |
|
1787 | - */ |
|
1782 | + * Retrieves the payment meta for an invoice. |
|
1783 | + * |
|
1784 | + * @since 1.0.19 |
|
1785 | + * @param string $context View or edit context. |
|
1786 | + * @return array |
|
1787 | + */ |
|
1788 | 1788 | public function get_payment_meta( $context = 'view' ) { |
1789 | 1789 | |
1790 | 1790 | return array( |
@@ -1804,31 +1804,31 @@ discard block |
||
1804 | 1804 | } |
1805 | 1805 | |
1806 | 1806 | /** |
1807 | - * Retrieves the cart details for an invoice. |
|
1808 | - * |
|
1809 | - * @since 1.0.19 |
|
1810 | - * @return array |
|
1811 | - */ |
|
1807 | + * Retrieves the cart details for an invoice. |
|
1808 | + * |
|
1809 | + * @since 1.0.19 |
|
1810 | + * @return array |
|
1811 | + */ |
|
1812 | 1812 | public function get_cart_details() { |
1813 | 1813 | $items = $this->get_items(); |
1814 | 1814 | $cart_details = array(); |
1815 | 1815 | |
1816 | 1816 | foreach ( $items as $item ) { |
1817 | - $item->invoice_id = $this->get_id(); |
|
1817 | + $item->invoice_id = $this->get_id(); |
|
1818 | 1818 | $cart_details[] = $item->prepare_data_for_saving(); |
1819 | 1819 | } |
1820 | 1820 | |
1821 | 1821 | return $cart_details; |
1822 | - } |
|
1822 | + } |
|
1823 | 1823 | |
1824 | - /** |
|
1825 | - * Retrieves the recurring item. |
|
1826 | - * |
|
1827 | - * @return null|GetPaid_Form_Item|int |
|
1828 | - */ |
|
1829 | - public function get_recurring( $object = false ) { |
|
1824 | + /** |
|
1825 | + * Retrieves the recurring item. |
|
1826 | + * |
|
1827 | + * @return null|GetPaid_Form_Item|int |
|
1828 | + */ |
|
1829 | + public function get_recurring( $object = false ) { |
|
1830 | 1830 | |
1831 | - // Are we returning an object? |
|
1831 | + // Are we returning an object? |
|
1832 | 1832 | if ( $object ) { |
1833 | 1833 | return $this->get_item( $this->recurring_item ); |
1834 | 1834 | } |
@@ -1836,114 +1836,114 @@ discard block |
||
1836 | 1836 | return $this->recurring_item; |
1837 | 1837 | } |
1838 | 1838 | |
1839 | - /** |
|
1840 | - * Retrieves the subscription name. |
|
1841 | - * |
|
1842 | - * @since 1.0.19 |
|
1843 | - * @return string |
|
1844 | - */ |
|
1845 | - public function get_subscription_name() { |
|
1839 | + /** |
|
1840 | + * Retrieves the subscription name. |
|
1841 | + * |
|
1842 | + * @since 1.0.19 |
|
1843 | + * @return string |
|
1844 | + */ |
|
1845 | + public function get_subscription_name() { |
|
1846 | 1846 | |
1847 | - // Retrieve the recurring name |
|
1847 | + // Retrieve the recurring name |
|
1848 | 1848 | $item = $this->get_recurring( true ); |
1849 | 1849 | |
1850 | - // Abort if it does not exist. |
|
1850 | + // Abort if it does not exist. |
|
1851 | 1851 | if ( empty( $item ) ) { |
1852 | 1852 | return ''; |
1853 | 1853 | } |
1854 | 1854 | |
1855 | - // Return the item name. |
|
1855 | + // Return the item name. |
|
1856 | 1856 | return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this ); |
1857 | - } |
|
1858 | - |
|
1859 | - /** |
|
1860 | - * Retrieves the view url. |
|
1861 | - * |
|
1862 | - * @since 1.0.19 |
|
1863 | - * @return string |
|
1864 | - */ |
|
1865 | - public function get_view_url() { |
|
1857 | + } |
|
1858 | + |
|
1859 | + /** |
|
1860 | + * Retrieves the view url. |
|
1861 | + * |
|
1862 | + * @since 1.0.19 |
|
1863 | + * @return string |
|
1864 | + */ |
|
1865 | + public function get_view_url() { |
|
1866 | 1866 | $invoice_url = get_permalink( $this->get_id() ); |
1867 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
1867 | + $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
1868 | 1868 | return apply_filters( 'wpinv_get_view_url', $invoice_url, $this ); |
1869 | - } |
|
1869 | + } |
|
1870 | 1870 | |
1871 | - /** |
|
1872 | - * Retrieves the payment url. |
|
1873 | - * |
|
1874 | - * @since 1.0.19 |
|
1875 | - * @return string |
|
1876 | - */ |
|
1877 | - public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
1871 | + /** |
|
1872 | + * Retrieves the payment url. |
|
1873 | + * |
|
1874 | + * @since 1.0.19 |
|
1875 | + * @return string |
|
1876 | + */ |
|
1877 | + public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
1878 | 1878 | |
1879 | - // Retrieve the checkout url. |
|
1879 | + // Retrieve the checkout url. |
|
1880 | 1880 | $pay_url = wpinv_get_checkout_uri(); |
1881 | 1881 | |
1882 | - // Maybe force ssl. |
|
1882 | + // Maybe force ssl. |
|
1883 | 1883 | if ( is_ssl() ) { |
1884 | 1884 | $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
1885 | 1885 | } |
1886 | 1886 | |
1887 | - // Add the invoice key. |
|
1888 | - $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
1887 | + // Add the invoice key. |
|
1888 | + $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
1889 | 1889 | |
1890 | - // (Maybe?) add a secret |
|
1890 | + // (Maybe?) add a secret |
|
1891 | 1891 | if ( $secret ) { |
1892 | 1892 | $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url ); |
1893 | 1893 | } |
1894 | 1894 | |
1895 | 1895 | return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret ); |
1896 | - } |
|
1896 | + } |
|
1897 | 1897 | |
1898 | - /** |
|
1899 | - * Retrieves the receipt url. |
|
1900 | - * |
|
1901 | - * @since 1.0.19 |
|
1902 | - * @return string |
|
1903 | - */ |
|
1904 | - public function get_receipt_url() { |
|
1905 | - |
|
1906 | - // Retrieve the checkout url. |
|
1898 | + /** |
|
1899 | + * Retrieves the receipt url. |
|
1900 | + * |
|
1901 | + * @since 1.0.19 |
|
1902 | + * @return string |
|
1903 | + */ |
|
1904 | + public function get_receipt_url() { |
|
1905 | + |
|
1906 | + // Retrieve the checkout url. |
|
1907 | 1907 | $receipt_url = wpinv_get_success_page_uri(); |
1908 | 1908 | |
1909 | - // Maybe force ssl. |
|
1909 | + // Maybe force ssl. |
|
1910 | 1910 | if ( is_ssl() ) { |
1911 | 1911 | $receipt_url = str_replace( 'http:', 'https:', $receipt_url ); |
1912 | 1912 | } |
1913 | 1913 | |
1914 | - // Add the invoice key. |
|
1915 | - $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
1914 | + // Add the invoice key. |
|
1915 | + $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
1916 | 1916 | |
1917 | 1917 | return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this ); |
1918 | - } |
|
1918 | + } |
|
1919 | 1919 | |
1920 | - /** |
|
1921 | - * Retrieves the default status. |
|
1922 | - * |
|
1923 | - * @since 1.0.19 |
|
1924 | - * @return string |
|
1925 | - */ |
|
1926 | - public function get_default_status() { |
|
1927 | - |
|
1928 | - $type = $this->get_type(); |
|
1929 | - $status = "wpi-$type-pending"; |
|
1930 | - return str_replace( '-invoice', '', $status ); |
|
1931 | - |
|
1932 | - } |
|
1933 | - |
|
1934 | - /** |
|
1935 | - * Magic method for accessing invoice properties. |
|
1936 | - * |
|
1937 | - * @since 1.0.15 |
|
1938 | - * @access public |
|
1939 | - * |
|
1940 | - * @param string $key Discount data to retrieve |
|
1941 | - * @param string $context View or edit context. |
|
1942 | - * @return mixed Value of the given invoice property (if set). |
|
1943 | - */ |
|
1944 | - public function get( $key, $context = 'view' ) { |
|
1920 | + /** |
|
1921 | + * Retrieves the default status. |
|
1922 | + * |
|
1923 | + * @since 1.0.19 |
|
1924 | + * @return string |
|
1925 | + */ |
|
1926 | + public function get_default_status() { |
|
1927 | + |
|
1928 | + $type = $this->get_type(); |
|
1929 | + $status = "wpi-$type-pending"; |
|
1930 | + return str_replace( '-invoice', '', $status ); |
|
1931 | + |
|
1932 | + } |
|
1933 | + |
|
1934 | + /** |
|
1935 | + * Magic method for accessing invoice properties. |
|
1936 | + * |
|
1937 | + * @since 1.0.15 |
|
1938 | + * @access public |
|
1939 | + * |
|
1940 | + * @param string $key Discount data to retrieve |
|
1941 | + * @param string $context View or edit context. |
|
1942 | + * @return mixed Value of the given invoice property (if set). |
|
1943 | + */ |
|
1944 | + public function get( $key, $context = 'view' ) { |
|
1945 | 1945 | return $this->get_prop( $key, $context ); |
1946 | - } |
|
1946 | + } |
|
1947 | 1947 | |
1948 | 1948 | /* |
1949 | 1949 | |-------------------------------------------------------------------------- |
@@ -1956,130 +1956,130 @@ discard block |
||
1956 | 1956 | */ |
1957 | 1957 | |
1958 | 1958 | /** |
1959 | - * Magic method for setting invoice properties. |
|
1960 | - * |
|
1961 | - * @since 1.0.19 |
|
1962 | - * @access public |
|
1963 | - * |
|
1964 | - * @param string $key Discount data to retrieve |
|
1965 | - * @param mixed $value new value. |
|
1966 | - * @return mixed Value of the given invoice property (if set). |
|
1967 | - */ |
|
1968 | - public function set( $key, $value ) { |
|
1959 | + * Magic method for setting invoice properties. |
|
1960 | + * |
|
1961 | + * @since 1.0.19 |
|
1962 | + * @access public |
|
1963 | + * |
|
1964 | + * @param string $key Discount data to retrieve |
|
1965 | + * @param mixed $value new value. |
|
1966 | + * @return mixed Value of the given invoice property (if set). |
|
1967 | + */ |
|
1968 | + public function set( $key, $value ) { |
|
1969 | 1969 | |
1970 | 1970 | $setter = "set_$key"; |
1971 | 1971 | if ( is_callable( array( $this, $setter ) ) ) { |
1972 | 1972 | $this->{$setter}( $value ); |
1973 | 1973 | } |
1974 | 1974 | |
1975 | - } |
|
1975 | + } |
|
1976 | 1976 | |
1977 | - /** |
|
1978 | - * Sets item status. |
|
1979 | - * |
|
1980 | - * @since 1.0.19 |
|
1981 | - * @param string $new_status New status. |
|
1982 | - * @param string $note Optional note to add. |
|
1983 | - * @param bool $manual_update Is this a manual status change?. |
|
1984 | - * @return array details of change. |
|
1985 | - */ |
|
1986 | - public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
1987 | - $old_status = $this->get_status(); |
|
1977 | + /** |
|
1978 | + * Sets item status. |
|
1979 | + * |
|
1980 | + * @since 1.0.19 |
|
1981 | + * @param string $new_status New status. |
|
1982 | + * @param string $note Optional note to add. |
|
1983 | + * @param bool $manual_update Is this a manual status change?. |
|
1984 | + * @return array details of change. |
|
1985 | + */ |
|
1986 | + public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
1987 | + $old_status = $this->get_status(); |
|
1988 | 1988 | |
1989 | - $statuses = $this->get_all_statuses(); |
|
1989 | + $statuses = $this->get_all_statuses(); |
|
1990 | 1990 | |
1991 | - if ( isset( $statuses[ 'draft' ] ) ) { |
|
1992 | - unset( $statuses[ 'draft' ] ); |
|
1993 | - } |
|
1991 | + if ( isset( $statuses[ 'draft' ] ) ) { |
|
1992 | + unset( $statuses[ 'draft' ] ); |
|
1993 | + } |
|
1994 | 1994 | |
1995 | - $this->set_prop( 'status', $new_status ); |
|
1995 | + $this->set_prop( 'status', $new_status ); |
|
1996 | 1996 | |
1997 | - // If setting the status, ensure it's set to a valid status. |
|
1998 | - if ( true === $this->object_read ) { |
|
1997 | + // If setting the status, ensure it's set to a valid status. |
|
1998 | + if ( true === $this->object_read ) { |
|
1999 | 1999 | |
2000 | - // Only allow valid new status. |
|
2001 | - if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
2002 | - $new_status = $this->get_default_status(); |
|
2003 | - } |
|
2000 | + // Only allow valid new status. |
|
2001 | + if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
2002 | + $new_status = $this->get_default_status(); |
|
2003 | + } |
|
2004 | 2004 | |
2005 | - // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
2006 | - if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
2007 | - $old_status = $this->get_default_status(); |
|
2008 | - } |
|
2005 | + // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
2006 | + if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
2007 | + $old_status = $this->get_default_status(); |
|
2008 | + } |
|
2009 | 2009 | |
2010 | - // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
2011 | - if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
2012 | - $old_status = 'wpi-pending'; |
|
2013 | - } |
|
2010 | + // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
2011 | + if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
2012 | + $old_status = 'wpi-pending'; |
|
2013 | + } |
|
2014 | 2014 | |
2015 | - if ( $old_status !== $new_status ) { |
|
2016 | - $this->status_transition = array( |
|
2017 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
2018 | - 'to' => $new_status, |
|
2019 | - 'note' => $note, |
|
2020 | - 'manual' => (bool) $manual_update, |
|
2021 | - ); |
|
2015 | + if ( $old_status !== $new_status ) { |
|
2016 | + $this->status_transition = array( |
|
2017 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
2018 | + 'to' => $new_status, |
|
2019 | + 'note' => $note, |
|
2020 | + 'manual' => (bool) $manual_update, |
|
2021 | + ); |
|
2022 | 2022 | |
2023 | - if ( $manual_update ) { |
|
2024 | - do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status ); |
|
2025 | - } |
|
2023 | + if ( $manual_update ) { |
|
2024 | + do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status ); |
|
2025 | + } |
|
2026 | 2026 | |
2027 | - $this->maybe_set_date_paid(); |
|
2027 | + $this->maybe_set_date_paid(); |
|
2028 | 2028 | |
2029 | - } |
|
2029 | + } |
|
2030 | 2030 | |
2031 | - } |
|
2031 | + } |
|
2032 | 2032 | |
2033 | - return array( |
|
2034 | - 'from' => $old_status, |
|
2035 | - 'to' => $new_status, |
|
2036 | - ); |
|
2037 | - } |
|
2033 | + return array( |
|
2034 | + 'from' => $old_status, |
|
2035 | + 'to' => $new_status, |
|
2036 | + ); |
|
2037 | + } |
|
2038 | 2038 | |
2039 | - /** |
|
2040 | - * Maybe set date paid. |
|
2041 | - * |
|
2042 | - * Sets the date paid variable when transitioning to the payment complete |
|
2043 | - * order status. |
|
2044 | - * |
|
2045 | - * @since 1.0.19 |
|
2046 | - */ |
|
2047 | - public function maybe_set_date_paid() { |
|
2039 | + /** |
|
2040 | + * Maybe set date paid. |
|
2041 | + * |
|
2042 | + * Sets the date paid variable when transitioning to the payment complete |
|
2043 | + * order status. |
|
2044 | + * |
|
2045 | + * @since 1.0.19 |
|
2046 | + */ |
|
2047 | + public function maybe_set_date_paid() { |
|
2048 | 2048 | |
2049 | - if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
2050 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
2051 | - } |
|
2052 | - } |
|
2049 | + if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
2050 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
2051 | + } |
|
2052 | + } |
|
2053 | 2053 | |
2054 | 2054 | /** |
2055 | - * Set parent invoice ID. |
|
2056 | - * |
|
2057 | - * @since 1.0.19 |
|
2058 | - */ |
|
2059 | - public function set_parent_id( $value ) { |
|
2060 | - if ( $value && ( $value === $this->get_id() ) ) { |
|
2061 | - return; |
|
2062 | - } |
|
2063 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
2055 | + * Set parent invoice ID. |
|
2056 | + * |
|
2057 | + * @since 1.0.19 |
|
2058 | + */ |
|
2059 | + public function set_parent_id( $value ) { |
|
2060 | + if ( $value && ( $value === $this->get_id() ) ) { |
|
2061 | + return; |
|
2062 | + } |
|
2063 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
2064 | 2064 | } |
2065 | 2065 | |
2066 | 2066 | /** |
2067 | - * Set plugin version when the invoice was created. |
|
2068 | - * |
|
2069 | - * @since 1.0.19 |
|
2070 | - */ |
|
2071 | - public function set_version( $value ) { |
|
2072 | - $this->set_prop( 'version', $value ); |
|
2067 | + * Set plugin version when the invoice was created. |
|
2068 | + * |
|
2069 | + * @since 1.0.19 |
|
2070 | + */ |
|
2071 | + public function set_version( $value ) { |
|
2072 | + $this->set_prop( 'version', $value ); |
|
2073 | 2073 | } |
2074 | - |
|
2075 | - /** |
|
2076 | - * Set date when the invoice was created. |
|
2077 | - * |
|
2078 | - * @since 1.0.19 |
|
2079 | - * @param string $value Value to set. |
|
2074 | + |
|
2075 | + /** |
|
2076 | + * Set date when the invoice was created. |
|
2077 | + * |
|
2078 | + * @since 1.0.19 |
|
2079 | + * @param string $value Value to set. |
|
2080 | 2080 | * @return bool Whether or not the date was set. |
2081 | - */ |
|
2082 | - public function set_date_created( $value ) { |
|
2081 | + */ |
|
2082 | + public function set_date_created( $value ) { |
|
2083 | 2083 | $date = strtotime( $value ); |
2084 | 2084 | |
2085 | 2085 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2087,19 +2087,19 @@ discard block |
||
2087 | 2087 | return true; |
2088 | 2088 | } |
2089 | 2089 | |
2090 | - $this->set_prop( 'date_created', '' ); |
|
2091 | - return false; |
|
2090 | + $this->set_prop( 'date_created', '' ); |
|
2091 | + return false; |
|
2092 | 2092 | |
2093 | 2093 | } |
2094 | 2094 | |
2095 | 2095 | /** |
2096 | - * Set date invoice due date. |
|
2097 | - * |
|
2098 | - * @since 1.0.19 |
|
2099 | - * @param string $value Value to set. |
|
2096 | + * Set date invoice due date. |
|
2097 | + * |
|
2098 | + * @since 1.0.19 |
|
2099 | + * @param string $value Value to set. |
|
2100 | 2100 | * @return bool Whether or not the date was set. |
2101 | - */ |
|
2102 | - public function set_due_date( $value ) { |
|
2101 | + */ |
|
2102 | + public function set_due_date( $value ) { |
|
2103 | 2103 | $date = strtotime( $value ); |
2104 | 2104 | |
2105 | 2105 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2107,29 +2107,29 @@ discard block |
||
2107 | 2107 | return true; |
2108 | 2108 | } |
2109 | 2109 | |
2110 | - $this->set_prop( 'due_date', '' ); |
|
2110 | + $this->set_prop( 'due_date', '' ); |
|
2111 | 2111 | return false; |
2112 | 2112 | |
2113 | 2113 | } |
2114 | 2114 | |
2115 | 2115 | /** |
2116 | - * Alias of self::set_due_date(). |
|
2117 | - * |
|
2118 | - * @since 1.0.19 |
|
2119 | - * @param string $value New name. |
|
2120 | - */ |
|
2121 | - public function set_date_due( $value ) { |
|
2122 | - $this->set_due_date( $value ); |
|
2116 | + * Alias of self::set_due_date(). |
|
2117 | + * |
|
2118 | + * @since 1.0.19 |
|
2119 | + * @param string $value New name. |
|
2120 | + */ |
|
2121 | + public function set_date_due( $value ) { |
|
2122 | + $this->set_due_date( $value ); |
|
2123 | 2123 | } |
2124 | 2124 | |
2125 | 2125 | /** |
2126 | - * Set date invoice was completed. |
|
2127 | - * |
|
2128 | - * @since 1.0.19 |
|
2129 | - * @param string $value Value to set. |
|
2126 | + * Set date invoice was completed. |
|
2127 | + * |
|
2128 | + * @since 1.0.19 |
|
2129 | + * @param string $value Value to set. |
|
2130 | 2130 | * @return bool Whether or not the date was set. |
2131 | - */ |
|
2132 | - public function set_completed_date( $value ) { |
|
2131 | + */ |
|
2132 | + public function set_completed_date( $value ) { |
|
2133 | 2133 | $date = strtotime( $value ); |
2134 | 2134 | |
2135 | 2135 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2137,29 +2137,29 @@ discard block |
||
2137 | 2137 | return true; |
2138 | 2138 | } |
2139 | 2139 | |
2140 | - $this->set_prop( 'completed_date', '' ); |
|
2140 | + $this->set_prop( 'completed_date', '' ); |
|
2141 | 2141 | return false; |
2142 | 2142 | |
2143 | 2143 | } |
2144 | 2144 | |
2145 | 2145 | /** |
2146 | - * Alias of self::set_completed_date(). |
|
2147 | - * |
|
2148 | - * @since 1.0.19 |
|
2149 | - * @param string $value New name. |
|
2150 | - */ |
|
2151 | - public function set_date_completed( $value ) { |
|
2152 | - $this->set_completed_date( $value ); |
|
2146 | + * Alias of self::set_completed_date(). |
|
2147 | + * |
|
2148 | + * @since 1.0.19 |
|
2149 | + * @param string $value New name. |
|
2150 | + */ |
|
2151 | + public function set_date_completed( $value ) { |
|
2152 | + $this->set_completed_date( $value ); |
|
2153 | 2153 | } |
2154 | 2154 | |
2155 | 2155 | /** |
2156 | - * Set date when the invoice was last modified. |
|
2157 | - * |
|
2158 | - * @since 1.0.19 |
|
2159 | - * @param string $value Value to set. |
|
2156 | + * Set date when the invoice was last modified. |
|
2157 | + * |
|
2158 | + * @since 1.0.19 |
|
2159 | + * @param string $value Value to set. |
|
2160 | 2160 | * @return bool Whether or not the date was set. |
2161 | - */ |
|
2162 | - public function set_date_modified( $value ) { |
|
2161 | + */ |
|
2162 | + public function set_date_modified( $value ) { |
|
2163 | 2163 | $date = strtotime( $value ); |
2164 | 2164 | |
2165 | 2165 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2167,813 +2167,813 @@ discard block |
||
2167 | 2167 | return true; |
2168 | 2168 | } |
2169 | 2169 | |
2170 | - $this->set_prop( 'date_modified', '' ); |
|
2170 | + $this->set_prop( 'date_modified', '' ); |
|
2171 | 2171 | return false; |
2172 | 2172 | |
2173 | 2173 | } |
2174 | 2174 | |
2175 | 2175 | /** |
2176 | - * Set the invoice number. |
|
2177 | - * |
|
2178 | - * @since 1.0.19 |
|
2179 | - * @param string $value New number. |
|
2180 | - */ |
|
2181 | - public function set_number( $value ) { |
|
2176 | + * Set the invoice number. |
|
2177 | + * |
|
2178 | + * @since 1.0.19 |
|
2179 | + * @param string $value New number. |
|
2180 | + */ |
|
2181 | + public function set_number( $value ) { |
|
2182 | 2182 | $number = sanitize_text_field( $value ); |
2183 | - $this->set_prop( 'number', $number ); |
|
2183 | + $this->set_prop( 'number', $number ); |
|
2184 | 2184 | } |
2185 | 2185 | |
2186 | 2186 | /** |
2187 | - * Set the invoice type. |
|
2188 | - * |
|
2189 | - * @since 1.0.19 |
|
2190 | - * @param string $value Type. |
|
2191 | - */ |
|
2192 | - public function set_type( $value ) { |
|
2187 | + * Set the invoice type. |
|
2188 | + * |
|
2189 | + * @since 1.0.19 |
|
2190 | + * @param string $value Type. |
|
2191 | + */ |
|
2192 | + public function set_type( $value ) { |
|
2193 | 2193 | $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) ); |
2194 | - $this->set_prop( 'type', $type ); |
|
2195 | - } |
|
2194 | + $this->set_prop( 'type', $type ); |
|
2195 | + } |
|
2196 | 2196 | |
2197 | 2197 | /** |
2198 | - * Set the invoice post type. |
|
2199 | - * |
|
2200 | - * @since 1.0.19 |
|
2201 | - * @param string $value Post type. |
|
2202 | - */ |
|
2203 | - public function set_post_type( $value ) { |
|
2198 | + * Set the invoice post type. |
|
2199 | + * |
|
2200 | + * @since 1.0.19 |
|
2201 | + * @param string $value Post type. |
|
2202 | + */ |
|
2203 | + public function set_post_type( $value ) { |
|
2204 | 2204 | if ( getpaid_is_invoice_post_type( $value ) ) { |
2205 | - $this->set_type( $value ); |
|
2205 | + $this->set_type( $value ); |
|
2206 | 2206 | $this->set_prop( 'post_type', $value ); |
2207 | 2207 | } |
2208 | 2208 | } |
2209 | 2209 | |
2210 | 2210 | /** |
2211 | - * Set the invoice key. |
|
2212 | - * |
|
2213 | - * @since 1.0.19 |
|
2214 | - * @param string $value New key. |
|
2215 | - */ |
|
2216 | - public function set_key( $value ) { |
|
2211 | + * Set the invoice key. |
|
2212 | + * |
|
2213 | + * @since 1.0.19 |
|
2214 | + * @param string $value New key. |
|
2215 | + */ |
|
2216 | + public function set_key( $value ) { |
|
2217 | 2217 | $key = sanitize_text_field( $value ); |
2218 | - $this->set_prop( 'key', $key ); |
|
2218 | + $this->set_prop( 'key', $key ); |
|
2219 | 2219 | } |
2220 | 2220 | |
2221 | 2221 | /** |
2222 | - * Set the invoice mode. |
|
2223 | - * |
|
2224 | - * @since 1.0.19 |
|
2225 | - * @param string $value mode. |
|
2226 | - */ |
|
2227 | - public function set_mode( $value ) { |
|
2222 | + * Set the invoice mode. |
|
2223 | + * |
|
2224 | + * @since 1.0.19 |
|
2225 | + * @param string $value mode. |
|
2226 | + */ |
|
2227 | + public function set_mode( $value ) { |
|
2228 | 2228 | if ( in_array( $value, array( 'live', 'test' ) ) ) { |
2229 | 2229 | $this->set_prop( 'mode', $value ); |
2230 | 2230 | } |
2231 | 2231 | } |
2232 | 2232 | |
2233 | 2233 | /** |
2234 | - * Set the invoice path. |
|
2235 | - * |
|
2236 | - * @since 1.0.19 |
|
2237 | - * @param string $value path. |
|
2238 | - */ |
|
2239 | - public function set_path( $value ) { |
|
2234 | + * Set the invoice path. |
|
2235 | + * |
|
2236 | + * @since 1.0.19 |
|
2237 | + * @param string $value path. |
|
2238 | + */ |
|
2239 | + public function set_path( $value ) { |
|
2240 | 2240 | $this->set_prop( 'path', $value ); |
2241 | 2241 | } |
2242 | 2242 | |
2243 | 2243 | /** |
2244 | - * Set the invoice name. |
|
2245 | - * |
|
2246 | - * @since 1.0.19 |
|
2247 | - * @param string $value New name. |
|
2248 | - */ |
|
2249 | - public function set_name( $value ) { |
|
2244 | + * Set the invoice name. |
|
2245 | + * |
|
2246 | + * @since 1.0.19 |
|
2247 | + * @param string $value New name. |
|
2248 | + */ |
|
2249 | + public function set_name( $value ) { |
|
2250 | 2250 | $name = sanitize_text_field( $value ); |
2251 | - $this->set_prop( 'name', $name ); |
|
2251 | + $this->set_prop( 'name', $name ); |
|
2252 | 2252 | } |
2253 | 2253 | |
2254 | 2254 | /** |
2255 | - * Alias of self::set_name(). |
|
2256 | - * |
|
2257 | - * @since 1.0.19 |
|
2258 | - * @param string $value New name. |
|
2259 | - */ |
|
2260 | - public function set_title( $value ) { |
|
2261 | - $this->set_name( $value ); |
|
2255 | + * Alias of self::set_name(). |
|
2256 | + * |
|
2257 | + * @since 1.0.19 |
|
2258 | + * @param string $value New name. |
|
2259 | + */ |
|
2260 | + public function set_title( $value ) { |
|
2261 | + $this->set_name( $value ); |
|
2262 | 2262 | } |
2263 | 2263 | |
2264 | 2264 | /** |
2265 | - * Set the invoice description. |
|
2266 | - * |
|
2267 | - * @since 1.0.19 |
|
2268 | - * @param string $value New description. |
|
2269 | - */ |
|
2270 | - public function set_description( $value ) { |
|
2265 | + * Set the invoice description. |
|
2266 | + * |
|
2267 | + * @since 1.0.19 |
|
2268 | + * @param string $value New description. |
|
2269 | + */ |
|
2270 | + public function set_description( $value ) { |
|
2271 | 2271 | $description = wp_kses_post( $value ); |
2272 | - $this->set_prop( 'description', $description ); |
|
2272 | + $this->set_prop( 'description', $description ); |
|
2273 | + } |
|
2274 | + |
|
2275 | + /** |
|
2276 | + * Alias of self::set_description(). |
|
2277 | + * |
|
2278 | + * @since 1.0.19 |
|
2279 | + * @param string $value New description. |
|
2280 | + */ |
|
2281 | + public function set_excerpt( $value ) { |
|
2282 | + $this->set_description( $value ); |
|
2283 | + } |
|
2284 | + |
|
2285 | + /** |
|
2286 | + * Alias of self::set_description(). |
|
2287 | + * |
|
2288 | + * @since 1.0.19 |
|
2289 | + * @param string $value New description. |
|
2290 | + */ |
|
2291 | + public function set_summary( $value ) { |
|
2292 | + $this->set_description( $value ); |
|
2293 | + } |
|
2294 | + |
|
2295 | + /** |
|
2296 | + * Set the receiver of the invoice. |
|
2297 | + * |
|
2298 | + * @since 1.0.19 |
|
2299 | + * @param int $value New author. |
|
2300 | + */ |
|
2301 | + public function set_author( $value ) { |
|
2302 | + $user = get_user_by( 'id', (int) $value ); |
|
2303 | + |
|
2304 | + if ( $user && $user->ID ) { |
|
2305 | + $this->set_prop( 'author', $user->ID ); |
|
2306 | + $this->set_prop( 'email', $user->user_email ); |
|
2307 | + } |
|
2308 | + |
|
2309 | + } |
|
2310 | + |
|
2311 | + /** |
|
2312 | + * Alias of self::set_author(). |
|
2313 | + * |
|
2314 | + * @since 1.0.19 |
|
2315 | + * @param int $value New user id. |
|
2316 | + */ |
|
2317 | + public function set_user_id( $value ) { |
|
2318 | + $this->set_author( $value ); |
|
2319 | + } |
|
2320 | + |
|
2321 | + /** |
|
2322 | + * Alias of self::set_author(). |
|
2323 | + * |
|
2324 | + * @since 1.0.19 |
|
2325 | + * @param int $value New user id. |
|
2326 | + */ |
|
2327 | + public function set_customer_id( $value ) { |
|
2328 | + $this->set_author( $value ); |
|
2329 | + } |
|
2330 | + |
|
2331 | + /** |
|
2332 | + * Set the customer's ip. |
|
2333 | + * |
|
2334 | + * @since 1.0.19 |
|
2335 | + * @param string $value ip address. |
|
2336 | + */ |
|
2337 | + public function set_ip( $value ) { |
|
2338 | + $this->set_prop( 'ip', $value ); |
|
2339 | + } |
|
2340 | + |
|
2341 | + /** |
|
2342 | + * Alias of self::set_ip(). |
|
2343 | + * |
|
2344 | + * @since 1.0.19 |
|
2345 | + * @param string $value ip address. |
|
2346 | + */ |
|
2347 | + public function set_user_ip( $value ) { |
|
2348 | + $this->set_ip( $value ); |
|
2349 | + } |
|
2350 | + |
|
2351 | + /** |
|
2352 | + * Set the customer's first name. |
|
2353 | + * |
|
2354 | + * @since 1.0.19 |
|
2355 | + * @param string $value first name. |
|
2356 | + */ |
|
2357 | + public function set_first_name( $value ) { |
|
2358 | + $this->set_prop( 'first_name', $value ); |
|
2359 | + } |
|
2360 | + |
|
2361 | + /** |
|
2362 | + * Alias of self::set_first_name(). |
|
2363 | + * |
|
2364 | + * @since 1.0.19 |
|
2365 | + * @param string $value first name. |
|
2366 | + */ |
|
2367 | + public function set_user_first_name( $value ) { |
|
2368 | + $this->set_first_name( $value ); |
|
2369 | + } |
|
2370 | + |
|
2371 | + /** |
|
2372 | + * Alias of self::set_first_name(). |
|
2373 | + * |
|
2374 | + * @since 1.0.19 |
|
2375 | + * @param string $value first name. |
|
2376 | + */ |
|
2377 | + public function set_customer_first_name( $value ) { |
|
2378 | + $this->set_first_name( $value ); |
|
2379 | + } |
|
2380 | + |
|
2381 | + /** |
|
2382 | + * Set the customer's last name. |
|
2383 | + * |
|
2384 | + * @since 1.0.19 |
|
2385 | + * @param string $value last name. |
|
2386 | + */ |
|
2387 | + public function set_last_name( $value ) { |
|
2388 | + $this->set_prop( 'last_name', $value ); |
|
2389 | + } |
|
2390 | + |
|
2391 | + /** |
|
2392 | + * Alias of self::set_last_name(). |
|
2393 | + * |
|
2394 | + * @since 1.0.19 |
|
2395 | + * @param string $value last name. |
|
2396 | + */ |
|
2397 | + public function set_user_last_name( $value ) { |
|
2398 | + $this->set_last_name( $value ); |
|
2399 | + } |
|
2400 | + |
|
2401 | + /** |
|
2402 | + * Alias of self::set_last_name(). |
|
2403 | + * |
|
2404 | + * @since 1.0.19 |
|
2405 | + * @param string $value last name. |
|
2406 | + */ |
|
2407 | + public function set_customer_last_name( $value ) { |
|
2408 | + $this->set_last_name( $value ); |
|
2409 | + } |
|
2410 | + |
|
2411 | + /** |
|
2412 | + * Set the customer's phone number. |
|
2413 | + * |
|
2414 | + * @since 1.0.19 |
|
2415 | + * @param string $value phone. |
|
2416 | + */ |
|
2417 | + public function set_phone( $value ) { |
|
2418 | + $this->set_prop( 'phone', $value ); |
|
2273 | 2419 | } |
2274 | 2420 | |
2275 | 2421 | /** |
2276 | - * Alias of self::set_description(). |
|
2277 | - * |
|
2278 | - * @since 1.0.19 |
|
2279 | - * @param string $value New description. |
|
2280 | - */ |
|
2281 | - public function set_excerpt( $value ) { |
|
2282 | - $this->set_description( $value ); |
|
2422 | + * Alias of self::set_phone(). |
|
2423 | + * |
|
2424 | + * @since 1.0.19 |
|
2425 | + * @param string $value phone. |
|
2426 | + */ |
|
2427 | + public function set_user_phone( $value ) { |
|
2428 | + $this->set_phone( $value ); |
|
2283 | 2429 | } |
2284 | 2430 | |
2285 | 2431 | /** |
2286 | - * Alias of self::set_description(). |
|
2287 | - * |
|
2288 | - * @since 1.0.19 |
|
2289 | - * @param string $value New description. |
|
2290 | - */ |
|
2291 | - public function set_summary( $value ) { |
|
2292 | - $this->set_description( $value ); |
|
2432 | + * Alias of self::set_phone(). |
|
2433 | + * |
|
2434 | + * @since 1.0.19 |
|
2435 | + * @param string $value phone. |
|
2436 | + */ |
|
2437 | + public function set_customer_phone( $value ) { |
|
2438 | + $this->set_phone( $value ); |
|
2293 | 2439 | } |
2294 | 2440 | |
2295 | 2441 | /** |
2296 | - * Set the receiver of the invoice. |
|
2297 | - * |
|
2298 | - * @since 1.0.19 |
|
2299 | - * @param int $value New author. |
|
2300 | - */ |
|
2301 | - public function set_author( $value ) { |
|
2302 | - $user = get_user_by( 'id', (int) $value ); |
|
2442 | + * Alias of self::set_phone(). |
|
2443 | + * |
|
2444 | + * @since 1.0.19 |
|
2445 | + * @param string $value phone. |
|
2446 | + */ |
|
2447 | + public function set_phone_number( $value ) { |
|
2448 | + $this->set_phone( $value ); |
|
2449 | + } |
|
2303 | 2450 | |
2304 | - if ( $user && $user->ID ) { |
|
2305 | - $this->set_prop( 'author', $user->ID ); |
|
2306 | - $this->set_prop( 'email', $user->user_email ); |
|
2307 | - } |
|
2451 | + /** |
|
2452 | + * Set the customer's email address. |
|
2453 | + * |
|
2454 | + * @since 1.0.19 |
|
2455 | + * @param string $value email address. |
|
2456 | + */ |
|
2457 | + public function set_email( $value ) { |
|
2458 | + $this->set_prop( 'email', $value ); |
|
2459 | + } |
|
2308 | 2460 | |
2461 | + /** |
|
2462 | + * Alias of self::set_email(). |
|
2463 | + * |
|
2464 | + * @since 1.0.19 |
|
2465 | + * @param string $value email address. |
|
2466 | + */ |
|
2467 | + public function set_user_email( $value ) { |
|
2468 | + $this->set_email( $value ); |
|
2309 | 2469 | } |
2310 | 2470 | |
2311 | 2471 | /** |
2312 | - * Alias of self::set_author(). |
|
2313 | - * |
|
2314 | - * @since 1.0.19 |
|
2315 | - * @param int $value New user id. |
|
2316 | - */ |
|
2317 | - public function set_user_id( $value ) { |
|
2318 | - $this->set_author( $value ); |
|
2472 | + * Alias of self::set_email(). |
|
2473 | + * |
|
2474 | + * @since 1.0.19 |
|
2475 | + * @param string $value email address. |
|
2476 | + */ |
|
2477 | + public function set_email_address( $value ) { |
|
2478 | + $this->set_email( $value ); |
|
2319 | 2479 | } |
2320 | 2480 | |
2321 | 2481 | /** |
2322 | - * Alias of self::set_author(). |
|
2323 | - * |
|
2324 | - * @since 1.0.19 |
|
2325 | - * @param int $value New user id. |
|
2326 | - */ |
|
2327 | - public function set_customer_id( $value ) { |
|
2328 | - $this->set_author( $value ); |
|
2482 | + * Alias of self::set_email(). |
|
2483 | + * |
|
2484 | + * @since 1.0.19 |
|
2485 | + * @param string $value email address. |
|
2486 | + */ |
|
2487 | + public function set_customer_email( $value ) { |
|
2488 | + $this->set_email( $value ); |
|
2329 | 2489 | } |
2330 | 2490 | |
2331 | 2491 | /** |
2332 | - * Set the customer's ip. |
|
2333 | - * |
|
2334 | - * @since 1.0.19 |
|
2335 | - * @param string $value ip address. |
|
2336 | - */ |
|
2337 | - public function set_ip( $value ) { |
|
2338 | - $this->set_prop( 'ip', $value ); |
|
2492 | + * Set the customer's country. |
|
2493 | + * |
|
2494 | + * @since 1.0.19 |
|
2495 | + * @param string $value country. |
|
2496 | + */ |
|
2497 | + public function set_country( $value ) { |
|
2498 | + $this->set_prop( 'country', $value ); |
|
2339 | 2499 | } |
2340 | 2500 | |
2341 | 2501 | /** |
2342 | - * Alias of self::set_ip(). |
|
2343 | - * |
|
2344 | - * @since 1.0.19 |
|
2345 | - * @param string $value ip address. |
|
2346 | - */ |
|
2347 | - public function set_user_ip( $value ) { |
|
2348 | - $this->set_ip( $value ); |
|
2502 | + * Alias of self::set_country(). |
|
2503 | + * |
|
2504 | + * @since 1.0.19 |
|
2505 | + * @param string $value country. |
|
2506 | + */ |
|
2507 | + public function set_user_country( $value ) { |
|
2508 | + $this->set_country( $value ); |
|
2349 | 2509 | } |
2350 | 2510 | |
2351 | 2511 | /** |
2352 | - * Set the customer's first name. |
|
2353 | - * |
|
2354 | - * @since 1.0.19 |
|
2355 | - * @param string $value first name. |
|
2356 | - */ |
|
2357 | - public function set_first_name( $value ) { |
|
2358 | - $this->set_prop( 'first_name', $value ); |
|
2512 | + * Alias of self::set_country(). |
|
2513 | + * |
|
2514 | + * @since 1.0.19 |
|
2515 | + * @param string $value country. |
|
2516 | + */ |
|
2517 | + public function set_customer_country( $value ) { |
|
2518 | + $this->set_country( $value ); |
|
2359 | 2519 | } |
2360 | 2520 | |
2361 | 2521 | /** |
2362 | - * Alias of self::set_first_name(). |
|
2363 | - * |
|
2364 | - * @since 1.0.19 |
|
2365 | - * @param string $value first name. |
|
2366 | - */ |
|
2367 | - public function set_user_first_name( $value ) { |
|
2368 | - $this->set_first_name( $value ); |
|
2522 | + * Set the customer's state. |
|
2523 | + * |
|
2524 | + * @since 1.0.19 |
|
2525 | + * @param string $value state. |
|
2526 | + */ |
|
2527 | + public function set_state( $value ) { |
|
2528 | + $this->set_prop( 'state', $value ); |
|
2369 | 2529 | } |
2370 | 2530 | |
2371 | 2531 | /** |
2372 | - * Alias of self::set_first_name(). |
|
2373 | - * |
|
2374 | - * @since 1.0.19 |
|
2375 | - * @param string $value first name. |
|
2376 | - */ |
|
2377 | - public function set_customer_first_name( $value ) { |
|
2378 | - $this->set_first_name( $value ); |
|
2532 | + * Alias of self::set_state(). |
|
2533 | + * |
|
2534 | + * @since 1.0.19 |
|
2535 | + * @param string $value state. |
|
2536 | + */ |
|
2537 | + public function set_user_state( $value ) { |
|
2538 | + $this->set_state( $value ); |
|
2379 | 2539 | } |
2380 | 2540 | |
2381 | 2541 | /** |
2382 | - * Set the customer's last name. |
|
2383 | - * |
|
2384 | - * @since 1.0.19 |
|
2385 | - * @param string $value last name. |
|
2386 | - */ |
|
2387 | - public function set_last_name( $value ) { |
|
2388 | - $this->set_prop( 'last_name', $value ); |
|
2542 | + * Alias of self::set_state(). |
|
2543 | + * |
|
2544 | + * @since 1.0.19 |
|
2545 | + * @param string $value state. |
|
2546 | + */ |
|
2547 | + public function set_customer_state( $value ) { |
|
2548 | + $this->set_state( $value ); |
|
2389 | 2549 | } |
2390 | 2550 | |
2391 | 2551 | /** |
2392 | - * Alias of self::set_last_name(). |
|
2393 | - * |
|
2394 | - * @since 1.0.19 |
|
2395 | - * @param string $value last name. |
|
2396 | - */ |
|
2397 | - public function set_user_last_name( $value ) { |
|
2398 | - $this->set_last_name( $value ); |
|
2552 | + * Set the customer's city. |
|
2553 | + * |
|
2554 | + * @since 1.0.19 |
|
2555 | + * @param string $value city. |
|
2556 | + */ |
|
2557 | + public function set_city( $value ) { |
|
2558 | + $this->set_prop( 'city', $value ); |
|
2399 | 2559 | } |
2400 | 2560 | |
2401 | 2561 | /** |
2402 | - * Alias of self::set_last_name(). |
|
2403 | - * |
|
2404 | - * @since 1.0.19 |
|
2405 | - * @param string $value last name. |
|
2406 | - */ |
|
2407 | - public function set_customer_last_name( $value ) { |
|
2408 | - $this->set_last_name( $value ); |
|
2562 | + * Alias of self::set_city(). |
|
2563 | + * |
|
2564 | + * @since 1.0.19 |
|
2565 | + * @param string $value city. |
|
2566 | + */ |
|
2567 | + public function set_user_city( $value ) { |
|
2568 | + $this->set_city( $value ); |
|
2409 | 2569 | } |
2410 | 2570 | |
2411 | 2571 | /** |
2412 | - * Set the customer's phone number. |
|
2413 | - * |
|
2414 | - * @since 1.0.19 |
|
2415 | - * @param string $value phone. |
|
2416 | - */ |
|
2417 | - public function set_phone( $value ) { |
|
2418 | - $this->set_prop( 'phone', $value ); |
|
2572 | + * Alias of self::set_city(). |
|
2573 | + * |
|
2574 | + * @since 1.0.19 |
|
2575 | + * @param string $value city. |
|
2576 | + */ |
|
2577 | + public function set_customer_city( $value ) { |
|
2578 | + $this->set_city( $value ); |
|
2419 | 2579 | } |
2420 | 2580 | |
2421 | 2581 | /** |
2422 | - * Alias of self::set_phone(). |
|
2423 | - * |
|
2424 | - * @since 1.0.19 |
|
2425 | - * @param string $value phone. |
|
2426 | - */ |
|
2427 | - public function set_user_phone( $value ) { |
|
2428 | - $this->set_phone( $value ); |
|
2582 | + * Set the customer's zip code. |
|
2583 | + * |
|
2584 | + * @since 1.0.19 |
|
2585 | + * @param string $value zip. |
|
2586 | + */ |
|
2587 | + public function set_zip( $value ) { |
|
2588 | + $this->set_prop( 'zip', $value ); |
|
2429 | 2589 | } |
2430 | 2590 | |
2431 | 2591 | /** |
2432 | - * Alias of self::set_phone(). |
|
2433 | - * |
|
2434 | - * @since 1.0.19 |
|
2435 | - * @param string $value phone. |
|
2436 | - */ |
|
2437 | - public function set_customer_phone( $value ) { |
|
2438 | - $this->set_phone( $value ); |
|
2592 | + * Alias of self::set_zip(). |
|
2593 | + * |
|
2594 | + * @since 1.0.19 |
|
2595 | + * @param string $value zip. |
|
2596 | + */ |
|
2597 | + public function set_user_zip( $value ) { |
|
2598 | + $this->set_zip( $value ); |
|
2439 | 2599 | } |
2440 | 2600 | |
2441 | 2601 | /** |
2442 | - * Alias of self::set_phone(). |
|
2443 | - * |
|
2444 | - * @since 1.0.19 |
|
2445 | - * @param string $value phone. |
|
2446 | - */ |
|
2447 | - public function set_phone_number( $value ) { |
|
2448 | - $this->set_phone( $value ); |
|
2602 | + * Alias of self::set_zip(). |
|
2603 | + * |
|
2604 | + * @since 1.0.19 |
|
2605 | + * @param string $value zip. |
|
2606 | + */ |
|
2607 | + public function set_customer_zip( $value ) { |
|
2608 | + $this->set_zip( $value ); |
|
2449 | 2609 | } |
2450 | 2610 | |
2451 | 2611 | /** |
2452 | - * Set the customer's email address. |
|
2453 | - * |
|
2454 | - * @since 1.0.19 |
|
2455 | - * @param string $value email address. |
|
2456 | - */ |
|
2457 | - public function set_email( $value ) { |
|
2458 | - $this->set_prop( 'email', $value ); |
|
2612 | + * Set the customer's company. |
|
2613 | + * |
|
2614 | + * @since 1.0.19 |
|
2615 | + * @param string $value company. |
|
2616 | + */ |
|
2617 | + public function set_company( $value ) { |
|
2618 | + $this->set_prop( 'company', $value ); |
|
2459 | 2619 | } |
2460 | 2620 | |
2461 | 2621 | /** |
2462 | - * Alias of self::set_email(). |
|
2463 | - * |
|
2464 | - * @since 1.0.19 |
|
2465 | - * @param string $value email address. |
|
2466 | - */ |
|
2467 | - public function set_user_email( $value ) { |
|
2468 | - $this->set_email( $value ); |
|
2622 | + * Alias of self::set_company(). |
|
2623 | + * |
|
2624 | + * @since 1.0.19 |
|
2625 | + * @param string $value company. |
|
2626 | + */ |
|
2627 | + public function set_user_company( $value ) { |
|
2628 | + $this->set_company( $value ); |
|
2469 | 2629 | } |
2470 | 2630 | |
2471 | 2631 | /** |
2472 | - * Alias of self::set_email(). |
|
2473 | - * |
|
2474 | - * @since 1.0.19 |
|
2475 | - * @param string $value email address. |
|
2476 | - */ |
|
2477 | - public function set_email_address( $value ) { |
|
2478 | - $this->set_email( $value ); |
|
2632 | + * Alias of self::set_company(). |
|
2633 | + * |
|
2634 | + * @since 1.0.19 |
|
2635 | + * @param string $value company. |
|
2636 | + */ |
|
2637 | + public function set_customer_company( $value ) { |
|
2638 | + $this->set_company( $value ); |
|
2479 | 2639 | } |
2480 | 2640 | |
2481 | 2641 | /** |
2482 | - * Alias of self::set_email(). |
|
2483 | - * |
|
2484 | - * @since 1.0.19 |
|
2485 | - * @param string $value email address. |
|
2486 | - */ |
|
2487 | - public function set_customer_email( $value ) { |
|
2488 | - $this->set_email( $value ); |
|
2642 | + * Set the customer's company id. |
|
2643 | + * |
|
2644 | + * @since 1.0.19 |
|
2645 | + * @param string $value company id. |
|
2646 | + */ |
|
2647 | + public function set_company_id( $value ) { |
|
2648 | + $this->set_prop( 'company_id', $value ); |
|
2489 | 2649 | } |
2490 | 2650 | |
2491 | 2651 | /** |
2492 | - * Set the customer's country. |
|
2493 | - * |
|
2494 | - * @since 1.0.19 |
|
2495 | - * @param string $value country. |
|
2496 | - */ |
|
2497 | - public function set_country( $value ) { |
|
2498 | - $this->set_prop( 'country', $value ); |
|
2652 | + * Set the customer's var number. |
|
2653 | + * |
|
2654 | + * @since 1.0.19 |
|
2655 | + * @param string $value var number. |
|
2656 | + */ |
|
2657 | + public function set_vat_number( $value ) { |
|
2658 | + $this->set_prop( 'vat_number', $value ); |
|
2499 | 2659 | } |
2500 | 2660 | |
2501 | 2661 | /** |
2502 | - * Alias of self::set_country(). |
|
2503 | - * |
|
2504 | - * @since 1.0.19 |
|
2505 | - * @param string $value country. |
|
2506 | - */ |
|
2507 | - public function set_user_country( $value ) { |
|
2508 | - $this->set_country( $value ); |
|
2662 | + * Alias of self::set_vat_number(). |
|
2663 | + * |
|
2664 | + * @since 1.0.19 |
|
2665 | + * @param string $value var number. |
|
2666 | + */ |
|
2667 | + public function set_user_vat_number( $value ) { |
|
2668 | + $this->set_vat_number( $value ); |
|
2509 | 2669 | } |
2510 | 2670 | |
2511 | 2671 | /** |
2512 | - * Alias of self::set_country(). |
|
2513 | - * |
|
2514 | - * @since 1.0.19 |
|
2515 | - * @param string $value country. |
|
2516 | - */ |
|
2517 | - public function set_customer_country( $value ) { |
|
2518 | - $this->set_country( $value ); |
|
2672 | + * Alias of self::set_vat_number(). |
|
2673 | + * |
|
2674 | + * @since 1.0.19 |
|
2675 | + * @param string $value var number. |
|
2676 | + */ |
|
2677 | + public function set_customer_vat_number( $value ) { |
|
2678 | + $this->set_vat_number( $value ); |
|
2519 | 2679 | } |
2520 | 2680 | |
2521 | 2681 | /** |
2522 | - * Set the customer's state. |
|
2523 | - * |
|
2524 | - * @since 1.0.19 |
|
2525 | - * @param string $value state. |
|
2526 | - */ |
|
2527 | - public function set_state( $value ) { |
|
2528 | - $this->set_prop( 'state', $value ); |
|
2682 | + * Set the customer's vat rate. |
|
2683 | + * |
|
2684 | + * @since 1.0.19 |
|
2685 | + * @param string $value var rate. |
|
2686 | + */ |
|
2687 | + public function set_vat_rate( $value ) { |
|
2688 | + $this->set_prop( 'vat_rate', $value ); |
|
2529 | 2689 | } |
2530 | 2690 | |
2531 | 2691 | /** |
2532 | - * Alias of self::set_state(). |
|
2533 | - * |
|
2534 | - * @since 1.0.19 |
|
2535 | - * @param string $value state. |
|
2536 | - */ |
|
2537 | - public function set_user_state( $value ) { |
|
2538 | - $this->set_state( $value ); |
|
2692 | + * Alias of self::set_vat_rate(). |
|
2693 | + * |
|
2694 | + * @since 1.0.19 |
|
2695 | + * @param string $value var number. |
|
2696 | + */ |
|
2697 | + public function set_user_vat_rate( $value ) { |
|
2698 | + $this->set_vat_rate( $value ); |
|
2539 | 2699 | } |
2540 | 2700 | |
2541 | 2701 | /** |
2542 | - * Alias of self::set_state(). |
|
2543 | - * |
|
2544 | - * @since 1.0.19 |
|
2545 | - * @param string $value state. |
|
2546 | - */ |
|
2547 | - public function set_customer_state( $value ) { |
|
2548 | - $this->set_state( $value ); |
|
2702 | + * Alias of self::set_vat_rate(). |
|
2703 | + * |
|
2704 | + * @since 1.0.19 |
|
2705 | + * @param string $value var number. |
|
2706 | + */ |
|
2707 | + public function set_customer_vat_rate( $value ) { |
|
2708 | + $this->set_vat_rate( $value ); |
|
2549 | 2709 | } |
2550 | 2710 | |
2551 | 2711 | /** |
2552 | - * Set the customer's city. |
|
2553 | - * |
|
2554 | - * @since 1.0.19 |
|
2555 | - * @param string $value city. |
|
2556 | - */ |
|
2557 | - public function set_city( $value ) { |
|
2558 | - $this->set_prop( 'city', $value ); |
|
2712 | + * Set the customer's address. |
|
2713 | + * |
|
2714 | + * @since 1.0.19 |
|
2715 | + * @param string $value address. |
|
2716 | + */ |
|
2717 | + public function set_address( $value ) { |
|
2718 | + $this->set_prop( 'address', $value ); |
|
2559 | 2719 | } |
2560 | 2720 | |
2561 | 2721 | /** |
2562 | - * Alias of self::set_city(). |
|
2563 | - * |
|
2564 | - * @since 1.0.19 |
|
2565 | - * @param string $value city. |
|
2566 | - */ |
|
2567 | - public function set_user_city( $value ) { |
|
2568 | - $this->set_city( $value ); |
|
2722 | + * Alias of self::set_address(). |
|
2723 | + * |
|
2724 | + * @since 1.0.19 |
|
2725 | + * @param string $value address. |
|
2726 | + */ |
|
2727 | + public function set_user_address( $value ) { |
|
2728 | + $this->set_address( $value ); |
|
2569 | 2729 | } |
2570 | 2730 | |
2571 | 2731 | /** |
2572 | - * Alias of self::set_city(). |
|
2573 | - * |
|
2574 | - * @since 1.0.19 |
|
2575 | - * @param string $value city. |
|
2576 | - */ |
|
2577 | - public function set_customer_city( $value ) { |
|
2578 | - $this->set_city( $value ); |
|
2732 | + * Alias of self::set_address(). |
|
2733 | + * |
|
2734 | + * @since 1.0.19 |
|
2735 | + * @param string $value address. |
|
2736 | + */ |
|
2737 | + public function set_customer_address( $value ) { |
|
2738 | + $this->set_address( $value ); |
|
2579 | 2739 | } |
2580 | 2740 | |
2581 | 2741 | /** |
2582 | - * Set the customer's zip code. |
|
2583 | - * |
|
2584 | - * @since 1.0.19 |
|
2585 | - * @param string $value zip. |
|
2586 | - */ |
|
2587 | - public function set_zip( $value ) { |
|
2588 | - $this->set_prop( 'zip', $value ); |
|
2742 | + * Set whether the customer has viewed the invoice or not. |
|
2743 | + * |
|
2744 | + * @since 1.0.19 |
|
2745 | + * @param int|bool $value confirmed. |
|
2746 | + */ |
|
2747 | + public function set_is_viewed( $value ) { |
|
2748 | + $this->set_prop( 'is_viewed', $value ); |
|
2589 | 2749 | } |
2590 | 2750 | |
2591 | 2751 | /** |
2592 | - * Alias of self::set_zip(). |
|
2593 | - * |
|
2594 | - * @since 1.0.19 |
|
2595 | - * @param string $value zip. |
|
2596 | - */ |
|
2597 | - public function set_user_zip( $value ) { |
|
2598 | - $this->set_zip( $value ); |
|
2752 | + * Set extra email recipients. |
|
2753 | + * |
|
2754 | + * @since 1.0.19 |
|
2755 | + * @param string $value email recipients. |
|
2756 | + */ |
|
2757 | + public function set_email_cc( $value ) { |
|
2758 | + $this->set_prop( 'email_cc', $value ); |
|
2599 | 2759 | } |
2600 | 2760 | |
2601 | 2761 | /** |
2602 | - * Alias of self::set_zip(). |
|
2603 | - * |
|
2604 | - * @since 1.0.19 |
|
2605 | - * @param string $value zip. |
|
2606 | - */ |
|
2607 | - public function set_customer_zip( $value ) { |
|
2608 | - $this->set_zip( $value ); |
|
2762 | + * Set the invoice template. |
|
2763 | + * |
|
2764 | + * @since 1.0.19 |
|
2765 | + * @param string $value template. |
|
2766 | + */ |
|
2767 | + public function set_template( $value ) { |
|
2768 | + if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
2769 | + $this->set_prop( 'template', $value ); |
|
2770 | + } |
|
2609 | 2771 | } |
2610 | 2772 | |
2611 | 2773 | /** |
2612 | - * Set the customer's company. |
|
2613 | - * |
|
2614 | - * @since 1.0.19 |
|
2615 | - * @param string $value company. |
|
2616 | - */ |
|
2617 | - public function set_company( $value ) { |
|
2618 | - $this->set_prop( 'company', $value ); |
|
2774 | + * Set the invoice source. |
|
2775 | + * |
|
2776 | + * @since 1.0.19 |
|
2777 | + * @param string $value source. |
|
2778 | + * @deprecated |
|
2779 | + */ |
|
2780 | + public function created_via( $value ) { |
|
2781 | + $this->set_created_via( sanitize_text_field( $value ) ); |
|
2619 | 2782 | } |
2620 | 2783 | |
2621 | 2784 | /** |
2622 | - * Alias of self::set_company(). |
|
2623 | - * |
|
2624 | - * @since 1.0.19 |
|
2625 | - * @param string $value company. |
|
2626 | - */ |
|
2627 | - public function set_user_company( $value ) { |
|
2628 | - $this->set_company( $value ); |
|
2785 | + * Set the invoice source. |
|
2786 | + * |
|
2787 | + * @since 1.0.19 |
|
2788 | + * @param string $value source. |
|
2789 | + */ |
|
2790 | + public function set_created_via( $value ) { |
|
2791 | + $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
2629 | 2792 | } |
2630 | 2793 | |
2631 | 2794 | /** |
2632 | - * Alias of self::set_company(). |
|
2633 | - * |
|
2634 | - * @since 1.0.19 |
|
2635 | - * @param string $value company. |
|
2636 | - */ |
|
2637 | - public function set_customer_company( $value ) { |
|
2638 | - $this->set_company( $value ); |
|
2639 | - } |
|
2640 | - |
|
2641 | - /** |
|
2642 | - * Set the customer's company id. |
|
2643 | - * |
|
2644 | - * @since 1.0.19 |
|
2645 | - * @param string $value company id. |
|
2646 | - */ |
|
2647 | - public function set_company_id( $value ) { |
|
2648 | - $this->set_prop( 'company_id', $value ); |
|
2795 | + * Set the customer's address confirmed status. |
|
2796 | + * |
|
2797 | + * @since 1.0.19 |
|
2798 | + * @param int|bool $value confirmed. |
|
2799 | + */ |
|
2800 | + public function set_address_confirmed( $value ) { |
|
2801 | + $this->set_prop( 'address_confirmed', $value ); |
|
2649 | 2802 | } |
2650 | 2803 | |
2651 | 2804 | /** |
2652 | - * Set the customer's var number. |
|
2653 | - * |
|
2654 | - * @since 1.0.19 |
|
2655 | - * @param string $value var number. |
|
2656 | - */ |
|
2657 | - public function set_vat_number( $value ) { |
|
2658 | - $this->set_prop( 'vat_number', $value ); |
|
2805 | + * Alias of self::set_address_confirmed(). |
|
2806 | + * |
|
2807 | + * @since 1.0.19 |
|
2808 | + * @param int|bool $value confirmed. |
|
2809 | + */ |
|
2810 | + public function set_user_address_confirmed( $value ) { |
|
2811 | + $this->set_address_confirmed( $value ); |
|
2659 | 2812 | } |
2660 | 2813 | |
2661 | 2814 | /** |
2662 | - * Alias of self::set_vat_number(). |
|
2663 | - * |
|
2664 | - * @since 1.0.19 |
|
2665 | - * @param string $value var number. |
|
2666 | - */ |
|
2667 | - public function set_user_vat_number( $value ) { |
|
2668 | - $this->set_vat_number( $value ); |
|
2815 | + * Alias of self::set_address_confirmed(). |
|
2816 | + * |
|
2817 | + * @since 1.0.19 |
|
2818 | + * @param int|bool $value confirmed. |
|
2819 | + */ |
|
2820 | + public function set_customer_address_confirmed( $value ) { |
|
2821 | + $this->set_address_confirmed( $value ); |
|
2669 | 2822 | } |
2670 | 2823 | |
2671 | 2824 | /** |
2672 | - * Alias of self::set_vat_number(). |
|
2673 | - * |
|
2674 | - * @since 1.0.19 |
|
2675 | - * @param string $value var number. |
|
2676 | - */ |
|
2677 | - public function set_customer_vat_number( $value ) { |
|
2678 | - $this->set_vat_number( $value ); |
|
2825 | + * Set the shipping fee |
|
2826 | + * |
|
2827 | + * @since 1.0.19 |
|
2828 | + * @param float $value shipping amount. |
|
2829 | + */ |
|
2830 | + public function set_shipping( $value ) { |
|
2831 | + |
|
2832 | + if ( ! is_numeric( $value ) ) { |
|
2833 | + return $this->set_prop( 'shipping', null ); |
|
2834 | + } |
|
2835 | + |
|
2836 | + $this->set_prop( 'shipping', max( 0, floatval( $value ) ) ); |
|
2679 | 2837 | } |
2680 | 2838 | |
2681 | 2839 | /** |
2682 | - * Set the customer's vat rate. |
|
2683 | - * |
|
2684 | - * @since 1.0.19 |
|
2685 | - * @param string $value var rate. |
|
2686 | - */ |
|
2687 | - public function set_vat_rate( $value ) { |
|
2688 | - $this->set_prop( 'vat_rate', $value ); |
|
2840 | + * Set the invoice sub total. |
|
2841 | + * |
|
2842 | + * @since 1.0.19 |
|
2843 | + * @param float $value sub total. |
|
2844 | + */ |
|
2845 | + public function set_subtotal( $value ) { |
|
2846 | + $this->set_prop( 'subtotal', max( 0, $value ) ); |
|
2689 | 2847 | } |
2690 | 2848 | |
2691 | - /** |
|
2692 | - * Alias of self::set_vat_rate(). |
|
2693 | - * |
|
2694 | - * @since 1.0.19 |
|
2695 | - * @param string $value var number. |
|
2696 | - */ |
|
2697 | - public function set_user_vat_rate( $value ) { |
|
2698 | - $this->set_vat_rate( $value ); |
|
2699 | - } |
|
2700 | - |
|
2701 | - /** |
|
2702 | - * Alias of self::set_vat_rate(). |
|
2703 | - * |
|
2704 | - * @since 1.0.19 |
|
2705 | - * @param string $value var number. |
|
2706 | - */ |
|
2707 | - public function set_customer_vat_rate( $value ) { |
|
2708 | - $this->set_vat_rate( $value ); |
|
2709 | - } |
|
2710 | - |
|
2711 | - /** |
|
2712 | - * Set the customer's address. |
|
2713 | - * |
|
2714 | - * @since 1.0.19 |
|
2715 | - * @param string $value address. |
|
2716 | - */ |
|
2717 | - public function set_address( $value ) { |
|
2718 | - $this->set_prop( 'address', $value ); |
|
2719 | - } |
|
2720 | - |
|
2721 | - /** |
|
2722 | - * Alias of self::set_address(). |
|
2723 | - * |
|
2724 | - * @since 1.0.19 |
|
2725 | - * @param string $value address. |
|
2726 | - */ |
|
2727 | - public function set_user_address( $value ) { |
|
2728 | - $this->set_address( $value ); |
|
2729 | - } |
|
2730 | - |
|
2731 | - /** |
|
2732 | - * Alias of self::set_address(). |
|
2733 | - * |
|
2734 | - * @since 1.0.19 |
|
2735 | - * @param string $value address. |
|
2736 | - */ |
|
2737 | - public function set_customer_address( $value ) { |
|
2738 | - $this->set_address( $value ); |
|
2739 | - } |
|
2740 | - |
|
2741 | - /** |
|
2742 | - * Set whether the customer has viewed the invoice or not. |
|
2743 | - * |
|
2744 | - * @since 1.0.19 |
|
2745 | - * @param int|bool $value confirmed. |
|
2746 | - */ |
|
2747 | - public function set_is_viewed( $value ) { |
|
2748 | - $this->set_prop( 'is_viewed', $value ); |
|
2749 | - } |
|
2750 | - |
|
2751 | - /** |
|
2752 | - * Set extra email recipients. |
|
2753 | - * |
|
2754 | - * @since 1.0.19 |
|
2755 | - * @param string $value email recipients. |
|
2756 | - */ |
|
2757 | - public function set_email_cc( $value ) { |
|
2758 | - $this->set_prop( 'email_cc', $value ); |
|
2759 | - } |
|
2760 | - |
|
2761 | - /** |
|
2762 | - * Set the invoice template. |
|
2763 | - * |
|
2764 | - * @since 1.0.19 |
|
2765 | - * @param string $value template. |
|
2766 | - */ |
|
2767 | - public function set_template( $value ) { |
|
2768 | - if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
2769 | - $this->set_prop( 'template', $value ); |
|
2770 | - } |
|
2771 | - } |
|
2772 | - |
|
2773 | - /** |
|
2774 | - * Set the invoice source. |
|
2775 | - * |
|
2776 | - * @since 1.0.19 |
|
2777 | - * @param string $value source. |
|
2778 | - * @deprecated |
|
2779 | - */ |
|
2780 | - public function created_via( $value ) { |
|
2781 | - $this->set_created_via( sanitize_text_field( $value ) ); |
|
2782 | - } |
|
2783 | - |
|
2784 | - /** |
|
2785 | - * Set the invoice source. |
|
2786 | - * |
|
2787 | - * @since 1.0.19 |
|
2788 | - * @param string $value source. |
|
2789 | - */ |
|
2790 | - public function set_created_via( $value ) { |
|
2791 | - $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
2792 | - } |
|
2793 | - |
|
2794 | - /** |
|
2795 | - * Set the customer's address confirmed status. |
|
2796 | - * |
|
2797 | - * @since 1.0.19 |
|
2798 | - * @param int|bool $value confirmed. |
|
2799 | - */ |
|
2800 | - public function set_address_confirmed( $value ) { |
|
2801 | - $this->set_prop( 'address_confirmed', $value ); |
|
2802 | - } |
|
2803 | - |
|
2804 | - /** |
|
2805 | - * Alias of self::set_address_confirmed(). |
|
2806 | - * |
|
2807 | - * @since 1.0.19 |
|
2808 | - * @param int|bool $value confirmed. |
|
2809 | - */ |
|
2810 | - public function set_user_address_confirmed( $value ) { |
|
2811 | - $this->set_address_confirmed( $value ); |
|
2812 | - } |
|
2813 | - |
|
2814 | - /** |
|
2815 | - * Alias of self::set_address_confirmed(). |
|
2816 | - * |
|
2817 | - * @since 1.0.19 |
|
2818 | - * @param int|bool $value confirmed. |
|
2819 | - */ |
|
2820 | - public function set_customer_address_confirmed( $value ) { |
|
2821 | - $this->set_address_confirmed( $value ); |
|
2822 | - } |
|
2823 | - |
|
2824 | - /** |
|
2825 | - * Set the shipping fee |
|
2826 | - * |
|
2827 | - * @since 1.0.19 |
|
2828 | - * @param float $value shipping amount. |
|
2829 | - */ |
|
2830 | - public function set_shipping( $value ) { |
|
2831 | - |
|
2832 | - if ( ! is_numeric( $value ) ) { |
|
2833 | - return $this->set_prop( 'shipping', null ); |
|
2834 | - } |
|
2835 | - |
|
2836 | - $this->set_prop( 'shipping', max( 0, floatval( $value ) ) ); |
|
2837 | - } |
|
2838 | - |
|
2839 | - /** |
|
2840 | - * Set the invoice sub total. |
|
2841 | - * |
|
2842 | - * @since 1.0.19 |
|
2843 | - * @param float $value sub total. |
|
2844 | - */ |
|
2845 | - public function set_subtotal( $value ) { |
|
2846 | - $this->set_prop( 'subtotal', max( 0, $value ) ); |
|
2847 | - } |
|
2848 | - |
|
2849 | - /** |
|
2850 | - * Set the invoice total. |
|
2851 | - * |
|
2852 | - * @since 1.0.19 |
|
2853 | - * @param float $value sub total. |
|
2854 | - */ |
|
2855 | - public function set_total( $value ) { |
|
2856 | - $this->set_prop( 'total', max( 0, $value ) ); |
|
2849 | + /** |
|
2850 | + * Set the invoice total. |
|
2851 | + * |
|
2852 | + * @since 1.0.19 |
|
2853 | + * @param float $value sub total. |
|
2854 | + */ |
|
2855 | + public function set_total( $value ) { |
|
2856 | + $this->set_prop( 'total', max( 0, $value ) ); |
|
2857 | 2857 | } |
2858 | 2858 | |
2859 | 2859 | /** |
2860 | - * Set the invoice discount amount. |
|
2861 | - * |
|
2862 | - * @since 1.0.19 |
|
2863 | - * @param float $value discount total. |
|
2864 | - */ |
|
2865 | - public function set_total_discount( $value ) { |
|
2866 | - $this->set_prop( 'total_discount', max( 0, $value ) ); |
|
2860 | + * Set the invoice discount amount. |
|
2861 | + * |
|
2862 | + * @since 1.0.19 |
|
2863 | + * @param float $value discount total. |
|
2864 | + */ |
|
2865 | + public function set_total_discount( $value ) { |
|
2866 | + $this->set_prop( 'total_discount', max( 0, $value ) ); |
|
2867 | 2867 | } |
2868 | 2868 | |
2869 | 2869 | /** |
2870 | - * Alias of self::set_total_discount(). |
|
2871 | - * |
|
2872 | - * @since 1.0.19 |
|
2873 | - * @param float $value discount total. |
|
2874 | - */ |
|
2875 | - public function set_discount( $value ) { |
|
2876 | - $this->set_total_discount( $value ); |
|
2870 | + * Alias of self::set_total_discount(). |
|
2871 | + * |
|
2872 | + * @since 1.0.19 |
|
2873 | + * @param float $value discount total. |
|
2874 | + */ |
|
2875 | + public function set_discount( $value ) { |
|
2876 | + $this->set_total_discount( $value ); |
|
2877 | 2877 | } |
2878 | 2878 | |
2879 | 2879 | /** |
2880 | - * Set the invoice tax amount. |
|
2881 | - * |
|
2882 | - * @since 1.0.19 |
|
2883 | - * @param float $value tax total. |
|
2884 | - */ |
|
2885 | - public function set_total_tax( $value ) { |
|
2886 | - $this->set_prop( 'total_tax', max( 0, $value ) ); |
|
2880 | + * Set the invoice tax amount. |
|
2881 | + * |
|
2882 | + * @since 1.0.19 |
|
2883 | + * @param float $value tax total. |
|
2884 | + */ |
|
2885 | + public function set_total_tax( $value ) { |
|
2886 | + $this->set_prop( 'total_tax', max( 0, $value ) ); |
|
2887 | 2887 | } |
2888 | 2888 | |
2889 | 2889 | /** |
2890 | - * Alias of self::set_total_tax(). |
|
2891 | - * |
|
2892 | - * @since 1.0.19 |
|
2893 | - * @param float $value tax total. |
|
2894 | - */ |
|
2895 | - public function set_tax_total( $value ) { |
|
2896 | - $this->set_total_tax( $value ); |
|
2890 | + * Alias of self::set_total_tax(). |
|
2891 | + * |
|
2892 | + * @since 1.0.19 |
|
2893 | + * @param float $value tax total. |
|
2894 | + */ |
|
2895 | + public function set_tax_total( $value ) { |
|
2896 | + $this->set_total_tax( $value ); |
|
2897 | 2897 | } |
2898 | 2898 | |
2899 | 2899 | /** |
2900 | - * Set the invoice fees amount. |
|
2901 | - * |
|
2902 | - * @since 1.0.19 |
|
2903 | - * @param float $value fees total. |
|
2904 | - */ |
|
2905 | - public function set_total_fees( $value ) { |
|
2906 | - $this->set_prop( 'total_fees', max( 0, $value ) ); |
|
2900 | + * Set the invoice fees amount. |
|
2901 | + * |
|
2902 | + * @since 1.0.19 |
|
2903 | + * @param float $value fees total. |
|
2904 | + */ |
|
2905 | + public function set_total_fees( $value ) { |
|
2906 | + $this->set_prop( 'total_fees', max( 0, $value ) ); |
|
2907 | 2907 | } |
2908 | 2908 | |
2909 | 2909 | /** |
2910 | - * Alias of self::set_total_fees(). |
|
2911 | - * |
|
2912 | - * @since 1.0.19 |
|
2913 | - * @param float $value fees total. |
|
2914 | - */ |
|
2915 | - public function set_fees_total( $value ) { |
|
2916 | - $this->set_total_fees( $value ); |
|
2910 | + * Alias of self::set_total_fees(). |
|
2911 | + * |
|
2912 | + * @since 1.0.19 |
|
2913 | + * @param float $value fees total. |
|
2914 | + */ |
|
2915 | + public function set_fees_total( $value ) { |
|
2916 | + $this->set_total_fees( $value ); |
|
2917 | 2917 | } |
2918 | 2918 | |
2919 | 2919 | /** |
2920 | - * Set the invoice fees. |
|
2921 | - * |
|
2922 | - * @since 1.0.19 |
|
2923 | - * @param array $value fees. |
|
2924 | - */ |
|
2925 | - public function set_fees( $value ) { |
|
2920 | + * Set the invoice fees. |
|
2921 | + * |
|
2922 | + * @since 1.0.19 |
|
2923 | + * @param array $value fees. |
|
2924 | + */ |
|
2925 | + public function set_fees( $value ) { |
|
2926 | 2926 | |
2927 | - if ( ! is_array( $value ) ) { |
|
2928 | - $value = array(); |
|
2929 | - } |
|
2927 | + if ( ! is_array( $value ) ) { |
|
2928 | + $value = array(); |
|
2929 | + } |
|
2930 | 2930 | |
2931 | - $this->set_prop( 'fees', $value ); |
|
2931 | + $this->set_prop( 'fees', $value ); |
|
2932 | 2932 | |
2933 | 2933 | } |
2934 | 2934 | |
2935 | 2935 | /** |
2936 | - * Set the invoice taxes. |
|
2937 | - * |
|
2938 | - * @since 1.0.19 |
|
2939 | - * @param array $value taxes. |
|
2940 | - */ |
|
2941 | - public function set_taxes( $value ) { |
|
2936 | + * Set the invoice taxes. |
|
2937 | + * |
|
2938 | + * @since 1.0.19 |
|
2939 | + * @param array $value taxes. |
|
2940 | + */ |
|
2941 | + public function set_taxes( $value ) { |
|
2942 | 2942 | |
2943 | - if ( ! is_array( $value ) ) { |
|
2944 | - $value = array(); |
|
2945 | - } |
|
2943 | + if ( ! is_array( $value ) ) { |
|
2944 | + $value = array(); |
|
2945 | + } |
|
2946 | 2946 | |
2947 | - $this->set_prop( 'taxes', $value ); |
|
2947 | + $this->set_prop( 'taxes', $value ); |
|
2948 | 2948 | |
2949 | 2949 | } |
2950 | 2950 | |
2951 | 2951 | /** |
2952 | - * Set the invoice discounts. |
|
2953 | - * |
|
2954 | - * @since 1.0.19 |
|
2955 | - * @param array $value discounts. |
|
2956 | - */ |
|
2957 | - public function set_discounts( $value ) { |
|
2952 | + * Set the invoice discounts. |
|
2953 | + * |
|
2954 | + * @since 1.0.19 |
|
2955 | + * @param array $value discounts. |
|
2956 | + */ |
|
2957 | + public function set_discounts( $value ) { |
|
2958 | 2958 | |
2959 | - if ( ! is_array( $value ) ) { |
|
2960 | - $value = array(); |
|
2961 | - } |
|
2959 | + if ( ! is_array( $value ) ) { |
|
2960 | + $value = array(); |
|
2961 | + } |
|
2962 | 2962 | |
2963 | - $this->set_prop( 'discounts', $value ); |
|
2963 | + $this->set_prop( 'discounts', $value ); |
|
2964 | 2964 | } |
2965 | 2965 | |
2966 | 2966 | /** |
2967 | - * Set the invoice items. |
|
2968 | - * |
|
2969 | - * @since 1.0.19 |
|
2970 | - * @param GetPaid_Form_Item[] $value items. |
|
2971 | - */ |
|
2972 | - public function set_items( $value ) { |
|
2967 | + * Set the invoice items. |
|
2968 | + * |
|
2969 | + * @since 1.0.19 |
|
2970 | + * @param GetPaid_Form_Item[] $value items. |
|
2971 | + */ |
|
2972 | + public function set_items( $value ) { |
|
2973 | 2973 | |
2974 | 2974 | // Remove existing items. |
2975 | 2975 | $this->set_prop( 'items', array() ); |
2976 | - $this->recurring_item = null; |
|
2976 | + $this->recurring_item = null; |
|
2977 | 2977 | |
2978 | 2978 | // Ensure that we have an array. |
2979 | 2979 | if ( ! is_array( $value ) ) { |
@@ -2987,95 +2987,95 @@ discard block |
||
2987 | 2987 | } |
2988 | 2988 | |
2989 | 2989 | /** |
2990 | - * Set the payment form. |
|
2991 | - * |
|
2992 | - * @since 1.0.19 |
|
2993 | - * @param int $value payment form. |
|
2994 | - */ |
|
2995 | - public function set_payment_form( $value ) { |
|
2996 | - $this->set_prop( 'payment_form', $value ); |
|
2990 | + * Set the payment form. |
|
2991 | + * |
|
2992 | + * @since 1.0.19 |
|
2993 | + * @param int $value payment form. |
|
2994 | + */ |
|
2995 | + public function set_payment_form( $value ) { |
|
2996 | + $this->set_prop( 'payment_form', $value ); |
|
2997 | 2997 | } |
2998 | 2998 | |
2999 | 2999 | /** |
3000 | - * Set the submission id. |
|
3001 | - * |
|
3002 | - * @since 1.0.19 |
|
3003 | - * @param string $value submission id. |
|
3004 | - */ |
|
3005 | - public function set_submission_id( $value ) { |
|
3006 | - $this->set_prop( 'submission_id', $value ); |
|
3000 | + * Set the submission id. |
|
3001 | + * |
|
3002 | + * @since 1.0.19 |
|
3003 | + * @param string $value submission id. |
|
3004 | + */ |
|
3005 | + public function set_submission_id( $value ) { |
|
3006 | + $this->set_prop( 'submission_id', $value ); |
|
3007 | 3007 | } |
3008 | 3008 | |
3009 | 3009 | /** |
3010 | - * Set the discount code. |
|
3011 | - * |
|
3012 | - * @since 1.0.19 |
|
3013 | - * @param string $value discount code. |
|
3014 | - */ |
|
3015 | - public function set_discount_code( $value ) { |
|
3016 | - $this->set_prop( 'discount_code', sanitize_text_field( $value ) ); |
|
3010 | + * Set the discount code. |
|
3011 | + * |
|
3012 | + * @since 1.0.19 |
|
3013 | + * @param string $value discount code. |
|
3014 | + */ |
|
3015 | + public function set_discount_code( $value ) { |
|
3016 | + $this->set_prop( 'discount_code', sanitize_text_field( $value ) ); |
|
3017 | 3017 | } |
3018 | 3018 | |
3019 | 3019 | /** |
3020 | - * Set the gateway. |
|
3021 | - * |
|
3022 | - * @since 1.0.19 |
|
3023 | - * @param string $value gateway. |
|
3024 | - */ |
|
3025 | - public function set_gateway( $value ) { |
|
3026 | - $this->set_prop( 'gateway', $value ); |
|
3020 | + * Set the gateway. |
|
3021 | + * |
|
3022 | + * @since 1.0.19 |
|
3023 | + * @param string $value gateway. |
|
3024 | + */ |
|
3025 | + public function set_gateway( $value ) { |
|
3026 | + $this->set_prop( 'gateway', $value ); |
|
3027 | 3027 | } |
3028 | 3028 | |
3029 | 3029 | /** |
3030 | - * Set the transaction id. |
|
3031 | - * |
|
3032 | - * @since 1.0.19 |
|
3033 | - * @param string $value transaction id. |
|
3034 | - */ |
|
3035 | - public function set_transaction_id( $value ) { |
|
3036 | - if ( ! empty( $value ) ) { |
|
3037 | - $this->set_prop( 'transaction_id', $value ); |
|
3038 | - } |
|
3030 | + * Set the transaction id. |
|
3031 | + * |
|
3032 | + * @since 1.0.19 |
|
3033 | + * @param string $value transaction id. |
|
3034 | + */ |
|
3035 | + public function set_transaction_id( $value ) { |
|
3036 | + if ( ! empty( $value ) ) { |
|
3037 | + $this->set_prop( 'transaction_id', $value ); |
|
3038 | + } |
|
3039 | 3039 | } |
3040 | 3040 | |
3041 | 3041 | /** |
3042 | - * Set the currency id. |
|
3043 | - * |
|
3044 | - * @since 1.0.19 |
|
3045 | - * @param string $value currency id. |
|
3046 | - */ |
|
3047 | - public function set_currency( $value ) { |
|
3048 | - $this->set_prop( 'currency', $value ); |
|
3042 | + * Set the currency id. |
|
3043 | + * |
|
3044 | + * @since 1.0.19 |
|
3045 | + * @param string $value currency id. |
|
3046 | + */ |
|
3047 | + public function set_currency( $value ) { |
|
3048 | + $this->set_prop( 'currency', $value ); |
|
3049 | 3049 | } |
3050 | 3050 | |
3051 | - /** |
|
3052 | - * Set whether to disable taxes. |
|
3053 | - * |
|
3054 | - * @since 1.0.19 |
|
3055 | - * @param bool $value value. |
|
3056 | - */ |
|
3057 | - public function set_disable_taxes( $value ) { |
|
3058 | - $this->set_prop( 'disable_taxes', (bool) $value ); |
|
3059 | - } |
|
3051 | + /** |
|
3052 | + * Set whether to disable taxes. |
|
3053 | + * |
|
3054 | + * @since 1.0.19 |
|
3055 | + * @param bool $value value. |
|
3056 | + */ |
|
3057 | + public function set_disable_taxes( $value ) { |
|
3058 | + $this->set_prop( 'disable_taxes', (bool) $value ); |
|
3059 | + } |
|
3060 | 3060 | |
3061 | 3061 | /** |
3062 | - * Set the subscription id. |
|
3063 | - * |
|
3064 | - * @since 1.0.19 |
|
3065 | - * @param string $value subscription id. |
|
3066 | - */ |
|
3067 | - public function set_subscription_id( $value ) { |
|
3068 | - $this->set_prop( 'subscription_id', $value ); |
|
3069 | - } |
|
3062 | + * Set the subscription id. |
|
3063 | + * |
|
3064 | + * @since 1.0.19 |
|
3065 | + * @param string $value subscription id. |
|
3066 | + */ |
|
3067 | + public function set_subscription_id( $value ) { |
|
3068 | + $this->set_prop( 'subscription_id', $value ); |
|
3069 | + } |
|
3070 | 3070 | |
3071 | - /** |
|
3072 | - * Set the remote subscription id. |
|
3073 | - * |
|
3074 | - * @since 1.0.19 |
|
3075 | - * @param string $value subscription id. |
|
3076 | - */ |
|
3077 | - public function set_remote_subscription_id( $value ) { |
|
3078 | - $this->set_prop( 'remote_subscription_id', $value ); |
|
3071 | + /** |
|
3072 | + * Set the remote subscription id. |
|
3073 | + * |
|
3074 | + * @since 1.0.19 |
|
3075 | + * @param string $value subscription id. |
|
3076 | + */ |
|
3077 | + public function set_remote_subscription_id( $value ) { |
|
3078 | + $this->set_prop( 'remote_subscription_id', $value ); |
|
3079 | 3079 | } |
3080 | 3080 | |
3081 | 3081 | /* |
@@ -3114,24 +3114,24 @@ discard block |
||
3114 | 3114 | */ |
3115 | 3115 | public function is_taxable() { |
3116 | 3116 | return ! $this->get_disable_taxes(); |
3117 | - } |
|
3117 | + } |
|
3118 | 3118 | |
3119 | - /** |
|
3120 | - * @deprecated |
|
3121 | - */ |
|
3122 | - public function has_vat() { |
|
3119 | + /** |
|
3120 | + * @deprecated |
|
3121 | + */ |
|
3122 | + public function has_vat() { |
|
3123 | 3123 | return $this->is_taxable(); |
3124 | - } |
|
3124 | + } |
|
3125 | 3125 | |
3126 | - /** |
|
3127 | - * Checks to see if the invoice requires payment. |
|
3128 | - */ |
|
3129 | - public function is_free() { |
|
3126 | + /** |
|
3127 | + * Checks to see if the invoice requires payment. |
|
3128 | + */ |
|
3129 | + public function is_free() { |
|
3130 | 3130 | $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 ); |
3131 | 3131 | |
3132 | - if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
3133 | - $is_free = false; |
|
3134 | - } |
|
3132 | + if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
3133 | + $is_free = false; |
|
3134 | + } |
|
3135 | 3135 | |
3136 | 3136 | return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
3137 | 3137 | } |
@@ -3142,46 +3142,46 @@ discard block |
||
3142 | 3142 | public function is_paid() { |
3143 | 3143 | $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
3144 | 3144 | return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
3145 | - } |
|
3145 | + } |
|
3146 | 3146 | |
3147 | - /** |
|
3147 | + /** |
|
3148 | 3148 | * Checks if the invoice needs payment. |
3149 | 3149 | */ |
3150 | - public function needs_payment() { |
|
3151 | - $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
3150 | + public function needs_payment() { |
|
3151 | + $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
3152 | 3152 | return apply_filters( 'wpinv_needs_payment', $needs_payment, $this ); |
3153 | 3153 | } |
3154 | 3154 | |
3155 | - /** |
|
3155 | + /** |
|
3156 | 3156 | * Checks if the invoice is refunded. |
3157 | 3157 | */ |
3158 | - public function is_refunded() { |
|
3158 | + public function is_refunded() { |
|
3159 | 3159 | $is_refunded = $this->has_status( 'wpi-refunded' ); |
3160 | 3160 | return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
3161 | - } |
|
3161 | + } |
|
3162 | 3162 | |
3163 | - /** |
|
3163 | + /** |
|
3164 | 3164 | * Checks if the invoice is held. |
3165 | 3165 | */ |
3166 | - public function is_held() { |
|
3166 | + public function is_held() { |
|
3167 | 3167 | $is_held = $this->has_status( 'wpi-onhold' ); |
3168 | 3168 | return apply_filters( 'wpinv_invoice_is_held', $is_held, $this ); |
3169 | - } |
|
3169 | + } |
|
3170 | 3170 | |
3171 | - /** |
|
3171 | + /** |
|
3172 | 3172 | * Checks if the invoice is due. |
3173 | 3173 | */ |
3174 | - public function is_due() { |
|
3175 | - $due_date = $this->get_due_date(); |
|
3176 | - return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
3177 | - } |
|
3174 | + public function is_due() { |
|
3175 | + $due_date = $this->get_due_date(); |
|
3176 | + return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
3177 | + } |
|
3178 | 3178 | |
3179 | - /** |
|
3179 | + /** |
|
3180 | 3180 | * Checks if the invoice is draft. |
3181 | 3181 | */ |
3182 | - public function is_draft() { |
|
3182 | + public function is_draft() { |
|
3183 | 3183 | return $this->has_status( 'draft, auto-draft' ); |
3184 | - } |
|
3184 | + } |
|
3185 | 3185 | |
3186 | 3186 | /** |
3187 | 3187 | * Checks if the invoice has a given status. |
@@ -3189,9 +3189,9 @@ discard block |
||
3189 | 3189 | public function has_status( $status ) { |
3190 | 3190 | $status = wpinv_parse_list( $status ); |
3191 | 3191 | return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status ); |
3192 | - } |
|
3192 | + } |
|
3193 | 3193 | |
3194 | - /** |
|
3194 | + /** |
|
3195 | 3195 | * Checks if the invoice is of a given type. |
3196 | 3196 | */ |
3197 | 3197 | public function is_type( $type ) { |
@@ -3214,25 +3214,25 @@ discard block |
||
3214 | 3214 | */ |
3215 | 3215 | public function has_free_trial() { |
3216 | 3216 | return $this->is_recurring() && 0 == $this->get_initial_total(); |
3217 | - } |
|
3217 | + } |
|
3218 | 3218 | |
3219 | - /** |
|
3219 | + /** |
|
3220 | 3220 | * @deprecated |
3221 | 3221 | */ |
3222 | 3222 | public function is_free_trial() { |
3223 | 3223 | $this->has_free_trial(); |
3224 | 3224 | } |
3225 | 3225 | |
3226 | - /** |
|
3226 | + /** |
|
3227 | 3227 | * Check if the initial payment if 0. |
3228 | 3228 | * |
3229 | 3229 | */ |
3230 | - public function is_initial_free() { |
|
3230 | + public function is_initial_free() { |
|
3231 | 3231 | $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 ); |
3232 | 3232 | return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this ); |
3233 | 3233 | } |
3234 | 3234 | |
3235 | - /** |
|
3235 | + /** |
|
3236 | 3236 | * Check if the recurring item has a free trial. |
3237 | 3237 | * |
3238 | 3238 | */ |
@@ -3245,21 +3245,21 @@ discard block |
||
3245 | 3245 | |
3246 | 3246 | $item = $this->get_recurring( true ); |
3247 | 3247 | return $item->has_free_trial(); |
3248 | - } |
|
3248 | + } |
|
3249 | 3249 | |
3250 | - /** |
|
3250 | + /** |
|
3251 | 3251 | * Check if the free trial is a result of a discount. |
3252 | 3252 | */ |
3253 | 3253 | public function is_free_trial_from_discount() { |
3254 | - return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
3255 | - } |
|
3254 | + return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
3255 | + } |
|
3256 | 3256 | |
3257 | - /** |
|
3257 | + /** |
|
3258 | 3258 | * @deprecated |
3259 | 3259 | */ |
3260 | 3260 | public function discount_first_payment_only() { |
3261 | 3261 | |
3262 | - $discount = wpinv_get_discount_obj( $this->get_discount_code() ); |
|
3262 | + $discount = wpinv_get_discount_obj( $this->get_discount_code() ); |
|
3263 | 3263 | if ( ! $discount->exists() || ! $this->is_recurring() ) { |
3264 | 3264 | return true; |
3265 | 3265 | } |
@@ -3284,147 +3284,147 @@ discard block |
||
3284 | 3284 | */ |
3285 | 3285 | public function add_item( $item ) { |
3286 | 3286 | |
3287 | - if ( is_array( $item ) ) { |
|
3288 | - $item = $this->process_array_item( $item ); |
|
3289 | - } |
|
3287 | + if ( is_array( $item ) ) { |
|
3288 | + $item = $this->process_array_item( $item ); |
|
3289 | + } |
|
3290 | 3290 | |
3291 | - if ( is_numeric( $item ) ) { |
|
3292 | - $item = new GetPaid_Form_Item( $item ); |
|
3293 | - } |
|
3291 | + if ( is_numeric( $item ) ) { |
|
3292 | + $item = new GetPaid_Form_Item( $item ); |
|
3293 | + } |
|
3294 | 3294 | |
3295 | 3295 | // Make sure that it is available for purchase. |
3296 | - if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
3297 | - return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
3296 | + if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
3297 | + return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
3298 | 3298 | } |
3299 | 3299 | |
3300 | 3300 | // Do we have a recurring item? |
3301 | - if ( $item->is_recurring() ) { |
|
3302 | - $this->recurring_item = $item->get_id(); |
|
3301 | + if ( $item->is_recurring() ) { |
|
3302 | + $this->recurring_item = $item->get_id(); |
|
3303 | 3303 | } |
3304 | 3304 | |
3305 | 3305 | // Invoice id. |
3306 | 3306 | $item->invoice_id = (int) $this->get_id(); |
3307 | 3307 | |
3308 | - // Remove duplicates. |
|
3309 | - $this->remove_item( $item->get_id() ); |
|
3308 | + // Remove duplicates. |
|
3309 | + $this->remove_item( $item->get_id() ); |
|
3310 | 3310 | |
3311 | - if ( 0 == $item->get_quantity() ) { |
|
3312 | - return; |
|
3313 | - } |
|
3311 | + if ( 0 == $item->get_quantity() ) { |
|
3312 | + return; |
|
3313 | + } |
|
3314 | 3314 | |
3315 | - // Retrieve all items. |
|
3315 | + // Retrieve all items. |
|
3316 | 3316 | $items = $this->get_items(); |
3317 | 3317 | |
3318 | - // Add new item. |
|
3318 | + // Add new item. |
|
3319 | 3319 | $items[] = $item; |
3320 | 3320 | |
3321 | 3321 | $this->set_prop( 'items', $items ); |
3322 | 3322 | |
3323 | - return true; |
|
3324 | - } |
|
3323 | + return true; |
|
3324 | + } |
|
3325 | 3325 | |
3326 | - /** |
|
3327 | - * Converts an array to an item. |
|
3328 | - * |
|
3329 | - * @since 1.0.19 |
|
3330 | - * @return GetPaid_Form_Item |
|
3331 | - */ |
|
3332 | - protected function process_array_item( $array ) { |
|
3326 | + /** |
|
3327 | + * Converts an array to an item. |
|
3328 | + * |
|
3329 | + * @since 1.0.19 |
|
3330 | + * @return GetPaid_Form_Item |
|
3331 | + */ |
|
3332 | + protected function process_array_item( $array ) { |
|
3333 | 3333 | |
3334 | - $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
3335 | - $item = new GetPaid_Form_Item( $item_id ); |
|
3334 | + $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
3335 | + $item = new GetPaid_Form_Item( $item_id ); |
|
3336 | 3336 | |
3337 | - // Set item data. |
|
3338 | - foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
3339 | - if ( isset( $array[ "item_$key" ] ) ) { |
|
3340 | - $method = "set_$key"; |
|
3341 | - $item->$method( $array[ "item_$key" ] ); |
|
3342 | - } |
|
3343 | - } |
|
3337 | + // Set item data. |
|
3338 | + foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
3339 | + if ( isset( $array[ "item_$key" ] ) ) { |
|
3340 | + $method = "set_$key"; |
|
3341 | + $item->$method( $array[ "item_$key" ] ); |
|
3342 | + } |
|
3343 | + } |
|
3344 | 3344 | |
3345 | - if ( isset( $array['quantity'] ) ) { |
|
3346 | - $item->set_quantity( $array['quantity'] ); |
|
3347 | - } |
|
3345 | + if ( isset( $array['quantity'] ) ) { |
|
3346 | + $item->set_quantity( $array['quantity'] ); |
|
3347 | + } |
|
3348 | 3348 | |
3349 | - // Set item meta. |
|
3350 | - if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
3351 | - $item->set_item_meta( $array['meta'] ); |
|
3352 | - } |
|
3349 | + // Set item meta. |
|
3350 | + if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
3351 | + $item->set_item_meta( $array['meta'] ); |
|
3352 | + } |
|
3353 | 3353 | |
3354 | - return $item; |
|
3354 | + return $item; |
|
3355 | 3355 | |
3356 | - } |
|
3356 | + } |
|
3357 | 3357 | |
3358 | 3358 | /** |
3359 | - * Retrieves a specific item. |
|
3360 | - * |
|
3361 | - * @since 1.0.19 |
|
3362 | - * @return GetPaid_Form_Item|null |
|
3363 | - */ |
|
3364 | - public function get_item( $item_id ) { |
|
3359 | + * Retrieves a specific item. |
|
3360 | + * |
|
3361 | + * @since 1.0.19 |
|
3362 | + * @return GetPaid_Form_Item|null |
|
3363 | + */ |
|
3364 | + public function get_item( $item_id ) { |
|
3365 | 3365 | |
3366 | - foreach ( $this->get_items() as $item ) { |
|
3367 | - if ( (int) $item_id == $item->get_id() ) { |
|
3368 | - return $item; |
|
3369 | - } |
|
3370 | - } |
|
3366 | + foreach ( $this->get_items() as $item ) { |
|
3367 | + if ( (int) $item_id == $item->get_id() ) { |
|
3368 | + return $item; |
|
3369 | + } |
|
3370 | + } |
|
3371 | 3371 | |
3372 | - return null; |
|
3372 | + return null; |
|
3373 | 3373 | } |
3374 | 3374 | |
3375 | 3375 | /** |
3376 | - * Removes a specific item. |
|
3377 | - * |
|
3378 | - * @since 1.0.19 |
|
3379 | - */ |
|
3380 | - public function remove_item( $item_id ) { |
|
3381 | - $items = $this->get_items(); |
|
3382 | - $item_id = (int) $item_id; |
|
3376 | + * Removes a specific item. |
|
3377 | + * |
|
3378 | + * @since 1.0.19 |
|
3379 | + */ |
|
3380 | + public function remove_item( $item_id ) { |
|
3381 | + $items = $this->get_items(); |
|
3382 | + $item_id = (int) $item_id; |
|
3383 | 3383 | |
3384 | - foreach ( $items as $index => $item ) { |
|
3385 | - if ( (int) $item_id == $item->get_id() ) { |
|
3386 | - unset( $items[ $index ] ); |
|
3387 | - $this->set_prop( 'items', $items ); |
|
3384 | + foreach ( $items as $index => $item ) { |
|
3385 | + if ( (int) $item_id == $item->get_id() ) { |
|
3386 | + unset( $items[ $index ] ); |
|
3387 | + $this->set_prop( 'items', $items ); |
|
3388 | 3388 | |
3389 | - if ( $item_id == $this->recurring_item ) { |
|
3390 | - $this->recurring_item = null; |
|
3391 | - } |
|
3389 | + if ( $item_id == $this->recurring_item ) { |
|
3390 | + $this->recurring_item = null; |
|
3391 | + } |
|
3392 | 3392 | |
3393 | - } |
|
3394 | - } |
|
3393 | + } |
|
3394 | + } |
|
3395 | 3395 | |
3396 | 3396 | } |
3397 | 3397 | |
3398 | 3398 | /** |
3399 | - * Adds a fee to the invoice. |
|
3400 | - * |
|
3401 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
3402 | - * @since 1.0.19 |
|
3403 | - */ |
|
3399 | + * Adds a fee to the invoice. |
|
3400 | + * |
|
3401 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
3402 | + * @since 1.0.19 |
|
3403 | + */ |
|
3404 | 3404 | public function add_fee( $fee ) { |
3405 | 3405 | |
3406 | - $fees = $this->get_fees(); |
|
3407 | - $fees[ $fee['name'] ] = $fee; |
|
3408 | - $this->set_prop( 'fees', $fees ); |
|
3406 | + $fees = $this->get_fees(); |
|
3407 | + $fees[ $fee['name'] ] = $fee; |
|
3408 | + $this->set_prop( 'fees', $fees ); |
|
3409 | 3409 | |
3410 | 3410 | } |
3411 | 3411 | |
3412 | 3412 | /** |
3413 | - * Retrieves a specific fee. |
|
3414 | - * |
|
3415 | - * @since 1.0.19 |
|
3416 | - */ |
|
3417 | - public function get_fee( $fee ) { |
|
3413 | + * Retrieves a specific fee. |
|
3414 | + * |
|
3415 | + * @since 1.0.19 |
|
3416 | + */ |
|
3417 | + public function get_fee( $fee ) { |
|
3418 | 3418 | $fees = $this->get_fees(); |
3419 | - return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
3419 | + return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
3420 | 3420 | } |
3421 | 3421 | |
3422 | 3422 | /** |
3423 | - * Removes a specific fee. |
|
3424 | - * |
|
3425 | - * @since 1.0.19 |
|
3426 | - */ |
|
3427 | - public function remove_fee( $fee ) { |
|
3423 | + * Removes a specific fee. |
|
3424 | + * |
|
3425 | + * @since 1.0.19 |
|
3426 | + */ |
|
3427 | + public function remove_fee( $fee ) { |
|
3428 | 3428 | $fees = $this->get_fees(); |
3429 | 3429 | if ( isset( $fees[ $fee ] ) ) { |
3430 | 3430 | unset( $fees[ $fee ] ); |
@@ -3432,55 +3432,55 @@ discard block |
||
3432 | 3432 | } |
3433 | 3433 | } |
3434 | 3434 | |
3435 | - /** |
|
3436 | - * Adds a discount to the invoice. |
|
3437 | - * |
|
3438 | - * @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. |
|
3439 | - * @since 1.0.19 |
|
3440 | - */ |
|
3441 | - public function add_discount( $discount ) { |
|
3435 | + /** |
|
3436 | + * Adds a discount to the invoice. |
|
3437 | + * |
|
3438 | + * @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. |
|
3439 | + * @since 1.0.19 |
|
3440 | + */ |
|
3441 | + public function add_discount( $discount ) { |
|
3442 | 3442 | |
3443 | - $discounts = $this->get_discounts(); |
|
3444 | - $discounts[ $discount['name'] ] = $discount; |
|
3445 | - $this->set_prop( 'discounts', $discounts ); |
|
3443 | + $discounts = $this->get_discounts(); |
|
3444 | + $discounts[ $discount['name'] ] = $discount; |
|
3445 | + $this->set_prop( 'discounts', $discounts ); |
|
3446 | 3446 | |
3447 | - } |
|
3447 | + } |
|
3448 | 3448 | |
3449 | 3449 | /** |
3450 | - * Retrieves a specific discount. |
|
3451 | - * |
|
3452 | - * @since 1.0.19 |
|
3453 | - * @return float |
|
3454 | - */ |
|
3455 | - public function get_discount( $discount = false ) { |
|
3450 | + * Retrieves a specific discount. |
|
3451 | + * |
|
3452 | + * @since 1.0.19 |
|
3453 | + * @return float |
|
3454 | + */ |
|
3455 | + public function get_discount( $discount = false ) { |
|
3456 | 3456 | |
3457 | - // Backwards compatibilty. |
|
3458 | - if ( empty( $discount ) ) { |
|
3459 | - return $this->get_total_discount(); |
|
3460 | - } |
|
3457 | + // Backwards compatibilty. |
|
3458 | + if ( empty( $discount ) ) { |
|
3459 | + return $this->get_total_discount(); |
|
3460 | + } |
|
3461 | 3461 | |
3462 | 3462 | $discounts = $this->get_discounts(); |
3463 | - return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
3463 | + return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
3464 | 3464 | } |
3465 | 3465 | |
3466 | 3466 | /** |
3467 | - * Removes a specific discount. |
|
3468 | - * |
|
3469 | - * @since 1.0.19 |
|
3470 | - */ |
|
3471 | - public function remove_discount( $discount ) { |
|
3467 | + * Removes a specific discount. |
|
3468 | + * |
|
3469 | + * @since 1.0.19 |
|
3470 | + */ |
|
3471 | + public function remove_discount( $discount ) { |
|
3472 | 3472 | $discounts = $this->get_discounts(); |
3473 | 3473 | if ( isset( $discounts[ $discount ] ) ) { |
3474 | 3474 | unset( $discounts[ $discount ] ); |
3475 | 3475 | $this->set_prop( 'discounts', $discounts ); |
3476 | 3476 | } |
3477 | 3477 | |
3478 | - if ( 'discount_code' == $discount ) { |
|
3479 | - foreach ( $this->get_items() as $item ) { |
|
3480 | - $item->item_discount = 0; |
|
3481 | - $item->recurring_item_discount = 0; |
|
3482 | - } |
|
3483 | - } |
|
3478 | + if ( 'discount_code' == $discount ) { |
|
3479 | + foreach ( $this->get_items() as $item ) { |
|
3480 | + $item->item_discount = 0; |
|
3481 | + $item->recurring_item_discount = 0; |
|
3482 | + } |
|
3483 | + } |
|
3484 | 3484 | |
3485 | 3485 | } |
3486 | 3486 | |
@@ -3493,34 +3493,34 @@ discard block |
||
3493 | 3493 | if ( $this->is_taxable() ) { |
3494 | 3494 | |
3495 | 3495 | $taxes = $this->get_taxes(); |
3496 | - $taxes[ $tax['name'] ] = $tax; |
|
3497 | - $this->set_prop( 'taxes', $tax ); |
|
3496 | + $taxes[ $tax['name'] ] = $tax; |
|
3497 | + $this->set_prop( 'taxes', $tax ); |
|
3498 | 3498 | |
3499 | 3499 | } |
3500 | 3500 | } |
3501 | 3501 | |
3502 | 3502 | /** |
3503 | - * Retrieves a specific tax. |
|
3504 | - * |
|
3505 | - * @since 1.0.19 |
|
3506 | - */ |
|
3507 | - public function get_tax( $tax = null ) { |
|
3503 | + * Retrieves a specific tax. |
|
3504 | + * |
|
3505 | + * @since 1.0.19 |
|
3506 | + */ |
|
3507 | + public function get_tax( $tax = null ) { |
|
3508 | 3508 | |
3509 | - // Backwards compatility. |
|
3510 | - if ( empty( $tax ) ) { |
|
3511 | - return $this->get_total_tax(); |
|
3512 | - } |
|
3509 | + // Backwards compatility. |
|
3510 | + if ( empty( $tax ) ) { |
|
3511 | + return $this->get_total_tax(); |
|
3512 | + } |
|
3513 | 3513 | |
3514 | 3514 | $taxes = $this->get_taxes(); |
3515 | - return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
3515 | + return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
3516 | 3516 | } |
3517 | 3517 | |
3518 | 3518 | /** |
3519 | - * Removes a specific tax. |
|
3520 | - * |
|
3521 | - * @since 1.0.19 |
|
3522 | - */ |
|
3523 | - public function remove_tax( $tax ) { |
|
3519 | + * Removes a specific tax. |
|
3520 | + * |
|
3521 | + * @since 1.0.19 |
|
3522 | + */ |
|
3523 | + public function remove_tax( $tax ) { |
|
3524 | 3524 | $taxes = $this->get_taxes(); |
3525 | 3525 | if ( isset( $taxes[ $tax ] ) ) { |
3526 | 3526 | unset( $taxes[ $tax ] ); |
@@ -3529,185 +3529,185 @@ discard block |
||
3529 | 3529 | } |
3530 | 3530 | |
3531 | 3531 | /** |
3532 | - * Recalculates the invoice subtotal. |
|
3533 | - * |
|
3534 | - * @since 1.0.19 |
|
3535 | - * @return float The recalculated subtotal |
|
3536 | - */ |
|
3537 | - public function recalculate_subtotal() { |
|
3532 | + * Recalculates the invoice subtotal. |
|
3533 | + * |
|
3534 | + * @since 1.0.19 |
|
3535 | + * @return float The recalculated subtotal |
|
3536 | + */ |
|
3537 | + public function recalculate_subtotal() { |
|
3538 | 3538 | $items = $this->get_items(); |
3539 | - $subtotal = 0; |
|
3540 | - $recurring = 0; |
|
3539 | + $subtotal = 0; |
|
3540 | + $recurring = 0; |
|
3541 | 3541 | |
3542 | 3542 | foreach ( $items as $item ) { |
3543 | - $subtotal += $item->get_sub_total( 'edit' ); |
|
3544 | - $recurring += $item->get_recurring_sub_total( 'edit' ); |
|
3543 | + $subtotal += $item->get_sub_total( 'edit' ); |
|
3544 | + $recurring += $item->get_recurring_sub_total( 'edit' ); |
|
3545 | 3545 | } |
3546 | 3546 | |
3547 | - if ( wpinv_prices_include_tax() ) { |
|
3548 | - $subtotal = max( 0, $subtotal - $this->totals['tax']['initial'] ); |
|
3549 | - $recurring = max( 0, $recurring - $this->totals['tax']['recurring'] ); |
|
3550 | - } |
|
3547 | + if ( wpinv_prices_include_tax() ) { |
|
3548 | + $subtotal = max( 0, $subtotal - $this->totals['tax']['initial'] ); |
|
3549 | + $recurring = max( 0, $recurring - $this->totals['tax']['recurring'] ); |
|
3550 | + } |
|
3551 | 3551 | |
3552 | - $current = $this->is_renewal() ? $recurring : $subtotal; |
|
3553 | - $this->set_subtotal( $current ); |
|
3552 | + $current = $this->is_renewal() ? $recurring : $subtotal; |
|
3553 | + $this->set_subtotal( $current ); |
|
3554 | 3554 | |
3555 | - $this->totals['subtotal'] = array( |
|
3556 | - 'initial' => $subtotal, |
|
3557 | - 'recurring' => $recurring, |
|
3558 | - ); |
|
3555 | + $this->totals['subtotal'] = array( |
|
3556 | + 'initial' => $subtotal, |
|
3557 | + 'recurring' => $recurring, |
|
3558 | + ); |
|
3559 | 3559 | |
3560 | 3560 | return $current; |
3561 | 3561 | } |
3562 | 3562 | |
3563 | 3563 | /** |
3564 | - * Recalculates the invoice discount total. |
|
3565 | - * |
|
3566 | - * @since 1.0.19 |
|
3567 | - * @return float The recalculated discount |
|
3568 | - */ |
|
3569 | - public function recalculate_total_discount() { |
|
3564 | + * Recalculates the invoice discount total. |
|
3565 | + * |
|
3566 | + * @since 1.0.19 |
|
3567 | + * @return float The recalculated discount |
|
3568 | + */ |
|
3569 | + public function recalculate_total_discount() { |
|
3570 | 3570 | $discounts = $this->get_discounts(); |
3571 | - $discount = 0; |
|
3572 | - $recurring = 0; |
|
3571 | + $discount = 0; |
|
3572 | + $recurring = 0; |
|
3573 | 3573 | |
3574 | 3574 | foreach ( $discounts as $data ) { |
3575 | - $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
3576 | - $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
3577 | - } |
|
3575 | + $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
3576 | + $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
3577 | + } |
|
3578 | 3578 | |
3579 | - $current = $this->is_renewal() ? $recurring : $discount; |
|
3579 | + $current = $this->is_renewal() ? $recurring : $discount; |
|
3580 | 3580 | |
3581 | - $this->set_total_discount( $current ); |
|
3581 | + $this->set_total_discount( $current ); |
|
3582 | 3582 | |
3583 | - $this->totals['discount'] = array( |
|
3584 | - 'initial' => $discount, |
|
3585 | - 'recurring' => $recurring, |
|
3586 | - ); |
|
3583 | + $this->totals['discount'] = array( |
|
3584 | + 'initial' => $discount, |
|
3585 | + 'recurring' => $recurring, |
|
3586 | + ); |
|
3587 | 3587 | |
3588 | - return $current; |
|
3588 | + return $current; |
|
3589 | 3589 | |
3590 | 3590 | } |
3591 | 3591 | |
3592 | 3592 | /** |
3593 | - * Recalculates the invoice tax total. |
|
3594 | - * |
|
3595 | - * @since 1.0.19 |
|
3596 | - * @return float The recalculated tax |
|
3597 | - */ |
|
3598 | - public function recalculate_total_tax() { |
|
3593 | + * Recalculates the invoice tax total. |
|
3594 | + * |
|
3595 | + * @since 1.0.19 |
|
3596 | + * @return float The recalculated tax |
|
3597 | + */ |
|
3598 | + public function recalculate_total_tax() { |
|
3599 | 3599 | |
3600 | - // Maybe disable taxes. |
|
3601 | - $vat_number = $this->get_vat_number(); |
|
3602 | - $skip_tax = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number ); |
|
3600 | + // Maybe disable taxes. |
|
3601 | + $vat_number = $this->get_vat_number(); |
|
3602 | + $skip_tax = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number ); |
|
3603 | 3603 | |
3604 | - if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
3605 | - $skip_tax = false; |
|
3606 | - } |
|
3604 | + if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
3605 | + $skip_tax = false; |
|
3606 | + } |
|
3607 | 3607 | |
3608 | - if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax ) { |
|
3608 | + if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax ) { |
|
3609 | 3609 | |
3610 | - $this->totals['tax'] = array( |
|
3611 | - 'initial' => 0, |
|
3612 | - 'recurring' => 0, |
|
3613 | - ); |
|
3610 | + $this->totals['tax'] = array( |
|
3611 | + 'initial' => 0, |
|
3612 | + 'recurring' => 0, |
|
3613 | + ); |
|
3614 | 3614 | |
3615 | - $this->tax_rate = 0; |
|
3615 | + $this->tax_rate = 0; |
|
3616 | 3616 | |
3617 | - $this->set_taxes( array() ); |
|
3618 | - $current = 0; |
|
3619 | - } else { |
|
3617 | + $this->set_taxes( array() ); |
|
3618 | + $current = 0; |
|
3619 | + } else { |
|
3620 | 3620 | |
3621 | - $item_taxes = array(); |
|
3621 | + $item_taxes = array(); |
|
3622 | 3622 | |
3623 | - foreach ( $this->get_items() as $item ) { |
|
3624 | - $rates = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() ); |
|
3625 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
3626 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
3627 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
3628 | - foreach ( $taxes as $name => $amount ) { |
|
3629 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
3630 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
3623 | + foreach ( $this->get_items() as $item ) { |
|
3624 | + $rates = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() ); |
|
3625 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
3626 | + $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
3627 | + $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
3628 | + foreach ( $taxes as $name => $amount ) { |
|
3629 | + $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
3630 | + $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
3631 | 3631 | |
3632 | - if ( ! isset( $item_taxes[ $name ] ) ) { |
|
3633 | - $item_taxes[ $name ] = $tax; |
|
3634 | - continue; |
|
3635 | - } |
|
3632 | + if ( ! isset( $item_taxes[ $name ] ) ) { |
|
3633 | + $item_taxes[ $name ] = $tax; |
|
3634 | + continue; |
|
3635 | + } |
|
3636 | 3636 | |
3637 | - $item_taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
3638 | - $item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
3637 | + $item_taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
3638 | + $item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
3639 | 3639 | |
3640 | - } |
|
3640 | + } |
|
3641 | 3641 | |
3642 | - } |
|
3642 | + } |
|
3643 | 3643 | |
3644 | - $item_taxes = array_replace( $this->get_taxes(), $item_taxes ); |
|
3645 | - $this->set_taxes( $item_taxes ); |
|
3644 | + $item_taxes = array_replace( $this->get_taxes(), $item_taxes ); |
|
3645 | + $this->set_taxes( $item_taxes ); |
|
3646 | 3646 | |
3647 | - $initial_tax = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) ); |
|
3648 | - $recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) ); |
|
3647 | + $initial_tax = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) ); |
|
3648 | + $recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) ); |
|
3649 | 3649 | |
3650 | - $current = $this->is_renewal() ? $recurring_tax : $initial_tax; |
|
3650 | + $current = $this->is_renewal() ? $recurring_tax : $initial_tax; |
|
3651 | 3651 | |
3652 | - $this->totals['tax'] = array( |
|
3653 | - 'initial' => $initial_tax, |
|
3654 | - 'recurring' => $recurring_tax, |
|
3655 | - ); |
|
3652 | + $this->totals['tax'] = array( |
|
3653 | + 'initial' => $initial_tax, |
|
3654 | + 'recurring' => $recurring_tax, |
|
3655 | + ); |
|
3656 | 3656 | |
3657 | - } |
|
3657 | + } |
|
3658 | 3658 | |
3659 | - $this->set_total_tax( $current ); |
|
3659 | + $this->set_total_tax( $current ); |
|
3660 | 3660 | |
3661 | - return $current; |
|
3661 | + return $current; |
|
3662 | 3662 | |
3663 | 3663 | } |
3664 | 3664 | |
3665 | 3665 | /** |
3666 | - * Recalculates the invoice fees total. |
|
3667 | - * |
|
3668 | - * @since 1.0.19 |
|
3669 | - * @return float The recalculated fee |
|
3670 | - */ |
|
3671 | - public function recalculate_total_fees() { |
|
3672 | - $fees = $this->get_fees(); |
|
3673 | - $fee = 0; |
|
3674 | - $recurring = 0; |
|
3666 | + * Recalculates the invoice fees total. |
|
3667 | + * |
|
3668 | + * @since 1.0.19 |
|
3669 | + * @return float The recalculated fee |
|
3670 | + */ |
|
3671 | + public function recalculate_total_fees() { |
|
3672 | + $fees = $this->get_fees(); |
|
3673 | + $fee = 0; |
|
3674 | + $recurring = 0; |
|
3675 | 3675 | |
3676 | 3676 | foreach ( $fees as $data ) { |
3677 | - $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
3678 | - $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
3679 | - } |
|
3677 | + $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
3678 | + $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
3679 | + } |
|
3680 | 3680 | |
3681 | - $current = $this->is_renewal() ? $recurring : $fee; |
|
3682 | - $this->set_total_fees( $current ); |
|
3681 | + $current = $this->is_renewal() ? $recurring : $fee; |
|
3682 | + $this->set_total_fees( $current ); |
|
3683 | 3683 | |
3684 | - $this->totals['fee'] = array( |
|
3685 | - 'initial' => $fee, |
|
3686 | - 'recurring' => $recurring, |
|
3687 | - ); |
|
3684 | + $this->totals['fee'] = array( |
|
3685 | + 'initial' => $fee, |
|
3686 | + 'recurring' => $recurring, |
|
3687 | + ); |
|
3688 | 3688 | |
3689 | 3689 | $this->set_total_fees( $fee ); |
3690 | 3690 | return $current; |
3691 | 3691 | } |
3692 | 3692 | |
3693 | 3693 | /** |
3694 | - * Recalculates the invoice total. |
|
3695 | - * |
|
3696 | - * @since 1.0.19 |
|
3694 | + * Recalculates the invoice total. |
|
3695 | + * |
|
3696 | + * @since 1.0.19 |
|
3697 | 3697 | * @return float The invoice total |
3698 | - */ |
|
3699 | - public function recalculate_total() { |
|
3698 | + */ |
|
3699 | + public function recalculate_total() { |
|
3700 | 3700 | $this->recalculate_total_fees(); |
3701 | 3701 | $this->recalculate_total_discount(); |
3702 | - $this->recalculate_total_tax(); |
|
3703 | - $this->recalculate_subtotal(); |
|
3704 | - $this->set_total( $this->get_total_tax( 'edit' ) + $this->get_total_fees( 'edit' ) + $this->get_subtotal( 'edit' ) - $this->get_total_discount( 'edit' ) ); |
|
3705 | - return $this->get_total(); |
|
3706 | - } |
|
3707 | - |
|
3708 | - /** |
|
3709 | - * @deprecated |
|
3710 | - */ |
|
3702 | + $this->recalculate_total_tax(); |
|
3703 | + $this->recalculate_subtotal(); |
|
3704 | + $this->set_total( $this->get_total_tax( 'edit' ) + $this->get_total_fees( 'edit' ) + $this->get_subtotal( 'edit' ) - $this->get_total_discount( 'edit' ) ); |
|
3705 | + return $this->get_total(); |
|
3706 | + } |
|
3707 | + |
|
3708 | + /** |
|
3709 | + * @deprecated |
|
3710 | + */ |
|
3711 | 3711 | public function recalculate_totals() { |
3712 | 3712 | $this->recalculate_total(); |
3713 | 3713 | $this->save( true ); |
@@ -3721,22 +3721,22 @@ discard block |
||
3721 | 3721 | return $this->get_data(); |
3722 | 3722 | } |
3723 | 3723 | |
3724 | - /** |
|
3724 | + /** |
|
3725 | 3725 | * Adds a system note to an invoice. |
3726 | 3726 | * |
3727 | 3727 | * @param string $note The note being added. |
3728 | - * @return int|false The new note's ID on success, false on failure. |
|
3728 | + * @return int|false The new note's ID on success, false on failure. |
|
3729 | 3729 | * |
3730 | 3730 | */ |
3731 | 3731 | public function add_system_note( $note ) { |
3732 | - return $this->add_note( $note, false, false, true ); |
|
3733 | - } |
|
3732 | + return $this->add_note( $note, false, false, true ); |
|
3733 | + } |
|
3734 | 3734 | |
3735 | 3735 | /** |
3736 | 3736 | * Adds a note to an invoice. |
3737 | 3737 | * |
3738 | 3738 | * @param string $note The note being added. |
3739 | - * @return int|false The new note's ID on success, false on failure. |
|
3739 | + * @return int|false The new note's ID on success, false on failure. |
|
3740 | 3740 | * |
3741 | 3741 | */ |
3742 | 3742 | public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
@@ -3746,21 +3746,21 @@ discard block |
||
3746 | 3746 | return false; |
3747 | 3747 | } |
3748 | 3748 | |
3749 | - $author = 'System'; |
|
3750 | - $author_email = '[email protected]'; |
|
3749 | + $author = 'System'; |
|
3750 | + $author_email = '[email protected]'; |
|
3751 | 3751 | |
3752 | - // If this is an admin comment or it has been added by the user. |
|
3753 | - if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
3754 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
3752 | + // If this is an admin comment or it has been added by the user. |
|
3753 | + if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
3754 | + $user = get_user_by( 'id', get_current_user_id() ); |
|
3755 | 3755 | $author = $user->display_name; |
3756 | 3756 | $author_email = $user->user_email; |
3757 | - } |
|
3757 | + } |
|
3758 | 3758 | |
3759 | - return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
3759 | + return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
3760 | 3760 | |
3761 | - } |
|
3761 | + } |
|
3762 | 3762 | |
3763 | - /** |
|
3763 | + /** |
|
3764 | 3764 | * Generates a unique key for the invoice. |
3765 | 3765 | */ |
3766 | 3766 | public function generate_key( $string = '' ) { |
@@ -3780,113 +3780,113 @@ discard block |
||
3780 | 3780 | $number = wpinv_get_next_invoice_number( $this->get_post_type() ); |
3781 | 3781 | } |
3782 | 3782 | |
3783 | - return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
3784 | - |
|
3785 | - } |
|
3786 | - |
|
3787 | - /** |
|
3788 | - * Handle the status transition. |
|
3789 | - */ |
|
3790 | - protected function status_transition() { |
|
3791 | - $status_transition = $this->status_transition; |
|
3792 | - |
|
3793 | - // Reset status transition variable. |
|
3794 | - $this->status_transition = false; |
|
3783 | + return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
3795 | 3784 | |
3796 | - if ( $status_transition ) { |
|
3797 | - try { |
|
3798 | - |
|
3799 | - // Fire a hook for the status change. |
|
3800 | - do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
3801 | - |
|
3802 | - // @deprecated this is deprecated and will be removed in the future. |
|
3803 | - do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3804 | - |
|
3805 | - if ( ! empty( $status_transition['from'] ) ) { |
|
3806 | - |
|
3807 | - /* translators: 1: old invoice status 2: new invoice status */ |
|
3808 | - $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 ) ); |
|
3809 | - |
|
3810 | - // Fire another hook. |
|
3811 | - do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
3812 | - do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
3813 | - |
|
3814 | - // @deprecated this is deprecated and will be removed in the future. |
|
3815 | - do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3816 | - |
|
3817 | - // Note the transition occurred. |
|
3818 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
3819 | - |
|
3820 | - // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
3821 | - if ( |
|
3822 | - in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
3823 | - && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3824 | - ) { |
|
3825 | - do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
3826 | - } |
|
3827 | - |
|
3828 | - // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
|
3829 | - if ( |
|
3830 | - in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3831 | - && in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
3832 | - ) { |
|
3833 | - do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
3834 | - } |
|
3835 | - } else { |
|
3836 | - /* translators: %s: new invoice status */ |
|
3837 | - $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
3838 | - |
|
3839 | - // Note the transition occurred. |
|
3840 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
3785 | + } |
|
3841 | 3786 | |
3842 | - } |
|
3843 | - } catch ( Exception $e ) { |
|
3844 | - $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
3845 | - } |
|
3846 | - } |
|
3847 | - } |
|
3787 | + /** |
|
3788 | + * Handle the status transition. |
|
3789 | + */ |
|
3790 | + protected function status_transition() { |
|
3791 | + $status_transition = $this->status_transition; |
|
3792 | + |
|
3793 | + // Reset status transition variable. |
|
3794 | + $this->status_transition = false; |
|
3795 | + |
|
3796 | + if ( $status_transition ) { |
|
3797 | + try { |
|
3798 | + |
|
3799 | + // Fire a hook for the status change. |
|
3800 | + do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
3801 | + |
|
3802 | + // @deprecated this is deprecated and will be removed in the future. |
|
3803 | + do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3804 | + |
|
3805 | + if ( ! empty( $status_transition['from'] ) ) { |
|
3806 | + |
|
3807 | + /* translators: 1: old invoice status 2: new invoice status */ |
|
3808 | + $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 ) ); |
|
3809 | + |
|
3810 | + // Fire another hook. |
|
3811 | + do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
3812 | + do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
3813 | + |
|
3814 | + // @deprecated this is deprecated and will be removed in the future. |
|
3815 | + do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3816 | + |
|
3817 | + // Note the transition occurred. |
|
3818 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
3819 | + |
|
3820 | + // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
3821 | + if ( |
|
3822 | + in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
3823 | + && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3824 | + ) { |
|
3825 | + do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
3826 | + } |
|
3827 | + |
|
3828 | + // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
|
3829 | + if ( |
|
3830 | + in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3831 | + && in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
3832 | + ) { |
|
3833 | + do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
3834 | + } |
|
3835 | + } else { |
|
3836 | + /* translators: %s: new invoice status */ |
|
3837 | + $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
3838 | + |
|
3839 | + // Note the transition occurred. |
|
3840 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
3841 | + |
|
3842 | + } |
|
3843 | + } catch ( Exception $e ) { |
|
3844 | + $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
3845 | + } |
|
3846 | + } |
|
3847 | + } |
|
3848 | 3848 | |
3849 | - /** |
|
3850 | - * Updates an invoice status. |
|
3851 | - */ |
|
3852 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
3849 | + /** |
|
3850 | + * Updates an invoice status. |
|
3851 | + */ |
|
3852 | + public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
3853 | 3853 | |
3854 | - // Fires before updating a status. |
|
3855 | - do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
3854 | + // Fires before updating a status. |
|
3855 | + do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
3856 | 3856 | |
3857 | - // Update the status. |
|
3858 | - $this->set_status( $new_status, $note, $manual ); |
|
3857 | + // Update the status. |
|
3858 | + $this->set_status( $new_status, $note, $manual ); |
|
3859 | 3859 | |
3860 | - // Save the order. |
|
3861 | - return $this->save(); |
|
3860 | + // Save the order. |
|
3861 | + return $this->save(); |
|
3862 | 3862 | |
3863 | - } |
|
3863 | + } |
|
3864 | 3864 | |
3865 | - /** |
|
3866 | - * @deprecated |
|
3867 | - */ |
|
3868 | - public function refresh_item_ids() { |
|
3865 | + /** |
|
3866 | + * @deprecated |
|
3867 | + */ |
|
3868 | + public function refresh_item_ids() { |
|
3869 | 3869 | $item_ids = implode( ',', array_unique( wp_list_pluck( $this->get_cart_details(), 'item_id' ) ) ); |
3870 | 3870 | update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids ); |
3871 | - } |
|
3871 | + } |
|
3872 | 3872 | |
3873 | - /** |
|
3874 | - * @deprecated |
|
3875 | - */ |
|
3876 | - public function update_items( $temp = false ) { |
|
3873 | + /** |
|
3874 | + * @deprecated |
|
3875 | + */ |
|
3876 | + public function update_items( $temp = false ) { |
|
3877 | 3877 | |
3878 | - $this->set_items( $this->get_items() ); |
|
3878 | + $this->set_items( $this->get_items() ); |
|
3879 | 3879 | |
3880 | - if ( ! $temp ) { |
|
3881 | - $this->save(); |
|
3882 | - } |
|
3880 | + if ( ! $temp ) { |
|
3881 | + $this->save(); |
|
3882 | + } |
|
3883 | 3883 | |
3884 | 3884 | return $this; |
3885 | - } |
|
3885 | + } |
|
3886 | 3886 | |
3887 | - /** |
|
3888 | - * @deprecated |
|
3889 | - */ |
|
3887 | + /** |
|
3888 | + * @deprecated |
|
3889 | + */ |
|
3890 | 3890 | public function validate_discount() { |
3891 | 3891 | |
3892 | 3892 | $discount_code = $this->get_discount_code(); |
@@ -3902,93 +3902,93 @@ discard block |
||
3902 | 3902 | |
3903 | 3903 | } |
3904 | 3904 | |
3905 | - /** |
|
3906 | - * Refunds an invoice. |
|
3907 | - */ |
|
3905 | + /** |
|
3906 | + * Refunds an invoice. |
|
3907 | + */ |
|
3908 | 3908 | public function refund() { |
3909 | - $this->set_status( 'wpi-refunded' ); |
|
3909 | + $this->set_status( 'wpi-refunded' ); |
|
3910 | 3910 | $this->save(); |
3911 | - } |
|
3911 | + } |
|
3912 | 3912 | |
3913 | - /** |
|
3914 | - * Marks an invoice as paid. |
|
3915 | - * |
|
3916 | - * @param string $transaction_id |
|
3917 | - */ |
|
3913 | + /** |
|
3914 | + * Marks an invoice as paid. |
|
3915 | + * |
|
3916 | + * @param string $transaction_id |
|
3917 | + */ |
|
3918 | 3918 | public function mark_paid( $transaction_id = null, $note = '' ) { |
3919 | 3919 | |
3920 | - // Set the transaction id. |
|
3921 | - if ( empty( $transaction_id ) ) { |
|
3922 | - $transaction_id = $this->generate_key('trans_'); |
|
3923 | - } |
|
3920 | + // Set the transaction id. |
|
3921 | + if ( empty( $transaction_id ) ) { |
|
3922 | + $transaction_id = $this->generate_key('trans_'); |
|
3923 | + } |
|
3924 | 3924 | |
3925 | - if ( ! $this->get_transaction_id() ) { |
|
3926 | - $this->set_transaction_id( $transaction_id ); |
|
3927 | - } |
|
3925 | + if ( ! $this->get_transaction_id() ) { |
|
3926 | + $this->set_transaction_id( $transaction_id ); |
|
3927 | + } |
|
3928 | 3928 | |
3929 | - if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) { |
|
3930 | - return $this->save(); |
|
3931 | - } |
|
3929 | + if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) { |
|
3930 | + return $this->save(); |
|
3931 | + } |
|
3932 | 3932 | |
3933 | - // Set the completed date. |
|
3934 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
3933 | + // Set the completed date. |
|
3934 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
3935 | 3935 | |
3936 | - // Set the new status. |
|
3937 | - $gateway = sanitize_text_field( $this->get_gateway_title() ); |
|
3938 | - if ( $this->is_renewal() || ! $this->is_parent() ) { |
|
3936 | + // Set the new status. |
|
3937 | + $gateway = sanitize_text_field( $this->get_gateway_title() ); |
|
3938 | + if ( $this->is_renewal() || ! $this->is_parent() ) { |
|
3939 | 3939 | |
3940 | - $_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway ); |
|
3941 | - $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
3940 | + $_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway ); |
|
3941 | + $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
3942 | 3942 | |
3943 | - if ( 'none' == $this->get_gateway() ) { |
|
3944 | - $_note = $note; |
|
3945 | - } |
|
3943 | + if ( 'none' == $this->get_gateway() ) { |
|
3944 | + $_note = $note; |
|
3945 | + } |
|
3946 | 3946 | |
3947 | - $this->set_status( 'wpi-renewal', $_note ); |
|
3947 | + $this->set_status( 'wpi-renewal', $_note ); |
|
3948 | 3948 | |
3949 | - } else { |
|
3949 | + } else { |
|
3950 | 3950 | |
3951 | - $_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway ); |
|
3952 | - $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
3951 | + $_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway ); |
|
3952 | + $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
3953 | 3953 | |
3954 | - if ( 'none' == $this->get_gateway() ) { |
|
3955 | - $_note = $note; |
|
3956 | - } |
|
3954 | + if ( 'none' == $this->get_gateway() ) { |
|
3955 | + $_note = $note; |
|
3956 | + } |
|
3957 | 3957 | |
3958 | - $this->set_status( 'publish', $_note ); |
|
3958 | + $this->set_status( 'publish', $_note ); |
|
3959 | 3959 | |
3960 | - } |
|
3960 | + } |
|
3961 | 3961 | |
3962 | - // Set checkout mode. |
|
3963 | - $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
3964 | - $this->set_mode( $mode ); |
|
3962 | + // Set checkout mode. |
|
3963 | + $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
3964 | + $this->set_mode( $mode ); |
|
3965 | 3965 | |
3966 | - // Save the invoice. |
|
3966 | + // Save the invoice. |
|
3967 | 3967 | $this->save(); |
3968 | - } |
|
3969 | - |
|
3970 | - /** |
|
3971 | - * Save data to the database. |
|
3972 | - * |
|
3973 | - * @since 1.0.19 |
|
3974 | - * @return int invoice ID |
|
3975 | - */ |
|
3976 | - public function save() { |
|
3977 | - $this->maybe_set_date_paid(); |
|
3978 | - $this->maybe_set_key(); |
|
3979 | - parent::save(); |
|
3980 | - $this->clear_cache(); |
|
3981 | - $this->status_transition(); |
|
3982 | - return $this->get_id(); |
|
3983 | - } |
|
3984 | - |
|
3985 | - /** |
|
3968 | + } |
|
3969 | + |
|
3970 | + /** |
|
3971 | + * Save data to the database. |
|
3972 | + * |
|
3973 | + * @since 1.0.19 |
|
3974 | + * @return int invoice ID |
|
3975 | + */ |
|
3976 | + public function save() { |
|
3977 | + $this->maybe_set_date_paid(); |
|
3978 | + $this->maybe_set_key(); |
|
3979 | + parent::save(); |
|
3980 | + $this->clear_cache(); |
|
3981 | + $this->status_transition(); |
|
3982 | + return $this->get_id(); |
|
3983 | + } |
|
3984 | + |
|
3985 | + /** |
|
3986 | 3986 | * Clears the subscription's cache. |
3987 | 3987 | */ |
3988 | 3988 | public function clear_cache() { |
3989 | - wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
3990 | - wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
3991 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
3992 | - } |
|
3989 | + wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
3990 | + wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
3991 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
3992 | + } |
|
3993 | 3993 | |
3994 | 3994 | } |