Passed
Push — master ( 72aaeb...55577f )
by Brian
04:34
created
includes/payments/class-getpaid-payment-exception.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -14,51 +14,51 @@
 block discarded – undo
14 14
  */
15 15
 class GetPaid_Payment_Exception extends Exception {
16 16
 
17
-	/**
18
-	 * Sanitized error code.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	protected $error_code;
17
+    /**
18
+     * Sanitized error code.
19
+     *
20
+     * @var string
21
+     */
22
+    protected $error_code;
23 23
 
24
-	/**
25
-	 * Error extra data.
26
-	 *
27
-	 * @var array
28
-	 */
29
-	protected $error_data;
24
+    /**
25
+     * Error extra data.
26
+     *
27
+     * @var array
28
+     */
29
+    protected $error_data;
30 30
 
31
-	/**
32
-	 * Setup exception.
33
-	 *
34
-	 * @param string $code             Machine-readable error code, e.g `getpaid-discount-error`.
35
-	 * @param string $message          User-friendly translated error message, e.g. 'Discount is invalid'.
36
-	 * @param int    $http_status_code Proper HTTP status code to respond with, e.g. 400.
37
-	 * @param array  $data             Extra error data.
38
-	 */
39
-	public function __construct( $code, $message, $http_status_code = 400, $data = array() ) {
40
-		$this->error_code = $code;
41
-		$this->error_data = array_merge( array( 'status' => $http_status_code ), $data );
31
+    /**
32
+     * Setup exception.
33
+     *
34
+     * @param string $code             Machine-readable error code, e.g `getpaid-discount-error`.
35
+     * @param string $message          User-friendly translated error message, e.g. 'Discount is invalid'.
36
+     * @param int    $http_status_code Proper HTTP status code to respond with, e.g. 400.
37
+     * @param array  $data             Extra error data.
38
+     */
39
+    public function __construct( $code, $message, $http_status_code = 400, $data = array() ) {
40
+        $this->error_code = $code;
41
+        $this->error_data = array_merge( array( 'status' => $http_status_code ), $data );
42 42
 
43
-		parent::__construct( $message, $http_status_code );
44
-	}
43
+        parent::__construct( $message, $http_status_code );
44
+    }
45 45
 
46
-	/**
47
-	 * Returns the error code.
48
-	 *
49
-	 * @return string
50
-	 */
51
-	public function getErrorCode() {
52
-		return $this->error_code;
53
-	}
46
+    /**
47
+     * Returns the error code.
48
+     *
49
+     * @return string
50
+     */
51
+    public function getErrorCode() {
52
+        return $this->error_code;
53
+    }
54 54
 
55
-	/**
56
-	 * Returns error data.
57
-	 *
58
-	 * @return array
59
-	 */
60
-	public function getErrorData() {
61
-		return $this->error_data;
62
-	}
55
+    /**
56
+     * Returns error data.
57
+     *
58
+     * @return array
59
+     */
60
+    public function getErrorData() {
61
+        return $this->error_data;
62
+    }
63 63
 
64 64
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-discount.php 1 patch
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -12,162 +12,162 @@
 block discarded – undo
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
-		// Exceeded limit.
71
-		if ( $discount->has_exceeded_limit() ) {
72
-			throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'This discount code has been used up', 'invoicing' ) );
73
-		}
74
-
75
-		// Validate usages.
76
-		$this->validate_single_use_discount( $submission, $discount );
77
-
78
-		// Validate amount.
79
-		$this->validate_discount_amount( $submission, $discount, $amount );
80
-
81
-		// Save the discount.
82
-		$this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount );
83
-	}
84
-
85
-	/**
86
-	 * Validates a single use discount.
87
-	 *
88
-	 * @param WPInv_Discount                  $discount
89
-	 * @return bool
90
-	 */
91
-	public function is_discount_active(  $discount ) {
92
-		return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired();
93
-	}
94
-
95
-	/**
96
-	 * Returns a user's id or email.
97
-	 *
98
-	 * @param string $email
99
-	 * @return int|string|false
100
-	 */
101
-	public function get_user_id_or_email( $email ) {
102
-
103
-		if ( is_user_logged_in() ) {
104
-			return get_current_user_id();
105
-		}
106
-
107
-		return empty( $email ) ? false : sanitize_email( $email );
108
-	}
109
-
110
-	/**
111
-	 * Validates a single use discount.
112
-	 *
113
-	 * @param GetPaid_Payment_Form_Submission $submission
114
-	 * @param WPInv_Discount                  $discount
115
-	 */
116
-	public function validate_single_use_discount( $submission, $discount ) {
117
-
118
-		// Abort if it is not a single use discount.
119
-		if ( ! $discount->is_single_use() ) {
120
-			return;
121
-		}
122
-
123
-		// Ensure there is a valid billing email.
124
-		$user = $this->get_user_id_or_email( $submission->get_billing_email() );
125
-
126
-		if ( empty( $user ) ) {
127
-			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' ) );
128
-		}
129
-
130
-		// Has the user used this discount code before?
131
-		if ( ! $discount->is_valid_for_user( $user ) ) {
132
-			throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You have already used this discount', 'invoicing' ) );
133
-		}
134
-
135
-	}
136
-
137
-	/**
138
-	 * Validates the discount's amount.
139
-	 *
140
-	 * @param GetPaid_Payment_Form_Submission $submission
141
-	 * @param WPInv_Discount         $discount
142
-	 * @param float                  $amount
143
-	 */
144
-	public function validate_discount_amount( $submission, $discount, $amount ) {
145
-
146
-		// Validate minimum amount.
147
-		if ( ! $discount->is_minimum_amount_met( $amount ) ) {
148
-			$min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() );
149
-			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 ) );
150
-		}
151
-
152
-		// Validate the maximum amount.
153
-		if ( ! $discount->is_maximum_amount_met( $amount ) ) {
154
-			$max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() );
155
-			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 ) );
156
-		}
157
-
158
-	}
159
-
160
-	/**
161
-	 * Calculates the discount code's amount.
162
-	 *
163
-	 * Ensure that the discount exists and has been validated before calling this method.
164
-	 *
165
-	 * @param GetPaid_Payment_Form_Submission $submission
166
-	 * @param WPInv_Discount                  $discount
167
-	 * @return array
168
-	 */
169
-	public function calculate_discount( $submission, $discount ) {
170
-		return getpaid_calculate_invoice_discount( $submission, $discount );
171
-	}
67
+            throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'Invalid or expired discount code', 'invoicing' ) );
68
+        }
69
+
70
+        // Exceeded limit.
71
+        if ( $discount->has_exceeded_limit() ) {
72
+            throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'This discount code has been used up', 'invoicing' ) );
73
+        }
74
+
75
+        // Validate usages.
76
+        $this->validate_single_use_discount( $submission, $discount );
77
+
78
+        // Validate amount.
79
+        $this->validate_discount_amount( $submission, $discount, $amount );
80
+
81
+        // Save the discount.
82
+        $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount );
83
+    }
84
+
85
+    /**
86
+     * Validates a single use discount.
87
+     *
88
+     * @param WPInv_Discount                  $discount
89
+     * @return bool
90
+     */
91
+    public function is_discount_active(  $discount ) {
92
+        return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired();
93
+    }
94
+
95
+    /**
96
+     * Returns a user's id or email.
97
+     *
98
+     * @param string $email
99
+     * @return int|string|false
100
+     */
101
+    public function get_user_id_or_email( $email ) {
102
+
103
+        if ( is_user_logged_in() ) {
104
+            return get_current_user_id();
105
+        }
106
+
107
+        return empty( $email ) ? false : sanitize_email( $email );
108
+    }
109
+
110
+    /**
111
+     * Validates a single use discount.
112
+     *
113
+     * @param GetPaid_Payment_Form_Submission $submission
114
+     * @param WPInv_Discount                  $discount
115
+     */
116
+    public function validate_single_use_discount( $submission, $discount ) {
117
+
118
+        // Abort if it is not a single use discount.
119
+        if ( ! $discount->is_single_use() ) {
120
+            return;
121
+        }
122
+
123
+        // Ensure there is a valid billing email.
124
+        $user = $this->get_user_id_or_email( $submission->get_billing_email() );
125
+
126
+        if ( empty( $user ) ) {
127
+            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' ) );
128
+        }
129
+
130
+        // Has the user used this discount code before?
131
+        if ( ! $discount->is_valid_for_user( $user ) ) {
132
+            throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'You have already used this discount', 'invoicing' ) );
133
+        }
134
+
135
+    }
136
+
137
+    /**
138
+     * Validates the discount's amount.
139
+     *
140
+     * @param GetPaid_Payment_Form_Submission $submission
141
+     * @param WPInv_Discount         $discount
142
+     * @param float                  $amount
143
+     */
144
+    public function validate_discount_amount( $submission, $discount, $amount ) {
145
+
146
+        // Validate minimum amount.
147
+        if ( ! $discount->is_minimum_amount_met( $amount ) ) {
148
+            $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() );
149
+            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 ) );
150
+        }
151
+
152
+        // Validate the maximum amount.
153
+        if ( ! $discount->is_maximum_amount_met( $amount ) ) {
154
+            $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() );
155
+            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 ) );
156
+        }
157
+
158
+    }
159
+
160
+    /**
161
+     * Calculates the discount code's amount.
162
+     *
163
+     * Ensure that the discount exists and has been validated before calling this method.
164
+     *
165
+     * @param GetPaid_Payment_Form_Submission $submission
166
+     * @param WPInv_Discount                  $discount
167
+     * @return array
168
+     */
169
+    public function calculate_discount( $submission, $discount ) {
170
+        return getpaid_calculate_invoice_discount( $submission, $discount );
171
+    }
172 172
 
173 173
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-authorize-net-gateway.php 1 patch
Indentation   +237 added lines, -237 removed lines patch added patch discarded remove patch
@@ -13,58 +13,58 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'authorizenet';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34 34
     public $order = 4;
35 35
 
36 36
     /**
37
-	 * Endpoint for requests from Authorize.net.
38
-	 *
39
-	 * @var string
40
-	 */
41
-	protected $notify_url;
42
-
43
-	/**
44
-	 * Endpoint for requests to Authorize.net.
45
-	 *
46
-	 * @var string
47
-	 */
37
+     * Endpoint for requests from Authorize.net.
38
+     *
39
+     * @var string
40
+     */
41
+    protected $notify_url;
42
+
43
+    /**
44
+     * Endpoint for requests to Authorize.net.
45
+     *
46
+     * @var string
47
+     */
48 48
     protected $endpoint;
