@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -10,199 +10,199 @@ discard block |
||
| 10 | 10 | class GetPaid_Payment_Form_Submission { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Submission ID |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - public $id = null; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * The raw submission data. |
|
| 21 | - * |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - protected $data = null; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Submission totals |
|
| 28 | - * |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $totals = array( |
|
| 32 | - |
|
| 33 | - 'subtotal' => array( |
|
| 34 | - 'initial' => 0, |
|
| 35 | - 'recurring' => 0, |
|
| 36 | - ), |
|
| 37 | - |
|
| 38 | - 'discount' => array( |
|
| 39 | - 'initial' => 0, |
|
| 40 | - 'recurring' => 0, |
|
| 41 | - ), |
|
| 42 | - |
|
| 43 | - 'fees' => array( |
|
| 44 | - 'initial' => 0, |
|
| 45 | - 'recurring' => 0, |
|
| 46 | - ), |
|
| 47 | - |
|
| 48 | - 'taxes' => array( |
|
| 49 | - 'initial' => 0, |
|
| 50 | - 'recurring' => 0, |
|
| 51 | - ), |
|
| 52 | - |
|
| 53 | - 'shipping' => array( |
|
| 54 | - 'initial' => 0, |
|
| 55 | - 'recurring' => 0, |
|
| 56 | - ), |
|
| 57 | - |
|
| 58 | - ); |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Sets the associated payment form. |
|
| 62 | - * |
|
| 63 | - * @var GetPaid_Payment_Form |
|
| 64 | - */ |
|
| 13 | + * Submission ID |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + public $id = null; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * The raw submission data. |
|
| 21 | + * |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + protected $data = null; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Submission totals |
|
| 28 | + * |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $totals = array( |
|
| 32 | + |
|
| 33 | + 'subtotal' => array( |
|
| 34 | + 'initial' => 0, |
|
| 35 | + 'recurring' => 0, |
|
| 36 | + ), |
|
| 37 | + |
|
| 38 | + 'discount' => array( |
|
| 39 | + 'initial' => 0, |
|
| 40 | + 'recurring' => 0, |
|
| 41 | + ), |
|
| 42 | + |
|
| 43 | + 'fees' => array( |
|
| 44 | + 'initial' => 0, |
|
| 45 | + 'recurring' => 0, |
|
| 46 | + ), |
|
| 47 | + |
|
| 48 | + 'taxes' => array( |
|
| 49 | + 'initial' => 0, |
|
| 50 | + 'recurring' => 0, |
|
| 51 | + ), |
|
| 52 | + |
|
| 53 | + 'shipping' => array( |
|
| 54 | + 'initial' => 0, |
|
| 55 | + 'recurring' => 0, |
|
| 56 | + ), |
|
| 57 | + |
|
| 58 | + ); |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Sets the associated payment form. |
|
| 62 | + * |
|
| 63 | + * @var GetPaid_Payment_Form |
|
| 64 | + */ |
|
| 65 | 65 | protected $payment_form = null; |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | - * The country for the submission. |
|
| 69 | - * |
|
| 70 | - * @var string |
|
| 71 | - */ |
|
| 72 | - public $country = null; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * The state for the submission. |
|
| 76 | - * |
|
| 77 | - * @since 1.0.19 |
|
| 78 | - * @var string |
|
| 79 | - */ |
|
| 80 | - public $state = null; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * The invoice associated with the submission. |
|
| 84 | - * |
|
| 85 | - * @var WPInv_Invoice |
|
| 86 | - */ |
|
| 87 | - protected $invoice = null; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * The recurring item for the submission. |
|
| 91 | - * |
|
| 92 | - * @var int |
|
| 93 | - */ |
|
| 94 | - public $has_recurring = 0; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * An array of fees for the submission. |
|
| 98 | - * |
|
| 99 | - * @var array |
|
| 100 | - */ |
|
| 101 | - protected $fees = array(); |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * An array of discounts for the submission. |
|
| 105 | - * |
|
| 106 | - * @var array |
|
| 107 | - */ |
|
| 108 | - protected $discounts = array(); |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * An array of taxes for the submission. |
|
| 112 | - * |
|
| 113 | - * @var array |
|
| 114 | - */ |
|
| 115 | - protected $taxes = array(); |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * An array of items for the submission. |
|
| 119 | - * |
|
| 120 | - * @var GetPaid_Form_Item[] |
|
| 121 | - */ |
|
| 122 | - protected $items = array(); |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * The last error. |
|
| 126 | - * |
|
| 127 | - * @var string |
|
| 128 | - */ |
|
| 129 | - public $last_error = null; |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * The last error code. |
|
| 133 | - * |
|
| 134 | - * @var string |
|
| 135 | - */ |
|
| 136 | - public $last_error_code = null; |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Class constructor. |
|
| 140 | - * |
|
| 141 | - */ |
|
| 142 | - public function __construct() { |
|
| 143 | - |
|
| 144 | - // Set the state and country to the default state and country. |
|
| 145 | - $this->country = wpinv_default_billing_country(); |
|
| 146 | - $this->state = wpinv_get_default_state(); |
|
| 147 | - |
|
| 148 | - // Do we have an actual submission? |
|
| 149 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 150 | - $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Loads submission data. |
|
| 157 | - * |
|
| 158 | - * @param array $data |
|
| 159 | - */ |
|
| 160 | - public function load_data( $data ) { |
|
| 161 | - |
|
| 162 | - // Allow plugins to filter the data. |
|
| 163 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 164 | - |
|
| 165 | - // Cache it... |
|
| 166 | - $this->data = $data; |
|
| 167 | - |
|
| 168 | - // Then generate a unique id from the data. |
|
| 169 | - $this->id = md5( wp_json_encode( $data ) ); |
|
| 170 | - |
|
| 171 | - // Finally, process the submission. |
|
| 172 | - try { |
|
| 173 | - |
|
| 174 | - // Each process is passed an instance of the class (with reference) |
|
| 175 | - // and should throw an Exception whenever it encounters one. |
|
| 176 | - $processors = apply_filters( |
|
| 177 | - 'getpaid_payment_form_submission_processors', |
|
| 178 | - array( |
|
| 179 | - array( $this, 'process_payment_form' ), |
|
| 180 | - array( $this, 'process_invoice' ), |
|
| 181 | - array( $this, 'process_fees' ), |
|
| 182 | - array( $this, 'process_items' ), |
|
| 183 | - array( $this, 'process_discount' ), |
|
| 184 | - array( $this, 'process_taxes' ), |
|
| 185 | - ), |
|
| 186 | - $this |
|
| 187 | - ); |
|
| 188 | - |
|
| 189 | - foreach ( $processors as $processor ) { |
|
| 190 | - call_user_func_array( $processor, array( &$this ) ); |
|
| 191 | - } |
|
| 68 | + * The country for the submission. |
|
| 69 | + * |
|
| 70 | + * @var string |
|
| 71 | + */ |
|
| 72 | + public $country = null; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * The state for the submission. |
|
| 76 | + * |
|
| 77 | + * @since 1.0.19 |
|
| 78 | + * @var string |
|
| 79 | + */ |
|
| 80 | + public $state = null; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * The invoice associated with the submission. |
|
| 84 | + * |
|
| 85 | + * @var WPInv_Invoice |
|
| 86 | + */ |
|
| 87 | + protected $invoice = null; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * The recurring item for the submission. |
|
| 91 | + * |
|
| 92 | + * @var int |
|
| 93 | + */ |
|
| 94 | + public $has_recurring = 0; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * An array of fees for the submission. |
|
| 98 | + * |
|
| 99 | + * @var array |
|
| 100 | + */ |
|
| 101 | + protected $fees = array(); |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * An array of discounts for the submission. |
|
| 105 | + * |
|
| 106 | + * @var array |
|
| 107 | + */ |
|
| 108 | + protected $discounts = array(); |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * An array of taxes for the submission. |
|
| 112 | + * |
|
| 113 | + * @var array |
|
| 114 | + */ |
|
| 115 | + protected $taxes = array(); |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * An array of items for the submission. |
|
| 119 | + * |
|
| 120 | + * @var GetPaid_Form_Item[] |
|
| 121 | + */ |
|
| 122 | + protected $items = array(); |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * The last error. |
|
| 126 | + * |
|
| 127 | + * @var string |
|
| 128 | + */ |
|
| 129 | + public $last_error = null; |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * The last error code. |
|
| 133 | + * |
|
| 134 | + * @var string |
|
| 135 | + */ |
|
| 136 | + public $last_error_code = null; |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Class constructor. |
|
| 140 | + * |
|
| 141 | + */ |
|
| 142 | + public function __construct() { |
|
| 143 | + |
|
| 144 | + // Set the state and country to the default state and country. |
|
| 145 | + $this->country = wpinv_default_billing_country(); |
|
| 146 | + $this->state = wpinv_get_default_state(); |
|
| 147 | + |
|
| 148 | + // Do we have an actual submission? |
|
| 149 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 150 | + $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Loads submission data. |
|
| 157 | + * |
|
| 158 | + * @param array $data |
|
| 159 | + */ |
|
| 160 | + public function load_data( $data ) { |
|
| 161 | + |
|
| 162 | + // Allow plugins to filter the data. |
|
| 163 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 164 | + |
|
| 165 | + // Cache it... |
|
| 166 | + $this->data = $data; |
|
| 167 | + |
|
| 168 | + // Then generate a unique id from the data. |
|
| 169 | + $this->id = md5( wp_json_encode( $data ) ); |
|
| 170 | + |
|
| 171 | + // Finally, process the submission. |
|
| 172 | + try { |
|
| 173 | + |
|
| 174 | + // Each process is passed an instance of the class (with reference) |
|
| 175 | + // and should throw an Exception whenever it encounters one. |
|
| 176 | + $processors = apply_filters( |
|
| 177 | + 'getpaid_payment_form_submission_processors', |
|
| 178 | + array( |
|
| 179 | + array( $this, 'process_payment_form' ), |
|
| 180 | + array( $this, 'process_invoice' ), |
|
| 181 | + array( $this, 'process_fees' ), |
|
| 182 | + array( $this, 'process_items' ), |
|
| 183 | + array( $this, 'process_discount' ), |
|
| 184 | + array( $this, 'process_taxes' ), |
|
| 185 | + ), |
|
| 186 | + $this |
|
| 187 | + ); |
|
| 188 | + |
|
| 189 | + foreach ( $processors as $processor ) { |
|
| 190 | + call_user_func_array( $processor, array( &$this ) ); |
|
| 191 | + } |
|
| 192 | 192 | } catch ( GetPaid_Payment_Exception $e ) { |
| 193 | - $this->last_error = $e->getMessage(); |
|
| 194 | - $this->last_error_code = $e->getErrorCode(); |
|
| 195 | - } catch ( Exception $e ) { |
|
| 196 | - $this->last_error = $e->getMessage(); |
|
| 197 | - $this->last_error_code = $e->getCode(); |
|
| 198 | - } |
|
| 193 | + $this->last_error = $e->getMessage(); |
|
| 194 | + $this->last_error_code = $e->getErrorCode(); |
|
| 195 | + } catch ( Exception $e ) { |
|
| 196 | + $this->last_error = $e->getMessage(); |
|
| 197 | + $this->last_error_code = $e->getCode(); |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - // Fired when we are done processing a submission. |
|
| 201 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 200 | + // Fired when we are done processing a submission. |
|
| 201 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 202 | 202 | |
| 203 | - } |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - /* |
|
| 205 | + /* |
|
| 206 | 206 | |-------------------------------------------------------------------------- |
| 207 | 207 | | Payment Forms. |
| 208 | 208 | |-------------------------------------------------------------------------- |
@@ -211,39 +211,39 @@ discard block |
||
| 211 | 211 | | submission has an active payment form etc. |
| 212 | 212 | */ |
| 213 | 213 | |
| 214 | - /** |
|
| 215 | - * Prepares the submission's payment form. |
|
| 216 | - * |
|
| 217 | - * @since 1.0.19 |
|
| 218 | - */ |
|
| 219 | - public function process_payment_form() { |
|
| 214 | + /** |
|
| 215 | + * Prepares the submission's payment form. |
|
| 216 | + * |
|
| 217 | + * @since 1.0.19 |
|
| 218 | + */ |
|
| 219 | + public function process_payment_form() { |
|
| 220 | 220 | |
| 221 | - // Every submission needs an active payment form. |
|
| 222 | - if ( empty( $this->data['form_id'] ) ) { |
|
| 223 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 224 | - } |
|
| 221 | + // Every submission needs an active payment form. |
|
| 222 | + if ( empty( $this->data['form_id'] ) ) { |
|
| 223 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - // Fetch the payment form. |
|
| 227 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 226 | + // Fetch the payment form. |
|
| 227 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 228 | 228 | |
| 229 | - if ( ! $this->payment_form->is_active() ) { |
|
| 230 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 231 | - } |
|
| 229 | + if ( ! $this->payment_form->is_active() ) { |
|
| 230 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 234 | - } |
|
| 233 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | 236 | /** |
| 237 | - * Returns the payment form. |
|
| 238 | - * |
|
| 239 | - * @since 1.0.19 |
|
| 240 | - * @return GetPaid_Payment_Form |
|
| 241 | - */ |
|
| 242 | - public function get_payment_form() { |
|
| 243 | - return $this->payment_form; |
|
| 244 | - } |
|
| 237 | + * Returns the payment form. |
|
| 238 | + * |
|
| 239 | + * @since 1.0.19 |
|
| 240 | + * @return GetPaid_Payment_Form |
|
| 241 | + */ |
|
| 242 | + public function get_payment_form() { |
|
| 243 | + return $this->payment_form; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - /* |
|
| 246 | + /* |
|
| 247 | 247 | |-------------------------------------------------------------------------- |
| 248 | 248 | | Invoices. |
| 249 | 249 | |-------------------------------------------------------------------------- |
@@ -252,84 +252,84 @@ discard block |
||
| 252 | 252 | | might be for an existing invoice. |
| 253 | 253 | */ |
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * Prepares the submission's invoice. |
|
| 257 | - * |
|
| 258 | - * @since 1.0.19 |
|
| 259 | - */ |
|
| 260 | - public function process_invoice() { |
|
| 255 | + /** |
|
| 256 | + * Prepares the submission's invoice. |
|
| 257 | + * |
|
| 258 | + * @since 1.0.19 |
|
| 259 | + */ |
|
| 260 | + public function process_invoice() { |
|
| 261 | 261 | |
| 262 | - // Abort if there is no invoice. |
|
| 263 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
| 264 | - return; |
|
| 265 | - } |
|
| 262 | + // Abort if there is no invoice. |
|
| 263 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
| 264 | + return; |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - // If the submission is for an existing invoice, ensure that it exists |
|
| 268 | - // and that it is not paid for. |
|
| 269 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 267 | + // If the submission is for an existing invoice, ensure that it exists |
|
| 268 | + // and that it is not paid for. |
|
| 269 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 270 | 270 | |
| 271 | 271 | if ( empty( $invoice ) ) { |
| 272 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - if ( $invoice->is_paid() ) { |
|
| 276 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - $this->payment_form->invoice = $invoice; |
|
| 280 | - if ( ! $this->payment_form->is_default() ) { |
|
| 281 | - |
|
| 282 | - $items = array(); |
|
| 283 | - $item_ids = array(); |
|
| 284 | - |
|
| 285 | - foreach ( $invoice->get_items() as $item ) { |
|
| 286 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 287 | - $item_ids[] = $item->get_id(); |
|
| 288 | - $items[] = $item; |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
| 293 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 294 | - $item_ids[] = $item->get_id(); |
|
| 295 | - $items[] = $item; |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - $this->payment_form->set_items( $items ); |
|
| 300 | - |
|
| 301 | - } else { |
|
| 302 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - $this->country = $invoice->get_country(); |
|
| 306 | - $this->state = $invoice->get_state(); |
|
| 307 | - $this->invoice = $invoice; |
|
| 308 | - |
|
| 309 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * Returns the associated invoice. |
|
| 314 | - * |
|
| 315 | - * @since 1.0.19 |
|
| 316 | - * @return WPInv_Invoice |
|
| 317 | - */ |
|
| 318 | - public function get_invoice() { |
|
| 319 | - return $this->invoice; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Checks whether there is an invoice associated with this submission. |
|
| 324 | - * |
|
| 325 | - * @since 1.0.19 |
|
| 326 | - * @return bool |
|
| 327 | - */ |
|
| 328 | - public function has_invoice() { |
|
| 329 | - return ! empty( $this->invoice ); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /* |
|
| 272 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + if ( $invoice->is_paid() ) { |
|
| 276 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + $this->payment_form->invoice = $invoice; |
|
| 280 | + if ( ! $this->payment_form->is_default() ) { |
|
| 281 | + |
|
| 282 | + $items = array(); |
|
| 283 | + $item_ids = array(); |
|
| 284 | + |
|
| 285 | + foreach ( $invoice->get_items() as $item ) { |
|
| 286 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 287 | + $item_ids[] = $item->get_id(); |
|
| 288 | + $items[] = $item; |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + foreach ( $this->payment_form->get_items() as $item ) { |
|
| 293 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 294 | + $item_ids[] = $item->get_id(); |
|
| 295 | + $items[] = $item; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + $this->payment_form->set_items( $items ); |
|
| 300 | + |
|
| 301 | + } else { |
|
| 302 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + $this->country = $invoice->get_country(); |
|
| 306 | + $this->state = $invoice->get_state(); |
|
| 307 | + $this->invoice = $invoice; |
|
| 308 | + |
|
| 309 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * Returns the associated invoice. |
|
| 314 | + * |
|
| 315 | + * @since 1.0.19 |
|
| 316 | + * @return WPInv_Invoice |
|
| 317 | + */ |
|
| 318 | + public function get_invoice() { |
|
| 319 | + return $this->invoice; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Checks whether there is an invoice associated with this submission. |
|
| 324 | + * |
|
| 325 | + * @since 1.0.19 |
|
| 326 | + * @return bool |
|
| 327 | + */ |
|
| 328 | + public function has_invoice() { |
|
| 329 | + return ! empty( $this->invoice ); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /* |
|
| 333 | 333 | |-------------------------------------------------------------------------- |
| 334 | 334 | | Items. |
| 335 | 335 | |-------------------------------------------------------------------------- |
@@ -338,129 +338,129 @@ discard block |
||
| 338 | 338 | | recurring item. But can have an unlimited number of non-recurring items. |
| 339 | 339 | */ |
| 340 | 340 | |
| 341 | - /** |
|
| 342 | - * Prepares the submission's items. |
|
| 343 | - * |
|
| 344 | - * @since 1.0.19 |
|
| 345 | - */ |
|
| 346 | - public function process_items() { |
|
| 347 | - |
|
| 348 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 349 | - |
|
| 350 | - foreach ( $processor->items as $item ) { |
|
| 351 | - $this->add_item( $item ); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * Adds an item to the submission. |
|
| 359 | - * |
|
| 360 | - * @since 1.0.19 |
|
| 361 | - * @param GetPaid_Form_Item $item |
|
| 362 | - */ |
|
| 363 | - public function add_item( $item ) { |
|
| 364 | - |
|
| 365 | - // Make sure that it is available for purchase. |
|
| 366 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 367 | - return; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - // Each submission can only contain one recurring item. |
|
| 371 | - if ( $item->is_recurring() ) { |
|
| 372 | - $this->has_recurring = $item->get_id(); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - // Update the items and totals. |
|
| 376 | - $this->items[ $item->get_id() ] = $item; |
|
| 377 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 378 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 379 | - |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Removes a specific item. |
|
| 384 | - * |
|
| 385 | - * You should not call this method after the discounts and taxes |
|
| 386 | - * have been calculated. |
|
| 387 | - * |
|
| 388 | - * @since 1.0.19 |
|
| 389 | - */ |
|
| 390 | - public function remove_item( $item_id ) { |
|
| 391 | - |
|
| 392 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
| 393 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 394 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 395 | - |
|
| 396 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 397 | - $this->has_recurring = 0; |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - unset( $this->items[ $item_id ] ); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * Returns the subtotal. |
|
| 407 | - * |
|
| 408 | - * @since 1.0.19 |
|
| 409 | - */ |
|
| 410 | - public function get_subtotal() { |
|
| 411 | - |
|
| 412 | - if ( wpinv_prices_include_tax() ) { |
|
| 413 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - return $this->totals['subtotal']['initial']; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * Returns the recurring subtotal. |
|
| 421 | - * |
|
| 422 | - * @since 1.0.19 |
|
| 423 | - */ |
|
| 424 | - public function get_recurring_subtotal() { |
|
| 425 | - |
|
| 426 | - if ( wpinv_prices_include_tax() ) { |
|
| 427 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - return $this->totals['subtotal']['recurring']; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * Returns all items. |
|
| 435 | - * |
|
| 436 | - * @since 1.0.19 |
|
| 437 | - * @return GetPaid_Form_Item[] |
|
| 438 | - */ |
|
| 439 | - public function get_items() { |
|
| 440 | - return $this->items; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Checks if there's a single subscription group in the submission. |
|
| 445 | - * |
|
| 446 | - * @since 2.3.0 |
|
| 447 | - * @return bool |
|
| 448 | - */ |
|
| 449 | - public function has_subscription_group() { |
|
| 450 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * Checks if there are multipe subscription groups in the submission. |
|
| 455 | - * |
|
| 456 | - * @since 2.3.0 |
|
| 457 | - * @return bool |
|
| 458 | - */ |
|
| 459 | - public function has_multiple_subscription_groups() { |
|
| 460 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /* |
|
| 341 | + /** |
|
| 342 | + * Prepares the submission's items. |
|
| 343 | + * |
|
| 344 | + * @since 1.0.19 |
|
| 345 | + */ |
|
| 346 | + public function process_items() { |
|
| 347 | + |
|
| 348 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 349 | + |
|
| 350 | + foreach ( $processor->items as $item ) { |
|
| 351 | + $this->add_item( $item ); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * Adds an item to the submission. |
|
| 359 | + * |
|
| 360 | + * @since 1.0.19 |
|
| 361 | + * @param GetPaid_Form_Item $item |
|
| 362 | + */ |
|
| 363 | + public function add_item( $item ) { |
|
| 364 | + |
|
| 365 | + // Make sure that it is available for purchase. |
|
| 366 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 367 | + return; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + // Each submission can only contain one recurring item. |
|
| 371 | + if ( $item->is_recurring() ) { |
|
| 372 | + $this->has_recurring = $item->get_id(); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + // Update the items and totals. |
|
| 376 | + $this->items[ $item->get_id() ] = $item; |
|
| 377 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 378 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 379 | + |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Removes a specific item. |
|
| 384 | + * |
|
| 385 | + * You should not call this method after the discounts and taxes |
|
| 386 | + * have been calculated. |
|
| 387 | + * |
|
| 388 | + * @since 1.0.19 |
|
| 389 | + */ |
|
| 390 | + public function remove_item( $item_id ) { |
|
| 391 | + |
|
| 392 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
| 393 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 394 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 395 | + |
|
| 396 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 397 | + $this->has_recurring = 0; |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + unset( $this->items[ $item_id ] ); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * Returns the subtotal. |
|
| 407 | + * |
|
| 408 | + * @since 1.0.19 |
|
| 409 | + */ |
|
| 410 | + public function get_subtotal() { |
|
| 411 | + |
|
| 412 | + if ( wpinv_prices_include_tax() ) { |
|
| 413 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + return $this->totals['subtotal']['initial']; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * Returns the recurring subtotal. |
|
| 421 | + * |
|
| 422 | + * @since 1.0.19 |
|
| 423 | + */ |
|
| 424 | + public function get_recurring_subtotal() { |
|
| 425 | + |
|
| 426 | + if ( wpinv_prices_include_tax() ) { |
|
| 427 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + return $this->totals['subtotal']['recurring']; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * Returns all items. |
|
| 435 | + * |
|
| 436 | + * @since 1.0.19 |
|
| 437 | + * @return GetPaid_Form_Item[] |
|
| 438 | + */ |
|
| 439 | + public function get_items() { |
|
| 440 | + return $this->items; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Checks if there's a single subscription group in the submission. |
|
| 445 | + * |
|
| 446 | + * @since 2.3.0 |
|
| 447 | + * @return bool |
|
| 448 | + */ |
|
| 449 | + public function has_subscription_group() { |
|
| 450 | + return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * Checks if there are multipe subscription groups in the submission. |
|
| 455 | + * |
|
| 456 | + * @since 2.3.0 |
|
| 457 | + * @return bool |
|
| 458 | + */ |
|
| 459 | + public function has_multiple_subscription_groups() { |
|
| 460 | + return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /* |
|
| 464 | 464 | |-------------------------------------------------------------------------- |
| 465 | 465 | | Taxes |
| 466 | 466 | |-------------------------------------------------------------------------- |
@@ -469,128 +469,128 @@ discard block |
||
| 469 | 469 | | or only one-time. |
| 470 | 470 | */ |
| 471 | 471 | |
| 472 | - /** |
|
| 473 | - * Prepares the submission's taxes. |
|
| 474 | - * |
|
| 475 | - * @since 1.0.19 |
|
| 476 | - */ |
|
| 477 | - public function process_taxes() { |
|
| 478 | - |
|
| 479 | - // Abort if we're not using taxes. |
|
| 480 | - if ( ! $this->use_taxes() ) { |
|
| 481 | - return; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 485 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 486 | - if ( ! empty( $country ) ) { |
|
| 487 | - $this->country = $country; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 491 | - if ( ! empty( $state ) ) { |
|
| 492 | - $this->state = $state; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - // Confirm if the provided country and the ip country are similar. |
|
| 496 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 497 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 498 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - // Abort if the country is not taxable. |
|
| 502 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 503 | - return; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 507 | - |
|
| 508 | - foreach ( $processor->taxes as $tax ) { |
|
| 509 | - $this->add_tax( $tax ); |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * Adds a tax to the submission. |
|
| 517 | - * |
|
| 518 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 519 | - * @since 1.0.19 |
|
| 520 | - */ |
|
| 521 | - public function add_tax( $tax ) { |
|
| 522 | - |
|
| 523 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 524 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 525 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - $this->taxes[ $tax['name'] ] = $tax; |
|
| 529 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 530 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 531 | - |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - /** |
|
| 535 | - * Removes a specific tax. |
|
| 536 | - * |
|
| 537 | - * @since 1.0.19 |
|
| 538 | - */ |
|
| 539 | - public function remove_tax( $tax_name ) { |
|
| 540 | - |
|
| 541 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 542 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 543 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 544 | - unset( $this->taxes[ $tax_name ] ); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Whether or not we'll use taxes for the submission. |
|
| 551 | - * |
|
| 552 | - * @since 1.0.19 |
|
| 553 | - */ |
|
| 554 | - public function use_taxes() { |
|
| 555 | - |
|
| 556 | - $use_taxes = wpinv_use_taxes(); |
|
| 557 | - |
|
| 558 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 559 | - $use_taxes = false; |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 563 | - |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * Returns the tax. |
|
| 568 | - * |
|
| 569 | - * @since 1.0.19 |
|
| 570 | - */ |
|
| 571 | - public function get_tax() { |
|
| 572 | - return $this->totals['taxes']['initial']; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * Returns the recurring tax. |
|
| 577 | - * |
|
| 578 | - * @since 1.0.19 |
|
| 579 | - */ |
|
| 580 | - public function get_recurring_tax() { |
|
| 581 | - return $this->totals['taxes']['recurring']; |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - /** |
|
| 585 | - * Returns all taxes. |
|
| 586 | - * |
|
| 587 | - * @since 1.0.19 |
|
| 588 | - */ |
|
| 589 | - public function get_taxes() { |
|
| 590 | - return $this->taxes; |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - /* |
|
| 472 | + /** |
|
| 473 | + * Prepares the submission's taxes. |
|
| 474 | + * |
|
| 475 | + * @since 1.0.19 |
|
| 476 | + */ |
|
| 477 | + public function process_taxes() { |
|
| 478 | + |
|
| 479 | + // Abort if we're not using taxes. |
|
| 480 | + if ( ! $this->use_taxes() ) { |
|
| 481 | + return; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 485 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 486 | + if ( ! empty( $country ) ) { |
|
| 487 | + $this->country = $country; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 491 | + if ( ! empty( $state ) ) { |
|
| 492 | + $this->state = $state; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + // Confirm if the provided country and the ip country are similar. |
|
| 496 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 497 | + if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 498 | + throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + // Abort if the country is not taxable. |
|
| 502 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 503 | + return; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 507 | + |
|
| 508 | + foreach ( $processor->taxes as $tax ) { |
|
| 509 | + $this->add_tax( $tax ); |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * Adds a tax to the submission. |
|
| 517 | + * |
|
| 518 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 519 | + * @since 1.0.19 |
|
| 520 | + */ |
|
| 521 | + public function add_tax( $tax ) { |
|
| 522 | + |
|
| 523 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 524 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 525 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + $this->taxes[ $tax['name'] ] = $tax; |
|
| 529 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 530 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 531 | + |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + /** |
|
| 535 | + * Removes a specific tax. |
|
| 536 | + * |
|
| 537 | + * @since 1.0.19 |
|
| 538 | + */ |
|
| 539 | + public function remove_tax( $tax_name ) { |
|
| 540 | + |
|
| 541 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 542 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 543 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 544 | + unset( $this->taxes[ $tax_name ] ); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Whether or not we'll use taxes for the submission. |
|
| 551 | + * |
|
| 552 | + * @since 1.0.19 |
|
| 553 | + */ |
|
| 554 | + public function use_taxes() { |
|
| 555 | + |
|
| 556 | + $use_taxes = wpinv_use_taxes(); |
|
| 557 | + |
|
| 558 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 559 | + $use_taxes = false; |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 563 | + |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * Returns the tax. |
|
| 568 | + * |
|
| 569 | + * @since 1.0.19 |
|
| 570 | + */ |
|
| 571 | + public function get_tax() { |
|
| 572 | + return $this->totals['taxes']['initial']; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * Returns the recurring tax. |
|
| 577 | + * |
|
| 578 | + * @since 1.0.19 |
|
| 579 | + */ |
|
| 580 | + public function get_recurring_tax() { |
|
| 581 | + return $this->totals['taxes']['recurring']; |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + /** |
|
| 585 | + * Returns all taxes. |
|
| 586 | + * |
|
| 587 | + * @since 1.0.19 |
|
| 588 | + */ |
|
| 589 | + public function get_taxes() { |
|
| 590 | + return $this->taxes; |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + /* |
|
| 594 | 594 | |-------------------------------------------------------------------------- |
| 595 | 595 | | Discounts |
| 596 | 596 | |-------------------------------------------------------------------------- |
@@ -599,99 +599,99 @@ discard block |
||
| 599 | 599 | | or only one-time. They also do not have to come from a discount code. |
| 600 | 600 | */ |
| 601 | 601 | |
| 602 | - /** |
|
| 603 | - * Prepares the submission's discount. |
|
| 604 | - * |
|
| 605 | - * @since 1.0.19 |
|
| 606 | - */ |
|
| 607 | - public function process_discount() { |
|
| 608 | - |
|
| 609 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 610 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 611 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 612 | - |
|
| 613 | - foreach ( $processor->discounts as $discount ) { |
|
| 614 | - $this->add_discount( $discount ); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * Adds a discount to the submission. |
|
| 622 | - * |
|
| 623 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 624 | - * @since 1.0.19 |
|
| 625 | - */ |
|
| 626 | - public function add_discount( $discount ) { |
|
| 627 | - $this->discounts[ $discount['name'] ] = $discount; |
|
| 628 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 629 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * Removes a discount from the submission. |
|
| 634 | - * |
|
| 635 | - * @since 1.0.19 |
|
| 636 | - */ |
|
| 637 | - public function remove_discount( $name ) { |
|
| 638 | - |
|
| 639 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
| 640 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 641 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 642 | - unset( $this->discounts[ $name ] ); |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - /** |
|
| 648 | - * Checks whether there is a discount code associated with this submission. |
|
| 649 | - * |
|
| 650 | - * @since 1.0.19 |
|
| 651 | - * @return bool |
|
| 652 | - */ |
|
| 653 | - public function has_discount_code() { |
|
| 654 | - return ! empty( $this->discounts['discount_code'] ); |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * Returns the discount code. |
|
| 659 | - * |
|
| 660 | - * @since 1.0.19 |
|
| 661 | - * @return string |
|
| 662 | - */ |
|
| 663 | - public function get_discount_code() { |
|
| 664 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * Returns the discount. |
|
| 669 | - * |
|
| 670 | - * @since 1.0.19 |
|
| 671 | - */ |
|
| 672 | - public function get_discount() { |
|
| 673 | - return $this->totals['discount']['initial']; |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - /** |
|
| 677 | - * Returns the recurring discount. |
|
| 678 | - * |
|
| 679 | - * @since 1.0.19 |
|
| 680 | - */ |
|
| 681 | - public function get_recurring_discount() { |
|
| 682 | - return $this->totals['discount']['recurring']; |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * Returns all discounts. |
|
| 687 | - * |
|
| 688 | - * @since 1.0.19 |
|
| 689 | - */ |
|
| 690 | - public function get_discounts() { |
|
| 691 | - return $this->discounts; |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - /* |
|
| 602 | + /** |
|
| 603 | + * Prepares the submission's discount. |
|
| 604 | + * |
|
| 605 | + * @since 1.0.19 |
|
| 606 | + */ |
|
| 607 | + public function process_discount() { |
|
| 608 | + |
|
| 609 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 610 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 611 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 612 | + |
|
| 613 | + foreach ( $processor->discounts as $discount ) { |
|
| 614 | + $this->add_discount( $discount ); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + /** |
|
| 621 | + * Adds a discount to the submission. |
|
| 622 | + * |
|
| 623 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 624 | + * @since 1.0.19 |
|
| 625 | + */ |
|
| 626 | + public function add_discount( $discount ) { |
|
| 627 | + $this->discounts[ $discount['name'] ] = $discount; |
|
| 628 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 629 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * Removes a discount from the submission. |
|
| 634 | + * |
|
| 635 | + * @since 1.0.19 |
|
| 636 | + */ |
|
| 637 | + public function remove_discount( $name ) { |
|
| 638 | + |
|
| 639 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
| 640 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 641 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 642 | + unset( $this->discounts[ $name ] ); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + /** |
|
| 648 | + * Checks whether there is a discount code associated with this submission. |
|
| 649 | + * |
|
| 650 | + * @since 1.0.19 |
|
| 651 | + * @return bool |
|
| 652 | + */ |
|
| 653 | + public function has_discount_code() { |
|
| 654 | + return ! empty( $this->discounts['discount_code'] ); |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * Returns the discount code. |
|
| 659 | + * |
|
| 660 | + * @since 1.0.19 |
|
| 661 | + * @return string |
|
| 662 | + */ |
|
| 663 | + public function get_discount_code() { |
|
| 664 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * Returns the discount. |
|
| 669 | + * |
|
| 670 | + * @since 1.0.19 |
|
| 671 | + */ |
|
| 672 | + public function get_discount() { |
|
| 673 | + return $this->totals['discount']['initial']; |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + /** |
|
| 677 | + * Returns the recurring discount. |
|
| 678 | + * |
|
| 679 | + * @since 1.0.19 |
|
| 680 | + */ |
|
| 681 | + public function get_recurring_discount() { |
|
| 682 | + return $this->totals['discount']['recurring']; |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * Returns all discounts. |
|
| 687 | + * |
|
| 688 | + * @since 1.0.19 |
|
| 689 | + */ |
|
| 690 | + public function get_discounts() { |
|
| 691 | + return $this->discounts; |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + /* |
|
| 695 | 695 | |-------------------------------------------------------------------------- |
| 696 | 696 | | Fees |
| 697 | 697 | |-------------------------------------------------------------------------- |
@@ -701,100 +701,100 @@ discard block |
||
| 701 | 701 | | fees. |
| 702 | 702 | */ |
| 703 | 703 | |
| 704 | - /** |
|
| 705 | - * Prepares the submission's fees. |
|
| 706 | - * |
|
| 707 | - * @since 1.0.19 |
|
| 708 | - */ |
|
| 709 | - public function process_fees() { |
|
| 710 | - |
|
| 711 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 712 | - |
|
| 713 | - foreach ( $fees_processor->fees as $fee ) { |
|
| 714 | - $this->add_fee( $fee ); |
|
| 715 | - } |
|
| 716 | - |
|
| 717 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 718 | - } |
|
| 719 | - |
|
| 720 | - /** |
|
| 721 | - * Adds a fee to the submission. |
|
| 722 | - * |
|
| 723 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 724 | - * @since 1.0.19 |
|
| 725 | - */ |
|
| 726 | - public function add_fee( $fee ) { |
|
| 727 | - |
|
| 728 | - if ( $fee['name'] == 'shipping' ) { |
|
| 729 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 730 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 731 | - return; |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - $this->fees[ $fee['name'] ] = $fee; |
|
| 735 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 736 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 737 | - |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - /** |
|
| 741 | - * Removes a fee from the submission. |
|
| 742 | - * |
|
| 743 | - * @since 1.0.19 |
|
| 744 | - */ |
|
| 745 | - public function remove_fee( $name ) { |
|
| 746 | - |
|
| 747 | - if ( isset( $this->fees[ $name ] ) ) { |
|
| 748 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 749 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 750 | - unset( $this->fees[ $name ] ); |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - if ( 'shipping' == $name ) { |
|
| 754 | - $this->totals['shipping']['initial'] = 0; |
|
| 755 | - $this->totals['shipping']['recurring'] = 0; |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - /** |
|
| 761 | - * Returns the fees. |
|
| 762 | - * |
|
| 763 | - * @since 1.0.19 |
|
| 764 | - */ |
|
| 765 | - public function get_fee() { |
|
| 766 | - return $this->totals['fees']['initial']; |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - /** |
|
| 770 | - * Returns the recurring fees. |
|
| 771 | - * |
|
| 772 | - * @since 1.0.19 |
|
| 773 | - */ |
|
| 774 | - public function get_recurring_fee() { |
|
| 775 | - return $this->totals['fees']['recurring']; |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - /** |
|
| 779 | - * Returns all fees. |
|
| 780 | - * |
|
| 781 | - * @since 1.0.19 |
|
| 782 | - */ |
|
| 783 | - public function get_fees() { |
|
| 784 | - return $this->fees; |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - /** |
|
| 788 | - * Checks if there are any fees for the form. |
|
| 789 | - * |
|
| 790 | - * @return bool |
|
| 791 | - * @since 1.0.19 |
|
| 792 | - */ |
|
| 793 | - public function has_fees() { |
|
| 794 | - return count( $this->fees ) !== 0; |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - /* |
|
| 704 | + /** |
|
| 705 | + * Prepares the submission's fees. |
|
| 706 | + * |
|
| 707 | + * @since 1.0.19 |
|
| 708 | + */ |
|
| 709 | + public function process_fees() { |
|
| 710 | + |
|
| 711 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 712 | + |
|
| 713 | + foreach ( $fees_processor->fees as $fee ) { |
|
| 714 | + $this->add_fee( $fee ); |
|
| 715 | + } |
|
| 716 | + |
|
| 717 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 718 | + } |
|
| 719 | + |
|
| 720 | + /** |
|
| 721 | + * Adds a fee to the submission. |
|
| 722 | + * |
|
| 723 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 724 | + * @since 1.0.19 |
|
| 725 | + */ |
|
| 726 | + public function add_fee( $fee ) { |
|
| 727 | + |
|
| 728 | + if ( $fee['name'] == 'shipping' ) { |
|
| 729 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 730 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 731 | + return; |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + $this->fees[ $fee['name'] ] = $fee; |
|
| 735 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 736 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 737 | + |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * Removes a fee from the submission. |
|
| 742 | + * |
|
| 743 | + * @since 1.0.19 |
|
| 744 | + */ |
|
| 745 | + public function remove_fee( $name ) { |
|
| 746 | + |
|
| 747 | + if ( isset( $this->fees[ $name ] ) ) { |
|
| 748 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 749 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 750 | + unset( $this->fees[ $name ] ); |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + if ( 'shipping' == $name ) { |
|
| 754 | + $this->totals['shipping']['initial'] = 0; |
|
| 755 | + $this->totals['shipping']['recurring'] = 0; |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + /** |
|
| 761 | + * Returns the fees. |
|
| 762 | + * |
|
| 763 | + * @since 1.0.19 |
|
| 764 | + */ |
|
| 765 | + public function get_fee() { |
|
| 766 | + return $this->totals['fees']['initial']; |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + /** |
|
| 770 | + * Returns the recurring fees. |
|
| 771 | + * |
|
| 772 | + * @since 1.0.19 |
|
| 773 | + */ |
|
| 774 | + public function get_recurring_fee() { |
|
| 775 | + return $this->totals['fees']['recurring']; |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + /** |
|
| 779 | + * Returns all fees. |
|
| 780 | + * |
|
| 781 | + * @since 1.0.19 |
|
| 782 | + */ |
|
| 783 | + public function get_fees() { |
|
| 784 | + return $this->fees; |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + /** |
|
| 788 | + * Checks if there are any fees for the form. |
|
| 789 | + * |
|
| 790 | + * @return bool |
|
| 791 | + * @since 1.0.19 |
|
| 792 | + */ |
|
| 793 | + public function has_fees() { |
|
| 794 | + return count( $this->fees ) !== 0; |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + /* |
|
| 798 | 798 | |-------------------------------------------------------------------------- |
| 799 | 799 | | MISC |
| 800 | 800 | |-------------------------------------------------------------------------- |
@@ -802,147 +802,147 @@ discard block |
||
| 802 | 802 | | Extra submission functions. |
| 803 | 803 | */ |
| 804 | 804 | |
| 805 | - /** |
|
| 806 | - * Returns the shipping amount. |
|
| 807 | - * |
|
| 808 | - * @since 1.0.19 |
|
| 809 | - */ |
|
| 810 | - public function get_shipping() { |
|
| 811 | - return $this->totals['shipping']['initial']; |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - /** |
|
| 815 | - * Returns the recurring shipping. |
|
| 816 | - * |
|
| 817 | - * @since 1.0.19 |
|
| 818 | - */ |
|
| 819 | - public function get_recurring_shipping() { |
|
| 820 | - return $this->totals['shipping']['recurring']; |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - /** |
|
| 824 | - * Checks if there are any shipping fees for the form. |
|
| 825 | - * |
|
| 826 | - * @return bool |
|
| 827 | - * @since 1.0.19 |
|
| 828 | - */ |
|
| 829 | - public function has_shipping() { |
|
| 830 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - /** |
|
| 834 | - * Checks if this is the initial fetch. |
|
| 835 | - * |
|
| 836 | - * @return bool |
|
| 837 | - * @since 1.0.19 |
|
| 838 | - */ |
|
| 839 | - public function is_initial_fetch() { |
|
| 840 | - return empty( $this->data['initial_state'] ); |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - /** |
|
| 844 | - * Returns the total amount to collect for this submission. |
|
| 845 | - * |
|
| 846 | - * @since 1.0.19 |
|
| 847 | - */ |
|
| 848 | - public function get_total() { |
|
| 849 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
|
| 850 | - return max( $total, 0 ); |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - /** |
|
| 854 | - * Returns the recurring total amount to collect for this submission. |
|
| 855 | - * |
|
| 856 | - * @since 1.0.19 |
|
| 857 | - */ |
|
| 858 | - public function get_recurring_total() { |
|
| 859 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
|
| 860 | - return max( $total, 0 ); |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - /** |
|
| 864 | - * Whether payment details should be collected for this submission. |
|
| 865 | - * |
|
| 866 | - * @since 1.0.19 |
|
| 867 | - */ |
|
| 868 | - public function should_collect_payment_details() { |
|
| 869 | - $initial = $this->get_total(); |
|
| 870 | - $recurring = $this->get_recurring_total(); |
|
| 871 | - |
|
| 872 | - if ( $this->has_recurring == 0 ) { |
|
| 873 | - $recurring = 0; |
|
| 874 | - } |
|
| 875 | - |
|
| 876 | - $collect = $initial > 0 || $recurring > 0; |
|
| 877 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - /** |
|
| 881 | - * Returns the billing email of the user. |
|
| 882 | - * |
|
| 883 | - * @since 1.0.19 |
|
| 884 | - */ |
|
| 885 | - public function get_billing_email() { |
|
| 886 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - /** |
|
| 890 | - * Checks if the submitter has a billing email. |
|
| 891 | - * |
|
| 892 | - * @since 1.0.19 |
|
| 893 | - */ |
|
| 894 | - public function has_billing_email() { |
|
| 895 | - $billing_email = $this->get_billing_email(); |
|
| 896 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - /** |
|
| 900 | - * Returns the appropriate currency for the submission. |
|
| 901 | - * |
|
| 902 | - * @since 1.0.19 |
|
| 903 | - * @return string |
|
| 904 | - */ |
|
| 905 | - public function get_currency() { |
|
| 906 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 907 | - } |
|
| 908 | - |
|
| 909 | - /** |
|
| 910 | - * Returns the raw submission data. |
|
| 911 | - * |
|
| 912 | - * @since 1.0.19 |
|
| 913 | - * @return array |
|
| 914 | - */ |
|
| 915 | - public function get_data() { |
|
| 916 | - return $this->data; |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - /** |
|
| 920 | - * Returns a field from the submission data |
|
| 921 | - * |
|
| 922 | - * @param string $field |
|
| 923 | - * @since 1.0.19 |
|
| 924 | - * @return mixed|null |
|
| 925 | - */ |
|
| 926 | - public function get_field( $field, $sub_array_key = null ) { |
|
| 927 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * Checks if a required field is set. |
|
| 932 | - * |
|
| 933 | - * @since 1.0.19 |
|
| 934 | - */ |
|
| 935 | - public function is_required_field_set( $field ) { |
|
| 936 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 937 | - } |
|
| 938 | - |
|
| 939 | - /** |
|
| 940 | - * Formats an amount |
|
| 941 | - * |
|
| 942 | - * @since 1.0.19 |
|
| 943 | - */ |
|
| 944 | - public function format_amount( $amount ) { |
|
| 945 | - return wpinv_price( $amount, $this->get_currency() ); |
|
| 946 | - } |
|
| 805 | + /** |
|
| 806 | + * Returns the shipping amount. |
|
| 807 | + * |
|
| 808 | + * @since 1.0.19 |
|
| 809 | + */ |
|
| 810 | + public function get_shipping() { |
|
| 811 | + return $this->totals['shipping']['initial']; |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + /** |
|
| 815 | + * Returns the recurring shipping. |
|
| 816 | + * |
|
| 817 | + * @since 1.0.19 |
|
| 818 | + */ |
|
| 819 | + public function get_recurring_shipping() { |
|
| 820 | + return $this->totals['shipping']['recurring']; |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + /** |
|
| 824 | + * Checks if there are any shipping fees for the form. |
|
| 825 | + * |
|
| 826 | + * @return bool |
|
| 827 | + * @since 1.0.19 |
|
| 828 | + */ |
|
| 829 | + public function has_shipping() { |
|
| 830 | + return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + /** |
|
| 834 | + * Checks if this is the initial fetch. |
|
| 835 | + * |
|
| 836 | + * @return bool |
|
| 837 | + * @since 1.0.19 |
|
| 838 | + */ |
|
| 839 | + public function is_initial_fetch() { |
|
| 840 | + return empty( $this->data['initial_state'] ); |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + /** |
|
| 844 | + * Returns the total amount to collect for this submission. |
|
| 845 | + * |
|
| 846 | + * @since 1.0.19 |
|
| 847 | + */ |
|
| 848 | + public function get_total() { |
|
| 849 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
|
| 850 | + return max( $total, 0 ); |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + /** |
|
| 854 | + * Returns the recurring total amount to collect for this submission. |
|
| 855 | + * |
|
| 856 | + * @since 1.0.19 |
|
| 857 | + */ |
|
| 858 | + public function get_recurring_total() { |
|
| 859 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
|
| 860 | + return max( $total, 0 ); |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + /** |
|
| 864 | + * Whether payment details should be collected for this submission. |
|
| 865 | + * |
|
| 866 | + * @since 1.0.19 |
|
| 867 | + */ |
|
| 868 | + public function should_collect_payment_details() { |
|
| 869 | + $initial = $this->get_total(); |
|
| 870 | + $recurring = $this->get_recurring_total(); |
|
| 871 | + |
|
| 872 | + if ( $this->has_recurring == 0 ) { |
|
| 873 | + $recurring = 0; |
|
| 874 | + } |
|
| 875 | + |
|
| 876 | + $collect = $initial > 0 || $recurring > 0; |
|
| 877 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + /** |
|
| 881 | + * Returns the billing email of the user. |
|
| 882 | + * |
|
| 883 | + * @since 1.0.19 |
|
| 884 | + */ |
|
| 885 | + public function get_billing_email() { |
|
| 886 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + /** |
|
| 890 | + * Checks if the submitter has a billing email. |
|
| 891 | + * |
|
| 892 | + * @since 1.0.19 |
|
| 893 | + */ |
|
| 894 | + public function has_billing_email() { |
|
| 895 | + $billing_email = $this->get_billing_email(); |
|
| 896 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * Returns the appropriate currency for the submission. |
|
| 901 | + * |
|
| 902 | + * @since 1.0.19 |
|
| 903 | + * @return string |
|
| 904 | + */ |
|
| 905 | + public function get_currency() { |
|
| 906 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 907 | + } |
|
| 908 | + |
|
| 909 | + /** |
|
| 910 | + * Returns the raw submission data. |
|
| 911 | + * |
|
| 912 | + * @since 1.0.19 |
|
| 913 | + * @return array |
|
| 914 | + */ |
|
| 915 | + public function get_data() { |
|
| 916 | + return $this->data; |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + /** |
|
| 920 | + * Returns a field from the submission data |
|
| 921 | + * |
|
| 922 | + * @param string $field |
|
| 923 | + * @since 1.0.19 |
|
| 924 | + * @return mixed|null |
|
| 925 | + */ |
|
| 926 | + public function get_field( $field, $sub_array_key = null ) { |
|
| 927 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * Checks if a required field is set. |
|
| 932 | + * |
|
| 933 | + * @since 1.0.19 |
|
| 934 | + */ |
|
| 935 | + public function is_required_field_set( $field ) { |
|
| 936 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 937 | + } |
|
| 938 | + |
|
| 939 | + /** |
|
| 940 | + * Formats an amount |
|
| 941 | + * |
|
| 942 | + * @since 1.0.19 |
|
| 943 | + */ |
|
| 944 | + public function format_amount( $amount ) { |
|
| 945 | + return wpinv_price( $amount, $this->get_currency() ); |
|
| 946 | + } |
|
| 947 | 947 | |
| 948 | 948 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | $this->state = wpinv_get_default_state(); |
| 147 | 147 | |
| 148 | 148 | // Do we have an actual submission? |
| 149 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 150 | - $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) ); |
|
| 149 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
| 150 | + $this->load_data(wp_kses_post_deep(wp_unslash($_POST))); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | } |
@@ -157,16 +157,16 @@ discard block |
||
| 157 | 157 | * |
| 158 | 158 | * @param array $data |
| 159 | 159 | */ |
| 160 | - public function load_data( $data ) { |
|
| 160 | + public function load_data($data) { |
|
| 161 | 161 | |
| 162 | 162 | // Allow plugins to filter the data. |
| 163 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 163 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
| 164 | 164 | |
| 165 | 165 | // Cache it... |
| 166 | 166 | $this->data = $data; |
| 167 | 167 | |
| 168 | 168 | // Then generate a unique id from the data. |
| 169 | - $this->id = md5( wp_json_encode( $data ) ); |
|
| 169 | + $this->id = md5(wp_json_encode($data)); |
|
| 170 | 170 | |
| 171 | 171 | // Finally, process the submission. |
| 172 | 172 | try { |
@@ -176,29 +176,29 @@ discard block |
||
| 176 | 176 | $processors = apply_filters( |
| 177 | 177 | 'getpaid_payment_form_submission_processors', |
| 178 | 178 | array( |
| 179 | - array( $this, 'process_payment_form' ), |
|
| 180 | - array( $this, 'process_invoice' ), |
|
| 181 | - array( $this, 'process_fees' ), |
|
| 182 | - array( $this, 'process_items' ), |
|
| 183 | - array( $this, 'process_discount' ), |
|
| 184 | - array( $this, 'process_taxes' ), |
|
| 179 | + array($this, 'process_payment_form'), |
|
| 180 | + array($this, 'process_invoice'), |
|
| 181 | + array($this, 'process_fees'), |
|
| 182 | + array($this, 'process_items'), |
|
| 183 | + array($this, 'process_discount'), |
|
| 184 | + array($this, 'process_taxes'), |
|
| 185 | 185 | ), |
| 186 | 186 | $this |
| 187 | 187 | ); |
| 188 | 188 | |
| 189 | - foreach ( $processors as $processor ) { |
|
| 190 | - call_user_func_array( $processor, array( &$this ) ); |
|
| 189 | + foreach ($processors as $processor) { |
|
| 190 | + call_user_func_array($processor, array(&$this)); |
|
| 191 | 191 | } |
| 192 | -} catch ( GetPaid_Payment_Exception $e ) { |
|
| 192 | +} catch (GetPaid_Payment_Exception $e) { |
|
| 193 | 193 | $this->last_error = $e->getMessage(); |
| 194 | 194 | $this->last_error_code = $e->getErrorCode(); |
| 195 | - } catch ( Exception $e ) { |
|
| 195 | + } catch (Exception $e) { |
|
| 196 | 196 | $this->last_error = $e->getMessage(); |
| 197 | 197 | $this->last_error_code = $e->getCode(); |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // Fired when we are done processing a submission. |
| 201 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 201 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
| 202 | 202 | |
| 203 | 203 | } |
| 204 | 204 | |
@@ -219,18 +219,18 @@ discard block |
||
| 219 | 219 | public function process_payment_form() { |
| 220 | 220 | |
| 221 | 221 | // Every submission needs an active payment form. |
| 222 | - if ( empty( $this->data['form_id'] ) ) { |
|
| 223 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 222 | + if (empty($this->data['form_id'])) { |
|
| 223 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | // Fetch the payment form. |
| 227 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 227 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
| 228 | 228 | |
| 229 | - if ( ! $this->payment_form->is_active() ) { |
|
| 230 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 229 | + if (!$this->payment_form->is_active()) { |
|
| 230 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 233 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -260,53 +260,53 @@ discard block |
||
| 260 | 260 | public function process_invoice() { |
| 261 | 261 | |
| 262 | 262 | // Abort if there is no invoice. |
| 263 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
| 263 | + if (empty($this->data['invoice_id'])) { |
|
| 264 | 264 | return; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | // If the submission is for an existing invoice, ensure that it exists |
| 268 | 268 | // and that it is not paid for. |
| 269 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 269 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
| 270 | 270 | |
| 271 | - if ( empty( $invoice ) ) { |
|
| 272 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 271 | + if (empty($invoice)) { |
|
| 272 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - if ( $invoice->is_paid() ) { |
|
| 276 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 275 | + if ($invoice->is_paid()) { |
|
| 276 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | $this->payment_form->invoice = $invoice; |
| 280 | - if ( ! $this->payment_form->is_default() ) { |
|
| 280 | + if (!$this->payment_form->is_default()) { |
|
| 281 | 281 | |
| 282 | 282 | $items = array(); |
| 283 | 283 | $item_ids = array(); |
| 284 | 284 | |
| 285 | - foreach ( $invoice->get_items() as $item ) { |
|
| 286 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 285 | + foreach ($invoice->get_items() as $item) { |
|
| 286 | + if (!in_array($item->get_id(), $item_ids)) { |
|
| 287 | 287 | $item_ids[] = $item->get_id(); |
| 288 | 288 | $items[] = $item; |
| 289 | 289 | } |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
| 293 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 292 | + foreach ($this->payment_form->get_items() as $item) { |
|
| 293 | + if (!in_array($item->get_id(), $item_ids)) { |
|
| 294 | 294 | $item_ids[] = $item->get_id(); |
| 295 | 295 | $items[] = $item; |
| 296 | 296 | } |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - $this->payment_form->set_items( $items ); |
|
| 299 | + $this->payment_form->set_items($items); |
|
| 300 | 300 | |
| 301 | 301 | } else { |
| 302 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
| 302 | + $this->payment_form->set_items($invoice->get_items()); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | $this->country = $invoice->get_country(); |
| 306 | 306 | $this->state = $invoice->get_state(); |
| 307 | 307 | $this->invoice = $invoice; |
| 308 | 308 | |
| 309 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 309 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | * @return bool |
| 327 | 327 | */ |
| 328 | 328 | public function has_invoice() { |
| 329 | - return ! empty( $this->invoice ); |
|
| 329 | + return !empty($this->invoice); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | /* |
@@ -345,13 +345,13 @@ discard block |
||
| 345 | 345 | */ |
| 346 | 346 | public function process_items() { |
| 347 | 347 | |
| 348 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 348 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
| 349 | 349 | |
| 350 | - foreach ( $processor->items as $item ) { |
|
| 351 | - $this->add_item( $item ); |
|
| 350 | + foreach ($processor->items as $item) { |
|
| 351 | + $this->add_item($item); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 354 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | /** |
@@ -360,20 +360,20 @@ discard block |
||
| 360 | 360 | * @since 1.0.19 |
| 361 | 361 | * @param GetPaid_Form_Item $item |
| 362 | 362 | */ |
| 363 | - public function add_item( $item ) { |
|
| 363 | + public function add_item($item) { |
|
| 364 | 364 | |
| 365 | 365 | // Make sure that it is available for purchase. |
| 366 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 366 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
| 367 | 367 | return; |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | // Each submission can only contain one recurring item. |
| 371 | - if ( $item->is_recurring() ) { |
|
| 371 | + if ($item->is_recurring()) { |
|
| 372 | 372 | $this->has_recurring = $item->get_id(); |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | // Update the items and totals. |
| 376 | - $this->items[ $item->get_id() ] = $item; |
|
| 376 | + $this->items[$item->get_id()] = $item; |
|
| 377 | 377 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
| 378 | 378 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
| 379 | 379 | |
@@ -387,17 +387,17 @@ discard block |
||
| 387 | 387 | * |
| 388 | 388 | * @since 1.0.19 |
| 389 | 389 | */ |
| 390 | - public function remove_item( $item_id ) { |
|
| 390 | + public function remove_item($item_id) { |
|
| 391 | 391 | |
| 392 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
| 393 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 394 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 392 | + if (isset($this->items[$item_id])) { |
|
| 393 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
| 394 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
| 395 | 395 | |
| 396 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 396 | + if ($this->items[$item_id]->is_recurring()) { |
|
| 397 | 397 | $this->has_recurring = 0; |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | - unset( $this->items[ $item_id ] ); |
|
| 400 | + unset($this->items[$item_id]); |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | } |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | */ |
| 410 | 410 | public function get_subtotal() { |
| 411 | 411 | |
| 412 | - if ( wpinv_prices_include_tax() ) { |
|
| 412 | + if (wpinv_prices_include_tax()) { |
|
| 413 | 413 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
| 414 | 414 | } |
| 415 | 415 | |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | */ |
| 424 | 424 | public function get_recurring_subtotal() { |
| 425 | 425 | |
| 426 | - if ( wpinv_prices_include_tax() ) { |
|
| 426 | + if (wpinv_prices_include_tax()) { |
|
| 427 | 427 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
| 428 | 428 | } |
| 429 | 429 | |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | * @return bool |
| 448 | 448 | */ |
| 449 | 449 | public function has_subscription_group() { |
| 450 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
| 450 | + return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this)); |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | /** |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | * @return bool |
| 458 | 458 | */ |
| 459 | 459 | public function has_multiple_subscription_groups() { |
| 460 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
| 460 | + return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this)); |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | /* |
@@ -477,39 +477,39 @@ discard block |
||
| 477 | 477 | public function process_taxes() { |
| 478 | 478 | |
| 479 | 479 | // Abort if we're not using taxes. |
| 480 | - if ( ! $this->use_taxes() ) { |
|
| 480 | + if (!$this->use_taxes()) { |
|
| 481 | 481 | return; |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | // If a custom country && state has been passed in, use it to calculate taxes. |
| 485 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 486 | - if ( ! empty( $country ) ) { |
|
| 485 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
| 486 | + if (!empty($country)) { |
|
| 487 | 487 | $this->country = $country; |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 491 | - if ( ! empty( $state ) ) { |
|
| 490 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
| 491 | + if (!empty($state)) { |
|
| 492 | 492 | $this->state = $state; |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | // Confirm if the provided country and the ip country are similar. |
| 496 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 497 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 498 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 496 | + $address_confirmed = $this->get_field('confirm-address'); |
|
| 497 | + if (isset($_POST['billing']['country']) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) { |
|
| 498 | + throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing')); |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | // Abort if the country is not taxable. |
| 502 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 502 | + if (!wpinv_is_country_taxable($this->country)) { |
|
| 503 | 503 | return; |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 506 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
| 507 | 507 | |
| 508 | - foreach ( $processor->taxes as $tax ) { |
|
| 509 | - $this->add_tax( $tax ); |
|
| 508 | + foreach ($processor->taxes as $tax) { |
|
| 509 | + $this->add_tax($tax); |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 512 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | /** |
@@ -518,16 +518,16 @@ discard block |
||
| 518 | 518 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
| 519 | 519 | * @since 1.0.19 |
| 520 | 520 | */ |
| 521 | - public function add_tax( $tax ) { |
|
| 521 | + public function add_tax($tax) { |
|
| 522 | 522 | |
| 523 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 524 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 525 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 523 | + if (wpinv_round_tax_per_tax_rate()) { |
|
| 524 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
| 525 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | - $this->taxes[ $tax['name'] ] = $tax; |
|
| 529 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 530 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 528 | + $this->taxes[$tax['name']] = $tax; |
|
| 529 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
| 530 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
| 531 | 531 | |
| 532 | 532 | } |
| 533 | 533 | |
@@ -536,12 +536,12 @@ discard block |
||
| 536 | 536 | * |
| 537 | 537 | * @since 1.0.19 |
| 538 | 538 | */ |
| 539 | - public function remove_tax( $tax_name ) { |
|
| 539 | + public function remove_tax($tax_name) { |
|
| 540 | 540 | |
| 541 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 542 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 543 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 544 | - unset( $this->taxes[ $tax_name ] ); |
|
| 541 | + if (isset($this->taxes[$tax_name])) { |
|
| 542 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
| 543 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
| 544 | + unset($this->taxes[$tax_name]); |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | } |
@@ -555,11 +555,11 @@ discard block |
||
| 555 | 555 | |
| 556 | 556 | $use_taxes = wpinv_use_taxes(); |
| 557 | 557 | |
| 558 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 558 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
| 559 | 559 | $use_taxes = false; |
| 560 | 560 | } |
| 561 | 561 | |
| 562 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 562 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
| 563 | 563 | |
| 564 | 564 | } |
| 565 | 565 | |
@@ -608,13 +608,13 @@ discard block |
||
| 608 | 608 | |
| 609 | 609 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
| 610 | 610 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
| 611 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 611 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
| 612 | 612 | |
| 613 | - foreach ( $processor->discounts as $discount ) { |
|
| 614 | - $this->add_discount( $discount ); |
|
| 613 | + foreach ($processor->discounts as $discount) { |
|
| 614 | + $this->add_discount($discount); |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 617 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | /** |
@@ -623,10 +623,10 @@ discard block |
||
| 623 | 623 | * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
| 624 | 624 | * @since 1.0.19 |
| 625 | 625 | */ |
| 626 | - public function add_discount( $discount ) { |
|
| 627 | - $this->discounts[ $discount['name'] ] = $discount; |
|
| 628 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 629 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 626 | + public function add_discount($discount) { |
|
| 627 | + $this->discounts[$discount['name']] = $discount; |
|
| 628 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
| 629 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | /** |
@@ -634,12 +634,12 @@ discard block |
||
| 634 | 634 | * |
| 635 | 635 | * @since 1.0.19 |
| 636 | 636 | */ |
| 637 | - public function remove_discount( $name ) { |
|
| 637 | + public function remove_discount($name) { |
|
| 638 | 638 | |
| 639 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
| 640 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 641 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 642 | - unset( $this->discounts[ $name ] ); |
|
| 639 | + if (isset($this->discounts[$name])) { |
|
| 640 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
| 641 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
| 642 | + unset($this->discounts[$name]); |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | } |
@@ -651,7 +651,7 @@ discard block |
||
| 651 | 651 | * @return bool |
| 652 | 652 | */ |
| 653 | 653 | public function has_discount_code() { |
| 654 | - return ! empty( $this->discounts['discount_code'] ); |
|
| 654 | + return !empty($this->discounts['discount_code']); |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
@@ -708,13 +708,13 @@ discard block |
||
| 708 | 708 | */ |
| 709 | 709 | public function process_fees() { |
| 710 | 710 | |
| 711 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 711 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
| 712 | 712 | |
| 713 | - foreach ( $fees_processor->fees as $fee ) { |
|
| 714 | - $this->add_fee( $fee ); |
|
| 713 | + foreach ($fees_processor->fees as $fee) { |
|
| 714 | + $this->add_fee($fee); |
|
| 715 | 715 | } |
| 716 | 716 | |
| 717 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 717 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | /** |
@@ -723,17 +723,17 @@ discard block |
||
| 723 | 723 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
| 724 | 724 | * @since 1.0.19 |
| 725 | 725 | */ |
| 726 | - public function add_fee( $fee ) { |
|
| 726 | + public function add_fee($fee) { |
|
| 727 | 727 | |
| 728 | - if ( $fee['name'] == 'shipping' ) { |
|
| 729 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 730 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 728 | + if ($fee['name'] == 'shipping') { |
|
| 729 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
| 730 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
| 731 | 731 | return; |
| 732 | 732 | } |
| 733 | 733 | |
| 734 | - $this->fees[ $fee['name'] ] = $fee; |
|
| 735 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 736 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 734 | + $this->fees[$fee['name']] = $fee; |
|
| 735 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
| 736 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
| 737 | 737 | |
| 738 | 738 | } |
| 739 | 739 | |
@@ -742,15 +742,15 @@ discard block |
||
| 742 | 742 | * |
| 743 | 743 | * @since 1.0.19 |
| 744 | 744 | */ |
| 745 | - public function remove_fee( $name ) { |
|
| 745 | + public function remove_fee($name) { |
|
| 746 | 746 | |
| 747 | - if ( isset( $this->fees[ $name ] ) ) { |
|
| 748 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 749 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 750 | - unset( $this->fees[ $name ] ); |
|
| 747 | + if (isset($this->fees[$name])) { |
|
| 748 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
| 749 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
| 750 | + unset($this->fees[$name]); |
|
| 751 | 751 | } |
| 752 | 752 | |
| 753 | - if ( 'shipping' == $name ) { |
|
| 753 | + if ('shipping' == $name) { |
|
| 754 | 754 | $this->totals['shipping']['initial'] = 0; |
| 755 | 755 | $this->totals['shipping']['recurring'] = 0; |
| 756 | 756 | } |
@@ -791,7 +791,7 @@ discard block |
||
| 791 | 791 | * @since 1.0.19 |
| 792 | 792 | */ |
| 793 | 793 | public function has_fees() { |
| 794 | - return count( $this->fees ) !== 0; |
|
| 794 | + return count($this->fees) !== 0; |
|
| 795 | 795 | } |
| 796 | 796 | |
| 797 | 797 | /* |
@@ -827,7 +827,7 @@ discard block |
||
| 827 | 827 | * @since 1.0.19 |
| 828 | 828 | */ |
| 829 | 829 | public function has_shipping() { |
| 830 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
| 830 | + return apply_filters('getpaid_payment_form_has_shipping', false, $this); |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | /** |
@@ -837,7 +837,7 @@ discard block |
||
| 837 | 837 | * @since 1.0.19 |
| 838 | 838 | */ |
| 839 | 839 | public function is_initial_fetch() { |
| 840 | - return empty( $this->data['initial_state'] ); |
|
| 840 | + return empty($this->data['initial_state']); |
|
| 841 | 841 | } |
| 842 | 842 | |
| 843 | 843 | /** |
@@ -847,7 +847,7 @@ discard block |
||
| 847 | 847 | */ |
| 848 | 848 | public function get_total() { |
| 849 | 849 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
| 850 | - return max( $total, 0 ); |
|
| 850 | + return max($total, 0); |
|
| 851 | 851 | } |
| 852 | 852 | |
| 853 | 853 | /** |
@@ -857,7 +857,7 @@ discard block |
||
| 857 | 857 | */ |
| 858 | 858 | public function get_recurring_total() { |
| 859 | 859 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
| 860 | - return max( $total, 0 ); |
|
| 860 | + return max($total, 0); |
|
| 861 | 861 | } |
| 862 | 862 | |
| 863 | 863 | /** |
@@ -869,12 +869,12 @@ discard block |
||
| 869 | 869 | $initial = $this->get_total(); |
| 870 | 870 | $recurring = $this->get_recurring_total(); |
| 871 | 871 | |
| 872 | - if ( $this->has_recurring == 0 ) { |
|
| 872 | + if ($this->has_recurring == 0) { |
|
| 873 | 873 | $recurring = 0; |
| 874 | 874 | } |
| 875 | 875 | |
| 876 | 876 | $collect = $initial > 0 || $recurring > 0; |
| 877 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 877 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | /** |
@@ -883,7 +883,7 @@ discard block |
||
| 883 | 883 | * @since 1.0.19 |
| 884 | 884 | */ |
| 885 | 885 | public function get_billing_email() { |
| 886 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 886 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
| 887 | 887 | } |
| 888 | 888 | |
| 889 | 889 | /** |
@@ -893,7 +893,7 @@ discard block |
||
| 893 | 893 | */ |
| 894 | 894 | public function has_billing_email() { |
| 895 | 895 | $billing_email = $this->get_billing_email(); |
| 896 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 896 | + return !empty($billing_email) && is_email($billing_email); |
|
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | /** |
@@ -923,8 +923,8 @@ discard block |
||
| 923 | 923 | * @since 1.0.19 |
| 924 | 924 | * @return mixed|null |
| 925 | 925 | */ |
| 926 | - public function get_field( $field, $sub_array_key = null ) { |
|
| 927 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 926 | + public function get_field($field, $sub_array_key = null) { |
|
| 927 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
| 928 | 928 | } |
| 929 | 929 | |
| 930 | 930 | /** |
@@ -932,8 +932,8 @@ discard block |
||
| 932 | 932 | * |
| 933 | 933 | * @since 1.0.19 |
| 934 | 934 | */ |
| 935 | - public function is_required_field_set( $field ) { |
|
| 936 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 935 | + public function is_required_field_set($field) { |
|
| 936 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
| 937 | 937 | } |
| 938 | 938 | |
| 939 | 939 | /** |
@@ -941,8 +941,8 @@ discard block |
||
| 941 | 941 | * |
| 942 | 942 | * @since 1.0.19 |
| 943 | 943 | */ |
| 944 | - public function format_amount( $amount ) { |
|
| 945 | - return wpinv_price( $amount, $this->get_currency() ); |
|
| 944 | + public function format_amount($amount) { |
|
| 945 | + return wpinv_price($amount, $this->get_currency()); |
|
| 946 | 946 | } |
| 947 | 947 | |
| 948 | 948 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -10,67 +10,67 @@ discard block |
||
| 10 | 10 | class GetPaid_Form_Item extends WPInv_Item { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Stores a custom description for the item. |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - protected $custom_description = null; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Stores the item quantity. |
|
| 21 | - * |
|
| 22 | - * @var float |
|
| 23 | - */ |
|
| 24 | - protected $quantity = 1; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Stores the item meta. |
|
| 28 | - * |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $meta = array(); |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Is this item required? |
|
| 35 | - * |
|
| 36 | - * @var int |
|
| 37 | - */ |
|
| 38 | - protected $is_required = true; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Are quantities allowed? |
|
| 42 | - * |
|
| 43 | - * @var int |
|
| 44 | - */ |
|
| 45 | - protected $allow_quantities = false; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Associated invoice. |
|
| 49 | - * |
|
| 50 | - * @var int |
|
| 51 | - */ |
|
| 52 | - public $invoice_id = 0; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Item discount. |
|
| 56 | - * |
|
| 57 | - * @var float |
|
| 58 | - */ |
|
| 59 | - public $item_discount = 0; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Recurring item discount. |
|
| 63 | - * |
|
| 64 | - * @var float |
|
| 65 | - */ |
|
| 66 | - public $recurring_item_discount = 0; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Item tax. |
|
| 70 | - * |
|
| 71 | - * @var float |
|
| 72 | - */ |
|
| 73 | - public $item_tax = 0; |
|
| 13 | + * Stores a custom description for the item. |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + protected $custom_description = null; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Stores the item quantity. |
|
| 21 | + * |
|
| 22 | + * @var float |
|
| 23 | + */ |
|
| 24 | + protected $quantity = 1; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Stores the item meta. |
|
| 28 | + * |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $meta = array(); |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Is this item required? |
|
| 35 | + * |
|
| 36 | + * @var int |
|
| 37 | + */ |
|
| 38 | + protected $is_required = true; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Are quantities allowed? |
|
| 42 | + * |
|
| 43 | + * @var int |
|
| 44 | + */ |
|
| 45 | + protected $allow_quantities = false; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Associated invoice. |
|
| 49 | + * |
|
| 50 | + * @var int |
|
| 51 | + */ |
|
| 52 | + public $invoice_id = 0; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Item discount. |
|
| 56 | + * |
|
| 57 | + * @var float |
|
| 58 | + */ |
|
| 59 | + public $item_discount = 0; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Recurring item discount. |
|
| 63 | + * |
|
| 64 | + * @var float |
|
| 65 | + */ |
|
| 66 | + public $recurring_item_discount = 0; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Item tax. |
|
| 70 | + * |
|
| 71 | + * @var float |
|
| 72 | + */ |
|
| 73 | + public $item_tax = 0; |
|
| 74 | 74 | |
| 75 | 75 | /* |
| 76 | 76 | |-------------------------------------------------------------------------- |
@@ -88,230 +88,230 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | |
| 90 | 90 | /** |
| 91 | - * Get the item name. |
|
| 92 | - * |
|
| 93 | - * @since 1.0.19 |
|
| 94 | - * @param string $context View or edit context. |
|
| 95 | - * @return string |
|
| 96 | - */ |
|
| 97 | - public function get_name( $context = 'view' ) { |
|
| 98 | - $name = parent::get_name( $context ); |
|
| 99 | - return $name . wpinv_get_item_suffix( $this ); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Get the item name without a suffix. |
|
| 104 | - * |
|
| 105 | - * @since 1.0.19 |
|
| 106 | - * @param string $context View or edit context. |
|
| 107 | - * @return string |
|
| 108 | - */ |
|
| 109 | - public function get_raw_name( $context = 'view' ) { |
|
| 110 | - return parent::get_name( $context ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Get the item description. |
|
| 115 | - * |
|
| 116 | - * @since 1.0.19 |
|
| 117 | - * @param string $context View or edit context. |
|
| 118 | - * @return string |
|
| 119 | - */ |
|
| 120 | - public function get_description( $context = 'view' ) { |
|
| 121 | - |
|
| 122 | - if ( isset( $this->custom_description ) ) { |
|
| 123 | - return $this->custom_description; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - return parent::get_description( $context ); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Returns the sub total. |
|
| 131 | - * |
|
| 132 | - * @since 1.0.19 |
|
| 133 | - * @param string $context View or edit context. |
|
| 134 | - * @return float |
|
| 135 | - */ |
|
| 136 | - public function get_sub_total( $context = 'view' ) { |
|
| 137 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Returns the recurring sub total. |
|
| 142 | - * |
|
| 143 | - * @since 1.0.19 |
|
| 144 | - * @param string $context View or edit context. |
|
| 145 | - * @return float |
|
| 146 | - */ |
|
| 147 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
| 148 | - |
|
| 149 | - if ( $this->is_recurring() ) { |
|
| 150 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return 0; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * @deprecated |
|
| 158 | - */ |
|
| 159 | - public function get_qantity( $context = 'view' ) { |
|
| 160 | - return $this->get_quantity( $context ); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Get the item quantity. |
|
| 165 | - * |
|
| 166 | - * @since 1.0.19 |
|
| 167 | - * @param string $context View or edit context. |
|
| 168 | - * @return float |
|
| 169 | - */ |
|
| 170 | - public function get_quantity( $context = 'view' ) { |
|
| 171 | - $quantity = (float) $this->quantity; |
|
| 172 | - |
|
| 173 | - if ( 'view' == $context ) { |
|
| 174 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return $quantity; |
|
| 178 | - |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Get the item meta data. |
|
| 183 | - * |
|
| 184 | - * @since 1.0.19 |
|
| 185 | - * @param string $context View or edit context. |
|
| 186 | - * @return meta |
|
| 187 | - */ |
|
| 188 | - public function get_item_meta( $context = 'view' ) { |
|
| 189 | - $meta = $this->meta; |
|
| 190 | - |
|
| 191 | - if ( 'view' == $context ) { |
|
| 192 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - return $meta; |
|
| 196 | - |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Returns whether or not customers can update the item quantity. |
|
| 201 | - * |
|
| 202 | - * @since 1.0.19 |
|
| 203 | - * @param string $context View or edit context. |
|
| 204 | - * @return bool |
|
| 205 | - */ |
|
| 206 | - public function get_allow_quantities( $context = 'view' ) { |
|
| 207 | - $allow_quantities = (bool) $this->allow_quantities; |
|
| 208 | - |
|
| 209 | - if ( 'view' == $context ) { |
|
| 210 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - return $allow_quantities; |
|
| 214 | - |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Returns whether or not the item is required. |
|
| 219 | - * |
|
| 220 | - * @since 1.0.19 |
|
| 221 | - * @param string $context View or edit context. |
|
| 222 | - * @return bool |
|
| 223 | - */ |
|
| 224 | - public function get_is_required( $context = 'view' ) { |
|
| 225 | - $is_required = (bool) $this->is_required; |
|
| 226 | - |
|
| 227 | - if ( 'view' == $context ) { |
|
| 228 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - return $is_required; |
|
| 232 | - |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * Prepares form data for use. |
|
| 237 | - * |
|
| 238 | - * @since 1.0.19 |
|
| 239 | - * @return array |
|
| 240 | - */ |
|
| 241 | - public function prepare_data_for_use( $required = null ) { |
|
| 242 | - |
|
| 243 | - $required = is_null( $required ) ? $this->is_required() : $required; |
|
| 244 | - return array( |
|
| 245 | - 'title' => strip_tags( $this->get_name() ), |
|
| 246 | - 'id' => $this->get_id(), |
|
| 247 | - 'price' => $this->get_price(), |
|
| 248 | - 'recurring' => $this->is_recurring(), |
|
| 249 | - 'description' => $this->get_description(), |
|
| 250 | - 'allow_quantities' => $this->allows_quantities(), |
|
| 251 | - 'required' => $required, |
|
| 252 | - ); |
|
| 253 | - |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * Prepares form data for ajax use. |
|
| 258 | - * |
|
| 259 | - * @since 1.0.19 |
|
| 260 | - * @return array |
|
| 261 | - */ |
|
| 262 | - public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
| 263 | - |
|
| 264 | - $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
| 265 | - |
|
| 266 | - if ( $description ) { |
|
| 267 | - $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
| 271 | - $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
| 272 | - return array( |
|
| 273 | - 'id' => $this->get_id(), |
|
| 274 | - 'texts' => array( |
|
| 275 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 276 | - 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
| 277 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 278 | - 'item-price' => wpinv_price( $price, $currency ), |
|
| 279 | - 'item-total' => wpinv_price( $subtotal, $currency ), |
|
| 280 | - ), |
|
| 281 | - 'inputs' => array( |
|
| 282 | - 'item-id' => $this->get_id(), |
|
| 283 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 284 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
| 285 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 286 | - 'item-price' => $price, |
|
| 287 | - ), |
|
| 288 | - ); |
|
| 289 | - |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Prepares form data for saving (cart_details). |
|
| 294 | - * |
|
| 295 | - * @since 1.0.19 |
|
| 296 | - * @return array |
|
| 297 | - */ |
|
| 298 | - public function prepare_data_for_saving() { |
|
| 299 | - |
|
| 300 | - return array( |
|
| 301 | - 'post_id' => $this->invoice_id, |
|
| 302 | - 'item_id' => $this->get_id(), |
|
| 303 | - 'item_name' => sanitize_text_field( $this->get_raw_name( 'edit' ) ), |
|
| 304 | - 'item_description' => $this->get_description( 'edit' ), |
|
| 305 | - 'tax' => $this->item_tax, |
|
| 306 | - 'item_price' => $this->get_price( 'edit' ), |
|
| 307 | - 'quantity' => (float) $this->get_quantity( 'edit' ), |
|
| 308 | - 'discount' => $this->item_discount, |
|
| 309 | - 'subtotal' => $this->get_sub_total( 'edit' ), |
|
| 310 | - 'price' => $this->get_sub_total( 'edit' ) + $this->item_tax - $this->item_discount, |
|
| 311 | - 'meta' => $this->get_item_meta( 'edit' ), |
|
| 312 | - ); |
|
| 313 | - |
|
| 314 | - } |
|
| 91 | + * Get the item name. |
|
| 92 | + * |
|
| 93 | + * @since 1.0.19 |
|
| 94 | + * @param string $context View or edit context. |
|
| 95 | + * @return string |
|
| 96 | + */ |
|
| 97 | + public function get_name( $context = 'view' ) { |
|
| 98 | + $name = parent::get_name( $context ); |
|
| 99 | + return $name . wpinv_get_item_suffix( $this ); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Get the item name without a suffix. |
|
| 104 | + * |
|
| 105 | + * @since 1.0.19 |
|
| 106 | + * @param string $context View or edit context. |
|
| 107 | + * @return string |
|
| 108 | + */ |
|
| 109 | + public function get_raw_name( $context = 'view' ) { |
|
| 110 | + return parent::get_name( $context ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Get the item description. |
|
| 115 | + * |
|
| 116 | + * @since 1.0.19 |
|
| 117 | + * @param string $context View or edit context. |
|
| 118 | + * @return string |
|
| 119 | + */ |
|
| 120 | + public function get_description( $context = 'view' ) { |
|
| 121 | + |
|
| 122 | + if ( isset( $this->custom_description ) ) { |
|
| 123 | + return $this->custom_description; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + return parent::get_description( $context ); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Returns the sub total. |
|
| 131 | + * |
|
| 132 | + * @since 1.0.19 |
|
| 133 | + * @param string $context View or edit context. |
|
| 134 | + * @return float |
|
| 135 | + */ |
|
| 136 | + public function get_sub_total( $context = 'view' ) { |
|
| 137 | + return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Returns the recurring sub total. |
|
| 142 | + * |
|
| 143 | + * @since 1.0.19 |
|
| 144 | + * @param string $context View or edit context. |
|
| 145 | + * @return float |
|
| 146 | + */ |
|
| 147 | + public function get_recurring_sub_total( $context = 'view' ) { |
|
| 148 | + |
|
| 149 | + if ( $this->is_recurring() ) { |
|
| 150 | + return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return 0; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * @deprecated |
|
| 158 | + */ |
|
| 159 | + public function get_qantity( $context = 'view' ) { |
|
| 160 | + return $this->get_quantity( $context ); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Get the item quantity. |
|
| 165 | + * |
|
| 166 | + * @since 1.0.19 |
|
| 167 | + * @param string $context View or edit context. |
|
| 168 | + * @return float |
|
| 169 | + */ |
|
| 170 | + public function get_quantity( $context = 'view' ) { |
|
| 171 | + $quantity = (float) $this->quantity; |
|
| 172 | + |
|
| 173 | + if ( 'view' == $context ) { |
|
| 174 | + return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return $quantity; |
|
| 178 | + |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Get the item meta data. |
|
| 183 | + * |
|
| 184 | + * @since 1.0.19 |
|
| 185 | + * @param string $context View or edit context. |
|
| 186 | + * @return meta |
|
| 187 | + */ |
|
| 188 | + public function get_item_meta( $context = 'view' ) { |
|
| 189 | + $meta = $this->meta; |
|
| 190 | + |
|
| 191 | + if ( 'view' == $context ) { |
|
| 192 | + return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + return $meta; |
|
| 196 | + |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Returns whether or not customers can update the item quantity. |
|
| 201 | + * |
|
| 202 | + * @since 1.0.19 |
|
| 203 | + * @param string $context View or edit context. |
|
| 204 | + * @return bool |
|
| 205 | + */ |
|
| 206 | + public function get_allow_quantities( $context = 'view' ) { |
|
| 207 | + $allow_quantities = (bool) $this->allow_quantities; |
|
| 208 | + |
|
| 209 | + if ( 'view' == $context ) { |
|
| 210 | + return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + return $allow_quantities; |
|
| 214 | + |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Returns whether or not the item is required. |
|
| 219 | + * |
|
| 220 | + * @since 1.0.19 |
|
| 221 | + * @param string $context View or edit context. |
|
| 222 | + * @return bool |
|
| 223 | + */ |
|
| 224 | + public function get_is_required( $context = 'view' ) { |
|
| 225 | + $is_required = (bool) $this->is_required; |
|
| 226 | + |
|
| 227 | + if ( 'view' == $context ) { |
|
| 228 | + return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + return $is_required; |
|
| 232 | + |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * Prepares form data for use. |
|
| 237 | + * |
|
| 238 | + * @since 1.0.19 |
|
| 239 | + * @return array |
|
| 240 | + */ |
|
| 241 | + public function prepare_data_for_use( $required = null ) { |
|
| 242 | + |
|
| 243 | + $required = is_null( $required ) ? $this->is_required() : $required; |
|
| 244 | + return array( |
|
| 245 | + 'title' => strip_tags( $this->get_name() ), |
|
| 246 | + 'id' => $this->get_id(), |
|
| 247 | + 'price' => $this->get_price(), |
|
| 248 | + 'recurring' => $this->is_recurring(), |
|
| 249 | + 'description' => $this->get_description(), |
|
| 250 | + 'allow_quantities' => $this->allows_quantities(), |
|
| 251 | + 'required' => $required, |
|
| 252 | + ); |
|
| 253 | + |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * Prepares form data for ajax use. |
|
| 258 | + * |
|
| 259 | + * @since 1.0.19 |
|
| 260 | + * @return array |
|
| 261 | + */ |
|
| 262 | + public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
| 263 | + |
|
| 264 | + $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
| 265 | + |
|
| 266 | + if ( $description ) { |
|
| 267 | + $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
| 271 | + $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
| 272 | + return array( |
|
| 273 | + 'id' => $this->get_id(), |
|
| 274 | + 'texts' => array( |
|
| 275 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 276 | + 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
| 277 | + 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 278 | + 'item-price' => wpinv_price( $price, $currency ), |
|
| 279 | + 'item-total' => wpinv_price( $subtotal, $currency ), |
|
| 280 | + ), |
|
| 281 | + 'inputs' => array( |
|
| 282 | + 'item-id' => $this->get_id(), |
|
| 283 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 284 | + 'item-description' => wp_kses_post( $this->get_description() ), |
|
| 285 | + 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 286 | + 'item-price' => $price, |
|
| 287 | + ), |
|
| 288 | + ); |
|
| 289 | + |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Prepares form data for saving (cart_details). |
|
| 294 | + * |
|
| 295 | + * @since 1.0.19 |
|
| 296 | + * @return array |
|
| 297 | + */ |
|
| 298 | + public function prepare_data_for_saving() { |
|
| 299 | + |
|
| 300 | + return array( |
|
| 301 | + 'post_id' => $this->invoice_id, |
|
| 302 | + 'item_id' => $this->get_id(), |
|
| 303 | + 'item_name' => sanitize_text_field( $this->get_raw_name( 'edit' ) ), |
|
| 304 | + 'item_description' => $this->get_description( 'edit' ), |
|
| 305 | + 'tax' => $this->item_tax, |
|
| 306 | + 'item_price' => $this->get_price( 'edit' ), |
|
| 307 | + 'quantity' => (float) $this->get_quantity( 'edit' ), |
|
| 308 | + 'discount' => $this->item_discount, |
|
| 309 | + 'subtotal' => $this->get_sub_total( 'edit' ), |
|
| 310 | + 'price' => $this->get_sub_total( 'edit' ) + $this->item_tax - $this->item_discount, |
|
| 311 | + 'meta' => $this->get_item_meta( 'edit' ), |
|
| 312 | + ); |
|
| 313 | + |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | 316 | /* |
| 317 | 317 | |-------------------------------------------------------------------------- |
@@ -323,70 +323,70 @@ discard block |
||
| 323 | 323 | | object. |
| 324 | 324 | */ |
| 325 | 325 | |
| 326 | - /** |
|
| 327 | - * Set the item qantity. |
|
| 328 | - * |
|
| 329 | - * @since 1.0.19 |
|
| 330 | - * @param float $quantity The item quantity. |
|
| 331 | - */ |
|
| 332 | - public function set_quantity( $quantity ) { |
|
| 333 | - |
|
| 334 | - if ( ! is_numeric( $quantity ) ) { |
|
| 335 | - $quantity = 1; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - $this->quantity = (float) $quantity; |
|
| 339 | - |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * Set the item meta data. |
|
| 344 | - * |
|
| 345 | - * @since 1.0.19 |
|
| 346 | - * @param array $meta The item meta data. |
|
| 347 | - */ |
|
| 348 | - public function set_item_meta( $meta ) { |
|
| 349 | - $this->meta = maybe_unserialize( $meta ); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Set whether or not the quantities are allowed. |
|
| 354 | - * |
|
| 355 | - * @since 1.0.19 |
|
| 356 | - * @param bool $allow_quantities |
|
| 357 | - */ |
|
| 358 | - public function set_allow_quantities( $allow_quantities ) { |
|
| 359 | - $this->allow_quantities = (bool) $allow_quantities; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * Set whether or not the item is required. |
|
| 364 | - * |
|
| 365 | - * @since 1.0.19 |
|
| 366 | - * @param bool $is_required |
|
| 367 | - */ |
|
| 368 | - public function set_is_required( $is_required ) { |
|
| 369 | - $this->is_required = (bool) $is_required; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Sets the custom item description. |
|
| 374 | - * |
|
| 375 | - * @since 1.0.19 |
|
| 376 | - * @param string $description |
|
| 377 | - */ |
|
| 378 | - public function set_custom_description( $description ) { |
|
| 379 | - $this->custom_description = $description; |
|
| 380 | - } |
|
| 326 | + /** |
|
| 327 | + * Set the item qantity. |
|
| 328 | + * |
|
| 329 | + * @since 1.0.19 |
|
| 330 | + * @param float $quantity The item quantity. |
|
| 331 | + */ |
|
| 332 | + public function set_quantity( $quantity ) { |
|
| 333 | + |
|
| 334 | + if ( ! is_numeric( $quantity ) ) { |
|
| 335 | + $quantity = 1; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + $this->quantity = (float) $quantity; |
|
| 339 | + |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * Set the item meta data. |
|
| 344 | + * |
|
| 345 | + * @since 1.0.19 |
|
| 346 | + * @param array $meta The item meta data. |
|
| 347 | + */ |
|
| 348 | + public function set_item_meta( $meta ) { |
|
| 349 | + $this->meta = maybe_unserialize( $meta ); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Set whether or not the quantities are allowed. |
|
| 354 | + * |
|
| 355 | + * @since 1.0.19 |
|
| 356 | + * @param bool $allow_quantities |
|
| 357 | + */ |
|
| 358 | + public function set_allow_quantities( $allow_quantities ) { |
|
| 359 | + $this->allow_quantities = (bool) $allow_quantities; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * Set whether or not the item is required. |
|
| 364 | + * |
|
| 365 | + * @since 1.0.19 |
|
| 366 | + * @param bool $is_required |
|
| 367 | + */ |
|
| 368 | + public function set_is_required( $is_required ) { |
|
| 369 | + $this->is_required = (bool) $is_required; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Sets the custom item description. |
|
| 374 | + * |
|
| 375 | + * @since 1.0.19 |
|
| 376 | + * @param string $description |
|
| 377 | + */ |
|
| 378 | + public function set_custom_description( $description ) { |
|
| 379 | + $this->custom_description = $description; |
|
| 380 | + } |
|
| 381 | 381 | |
| 382 | 382 | /** |
| 383 | 383 | * We do not want to save items to the database. |
| 384 | 384 | * |
| 385 | - * @return int item id |
|
| 385 | + * @return int item id |
|
| 386 | 386 | */ |
| 387 | 387 | public function save( $data = array() ) { |
| 388 | 388 | return $this->get_id(); |
| 389 | - } |
|
| 389 | + } |
|
| 390 | 390 | |
| 391 | 391 | /* |
| 392 | 392 | |-------------------------------------------------------------------------- |
@@ -398,23 +398,23 @@ discard block |
||
| 398 | 398 | */ |
| 399 | 399 | |
| 400 | 400 | /** |
| 401 | - * Checks whether the item has enabled dynamic pricing. |
|
| 402 | - * |
|
| 403 | - * @since 1.0.19 |
|
| 404 | - * @return bool |
|
| 405 | - */ |
|
| 406 | - public function is_required() { |
|
| 401 | + * Checks whether the item has enabled dynamic pricing. |
|
| 402 | + * |
|
| 403 | + * @since 1.0.19 |
|
| 404 | + * @return bool |
|
| 405 | + */ |
|
| 406 | + public function is_required() { |
|
| 407 | 407 | return (bool) $this->get_is_required(); |
| 408 | - } |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Checks whether users can edit the quantities. |
|
| 412 | - * |
|
| 413 | - * @since 1.0.19 |
|
| 414 | - * @return bool |
|
| 415 | - */ |
|
| 416 | - public function allows_quantities() { |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Checks whether users can edit the quantities. |
|
| 412 | + * |
|
| 413 | + * @since 1.0.19 |
|
| 414 | + * @return bool |
|
| 415 | + */ |
|
| 416 | + public function allows_quantities() { |
|
| 417 | 417 | return (bool) $this->get_allow_quantities(); |
| 418 | - } |
|
| 418 | + } |
|
| 419 | 419 | |
| 420 | 420 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | * @param string $context View or edit context. |
| 95 | 95 | * @return string |
| 96 | 96 | */ |
| 97 | - public function get_name( $context = 'view' ) { |
|
| 98 | - $name = parent::get_name( $context ); |
|
| 99 | - return $name . wpinv_get_item_suffix( $this ); |
|
| 97 | + public function get_name($context = 'view') { |
|
| 98 | + $name = parent::get_name($context); |
|
| 99 | + return $name . wpinv_get_item_suffix($this); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -106,8 +106,8 @@ discard block |
||
| 106 | 106 | * @param string $context View or edit context. |
| 107 | 107 | * @return string |
| 108 | 108 | */ |
| 109 | - public function get_raw_name( $context = 'view' ) { |
|
| 110 | - return parent::get_name( $context ); |
|
| 109 | + public function get_raw_name($context = 'view') { |
|
| 110 | + return parent::get_name($context); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -117,13 +117,13 @@ discard block |
||
| 117 | 117 | * @param string $context View or edit context. |
| 118 | 118 | * @return string |
| 119 | 119 | */ |
| 120 | - public function get_description( $context = 'view' ) { |
|
| 120 | + public function get_description($context = 'view') { |
|
| 121 | 121 | |
| 122 | - if ( isset( $this->custom_description ) ) { |
|
| 122 | + if (isset($this->custom_description)) { |
|
| 123 | 123 | return $this->custom_description; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - return parent::get_description( $context ); |
|
| 126 | + return parent::get_description($context); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -133,8 +133,8 @@ discard block |
||
| 133 | 133 | * @param string $context View or edit context. |
| 134 | 134 | * @return float |
| 135 | 135 | */ |
| 136 | - public function get_sub_total( $context = 'view' ) { |
|
| 137 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
| 136 | + public function get_sub_total($context = 'view') { |
|
| 137 | + return $this->get_quantity($context) * $this->get_initial_price($context); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -144,10 +144,10 @@ discard block |
||
| 144 | 144 | * @param string $context View or edit context. |
| 145 | 145 | * @return float |
| 146 | 146 | */ |
| 147 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
| 147 | + public function get_recurring_sub_total($context = 'view') { |
|
| 148 | 148 | |
| 149 | - if ( $this->is_recurring() ) { |
|
| 150 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
| 149 | + if ($this->is_recurring()) { |
|
| 150 | + return $this->get_quantity($context) * $this->get_price($context); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | return 0; |
@@ -156,8 +156,8 @@ discard block |
||
| 156 | 156 | /** |
| 157 | 157 | * @deprecated |
| 158 | 158 | */ |
| 159 | - public function get_qantity( $context = 'view' ) { |
|
| 160 | - return $this->get_quantity( $context ); |
|
| 159 | + public function get_qantity($context = 'view') { |
|
| 160 | + return $this->get_quantity($context); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -167,11 +167,11 @@ discard block |
||
| 167 | 167 | * @param string $context View or edit context. |
| 168 | 168 | * @return float |
| 169 | 169 | */ |
| 170 | - public function get_quantity( $context = 'view' ) { |
|
| 170 | + public function get_quantity($context = 'view') { |
|
| 171 | 171 | $quantity = (float) $this->quantity; |
| 172 | 172 | |
| 173 | - if ( 'view' == $context ) { |
|
| 174 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
| 173 | + if ('view' == $context) { |
|
| 174 | + return apply_filters('getpaid_payment_form_item_quantity', $quantity, $this); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | return $quantity; |
@@ -185,11 +185,11 @@ discard block |
||
| 185 | 185 | * @param string $context View or edit context. |
| 186 | 186 | * @return meta |
| 187 | 187 | */ |
| 188 | - public function get_item_meta( $context = 'view' ) { |
|
| 188 | + public function get_item_meta($context = 'view') { |
|
| 189 | 189 | $meta = $this->meta; |
| 190 | 190 | |
| 191 | - if ( 'view' == $context ) { |
|
| 192 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
| 191 | + if ('view' == $context) { |
|
| 192 | + return apply_filters('getpaid_payment_form_item_meta', $meta, $this); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | return $meta; |
@@ -203,11 +203,11 @@ discard block |
||
| 203 | 203 | * @param string $context View or edit context. |
| 204 | 204 | * @return bool |
| 205 | 205 | */ |
| 206 | - public function get_allow_quantities( $context = 'view' ) { |
|
| 206 | + public function get_allow_quantities($context = 'view') { |
|
| 207 | 207 | $allow_quantities = (bool) $this->allow_quantities; |
| 208 | 208 | |
| 209 | - if ( 'view' == $context ) { |
|
| 210 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
| 209 | + if ('view' == $context) { |
|
| 210 | + return apply_filters('getpaid_payment_form_item_allow_quantities', $allow_quantities, $this); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | return $allow_quantities; |
@@ -221,11 +221,11 @@ discard block |
||
| 221 | 221 | * @param string $context View or edit context. |
| 222 | 222 | * @return bool |
| 223 | 223 | */ |
| 224 | - public function get_is_required( $context = 'view' ) { |
|
| 224 | + public function get_is_required($context = 'view') { |
|
| 225 | 225 | $is_required = (bool) $this->is_required; |
| 226 | 226 | |
| 227 | - if ( 'view' == $context ) { |
|
| 228 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
| 227 | + if ('view' == $context) { |
|
| 228 | + return apply_filters('getpaid_payment_form_item_is_required', $is_required, $this); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | return $is_required; |
@@ -238,11 +238,11 @@ discard block |
||
| 238 | 238 | * @since 1.0.19 |
| 239 | 239 | * @return array |
| 240 | 240 | */ |
| 241 | - public function prepare_data_for_use( $required = null ) { |
|
| 241 | + public function prepare_data_for_use($required = null) { |
|
| 242 | 242 | |
| 243 | - $required = is_null( $required ) ? $this->is_required() : $required; |
|
| 243 | + $required = is_null($required) ? $this->is_required() : $required; |
|
| 244 | 244 | return array( |
| 245 | - 'title' => strip_tags( $this->get_name() ), |
|
| 245 | + 'title' => strip_tags($this->get_name()), |
|
| 246 | 246 | 'id' => $this->get_id(), |
| 247 | 247 | 'price' => $this->get_price(), |
| 248 | 248 | 'recurring' => $this->is_recurring(), |
@@ -259,30 +259,30 @@ discard block |
||
| 259 | 259 | * @since 1.0.19 |
| 260 | 260 | * @return array |
| 261 | 261 | */ |
| 262 | - public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
| 262 | + public function prepare_data_for_invoice_edit_ajax($currency = '', $is_renewal = false) { |
|
| 263 | 263 | |
| 264 | - $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
| 264 | + $description = getpaid_item_recurring_price_help_text($this, $currency); |
|
| 265 | 265 | |
| 266 | - if ( $description ) { |
|
| 266 | + if ($description) { |
|
| 267 | 267 | $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
| 271 | - $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
| 270 | + $price = !$is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
| 271 | + $subtotal = !$is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
| 272 | 272 | return array( |
| 273 | 273 | 'id' => $this->get_id(), |
| 274 | 274 | 'texts' => array( |
| 275 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 276 | - 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
| 277 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 278 | - 'item-price' => wpinv_price( $price, $currency ), |
|
| 279 | - 'item-total' => wpinv_price( $subtotal, $currency ), |
|
| 275 | + 'item-name' => sanitize_text_field($this->get_name()), |
|
| 276 | + 'item-description' => wp_kses_post($this->get_description()) . $description, |
|
| 277 | + 'item-quantity' => floatval($this->get_quantity()), |
|
| 278 | + 'item-price' => wpinv_price($price, $currency), |
|
| 279 | + 'item-total' => wpinv_price($subtotal, $currency), |
|
| 280 | 280 | ), |
| 281 | 281 | 'inputs' => array( |
| 282 | 282 | 'item-id' => $this->get_id(), |
| 283 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 284 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
| 285 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 283 | + 'item-name' => sanitize_text_field($this->get_name()), |
|
| 284 | + 'item-description' => wp_kses_post($this->get_description()), |
|
| 285 | + 'item-quantity' => floatval($this->get_quantity()), |
|
| 286 | 286 | 'item-price' => $price, |
| 287 | 287 | ), |
| 288 | 288 | ); |
@@ -300,15 +300,15 @@ discard block |
||
| 300 | 300 | return array( |
| 301 | 301 | 'post_id' => $this->invoice_id, |
| 302 | 302 | 'item_id' => $this->get_id(), |
| 303 | - 'item_name' => sanitize_text_field( $this->get_raw_name( 'edit' ) ), |
|
| 304 | - 'item_description' => $this->get_description( 'edit' ), |
|
| 303 | + 'item_name' => sanitize_text_field($this->get_raw_name('edit')), |
|
| 304 | + 'item_description' => $this->get_description('edit'), |
|
| 305 | 305 | 'tax' => $this->item_tax, |
| 306 | - 'item_price' => $this->get_price( 'edit' ), |
|
| 307 | - 'quantity' => (float) $this->get_quantity( 'edit' ), |
|
| 306 | + 'item_price' => $this->get_price('edit'), |
|
| 307 | + 'quantity' => (float) $this->get_quantity('edit'), |
|
| 308 | 308 | 'discount' => $this->item_discount, |
| 309 | - 'subtotal' => $this->get_sub_total( 'edit' ), |
|
| 310 | - 'price' => $this->get_sub_total( 'edit' ) + $this->item_tax - $this->item_discount, |
|
| 311 | - 'meta' => $this->get_item_meta( 'edit' ), |
|
| 309 | + 'subtotal' => $this->get_sub_total('edit'), |
|
| 310 | + 'price' => $this->get_sub_total('edit') + $this->item_tax - $this->item_discount, |
|
| 311 | + 'meta' => $this->get_item_meta('edit'), |
|
| 312 | 312 | ); |
| 313 | 313 | |
| 314 | 314 | } |
@@ -329,9 +329,9 @@ discard block |
||
| 329 | 329 | * @since 1.0.19 |
| 330 | 330 | * @param float $quantity The item quantity. |
| 331 | 331 | */ |
| 332 | - public function set_quantity( $quantity ) { |
|
| 332 | + public function set_quantity($quantity) { |
|
| 333 | 333 | |
| 334 | - if ( ! is_numeric( $quantity ) ) { |
|
| 334 | + if (!is_numeric($quantity)) { |
|
| 335 | 335 | $quantity = 1; |
| 336 | 336 | } |
| 337 | 337 | |
@@ -345,8 +345,8 @@ discard block |
||
| 345 | 345 | * @since 1.0.19 |
| 346 | 346 | * @param array $meta The item meta data. |
| 347 | 347 | */ |
| 348 | - public function set_item_meta( $meta ) { |
|
| 349 | - $this->meta = maybe_unserialize( $meta ); |
|
| 348 | + public function set_item_meta($meta) { |
|
| 349 | + $this->meta = maybe_unserialize($meta); |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | /** |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | * @since 1.0.19 |
| 356 | 356 | * @param bool $allow_quantities |
| 357 | 357 | */ |
| 358 | - public function set_allow_quantities( $allow_quantities ) { |
|
| 358 | + public function set_allow_quantities($allow_quantities) { |
|
| 359 | 359 | $this->allow_quantities = (bool) $allow_quantities; |
| 360 | 360 | } |
| 361 | 361 | |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | * @since 1.0.19 |
| 366 | 366 | * @param bool $is_required |
| 367 | 367 | */ |
| 368 | - public function set_is_required( $is_required ) { |
|
| 368 | + public function set_is_required($is_required) { |
|
| 369 | 369 | $this->is_required = (bool) $is_required; |
| 370 | 370 | } |
| 371 | 371 | |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | * @since 1.0.19 |
| 376 | 376 | * @param string $description |
| 377 | 377 | */ |
| 378 | - public function set_custom_description( $description ) { |
|
| 378 | + public function set_custom_description($description) { |
|
| 379 | 379 | $this->custom_description = $description; |
| 380 | 380 | } |
| 381 | 381 | |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | * |
| 385 | 385 | * @return int item id |
| 386 | 386 | */ |
| 387 | - public function save( $data = array() ) { |
|
| 387 | + public function save($data = array()) { |
|
| 388 | 388 | return $this->get_id(); |
| 389 | 389 | } |
| 390 | 390 | |
@@ -12,167 +12,167 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Discount { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Submission discounts. |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $discounts = array(); |
|
| 15 | + /** |
|
| 16 | + * Submission discounts. |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $discounts = array(); |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Class constructor |
|
| 23 | + * |
|
| 24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | + * @param float $initial_total |
|
| 26 | + * @param float $recurring_total |
|
| 27 | + */ |
|
| 28 | + public function __construct( $submission, $initial_total, $recurring_total ) { |
|
| 29 | + |
|
| 30 | + // Process any existing invoice discounts. |
|
| 31 | + if ( $submission->has_invoice() ) { |
|
| 32 | + $this->discounts = $submission->get_invoice()->get_discounts(); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + // Do we have a discount? |
|
| 36 | + $discount = $submission->get_field( 'discount' ); |
|
| 37 | + |
|
| 38 | + if ( empty( $discount ) ) { |
|
| 39 | + |
|
| 40 | + if ( isset( $this->discounts['discount_code'] ) ) { |
|
| 41 | + unset( $this->discounts['discount_code'] ); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + return; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + // Processes the discount code. |
|
| 48 | + $amount = max( $initial_total, $recurring_total ); |
|
| 49 | + $this->process_discount( $submission, $discount, $amount ); |
|
| 50 | + |
|
| 51 | + } |
|
| 20 | 52 | |
| 21 | 53 | /** |
| 22 | - * Class constructor |
|
| 23 | - * |
|
| 24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | - * @param float $initial_total |
|
| 26 | - * @param float $recurring_total |
|
| 27 | - */ |
|
| 28 | - public function __construct( $submission, $initial_total, $recurring_total ) { |
|
| 29 | - |
|
| 30 | - // Process any existing invoice discounts. |
|
| 31 | - if ( $submission->has_invoice() ) { |
|
| 32 | - $this->discounts = $submission->get_invoice()->get_discounts(); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - // Do we have a discount? |
|
| 36 | - $discount = $submission->get_field( 'discount' ); |
|
| 37 | - |
|
| 38 | - if ( empty( $discount ) ) { |
|
| 39 | - |
|
| 40 | - if ( isset( $this->discounts['discount_code'] ) ) { |
|
| 41 | - unset( $this->discounts['discount_code'] ); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - return; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - // Processes the discount code. |
|
| 48 | - $amount = max( $initial_total, $recurring_total ); |
|
| 49 | - $this->process_discount( $submission, $discount, $amount ); |
|
| 50 | - |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Processes a submission discount. |
|
| 55 | - * |
|
| 56 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 57 | - * @param string $discount |
|
| 58 | - * @param float $amount |
|
| 59 | - */ |
|
| 60 | - public function process_discount( $submission, $discount, $amount ) { |
|
| 61 | - |
|
| 62 | - // Fetch the discount. |
|
| 63 | - $discount = new WPInv_Discount( $discount ); |
|
| 64 | - |
|
| 65 | - // Ensure it is active. |
|
| 54 | + * Processes a submission discount. |
|
| 55 | + * |
|
| 56 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 57 | + * @param string $discount |
|
| 58 | + * @param float $amount |
|
| 59 | + */ |
|
| 60 | + public function process_discount( $submission, $discount, $amount ) { |
|
| 61 | + |
|
| 62 | + // Fetch the discount. |
|
| 63 | + $discount = new WPInv_Discount( $discount ); |
|
| 64 | + |
|
| 65 | + // Ensure it is active. |
|
| 66 | 66 | if ( ! $this->is_discount_active( $discount ) ) { |
| 67 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'Invalid or expired discount code', 'invoicing' ) ); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - // Required items. |
|
| 71 | - if ( ! $discount->is_required_items_met( array_keys( $submission->get_items() ) ) ) { |
|
| 72 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You are not allowed to use this discount code.', 'invoicing' ) ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - // Exceeded limit. |
|
| 76 | - if ( $discount->has_exceeded_limit() ) { |
|
| 77 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'This discount code has been used up', 'invoicing' ) ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // Validate usages. |
|
| 81 | - $this->validate_single_use_discount( $submission, $discount ); |
|
| 82 | - |
|
| 83 | - // Validate amount. |
|
| 84 | - $this->validate_discount_amount( $submission, $discount, $amount ); |
|
| 85 | - |
|
| 86 | - // Save the discount. |
|
| 87 | - $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount ); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Validates a single use discount. |
|
| 92 | - * |
|
| 93 | - * @param WPInv_Discount $discount |
|
| 94 | - * @return bool |
|
| 95 | - */ |
|
| 96 | - public function is_discount_active( $discount ) { |
|
| 97 | - return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired(); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Returns a user's id or email. |
|
| 102 | - * |
|
| 103 | - * @param string $email |
|
| 104 | - * @return int|string|false |
|
| 105 | - */ |
|
| 106 | - public function get_user_id_or_email( $email ) { |
|
| 107 | - |
|
| 108 | - if ( is_user_logged_in() ) { |
|
| 109 | - return get_current_user_id(); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return empty( $email ) ? false : sanitize_email( $email ); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Validates a single use discount. |
|
| 117 | - * |
|
| 118 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 119 | - * @param WPInv_Discount $discount |
|
| 120 | - */ |
|
| 121 | - public function validate_single_use_discount( $submission, $discount ) { |
|
| 122 | - |
|
| 123 | - // Abort if it is not a single use discount. |
|
| 124 | - if ( ! $discount->is_single_use() ) { |
|
| 125 | - return; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - // Ensure there is a valid billing email. |
|
| 129 | - $user = $this->get_user_id_or_email( $submission->get_billing_email() ); |
|
| 130 | - |
|
| 131 | - if ( empty( $user ) ) { |
|
| 132 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) ); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // Has the user used this discount code before? |
|
| 136 | - if ( ! $discount->is_valid_for_user( $user ) ) { |
|
| 137 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You have already used this discount', 'invoicing' ) ); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Validates the discount's amount. |
|
| 144 | - * |
|
| 145 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 146 | - * @param WPInv_Discount $discount |
|
| 147 | - * @param float $amount |
|
| 148 | - */ |
|
| 149 | - public function validate_discount_amount( $submission, $discount, $amount ) { |
|
| 150 | - |
|
| 151 | - // Validate minimum amount. |
|
| 152 | - if ( ! $discount->is_minimum_amount_met( $amount ) ) { |
|
| 153 | - $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() ); |
|
| 154 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) ); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // Validate the maximum amount. |
|
| 158 | - if ( ! $discount->is_maximum_amount_met( $amount ) ) { |
|
| 159 | - $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() ); |
|
| 160 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) ); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Calculates the discount code's amount. |
|
| 167 | - * |
|
| 168 | - * Ensure that the discount exists and has been validated before calling this method. |
|
| 169 | - * |
|
| 170 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 171 | - * @param WPInv_Discount $discount |
|
| 172 | - * @return array |
|
| 173 | - */ |
|
| 174 | - public function calculate_discount( $submission, $discount ) { |
|
| 175 | - return getpaid_calculate_invoice_discount( $submission, $discount ); |
|
| 176 | - } |
|
| 67 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'Invalid or expired discount code', 'invoicing' ) ); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + // Required items. |
|
| 71 | + if ( ! $discount->is_required_items_met( array_keys( $submission->get_items() ) ) ) { |
|
| 72 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You are not allowed to use this discount code.', 'invoicing' ) ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + // Exceeded limit. |
|
| 76 | + if ( $discount->has_exceeded_limit() ) { |
|
| 77 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'This discount code has been used up', 'invoicing' ) ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // Validate usages. |
|
| 81 | + $this->validate_single_use_discount( $submission, $discount ); |
|
| 82 | + |
|
| 83 | + // Validate amount. |
|
| 84 | + $this->validate_discount_amount( $submission, $discount, $amount ); |
|
| 85 | + |
|
| 86 | + // Save the discount. |
|
| 87 | + $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount ); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Validates a single use discount. |
|
| 92 | + * |
|
| 93 | + * @param WPInv_Discount $discount |
|
| 94 | + * @return bool |
|
| 95 | + */ |
|
| 96 | + public function is_discount_active( $discount ) { |
|
| 97 | + return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired(); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Returns a user's id or email. |
|
| 102 | + * |
|
| 103 | + * @param string $email |
|
| 104 | + * @return int|string|false |
|
| 105 | + */ |
|
| 106 | + public function get_user_id_or_email( $email ) { |
|
| 107 | + |
|
| 108 | + if ( is_user_logged_in() ) { |
|
| 109 | + return get_current_user_id(); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + return empty( $email ) ? false : sanitize_email( $email ); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Validates a single use discount. |
|
| 117 | + * |
|
| 118 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 119 | + * @param WPInv_Discount $discount |
|
| 120 | + */ |
|
| 121 | + public function validate_single_use_discount( $submission, $discount ) { |
|
| 122 | + |
|
| 123 | + // Abort if it is not a single use discount. |
|
| 124 | + if ( ! $discount->is_single_use() ) { |
|
| 125 | + return; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + // Ensure there is a valid billing email. |
|
| 129 | + $user = $this->get_user_id_or_email( $submission->get_billing_email() ); |
|
| 130 | + |
|
| 131 | + if ( empty( $user ) ) { |
|
| 132 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) ); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // Has the user used this discount code before? |
|
| 136 | + if ( ! $discount->is_valid_for_user( $user ) ) { |
|
| 137 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You have already used this discount', 'invoicing' ) ); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Validates the discount's amount. |
|
| 144 | + * |
|
| 145 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 146 | + * @param WPInv_Discount $discount |
|
| 147 | + * @param float $amount |
|
| 148 | + */ |
|
| 149 | + public function validate_discount_amount( $submission, $discount, $amount ) { |
|
| 150 | + |
|
| 151 | + // Validate minimum amount. |
|
| 152 | + if ( ! $discount->is_minimum_amount_met( $amount ) ) { |
|
| 153 | + $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() ); |
|
| 154 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) ); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // Validate the maximum amount. |
|
| 158 | + if ( ! $discount->is_maximum_amount_met( $amount ) ) { |
|
| 159 | + $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() ); |
|
| 160 | + throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) ); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Calculates the discount code's amount. |
|
| 167 | + * |
|
| 168 | + * Ensure that the discount exists and has been validated before calling this method. |
|
| 169 | + * |
|
| 170 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 171 | + * @param WPInv_Discount $discount |
|
| 172 | + * @return array |
|
| 173 | + */ |
|
| 174 | + public function calculate_discount( $submission, $discount ) { |
|
| 175 | + return getpaid_calculate_invoice_discount( $submission, $discount ); |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | 178 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Payment form submission discount class |
@@ -25,28 +25,28 @@ discard block |
||
| 25 | 25 | * @param float $initial_total |
| 26 | 26 | * @param float $recurring_total |
| 27 | 27 | */ |
| 28 | - public function __construct( $submission, $initial_total, $recurring_total ) { |
|
| 28 | + public function __construct($submission, $initial_total, $recurring_total) { |
|
| 29 | 29 | |
| 30 | 30 | // Process any existing invoice discounts. |
| 31 | - if ( $submission->has_invoice() ) { |
|
| 31 | + if ($submission->has_invoice()) { |
|
| 32 | 32 | $this->discounts = $submission->get_invoice()->get_discounts(); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | // Do we have a discount? |
| 36 | - $discount = $submission->get_field( 'discount' ); |
|
| 36 | + $discount = $submission->get_field('discount'); |
|
| 37 | 37 | |
| 38 | - if ( empty( $discount ) ) { |
|
| 38 | + if (empty($discount)) { |
|
| 39 | 39 | |
| 40 | - if ( isset( $this->discounts['discount_code'] ) ) { |
|
| 41 | - unset( $this->discounts['discount_code'] ); |
|
| 40 | + if (isset($this->discounts['discount_code'])) { |
|
| 41 | + unset($this->discounts['discount_code']); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | return; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | // Processes the discount code. |
| 48 | - $amount = max( $initial_total, $recurring_total ); |
|
| 49 | - $this->process_discount( $submission, $discount, $amount ); |
|
| 48 | + $amount = max($initial_total, $recurring_total); |
|
| 49 | + $this->process_discount($submission, $discount, $amount); |
|
| 50 | 50 | |
| 51 | 51 | } |
| 52 | 52 | |
@@ -57,34 +57,34 @@ discard block |
||
| 57 | 57 | * @param string $discount |
| 58 | 58 | * @param float $amount |
| 59 | 59 | */ |
| 60 | - public function process_discount( $submission, $discount, $amount ) { |
|
| 60 | + public function process_discount($submission, $discount, $amount) { |
|
| 61 | 61 | |
| 62 | 62 | // Fetch the discount. |
| 63 | - $discount = new WPInv_Discount( $discount ); |
|
| 63 | + $discount = new WPInv_Discount($discount); |
|
| 64 | 64 | |
| 65 | 65 | // Ensure it is active. |
| 66 | - if ( ! $this->is_discount_active( $discount ) ) { |
|
| 67 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'Invalid or expired discount code', 'invoicing' ) ); |
|
| 66 | + if (!$this->is_discount_active($discount)) { |
|
| 67 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', __('Invalid or expired discount code', 'invoicing')); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | // Required items. |
| 71 | - if ( ! $discount->is_required_items_met( array_keys( $submission->get_items() ) ) ) { |
|
| 72 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You are not allowed to use this discount code.', 'invoicing' ) ); |
|
| 71 | + if (!$discount->is_required_items_met(array_keys($submission->get_items()))) { |
|
| 72 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', __('You are not allowed to use this discount code.', 'invoicing')); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | // Exceeded limit. |
| 76 | - if ( $discount->has_exceeded_limit() ) { |
|
| 77 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'This discount code has been used up', 'invoicing' ) ); |
|
| 76 | + if ($discount->has_exceeded_limit()) { |
|
| 77 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', __('This discount code has been used up', 'invoicing')); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // Validate usages. |
| 81 | - $this->validate_single_use_discount( $submission, $discount ); |
|
| 81 | + $this->validate_single_use_discount($submission, $discount); |
|
| 82 | 82 | |
| 83 | 83 | // Validate amount. |
| 84 | - $this->validate_discount_amount( $submission, $discount, $amount ); |
|
| 84 | + $this->validate_discount_amount($submission, $discount, $amount); |
|
| 85 | 85 | |
| 86 | 86 | // Save the discount. |
| 87 | - $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount ); |
|
| 87 | + $this->discounts['discount_code'] = $this->calculate_discount($submission, $discount); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -93,8 +93,8 @@ discard block |
||
| 93 | 93 | * @param WPInv_Discount $discount |
| 94 | 94 | * @return bool |
| 95 | 95 | */ |
| 96 | - public function is_discount_active( $discount ) { |
|
| 97 | - return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired(); |
|
| 96 | + public function is_discount_active($discount) { |
|
| 97 | + return $discount->exists() && $discount->is_active() && $discount->has_started() && !$discount->is_expired(); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -103,13 +103,13 @@ discard block |
||
| 103 | 103 | * @param string $email |
| 104 | 104 | * @return int|string|false |
| 105 | 105 | */ |
| 106 | - public function get_user_id_or_email( $email ) { |
|
| 106 | + public function get_user_id_or_email($email) { |
|
| 107 | 107 | |
| 108 | - if ( is_user_logged_in() ) { |
|
| 108 | + if (is_user_logged_in()) { |
|
| 109 | 109 | return get_current_user_id(); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - return empty( $email ) ? false : sanitize_email( $email ); |
|
| 112 | + return empty($email) ? false : sanitize_email($email); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -118,23 +118,23 @@ discard block |
||
| 118 | 118 | * @param GetPaid_Payment_Form_Submission $submission |
| 119 | 119 | * @param WPInv_Discount $discount |
| 120 | 120 | */ |
| 121 | - public function validate_single_use_discount( $submission, $discount ) { |
|
| 121 | + public function validate_single_use_discount($submission, $discount) { |
|
| 122 | 122 | |
| 123 | 123 | // Abort if it is not a single use discount. |
| 124 | - if ( ! $discount->is_single_use() ) { |
|
| 124 | + if (!$discount->is_single_use()) { |
|
| 125 | 125 | return; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // Ensure there is a valid billing email. |
| 129 | - $user = $this->get_user_id_or_email( $submission->get_billing_email() ); |
|
| 129 | + $user = $this->get_user_id_or_email($submission->get_billing_email()); |
|
| 130 | 130 | |
| 131 | - if ( empty( $user ) ) { |
|
| 132 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) ); |
|
| 131 | + if (empty($user)) { |
|
| 132 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', __('You need to either log in or enter your billing email before applying this discount', 'invoicing')); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | // Has the user used this discount code before? |
| 136 | - if ( ! $discount->is_valid_for_user( $user ) ) { |
|
| 137 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You have already used this discount', 'invoicing' ) ); |
|
| 136 | + if (!$discount->is_valid_for_user($user)) { |
|
| 137 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', __('You have already used this discount', 'invoicing')); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | } |
@@ -146,18 +146,18 @@ discard block |
||
| 146 | 146 | * @param WPInv_Discount $discount |
| 147 | 147 | * @param float $amount |
| 148 | 148 | */ |
| 149 | - public function validate_discount_amount( $submission, $discount, $amount ) { |
|
| 149 | + public function validate_discount_amount($submission, $discount, $amount) { |
|
| 150 | 150 | |
| 151 | 151 | // Validate minimum amount. |
| 152 | - if ( ! $discount->is_minimum_amount_met( $amount ) ) { |
|
| 153 | - $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() ); |
|
| 154 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) ); |
|
| 152 | + if (!$discount->is_minimum_amount_met($amount)) { |
|
| 153 | + $min = wpinv_price($discount->get_minimum_total(), $submission->get_currency()); |
|
| 154 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf(__('The minimum total for using this discount is %s', 'invoicing'), $min)); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | // Validate the maximum amount. |
| 158 | - if ( ! $discount->is_maximum_amount_met( $amount ) ) { |
|
| 159 | - $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() ); |
|
| 160 | - throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) ); |
|
| 158 | + if (!$discount->is_maximum_amount_met($amount)) { |
|
| 159 | + $max = wpinv_price($discount->get_maximum_total(), $submission->get_currency()); |
|
| 160 | + throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', sprintf(__('The maximum total for using this discount is %s', 'invoicing'), $max)); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | } |
@@ -171,8 +171,8 @@ discard block |
||
| 171 | 171 | * @param WPInv_Discount $discount |
| 172 | 172 | * @return array |
| 173 | 173 | */ |
| 174 | - public function calculate_discount( $submission, $discount ) { |
|
| 175 | - return getpaid_calculate_invoice_discount( $submission, $discount ); |
|
| 174 | + public function calculate_discount($submission, $discount) { |
|
| 175 | + return getpaid_calculate_invoice_discount($submission, $discount); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | } |
@@ -12,113 +12,113 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Fees { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * The fee validation error. |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - public $fee_error; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Submission fees. |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - public $fees = array(); |
|
| 15 | + /** |
|
| 16 | + * The fee validation error. |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + public $fee_error; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Submission fees. |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + public $fees = array(); |
|
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | - * Class constructor |
|
| 29 | - * |
|
| 30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | - */ |
|
| 32 | - public function __construct( $submission ) { |
|
| 33 | - |
|
| 34 | - // Process any existing invoice fees. |
|
| 35 | - if ( $submission->has_invoice() ) { |
|
| 36 | - $this->fees = $submission->get_invoice()->get_fees(); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // Process price fields. |
|
| 40 | - $data = $submission->get_data(); |
|
| 41 | - $payment_form = $submission->get_payment_form(); |
|
| 42 | - |
|
| 43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
| 44 | - |
|
| 45 | - if ( 'price_input' == $element['type'] ) { |
|
| 46 | - $this->process_price_input( $element, $data, $submission ); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - if ( 'price_select' == $element['type'] ) { |
|
| 50 | - $this->process_price_select( $element, $data ); |
|
| 51 | - } |
|
| 28 | + * Class constructor |
|
| 29 | + * |
|
| 30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | + */ |
|
| 32 | + public function __construct( $submission ) { |
|
| 33 | + |
|
| 34 | + // Process any existing invoice fees. |
|
| 35 | + if ( $submission->has_invoice() ) { |
|
| 36 | + $this->fees = $submission->get_invoice()->get_fees(); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // Process price fields. |
|
| 40 | + $data = $submission->get_data(); |
|
| 41 | + $payment_form = $submission->get_payment_form(); |
|
| 42 | + |
|
| 43 | + foreach ( $payment_form->get_elements() as $element ) { |
|
| 44 | + |
|
| 45 | + if ( 'price_input' == $element['type'] ) { |
|
| 46 | + $this->process_price_input( $element, $data, $submission ); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + if ( 'price_select' == $element['type'] ) { |
|
| 50 | + $this->process_price_select( $element, $data ); |
|
| 51 | + } |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Process a price input field. |
|
| 58 | - * |
|
| 59 | - * @param array $element |
|
| 60 | - * @param array $data |
|
| 61 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 62 | - */ |
|
| 63 | - public function process_price_input( $element, $data, $submission ) { |
|
| 64 | - |
|
| 65 | - // Abort if not passed. |
|
| 66 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
| 67 | - return; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
| 71 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
| 72 | - |
|
| 73 | - if ( $amount < $minimum ) { |
|
| 74 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) ); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $this->fees[ $element['label'] ] = array( |
|
| 78 | - 'name' => $element['label'], |
|
| 79 | - 'initial_fee' => $amount, |
|
| 80 | - 'recurring_fee' => 0, |
|
| 81 | - ); |
|
| 82 | - |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Process a price select field. |
|
| 87 | - * |
|
| 88 | - * @param array $element |
|
| 89 | - * @param array $data |
|
| 90 | - */ |
|
| 91 | - public function process_price_select( $element, $data ) { |
|
| 92 | - |
|
| 93 | - // Abort if not passed. |
|
| 94 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
| 95 | - return; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
| 99 | - $selected = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) ); |
|
| 100 | - $total = 0; |
|
| 101 | - $sub_labels = array(); |
|
| 102 | - |
|
| 103 | - foreach ( $selected as $price ) { |
|
| 104 | - |
|
| 105 | - if ( ! isset( $options[ $price ] ) ) { |
|
| 106 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - $price = explode( '|', $price ); |
|
| 110 | - |
|
| 111 | - $sub_labels[] = $price[0]; |
|
| 112 | - $total += (float) wpinv_sanitize_amount( $price[1] ); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $this->fees[ $element['label'] ] = array( |
|
| 116 | - 'name' => $element['label'], |
|
| 117 | - 'initial_fee' => $total, |
|
| 118 | - 'recurring_fee' => 0, |
|
| 119 | - 'description' => implode( ', ', $sub_labels ), |
|
| 120 | - ); |
|
| 121 | - |
|
| 122 | - } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Process a price input field. |
|
| 58 | + * |
|
| 59 | + * @param array $element |
|
| 60 | + * @param array $data |
|
| 61 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 62 | + */ |
|
| 63 | + public function process_price_input( $element, $data, $submission ) { |
|
| 64 | + |
|
| 65 | + // Abort if not passed. |
|
| 66 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
| 67 | + return; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
| 71 | + $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
| 72 | + |
|
| 73 | + if ( $amount < $minimum ) { |
|
| 74 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) ); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $this->fees[ $element['label'] ] = array( |
|
| 78 | + 'name' => $element['label'], |
|
| 79 | + 'initial_fee' => $amount, |
|
| 80 | + 'recurring_fee' => 0, |
|
| 81 | + ); |
|
| 82 | + |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Process a price select field. |
|
| 87 | + * |
|
| 88 | + * @param array $element |
|
| 89 | + * @param array $data |
|
| 90 | + */ |
|
| 91 | + public function process_price_select( $element, $data ) { |
|
| 92 | + |
|
| 93 | + // Abort if not passed. |
|
| 94 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
| 95 | + return; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
| 99 | + $selected = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) ); |
|
| 100 | + $total = 0; |
|
| 101 | + $sub_labels = array(); |
|
| 102 | + |
|
| 103 | + foreach ( $selected as $price ) { |
|
| 104 | + |
|
| 105 | + if ( ! isset( $options[ $price ] ) ) { |
|
| 106 | + throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + $price = explode( '|', $price ); |
|
| 110 | + |
|
| 111 | + $sub_labels[] = $price[0]; |
|
| 112 | + $total += (float) wpinv_sanitize_amount( $price[1] ); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $this->fees[ $element['label'] ] = array( |
|
| 116 | + 'name' => $element['label'], |
|
| 117 | + 'initial_fee' => $total, |
|
| 118 | + 'recurring_fee' => 0, |
|
| 119 | + 'description' => implode( ', ', $sub_labels ), |
|
| 120 | + ); |
|
| 121 | + |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | 124 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Payment form submission fees class |
@@ -29,10 +29,10 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | * @param GetPaid_Payment_Form_Submission $submission |
| 31 | 31 | */ |
| 32 | - public function __construct( $submission ) { |
|
| 32 | + public function __construct($submission) { |
|
| 33 | 33 | |
| 34 | 34 | // Process any existing invoice fees. |
| 35 | - if ( $submission->has_invoice() ) { |
|
| 35 | + if ($submission->has_invoice()) { |
|
| 36 | 36 | $this->fees = $submission->get_invoice()->get_fees(); |
| 37 | 37 | } |
| 38 | 38 | |
@@ -40,14 +40,14 @@ discard block |
||
| 40 | 40 | $data = $submission->get_data(); |
| 41 | 41 | $payment_form = $submission->get_payment_form(); |
| 42 | 42 | |
| 43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
| 43 | + foreach ($payment_form->get_elements() as $element) { |
|
| 44 | 44 | |
| 45 | - if ( 'price_input' == $element['type'] ) { |
|
| 46 | - $this->process_price_input( $element, $data, $submission ); |
|
| 45 | + if ('price_input' == $element['type']) { |
|
| 46 | + $this->process_price_input($element, $data, $submission); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - if ( 'price_select' == $element['type'] ) { |
|
| 50 | - $this->process_price_select( $element, $data ); |
|
| 49 | + if ('price_select' == $element['type']) { |
|
| 50 | + $this->process_price_select($element, $data); |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
@@ -60,21 +60,21 @@ discard block |
||
| 60 | 60 | * @param array $data |
| 61 | 61 | * @param GetPaid_Payment_Form_Submission $submission |
| 62 | 62 | */ |
| 63 | - public function process_price_input( $element, $data, $submission ) { |
|
| 63 | + public function process_price_input($element, $data, $submission) { |
|
| 64 | 64 | |
| 65 | 65 | // Abort if not passed. |
| 66 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
| 66 | + if (empty($data[$element['id']])) { |
|
| 67 | 67 | return; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
| 71 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
| 70 | + $amount = (float) wpinv_sanitize_amount($data[$element['id']]); |
|
| 71 | + $minimum = empty($element['minimum']) ? 0 : (float) wpinv_sanitize_amount($element['minimum']); |
|
| 72 | 72 | |
| 73 | - if ( $amount < $minimum ) { |
|
| 74 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) ); |
|
| 73 | + if ($amount < $minimum) { |
|
| 74 | + throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), getpaid_unstandardize_amount($minimum, $submission->get_currency()))); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - $this->fees[ $element['label'] ] = array( |
|
| 77 | + $this->fees[$element['label']] = array( |
|
| 78 | 78 | 'name' => $element['label'], |
| 79 | 79 | 'initial_fee' => $amount, |
| 80 | 80 | 'recurring_fee' => 0, |
@@ -88,35 +88,35 @@ discard block |
||
| 88 | 88 | * @param array $element |
| 89 | 89 | * @param array $data |
| 90 | 90 | */ |
| 91 | - public function process_price_select( $element, $data ) { |
|
| 91 | + public function process_price_select($element, $data) { |
|
| 92 | 92 | |
| 93 | 93 | // Abort if not passed. |
| 94 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
| 94 | + if (empty($data[$element['id']])) { |
|
| 95 | 95 | return; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
| 99 | - $selected = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) ); |
|
| 98 | + $options = getpaid_convert_price_string_to_options($element['options']); |
|
| 99 | + $selected = array_filter(array_map('trim', explode(',', $data[$element['id']]))); |
|
| 100 | 100 | $total = 0; |
| 101 | 101 | $sub_labels = array(); |
| 102 | 102 | |
| 103 | - foreach ( $selected as $price ) { |
|
| 103 | + foreach ($selected as $price) { |
|
| 104 | 104 | |
| 105 | - if ( ! isset( $options[ $price ] ) ) { |
|
| 106 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
| 105 | + if (!isset($options[$price])) { |
|
| 106 | + throw new Exception(__('You have selected an invalid amount', 'invoicing')); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - $price = explode( '|', $price ); |
|
| 109 | + $price = explode('|', $price); |
|
| 110 | 110 | |
| 111 | 111 | $sub_labels[] = $price[0]; |
| 112 | - $total += (float) wpinv_sanitize_amount( $price[1] ); |
|
| 112 | + $total += (float) wpinv_sanitize_amount($price[1]); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - $this->fees[ $element['label'] ] = array( |
|
| 115 | + $this->fees[$element['label']] = array( |
|
| 116 | 116 | 'name' => $element['label'], |
| 117 | 117 | 'initial_fee' => $total, |
| 118 | 118 | 'recurring_fee' => 0, |
| 119 | - 'description' => implode( ', ', $sub_labels ), |
|
| 119 | + 'description' => implode(', ', $sub_labels), |
|
| 120 | 120 | ); |
| 121 | 121 | |
| 122 | 122 | } |
@@ -12,290 +12,290 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Refresh_Prices { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Contains the response for refreshing prices. |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $response = array(); |
|
| 15 | + /** |
|
| 16 | + * Contains the response for refreshing prices. |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $response = array(); |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | - * Class constructor |
|
| 23 | - * |
|
| 24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | - */ |
|
| 26 | - public function __construct( $submission ) { |
|
| 27 | - |
|
| 28 | - $this->response = array( |
|
| 29 | - 'submission_id' => $submission->id, |
|
| 22 | + * Class constructor |
|
| 23 | + * |
|
| 24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | + */ |
|
| 26 | + public function __construct( $submission ) { |
|
| 27 | + |
|
| 28 | + $this->response = array( |
|
| 29 | + 'submission_id' => $submission->id, |
|
| 30 | 30 | 'has_recurring' => $submission->has_recurring, |
| 31 | - 'has_subscription_group' => $submission->has_subscription_group(), |
|
| 32 | - 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
|
| 31 | + 'has_subscription_group' => $submission->has_subscription_group(), |
|
| 32 | + 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
|
| 33 | 33 | 'is_free' => ! $submission->should_collect_payment_details(), |
| 34 | - ); |
|
| 35 | - |
|
| 36 | - $this->add_totals( $submission ); |
|
| 37 | - $this->add_texts( $submission ); |
|
| 38 | - $this->add_items( $submission ); |
|
| 39 | - $this->add_fees( $submission ); |
|
| 40 | - $this->add_discounts( $submission ); |
|
| 41 | - $this->add_taxes( $submission ); |
|
| 42 | - $this->add_gateways( $submission ); |
|
| 43 | - $this->add_data( $submission ); |
|
| 44 | - |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Adds totals to a response for submission refresh prices. |
|
| 49 | - * |
|
| 50 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 51 | - */ |
|
| 52 | - public function add_totals( $submission ) { |
|
| 53 | - |
|
| 54 | - $this->response = array_merge( |
|
| 55 | - $this->response, |
|
| 56 | - array( |
|
| 57 | - |
|
| 58 | - 'totals' => array( |
|
| 59 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 60 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 61 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 62 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 63 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 64 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 65 | - ), |
|
| 66 | - |
|
| 67 | - 'recurring' => array( |
|
| 68 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 69 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 70 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 71 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 72 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 73 | - ), |
|
| 74 | - |
|
| 75 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 76 | - 'currency' => $submission->get_currency(), |
|
| 77 | - |
|
| 78 | - ) |
|
| 79 | - ); |
|
| 80 | - |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Adds texts to a response for submission refresh prices. |
|
| 85 | - * |
|
| 86 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 87 | - */ |
|
| 88 | - public function add_texts( $submission ) { |
|
| 89 | - |
|
| 90 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
| 91 | - $groups = getpaid_get_subscription_groups( $submission ); |
|
| 92 | - |
|
| 93 | - if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
| 94 | - |
|
| 95 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 96 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 97 | - $main_item = reset( $groups ); |
|
| 98 | - |
|
| 99 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 100 | - $payable = "$payable / $period"; |
|
| 101 | - } elseif ( $main_item ) { |
|
| 102 | - |
|
| 103 | - $main_item = reset( $main_item ); |
|
| 104 | - |
|
| 105 | - // Calculate the next renewal date. |
|
| 106 | - $_period = $main_item->get_recurring_period( true ); |
|
| 107 | - $_interval = $main_item->get_recurring_interval(); |
|
| 108 | - |
|
| 109 | - // If the subscription item has a trial period... |
|
| 110 | - if ( $main_item->has_free_trial() ) { |
|
| 111 | - $_period = $main_item->get_trial_period( true ); |
|
| 112 | - $_interval = $main_item->get_trial_interval(); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $payable = sprintf( |
|
| 116 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 117 | - $submission->format_amount( $submission->get_total() ), |
|
| 118 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
| 119 | - $period |
|
| 120 | - ); |
|
| 121 | - |
|
| 122 | - $payable .= sprintf( |
|
| 123 | - '<small class="text-muted form-text">%s</small>', |
|
| 124 | - sprintf( |
|
| 125 | - __( 'First renewal on %s', 'invoicing' ), |
|
| 126 | - getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) ) |
|
| 127 | - ) |
|
| 128 | - ); |
|
| 129 | - |
|
| 130 | - } else { |
|
| 131 | - $payable = sprintf( |
|
| 132 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 133 | - $submission->format_amount( $submission->get_total() ), |
|
| 134 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
| 135 | - $period |
|
| 136 | - ); |
|
| 137 | - } |
|
| 138 | -} |
|
| 34 | + ); |
|
| 139 | 35 | |
| 140 | - $texts = array( |
|
| 141 | - '.getpaid-checkout-total-payable' => $payable, |
|
| 142 | - ); |
|
| 36 | + $this->add_totals( $submission ); |
|
| 37 | + $this->add_texts( $submission ); |
|
| 38 | + $this->add_items( $submission ); |
|
| 39 | + $this->add_fees( $submission ); |
|
| 40 | + $this->add_discounts( $submission ); |
|
| 41 | + $this->add_taxes( $submission ); |
|
| 42 | + $this->add_gateways( $submission ); |
|
| 43 | + $this->add_data( $submission ); |
|
| 143 | 44 | |
| 144 | - foreach ( $submission->get_items() as $item ) { |
|
| 145 | - $item_id = $item->get_id(); |
|
| 146 | - $initial_price = $submission->format_amount( $item->get_sub_total() - $item->item_discount ); |
|
| 147 | - $recurring_price = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount ); |
|
| 148 | - $texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 149 | - $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) ); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Adds totals to a response for submission refresh prices. |
|
| 49 | + * |
|
| 50 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 51 | + */ |
|
| 52 | + public function add_totals( $submission ) { |
|
| 53 | + |
|
| 54 | + $this->response = array_merge( |
|
| 55 | + $this->response, |
|
| 56 | + array( |
|
| 57 | + |
|
| 58 | + 'totals' => array( |
|
| 59 | + 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 60 | + 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 61 | + 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 62 | + 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 63 | + 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 64 | + 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 65 | + ), |
|
| 66 | + |
|
| 67 | + 'recurring' => array( |
|
| 68 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 69 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 70 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 71 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 72 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 73 | + ), |
|
| 74 | + |
|
| 75 | + 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 76 | + 'currency' => $submission->get_currency(), |
|
| 77 | + |
|
| 78 | + ) |
|
| 79 | + ); |
|
| 80 | + |
|
| 81 | + } |
|
| 150 | 82 | |
| 151 | - if ( $item->get_quantity() == 1 ) { |
|
| 152 | - $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = ''; |
|
| 153 | - } |
|
| 83 | + /** |
|
| 84 | + * Adds texts to a response for submission refresh prices. |
|
| 85 | + * |
|
| 86 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 87 | + */ |
|
| 88 | + public function add_texts( $submission ) { |
|
| 89 | + |
|
| 90 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
| 91 | + $groups = getpaid_get_subscription_groups( $submission ); |
|
| 92 | + |
|
| 93 | + if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
| 94 | + |
|
| 95 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 96 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 97 | + $main_item = reset( $groups ); |
|
| 98 | + |
|
| 99 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 100 | + $payable = "$payable / $period"; |
|
| 101 | + } elseif ( $main_item ) { |
|
| 102 | + |
|
| 103 | + $main_item = reset( $main_item ); |
|
| 104 | + |
|
| 105 | + // Calculate the next renewal date. |
|
| 106 | + $_period = $main_item->get_recurring_period( true ); |
|
| 107 | + $_interval = $main_item->get_recurring_interval(); |
|
| 108 | + |
|
| 109 | + // If the subscription item has a trial period... |
|
| 110 | + if ( $main_item->has_free_trial() ) { |
|
| 111 | + $_period = $main_item->get_trial_period( true ); |
|
| 112 | + $_interval = $main_item->get_trial_interval(); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $payable = sprintf( |
|
| 116 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 117 | + $submission->format_amount( $submission->get_total() ), |
|
| 118 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
| 119 | + $period |
|
| 120 | + ); |
|
| 121 | + |
|
| 122 | + $payable .= sprintf( |
|
| 123 | + '<small class="text-muted form-text">%s</small>', |
|
| 124 | + sprintf( |
|
| 125 | + __( 'First renewal on %s', 'invoicing' ), |
|
| 126 | + getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) ) |
|
| 127 | + ) |
|
| 128 | + ); |
|
| 129 | + |
|
| 130 | + } else { |
|
| 131 | + $payable = sprintf( |
|
| 132 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 133 | + $submission->format_amount( $submission->get_total() ), |
|
| 134 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
| 135 | + $period |
|
| 136 | + ); |
|
| 137 | + } |
|
| 154 | 138 | } |
| 155 | 139 | |
| 156 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 140 | + $texts = array( |
|
| 141 | + '.getpaid-checkout-total-payable' => $payable, |
|
| 142 | + ); |
|
| 157 | 143 | |
| 158 | - } |
|
| 144 | + foreach ( $submission->get_items() as $item ) { |
|
| 145 | + $item_id = $item->get_id(); |
|
| 146 | + $initial_price = $submission->format_amount( $item->get_sub_total() - $item->item_discount ); |
|
| 147 | + $recurring_price = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount ); |
|
| 148 | + $texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 149 | + $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) ); |
|
| 150 | + |
|
| 151 | + if ( $item->get_quantity() == 1 ) { |
|
| 152 | + $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = ''; |
|
| 153 | + } |
|
| 154 | +} |
|
| 159 | 155 | |
| 160 | - /** |
|
| 161 | - * Adds items to a response for submission refresh prices. |
|
| 162 | - * |
|
| 163 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 164 | - */ |
|
| 165 | - public function add_items( $submission ) { |
|
| 156 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 166 | 157 | |
| 167 | - // Add items. |
|
| 168 | - $items = array(); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Adds items to a response for submission refresh prices. |
|
| 162 | + * |
|
| 163 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 164 | + */ |
|
| 165 | + public function add_items( $submission ) { |
|
| 166 | + |
|
| 167 | + // Add items. |
|
| 168 | + $items = array(); |
|
| 169 | 169 | |
| 170 | 170 | foreach ( $submission->get_items() as $item ) { |
| 171 | - $item_id = $item->get_id(); |
|
| 172 | - $items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() ); |
|
| 173 | - } |
|
| 171 | + $item_id = $item->get_id(); |
|
| 172 | + $items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() ); |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - $this->response = array_merge( |
|
| 176 | - $this->response, |
|
| 177 | - array( 'items' => $items ) |
|
| 178 | - ); |
|
| 175 | + $this->response = array_merge( |
|
| 176 | + $this->response, |
|
| 177 | + array( 'items' => $items ) |
|
| 178 | + ); |
|
| 179 | 179 | |
| 180 | - } |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * Adds fees to a response for submission refresh prices. |
|
| 184 | - * |
|
| 185 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 186 | - */ |
|
| 187 | - public function add_fees( $submission ) { |
|
| 182 | + /** |
|
| 183 | + * Adds fees to a response for submission refresh prices. |
|
| 184 | + * |
|
| 185 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 186 | + */ |
|
| 187 | + public function add_fees( $submission ) { |
|
| 188 | 188 | |
| 189 | - $fees = array(); |
|
| 189 | + $fees = array(); |
|
| 190 | 190 | |
| 191 | 191 | foreach ( $submission->get_fees() as $name => $data ) { |
| 192 | - $fees[ $name ] = $submission->format_amount( $data['initial_fee'] ); |
|
| 193 | - } |
|
| 192 | + $fees[ $name ] = $submission->format_amount( $data['initial_fee'] ); |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - $this->response = array_merge( |
|
| 196 | - $this->response, |
|
| 197 | - array( 'fees' => $fees ) |
|
| 198 | - ); |
|
| 195 | + $this->response = array_merge( |
|
| 196 | + $this->response, |
|
| 197 | + array( 'fees' => $fees ) |
|
| 198 | + ); |
|
| 199 | 199 | |
| 200 | - } |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * Adds discounts to a response for submission refresh prices. |
|
| 204 | - * |
|
| 205 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 206 | - */ |
|
| 207 | - public function add_discounts( $submission ) { |
|
| 202 | + /** |
|
| 203 | + * Adds discounts to a response for submission refresh prices. |
|
| 204 | + * |
|
| 205 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 206 | + */ |
|
| 207 | + public function add_discounts( $submission ) { |
|
| 208 | 208 | |
| 209 | - $discounts = array(); |
|
| 209 | + $discounts = array(); |
|
| 210 | 210 | |
| 211 | 211 | foreach ( $submission->get_discounts() as $name => $data ) { |
| 212 | - $discounts[ $name ] = $submission->format_amount( $data['initial_discount'] ); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - $this->response = array_merge( |
|
| 216 | - $this->response, |
|
| 217 | - array( 'discounts' => $discounts ) |
|
| 218 | - ); |
|
| 212 | + $discounts[ $name ] = $submission->format_amount( $data['initial_discount'] ); |
|
| 213 | + } |
|
| 219 | 214 | |
| 220 | - } |
|
| 215 | + $this->response = array_merge( |
|
| 216 | + $this->response, |
|
| 217 | + array( 'discounts' => $discounts ) |
|
| 218 | + ); |
|
| 221 | 219 | |
| 222 | - /** |
|
| 223 | - * Adds taxes to a response for submission refresh prices. |
|
| 224 | - * |
|
| 225 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 226 | - */ |
|
| 227 | - public function add_taxes( $submission ) { |
|
| 220 | + } |
|
| 228 | 221 | |
| 229 | - $taxes = array(); |
|
| 230 | - $markup = ''; |
|
| 222 | + /** |
|
| 223 | + * Adds taxes to a response for submission refresh prices. |
|
| 224 | + * |
|
| 225 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 226 | + */ |
|
| 227 | + public function add_taxes( $submission ) { |
|
| 228 | + |
|
| 229 | + $taxes = array(); |
|
| 230 | + $markup = ''; |
|
| 231 | 231 | foreach ( $submission->get_taxes() as $name => $data ) { |
| 232 | - $name = sanitize_text_field( $name ); |
|
| 233 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 234 | - $taxes[ $name ] = $amount; |
|
| 235 | - $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
| 239 | - $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - $this->response = array_merge( |
|
| 243 | - $this->response, |
|
| 244 | - array( 'taxes' => $taxes ) |
|
| 245 | - ); |
|
| 246 | - |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Adds gateways to a response for submission refresh prices. |
|
| 251 | - * |
|
| 252 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 253 | - */ |
|
| 254 | - public function add_gateways( $submission ) { |
|
| 255 | - |
|
| 256 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 257 | - |
|
| 258 | - if ( $this->response['has_recurring'] ) { |
|
| 259 | - |
|
| 260 | - foreach ( $gateways as $i => $gateway ) { |
|
| 261 | - |
|
| 262 | - if ( |
|
| 263 | - ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
| 264 | - || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
| 265 | - || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
| 266 | - unset( $gateways[ $i ] ); |
|
| 267 | - } |
|
| 232 | + $name = sanitize_text_field( $name ); |
|
| 233 | + $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 234 | + $taxes[ $name ] = $amount; |
|
| 235 | + $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
| 239 | + $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + $this->response = array_merge( |
|
| 243 | + $this->response, |
|
| 244 | + array( 'taxes' => $taxes ) |
|
| 245 | + ); |
|
| 246 | + |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Adds gateways to a response for submission refresh prices. |
|
| 251 | + * |
|
| 252 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 253 | + */ |
|
| 254 | + public function add_gateways( $submission ) { |
|
| 255 | + |
|
| 256 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 257 | + |
|
| 258 | + if ( $this->response['has_recurring'] ) { |
|
| 259 | + |
|
| 260 | + foreach ( $gateways as $i => $gateway ) { |
|
| 261 | + |
|
| 262 | + if ( |
|
| 263 | + ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
| 264 | + || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
| 265 | + || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
| 266 | + unset( $gateways[ $i ] ); |
|
| 267 | + } |
|
| 268 | 268 | } |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 272 | - $this->response = array_merge( |
|
| 273 | - $this->response, |
|
| 274 | - array( 'gateways' => $gateways ) |
|
| 275 | - ); |
|
| 276 | - |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Adds data to a response for submission refresh prices. |
|
| 281 | - * |
|
| 282 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 283 | - */ |
|
| 284 | - public function add_data( $submission ) { |
|
| 285 | - |
|
| 286 | - $this->response = array_merge( |
|
| 287 | - $this->response, |
|
| 288 | - array( |
|
| 289 | - 'js_data' => apply_filters( |
|
| 290 | - 'getpaid_submission_js_data', |
|
| 291 | - array( |
|
| 292 | - 'is_recurring' => $this->response['has_recurring'], |
|
| 293 | - ), |
|
| 294 | - $submission |
|
| 295 | - ), |
|
| 296 | - ) |
|
| 297 | - ); |
|
| 298 | - |
|
| 299 | - } |
|
| 271 | + $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 272 | + $this->response = array_merge( |
|
| 273 | + $this->response, |
|
| 274 | + array( 'gateways' => $gateways ) |
|
| 275 | + ); |
|
| 276 | + |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Adds data to a response for submission refresh prices. |
|
| 281 | + * |
|
| 282 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 283 | + */ |
|
| 284 | + public function add_data( $submission ) { |
|
| 285 | + |
|
| 286 | + $this->response = array_merge( |
|
| 287 | + $this->response, |
|
| 288 | + array( |
|
| 289 | + 'js_data' => apply_filters( |
|
| 290 | + 'getpaid_submission_js_data', |
|
| 291 | + array( |
|
| 292 | + 'is_recurring' => $this->response['has_recurring'], |
|
| 293 | + ), |
|
| 294 | + $submission |
|
| 295 | + ), |
|
| 296 | + ) |
|
| 297 | + ); |
|
| 298 | + |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | 301 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Payment form submission refresh prices class |
@@ -23,24 +23,24 @@ discard block |
||
| 23 | 23 | * |
| 24 | 24 | * @param GetPaid_Payment_Form_Submission $submission |
| 25 | 25 | */ |
| 26 | - public function __construct( $submission ) { |
|
| 26 | + public function __construct($submission) { |
|
| 27 | 27 | |
| 28 | 28 | $this->response = array( |
| 29 | 29 | 'submission_id' => $submission->id, |
| 30 | 30 | 'has_recurring' => $submission->has_recurring, |
| 31 | 31 | 'has_subscription_group' => $submission->has_subscription_group(), |
| 32 | 32 | 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
| 33 | - 'is_free' => ! $submission->should_collect_payment_details(), |
|
| 33 | + 'is_free' => !$submission->should_collect_payment_details(), |
|
| 34 | 34 | ); |
| 35 | 35 | |
| 36 | - $this->add_totals( $submission ); |
|
| 37 | - $this->add_texts( $submission ); |
|
| 38 | - $this->add_items( $submission ); |
|
| 39 | - $this->add_fees( $submission ); |
|
| 40 | - $this->add_discounts( $submission ); |
|
| 41 | - $this->add_taxes( $submission ); |
|
| 42 | - $this->add_gateways( $submission ); |
|
| 43 | - $this->add_data( $submission ); |
|
| 36 | + $this->add_totals($submission); |
|
| 37 | + $this->add_texts($submission); |
|
| 38 | + $this->add_items($submission); |
|
| 39 | + $this->add_fees($submission); |
|
| 40 | + $this->add_discounts($submission); |
|
| 41 | + $this->add_taxes($submission); |
|
| 42 | + $this->add_gateways($submission); |
|
| 43 | + $this->add_data($submission); |
|
| 44 | 44 | |
| 45 | 45 | } |
| 46 | 46 | |
@@ -49,30 +49,30 @@ discard block |
||
| 49 | 49 | * |
| 50 | 50 | * @param GetPaid_Payment_Form_Submission $submission |
| 51 | 51 | */ |
| 52 | - public function add_totals( $submission ) { |
|
| 52 | + public function add_totals($submission) { |
|
| 53 | 53 | |
| 54 | 54 | $this->response = array_merge( |
| 55 | 55 | $this->response, |
| 56 | 56 | array( |
| 57 | 57 | |
| 58 | 58 | 'totals' => array( |
| 59 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 60 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 61 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 62 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 63 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 64 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 59 | + 'subtotal' => $submission->format_amount($submission->get_subtotal()), |
|
| 60 | + 'discount' => $submission->format_amount($submission->get_discount()), |
|
| 61 | + 'fees' => $submission->format_amount($submission->get_fee()), |
|
| 62 | + 'tax' => $submission->format_amount($submission->get_tax()), |
|
| 63 | + 'total' => $submission->format_amount($submission->get_total()), |
|
| 64 | + 'raw_total' => html_entity_decode(sanitize_text_field($submission->format_amount($submission->get_total())), ENT_QUOTES), |
|
| 65 | 65 | ), |
| 66 | 66 | |
| 67 | 67 | 'recurring' => array( |
| 68 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 69 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 70 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 71 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 72 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 68 | + 'subtotal' => $submission->format_amount($submission->get_recurring_subtotal()), |
|
| 69 | + 'discount' => $submission->format_amount($submission->get_recurring_discount()), |
|
| 70 | + 'fees' => $submission->format_amount($submission->get_recurring_fee()), |
|
| 71 | + 'tax' => $submission->format_amount($submission->get_recurring_tax()), |
|
| 72 | + 'total' => $submission->format_amount($submission->get_recurring_total()), |
|
| 73 | 73 | ), |
| 74 | 74 | |
| 75 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 75 | + 'initial_amt' => wpinv_round_amount($submission->get_total(), null, true), |
|
| 76 | 76 | 'currency' => $submission->get_currency(), |
| 77 | 77 | |
| 78 | 78 | ) |
@@ -85,53 +85,53 @@ discard block |
||
| 85 | 85 | * |
| 86 | 86 | * @param GetPaid_Payment_Form_Submission $submission |
| 87 | 87 | */ |
| 88 | - public function add_texts( $submission ) { |
|
| 88 | + public function add_texts($submission) { |
|
| 89 | 89 | |
| 90 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
| 91 | - $groups = getpaid_get_subscription_groups( $submission ); |
|
| 90 | + $payable = $submission->format_amount($submission->get_total()); |
|
| 91 | + $groups = getpaid_get_subscription_groups($submission); |
|
| 92 | 92 | |
| 93 | - if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
| 93 | + if ($submission->has_recurring && 2 > count($groups)) { |
|
| 94 | 94 | |
| 95 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 96 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 97 | - $main_item = reset( $groups ); |
|
| 95 | + $recurring = new WPInv_Item($submission->has_recurring); |
|
| 96 | + $period = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), ''); |
|
| 97 | + $main_item = reset($groups); |
|
| 98 | 98 | |
| 99 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 99 | + if ($submission->get_total() == $submission->get_recurring_total()) { |
|
| 100 | 100 | $payable = "$payable / $period"; |
| 101 | - } elseif ( $main_item ) { |
|
| 101 | + } elseif ($main_item) { |
|
| 102 | 102 | |
| 103 | - $main_item = reset( $main_item ); |
|
| 103 | + $main_item = reset($main_item); |
|
| 104 | 104 | |
| 105 | 105 | // Calculate the next renewal date. |
| 106 | - $_period = $main_item->get_recurring_period( true ); |
|
| 106 | + $_period = $main_item->get_recurring_period(true); |
|
| 107 | 107 | $_interval = $main_item->get_recurring_interval(); |
| 108 | 108 | |
| 109 | 109 | // If the subscription item has a trial period... |
| 110 | - if ( $main_item->has_free_trial() ) { |
|
| 111 | - $_period = $main_item->get_trial_period( true ); |
|
| 110 | + if ($main_item->has_free_trial()) { |
|
| 111 | + $_period = $main_item->get_trial_period(true); |
|
| 112 | 112 | $_interval = $main_item->get_trial_interval(); |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | $payable = sprintf( |
| 116 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 117 | - $submission->format_amount( $submission->get_total() ), |
|
| 118 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
| 116 | + __('%1$s (renews at %2$s / %3$s)', 'invoicing'), |
|
| 117 | + $submission->format_amount($submission->get_total()), |
|
| 118 | + $submission->format_amount($submission->get_recurring_total()), |
|
| 119 | 119 | $period |
| 120 | 120 | ); |
| 121 | 121 | |
| 122 | 122 | $payable .= sprintf( |
| 123 | 123 | '<small class="text-muted form-text">%s</small>', |
| 124 | 124 | sprintf( |
| 125 | - __( 'First renewal on %s', 'invoicing' ), |
|
| 126 | - getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) ) |
|
| 125 | + __('First renewal on %s', 'invoicing'), |
|
| 126 | + getpaid_format_date(date('Y-m-d H:i:s', strtotime("+$_interval $_period", current_time('timestamp')))) |
|
| 127 | 127 | ) |
| 128 | 128 | ); |
| 129 | 129 | |
| 130 | 130 | } else { |
| 131 | 131 | $payable = sprintf( |
| 132 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 133 | - $submission->format_amount( $submission->get_total() ), |
|
| 134 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
| 132 | + __('%1$s (renews at %2$s / %3$s)', 'invoicing'), |
|
| 133 | + $submission->format_amount($submission->get_total()), |
|
| 134 | + $submission->format_amount($submission->get_recurring_total()), |
|
| 135 | 135 | $period |
| 136 | 136 | ); |
| 137 | 137 | } |
@@ -141,19 +141,19 @@ discard block |
||
| 141 | 141 | '.getpaid-checkout-total-payable' => $payable, |
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | - foreach ( $submission->get_items() as $item ) { |
|
| 144 | + foreach ($submission->get_items() as $item) { |
|
| 145 | 145 | $item_id = $item->get_id(); |
| 146 | - $initial_price = $submission->format_amount( $item->get_sub_total() - $item->item_discount ); |
|
| 147 | - $recurring_price = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount ); |
|
| 148 | - $texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 149 | - $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) ); |
|
| 146 | + $initial_price = $submission->format_amount($item->get_sub_total() - $item->item_discount); |
|
| 147 | + $recurring_price = $submission->format_amount($item->get_recurring_sub_total() - $item->recurring_item_discount); |
|
| 148 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text($item, $submission->get_currency(), $initial_price, $recurring_price); |
|
| 149 | + $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = sprintf(__('Subtotal: %s', 'invoicing'), $submission->format_amount($item->get_sub_total())); |
|
| 150 | 150 | |
| 151 | - if ( $item->get_quantity() == 1 ) { |
|
| 152 | - $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = ''; |
|
| 151 | + if ($item->get_quantity() == 1) { |
|
| 152 | + $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = ''; |
|
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 156 | + $this->response = array_merge($this->response, array('texts' => $texts)); |
|
| 157 | 157 | |
| 158 | 158 | } |
| 159 | 159 | |
@@ -162,19 +162,19 @@ discard block |
||
| 162 | 162 | * |
| 163 | 163 | * @param GetPaid_Payment_Form_Submission $submission |
| 164 | 164 | */ |
| 165 | - public function add_items( $submission ) { |
|
| 165 | + public function add_items($submission) { |
|
| 166 | 166 | |
| 167 | 167 | // Add items. |
| 168 | 168 | $items = array(); |
| 169 | 169 | |
| 170 | - foreach ( $submission->get_items() as $item ) { |
|
| 171 | - $item_id = $item->get_id(); |
|
| 172 | - $items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() ); |
|
| 170 | + foreach ($submission->get_items() as $item) { |
|
| 171 | + $item_id = $item->get_id(); |
|
| 172 | + $items["$item_id"] = $submission->format_amount($item->get_sub_total()); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | $this->response = array_merge( |
| 176 | 176 | $this->response, |
| 177 | - array( 'items' => $items ) |
|
| 177 | + array('items' => $items) |
|
| 178 | 178 | ); |
| 179 | 179 | |
| 180 | 180 | } |
@@ -184,17 +184,17 @@ discard block |
||
| 184 | 184 | * |
| 185 | 185 | * @param GetPaid_Payment_Form_Submission $submission |
| 186 | 186 | */ |
| 187 | - public function add_fees( $submission ) { |
|
| 187 | + public function add_fees($submission) { |
|
| 188 | 188 | |
| 189 | 189 | $fees = array(); |
| 190 | 190 | |
| 191 | - foreach ( $submission->get_fees() as $name => $data ) { |
|
| 192 | - $fees[ $name ] = $submission->format_amount( $data['initial_fee'] ); |
|
| 191 | + foreach ($submission->get_fees() as $name => $data) { |
|
| 192 | + $fees[$name] = $submission->format_amount($data['initial_fee']); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | $this->response = array_merge( |
| 196 | 196 | $this->response, |
| 197 | - array( 'fees' => $fees ) |
|
| 197 | + array('fees' => $fees) |
|
| 198 | 198 | ); |
| 199 | 199 | |
| 200 | 200 | } |
@@ -204,17 +204,17 @@ discard block |
||
| 204 | 204 | * |
| 205 | 205 | * @param GetPaid_Payment_Form_Submission $submission |
| 206 | 206 | */ |
| 207 | - public function add_discounts( $submission ) { |
|
| 207 | + public function add_discounts($submission) { |
|
| 208 | 208 | |
| 209 | 209 | $discounts = array(); |
| 210 | 210 | |
| 211 | - foreach ( $submission->get_discounts() as $name => $data ) { |
|
| 212 | - $discounts[ $name ] = $submission->format_amount( $data['initial_discount'] ); |
|
| 211 | + foreach ($submission->get_discounts() as $name => $data) { |
|
| 212 | + $discounts[$name] = $submission->format_amount($data['initial_discount']); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | $this->response = array_merge( |
| 216 | 216 | $this->response, |
| 217 | - array( 'discounts' => $discounts ) |
|
| 217 | + array('discounts' => $discounts) |
|
| 218 | 218 | ); |
| 219 | 219 | |
| 220 | 220 | } |
@@ -224,24 +224,24 @@ discard block |
||
| 224 | 224 | * |
| 225 | 225 | * @param GetPaid_Payment_Form_Submission $submission |
| 226 | 226 | */ |
| 227 | - public function add_taxes( $submission ) { |
|
| 227 | + public function add_taxes($submission) { |
|
| 228 | 228 | |
| 229 | 229 | $taxes = array(); |
| 230 | 230 | $markup = ''; |
| 231 | - foreach ( $submission->get_taxes() as $name => $data ) { |
|
| 232 | - $name = sanitize_text_field( $name ); |
|
| 233 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 234 | - $taxes[ $name ] = $amount; |
|
| 231 | + foreach ($submission->get_taxes() as $name => $data) { |
|
| 232 | + $name = sanitize_text_field($name); |
|
| 233 | + $amount = $submission->format_amount($data['initial_tax']); |
|
| 234 | + $taxes[$name] = $amount; |
|
| 235 | 235 | $markup .= "<small class='form-text'>$name : $amount</small>"; |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
| 238 | + if (wpinv_display_individual_tax_rates() && !empty($taxes)) { |
|
| 239 | 239 | $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | $this->response = array_merge( |
| 243 | 243 | $this->response, |
| 244 | - array( 'taxes' => $taxes ) |
|
| 244 | + array('taxes' => $taxes) |
|
| 245 | 245 | ); |
| 246 | 246 | |
| 247 | 247 | } |
@@ -251,27 +251,27 @@ discard block |
||
| 251 | 251 | * |
| 252 | 252 | * @param GetPaid_Payment_Form_Submission $submission |
| 253 | 253 | */ |
| 254 | - public function add_gateways( $submission ) { |
|
| 254 | + public function add_gateways($submission) { |
|
| 255 | 255 | |
| 256 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 256 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
| 257 | 257 | |
| 258 | - if ( $this->response['has_recurring'] ) { |
|
| 258 | + if ($this->response['has_recurring']) { |
|
| 259 | 259 | |
| 260 | - foreach ( $gateways as $i => $gateway ) { |
|
| 260 | + foreach ($gateways as $i => $gateway) { |
|
| 261 | 261 | |
| 262 | 262 | if ( |
| 263 | - ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
| 264 | - || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
| 265 | - || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
| 266 | - unset( $gateways[ $i ] ); |
|
| 263 | + !getpaid_payment_gateway_supports($gateway, 'subscription') |
|
| 264 | + || ($this->response['has_subscription_group'] && !getpaid_payment_gateway_supports($gateway, 'single_subscription_group')) |
|
| 265 | + || ($this->response['has_multiple_subscription_groups'] && !getpaid_payment_gateway_supports($gateway, 'multiple_subscription_groups')) ) { |
|
| 266 | + unset($gateways[$i]); |
|
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 271 | + $gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission); |
|
| 272 | 272 | $this->response = array_merge( |
| 273 | 273 | $this->response, |
| 274 | - array( 'gateways' => $gateways ) |
|
| 274 | + array('gateways' => $gateways) |
|
| 275 | 275 | ); |
| 276 | 276 | |
| 277 | 277 | } |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | * |
| 282 | 282 | * @param GetPaid_Payment_Form_Submission $submission |
| 283 | 283 | */ |
| 284 | - public function add_data( $submission ) { |
|
| 284 | + public function add_data($submission) { |
|
| 285 | 285 | |
| 286 | 286 | $this->response = array_merge( |
| 287 | 287 | $this->response, |
@@ -12,227 +12,227 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Taxes { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Submission taxes. |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $taxes = array(); |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Whether or not we should skip the taxes. |
|
| 23 | - * @var bool |
|
| 24 | - */ |
|
| 25 | - protected $skip_taxes = false; |
|
| 15 | + /** |
|
| 16 | + * Submission taxes. |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $taxes = array(); |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Whether or not we should skip the taxes. |
|
| 23 | + * @var bool |
|
| 24 | + */ |
|
| 25 | + protected $skip_taxes = false; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Class constructor |
|
| 29 | + * |
|
| 30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | + */ |
|
| 32 | + public function __construct( $submission ) { |
|
| 33 | + |
|
| 34 | + // Validate VAT number. |
|
| 35 | + $this->validate_vat( $submission ); |
|
| 36 | + |
|
| 37 | + if ( $this->skip_taxes ) { |
|
| 38 | + return; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + foreach ( $submission->get_items() as $item ) { |
|
| 42 | + $this->process_item_tax( $item, $submission ); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + // Process any existing invoice taxes. |
|
| 46 | + if ( $submission->has_invoice() ) { |
|
| 47 | + $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Maybe process tax. |
|
| 54 | + * |
|
| 55 | + * @since 1.0.19 |
|
| 56 | + * @param GetPaid_Form_Item $item |
|
| 57 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 58 | + */ |
|
| 59 | + public function process_item_tax( $item, $submission ) { |
|
| 60 | + |
|
| 61 | + $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
| 62 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 63 | + $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
| 64 | + $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
| 65 | + |
|
| 66 | + foreach ( $taxes as $name => $amount ) { |
|
| 67 | + $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 68 | + $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 69 | + |
|
| 70 | + $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 71 | + |
|
| 72 | + if ( ! isset( $this->taxes[ $name ] ) ) { |
|
| 73 | + $this->taxes[ $name ] = $tax; |
|
| 74 | + continue; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 78 | + $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 79 | + |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + } |
|
| 26 | 83 | |
| 27 | 84 | /** |
| 28 | - * Class constructor |
|
| 29 | - * |
|
| 30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | - */ |
|
| 32 | - public function __construct( $submission ) { |
|
| 33 | - |
|
| 34 | - // Validate VAT number. |
|
| 35 | - $this->validate_vat( $submission ); |
|
| 36 | - |
|
| 37 | - if ( $this->skip_taxes ) { |
|
| 38 | - return; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - foreach ( $submission->get_items() as $item ) { |
|
| 42 | - $this->process_item_tax( $item, $submission ); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - // Process any existing invoice taxes. |
|
| 46 | - if ( $submission->has_invoice() ) { |
|
| 47 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Maybe process tax. |
|
| 54 | - * |
|
| 55 | - * @since 1.0.19 |
|
| 56 | - * @param GetPaid_Form_Item $item |
|
| 57 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 58 | - */ |
|
| 59 | - public function process_item_tax( $item, $submission ) { |
|
| 60 | - |
|
| 61 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
| 62 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 63 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
| 64 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
| 65 | - |
|
| 66 | - foreach ( $taxes as $name => $amount ) { |
|
| 67 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 68 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 69 | - |
|
| 70 | - $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 71 | - |
|
| 72 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
| 73 | - $this->taxes[ $name ] = $tax; |
|
| 74 | - continue; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 78 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 79 | - |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Checks if the submission has a digital item. |
|
| 86 | - * |
|
| 87 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 88 | - * @since 1.0.19 |
|
| 89 | - * @return bool |
|
| 90 | - */ |
|
| 91 | - public function has_digital_item( $submission ) { |
|
| 92 | - |
|
| 93 | - foreach ( $submission->get_items() as $item ) { |
|
| 94 | - |
|
| 95 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
| 96 | - return true; |
|
| 97 | - } |
|
| 85 | + * Checks if the submission has a digital item. |
|
| 86 | + * |
|
| 87 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 88 | + * @since 1.0.19 |
|
| 89 | + * @return bool |
|
| 90 | + */ |
|
| 91 | + public function has_digital_item( $submission ) { |
|
| 92 | + |
|
| 93 | + foreach ( $submission->get_items() as $item ) { |
|
| 94 | + |
|
| 95 | + if ( 'digital' == $item->get_vat_rule() ) { |
|
| 96 | + return true; |
|
| 97 | + } |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - return false; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Checks if this is an eu store. |
|
| 105 | - * |
|
| 106 | - * @since 1.0.19 |
|
| 107 | - * @return bool |
|
| 108 | - */ |
|
| 109 | - public static function is_eu_store() { |
|
| 110 | - return self::is_eu_country( wpinv_get_default_country() ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Checks if this is an eu country. |
|
| 115 | - * |
|
| 116 | - * @param string $country |
|
| 117 | - * @since 1.0.19 |
|
| 118 | - * @return bool |
|
| 119 | - */ |
|
| 120 | - public static function is_eu_country( $country ) { |
|
| 121 | - return getpaid_is_eu_state( $country ); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Checks if this is an eu purchase. |
|
| 126 | - * |
|
| 127 | - * @param string $customer_country |
|
| 128 | - * @since 1.0.19 |
|
| 129 | - * @return bool |
|
| 130 | - */ |
|
| 131 | - public static function is_eu_transaction( $customer_country ) { |
|
| 132 | - return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Retrieves the vat number. |
|
| 137 | - * |
|
| 138 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 139 | - * @since 1.0.19 |
|
| 140 | - * @return string |
|
| 141 | - */ |
|
| 142 | - public function get_vat_number( $submission ) { |
|
| 143 | - |
|
| 144 | - // Retrieve from the posted number. |
|
| 145 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
| 146 | - if ( ! is_null( $vat_number ) ) { |
|
| 147 | - return wpinv_clean( $vat_number ); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Retrieves the company. |
|
| 155 | - * |
|
| 156 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 157 | - * @since 1.0.19 |
|
| 158 | - * @return string |
|
| 159 | - */ |
|
| 160 | - public function get_company( $submission ) { |
|
| 161 | - |
|
| 162 | - // Retrieve from the posted data. |
|
| 163 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
| 164 | - if ( ! empty( $company ) ) { |
|
| 165 | - return wpinv_clean( $company ); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - // Retrieve from the invoice. |
|
| 169 | - return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Checks if we require a VAT number. |
|
| 174 | - * |
|
| 175 | - * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
| 176 | - * @param bool $country_in_eu Whether the customer country is from the EU |
|
| 177 | - * @since 1.0.19 |
|
| 178 | - * @return string |
|
| 179 | - */ |
|
| 180 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 181 | - |
|
| 182 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 183 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 184 | - $is_eu = $ip_in_eu || $country_in_eu; |
|
| 185 | - |
|
| 186 | - return $prevent_b2c && $is_eu; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Validate VAT data. |
|
| 191 | - * |
|
| 192 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 193 | - * @since 1.0.19 |
|
| 194 | - */ |
|
| 195 | - public function validate_vat( $submission ) { |
|
| 196 | - |
|
| 197 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 198 | - |
|
| 199 | - // Abort if we are not validating vat numbers. |
|
| 200 | - if ( ! $in_eu ) { |
|
| 100 | + return false; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Checks if this is an eu store. |
|
| 105 | + * |
|
| 106 | + * @since 1.0.19 |
|
| 107 | + * @return bool |
|
| 108 | + */ |
|
| 109 | + public static function is_eu_store() { |
|
| 110 | + return self::is_eu_country( wpinv_get_default_country() ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Checks if this is an eu country. |
|
| 115 | + * |
|
| 116 | + * @param string $country |
|
| 117 | + * @since 1.0.19 |
|
| 118 | + * @return bool |
|
| 119 | + */ |
|
| 120 | + public static function is_eu_country( $country ) { |
|
| 121 | + return getpaid_is_eu_state( $country ); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Checks if this is an eu purchase. |
|
| 126 | + * |
|
| 127 | + * @param string $customer_country |
|
| 128 | + * @since 1.0.19 |
|
| 129 | + * @return bool |
|
| 130 | + */ |
|
| 131 | + public static function is_eu_transaction( $customer_country ) { |
|
| 132 | + return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Retrieves the vat number. |
|
| 137 | + * |
|
| 138 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 139 | + * @since 1.0.19 |
|
| 140 | + * @return string |
|
| 141 | + */ |
|
| 142 | + public function get_vat_number( $submission ) { |
|
| 143 | + |
|
| 144 | + // Retrieve from the posted number. |
|
| 145 | + $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
| 146 | + if ( ! is_null( $vat_number ) ) { |
|
| 147 | + return wpinv_clean( $vat_number ); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Retrieves the company. |
|
| 155 | + * |
|
| 156 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 157 | + * @since 1.0.19 |
|
| 158 | + * @return string |
|
| 159 | + */ |
|
| 160 | + public function get_company( $submission ) { |
|
| 161 | + |
|
| 162 | + // Retrieve from the posted data. |
|
| 163 | + $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
| 164 | + if ( ! empty( $company ) ) { |
|
| 165 | + return wpinv_clean( $company ); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + // Retrieve from the invoice. |
|
| 169 | + return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Checks if we require a VAT number. |
|
| 174 | + * |
|
| 175 | + * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
| 176 | + * @param bool $country_in_eu Whether the customer country is from the EU |
|
| 177 | + * @since 1.0.19 |
|
| 178 | + * @return string |
|
| 179 | + */ |
|
| 180 | + public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 181 | + |
|
| 182 | + $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 183 | + $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 184 | + $is_eu = $ip_in_eu || $country_in_eu; |
|
| 185 | + |
|
| 186 | + return $prevent_b2c && $is_eu; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Validate VAT data. |
|
| 191 | + * |
|
| 192 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 193 | + * @since 1.0.19 |
|
| 194 | + */ |
|
| 195 | + public function validate_vat( $submission ) { |
|
| 196 | + |
|
| 197 | + $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 198 | + |
|
| 199 | + // Abort if we are not validating vat numbers. |
|
| 200 | + if ( ! $in_eu ) { |
|
| 201 | 201 | return; |
| 202 | - } |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - // Prepare variables. |
|
| 205 | - $vat_number = $this->get_vat_number( $submission ); |
|
| 206 | - $ip_country = getpaid_get_ip_country(); |
|
| 204 | + // Prepare variables. |
|
| 205 | + $vat_number = $this->get_vat_number( $submission ); |
|
| 206 | + $ip_country = getpaid_get_ip_country(); |
|
| 207 | 207 | $is_eu = $this->is_eu_country( $submission->country ); |
| 208 | 208 | $is_ip_eu = $this->is_eu_country( $ip_country ); |
| 209 | 209 | |
| 210 | - // Maybe abort early for initial fetches. |
|
| 211 | - if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
| 212 | - return; |
|
| 213 | - } |
|
| 210 | + // Maybe abort early for initial fetches. |
|
| 211 | + if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
| 212 | + return; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - // If we're preventing business to consumer purchases, |
|
| 216 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 215 | + // If we're preventing business to consumer purchases, |
|
| 216 | + if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 217 | 217 | |
| 218 | - // Ensure that a vat number has been specified. |
|
| 219 | - throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) ); |
|
| 218 | + // Ensure that a vat number has been specified. |
|
| 219 | + throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) ); |
|
| 220 | 220 | |
| 221 | - } |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - if ( empty( $vat_number ) ) { |
|
| 224 | - return; |
|
| 225 | - } |
|
| 223 | + if ( empty( $vat_number ) ) { |
|
| 224 | + return; |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
| 228 | - throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
| 229 | - } |
|
| 227 | + if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
| 228 | + throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 232 | - return; |
|
| 233 | - } |
|
| 231 | + if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 232 | + return; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - $this->skip_taxes = true; |
|
| 236 | - } |
|
| 235 | + $this->skip_taxes = true; |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | 238 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Payment form submission taxes class |
@@ -29,22 +29,22 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | * @param GetPaid_Payment_Form_Submission $submission |
| 31 | 31 | */ |
| 32 | - public function __construct( $submission ) { |
|
| 32 | + public function __construct($submission) { |
|
| 33 | 33 | |
| 34 | 34 | // Validate VAT number. |
| 35 | - $this->validate_vat( $submission ); |
|
| 35 | + $this->validate_vat($submission); |
|
| 36 | 36 | |
| 37 | - if ( $this->skip_taxes ) { |
|
| 37 | + if ($this->skip_taxes) { |
|
| 38 | 38 | return; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - foreach ( $submission->get_items() as $item ) { |
|
| 42 | - $this->process_item_tax( $item, $submission ); |
|
| 41 | + foreach ($submission->get_items() as $item) { |
|
| 42 | + $this->process_item_tax($item, $submission); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | // Process any existing invoice taxes. |
| 46 | - if ( $submission->has_invoice() ) { |
|
| 47 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
| 46 | + if ($submission->has_invoice()) { |
|
| 47 | + $this->taxes = array_replace($submission->get_invoice()->get_taxes(), $this->taxes); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | } |
@@ -56,26 +56,26 @@ discard block |
||
| 56 | 56 | * @param GetPaid_Form_Item $item |
| 57 | 57 | * @param GetPaid_Payment_Form_Submission $submission |
| 58 | 58 | */ |
| 59 | - public function process_item_tax( $item, $submission ) { |
|
| 59 | + public function process_item_tax($item, $submission) { |
|
| 60 | 60 | |
| 61 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
| 62 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 63 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
| 64 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
| 61 | + $rates = getpaid_get_item_tax_rates($item, $submission->country, $submission->state); |
|
| 62 | + $rates = getpaid_filter_item_tax_rates($item, $rates); |
|
| 63 | + $taxes = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, false), $rates); |
|
| 64 | + $r_taxes = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, true), $rates); |
|
| 65 | 65 | |
| 66 | - foreach ( $taxes as $name => $amount ) { |
|
| 67 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 68 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 66 | + foreach ($taxes as $name => $amount) { |
|
| 67 | + $recurring = isset($r_taxes[$name]) ? $r_taxes[$name] : 0; |
|
| 68 | + $tax = getpaid_prepare_item_tax($item, $name, $amount, $recurring); |
|
| 69 | 69 | |
| 70 | - $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 70 | + $item->item_tax += wpinv_sanitize_amount($tax['initial_tax']); |
|
| 71 | 71 | |
| 72 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
| 73 | - $this->taxes[ $name ] = $tax; |
|
| 72 | + if (!isset($this->taxes[$name])) { |
|
| 73 | + $this->taxes[$name] = $tax; |
|
| 74 | 74 | continue; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 78 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 77 | + $this->taxes[$name]['initial_tax'] += $tax['initial_tax']; |
|
| 78 | + $this->taxes[$name]['recurring_tax'] += $tax['recurring_tax']; |
|
| 79 | 79 | |
| 80 | 80 | } |
| 81 | 81 | |
@@ -88,11 +88,11 @@ discard block |
||
| 88 | 88 | * @since 1.0.19 |
| 89 | 89 | * @return bool |
| 90 | 90 | */ |
| 91 | - public function has_digital_item( $submission ) { |
|
| 91 | + public function has_digital_item($submission) { |
|
| 92 | 92 | |
| 93 | - foreach ( $submission->get_items() as $item ) { |
|
| 93 | + foreach ($submission->get_items() as $item) { |
|
| 94 | 94 | |
| 95 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
| 95 | + if ('digital' == $item->get_vat_rule()) { |
|
| 96 | 96 | return true; |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * @return bool |
| 108 | 108 | */ |
| 109 | 109 | public static function is_eu_store() { |
| 110 | - return self::is_eu_country( wpinv_get_default_country() ); |
|
| 110 | + return self::is_eu_country(wpinv_get_default_country()); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -117,8 +117,8 @@ discard block |
||
| 117 | 117 | * @since 1.0.19 |
| 118 | 118 | * @return bool |
| 119 | 119 | */ |
| 120 | - public static function is_eu_country( $country ) { |
|
| 121 | - return getpaid_is_eu_state( $country ); |
|
| 120 | + public static function is_eu_country($country) { |
|
| 121 | + return getpaid_is_eu_state($country); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -128,8 +128,8 @@ discard block |
||
| 128 | 128 | * @since 1.0.19 |
| 129 | 129 | * @return bool |
| 130 | 130 | */ |
| 131 | - public static function is_eu_transaction( $customer_country ) { |
|
| 132 | - return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
| 131 | + public static function is_eu_transaction($customer_country) { |
|
| 132 | + return self::is_eu_country($customer_country) && self::is_eu_store(); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -139,12 +139,12 @@ discard block |
||
| 139 | 139 | * @since 1.0.19 |
| 140 | 140 | * @return string |
| 141 | 141 | */ |
| 142 | - public function get_vat_number( $submission ) { |
|
| 142 | + public function get_vat_number($submission) { |
|
| 143 | 143 | |
| 144 | 144 | // Retrieve from the posted number. |
| 145 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
| 146 | - if ( ! is_null( $vat_number ) ) { |
|
| 147 | - return wpinv_clean( $vat_number ); |
|
| 145 | + $vat_number = $submission->get_field('wpinv_vat_number', 'billing'); |
|
| 146 | + if (!is_null($vat_number)) { |
|
| 147 | + return wpinv_clean($vat_number); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
@@ -157,12 +157,12 @@ discard block |
||
| 157 | 157 | * @since 1.0.19 |
| 158 | 158 | * @return string |
| 159 | 159 | */ |
| 160 | - public function get_company( $submission ) { |
|
| 160 | + public function get_company($submission) { |
|
| 161 | 161 | |
| 162 | 162 | // Retrieve from the posted data. |
| 163 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
| 164 | - if ( ! empty( $company ) ) { |
|
| 165 | - return wpinv_clean( $company ); |
|
| 163 | + $company = $submission->get_field('wpinv_company', 'billing'); |
|
| 164 | + if (!empty($company)) { |
|
| 165 | + return wpinv_clean($company); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | // Retrieve from the invoice. |
@@ -177,10 +177,10 @@ discard block |
||
| 177 | 177 | * @since 1.0.19 |
| 178 | 178 | * @return string |
| 179 | 179 | */ |
| 180 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 180 | + public function requires_vat($ip_in_eu, $country_in_eu) { |
|
| 181 | 181 | |
| 182 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 183 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 182 | + $prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase'); |
|
| 183 | + $prevent_b2c = !empty($prevent_b2c); |
|
| 184 | 184 | $is_eu = $ip_in_eu || $country_in_eu; |
| 185 | 185 | |
| 186 | 186 | return $prevent_b2c && $is_eu; |
@@ -192,43 +192,43 @@ discard block |
||
| 192 | 192 | * @param GetPaid_Payment_Form_Submission $submission |
| 193 | 193 | * @since 1.0.19 |
| 194 | 194 | */ |
| 195 | - public function validate_vat( $submission ) { |
|
| 195 | + public function validate_vat($submission) { |
|
| 196 | 196 | |
| 197 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 197 | + $in_eu = $this->is_eu_transaction($submission->country); |
|
| 198 | 198 | |
| 199 | 199 | // Abort if we are not validating vat numbers. |
| 200 | - if ( ! $in_eu ) { |
|
| 200 | + if (!$in_eu) { |
|
| 201 | 201 | return; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | // Prepare variables. |
| 205 | - $vat_number = $this->get_vat_number( $submission ); |
|
| 205 | + $vat_number = $this->get_vat_number($submission); |
|
| 206 | 206 | $ip_country = getpaid_get_ip_country(); |
| 207 | - $is_eu = $this->is_eu_country( $submission->country ); |
|
| 208 | - $is_ip_eu = $this->is_eu_country( $ip_country ); |
|
| 207 | + $is_eu = $this->is_eu_country($submission->country); |
|
| 208 | + $is_ip_eu = $this->is_eu_country($ip_country); |
|
| 209 | 209 | |
| 210 | 210 | // Maybe abort early for initial fetches. |
| 211 | - if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
| 211 | + if ($submission->is_initial_fetch() && empty($vat_number)) { |
|
| 212 | 212 | return; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | // If we're preventing business to consumer purchases, |
| 216 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 216 | + if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) { |
|
| 217 | 217 | |
| 218 | 218 | // Ensure that a vat number has been specified. |
| 219 | - throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) ); |
|
| 219 | + throw new GetPaid_Payment_Exception('.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __('Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing')); |
|
| 220 | 220 | |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - if ( empty( $vat_number ) ) { |
|
| 223 | + if (empty($vat_number)) { |
|
| 224 | 224 | return; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
| 228 | - throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
| 227 | + if (wpinv_should_validate_vat_number() && !wpinv_validate_vat_number($vat_number, $submission->country)) { |
|
| 228 | + throw new GetPaid_Payment_Exception('.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __('Your VAT number is invalid', 'invoicing')); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 231 | + if (wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option('vat_same_country_rule', 'vat_too')) { |
|
| 232 | 232 | return; |
| 233 | 233 | } |
| 234 | 234 | |
@@ -12,69 +12,69 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | abstract class GetPaid_Reports_Abstract_Report { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var array |
|
| 17 | - */ |
|
| 18 | - public $stats; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Class constructor. |
|
| 22 | - * |
|
| 23 | - */ |
|
| 24 | - public function __construct() { |
|
| 25 | - $this->prepare_stats(); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Retrieves the current range. |
|
| 30 | - * |
|
| 31 | - */ |
|
| 32 | - public function get_range() { |
|
| 33 | - $valid_ranges = $this->get_periods(); |
|
| 34 | - |
|
| 35 | - if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
| 36 | - return sanitize_key( $_GET['date_range'] ); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - return '7_days'; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Returns an array of date ranges. |
|
| 44 | - * |
|
| 45 | - * @return array |
|
| 46 | - */ |
|
| 47 | - public function get_periods() { |
|
| 48 | - |
|
| 49 | - $periods = array( |
|
| 15 | + /** |
|
| 16 | + * @var array |
|
| 17 | + */ |
|
| 18 | + public $stats; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Class constructor. |
|
| 22 | + * |
|
| 23 | + */ |
|
| 24 | + public function __construct() { |
|
| 25 | + $this->prepare_stats(); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Retrieves the current range. |
|
| 30 | + * |
|
| 31 | + */ |
|
| 32 | + public function get_range() { |
|
| 33 | + $valid_ranges = $this->get_periods(); |
|
| 34 | + |
|
| 35 | + if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
| 36 | + return sanitize_key( $_GET['date_range'] ); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + return '7_days'; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Returns an array of date ranges. |
|
| 44 | + * |
|
| 45 | + * @return array |
|
| 46 | + */ |
|
| 47 | + public function get_periods() { |
|
| 48 | + |
|
| 49 | + $periods = array( |
|
| 50 | 50 | 'today' => __( 'Today', 'invoicing' ), |
| 51 | 51 | 'yesterday' => __( 'Yesterday', 'invoicing' ), |
| 52 | 52 | '7_days' => __( 'Last 7 days', 'invoicing' ), |
| 53 | - '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
| 54 | - '60_days' => __( 'Last 60 days', 'invoicing' ), |
|
| 55 | - '90_days' => __( 'Last 90 days', 'invoicing' ), |
|
| 56 | - '180_days' => __( 'Last 180 days', 'invoicing' ), |
|
| 57 | - '360_days' => __( 'Last 360 days', 'invoicing' ), |
|
| 58 | - ); |
|
| 59 | - |
|
| 60 | - return apply_filters( 'getpaid_earning_periods', $periods ); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Retrieves the current range's sql. |
|
| 65 | - * |
|
| 66 | - */ |
|
| 67 | - public function get_range_sql( $range, $date = 'CAST(meta.completed_date AS DATE)', $datetime = 'meta.comlpeted_date' ) { |
|
| 53 | + '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
| 54 | + '60_days' => __( 'Last 60 days', 'invoicing' ), |
|
| 55 | + '90_days' => __( 'Last 90 days', 'invoicing' ), |
|
| 56 | + '180_days' => __( 'Last 180 days', 'invoicing' ), |
|
| 57 | + '360_days' => __( 'Last 360 days', 'invoicing' ), |
|
| 58 | + ); |
|
| 59 | + |
|
| 60 | + return apply_filters( 'getpaid_earning_periods', $periods ); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Retrieves the current range's sql. |
|
| 65 | + * |
|
| 66 | + */ |
|
| 67 | + public function get_range_sql( $range, $date = 'CAST(meta.completed_date AS DATE)', $datetime = 'meta.comlpeted_date' ) { |
|
| 68 | 68 | |
| 69 | 69 | // Prepare durations. |
| 70 | 70 | $today = current_time( 'Y-m-d' ); |
| 71 | - $yesterday = date( 'Y-m-d', strtotime( '-1 day', current_time( 'timestamp' ) ) ); |
|
| 72 | - $seven_days_ago = date( 'Y-m-d', strtotime( '-7 days', current_time( 'timestamp' ) ) ); |
|
| 73 | - $thirty_days_ago = date( 'Y-m-d', strtotime( '-30 days', current_time( 'timestamp' ) ) ); |
|
| 74 | - $ninety_days_ago = date( 'Y-m-d', strtotime( '-90 days', current_time( 'timestamp' ) ) ); |
|
| 75 | - $sixty_days_ago = date( 'Y-m-d', strtotime( '-60 days', current_time( 'timestamp' ) ) ); |
|
| 76 | - $one_eighty_days_ago = date( 'Y-m-d', strtotime( '-180 days', current_time( 'timestamp' ) ) ); |
|
| 77 | - $three_sixty_days_ago = date( 'Y-m-d', strtotime( '-360 days', current_time( 'timestamp' ) ) ); |
|
| 71 | + $yesterday = date( 'Y-m-d', strtotime( '-1 day', current_time( 'timestamp' ) ) ); |
|
| 72 | + $seven_days_ago = date( 'Y-m-d', strtotime( '-7 days', current_time( 'timestamp' ) ) ); |
|
| 73 | + $thirty_days_ago = date( 'Y-m-d', strtotime( '-30 days', current_time( 'timestamp' ) ) ); |
|
| 74 | + $ninety_days_ago = date( 'Y-m-d', strtotime( '-90 days', current_time( 'timestamp' ) ) ); |
|
| 75 | + $sixty_days_ago = date( 'Y-m-d', strtotime( '-60 days', current_time( 'timestamp' ) ) ); |
|
| 76 | + $one_eighty_days_ago = date( 'Y-m-d', strtotime( '-180 days', current_time( 'timestamp' ) ) ); |
|
| 77 | + $three_sixty_days_ago = date( 'Y-m-d', strtotime( '-360 days', current_time( 'timestamp' ) ) ); |
|
| 78 | 78 | |
| 79 | 79 | $ranges = array( |
| 80 | 80 | |
@@ -91,130 +91,130 @@ discard block |
||
| 91 | 91 | '7_days' => array( |
| 92 | 92 | "DATE($datetime)", |
| 93 | 93 | "$date BETWEEN '$seven_days_ago' AND '$today'", |
| 94 | - ), |
|
| 94 | + ), |
|
| 95 | 95 | |
| 96 | - '30_days' => array( |
|
| 96 | + '30_days' => array( |
|
| 97 | 97 | "DATE($datetime)", |
| 98 | 98 | "$date BETWEEN '$thirty_days_ago' AND '$today'", |
| 99 | - ), |
|
| 99 | + ), |
|
| 100 | 100 | |
| 101 | - '60_days' => array( |
|
| 101 | + '60_days' => array( |
|
| 102 | 102 | "DATE($datetime)", |
| 103 | 103 | "$date BETWEEN '$sixty_days_ago' AND '$today'", |
| 104 | - ), |
|
| 104 | + ), |
|
| 105 | 105 | |
| 106 | - '90_days' => array( |
|
| 106 | + '90_days' => array( |
|
| 107 | 107 | "WEEK($datetime)", |
| 108 | 108 | "$date BETWEEN '$ninety_days_ago' AND '$today'", |
| 109 | - ), |
|
| 109 | + ), |
|
| 110 | 110 | |
| 111 | - '180_days' => array( |
|
| 111 | + '180_days' => array( |
|
| 112 | 112 | "WEEK($datetime)", |
| 113 | 113 | "$date BETWEEN '$one_eighty_days_ago' AND '$today'", |
| 114 | - ), |
|
| 114 | + ), |
|
| 115 | 115 | |
| 116 | - '360_days' => array( |
|
| 116 | + '360_days' => array( |
|
| 117 | 117 | "WEEK($datetime)", |
| 118 | 118 | "$date BETWEEN '$three_sixty_days_ago' AND '$today'", |
| 119 | 119 | ), |
| 120 | 120 | |
| 121 | 121 | ); |
| 122 | 122 | |
| 123 | - $sql = isset( $ranges[ $range ] ) ? $ranges[ $range ] : $ranges['7_days']; |
|
| 124 | - return apply_filters( 'getpaid_earning_graphs_get_range_sql', $sql, $range ); |
|
| 125 | - |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Retrieves the hours in a day |
|
| 130 | - * |
|
| 131 | - */ |
|
| 132 | - public function get_hours_in_a_day() { |
|
| 133 | - |
|
| 134 | - return array( |
|
| 135 | - '12AM' => __( '12 AM', 'invoicing' ), |
|
| 136 | - '1AM' => __( '1 AM', 'invoicing' ), |
|
| 137 | - '2AM' => __( '2 AM', 'invoicing' ), |
|
| 138 | - '3AM' => __( '3 AM', 'invoicing' ), |
|
| 139 | - '4AM' => __( '4 AM', 'invoicing' ), |
|
| 140 | - '5AM' => __( '5 AM', 'invoicing' ), |
|
| 141 | - '6AM' => __( '6 AM', 'invoicing' ), |
|
| 142 | - '7AM' => __( '7 AM', 'invoicing' ), |
|
| 143 | - '8AM' => __( '8 AM', 'invoicing' ), |
|
| 144 | - '9AM' => __( '9 AM', 'invoicing' ), |
|
| 145 | - '10AM' => __( '10 AM', 'invoicing' ), |
|
| 146 | - '11AM' => __( '11 AM', 'invoicing' ), |
|
| 147 | - '12pm' => __( '12 PM', 'invoicing' ), |
|
| 148 | - '1PM' => __( '1 PM', 'invoicing' ), |
|
| 149 | - '2PM' => __( '2 PM', 'invoicing' ), |
|
| 150 | - '3PM' => __( '3 PM', 'invoicing' ), |
|
| 151 | - '4PM' => __( '4 PM', 'invoicing' ), |
|
| 152 | - '5PM' => __( '5 PM', 'invoicing' ), |
|
| 153 | - '6PM' => __( '6 PM', 'invoicing' ), |
|
| 154 | - '7PM' => __( '7 PM', 'invoicing' ), |
|
| 155 | - '8PM' => __( '8 PM', 'invoicing' ), |
|
| 156 | - '9PM' => __( '9 PM', 'invoicing' ), |
|
| 157 | - '10PM' => __( '10 PM', 'invoicing' ), |
|
| 158 | - '11PM' => __( '11 PM', 'invoicing' ), |
|
| 159 | - ); |
|
| 160 | - |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Retrieves the days in a period |
|
| 165 | - * |
|
| 166 | - */ |
|
| 167 | - public function get_days_in_period( $days ) { |
|
| 168 | - |
|
| 169 | - $return = array(); |
|
| 170 | - $format = 'Y-m-d'; |
|
| 171 | - |
|
| 172 | - if ( $days < 8 ) { |
|
| 173 | - $format = 'D'; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - if ( $days < 32 ) { |
|
| 177 | - $format = 'M j'; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - while ( $days > 0 ) { |
|
| 181 | - |
|
| 182 | - $key = date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
| 183 | - $label = date_i18n( $format, strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
| 184 | - $return[ $key ] = $label; |
|
| 185 | - $days--; |
|
| 186 | - |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - return $return; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Retrieves the weeks in a period |
|
| 194 | - * |
|
| 195 | - */ |
|
| 196 | - public function get_weeks_in_period( $days ) { |
|
| 197 | - |
|
| 198 | - $return = array(); |
|
| 199 | - |
|
| 200 | - while ( $days > 0 ) { |
|
| 201 | - |
|
| 202 | - $key = date( 'W', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
| 203 | - $label = date_i18n( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
| 204 | - $return[ $key ] = $label; |
|
| 205 | - $days--; |
|
| 206 | - |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - return $return; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Displays the report card. |
|
| 214 | - * |
|
| 215 | - */ |
|
| 216 | - public function display() { |
|
| 217 | - ?> |
|
| 123 | + $sql = isset( $ranges[ $range ] ) ? $ranges[ $range ] : $ranges['7_days']; |
|
| 124 | + return apply_filters( 'getpaid_earning_graphs_get_range_sql', $sql, $range ); |
|
| 125 | + |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Retrieves the hours in a day |
|
| 130 | + * |
|
| 131 | + */ |
|
| 132 | + public function get_hours_in_a_day() { |
|
| 133 | + |
|
| 134 | + return array( |
|
| 135 | + '12AM' => __( '12 AM', 'invoicing' ), |
|
| 136 | + '1AM' => __( '1 AM', 'invoicing' ), |
|
| 137 | + '2AM' => __( '2 AM', 'invoicing' ), |
|
| 138 | + '3AM' => __( '3 AM', 'invoicing' ), |
|
| 139 | + '4AM' => __( '4 AM', 'invoicing' ), |
|
| 140 | + '5AM' => __( '5 AM', 'invoicing' ), |
|
| 141 | + '6AM' => __( '6 AM', 'invoicing' ), |
|
| 142 | + '7AM' => __( '7 AM', 'invoicing' ), |
|
| 143 | + '8AM' => __( '8 AM', 'invoicing' ), |
|
| 144 | + '9AM' => __( '9 AM', 'invoicing' ), |
|
| 145 | + '10AM' => __( '10 AM', 'invoicing' ), |
|
| 146 | + '11AM' => __( '11 AM', 'invoicing' ), |
|
| 147 | + '12pm' => __( '12 PM', 'invoicing' ), |
|
| 148 | + '1PM' => __( '1 PM', 'invoicing' ), |
|
| 149 | + '2PM' => __( '2 PM', 'invoicing' ), |
|
| 150 | + '3PM' => __( '3 PM', 'invoicing' ), |
|
| 151 | + '4PM' => __( '4 PM', 'invoicing' ), |
|
| 152 | + '5PM' => __( '5 PM', 'invoicing' ), |
|
| 153 | + '6PM' => __( '6 PM', 'invoicing' ), |
|
| 154 | + '7PM' => __( '7 PM', 'invoicing' ), |
|
| 155 | + '8PM' => __( '8 PM', 'invoicing' ), |
|
| 156 | + '9PM' => __( '9 PM', 'invoicing' ), |
|
| 157 | + '10PM' => __( '10 PM', 'invoicing' ), |
|
| 158 | + '11PM' => __( '11 PM', 'invoicing' ), |
|
| 159 | + ); |
|
| 160 | + |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Retrieves the days in a period |
|
| 165 | + * |
|
| 166 | + */ |
|
| 167 | + public function get_days_in_period( $days ) { |
|
| 168 | + |
|
| 169 | + $return = array(); |
|
| 170 | + $format = 'Y-m-d'; |
|
| 171 | + |
|
| 172 | + if ( $days < 8 ) { |
|
| 173 | + $format = 'D'; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + if ( $days < 32 ) { |
|
| 177 | + $format = 'M j'; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + while ( $days > 0 ) { |
|
| 181 | + |
|
| 182 | + $key = date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
| 183 | + $label = date_i18n( $format, strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
| 184 | + $return[ $key ] = $label; |
|
| 185 | + $days--; |
|
| 186 | + |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + return $return; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Retrieves the weeks in a period |
|
| 194 | + * |
|
| 195 | + */ |
|
| 196 | + public function get_weeks_in_period( $days ) { |
|
| 197 | + |
|
| 198 | + $return = array(); |
|
| 199 | + |
|
| 200 | + while ( $days > 0 ) { |
|
| 201 | + |
|
| 202 | + $key = date( 'W', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
| 203 | + $label = date_i18n( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
| 204 | + $return[ $key ] = $label; |
|
| 205 | + $days--; |
|
| 206 | + |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + return $return; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Displays the report card. |
|
| 214 | + * |
|
| 215 | + */ |
|
| 216 | + public function display() { |
|
| 217 | + ?> |
|
| 218 | 218 | |
| 219 | 219 | <div class="row"> |
| 220 | 220 | <div class="col-12"> |
@@ -228,20 +228,20 @@ discard block |
||
| 228 | 228 | |
| 229 | 229 | <?php |
| 230 | 230 | |
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Prepares the report stats. |
|
| 235 | - * |
|
| 236 | - * Extend this in child classes. |
|
| 237 | - */ |
|
| 238 | - abstract public function prepare_stats(); |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Displays the actual report. |
|
| 242 | - * |
|
| 243 | - * Extend this in child classes. |
|
| 244 | - */ |
|
| 245 | - abstract public function display_stats(); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Prepares the report stats. |
|
| 235 | + * |
|
| 236 | + * Extend this in child classes. |
|
| 237 | + */ |
|
| 238 | + abstract public function prepare_stats(); |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Displays the actual report. |
|
| 242 | + * |
|
| 243 | + * Extend this in child classes. |
|
| 244 | + */ |
|
| 245 | + abstract public function display_stats(); |
|
| 246 | 246 | |
| 247 | 247 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -defined( 'ABSPATH' ) || exit; |
|
| 8 | +defined('ABSPATH') || exit; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * GetPaid_Reports_Abstract_Report Class. |
@@ -32,8 +32,8 @@ discard block |
||
| 32 | 32 | public function get_range() { |
| 33 | 33 | $valid_ranges = $this->get_periods(); |
| 34 | 34 | |
| 35 | - if ( isset( $_GET['date_range'] ) && array_key_exists( $_GET['date_range'], $valid_ranges ) ) { |
|
| 36 | - return sanitize_key( $_GET['date_range'] ); |
|
| 35 | + if (isset($_GET['date_range']) && array_key_exists($_GET['date_range'], $valid_ranges)) { |
|
| 36 | + return sanitize_key($_GET['date_range']); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | return '7_days'; |
@@ -47,34 +47,34 @@ discard block |
||
| 47 | 47 | public function get_periods() { |
| 48 | 48 | |
| 49 | 49 | $periods = array( |
| 50 | - 'today' => __( 'Today', 'invoicing' ), |
|
| 51 | - 'yesterday' => __( 'Yesterday', 'invoicing' ), |
|
| 52 | - '7_days' => __( 'Last 7 days', 'invoicing' ), |
|
| 53 | - '30_days' => __( 'Last 30 days', 'invoicing' ), |
|
| 54 | - '60_days' => __( 'Last 60 days', 'invoicing' ), |
|
| 55 | - '90_days' => __( 'Last 90 days', 'invoicing' ), |
|
| 56 | - '180_days' => __( 'Last 180 days', 'invoicing' ), |
|
| 57 | - '360_days' => __( 'Last 360 days', 'invoicing' ), |
|
| 50 | + 'today' => __('Today', 'invoicing'), |
|
| 51 | + 'yesterday' => __('Yesterday', 'invoicing'), |
|
| 52 | + '7_days' => __('Last 7 days', 'invoicing'), |
|
| 53 | + '30_days' => __('Last 30 days', 'invoicing'), |
|
| 54 | + '60_days' => __('Last 60 days', 'invoicing'), |
|
| 55 | + '90_days' => __('Last 90 days', 'invoicing'), |
|
| 56 | + '180_days' => __('Last 180 days', 'invoicing'), |
|
| 57 | + '360_days' => __('Last 360 days', 'invoicing'), |
|
| 58 | 58 | ); |
| 59 | 59 | |
| 60 | - return apply_filters( 'getpaid_earning_periods', $periods ); |
|
| 60 | + return apply_filters('getpaid_earning_periods', $periods); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * Retrieves the current range's sql. |
| 65 | 65 | * |
| 66 | 66 | */ |
| 67 | - public function get_range_sql( $range, $date = 'CAST(meta.completed_date AS DATE)', $datetime = 'meta.comlpeted_date' ) { |
|
| 67 | + public function get_range_sql($range, $date = 'CAST(meta.completed_date AS DATE)', $datetime = 'meta.comlpeted_date') { |
|
| 68 | 68 | |
| 69 | 69 | // Prepare durations. |
| 70 | - $today = current_time( 'Y-m-d' ); |
|
| 71 | - $yesterday = date( 'Y-m-d', strtotime( '-1 day', current_time( 'timestamp' ) ) ); |
|
| 72 | - $seven_days_ago = date( 'Y-m-d', strtotime( '-7 days', current_time( 'timestamp' ) ) ); |
|
| 73 | - $thirty_days_ago = date( 'Y-m-d', strtotime( '-30 days', current_time( 'timestamp' ) ) ); |
|
| 74 | - $ninety_days_ago = date( 'Y-m-d', strtotime( '-90 days', current_time( 'timestamp' ) ) ); |
|
| 75 | - $sixty_days_ago = date( 'Y-m-d', strtotime( '-60 days', current_time( 'timestamp' ) ) ); |
|
| 76 | - $one_eighty_days_ago = date( 'Y-m-d', strtotime( '-180 days', current_time( 'timestamp' ) ) ); |
|
| 77 | - $three_sixty_days_ago = date( 'Y-m-d', strtotime( '-360 days', current_time( 'timestamp' ) ) ); |
|
| 70 | + $today = current_time('Y-m-d'); |
|
| 71 | + $yesterday = date('Y-m-d', strtotime('-1 day', current_time('timestamp'))); |
|
| 72 | + $seven_days_ago = date('Y-m-d', strtotime('-7 days', current_time('timestamp'))); |
|
| 73 | + $thirty_days_ago = date('Y-m-d', strtotime('-30 days', current_time('timestamp'))); |
|
| 74 | + $ninety_days_ago = date('Y-m-d', strtotime('-90 days', current_time('timestamp'))); |
|
| 75 | + $sixty_days_ago = date('Y-m-d', strtotime('-60 days', current_time('timestamp'))); |
|
| 76 | + $one_eighty_days_ago = date('Y-m-d', strtotime('-180 days', current_time('timestamp'))); |
|
| 77 | + $three_sixty_days_ago = date('Y-m-d', strtotime('-360 days', current_time('timestamp'))); |
|
| 78 | 78 | |
| 79 | 79 | $ranges = array( |
| 80 | 80 | |
@@ -120,8 +120,8 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | ); |
| 122 | 122 | |
| 123 | - $sql = isset( $ranges[ $range ] ) ? $ranges[ $range ] : $ranges['7_days']; |
|
| 124 | - return apply_filters( 'getpaid_earning_graphs_get_range_sql', $sql, $range ); |
|
| 123 | + $sql = isset($ranges[$range]) ? $ranges[$range] : $ranges['7_days']; |
|
| 124 | + return apply_filters('getpaid_earning_graphs_get_range_sql', $sql, $range); |
|
| 125 | 125 | |
| 126 | 126 | } |
| 127 | 127 | |
@@ -132,30 +132,30 @@ discard block |
||
| 132 | 132 | public function get_hours_in_a_day() { |
| 133 | 133 | |
| 134 | 134 | return array( |
| 135 | - '12AM' => __( '12 AM', 'invoicing' ), |
|
| 136 | - '1AM' => __( '1 AM', 'invoicing' ), |
|
| 137 | - '2AM' => __( '2 AM', 'invoicing' ), |
|
| 138 | - '3AM' => __( '3 AM', 'invoicing' ), |
|
| 139 | - '4AM' => __( '4 AM', 'invoicing' ), |
|
| 140 | - '5AM' => __( '5 AM', 'invoicing' ), |
|
| 141 | - '6AM' => __( '6 AM', 'invoicing' ), |
|
| 142 | - '7AM' => __( '7 AM', 'invoicing' ), |
|
| 143 | - '8AM' => __( '8 AM', 'invoicing' ), |
|
| 144 | - '9AM' => __( '9 AM', 'invoicing' ), |
|
| 145 | - '10AM' => __( '10 AM', 'invoicing' ), |
|
| 146 | - '11AM' => __( '11 AM', 'invoicing' ), |
|
| 147 | - '12pm' => __( '12 PM', 'invoicing' ), |
|
| 148 | - '1PM' => __( '1 PM', 'invoicing' ), |
|
| 149 | - '2PM' => __( '2 PM', 'invoicing' ), |
|
| 150 | - '3PM' => __( '3 PM', 'invoicing' ), |
|
| 151 | - '4PM' => __( '4 PM', 'invoicing' ), |
|
| 152 | - '5PM' => __( '5 PM', 'invoicing' ), |
|
| 153 | - '6PM' => __( '6 PM', 'invoicing' ), |
|
| 154 | - '7PM' => __( '7 PM', 'invoicing' ), |
|
| 155 | - '8PM' => __( '8 PM', 'invoicing' ), |
|
| 156 | - '9PM' => __( '9 PM', 'invoicing' ), |
|
| 157 | - '10PM' => __( '10 PM', 'invoicing' ), |
|
| 158 | - '11PM' => __( '11 PM', 'invoicing' ), |
|
| 135 | + '12AM' => __('12 AM', 'invoicing'), |
|
| 136 | + '1AM' => __('1 AM', 'invoicing'), |
|
| 137 | + '2AM' => __('2 AM', 'invoicing'), |
|
| 138 | + '3AM' => __('3 AM', 'invoicing'), |
|
| 139 | + '4AM' => __('4 AM', 'invoicing'), |
|
| 140 | + '5AM' => __('5 AM', 'invoicing'), |
|
| 141 | + '6AM' => __('6 AM', 'invoicing'), |
|
| 142 | + '7AM' => __('7 AM', 'invoicing'), |
|
| 143 | + '8AM' => __('8 AM', 'invoicing'), |
|
| 144 | + '9AM' => __('9 AM', 'invoicing'), |
|
| 145 | + '10AM' => __('10 AM', 'invoicing'), |
|
| 146 | + '11AM' => __('11 AM', 'invoicing'), |
|
| 147 | + '12pm' => __('12 PM', 'invoicing'), |
|
| 148 | + '1PM' => __('1 PM', 'invoicing'), |
|
| 149 | + '2PM' => __('2 PM', 'invoicing'), |
|
| 150 | + '3PM' => __('3 PM', 'invoicing'), |
|
| 151 | + '4PM' => __('4 PM', 'invoicing'), |
|
| 152 | + '5PM' => __('5 PM', 'invoicing'), |
|
| 153 | + '6PM' => __('6 PM', 'invoicing'), |
|
| 154 | + '7PM' => __('7 PM', 'invoicing'), |
|
| 155 | + '8PM' => __('8 PM', 'invoicing'), |
|
| 156 | + '9PM' => __('9 PM', 'invoicing'), |
|
| 157 | + '10PM' => __('10 PM', 'invoicing'), |
|
| 158 | + '11PM' => __('11 PM', 'invoicing'), |
|
| 159 | 159 | ); |
| 160 | 160 | |
| 161 | 161 | } |
@@ -164,24 +164,24 @@ discard block |
||
| 164 | 164 | * Retrieves the days in a period |
| 165 | 165 | * |
| 166 | 166 | */ |
| 167 | - public function get_days_in_period( $days ) { |
|
| 167 | + public function get_days_in_period($days) { |
|
| 168 | 168 | |
| 169 | 169 | $return = array(); |
| 170 | 170 | $format = 'Y-m-d'; |
| 171 | 171 | |
| 172 | - if ( $days < 8 ) { |
|
| 172 | + if ($days < 8) { |
|
| 173 | 173 | $format = 'D'; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - if ( $days < 32 ) { |
|
| 176 | + if ($days < 32) { |
|
| 177 | 177 | $format = 'M j'; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - while ( $days > 0 ) { |
|
| 180 | + while ($days > 0) { |
|
| 181 | 181 | |
| 182 | - $key = date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
| 183 | - $label = date_i18n( $format, strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
| 184 | - $return[ $key ] = $label; |
|
| 182 | + $key = date('Y-m-d', strtotime("-$days days", current_time('timestamp'))); |
|
| 183 | + $label = date_i18n($format, strtotime("-$days days", current_time('timestamp'))); |
|
| 184 | + $return[$key] = $label; |
|
| 185 | 185 | $days--; |
| 186 | 186 | |
| 187 | 187 | } |
@@ -193,15 +193,15 @@ discard block |
||
| 193 | 193 | * Retrieves the weeks in a period |
| 194 | 194 | * |
| 195 | 195 | */ |
| 196 | - public function get_weeks_in_period( $days ) { |
|
| 196 | + public function get_weeks_in_period($days) { |
|
| 197 | 197 | |
| 198 | 198 | $return = array(); |
| 199 | 199 | |
| 200 | - while ( $days > 0 ) { |
|
| 200 | + while ($days > 0) { |
|
| 201 | 201 | |
| 202 | - $key = date( 'W', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
| 203 | - $label = date_i18n( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ); |
|
| 204 | - $return[ $key ] = $label; |
|
| 202 | + $key = date('W', strtotime("-$days days", current_time('timestamp'))); |
|
| 203 | + $label = date_i18n('Y-m-d', strtotime("-$days days", current_time('timestamp'))); |
|
| 204 | + $return[$key] = $label; |
|
| 205 | 205 | $days--; |
| 206 | 206 | |
| 207 | 207 | } |
@@ -12,23 +12,23 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Reports_Report_Items extends GetPaid_Reports_Abstract_Report { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var string |
|
| 17 | - */ |
|
| 18 | - public $field = 'item_name'; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Retrieves the earning sql. |
|
| 22 | - * |
|
| 23 | - */ |
|
| 24 | - public function get_sql( $range ) { |
|
| 25 | - global $wpdb; |
|
| 26 | - |
|
| 27 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 28 | - $table2 = $wpdb->prefix . 'getpaid_invoice_items'; |
|
| 29 | - $clauses = $this->get_range_sql( $range ); |
|
| 30 | - |
|
| 31 | - $sql = "SELECT |
|
| 15 | + /** |
|
| 16 | + * @var string |
|
| 17 | + */ |
|
| 18 | + public $field = 'item_name'; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Retrieves the earning sql. |
|
| 22 | + * |
|
| 23 | + */ |
|
| 24 | + public function get_sql( $range ) { |
|
| 25 | + global $wpdb; |
|
| 26 | + |
|
| 27 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 28 | + $table2 = $wpdb->prefix . 'getpaid_invoice_items'; |
|
| 29 | + $clauses = $this->get_range_sql( $range ); |
|
| 30 | + |
|
| 31 | + $sql = "SELECT |
|
| 32 | 32 | item.item_name AS item_name, |
| 33 | 33 | item.item_id AS item_id, |
| 34 | 34 | SUM(price) as total |
@@ -43,91 +43,91 @@ discard block |
||
| 43 | 43 | ORDER BY total DESC |
| 44 | 44 | "; |
| 45 | 45 | |
| 46 | - return apply_filters( 'getpaid_items_graphs_get_sql', $sql, $range ); |
|
| 46 | + return apply_filters( 'getpaid_items_graphs_get_sql', $sql, $range ); |
|
| 47 | 47 | |
| 48 | - } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Prepares the report stats. |
|
| 52 | - * |
|
| 53 | - */ |
|
| 54 | - public function prepare_stats() { |
|
| 55 | - global $wpdb; |
|
| 56 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 57 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
| 58 | - } |
|
| 50 | + /** |
|
| 51 | + * Prepares the report stats. |
|
| 52 | + * |
|
| 53 | + */ |
|
| 54 | + public function prepare_stats() { |
|
| 55 | + global $wpdb; |
|
| 56 | + $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 57 | + $this->stats = $this->normalize_stats( $this->stats ); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Normalizes the report stats. |
|
| 62 | - * |
|
| 63 | - */ |
|
| 64 | - public function normalize_stats( $stats ) { |
|
| 65 | - $normalized = array(); |
|
| 66 | - $others = 0; |
|
| 67 | - $did = 0; |
|
| 60 | + /** |
|
| 61 | + * Normalizes the report stats. |
|
| 62 | + * |
|
| 63 | + */ |
|
| 64 | + public function normalize_stats( $stats ) { |
|
| 65 | + $normalized = array(); |
|
| 66 | + $others = 0; |
|
| 67 | + $did = 0; |
|
| 68 | 68 | |
| 69 | - foreach ( $stats as $stat ) { |
|
| 69 | + foreach ( $stats as $stat ) { |
|
| 70 | 70 | |
| 71 | - if ( $did > 4 ) { |
|
| 71 | + if ( $did > 4 ) { |
|
| 72 | 72 | |
| 73 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
| 73 | + $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
| 74 | 74 | |
| 75 | - } else { |
|
| 75 | + } else { |
|
| 76 | 76 | |
| 77 | - $normalized[] = array( |
|
| 78 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
| 79 | - 'item_name' => strip_tags( $stat->item_name ), |
|
| 80 | - ); |
|
| 77 | + $normalized[] = array( |
|
| 78 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
| 79 | + 'item_name' => strip_tags( $stat->item_name ), |
|
| 80 | + ); |
|
| 81 | 81 | |
| 82 | - } |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - $did++; |
|
| 85 | - } |
|
| 84 | + $did++; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - if ( $others > 0 ) { |
|
| 87 | + if ( $others > 0 ) { |
|
| 88 | 88 | |
| 89 | - $normalized[] = array( |
|
| 90 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
| 91 | - 'item_name' => esc_html__( 'Others', 'invoicing' ), |
|
| 92 | - ); |
|
| 89 | + $normalized[] = array( |
|
| 90 | + 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
| 91 | + 'item_name' => esc_html__( 'Others', 'invoicing' ), |
|
| 92 | + ); |
|
| 93 | 93 | |
| 94 | - } |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - return $normalized; |
|
| 97 | - } |
|
| 96 | + return $normalized; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Retrieves report data. |
|
| 101 | - * |
|
| 102 | - */ |
|
| 103 | - public function get_data() { |
|
| 99 | + /** |
|
| 100 | + * Retrieves report data. |
|
| 101 | + * |
|
| 102 | + */ |
|
| 103 | + public function get_data() { |
|
| 104 | 104 | |
| 105 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
| 106 | - $colors = array( '#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3' ); |
|
| 105 | + $data = wp_list_pluck( $this->stats, 'total' ); |
|
| 106 | + $colors = array( '#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3' ); |
|
| 107 | 107 | |
| 108 | - shuffle( $colors ); |
|
| 108 | + shuffle( $colors ); |
|
| 109 | 109 | |
| 110 | - return array( |
|
| 111 | - 'data' => $data, |
|
| 112 | - 'backgroundColor' => $colors, |
|
| 113 | - ); |
|
| 110 | + return array( |
|
| 111 | + 'data' => $data, |
|
| 112 | + 'backgroundColor' => $colors, |
|
| 113 | + ); |
|
| 114 | 114 | |
| 115 | - } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Retrieves report labels. |
|
| 119 | - * |
|
| 120 | - */ |
|
| 121 | - public function get_labels() { |
|
| 122 | - return wp_list_pluck( $this->stats, 'item_name' ); |
|
| 123 | - } |
|
| 117 | + /** |
|
| 118 | + * Retrieves report labels. |
|
| 119 | + * |
|
| 120 | + */ |
|
| 121 | + public function get_labels() { |
|
| 122 | + return wp_list_pluck( $this->stats, 'item_name' ); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * Displays the actual report. |
|
| 127 | - * |
|
| 128 | - */ |
|
| 129 | - public function display_stats() { |
|
| 130 | - ?> |
|
| 125 | + /** |
|
| 126 | + * Displays the actual report. |
|
| 127 | + * |
|
| 128 | + */ |
|
| 129 | + public function display_stats() { |
|
| 130 | + ?> |
|
| 131 | 131 | |
| 132 | 132 | <canvas id="getpaid-chartjs-earnings-items"></canvas> |
| 133 | 133 | |
@@ -156,6 +156,6 @@ discard block |
||
| 156 | 156 | </script> |
| 157 | 157 | |
| 158 | 158 | <?php |
| 159 | - } |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | 161 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -defined( 'ABSPATH' ) || exit; |
|
| 8 | +defined('ABSPATH') || exit; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * GetPaid_Reports_Report_Items Class. |
@@ -21,12 +21,12 @@ discard block |
||
| 21 | 21 | * Retrieves the earning sql. |
| 22 | 22 | * |
| 23 | 23 | */ |
| 24 | - public function get_sql( $range ) { |
|
| 24 | + public function get_sql($range) { |
|
| 25 | 25 | global $wpdb; |
| 26 | 26 | |
| 27 | 27 | $table = $wpdb->prefix . 'getpaid_invoices'; |
| 28 | 28 | $table2 = $wpdb->prefix . 'getpaid_invoice_items'; |
| 29 | - $clauses = $this->get_range_sql( $range ); |
|
| 29 | + $clauses = $this->get_range_sql($range); |
|
| 30 | 30 | |
| 31 | 31 | $sql = "SELECT |
| 32 | 32 | item.item_name AS item_name, |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | ORDER BY total DESC |
| 44 | 44 | "; |
| 45 | 45 | |
| 46 | - return apply_filters( 'getpaid_items_graphs_get_sql', $sql, $range ); |
|
| 46 | + return apply_filters('getpaid_items_graphs_get_sql', $sql, $range); |
|
| 47 | 47 | |
| 48 | 48 | } |
| 49 | 49 | |
@@ -53,30 +53,30 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function prepare_stats() { |
| 55 | 55 | global $wpdb; |
| 56 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 57 | - $this->stats = $this->normalize_stats( $this->stats ); |
|
| 56 | + $this->stats = $wpdb->get_results($this->get_sql($this->get_range())); |
|
| 57 | + $this->stats = $this->normalize_stats($this->stats); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * Normalizes the report stats. |
| 62 | 62 | * |
| 63 | 63 | */ |
| 64 | - public function normalize_stats( $stats ) { |
|
| 64 | + public function normalize_stats($stats) { |
|
| 65 | 65 | $normalized = array(); |
| 66 | 66 | $others = 0; |
| 67 | 67 | $did = 0; |
| 68 | 68 | |
| 69 | - foreach ( $stats as $stat ) { |
|
| 69 | + foreach ($stats as $stat) { |
|
| 70 | 70 | |
| 71 | - if ( $did > 4 ) { |
|
| 71 | + if ($did > 4) { |
|
| 72 | 72 | |
| 73 | - $others += wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ); |
|
| 73 | + $others += wpinv_round_amount(wpinv_sanitize_amount($stat->total)); |
|
| 74 | 74 | |
| 75 | 75 | } else { |
| 76 | 76 | |
| 77 | 77 | $normalized[] = array( |
| 78 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $stat->total ) ), |
|
| 79 | - 'item_name' => strip_tags( $stat->item_name ), |
|
| 78 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($stat->total)), |
|
| 79 | + 'item_name' => strip_tags($stat->item_name), |
|
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | 82 | } |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | $did++; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - if ( $others > 0 ) { |
|
| 87 | + if ($others > 0) { |
|
| 88 | 88 | |
| 89 | 89 | $normalized[] = array( |
| 90 | - 'total' => wpinv_round_amount( wpinv_sanitize_amount( $others ) ), |
|
| 91 | - 'item_name' => esc_html__( 'Others', 'invoicing' ), |
|
| 90 | + 'total' => wpinv_round_amount(wpinv_sanitize_amount($others)), |
|
| 91 | + 'item_name' => esc_html__('Others', 'invoicing'), |
|
| 92 | 92 | ); |
| 93 | 93 | |
| 94 | 94 | } |
@@ -102,10 +102,10 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | public function get_data() { |
| 104 | 104 | |
| 105 | - $data = wp_list_pluck( $this->stats, 'total' ); |
|
| 106 | - $colors = array( '#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3' ); |
|
| 105 | + $data = wp_list_pluck($this->stats, 'total'); |
|
| 106 | + $colors = array('#009688', '#4caf50', '#8bc34a', '#00bcd4', '#03a9f4', '#2196f3'); |
|
| 107 | 107 | |
| 108 | - shuffle( $colors ); |
|
| 108 | + shuffle($colors); |
|
| 109 | 109 | |
| 110 | 110 | return array( |
| 111 | 111 | 'data' => $data, |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * |
| 120 | 120 | */ |
| 121 | 121 | public function get_labels() { |
| 122 | - return wp_list_pluck( $this->stats, 'item_name' ); |
|
| 122 | + return wp_list_pluck($this->stats, 'item_name'); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -140,8 +140,8 @@ discard block |
||
| 140 | 140 | { |
| 141 | 141 | type: 'doughnut', |
| 142 | 142 | data: { |
| 143 | - 'labels': <?php echo wp_json_encode( wp_kses_post_deep( $this->get_labels() ) ); ?>, |
|
| 144 | - 'datasets': [ <?php echo wp_json_encode( wp_kses_post_deep( $this->get_data() ) ); ?> ] |
|
| 143 | + 'labels': <?php echo wp_json_encode(wp_kses_post_deep($this->get_labels())); ?>, |
|
| 144 | + 'datasets': [ <?php echo wp_json_encode(wp_kses_post_deep($this->get_data())); ?> ] |
|
| 145 | 145 | }, |
| 146 | 146 | options: { |
| 147 | 147 | legend: { |
@@ -12,43 +12,43 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Reports_Report_Earnings extends GetPaid_Reports_Abstract_Report { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Retrieves the earning graphs. |
|
| 17 | - * |
|
| 18 | - */ |
|
| 19 | - public function get_graphs() { |
|
| 15 | + /** |
|
| 16 | + * Retrieves the earning graphs. |
|
| 17 | + * |
|
| 18 | + */ |
|
| 19 | + public function get_graphs() { |
|
| 20 | 20 | |
| 21 | - $graphs = array( |
|
| 21 | + $graphs = array( |
|
| 22 | 22 | |
| 23 | 23 | 'total' => __( 'Earnings', 'invoicing' ), |
| 24 | 24 | 'discount' => __( 'Discount', 'invoicing' ), |
| 25 | - 'fees_total' => __( 'Fees', 'invoicing' ), |
|
| 26 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
| 25 | + 'fees_total' => __( 'Fees', 'invoicing' ), |
|
| 26 | + 'tax' => __( 'Tax', 'invoicing' ), |
|
| 27 | 27 | |
| 28 | - ); |
|
| 28 | + ); |
|
| 29 | 29 | |
| 30 | - return apply_filters( 'getpaid_earning_graphs', $graphs ); |
|
| 30 | + return apply_filters( 'getpaid_earning_graphs', $graphs ); |
|
| 31 | 31 | |
| 32 | - } |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Retrieves the earning sql. |
|
| 36 | - * |
|
| 37 | - */ |
|
| 38 | - public function get_sql( $range ) { |
|
| 39 | - global $wpdb; |
|
| 34 | + /** |
|
| 35 | + * Retrieves the earning sql. |
|
| 36 | + * |
|
| 37 | + */ |
|
| 38 | + public function get_sql( $range ) { |
|
| 39 | + global $wpdb; |
|
| 40 | 40 | |
| 41 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 42 | - $clauses = $this->get_range_sql( $range ); |
|
| 43 | - $graphs = array_keys( $this->get_graphs() ); |
|
| 44 | - $graphs_sql = array(); |
|
| 41 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 42 | + $clauses = $this->get_range_sql( $range ); |
|
| 43 | + $graphs = array_keys( $this->get_graphs() ); |
|
| 44 | + $graphs_sql = array(); |
|
| 45 | 45 | |
| 46 | - foreach ( $graphs as $graph ) { |
|
| 47 | - $graphs_sql[] = "SUM( meta.$graph ) AS $graph"; |
|
| 48 | - } |
|
| 46 | + foreach ( $graphs as $graph ) { |
|
| 47 | + $graphs_sql[] = "SUM( meta.$graph ) AS $graph"; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - $graphs_sql = implode( ', ', $graphs_sql ); |
|
| 51 | - $sql = "SELECT {$clauses[0]} AS completed_date, $graphs_sql |
|
| 50 | + $graphs_sql = implode( ', ', $graphs_sql ); |
|
| 51 | + $sql = "SELECT {$clauses[0]} AS completed_date, $graphs_sql |
|
| 52 | 52 | FROM $wpdb->posts |
| 53 | 53 | LEFT JOIN $table as meta ON meta.post_id = $wpdb->posts.ID |
| 54 | 54 | WHERE meta.post_id IS NOT NULL |
@@ -58,94 +58,94 @@ discard block |
||
| 58 | 58 | GROUP BY {$clauses[0]} |
| 59 | 59 | "; |
| 60 | 60 | |
| 61 | - return apply_filters( 'getpaid_earning_graphs_get_sql', $sql, $range ); |
|
| 62 | - |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Prepares the report stats. |
|
| 67 | - * |
|
| 68 | - */ |
|
| 69 | - public function prepare_stats() { |
|
| 70 | - global $wpdb; |
|
| 71 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Retrieves report labels. |
|
| 76 | - * |
|
| 77 | - */ |
|
| 78 | - public function get_labels( $range ) { |
|
| 79 | - |
|
| 80 | - $labels = array( |
|
| 81 | - 'today' => $this->get_hours_in_a_day(), |
|
| 82 | - 'yesterday' => $this->get_hours_in_a_day(), |
|
| 83 | - '7_days' => $this->get_days_in_period( 7 ), |
|
| 84 | - '30_days' => $this->get_days_in_period( 30 ), |
|
| 85 | - '60_days' => $this->get_days_in_period( 60 ), |
|
| 86 | - '90_days' => $this->get_weeks_in_period( 90 ), |
|
| 87 | - '180_days' => $this->get_weeks_in_period( 180 ), |
|
| 88 | - '360_days' => $this->get_weeks_in_period( 360 ), |
|
| 89 | - ); |
|
| 90 | - |
|
| 91 | - $label = isset( $labels[ $range ] ) ? $labels[ $range ] : $labels['7_days']; |
|
| 92 | - return apply_filters( 'getpaid_earning_graphs_get_labels', $label, $range ); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Retrieves report datasets. |
|
| 97 | - * |
|
| 98 | - */ |
|
| 99 | - public function get_datasets( $labels ) { |
|
| 100 | - |
|
| 101 | - $datasets = array(); |
|
| 102 | - |
|
| 103 | - foreach ( $this->get_graphs() as $key => $label ) { |
|
| 104 | - $datasets[ $key ] = array( |
|
| 105 | - 'label' => $label, |
|
| 106 | - 'data' => $this->get_data( $key, $labels ), |
|
| 107 | - ); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - return apply_filters( 'getpaid_earning_graphs_get_datasets', $datasets, $labels ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Retrieves report data. |
|
| 115 | - * |
|
| 116 | - */ |
|
| 117 | - public function get_data( $key, $labels ) { |
|
| 118 | - |
|
| 119 | - $data = wp_list_pluck( $this->stats, $key, 'completed_date' ); |
|
| 120 | - $prepared = array(); |
|
| 121 | - |
|
| 122 | - foreach ( $labels as $label ) { |
|
| 123 | - |
|
| 124 | - $value = 0; |
|
| 125 | - if ( isset( $data[ $label ] ) ) { |
|
| 126 | - $value = wpinv_round_amount( wpinv_sanitize_amount( $data[ $label ] ) ); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - $prepared[] = $value; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - return apply_filters( 'getpaid_earning_graphs_get_data', $prepared, $key, $labels ); |
|
| 133 | - |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Displays the report card. |
|
| 138 | - * |
|
| 139 | - */ |
|
| 140 | - public function display() { |
|
| 141 | - |
|
| 142 | - $labels = $this->get_labels( $this->get_range() ); |
|
| 143 | - $chart_data = array( |
|
| 144 | - 'labels' => array_values( $labels ), |
|
| 145 | - 'datasets' => $this->get_datasets( array_keys( $labels ) ), |
|
| 146 | - ); |
|
| 147 | - |
|
| 148 | - ?> |
|
| 61 | + return apply_filters( 'getpaid_earning_graphs_get_sql', $sql, $range ); |
|
| 62 | + |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Prepares the report stats. |
|
| 67 | + * |
|
| 68 | + */ |
|
| 69 | + public function prepare_stats() { |
|
| 70 | + global $wpdb; |
|
| 71 | + $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Retrieves report labels. |
|
| 76 | + * |
|
| 77 | + */ |
|
| 78 | + public function get_labels( $range ) { |
|
| 79 | + |
|
| 80 | + $labels = array( |
|
| 81 | + 'today' => $this->get_hours_in_a_day(), |
|
| 82 | + 'yesterday' => $this->get_hours_in_a_day(), |
|
| 83 | + '7_days' => $this->get_days_in_period( 7 ), |
|
| 84 | + '30_days' => $this->get_days_in_period( 30 ), |
|
| 85 | + '60_days' => $this->get_days_in_period( 60 ), |
|
| 86 | + '90_days' => $this->get_weeks_in_period( 90 ), |
|
| 87 | + '180_days' => $this->get_weeks_in_period( 180 ), |
|
| 88 | + '360_days' => $this->get_weeks_in_period( 360 ), |
|
| 89 | + ); |
|
| 90 | + |
|
| 91 | + $label = isset( $labels[ $range ] ) ? $labels[ $range ] : $labels['7_days']; |
|
| 92 | + return apply_filters( 'getpaid_earning_graphs_get_labels', $label, $range ); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Retrieves report datasets. |
|
| 97 | + * |
|
| 98 | + */ |
|
| 99 | + public function get_datasets( $labels ) { |
|
| 100 | + |
|
| 101 | + $datasets = array(); |
|
| 102 | + |
|
| 103 | + foreach ( $this->get_graphs() as $key => $label ) { |
|
| 104 | + $datasets[ $key ] = array( |
|
| 105 | + 'label' => $label, |
|
| 106 | + 'data' => $this->get_data( $key, $labels ), |
|
| 107 | + ); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + return apply_filters( 'getpaid_earning_graphs_get_datasets', $datasets, $labels ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Retrieves report data. |
|
| 115 | + * |
|
| 116 | + */ |
|
| 117 | + public function get_data( $key, $labels ) { |
|
| 118 | + |
|
| 119 | + $data = wp_list_pluck( $this->stats, $key, 'completed_date' ); |
|
| 120 | + $prepared = array(); |
|
| 121 | + |
|
| 122 | + foreach ( $labels as $label ) { |
|
| 123 | + |
|
| 124 | + $value = 0; |
|
| 125 | + if ( isset( $data[ $label ] ) ) { |
|
| 126 | + $value = wpinv_round_amount( wpinv_sanitize_amount( $data[ $label ] ) ); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + $prepared[] = $value; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + return apply_filters( 'getpaid_earning_graphs_get_data', $prepared, $key, $labels ); |
|
| 133 | + |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Displays the report card. |
|
| 138 | + * |
|
| 139 | + */ |
|
| 140 | + public function display() { |
|
| 141 | + |
|
| 142 | + $labels = $this->get_labels( $this->get_range() ); |
|
| 143 | + $chart_data = array( |
|
| 144 | + 'labels' => array_values( $labels ), |
|
| 145 | + 'datasets' => $this->get_datasets( array_keys( $labels ) ), |
|
| 146 | + ); |
|
| 147 | + |
|
| 148 | + ?> |
|
| 149 | 149 | |
| 150 | 150 | <?php foreach ( $chart_data['datasets'] as $key => $dataset ) : ?> |
| 151 | 151 | <div class="row mb-4"> |
@@ -165,15 +165,15 @@ discard block |
||
| 165 | 165 | |
| 166 | 166 | <?php |
| 167 | 167 | |
| 168 | - } |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * Displays the actual report. |
|
| 172 | - * |
|
| 173 | - */ |
|
| 174 | - public function display_graph( $key, $dataset, $labels ) { |
|
| 170 | + /** |
|
| 171 | + * Displays the actual report. |
|
| 172 | + * |
|
| 173 | + */ |
|
| 174 | + public function display_graph( $key, $dataset, $labels ) { |
|
| 175 | 175 | |
| 176 | - ?> |
|
| 176 | + ?> |
|
| 177 | 177 | |
| 178 | 178 | <canvas id="getpaid-chartjs-earnings-<?php echo esc_attr( $key ); ?>"></canvas> |
| 179 | 179 | |
@@ -223,20 +223,20 @@ discard block |
||
| 223 | 223 | </script> |
| 224 | 224 | |
| 225 | 225 | <?php |
| 226 | - } |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - /** |
|
| 229 | - * Displays the actual report. |
|
| 230 | - * |
|
| 231 | - */ |
|
| 232 | - public function display_stats() {} |
|
| 228 | + /** |
|
| 229 | + * Displays the actual report. |
|
| 230 | + * |
|
| 231 | + */ |
|
| 232 | + public function display_stats() {} |
|
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * Displays the range selector. |
|
| 236 | - * |
|
| 237 | - */ |
|
| 238 | - public function display_range_selector() { |
|
| 234 | + /** |
|
| 235 | + * Displays the range selector. |
|
| 236 | + * |
|
| 237 | + */ |
|
| 238 | + public function display_range_selector() { |
|
| 239 | 239 | |
| 240 | - } |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | 242 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -defined( 'ABSPATH' ) || exit; |
|
| 8 | +defined('ABSPATH') || exit; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * GetPaid_Reports_Report_Earnings Class. |
@@ -20,14 +20,14 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | $graphs = array( |
| 22 | 22 | |
| 23 | - 'total' => __( 'Earnings', 'invoicing' ), |
|
| 24 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
| 25 | - 'fees_total' => __( 'Fees', 'invoicing' ), |
|
| 26 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
| 23 | + 'total' => __('Earnings', 'invoicing'), |
|
| 24 | + 'discount' => __('Discount', 'invoicing'), |
|
| 25 | + 'fees_total' => __('Fees', 'invoicing'), |
|
| 26 | + 'tax' => __('Tax', 'invoicing'), |
|
| 27 | 27 | |
| 28 | 28 | ); |
| 29 | 29 | |
| 30 | - return apply_filters( 'getpaid_earning_graphs', $graphs ); |
|
| 30 | + return apply_filters('getpaid_earning_graphs', $graphs); |
|
| 31 | 31 | |
| 32 | 32 | } |
| 33 | 33 | |
@@ -35,19 +35,19 @@ discard block |
||
| 35 | 35 | * Retrieves the earning sql. |
| 36 | 36 | * |
| 37 | 37 | */ |
| 38 | - public function get_sql( $range ) { |
|
| 38 | + public function get_sql($range) { |
|
| 39 | 39 | global $wpdb; |
| 40 | 40 | |
| 41 | 41 | $table = $wpdb->prefix . 'getpaid_invoices'; |
| 42 | - $clauses = $this->get_range_sql( $range ); |
|
| 43 | - $graphs = array_keys( $this->get_graphs() ); |
|
| 42 | + $clauses = $this->get_range_sql($range); |
|
| 43 | + $graphs = array_keys($this->get_graphs()); |
|
| 44 | 44 | $graphs_sql = array(); |
| 45 | 45 | |
| 46 | - foreach ( $graphs as $graph ) { |
|
| 46 | + foreach ($graphs as $graph) { |
|
| 47 | 47 | $graphs_sql[] = "SUM( meta.$graph ) AS $graph"; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - $graphs_sql = implode( ', ', $graphs_sql ); |
|
| 50 | + $graphs_sql = implode(', ', $graphs_sql); |
|
| 51 | 51 | $sql = "SELECT {$clauses[0]} AS completed_date, $graphs_sql |
| 52 | 52 | FROM $wpdb->posts |
| 53 | 53 | LEFT JOIN $table as meta ON meta.post_id = $wpdb->posts.ID |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | GROUP BY {$clauses[0]} |
| 59 | 59 | "; |
| 60 | 60 | |
| 61 | - return apply_filters( 'getpaid_earning_graphs_get_sql', $sql, $range ); |
|
| 61 | + return apply_filters('getpaid_earning_graphs_get_sql', $sql, $range); |
|
| 62 | 62 | |
| 63 | 63 | } |
| 64 | 64 | |
@@ -68,68 +68,68 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | public function prepare_stats() { |
| 70 | 70 | global $wpdb; |
| 71 | - $this->stats = $wpdb->get_results( $this->get_sql( $this->get_range() ) ); |
|
| 71 | + $this->stats = $wpdb->get_results($this->get_sql($this->get_range())); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * Retrieves report labels. |
| 76 | 76 | * |
| 77 | 77 | */ |
| 78 | - public function get_labels( $range ) { |
|
| 78 | + public function get_labels($range) { |
|
| 79 | 79 | |
| 80 | 80 | $labels = array( |
| 81 | 81 | 'today' => $this->get_hours_in_a_day(), |
| 82 | 82 | 'yesterday' => $this->get_hours_in_a_day(), |
| 83 | - '7_days' => $this->get_days_in_period( 7 ), |
|
| 84 | - '30_days' => $this->get_days_in_period( 30 ), |
|
| 85 | - '60_days' => $this->get_days_in_period( 60 ), |
|
| 86 | - '90_days' => $this->get_weeks_in_period( 90 ), |
|
| 87 | - '180_days' => $this->get_weeks_in_period( 180 ), |
|
| 88 | - '360_days' => $this->get_weeks_in_period( 360 ), |
|
| 83 | + '7_days' => $this->get_days_in_period(7), |
|
| 84 | + '30_days' => $this->get_days_in_period(30), |
|
| 85 | + '60_days' => $this->get_days_in_period(60), |
|
| 86 | + '90_days' => $this->get_weeks_in_period(90), |
|
| 87 | + '180_days' => $this->get_weeks_in_period(180), |
|
| 88 | + '360_days' => $this->get_weeks_in_period(360), |
|
| 89 | 89 | ); |
| 90 | 90 | |
| 91 | - $label = isset( $labels[ $range ] ) ? $labels[ $range ] : $labels['7_days']; |
|
| 92 | - return apply_filters( 'getpaid_earning_graphs_get_labels', $label, $range ); |
|
| 91 | + $label = isset($labels[$range]) ? $labels[$range] : $labels['7_days']; |
|
| 92 | + return apply_filters('getpaid_earning_graphs_get_labels', $label, $range); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | 96 | * Retrieves report datasets. |
| 97 | 97 | * |
| 98 | 98 | */ |
| 99 | - public function get_datasets( $labels ) { |
|
| 99 | + public function get_datasets($labels) { |
|
| 100 | 100 | |
| 101 | 101 | $datasets = array(); |
| 102 | 102 | |
| 103 | - foreach ( $this->get_graphs() as $key => $label ) { |
|
| 104 | - $datasets[ $key ] = array( |
|
| 103 | + foreach ($this->get_graphs() as $key => $label) { |
|
| 104 | + $datasets[$key] = array( |
|
| 105 | 105 | 'label' => $label, |
| 106 | - 'data' => $this->get_data( $key, $labels ), |
|
| 106 | + 'data' => $this->get_data($key, $labels), |
|
| 107 | 107 | ); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - return apply_filters( 'getpaid_earning_graphs_get_datasets', $datasets, $labels ); |
|
| 110 | + return apply_filters('getpaid_earning_graphs_get_datasets', $datasets, $labels); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
| 114 | 114 | * Retrieves report data. |
| 115 | 115 | * |
| 116 | 116 | */ |
| 117 | - public function get_data( $key, $labels ) { |
|
| 117 | + public function get_data($key, $labels) { |
|
| 118 | 118 | |
| 119 | - $data = wp_list_pluck( $this->stats, $key, 'completed_date' ); |
|
| 119 | + $data = wp_list_pluck($this->stats, $key, 'completed_date'); |
|
| 120 | 120 | $prepared = array(); |
| 121 | 121 | |
| 122 | - foreach ( $labels as $label ) { |
|
| 122 | + foreach ($labels as $label) { |
|
| 123 | 123 | |
| 124 | 124 | $value = 0; |
| 125 | - if ( isset( $data[ $label ] ) ) { |
|
| 126 | - $value = wpinv_round_amount( wpinv_sanitize_amount( $data[ $label ] ) ); |
|
| 125 | + if (isset($data[$label])) { |
|
| 126 | + $value = wpinv_round_amount(wpinv_sanitize_amount($data[$label])); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | $prepared[] = $value; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - return apply_filters( 'getpaid_earning_graphs_get_data', $prepared, $key, $labels ); |
|
| 132 | + return apply_filters('getpaid_earning_graphs_get_data', $prepared, $key, $labels); |
|
| 133 | 133 | |
| 134 | 134 | } |
| 135 | 135 | |
@@ -139,24 +139,24 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | public function display() { |
| 141 | 141 | |
| 142 | - $labels = $this->get_labels( $this->get_range() ); |
|
| 142 | + $labels = $this->get_labels($this->get_range()); |
|
| 143 | 143 | $chart_data = array( |
| 144 | - 'labels' => array_values( $labels ), |
|
| 145 | - 'datasets' => $this->get_datasets( array_keys( $labels ) ), |
|
| 144 | + 'labels' => array_values($labels), |
|
| 145 | + 'datasets' => $this->get_datasets(array_keys($labels)), |
|
| 146 | 146 | ); |
| 147 | 147 | |
| 148 | 148 | ?> |
| 149 | 149 | |
| 150 | - <?php foreach ( $chart_data['datasets'] as $key => $dataset ) : ?> |
|
| 150 | + <?php foreach ($chart_data['datasets'] as $key => $dataset) : ?> |
|
| 151 | 151 | <div class="row mb-4"> |
| 152 | 152 | <div class="col-12"> |
| 153 | 153 | <div class="card m-0 p-0" style="max-width:100%"> |
| 154 | 154 | <div class="card-header d-flex align-items-center"> |
| 155 | - <strong class="flex-grow-1"><?php echo esc_html( $dataset['label'] ); ?></strong> |
|
| 155 | + <strong class="flex-grow-1"><?php echo esc_html($dataset['label']); ?></strong> |
|
| 156 | 156 | <?php $this->display_range_selector(); ?> |
| 157 | 157 | </div> |
| 158 | 158 | <div class="card-body"> |
| 159 | - <?php $this->display_graph( $key, $dataset, $chart_data['labels'] ); ?> |
|
| 159 | + <?php $this->display_graph($key, $dataset, $chart_data['labels']); ?> |
|
| 160 | 160 | </div> |
| 161 | 161 | </div> |
| 162 | 162 | </div> |
@@ -171,26 +171,26 @@ discard block |
||
| 171 | 171 | * Displays the actual report. |
| 172 | 172 | * |
| 173 | 173 | */ |
| 174 | - public function display_graph( $key, $dataset, $labels ) { |
|
| 174 | + public function display_graph($key, $dataset, $labels) { |
|
| 175 | 175 | |
| 176 | 176 | ?> |
| 177 | 177 | |
| 178 | - <canvas id="getpaid-chartjs-earnings-<?php echo esc_attr( $key ); ?>"></canvas> |
|
| 178 | + <canvas id="getpaid-chartjs-earnings-<?php echo esc_attr($key); ?>"></canvas> |
|
| 179 | 179 | |
| 180 | 180 | <script> |
| 181 | 181 | window.addEventListener( 'DOMContentLoaded', function() { |
| 182 | 182 | |
| 183 | - var ctx = document.getElementById( 'getpaid-chartjs-earnings-<?php echo esc_attr( $key ); ?>' ).getContext('2d'); |
|
| 183 | + var ctx = document.getElementById( 'getpaid-chartjs-earnings-<?php echo esc_attr($key); ?>' ).getContext('2d'); |
|
| 184 | 184 | new Chart( |
| 185 | 185 | ctx, |
| 186 | 186 | { |
| 187 | 187 | type: 'line', |
| 188 | 188 | data: { |
| 189 | - 'labels': <?php echo wp_json_encode( wpinv_clean( $labels ) ); ?>, |
|
| 189 | + 'labels': <?php echo wp_json_encode(wpinv_clean($labels)); ?>, |
|
| 190 | 190 | 'datasets': [ |
| 191 | 191 | { |
| 192 | - label: '<?php echo esc_attr( $dataset['label'] ); ?>', |
|
| 193 | - data: <?php echo wp_json_encode( wpinv_clean( $dataset['data'] ) ); ?>, |
|
| 192 | + label: '<?php echo esc_attr($dataset['label']); ?>', |
|
| 193 | + data: <?php echo wp_json_encode(wpinv_clean($dataset['data'])); ?>, |
|
| 194 | 194 | backgroundColor: 'rgba(54, 162, 235, 0.1)', |
| 195 | 195 | borderColor: 'rgb(54, 162, 235)', |
| 196 | 196 | borderWidth: 4, |