@@ -168,6 +168,9 @@ discard block |
||
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | + /** |
|
| 172 | + * @param integer $code |
|
| 173 | + */ |
|
| 171 | 174 | public function send_status( $code ) { |
| 172 | 175 | status_header( $code ); |
| 173 | 176 | } |
@@ -320,6 +323,10 @@ discard block |
||
| 320 | 323 | class WPInv_API_Exception extends Exception { |
| 321 | 324 | protected $error_code; |
| 322 | 325 | |
| 326 | + /** |
|
| 327 | + * @param string $error_code |
|
| 328 | + * @param integer $http_status_code |
|
| 329 | + */ |
|
| 323 | 330 | public function __construct( $error_code, $error_message, $http_status_code ) { |
| 324 | 331 | $this->error_code = $error_code; |
| 325 | 332 | parent::__construct( $error_message, $http_status_code ); |
@@ -7,22 +7,22 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | class WPInv_API { |
| 15 | 15 | protected $post_type = 'wpi_invoice'; |
| 16 | 16 | |
| 17 | - public function __construct( $params = array() ) { |
|
| 17 | + public function __construct($params = array()) { |
|
| 18 | 18 | } |
| 19 | - public function insert_invoice( $data ) { |
|
| 19 | + public function insert_invoice($data) { |
|
| 20 | 20 | global $wpdb; |
| 21 | 21 | //wpinv_transaction_query( 'start' ); |
| 22 | 22 | |
| 23 | 23 | try { |
| 24 | - if ( ! isset( $data['invoice'] ) ) { |
|
| 25 | - throw new WPInv_API_Exception( 'wpinv_api_missing_invoice_data', sprintf( __( 'No %1$s data specified to create %1$s', 'invoicing' ), 'invoice' ), 400 ); |
|
| 24 | + if (!isset($data['invoice'])) { |
|
| 25 | + throw new WPInv_API_Exception('wpinv_api_missing_invoice_data', sprintf(__('No %1$s data specified to create %1$s', 'invoicing'), 'invoice'), 400); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | $data = $data['invoice']; |
@@ -32,37 +32,37 @@ discard block |
||
| 32 | 32 | //throw new WPInv_API_Exception( 'wpinv_api_user_cannot_create_invoice', __( 'You do not have permission to create invoices', 'invoicing' ), 401 ); |
| 33 | 33 | //} |
| 34 | 34 | |
| 35 | - $data = apply_filters( 'wpinv_api_create_invoice_data', $data, $this ); |
|
| 35 | + $data = apply_filters('wpinv_api_create_invoice_data', $data, $this); |
|
| 36 | 36 | |
| 37 | - $invoice = wpinv_insert_invoice( $data ); |
|
| 38 | - if ( is_wp_error( $invoice ) ) { |
|
| 39 | - throw new WPInv_API_Exception( 'wpinv_api_cannot_create_invoice', sprintf( __( 'Cannot create invoice: %s', 'invoicing' ), implode( ', ', $invoice->get_error_messages() ) ), 400 ); |
|
| 37 | + $invoice = wpinv_insert_invoice($data); |
|
| 38 | + if (is_wp_error($invoice)) { |
|
| 39 | + throw new WPInv_API_Exception('wpinv_api_cannot_create_invoice', sprintf(__('Cannot create invoice: %s', 'invoicing'), implode(', ', $invoice->get_error_messages())), 400); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | // HTTP 201 Created |
| 43 | - $this->send_status( 201 ); |
|
| 43 | + $this->send_status(201); |
|
| 44 | 44 | |
| 45 | - do_action( 'wpinv_api_create_invoice', $invoice->ID, $data, $this ); |
|
| 45 | + do_action('wpinv_api_create_invoice', $invoice->ID, $data, $this); |
|
| 46 | 46 | |
| 47 | 47 | //wpinv_transaction_query( 'commit' ); |
| 48 | 48 | |
| 49 | - return wpinv_get_invoice( $invoice->ID ); |
|
| 49 | + return wpinv_get_invoice($invoice->ID); |
|
| 50 | 50 | |
| 51 | - } catch ( WPInv_API_Exception $e ) { |
|
| 51 | + } catch (WPInv_API_Exception $e) { |
|
| 52 | 52 | |
| 53 | 53 | //wpinv_transaction_query( 'rollback' ); |
| 54 | 54 | |
| 55 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
| 55 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - public function create_invoice( $data ) { |
|
| 59 | + public function create_invoice($data) { |
|
| 60 | 60 | global $wpdb; |
| 61 | 61 | //wpinv_transaction_query( 'start' ); |
| 62 | 62 | |
| 63 | 63 | try { |
| 64 | - if ( ! isset( $data['invoice'] ) ) { |
|
| 65 | - throw new WPInv_API_Exception( 'wpinv_api_missing_invoice_data', sprintf( __( 'No %1$s data specified to create %1$s', 'invoicing' ), 'invoice' ), 400 ); |
|
| 64 | + if (!isset($data['invoice'])) { |
|
| 65 | + throw new WPInv_API_Exception('wpinv_api_missing_invoice_data', sprintf(__('No %1$s data specified to create %1$s', 'invoicing'), 'invoice'), 400); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | $data = $data['invoice']; |
@@ -72,111 +72,111 @@ discard block |
||
| 72 | 72 | //throw new WPInv_API_Exception( 'wpinv_api_user_cannot_create_invoice', __( 'You do not have permission to create invoices', 'invoicing' ), 401 ); |
| 73 | 73 | //} |
| 74 | 74 | |
| 75 | - $data = apply_filters( 'wpinv_api_create_invoice_data', $data, $this ); |
|
| 75 | + $data = apply_filters('wpinv_api_create_invoice_data', $data, $this); |
|
| 76 | 76 | |
| 77 | 77 | // default invoice args, note that status is checked for validity in wpinv_create_invoice() |
| 78 | 78 | $default_invoice_args = array( |
| 79 | - 'status' => isset( $data['status'] ) ? $data['status'] : '', |
|
| 80 | - 'user_note' => isset( $data['note'] ) ? $data['note'] : null, |
|
| 81 | - 'invoice_id' => isset( $data['invoice_id'] ) ? (int)$data['invoice_id'] : 0, |
|
| 79 | + 'status' => isset($data['status']) ? $data['status'] : '', |
|
| 80 | + 'user_note' => isset($data['note']) ? $data['note'] : null, |
|
| 81 | + 'invoice_id' => isset($data['invoice_id']) ? (int)$data['invoice_id'] : 0, |
|
| 82 | 82 | ); |
| 83 | 83 | |
| 84 | 84 | // if creating invoice for existing user |
| 85 | - if ( ! empty( $data['user_id'] ) ) { |
|
| 85 | + if (!empty($data['user_id'])) { |
|
| 86 | 86 | // make sure user exists |
| 87 | - if ( false === get_user_by( 'id', $data['user_id'] ) ) { |
|
| 88 | - throw new WPInv_API_Exception( 'wpinv_api_invalid_user_id', __( 'User ID is invalid', 'invoicing' ), 400 ); |
|
| 87 | + if (false === get_user_by('id', $data['user_id'])) { |
|
| 88 | + throw new WPInv_API_Exception('wpinv_api_invalid_user_id', __('User ID is invalid', 'invoicing'), 400); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | $default_invoice_args['user_id'] = $data['user_id']; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | // create the pending invoice |
| 95 | - $invoice = $this->create_base_invoice( $default_invoice_args, $data ); |
|
| 95 | + $invoice = $this->create_base_invoice($default_invoice_args, $data); |
|
| 96 | 96 | |
| 97 | - if ( is_wp_error( $invoice ) ) { |
|
| 98 | - throw new WPInv_API_Exception( 'wpinv_api_cannot_create_invoice', sprintf( __( 'Cannot create invoice: %s', 'invoicing' ), implode( ', ', $invoice->get_error_messages() ) ), 400 ); |
|
| 97 | + if (is_wp_error($invoice)) { |
|
| 98 | + throw new WPInv_API_Exception('wpinv_api_cannot_create_invoice', sprintf(__('Cannot create invoice: %s', 'invoicing'), implode(', ', $invoice->get_error_messages())), 400); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // Add note |
| 102 | - if ( !empty( $data['user_note'] ) ) { |
|
| 103 | - $invoice->add_note( $data['user_note'], true ); |
|
| 102 | + if (!empty($data['user_note'])) { |
|
| 103 | + $invoice->add_note($data['user_note'], true); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - if ( !empty( $data['private_note'] ) ) { |
|
| 107 | - $invoice->add_note( $data['private_note'] ); |
|
| 106 | + if (!empty($data['private_note'])) { |
|
| 107 | + $invoice->add_note($data['private_note']); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | // billing address |
| 111 | - $invoice = $this->set_billing_details( $invoice, $data ); |
|
| 111 | + $invoice = $this->set_billing_details($invoice, $data); |
|
| 112 | 112 | |
| 113 | 113 | // items |
| 114 | - $invoice = $this->set_discount( $invoice, $data ); |
|
| 114 | + $invoice = $this->set_discount($invoice, $data); |
|
| 115 | 115 | |
| 116 | 116 | // items |
| 117 | - $invoice = $this->set_items( $invoice, $data ); |
|
| 117 | + $invoice = $this->set_items($invoice, $data); |
|
| 118 | 118 | |
| 119 | 119 | // payment method (and payment_complete() if `paid` == true) |
| 120 | - if ( isset( $data['payment_details'] ) && is_array( $data['payment_details'] ) ) { |
|
| 120 | + if (isset($data['payment_details']) && is_array($data['payment_details'])) { |
|
| 121 | 121 | // method ID & title are required |
| 122 | - if ( empty( $data['payment_details']['method_id'] ) || empty( $data['payment_details']['method_title'] ) ) { |
|
| 123 | - throw new WPInv_API_Exception( 'wpinv_invalid_payment_details', __( 'Payment method ID and title are required', 'invoicing' ), 400 ); |
|
| 122 | + if (empty($data['payment_details']['method_id']) || empty($data['payment_details']['method_title'])) { |
|
| 123 | + throw new WPInv_API_Exception('wpinv_invalid_payment_details', __('Payment method ID and title are required', 'invoicing'), 400); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // set invoice currency |
| 127 | - if ( isset( $data['payment_details']['currency'] ) ) { |
|
| 128 | - if ( ! array_key_exists( $data['payment_details']['currency'], wpinv_get_currencies() ) ) { |
|
| 129 | - throw new WPInv_API_Exception( 'wpinv_invalid_invoice_currency', __( 'Provided invoice currency is invalid', 'invoicing' ), 400 ); |
|
| 127 | + if (isset($data['payment_details']['currency'])) { |
|
| 128 | + if (!array_key_exists($data['payment_details']['currency'], wpinv_get_currencies())) { |
|
| 129 | + throw new WPInv_API_Exception('wpinv_invalid_invoice_currency', __('Provided invoice currency is invalid', 'invoicing'), 400); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - update_post_meta( $invoice->ID, '_wpinv_currency', $data['payment_details']['currency'] ); |
|
| 132 | + update_post_meta($invoice->ID, '_wpinv_currency', $data['payment_details']['currency']); |
|
| 133 | 133 | |
| 134 | 134 | $invoice->currency = $data['payment_details']['currency']; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - update_post_meta( $invoice->ID, '_wpinv_gateway', $data['payment_details']['method_id'] ); |
|
| 138 | - update_post_meta( $invoice->ID, '_wpinv_gateway_title', $data['payment_details']['method_title'] ); |
|
| 137 | + update_post_meta($invoice->ID, '_wpinv_gateway', $data['payment_details']['method_id']); |
|
| 138 | + update_post_meta($invoice->ID, '_wpinv_gateway_title', $data['payment_details']['method_title']); |
|
| 139 | 139 | |
| 140 | 140 | $invoice->gateway = $data['payment_details']['method_id']; |
| 141 | 141 | $invoice->gateway_title = $data['payment_details']['method_title']; |
| 142 | 142 | |
| 143 | 143 | // mark as paid if set |
| 144 | - if ( isset( $data['payment_details']['paid'] ) && true === $data['payment_details']['paid'] ) { |
|
| 144 | + if (isset($data['payment_details']['paid']) && true === $data['payment_details']['paid']) { |
|
| 145 | 145 | //$invoice->payment_complete( isset( $data['payment_details']['transaction_id'] ) ? $data['payment_details']['transaction_id'] : $invoice->ID ); |
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | // set invoice meta |
| 150 | - if ( isset( $data['invoice_meta'] ) && is_array( $data['invoice_meta'] ) ) { |
|
| 151 | - $this->set_invoice_meta( $invoice->ID, $data['invoice_meta'] ); |
|
| 150 | + if (isset($data['invoice_meta']) && is_array($data['invoice_meta'])) { |
|
| 151 | + $this->set_invoice_meta($invoice->ID, $data['invoice_meta']); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | // HTTP 201 Created |
| 155 | - $this->send_status( 201 ); |
|
| 155 | + $this->send_status(201); |
|
| 156 | 156 | |
| 157 | - do_action( 'wpinv_api_create_invoice', $invoice->ID, $data, $this ); |
|
| 157 | + do_action('wpinv_api_create_invoice', $invoice->ID, $data, $this); |
|
| 158 | 158 | |
| 159 | 159 | //wpinv_transaction_query( 'commit' ); |
| 160 | 160 | |
| 161 | - return wpinv_get_invoice( $invoice->ID ); |
|
| 161 | + return wpinv_get_invoice($invoice->ID); |
|
| 162 | 162 | |
| 163 | - } catch ( WPInv_API_Exception $e ) { |
|
| 163 | + } catch (WPInv_API_Exception $e) { |
|
| 164 | 164 | |
| 165 | 165 | //wpinv_transaction_query( 'rollback' ); |
| 166 | 166 | |
| 167 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
| 167 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - public function send_status( $code ) { |
|
| 172 | - status_header( $code ); |
|
| 171 | + public function send_status($code) { |
|
| 172 | + status_header($code); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - protected function create_base_invoice( $args, $data ) { |
|
| 176 | - return wpinv_create_invoice( $args, $data ); |
|
| 175 | + protected function create_base_invoice($args, $data) { |
|
| 176 | + return wpinv_create_invoice($args, $data); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - protected function set_billing_details( $invoice, $data ) { |
|
| 179 | + protected function set_billing_details($invoice, $data) { |
|
| 180 | 180 | $address_fields = array( |
| 181 | 181 | 'user_id', |
| 182 | 182 | 'first_name', |
@@ -195,66 +195,66 @@ discard block |
||
| 195 | 195 | $billing_details = array(); |
| 196 | 196 | $user_id = $invoice->get_user_id(); |
| 197 | 197 | |
| 198 | - foreach ( $address_fields as $field ) { |
|
| 199 | - if ( isset( $data['billing_details'][ $field ] ) ) { |
|
| 200 | - $value = sanitize_text_field( $data['billing_details'][ $field ] ); |
|
| 198 | + foreach ($address_fields as $field) { |
|
| 199 | + if (isset($data['billing_details'][$field])) { |
|
| 200 | + $value = sanitize_text_field($data['billing_details'][$field]); |
|
| 201 | 201 | |
| 202 | - if ( $field == 'country' && empty( $value ) ) { |
|
| 203 | - if ( !empty( $invoice->country ) ) { |
|
| 202 | + if ($field == 'country' && empty($value)) { |
|
| 203 | + if (!empty($invoice->country)) { |
|
| 204 | 204 | $value = $invoice->country; |
| 205 | 205 | } else { |
| 206 | - $value = wpinv_default_billing_country( '', $user_id ); |
|
| 206 | + $value = wpinv_default_billing_country('', $user_id); |
|
| 207 | 207 | } |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - if ( $field == 'state' && empty( $value ) ) { |
|
| 211 | - if ( !empty( $invoice->state ) ) { |
|
| 210 | + if ($field == 'state' && empty($value)) { |
|
| 211 | + if (!empty($invoice->state)) { |
|
| 212 | 212 | $value = $invoice->state; |
| 213 | 213 | } else { |
| 214 | 214 | $value = wpinv_get_default_state(); |
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - $invoice->set( $field, $value ); |
|
| 218 | + $invoice->set($field, $value); |
|
| 219 | 219 | |
| 220 | - update_post_meta( $invoice->ID, '_wpinv_' . $field, $value ); |
|
| 220 | + update_post_meta($invoice->ID, '_wpinv_' . $field, $value); |
|
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | return $invoice; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - protected function set_discount( $invoice, $data ) { |
|
| 228 | - if ( isset( $data['discount'] ) ) { |
|
| 229 | - $invoice->set( 'discount', wpinv_format_amount( $data['discount'], NULL, true ) ); |
|
| 227 | + protected function set_discount($invoice, $data) { |
|
| 228 | + if (isset($data['discount'])) { |
|
| 229 | + $invoice->set('discount', wpinv_format_amount($data['discount'], NULL, true)); |
|
| 230 | 230 | |
| 231 | - update_post_meta( $invoice->ID, '_wpinv_discount', wpinv_format_amount( $data['discount'], NULL, true ) ); |
|
| 231 | + update_post_meta($invoice->ID, '_wpinv_discount', wpinv_format_amount($data['discount'], NULL, true)); |
|
| 232 | 232 | |
| 233 | - if ( isset( $data['discount_code'] ) ) { |
|
| 234 | - $invoice->set( 'discount_code', $data['discount_code'] ); |
|
| 233 | + if (isset($data['discount_code'])) { |
|
| 234 | + $invoice->set('discount_code', $data['discount_code']); |
|
| 235 | 235 | |
| 236 | - update_post_meta( $invoice->ID, '_wpinv_discount_code', $data['discount_code'] ); |
|
| 236 | + update_post_meta($invoice->ID, '_wpinv_discount_code', $data['discount_code']); |
|
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | return $invoice; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - protected function set_items( $invoice, $data ) { |
|
| 244 | - if ( !empty( $data['items'] ) && is_array( $data['items'] ) ) { |
|
| 243 | + protected function set_items($invoice, $data) { |
|
| 244 | + if (!empty($data['items']) && is_array($data['items'])) { |
|
| 245 | 245 | $items_array = array(); |
| 246 | 246 | |
| 247 | - if ( !empty( $invoice->country ) ) { |
|
| 247 | + if (!empty($invoice->country)) { |
|
| 248 | 248 | $country = $invoice->country; |
| 249 | - } else if ( !empty( $data['billing_details']['country'] ) ) { |
|
| 249 | + } else if (!empty($data['billing_details']['country'])) { |
|
| 250 | 250 | $country = $data['billing_details']['country']; |
| 251 | 251 | } else { |
| 252 | - $country = wpinv_default_billing_country( '', $invoice->get_user_id() ); |
|
| 252 | + $country = wpinv_default_billing_country('', $invoice->get_user_id()); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - if ( !empty( $invoice->state ) ) { |
|
| 255 | + if (!empty($invoice->state)) { |
|
| 256 | 256 | $state = $invoice->state; |
| 257 | - } else if ( !empty( $data['billing_details']['state'] ) ) { |
|
| 257 | + } else if (!empty($data['billing_details']['state'])) { |
|
| 258 | 258 | $state = $data['billing_details']['state']; |
| 259 | 259 | } else { |
| 260 | 260 | $state = wpinv_get_default_state(); |
@@ -263,54 +263,54 @@ discard block |
||
| 263 | 263 | $_POST['country'] = $country; |
| 264 | 264 | $_POST['state'] = $state; |
| 265 | 265 | |
| 266 | - $rate = wpinv_get_tax_rate( $country, $state, 'global' ); |
|
| 266 | + $rate = wpinv_get_tax_rate($country, $state, 'global'); |
|
| 267 | 267 | |
| 268 | 268 | $total_tax = 0; |
| 269 | - foreach ( $data['items'] as $item ) { |
|
| 270 | - $id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
| 271 | - $title = isset( $item['title'] ) ? sanitize_text_field( $item['title'] ) : ''; |
|
| 272 | - $desc = isset( $item['description'] ) ? sanitize_text_field( $item['description'] ) : ''; |
|
| 273 | - $amount = isset( $item['amount'] ) ? wpinv_format_amount( $item['amount'], NULL, true ) : 0; |
|
| 269 | + foreach ($data['items'] as $item) { |
|
| 270 | + $id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
| 271 | + $title = isset($item['title']) ? sanitize_text_field($item['title']) : ''; |
|
| 272 | + $desc = isset($item['description']) ? sanitize_text_field($item['description']) : ''; |
|
| 273 | + $amount = isset($item['amount']) ? wpinv_format_amount($item['amount'], NULL, true) : 0; |
|
| 274 | 274 | |
| 275 | - if ( !empty( $item['vat_rates_class'] ) ) { |
|
| 275 | + if (!empty($item['vat_rates_class'])) { |
|
| 276 | 276 | $vat_rates_class = $item['vat_rates_class']; |
| 277 | 277 | } else { |
| 278 | 278 | $vat_rates_class = '_standard'; |
| 279 | 279 | } |
| 280 | - $vat_rate = wpinv_get_tax_rate( $country, $state, $id ); |
|
| 280 | + $vat_rate = wpinv_get_tax_rate($country, $state, $id); |
|
| 281 | 281 | |
| 282 | - $tax = $amount > 0 ? ( $amount * 0.01 * (float)$vat_rate ) : 0; |
|
| 282 | + $tax = $amount > 0 ? ($amount * 0.01 * (float)$vat_rate) : 0; |
|
| 283 | 283 | $total_tax += $tax; |
| 284 | 284 | |
| 285 | 285 | $items_array[] = array( |
| 286 | 286 | 'id' => $id, |
| 287 | - 'title' => esc_html( $title ), |
|
| 288 | - 'description' => esc_html( $desc ), |
|
| 289 | - 'amount' => $amount > 0 ? wpinv_format_amount( $amount, NULL, true ) : 0, |
|
| 290 | - 'subtotal' => $amount > 0 ? wpinv_format_amount( $amount, NULL, true ) : 0, |
|
| 287 | + 'title' => esc_html($title), |
|
| 288 | + 'description' => esc_html($desc), |
|
| 289 | + 'amount' => $amount > 0 ? wpinv_format_amount($amount, NULL, true) : 0, |
|
| 290 | + 'subtotal' => $amount > 0 ? wpinv_format_amount($amount, NULL, true) : 0, |
|
| 291 | 291 | 'vat_rates_class' => $vat_rates_class, |
| 292 | - 'vat_rate' => $vat_rate > 0 ? wpinv_format_amount( $vat_rate, NULL, true ) : 0, |
|
| 293 | - 'tax' => $tax > 0 ? wpinv_format_amount( $tax, NULL, true ) : 0, |
|
| 292 | + 'vat_rate' => $vat_rate > 0 ? wpinv_format_amount($vat_rate, NULL, true) : 0, |
|
| 293 | + 'tax' => $tax > 0 ? wpinv_format_amount($tax, NULL, true) : 0, |
|
| 294 | 294 | ); |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | - update_post_meta( $invoice->ID, '_wpinv_tax', wpinv_format_amount( $total_tax, NULL, true ) ); |
|
| 298 | - $invoice->set( 'tax', wpinv_format_amount( $total_tax, NULL, true ) ); |
|
| 297 | + update_post_meta($invoice->ID, '_wpinv_tax', wpinv_format_amount($total_tax, NULL, true)); |
|
| 298 | + $invoice->set('tax', wpinv_format_amount($total_tax, NULL, true)); |
|
| 299 | 299 | |
| 300 | - $items_array = apply_filters( 'wpinv_save_invoice_items', $items_array, $data['items'], $invoice ); |
|
| 300 | + $items_array = apply_filters('wpinv_save_invoice_items', $items_array, $data['items'], $invoice); |
|
| 301 | 301 | |
| 302 | - $invoice->set( 'items', $items_array ); |
|
| 303 | - update_post_meta( $invoice->ID, '_wpinv_items', $items_array ); |
|
| 302 | + $invoice->set('items', $items_array); |
|
| 303 | + update_post_meta($invoice->ID, '_wpinv_items', $items_array); |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | return $invoice; |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - protected function set_invoice_meta( $invoice_id, $invoice_meta ) { |
|
| 310 | - foreach ( $invoice_meta as $meta_key => $meta_value ) { |
|
| 309 | + protected function set_invoice_meta($invoice_id, $invoice_meta) { |
|
| 310 | + foreach ($invoice_meta as $meta_key => $meta_value) { |
|
| 311 | 311 | |
| 312 | - if ( is_string( $meta_key) && ! is_protected_meta( $meta_key ) && is_scalar( $meta_value ) ) { |
|
| 313 | - update_post_meta( $invoice_id, $meta_key, $meta_value ); |
|
| 312 | + if (is_string($meta_key) && !is_protected_meta($meta_key) && is_scalar($meta_value)) { |
|
| 313 | + update_post_meta($invoice_id, $meta_key, $meta_value); |
|
| 314 | 314 | } |
| 315 | 315 | } |
| 316 | 316 | } |
@@ -320,9 +320,9 @@ discard block |
||
| 320 | 320 | class WPInv_API_Exception extends Exception { |
| 321 | 321 | protected $error_code; |
| 322 | 322 | |
| 323 | - public function __construct( $error_code, $error_message, $http_status_code ) { |
|
| 323 | + public function __construct($error_code, $error_message, $http_status_code) { |
|
| 324 | 324 | $this->error_code = $error_code; |
| 325 | - parent::__construct( $error_message, $http_status_code ); |
|
| 325 | + parent::__construct($error_message, $http_status_code); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | public function getErrorCode() { |
@@ -82,6 +82,9 @@ discard block |
||
| 82 | 82 | return $value; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | + /** |
|
| 86 | + * @param string $key |
|
| 87 | + */ |
|
| 85 | 88 | public function set( $key, $value ) { |
| 86 | 89 | $ignore = array( 'items', 'cart_details', 'fees', '_ID' ); |
| 87 | 90 | |
@@ -918,6 +921,9 @@ discard block |
||
| 918 | 921 | return $removed; |
| 919 | 922 | } |
| 920 | 923 | |
| 924 | + /** |
|
| 925 | + * @param string $key |
|
| 926 | + */ |
|
| 921 | 927 | public function remove_fee_by( $key, $value, $global = false ) { |
| 922 | 928 | $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array( |
| 923 | 929 | 'index', 'label', 'amount', 'type', |
@@ -1374,6 +1380,9 @@ discard block |
||
| 1374 | 1380 | return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency ); |
| 1375 | 1381 | } |
| 1376 | 1382 | |
| 1383 | + /** |
|
| 1384 | + * @return boolean |
|
| 1385 | + */ |
|
| 1377 | 1386 | public function get_discounts( $array = false ) { |
| 1378 | 1387 | $discounts = $this->discounts; |
| 1379 | 1388 | if ( $array && $discounts ) { |
@@ -1382,6 +1391,9 @@ discard block |
||
| 1382 | 1391 | return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array ); |
| 1383 | 1392 | } |
| 1384 | 1393 | |
| 1394 | + /** |
|
| 1395 | + * @return string |
|
| 1396 | + */ |
|
| 1385 | 1397 | public function get_discount( $currency = false, $dash = false ) { |
| 1386 | 1398 | if ( !empty( $this->discounts ) ) { |
| 1387 | 1399 | global $ajax_cart_details; |
@@ -1478,6 +1490,9 @@ discard block |
||
| 1478 | 1490 | return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this ); |
| 1479 | 1491 | } |
| 1480 | 1492 | |
| 1493 | + /** |
|
| 1494 | + * @return string |
|
| 1495 | + */ |
|
| 1481 | 1496 | public function get_user_info() { |
| 1482 | 1497 | return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this ); |
| 1483 | 1498 | } |
@@ -1524,10 +1539,16 @@ discard block |
||
| 1524 | 1539 | return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this ); |
| 1525 | 1540 | } |
| 1526 | 1541 | |
| 1542 | + /** |
|
| 1543 | + * @return string |
|
| 1544 | + */ |
|
| 1527 | 1545 | public function get_created_date() { |
| 1528 | 1546 | return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this ); |
| 1529 | 1547 | } |
| 1530 | 1548 | |
| 1549 | + /** |
|
| 1550 | + * @return string |
|
| 1551 | + */ |
|
| 1531 | 1552 | public function get_due_date( $display = false ) { |
| 1532 | 1553 | $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this ); |
| 1533 | 1554 | |
@@ -2075,6 +2096,9 @@ discard block |
||
| 2075 | 2096 | return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this ); |
| 2076 | 2097 | } |
| 2077 | 2098 | |
| 2099 | + /** |
|
| 2100 | + * @return string |
|
| 2101 | + */ |
|
| 2078 | 2102 | public function get_expiration() { |
| 2079 | 2103 | $expiration = $this->get_meta( '_wpinv_subscr_expiration', true ); |
| 2080 | 2104 | return $expiration; |
@@ -2090,6 +2114,9 @@ discard block |
||
| 2090 | 2114 | return $cancelled_date; |
| 2091 | 2115 | } |
| 2092 | 2116 | |
| 2117 | + /** |
|
| 2118 | + * @return string |
|
| 2119 | + */ |
|
| 2093 | 2120 | public function get_trial_end_date( $formatted = true ) { |
| 2094 | 2121 | if ( !$this->is_free_trial() || !$this->is_paid() ) { |
| 2095 | 2122 | return NULL; |
@@ -2111,6 +2138,9 @@ discard block |
||
| 2111 | 2138 | return $trial_end_date; |
| 2112 | 2139 | } |
| 2113 | 2140 | |
| 2141 | + /** |
|
| 2142 | + * @return string |
|
| 2143 | + */ |
|
| 2114 | 2144 | public function get_subscription_created( $default = true ) { |
| 2115 | 2145 | $created = $this->get_meta( '_wpinv_subscr_created', true ); |
| 2116 | 2146 | |
@@ -2120,6 +2150,9 @@ discard block |
||
| 2120 | 2150 | return $created; |
| 2121 | 2151 | } |
| 2122 | 2152 | |
| 2153 | + /** |
|
| 2154 | + * @return string |
|
| 2155 | + */ |
|
| 2123 | 2156 | public function get_subscription_start( $formatted = true ) { |
| 2124 | 2157 | if ( !$this->is_paid() ) { |
| 2125 | 2158 | return '-'; |
@@ -7,12 +7,12 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | final class WPInv_Invoice { |
| 15 | - public $ID = 0; |
|
| 15 | + public $ID = 0; |
|
| 16 | 16 | public $title; |
| 17 | 17 | |
| 18 | 18 | public $pending; |
@@ -64,17 +64,17 @@ discard block |
||
| 64 | 64 | public $full_name = ''; |
| 65 | 65 | public $parent_invoice = 0; |
| 66 | 66 | |
| 67 | - public function __construct( $invoice_id = false ) { |
|
| 68 | - if( empty( $invoice_id ) ) { |
|
| 67 | + public function __construct($invoice_id = false) { |
|
| 68 | + if (empty($invoice_id)) { |
|
| 69 | 69 | return false; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - $this->setup_invoice( $invoice_id ); |
|
| 72 | + $this->setup_invoice($invoice_id); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - public function get( $key ) { |
|
| 76 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
| 77 | - $value = call_user_func( array( $this, 'get_' . $key ) ); |
|
| 75 | + public function get($key) { |
|
| 76 | + if (method_exists($this, 'get_' . $key)) { |
|
| 77 | + $value = call_user_func(array($this, 'get_' . $key)); |
|
| 78 | 78 | } else { |
| 79 | 79 | $value = $this->$key; |
| 80 | 80 | } |
@@ -82,51 +82,51 @@ discard block |
||
| 82 | 82 | return $value; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - public function set( $key, $value ) { |
|
| 86 | - $ignore = array( 'items', 'cart_details', 'fees', '_ID' ); |
|
| 85 | + public function set($key, $value) { |
|
| 86 | + $ignore = array('items', 'cart_details', 'fees', '_ID'); |
|
| 87 | 87 | |
| 88 | - if ( $key === 'status' ) { |
|
| 88 | + if ($key === 'status') { |
|
| 89 | 89 | $this->old_status = $this->status; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - if ( ! in_array( $key, $ignore ) ) { |
|
| 93 | - $this->pending[ $key ] = $value; |
|
| 92 | + if (!in_array($key, $ignore)) { |
|
| 93 | + $this->pending[$key] = $value; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - if( '_ID' !== $key ) { |
|
| 96 | + if ('_ID' !== $key) { |
|
| 97 | 97 | $this->$key = $value; |
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - public function _isset( $name ) { |
|
| 102 | - if ( property_exists( $this, $name) ) { |
|
| 103 | - return false === empty( $this->$name ); |
|
| 101 | + public function _isset($name) { |
|
| 102 | + if (property_exists($this, $name)) { |
|
| 103 | + return false === empty($this->$name); |
|
| 104 | 104 | } else { |
| 105 | 105 | return null; |
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - private function setup_invoice( $invoice_id ) { |
|
| 109 | + private function setup_invoice($invoice_id) { |
|
| 110 | 110 | $this->pending = array(); |
| 111 | 111 | |
| 112 | - if ( empty( $invoice_id ) ) { |
|
| 112 | + if (empty($invoice_id)) { |
|
| 113 | 113 | return false; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - $invoice = get_post( $invoice_id ); |
|
| 116 | + $invoice = get_post($invoice_id); |
|
| 117 | 117 | |
| 118 | - if( !$invoice || is_wp_error( $invoice ) ) { |
|
| 118 | + if (!$invoice || is_wp_error($invoice)) { |
|
| 119 | 119 | return false; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - if( 'wpi_invoice' !== $invoice->post_type ) { |
|
| 122 | + if ('wpi_invoice' !== $invoice->post_type) { |
|
| 123 | 123 | return false; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id ); |
|
| 126 | + do_action('wpinv_pre_setup_invoice', $this, $invoice_id); |
|
| 127 | 127 | |
| 128 | 128 | // Primary Identifier |
| 129 | - $this->ID = absint( $invoice_id ); |
|
| 129 | + $this->ID = absint($invoice_id); |
|
| 130 | 130 | |
| 131 | 131 | // We have a payment, get the generic payment_meta item to reduce calls to it |
| 132 | 132 | $this->payment_meta = $this->get_meta(); |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | $this->post_status = $this->status; |
| 138 | 138 | $this->mode = $this->setup_mode(); |
| 139 | 139 | $this->parent_invoice = $invoice->post_parent; |
| 140 | - $this->post_name = $this->setup_post_name( $invoice ); |
|
| 140 | + $this->post_name = $this->setup_post_name($invoice); |
|
| 141 | 141 | $this->status_nicename = $this->setup_status_nicename(); |
| 142 | 142 | |
| 143 | 143 | // Items |
@@ -159,8 +159,8 @@ discard block |
||
| 159 | 159 | |
| 160 | 160 | // User based |
| 161 | 161 | $this->ip = $this->setup_ip(); |
| 162 | - $this->user_id = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id(); |
|
| 163 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
| 162 | + $this->user_id = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id(); |
|
| 163 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
| 164 | 164 | |
| 165 | 165 | $this->user_info = $this->setup_user_info(); |
| 166 | 166 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | $this->company = $this->user_info['company']; |
| 170 | 170 | $this->vat_number = $this->user_info['vat_number']; |
| 171 | 171 | $this->vat_rate = $this->user_info['vat_rate']; |
| 172 | - $this->adddress_confirmed = $this->user_info['adddress_confirmed']; |
|
| 172 | + $this->adddress_confirmed = $this->user_info['adddress_confirmed']; |
|
| 173 | 173 | $this->address = $this->user_info['address']; |
| 174 | 174 | $this->city = $this->user_info['city']; |
| 175 | 175 | $this->country = $this->user_info['country']; |
@@ -184,48 +184,48 @@ discard block |
||
| 184 | 184 | // Other Identifiers |
| 185 | 185 | $this->key = $this->setup_invoice_key(); |
| 186 | 186 | $this->number = $this->setup_invoice_number(); |
| 187 | - $this->title = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number; |
|
| 187 | + $this->title = !empty($invoice->post_title) ? $invoice->post_title : $this->number; |
|
| 188 | 188 | |
| 189 | - $this->full_name = trim( $this->first_name . ' '. $this->last_name ); |
|
| 189 | + $this->full_name = trim($this->first_name . ' ' . $this->last_name); |
|
| 190 | 190 | |
| 191 | 191 | // Allow extensions to add items to this object via hook |
| 192 | - do_action( 'wpinv_setup_invoice', $this, $invoice_id ); |
|
| 192 | + do_action('wpinv_setup_invoice', $this, $invoice_id); |
|
| 193 | 193 | |
| 194 | 194 | return true; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | private function setup_status_nicename() { |
| 198 | - $all_invoice_statuses = wpinv_get_invoice_statuses(); |
|
| 198 | + $all_invoice_statuses = wpinv_get_invoice_statuses(); |
|
| 199 | 199 | |
| 200 | - $status = array_key_exists( $this->status, $all_invoice_statuses ) ? $all_invoice_statuses[$this->status] : ucfirst( $this->status ); |
|
| 200 | + $status = array_key_exists($this->status, $all_invoice_statuses) ? $all_invoice_statuses[$this->status] : ucfirst($this->status); |
|
| 201 | 201 | |
| 202 | 202 | return $status; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - private function setup_post_name( $post = NULL ) { |
|
| 205 | + private function setup_post_name($post = NULL) { |
|
| 206 | 206 | $post_name = ''; |
| 207 | 207 | |
| 208 | - if ( !empty( $post ) ) { |
|
| 209 | - if( !empty( $post->post_name ) ) { |
|
| 208 | + if (!empty($post)) { |
|
| 209 | + if (!empty($post->post_name)) { |
|
| 210 | 210 | $post_name = $post->post_name; |
| 211 | - } else if ( !empty( $post->ID ) && !empty( $post->post_title ) ) { |
|
| 212 | - $post_name = sanitize_title( $post->post_title ); |
|
| 211 | + } else if (!empty($post->ID) && !empty($post->post_title)) { |
|
| 212 | + $post_name = sanitize_title($post->post_title); |
|
| 213 | 213 | |
| 214 | 214 | global $wpdb; |
| 215 | - $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) ); |
|
| 215 | + $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID)); |
|
| 216 | 216 | } |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - $this->post_name = $post_name; |
|
| 219 | + $this->post_name = $post_name; |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | private function setup_due_date() { |
| 223 | - $due_date = $this->get_meta( '_wpinv_due_date' ); |
|
| 223 | + $due_date = $this->get_meta('_wpinv_due_date'); |
|
| 224 | 224 | |
| 225 | - if ( empty( $due_date ) ) { |
|
| 226 | - $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) ); |
|
| 227 | - $due_date = date_i18n( 'Y-m-d', $overdue_time ); |
|
| 228 | - } else if ( $due_date == 'none' ) { |
|
| 225 | + if (empty($due_date)) { |
|
| 226 | + $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days'))); |
|
| 227 | + $due_date = date_i18n('Y-m-d', $overdue_time); |
|
| 228 | + } else if ($due_date == 'none') { |
|
| 229 | 229 | $due_date = ''; |
| 230 | 230 | } |
| 231 | 231 | |
@@ -233,63 +233,63 @@ discard block |
||
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | private function setup_completed_date() { |
| 236 | - $invoice = get_post( $this->ID ); |
|
| 236 | + $invoice = get_post($this->ID); |
|
| 237 | 237 | |
| 238 | - if ( 'pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) { |
|
| 238 | + if ('pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) { |
|
| 239 | 239 | return false; // This invoice was never paid |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date; |
|
| 242 | + $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date; |
|
| 243 | 243 | |
| 244 | 244 | return $date; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | private function setup_cart_details() { |
| 248 | - $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array(); |
|
| 248 | + $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array(); |
|
| 249 | 249 | return $cart_details; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | public function array_convert() { |
| 253 | - return get_object_vars( $this ); |
|
| 253 | + return get_object_vars($this); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | private function setup_items() { |
| 257 | - $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array(); |
|
| 257 | + $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array(); |
|
| 258 | 258 | return $items; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | private function setup_fees() { |
| 262 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
| 262 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
| 263 | 263 | return $payment_fees; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | private function setup_currency() { |
| 267 | - $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this ); |
|
| 267 | + $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this); |
|
| 268 | 268 | return $currency; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | private function setup_discount() { |
| 272 | 272 | //$discount = $this->get_meta( '_wpinv_discount', true ); |
| 273 | - $discount = $this->subtotal - ( $this->total - $this->tax - $this->fees_total ); |
|
| 274 | - if ( $discount < 0 ) { |
|
| 273 | + $discount = $this->subtotal - ($this->total - $this->tax - $this->fees_total); |
|
| 274 | + if ($discount < 0) { |
|
| 275 | 275 | $discount = 0; |
| 276 | 276 | } |
| 277 | - $discount = wpinv_format_amount( $discount, NULL, true ); |
|
| 277 | + $discount = wpinv_format_amount($discount, NULL, true); |
|
| 278 | 278 | |
| 279 | 279 | return $discount; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | private function setup_discount_code() { |
| 283 | - $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true ); |
|
| 283 | + $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true); |
|
| 284 | 284 | return $discount_code; |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | private function setup_tax() { |
| 288 | - $tax = $this->get_meta( '_wpinv_tax', true ); |
|
| 288 | + $tax = $this->get_meta('_wpinv_tax', true); |
|
| 289 | 289 | |
| 290 | 290 | // We don't have tax as it's own meta and no meta was passed |
| 291 | - if ( '' === $tax ) { |
|
| 292 | - $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0; |
|
| 291 | + if ('' === $tax) { |
|
| 292 | + $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0; |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | return $tax; |
@@ -303,9 +303,9 @@ discard block |
||
| 303 | 303 | $subtotal = 0; |
| 304 | 304 | $cart_details = $this->cart_details; |
| 305 | 305 | |
| 306 | - if ( is_array( $cart_details ) ) { |
|
| 307 | - foreach ( $cart_details as $item ) { |
|
| 308 | - if ( isset( $item['subtotal'] ) ) { |
|
| 306 | + if (is_array($cart_details)) { |
|
| 307 | + foreach ($cart_details as $item) { |
|
| 308 | + if (isset($item['subtotal'])) { |
|
| 309 | 309 | $subtotal += $item['subtotal']; |
| 310 | 310 | } |
| 311 | 311 | } |
@@ -319,18 +319,18 @@ discard block |
||
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | private function setup_discounts() { |
| 322 | - $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array(); |
|
| 322 | + $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array(); |
|
| 323 | 323 | return $discounts; |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | private function setup_total() { |
| 327 | - $amount = $this->get_meta( '_wpinv_total', true ); |
|
| 327 | + $amount = $this->get_meta('_wpinv_total', true); |
|
| 328 | 328 | |
| 329 | - if ( empty( $amount ) && '0.00' != $amount ) { |
|
| 330 | - $meta = $this->get_meta( '_wpinv_payment_meta', true ); |
|
| 331 | - $meta = maybe_unserialize( $meta ); |
|
| 329 | + if (empty($amount) && '0.00' != $amount) { |
|
| 330 | + $meta = $this->get_meta('_wpinv_payment_meta', true); |
|
| 331 | + $meta = maybe_unserialize($meta); |
|
| 332 | 332 | |
| 333 | - if ( isset( $meta['amount'] ) ) { |
|
| 333 | + if (isset($meta['amount'])) { |
|
| 334 | 334 | $amount = $meta['amount']; |
| 335 | 335 | } |
| 336 | 336 | } |
@@ -339,13 +339,13 @@ discard block |
||
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | private function setup_mode() { |
| 342 | - return $this->get_meta( '_wpinv_mode' ); |
|
| 342 | + return $this->get_meta('_wpinv_mode'); |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | private function setup_gateway() { |
| 346 | - $gateway = $this->get_meta( '_wpinv_gateway' ); |
|
| 346 | + $gateway = $this->get_meta('_wpinv_gateway'); |
|
| 347 | 347 | |
| 348 | - if ( empty( $gateway ) && 'publish' === $this->status || 'complete' === $this->status ) { |
|
| 348 | + if (empty($gateway) && 'publish' === $this->status || 'complete' === $this->status) { |
|
| 349 | 349 | $gateway = 'manual'; |
| 350 | 350 | } |
| 351 | 351 | |
@@ -353,23 +353,23 @@ discard block |
||
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | private function setup_gateway_title() { |
| 356 | - $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway ); |
|
| 356 | + $gateway_title = wpinv_get_gateway_checkout_label($this->gateway); |
|
| 357 | 357 | return $gateway_title; |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | private function setup_transaction_id() { |
| 361 | - $transaction_id = $this->get_meta( '_wpinv_transaction_id' ); |
|
| 361 | + $transaction_id = $this->get_meta('_wpinv_transaction_id'); |
|
| 362 | 362 | |
| 363 | - if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) { |
|
| 363 | + if (empty($transaction_id) || (int)$transaction_id === (int)$this->ID) { |
|
| 364 | 364 | $gateway = $this->gateway; |
| 365 | - $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID ); |
|
| 365 | + $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID); |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | return $transaction_id; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | private function setup_ip() { |
| 372 | - $ip = $this->get_meta( '_wpinv_user_ip' ); |
|
| 372 | + $ip = $this->get_meta('_wpinv_user_ip'); |
|
| 373 | 373 | return $ip; |
| 374 | 374 | } |
| 375 | 375 | |
@@ -379,62 +379,62 @@ discard block |
||
| 379 | 379 | ///} |
| 380 | 380 | |
| 381 | 381 | private function setup_first_name() { |
| 382 | - $first_name = $this->get_meta( '_wpinv_first_name' ); |
|
| 382 | + $first_name = $this->get_meta('_wpinv_first_name'); |
|
| 383 | 383 | return $first_name; |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | private function setup_last_name() { |
| 387 | - $last_name = $this->get_meta( '_wpinv_last_name' ); |
|
| 387 | + $last_name = $this->get_meta('_wpinv_last_name'); |
|
| 388 | 388 | return $last_name; |
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | private function setup_company() { |
| 392 | - $company = $this->get_meta( '_wpinv_company' ); |
|
| 392 | + $company = $this->get_meta('_wpinv_company'); |
|
| 393 | 393 | return $company; |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | private function setup_vat_number() { |
| 397 | - $vat_number = $this->get_meta( '_wpinv_vat_number' ); |
|
| 397 | + $vat_number = $this->get_meta('_wpinv_vat_number'); |
|
| 398 | 398 | return $vat_number; |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | private function setup_vat_rate() { |
| 402 | - $vat_rate = $this->get_meta( '_wpinv_vat_rate' ); |
|
| 402 | + $vat_rate = $this->get_meta('_wpinv_vat_rate'); |
|
| 403 | 403 | return $vat_rate; |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | private function setup_adddress_confirmed() { |
| 407 | - $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' ); |
|
| 407 | + $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed'); |
|
| 408 | 408 | return $adddress_confirmed; |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | private function setup_phone() { |
| 412 | - $phone = $this->get_meta( '_wpinv_phone' ); |
|
| 412 | + $phone = $this->get_meta('_wpinv_phone'); |
|
| 413 | 413 | return $phone; |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | private function setup_address() { |
| 417 | - $address = $this->get_meta( '_wpinv_address', true ); |
|
| 417 | + $address = $this->get_meta('_wpinv_address', true); |
|
| 418 | 418 | return $address; |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | private function setup_city() { |
| 422 | - $city = $this->get_meta( '_wpinv_city', true ); |
|
| 422 | + $city = $this->get_meta('_wpinv_city', true); |
|
| 423 | 423 | return $city; |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | private function setup_country() { |
| 427 | - $country = $this->get_meta( '_wpinv_country', true ); |
|
| 427 | + $country = $this->get_meta('_wpinv_country', true); |
|
| 428 | 428 | return $country; |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | private function setup_state() { |
| 432 | - $state = $this->get_meta( '_wpinv_state', true ); |
|
| 432 | + $state = $this->get_meta('_wpinv_state', true); |
|
| 433 | 433 | return $state; |
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | private function setup_zip() { |
| 437 | - $zip = $this->get_meta( '_wpinv_zip', true ); |
|
| 437 | + $zip = $this->get_meta('_wpinv_zip', true); |
|
| 438 | 438 | return $zip; |
| 439 | 439 | } |
| 440 | 440 | |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | 'user_id' => $this->user_id, |
| 444 | 444 | 'first_name' => $this->first_name, |
| 445 | 445 | 'last_name' => $this->last_name, |
| 446 | - 'email' => get_the_author_meta( 'email', $this->user_id ), |
|
| 446 | + 'email' => get_the_author_meta('email', $this->user_id), |
|
| 447 | 447 | 'phone' => $this->phone, |
| 448 | 448 | 'address' => $this->address, |
| 449 | 449 | 'city' => $this->city, |
@@ -458,12 +458,12 @@ discard block |
||
| 458 | 458 | ); |
| 459 | 459 | |
| 460 | 460 | $user_info = array(); |
| 461 | - if ( isset( $this->payment_meta['user_info'] ) ) { |
|
| 462 | - $user_info = maybe_unserialize( $this->payment_meta['user_info'] ); |
|
| 461 | + if (isset($this->payment_meta['user_info'])) { |
|
| 462 | + $user_info = maybe_unserialize($this->payment_meta['user_info']); |
|
| 463 | 463 | |
| 464 | - if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) { |
|
| 464 | + if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) { |
|
| 465 | 465 | $this->user_id = $post->post_author; |
| 466 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
| 466 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
| 467 | 467 | |
| 468 | 468 | $user_info['user_id'] = $this->user_id; |
| 469 | 469 | $user_info['email'] = $this->email; |
@@ -472,13 +472,13 @@ discard block |
||
| 472 | 472 | } |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | - $user_info = wp_parse_args( $user_info, $defaults ); |
|
| 475 | + $user_info = wp_parse_args($user_info, $defaults); |
|
| 476 | 476 | |
| 477 | 477 | // Get the user, but only if it's been created |
| 478 | - $user = get_userdata( $this->user_id ); |
|
| 478 | + $user = get_userdata($this->user_id); |
|
| 479 | 479 | |
| 480 | - if ( !empty( $user ) && $user->ID > 0 ) { |
|
| 481 | - if ( empty( $user_info ) ) { |
|
| 480 | + if (!empty($user) && $user->ID > 0) { |
|
| 481 | + if (empty($user_info)) { |
|
| 482 | 482 | $user_info = array( |
| 483 | 483 | 'user_id' => $user->ID, |
| 484 | 484 | 'first_name' => $user->first_name, |
@@ -487,23 +487,23 @@ discard block |
||
| 487 | 487 | 'discount' => '', |
| 488 | 488 | ); |
| 489 | 489 | } else { |
| 490 | - foreach ( $user_info as $key => $value ) { |
|
| 491 | - if ( ! empty( $value ) ) { |
|
| 490 | + foreach ($user_info as $key => $value) { |
|
| 491 | + if (!empty($value)) { |
|
| 492 | 492 | continue; |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | - switch( $key ) { |
|
| 495 | + switch ($key) { |
|
| 496 | 496 | case 'user_id': |
| 497 | - $user_info[ $key ] = $user->ID; |
|
| 497 | + $user_info[$key] = $user->ID; |
|
| 498 | 498 | break; |
| 499 | 499 | case 'first_name': |
| 500 | - $user_info[ $key ] = $user->first_name; |
|
| 500 | + $user_info[$key] = $user->first_name; |
|
| 501 | 501 | break; |
| 502 | 502 | case 'last_name': |
| 503 | - $user_info[ $key ] = $user->last_name; |
|
| 503 | + $user_info[$key] = $user->last_name; |
|
| 504 | 504 | break; |
| 505 | 505 | case 'email': |
| 506 | - $user_info[ $key ] = $user->user_email; |
|
| 506 | + $user_info[$key] = $user->user_email; |
|
| 507 | 507 | break; |
| 508 | 508 | } |
| 509 | 509 | } |
@@ -514,16 +514,16 @@ discard block |
||
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | private function setup_invoice_key() { |
| 517 | - $key = $this->get_meta( '_wpinv_key', true ); |
|
| 517 | + $key = $this->get_meta('_wpinv_key', true); |
|
| 518 | 518 | |
| 519 | 519 | return $key; |
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | private function setup_invoice_number() { |
| 523 | - $number = $this->get_meta( '_wpinv_number', true ); |
|
| 523 | + $number = $this->get_meta('_wpinv_number', true); |
|
| 524 | 524 | |
| 525 | - if ( !$number ) { |
|
| 526 | - $number = wpinv_format_invoice_number( $this->ID ); |
|
| 525 | + if (!$number) { |
|
| 526 | + $number = wpinv_format_invoice_number($this->ID); |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | return $number; |
@@ -534,18 +534,18 @@ discard block |
||
| 534 | 534 | |
| 535 | 535 | if ($number = $this->get_number()) { |
| 536 | 536 | $invoice_title = $number; |
| 537 | - } else if ( ! empty( $this->ID ) ) { |
|
| 538 | - $invoice_title = wpinv_format_invoice_number( $this->ID ); |
|
| 537 | + } else if (!empty($this->ID)) { |
|
| 538 | + $invoice_title = wpinv_format_invoice_number($this->ID); |
|
| 539 | 539 | } else { |
| 540 | - $invoice_title = wpinv_format_invoice_number( 0 ); |
|
| 540 | + $invoice_title = wpinv_format_invoice_number(0); |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | - if ( empty( $this->key ) ) { |
|
| 543 | + if (empty($this->key)) { |
|
| 544 | 544 | $this->key = self::generate_key(); |
| 545 | 545 | $this->pending['key'] = $this->key; |
| 546 | 546 | } |
| 547 | 547 | |
| 548 | - if ( empty( $this->ip ) ) { |
|
| 548 | + if (empty($this->ip)) { |
|
| 549 | 549 | $this->ip = wpinv_get_ip(); |
| 550 | 550 | $this->pending['ip'] = $this->ip; |
| 551 | 551 | } |
@@ -577,75 +577,75 @@ discard block |
||
| 577 | 577 | 'fees' => $this->fees, |
| 578 | 578 | ); |
| 579 | 579 | |
| 580 | - $post_name = sanitize_title( $invoice_title ); |
|
| 580 | + $post_name = sanitize_title($invoice_title); |
|
| 581 | 581 | |
| 582 | 582 | $post_data = array( |
| 583 | 583 | 'post_title' => $invoice_title, |
| 584 | 584 | 'post_status' => $this->status, |
| 585 | 585 | 'post_author' => $this->user_id, |
| 586 | 586 | 'post_type' => 'wpi_invoice', |
| 587 | - 'post_date' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ), |
|
| 588 | - 'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ), |
|
| 587 | + 'post_date' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'), |
|
| 588 | + 'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1), |
|
| 589 | 589 | 'post_parent' => $this->parent_invoice, |
| 590 | 590 | ); |
| 591 | - $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this ); |
|
| 591 | + $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this); |
|
| 592 | 592 | |
| 593 | 593 | // Create a blank invoice |
| 594 | - if ( !empty( $this->ID ) ) { |
|
| 594 | + if (!empty($this->ID)) { |
|
| 595 | 595 | $args['ID'] = $this->ID; |
| 596 | 596 | $args['post_name'] = $post_name; |
| 597 | 597 | |
| 598 | - $invoice_id = wp_update_post( $args ); |
|
| 598 | + $invoice_id = wp_update_post($args); |
|
| 599 | 599 | } else { |
| 600 | - $invoice_id = wp_insert_post( $args ); |
|
| 600 | + $invoice_id = wp_insert_post($args); |
|
| 601 | 601 | |
| 602 | - $post_title = wpinv_format_invoice_number( $invoice_id ); |
|
| 602 | + $post_title = wpinv_format_invoice_number($invoice_id); |
|
| 603 | 603 | global $wpdb; |
| 604 | - $wpdb->update( $wpdb->posts, array( 'post_title' => $post_title, 'post_name' => sanitize_title( $post_title ) ), array( 'ID' => $invoice_id ) ); |
|
| 605 | - clean_post_cache( $invoice_id ); |
|
| 604 | + $wpdb->update($wpdb->posts, array('post_title' => $post_title, 'post_name' => sanitize_title($post_title)), array('ID' => $invoice_id)); |
|
| 605 | + clean_post_cache($invoice_id); |
|
| 606 | 606 | } |
| 607 | 607 | |
| 608 | - if ( !empty( $invoice_id ) ) { |
|
| 608 | + if (!empty($invoice_id)) { |
|
| 609 | 609 | $this->ID = $invoice_id; |
| 610 | 610 | $this->_ID = $invoice_id; |
| 611 | 611 | |
| 612 | 612 | ///$this->pending['user_id'] = $this->user_id; |
| 613 | - if ( isset( $this->pending['number'] ) ) { |
|
| 613 | + if (isset($this->pending['number'])) { |
|
| 614 | 614 | $this->pending['number'] = $post_name; |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | - $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data ); |
|
| 618 | - if ( ! empty( $this->payment_meta['fees'] ) ) { |
|
| 619 | - $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] ); |
|
| 620 | - foreach( $this->fees as $fee ) { |
|
| 621 | - $this->increase_fees( $fee['amount'] ); |
|
| 617 | + $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data); |
|
| 618 | + if (!empty($this->payment_meta['fees'])) { |
|
| 619 | + $this->fees = array_merge($this->fees, $this->payment_meta['fees']); |
|
| 620 | + foreach ($this->fees as $fee) { |
|
| 621 | + $this->increase_fees($fee['amount']); |
|
| 622 | 622 | } |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | - $this->update_meta( '_wpinv_payment_meta', $this->payment_meta ); |
|
| 625 | + $this->update_meta('_wpinv_payment_meta', $this->payment_meta); |
|
| 626 | 626 | $this->new = true; |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | return $this->ID; |
| 630 | 630 | } |
| 631 | 631 | |
| 632 | - public function save( $setup = false ) { |
|
| 632 | + public function save($setup = false) { |
|
| 633 | 633 | global $wpi_session; |
| 634 | 634 | |
| 635 | 635 | $saved = false; |
| 636 | - if ( empty( $this->items ) ) { |
|
| 636 | + if (empty($this->items)) { |
|
| 637 | 637 | return $saved; // Don't save empty invoice. |
| 638 | 638 | } |
| 639 | 639 | |
| 640 | - if ( empty( $this->key ) ) { |
|
| 640 | + if (empty($this->key)) { |
|
| 641 | 641 | $this->key = self::generate_key(); |
| 642 | 642 | $this->pending['key'] = $this->key; |
| 643 | 643 | } |
| 644 | 644 | |
| 645 | - if ( empty( $this->ID ) ) { |
|
| 645 | + if (empty($this->ID)) { |
|
| 646 | 646 | $invoice_id = $this->insert_invoice(); |
| 647 | 647 | |
| 648 | - if ( false === $invoice_id ) { |
|
| 648 | + if (false === $invoice_id) { |
|
| 649 | 649 | $saved = false; |
| 650 | 650 | } else { |
| 651 | 651 | $this->ID = $invoice_id; |
@@ -653,27 +653,27 @@ discard block |
||
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | // If we have something pending, let's save it |
| 656 | - if ( !empty( $this->pending ) ) { |
|
| 656 | + if (!empty($this->pending)) { |
|
| 657 | 657 | $total_increase = 0; |
| 658 | 658 | $total_decrease = 0; |
| 659 | 659 | |
| 660 | - foreach ( $this->pending as $key => $value ) { |
|
| 661 | - switch( $key ) { |
|
| 660 | + foreach ($this->pending as $key => $value) { |
|
| 661 | + switch ($key) { |
|
| 662 | 662 | case 'items': |
| 663 | 663 | // Update totals for pending items |
| 664 | - foreach ( $this->pending[ $key ] as $item ) { |
|
| 665 | - switch( $item['action'] ) { |
|
| 664 | + foreach ($this->pending[$key] as $item) { |
|
| 665 | + switch ($item['action']) { |
|
| 666 | 666 | case 'add': |
| 667 | 667 | $price = $item['price']; |
| 668 | 668 | $taxes = $item['tax']; |
| 669 | 669 | |
| 670 | - if ( 'publish' === $this->status || 'complete' === $this->status || 'revoked' === $this->status ) { |
|
| 670 | + if ('publish' === $this->status || 'complete' === $this->status || 'revoked' === $this->status) { |
|
| 671 | 671 | $total_increase += $price; |
| 672 | 672 | } |
| 673 | 673 | break; |
| 674 | 674 | |
| 675 | 675 | case 'remove': |
| 676 | - if ( 'publish' === $this->status || 'complete' === $this->status || 'revoked' === $this->status ) { |
|
| 676 | + if ('publish' === $this->status || 'complete' === $this->status || 'revoked' === $this->status) { |
|
| 677 | 677 | $total_decrease += $item['price']; |
| 678 | 678 | } |
| 679 | 679 | break; |
@@ -681,16 +681,16 @@ discard block |
||
| 681 | 681 | } |
| 682 | 682 | break; |
| 683 | 683 | case 'fees': |
| 684 | - if ( 'publish' !== $this->status && 'complete' !== $this->status && 'revoked' !== $this->status ) { |
|
| 684 | + if ('publish' !== $this->status && 'complete' !== $this->status && 'revoked' !== $this->status) { |
|
| 685 | 685 | break; |
| 686 | 686 | } |
| 687 | 687 | |
| 688 | - if ( empty( $this->pending[ $key ] ) ) { |
|
| 688 | + if (empty($this->pending[$key])) { |
|
| 689 | 689 | break; |
| 690 | 690 | } |
| 691 | 691 | |
| 692 | - foreach ( $this->pending[ $key ] as $fee ) { |
|
| 693 | - switch( $fee['action'] ) { |
|
| 692 | + foreach ($this->pending[$key] as $fee) { |
|
| 693 | + switch ($fee['action']) { |
|
| 694 | 694 | case 'add': |
| 695 | 695 | $total_increase += $fee['amount']; |
| 696 | 696 | break; |
@@ -702,86 +702,86 @@ discard block |
||
| 702 | 702 | } |
| 703 | 703 | break; |
| 704 | 704 | case 'status': |
| 705 | - $this->update_status( $this->status ); |
|
| 705 | + $this->update_status($this->status); |
|
| 706 | 706 | break; |
| 707 | 707 | case 'gateway': |
| 708 | - $this->update_meta( '_wpinv_gateway', $this->gateway ); |
|
| 708 | + $this->update_meta('_wpinv_gateway', $this->gateway); |
|
| 709 | 709 | break; |
| 710 | 710 | case 'mode': |
| 711 | - $this->update_meta( '_wpinv_mode', $this->mode ); |
|
| 711 | + $this->update_meta('_wpinv_mode', $this->mode); |
|
| 712 | 712 | break; |
| 713 | 713 | case 'transaction_id': |
| 714 | - $this->update_meta( '_wpinv_transaction_id', $this->transaction_id ); |
|
| 714 | + $this->update_meta('_wpinv_transaction_id', $this->transaction_id); |
|
| 715 | 715 | break; |
| 716 | 716 | case 'ip': |
| 717 | - $this->update_meta( '_wpinv_user_ip', $this->ip ); |
|
| 717 | + $this->update_meta('_wpinv_user_ip', $this->ip); |
|
| 718 | 718 | break; |
| 719 | 719 | ///case 'user_id': |
| 720 | 720 | ///$this->update_meta( '_wpinv_user_id', $this->user_id ); |
| 721 | 721 | ///$this->user_info['user_id'] = $this->user_id; |
| 722 | 722 | ///break; |
| 723 | 723 | case 'first_name': |
| 724 | - $this->update_meta( '_wpinv_first_name', $this->first_name ); |
|
| 724 | + $this->update_meta('_wpinv_first_name', $this->first_name); |
|
| 725 | 725 | $this->user_info['first_name'] = $this->first_name; |
| 726 | 726 | break; |
| 727 | 727 | case 'last_name': |
| 728 | - $this->update_meta( '_wpinv_last_name', $this->last_name ); |
|
| 728 | + $this->update_meta('_wpinv_last_name', $this->last_name); |
|
| 729 | 729 | $this->user_info['last_name'] = $this->last_name; |
| 730 | 730 | break; |
| 731 | 731 | case 'phone': |
| 732 | - $this->update_meta( '_wpinv_phone', $this->phone ); |
|
| 732 | + $this->update_meta('_wpinv_phone', $this->phone); |
|
| 733 | 733 | $this->user_info['phone'] = $this->phone; |
| 734 | 734 | break; |
| 735 | 735 | case 'address': |
| 736 | - $this->update_meta( '_wpinv_address', $this->address ); |
|
| 736 | + $this->update_meta('_wpinv_address', $this->address); |
|
| 737 | 737 | $this->user_info['address'] = $this->address; |
| 738 | 738 | break; |
| 739 | 739 | case 'city': |
| 740 | - $this->update_meta( '_wpinv_city', $this->city ); |
|
| 740 | + $this->update_meta('_wpinv_city', $this->city); |
|
| 741 | 741 | $this->user_info['city'] = $this->city; |
| 742 | 742 | break; |
| 743 | 743 | case 'country': |
| 744 | - $this->update_meta( '_wpinv_country', $this->country ); |
|
| 744 | + $this->update_meta('_wpinv_country', $this->country); |
|
| 745 | 745 | $this->user_info['country'] = $this->country; |
| 746 | 746 | break; |
| 747 | 747 | case 'state': |
| 748 | - $this->update_meta( '_wpinv_state', $this->state ); |
|
| 748 | + $this->update_meta('_wpinv_state', $this->state); |
|
| 749 | 749 | $this->user_info['state'] = $this->state; |
| 750 | 750 | break; |
| 751 | 751 | case 'zip': |
| 752 | - $this->update_meta( '_wpinv_zip', $this->zip ); |
|
| 752 | + $this->update_meta('_wpinv_zip', $this->zip); |
|
| 753 | 753 | $this->user_info['zip'] = $this->zip; |
| 754 | 754 | break; |
| 755 | 755 | case 'company': |
| 756 | - $this->update_meta( '_wpinv_company', $this->company ); |
|
| 756 | + $this->update_meta('_wpinv_company', $this->company); |
|
| 757 | 757 | $this->user_info['company'] = $this->company; |
| 758 | 758 | break; |
| 759 | 759 | case 'vat_number': |
| 760 | - $this->update_meta( '_wpinv_vat_number', $this->vat_number ); |
|
| 760 | + $this->update_meta('_wpinv_vat_number', $this->vat_number); |
|
| 761 | 761 | $this->user_info['vat_number'] = $this->vat_number; |
| 762 | 762 | |
| 763 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
| 764 | - if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) { |
|
| 765 | - $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false; |
|
| 766 | - $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed ); |
|
| 763 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
| 764 | + if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) { |
|
| 765 | + $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
| 766 | + $this->update_meta('_wpinv_adddress_confirmed', (bool)$adddress_confirmed); |
|
| 767 | 767 | $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed; |
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | break; |
| 771 | 771 | case 'vat_rate': |
| 772 | - $this->update_meta( '_wpinv_vat_rate', $this->vat_rate ); |
|
| 772 | + $this->update_meta('_wpinv_vat_rate', $this->vat_rate); |
|
| 773 | 773 | $this->user_info['vat_rate'] = $this->vat_rate; |
| 774 | 774 | break; |
| 775 | 775 | case 'adddress_confirmed': |
| 776 | - $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed ); |
|
| 776 | + $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed); |
|
| 777 | 777 | $this->user_info['adddress_confirmed'] = $this->adddress_confirmed; |
| 778 | 778 | break; |
| 779 | 779 | |
| 780 | 780 | case 'key': |
| 781 | - $this->update_meta( '_wpinv_key', $this->key ); |
|
| 781 | + $this->update_meta('_wpinv_key', $this->key); |
|
| 782 | 782 | break; |
| 783 | 783 | case 'number': |
| 784 | - $this->update_meta( '_wpinv_number', $this->number ); |
|
| 784 | + $this->update_meta('_wpinv_number', $this->number); |
|
| 785 | 785 | break; |
| 786 | 786 | case 'date': |
| 787 | 787 | $args = array( |
@@ -790,34 +790,34 @@ discard block |
||
| 790 | 790 | 'edit_date' => true, |
| 791 | 791 | ); |
| 792 | 792 | |
| 793 | - wp_update_post( $args ); |
|
| 793 | + wp_update_post($args); |
|
| 794 | 794 | break; |
| 795 | 795 | case 'due_date': |
| 796 | - if ( empty( $this->due_date ) ) { |
|
| 796 | + if (empty($this->due_date)) { |
|
| 797 | 797 | $this->due_date = 'none'; |
| 798 | 798 | } |
| 799 | 799 | |
| 800 | - $this->update_meta( '_wpinv_due_date', $this->due_date ); |
|
| 800 | + $this->update_meta('_wpinv_due_date', $this->due_date); |
|
| 801 | 801 | break; |
| 802 | 802 | case 'completed_date': |
| 803 | - $this->update_meta( '_wpinv_completed_date', $this->completed_date ); |
|
| 803 | + $this->update_meta('_wpinv_completed_date', $this->completed_date); |
|
| 804 | 804 | break; |
| 805 | 805 | case 'discounts': |
| 806 | - if ( ! is_array( $this->discounts ) ) { |
|
| 807 | - $this->discounts = explode( ',', $this->discounts ); |
|
| 806 | + if (!is_array($this->discounts)) { |
|
| 807 | + $this->discounts = explode(',', $this->discounts); |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | - $this->user_info['discount'] = implode( ',', $this->discounts ); |
|
| 810 | + $this->user_info['discount'] = implode(',', $this->discounts); |
|
| 811 | 811 | break; |
| 812 | 812 | |
| 813 | 813 | //case 'tax': |
| 814 | 814 | //$this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) ); |
| 815 | 815 | //break; |
| 816 | 816 | case 'discount': |
| 817 | - $this->update_meta( '_wpinv_discount', wpinv_format_amount( $this->discount, NULL, true ) ); |
|
| 817 | + $this->update_meta('_wpinv_discount', wpinv_format_amount($this->discount, NULL, true)); |
|
| 818 | 818 | break; |
| 819 | 819 | case 'discount_code': |
| 820 | - $this->update_meta( '_wpinv_discount_code', $this->discount_code ); |
|
| 820 | + $this->update_meta('_wpinv_discount_code', $this->discount_code); |
|
| 821 | 821 | break; |
| 822 | 822 | //case 'fees': |
| 823 | 823 | //$this->update_meta( '_wpinv_fees', $this->fees ); |
@@ -827,19 +827,19 @@ discard block |
||
| 827 | 827 | 'ID' => $this->ID, |
| 828 | 828 | 'post_parent' => $this->parent_invoice, |
| 829 | 829 | ); |
| 830 | - wp_update_post( $args ); |
|
| 830 | + wp_update_post($args); |
|
| 831 | 831 | break; |
| 832 | 832 | default: |
| 833 | - do_action( 'wpinv_save', $this, $key ); |
|
| 833 | + do_action('wpinv_save', $this, $key); |
|
| 834 | 834 | break; |
| 835 | 835 | } |
| 836 | 836 | } |
| 837 | 837 | |
| 838 | - $this->update_meta( '_wpinv_subtotal', wpinv_format_amount( $this->subtotal, NULL, true ) ); |
|
| 839 | - $this->update_meta( '_wpinv_total', wpinv_format_amount( $this->total, NULL, true ) ); |
|
| 840 | - $this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) ); |
|
| 838 | + $this->update_meta('_wpinv_subtotal', wpinv_format_amount($this->subtotal, NULL, true)); |
|
| 839 | + $this->update_meta('_wpinv_total', wpinv_format_amount($this->total, NULL, true)); |
|
| 840 | + $this->update_meta('_wpinv_tax', wpinv_format_amount($this->tax, NULL, true)); |
|
| 841 | 841 | |
| 842 | - $this->items = array_values( $this->items ); |
|
| 842 | + $this->items = array_values($this->items); |
|
| 843 | 843 | |
| 844 | 844 | $new_meta = array( |
| 845 | 845 | 'items' => $this->items, |
@@ -850,12 +850,12 @@ discard block |
||
| 850 | 850 | ); |
| 851 | 851 | |
| 852 | 852 | $meta = $this->get_meta(); |
| 853 | - $merged_meta = array_merge( $meta, $new_meta ); |
|
| 853 | + $merged_meta = array_merge($meta, $new_meta); |
|
| 854 | 854 | |
| 855 | 855 | // Only save the payment meta if it's changed |
| 856 | - if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) { |
|
| 857 | - $updated = $this->update_meta( '_wpinv_payment_meta', $merged_meta ); |
|
| 858 | - if ( false !== $updated ) { |
|
| 856 | + if (md5(serialize($meta)) !== md5(serialize($merged_meta))) { |
|
| 857 | + $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta); |
|
| 858 | + if (false !== $updated) { |
|
| 859 | 859 | $saved = true; |
| 860 | 860 | } |
| 861 | 861 | } |
@@ -863,15 +863,15 @@ discard block |
||
| 863 | 863 | $this->pending = array(); |
| 864 | 864 | $saved = true; |
| 865 | 865 | } else { |
| 866 | - $this->update_meta( '_wpinv_subtotal', wpinv_format_amount( $this->subtotal, NULL, true ) ); |
|
| 867 | - $this->update_meta( '_wpinv_total', wpinv_format_amount( $this->total, NULL, true ) ); |
|
| 868 | - $this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) ); |
|
| 866 | + $this->update_meta('_wpinv_subtotal', wpinv_format_amount($this->subtotal, NULL, true)); |
|
| 867 | + $this->update_meta('_wpinv_total', wpinv_format_amount($this->total, NULL, true)); |
|
| 868 | + $this->update_meta('_wpinv_tax', wpinv_format_amount($this->tax, NULL, true)); |
|
| 869 | 869 | } |
| 870 | 870 | |
| 871 | - do_action( 'wpinv_invoice_save', $this, $saved ); |
|
| 871 | + do_action('wpinv_invoice_save', $this, $saved); |
|
| 872 | 872 | |
| 873 | - if ( true === $saved || $setup ) { |
|
| 874 | - $this->setup_invoice( $this->ID ); |
|
| 873 | + if (true === $saved || $setup) { |
|
| 874 | + $this->setup_invoice($this->ID); |
|
| 875 | 875 | } |
| 876 | 876 | |
| 877 | 877 | $this->refresh_item_ids(); |
@@ -879,7 +879,7 @@ discard block |
||
| 879 | 879 | return $saved; |
| 880 | 880 | } |
| 881 | 881 | |
| 882 | - public function add_fee( $args, $global = true ) { |
|
| 882 | + public function add_fee($args, $global = true) { |
|
| 883 | 883 | $default_args = array( |
| 884 | 884 | 'label' => '', |
| 885 | 885 | 'amount' => 0, |
@@ -889,75 +889,75 @@ discard block |
||
| 889 | 889 | 'item_id' => 0, |
| 890 | 890 | ); |
| 891 | 891 | |
| 892 | - $fee = wp_parse_args( $args, $default_args ); |
|
| 892 | + $fee = wp_parse_args($args, $default_args); |
|
| 893 | 893 | |
| 894 | - if ( !empty( $fee['label'] ) ) { |
|
| 894 | + if (!empty($fee['label'])) { |
|
| 895 | 895 | return false; |
| 896 | 896 | } |
| 897 | 897 | |
| 898 | - $fee['id'] = sanitize_title( $fee['label'] ); |
|
| 898 | + $fee['id'] = sanitize_title($fee['label']); |
|
| 899 | 899 | |
| 900 | - $this->fees[] = $fee; |
|
| 900 | + $this->fees[] = $fee; |
|
| 901 | 901 | |
| 902 | 902 | $added_fee = $fee; |
| 903 | 903 | $added_fee['action'] = 'add'; |
| 904 | 904 | $this->pending['fees'][] = $added_fee; |
| 905 | - reset( $this->fees ); |
|
| 905 | + reset($this->fees); |
|
| 906 | 906 | |
| 907 | - $this->increase_fees( $fee['amount'] ); |
|
| 907 | + $this->increase_fees($fee['amount']); |
|
| 908 | 908 | return true; |
| 909 | 909 | } |
| 910 | 910 | |
| 911 | - public function remove_fee( $key ) { |
|
| 911 | + public function remove_fee($key) { |
|
| 912 | 912 | $removed = false; |
| 913 | 913 | |
| 914 | - if ( is_numeric( $key ) ) { |
|
| 915 | - $removed = $this->remove_fee_by( 'index', $key ); |
|
| 914 | + if (is_numeric($key)) { |
|
| 915 | + $removed = $this->remove_fee_by('index', $key); |
|
| 916 | 916 | } |
| 917 | 917 | |
| 918 | 918 | return $removed; |
| 919 | 919 | } |
| 920 | 920 | |
| 921 | - public function remove_fee_by( $key, $value, $global = false ) { |
|
| 922 | - $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array( |
|
| 921 | + public function remove_fee_by($key, $value, $global = false) { |
|
| 922 | + $allowed_fee_keys = apply_filters('wpinv_fee_keys', array( |
|
| 923 | 923 | 'index', 'label', 'amount', 'type', |
| 924 | - ) ); |
|
| 924 | + )); |
|
| 925 | 925 | |
| 926 | - if ( ! in_array( $key, $allowed_fee_keys ) ) { |
|
| 926 | + if (!in_array($key, $allowed_fee_keys)) { |
|
| 927 | 927 | return false; |
| 928 | 928 | } |
| 929 | 929 | |
| 930 | 930 | $removed = false; |
| 931 | - if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) { |
|
| 932 | - $removed_fee = $this->fees[ $value ]; |
|
| 931 | + if ('index' === $key && array_key_exists($value, $this->fees)) { |
|
| 932 | + $removed_fee = $this->fees[$value]; |
|
| 933 | 933 | $removed_fee['action'] = 'remove'; |
| 934 | 934 | $this->pending['fees'][] = $removed_fee; |
| 935 | 935 | |
| 936 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
| 936 | + $this->decrease_fees($removed_fee['amount']); |
|
| 937 | 937 | |
| 938 | - unset( $this->fees[ $value ] ); |
|
| 938 | + unset($this->fees[$value]); |
|
| 939 | 939 | $removed = true; |
| 940 | - } else if ( 'index' !== $key ) { |
|
| 941 | - foreach ( $this->fees as $index => $fee ) { |
|
| 942 | - if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) { |
|
| 940 | + } else if ('index' !== $key) { |
|
| 941 | + foreach ($this->fees as $index => $fee) { |
|
| 942 | + if (isset($fee[$key]) && $fee[$key] == $value) { |
|
| 943 | 943 | $removed_fee = $fee; |
| 944 | 944 | $removed_fee['action'] = 'remove'; |
| 945 | 945 | $this->pending['fees'][] = $removed_fee; |
| 946 | 946 | |
| 947 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
| 947 | + $this->decrease_fees($removed_fee['amount']); |
|
| 948 | 948 | |
| 949 | - unset( $this->fees[ $index ] ); |
|
| 949 | + unset($this->fees[$index]); |
|
| 950 | 950 | $removed = true; |
| 951 | 951 | |
| 952 | - if ( false === $global ) { |
|
| 952 | + if (false === $global) { |
|
| 953 | 953 | break; |
| 954 | 954 | } |
| 955 | 955 | } |
| 956 | 956 | } |
| 957 | 957 | } |
| 958 | 958 | |
| 959 | - if ( true === $removed ) { |
|
| 960 | - $this->fees = array_values( $this->fees ); |
|
| 959 | + if (true === $removed) { |
|
| 960 | + $this->fees = array_values($this->fees); |
|
| 961 | 961 | } |
| 962 | 962 | |
| 963 | 963 | return $removed; |
@@ -965,35 +965,35 @@ discard block |
||
| 965 | 965 | |
| 966 | 966 | |
| 967 | 967 | |
| 968 | - public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
|
| 968 | + public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) { |
|
| 969 | 969 | // Bail if no note specified |
| 970 | - if( !$note ) { |
|
| 970 | + if (!$note) { |
|
| 971 | 971 | return false; |
| 972 | 972 | } |
| 973 | 973 | |
| 974 | - if ( empty( $this->ID ) ) |
|
| 974 | + if (empty($this->ID)) |
|
| 975 | 975 | return false; |
| 976 | 976 | |
| 977 | - if ( ( ( is_user_logged_in() && current_user_can( 'manage_options' ) ) || $added_by_user ) && !$system ) { |
|
| 978 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
| 977 | + if (((is_user_logged_in() && current_user_can('manage_options')) || $added_by_user) && !$system) { |
|
| 978 | + $user = get_user_by('id', get_current_user_id()); |
|
| 979 | 979 | $comment_author = $user->display_name; |
| 980 | 980 | $comment_author_email = $user->user_email; |
| 981 | 981 | } else { |
| 982 | - $comment_author = __( 'System', 'invoicing' ); |
|
| 983 | - $comment_author_email = strtolower( __( 'System', 'invoicing' ) ) . '@'; |
|
| 984 | - $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com'; |
|
| 985 | - $comment_author_email = sanitize_email( $comment_author_email ); |
|
| 982 | + $comment_author = __('System', 'invoicing'); |
|
| 983 | + $comment_author_email = strtolower(__('System', 'invoicing')) . '@'; |
|
| 984 | + $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com'; |
|
| 985 | + $comment_author_email = sanitize_email($comment_author_email); |
|
| 986 | 986 | } |
| 987 | 987 | |
| 988 | - do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type ); |
|
| 988 | + do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type); |
|
| 989 | 989 | |
| 990 | - $note_id = wp_insert_comment( wp_filter_comment( array( |
|
| 990 | + $note_id = wp_insert_comment(wp_filter_comment(array( |
|
| 991 | 991 | 'comment_post_ID' => $this->ID, |
| 992 | 992 | 'comment_content' => $note, |
| 993 | 993 | 'comment_agent' => 'GeoDirectory', |
| 994 | 994 | 'user_id' => is_admin() ? get_current_user_id() : 0, |
| 995 | - 'comment_date' => current_time( 'mysql' ), |
|
| 996 | - 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
| 995 | + 'comment_date' => current_time('mysql'), |
|
| 996 | + 'comment_date_gmt' => current_time('mysql', 1), |
|
| 997 | 997 | 'comment_approved' => 1, |
| 998 | 998 | 'comment_parent' => 0, |
| 999 | 999 | 'comment_author' => $comment_author, |
@@ -1001,53 +1001,53 @@ discard block |
||
| 1001 | 1001 | 'comment_author_url' => '', |
| 1002 | 1002 | 'comment_author_email' => $comment_author_email, |
| 1003 | 1003 | 'comment_type' => 'wpinv_note' |
| 1004 | - ) ) ); |
|
| 1004 | + ))); |
|
| 1005 | 1005 | |
| 1006 | - do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note ); |
|
| 1006 | + do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note); |
|
| 1007 | 1007 | |
| 1008 | - if ( $customer_type ) { |
|
| 1009 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
| 1008 | + if ($customer_type) { |
|
| 1009 | + add_comment_meta($note_id, '_wpi_customer_note', 1); |
|
| 1010 | 1010 | |
| 1011 | - do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) ); |
|
| 1011 | + do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note)); |
|
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | 1014 | return $note_id; |
| 1015 | 1015 | } |
| 1016 | 1016 | |
| 1017 | - private function increase_subtotal( $amount = 0.00 ) { |
|
| 1018 | - $amount = (float) $amount; |
|
| 1017 | + private function increase_subtotal($amount = 0.00) { |
|
| 1018 | + $amount = (float)$amount; |
|
| 1019 | 1019 | $this->subtotal += $amount; |
| 1020 | - $this->subtotal = wpinv_format_amount( $this->subtotal, NULL, true ); |
|
| 1020 | + $this->subtotal = wpinv_format_amount($this->subtotal, NULL, true); |
|
| 1021 | 1021 | |
| 1022 | 1022 | $this->recalculate_total(); |
| 1023 | 1023 | } |
| 1024 | 1024 | |
| 1025 | - private function decrease_subtotal( $amount = 0.00 ) { |
|
| 1026 | - $amount = (float) $amount; |
|
| 1025 | + private function decrease_subtotal($amount = 0.00) { |
|
| 1026 | + $amount = (float)$amount; |
|
| 1027 | 1027 | $this->subtotal -= $amount; |
| 1028 | - $this->subtotal = wpinv_format_amount( $this->subtotal, NULL, true ); |
|
| 1028 | + $this->subtotal = wpinv_format_amount($this->subtotal, NULL, true); |
|
| 1029 | 1029 | |
| 1030 | - if ( $this->subtotal < 0 ) { |
|
| 1030 | + if ($this->subtotal < 0) { |
|
| 1031 | 1031 | $this->subtotal = 0; |
| 1032 | 1032 | } |
| 1033 | 1033 | |
| 1034 | 1034 | $this->recalculate_total(); |
| 1035 | 1035 | } |
| 1036 | 1036 | |
| 1037 | - private function increase_fees( $amount = 0.00 ) { |
|
| 1037 | + private function increase_fees($amount = 0.00) { |
|
| 1038 | 1038 | $amount = (float)$amount; |
| 1039 | 1039 | $this->fees_total += $amount; |
| 1040 | - $this->fees_total = wpinv_format_amount( $this->fees_total, NULL, true ); |
|
| 1040 | + $this->fees_total = wpinv_format_amount($this->fees_total, NULL, true); |
|
| 1041 | 1041 | |
| 1042 | 1042 | $this->recalculate_total(); |
| 1043 | 1043 | } |
| 1044 | 1044 | |
| 1045 | - private function decrease_fees( $amount = 0.00 ) { |
|
| 1046 | - $amount = (float) $amount; |
|
| 1045 | + private function decrease_fees($amount = 0.00) { |
|
| 1046 | + $amount = (float)$amount; |
|
| 1047 | 1047 | $this->fees_total -= $amount; |
| 1048 | - $this->fees_total = wpinv_format_amount( $this->fees_total, NULL, true ); |
|
| 1048 | + $this->fees_total = wpinv_format_amount($this->fees_total, NULL, true); |
|
| 1049 | 1049 | |
| 1050 | - if ( $this->fees_total < 0 ) { |
|
| 1050 | + if ($this->fees_total < 0) { |
|
| 1051 | 1051 | $this->fees_total = 0; |
| 1052 | 1052 | } |
| 1053 | 1053 | |
@@ -1058,54 +1058,54 @@ discard block |
||
| 1058 | 1058 | global $wpi_nosave; |
| 1059 | 1059 | |
| 1060 | 1060 | $this->total = $this->subtotal + $this->tax + $this->fees_total; |
| 1061 | - $this->total = wpinv_format_amount( $this->total, NULL, true ); |
|
| 1061 | + $this->total = wpinv_format_amount($this->total, NULL, true); |
|
| 1062 | 1062 | |
| 1063 | - do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave ); |
|
| 1063 | + do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave); |
|
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | - public function increase_tax( $amount = 0.00 ) { |
|
| 1067 | - $amount = (float) $amount; |
|
| 1066 | + public function increase_tax($amount = 0.00) { |
|
| 1067 | + $amount = (float)$amount; |
|
| 1068 | 1068 | $this->tax += $amount; |
| 1069 | 1069 | |
| 1070 | 1070 | $this->recalculate_total(); |
| 1071 | 1071 | } |
| 1072 | 1072 | |
| 1073 | - public function decrease_tax( $amount = 0.00 ) { |
|
| 1074 | - $amount = (float) $amount; |
|
| 1073 | + public function decrease_tax($amount = 0.00) { |
|
| 1074 | + $amount = (float)$amount; |
|
| 1075 | 1075 | $this->tax -= $amount; |
| 1076 | 1076 | |
| 1077 | - if ( $this->tax < 0 ) { |
|
| 1077 | + if ($this->tax < 0) { |
|
| 1078 | 1078 | $this->tax = 0; |
| 1079 | 1079 | } |
| 1080 | 1080 | |
| 1081 | 1081 | $this->recalculate_total(); |
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
| 1085 | - $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID ); |
|
| 1084 | + public function update_status($new_status = false, $note = '', $manual = false) { |
|
| 1085 | + $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID); |
|
| 1086 | 1086 | |
| 1087 | - if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses() ) ) ) { |
|
| 1087 | + if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses()))) { |
|
| 1088 | 1088 | return false; // Don't permit status changes that aren't changes |
| 1089 | 1089 | } |
| 1090 | 1090 | |
| 1091 | - $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status ); |
|
| 1091 | + $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status); |
|
| 1092 | 1092 | $updated = false; |
| 1093 | 1093 | |
| 1094 | - if ( $do_change ) { |
|
| 1095 | - do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status ); |
|
| 1094 | + if ($do_change) { |
|
| 1095 | + do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status); |
|
| 1096 | 1096 | |
| 1097 | 1097 | $update_post_data = array(); |
| 1098 | 1098 | $update_post_data['ID'] = $this->ID; |
| 1099 | 1099 | $update_post_data['post_status'] = $new_status; |
| 1100 | - $update_post_data['edit_date'] = current_time( 'mysql', 0 ); |
|
| 1101 | - $update_post_data['edit_date_gmt'] = current_time( 'mysql', 1 ); |
|
| 1100 | + $update_post_data['edit_date'] = current_time('mysql', 0); |
|
| 1101 | + $update_post_data['edit_date_gmt'] = current_time('mysql', 1); |
|
| 1102 | 1102 | |
| 1103 | - $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID ); |
|
| 1103 | + $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID); |
|
| 1104 | 1104 | |
| 1105 | - $updated = wp_update_post( $update_post_data ); |
|
| 1105 | + $updated = wp_update_post($update_post_data); |
|
| 1106 | 1106 | |
| 1107 | 1107 | // Process any specific status functions |
| 1108 | - switch( $new_status ) { |
|
| 1108 | + switch ($new_status) { |
|
| 1109 | 1109 | case 'refunded': |
| 1110 | 1110 | $this->process_refund(); |
| 1111 | 1111 | break; |
@@ -1118,9 +1118,9 @@ discard block |
||
| 1118 | 1118 | } |
| 1119 | 1119 | |
| 1120 | 1120 | // Status was changed. |
| 1121 | - do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status ); |
|
| 1122 | - do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status ); |
|
| 1123 | - do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status ); |
|
| 1121 | + do_action('wpinv_status_' . $new_status, $this->ID, $old_status); |
|
| 1122 | + do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status); |
|
| 1123 | + do_action('wpinv_update_status', $this->ID, $new_status, $old_status); |
|
| 1124 | 1124 | } |
| 1125 | 1125 | |
| 1126 | 1126 | return $updated; |
@@ -1134,72 +1134,72 @@ discard block |
||
| 1134 | 1134 | $this->save(); |
| 1135 | 1135 | } |
| 1136 | 1136 | |
| 1137 | - public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
| 1138 | - if ( empty( $meta_key ) ) { |
|
| 1137 | + public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { |
|
| 1138 | + if (empty($meta_key)) { |
|
| 1139 | 1139 | return false; |
| 1140 | 1140 | } |
| 1141 | 1141 | |
| 1142 | - if ( $meta_key == 'key' || $meta_key == 'date' ) { |
|
| 1142 | + if ($meta_key == 'key' || $meta_key == 'date') { |
|
| 1143 | 1143 | $current_meta = $this->get_meta(); |
| 1144 | - $current_meta[ $meta_key ] = $meta_value; |
|
| 1144 | + $current_meta[$meta_key] = $meta_value; |
|
| 1145 | 1145 | |
| 1146 | 1146 | $meta_key = '_wpinv_payment_meta'; |
| 1147 | 1147 | $meta_value = $current_meta; |
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | - $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID ); |
|
| 1150 | + $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID); |
|
| 1151 | 1151 | |
| 1152 | - if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) { |
|
| 1152 | + if ($meta_key == '_wpinv_completed_date' && !empty($meta_value)) { |
|
| 1153 | 1153 | $args = array( |
| 1154 | 1154 | 'ID' => $this->ID, |
| 1155 | 1155 | 'post_date' => $meta_value, |
| 1156 | 1156 | 'edit_date' => true, |
| 1157 | - 'post_date_gmt' => get_gmt_from_date( $meta_value ), |
|
| 1157 | + 'post_date_gmt' => get_gmt_from_date($meta_value), |
|
| 1158 | 1158 | 'post_modified' => $meta_value, |
| 1159 | - 'post_modified_gmt' => get_gmt_from_date( $meta_value ) |
|
| 1159 | + 'post_modified_gmt' => get_gmt_from_date($meta_value) |
|
| 1160 | 1160 | ); |
| 1161 | - wp_update_post( $args ); |
|
| 1161 | + wp_update_post($args); |
|
| 1162 | 1162 | } |
| 1163 | 1163 | |
| 1164 | - return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value ); |
|
| 1164 | + return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value); |
|
| 1165 | 1165 | } |
| 1166 | 1166 | |
| 1167 | 1167 | private function process_refund() { |
| 1168 | 1168 | $process_refund = true; |
| 1169 | 1169 | |
| 1170 | 1170 | // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented |
| 1171 | - if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'refunded' != $this->status ) { |
|
| 1171 | + if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'refunded' != $this->status) { |
|
| 1172 | 1172 | $process_refund = false; |
| 1173 | 1173 | } |
| 1174 | 1174 | |
| 1175 | 1175 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
| 1176 | - $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this ); |
|
| 1176 | + $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this); |
|
| 1177 | 1177 | |
| 1178 | - if ( false === $process_refund ) { |
|
| 1178 | + if (false === $process_refund) { |
|
| 1179 | 1179 | return; |
| 1180 | 1180 | } |
| 1181 | 1181 | |
| 1182 | - do_action( 'wpinv_pre_refund_invoice', $this ); |
|
| 1182 | + do_action('wpinv_pre_refund_invoice', $this); |
|
| 1183 | 1183 | |
| 1184 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this ); |
|
| 1185 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this ); |
|
| 1186 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this ); |
|
| 1184 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this); |
|
| 1185 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this); |
|
| 1186 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this); |
|
| 1187 | 1187 | |
| 1188 | - do_action( 'wpinv_post_refund_invoice', $this ); |
|
| 1188 | + do_action('wpinv_post_refund_invoice', $this); |
|
| 1189 | 1189 | } |
| 1190 | 1190 | |
| 1191 | 1191 | private function process_failure() { |
| 1192 | 1192 | $discounts = $this->discounts; |
| 1193 | - if ( empty( $discounts ) ) { |
|
| 1193 | + if (empty($discounts)) { |
|
| 1194 | 1194 | return; |
| 1195 | 1195 | } |
| 1196 | 1196 | |
| 1197 | - if ( ! is_array( $discounts ) ) { |
|
| 1198 | - $discounts = array_map( 'trim', explode( ',', $discounts ) ); |
|
| 1197 | + if (!is_array($discounts)) { |
|
| 1198 | + $discounts = array_map('trim', explode(',', $discounts)); |
|
| 1199 | 1199 | } |
| 1200 | 1200 | |
| 1201 | - foreach ( $discounts as $discount ) { |
|
| 1202 | - wpinv_decrease_discount_usage( $discount ); |
|
| 1201 | + foreach ($discounts as $discount) { |
|
| 1202 | + wpinv_decrease_discount_usage($discount); |
|
| 1203 | 1203 | } |
| 1204 | 1204 | } |
| 1205 | 1205 | |
@@ -1207,89 +1207,89 @@ discard block |
||
| 1207 | 1207 | $process_pending = true; |
| 1208 | 1208 | |
| 1209 | 1209 | // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented |
| 1210 | - if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'pending' != $this->status ) { |
|
| 1210 | + if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'pending' != $this->status) { |
|
| 1211 | 1211 | $process_pending = false; |
| 1212 | 1212 | } |
| 1213 | 1213 | |
| 1214 | 1214 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
| 1215 | - $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this ); |
|
| 1215 | + $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this); |
|
| 1216 | 1216 | |
| 1217 | - if ( false === $process_pending ) { |
|
| 1217 | + if (false === $process_pending) { |
|
| 1218 | 1218 | return; |
| 1219 | 1219 | } |
| 1220 | 1220 | |
| 1221 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this ); |
|
| 1222 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this ); |
|
| 1223 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this ); |
|
| 1221 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this); |
|
| 1222 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this); |
|
| 1223 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this); |
|
| 1224 | 1224 | |
| 1225 | 1225 | $this->completed_date = false; |
| 1226 | - $this->update_meta( '_wpinv_completed_date', '' ); |
|
| 1226 | + $this->update_meta('_wpinv_completed_date', ''); |
|
| 1227 | 1227 | } |
| 1228 | 1228 | |
| 1229 | 1229 | // get data |
| 1230 | - public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
| 1231 | - $meta = get_post_meta( $this->ID, $meta_key, $single ); |
|
| 1230 | + public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) { |
|
| 1231 | + $meta = get_post_meta($this->ID, $meta_key, $single); |
|
| 1232 | 1232 | |
| 1233 | - if ( $meta_key === '_wpinv_payment_meta' ) { |
|
| 1234 | - if ( empty( $meta['key'] ) ) { |
|
| 1233 | + if ($meta_key === '_wpinv_payment_meta') { |
|
| 1234 | + if (empty($meta['key'])) { |
|
| 1235 | 1235 | $meta['key'] = $this->setup_invoice_key(); |
| 1236 | 1236 | } |
| 1237 | 1237 | |
| 1238 | - if ( empty( $meta['date'] ) ) { |
|
| 1239 | - $meta['date'] = get_post_field( 'post_date', $this->ID ); |
|
| 1238 | + if (empty($meta['date'])) { |
|
| 1239 | + $meta['date'] = get_post_field('post_date', $this->ID); |
|
| 1240 | 1240 | } |
| 1241 | 1241 | } |
| 1242 | 1242 | |
| 1243 | - $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID ); |
|
| 1243 | + $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID); |
|
| 1244 | 1244 | |
| 1245 | - return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key ); |
|
| 1245 | + return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key); |
|
| 1246 | 1246 | } |
| 1247 | 1247 | |
| 1248 | 1248 | public function get_description() { |
| 1249 | - $post = get_post( $this->ID ); |
|
| 1249 | + $post = get_post($this->ID); |
|
| 1250 | 1250 | |
| 1251 | - $description = !empty( $post ) ? $post->post_content : ''; |
|
| 1252 | - return apply_filters( 'wpinv_get_description', $description, $this->ID, $this ); |
|
| 1251 | + $description = !empty($post) ? $post->post_content : ''; |
|
| 1252 | + return apply_filters('wpinv_get_description', $description, $this->ID, $this); |
|
| 1253 | 1253 | } |
| 1254 | 1254 | |
| 1255 | - public function get_status( $nicename = false ) { |
|
| 1256 | - if ( !$nicename ) { |
|
| 1255 | + public function get_status($nicename = false) { |
|
| 1256 | + if (!$nicename) { |
|
| 1257 | 1257 | $status = $this->status; |
| 1258 | 1258 | } else { |
| 1259 | 1259 | $status = $this->status_nicename; |
| 1260 | 1260 | } |
| 1261 | 1261 | |
| 1262 | - return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this ); |
|
| 1262 | + return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this); |
|
| 1263 | 1263 | } |
| 1264 | 1264 | |
| 1265 | 1265 | public function get_cart_details() { |
| 1266 | - return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this ); |
|
| 1266 | + return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this); |
|
| 1267 | 1267 | } |
| 1268 | 1268 | |
| 1269 | - public function get_subtotal( $currency = false ) { |
|
| 1270 | - $subtotal = wpinv_format_amount( $this->subtotal, NULL, !$currency ); |
|
| 1269 | + public function get_subtotal($currency = false) { |
|
| 1270 | + $subtotal = wpinv_format_amount($this->subtotal, NULL, !$currency); |
|
| 1271 | 1271 | |
| 1272 | - if ( $currency ) { |
|
| 1273 | - $subtotal = wpinv_price( $subtotal, $this->get_currency() ); |
|
| 1272 | + if ($currency) { |
|
| 1273 | + $subtotal = wpinv_price($subtotal, $this->get_currency()); |
|
| 1274 | 1274 | } |
| 1275 | 1275 | |
| 1276 | - return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency ); |
|
| 1276 | + return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency); |
|
| 1277 | 1277 | } |
| 1278 | 1278 | |
| 1279 | - public function get_total( $currency = false ) { |
|
| 1280 | - if ( $this->is_free_trial() ) { |
|
| 1281 | - $total = wpinv_format_amount( 0, NULL, !$currency ); |
|
| 1279 | + public function get_total($currency = false) { |
|
| 1280 | + if ($this->is_free_trial()) { |
|
| 1281 | + $total = wpinv_format_amount(0, NULL, !$currency); |
|
| 1282 | 1282 | } else { |
| 1283 | - $total = wpinv_format_amount( $this->total, NULL, !$currency ); |
|
| 1283 | + $total = wpinv_format_amount($this->total, NULL, !$currency); |
|
| 1284 | 1284 | } |
| 1285 | - if ( $currency ) { |
|
| 1286 | - $total = wpinv_price( $total, $this->get_currency() ); |
|
| 1285 | + if ($currency) { |
|
| 1286 | + $total = wpinv_price($total, $this->get_currency()); |
|
| 1287 | 1287 | } |
| 1288 | 1288 | |
| 1289 | - return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency ); |
|
| 1289 | + return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency); |
|
| 1290 | 1290 | } |
| 1291 | 1291 | |
| 1292 | - public function get_recurring_details( $field = '', $currency = false ) { |
|
| 1292 | + public function get_recurring_details($field = '', $currency = false) { |
|
| 1293 | 1293 | $data = array(); |
| 1294 | 1294 | $data['cart_details'] = $this->cart_details; |
| 1295 | 1295 | $data['subtotal'] = $this->get_subtotal(); |
@@ -1297,45 +1297,45 @@ discard block |
||
| 1297 | 1297 | $data['tax'] = $this->get_tax(); |
| 1298 | 1298 | $data['total'] = $this->get_total(); |
| 1299 | 1299 | |
| 1300 | - if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) { |
|
| 1300 | + if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) { |
|
| 1301 | 1301 | $is_free_trial = $this->is_free_trial(); |
| 1302 | - $discounts = $this->get_discounts( true ); |
|
| 1302 | + $discounts = $this->get_discounts(true); |
|
| 1303 | 1303 | |
| 1304 | - if ( $is_free_trial || !empty( $discounts ) ) { |
|
| 1304 | + if ($is_free_trial || !empty($discounts)) { |
|
| 1305 | 1305 | $first_use_only = false; |
| 1306 | 1306 | |
| 1307 | - if ( !empty( $discounts ) ) { |
|
| 1308 | - foreach ( $discounts as $key => $code ) { |
|
| 1309 | - if ( wpinv_discount_is_recurring( $code, true ) ) { |
|
| 1307 | + if (!empty($discounts)) { |
|
| 1308 | + foreach ($discounts as $key => $code) { |
|
| 1309 | + if (wpinv_discount_is_recurring($code, true)) { |
|
| 1310 | 1310 | $first_use_only = true; |
| 1311 | 1311 | break; |
| 1312 | 1312 | } |
| 1313 | 1313 | } |
| 1314 | 1314 | } |
| 1315 | 1315 | |
| 1316 | - if ( !$first_use_only ) { |
|
| 1317 | - $data['subtotal'] = wpinv_format_amount( $this->subtotal, NULL, true ); |
|
| 1318 | - $data['discount'] = wpinv_format_amount( $this->discount, NULL, true ); |
|
| 1319 | - $data['tax'] = wpinv_format_amount( $this->tax, NULL, true ); |
|
| 1320 | - $data['total'] = wpinv_format_amount( $this->total, NULL, true ); |
|
| 1316 | + if (!$first_use_only) { |
|
| 1317 | + $data['subtotal'] = wpinv_format_amount($this->subtotal, NULL, true); |
|
| 1318 | + $data['discount'] = wpinv_format_amount($this->discount, NULL, true); |
|
| 1319 | + $data['tax'] = wpinv_format_amount($this->tax, NULL, true); |
|
| 1320 | + $data['total'] = wpinv_format_amount($this->total, NULL, true); |
|
| 1321 | 1321 | } else { |
| 1322 | 1322 | $cart_subtotal = 0; |
| 1323 | 1323 | $cart_discount = 0; |
| 1324 | 1324 | $cart_tax = 0; |
| 1325 | 1325 | |
| 1326 | - foreach ( $this->cart_details as $key => $item ) { |
|
| 1327 | - $item_quantity = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
| 1328 | - $item_subtotal = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity; |
|
| 1326 | + foreach ($this->cart_details as $key => $item) { |
|
| 1327 | + $item_quantity = $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
| 1328 | + $item_subtotal = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity; |
|
| 1329 | 1329 | $item_discount = 0; |
| 1330 | - $item_tax = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0; |
|
| 1330 | + $item_tax = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float)$item['vat_rate']) : 0; |
|
| 1331 | 1331 | |
| 1332 | - if ( wpinv_prices_include_tax() ) { |
|
| 1333 | - $item_subtotal -= wpinv_format_amount( $item_tax, NULL, true ); |
|
| 1332 | + if (wpinv_prices_include_tax()) { |
|
| 1333 | + $item_subtotal -= wpinv_format_amount($item_tax, NULL, true); |
|
| 1334 | 1334 | } |
| 1335 | 1335 | |
| 1336 | 1336 | $item_total = $item_subtotal - $item_discount + $item_tax; |
| 1337 | 1337 | // Do not allow totals to go negative |
| 1338 | - if ( $item_total < 0 ) { |
|
| 1338 | + if ($item_total < 0) { |
|
| 1339 | 1339 | $item_total = 0; |
| 1340 | 1340 | } |
| 1341 | 1341 | |
@@ -1343,107 +1343,107 @@ discard block |
||
| 1343 | 1343 | $cart_discount += (float)($item_discount); |
| 1344 | 1344 | $cart_tax += (float)($item_tax); |
| 1345 | 1345 | |
| 1346 | - $data['cart_details'][$key]['discount'] = wpinv_format_amount( $item_discount, NULL, true ); |
|
| 1347 | - $data['cart_details'][$key]['tax'] = wpinv_format_amount( $item_tax, NULL, true ); |
|
| 1348 | - $data['cart_details'][$key]['price'] = wpinv_format_amount( $item_total, NULL, true ); |
|
| 1346 | + $data['cart_details'][$key]['discount'] = wpinv_format_amount($item_discount, NULL, true); |
|
| 1347 | + $data['cart_details'][$key]['tax'] = wpinv_format_amount($item_tax, NULL, true); |
|
| 1348 | + $data['cart_details'][$key]['price'] = wpinv_format_amount($item_total, NULL, true); |
|
| 1349 | 1349 | } |
| 1350 | 1350 | |
| 1351 | - $data['subtotal'] = wpinv_format_amount( $cart_subtotal, NULL, true ); |
|
| 1352 | - $data['discount'] = wpinv_format_amount( $cart_discount, NULL, true ); |
|
| 1353 | - $data['tax'] = wpinv_format_amount( $cart_tax, NULL, true ); |
|
| 1354 | - $data['total'] = wpinv_format_amount( ( $data['subtotal'] + $data['tax'] ), NULL, true ); |
|
| 1351 | + $data['subtotal'] = wpinv_format_amount($cart_subtotal, NULL, true); |
|
| 1352 | + $data['discount'] = wpinv_format_amount($cart_discount, NULL, true); |
|
| 1353 | + $data['tax'] = wpinv_format_amount($cart_tax, NULL, true); |
|
| 1354 | + $data['total'] = wpinv_format_amount(($data['subtotal'] + $data['tax']), NULL, true); |
|
| 1355 | 1355 | } |
| 1356 | 1356 | } |
| 1357 | 1357 | } |
| 1358 | 1358 | |
| 1359 | - $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency ); |
|
| 1359 | + $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency); |
|
| 1360 | 1360 | |
| 1361 | - if ( isset( $data[$field] ) ) { |
|
| 1362 | - return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
|
| 1361 | + if (isset($data[$field])) { |
|
| 1362 | + return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]); |
|
| 1363 | 1363 | } |
| 1364 | 1364 | |
| 1365 | 1365 | return $data; |
| 1366 | 1366 | } |
| 1367 | 1367 | |
| 1368 | - public function get_final_tax( $currency = false ) { |
|
| 1369 | - $final_total = wpinv_format_amount( $this->tax, NULL, !$currency ); |
|
| 1370 | - if ( $currency ) { |
|
| 1371 | - $final_total = wpinv_price( $final_total, $this->get_currency() ); |
|
| 1368 | + public function get_final_tax($currency = false) { |
|
| 1369 | + $final_total = wpinv_format_amount($this->tax, NULL, !$currency); |
|
| 1370 | + if ($currency) { |
|
| 1371 | + $final_total = wpinv_price($final_total, $this->get_currency()); |
|
| 1372 | 1372 | } |
| 1373 | 1373 | |
| 1374 | - return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency ); |
|
| 1374 | + return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency); |
|
| 1375 | 1375 | } |
| 1376 | 1376 | |
| 1377 | - public function get_discounts( $array = false ) { |
|
| 1377 | + public function get_discounts($array = false) { |
|
| 1378 | 1378 | $discounts = $this->discounts; |
| 1379 | - if ( $array && $discounts ) { |
|
| 1380 | - $discounts = explode( ',', $discounts ); |
|
| 1379 | + if ($array && $discounts) { |
|
| 1380 | + $discounts = explode(',', $discounts); |
|
| 1381 | 1381 | } |
| 1382 | - return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array ); |
|
| 1382 | + return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array); |
|
| 1383 | 1383 | } |
| 1384 | 1384 | |
| 1385 | - public function get_discount( $currency = false, $dash = false ) { |
|
| 1386 | - if ( !empty( $this->discounts ) ) { |
|
| 1385 | + public function get_discount($currency = false, $dash = false) { |
|
| 1386 | + if (!empty($this->discounts)) { |
|
| 1387 | 1387 | global $ajax_cart_details; |
| 1388 | 1388 | $ajax_cart_details = $this->get_cart_details(); |
| 1389 | 1389 | |
| 1390 | - $this->discount = wpinv_get_cart_items_discount_amount( $this->items , $this->discounts ); |
|
| 1390 | + $this->discount = wpinv_get_cart_items_discount_amount($this->items, $this->discounts); |
|
| 1391 | 1391 | } |
| 1392 | - $discount = wpinv_format_amount( $this->discount, NULL, !$currency ); |
|
| 1392 | + $discount = wpinv_format_amount($this->discount, NULL, !$currency); |
|
| 1393 | 1393 | $dash = $dash && $discount > 0 ? '–' : ''; |
| 1394 | 1394 | |
| 1395 | - if ( $currency ) { |
|
| 1396 | - $discount = wpinv_price( $discount, $this->get_currency() ); |
|
| 1395 | + if ($currency) { |
|
| 1396 | + $discount = wpinv_price($discount, $this->get_currency()); |
|
| 1397 | 1397 | } |
| 1398 | 1398 | |
| 1399 | - $discount = $dash . $discount; |
|
| 1399 | + $discount = $dash . $discount; |
|
| 1400 | 1400 | |
| 1401 | - return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash ); |
|
| 1401 | + return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash); |
|
| 1402 | 1402 | } |
| 1403 | 1403 | |
| 1404 | 1404 | public function get_discount_code() { |
| 1405 | 1405 | return $this->discount_code; |
| 1406 | 1406 | } |
| 1407 | 1407 | |
| 1408 | - public function get_tax( $currency = false ) { |
|
| 1409 | - $tax = wpinv_format_amount( $this->tax, NULL, !$currency ); |
|
| 1408 | + public function get_tax($currency = false) { |
|
| 1409 | + $tax = wpinv_format_amount($this->tax, NULL, !$currency); |
|
| 1410 | 1410 | |
| 1411 | - if ( $currency ) { |
|
| 1412 | - $tax = wpinv_price( $tax, $this->get_currency() ); |
|
| 1411 | + if ($currency) { |
|
| 1412 | + $tax = wpinv_price($tax, $this->get_currency()); |
|
| 1413 | 1413 | } |
| 1414 | 1414 | |
| 1415 | - return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency ); |
|
| 1415 | + return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency); |
|
| 1416 | 1416 | } |
| 1417 | 1417 | |
| 1418 | - public function get_fees( $type = 'all' ) { |
|
| 1419 | - $fees = array(); |
|
| 1418 | + public function get_fees($type = 'all') { |
|
| 1419 | + $fees = array(); |
|
| 1420 | 1420 | |
| 1421 | - if ( ! empty( $this->fees ) && is_array( $this->fees ) ) { |
|
| 1422 | - foreach ( $this->fees as $fee ) { |
|
| 1423 | - if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
| 1421 | + if (!empty($this->fees) && is_array($this->fees)) { |
|
| 1422 | + foreach ($this->fees as $fee) { |
|
| 1423 | + if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) { |
|
| 1424 | 1424 | continue; |
| 1425 | 1425 | } |
| 1426 | 1426 | |
| 1427 | - $fee['label'] = stripslashes( $fee['label'] ); |
|
| 1428 | - $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() ); |
|
| 1429 | - $fees[] = $fee; |
|
| 1427 | + $fee['label'] = stripslashes($fee['label']); |
|
| 1428 | + $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency()); |
|
| 1429 | + $fees[] = $fee; |
|
| 1430 | 1430 | } |
| 1431 | 1431 | } |
| 1432 | 1432 | |
| 1433 | - return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this ); |
|
| 1433 | + return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this); |
|
| 1434 | 1434 | } |
| 1435 | 1435 | |
| 1436 | - public function get_fees_total( $type = 'all' ) { |
|
| 1437 | - $fees_total = (float) 0.00; |
|
| 1436 | + public function get_fees_total($type = 'all') { |
|
| 1437 | + $fees_total = (float)0.00; |
|
| 1438 | 1438 | |
| 1439 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
| 1440 | - if ( ! empty( $payment_fees ) ) { |
|
| 1441 | - foreach ( $payment_fees as $fee ) { |
|
| 1442 | - $fees_total += (float) $fee['amount']; |
|
| 1439 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
| 1440 | + if (!empty($payment_fees)) { |
|
| 1441 | + foreach ($payment_fees as $fee) { |
|
| 1442 | + $fees_total += (float)$fee['amount']; |
|
| 1443 | 1443 | } |
| 1444 | 1444 | } |
| 1445 | 1445 | |
| 1446 | - return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this ); |
|
| 1446 | + return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this); |
|
| 1447 | 1447 | /* |
| 1448 | 1448 | $fees = $this->get_fees( $type ); |
| 1449 | 1449 | |
@@ -1463,116 +1463,116 @@ discard block |
||
| 1463 | 1463 | } |
| 1464 | 1464 | |
| 1465 | 1465 | public function get_user_id() { |
| 1466 | - return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this ); |
|
| 1466 | + return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this); |
|
| 1467 | 1467 | } |
| 1468 | 1468 | |
| 1469 | 1469 | public function get_first_name() { |
| 1470 | - return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this ); |
|
| 1470 | + return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this); |
|
| 1471 | 1471 | } |
| 1472 | 1472 | |
| 1473 | 1473 | public function get_last_name() { |
| 1474 | - return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this ); |
|
| 1474 | + return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this); |
|
| 1475 | 1475 | } |
| 1476 | 1476 | |
| 1477 | 1477 | public function get_user_full_name() { |
| 1478 | - return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this ); |
|
| 1478 | + return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this); |
|
| 1479 | 1479 | } |
| 1480 | 1480 | |
| 1481 | 1481 | public function get_user_info() { |
| 1482 | - return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this ); |
|
| 1482 | + return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this); |
|
| 1483 | 1483 | } |
| 1484 | 1484 | |
| 1485 | 1485 | public function get_email() { |
| 1486 | - return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this ); |
|
| 1486 | + return apply_filters('wpinv_user_email', $this->email, $this->ID, $this); |
|
| 1487 | 1487 | } |
| 1488 | 1488 | |
| 1489 | 1489 | public function get_address() { |
| 1490 | - return apply_filters( 'wpinv_address', $this->address, $this->ID, $this ); |
|
| 1490 | + return apply_filters('wpinv_address', $this->address, $this->ID, $this); |
|
| 1491 | 1491 | } |
| 1492 | 1492 | |
| 1493 | 1493 | public function get_phone() { |
| 1494 | - return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this ); |
|
| 1494 | + return apply_filters('wpinv_phone', $this->phone, $this->ID, $this); |
|
| 1495 | 1495 | } |
| 1496 | 1496 | |
| 1497 | 1497 | public function get_number() { |
| 1498 | - return apply_filters( 'wpinv_number', $this->number, $this->ID, $this ); |
|
| 1498 | + return apply_filters('wpinv_number', $this->number, $this->ID, $this); |
|
| 1499 | 1499 | } |
| 1500 | 1500 | |
| 1501 | 1501 | public function get_items() { |
| 1502 | - return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this ); |
|
| 1502 | + return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this); |
|
| 1503 | 1503 | } |
| 1504 | 1504 | |
| 1505 | 1505 | public function get_key() { |
| 1506 | - return apply_filters( 'wpinv_key', $this->key, $this->ID, $this ); |
|
| 1506 | + return apply_filters('wpinv_key', $this->key, $this->ID, $this); |
|
| 1507 | 1507 | } |
| 1508 | 1508 | |
| 1509 | 1509 | public function get_transaction_id() { |
| 1510 | - return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this ); |
|
| 1510 | + return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this); |
|
| 1511 | 1511 | } |
| 1512 | 1512 | |
| 1513 | 1513 | public function get_gateway() { |
| 1514 | - return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this ); |
|
| 1514 | + return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this); |
|
| 1515 | 1515 | } |
| 1516 | 1516 | |
| 1517 | 1517 | public function get_gateway_title() { |
| 1518 | - $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway ); |
|
| 1518 | + $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway); |
|
| 1519 | 1519 | |
| 1520 | - return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this ); |
|
| 1520 | + return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this); |
|
| 1521 | 1521 | } |
| 1522 | 1522 | |
| 1523 | 1523 | public function get_currency() { |
| 1524 | - return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this ); |
|
| 1524 | + return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this); |
|
| 1525 | 1525 | } |
| 1526 | 1526 | |
| 1527 | 1527 | public function get_created_date() { |
| 1528 | - return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this ); |
|
| 1528 | + return apply_filters('wpinv_created_date', $this->date, $this->ID, $this); |
|
| 1529 | 1529 | } |
| 1530 | 1530 | |
| 1531 | - public function get_due_date( $display = false ) { |
|
| 1532 | - $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this ); |
|
| 1531 | + public function get_due_date($display = false) { |
|
| 1532 | + $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this); |
|
| 1533 | 1533 | |
| 1534 | - if ( !$display || empty( $due_date ) ) { |
|
| 1534 | + if (!$display || empty($due_date)) { |
|
| 1535 | 1535 | return $due_date; |
| 1536 | 1536 | } |
| 1537 | 1537 | |
| 1538 | - return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) ); |
|
| 1538 | + return date_i18n(get_option('date_format'), strtotime($due_date)); |
|
| 1539 | 1539 | } |
| 1540 | 1540 | |
| 1541 | 1541 | public function get_completed_date() { |
| 1542 | - return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this ); |
|
| 1542 | + return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this); |
|
| 1543 | 1543 | } |
| 1544 | 1544 | |
| 1545 | - public function get_invoice_date( $formatted = true ) { |
|
| 1545 | + public function get_invoice_date($formatted = true) { |
|
| 1546 | 1546 | $date_completed = $this->completed_date; |
| 1547 | 1547 | $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : ''; |
| 1548 | 1548 | |
| 1549 | - if ( $invoice_date == '' ) { |
|
| 1549 | + if ($invoice_date == '') { |
|
| 1550 | 1550 | $date_created = $this->date; |
| 1551 | 1551 | $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : ''; |
| 1552 | 1552 | } |
| 1553 | 1553 | |
| 1554 | - if ( $formatted && $invoice_date ) { |
|
| 1555 | - $invoice_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) ); |
|
| 1554 | + if ($formatted && $invoice_date) { |
|
| 1555 | + $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date)); |
|
| 1556 | 1556 | } |
| 1557 | 1557 | |
| 1558 | - return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this ); |
|
| 1558 | + return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this); |
|
| 1559 | 1559 | } |
| 1560 | 1560 | |
| 1561 | 1561 | public function get_ip() { |
| 1562 | - return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this ); |
|
| 1562 | + return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this); |
|
| 1563 | 1563 | } |
| 1564 | 1564 | |
| 1565 | - public function has_status( $status ) { |
|
| 1566 | - return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status ); |
|
| 1565 | + public function has_status($status) { |
|
| 1566 | + return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status); |
|
| 1567 | 1567 | } |
| 1568 | 1568 | |
| 1569 | - public function add_item( $item_id = 0, $args = array() ) { |
|
| 1569 | + public function add_item($item_id = 0, $args = array()) { |
|
| 1570 | 1570 | global $wpi_current_id, $wpi_item_id; |
| 1571 | 1571 | |
| 1572 | - $item = new WPInv_Item( $item_id ); |
|
| 1572 | + $item = new WPInv_Item($item_id); |
|
| 1573 | 1573 | |
| 1574 | 1574 | // Bail if this post isn't a item |
| 1575 | - if( !$item || $item->post_type !== 'wpi_item' ) { |
|
| 1575 | + if (!$item || $item->post_type !== 'wpi_item') { |
|
| 1576 | 1576 | return false; |
| 1577 | 1577 | } |
| 1578 | 1578 | |
@@ -1590,8 +1590,8 @@ discard block |
||
| 1590 | 1590 | 'fees' => array() |
| 1591 | 1591 | ); |
| 1592 | 1592 | |
| 1593 | - $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults ); |
|
| 1594 | - $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1; |
|
| 1593 | + $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults); |
|
| 1594 | + $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1; |
|
| 1595 | 1595 | |
| 1596 | 1596 | $wpi_current_id = $this->ID; |
| 1597 | 1597 | $wpi_item_id = $item->ID; |
@@ -1601,20 +1601,20 @@ discard block |
||
| 1601 | 1601 | $_POST['wpinv_state'] = $this->state; |
| 1602 | 1602 | |
| 1603 | 1603 | if ($has_quantities) { |
| 1604 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
| 1604 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
| 1605 | 1605 | |
| 1606 | - foreach ( $this->items as $key => $cart_item ) { |
|
| 1607 | - if ( (int)$item_id !== (int)$cart_item['id'] ) { |
|
| 1606 | + foreach ($this->items as $key => $cart_item) { |
|
| 1607 | + if ((int)$item_id !== (int)$cart_item['id']) { |
|
| 1608 | 1608 | continue; |
| 1609 | 1609 | } |
| 1610 | 1610 | |
| 1611 | - $this->items[ $key ]['quantity'] += $args['quantity']; |
|
| 1611 | + $this->items[$key]['quantity'] += $args['quantity']; |
|
| 1612 | 1612 | break; |
| 1613 | 1613 | } |
| 1614 | 1614 | |
| 1615 | 1615 | $found_cart_key = false; |
| 1616 | - foreach ( $this->cart_details as $cart_key => $cart_item ) { |
|
| 1617 | - if ( $item_id != $cart_item['id'] ) { |
|
| 1616 | + foreach ($this->cart_details as $cart_key => $cart_item) { |
|
| 1617 | + if ($item_id != $cart_item['id']) { |
|
| 1618 | 1618 | continue; |
| 1619 | 1619 | } |
| 1620 | 1620 | |
@@ -1626,29 +1626,29 @@ discard block |
||
| 1626 | 1626 | if ($has_quantities && $found_cart_key !== false) { |
| 1627 | 1627 | $cart_item = $this->cart_details[$found_cart_key]; |
| 1628 | 1628 | $item_price = $cart_item['item_price']; |
| 1629 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
| 1630 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
| 1629 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
| 1630 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
| 1631 | 1631 | |
| 1632 | 1632 | $new_quantity = $quantity + $args['quantity']; |
| 1633 | 1633 | $subtotal = $item_price * $new_quantity; |
| 1634 | 1634 | |
| 1635 | 1635 | $args['quantity'] = $new_quantity; |
| 1636 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
| 1637 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
| 1636 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
| 1637 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0; |
|
| 1638 | 1638 | |
| 1639 | 1639 | $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0; |
| 1640 | 1640 | $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0; |
| 1641 | 1641 | // The total increase equals the number removed * the item_price |
| 1642 | - $total_increased = wpinv_format_amount( $item_price, NULL, true ); |
|
| 1642 | + $total_increased = wpinv_format_amount($item_price, NULL, true); |
|
| 1643 | 1643 | |
| 1644 | - if ( wpinv_prices_include_tax() ) { |
|
| 1645 | - $subtotal -= wpinv_format_amount( $tax, NULL, true ); |
|
| 1644 | + if (wpinv_prices_include_tax()) { |
|
| 1645 | + $subtotal -= wpinv_format_amount($tax, NULL, true); |
|
| 1646 | 1646 | } |
| 1647 | 1647 | |
| 1648 | - $total = $subtotal - $discount + $tax; |
|
| 1648 | + $total = $subtotal - $discount + $tax; |
|
| 1649 | 1649 | |
| 1650 | 1650 | // Do not allow totals to go negative |
| 1651 | - if( $total < 0 ) { |
|
| 1651 | + if ($total < 0) { |
|
| 1652 | 1652 | $total = 0; |
| 1653 | 1653 | } |
| 1654 | 1654 | |
@@ -1664,20 +1664,20 @@ discard block |
||
| 1664 | 1664 | $this->cart_details[$found_cart_key] = $cart_item; |
| 1665 | 1665 | } else { |
| 1666 | 1666 | // Allow overriding the price |
| 1667 | - if( false !== $args['item_price'] ) { |
|
| 1667 | + if (false !== $args['item_price']) { |
|
| 1668 | 1668 | $item_price = $args['item_price']; |
| 1669 | 1669 | } else { |
| 1670 | - $item_price = wpinv_get_item_price( $item->ID ); |
|
| 1670 | + $item_price = wpinv_get_item_price($item->ID); |
|
| 1671 | 1671 | } |
| 1672 | 1672 | |
| 1673 | 1673 | // Sanitizing the price here so we don't have a dozen calls later |
| 1674 | - $item_price = wpinv_sanitize_amount( $item_price ); |
|
| 1675 | - $subtotal = wpinv_format_amount( $item_price * $args['quantity'], NULL, true ); |
|
| 1674 | + $item_price = wpinv_sanitize_amount($item_price); |
|
| 1675 | + $subtotal = wpinv_format_amount($item_price * $args['quantity'], NULL, true); |
|
| 1676 | 1676 | |
| 1677 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
| 1678 | - $tax_class = !empty( $args['vat_class'] ) ? $args['vat_class'] : ''; |
|
| 1679 | - $tax_rate = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0; |
|
| 1680 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
| 1677 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
| 1678 | + $tax_class = !empty($args['vat_class']) ? $args['vat_class'] : ''; |
|
| 1679 | + $tax_rate = !empty($args['vat_rate']) ? $args['vat_rate'] : 0; |
|
| 1680 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0; |
|
| 1681 | 1681 | |
| 1682 | 1682 | // Setup the items meta item |
| 1683 | 1683 | $new_item = array( |
@@ -1685,28 +1685,28 @@ discard block |
||
| 1685 | 1685 | 'quantity' => $args['quantity'], |
| 1686 | 1686 | ); |
| 1687 | 1687 | |
| 1688 | - $this->items[] = $new_item; |
|
| 1688 | + $this->items[] = $new_item; |
|
| 1689 | 1689 | |
| 1690 | - if ( wpinv_prices_include_tax() ) { |
|
| 1691 | - $subtotal -= wpinv_format_amount( $tax, NULL, true ); |
|
| 1690 | + if (wpinv_prices_include_tax()) { |
|
| 1691 | + $subtotal -= wpinv_format_amount($tax, NULL, true); |
|
| 1692 | 1692 | } |
| 1693 | 1693 | |
| 1694 | - $total = $subtotal - $discount + $tax; |
|
| 1694 | + $total = $subtotal - $discount + $tax; |
|
| 1695 | 1695 | |
| 1696 | 1696 | // Do not allow totals to go negative |
| 1697 | - if( $total < 0 ) { |
|
| 1697 | + if ($total < 0) { |
|
| 1698 | 1698 | $total = 0; |
| 1699 | 1699 | } |
| 1700 | 1700 | |
| 1701 | 1701 | $this->cart_details[] = array( |
| 1702 | 1702 | 'name' => !empty($args['name']) ? $args['name'] : $item->get_name(), |
| 1703 | 1703 | 'id' => $item->ID, |
| 1704 | - 'item_price' => wpinv_format_amount( $item_price, NULL, true ), |
|
| 1704 | + 'item_price' => wpinv_format_amount($item_price, NULL, true), |
|
| 1705 | 1705 | 'quantity' => $args['quantity'], |
| 1706 | 1706 | 'discount' => $discount, |
| 1707 | - 'subtotal' => wpinv_format_amount( $subtotal, NULL, true ), |
|
| 1708 | - 'tax' => wpinv_format_amount( $tax, NULL, true ), |
|
| 1709 | - 'price' => wpinv_format_amount( $total, NULL, true ), |
|
| 1707 | + 'subtotal' => wpinv_format_amount($subtotal, NULL, true), |
|
| 1708 | + 'tax' => wpinv_format_amount($tax, NULL, true), |
|
| 1709 | + 'price' => wpinv_format_amount($total, NULL, true), |
|
| 1710 | 1710 | 'vat_rate' => $tax_rate, |
| 1711 | 1711 | 'vat_class' => $tax_class, |
| 1712 | 1712 | 'meta' => $args['meta'], |
@@ -1716,69 +1716,69 @@ discard block |
||
| 1716 | 1716 | $subtotal = $subtotal - $discount; |
| 1717 | 1717 | } |
| 1718 | 1718 | |
| 1719 | - $added_item = end( $this->cart_details ); |
|
| 1720 | - $added_item['action'] = 'add'; |
|
| 1719 | + $added_item = end($this->cart_details); |
|
| 1720 | + $added_item['action'] = 'add'; |
|
| 1721 | 1721 | |
| 1722 | 1722 | $this->pending['items'][] = $added_item; |
| 1723 | 1723 | |
| 1724 | - $this->increase_subtotal( $subtotal ); |
|
| 1725 | - $this->increase_tax( $tax ); |
|
| 1724 | + $this->increase_subtotal($subtotal); |
|
| 1725 | + $this->increase_tax($tax); |
|
| 1726 | 1726 | |
| 1727 | 1727 | return true; |
| 1728 | 1728 | } |
| 1729 | 1729 | |
| 1730 | - public function remove_item( $item_id, $args = array() ) { |
|
| 1730 | + public function remove_item($item_id, $args = array()) { |
|
| 1731 | 1731 | // Set some defaults |
| 1732 | 1732 | $defaults = array( |
| 1733 | 1733 | 'quantity' => 1, |
| 1734 | 1734 | 'item_price' => false, |
| 1735 | 1735 | 'cart_index' => false, |
| 1736 | 1736 | ); |
| 1737 | - $args = wp_parse_args( $args, $defaults ); |
|
| 1737 | + $args = wp_parse_args($args, $defaults); |
|
| 1738 | 1738 | |
| 1739 | 1739 | // Bail if this post isn't a item |
| 1740 | - if ( get_post_type( $item_id ) !== 'wpi_item' ) { |
|
| 1740 | + if (get_post_type($item_id) !== 'wpi_item') { |
|
| 1741 | 1741 | return false; |
| 1742 | 1742 | } |
| 1743 | 1743 | |
| 1744 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
| 1744 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
| 1745 | 1745 | |
| 1746 | - foreach ( $this->items as $key => $item ) { |
|
| 1747 | - if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) { |
|
| 1746 | + foreach ($this->items as $key => $item) { |
|
| 1747 | + if (!empty($item['id']) && (int)$item_id !== (int)$item['id']) { |
|
| 1748 | 1748 | continue; |
| 1749 | 1749 | } |
| 1750 | 1750 | |
| 1751 | - if ( false !== $args['cart_index'] ) { |
|
| 1752 | - $cart_index = absint( $args['cart_index'] ); |
|
| 1753 | - $cart_item = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false; |
|
| 1751 | + if (false !== $args['cart_index']) { |
|
| 1752 | + $cart_index = absint($args['cart_index']); |
|
| 1753 | + $cart_item = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false; |
|
| 1754 | 1754 | |
| 1755 | - if ( ! empty( $cart_item ) ) { |
|
| 1755 | + if (!empty($cart_item)) { |
|
| 1756 | 1756 | // If the cart index item isn't the same item ID, don't remove it |
| 1757 | - if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) { |
|
| 1757 | + if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) { |
|
| 1758 | 1758 | continue; |
| 1759 | 1759 | } |
| 1760 | 1760 | } |
| 1761 | 1761 | } |
| 1762 | 1762 | |
| 1763 | - $item_quantity = $this->items[ $key ]['quantity']; |
|
| 1764 | - if ( $item_quantity > $args['quantity'] ) { |
|
| 1765 | - $this->items[ $key ]['quantity'] -= $args['quantity']; |
|
| 1763 | + $item_quantity = $this->items[$key]['quantity']; |
|
| 1764 | + if ($item_quantity > $args['quantity']) { |
|
| 1765 | + $this->items[$key]['quantity'] -= $args['quantity']; |
|
| 1766 | 1766 | break; |
| 1767 | 1767 | } else { |
| 1768 | - unset( $this->items[ $key ] ); |
|
| 1768 | + unset($this->items[$key]); |
|
| 1769 | 1769 | break; |
| 1770 | 1770 | } |
| 1771 | 1771 | } |
| 1772 | 1772 | |
| 1773 | 1773 | $found_cart_key = false; |
| 1774 | - if ( false === $args['cart_index'] ) { |
|
| 1775 | - foreach ( $this->cart_details as $cart_key => $item ) { |
|
| 1776 | - if ( $item_id != $item['id'] ) { |
|
| 1774 | + if (false === $args['cart_index']) { |
|
| 1775 | + foreach ($this->cart_details as $cart_key => $item) { |
|
| 1776 | + if ($item_id != $item['id']) { |
|
| 1777 | 1777 | continue; |
| 1778 | 1778 | } |
| 1779 | 1779 | |
| 1780 | - if ( false !== $args['item_price'] ) { |
|
| 1781 | - if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) { |
|
| 1780 | + if (false !== $args['item_price']) { |
|
| 1781 | + if (isset($item['item_price']) && (float)$args['item_price'] != (float)$item['item_price']) { |
|
| 1782 | 1782 | continue; |
| 1783 | 1783 | } |
| 1784 | 1784 | } |
@@ -1787,13 +1787,13 @@ discard block |
||
| 1787 | 1787 | break; |
| 1788 | 1788 | } |
| 1789 | 1789 | } else { |
| 1790 | - $cart_index = absint( $args['cart_index'] ); |
|
| 1790 | + $cart_index = absint($args['cart_index']); |
|
| 1791 | 1791 | |
| 1792 | - if ( ! array_key_exists( $cart_index, $this->cart_details ) ) { |
|
| 1792 | + if (!array_key_exists($cart_index, $this->cart_details)) { |
|
| 1793 | 1793 | return false; // Invalid cart index passed. |
| 1794 | 1794 | } |
| 1795 | 1795 | |
| 1796 | - if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) { |
|
| 1796 | + if ((int)$this->cart_details[$cart_index]['id'] > 0 && (int)$this->cart_details[$cart_index]['id'] !== (int)$item_id) { |
|
| 1797 | 1797 | return false; // We still need the proper Item ID to be sure. |
| 1798 | 1798 | } |
| 1799 | 1799 | |
@@ -1801,41 +1801,41 @@ discard block |
||
| 1801 | 1801 | } |
| 1802 | 1802 | |
| 1803 | 1803 | $cart_item = $this->cart_details[$found_cart_key]; |
| 1804 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
| 1804 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
| 1805 | 1805 | |
| 1806 | - if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) { |
|
| 1806 | + if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) { |
|
| 1807 | 1807 | return false; // Invoice must contain at least one item. |
| 1808 | 1808 | } |
| 1809 | 1809 | |
| 1810 | - $discounts = $this->get_discounts(); |
|
| 1810 | + $discounts = $this->get_discounts(); |
|
| 1811 | 1811 | |
| 1812 | - if ( $quantity > $args['quantity'] ) { |
|
| 1812 | + if ($quantity > $args['quantity']) { |
|
| 1813 | 1813 | $item_price = $cart_item['item_price']; |
| 1814 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
| 1814 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
| 1815 | 1815 | |
| 1816 | - $new_quantity = max( $quantity - $args['quantity'], 1); |
|
| 1816 | + $new_quantity = max($quantity - $args['quantity'], 1); |
|
| 1817 | 1817 | $subtotal = $item_price * $new_quantity; |
| 1818 | 1818 | |
| 1819 | 1819 | $args['quantity'] = $new_quantity; |
| 1820 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
| 1821 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
| 1820 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
| 1821 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0; |
|
| 1822 | 1822 | |
| 1823 | - $discount_decrease = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_format_amount( ( (float)$cart_item['discount'] / $quantity ), NULL, true ) : 0; |
|
| 1823 | + $discount_decrease = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_format_amount(((float)$cart_item['discount'] / $quantity), NULL, true) : 0; |
|
| 1824 | 1824 | $discount_decrease = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; |
| 1825 | - $tax_decrease = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_format_amount( ( (float)$cart_item['tax'] / $quantity ), NULL, true ) : 0; |
|
| 1825 | + $tax_decrease = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_format_amount(((float)$cart_item['tax'] / $quantity), NULL, true) : 0; |
|
| 1826 | 1826 | $tax_decrease = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease; |
| 1827 | 1827 | |
| 1828 | 1828 | // The total increase equals the number removed * the item_price |
| 1829 | - $total_decrease = wpinv_format_amount( $item_price, NULL, true ); |
|
| 1829 | + $total_decrease = wpinv_format_amount($item_price, NULL, true); |
|
| 1830 | 1830 | |
| 1831 | - if ( wpinv_prices_include_tax() ) { |
|
| 1832 | - $subtotal -= wpinv_format_amount( $tax, NULL, true ); |
|
| 1831 | + if (wpinv_prices_include_tax()) { |
|
| 1832 | + $subtotal -= wpinv_format_amount($tax, NULL, true); |
|
| 1833 | 1833 | } |
| 1834 | 1834 | |
| 1835 | - $total = $subtotal - $discount + $tax; |
|
| 1835 | + $total = $subtotal - $discount + $tax; |
|
| 1836 | 1836 | |
| 1837 | 1837 | // Do not allow totals to go negative |
| 1838 | - if( $total < 0 ) { |
|
| 1838 | + if ($total < 0) { |
|
| 1839 | 1839 | $total = 0; |
| 1840 | 1840 | } |
| 1841 | 1841 | |
@@ -1854,16 +1854,16 @@ discard block |
||
| 1854 | 1854 | |
| 1855 | 1855 | $this->cart_details[$found_cart_key] = $cart_item; |
| 1856 | 1856 | |
| 1857 | - $remove_item = end( $this->cart_details ); |
|
| 1857 | + $remove_item = end($this->cart_details); |
|
| 1858 | 1858 | } else { |
| 1859 | 1859 | $item_price = $cart_item['item_price']; |
| 1860 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
| 1861 | - $tax = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0; |
|
| 1860 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
| 1861 | + $tax = !empty($cart_item['tax']) ? $cart_item['tax'] : 0; |
|
| 1862 | 1862 | |
| 1863 | - $subtotal_decrease = ( $item_price * $quantity ) - $discount; |
|
| 1863 | + $subtotal_decrease = ($item_price * $quantity) - $discount; |
|
| 1864 | 1864 | $tax_decrease = $tax; |
| 1865 | 1865 | |
| 1866 | - unset( $this->cart_details[$found_cart_key] ); |
|
| 1866 | + unset($this->cart_details[$found_cart_key]); |
|
| 1867 | 1867 | |
| 1868 | 1868 | $remove_item = $args; |
| 1869 | 1869 | $remove_item['id'] = $item_id; |
@@ -1874,8 +1874,8 @@ discard block |
||
| 1874 | 1874 | $remove_item['action'] = 'remove'; |
| 1875 | 1875 | $this->pending['items'][] = $remove_item; |
| 1876 | 1876 | |
| 1877 | - $this->decrease_subtotal( $subtotal_decrease ); |
|
| 1878 | - $this->decrease_tax( $tax_decrease ); |
|
| 1877 | + $this->decrease_subtotal($subtotal_decrease); |
|
| 1878 | + $this->decrease_tax($tax_decrease); |
|
| 1879 | 1879 | |
| 1880 | 1880 | return true; |
| 1881 | 1881 | } |
@@ -1883,7 +1883,7 @@ discard block |
||
| 1883 | 1883 | public function update_items($temp = false) { |
| 1884 | 1884 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave; |
| 1885 | 1885 | |
| 1886 | - if ( !empty( $this->cart_details ) ) { |
|
| 1886 | + if (!empty($this->cart_details)) { |
|
| 1887 | 1887 | $wpi_nosave = $temp; |
| 1888 | 1888 | $cart_subtotal = 0; |
| 1889 | 1889 | $cart_discount = 0; |
@@ -1893,41 +1893,41 @@ discard block |
||
| 1893 | 1893 | $_POST['wpinv_country'] = $this->country; |
| 1894 | 1894 | $_POST['wpinv_state'] = $this->state; |
| 1895 | 1895 | |
| 1896 | - foreach ( $this->cart_details as $key => $item ) { |
|
| 1896 | + foreach ($this->cart_details as $key => $item) { |
|
| 1897 | 1897 | $item_price = $item['item_price']; |
| 1898 | - $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
| 1899 | - $amount = wpinv_format_amount( $item_price * $quantity, NULL, true ); |
|
| 1898 | + $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
| 1899 | + $amount = wpinv_format_amount($item_price * $quantity, NULL, true); |
|
| 1900 | 1900 | $subtotal = $item_price * $quantity; |
| 1901 | 1901 | |
| 1902 | 1902 | $wpi_current_id = $this->ID; |
| 1903 | 1903 | $wpi_item_id = $item['id']; |
| 1904 | 1904 | |
| 1905 | - $discount = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() ); |
|
| 1905 | + $discount = wpinv_get_cart_item_discount_amount($item, $this->get_discounts()); |
|
| 1906 | 1906 | |
| 1907 | - $tax_rate = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id ); |
|
| 1908 | - $tax_class = $wpinv_euvat->get_item_class( $wpi_item_id ); |
|
| 1909 | - $tax = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
| 1907 | + $tax_rate = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id); |
|
| 1908 | + $tax_class = $wpinv_euvat->get_item_class($wpi_item_id); |
|
| 1909 | + $tax = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0; |
|
| 1910 | 1910 | |
| 1911 | - if ( wpinv_prices_include_tax() ) { |
|
| 1912 | - $subtotal -= wpinv_format_amount( $tax, NULL, true ); |
|
| 1911 | + if (wpinv_prices_include_tax()) { |
|
| 1912 | + $subtotal -= wpinv_format_amount($tax, NULL, true); |
|
| 1913 | 1913 | } |
| 1914 | 1914 | |
| 1915 | - $total = $subtotal - $discount + $tax; |
|
| 1915 | + $total = $subtotal - $discount + $tax; |
|
| 1916 | 1916 | |
| 1917 | 1917 | // Do not allow totals to go negative |
| 1918 | - if( $total < 0 ) { |
|
| 1918 | + if ($total < 0) { |
|
| 1919 | 1919 | $total = 0; |
| 1920 | 1920 | } |
| 1921 | 1921 | |
| 1922 | 1922 | $cart_details[] = array( |
| 1923 | 1923 | 'id' => $item['id'], |
| 1924 | 1924 | 'name' => $item['name'], |
| 1925 | - 'item_price' => wpinv_format_amount( $item_price, NULL, true ), |
|
| 1925 | + 'item_price' => wpinv_format_amount($item_price, NULL, true), |
|
| 1926 | 1926 | 'quantity' => $quantity, |
| 1927 | 1927 | 'discount' => $discount, |
| 1928 | - 'subtotal' => wpinv_format_amount( $subtotal, NULL, true ), |
|
| 1929 | - 'tax' => wpinv_format_amount( $tax, NULL, true ), |
|
| 1930 | - 'price' => wpinv_format_amount( $total, NULL, true ), |
|
| 1928 | + 'subtotal' => wpinv_format_amount($subtotal, NULL, true), |
|
| 1929 | + 'tax' => wpinv_format_amount($tax, NULL, true), |
|
| 1930 | + 'price' => wpinv_format_amount($total, NULL, true), |
|
| 1931 | 1931 | 'vat_rate' => $tax_rate, |
| 1932 | 1932 | 'vat_class' => $tax_class, |
| 1933 | 1933 | 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
@@ -1938,9 +1938,9 @@ discard block |
||
| 1938 | 1938 | $cart_discount += (float)($discount); |
| 1939 | 1939 | $cart_tax += (float)($tax); |
| 1940 | 1940 | } |
| 1941 | - $this->subtotal = wpinv_format_amount( $cart_subtotal, NULL, true ); |
|
| 1942 | - $this->tax = wpinv_format_amount( $cart_tax, NULL, true ); |
|
| 1943 | - $this->discount = wpinv_format_amount( $cart_discount, NULL, true ); |
|
| 1941 | + $this->subtotal = wpinv_format_amount($cart_subtotal, NULL, true); |
|
| 1942 | + $this->tax = wpinv_format_amount($cart_tax, NULL, true); |
|
| 1943 | + $this->discount = wpinv_format_amount($cart_discount, NULL, true); |
|
| 1944 | 1944 | |
| 1945 | 1945 | $this->recalculate_total(); |
| 1946 | 1946 | |
@@ -1952,221 +1952,221 @@ discard block |
||
| 1952 | 1952 | |
| 1953 | 1953 | public function recalculate_totals($temp = false) { |
| 1954 | 1954 | $this->update_items($temp); |
| 1955 | - $this->save( true ); |
|
| 1955 | + $this->save(true); |
|
| 1956 | 1956 | |
| 1957 | 1957 | return $this; |
| 1958 | 1958 | } |
| 1959 | 1959 | |
| 1960 | 1960 | public function needs_payment() { |
| 1961 | - $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'pending' ), $this ); |
|
| 1961 | + $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('pending'), $this); |
|
| 1962 | 1962 | |
| 1963 | - if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() ) ) { |
|
| 1963 | + if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial())) { |
|
| 1964 | 1964 | $needs_payment = true; |
| 1965 | 1965 | } else { |
| 1966 | 1966 | $needs_payment = false; |
| 1967 | 1967 | } |
| 1968 | 1968 | |
| 1969 | - return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses ); |
|
| 1969 | + return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses); |
|
| 1970 | 1970 | } |
| 1971 | 1971 | |
| 1972 | - public function get_checkout_payment_url( $on_checkout = false, $secret = false ) { |
|
| 1972 | + public function get_checkout_payment_url($on_checkout = false, $secret = false) { |
|
| 1973 | 1973 | $pay_url = wpinv_get_checkout_uri(); |
| 1974 | 1974 | |
| 1975 | - if ( is_ssl() ) { |
|
| 1976 | - $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
|
| 1975 | + if (is_ssl()) { |
|
| 1976 | + $pay_url = str_replace('http:', 'https:', $pay_url); |
|
| 1977 | 1977 | } |
| 1978 | 1978 | |
| 1979 | 1979 | $key = $this->get_key(); |
| 1980 | 1980 | |
| 1981 | - if ( $on_checkout ) { |
|
| 1982 | - $pay_url = add_query_arg( 'invoice_key', $key, $pay_url ); |
|
| 1981 | + if ($on_checkout) { |
|
| 1982 | + $pay_url = add_query_arg('invoice_key', $key, $pay_url); |
|
| 1983 | 1983 | } else { |
| 1984 | - $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url ); |
|
| 1984 | + $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url); |
|
| 1985 | 1985 | } |
| 1986 | 1986 | |
| 1987 | - if ( $secret ) { |
|
| 1988 | - $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url ); |
|
| 1987 | + if ($secret) { |
|
| 1988 | + $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url); |
|
| 1989 | 1989 | } |
| 1990 | 1990 | |
| 1991 | - return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this ); |
|
| 1991 | + return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this); |
|
| 1992 | 1992 | } |
| 1993 | 1993 | |
| 1994 | - public function get_view_url( $secret = false ) { |
|
| 1995 | - $print_url = get_permalink( $this->ID ); |
|
| 1994 | + public function get_view_url($secret = false) { |
|
| 1995 | + $print_url = get_permalink($this->ID); |
|
| 1996 | 1996 | |
| 1997 | - if ( $secret ) { |
|
| 1998 | - $print_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $print_url ); |
|
| 1997 | + if ($secret) { |
|
| 1998 | + $print_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $print_url); |
|
| 1999 | 1999 | } |
| 2000 | 2000 | |
| 2001 | - return apply_filters( 'wpinv_get_view_url', $print_url, $this ); |
|
| 2001 | + return apply_filters('wpinv_get_view_url', $print_url, $this); |
|
| 2002 | 2002 | } |
| 2003 | 2003 | |
| 2004 | - public function generate_key( $string = '' ) { |
|
| 2005 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
| 2006 | - return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) ); // Unique key |
|
| 2004 | + public function generate_key($string = '') { |
|
| 2005 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
| 2006 | + return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key |
|
| 2007 | 2007 | } |
| 2008 | 2008 | |
| 2009 | 2009 | public function is_recurring() { |
| 2010 | - if ( empty( $this->cart_details ) ) { |
|
| 2010 | + if (empty($this->cart_details)) { |
|
| 2011 | 2011 | return false; |
| 2012 | 2012 | } |
| 2013 | 2013 | |
| 2014 | 2014 | $has_subscription = false; |
| 2015 | - foreach( $this->cart_details as $cart_item ) { |
|
| 2016 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
| 2015 | + foreach ($this->cart_details as $cart_item) { |
|
| 2016 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
| 2017 | 2017 | $has_subscription = true; |
| 2018 | 2018 | break; |
| 2019 | 2019 | } |
| 2020 | 2020 | } |
| 2021 | 2021 | |
| 2022 | - if ( count( $this->cart_details ) > 1 ) { |
|
| 2022 | + if (count($this->cart_details) > 1) { |
|
| 2023 | 2023 | $has_subscription = false; |
| 2024 | 2024 | } |
| 2025 | 2025 | |
| 2026 | - return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details ); |
|
| 2026 | + return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details); |
|
| 2027 | 2027 | } |
| 2028 | 2028 | |
| 2029 | 2029 | public function is_free_trial() { |
| 2030 | 2030 | $is_free_trial = false; |
| 2031 | 2031 | |
| 2032 | - if ( $this->is_parent() && $item = $this->get_recurring( true ) ) { |
|
| 2033 | - if ( !empty( $item ) && $item->has_free_trial() ) { |
|
| 2032 | + if ($this->is_parent() && $item = $this->get_recurring(true)) { |
|
| 2033 | + if (!empty($item) && $item->has_free_trial()) { |
|
| 2034 | 2034 | $is_free_trial = true; |
| 2035 | 2035 | } |
| 2036 | 2036 | } |
| 2037 | 2037 | |
| 2038 | - return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details ); |
|
| 2038 | + return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details); |
|
| 2039 | 2039 | } |
| 2040 | 2040 | |
| 2041 | - public function get_recurring( $object = false ) { |
|
| 2041 | + public function get_recurring($object = false) { |
|
| 2042 | 2042 | $item = NULL; |
| 2043 | 2043 | |
| 2044 | - if ( empty( $this->cart_details ) ) { |
|
| 2044 | + if (empty($this->cart_details)) { |
|
| 2045 | 2045 | return $item; |
| 2046 | 2046 | } |
| 2047 | 2047 | |
| 2048 | - foreach( $this->cart_details as $cart_item ) { |
|
| 2049 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
| 2048 | + foreach ($this->cart_details as $cart_item) { |
|
| 2049 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
| 2050 | 2050 | $item = $cart_item['id']; |
| 2051 | 2051 | break; |
| 2052 | 2052 | } |
| 2053 | 2053 | } |
| 2054 | 2054 | |
| 2055 | - if ( $object ) { |
|
| 2056 | - $item = $item ? new WPInv_Item( $item ) : NULL; |
|
| 2055 | + if ($object) { |
|
| 2056 | + $item = $item ? new WPInv_Item($item) : NULL; |
|
| 2057 | 2057 | |
| 2058 | - apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this ); |
|
| 2058 | + apply_filters('wpinv_invoice_get_recurring_item', $item, $this); |
|
| 2059 | 2059 | } |
| 2060 | 2060 | |
| 2061 | - return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this ); |
|
| 2061 | + return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this); |
|
| 2062 | 2062 | } |
| 2063 | 2063 | |
| 2064 | 2064 | public function get_subscription_name() { |
| 2065 | - $item = $this->get_recurring( true ); |
|
| 2065 | + $item = $this->get_recurring(true); |
|
| 2066 | 2066 | |
| 2067 | - if ( empty( $item ) ) { |
|
| 2067 | + if (empty($item)) { |
|
| 2068 | 2068 | return NULL; |
| 2069 | 2069 | } |
| 2070 | 2070 | |
| 2071 | - if ( !($name = $item->get_name()) ) { |
|
| 2071 | + if (!($name = $item->get_name())) { |
|
| 2072 | 2072 | $name = $item->post_name; |
| 2073 | 2073 | } |
| 2074 | 2074 | |
| 2075 | - return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this ); |
|
| 2075 | + return apply_filters('wpinv_invoice_get_subscription_name', $name, $this); |
|
| 2076 | 2076 | } |
| 2077 | 2077 | |
| 2078 | 2078 | public function get_expiration() { |
| 2079 | - $expiration = $this->get_meta( '_wpinv_subscr_expiration', true ); |
|
| 2079 | + $expiration = $this->get_meta('_wpinv_subscr_expiration', true); |
|
| 2080 | 2080 | return $expiration; |
| 2081 | 2081 | } |
| 2082 | 2082 | |
| 2083 | - public function get_cancelled_date( $formatted = true ) { |
|
| 2084 | - $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta( '_wpinv_subscr_cancelled_on', true ) : ''; |
|
| 2083 | + public function get_cancelled_date($formatted = true) { |
|
| 2084 | + $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta('_wpinv_subscr_cancelled_on', true) : ''; |
|
| 2085 | 2085 | |
| 2086 | - if ( $formatted && $cancelled_date ) { |
|
| 2087 | - $cancelled_date = date_i18n( get_option( 'date_format' ), strtotime( $cancelled_date ) ); |
|
| 2086 | + if ($formatted && $cancelled_date) { |
|
| 2087 | + $cancelled_date = date_i18n(get_option('date_format'), strtotime($cancelled_date)); |
|
| 2088 | 2088 | } |
| 2089 | 2089 | |
| 2090 | 2090 | return $cancelled_date; |
| 2091 | 2091 | } |
| 2092 | 2092 | |
| 2093 | - public function get_trial_end_date( $formatted = true ) { |
|
| 2094 | - if ( !$this->is_free_trial() || !$this->is_paid() ) { |
|
| 2093 | + public function get_trial_end_date($formatted = true) { |
|
| 2094 | + if (!$this->is_free_trial() || !$this->is_paid()) { |
|
| 2095 | 2095 | return NULL; |
| 2096 | 2096 | } |
| 2097 | 2097 | |
| 2098 | - $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta( '_wpinv_subscr_trial_end', true ) : ''; |
|
| 2098 | + $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta('_wpinv_subscr_trial_end', true) : ''; |
|
| 2099 | 2099 | |
| 2100 | - if ( empty( $trial_end_date ) ) { |
|
| 2101 | - $trial_start_time = strtotime( $this->get_subscription_start() ); |
|
| 2102 | - $trial_start_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ; |
|
| 2100 | + if (empty($trial_end_date)) { |
|
| 2101 | + $trial_start_time = strtotime($this->get_subscription_start()); |
|
| 2102 | + $trial_start_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS); |
|
| 2103 | 2103 | |
| 2104 | - $trial_end_date = date_i18n( 'Y-m-d H:i:s', $trial_start_time ); |
|
| 2104 | + $trial_end_date = date_i18n('Y-m-d H:i:s', $trial_start_time); |
|
| 2105 | 2105 | } |
| 2106 | 2106 | |
| 2107 | - if ( $formatted && $trial_end_date ) { |
|
| 2108 | - $trial_end_date = date_i18n( get_option( 'date_format' ), strtotime( $trial_end_date ) ); |
|
| 2107 | + if ($formatted && $trial_end_date) { |
|
| 2108 | + $trial_end_date = date_i18n(get_option('date_format'), strtotime($trial_end_date)); |
|
| 2109 | 2109 | } |
| 2110 | 2110 | |
| 2111 | 2111 | return $trial_end_date; |
| 2112 | 2112 | } |
| 2113 | 2113 | |
| 2114 | - public function get_subscription_created( $default = true ) { |
|
| 2115 | - $created = $this->get_meta( '_wpinv_subscr_created', true ); |
|
| 2114 | + public function get_subscription_created($default = true) { |
|
| 2115 | + $created = $this->get_meta('_wpinv_subscr_created', true); |
|
| 2116 | 2116 | |
| 2117 | - if ( empty( $created ) && $default ) { |
|
| 2117 | + if (empty($created) && $default) { |
|
| 2118 | 2118 | $created = $this->date; |
| 2119 | 2119 | } |
| 2120 | 2120 | return $created; |
| 2121 | 2121 | } |
| 2122 | 2122 | |
| 2123 | - public function get_subscription_start( $formatted = true ) { |
|
| 2124 | - if ( !$this->is_paid() ) { |
|
| 2123 | + public function get_subscription_start($formatted = true) { |
|
| 2124 | + if (!$this->is_paid()) { |
|
| 2125 | 2125 | return '-'; |
| 2126 | 2126 | } |
| 2127 | - $start = $this->get_subscription_created(); |
|
| 2127 | + $start = $this->get_subscription_created(); |
|
| 2128 | 2128 | |
| 2129 | - if ( $formatted ) { |
|
| 2130 | - $date = date_i18n( get_option( 'date_format' ), strtotime( $start ) ); |
|
| 2129 | + if ($formatted) { |
|
| 2130 | + $date = date_i18n(get_option('date_format'), strtotime($start)); |
|
| 2131 | 2131 | } else { |
| 2132 | - $date = date_i18n( 'Y-m-d H:i:s', strtotime( $start ) ); |
|
| 2132 | + $date = date_i18n('Y-m-d H:i:s', strtotime($start)); |
|
| 2133 | 2133 | } |
| 2134 | 2134 | |
| 2135 | 2135 | return $date; |
| 2136 | 2136 | } |
| 2137 | 2137 | |
| 2138 | - public function get_subscription_end( $formatted = true ) { |
|
| 2139 | - if ( !$this->is_paid() ) { |
|
| 2138 | + public function get_subscription_end($formatted = true) { |
|
| 2139 | + if (!$this->is_paid()) { |
|
| 2140 | 2140 | return '-'; |
| 2141 | 2141 | } |
| 2142 | 2142 | $start = $this->get_subscription_created(); |
| 2143 | 2143 | $interval = $this->get_subscription_interval(); |
| 2144 | - $period = $this->get_subscription_period( true ); |
|
| 2144 | + $period = $this->get_subscription_period(true); |
|
| 2145 | 2145 | $bill_times = (int)$this->get_bill_times(); |
| 2146 | 2146 | |
| 2147 | - if ( $bill_times == 0 ) { |
|
| 2148 | - return $formatted ? __( 'Until cancelled', 'invoicing' ) : $bill_times; |
|
| 2147 | + if ($bill_times == 0) { |
|
| 2148 | + return $formatted ? __('Until cancelled', 'invoicing') : $bill_times; |
|
| 2149 | 2149 | } |
| 2150 | 2150 | |
| 2151 | - $total_period = $start . '+' . ( $interval * $bill_times ) . ' ' . $period; |
|
| 2151 | + $total_period = $start . '+' . ($interval * $bill_times) . ' ' . $period; |
|
| 2152 | 2152 | |
| 2153 | - $end_time = strtotime( $start . '+' . ( $interval * $bill_times ) . ' ' . $period ); |
|
| 2153 | + $end_time = strtotime($start . '+' . ($interval * $bill_times) . ' ' . $period); |
|
| 2154 | 2154 | |
| 2155 | - if ( $this->is_free_trial() ) { |
|
| 2156 | - $end_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ; |
|
| 2155 | + if ($this->is_free_trial()) { |
|
| 2156 | + $end_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS); |
|
| 2157 | 2157 | } |
| 2158 | 2158 | |
| 2159 | - if ( $formatted ) { |
|
| 2160 | - $date = date_i18n( get_option( 'date_format' ), $end_time ); |
|
| 2159 | + if ($formatted) { |
|
| 2160 | + $date = date_i18n(get_option('date_format'), $end_time); |
|
| 2161 | 2161 | } else { |
| 2162 | - $date = date_i18n( 'Y-m-d H:i:s', $end_time ); |
|
| 2162 | + $date = date_i18n('Y-m-d H:i:s', $end_time); |
|
| 2163 | 2163 | } |
| 2164 | 2164 | |
| 2165 | 2165 | return $date; |
| 2166 | 2166 | } |
| 2167 | 2167 | |
| 2168 | 2168 | public function get_expiration_time() { |
| 2169 | - return strtotime( $this->get_expiration(), current_time( 'timestamp' ) ); |
|
| 2169 | + return strtotime($this->get_expiration(), current_time('timestamp')); |
|
| 2170 | 2170 | } |
| 2171 | 2171 | |
| 2172 | 2172 | public function get_original_invoice_id() { |
@@ -2178,125 +2178,125 @@ discard block |
||
| 2178 | 2178 | return $subscription_data['bill_times']; |
| 2179 | 2179 | } |
| 2180 | 2180 | |
| 2181 | - public function get_child_payments( $self = false ) { |
|
| 2182 | - $invoices = get_posts( array( |
|
| 2181 | + public function get_child_payments($self = false) { |
|
| 2182 | + $invoices = get_posts(array( |
|
| 2183 | 2183 | 'post_type' => 'wpi_invoice', |
| 2184 | 2184 | 'post_parent' => (int)$this->ID, |
| 2185 | 2185 | 'posts_per_page' => '999', |
| 2186 | - 'post_status' => array( 'publish', 'complete', 'processing', 'renewal' ), |
|
| 2186 | + 'post_status' => array('publish', 'complete', 'processing', 'renewal'), |
|
| 2187 | 2187 | 'orderby' => 'ID', |
| 2188 | 2188 | 'order' => 'DESC', |
| 2189 | 2189 | 'fields' => 'ids' |
| 2190 | - ) ); |
|
| 2190 | + )); |
|
| 2191 | 2191 | |
| 2192 | - if ( $this->is_free_trial() ) { |
|
| 2192 | + if ($this->is_free_trial()) { |
|
| 2193 | 2193 | $self = false; |
| 2194 | 2194 | } |
| 2195 | 2195 | |
| 2196 | - if ( $self && $this->is_paid() ) { |
|
| 2197 | - if ( !empty( $invoices ) ) { |
|
| 2196 | + if ($self && $this->is_paid()) { |
|
| 2197 | + if (!empty($invoices)) { |
|
| 2198 | 2198 | $invoices[] = (int)$this->ID; |
| 2199 | 2199 | } else { |
| 2200 | - $invoices = array( $this->ID ); |
|
| 2200 | + $invoices = array($this->ID); |
|
| 2201 | 2201 | } |
| 2202 | 2202 | |
| 2203 | - $invoices = array_unique( $invoices ); |
|
| 2203 | + $invoices = array_unique($invoices); |
|
| 2204 | 2204 | } |
| 2205 | 2205 | |
| 2206 | 2206 | return $invoices; |
| 2207 | 2207 | } |
| 2208 | 2208 | |
| 2209 | - public function get_total_payments( $self = true ) { |
|
| 2210 | - return count( $this->get_child_payments( $self ) ); |
|
| 2209 | + public function get_total_payments($self = true) { |
|
| 2210 | + return count($this->get_child_payments($self)); |
|
| 2211 | 2211 | } |
| 2212 | 2212 | |
| 2213 | - public function get_subscriptions( $limit = -1 ) { |
|
| 2214 | - $subscriptions = wpinv_get_subscriptions( array( 'parent_invoice_id' => $this->ID, 'numberposts' => $limit ) ); |
|
| 2213 | + public function get_subscriptions($limit = -1) { |
|
| 2214 | + $subscriptions = wpinv_get_subscriptions(array('parent_invoice_id' => $this->ID, 'numberposts' => $limit)); |
|
| 2215 | 2215 | |
| 2216 | 2216 | return $subscriptions; |
| 2217 | 2217 | } |
| 2218 | 2218 | |
| 2219 | 2219 | public function get_subscription_id() { |
| 2220 | - $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true ); |
|
| 2220 | + $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true); |
|
| 2221 | 2221 | |
| 2222 | - if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) { |
|
| 2223 | - $parent_invoice = wpinv_get_invoice( $this->parent_invoice ); |
|
| 2222 | + if (empty($subscription_id) && !empty($this->parent_invoice)) { |
|
| 2223 | + $parent_invoice = wpinv_get_invoice($this->parent_invoice); |
|
| 2224 | 2224 | |
| 2225 | - $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true ); |
|
| 2225 | + $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true); |
|
| 2226 | 2226 | } |
| 2227 | 2227 | |
| 2228 | 2228 | return $subscription_id; |
| 2229 | 2229 | } |
| 2230 | 2230 | |
| 2231 | 2231 | public function get_subscription_status() { |
| 2232 | - $subscription_status = $this->get_meta( '_wpinv_subscr_status', true ); |
|
| 2232 | + $subscription_status = $this->get_meta('_wpinv_subscr_status', true); |
|
| 2233 | 2233 | |
| 2234 | - if ( empty( $subscription_status ) ) { |
|
| 2234 | + if (empty($subscription_status)) { |
|
| 2235 | 2235 | $status = 'pending'; |
| 2236 | 2236 | |
| 2237 | - if ( $this->is_paid() ) { |
|
| 2237 | + if ($this->is_paid()) { |
|
| 2238 | 2238 | $bill_times = (int)$this->get_bill_times(); |
| 2239 | 2239 | $times_billed = (int)$this->get_total_payments(); |
| 2240 | - $expiration = $this->get_subscription_end( false ); |
|
| 2241 | - $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime( date_i18n( 'Y-m-d', strtotime( $expiration ) ) ) < strtotime( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) ) ? true : false; |
|
| 2240 | + $expiration = $this->get_subscription_end(false); |
|
| 2241 | + $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime(date_i18n('Y-m-d', strtotime($expiration))) < strtotime(date_i18n('Y-m-d', current_time('timestamp'))) ? true : false; |
|
| 2242 | 2242 | |
| 2243 | - if ( (int)$bill_times == 0 ) { |
|
| 2243 | + if ((int)$bill_times == 0) { |
|
| 2244 | 2244 | $status = $expired ? 'expired' : 'active'; |
| 2245 | - } else if ( $bill_times > 0 && $times_billed >= $bill_times ) { |
|
| 2245 | + } else if ($bill_times > 0 && $times_billed >= $bill_times) { |
|
| 2246 | 2246 | $status = 'completed'; |
| 2247 | - } else if ( $expired ) { |
|
| 2247 | + } else if ($expired) { |
|
| 2248 | 2248 | $status = 'expired'; |
| 2249 | - } else if ( $bill_times > 0 ) { |
|
| 2249 | + } else if ($bill_times > 0) { |
|
| 2250 | 2250 | $status = 'active'; |
| 2251 | 2251 | } else { |
| 2252 | 2252 | $status = 'pending'; |
| 2253 | 2253 | } |
| 2254 | 2254 | } |
| 2255 | 2255 | |
| 2256 | - if ( $status && $status != $subscription_status ) { |
|
| 2256 | + if ($status && $status != $subscription_status) { |
|
| 2257 | 2257 | $subscription_status = $status; |
| 2258 | 2258 | |
| 2259 | - $this->update_meta( '_wpinv_subscr_status', $status ); |
|
| 2259 | + $this->update_meta('_wpinv_subscr_status', $status); |
|
| 2260 | 2260 | } |
| 2261 | 2261 | } |
| 2262 | 2262 | |
| 2263 | 2263 | return $subscription_status; |
| 2264 | 2264 | } |
| 2265 | 2265 | |
| 2266 | - public function get_subscription_status_label( $status = '' ) { |
|
| 2267 | - $status = !empty( $status ) ? $status : $this->get_subscription_status(); |
|
| 2266 | + public function get_subscription_status_label($status = '') { |
|
| 2267 | + $status = !empty($status) ? $status : $this->get_subscription_status(); |
|
| 2268 | 2268 | |
| 2269 | - switch( $status ) { |
|
| 2269 | + switch ($status) { |
|
| 2270 | 2270 | case 'active' : |
| 2271 | - $status_label = __( 'Active', 'invoicing' ); |
|
| 2271 | + $status_label = __('Active', 'invoicing'); |
|
| 2272 | 2272 | break; |
| 2273 | 2273 | |
| 2274 | 2274 | case 'cancelled' : |
| 2275 | - $status_label = __( 'Cancelled', 'invoicing' ); |
|
| 2275 | + $status_label = __('Cancelled', 'invoicing'); |
|
| 2276 | 2276 | break; |
| 2277 | 2277 | |
| 2278 | 2278 | case 'completed' : |
| 2279 | - $status_label = __( 'Completed', 'invoicing' ); |
|
| 2279 | + $status_label = __('Completed', 'invoicing'); |
|
| 2280 | 2280 | break; |
| 2281 | 2281 | |
| 2282 | 2282 | case 'expired' : |
| 2283 | - $status_label = __( 'Expired', 'invoicing' ); |
|
| 2283 | + $status_label = __('Expired', 'invoicing'); |
|
| 2284 | 2284 | break; |
| 2285 | 2285 | |
| 2286 | 2286 | case 'pending' : |
| 2287 | - $status_label = __( 'Pending', 'invoicing' ); |
|
| 2287 | + $status_label = __('Pending', 'invoicing'); |
|
| 2288 | 2288 | break; |
| 2289 | 2289 | |
| 2290 | 2290 | case 'failing' : |
| 2291 | - $status_label = __( 'Failing', 'invoicing' ); |
|
| 2291 | + $status_label = __('Failing', 'invoicing'); |
|
| 2292 | 2292 | break; |
| 2293 | 2293 | |
| 2294 | 2294 | case 'stopped' : |
| 2295 | - $status_label = __( 'Stopped', 'invoicing' ); |
|
| 2295 | + $status_label = __('Stopped', 'invoicing'); |
|
| 2296 | 2296 | break; |
| 2297 | 2297 | |
| 2298 | 2298 | case 'trialing' : |
| 2299 | - $status_label = __( 'Trialing', 'invoicing' ); |
|
| 2299 | + $status_label = __('Trialing', 'invoicing'); |
|
| 2300 | 2300 | break; |
| 2301 | 2301 | |
| 2302 | 2302 | default: |
@@ -2307,15 +2307,15 @@ discard block |
||
| 2307 | 2307 | return $status_label; |
| 2308 | 2308 | } |
| 2309 | 2309 | |
| 2310 | - public function get_subscription_period( $full = false ) { |
|
| 2311 | - $period = $this->get_meta( '_wpinv_subscr_period', true ); |
|
| 2310 | + public function get_subscription_period($full = false) { |
|
| 2311 | + $period = $this->get_meta('_wpinv_subscr_period', true); |
|
| 2312 | 2312 | |
| 2313 | - if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { |
|
| 2313 | + if (!in_array($period, array('D', 'W', 'M', 'Y'))) { |
|
| 2314 | 2314 | $period = 'D'; |
| 2315 | 2315 | } |
| 2316 | 2316 | |
| 2317 | - if ( $full ) { |
|
| 2318 | - switch( $period ) { |
|
| 2317 | + if ($full) { |
|
| 2318 | + switch ($period) { |
|
| 2319 | 2319 | case 'D': |
| 2320 | 2320 | $period = 'day'; |
| 2321 | 2321 | break; |
@@ -2335,28 +2335,28 @@ discard block |
||
| 2335 | 2335 | } |
| 2336 | 2336 | |
| 2337 | 2337 | public function get_subscription_interval() { |
| 2338 | - $interval = (int)$this->get_meta( '_wpinv_subscr_interval', true ); |
|
| 2338 | + $interval = (int)$this->get_meta('_wpinv_subscr_interval', true); |
|
| 2339 | 2339 | |
| 2340 | - if ( !$interval > 0 ) { |
|
| 2340 | + if (!$interval > 0) { |
|
| 2341 | 2341 | $interval = 1; |
| 2342 | 2342 | } |
| 2343 | 2343 | |
| 2344 | 2344 | return $interval; |
| 2345 | 2345 | } |
| 2346 | 2346 | |
| 2347 | - public function get_subscription_trial_period( $full = false ) { |
|
| 2348 | - if ( !$this->is_free_trial() ) { |
|
| 2347 | + public function get_subscription_trial_period($full = false) { |
|
| 2348 | + if (!$this->is_free_trial()) { |
|
| 2349 | 2349 | return ''; |
| 2350 | 2350 | } |
| 2351 | 2351 | |
| 2352 | - $period = $this->get_meta( '_wpinv_subscr_trial_period', true ); |
|
| 2352 | + $period = $this->get_meta('_wpinv_subscr_trial_period', true); |
|
| 2353 | 2353 | |
| 2354 | - if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { |
|
| 2354 | + if (!in_array($period, array('D', 'W', 'M', 'Y'))) { |
|
| 2355 | 2355 | $period = 'D'; |
| 2356 | 2356 | } |
| 2357 | 2357 | |
| 2358 | - if ( $full ) { |
|
| 2359 | - switch( $period ) { |
|
| 2358 | + if ($full) { |
|
| 2359 | + switch ($period) { |
|
| 2360 | 2360 | case 'D': |
| 2361 | 2361 | $period = 'day'; |
| 2362 | 2362 | break; |
@@ -2376,13 +2376,13 @@ discard block |
||
| 2376 | 2376 | } |
| 2377 | 2377 | |
| 2378 | 2378 | public function get_subscription_trial_interval() { |
| 2379 | - if ( !$this->is_free_trial() ) { |
|
| 2379 | + if (!$this->is_free_trial()) { |
|
| 2380 | 2380 | return 0; |
| 2381 | 2381 | } |
| 2382 | 2382 | |
| 2383 | - $interval = (int)$this->get_meta( '_wpinv_subscr_trial_interval', true ); |
|
| 2383 | + $interval = (int)$this->get_meta('_wpinv_subscr_trial_interval', true); |
|
| 2384 | 2384 | |
| 2385 | - if ( !$interval > 0 ) { |
|
| 2385 | + if (!$interval > 0) { |
|
| 2386 | 2386 | $interval = 1; |
| 2387 | 2387 | } |
| 2388 | 2388 | |
@@ -2394,8 +2394,8 @@ discard block |
||
| 2394 | 2394 | 'status' => 'failing' |
| 2395 | 2395 | ); |
| 2396 | 2396 | |
| 2397 | - if ( $this->update_subscription( $args ) ) { |
|
| 2398 | - do_action( 'wpinv_subscription_failing', $this->ID, $this ); |
|
| 2397 | + if ($this->update_subscription($args)) { |
|
| 2398 | + do_action('wpinv_subscription_failing', $this->ID, $this); |
|
| 2399 | 2399 | return true; |
| 2400 | 2400 | } |
| 2401 | 2401 | |
@@ -2407,8 +2407,8 @@ discard block |
||
| 2407 | 2407 | 'status' => 'stopped' |
| 2408 | 2408 | ); |
| 2409 | 2409 | |
| 2410 | - if ( $this->update_subscription( $args ) ) { |
|
| 2411 | - do_action( 'wpinv_subscription_stopped', $this->ID, $this ); |
|
| 2410 | + if ($this->update_subscription($args)) { |
|
| 2411 | + do_action('wpinv_subscription_stopped', $this->ID, $this); |
|
| 2412 | 2412 | return true; |
| 2413 | 2413 | } |
| 2414 | 2414 | |
@@ -2420,8 +2420,8 @@ discard block |
||
| 2420 | 2420 | 'status' => 'active' |
| 2421 | 2421 | ); |
| 2422 | 2422 | |
| 2423 | - if ( $this->update_subscription( $args ) ) { |
|
| 2424 | - do_action( 'wpinv_subscription_restarted', $this->ID, $this ); |
|
| 2423 | + if ($this->update_subscription($args)) { |
|
| 2424 | + do_action('wpinv_subscription_restarted', $this->ID, $this); |
|
| 2425 | 2425 | return true; |
| 2426 | 2426 | } |
| 2427 | 2427 | |
@@ -2433,23 +2433,23 @@ discard block |
||
| 2433 | 2433 | 'status' => 'cancelled' |
| 2434 | 2434 | ); |
| 2435 | 2435 | |
| 2436 | - if ( $this->update_subscription( $args ) ) { |
|
| 2437 | - if ( is_user_logged_in() ) { |
|
| 2438 | - $userdata = get_userdata( get_current_user_id() ); |
|
| 2436 | + if ($this->update_subscription($args)) { |
|
| 2437 | + if (is_user_logged_in()) { |
|
| 2438 | + $userdata = get_userdata(get_current_user_id()); |
|
| 2439 | 2439 | $user = $userdata->user_login; |
| 2440 | 2440 | } else { |
| 2441 | - $user = __( 'gateway', 'invoicing' ); |
|
| 2441 | + $user = __('gateway', 'invoicing'); |
|
| 2442 | 2442 | } |
| 2443 | 2443 | |
| 2444 | 2444 | $subscription_id = $this->get_subscription_id(); |
| 2445 | - if ( !$subscription_id ) { |
|
| 2445 | + if (!$subscription_id) { |
|
| 2446 | 2446 | $subscription_id = $this->ID; |
| 2447 | 2447 | } |
| 2448 | 2448 | |
| 2449 | - $note = sprintf( __( 'Subscription %s has been cancelled by %s', 'invoicing' ), $subscription_id, $user ); |
|
| 2450 | - $this->add_note( $note ); |
|
| 2449 | + $note = sprintf(__('Subscription %s has been cancelled by %s', 'invoicing'), $subscription_id, $user); |
|
| 2450 | + $this->add_note($note); |
|
| 2451 | 2451 | |
| 2452 | - do_action( 'wpinv_subscription_cancelled', $this->ID, $this ); |
|
| 2452 | + do_action('wpinv_subscription_cancelled', $this->ID, $this); |
|
| 2453 | 2453 | return true; |
| 2454 | 2454 | } |
| 2455 | 2455 | |
@@ -2457,11 +2457,11 @@ discard block |
||
| 2457 | 2457 | } |
| 2458 | 2458 | |
| 2459 | 2459 | public function can_cancel() { |
| 2460 | - return apply_filters( 'wpinv_subscription_can_cancel', false, $this ); |
|
| 2460 | + return apply_filters('wpinv_subscription_can_cancel', false, $this); |
|
| 2461 | 2461 | } |
| 2462 | 2462 | |
| 2463 | - public function add_subscription( $data = array() ) { |
|
| 2464 | - if ( empty( $this->ID ) ) { |
|
| 2463 | + public function add_subscription($data = array()) { |
|
| 2464 | + if (empty($this->ID)) { |
|
| 2465 | 2465 | return false; |
| 2466 | 2466 | } |
| 2467 | 2467 | |
@@ -2480,85 +2480,85 @@ discard block |
||
| 2480 | 2480 | 'profile_id' => '', |
| 2481 | 2481 | ); |
| 2482 | 2482 | |
| 2483 | - $args = wp_parse_args( $data, $defaults ); |
|
| 2483 | + $args = wp_parse_args($data, $defaults); |
|
| 2484 | 2484 | |
| 2485 | - if ( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
| 2486 | - if ( 'active' == $args['status'] || $args['status'] == 'trialing' ) { |
|
| 2485 | + if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) { |
|
| 2486 | + if ('active' == $args['status'] || $args['status'] == 'trialing') { |
|
| 2487 | 2487 | $args['status'] = 'expired'; |
| 2488 | 2488 | } |
| 2489 | 2489 | } |
| 2490 | 2490 | |
| 2491 | - do_action( 'wpinv_subscription_pre_create', $args, $data, $this ); |
|
| 2491 | + do_action('wpinv_subscription_pre_create', $args, $data, $this); |
|
| 2492 | 2492 | |
| 2493 | - if ( !empty( $args ) ) { |
|
| 2494 | - foreach ( $args as $key => $value ) { |
|
| 2495 | - $this->update_meta( '_wpinv_subscr_' . $key, $value ); |
|
| 2493 | + if (!empty($args)) { |
|
| 2494 | + foreach ($args as $key => $value) { |
|
| 2495 | + $this->update_meta('_wpinv_subscr_' . $key, $value); |
|
| 2496 | 2496 | } |
| 2497 | 2497 | } |
| 2498 | 2498 | |
| 2499 | - do_action( 'wpinv_subscription_post_create', $args, $data, $this ); |
|
| 2499 | + do_action('wpinv_subscription_post_create', $args, $data, $this); |
|
| 2500 | 2500 | |
| 2501 | 2501 | return true; |
| 2502 | 2502 | } |
| 2503 | 2503 | |
| 2504 | - public function update_subscription( $args = array() ) { |
|
| 2505 | - if ( empty( $this->ID ) ) { |
|
| 2504 | + public function update_subscription($args = array()) { |
|
| 2505 | + if (empty($this->ID)) { |
|
| 2506 | 2506 | return false; |
| 2507 | 2507 | } |
| 2508 | 2508 | |
| 2509 | - if ( !empty( $args['expiration'] ) && $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
| 2510 | - if ( !isset( $args['status'] ) || ( isset( $args['status'] ) && ( 'active' == $args['status'] || $args['status'] == 'trialing' ) ) ) { |
|
| 2509 | + if (!empty($args['expiration']) && $args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) { |
|
| 2510 | + if (!isset($args['status']) || (isset($args['status']) && ('active' == $args['status'] || $args['status'] == 'trialing'))) { |
|
| 2511 | 2511 | $args['status'] = 'expired'; |
| 2512 | 2512 | } |
| 2513 | 2513 | } |
| 2514 | 2514 | |
| 2515 | - if ( isset( $args['status'] ) && $args['status'] == 'cancelled' && empty( $args['cancelled_on'] ) ) { |
|
| 2516 | - $args['cancelled_on'] = date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ); |
|
| 2515 | + if (isset($args['status']) && $args['status'] == 'cancelled' && empty($args['cancelled_on'])) { |
|
| 2516 | + $args['cancelled_on'] = date_i18n('Y-m-d H:i:s', current_time('timestamp')); |
|
| 2517 | 2517 | } |
| 2518 | 2518 | |
| 2519 | - do_action( 'wpinv_subscription_pre_update', $args, $this ); |
|
| 2519 | + do_action('wpinv_subscription_pre_update', $args, $this); |
|
| 2520 | 2520 | |
| 2521 | - if ( !empty( $args ) ) { |
|
| 2522 | - foreach ( $args as $key => $value ) { |
|
| 2523 | - $this->update_meta( '_wpinv_subscr_' . $key, $value ); |
|
| 2521 | + if (!empty($args)) { |
|
| 2522 | + foreach ($args as $key => $value) { |
|
| 2523 | + $this->update_meta('_wpinv_subscr_' . $key, $value); |
|
| 2524 | 2524 | } |
| 2525 | 2525 | } |
| 2526 | 2526 | |
| 2527 | - do_action( 'wpinv_subscription_post_update', $args, $this ); |
|
| 2527 | + do_action('wpinv_subscription_post_update', $args, $this); |
|
| 2528 | 2528 | |
| 2529 | 2529 | return true; |
| 2530 | 2530 | } |
| 2531 | 2531 | |
| 2532 | 2532 | public function renew_subscription() { |
| 2533 | 2533 | $parent_invoice = $this->get_parent_payment(); |
| 2534 | - $parent_invoice = empty( $parent_invoice ) ? $this : $parent_invoice; |
|
| 2534 | + $parent_invoice = empty($parent_invoice) ? $this : $parent_invoice; |
|
| 2535 | 2535 | |
| 2536 | - $current_time = current_time( 'timestamp' ); |
|
| 2536 | + $current_time = current_time('timestamp'); |
|
| 2537 | 2537 | $start = $this->get_subscription_created(); |
| 2538 | - $start = $start ? strtotime( $start ) : $current_time; |
|
| 2538 | + $start = $start ? strtotime($start) : $current_time; |
|
| 2539 | 2539 | $expires = $this->get_expiration_time(); |
| 2540 | 2540 | |
| 2541 | - if ( !$expires ) { |
|
| 2542 | - $expires = strtotime( '+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period( true ), $start ); |
|
| 2541 | + if (!$expires) { |
|
| 2542 | + $expires = strtotime('+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period(true), $start); |
|
| 2543 | 2543 | } |
| 2544 | 2544 | |
| 2545 | - $expiration = date_i18n( 'Y-m-d 23:59:59', $expires ); |
|
| 2546 | - $expiration = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this ); |
|
| 2545 | + $expiration = date_i18n('Y-m-d 23:59:59', $expires); |
|
| 2546 | + $expiration = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this); |
|
| 2547 | 2547 | $bill_times = $parent_invoice->get_bill_times(); |
| 2548 | 2548 | $times_billed = $parent_invoice->get_total_payments(); |
| 2549 | 2549 | |
| 2550 | - if ( $parent_invoice->get_subscription_status() == 'trialing' && ( $times_billed > 0 || strtotime( date_i18n( 'Y-m-d' ) ) < strtotime( $parent_invoice->get_trial_end_date( false ) ) ) ) { |
|
| 2550 | + if ($parent_invoice->get_subscription_status() == 'trialing' && ($times_billed > 0 || strtotime(date_i18n('Y-m-d')) < strtotime($parent_invoice->get_trial_end_date(false)))) { |
|
| 2551 | 2551 | $args = array( |
| 2552 | 2552 | 'status' => 'active', |
| 2553 | 2553 | ); |
| 2554 | 2554 | |
| 2555 | - $parent_invoice->update_subscription( $args ); |
|
| 2555 | + $parent_invoice->update_subscription($args); |
|
| 2556 | 2556 | } |
| 2557 | 2557 | |
| 2558 | - do_action( 'wpinv_subscription_pre_renew', $this->ID, $expiration, $this ); |
|
| 2558 | + do_action('wpinv_subscription_pre_renew', $this->ID, $expiration, $this); |
|
| 2559 | 2559 | |
| 2560 | - $status = 'active'; |
|
| 2561 | - if ( $bill_times > 0 && $times_billed >= $bill_times ) { |
|
| 2560 | + $status = 'active'; |
|
| 2561 | + if ($bill_times > 0 && $times_billed >= $bill_times) { |
|
| 2562 | 2562 | $this->complete_subscription(); |
| 2563 | 2563 | $status = 'completed'; |
| 2564 | 2564 | } |
@@ -2568,10 +2568,10 @@ discard block |
||
| 2568 | 2568 | 'status' => $status, |
| 2569 | 2569 | ); |
| 2570 | 2570 | |
| 2571 | - $this->update_subscription( $args ); |
|
| 2571 | + $this->update_subscription($args); |
|
| 2572 | 2572 | |
| 2573 | - do_action( 'wpinv_subscription_post_renew', $this->ID, $expiration, $this ); |
|
| 2574 | - do_action( 'wpinv_recurring_set_subscription_status', $this->ID, $status, $this ); |
|
| 2573 | + do_action('wpinv_subscription_post_renew', $this->ID, $expiration, $this); |
|
| 2574 | + do_action('wpinv_recurring_set_subscription_status', $this->ID, $status, $this); |
|
| 2575 | 2575 | } |
| 2576 | 2576 | |
| 2577 | 2577 | public function complete_subscription() { |
@@ -2579,8 +2579,8 @@ discard block |
||
| 2579 | 2579 | 'status' => 'completed' |
| 2580 | 2580 | ); |
| 2581 | 2581 | |
| 2582 | - if ( $this->update_subscription( $args ) ) { |
|
| 2583 | - do_action( 'wpinv_subscription_completed', $this->ID, $this ); |
|
| 2582 | + if ($this->update_subscription($args)) { |
|
| 2583 | + do_action('wpinv_subscription_completed', $this->ID, $this); |
|
| 2584 | 2584 | } |
| 2585 | 2585 | } |
| 2586 | 2586 | |
@@ -2589,44 +2589,44 @@ discard block |
||
| 2589 | 2589 | 'status' => 'expired' |
| 2590 | 2590 | ); |
| 2591 | 2591 | |
| 2592 | - if ( $this->update_subscription( $args ) ) { |
|
| 2593 | - do_action( 'wpinv_subscription_expired', $this->ID, $this ); |
|
| 2592 | + if ($this->update_subscription($args)) { |
|
| 2593 | + do_action('wpinv_subscription_expired', $this->ID, $this); |
|
| 2594 | 2594 | } |
| 2595 | 2595 | } |
| 2596 | 2596 | |
| 2597 | 2597 | public function get_cancel_url() { |
| 2598 | - $url = wp_nonce_url( add_query_arg( array( 'wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID ) ), 'wpinv-recurring-cancel' ); |
|
| 2598 | + $url = wp_nonce_url(add_query_arg(array('wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID)), 'wpinv-recurring-cancel'); |
|
| 2599 | 2599 | |
| 2600 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 2600 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
| 2601 | 2601 | } |
| 2602 | 2602 | |
| 2603 | 2603 | public function can_update() { |
| 2604 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 2604 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
| 2605 | 2605 | } |
| 2606 | 2606 | |
| 2607 | 2607 | public function get_update_url() { |
| 2608 | - $url = add_query_arg( array( 'action' => 'update', 'sub_id' => $this->ID ) ); |
|
| 2608 | + $url = add_query_arg(array('action' => 'update', 'sub_id' => $this->ID)); |
|
| 2609 | 2609 | |
| 2610 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 2610 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
| 2611 | 2611 | } |
| 2612 | 2612 | |
| 2613 | 2613 | public function is_parent() { |
| 2614 | - $is_parent = empty( $this->parent_invoice ) ? true : false; |
|
| 2614 | + $is_parent = empty($this->parent_invoice) ? true : false; |
|
| 2615 | 2615 | |
| 2616 | - return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this ); |
|
| 2616 | + return apply_filters('wpinv_invoice_is_parent', $is_parent, $this); |
|
| 2617 | 2617 | } |
| 2618 | 2618 | |
| 2619 | 2619 | public function is_renewal() { |
| 2620 | 2620 | $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false; |
| 2621 | 2621 | |
| 2622 | - return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this ); |
|
| 2622 | + return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this); |
|
| 2623 | 2623 | } |
| 2624 | 2624 | |
| 2625 | 2625 | public function get_parent_payment() { |
| 2626 | 2626 | $parent_payment = NULL; |
| 2627 | 2627 | |
| 2628 | - if ( $this->is_renewal() ) { |
|
| 2629 | - $parent_payment = wpinv_get_invoice( $this->parent_invoice ); |
|
| 2628 | + if ($this->is_renewal()) { |
|
| 2629 | + $parent_payment = wpinv_get_invoice($this->parent_invoice); |
|
| 2630 | 2630 | } |
| 2631 | 2631 | |
| 2632 | 2632 | return $parent_payment; |
@@ -2637,100 +2637,100 @@ discard block |
||
| 2637 | 2637 | |
| 2638 | 2638 | $subscription_status = $this->get_subscription_status(); |
| 2639 | 2639 | |
| 2640 | - if( ! $this->is_subscription_expired() && ( $subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing' ) ) { |
|
| 2640 | + if (!$this->is_subscription_expired() && ($subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing')) { |
|
| 2641 | 2641 | $ret = true; |
| 2642 | 2642 | } |
| 2643 | 2643 | |
| 2644 | - return apply_filters( 'wpinv_subscription_is_active', $ret, $this->ID, $this ); |
|
| 2644 | + return apply_filters('wpinv_subscription_is_active', $ret, $this->ID, $this); |
|
| 2645 | 2645 | } |
| 2646 | 2646 | |
| 2647 | 2647 | public function is_subscription_expired() { |
| 2648 | 2648 | $ret = false; |
| 2649 | 2649 | $subscription_status = $this->get_subscription_status(); |
| 2650 | 2650 | |
| 2651 | - if ( $subscription_status == 'expired' ) { |
|
| 2651 | + if ($subscription_status == 'expired') { |
|
| 2652 | 2652 | $ret = true; |
| 2653 | - } else if ( 'active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status ) { |
|
| 2653 | + } else if ('active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status) { |
|
| 2654 | 2654 | $ret = false; |
| 2655 | 2655 | $expiration = $this->get_expiration_time(); |
| 2656 | 2656 | |
| 2657 | - if ( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
| 2657 | + if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) { |
|
| 2658 | 2658 | $ret = true; |
| 2659 | 2659 | |
| 2660 | - if ( 'active' === $subscription_status || 'trialing' === $subscription_status ) { |
|
| 2660 | + if ('active' === $subscription_status || 'trialing' === $subscription_status) { |
|
| 2661 | 2661 | $this->expire_subscription(); |
| 2662 | 2662 | } |
| 2663 | 2663 | } |
| 2664 | 2664 | } |
| 2665 | 2665 | |
| 2666 | - return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->ID, $this ); |
|
| 2666 | + return apply_filters('wpinv_subscription_is_expired', $ret, $this->ID, $this); |
|
| 2667 | 2667 | } |
| 2668 | 2668 | |
| 2669 | - public function get_new_expiration( $item_id = 0, $trial = true ) { |
|
| 2670 | - $item = new WPInv_Item( $item_id ); |
|
| 2669 | + public function get_new_expiration($item_id = 0, $trial = true) { |
|
| 2670 | + $item = new WPInv_Item($item_id); |
|
| 2671 | 2671 | $interval = $item->get_recurring_interval(); |
| 2672 | - $period = $item->get_recurring_period( true ); |
|
| 2672 | + $period = $item->get_recurring_period(true); |
|
| 2673 | 2673 | |
| 2674 | - $expiration_time = strtotime( '+' . $interval . ' ' . $period ); |
|
| 2674 | + $expiration_time = strtotime('+' . $interval . ' ' . $period); |
|
| 2675 | 2675 | |
| 2676 | - if ( $trial && $this->is_free_trial() && $item->has_free_trial() ) { |
|
| 2677 | - $expiration_time += ( wpinv_period_in_days( $item->get_trial_interval(), $item->get_trial_period() ) * DAY_IN_SECONDS ) ; |
|
| 2676 | + if ($trial && $this->is_free_trial() && $item->has_free_trial()) { |
|
| 2677 | + $expiration_time += (wpinv_period_in_days($item->get_trial_interval(), $item->get_trial_period()) * DAY_IN_SECONDS); |
|
| 2678 | 2678 | } |
| 2679 | 2679 | |
| 2680 | - return date_i18n( 'Y-m-d 23:59:59', $expiration_time ); |
|
| 2680 | + return date_i18n('Y-m-d 23:59:59', $expiration_time); |
|
| 2681 | 2681 | } |
| 2682 | 2682 | |
| 2683 | - public function get_subscription_data( $filed = '' ) { |
|
| 2684 | - $fields = array( 'item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on' ); |
|
| 2683 | + public function get_subscription_data($filed = '') { |
|
| 2684 | + $fields = array('item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on'); |
|
| 2685 | 2685 | |
| 2686 | 2686 | $subscription_meta = array(); |
| 2687 | - foreach ( $fields as $field ) { |
|
| 2688 | - $subscription_meta[ $field ] = $this->get_meta( '_wpinv_subscr_' . $field ); |
|
| 2687 | + foreach ($fields as $field) { |
|
| 2688 | + $subscription_meta[$field] = $this->get_meta('_wpinv_subscr_' . $field); |
|
| 2689 | 2689 | } |
| 2690 | 2690 | |
| 2691 | - $item = $this->get_recurring( true ); |
|
| 2691 | + $item = $this->get_recurring(true); |
|
| 2692 | 2692 | |
| 2693 | - if ( !empty( $item ) ) { |
|
| 2694 | - if ( empty( $subscription_meta['item_id'] ) ) { |
|
| 2693 | + if (!empty($item)) { |
|
| 2694 | + if (empty($subscription_meta['item_id'])) { |
|
| 2695 | 2695 | $subscription_meta['item_id'] = $item->ID; |
| 2696 | 2696 | } |
| 2697 | - if ( empty( $subscription_meta['period'] ) ) { |
|
| 2697 | + if (empty($subscription_meta['period'])) { |
|
| 2698 | 2698 | $subscription_meta['period'] = $item->get_recurring_period(); |
| 2699 | 2699 | } |
| 2700 | - if ( empty( $subscription_meta['interval'] ) ) { |
|
| 2700 | + if (empty($subscription_meta['interval'])) { |
|
| 2701 | 2701 | $subscription_meta['interval'] = $item->get_recurring_interval(); |
| 2702 | 2702 | } |
| 2703 | - if ( $item->has_free_trial() ) { |
|
| 2704 | - if ( empty( $subscription_meta['trial_period'] ) ) { |
|
| 2703 | + if ($item->has_free_trial()) { |
|
| 2704 | + if (empty($subscription_meta['trial_period'])) { |
|
| 2705 | 2705 | $subscription_meta['trial_period'] = $item->get_trial_period(); |
| 2706 | 2706 | } |
| 2707 | - if ( empty( $subscription_meta['trial_interval'] ) ) { |
|
| 2707 | + if (empty($subscription_meta['trial_interval'])) { |
|
| 2708 | 2708 | $subscription_meta['trial_interval'] = $item->get_trial_interval(); |
| 2709 | 2709 | } |
| 2710 | 2710 | } else { |
| 2711 | 2711 | $subscription_meta['trial_period'] = ''; |
| 2712 | 2712 | $subscription_meta['trial_interval'] = 0; |
| 2713 | 2713 | } |
| 2714 | - if ( !$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0 ) { |
|
| 2714 | + if (!$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0) { |
|
| 2715 | 2715 | $subscription_meta['bill_times'] = $item->get_recurring_limit(); |
| 2716 | 2716 | } |
| 2717 | - if ( $subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '' ) { |
|
| 2718 | - $subscription_meta['initial_amount'] = wpinv_format_amount( $this->get_total() ); |
|
| 2719 | - $subscription_meta['recurring_amount'] = wpinv_format_amount( $this->get_recurring_details( 'total' ) ); |
|
| 2717 | + if ($subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '') { |
|
| 2718 | + $subscription_meta['initial_amount'] = wpinv_format_amount($this->get_total()); |
|
| 2719 | + $subscription_meta['recurring_amount'] = wpinv_format_amount($this->get_recurring_details('total')); |
|
| 2720 | 2720 | } |
| 2721 | 2721 | } |
| 2722 | 2722 | |
| 2723 | - if ( $filed === '' ) { |
|
| 2724 | - return apply_filters( 'wpinv_get_invoice_subscription_data', $subscription_meta, $this ); |
|
| 2723 | + if ($filed === '') { |
|
| 2724 | + return apply_filters('wpinv_get_invoice_subscription_data', $subscription_meta, $this); |
|
| 2725 | 2725 | } |
| 2726 | 2726 | |
| 2727 | - $value = isset( $subscription_meta[$filed] ) ? $subscription_meta[$filed] : ''; |
|
| 2727 | + $value = isset($subscription_meta[$filed]) ? $subscription_meta[$filed] : ''; |
|
| 2728 | 2728 | |
| 2729 | - return apply_filters( 'wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this ); |
|
| 2729 | + return apply_filters('wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this); |
|
| 2730 | 2730 | } |
| 2731 | 2731 | |
| 2732 | 2732 | public function is_paid() { |
| 2733 | - if ( $this->has_status( array( 'publish', 'complete', 'processing', 'renewal' ) ) ) { |
|
| 2733 | + if ($this->has_status(array('publish', 'complete', 'processing', 'renewal'))) { |
|
| 2734 | 2734 | return true; |
| 2735 | 2735 | } |
| 2736 | 2736 | |
@@ -2742,28 +2742,28 @@ discard block |
||
| 2742 | 2742 | |
| 2743 | 2743 | $requires_vat = false; |
| 2744 | 2744 | |
| 2745 | - if ( $this->country ) { |
|
| 2745 | + if ($this->country) { |
|
| 2746 | 2746 | $wpi_country = $this->country; |
| 2747 | 2747 | |
| 2748 | - $requires_vat = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) ); |
|
| 2748 | + $requires_vat = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this)); |
|
| 2749 | 2749 | } |
| 2750 | 2750 | |
| 2751 | - return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this ); |
|
| 2751 | + return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this); |
|
| 2752 | 2752 | } |
| 2753 | 2753 | |
| 2754 | 2754 | public function refresh_item_ids() { |
| 2755 | 2755 | $item_ids = array(); |
| 2756 | 2756 | |
| 2757 | - if ( !empty( $this->cart_details ) ) { |
|
| 2758 | - foreach ( $this->cart_details as $key => $item ) { |
|
| 2759 | - if ( !empty( $item['id'] ) ) { |
|
| 2757 | + if (!empty($this->cart_details)) { |
|
| 2758 | + foreach ($this->cart_details as $key => $item) { |
|
| 2759 | + if (!empty($item['id'])) { |
|
| 2760 | 2760 | $item_ids[] = $item['id']; |
| 2761 | 2761 | } |
| 2762 | 2762 | } |
| 2763 | 2763 | } |
| 2764 | 2764 | |
| 2765 | - $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : ''; |
|
| 2765 | + $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : ''; |
|
| 2766 | 2766 | |
| 2767 | - update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids ); |
|
| 2767 | + update_post_meta($this->ID, '_wpinv_item_ids', $item_ids); |
|
| 2768 | 2768 | } |
| 2769 | 2769 | } |
@@ -164,8 +164,7 @@ discard block |
||
| 164 | 164 | * @since 1.0.0 |
| 165 | 165 | * |
| 166 | 166 | * @param string|array $key Session key. |
| 167 | - * @param integer $value Session variable. |
|
| 168 | - * @return string Session variable. |
|
| 167 | + * @return boolean Session variable. |
|
| 169 | 168 | */ |
| 170 | 169 | public function un_set( $key ) { |
| 171 | 170 | if ( empty( $key ) ) { |
@@ -201,8 +200,7 @@ discard block |
||
| 201 | 200 | * @since 1.0.0 |
| 202 | 201 | * |
| 203 | 202 | * @param string $key Session key. |
| 204 | - * @param integer $value Session variable. |
|
| 205 | - * @return string Session variable. |
|
| 203 | + * @return boolean Session variable. |
|
| 206 | 204 | */ |
| 207 | 205 | public function is_set( $key ) { |
| 208 | 206 | $key = sanitize_key( $key ); |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly. |
| 3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined('ABSPATH')) exit; |
|
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | 6 | * WPInv_Session Class. |
@@ -46,44 +46,44 @@ discard block |
||
| 46 | 46 | public function __construct() { |
| 47 | 47 | $this->use_php_sessions = $this->use_php_sessions(); |
| 48 | 48 | |
| 49 | - if ( $this->use_php_sessions ) { |
|
| 50 | - if ( is_multisite() ) { |
|
| 49 | + if ($this->use_php_sessions) { |
|
| 50 | + if (is_multisite()) { |
|
| 51 | 51 | $this->prefix = '_' . get_current_blog_id(); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | // Use PHP SESSION (must be enabled via the WPINV_USE_PHP_SESSIONS constant) |
| 55 | - add_action( 'init', array( $this, 'maybe_start_session' ), -2 ); |
|
| 55 | + add_action('init', array($this, 'maybe_start_session'), -2); |
|
| 56 | 56 | } else { |
| 57 | 57 | // Use WP_Session (default) |
| 58 | - if ( !defined( 'WP_SESSION_COOKIE' ) ) { |
|
| 59 | - define( 'WP_SESSION_COOKIE', 'wpinv_wp_session' ); |
|
| 58 | + if (!defined('WP_SESSION_COOKIE')) { |
|
| 59 | + define('WP_SESSION_COOKIE', 'wpinv_wp_session'); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - if ( !class_exists( 'Recursive_ArrayAccess' ) ) { |
|
| 62 | + if (!class_exists('Recursive_ArrayAccess')) { |
|
| 63 | 63 | require_once WPINV_PLUGIN_DIR . 'includes/libraries/wp-session/class-recursive-arrayaccess.php'; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - if ( !class_exists( 'WP_Session_Utils' ) ) { |
|
| 66 | + if (!class_exists('WP_Session_Utils')) { |
|
| 67 | 67 | require_once WPINV_PLUGIN_DIR . 'includes/libraries/wp-session/class-wp-session-utils.php'; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - if ( defined( 'WP_CLI' ) && WP_CLI && !class_exists( 'WP_Session_Command' ) ) { |
|
| 70 | + if (defined('WP_CLI') && WP_CLI && !class_exists('WP_Session_Command')) { |
|
| 71 | 71 | require_once WPINV_PLUGIN_DIR . 'includes/libraries/wp-session/wp-cli.php'; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if ( !class_exists( 'WP_Session' ) ) { |
|
| 74 | + if (!class_exists('WP_Session')) { |
|
| 75 | 75 | require_once WPINV_PLUGIN_DIR . 'includes/libraries/wp-session/class-wp-session.php'; |
| 76 | 76 | require_once WPINV_PLUGIN_DIR . 'includes/libraries/wp-session/wp-session.php'; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - add_filter( 'wp_session_expiration_variant', array( $this, 'set_expiration_variant_time' ), 99999 ); |
|
| 80 | - add_filter( 'wp_session_expiration', array( $this, 'set_expiration_time' ), 99999 ); |
|
| 79 | + add_filter('wp_session_expiration_variant', array($this, 'set_expiration_variant_time'), 99999); |
|
| 80 | + add_filter('wp_session_expiration', array($this, 'set_expiration_time'), 99999); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - if ( empty( $this->session ) && ! $this->use_php_sessions ) { |
|
| 84 | - add_action( 'plugins_loaded', array( $this, 'init' ), -1 ); |
|
| 83 | + if (empty($this->session) && !$this->use_php_sessions) { |
|
| 84 | + add_action('plugins_loaded', array($this, 'init'), -1); |
|
| 85 | 85 | } else { |
| 86 | - add_action( 'init', array( $this, 'init' ), -1 ); |
|
| 86 | + add_action('init', array($this, 'init'), -1); |
|
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | * @return void |
| 96 | 96 | */ |
| 97 | 97 | public function init() { |
| 98 | - if ( $this->use_php_sessions ) { |
|
| 99 | - $this->session = isset( $_SESSION['wpi' . $this->prefix ] ) && is_array( $_SESSION['wpi' . $this->prefix ] ) ? $_SESSION['wpi' . $this->prefix ] : array(); |
|
| 98 | + if ($this->use_php_sessions) { |
|
| 99 | + $this->session = isset($_SESSION['wpi' . $this->prefix]) && is_array($_SESSION['wpi' . $this->prefix]) ? $_SESSION['wpi' . $this->prefix] : array(); |
|
| 100 | 100 | } else { |
| 101 | 101 | $this->session = WP_Session::get_instance(); |
| 102 | 102 | } |
@@ -112,10 +112,10 @@ discard block |
||
| 112 | 112 | * @return string Session ID |
| 113 | 113 | */ |
| 114 | 114 | public function get_id() { |
| 115 | - if ( $this->use_php_sessions ) { |
|
| 116 | - $session_id = !empty( $_SESSION ) && function_exists( 'session_id' ) ? session_id() : NULL; |
|
| 115 | + if ($this->use_php_sessions) { |
|
| 116 | + $session_id = !empty($_SESSION) && function_exists('session_id') ? session_id() : NULL; |
|
| 117 | 117 | } else { |
| 118 | - $session_id = !empty( $this->session ) && isset( $this->session->session_id ) ? $this->session->session_id : NULL; |
|
| 118 | + $session_id = !empty($this->session) && isset($this->session->session_id) ? $this->session->session_id : NULL; |
|
| 119 | 119 | } |
| 120 | 120 | return $session_id; |
| 121 | 121 | } |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | * @param string $key Session key |
| 129 | 129 | * @return string Session variable |
| 130 | 130 | */ |
| 131 | - public function get( $key ) { |
|
| 132 | - $key = sanitize_key( $key ); |
|
| 133 | - return isset( $this->session[ $key ] ) ? maybe_unserialize( $this->session[ $key ] ) : false; |
|
| 131 | + public function get($key) { |
|
| 132 | + $key = sanitize_key($key); |
|
| 133 | + return isset($this->session[$key]) ? maybe_unserialize($this->session[$key]) : false; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -142,20 +142,20 @@ discard block |
||
| 142 | 142 | * @param integer $value Session variable |
| 143 | 143 | * @return string Session variable |
| 144 | 144 | */ |
| 145 | - public function set( $key, $value ) { |
|
| 146 | - $key = sanitize_key( $key ); |
|
| 145 | + public function set($key, $value) { |
|
| 146 | + $key = sanitize_key($key); |
|
| 147 | 147 | |
| 148 | - if ( is_array( $value ) ) { |
|
| 149 | - $this->session[ $key ] = maybe_serialize( $value ); |
|
| 148 | + if (is_array($value)) { |
|
| 149 | + $this->session[$key] = maybe_serialize($value); |
|
| 150 | 150 | } else { |
| 151 | - $this->session[ $key ] = $value; |
|
| 151 | + $this->session[$key] = $value; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - if ( $this->use_php_sessions ) { |
|
| 155 | - $_SESSION['wpi' . $this->prefix ] = $this->session; |
|
| 154 | + if ($this->use_php_sessions) { |
|
| 155 | + $_SESSION['wpi' . $this->prefix] = $this->session; |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - return $this->session[ $key ]; |
|
| 158 | + return $this->session[$key]; |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -167,29 +167,29 @@ discard block |
||
| 167 | 167 | * @param integer $value Session variable. |
| 168 | 168 | * @return string Session variable. |
| 169 | 169 | */ |
| 170 | - public function un_set( $key ) { |
|
| 171 | - if ( empty( $key ) ) { |
|
| 170 | + public function un_set($key) { |
|
| 171 | + if (empty($key)) { |
|
| 172 | 172 | return false; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - if ( is_array( $key ) ) { |
|
| 175 | + if (is_array($key)) { |
|
| 176 | 176 | foreach ($key as $index) { |
| 177 | - $index = sanitize_key( $index ); |
|
| 177 | + $index = sanitize_key($index); |
|
| 178 | 178 | |
| 179 | - if ( $index && isset( $this->session[ $index ] ) ) { |
|
| 180 | - unset( $this->session[ $index ] ); |
|
| 179 | + if ($index && isset($this->session[$index])) { |
|
| 180 | + unset($this->session[$index]); |
|
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | 183 | } else { |
| 184 | - $key = sanitize_key( $key ); |
|
| 184 | + $key = sanitize_key($key); |
|
| 185 | 185 | |
| 186 | - if ( isset( $this->session[ $key ] ) ) { |
|
| 187 | - unset( $this->session[ $key ] ); |
|
| 186 | + if (isset($this->session[$key])) { |
|
| 187 | + unset($this->session[$key]); |
|
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - if ( $this->use_php_sessions ) { |
|
| 192 | - $_SESSION['wpi' . $this->prefix ] = $this->session; |
|
| 191 | + if ($this->use_php_sessions) { |
|
| 192 | + $_SESSION['wpi' . $this->prefix] = $this->session; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | return true; |
@@ -204,14 +204,14 @@ discard block |
||
| 204 | 204 | * @param integer $value Session variable. |
| 205 | 205 | * @return string Session variable. |
| 206 | 206 | */ |
| 207 | - public function is_set( $key ) { |
|
| 208 | - $key = sanitize_key( $key ); |
|
| 207 | + public function is_set($key) { |
|
| 208 | + $key = sanitize_key($key); |
|
| 209 | 209 | |
| 210 | - if ( empty( $key ) ) { |
|
| 210 | + if (empty($key)) { |
|
| 211 | 211 | return false; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - if ( isset( $this->session[ $key ] ) ) { |
|
| 214 | + if (isset($this->session[$key])) { |
|
| 215 | 215 | return true; |
| 216 | 216 | } |
| 217 | 217 | |
@@ -226,8 +226,8 @@ discard block |
||
| 226 | 226 | * @param int $exp Default expiration (1 hour) |
| 227 | 227 | * @return int |
| 228 | 228 | */ |
| 229 | - public function set_expiration_variant_time( $exp ) { |
|
| 230 | - return ( 30 * 60 * 23 ); |
|
| 229 | + public function set_expiration_variant_time($exp) { |
|
| 230 | + return (30 * 60 * 23); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -238,8 +238,8 @@ discard block |
||
| 238 | 238 | * @param int $exp Default expiration (1 hour) |
| 239 | 239 | * @return int |
| 240 | 240 | */ |
| 241 | - public function set_expiration_time( $exp ) { |
|
| 242 | - return ( 30 * 60 * 24 ); |
|
| 241 | + public function set_expiration_time($exp) { |
|
| 242 | + return (30 * 60 * 24); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -257,18 +257,18 @@ discard block |
||
| 257 | 257 | $ret = false; |
| 258 | 258 | |
| 259 | 259 | // If the database variable is already set, no need to run autodetection |
| 260 | - $wpinv_use_php_sessions = (bool)get_option( 'wpinv_use_php_sessions' ); |
|
| 260 | + $wpinv_use_php_sessions = (bool)get_option('wpinv_use_php_sessions'); |
|
| 261 | 261 | |
| 262 | - if (!$wpinv_use_php_sessions ) { |
|
| 262 | + if (!$wpinv_use_php_sessions) { |
|
| 263 | 263 | // Attempt to detect if the server supports PHP sessions |
| 264 | - if ( function_exists( 'session_start' ) && ! ini_get( 'safe_mode' ) ) { |
|
| 265 | - $this->set( 'wpinv_use_php_sessions', 1 ); |
|
| 264 | + if (function_exists('session_start') && !ini_get('safe_mode')) { |
|
| 265 | + $this->set('wpinv_use_php_sessions', 1); |
|
| 266 | 266 | |
| 267 | - if ( $this->get( 'wpinv_use_php_sessions' ) ) { |
|
| 267 | + if ($this->get('wpinv_use_php_sessions')) { |
|
| 268 | 268 | $ret = true; |
| 269 | 269 | |
| 270 | 270 | // Set the database option |
| 271 | - update_option( 'wpinv_use_php_sessions', true ); |
|
| 271 | + update_option('wpinv_use_php_sessions', true); |
|
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | } else { |
@@ -276,20 +276,20 @@ discard block |
||
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | // Enable or disable PHP Sessions based on the WPINV_USE_PHP_SESSIONS constant |
| 279 | - if ( defined( 'WPINV_USE_PHP_SESSIONS' ) && WPINV_USE_PHP_SESSIONS ) { |
|
| 279 | + if (defined('WPINV_USE_PHP_SESSIONS') && WPINV_USE_PHP_SESSIONS) { |
|
| 280 | 280 | $ret = true; |
| 281 | - } else if ( defined( 'WPINV_USE_PHP_SESSIONS' ) && ! WPINV_USE_PHP_SESSIONS ) { |
|
| 281 | + } else if (defined('WPINV_USE_PHP_SESSIONS') && !WPINV_USE_PHP_SESSIONS) { |
|
| 282 | 282 | $ret = false; |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - return (bool) apply_filters( 'wpinv_use_php_sessions', $ret ); |
|
| 285 | + return (bool)apply_filters('wpinv_use_php_sessions', $ret); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
| 289 | 289 | * Starts a new session if one hasn't started yet. |
| 290 | 290 | */ |
| 291 | 291 | public function maybe_start_session() { |
| 292 | - if ( !session_id() && !headers_sent() ) { |
|
| 292 | + if (!session_id() && !headers_sent()) { |
|
| 293 | 293 | session_start(); |
| 294 | 294 | } |
| 295 | 295 | } |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @param string $card_num The credit card number |
| 102 | 102 | * @param string $exp_date CC expiration date |
| 103 | 103 | * |
| 104 | - * @return AuthorizeNetAIM_Response |
|
| 104 | + * @return AuthorizeNetARB_Response |
|
| 105 | 105 | */ |
| 106 | 106 | public function authorizeAndCapture($amount = false, $card_num = false, $exp_date = false) |
| 107 | 107 | { |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @param string $trans_id Transaction id to charge |
| 123 | 123 | * @param string $amount Dollar amount to charge if lesser than auth |
| 124 | 124 | * |
| 125 | - * @return AuthorizeNetAIM_Response |
|
| 125 | + * @return AuthorizeNetARB_Response |
|
| 126 | 126 | */ |
| 127 | 127 | public function priorAuthCapture($trans_id = false, $amount = false) |
| 128 | 128 | { |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | * @param string $card_num The credit card number |
| 142 | 142 | * @param string $exp_date CC expiration date |
| 143 | 143 | * |
| 144 | - * @return AuthorizeNetAIM_Response |
|
| 144 | + * @return AuthorizeNetARB_Response |
|
| 145 | 145 | */ |
| 146 | 146 | public function authorizeOnly($amount = false, $card_num = false, $exp_date = false) |
| 147 | 147 | { |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @param string $trans_id Transaction id to void |
| 162 | 162 | * |
| 163 | - * @return AuthorizeNetAIM_Response |
|
| 163 | + * @return AuthorizeNetARB_Response |
|
| 164 | 164 | */ |
| 165 | 165 | public function void($trans_id = false) |
| 166 | 166 | { |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | * @param string $card_num The last 4 of credit card number |
| 180 | 180 | * @param string $exp_date CC expiration date |
| 181 | 181 | * |
| 182 | - * @return AuthorizeNetAIM_Response |
|
| 182 | + * @return AuthorizeNetARB_Response |
|
| 183 | 183 | */ |
| 184 | 184 | public function captureOnly($auth_code = false, $amount = false, $card_num = false, $exp_date = false) |
| 185 | 185 | { |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | * @param string $amount The dollar amount to credit |
| 201 | 201 | * @param string $card_num The last 4 of credit card number |
| 202 | 202 | * |
| 203 | - * @return AuthorizeNetAIM_Response |
|
| 203 | + * @return AuthorizeNetARB_Response |
|
| 204 | 204 | */ |
| 205 | 205 | public function credit($trans_id = false, $amount = false, $card_num = false) |
| 206 | 206 | { |
@@ -77,19 +77,19 @@ discard block |
||
| 77 | 77 | * A list of all fields in the AIM API. |
| 78 | 78 | * Used to warn user if they try to set a field not offered in the API. |
| 79 | 79 | */ |
| 80 | - private $_all_aim_fields = array("address","allow_partial_auth","amount", |
|
| 81 | - "auth_code","authentication_indicator", "bank_aba_code","bank_acct_name", |
|
| 82 | - "bank_acct_num","bank_acct_type","bank_check_number","bank_name", |
|
| 83 | - "card_code","card_num","cardholder_authentication_value","city","company", |
|
| 84 | - "country","cust_id","customer_ip","delim_char","delim_data","description", |
|
| 85 | - "duplicate_window","duty","echeck_type","email","email_customer", |
|
| 86 | - "encap_char","exp_date","fax","first_name","footer_email_receipt", |
|
| 87 | - "freight","header_email_receipt","invoice_num","last_name","line_item", |
|
| 88 | - "login","method","phone","po_num","recurring_billing","relay_response", |
|
| 89 | - "ship_to_address","ship_to_city","ship_to_company","ship_to_country", |
|
| 90 | - "ship_to_first_name","ship_to_last_name","ship_to_state","ship_to_zip", |
|
| 91 | - "split_tender_id","state","tax","tax_exempt","test_request","tran_key", |
|
| 92 | - "trans_id","type","version","zip" |
|
| 80 | + private $_all_aim_fields = array("address", "allow_partial_auth", "amount", |
|
| 81 | + "auth_code", "authentication_indicator", "bank_aba_code", "bank_acct_name", |
|
| 82 | + "bank_acct_num", "bank_acct_type", "bank_check_number", "bank_name", |
|
| 83 | + "card_code", "card_num", "cardholder_authentication_value", "city", "company", |
|
| 84 | + "country", "cust_id", "customer_ip", "delim_char", "delim_data", "description", |
|
| 85 | + "duplicate_window", "duty", "echeck_type", "email", "email_customer", |
|
| 86 | + "encap_char", "exp_date", "fax", "first_name", "footer_email_receipt", |
|
| 87 | + "freight", "header_email_receipt", "invoice_num", "last_name", "line_item", |
|
| 88 | + "login", "method", "phone", "po_num", "recurring_billing", "relay_response", |
|
| 89 | + "ship_to_address", "ship_to_city", "ship_to_company", "ship_to_country", |
|
| 90 | + "ship_to_first_name", "ship_to_last_name", "ship_to_state", "ship_to_zip", |
|
| 91 | + "split_tender_id", "state", "tax", "tax_exempt", "test_request", "tran_key", |
|
| 92 | + "trans_id", "type", "version", "zip" |
|
| 93 | 93 | ); |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | // Split Array |
| 404 | 404 | $this->response = $response; |
| 405 | 405 | if ($encap_char) { |
| 406 | - $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1)); |
|
| 406 | + $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
| 407 | 407 | } else { |
| 408 | 408 | $this->_response_array = explode($delimiter, $response); |
| 409 | 409 | } |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | $this->duty = $this->_response_array[33]; |
| 458 | 458 | $this->freight = $this->_response_array[34]; |
| 459 | 459 | $this->tax_exempt = $this->_response_array[35]; |
| 460 | - $this->purchase_order_number= $this->_response_array[36]; |
|
| 460 | + $this->purchase_order_number = $this->_response_array[36]; |
|
| 461 | 461 | $this->md5_hash = $this->_response_array[37]; |
| 462 | 462 | $this->card_code_response = $this->_response_array[38]; |
| 463 | 463 | $this->cavv_response = $this->_response_array[39]; |
@@ -484,10 +484,10 @@ discard block |
||
| 484 | 484 | |
| 485 | 485 | if ($this->error) { |
| 486 | 486 | $this->error_message = "AuthorizeNet Error: |
| 487 | - Response Code: ".$this->response_code." |
|
| 488 | - Response Subcode: ".$this->response_subcode." |
|
| 489 | - Response Reason Code: ".$this->response_reason_code." |
|
| 490 | - Response Reason Text: ".$this->response_reason_text." |
|
| 487 | + Response Code: ".$this->response_code . " |
|
| 488 | + Response Subcode: ".$this->response_subcode . " |
|
| 489 | + Response Reason Code: ".$this->response_reason_code . " |
|
| 490 | + Response Reason Text: ".$this->response_reason_text . " |
|
| 491 | 491 | "; |
| 492 | 492 | } |
| 493 | 493 | } else { |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @param AuthorizeNetCustomer $customerProfile |
| 52 | 52 | * @param string $validationMode |
| 53 | 53 | * |
| 54 | - * @return AuthorizeNetCIM_Response |
|
| 54 | + * @return AuthorizeNetARB_Response |
|
| 55 | 55 | */ |
| 56 | 56 | public function createCustomerProfile($customerProfile, $validationMode = "none") |
| 57 | 57 | { |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @param AuthorizeNetPaymentProfile $paymentProfile |
| 70 | 70 | * @param string $validationMode |
| 71 | 71 | * |
| 72 | - * @return AuthorizeNetCIM_Response |
|
| 72 | + * @return AuthorizeNetARB_Response |
|
| 73 | 73 | */ |
| 74 | 74 | public function createCustomerPaymentProfile($customerProfileId, $paymentProfile, $validationMode = "none") |
| 75 | 75 | { |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @param int $customerProfileId |
| 88 | 88 | * @param AuthorizeNetAddress $shippingAddress |
| 89 | 89 | * |
| 90 | - * @return AuthorizeNetCIM_Response |
|
| 90 | + * @return AuthorizeNetARB_Response |
|
| 91 | 91 | */ |
| 92 | 92 | public function createCustomerShippingAddress($customerProfileId, $shippingAddress) |
| 93 | 93 | { |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * @param AuthorizeNetTransaction $transaction |
| 106 | 106 | * @param string $extraOptionsString |
| 107 | 107 | * |
| 108 | - * @return AuthorizeNetCIM_Response |
|
| 108 | + * @return AuthorizeNetARB_Response |
|
| 109 | 109 | */ |
| 110 | 110 | public function createCustomerProfileTransaction($transactionType, $transaction, $extraOptionsString = "") |
| 111 | 111 | { |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * |
| 123 | 123 | * @param int $customerProfileId |
| 124 | 124 | * |
| 125 | - * @return AuthorizeNetCIM_Response |
|
| 125 | + * @return AuthorizeNetARB_Response |
|
| 126 | 126 | */ |
| 127 | 127 | public function deleteCustomerProfile($customerProfileId) |
| 128 | 128 | { |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * @param int $customerProfileId |
| 138 | 138 | * @param int $customerPaymentProfileId |
| 139 | 139 | * |
| 140 | - * @return AuthorizeNetCIM_Response |
|
| 140 | + * @return AuthorizeNetARB_Response |
|
| 141 | 141 | */ |
| 142 | 142 | public function deleteCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId) |
| 143 | 143 | { |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @param int $customerProfileId |
| 154 | 154 | * @param int $customerAddressId |
| 155 | 155 | * |
| 156 | - * @return AuthorizeNetCIM_Response |
|
| 156 | + * @return AuthorizeNetARB_Response |
|
| 157 | 157 | */ |
| 158 | 158 | public function deleteCustomerShippingAddress($customerProfileId, $customerAddressId) |
| 159 | 159 | { |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | /** |
| 167 | 167 | * Get all customer profile ids. |
| 168 | 168 | * |
| 169 | - * @return AuthorizeNetCIM_Response |
|
| 169 | + * @return AuthorizeNetARB_Response |
|
| 170 | 170 | */ |
| 171 | 171 | public function getCustomerProfileIds() |
| 172 | 172 | { |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | * |
| 180 | 180 | * @param int $customerProfileId |
| 181 | 181 | * |
| 182 | - * @return AuthorizeNetCIM_Response |
|
| 182 | + * @return AuthorizeNetARB_Response |
|
| 183 | 183 | */ |
| 184 | 184 | public function getCustomerProfile($customerProfileId) |
| 185 | 185 | { |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | * @param int $customerProfileId |
| 195 | 195 | * @param int $customerPaymentProfileId |
| 196 | 196 | * |
| 197 | - * @return AuthorizeNetCIM_Response |
|
| 197 | + * @return AuthorizeNetARB_Response |
|
| 198 | 198 | */ |
| 199 | 199 | public function getCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId) |
| 200 | 200 | { |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | * @param int $customerProfileId |
| 211 | 211 | * @param int $customerAddressId |
| 212 | 212 | * |
| 213 | - * @return AuthorizeNetCIM_Response |
|
| 213 | + * @return AuthorizeNetARB_Response |
|
| 214 | 214 | */ |
| 215 | 215 | public function getCustomerShippingAddress($customerProfileId, $customerAddressId) |
| 216 | 216 | { |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | * @param int $customerProfileId |
| 227 | 227 | * @param AuthorizeNetCustomer $customerProfile |
| 228 | 228 | * |
| 229 | - * @return AuthorizeNetCIM_Response |
|
| 229 | + * @return AuthorizeNetARB_Response |
|
| 230 | 230 | */ |
| 231 | 231 | public function updateCustomerProfile($customerProfileId, $customerProfile) |
| 232 | 232 | { |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | * @param AuthorizeNetPaymentProfile $paymentProfile |
| 246 | 246 | * @param string $validationMode |
| 247 | 247 | * |
| 248 | - * @return AuthorizeNetCIM_Response |
|
| 248 | + * @return AuthorizeNetARB_Response |
|
| 249 | 249 | */ |
| 250 | 250 | public function updateCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId, $paymentProfile, $validationMode = "none") |
| 251 | 251 | { |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | * @param int $customerShippingAddressId |
| 266 | 266 | * @param AuthorizeNetAddress $shippingAddress |
| 267 | 267 | * |
| 268 | - * @return AuthorizeNetCIM_Response |
|
| 268 | + * @return AuthorizeNetARB_Response |
|
| 269 | 269 | */ |
| 270 | 270 | public function updateCustomerShippingAddress($customerProfileId, $customerShippingAddressId, $shippingAddress) |
| 271 | 271 | { |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | * @param int $splitTenderId |
| 285 | 285 | * @param string $splitTenderStatus |
| 286 | 286 | * |
| 287 | - * @return AuthorizeNetCIM_Response |
|
| 287 | + * @return AuthorizeNetARB_Response |
|
| 288 | 288 | */ |
| 289 | 289 | public function updateSplitTenderGroup($splitTenderId, $splitTenderStatus) |
| 290 | 290 | { |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | * @param int $cardCode |
| 304 | 304 | * @param string $validationMode |
| 305 | 305 | * |
| 306 | - * @return AuthorizeNetCIM_Response |
|
| 306 | + * @return AuthorizeNetARB_Response |
|
| 307 | 307 | */ |
| 308 | 308 | public function validateCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId, $customerShippingAddressId, $cardCode, $validationMode = "testMode") |
| 309 | 309 | { |
@@ -309,10 +309,10 @@ discard block |
||
| 309 | 309 | { |
| 310 | 310 | $this->_validationMode = $validationMode; |
| 311 | 311 | $this->_constructXml("validateCustomerPaymentProfileRequest"); |
| 312 | - $this->_xml->addChild("customerProfileId",$customerProfileId); |
|
| 313 | - $this->_xml->addChild("customerPaymentProfileId",$customerPaymentProfileId); |
|
| 314 | - $this->_xml->addChild("customerShippingAddressId",$customerShippingAddressId); |
|
| 315 | - $this->_xml->addChild("cardCode",$cardCode); |
|
| 312 | + $this->_xml->addChild("customerProfileId", $customerProfileId); |
|
| 313 | + $this->_xml->addChild("customerPaymentProfileId", $customerPaymentProfileId); |
|
| 314 | + $this->_xml->addChild("customerShippingAddressId", $customerShippingAddressId); |
|
| 315 | + $this->_xml->addChild("cardCode", $cardCode); |
|
| 316 | 316 | return $this->_sendRequest(); |
| 317 | 317 | } |
| 318 | 318 | |
@@ -341,13 +341,13 @@ discard block |
||
| 341 | 341 | */ |
| 342 | 342 | protected function _setPostString() |
| 343 | 343 | { |
| 344 | - ($this->_validationMode != "none" ? $this->_xml->addChild('validationMode',$this->_validationMode) : ""); |
|
| 344 | + ($this->_validationMode != "none" ? $this->_xml->addChild('validationMode', $this->_validationMode) : ""); |
|
| 345 | 345 | $this->_post_string = $this->_xml->asXML(); |
| 346 | 346 | |
| 347 | 347 | // Add extraOptions CDATA |
| 348 | 348 | if ($this->_extraOptions) { |
| 349 | 349 | $this->_xml->addChild("extraOptions"); |
| 350 | - $this->_post_string = str_replace("<extraOptions></extraOptions>",'<extraOptions><![CDATA[' . $this->_extraOptions . ']]></extraOptions>', $this->_xml->asXML()); |
|
| 350 | + $this->_post_string = str_replace("<extraOptions></extraOptions>", '<extraOptions><![CDATA[' . $this->_extraOptions . ']]></extraOptions>', $this->_xml->asXML()); |
|
| 351 | 351 | $this->_extraOptions = false; |
| 352 | 352 | } |
| 353 | 353 | // Blank out our validation mode, so that we don't include it in calls that |
@@ -362,12 +362,12 @@ discard block |
||
| 362 | 362 | */ |
| 363 | 363 | private function _constructXml($request_type) |
| 364 | 364 | { |
| 365 | - $string = '<?xml version="1.0" encoding="utf-8"?><'.$request_type.' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></'.$request_type.'>'; |
|
| 365 | + $string = '<?xml version="1.0" encoding="utf-8"?><' . $request_type . ' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></' . $request_type . '>'; |
|
| 366 | 366 | $this->_xml = @new SimpleXMLElement($string); |
| 367 | 367 | $merchant = $this->_xml->addChild('merchantAuthentication'); |
| 368 | - $merchant->addChild('name',$this->_api_login); |
|
| 369 | - $merchant->addChild('transactionKey',$this->_transaction_key); |
|
| 370 | - ($this->_refId ? $this->_xml->addChild('refId',$this->_refId) : ""); |
|
| 368 | + $merchant->addChild('name', $this->_api_login); |
|
| 369 | + $merchant->addChild('transactionKey', $this->_transaction_key); |
|
| 370 | + ($this->_refId ? $this->_xml->addChild('refId', $this->_refId) : ""); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | /** |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | $this->_addObject($items, $item); |
| 388 | 388 | } |
| 389 | 389 | } else { |
| 390 | - $destination->addChild($key,$value); |
|
| 390 | + $destination->addChild($key, $value); |
|
| 391 | 391 | } |
| 392 | 392 | } elseif (is_object($value) && self::_notEmpty($value)) { |
| 393 | 393 | $dest = $destination->addChild($key); |
@@ -79,7 +79,7 @@ |
||
| 79 | 79 | * |
| 80 | 80 | * @param string $response |
| 81 | 81 | * |
| 82 | - * @return AuthorizeNetAIM_Response |
|
| 82 | + * @return AuthorizeNetCP_Response |
|
| 83 | 83 | */ |
| 84 | 84 | protected function _handleResponse($response) |
| 85 | 85 | { |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | $this->xml = @simplexml_load_string($response); |
| 118 | 118 | // Set all fields |
| 119 | - $this->version = array_pop(array_slice(explode('"', $response), 1,1)); |
|
| 119 | + $this->version = array_pop(array_slice(explode('"', $response), 1, 1)); |
|
| 120 | 120 | $this->response_code = (string)$this->xml->ResponseCode; |
| 121 | 121 | |
| 122 | 122 | if ($this->response_code == 1) { |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | // Split Array |
| 145 | 145 | $this->response = $response; |
| 146 | 146 | if ($encap_char) { |
| 147 | - $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1)); |
|
| 147 | + $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
| 148 | 148 | } else { |
| 149 | 149 | $this->_response_array = explode($delimiter, $response); |
| 150 | 150 | } |
@@ -190,9 +190,9 @@ discard block |
||
| 190 | 190 | |
| 191 | 191 | if ($this->error) { |
| 192 | 192 | $this->error_message = "AuthorizeNet Error: |
| 193 | - Response Code: ".$this->response_code." |
|
| 194 | - Response Reason Code: ".$this->response_reason_code." |
|
| 195 | - Response Reason Text: ".$this->response_reason_text." |
|
| 193 | + Response Code: ".$this->response_code . " |
|
| 194 | + Response Reason Code: ".$this->response_reason_code . " |
|
| 195 | + Response Reason Text: ".$this->response_reason_text . " |
|
| 196 | 196 | "; |
| 197 | 197 | } |
| 198 | 198 | |
@@ -28,6 +28,7 @@ |
||
| 28 | 28 | /** |
| 29 | 29 | * Get the post url. We need this because until 5.3 you |
| 30 | 30 | * you could not access child constants in a parent class. |
| 31 | + * @return string|null |
|
| 31 | 32 | */ |
| 32 | 33 | abstract protected function _getPostUrl(); |
| 33 | 34 | |
@@ -96,7 +96,7 @@ |
||
| 96 | 96 | curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - if (preg_match('/xml/',$post_url)) { |
|
| 99 | + if (preg_match('/xml/', $post_url)) { |
|
| 100 | 100 | curl_setopt($curl_request, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); |
| 101 | 101 | } |
| 102 | 102 | |
@@ -110,6 +110,7 @@ |
||
| 110 | 110 | * Grabs the contents of a unique element. |
| 111 | 111 | * |
| 112 | 112 | * @param string |
| 113 | + * @param string $elementName |
|
| 113 | 114 | * @return string |
| 114 | 115 | */ |
| 115 | 116 | protected function _getElementContents($elementName) |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | $this->xml = @simplexml_load_string($response); |
| 30 | 30 | |
| 31 | 31 | // Remove namespaces for use with XPath. |
| 32 | - $this->xpath_xml = @simplexml_load_string(preg_replace('/ xmlns:xsi[^>]+/','',$response)); |
|
| 32 | + $this->xpath_xml = @simplexml_load_string(preg_replace('/ xmlns:xsi[^>]+/', '', $response)); |
|
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | |
@@ -116,12 +116,12 @@ discard block |
||
| 116 | 116 | { |
| 117 | 117 | $start = "<$elementName>"; |
| 118 | 118 | $end = "</$elementName>"; |
| 119 | - if (strpos($this->response,$start) === false || strpos($this->response,$end) === false) { |
|
| 119 | + if (strpos($this->response, $start) === false || strpos($this->response, $end) === false) { |
|
| 120 | 120 | return false; |
| 121 | 121 | } else { |
| 122 | - $start_position = strpos($this->response, $start)+strlen($start); |
|
| 122 | + $start_position = strpos($this->response, $start) + strlen($start); |
|
| 123 | 123 | $end_position = strpos($this->response, $end); |
| 124 | - return substr($this->response, $start_position, $end_position-$start_position); |
|
| 124 | + return substr($this->response, $start_position, $end_position - $start_position); |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
@@ -69,6 +69,7 @@ discard block |
||
| 69 | 69 | * remove XML response namespaces |
| 70 | 70 | * without this php will spit out warinings |
| 71 | 71 | * @see http://community.developer.authorize.net/t5/Integration-and-Testing/ARB-with-SimpleXML-PHP-Issue/m-p/7128#M5139 |
| 72 | + * @return string |
|
| 72 | 73 | */ |
| 73 | 74 | private function removeResponseXMLNS($input) |
| 74 | 75 | { |
@@ -150,6 +151,9 @@ discard block |
||
| 150 | 151 | $this->process(); |
| 151 | 152 | } |
| 152 | 153 | |
| 154 | + /** |
|
| 155 | + * @param SimpleXMLElement $xml |
|
| 156 | + */ |
|
| 153 | 157 | private function setParameters($xml, $array) |
| 154 | 158 | { |
| 155 | 159 | if (is_array($array)) |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | public function __construct($login, $transkey, $test = self::USE_PRODUCTION_SERVER) |
| 52 | 52 | { |
| 53 | - $login = trim($login); |
|
| 53 | + $login = trim($login); |
|
| 54 | 54 | $transkey = trim($transkey); |
| 55 | 55 | if (empty($login) || empty($transkey)) |
| 56 | 56 | { |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | $this->login = trim($login); |
| 61 | 61 | $this->transkey = trim($transkey); |
| 62 | - $test = (bool) $test; |
|
| 62 | + $test = (bool)$test; |
|
| 63 | 63 | |
| 64 | 64 | $subdomain = ($test) ? 'apitest' : 'api'; |
| 65 | 65 | $this->url = 'https://' . $subdomain . '.authorize.net/xml/v1/request.api'; |
@@ -73,14 +73,14 @@ discard block |
||
| 73 | 73 | private function removeResponseXMLNS($input) |
| 74 | 74 | { |
| 75 | 75 | // why remove them one at a time? all three aren't consistantly used in the response |
| 76 | - $input = str_replace(' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"','',$input); |
|
| 77 | - $input = str_replace(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"','',$input); |
|
| 78 | - return str_replace(' xmlns:xsd="http://www.w3.org/2001/XMLSchema"','',$input); |
|
| 76 | + $input = str_replace(' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"', '', $input); |
|
| 77 | + $input = str_replace(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"', '', $input); |
|
| 78 | + return str_replace(' xmlns:xsd="http://www.w3.org/2001/XMLSchema"', '', $input); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | public function __toString() |
| 82 | 82 | { |
| 83 | - $output = ''; |
|
| 83 | + $output = ''; |
|
| 84 | 84 | $output .= '<table summary="Authorize.Net Results" id="authnet">' . "\n"; |
| 85 | 85 | $output .= '<tr>' . "\n\t\t" . '<th colspan="2"><b>Class Parameters</b></th>' . "\n" . '</tr>' . "\n"; |
| 86 | 86 | $output .= '<tr>' . "\n\t\t" . '<td><b>API Login ID</b></td><td>' . $this->login . '</td>' . "\n" . '</tr>' . "\n"; |
@@ -159,9 +159,9 @@ discard block |
||
| 159 | 159 | { |
| 160 | 160 | if (is_array($value)) |
| 161 | 161 | { |
| 162 | - if(is_numeric($key)) |
|
| 162 | + if (is_numeric($key)) |
|
| 163 | 163 | { |
| 164 | - if($first === true) |
|
| 164 | + if ($first === true) |
|
| 165 | 165 | { |
| 166 | 166 | $xmlx = $xml; |
| 167 | 167 | $first = false; |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 2); |
| 201 | 201 | curl_setopt($this->ch, CURLOPT_CAINFO, dirname(__FILE__) . '/ssl/cert.pem'); |
| 202 | 202 | |
| 203 | - if(($this->response = curl_exec($this->ch)) !== false) |
|
| 203 | + if (($this->response = curl_exec($this->ch)) !== false) |
|
| 204 | 204 | { |
| 205 | 205 | $this->response_xml = @new SimpleXMLElement($this->response); |
| 206 | 206 | |