49 49
 
50 50
     /**
51
-	 * Currencies this gateway is allowed for.
52
-	 *
53
-	 * @var array
54
-	 */
55
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
51
+     * Currencies this gateway is allowed for.
52
+     *
53
+     * @var array
54
+     */
55
+    public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
56 56
 
57 57
     /**
58
-	 * URL to view a transaction.
59
-	 *
60
-	 * @var string
61
-	 */
58
+     * URL to view a transaction.
59
+     *
60
+     * @var string
61
+     */
62 62
     public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s';
63 63
 
64 64
     /**
65
-	 * Class constructor.
66
-	 */
67
-	public function __construct() {
65
+     * Class constructor.
66
+     */
67
+    public function __construct() {
68 68
 
69 69
         $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
70 70
         $this->method_title         = __( 'Authorize.Net', 'invoicing' );
@@ -76,11 +76,11 @@  discard block
 block discarded – undo
76 76
     }
77 77
 
78 78
     /**
79
-	 * Displays the payment method select field.
80
-	 *
81
-	 * @param int $invoice_id 0 or invoice id.
82
-	 * @param GetPaid_Payment_Form $form Current payment form.
83
-	 */
79
+     * Displays the payment method select field.
80
+     *
81
+     * @param int $invoice_id 0 or invoice id.
82
+     * @param GetPaid_Payment_Form $form Current payment form.
83
+     */
84 84
     public function payment_fields( $invoice_id, $form ) {
85 85
 
86 86
         // Let the user select a payment method.
@@ -91,16 +91,16 @@  discard block
 block discarded – undo
91 91
     }
92 92
 
93 93
     /**
94
-	 * Creates a customer profile.
95
-	 *
96
-	 *
97
-	 * @param WPInv_Invoice $invoice Invoice.
94
+     * Creates a customer profile.
95
+     *
96
+     *
97
+     * @param WPInv_Invoice $invoice Invoice.
98 98
      * @param array $submission_data Posted checkout fields.
99 99
      * @param bool $save Whether or not to save the payment as a token.
100 100
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
101
-	 * @return string|WP_Error Payment profile id.
102
-	 */
103
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
101
+     * @return string|WP_Error Payment profile id.
102
+     */
103
+    public function create_customer_profile( $invoice, $submission_data, $save = true ) {
104 104
 
105 105
         // Remove non-digits from the number
106 106
         $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -167,14 +167,14 @@  discard block
 block discarded – undo
167 167
     }
168 168
 
169 169
     /**
170
-	 * Retrieves a customer profile.
171
-	 *
172
-	 *
173
-	 * @param string $profile_id profile id.
174
-	 * @return string|WP_Error Profile id.
170
+     * Retrieves a customer profile.
171
+     *
172
+     *
173
+     * @param string $profile_id profile id.
174
+     * @return string|WP_Error Profile id.
175 175
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
176
-	 */
177
-	public function get_customer_profile( $profile_id ) {
176
+     */
177
+    public function get_customer_profile( $profile_id ) {
178 178
 
179 179
         // Generate args.
180 180
         $args = array(
@@ -189,17 +189,17 @@  discard block
 block discarded – undo
189 189
     }
190 190
 
191 191
     /**
192
-	 * Creates a customer profile.
193
-	 *
194
-	 *
192
+     * Creates a customer profile.
193
+     *
194
+     *
195 195
      * @param string $profile_id profile id.
196
-	 * @param WPInv_Invoice $invoice Invoice.
196
+     * @param WPInv_Invoice $invoice Invoice.
197 197
      * @param array $submission_data Posted checkout fields.
198 198
      * @param bool $save Whether or not to save the payment as a token.
199 199
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
200
-	 * @return string|WP_Error Profile id.
201
-	 */
202
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
200
+     * @return string|WP_Error Profile id.
201
+     */
202
+    public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
203 203
 
204 204
         // Remove non-digits from the number
205 205
         $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -272,13 +272,13 @@  discard block
 block discarded – undo
272 272
     }
273 273
 
274 274
     /**
275
-	 * Retrieves payment details from cache.
276
-	 *
277
-	 *
275
+     * Retrieves payment details from cache.
276
+     *
277
+     *
278 278
      * @param array $payment_details.
279
-	 * @return array|false Profile id.
280
-	 */
281
-	public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
279
+     * @return array|false Profile id.
280
+     */
281
+    public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
282 282
 
283 283
         $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
284 284
         $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
@@ -303,13 +303,13 @@  discard block
 block discarded – undo
303 303
     }
304 304
 
305 305
     /**
306
-	 * Securely adds payment details to cache.
307
-	 *
308
-	 *
306
+     * Securely adds payment details to cache.
307
+     *
308
+     *
309 309
      * @param array $payment_details.
310 310
      * @param string $payment_profile_id.
311
-	 */
312
-	public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
311
+     */
312
+    public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
313 313
 
314 314
         $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
315 315
         $cached_information = is_array( $cached_information ) ? $cached_information : array();
@@ -321,15 +321,15 @@  discard block
 block discarded – undo
321 321
     }
322 322
 
323 323
     /**
324
-	 * Retrieves a customer payment profile.
325
-	 *
326
-	 *
327
-	 * @param string $customer_profile_id customer profile id.
324
+     * Retrieves a customer payment profile.
325
+     *
326
+     *
327
+     * @param string $customer_profile_id customer profile id.
328 328
      * @param string $payment_profile_id payment profile id.
329
-	 * @return string|WP_Error Profile id.
329
+     * @return string|WP_Error Profile id.
330 330
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
331
-	 */
332
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
331
+     */
332
+    public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
333 333
 
334 334
         // Generate args.
335 335
         $args = array(
@@ -345,15 +345,15 @@  discard block
 block discarded – undo
345 345
     }
346 346
 
347 347
     /**
348
-	 * Charges a customer payment profile.
349
-	 *
348
+     * Charges a customer payment profile.
349
+     *
350 350
      * @param string $customer_profile_id customer profile id.
351 351
      * @param string $payment_profile_id payment profile id.
352
-	 * @param WPInv_Invoice $invoice Invoice.
352
+     * @param WPInv_Invoice $invoice Invoice.
353 353
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
354
-	 * @return WP_Error|object
355
-	 */
356
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
354
+     * @return WP_Error|object
355
+     */
356
+    public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
357 357
 
358 358
         // Generate args.
359 359
         $args = array(
@@ -399,41 +399,41 @@  discard block
 block discarded – undo
399 399
     }
400 400
 
401 401
     /**
402
-	 * Processes a customer charge.
403
-	 *
402
+     * Processes a customer charge.
403
+     *
404 404
      * @param stdClass $result Api response.
405
-	 * @param WPInv_Invoice $invoice Invoice.
406
-	 */
407
-	public function process_charge_response( $result, $invoice ) {
405
+     * @param WPInv_Invoice $invoice Invoice.
406
+     */
407
+    public function process_charge_response( $result, $invoice ) {
408 408
 
409 409
         wpinv_clear_errors();
410
-		$response_code = (int) $result->transactionResponse->responseCode;
410
+        $response_code = (int) $result->transactionResponse->responseCode;
411 411
 
412
-		// Succeeded.
413
-		if ( 1 == $response_code || 4 == $response_code ) {
412
+        // Succeeded.
413
+        if ( 1 == $response_code || 4 == $response_code ) {
414 414
 
415
-			// Maybe set a transaction id.
416
-			if ( ! empty( $result->transactionResponse->transId ) ) {
417
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
418
-			}
415
+            // Maybe set a transaction id.
416
+            if ( ! empty( $result->transactionResponse->transId ) ) {
417
+                $invoice->set_transaction_id( $result->transactionResponse->transId );
418
+            }
419 419
 
420
-			$invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
420
+            $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
421 421
 
422
-			if ( 1 == $response_code ) {
423
-				return $invoice->mark_paid();
424
-			}
422
+            if ( 1 == $response_code ) {
423
+                return $invoice->mark_paid();
424
+            }
425 425
 
426
-			$invoice->set_status( 'wpi-onhold' );
427
-        	$invoice->add_note(
426
+            $invoice->set_status( 'wpi-onhold' );
427
+            $invoice->add_note(
428 428
                 sprintf(
429 429
                     __( 'Held for review: %s', 'invoicing' ),
430 430
                     $result->transactionResponse->messages->message[0]->description
431 431
                 )
432
-			);
432
+            );
433 433
 
434
-			return $invoice->save();
434
+            return $invoice->save();
435 435
 
436
-		}
436
+        }
437 437
 
438 438
         wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) );
439 439
 
@@ -445,13 +445,13 @@  discard block
 block discarded – undo
445 445
     }
446 446
 
447 447
     /**
448
-	 * Returns payment information.
449
-	 *
450
-	 *
451
-	 * @param array $card Card details.
452
-	 * @return array
453
-	 */
454
-	public function get_payment_information( $card ) {
448
+     * Returns payment information.
449
+     *
450
+     *
451
+     * @param array $card Card details.
452
+     * @return array
453
+     */
454
+    public function get_payment_information( $card ) {
455 455
         return array(
456 456
 
457 457
             'creditCard'         => array (
@@ -464,25 +464,25 @@  discard block
 block discarded – undo
464 464
     }
465 465
 
466 466
     /**
467
-	 * Returns the customer profile meta name.
468
-	 *
469
-	 *
470
-	 * @param WPInv_Invoice $invoice Invoice.
471
-	 * @return string
472
-	 */
473
-	public function get_customer_profile_meta_name( $invoice ) {
467
+     * Returns the customer profile meta name.
468
+     *
469
+     *
470
+     * @param WPInv_Invoice $invoice Invoice.
471
+     * @return string
472
+     */
473
+    public function get_customer_profile_meta_name( $invoice ) {
474 474
         return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
475 475
     }
476 476
 
477 477
     /**
478
-	 * Validates the submitted data.
479
-	 *
480
-	 *
481
-	 * @param array $submission_data Posted checkout fields.
478
+     * Validates the submitted data.
479
+     *
480
+     *
481
+     * @param array $submission_data Posted checkout fields.
482 482
      * @param WPInv_Invoice $invoice
483
-	 * @return WP_Error|string The payment profile id
484
-	 */
485
-	public function validate_submission_data( $submission_data, $invoice ) {
483
+     * @return WP_Error|string The payment profile id
484
+     */
485
+    public function validate_submission_data( $submission_data, $invoice ) {
486 486
 
487 487
         // Validate authentication details.
488 488
         $auth = $this->get_auth_params();
@@ -514,13 +514,13 @@  discard block
 block discarded – undo
514 514
     }
515 515
 
516 516
     /**
517
-	 * Returns invoice line items.
518
-	 *
519
-	 *
520
-	 * @param WPInv_Invoice $invoice Invoice.
521
-	 * @return array
522
-	 */
523
-	public function get_line_items( $invoice ) {
517
+     * Returns invoice line items.
518
+     *
519
+     *
520
+     * @param WPInv_Invoice $invoice Invoice.
521
+     * @return array
522
+     */
523
+    public function get_line_items( $invoice ) {
524 524
         $items = array();
525 525
 
526 526
         foreach ( $invoice->get_items() as $item ) {
@@ -558,15 +558,15 @@  discard block
 block discarded – undo
558 558
     }
559 559
 
560 560
     /**
561
-	 * Process Payment.
562
-	 *
563
-	 *
564
-	 * @param WPInv_Invoice $invoice Invoice.
565
-	 * @param array $submission_data Posted checkout fields.
566
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
567
-	 * @return array
568
-	 */
569
-	public function process_payment( $invoice, $submission_data, $submission ) {
561
+     * Process Payment.
562
+     *
563
+     *
564
+     * @param WPInv_Invoice $invoice Invoice.
565
+     * @param array $submission_data Posted checkout fields.
566
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
567
+     * @return array
568
+     */
569
+    public function process_payment( $invoice, $submission_data, $submission ) {
570 570
 
571 571
         // Validate the submitted data.
572 572
         $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
@@ -599,69 +599,69 @@  discard block
 block discarded – undo
599 599
 
600 600
         exit;
601 601
 
602
-	}
602
+    }
603 603
 	
604
-	/**
605
-	 * Processes the initial payment.
606
-	 *
604
+    /**
605
+     * Processes the initial payment.
606
+     *
607 607
      * @param WPInv_Invoice $invoice Invoice.
608
-	 */
609
-	protected function process_initial_payment( $invoice ) {
608
+     */
609
+    protected function process_initial_payment( $invoice ) {
610 610
 
611
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
611
+        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
612 612
         $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
613
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
613
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
614 614
 
615
-		// Do we have an error?
616
-		if ( is_wp_error( $result ) ) {
617
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
618
-			wpinv_send_back_to_checkout( $invoice );
619
-		}
615
+        // Do we have an error?
616
+        if ( is_wp_error( $result ) ) {
617
+            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
618
+            wpinv_send_back_to_checkout( $invoice );
619
+        }
620 620
 
621
-		// Process the response.
622
-		$this->process_charge_response( $result, $invoice );
621
+        // Process the response.
622
+        $this->process_charge_response( $result, $invoice );
623 623
 
624
-		if ( wpinv_get_errors() ) {
625
-			wpinv_send_back_to_checkout( $invoice );
626
-		}
624
+        if ( wpinv_get_errors() ) {
625
+            wpinv_send_back_to_checkout( $invoice );
626
+        }
627 627
 
628
-	}
628
+    }
629 629
 
630 630
     /**
631
-	 * Processes recurring payments.
632
-	 *
631
+     * Processes recurring payments.
632
+     *
633 633
      * @param WPInv_Invoice $invoice Invoice.
634 634
      * @param WPInv_Subscription $subscription Subscription.
635
-	 */
636
-	public function process_subscription( $invoice, $subscription ) {
635
+     */
636
+    public function process_subscription( $invoice, $subscription ) {
637 637
 
638 638
         // Check if there is an initial amount to charge.
639 639
         if ( (float) $invoice->get_total() > 0 ) {
640
-			$this->process_initial_payment( $invoice );
640
+            $this->process_initial_payment( $invoice );
641 641
         }
642 642
 
643 643
         // Activate the subscription.
644 644
         $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
645 645
         $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
646 646
 
647
-		$subscription->set_next_renewal_date( $expiry );
648
-		$subscription->set_date_created( current_time( 'mysql' ) );
649
-		$subscription->set_profile_id( $invoice->generate_key() );
650
-		$subscription->activate();
647
+        $subscription->set_next_renewal_date( $expiry );
648
+        $subscription->set_date_created( current_time( 'mysql' ) );
649
+        $subscription->set_profile_id( $invoice->generate_key() );
650
+        $subscription->activate();
651 651
 
652
-		// Redirect to the success page.
652
+        // Redirect to the success page.
653 653
         wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
654 654
 
655 655
     }
656 656
 
657
-	/**
658
-	 * (Maybe) renews an authorize.net subscription profile.
659
-	 *
660
-	 *
661
-	 * @param bool $should_expire
657
+    /**
658
+     * (Maybe) renews an authorize.net subscription profile.
659
+     *
660
+     *
661
+     * @param bool $should_expire
662 662
      * @param WPInv_Subscription $subscription
663
-	 */
664
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
663
+     */
664
+    public function maybe_renew_subscription( $should_expire, $subscription ) {
665 665
 
666 666
         // Ensure its our subscription && it's active.
667 667
         if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
@@ -678,18 +678,18 @@  discard block
 block discarded – undo
678 678
 
679 679
         return false;
680 680
 
681
-	}
681
+    }
682 682
 
683 683
     /**
684
-	 * Renews a subscription.
685
-	 *
684
+     * Renews a subscription.
685
+     *
686 686
      * @param WPInv_Subscription $subscription
687
-	 */
688
-	public function renew_subscription( $subscription ) {
687
+     */
688
+    public function renew_subscription( $subscription ) {
689 689
 
690
-		// Generate the renewal invoice.
691
-		$new_invoice = $subscription->create_payment();
692
-		$old_invoice = $subscription->get_parent_payment();
690
+        // Generate the renewal invoice.
691
+        $new_invoice = $subscription->create_payment();
692
+        $old_invoice = $subscription->get_parent_payment();
693 693
 
694 694
         if ( empty( $new_invoice ) ) {
695 695
             $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
@@ -698,37 +698,37 @@  discard block
 block discarded – undo
698 698
         }
699 699
 
700 700
         // Charge the payment method.
701
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
702
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
703
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
704
-
705
-		// Do we have an error?
706
-		if ( is_wp_error( $result ) ) {
707
-
708
-			$old_invoice->add_note(
709
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
710
-				true,
711
-				false,
712
-				true
713
-			);
714
-			$subscription->failing();
715
-			return;
716
-
717
-		}
718
-
719
-		// Process the response.
720
-		$this->process_charge_response( $result, $new_invoice );
721
-
722
-		if ( wpinv_get_errors() ) {
723
-
724
-			$old_invoice->add_note(
725
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
726
-				true,
727
-				false,
728
-				true
729
-			);
730
-			$subscription->failing();
731
-			return;
701
+        $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
702
+        $customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
703
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
704
+
705
+        // Do we have an error?
706
+        if ( is_wp_error( $result ) ) {
707
+
708
+            $old_invoice->add_note(
709
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
710
+                true,
711
+                false,
712
+                true
713
+            );
714
+            $subscription->failing();
715
+            return;
716
+
717
+        }
718
+
719
+        // Process the response.
720
+        $this->process_charge_response( $result, $new_invoice );
721
+
722
+        if ( wpinv_get_errors() ) {
723
+
724
+            $old_invoice->add_note(
725
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
726
+                true,
727
+                false,
728
+                true
729
+            );
730
+            $subscription->failing();
731
+            return;
732 732
 
733 733
         }
734 734
 
@@ -737,13 +737,13 @@  discard block
 block discarded – undo
737 737
     }
738 738
 
739 739
     /**
740
-	 * Processes invoice addons.
741
-	 *
742
-	 * @param WPInv_Invoice $invoice
743
-	 * @param GetPaid_Form_Item[] $items
744
-	 * @return WPInv_Invoice
745
-	 */
746
-	public function process_addons( $invoice, $items ) {
740
+     * Processes invoice addons.
741
+     *
742
+     * @param WPInv_Invoice $invoice
743
+     * @param GetPaid_Form_Item[] $items
744
+     * @return WPInv_Invoice
745
+     */
746
+    public function process_addons( $invoice, $items ) {
747 747
 
748 748
         global $getpaid_authorize_addons;
749 749
 
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
         $invoice->recalculate_total();
764 764
 
765 765
         $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
766
-		$customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
766
+        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
767 767
 
768 768
         add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 );
769 769
         $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
@@ -778,11 +778,11 @@  discard block
 block discarded – undo
778 778
     }
779 779
 
780 780
     /**
781
-	 * Processes invoice addons.
782
-	 *
781
+     * Processes invoice addons.
782
+     *
783 783
      * @param array $args
784
-	 * @return array
785
-	 */
784
+     * @return array
785
+     */
786 786
     public function filter_addons_request( $args ) {
787 787
 
788 788
         global $getpaid_authorize_addons;
@@ -816,11 +816,11 @@  discard block
 block discarded – undo
816 816
     }
817 817
 
818 818
     /**
819
-	 * Filters the gateway settings.
820
-	 *
821
-	 * @param array $admin_settings
822
-	 */
823
-	public function admin_settings( $admin_settings ) {
819
+     * Filters the gateway settings.
820
+     *
821
+     * @param array $admin_settings
822
+     */
823
+    public function admin_settings( $admin_settings ) {
824 824
 
825 825
         $currencies = sprintf(
826 826
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -860,7 +860,7 @@  discard block
 block discarded – undo
860 860
             'readonly' => true,
861 861
         );
862 862
 
863
-		return $admin_settings;
864
-	}
863
+        return $admin_settings;
864
+    }
865 865
 
866 866
 }
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports-helper.php 1 patch
Indentation   +276 added lines, -276 removed lines patch added patch discarded remove patch
@@ -12,294 +12,294 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Reports_Helper {
14 14
 
15
-	/**
16
-	 * Get report totals such as invoice totals and discount amounts.
17
-	 *
18
-	 * Data example:
19
-	 *
20
-	 * 'subtotal' => array(
21
-	 *     'type'     => 'invoice_data',
22
-	 *     'function' => 'SUM',
23
-	 *     'name'     => 'subtotal'
24
-	 * )
25
-	 *
26
-	 * @param  array $args
27
-	 * @return mixed depending on query_type
28
-	 */
29
-	public static function get_invoice_report_data( $args = array() ) {
30
-		global $wpdb;
31
-
32
-		$default_args = array(
33
-			'data'                  => array(), // The data to retrieve.
34
-			'where'                 => array(), // An array of where queries.
35
-			'query_type'            => 'get_row', // wpdb query to run.
36
-			'group_by'              => '', // What to group results by.
37
-			'order_by'              => '', // What to order by.
38
-			'limit'                 => '', // Results limit.
39
-			'filter_range'          => array(), // An array of before and after dates to limit results by.
40
-			'invoice_types'         => array( 'wpi_invoice' ), // An array of post types to retrieve.
41
-			'invoice_status'        => array( 'publish', 'wpi-processing', 'wpi-onhold' ),
42
-			'parent_invoice_status' => false, // Optionally filter by parent invoice status.
43
-		);
44
-
45
-		$args         = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args );
46
-		$args         = wp_parse_args( $args, $default_args );
47
-
48
-		extract( $args );
49
-
50
-		if ( empty( $data ) ) {
51
-			return '';
52
-		}
53
-
54
-		$query           = array();
55
-		$query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) );
56
-		$query['from']   = "FROM {$wpdb->posts} AS posts";
57
-		$query['join']   = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) );
58
-
59
-		$query['where']  = "
15
+    /**
16
+     * Get report totals such as invoice totals and discount amounts.
17
+     *
18
+     * Data example:
19
+     *
20
+     * 'subtotal' => array(
21
+     *     'type'     => 'invoice_data',
22
+     *     'function' => 'SUM',
23
+     *     'name'     => 'subtotal'
24
+     * )
25
+     *
26
+     * @param  array $args
27
+     * @return mixed depending on query_type
28
+     */
29
+    public static function get_invoice_report_data( $args = array() ) {
30
+        global $wpdb;
31
+
32
+        $default_args = array(
33
+            'data'                  => array(), // The data to retrieve.
34
+            'where'                 => array(), // An array of where queries.
35
+            'query_type'            => 'get_row', // wpdb query to run.
36
+            'group_by'              => '', // What to group results by.
37
+            'order_by'              => '', // What to order by.
38
+            'limit'                 => '', // Results limit.
39
+            'filter_range'          => array(), // An array of before and after dates to limit results by.
40
+            'invoice_types'         => array( 'wpi_invoice' ), // An array of post types to retrieve.
41
+            'invoice_status'        => array( 'publish', 'wpi-processing', 'wpi-onhold' ),
42
+            'parent_invoice_status' => false, // Optionally filter by parent invoice status.
43
+        );
44
+
45
+        $args         = apply_filters( 'getpaid_reports_get_invoice_report_data_args', $args );
46
+        $args         = wp_parse_args( $args, $default_args );
47
+
48
+        extract( $args );
49
+
50
+        if ( empty( $data ) ) {
51
+            return '';
52
+        }
53
+
54
+        $query           = array();
55
+        $query['select'] = 'SELECT ' . implode( ',', self::prepare_invoice_data( $data ) );
56
+        $query['from']   = "FROM {$wpdb->posts} AS posts";
57
+        $query['join']   = implode( ' ', self::prepare_invoice_joins( $data + $where, ! empty( $parent_invoice_status ) ) );
58
+
59
+        $query['where']  = "
60 60
 			WHERE 	posts.post_type 	IN ( '" . implode( "','", $invoice_types ) . "' )
61 61
 			";
62 62
 
63
-		if ( ! empty( $invoice_status ) ) {
64
-			$query['where'] .= "
63
+        if ( ! empty( $invoice_status ) ) {
64
+            $query['where'] .= "
65 65
 				AND 	posts.post_status 	IN ( '" . implode( "','", $invoice_status ) . "' )
66 66
 			";
67
-		}
68
-
69
-		if ( ! empty( $parent_invoice_status ) ) {
70
-			if ( ! empty( $invoice_status ) ) {
71
-				$query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) ";
72
-			} else {
73
-				$query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) ";
74
-			}
75
-		}
76
-
77
-		if ( ! empty( $filter_range['before'] ) ) {
78
-			$query['where'] .= "
67
+        }
68
+
69
+        if ( ! empty( $parent_invoice_status ) ) {
70
+            if ( ! empty( $invoice_status ) ) {
71
+                $query['where'] .= " AND ( parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) OR parent.ID IS NULL ) ";
72
+            } else {
73
+                $query['where'] .= " AND parent.post_status IN ( '" . implode( "','", $parent_invoice_status ) . "' ) ";
74
+            }
75
+        }
76
+
77
+        if ( ! empty( $filter_range['before'] ) ) {
78
+            $query['where'] .= "
79 79
 				AND 	posts.post_date < '" . date( 'Y-m-d H:i:s', strtotime( $filter_range['before'] ) ) . "'
80 80
 			";
81
-		}
81
+        }
82 82
 
83
-		if ( ! empty( $filter_range['after'] ) ) {
84
-			$query['where'] .= "
83
+        if ( ! empty( $filter_range['after'] ) ) {
84
+            $query['where'] .= "
85 85
 				AND 	posts.post_date > '" . date( 'Y-m-d H:i:s', strtotime( $filter_range['after'] ) ) . "'
86 86
 			";
87
-		}
87
+        }
88 88
 
89
-		if ( ! empty( $where ) ) {
89
+        if ( ! empty( $where ) ) {
90 90
 
91
-			foreach ( $where as $value ) {
91
+            foreach ( $where as $value ) {
92 92
 
93
-				if ( strtolower( $value['operator'] ) == 'in' || strtolower( $value['operator'] ) == 'not in' ) {
94
-
95
-					if ( is_array( $value['value'] ) ) {
96
-						$value['value'] = implode( "','", $value['value'] );
97
-					}
98
-
99
-					if ( ! empty( $value['value'] ) ) {
100
-						$where_value = "{$value['operator']} ('{$value['value']}')";
101
-					}
102
-				} else {
103
-					$where_value = "{$value['operator']} '{$value['value']}'";
104
-				}
105
-
106
-				if ( ! empty( $where_value ) ) {
107
-					$query['where'] .= " AND {$value['key']} {$where_value}";
108
-				}
109
-			}
110
-		}
111
-
112
-		if ( $group_by ) {
113
-			$query['group_by'] = "GROUP BY {$group_by}";
114
-		}
115
-
116
-		if ( $order_by ) {
117
-			$query['order_by'] = "ORDER BY {$order_by}";
118
-		}
119
-
120
-		if ( $limit ) {
121
-			$query['limit'] = "LIMIT {$limit}";
122
-		}
123
-
124
-		$query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data );
125
-		$query = implode( ' ', $query );
126
-
127
-		return self::execute( $query_type, $query );
128
-
129
-	}
130
-
131
-	/**
132
-	 * Prepares the data to select.
133
-	 *
134
-	 *
135
-	 * @param  array $data
136
-	 * @return array
137
-	 */
138
-	public static function prepare_invoice_data( $data ) {
139
-
140
-		$prepared = array();
141
-
142
-		foreach ( $data as $raw_key => $value ) {
143
-			$key      = sanitize_key( $raw_key );
144
-			$distinct = '';
145
-
146
-			if ( isset( $value['distinct'] ) ) {
147
-				$distinct = 'DISTINCT';
148
-			}
149
-
150
-			$get_key = self::get_invoice_table_key( $key, $value['type'] );
151
-
152
-			if ( false === $get_key ) {
153
-				// Skip to the next foreach iteration else the query will be invalid.
154
-				continue;
155
-			}
156
-
157
-			if ( ! empty( $value['function'] ) ) {
158
-				$get = "{$value['function']}({$distinct} {$get_key})";
159
-			} else {
160
-				$get = "{$distinct} {$get_key}";
161
-			}
162
-
163
-			$prepared[] = "{$get} as {$value['name']}";
164
-		}
165
-
166
-		return $prepared;
167
-
168
-	}
169
-
170
-	/**
171
-	 * Prepares the joins to use.
172
-	 *
173
-	 *
174
-	 * @param  array $data
175
-	 * @param  bool $with_parent
176
-	 * @return array
177
-	 */
178
-	public static function prepare_invoice_joins( $data, $with_parent ) {
179
-		global $wpdb;
180
-
181
-		$prepared = array();
182
-
183
-		foreach ( $data as $raw_key => $value ) {
184
-			$join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER';
185
-			$type      = isset( $value['type'] ) ? $value['type'] : false;
186
-			$key       = sanitize_key( $raw_key );
187
-
188
-			switch ( $type ) {
189
-				case 'meta':
190
-					$prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )";
191
-					break;
192
-				case 'parent_meta':
193
-					$prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')";
194
-					break;
195
-				case 'invoice_data':
196
-					$prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id";
197
-					break;
198
-				case 'invoice_item':
199
-					$prepared['invoice_items'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoice_items AS invoice_items ON posts.ID = invoice_items.post_id";
200
-					break;
201
-			}
202
-		}
203
-
204
-		if ( $with_parent ) {
205
-			$prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID";
206
-		}
207
-
208
-		return $prepared;
209
-
210
-	}
211
-
212
-	/**
213
-	 * Retrieves the appropriate table key to use.
214
-	 *
215
-	 *
216
-	 * @param  string $key
217
-	 * @param  string $table
218
-	 * @return string|false
219
-	 */
220
-	public static function get_invoice_table_key( $key, $table ) {
221
-
222
-		$keys = array(
223
-			'meta'         => "meta_{$key}.meta_value",
224
-			'parent_meta'  => "parent_meta_{$key}.meta_value",
225
-			'post_data'    => "posts.{$key}",
226
-			'invoice_data' => "invoices.{$key}",
227
-			'invoice_item' => "invoice_items.{$key}",
228
-		);
229
-
230
-		return isset( $keys[ $table ] ) ? $keys[ $table ] : false;
231
-
232
-	}
233
-
234
-	/**
235
-	 * Executes a query and caches the result for a minute.
236
-	 *
237
-	 *
238
-	 * @param  string $query_type
239
-	 * @param  string $query
240
-	 * @return mixed depending on query_type
241
-	 */
242
-	public static function execute( $query_type, $query ) {
243
-		global $wpdb;
244
-
245
-		$query_hash = md5( $query_type . $query );
246
-		$result     = self::get_cached_query( $query_hash );
247
-		if ( $result === false ) {
248
-			self::enable_big_selects();
249
-
250
-			$result = $wpdb->$query_type( $query );
251
-			self::set_cached_query( $query_hash, $result );
252
-		}
253
-
254
-		return $result;
255
-
256
-	}
257
-
258
-	/**
259
-	 * Enables big mysql selects for reports, just once for this session.
260
-	 */
261
-	protected static function enable_big_selects() {
262
-		static $big_selects = false;
263
-
264
-		global $wpdb;
265
-
266
-		if ( ! $big_selects ) {
267
-			$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
268
-			$big_selects = true;
269
-		}
270
-	}
271
-
272
-	/**
273
-	 * Get the cached query result or null if it's not in the cache.
274
-	 *
275
-	 * @param string $query_hash The query hash.
276
-	 *
277
-	 * @return mixed|false The cache contents on success, false on failure to retrieve contents.
278
-	 */
279
-	protected static function get_cached_query( $query_hash ) {
280
-
281
-		return wp_cache_get(
282
-			$query_hash,
283
-			strtolower( __CLASS__ )
284
-		);
285
-
286
-	}
287
-
288
-	/**
289
-	 * Set the cached query result.
290
-	 *
291
-	 * @param string $query_hash The query hash.
292
-	 * @param mixed  $data The data to cache.
293
-	 */
294
-	protected static function set_cached_query( $query_hash, $data ) {
295
-
296
-		wp_cache_set(
297
-			$query_hash,
298
-			$data,
299
-			strtolower( __CLASS__ ),
300
-			MINUTE_IN_SECONDS
301
-		);
302
-
303
-	}
93
+                if ( strtolower( $value['operator'] ) == 'in' || strtolower( $value['operator'] ) == 'not in' ) {
94
+
95
+                    if ( is_array( $value['value'] ) ) {
96
+                        $value['value'] = implode( "','", $value['value'] );
97
+                    }
98
+
99
+                    if ( ! empty( $value['value'] ) ) {
100
+                        $where_value = "{$value['operator']} ('{$value['value']}')";
101
+                    }
102
+                } else {
103
+                    $where_value = "{$value['operator']} '{$value['value']}'";
104
+                }
105
+
106
+                if ( ! empty( $where_value ) ) {
107
+                    $query['where'] .= " AND {$value['key']} {$where_value}";
108
+                }
109
+            }
110
+        }
111
+
112
+        if ( $group_by ) {
113
+            $query['group_by'] = "GROUP BY {$group_by}";
114
+        }
115
+
116
+        if ( $order_by ) {
117
+            $query['order_by'] = "ORDER BY {$order_by}";
118
+        }
119
+
120
+        if ( $limit ) {
121
+            $query['limit'] = "LIMIT {$limit}";
122
+        }
123
+
124
+        $query = apply_filters( 'getpaid_reports_get_invoice_report_query', $query, $data );
125
+        $query = implode( ' ', $query );
126
+
127
+        return self::execute( $query_type, $query );
128
+
129
+    }
130
+
131
+    /**
132
+     * Prepares the data to select.
133
+     *
134
+     *
135
+     * @param  array $data
136
+     * @return array
137
+     */
138
+    public static function prepare_invoice_data( $data ) {
139
+
140
+        $prepared = array();
141
+
142
+        foreach ( $data as $raw_key => $value ) {
143
+            $key      = sanitize_key( $raw_key );
144
+            $distinct = '';
145
+
146
+            if ( isset( $value['distinct'] ) ) {
147
+                $distinct = 'DISTINCT';
148
+            }
149
+
150
+            $get_key = self::get_invoice_table_key( $key, $value['type'] );
151
+
152
+            if ( false === $get_key ) {
153
+                // Skip to the next foreach iteration else the query will be invalid.
154
+                continue;
155
+            }
156
+
157
+            if ( ! empty( $value['function'] ) ) {
158
+                $get = "{$value['function']}({$distinct} {$get_key})";
159
+            } else {
160
+                $get = "{$distinct} {$get_key}";
161
+            }
162
+
163
+            $prepared[] = "{$get} as {$value['name']}";
164
+        }
165
+
166
+        return $prepared;
167
+
168
+    }
169
+
170
+    /**
171
+     * Prepares the joins to use.
172
+     *
173
+     *
174
+     * @param  array $data
175
+     * @param  bool $with_parent
176
+     * @return array
177
+     */
178
+    public static function prepare_invoice_joins( $data, $with_parent ) {
179
+        global $wpdb;
180
+
181
+        $prepared = array();
182
+
183
+        foreach ( $data as $raw_key => $value ) {
184
+            $join_type = isset( $value['join_type'] ) ? $value['join_type'] : 'INNER';
185
+            $type      = isset( $value['type'] ) ? $value['type'] : false;
186
+            $key       = sanitize_key( $raw_key );
187
+
188
+            switch ( $type ) {
189
+                case 'meta':
190
+                    $prepared[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )";
191
+                    break;
192
+                case 'parent_meta':
193
+                    $prepared[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')";
194
+                    break;
195
+                case 'invoice_data':
196
+                    $prepared['invoices'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoices AS invoices ON posts.ID = invoices.post_id";
197
+                    break;
198
+                case 'invoice_item':
199
+                    $prepared['invoice_items'] = "{$join_type} JOIN {$wpdb->prefix}getpaid_invoice_items AS invoice_items ON posts.ID = invoice_items.post_id";
200
+                    break;
201
+            }
202
+        }
203
+
204
+        if ( $with_parent ) {
205
+            $prepared['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID";
206
+        }
207
+
208
+        return $prepared;
209
+
210
+    }
211
+
212
+    /**
213
+     * Retrieves the appropriate table key to use.
214
+     *
215
+     *
216
+     * @param  string $key
217
+     * @param  string $table
218
+     * @return string|false
219
+     */
220
+    public static function get_invoice_table_key( $key, $table ) {
221
+
222
+        $keys = array(
223
+            'meta'         => "meta_{$key}.meta_value",
224
+            'parent_meta'  => "parent_meta_{$key}.meta_value",
225
+            'post_data'    => "posts.{$key}",
226
+            'invoice_data' => "invoices.{$key}",
227
+            'invoice_item' => "invoice_items.{$key}",
228
+        );
229
+
230
+        return isset( $keys[ $table ] ) ? $keys[ $table ] : false;
231
+
232
+    }
233
+
234
+    /**
235
+     * Executes a query and caches the result for a minute.
236
+     *
237
+     *
238
+     * @param  string $query_type
239
+     * @param  string $query
240
+     * @return mixed depending on query_type
241
+     */
242
+    public static function execute( $query_type, $query ) {
243
+        global $wpdb;
244
+
245
+        $query_hash = md5( $query_type . $query );
246
+        $result     = self::get_cached_query( $query_hash );
247
+        if ( $result === false ) {
248
+            self::enable_big_selects();
249
+
250
+            $result = $wpdb->$query_type( $query );
251
+            self::set_cached_query( $query_hash, $result );
252
+        }
253
+
254
+        return $result;
255
+
256
+    }
257
+
258
+    /**
259
+     * Enables big mysql selects for reports, just once for this session.
260
+     */
261
+    protected static function enable_big_selects() {
262
+        static $big_selects = false;
263
+
264
+        global $wpdb;
265
+
266
+        if ( ! $big_selects ) {
267
+            $wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
268
+            $big_selects = true;
269
+        }
270
+    }
271
+
272
+    /**
273
+     * Get the cached query result or null if it's not in the cache.
274
+     *
275
+     * @param string $query_hash The query hash.
276
+     *
277
+     * @return mixed|false The cache contents on success, false on failure to retrieve contents.
278
+     */
279
+    protected static function get_cached_query( $query_hash ) {
280
+
281
+        return wp_cache_get(
282
+            $query_hash,
283
+            strtolower( __CLASS__ )
284
+        );
285
+
286
+    }
287
+
288
+    /**
289
+     * Set the cached query result.
290
+     *
291
+     * @param string $query_hash The query hash.
292
+     * @param mixed  $data The data to cache.
293
+     */
294
+    protected static function set_cached_query( $query_hash, $data ) {
295
+
296
+        wp_cache_set(
297
+            $query_hash,
298
+            $data,
299
+            strtolower( __CLASS__ ),
300
+            MINUTE_IN_SECONDS
301
+        );
302
+
303
+    }
304 304
 
305 305
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-taxes.php 1 patch
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -12,228 +12,228 @@
 block discarded – undo
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
+            if ( ! isset( $this->taxes[ $name ] ) ) {
71
+                $this->taxes[ $name ] = $tax;
72
+                continue;
73
+            }
74
+
75
+            $this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
76
+            $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
77
+
78
+        }
79
+
80
+    }
81
+
82
+    /**
83
+     * Checks if the submission has a digital item.
84
+     *
85
+     * @param GetPaid_Payment_Form_Submission $submission
86
+     * @since 1.0.19
87
+     * @return bool
88
+     */
89
+    public function has_digital_item( $submission ) {
90
+
91
+        foreach ( $submission->get_items() as $item ) {
92
+
93
+            if ( 'digital' == $item->get_vat_rule() ) {
94
+                return true;
95
+            }
96
+
97
+        }
98
+
99
+        return false;
100
+    }
101
+
102
+    /**
103
+     * Checks if this is an eu store.
104
+     *
105
+     * @since 1.0.19
106
+     * @return bool
107
+     */
108
+    public static function is_eu_store() {
109
+        return self::is_eu_country( wpinv_get_default_country() );
110
+    }
26 111
 
27 112
     /**
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
-			if ( ! isset( $this->taxes[ $name ] ) ) {
71
-				$this->taxes[ $name ] = $tax;
72
-				continue;
73
-			}
74
-
75
-			$this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
76
-			$this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
77
-
78
-		}
79
-
80
-	}
81
-
82
-	/**
83
-	 * Checks if the submission has a digital item.
84
-	 *
85
-	 * @param GetPaid_Payment_Form_Submission $submission
86
-	 * @since 1.0.19
87
-	 * @return bool
88
-	 */
89
-	public function has_digital_item( $submission ) {
90
-
91
-		foreach ( $submission->get_items() as $item ) {
92
-
93
-			if ( 'digital' == $item->get_vat_rule() ) {
94
-				return true;
95
-			}
96
-
97
-		}
98
-
99
-		return false;
100
-	}
101
-
102
-	/**
103
-	 * Checks if this is an eu store.
104
-	 *
105
-	 * @since 1.0.19
106
-	 * @return bool
107
-	 */
108
-	public static function is_eu_store() {
109
-		return self::is_eu_country( wpinv_get_default_country() );
110
-	}
111
-
112
-	/**
113
-	 * Checks if this is an eu country.
114
-	 *
115
-	 * @param string $country
116
-	 * @since 1.0.19
117
-	 * @return bool
118
-	 */
119
-	public static function is_eu_country( $country ) {
120
-		return getpaid_is_eu_state( $country );
121
-	}
122
-
123
-	/**
124
-	 * Checks if this is an eu purchase.
125
-	 *
126
-	 * @param string $customer_country
127
-	 * @since 1.0.19
128
-	 * @return bool
129
-	 */
130
-	public static function is_eu_transaction( $customer_country ) {
131
-		return self::is_eu_country( $customer_country ) && self::is_eu_store();
132
-	}
133
-
134
-	/**
135
-	 * Retrieves the vat number.
136
-	 *
137
-	 * @param GetPaid_Payment_Form_Submission $submission
138
-	 * @since 1.0.19
139
-	 * @return string
140
-	 */
141
-	public function get_vat_number( $submission ) {
142
-
143
-		// Retrieve from the posted number.
144
-		$vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
145
-		if ( ! is_null( $vat_number ) ) {
146
-			return wpinv_clean( $vat_number );
147
-		}
148
-
149
-		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
150
-	}
151
-
152
-	/**
153
-	 * Retrieves the company.
154
-	 *
155
-	 * @param GetPaid_Payment_Form_Submission $submission
156
-	 * @since 1.0.19
157
-	 * @return string
158
-	 */
159
-	public function get_company( $submission ) {
160
-
161
-		// Retrieve from the posted data.
162
-		$company = $submission->get_field( 'wpinv_company', 'billing' );
163
-		if ( ! empty( $company ) ) {
164
-			return wpinv_clean( $company );
165
-		}
166
-
167
-		// Retrieve from the invoice.
168
-		return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
169
-	}
170
-
171
-	/**
172
-	 * Checks if we require a VAT number.
173
-	 *
174
-	 * @param bool $ip_in_eu Whether the customer IP is from the EU
175
-	 * @param bool $country_in_eu Whether the customer country is from the EU
176
-	 * @since 1.0.19
177
-	 * @return string
178
-	 */
179
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
180
-
181
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
182
-		$prevent_b2c = ! empty( $prevent_b2c );
183
-		$is_eu       = $ip_in_eu || $country_in_eu;
184
-
185
-		return $prevent_b2c && $is_eu;
186
-	}
187
-
188
-	/**
189
-	 * Validate VAT data.
190
-	 *
191
-	 * @param GetPaid_Payment_Form_Submission $submission
192
-	 * @since 1.0.19
193
-	 */
194
-	public function validate_vat( $submission ) {
195
-
196
-		$in_eu = $this->is_eu_transaction( $submission->country );
197
-
198
-		// Abort if we are not validating vat numbers.
199
-		if ( ! $in_eu ) {
113
+     * Checks if this is an eu country.
114
+     *
115
+     * @param string $country
116
+     * @since 1.0.19
117
+     * @return bool
118
+     */
119
+    public static function is_eu_country( $country ) {
120
+        return getpaid_is_eu_state( $country );
121
+    }
122
+
123
+    /**
124
+     * Checks if this is an eu purchase.
125
+     *
126
+     * @param string $customer_country
127
+     * @since 1.0.19
128
+     * @return bool
129
+     */
130
+    public static function is_eu_transaction( $customer_country ) {
131
+        return self::is_eu_country( $customer_country ) && self::is_eu_store();
132
+    }
133
+
134
+    /**
135
+     * Retrieves the vat number.
136
+     *
137
+     * @param GetPaid_Payment_Form_Submission $submission
138
+     * @since 1.0.19
139
+     * @return string
140
+     */
141
+    public function get_vat_number( $submission ) {
142
+
143
+        // Retrieve from the posted number.
144
+        $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
145
+        if ( ! is_null( $vat_number ) ) {
146
+            return wpinv_clean( $vat_number );
147
+        }
148
+
149
+        return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
150
+    }
151
+
152
+    /**
153
+     * Retrieves the company.
154
+     *
155
+     * @param GetPaid_Payment_Form_Submission $submission
156
+     * @since 1.0.19
157
+     * @return string
158
+     */
159
+    public function get_company( $submission ) {
160
+
161
+        // Retrieve from the posted data.
162
+        $company = $submission->get_field( 'wpinv_company', 'billing' );
163
+        if ( ! empty( $company ) ) {
164
+            return wpinv_clean( $company );
165
+        }
166
+
167
+        // Retrieve from the invoice.
168
+        return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
169
+    }
170
+
171
+    /**
172
+     * Checks if we require a VAT number.
173
+     *
174
+     * @param bool $ip_in_eu Whether the customer IP is from the EU
175
+     * @param bool $country_in_eu Whether the customer country is from the EU
176
+     * @since 1.0.19
177
+     * @return string
178
+     */
179
+    public function requires_vat( $ip_in_eu, $country_in_eu ) {
180
+
181
+        $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
182
+        $prevent_b2c = ! empty( $prevent_b2c );
183
+        $is_eu       = $ip_in_eu || $country_in_eu;
184
+
185
+        return $prevent_b2c && $is_eu;
186
+    }
187
+
188
+    /**
189
+     * Validate VAT data.
190
+     *
191
+     * @param GetPaid_Payment_Form_Submission $submission
192
+     * @since 1.0.19
193
+     */
194
+    public function validate_vat( $submission ) {
195
+
196
+        $in_eu = $this->is_eu_transaction( $submission->country );
197
+
198
+        // Abort if we are not validating vat numbers.
199
+        if ( ! $in_eu ) {
200 200
             return;
201
-		}
201
+        }
202 202
 
203
-		// Prepare variables.
204
-		$vat_number  = $this->get_vat_number( $submission );
205
-		$ip_country  = getpaid_get_ip_country();
203
+        // Prepare variables.
204
+        $vat_number  = $this->get_vat_number( $submission );
205
+        $ip_country  = getpaid_get_ip_country();
206 206
         $is_eu       = $this->is_eu_country( $submission->country );
207 207
         $is_ip_eu    = $this->is_eu_country( $ip_country );
208 208
 
209
-		// Maybe abort early for initial fetches.
210
-		if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
211
-			return;
212
-		}
209
+        // Maybe abort early for initial fetches.
210
+        if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
211
+            return;
212
+        }
213 213
 
214
-		// If we're preventing business to consumer purchases,
215
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
214
+        // If we're preventing business to consumer purchases,
215
+        if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
216 216
 
217
-			// Ensure that a vat number has been specified.
218
-			throw new Exception(
219
-				__( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' )
220
-			);
217
+            // Ensure that a vat number has been specified.
218
+            throw new Exception(
219
+                __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' )
220
+            );
221 221
 
222
-		}
222
+        }
223 223
 
224
-		if ( empty( $vat_number ) ) {
225
-			return;
226
-		}
224
+        if ( empty( $vat_number ) ) {
225
+            return;
226
+        }
227 227
 
228
-		if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
229
-			throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) );
230
-		}
228
+        if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
229
+            throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) );
230
+        }
231 231
 
232
-		if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
233
-			return;
234
-		}
232
+        if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
233
+            return;
234
+        }
235 235
 
236
-		$this->skip_taxes = true;
237
-	}
236
+        $this->skip_taxes = true;
237
+    }
238 238
 
239 239
 }
Please login to merge, or discard this patch.
vendor/composer/installed.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php return array (
2
-  'root' => 
3
-  array (
2
+    'root' => 
3
+    array (
4 4
     'pretty_version' => 'dev-master',
5 5
     'version' => 'dev-master',
6 6
     'aliases' => 
@@ -8,85 +8,85 @@  discard block
 block discarded – undo
8 8
     ),
9 9
     'reference' => '9c927243c25ee910689e3996f51ee54ad348da50',
10 10
     'name' => 'ayecode/invoicing',
11
-  ),
12
-  'versions' => 
13
-  array (
11
+    ),
12
+    'versions' => 
13
+    array (
14 14
     'ayecode/ayecode-connect-helper' => 
15 15
     array (
16
-      'pretty_version' => '1.0.3',
17
-      'version' => '1.0.3.0',
18
-      'aliases' => 
19
-      array (
20
-      ),
21
-      'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4',
16
+        'pretty_version' => '1.0.3',
17
+        'version' => '1.0.3.0',
18
+        'aliases' => 
19
+        array (
20
+        ),
21
+        'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4',
22 22
     ),
23 23
     'ayecode/invoicing' => 
24 24
     array (
25
-      'pretty_version' => 'dev-master',
26
-      'version' => 'dev-master',
27
-      'aliases' => 
28
-      array (
29
-      ),
30
-      'reference' => '9c927243c25ee910689e3996f51ee54ad348da50',
25
+        'pretty_version' => 'dev-master',
26
+        'version' => 'dev-master',
27
+        'aliases' => 
28
+        array (
29
+        ),
30
+        'reference' => '9c927243c25ee910689e3996f51ee54ad348da50',
31 31
     ),
32 32
     'ayecode/wp-ayecode-ui' => 
33 33
     array (
34
-      'pretty_version' => '0.1.46',
35
-      'version' => '0.1.46.0',
36
-      'aliases' => 
37
-      array (
38
-      ),
39
-      'reference' => '8b9825d9fe52f6da57302358df1a920eec3bace3',
34
+        'pretty_version' => '0.1.46',
35
+        'version' => '0.1.46.0',
36
+        'aliases' => 
37
+        array (
38
+        ),
39
+        'reference' => '8b9825d9fe52f6da57302358df1a920eec3bace3',
40 40
     ),
41 41
     'ayecode/wp-font-awesome-settings' => 
42 42
     array (
43
-      'pretty_version' => '1.0.12',
44
-      'version' => '1.0.12.0',
45
-      'aliases' => 
46
-      array (
47
-      ),
48
-      'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288',
43
+        'pretty_version' => '1.0.12',
44
+        'version' => '1.0.12.0',
45
+        'aliases' => 
46
+        array (
47
+        ),
48
+        'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288',
49 49
     ),
50 50
     'ayecode/wp-super-duper' => 
51 51
     array (
52
-      'pretty_version' => '1.0.24',
53
-      'version' => '1.0.24.0',
54
-      'aliases' => 
55
-      array (
56
-      ),
57
-      'reference' => '4eaa2f6f6e1a29ff71f7fdbd694892d7479ef754',
52
+        'pretty_version' => '1.0.24',
53
+        'version' => '1.0.24.0',
54
+        'aliases' => 
55
+        array (
56
+        ),
57
+        'reference' => '4eaa2f6f6e1a29ff71f7fdbd694892d7479ef754',
58 58
     ),
59 59
     'composer/installers' => 
60 60
     array (
61
-      'pretty_version' => 'v1.10.0',
62
-      'version' => '1.10.0.0',
63
-      'aliases' => 
64
-      array (
65
-      ),
66
-      'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d',
61
+        'pretty_version' => 'v1.10.0',
62
+        'version' => '1.10.0.0',
63
+        'aliases' => 
64
+        array (
65
+        ),
66
+        'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d',
67 67
     ),
68 68
     'maxmind-db/reader' => 
69 69
     array (
70
-      'pretty_version' => 'v1.6.0',
71
-      'version' => '1.6.0.0',
72
-      'aliases' => 
73
-      array (
74
-      ),
75
-      'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4',
70
+        'pretty_version' => 'v1.6.0',
71
+        'version' => '1.6.0.0',
72
+        'aliases' => 
73
+        array (
74
+        ),
75
+        'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4',
76 76
     ),
77 77
     'roundcube/plugin-installer' => 
78 78
     array (
79
-      'replaced' => 
80
-      array (
79
+        'replaced' => 
80
+        array (
81 81
         0 => '*',
82
-      ),
82
+        ),
83 83
     ),
84 84
     'shama/baton' => 
85 85
     array (
86
-      'replaced' => 
87
-      array (
86
+        'replaced' => 
87
+        array (
88 88
         0 => '*',
89
-      ),
89
+        ),
90
+    ),
90 91
     ),
91
-  ),
92 92
 );
Please login to merge, or discard this patch.
vendor/composer/InstalledVersions.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
 class InstalledVersions
13 13
 {
14 14
 private static $installed = array (
15
-  'root' => 
16
-  array (
15
+    'root' => 
16
+    array (
17 17
     'pretty_version' => 'dev-master',
18 18
     'version' => 'dev-master',
19 19
     'aliases' => 
@@ -21,87 +21,87 @@  discard block
 block discarded – undo
21 21
     ),
22 22
     'reference' => '9c927243c25ee910689e3996f51ee54ad348da50',
23 23
     'name' => 'ayecode/invoicing',
24
-  ),
25
-  'versions' => 
26
-  array (
24
+    ),
25
+    'versions' => 
26
+    array (
27 27
     'ayecode/ayecode-connect-helper' => 
28 28
     array (
29
-      'pretty_version' => '1.0.3',
30
-      'version' => '1.0.3.0',
31
-      'aliases' => 
32
-      array (
33
-      ),
34
-      'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4',
29
+        'pretty_version' => '1.0.3',
30
+        'version' => '1.0.3.0',
31
+        'aliases' => 
32
+        array (
33
+        ),
34
+        'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4',
35 35
     ),
36 36
     'ayecode/invoicing' => 
37 37
     array (
38
-      'pretty_version' => 'dev-master',
39
-      'version' => 'dev-master',
40
-      'aliases' => 
41
-      array (
42
-      ),
43
-      'reference' => '9c927243c25ee910689e3996f51ee54ad348da50',
38
+        'pretty_version' => 'dev-master',
39
+        'version' => 'dev-master',
40
+        'aliases' => 
41
+        array (
42
+        ),
43
+        'reference' => '9c927243c25ee910689e3996f51ee54ad348da50',
44 44
     ),
45 45
     'ayecode/wp-ayecode-ui' => 
46 46
     array (
47
-      'pretty_version' => '0.1.46',
48
-      'version' => '0.1.46.0',
49
-      'aliases' => 
50
-      array (
51
-      ),
52
-      'reference' => '8b9825d9fe52f6da57302358df1a920eec3bace3',
47
+        'pretty_version' => '0.1.46',
48
+        'version' => '0.1.46.0',
49
+        'aliases' => 
50
+        array (
51
+        ),
52
+        'reference' => '8b9825d9fe52f6da57302358df1a920eec3bace3',
53 53
     ),
54 54
     'ayecode/wp-font-awesome-settings' => 
55 55
     array (
56
-      'pretty_version' => '1.0.12',
57
-      'version' => '1.0.12.0',
58
-      'aliases' => 
59
-      array (
60
-      ),
61
-      'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288',
56
+        'pretty_version' => '1.0.12',
57
+        'version' => '1.0.12.0',
58
+        'aliases' => 
59
+        array (
60
+        ),
61
+        'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288',
62 62
     ),
63 63
     'ayecode/wp-super-duper' => 
64 64
     array (
65
-      'pretty_version' => '1.0.24',
66
-      'version' => '1.0.24.0',
67
-      'aliases' => 
68
-      array (
69
-      ),
70
-      'reference' => '4eaa2f6f6e1a29ff71f7fdbd694892d7479ef754',
65
+        'pretty_version' => '1.0.24',
66
+        'version' => '1.0.24.0',
67
+        'aliases' => 
68
+        array (
69
+        ),
70
+        'reference' => '4eaa2f6f6e1a29ff71f7fdbd694892d7479ef754',
71 71
     ),
72 72
     'composer/installers' => 
73 73
     array (
74
-      'pretty_version' => 'v1.10.0',
75
-      'version' => '1.10.0.0',
76
-      'aliases' => 
77
-      array (
78
-      ),
79
-      'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d',
74
+        'pretty_version' => 'v1.10.0',
75
+        'version' => '1.10.0.0',
76
+        'aliases' => 
77
+        array (
78
+        ),
79
+        'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d',
80 80
     ),
81 81
     'maxmind-db/reader' => 
82 82
     array (
83
-      'pretty_version' => 'v1.6.0',
84
-      'version' => '1.6.0.0',
85
-      'aliases' => 
86
-      array (
87
-      ),
88
-      'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4',
83
+        'pretty_version' => 'v1.6.0',
84
+        'version' => '1.6.0.0',
85
+        'aliases' => 
86
+        array (
87
+        ),
88
+        'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4',
89 89
     ),
90 90
     'roundcube/plugin-installer' => 
91 91
     array (
92
-      'replaced' => 
93
-      array (
92
+        'replaced' => 
93
+        array (
94 94
         0 => '*',
95
-      ),
95
+        ),
96 96
     ),
97 97
     'shama/baton' => 
98 98
     array (
99
-      'replaced' => 
100
-      array (
99
+        'replaced' => 
100
+        array (
101 101
         0 => '*',
102
-      ),
102
+        ),
103
+    ),
103 104
     ),
104
-  ),
105 105
 );
106 106
 
107 107
 
Please login to merge, or discard this patch.
includes/class-wpinv-notes.php 1 patch
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -12,202 +12,202 @@
 block discarded – undo
12 12
  */
13 13
 class WPInv_Notes {
14 14
 
15
-	/**
16
-	 * Class constructor.
17
-	 */
18
-	public function __construct() {
19
-
20
-		// Filter inovice notes.
21
-		add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
22
-		add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 );
23
-
24
-		// Delete comments count cache whenever there is a new comment or a comment status changes.
25
-		add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) );
26
-		add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) );
27
-
28
-		// Count comments.
29
-		add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 );
30
-
31
-		// Fires after notes are loaded.
32
-		do_action( 'wpinv_notes_init', $this );
33
-	}
34
-
35
-	/**
36
-	 * Filters invoice notes query to only include our notes.
37
-	 *
38
-	 * @param WP_Comment_Query $query
39
-	 */
40
-	public function set_invoice_note_type( $query ) {
41
-		$post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
42
-
43
-		if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) {
44
-			$query->query_vars['type'] = 'wpinv_note';
45
-		} else {
46
-
47
-			if ( empty( $query->query_vars['type__not_in'] ) ) {
48
-				$query->query_vars['type__not_in'] = array();
49
-			}
50
-
51
-			$query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] );
52
-			$query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] );
53
-		}
54
-
55
-		return $query;
56
-	}
57
-
58
-	/**
59
-	 * Exclude notes from the comments feed.
60
-	 */
61
-	function wpinv_comment_feed_where( $where ){
62
-		return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
63
-	}
64
-
65
-	/**
66
-	 * Delete comments count cache whenever there is
67
-	 * new comment or the status of a comment changes. Cache
68
-	 * will be regenerated next time WPInv_Notes::wp_count_comments()
69
-	 * is called.
70
-	 */
71
-	public function delete_comments_count_cache() {
72
-		delete_transient( 'getpaid_count_comments' );
73
-	}
74
-
75
-	/**
76
-	 * Remove invoice notes from wp_count_comments().
77
-	 *
78
-	 * @since  2.2
79
-	 * @param  object $stats   Comment stats.
80
-	 * @param  int    $post_id Post ID.
81
-	 * @return object
82
-	 */
83
-	public function wp_count_comments( $stats, $post_id ) {
84
-		global $wpdb;
85
-
86
-		if ( empty( $post_id ) ) {
87
-			$stats = get_transient( 'getpaid_count_comments' );
88
-
89
-			if ( ! $stats ) {
90
-				$stats = array(
91
-					'total_comments' => 0,
92
-					'all'            => 0,
93
-				);
94
-
95
-				$count = $wpdb->get_results(
96
-					"
15
+    /**
16
+     * Class constructor.
17
+     */
18
+    public function __construct() {
19
+
20
+        // Filter inovice notes.
21
+        add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
22
+        add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 );
23
+
24
+        // Delete comments count cache whenever there is a new comment or a comment status changes.
25
+        add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) );
26
+        add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) );
27
+
28
+        // Count comments.
29
+        add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 );
30
+
31
+        // Fires after notes are loaded.
32
+        do_action( 'wpinv_notes_init', $this );
33
+    }
34
+
35
+    /**
36
+     * Filters invoice notes query to only include our notes.
37
+     *
38
+     * @param WP_Comment_Query $query
39
+     */
40
+    public function set_invoice_note_type( $query ) {
41
+        $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
42
+
43
+        if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) {
44
+            $query->query_vars['type'] = 'wpinv_note';
45
+        } else {
46
+
47
+            if ( empty( $query->query_vars['type__not_in'] ) ) {
48
+                $query->query_vars['type__not_in'] = array();
49
+            }
50
+
51
+            $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] );
52
+            $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] );
53
+        }
54
+
55
+        return $query;
56
+    }
57
+
58
+    /**
59
+     * Exclude notes from the comments feed.
60
+     */
61
+    function wpinv_comment_feed_where( $where ){
62
+        return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
63
+    }
64
+
65
+    /**
66
+     * Delete comments count cache whenever there is
67
+     * new comment or the status of a comment changes. Cache
68
+     * will be regenerated next time WPInv_Notes::wp_count_comments()
69
+     * is called.
70
+     */
71
+    public function delete_comments_count_cache() {
72
+        delete_transient( 'getpaid_count_comments' );
73
+    }
74
+
75
+    /**
76
+     * Remove invoice notes from wp_count_comments().
77
+     *
78
+     * @since  2.2
79
+     * @param  object $stats   Comment stats.
80
+     * @param  int    $post_id Post ID.
81
+     * @return object
82
+     */
83
+    public function wp_count_comments( $stats, $post_id ) {
84
+        global $wpdb;
85
+
86
+        if ( empty( $post_id ) ) {
87
+            $stats = get_transient( 'getpaid_count_comments' );
88
+
89
+            if ( ! $stats ) {
90
+                $stats = array(
91
+                    'total_comments' => 0,
92
+                    'all'            => 0,
93
+                );
94
+
95
+                $count = $wpdb->get_results(
96
+                    "
97 97
 					SELECT comment_approved, COUNT(*) AS num_comments
98 98
 					FROM {$wpdb->comments}
99 99
 					WHERE comment_type NOT IN ('action_log', 'order_note', 'webhook_delivery', 'wpinv_note')
100 100
 					GROUP BY comment_approved
101 101
 					",
102
-					ARRAY_A
103
-				);
104
-
105
-				$approved = array(
106
-					'0'            => 'moderated',
107
-					'1'            => 'approved',
108
-					'spam'         => 'spam',
109
-					'trash'        => 'trash',
110
-					'post-trashed' => 'post-trashed',
111
-				);
112
-
113
-				foreach ( (array) $count as $row ) {
114
-					// Don't count post-trashed toward totals.
115
-					if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) {
116
-						$stats['all']            += $row['num_comments'];
117
-						$stats['total_comments'] += $row['num_comments'];
118
-					} elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) {
119
-						$stats['total_comments'] += $row['num_comments'];
120
-					}
121
-					if ( isset( $approved[ $row['comment_approved'] ] ) ) {
122
-						$stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
123
-					}
124
-				}
125
-
126
-				foreach ( $approved as $key ) {
127
-					if ( empty( $stats[ $key ] ) ) {
128
-						$stats[ $key ] = 0;
129
-					}
130
-				}
131
-
132
-				$stats = (object) $stats;
133
-				set_transient( 'getpaid_count_comments', $stats );
134
-			}
135
-
136
-		}
137
-
138
-		return $stats;
139
-	}
140
-
141
-	/**
142
-	 * Returns an array of invoice notes.
143
-	 *
144
-	 * @param int $invoice_id The invoice ID whose notes to retrieve.
145
-	 * @param string $type Optional. Pass in customer to only return customer notes.
146
-	 * @return WP_Comment[]
147
-	 */
148
-	public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) {
149
-
150
-		// Default comment args.
151
-		$args = array(
152
-			'post_id'   => $invoice_id,
153
-			'orderby'   => 'comment_ID',
154
-			'order'     => 'ASC',
155
-		);
156
-
157
-		// Maybe only show customer comments.
158
-		if ( $type == 'customer' ) {
159
-			$args['meta_key']   = '_wpi_customer_note';
160
-			$args['meta_value'] = 1;
161
-		}
162
-
163
-		$args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
164
-
165
-		return get_comments( $args );
166
-	}
167
-
168
-	/**
169
-	 * Saves an invoice comment.
170
-	 * 
171
-	 * @param WPInv_Invoice $invoice The invoice to add the comment to.
172
-	 * @param string $note The note content.
173
-	 * @param string $note_author The name of the author of the note.
174
-	 * @param bool $for_customer Whether or not this comment is meant to be sent to the customer.
175
-	 * @return int|false The new note's ID on success, false on failure.
176
-	 */
177
-	function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ){
178
-
179
-		do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer );
180
-
181
-		/**
182
-		 * Insert the comment.
183
-		 */
184
-		$note_id = wp_insert_comment(
185
-			wp_filter_comment(
186
-				array(
187
-					'comment_post_ID'      => $invoice->get_id(),
188
-					'comment_content'      => $note,
189
-					'comment_agent'        => 'Invoicing',
190
-					'user_id'              => get_current_user_id(),
191
-					'comment_author'       => $note_author,
192
-					'comment_author_IP'    => wpinv_get_ip(),
193
-					'comment_author_email' => $author_email,
194
-					'comment_author_url'   => $invoice->get_view_url(),
195
-					'comment_type'         => 'wpinv_note',
196
-				)
197
-			)
198
-		);
199
-
200
-		do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer );
201
-
202
-		// Are we notifying the customer?
203
-		if ( empty( $note_id ) || empty( $for_customer ) ) {
204
-			return $note_id;
205
-		}
206
-
207
-		add_comment_meta( $note_id, '_wpi_customer_note', 1 );
208
-		do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $invoice->get_id(), 'user_note' => $note ) );
209
-		do_action( 'getpaid_new_customer_note', $invoice, $note );
210
-		return $note_id;
211
-	}
102
+                    ARRAY_A
103
+                );
104
+
105
+                $approved = array(
106
+                    '0'            => 'moderated',
107
+                    '1'            => 'approved',
108
+                    'spam'         => 'spam',
109
+                    'trash'        => 'trash',
110
+                    'post-trashed' => 'post-trashed',
111
+                );
112
+
113
+                foreach ( (array) $count as $row ) {
114
+                    // Don't count post-trashed toward totals.
115
+                    if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) {
116
+                        $stats['all']            += $row['num_comments'];
117
+                        $stats['total_comments'] += $row['num_comments'];
118
+                    } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) {
119
+                        $stats['total_comments'] += $row['num_comments'];
120
+                    }
121
+                    if ( isset( $approved[ $row['comment_approved'] ] ) ) {
122
+                        $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
123
+                    }
124
+                }
125
+
126
+                foreach ( $approved as $key ) {
127
+                    if ( empty( $stats[ $key ] ) ) {
128
+                        $stats[ $key ] = 0;
129
+                    }
130
+                }
131
+
132
+                $stats = (object) $stats;
133
+                set_transient( 'getpaid_count_comments', $stats );
134
+            }
135
+
136
+        }
137
+
138
+        return $stats;
139
+    }
140
+
141
+    /**
142
+     * Returns an array of invoice notes.
143
+     *
144
+     * @param int $invoice_id The invoice ID whose notes to retrieve.
145
+     * @param string $type Optional. Pass in customer to only return customer notes.
146
+     * @return WP_Comment[]
147
+     */
148
+    public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) {
149
+
150
+        // Default comment args.
151
+        $args = array(
152
+            'post_id'   => $invoice_id,
153
+            'orderby'   => 'comment_ID',
154
+            'order'     => 'ASC',
155
+        );
156
+
157
+        // Maybe only show customer comments.
158
+        if ( $type == 'customer' ) {
159
+            $args['meta_key']   = '_wpi_customer_note';
160
+            $args['meta_value'] = 1;
161
+        }
162
+
163
+        $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
164
+
165
+        return get_comments( $args );
166
+    }
167
+
168
+    /**
169
+     * Saves an invoice comment.
170
+     * 
171
+     * @param WPInv_Invoice $invoice The invoice to add the comment to.
172
+     * @param string $note The note content.
173
+     * @param string $note_author The name of the author of the note.
174
+     * @param bool $for_customer Whether or not this comment is meant to be sent to the customer.
175
+     * @return int|false The new note's ID on success, false on failure.
176
+     */
177
+    function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ){
178
+
179
+        do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer );
180
+
181
+        /**
182
+         * Insert the comment.
183
+         */
184
+        $note_id = wp_insert_comment(
185
+            wp_filter_comment(
186
+                array(
187
+                    'comment_post_ID'      => $invoice->get_id(),
188
+                    'comment_content'      => $note,
189
+                    'comment_agent'        => 'Invoicing',
190
+                    'user_id'              => get_current_user_id(),
191
+                    'comment_author'       => $note_author,
192
+                    'comment_author_IP'    => wpinv_get_ip(),
193
+                    'comment_author_email' => $author_email,
194
+                    'comment_author_url'   => $invoice->get_view_url(),
195
+                    'comment_type'         => 'wpinv_note',
196
+                )
197
+            )
198
+        );
199
+
200
+        do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer );
201
+
202
+        // Are we notifying the customer?
203
+        if ( empty( $note_id ) || empty( $for_customer ) ) {
204
+            return $note_id;
205
+        }
206
+
207
+        add_comment_meta( $note_id, '_wpi_customer_note', 1 );
208
+        do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $invoice->get_id(), 'user_note' => $note ) );
209
+        do_action( 'getpaid_new_customer_note', $invoice, $note );
210
+        return $note_id;
211
+    }
212 212
 
213 213
 }
Please login to merge, or discard this patch.
includes/invoice-functions.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
  * Checks if the current user cna view an invoice receipt.
68 68
  */
69 69
 function wpinv_can_view_receipt( $invoice ) {
70
-	return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
70
+    return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
71 71
 }
72 72
 
73 73
 /**
@@ -1280,22 +1280,22 @@  discard block
 block discarded – undo
1280 1280
  */
1281 1281
 function getpaid_get_invoice_status_classes() {
1282 1282
 
1283
-	return apply_filters(
1284
-		'getpaid_get_invoice_status_classes',
1285
-		array(
1283
+    return apply_filters(
1284
+        'getpaid_get_invoice_status_classes',
1285
+        array(
1286 1286
             'wpi-quote-declined' => 'badge-danger',
1287 1287
             'wpi-failed'         => 'badge-danger',
1288
-			'wpi-processing'     => 'badge-info',
1289
-			'wpi-onhold'         => 'badge-warning',
1290
-			'wpi-quote-accepted' => 'badge-success',
1291
-			'publish'            => 'badge-success',
1292
-			'wpi-renewal'        => 'badge-primary',
1288
+            'wpi-processing'     => 'badge-info',
1289
+            'wpi-onhold'         => 'badge-warning',
1290
+            'wpi-quote-accepted' => 'badge-success',
1291
+            'publish'            => 'badge-success',
1292
+            'wpi-renewal'        => 'badge-primary',
1293 1293
             'wpi-cancelled'      => 'badge-secondary',
1294 1294
             'wpi-pending'        => 'badge-dark',
1295 1295
             'wpi-quote-pending'  => 'badge-dark',
1296 1296
             'wpi-refunded'       => 'badge-secondary',
1297
-		)
1298
-	);
1297
+        )
1298
+    );
1299 1299
 
1300 1300
 }
1301 1301
 
@@ -1309,7 +1309,7 @@  discard block
 block discarded – undo
1309 1309
 function getpaid_get_invoice_tax_rate( $invoice, $item ) {
1310 1310
 
1311 1311
     $rates   = getpaid_get_item_tax_rates( $item, $invoice->get_country(), $invoice->get_state() );
1312
-	$rates   = getpaid_filter_item_tax_rates( $item, $rates );
1312
+    $rates   = getpaid_filter_item_tax_rates( $item, $rates );
1313 1313
     $rates   = wp_list_pluck( $rates, 'rate' );
1314 1314
 	
1315 1315
     return array_sum( $rates );
Please login to merge, or discard this patch.