Passed
Push — master ( eadd35...968588 )
by Brian
04:42
created
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 1 patch
Indentation   +267 added lines, -267 removed lines patch added patch discarded remove patch
@@ -12,294 +12,294 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Refresh_Prices {
14 14
 
15
-	/**
16
-	 * Contains the response for refreshing prices.
17
-	 * @var array
18
-	 */
19
-	public $response = array();
15
+    /**
16
+     * Contains the response for refreshing prices.
17
+     * @var array
18
+     */
19
+    public $response = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$this->response = array(
29
-			'submission_id'                    => $submission->id,
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $this->response = array(
29
+            'submission_id'                    => $submission->id,
30 30
             'has_recurring'                    => $submission->has_recurring,
31
-			'has_subscription_group'           => $submission->has_subscription_group(),
32
-			'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
31
+            'has_subscription_group'           => $submission->has_subscription_group(),
32
+            'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
33 33
             'is_free'                          => ! $submission->should_collect_payment_details(),
34
-		);
35
-
36
-		$this->add_totals( $submission );
37
-		$this->add_texts( $submission );
38
-		$this->add_items( $submission );
39
-		$this->add_fees( $submission );
40
-		$this->add_discounts( $submission );
41
-		$this->add_taxes( $submission );
42
-		$this->add_gateways( $submission );
43
-		$this->add_data( $submission );
44
-
45
-	}
46
-
47
-	/**
48
-	 * Adds totals to a response for submission refresh prices.
49
-	 *
50
-	 * @param GetPaid_Payment_Form_Submission $submission
51
-	 */
52
-	public function add_totals( $submission ) {
53
-
54
-		$this->response = array_merge(
55
-			$this->response,
56
-			array(
57
-
58
-				'totals'        => array(
59
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
60
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
61
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
62
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
63
-					'total'     => $submission->format_amount( $submission->get_total() ),
64
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
65
-				),
66
-
67
-				'recurring'     => array(
68
-					'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
69
-					'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
70
-					'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
71
-					'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
72
-					'total'     => $submission->format_amount( $submission->get_recurring_total() ),
73
-				),
74
-
75
-				'initial_amt'   => wpinv_round_amount( $submission->get_total(), null, true ),
76
-				'currency'      => $submission->get_currency(),
77
-
78
-			)
79
-		);
80
-
81
-	}
82
-
83
-	/**
84
-	 * Adds texts to a response for submission refresh prices.
85
-	 *
86
-	 * @param GetPaid_Payment_Form_Submission $submission
87
-	 */
88
-	public function add_texts( $submission ) {
89
-
90
-		$payable = $submission->format_amount( $submission->get_total() );
91
-		$groups  = getpaid_get_subscription_groups( $submission );
92
-
93
-		if ( $submission->has_recurring && 2 > count( $groups ) ) {
94
-
95
-			$recurring = new WPInv_Item( $submission->has_recurring );
96
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
97
-			$main_item = reset( $groups );
98
-
99
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
100
-				$payable = "$payable / $period";
101
-			} else if ( $main_item ) {
102
-
103
-				$main_item = reset( $main_item );
104
-
105
-				// Calculate the next renewal date.
106
-				$_period      = $main_item->get_recurring_period( true );
107
-				$_interval    = $main_item->get_recurring_interval();
108
-
109
-				// If the subscription item has a trial period...
110
-				if ( $main_item->has_free_trial() ) {
111
-					$_period   = $main_item->get_trial_period( true );
112
-					$_interval = $main_item->get_trial_interval();
113
-				}
114
-
115
-				$payable = sprintf(
116
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
117
-					$submission->format_amount( $submission->get_total() ),
118
-					$submission->format_amount( $submission->get_recurring_total() ),
119
-					$period
120
-				);
121
-
122
-				$payable .= sprintf(
123
-					'<small class="text-muted form-text">%s</small>',
124
-					sprintf(
125
-						__( 'First renewal on %s', 'invoicing' ),
126
-						getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) )
127
-					)
128
-				);
129
-
130
-			} else {
131
-				$payable = sprintf(
132
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
133
-					$submission->format_amount( $submission->get_total() ),
134
-					$submission->format_amount( $submission->get_recurring_total() ),
135
-					$period
136
-				);
137
-			}
138
-
139
-		}
140
-
141
-		$texts = array(
142
-			'.getpaid-checkout-total-payable' => $payable,
143
-		);
144
-
145
-		foreach ( $submission->get_items() as $item ) {
146
-			$item_id                                               = $item->get_id();
147
-			$initial_price                                         = $submission->format_amount( $item->get_sub_total() - $item->item_discount );
148
-			$recurring_price                                       = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount );
149
-			$texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
150
-			$texts[".item-$item_id .getpaid-mobile-item-subtotal"] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) );
151
-
152
-			if ( $item->get_quantity() == 1 ) {
153
-				$texts[".item-$item_id .getpaid-mobile-item-subtotal"] = '';
154
-			}
155
-
156
-		}
157
-
158
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
159
-
160
-	}
161
-
162
-	/**
163
-	 * Adds items to a response for submission refresh prices.
164
-	 *
165
-	 * @param GetPaid_Payment_Form_Submission $submission
166
-	 */
167
-	public function add_items( $submission ) {
168
-
169
-		// Add items.
170
-		$items = array();
34
+        );
35
+
36
+        $this->add_totals( $submission );
37
+        $this->add_texts( $submission );
38
+        $this->add_items( $submission );
39
+        $this->add_fees( $submission );
40
+        $this->add_discounts( $submission );
41
+        $this->add_taxes( $submission );
42
+        $this->add_gateways( $submission );
43
+        $this->add_data( $submission );
44
+
45
+    }
46
+
47
+    /**
48
+     * Adds totals to a response for submission refresh prices.
49
+     *
50
+     * @param GetPaid_Payment_Form_Submission $submission
51
+     */
52
+    public function add_totals( $submission ) {
53
+
54
+        $this->response = array_merge(
55
+            $this->response,
56
+            array(
57
+
58
+                'totals'        => array(
59
+                    'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
60
+                    'discount'  => $submission->format_amount( $submission->get_discount() ),
61
+                    'fees'      => $submission->format_amount( $submission->get_fee() ),
62
+                    'tax'       => $submission->format_amount( $submission->get_tax() ),
63
+                    'total'     => $submission->format_amount( $submission->get_total() ),
64
+                    'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
65
+                ),
66
+
67
+                'recurring'     => array(
68
+                    'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
69
+                    'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
70
+                    'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
71
+                    'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
72
+                    'total'     => $submission->format_amount( $submission->get_recurring_total() ),
73
+                ),
74
+
75
+                'initial_amt'   => wpinv_round_amount( $submission->get_total(), null, true ),
76
+                'currency'      => $submission->get_currency(),
77
+
78
+            )
79
+        );
80
+
81
+    }
82
+
83
+    /**
84
+     * Adds texts to a response for submission refresh prices.
85
+     *
86
+     * @param GetPaid_Payment_Form_Submission $submission
87
+     */
88
+    public function add_texts( $submission ) {
89
+
90
+        $payable = $submission->format_amount( $submission->get_total() );
91
+        $groups  = getpaid_get_subscription_groups( $submission );
92
+
93
+        if ( $submission->has_recurring && 2 > count( $groups ) ) {
94
+
95
+            $recurring = new WPInv_Item( $submission->has_recurring );
96
+            $period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
97
+            $main_item = reset( $groups );
98
+
99
+            if ( $submission->get_total() == $submission->get_recurring_total() ) {
100
+                $payable = "$payable / $period";
101
+            } else if ( $main_item ) {
102
+
103
+                $main_item = reset( $main_item );
104
+
105
+                // Calculate the next renewal date.
106
+                $_period      = $main_item->get_recurring_period( true );
107
+                $_interval    = $main_item->get_recurring_interval();
108
+
109
+                // If the subscription item has a trial period...
110
+                if ( $main_item->has_free_trial() ) {
111
+                    $_period   = $main_item->get_trial_period( true );
112
+                    $_interval = $main_item->get_trial_interval();
113
+                }
114
+
115
+                $payable = sprintf(
116
+                    __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
117
+                    $submission->format_amount( $submission->get_total() ),
118
+                    $submission->format_amount( $submission->get_recurring_total() ),
119
+                    $period
120
+                );
121
+
122
+                $payable .= sprintf(
123
+                    '<small class="text-muted form-text">%s</small>',
124
+                    sprintf(
125
+                        __( 'First renewal on %s', 'invoicing' ),
126
+                        getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) )
127
+                    )
128
+                );
129
+
130
+            } else {
131
+                $payable = sprintf(
132
+                    __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
133
+                    $submission->format_amount( $submission->get_total() ),
134
+                    $submission->format_amount( $submission->get_recurring_total() ),
135
+                    $period
136
+                );
137
+            }
138
+
139
+        }
140
+
141
+        $texts = array(
142
+            '.getpaid-checkout-total-payable' => $payable,
143
+        );
144
+
145
+        foreach ( $submission->get_items() as $item ) {
146
+            $item_id                                               = $item->get_id();
147
+            $initial_price                                         = $submission->format_amount( $item->get_sub_total() - $item->item_discount );
148
+            $recurring_price                                       = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount );
149
+            $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
150
+            $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) );
151
+
152
+            if ( $item->get_quantity() == 1 ) {
153
+                $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = '';
154
+            }
155
+
156
+        }
157
+
158
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
159
+
160
+    }
161
+
162
+    /**
163
+     * Adds items to a response for submission refresh prices.
164
+     *
165
+     * @param GetPaid_Payment_Form_Submission $submission
166
+     */
167
+    public function add_items( $submission ) {
168
+
169
+        // Add items.
170
+        $items = array();
171 171
 
172 172
         foreach ( $submission->get_items() as $item ) {
173
-			$item_id           = $item->get_id();
174
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
175
-		}
173
+            $item_id           = $item->get_id();
174
+            $items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
175
+        }
176 176
 
177
-		$this->response = array_merge(
178
-			$this->response,
179
-			array( 'items' => $items )
180
-		);
177
+        $this->response = array_merge(
178
+            $this->response,
179
+            array( 'items' => $items )
180
+        );
181 181
 
182
-	}
182
+    }
183 183
 
184
-	/**
185
-	 * Adds fees to a response for submission refresh prices.
186
-	 *
187
-	 * @param GetPaid_Payment_Form_Submission $submission
188
-	 */
189
-	public function add_fees( $submission ) {
184
+    /**
185
+     * Adds fees to a response for submission refresh prices.
186
+     *
187
+     * @param GetPaid_Payment_Form_Submission $submission
188
+     */
189
+    public function add_fees( $submission ) {
190 190
 
191
-		$fees = array();
191
+        $fees = array();
192 192
 
193 193
         foreach ( $submission->get_fees() as $name => $data ) {
194
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
195
-		}
194
+            $fees[$name] = $submission->format_amount( $data['initial_fee'] );
195
+        }
196 196
 
197
-		$this->response = array_merge(
198
-			$this->response,
199
-			array( 'fees' => $fees )
200
-		);
197
+        $this->response = array_merge(
198
+            $this->response,
199
+            array( 'fees' => $fees )
200
+        );
201 201
 
202
-	}
202
+    }
203 203
 
204
-	/**
205
-	 * Adds discounts to a response for submission refresh prices.
206
-	 *
207
-	 * @param GetPaid_Payment_Form_Submission $submission
208
-	 */
209
-	public function add_discounts( $submission ) {
204
+    /**
205
+     * Adds discounts to a response for submission refresh prices.
206
+     *
207
+     * @param GetPaid_Payment_Form_Submission $submission
208
+     */
209
+    public function add_discounts( $submission ) {
210 210
 
211
-		$discounts = array();
211
+        $discounts = array();
212 212
 
213 213
         foreach ( $submission->get_discounts() as $name => $data ) {
214
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
215
-		}
214
+            $discounts[$name] = $submission->format_amount( $data['initial_discount'] );
215
+        }
216 216
 
217
-		$this->response = array_merge(
218
-			$this->response,
219
-			array( 'discounts' => $discounts )
220
-		);
217
+        $this->response = array_merge(
218
+            $this->response,
219
+            array( 'discounts' => $discounts )
220
+        );
221 221
 
222
-	}
222
+    }
223 223
 
224
-	/**
225
-	 * Adds taxes to a response for submission refresh prices.
226
-	 *
227
-	 * @param GetPaid_Payment_Form_Submission $submission
228
-	 */
229
-	public function add_taxes( $submission ) {
230
-
231
-		$taxes  = array();
232
-		$markup = '';
224
+    /**
225
+     * Adds taxes to a response for submission refresh prices.
226
+     *
227
+     * @param GetPaid_Payment_Form_Submission $submission
228
+     */
229
+    public function add_taxes( $submission ) {
230
+
231
+        $taxes  = array();
232
+        $markup = '';
233 233
         foreach ( $submission->get_taxes() as $name => $data ) {
234
-			$name          = sanitize_text_field( $name );
235
-			$amount        = $submission->format_amount( $data['initial_tax'] );
236
-			$taxes[$name]  = $amount;
237
-			$markup       .= "<small class='form-text'>$name : $amount</small>";
238
-		}
239
-
240
-		if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) {
241
-			$this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
242
-		}
243
-
244
-		$this->response = array_merge(
245
-			$this->response,
246
-			array( 'taxes' => $taxes )
247
-		);
248
-
249
-	}
250
-
251
-	/**
252
-	 * Adds gateways to a response for submission refresh prices.
253
-	 *
254
-	 * @param GetPaid_Payment_Form_Submission $submission
255
-	 */
256
-	public function add_gateways( $submission ) {
257
-
258
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
259
-
260
-		if ( $this->response['has_recurring'] ) {
261
-
262
-			foreach ( $gateways as $i => $gateway ) {
263
-
264
-				if (
265
-					! getpaid_payment_gateway_supports( $gateway, 'subscription' )
266
-					|| ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
267
-					|| ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
268
-					unset( $gateways[ $i ] );
269
-				}
270
-
271
-			}
272
-
273
-		}
274
-
275
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
276
-		$this->response = array_merge(
277
-			$this->response,
278
-			array( 'gateways' => $gateways )
279
-		);
280
-
281
-	}
282
-
283
-	/**
284
-	 * Adds data to a response for submission refresh prices.
285
-	 *
286
-	 * @param GetPaid_Payment_Form_Submission $submission
287
-	 */
288
-	public function add_data( $submission ) {
289
-
290
-		$this->response = array_merge(
291
-			$this->response,
292
-			array(
293
-				'js_data' => apply_filters(
294
-					'getpaid_submission_js_data',
295
-					array(
296
-						'is_recurring' => $this->response['has_recurring'],
297
-					),
298
-					$submission
299
-				)
300
-			)
301
-		);
302
-
303
-	}
234
+            $name          = sanitize_text_field( $name );
235
+            $amount        = $submission->format_amount( $data['initial_tax'] );
236
+            $taxes[$name]  = $amount;
237
+            $markup       .= "<small class='form-text'>$name : $amount</small>";
238
+        }
239
+
240
+        if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) {
241
+            $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
242
+        }
243
+
244
+        $this->response = array_merge(
245
+            $this->response,
246
+            array( 'taxes' => $taxes )
247
+        );
248
+
249
+    }
250
+
251
+    /**
252
+     * Adds gateways to a response for submission refresh prices.
253
+     *
254
+     * @param GetPaid_Payment_Form_Submission $submission
255
+     */
256
+    public function add_gateways( $submission ) {
257
+
258
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
259
+
260
+        if ( $this->response['has_recurring'] ) {
261
+
262
+            foreach ( $gateways as $i => $gateway ) {
263
+
264
+                if (
265
+                    ! getpaid_payment_gateway_supports( $gateway, 'subscription' )
266
+                    || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
267
+                    || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
268
+                    unset( $gateways[ $i ] );
269
+                }
270
+
271
+            }
272
+
273
+        }
274
+
275
+        $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
276
+        $this->response = array_merge(
277
+            $this->response,
278
+            array( 'gateways' => $gateways )
279
+        );
280
+
281
+    }
282
+
283
+    /**
284
+     * Adds data to a response for submission refresh prices.
285
+     *
286
+     * @param GetPaid_Payment_Form_Submission $submission
287
+     */
288
+    public function add_data( $submission ) {
289
+
290
+        $this->response = array_merge(
291
+            $this->response,
292
+            array(
293
+                'js_data' => apply_filters(
294
+                    'getpaid_submission_js_data',
295
+                    array(
296
+                        'is_recurring' => $this->response['has_recurring'],
297
+                    ),
298
+                    $submission
299
+                )
300
+            )
301
+        );
302
+
303
+    }
304 304
 
305 305
 }
Please login to merge, or discard this patch.
templates/payment-forms/cart-item.php 1 patch
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -26,112 +26,112 @@  discard block
 block discarded – undo
26 26
 
27 27
 				<?php
28 28
 
29
-					// Fires before printing a line item column.
30
-					do_action( "getpaid_form_cart_item_before_$key", $item, $form );
29
+                    // Fires before printing a line item column.
30
+                    do_action( "getpaid_form_cart_item_before_$key", $item, $form );
31 31
 
32
-					// Item name.
33
-					if ( 'name' == $key ) {
32
+                    // Item name.
33
+                    if ( 'name' == $key ) {
34 34
 
35
-						ob_start();
36
-						// And an optional description.
35
+                        ob_start();
36
+                        // And an optional description.
37 37
                         $description = $item->get_description();
38 38
 
39 39
                         if ( ! empty( $description ) ) {
40 40
                             $description = wp_kses_post( $description );
41 41
                             echo "<small class='form-text text-muted pr-2 m-0'>$description</small>";
42
-						}
42
+                        }
43 43
 
44
-						// Price help text.
44
+                        // Price help text.
45 45
                         $description = getpaid_item_recurring_price_help_text( $item, $currency );
46 46
                         if ( $description ) {
47 47
                             echo "<small class='getpaid-form-item-price-desc form-text text-muted pr-2 m-0'>$description</small>";
48
-						}
48
+                        }
49 49
 
50
-						do_action( 'getpaid_payment_form_cart_item_description', $item, $form );
50
+                        do_action( 'getpaid_payment_form_cart_item_description', $item, $form );
51 51
 
52
-						if ( wpinv_current_user_can_manage_invoicing() ) {
52
+                        if ( wpinv_current_user_can_manage_invoicing() ) {
53 53
 
54
-							edit_post_link(
55
-								__( 'Edit this item.', 'invoicing' ),
56
-								'<small class="form-text text-muted">',
57
-								'</small>',
58
-								$item->get_id(),
59
-								'text-danger'
60
-							);
54
+                            edit_post_link(
55
+                                __( 'Edit this item.', 'invoicing' ),
56
+                                '<small class="form-text text-muted">',
57
+                                '</small>',
58
+                                $item->get_id(),
59
+                                'text-danger'
60
+                            );
61 61
 
62
-						}
62
+                        }
63 63
 
64
-						$description = ob_get_clean();
64
+                        $description = ob_get_clean();
65 65
 
66
-						// Display the name.
67
-						$tootip = empty( $description ) ? '' : "&nbsp;" . '<i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>';
68
-						echo '<div class="mb-1">' . esc_html( $item->get_name() ) . $tootip . '</div>';
66
+                        // Display the name.
67
+                        $tootip = empty( $description ) ? '' : "&nbsp;" . '<i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>';
68
+                        echo '<div class="mb-1">' . esc_html( $item->get_name() ) . $tootip . '</div>';
69 69
 
70
-						if ( ! empty( $description ) ) {
71
-							printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', $description );
72
-						}
73
-
74
-						if ( $item->allows_quantities() ) {
75
-							printf(
76
-								'<small class="d-sm-none text-muted form-text">%s</small>',
77
-								sprintf(
78
-									__( 'Qty %s', 'invoicing' ),
79
-									sprintf(
80
-										'<input
70
+                        if ( ! empty( $description ) ) {
71
+                            printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', $description );
72
+                        }
73
+
74
+                        if ( $item->allows_quantities() ) {
75
+                            printf(
76
+                                '<small class="d-sm-none text-muted form-text">%s</small>',
77
+                                sprintf(
78
+                                    __( 'Qty %s', 'invoicing' ),
79
+                                    sprintf(
80
+                                        '<input
81 81
 											type="text"
82 82
 											style="width: 48px;"
83 83
 											class="getpaid-item-mobile-quantity-input p-1 m-0 text-center"
84 84
 											value="%s"
85 85
 											min="1">',
86
-											(float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity()
87
-									)
88
-								)
89
-							);
90
-						} else {
91
-							printf(
92
-								'<small class="d-sm-none text-muted form-text">%s</small>',
93
-								sprintf(
94
-									__( 'Qty %s', 'invoicing' ),
95
-									(float) $item->get_quantity()
96
-								)
97
-							);
98
-						}
99
-
100
-					}
101
-
102
-					// Item price.
103
-					if ( 'price' == $key ) {
104
-
105
-						// Set the currency position.
106
-						$position = wpinv_currency_position();
107
-
108
-						if ( $position == 'left_space' ) {
109
-							$position = 'left';
110
-						}
111
-
112
-						if ( $position == 'right_space' ) {
113
-							$position = 'right';
114
-						}
115
-
116
-						if ( $item->user_can_set_their_price() ) {
117
-							$price            = max( (float) $item->get_price(), (float) $item->get_minimum_price() );
118
-							$minimum          = (float) $item->get_minimum_price();
119
-							$validate_minimum = '';
120
-							$class            = '';
121
-							$data_minimum     = '';
122
-
123
-							if ( $minimum > 0 ) {
124
-								$validate_minimum = sprintf(
125
-									esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ),
126
-									strip_tags( wpinv_price( $minimum, $currency ) )
127
-								);
128
-
129
-								$class = 'getpaid-validate-minimum-amount';
130
-
131
-								$data_minimum     = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'";
132
-							}
133
-
134
-							?>
86
+                                            (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity()
87
+                                    )
88
+                                )
89
+                            );
90
+                        } else {
91
+                            printf(
92
+                                '<small class="d-sm-none text-muted form-text">%s</small>',
93
+                                sprintf(
94
+                                    __( 'Qty %s', 'invoicing' ),
95
+                                    (float) $item->get_quantity()
96
+                                )
97
+                            );
98
+                        }
99
+
100
+                    }
101
+
102
+                    // Item price.
103
+                    if ( 'price' == $key ) {
104
+
105
+                        // Set the currency position.
106
+                        $position = wpinv_currency_position();
107
+
108
+                        if ( $position == 'left_space' ) {
109
+                            $position = 'left';
110
+                        }
111
+
112
+                        if ( $position == 'right_space' ) {
113
+                            $position = 'right';
114
+                        }
115
+
116
+                        if ( $item->user_can_set_their_price() ) {
117
+                            $price            = max( (float) $item->get_price(), (float) $item->get_minimum_price() );
118
+                            $minimum          = (float) $item->get_minimum_price();
119
+                            $validate_minimum = '';
120
+                            $class            = '';
121
+                            $data_minimum     = '';
122
+
123
+                            if ( $minimum > 0 ) {
124
+                                $validate_minimum = sprintf(
125
+                                    esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ),
126
+                                    strip_tags( wpinv_price( $minimum, $currency ) )
127
+                                );
128
+
129
+                                $class = 'getpaid-validate-minimum-amount';
130
+
131
+                                $data_minimum     = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'";
132
+                            }
133
+
134
+                            ?>
135 135
 								<div class="input-group input-group-sm">
136 136
 									<?php if( 'left' == $position ) : ?>
137 137
 										<div class="input-group-prepend">
@@ -156,44 +156,44 @@  discard block
 block discarded – undo
156 156
 
157 157
 							<?php
158 158
 
159
-						} else {
160
-							echo wpinv_price( $item->get_price(), $currency );
159
+                        } else {
160
+                            echo wpinv_price( $item->get_price(), $currency );
161 161
 
162
-							?>
162
+                            ?>
163 163
 								<input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'>
164 164
 							<?php
165
-						}
165
+                        }
166 166
 
167
-						printf(
168
-							'<small class="d-sm-none text-muted form-text getpaid-mobile-item-subtotal">%s</small>',
169
-							sprintf( __( 'Subtotal: %s', 'invoicing' ), wpinv_price( $item->get_sub_total(), $currency ) )
170
-						);
171
-					}
167
+                        printf(
168
+                            '<small class="d-sm-none text-muted form-text getpaid-mobile-item-subtotal">%s</small>',
169
+                            sprintf( __( 'Subtotal: %s', 'invoicing' ), wpinv_price( $item->get_sub_total(), $currency ) )
170
+                        );
171
+                    }
172 172
 
173
-					// Item quantity.
174
-					if ( 'quantity' == $key ) {
173
+                    // Item quantity.
174
+                    if ( 'quantity' == $key ) {
175 175
 
176
-						if ( $item->allows_quantities() ) {
177
-							?>
176
+                        if ( $item->allows_quantities() ) {
177
+                            ?>
178 178
 								<input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type='text' style='width: 64px; line-height: 1; min-height: 35px;' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(); ?>' min='1' required>
179 179
 							<?php
180
-						} else {
181
-							echo (float) $item->get_quantity();
182
-							echo '&nbsp;&nbsp;&nbsp;';
183
-							?>
180
+                        } else {
181
+                            echo (float) $item->get_quantity();
182
+                            echo '&nbsp;&nbsp;&nbsp;';
183
+                            ?>
184 184
 								<input type='hidden' name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' class='getpaid-item-quantity-input' value='<?php echo (float) $item->get_quantity(); ?>'>
185 185
 							<?php
186
-						}
186
+                        }
187 187
 
188
-					}
188
+                    }
189 189
 
190
-					// Item sub total.
191
-					if ( 'subtotal' == $key ) {
192
-						echo wpinv_price( $item->get_sub_total(), $currency );
193
-					}
190
+                    // Item sub total.
191
+                    if ( 'subtotal' == $key ) {
192
+                        echo wpinv_price( $item->get_sub_total(), $currency );
193
+                    }
194 194
 
195
-					do_action( "getpaid_payment_form_cart_item_$key", $item, $form );
196
-				?>
195
+                    do_action( "getpaid_payment_form_cart_item_$key", $item, $form );
196
+                ?>
197 197
 
198 198
 			</div>
199 199
 
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-gateway.php 1 patch
Indentation   +350 added lines, -350 removed lines patch added patch discarded remove patch
@@ -13,96 +13,96 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Paypal_Gateway extends GetPaid_Payment_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 = 'paypal';
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', 'single_subscription_group' );
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 = 1;
35 35
 
36 36
     /**
37
-	 * Stores line items to send to PayPal.
38
-	 *
39
-	 * @var array
40
-	 */
37
+     * Stores line items to send to PayPal.
38
+     *
39
+     * @var array
40
+     */
41 41
     protected $line_items = array();
42 42
 
43 43
     /**
44
-	 * Endpoint for requests from PayPal.
45
-	 *
46
-	 * @var string
47
-	 */
48
-	protected $notify_url;
49
-
50
-	/**
51
-	 * Endpoint for requests to PayPal.
52
-	 *
53
-	 * @var string
54
-	 */
44
+     * Endpoint for requests from PayPal.
45
+     *
46
+     * @var string
47
+     */
48
+    protected $notify_url;
49
+
50
+    /**
51
+     * Endpoint for requests to PayPal.
52
+     *
53
+     * @var string
54
+     */
55 55
     protected $endpoint;
56 56
 
57 57
     /**
58
-	 * Currencies this gateway is allowed for.
59
-	 *
60
-	 * @var array
61
-	 */
62
-	public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
58
+     * Currencies this gateway is allowed for.
59
+     *
60
+     * @var array
61
+     */
62
+    public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
63 63
 
64 64
     /**
65
-	 * URL to view a transaction.
66
-	 *
67
-	 * @var string
68
-	 */
65
+     * URL to view a transaction.
66
+     *
67
+     * @var string
68
+     */
69 69
     public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s';
70 70
 
71 71
     /**
72
-	 * URL to view a subscription.
73
-	 *
74
-	 * @var string
75
-	 */
76
-	public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
72
+     * URL to view a subscription.
73
+     *
74
+     * @var string
75
+     */
76
+    public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
77 77
 
78 78
     /**
79
-	 * Class constructor.
80
-	 */
81
-	public function __construct() {
79
+     * Class constructor.
80
+     */
81
+    public function __construct() {
82 82
 
83 83
         $this->title                = __( 'PayPal Standard', 'invoicing' );
84 84
         $this->method_title         = __( 'PayPal Standard', 'invoicing' );
85 85
         $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' );
86 86
         $this->notify_url           = wpinv_get_ipn_url( $this->id );
87 87
 
88
-		add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
88
+        add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
89 89
         add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) );
90
-		add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
91
-		add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
90
+        add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
91
+        add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
92 92
 
93
-		parent::__construct();
93
+        parent::__construct();
94 94
     }
95 95
 
96 96
     /**
97
-	 * Process Payment.
98
-	 *
99
-	 *
100
-	 * @param WPInv_Invoice $invoice Invoice.
101
-	 * @param array $submission_data Posted checkout fields.
102
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
103
-	 * @return array
104
-	 */
105
-	public function process_payment( $invoice, $submission_data, $submission ) {
97
+     * Process Payment.
98
+     *
99
+     *
100
+     * @param WPInv_Invoice $invoice Invoice.
101
+     * @param array $submission_data Posted checkout fields.
102
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
103
+     * @return array
104
+     */
105
+    public function process_payment( $invoice, $submission_data, $submission ) {
106 106
 
107 107
         // Get redirect url.
108 108
         $paypal_redirect = $this->get_request_url( $invoice );
@@ -125,15 +125,15 @@  discard block
 block discarded – undo
125 125
     }
126 126
 
127 127
     /**
128
-	 * Get the PayPal request URL for an invoice.
129
-	 *
130
-	 * @param  WPInv_Invoice $invoice Invoice object.
131
-	 * @return string
132
-	 */
133
-	public function get_request_url( $invoice ) {
128
+     * Get the PayPal request URL for an invoice.
129
+     *
130
+     * @param  WPInv_Invoice $invoice Invoice object.
131
+     * @return string
132
+     */
133
+    public function get_request_url( $invoice ) {
134 134
 
135 135
         // Endpoint for this request
136
-		$this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
136
+        $this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
137 137
 
138 138
         // Retrieve paypal args.
139 139
         $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
@@ -146,45 +146,45 @@  discard block
 block discarded – undo
146 146
 
147 147
         return add_query_arg( $paypal_args, $this->endpoint );
148 148
 
149
-	}
149
+    }
150 150
 
151 151
     /**
152
-	 * Get PayPal Args for passing to PP.
153
-	 *
154
-	 * @param  WPInv_Invoice $invoice Invoice object.
155
-	 * @return array
156
-	 */
157
-	protected function get_paypal_args( $invoice ) {
152
+     * Get PayPal Args for passing to PP.
153
+     *
154
+     * @param  WPInv_Invoice $invoice Invoice object.
155
+     * @return array
156
+     */
157
+    protected function get_paypal_args( $invoice ) {
158 158
 
159 159
         // Whether or not to send the line items as one item.
160
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
161
-
162
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
163
-			$force_one_line_item = true;
164
-		}
165
-
166
-		$paypal_args = apply_filters(
167
-			'getpaid_paypal_args',
168
-			array_merge(
169
-				$this->get_transaction_args( $invoice ),
170
-				$this->get_line_item_args( $invoice, $force_one_line_item )
171
-			),
172
-			$invoice
173
-		);
174
-
175
-		return $this->fix_request_length( $invoice, $paypal_args );
160
+        $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
161
+
162
+        if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
163
+            $force_one_line_item = true;
164
+        }
165
+
166
+        $paypal_args = apply_filters(
167
+            'getpaid_paypal_args',
168
+            array_merge(
169
+                $this->get_transaction_args( $invoice ),
170
+                $this->get_line_item_args( $invoice, $force_one_line_item )
171
+            ),
172
+            $invoice
173
+        );
174
+
175
+        return $this->fix_request_length( $invoice, $paypal_args );
176 176
     }
177 177
 
178 178
     /**
179
-	 * Get transaction args for paypal request.
180
-	 *
181
-	 * @param WPInv_Invoice $invoice Invoice object.
182
-	 * @return array
183
-	 */
184
-	protected function get_transaction_args( $invoice ) {
185
-
186
-		$email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
187
-		return array(
179
+     * Get transaction args for paypal request.
180
+     *
181
+     * @param WPInv_Invoice $invoice Invoice object.
182
+     * @return array
183
+     */
184
+    protected function get_transaction_args( $invoice ) {
185
+
186
+        $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
187
+        return array(
188 188
             'cmd'           => '_cart',
189 189
             'business'      => $email,
190 190
             'no_shipping'   => '1',
@@ -209,16 +209,16 @@  discard block
 block discarded – undo
209 209
     }
210 210
 
211 211
     /**
212
-	 * Get line item args for paypal request.
213
-	 *
214
-	 * @param  WPInv_Invoice $invoice Invoice object.
215
-	 * @param  bool     $force_one_line_item Create only one item for this invoice.
216
-	 * @return array
217
-	 */
218
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
212
+     * Get line item args for paypal request.
213
+     *
214
+     * @param  WPInv_Invoice $invoice Invoice object.
215
+     * @param  bool     $force_one_line_item Create only one item for this invoice.
216
+     * @return array
217
+     */
218
+    protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
219 219
 
220 220
         // Maybe send invoice as a single item.
221
-		if ( $force_one_line_item ) {
221
+        if ( $force_one_line_item ) {
222 222
             return $this->get_line_item_args_single_item( $invoice );
223 223
         }
224 224
 
@@ -238,129 +238,129 @@  discard block
 block discarded – undo
238 238
             $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
239 239
         }
240 240
 
241
-		return array_merge( $line_item_args, $this->get_line_items() );
241
+        return array_merge( $line_item_args, $this->get_line_items() );
242 242
 
243 243
     }
244 244
 
245 245
     /**
246
-	 * Get line item args for paypal request as a single line item.
247
-	 *
248
-	 * @param  WPInv_Invoice $invoice Invoice object.
249
-	 * @return array
250
-	 */
251
-	protected function get_line_item_args_single_item( $invoice ) {
252
-		$this->delete_line_items();
246
+     * Get line item args for paypal request as a single line item.
247
+     *
248
+     * @param  WPInv_Invoice $invoice Invoice object.
249
+     * @return array
250
+     */
251
+    protected function get_line_item_args_single_item( $invoice ) {
252
+        $this->delete_line_items();
253 253
 
254 254
         $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
255
-		$this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
255
+        $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
256 256
 
257
-		return $this->get_line_items();
257
+        return $this->get_line_items();
258 258
     }
259 259
 
260 260
     /**
261
-	 * Return all line items.
262
-	 */
263
-	protected function get_line_items() {
264
-		return $this->line_items;
265
-	}
261
+     * Return all line items.
262
+     */
263
+    protected function get_line_items() {
264
+        return $this->line_items;
265
+    }
266 266
 
267 267
     /**
268
-	 * Remove all line items.
269
-	 */
270
-	protected function delete_line_items() {
271
-		$this->line_items = array();
268
+     * Remove all line items.
269
+     */
270
+    protected function delete_line_items() {
271
+        $this->line_items = array();
272 272
     }
273 273
 
274 274
     /**
275
-	 * Prepare line items to send to paypal.
276
-	 *
277
-	 * @param  WPInv_Invoice $invoice Invoice object.
278
-	 */
279
-	protected function prepare_line_items( $invoice ) {
280
-		$this->delete_line_items();
281
-
282
-		// Items.
283
-		foreach ( $invoice->get_items() as $item ) {
284
-			$amount   = $item->get_price();
285
-			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
286
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
275
+     * Prepare line items to send to paypal.
276
+     *
277
+     * @param  WPInv_Invoice $invoice Invoice object.
278
+     */
279
+    protected function prepare_line_items( $invoice ) {
280
+        $this->delete_line_items();
281
+
282
+        // Items.
283
+        foreach ( $invoice->get_items() as $item ) {
284
+            $amount   = $item->get_price();
285
+            $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
286
+            $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
287 287
         }
288 288
 
289 289
         // Fees.
290
-		foreach ( $invoice->get_fees() as $fee => $data ) {
290
+        foreach ( $invoice->get_fees() as $fee => $data ) {
291 291
             $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) );
292 292
         }
293 293
 
294 294
     }
295 295
 
296 296
     /**
297
-	 * Add PayPal Line Item.
298
-	 *
299
-	 * @param  string $item_name Item name.
300
-	 * @param  float    $quantity Item quantity.
301
-	 * @param  float  $amount Amount.
302
-	 * @param  string $item_number Item number.
303
-	 */
304
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
305
-		$index = ( count( $this->line_items ) / 4 ) + 1;
306
-
307
-		$item = apply_filters(
308
-			'getpaid_paypal_line_item',
309
-			array(
310
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
311
-				'quantity'    => (float) $quantity,
312
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
313
-				'item_number' => $item_number,
314
-			),
315
-			$item_name,
316
-			$quantity,
317
-			$amount,
318
-			$item_number
319
-		);
320
-
321
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
297
+     * Add PayPal Line Item.
298
+     *
299
+     * @param  string $item_name Item name.
300
+     * @param  float    $quantity Item quantity.
301
+     * @param  float  $amount Amount.
302
+     * @param  string $item_number Item number.
303
+     */
304
+    protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
305
+        $index = ( count( $this->line_items ) / 4 ) + 1;
306
+
307
+        $item = apply_filters(
308
+            'getpaid_paypal_line_item',
309
+            array(
310
+                'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
311
+                'quantity'    => (float) $quantity,
312
+                'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
313
+                'item_number' => $item_number,
314
+            ),
315
+            $item_name,
316
+            $quantity,
317
+            $amount,
318
+            $item_number
319
+        );
320
+
321
+        $this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
322 322
         $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
323 323
 
324 324
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
325
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
326
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
325
+        $this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
326
+        $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
327 327
     }
328 328
 
329 329
     /**
330
-	 * If the default request with line items is too long, generate a new one with only one line item.
331
-	 *
332
-	 * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
333
-	 *
334
-	 * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
335
-	 * @param array    $paypal_args Arguments sent to Paypal in the request.
336
-	 * @return array
337
-	 */
338
-	protected function fix_request_length( $invoice, $paypal_args ) {
339
-		$max_paypal_length = 2083;
340
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
341
-
342
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
343
-			return $paypal_args;
344
-		}
345
-
346
-		return apply_filters(
347
-			'getpaid_paypal_args',
348
-			array_merge(
349
-				$this->get_transaction_args( $invoice ),
350
-				$this->get_line_item_args( $invoice, true )
351
-			),
352
-			$invoice
353
-		);
330
+     * If the default request with line items is too long, generate a new one with only one line item.
331
+     *
332
+     * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
333
+     *
334
+     * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
335
+     * @param array    $paypal_args Arguments sent to Paypal in the request.
336
+     * @return array
337
+     */
338
+    protected function fix_request_length( $invoice, $paypal_args ) {
339
+        $max_paypal_length = 2083;
340
+        $query_candidate   = http_build_query( $paypal_args, '', '&' );
341
+
342
+        if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
343
+            return $paypal_args;
344
+        }
345
+
346
+        return apply_filters(
347
+            'getpaid_paypal_args',
348
+            array_merge(
349
+                $this->get_transaction_args( $invoice ),
350
+                $this->get_line_item_args( $invoice, true )
351
+            ),
352
+            $invoice
353
+        );
354 354
 
355 355
     }
356 356
 
357 357
     /**
358
-	 * Processes recurring invoices.
359
-	 *
360
-	 * @param  array $paypal_args PayPal args.
361
-	 * @param  WPInv_Invoice    $invoice Invoice object.
362
-	 */
363
-	public function process_subscription( $paypal_args, $invoice ) {
358
+     * Processes recurring invoices.
359
+     *
360
+     * @param  array $paypal_args PayPal args.
361
+     * @param  WPInv_Invoice    $invoice Invoice object.
362
+     */
363
+    public function process_subscription( $paypal_args, $invoice ) {
364 364
 
365 365
         // Make sure this is a subscription.
366 366
         if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) {
@@ -381,21 +381,21 @@  discard block
 block discarded – undo
381 381
         $recurring_amount       = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 );
382 382
         $subscription_item      = $invoice->get_recurring( true );
383 383
 
384
-		// Convert 365 days to 1 year.
385
-		if ( 'D' == $period && 365 == $interval ) {
386
-			$period = 'Y';
387
-			$interval = 1;
388
-		}
384
+        // Convert 365 days to 1 year.
385
+        if ( 'D' == $period && 365 == $interval ) {
386
+            $period = 'Y';
387
+            $interval = 1;
388
+        }
389 389
 
390 390
         if ( $subscription_item->has_free_trial() ) {
391 391
 
392 392
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
393 393
 
394
-			// Trial period length.
395
-			$paypal_args['p1'] = $subscription_item->get_trial_interval();
394
+            // Trial period length.
395
+            $paypal_args['p1'] = $subscription_item->get_trial_interval();
396 396
 
397
-			// Trial period.
398
-			$paypal_args['t1'] = $subscription_item->get_trial_period();
397
+            // Trial period.
398
+            $paypal_args['t1'] = $subscription_item->get_trial_period();
399 399
 
400 400
         } else if ( $initial_amount != $recurring_amount ) {
401 401
 
@@ -418,40 +418,40 @@  discard block
 block discarded – undo
418 418
         }
419 419
 
420 420
         // We have a recurring payment
421
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
421
+        if ( ! isset( $param_number ) || 1 == $param_number ) {
422 422
 
423
-			// Subscription price
424
-			$paypal_args['a3'] = $recurring_amount;
423
+            // Subscription price
424
+            $paypal_args['a3'] = $recurring_amount;
425 425
 
426
-			// Subscription duration
427
-			$paypal_args['p3'] = $interval;
426
+            // Subscription duration
427
+            $paypal_args['p3'] = $interval;
428 428
 
429
-			// Subscription period
430
-			$paypal_args['t3'] = $period;
429
+            // Subscription period
430
+            $paypal_args['t3'] = $period;
431 431
 
432 432
         }
433 433
 
434 434
         // Recurring payments
435
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
435
+        if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
436 436
 
437
-			// Non-recurring payments
438
-			$paypal_args['src'] = 0;
437
+            // Non-recurring payments
438
+            $paypal_args['src'] = 0;
439 439
 
440
-		} else {
440
+        } else {
441 441
 
442
-			$paypal_args['src'] = 1;
442
+            $paypal_args['src'] = 1;
443 443
 
444
-			if ( $bill_times > 0 ) {
444
+            if ( $bill_times > 0 ) {
445 445
 
446
-				// An initial period is being used to charge a sign-up fee
447
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
448
-					$bill_times--;
449
-				}
446
+                // An initial period is being used to charge a sign-up fee
447
+                if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
448
+                    $bill_times--;
449
+                }
450 450
 
451 451
                 // Make sure it's not over the max of 52
452 452
                 $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
453 453
 
454
-			}
454
+            }
455 455
         }
456 456
 
457 457
         // Force return URL so that order description & instructions display
@@ -467,19 +467,19 @@  discard block
 block discarded – undo
467 467
         }
468 468
 
469 469
         return apply_filters(
470
-			'getpaid_paypal_subscription_args',
471
-			$paypal_args,
472
-			$invoice
470
+            'getpaid_paypal_subscription_args',
471
+            $paypal_args,
472
+            $invoice
473 473
         );
474 474
 
475 475
     }
476 476
 
477 477
     /**
478
-	 * Processes ipns and marks payments as complete.
479
-	 *
480
-	 * @return void
481
-	 */
482
-	public function verify_ipn() {
478
+     * Processes ipns and marks payments as complete.
479
+     *
480
+     * @return void
481
+     */
482
+    public function verify_ipn() {
483 483
         new GetPaid_Paypal_Gateway_IPN_Handler( $this );
484 484
     }
485 485
 
@@ -489,19 +489,19 @@  discard block
 block discarded – undo
489 489
     public function sandbox_notice() {
490 490
 
491 491
         return sprintf(
492
-			__( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
493
-			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
494
-			'</a>'
495
-		);
492
+            __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
493
+            '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
494
+            '</a>'
495
+        );
496 496
 
497 497
     }
498 498
 
499
-	/**
500
-	 * Filters the gateway settings.
501
-	 *
502
-	 * @param array $admin_settings
503
-	 */
504
-	public function admin_settings( $admin_settings ) {
499
+    /**
500
+     * Filters the gateway settings.
501
+     *
502
+     * @param array $admin_settings
503
+     */
504
+    public function admin_settings( $admin_settings ) {
505 505
 
506 506
         $currencies = sprintf(
507 507
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -511,39 +511,39 @@  discard block
 block discarded – undo
511 511
         $admin_settings['paypal_active']['desc'] .= " ($currencies)";
512 512
         $admin_settings['paypal_desc']['std']     = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
513 513
 
514
-		// Access tokens.
515
-		$live_email      = wpinv_get_option( 'paypal_email' );
516
-		$sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
517
-
518
-		$admin_settings['paypal_connect'] = array(
519
-			'type'       => 'raw_html',
520
-			'id'         => 'paypal_connect',
521
-			'name'       => __( 'Connect to PayPal', 'invoicing' ),
522
-			'desc'       => sprintf(
523
-				'<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s',
524
-				esc_url( self::get_connect_url( false ) ),
525
-				__( 'Connect to PayPal', 'invoicing' ),
526
-				esc_url( self::get_connect_url( true ) ),
527
-				__( 'Connect to PayPal Sandox', 'invoicing' ),
528
-				$this->get_js()
529
-			),
530
-		);
514
+        // Access tokens.
515
+        $live_email      = wpinv_get_option( 'paypal_email' );
516
+        $sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
517
+
518
+        $admin_settings['paypal_connect'] = array(
519
+            'type'       => 'raw_html',
520
+            'id'         => 'paypal_connect',
521
+            'name'       => __( 'Connect to PayPal', 'invoicing' ),
522
+            'desc'       => sprintf(
523
+                '<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s',
524
+                esc_url( self::get_connect_url( false ) ),
525
+                __( 'Connect to PayPal', 'invoicing' ),
526
+                esc_url( self::get_connect_url( true ) ),
527
+                __( 'Connect to PayPal Sandox', 'invoicing' ),
528
+                $this->get_js()
529
+            ),
530
+        );
531 531
 
532 532
         $admin_settings['paypal_email'] = array(
533 533
             'type'  => 'text',
534
-			'class' => 'live-auth-data',
534
+            'class' => 'live-auth-data',
535 535
             'id'    => 'paypal_email',
536 536
             'name'  => __( 'Live Email Address', 'invoicing' ),
537 537
             'desc'  => __( 'The email address of your PayPal account.', 'invoicing' ),
538 538
         );
539 539
 
540
-		$admin_settings['paypal_sandbox_email'] = array(
540
+        $admin_settings['paypal_sandbox_email'] = array(
541 541
             'type'  => 'text',
542
-			'class' => 'sandbox-auth-data',
542
+            'class' => 'sandbox-auth-data',
543 543
             'id'    => 'paypal_sandbox_email',
544 544
             'name'  => __( 'Sandbox Email Address', 'invoicing' ),
545 545
             'desc'  => __( 'The email address of your sandbox PayPal account.', 'invoicing' ),
546
-			'std'   => wpinv_get_option( 'paypal_email', '' ),
546
+            'std'   => wpinv_get_option( 'paypal_email', '' ),
547 547
         );
548 548
 
549 549
         $admin_settings['paypal_ipn_url'] = array(
@@ -555,29 +555,29 @@  discard block
 block discarded – undo
555 555
             'readonly' => true,
556 556
         );
557 557
 
558
-		return $admin_settings;
559
-	}
558
+        return $admin_settings;
559
+    }
560 560
 
561
-	/**
562
-	 * Retrieves the PayPal connect URL when using the setup wizzard.
563
-	 *
564
-	 *
561
+    /**
562
+     * Retrieves the PayPal connect URL when using the setup wizzard.
563
+     *
564
+     *
565 565
      * @param array $data
566 566
      * @return string
567
-	 */
568
-	public static function maybe_get_connect_url( $url = '', $data = array() ) {
569
-		return self::get_connect_url( false, urldecode( $data['redirect'] ) );
570
-	}
571
-
572
-	/**
573
-	 * Retrieves the PayPal connect URL.
574
-	 *
575
-	 *
567
+     */
568
+    public static function maybe_get_connect_url( $url = '', $data = array() ) {
569
+        return self::get_connect_url( false, urldecode( $data['redirect'] ) );
570
+    }
571
+
572
+    /**
573
+     * Retrieves the PayPal connect URL.
574
+     *
575
+     *
576 576
      * @param bool $is_sandbox
577
-	 * @param string $redirect
577
+     * @param string $redirect
578 578
      * @return string
579
-	 */
580
-	public static function get_connect_url( $is_sandbox, $redirect = '' ) {
579
+     */
580
+    public static function get_connect_url( $is_sandbox, $redirect = '' ) {
581 581
 
582 582
         $redirect_url = add_query_arg(
583 583
             array(
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
                 'tab'                  => 'gateways',
588 588
                 'section'              => 'paypal',
589 589
                 'getpaid-nonce'        => wp_create_nonce( 'getpaid-nonce' ),
590
-				'redirect'             => urlencode( $redirect ),
590
+                'redirect'             => urlencode( $redirect ),
591 591
             ),
592 592
             admin_url( 'admin.php' )
593 593
         );
@@ -602,12 +602,12 @@  discard block
 block discarded – undo
602 602
 
603 603
     }
604 604
 
605
-	/**
606
-	 * Generates settings page js.
607
-	 *
605
+    /**
606
+     * Generates settings page js.
607
+     *
608 608
      * @return void
609
-	 */
610
-	public static function get_js() {
609
+     */
610
+    public static function get_js() {
611 611
         ob_start();
612 612
         ?>
613 613
             <script>
@@ -643,72 +643,72 @@  discard block
 block discarded – undo
643 643
         return ob_get_clean();
644 644
     }
645 645
 
646
-	/**
647
-	 * Connects to PayPal.
648
-	 *
649
-	 * @param array $data Connection data.
650
-	 * @return void
651
-	 */
652
-	public function connect_paypal( $data ) {
653
-
654
-		$sandbox      = $this->is_sandbox();
655
-		$data         = wp_unslash( $data );
656
-		$access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
657
-
658
-		if ( isset( $data['live_mode'] ) ) {
659
-			$sandbox = empty( $data['live_mode'] );
660
-		}
661
-
662
-		wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
663
-		wpinv_update_option( 'paypal_active', 1 );
664
-
665
-		if ( ! empty( $data['error_description'] ) ) {
666
-			getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
667
-		} else {
668
-
669
-			// Retrieve the user info.
670
-			$user_info = wp_remote_get(
671
-				! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
672
-				array(
673
-
674
-					'headers' => array(
675
-						'Authorization' => 'Bearer ' . $access_token,
676
-						'Content-type'  => 'application/json',
677
-					)
678
-
679
-				)
680
-			);
681
-
682
-			if ( is_wp_error( $user_info ) ) {
683
-				getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
684
-			} else {
685
-
686
-				// Create application.
687
-				$user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
688
-
689
-				if ( $sandbox ) {
690
-					wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
691
-					wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
692
-					set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
693
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
694
-				} else {
695
-					wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
696
-					wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
697
-					set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
698
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
699
-				}
700
-
701
-			}
702
-
703
-		}
704
-
705
-		$redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
706
-
707
-		if ( isset( $data['step'] ) ) {
708
-			$redirect = add_query_arg( 'step', $data['step'], $redirect );
709
-		}
710
-		wp_redirect( $redirect );
711
-		exit;
712
-	}
646
+    /**
647
+     * Connects to PayPal.
648
+     *
649
+     * @param array $data Connection data.
650
+     * @return void
651
+     */
652
+    public function connect_paypal( $data ) {
653
+
654
+        $sandbox      = $this->is_sandbox();
655
+        $data         = wp_unslash( $data );
656
+        $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
657
+
658
+        if ( isset( $data['live_mode'] ) ) {
659
+            $sandbox = empty( $data['live_mode'] );
660
+        }
661
+
662
+        wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
663
+        wpinv_update_option( 'paypal_active', 1 );
664
+
665
+        if ( ! empty( $data['error_description'] ) ) {
666
+            getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
667
+        } else {
668
+
669
+            // Retrieve the user info.
670
+            $user_info = wp_remote_get(
671
+                ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
672
+                array(
673
+
674
+                    'headers' => array(
675
+                        'Authorization' => 'Bearer ' . $access_token,
676
+                        'Content-type'  => 'application/json',
677
+                    )
678
+
679
+                )
680
+            );
681
+
682
+            if ( is_wp_error( $user_info ) ) {
683
+                getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
684
+            } else {
685
+
686
+                // Create application.
687
+                $user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
688
+
689
+                if ( $sandbox ) {
690
+                    wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
691
+                    wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
692
+                    set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
693
+                    getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
694
+                } else {
695
+                    wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
696
+                    wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
697
+                    set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
698
+                    getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
699
+                }
700
+
701
+            }
702
+
703
+        }
704
+
705
+        $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
706
+
707
+        if ( isset( $data['step'] ) ) {
708
+            $redirect = add_query_arg( 'step', $data['step'], $redirect );
709
+        }
710
+        wp_redirect( $redirect );
711
+        exit;
712
+    }
713 713
 
714 714
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-authorize-net-legacy-gateway.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -15,31 +15,31 @@  discard block
 block discarded – undo
15 15
 abstract class GetPaid_Authorize_Net_Legacy_Gateway extends GetPaid_Payment_Gateway {
16 16
 
17 17
     /**
18
-	 * Class constructor.
19
-	 */
20
-	public function __construct() {
18
+     * Class constructor.
19
+     */
20
+    public function __construct() {
21 21
         parent::__construct();
22 22
     }
23 23
 
24 24
     /**
25
-	 * Returns the API URL.
26
-	 *
27
-	 *
28
-	 * @param WPInv_Invoice $invoice Invoice.
29
-	 * @return string
30
-	 */
31
-	public function get_api_url( $invoice ) {
25
+     * Returns the API URL.
26
+     *
27
+     *
28
+     * @param WPInv_Invoice $invoice Invoice.
29
+     * @return string
30
+     */
31
+    public function get_api_url( $invoice ) {
32 32
         return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api';
33 33
     }
34 34
 
35 35
     /**
36
-	 * Communicates with authorize.net
37
-	 *
38
-	 *
39
-	 * @param array $post Data to post.
36
+     * Communicates with authorize.net
37
+     *
38
+     *
39
+     * @param array $post Data to post.
40 40
      * @param WPInv_Invoice $invoice Invoice.
41
-	 * @return stdClass|WP_Error
42
-	 */
41
+     * @return stdClass|WP_Error
42
+     */
43 43
     public function post( $post, $invoice ){
44 44
 
45 45
         $url      = $this->get_api_url( $invoice );
@@ -89,12 +89,12 @@  discard block
 block discarded – undo
89 89
     }
90 90
 
91 91
     /**
92
-	 * Returns the API authentication params.
93
-	 *
94
-	 *
95
-	 * @return array
96
-	 */
97
-	public function get_auth_params() {
92
+     * Returns the API authentication params.
93
+     *
94
+     *
95
+     * @return array
96
+     */
97
+    public function get_auth_params() {
98 98
 
99 99
         return array(
100 100
             'name'           => $this->get_option( 'login_id' ),
@@ -104,13 +104,13 @@  discard block
 block discarded – undo
104 104
     }
105 105
 
106 106
     /**
107
-	 * Cancels a subscription remotely
108
-	 *
109
-	 *
110
-	 * @param WPInv_Subscription $subscription Subscription.
107
+     * Cancels a subscription remotely
108
+     *
109
+     *
110
+     * @param WPInv_Subscription $subscription Subscription.
111 111
      * @param WPInv_Invoice $invoice Invoice.
112
-	 */
113
-	public function cancel_subscription( $subscription, $invoice ) {
112
+     */
113
+    public function cancel_subscription( $subscription, $invoice ) {
114 114
 
115 115
         // Backwards compatibility. New version do not use authorize.net subscriptions.
116 116
         $this->post(
@@ -126,17 +126,17 @@  discard block
 block discarded – undo
126 126
     }
127 127
 
128 128
     /**
129
-	 * Processes ipns.
130
-	 *
131
-	 * @return void
132
-	 */
133
-	public function verify_ipn() {
129
+     * Processes ipns.
130
+     *
131
+     * @return void
132
+     */
133
+    public function verify_ipn() {
134 134
 
135 135
         $this->maybe_process_old_ipn();
136 136
 
137 137
         // Validate the IPN.
138 138
         if ( empty( $_POST ) || ! $this->validate_ipn() ) {
139
-		    wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) );
139
+            wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) );
140 140
         }
141 141
 
142 142
         // Event type.
@@ -175,24 +175,24 @@  discard block
 block discarded – undo
175 175
     }
176 176
 
177 177
     /**
178
-	 * Validates IPN invoices.
179
-	 *
178
+     * Validates IPN invoices.
179
+     *
180 180
      * @param WPInv_Invoice $invoice
181 181
      * @param object $payload
182
-	 * @return void
183
-	 */
184
-	public function validate_ipn_invoice( $invoice, $payload ) {
182
+     * @return void
183
+     */
184
+    public function validate_ipn_invoice( $invoice, $payload ) {
185 185
         if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) {
186 186
             exit;
187 187
         }
188 188
     }
189 189
 
190 190
     /**
191
-	 * Process subscriptio IPNS.
192
-	 *
193
-	 * @return void
194
-	 */
195
-	public function maybe_process_old_ipn() {
191
+     * Process subscriptio IPNS.
192
+     *
193
+     * @return void
194
+     */
195
+    public function maybe_process_old_ipn() {
196 196
 
197 197
         $data = wp_kses_post_deep( wp_unslash( $_POST ) );
198 198
 
@@ -234,11 +234,11 @@  discard block
 block discarded – undo
234 234
     }
235 235
 
236 236
     /**
237
-	 * Validates the old IPN signature.
237
+     * Validates the old IPN signature.
238 238
      *
239 239
      * @param array $posted
240
-	 */
241
-	public function validate_old_ipn_signature( $posted ) {
240
+     */
241
+    public function validate_old_ipn_signature( $posted ) {
242 242
 
243 243
         $signature = $this->get_option( 'signature_key' );
244 244
         if ( ! empty( $signature ) ) {
@@ -257,9 +257,9 @@  discard block
 block discarded – undo
257 257
     }
258 258
 
259 259
     /**
260
-	 * Check Authorize.NET IPN validity.
261
-	 */
262
-	public function validate_ipn() {
260
+     * Check Authorize.NET IPN validity.
261
+     */
262
+    public function validate_ipn() {
263 263
 
264 264
         wpinv_error_log( 'Validating Authorize.NET IPN response' );
265 265
 
Please login to merge, or discard this patch.
includes/admin/class-getpaid-metaboxes.php 1 patch
Indentation   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -12,276 +12,276 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Metaboxes {
14 14
 
15
-	/**
16
-	 * Only save metaboxes once.
17
-	 *
18
-	 * @var boolean
19
-	 */
20
-	private static $saved_meta_boxes = false;
21
-
22 15
     /**
23
-	 * Hook in methods.
24
-	 */
25
-	public static function init() {
26
-
27
-		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
29
-
30
-		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
32
-
33
-		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
35
-
36
-		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
-	}
39
-
40
-	/**
41
-	 * Register core metaboxes.
42
-	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
44
-
45
-		// For invoices...
46
-		self::add_invoice_meta_boxes( $post_type, $post );
47
-
48
-		// For payment forms.
49
-		self::add_payment_form_meta_boxes( $post_type, $post );
50
-
51
-		// For invoice items.
52
-		self::add_item_meta_boxes( $post_type );
53
-
54
-		// For invoice discounts.
55
-		if ( $post_type == 'wpi_discount' ) {
56
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
57
-		}
58
-
59
-	}
16
+     * Only save metaboxes once.
17
+     *
18
+     * @var boolean
19
+     */
20
+    private static $saved_meta_boxes = false;
60 21
 
61
-	/**
62
-	 * Register core metaboxes.
63
-	 */
64
-	protected static function add_payment_form_meta_boxes( $post_type, $post ) {
22
+    /**
23
+     * Hook in methods.
24
+     */
25
+    public static function init() {
65 26
 
66
-		// For payment forms.
67
-		if ( $post_type == 'wpi_payment_form' ) {
27
+        // Register metaboxes.
28
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
68 29
 
69
-			// Design payment form.
70
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
30
+        // Remove metaboxes.
31
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
71 32
 
72
-			// Payment form information.
73
-			if ( $post->ID != wpinv_get_default_payment_form() ) {
74
-				add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
75
-			}
33
+        // Rename metaboxes.
34
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
76 35
 
77
-		}
36
+        // Save metaboxes.
37
+        add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
+    }
78 39
 
79
-	}
40
+    /**
41
+     * Register core metaboxes.
42
+     */
43
+    public static function add_meta_boxes( $post_type, $post ) {
80 44
 
81
-	/**
82
-	 * Register core metaboxes.
83
-	 */
84
-	protected static function add_item_meta_boxes( $post_type ) {
45
+        // For invoices...
46
+        self::add_invoice_meta_boxes( $post_type, $post );
85 47
 
86
-		if ( $post_type == 'wpi_item' ) {
48
+        // For payment forms.
49
+        self::add_payment_form_meta_boxes( $post_type, $post );
87 50
 
88
-			// Item details.
89
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
51
+        // For invoice items.
52
+        self::add_item_meta_boxes( $post_type );
90 53
 
91
-			// If taxes are enabled, register the tax metabox.
92
-			if ( wpinv_use_taxes() ) {
93
-				add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
94
-			}
54
+        // For invoice discounts.
55
+        if ( $post_type == 'wpi_discount' ) {
56
+            add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
57
+        }
95 58
 
96
-			// Item info.
97
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
59
+    }
98 60
 
99
-		}
61
+    /**
62
+     * Register core metaboxes.
63
+     */
64
+    protected static function add_payment_form_meta_boxes( $post_type, $post ) {
100 65
 
101
-	}
66
+        // For payment forms.
67
+        if ( $post_type == 'wpi_payment_form' ) {
102 68
 
103
-	/**
104
-	 * Register invoice metaboxes.
105
-	 */
106
-	protected static function add_invoice_meta_boxes( $post_type, $post ) {
69
+            // Design payment form.
70
+            add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
107 71
 
108
-		// For invoices...
109
-		if ( getpaid_is_invoice_post_type( $post_type ) ) {
110
-			$invoice = new WPInv_Invoice( $post );
72
+            // Payment form information.
73
+            if ( $post->ID != wpinv_get_default_payment_form() ) {
74
+                add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
75
+            }
111 76
 
112
-			// Resend invoice.
113
-			if ( ! $invoice->is_draft() ) {
77
+        }
114 78
 
115
-				add_meta_box(
116
-					'wpinv-mb-resend-invoice',
117
-					sprintf(
118
-						__( 'Resend %s', 'invoicing' ),
119
-						ucfirst( $invoice->get_invoice_quote_type() )
120
-					),
121
-					'GetPaid_Meta_Box_Resend_Invoice::output',
122
-					$post_type,
123
-					'side',
124
-					'low'
125
-				);
79
+    }
126 80
 
127
-			}
81
+    /**
82
+     * Register core metaboxes.
83
+     */
84
+    protected static function add_item_meta_boxes( $post_type ) {
128 85
 
129
-			// Subscriptions.
130
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
131
-			if ( ! empty( $subscriptions ) ) {
86
+        if ( $post_type == 'wpi_item' ) {
132 87
 
133
-				if ( is_array( $subscriptions ) ) {
134
-					add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' );
135
-				} else {
136
-					add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
137
-				}
88
+            // Item details.
89
+            add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
138 90
 
139
-				if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) {
140
-					add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
141
-				}
91
+            // If taxes are enabled, register the tax metabox.
92
+            if ( wpinv_use_taxes() ) {
93
+                add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
94
+            }
142 95
 
143
-			}
96
+            // Item info.
97
+            add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
144 98
 
145
-			// Invoice details.
146
-			add_meta_box(
147
-				'wpinv-details',
148
-				sprintf(
149
-					__( '%s Details', 'invoicing' ),
150
-					ucfirst( $invoice->get_invoice_quote_type() )
151
-				),
152
-				'GetPaid_Meta_Box_Invoice_Details::output',
153
-				$post_type,
154
-				'side'
155
-			);
99
+        }
156 100
 
157
-			// Payment details.
158
-			add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
101
+    }
159 102
 
160
-			// Billing details.
161
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
103
+    /**
104
+     * Register invoice metaboxes.
105
+     */
106
+    protected static function add_invoice_meta_boxes( $post_type, $post ) {
107
+
108
+        // For invoices...
109
+        if ( getpaid_is_invoice_post_type( $post_type ) ) {
110
+            $invoice = new WPInv_Invoice( $post );
111
+
112
+            // Resend invoice.
113
+            if ( ! $invoice->is_draft() ) {
114
+
115
+                add_meta_box(
116
+                    'wpinv-mb-resend-invoice',
117
+                    sprintf(
118
+                        __( 'Resend %s', 'invoicing' ),
119
+                        ucfirst( $invoice->get_invoice_quote_type() )
120
+                    ),
121
+                    'GetPaid_Meta_Box_Resend_Invoice::output',
122
+                    $post_type,
123
+                    'side',
124
+                    'low'
125
+                );
126
+
127
+            }
128
+
129
+            // Subscriptions.
130
+            $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
131
+            if ( ! empty( $subscriptions ) ) {
132
+
133
+                if ( is_array( $subscriptions ) ) {
134
+                    add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' );
135
+                } else {
136
+                    add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
137
+                }
138
+
139
+                if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) {
140
+                    add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
141
+                }
142
+
143
+            }
144
+
145
+            // Invoice details.
146
+            add_meta_box(
147
+                'wpinv-details',
148
+                sprintf(
149
+                    __( '%s Details', 'invoicing' ),
150
+                    ucfirst( $invoice->get_invoice_quote_type() )
151
+                ),
152
+                'GetPaid_Meta_Box_Invoice_Details::output',
153
+                $post_type,
154
+                'side'
155
+            );
156
+
157
+            // Payment details.
158
+            add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
159
+
160
+            // Billing details.
161
+            add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
162 162
 			
163
-			// Invoice items.
164
-			add_meta_box(
165
-				'wpinv-items',
166
-				sprintf(
167
-					__( '%s Items', 'invoicing' ),
168
-					ucfirst( $invoice->get_invoice_quote_type() )
169
-				),
170
-				'GetPaid_Meta_Box_Invoice_Items::output',
171
-				$post_type,
172
-				'normal',
173
-				'high'
174
-			);
163
+            // Invoice items.
164
+            add_meta_box(
165
+                'wpinv-items',
166
+                sprintf(
167
+                    __( '%s Items', 'invoicing' ),
168
+                    ucfirst( $invoice->get_invoice_quote_type() )
169
+                ),
170
+                'GetPaid_Meta_Box_Invoice_Items::output',
171
+                $post_type,
172
+                'normal',
173
+                'high'
174
+            );
175 175
 			
176
-			// Invoice notes.
177
-			add_meta_box(
178
-				'wpinv-notes',
179
-				sprintf(
180
-					__( '%s Notes', 'invoicing' ),
181
-					ucfirst( $invoice->get_invoice_quote_type() )
182
-				),
183
-				'WPInv_Meta_Box_Notes::output',
184
-				$post_type,
185
-				'side',
186
-				'low'
187
-			);
188
-
189
-			// Shipping Address.
190
-			if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
191
-				add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
192
-			}
193
-
194
-			// Payment form information.
195
-			if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
196
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
197
-			}
198
-
199
-		}
200
-
201
-	}
202
-
203
-	/**
204
-	 * Remove some metaboxes.
205
-	 */
206
-	public static function remove_meta_boxes() {
207
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
208
-	}
209
-
210
-	/**
211
-	 * Rename other metaboxes.
212
-	 */
213
-	public static function rename_meta_boxes() {
176
+            // Invoice notes.
177
+            add_meta_box(
178
+                'wpinv-notes',
179
+                sprintf(
180
+                    __( '%s Notes', 'invoicing' ),
181
+                    ucfirst( $invoice->get_invoice_quote_type() )
182
+                ),
183
+                'WPInv_Meta_Box_Notes::output',
184
+                $post_type,
185
+                'side',
186
+                'low'
187
+            );
188
+
189
+            // Shipping Address.
190
+            if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
191
+                add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
192
+            }
193
+
194
+            // Payment form information.
195
+            if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
196
+                add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
197
+            }
198
+
199
+        }
200
+
201
+    }
202
+
203
+    /**
204
+     * Remove some metaboxes.
205
+     */
206
+    public static function remove_meta_boxes() {
207
+        remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
208
+    }
209
+
210
+    /**
211
+     * Rename other metaboxes.
212
+     */
213
+    public static function rename_meta_boxes() {
214 214
 		
215
-	}
216
-
217
-	/**
218
-	 * Check if we're saving, then trigger an action based on the post type.
219
-	 *
220
-	 * @param  int    $post_id Post ID.
221
-	 * @param  object $post Post object.
222
-	 */
223
-	public static function save_meta_boxes( $post_id, $post ) {
224
-		$post_id = absint( $post_id );
225
-		$data    = wp_kses_post_deep( wp_unslash( $_POST ) );
226
-
227
-		// Do not save for ajax requests.
228
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
229
-			return;
230
-		}
231
-
232
-		// $post_id and $post are required
233
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
234
-			return;
235
-		}
236
-
237
-		// Dont' save meta boxes for revisions or autosaves.
238
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
239
-			return;
240
-		}
241
-
242
-		// Check the nonce.
243
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
244
-			return;
245
-		}
246
-
247
-		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
248
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
249
-			return;
250
-		}
251
-
252
-		// Check user has permission to edit.
253
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
254
-			return;
255
-		}
256
-
257
-		if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
258
-
259
-			// We need this save event to run once to avoid potential endless loops.
260
-			self::$saved_meta_boxes = true;
261
-
262
-			return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
263
-
264
-		}
265
-
266
-		// Ensure this is our post type.
267
-		$post_types_map = array(
268
-			'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
269
-			'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
270
-			'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
271
-		);
272
-
273
-		// Is this our post type?
274
-		if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
275
-			return;
276
-		}
277
-
278
-		// We need this save event to run once to avoid potential endless loops.
279
-		self::$saved_meta_boxes = true;
215
+    }
216
+
217
+    /**
218
+     * Check if we're saving, then trigger an action based on the post type.
219
+     *
220
+     * @param  int    $post_id Post ID.
221
+     * @param  object $post Post object.
222
+     */
223
+    public static function save_meta_boxes( $post_id, $post ) {
224
+        $post_id = absint( $post_id );
225
+        $data    = wp_kses_post_deep( wp_unslash( $_POST ) );
226
+
227
+        // Do not save for ajax requests.
228
+        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
229
+            return;
230
+        }
231
+
232
+        // $post_id and $post are required
233
+        if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
234
+            return;
235
+        }
236
+
237
+        // Dont' save meta boxes for revisions or autosaves.
238
+        if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
239
+            return;
240
+        }
241
+
242
+        // Check the nonce.
243
+        if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
244
+            return;
245
+        }
246
+
247
+        // Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
248
+        if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
249
+            return;
250
+        }
251
+
252
+        // Check user has permission to edit.
253
+        if ( ! current_user_can( 'edit_post', $post_id ) ) {
254
+            return;
255
+        }
256
+
257
+        if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
258
+
259
+            // We need this save event to run once to avoid potential endless loops.
260
+            self::$saved_meta_boxes = true;
261
+
262
+            return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
263
+
264
+        }
265
+
266
+        // Ensure this is our post type.
267
+        $post_types_map = array(
268
+            'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
269
+            'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
270
+            'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
271
+        );
272
+
273
+        // Is this our post type?
274
+        if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
275
+            return;
276
+        }
277
+
278
+        // We need this save event to run once to avoid potential endless loops.
279
+        self::$saved_meta_boxes = true;
280 280
 		
281
-		// Save the post.
282
-		$class = $post_types_map[ $post->post_type ];
283
-		$class::save( $post_id, $_POST, $post );
281
+        // Save the post.
282
+        $class = $post_types_map[ $post->post_type ];
283
+        $class::save( $post_id, $_POST, $post );
284 284
 
285
-	}
285
+    }
286 286
 
287 287
 }
Please login to merge, or discard this patch.
templates/payment-forms/elements/date.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -12,58 +12,58 @@
 block discarded – undo
12 12
 $label       = empty( $label ) ? '' : wp_kses_post( $label );
13 13
 $label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) );
14 14
 if ( ! empty( $required ) ) {
15
-	$label .= "<span class='text-danger'> *</span>";
15
+    $label .= "<span class='text-danger'> *</span>";
16 16
 }
17 17
 
18 18
 $disable_dates = array();
19 19
 
20 20
 if ( ! empty( $disabled_dates ) ) {
21
-	$disabled_dates = preg_replace( '/\s+/', '', $disabled_dates );
22
-	$disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates );
23
-	$disabled_dates = array_filter( explode( ',', $disabled_dates ) );
21
+    $disabled_dates = preg_replace( '/\s+/', '', $disabled_dates );
22
+    $disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates );
23
+    $disabled_dates = array_filter( explode( ',', $disabled_dates ) );
24 24
 
25
-	foreach ( $disabled_dates as $disabled_date ) {
25
+    foreach ( $disabled_dates as $disabled_date ) {
26 26
 
27
-		$disabled_date = trim( $disabled_date );
27
+        $disabled_date = trim( $disabled_date );
28 28
 
29
-		if ( false === strpos( $disabled_date, '|' ) ) {
30
-			$disable_dates[] = $disabled_date;
31
-			continue;
32
-		}
29
+        if ( false === strpos( $disabled_date, '|' ) ) {
30
+            $disable_dates[] = $disabled_date;
31
+            continue;
32
+        }
33 33
 
34
-		$disabled_date   = explode( '|', $disabled_date );
35
-		$disable_dates[] = array(
36
-			'from' => trim( $disabled_date[0] ),
37
-			'to'   => trim( $disabled_date[1] ),
38
-		);
34
+        $disabled_date   = explode( '|', $disabled_date );
35
+        $disable_dates[] = array(
36
+            'from' => trim( $disabled_date[0] ),
37
+            'to'   => trim( $disabled_date[1] ),
38
+        );
39 39
 
40
-	}
40
+    }
41 41
 
42 42
 }
43 43
 
44 44
 $options = array(
45
-	'data-default-date' => empty( 'default_date' ) ? false : $default_date,
46
-	'data-min-date'     => empty( 'min_date' ) ? false : $min_date,
47
-	'data-max-date'     => empty( 'max_date' ) ? false : $max_date,
48
-	'data-mode'         => empty( 'mode' ) ? 'single' : $mode,
49
-	'data-alt-format'   => get_option( 'date_format', 'F j, Y' ),
50
-	'data-date-format'  => 'Y-m-d',
51
-	'data-alt-input'    => 'true',
52
-	'data-disable_alt'  => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ),
53
-	'data-disable_days_alt'  => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ),
45
+    'data-default-date' => empty( 'default_date' ) ? false : $default_date,
46
+    'data-min-date'     => empty( 'min_date' ) ? false : $min_date,
47
+    'data-max-date'     => empty( 'max_date' ) ? false : $max_date,
48
+    'data-mode'         => empty( 'mode' ) ? 'single' : $mode,
49
+    'data-alt-format'   => get_option( 'date_format', 'F j, Y' ),
50
+    'data-date-format'  => 'Y-m-d',
51
+    'data-alt-input'    => 'true',
52
+    'data-disable_alt'  => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ),
53
+    'data-disable_days_alt'  => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ),
54 54
 );
55 55
 
56 56
 echo aui()->input(
57
-	array(
58
-		'name'             => esc_attr( $id ),
59
-		'id'               => esc_attr( $id ) . uniqid( '_' ),
60
-		'placeholder'      => empty( $placeholder ) ? '' : esc_attr( $placeholder ),
61
-		'required'         => ! empty( $required ),
62
-		'label'            => $label,
63
-		'label_type'       => 'vertical',
64
-		'help_text'        => empty( $description ) ? '' : wp_kses_post( $description ),
65
-		'type'             => 'datepicker',
66
-		'class'            => $label_class . ' getpaid-init-flatpickr flatpickr-input',
67
-		'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ),
68
-	)
57
+    array(
58
+        'name'             => esc_attr( $id ),
59
+        'id'               => esc_attr( $id ) . uniqid( '_' ),
60
+        'placeholder'      => empty( $placeholder ) ? '' : esc_attr( $placeholder ),
61
+        'required'         => ! empty( $required ),
62
+        'label'            => $label,
63
+        'label_type'       => 'vertical',
64
+        'help_text'        => empty( $description ) ? '' : wp_kses_post( $description ),
65
+        'type'             => 'datepicker',
66
+        'class'            => $label_class . ' getpaid-init-flatpickr flatpickr-input',
67
+        'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ),
68
+    )
69 69
 );
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 1 patch
Indentation   +862 added lines, -862 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,203 +10,203 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form_Submission {
11 11
 
12 12
     /**
13
-	 * Submission ID
14
-	 *
15
-	 * @var string
16
-	 */
17
-	public $id = null;
18
-
19
-	/**
20
-	 * The raw submission data.
21
-	 *
22
-	 * @var array
23
-	 */
24
-	protected $data = null;
25
-
26
-	/**
27
-	 * Submission totals
28
-	 *
29
-	 * @var array
30
-	 */
31
-	protected $totals = array(
32
-
33
-		'subtotal'      => array(
34
-			'initial'   => 0,
35
-			'recurring' => 0,
36
-		),
37
-
38
-		'discount'      => array(
39
-			'initial'   => 0,
40
-			'recurring' => 0,
41
-		),
42
-
43
-		'fees'          => array(
44
-			'initial'   => 0,
45
-			'recurring' => 0,
46
-		),
47
-
48
-		'taxes'         => array(
49
-			'initial'   => 0,
50
-			'recurring' => 0,
51
-		),
52
-
53
-		'shipping'         => array(
54
-			'initial'   => 0,
55
-			'recurring' => 0,
56
-		),
57
-
58
-	);
59
-
60
-	/**
61
-	 * Sets the associated payment form.
62
-	 *
63
-	 * @var GetPaid_Payment_Form
64
-	 */
13
+     * Submission ID
14
+     *
15
+     * @var string
16
+     */
17
+    public $id = null;
18
+
19
+    /**
20
+     * The raw submission data.
21
+     *
22
+     * @var array
23
+     */
24
+    protected $data = null;
25
+
26
+    /**
27
+     * Submission totals
28
+     *
29
+     * @var array
30
+     */
31
+    protected $totals = array(
32
+
33
+        'subtotal'      => array(
34
+            'initial'   => 0,
35
+            'recurring' => 0,
36
+        ),
37
+
38
+        'discount'      => array(
39
+            'initial'   => 0,
40
+            'recurring' => 0,
41
+        ),
42
+
43
+        'fees'          => array(
44
+            'initial'   => 0,
45
+            'recurring' => 0,
46
+        ),
47
+
48
+        'taxes'         => array(
49
+            'initial'   => 0,
50
+            'recurring' => 0,
51
+        ),
52
+
53
+        'shipping'         => array(
54
+            'initial'   => 0,
55
+            'recurring' => 0,
56
+        ),
57
+
58
+    );
59
+
60
+    /**
61
+     * Sets the associated payment form.
62
+     *
63
+     * @var GetPaid_Payment_Form
64
+     */
65 65
     protected $payment_form = null;
66 66
 
67 67
     /**
68
-	 * The country for the submission.
69
-	 *
70
-	 * @var string
71
-	 */
72
-	public $country = null;
73
-
74
-    /**
75
-	 * The state for the submission.
76
-	 *
77
-	 * @since 1.0.19
78
-	 * @var string
79
-	 */
80
-	public $state = null;
81
-
82
-	/**
83
-	 * The invoice associated with the submission.
84
-	 *
85
-	 * @var WPInv_Invoice
86
-	 */
87
-	protected $invoice = null;
88
-
89
-	/**
90
-	 * The recurring item for the submission.
91
-	 *
92
-	 * @var int
93
-	 */
94
-	public $has_recurring = 0;
95
-
96
-	/**
97
-	 * An array of fees for the submission.
98
-	 *
99
-	 * @var array
100
-	 */
101
-	protected $fees = array();
102
-
103
-	/**
104
-	 * An array of discounts for the submission.
105
-	 *
106
-	 * @var array
107
-	 */
108
-	protected $discounts = array();
109
-
110
-	/**
111
-	 * An array of taxes for the submission.
112
-	 *
113
-	 * @var array
114
-	 */
115
-	protected $taxes = array();
116
-
117
-	/**
118
-	 * An array of items for the submission.
119
-	 *
120
-	 * @var GetPaid_Form_Item[]
121
-	 */
122
-	protected $items = array();
123
-
124
-	/**
125
-	 * The last error.
126
-	 *
127
-	 * @var string
128
-	 */
129
-	public $last_error = null;
130
-
131
-	/**
132
-	 * The last error code.
133
-	 *
134
-	 * @var string
135
-	 */
136
-	public $last_error_code = null;
137
-
138
-    /**
139
-	 * Class constructor.
140
-	 *
141
-	 */
142
-	public function __construct() {
143
-
144
-		// Set the state and country to the default state and country.
145
-		$this->country = wpinv_default_billing_country();
146
-		$this->state   = wpinv_get_default_state();
147
-
148
-		// Do we have an actual submission?
149
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
150
-			$this->load_data( $_POST );
151
-		}
152
-
153
-	}
154
-
155
-	/**
156
-	 * Loads submission data.
157
-	 *
158
-	 * @param array $data
159
-	 */
160
-	public function load_data( $data ) {
161
-
162
-		// Remove slashes from the submitted data...
163
-		$data       = wp_kses_post_deep( wp_unslash( $data ) );
164
-
165
-		// Allow plugins to filter the data.
166
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
167
-
168
-		// Cache it...
169
-		$this->data = $data;
170
-
171
-		// Then generate a unique id from the data.
172
-		$this->id   = md5( wp_json_encode( $data ) );
173
-
174
-		// Finally, process the submission.
175
-		try {
176
-
177
-			// Each process is passed an instance of the class (with reference)
178
-			// and should throw an Exception whenever it encounters one.
179
-			$processors = apply_filters(
180
-				'getpaid_payment_form_submission_processors',
181
-				array(
182
-					array( $this, 'process_payment_form' ),
183
-					array( $this, 'process_invoice' ),
184
-					array( $this, 'process_fees' ),
185
-					array( $this, 'process_items' ),
186
-					array( $this, 'process_discount' ),
187
-					array( $this, 'process_taxes' ),
188
-				),
189
-				$this		
190
-			);
191
-
192
-			foreach ( $processors as $processor ) {
193
-				call_user_func_array( $processor, array( &$this ) );
194
-			}
195
-
196
-		} catch( GetPaid_Payment_Exception $e ) {
197
-			$this->last_error      = $e->getMessage();
198
-			$this->last_error_code = $e->getErrorCode();
199
-		} catch ( Exception $e ) {
200
-			$this->last_error      = $e->getMessage();
201
-			$this->last_error_code = $e->getCode();
202
-		}
203
-
204
-		// Fired when we are done processing a submission.
205
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
206
-
207
-	}
208
-
209
-	/*
68
+     * The country for the submission.
69
+     *
70
+     * @var string
71
+     */
72
+    public $country = null;
73
+
74
+    /**
75
+     * The state for the submission.
76
+     *
77
+     * @since 1.0.19
78
+     * @var string
79
+     */
80
+    public $state = null;
81
+
82
+    /**
83
+     * The invoice associated with the submission.
84
+     *
85
+     * @var WPInv_Invoice
86
+     */
87
+    protected $invoice = null;
88
+
89
+    /**
90
+     * The recurring item for the submission.
91
+     *
92
+     * @var int
93
+     */
94
+    public $has_recurring = 0;
95
+
96
+    /**
97
+     * An array of fees for the submission.
98
+     *
99
+     * @var array
100
+     */
101
+    protected $fees = array();
102
+
103
+    /**
104
+     * An array of discounts for the submission.
105
+     *
106
+     * @var array
107
+     */
108
+    protected $discounts = array();
109
+
110
+    /**
111
+     * An array of taxes for the submission.
112
+     *
113
+     * @var array
114
+     */
115
+    protected $taxes = array();
116
+
117
+    /**
118
+     * An array of items for the submission.
119
+     *
120
+     * @var GetPaid_Form_Item[]
121
+     */
122
+    protected $items = array();
123
+
124
+    /**
125
+     * The last error.
126
+     *
127
+     * @var string
128
+     */
129
+    public $last_error = null;
130
+
131
+    /**
132
+     * The last error code.
133
+     *
134
+     * @var string
135
+     */
136
+    public $last_error_code = null;
137
+
138
+    /**
139
+     * Class constructor.
140
+     *
141
+     */
142
+    public function __construct() {
143
+
144
+        // Set the state and country to the default state and country.
145
+        $this->country = wpinv_default_billing_country();
146
+        $this->state   = wpinv_get_default_state();
147
+
148
+        // Do we have an actual submission?
149
+        if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
150
+            $this->load_data( $_POST );
151
+        }
152
+
153
+    }
154
+
155
+    /**
156
+     * Loads submission data.
157
+     *
158
+     * @param array $data
159
+     */
160
+    public function load_data( $data ) {
161
+
162
+        // Remove slashes from the submitted data...
163
+        $data       = wp_kses_post_deep( wp_unslash( $data ) );
164
+
165
+        // Allow plugins to filter the data.
166
+        $data       = apply_filters( 'getpaid_submission_data', $data, $this );
167
+
168
+        // Cache it...
169
+        $this->data = $data;
170
+
171
+        // Then generate a unique id from the data.
172
+        $this->id   = md5( wp_json_encode( $data ) );
173
+
174
+        // Finally, process the submission.
175
+        try {
176
+
177
+            // Each process is passed an instance of the class (with reference)
178
+            // and should throw an Exception whenever it encounters one.
179
+            $processors = apply_filters(
180
+                'getpaid_payment_form_submission_processors',
181
+                array(
182
+                    array( $this, 'process_payment_form' ),
183
+                    array( $this, 'process_invoice' ),
184
+                    array( $this, 'process_fees' ),
185
+                    array( $this, 'process_items' ),
186
+                    array( $this, 'process_discount' ),
187
+                    array( $this, 'process_taxes' ),
188
+                ),
189
+                $this		
190
+            );
191
+
192
+            foreach ( $processors as $processor ) {
193
+                call_user_func_array( $processor, array( &$this ) );
194
+            }
195
+
196
+        } catch( GetPaid_Payment_Exception $e ) {
197
+            $this->last_error      = $e->getMessage();
198
+            $this->last_error_code = $e->getErrorCode();
199
+        } catch ( Exception $e ) {
200
+            $this->last_error      = $e->getMessage();
201
+            $this->last_error_code = $e->getCode();
202
+        }
203
+
204
+        // Fired when we are done processing a submission.
205
+        do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
206
+
207
+    }
208
+
209
+    /*
210 210
 	|--------------------------------------------------------------------------
211 211
 	| Payment Forms.
212 212
 	|--------------------------------------------------------------------------
@@ -215,39 +215,39 @@  discard block
 block discarded – undo
215 215
 	| submission has an active payment form etc.
216 216
     */
217 217
 
218
-	/**
219
-	 * Prepares the submission's payment form.
220
-	 *
221
-	 * @since 1.0.19
222
-	 */
223
-	public function process_payment_form() {
218
+    /**
219
+     * Prepares the submission's payment form.
220
+     *
221
+     * @since 1.0.19
222
+     */
223
+    public function process_payment_form() {
224 224
 
225
-		// Every submission needs an active payment form.
226
-		if ( empty( $this->data['form_id'] ) ) {
227
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
228
-		}
225
+        // Every submission needs an active payment form.
226
+        if ( empty( $this->data['form_id'] ) ) {
227
+            throw new Exception( __( 'Missing payment form', 'invoicing' ) );
228
+        }
229 229
 
230
-		// Fetch the payment form.
231
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
230
+        // Fetch the payment form.
231
+        $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
232 232
 
233
-		if ( ! $this->payment_form->is_active() ) {
234
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
235
-		}
233
+        if ( ! $this->payment_form->is_active() ) {
234
+            throw new Exception( __( 'Payment form not active', 'invoicing' ) );
235
+        }
236 236
 
237
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
238
-	}
237
+        do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
238
+    }
239 239
 
240 240
     /**
241
-	 * Returns the payment form.
242
-	 *
243
-	 * @since 1.0.19
244
-	 * @return GetPaid_Payment_Form
245
-	 */
246
-	public function get_payment_form() {
247
-		return $this->payment_form;
248
-	}
241
+     * Returns the payment form.
242
+     *
243
+     * @since 1.0.19
244
+     * @return GetPaid_Payment_Form
245
+     */
246
+    public function get_payment_form() {
247
+        return $this->payment_form;
248
+    }
249 249
 
250
-	/*
250
+    /*
251 251
 	|--------------------------------------------------------------------------
252 252
 	| Invoices.
253 253
 	|--------------------------------------------------------------------------
@@ -256,84 +256,84 @@  discard block
 block discarded – undo
256 256
 	| might be for an existing invoice.
257 257
 	*/
258 258
 
259
-	/**
260
-	 * Prepares the submission's invoice.
261
-	 *
262
-	 * @since 1.0.19
263
-	 */
264
-	public function process_invoice() {
259
+    /**
260
+     * Prepares the submission's invoice.
261
+     *
262
+     * @since 1.0.19
263
+     */
264
+    public function process_invoice() {
265 265
 
266
-		// Abort if there is no invoice.
267
-		if ( empty( $this->data['invoice_id'] ) ) {
268
-			return;
269
-		}
266
+        // Abort if there is no invoice.
267
+        if ( empty( $this->data['invoice_id'] ) ) {
268
+            return;
269
+        }
270 270
 
271
-		// If the submission is for an existing invoice, ensure that it exists
272
-		// and that it is not paid for.
273
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
271
+        // If the submission is for an existing invoice, ensure that it exists
272
+        // and that it is not paid for.
273
+        $invoice = wpinv_get_invoice( $this->data['invoice_id'] );
274 274
 
275 275
         if ( empty( $invoice ) ) {
276
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
277
-		}
276
+            throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
277
+        }
278 278
 
279
-		if ( $invoice->is_paid() ) {
280
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
281
-		}
279
+        if ( $invoice->is_paid() ) {
280
+            throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
281
+        }
282 282
 
283
-		$this->payment_form->invoice = $invoice;
284
-		if ( ! $this->payment_form->is_default() ) {
283
+        $this->payment_form->invoice = $invoice;
284
+        if ( ! $this->payment_form->is_default() ) {
285 285
 
286
-			$items    = array();
287
-			$item_ids = array();
286
+            $items    = array();
287
+            $item_ids = array();
288 288
 	
289
-			foreach ( $invoice->get_items() as $item ) {
290
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
291
-					$item_ids[] = $item->get_id();
292
-					$items[]    = $item;
293
-				}
294
-			}
289
+            foreach ( $invoice->get_items() as $item ) {
290
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
291
+                    $item_ids[] = $item->get_id();
292
+                    $items[]    = $item;
293
+                }
294
+            }
295 295
 	
296
-			foreach ( $this->payment_form->get_items() as $item ) {
297
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
298
-					$item_ids[] = $item->get_id();
299
-					$items[]    = $item;
300
-				}
301
-			}
296
+            foreach ( $this->payment_form->get_items() as $item ) {
297
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
298
+                    $item_ids[] = $item->get_id();
299
+                    $items[]    = $item;
300
+                }
301
+            }
302 302
 	
303
-			$this->payment_form->set_items( $items );
303
+            $this->payment_form->set_items( $items );
304 304
 	
305
-		} else {
306
-			$this->payment_form->set_items( $invoice->get_items() );
307
-		}
308
-
309
-		$this->country = $invoice->get_country();
310
-		$this->state   = $invoice->get_state();
311
-		$this->invoice = $invoice;
312
-
313
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
314
-	}
315
-
316
-	/**
317
-	 * Returns the associated invoice.
318
-	 *
319
-	 * @since 1.0.19
320
-	 * @return WPInv_Invoice
321
-	 */
322
-	public function get_invoice() {
323
-		return $this->invoice;
324
-	}
325
-
326
-	/**
327
-	 * Checks whether there is an invoice associated with this submission.
328
-	 *
329
-	 * @since 1.0.19
330
-	 * @return bool
331
-	 */
332
-	public function has_invoice() {
333
-		return ! empty( $this->invoice );
334
-	}
335
-
336
-	/*
305
+        } else {
306
+            $this->payment_form->set_items( $invoice->get_items() );
307
+        }
308
+
309
+        $this->country = $invoice->get_country();
310
+        $this->state   = $invoice->get_state();
311
+        $this->invoice = $invoice;
312
+
313
+        do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
314
+    }
315
+
316
+    /**
317
+     * Returns the associated invoice.
318
+     *
319
+     * @since 1.0.19
320
+     * @return WPInv_Invoice
321
+     */
322
+    public function get_invoice() {
323
+        return $this->invoice;
324
+    }
325
+
326
+    /**
327
+     * Checks whether there is an invoice associated with this submission.
328
+     *
329
+     * @since 1.0.19
330
+     * @return bool
331
+     */
332
+    public function has_invoice() {
333
+        return ! empty( $this->invoice );
334
+    }
335
+
336
+    /*
337 337
 	|--------------------------------------------------------------------------
338 338
 	| Items.
339 339
 	|--------------------------------------------------------------------------
@@ -342,129 +342,129 @@  discard block
 block discarded – undo
342 342
 	| recurring item. But can have an unlimited number of non-recurring items.
343 343
 	*/
344 344
 
345
-	/**
346
-	 * Prepares the submission's items.
347
-	 *
348
-	 * @since 1.0.19
349
-	 */
350
-	public function process_items() {
351
-
352
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
353
-
354
-		foreach ( $processor->items as $item ) {
355
-			$this->add_item( $item );
356
-		}
357
-
358
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
359
-	}
360
-
361
-	/**
362
-	 * Adds an item to the submission.
363
-	 *
364
-	 * @since 1.0.19
365
-	 * @param GetPaid_Form_Item $item
366
-	 */
367
-	public function add_item( $item ) {
368
-
369
-		// Make sure that it is available for purchase.
370
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
371
-			return;
372
-		}
373
-
374
-		// Each submission can only contain one recurring item.
375
-		if ( $item->is_recurring() ) {
376
-			$this->has_recurring = $item->get_id();
377
-		}
378
-
379
-		// Update the items and totals.
380
-		$this->items[ $item->get_id() ]         = $item;
381
-		$this->totals['subtotal']['initial']   += $item->get_sub_total();
382
-		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
383
-
384
-	}
385
-
386
-	/**
387
-	 * Removes a specific item.
388
-	 * 
389
-	 * You should not call this method after the discounts and taxes
390
-	 * have been calculated.
391
-	 *
392
-	 * @since 1.0.19
393
-	 */
394
-	public function remove_item( $item_id ) {
395
-
396
-		if ( isset( $this->items[ $item_id ] ) ) {
397
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
398
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
399
-
400
-			if ( $this->items[ $item_id ]->is_recurring() ) {
401
-				$this->has_recurring = 0;
402
-			}
403
-
404
-			unset( $this->items[ $item_id ] );
405
-		}
406
-
407
-	}
408
-
409
-	/**
410
-	 * Returns the subtotal.
411
-	 *
412
-	 * @since 1.0.19
413
-	 */
414
-	public function get_subtotal() {
415
-
416
-		if ( wpinv_prices_include_tax() ) {
417
-			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
418
-		}
419
-
420
-		return $this->totals['subtotal']['initial'];
421
-	}
422
-
423
-	/**
424
-	 * Returns the recurring subtotal.
425
-	 *
426
-	 * @since 1.0.19
427
-	 */
428
-	public function get_recurring_subtotal() {
429
-
430
-		if ( wpinv_prices_include_tax() ) {
431
-			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
432
-		}
433
-
434
-		return $this->totals['subtotal']['recurring'];
435
-	}
436
-
437
-	/**
438
-	 * Returns all items.
439
-	 *
440
-	 * @since 1.0.19
441
-	 * @return GetPaid_Form_Item[]
442
-	 */
443
-	public function get_items() {
444
-		return $this->items;
445
-	}
446
-
447
-	/**
448
-	 * Checks if there's a single subscription group in the submission.
449
-	 *
450
-	 * @since 2.3.0
451
-	 * @return bool
452
-	 */
453
-	public function has_subscription_group() {
454
-		return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
455
-	}
456
-
457
-	/**
458
-	 * Checks if there are multipe subscription groups in the submission.
459
-	 *
460
-	 * @since 2.3.0
461
-	 * @return bool
462
-	 */
463
-	public function has_multiple_subscription_groups() {
464
-		return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
465
-	}
466
-
467
-	/*
345
+    /**
346
+     * Prepares the submission's items.
347
+     *
348
+     * @since 1.0.19
349
+     */
350
+    public function process_items() {
351
+
352
+        $processor = new GetPaid_Payment_Form_Submission_Items( $this );
353
+
354
+        foreach ( $processor->items as $item ) {
355
+            $this->add_item( $item );
356
+        }
357
+
358
+        do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
359
+    }
360
+
361
+    /**
362
+     * Adds an item to the submission.
363
+     *
364
+     * @since 1.0.19
365
+     * @param GetPaid_Form_Item $item
366
+     */
367
+    public function add_item( $item ) {
368
+
369
+        // Make sure that it is available for purchase.
370
+        if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
371
+            return;
372
+        }
373
+
374
+        // Each submission can only contain one recurring item.
375
+        if ( $item->is_recurring() ) {
376
+            $this->has_recurring = $item->get_id();
377
+        }
378
+
379
+        // Update the items and totals.
380
+        $this->items[ $item->get_id() ]         = $item;
381
+        $this->totals['subtotal']['initial']   += $item->get_sub_total();
382
+        $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
383
+
384
+    }
385
+
386
+    /**
387
+     * Removes a specific item.
388
+     * 
389
+     * You should not call this method after the discounts and taxes
390
+     * have been calculated.
391
+     *
392
+     * @since 1.0.19
393
+     */
394
+    public function remove_item( $item_id ) {
395
+
396
+        if ( isset( $this->items[ $item_id ] ) ) {
397
+            $this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
398
+            $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
399
+
400
+            if ( $this->items[ $item_id ]->is_recurring() ) {
401
+                $this->has_recurring = 0;
402
+            }
403
+
404
+            unset( $this->items[ $item_id ] );
405
+        }
406
+
407
+    }
408
+
409
+    /**
410
+     * Returns the subtotal.
411
+     *
412
+     * @since 1.0.19
413
+     */
414
+    public function get_subtotal() {
415
+
416
+        if ( wpinv_prices_include_tax() ) {
417
+            return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
418
+        }
419
+
420
+        return $this->totals['subtotal']['initial'];
421
+    }
422
+
423
+    /**
424
+     * Returns the recurring subtotal.
425
+     *
426
+     * @since 1.0.19
427
+     */
428
+    public function get_recurring_subtotal() {
429
+
430
+        if ( wpinv_prices_include_tax() ) {
431
+            return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
432
+        }
433
+
434
+        return $this->totals['subtotal']['recurring'];
435
+    }
436
+
437
+    /**
438
+     * Returns all items.
439
+     *
440
+     * @since 1.0.19
441
+     * @return GetPaid_Form_Item[]
442
+     */
443
+    public function get_items() {
444
+        return $this->items;
445
+    }
446
+
447
+    /**
448
+     * Checks if there's a single subscription group in the submission.
449
+     *
450
+     * @since 2.3.0
451
+     * @return bool
452
+     */
453
+    public function has_subscription_group() {
454
+        return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
455
+    }
456
+
457
+    /**
458
+     * Checks if there are multipe subscription groups in the submission.
459
+     *
460
+     * @since 2.3.0
461
+     * @return bool
462
+     */
463
+    public function has_multiple_subscription_groups() {
464
+        return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
465
+    }
466
+
467
+    /*
468 468
 	|--------------------------------------------------------------------------
469 469
 	| Taxes
470 470
 	|--------------------------------------------------------------------------
@@ -473,128 +473,128 @@  discard block
 block discarded – undo
473 473
 	| or only one-time.
474 474
     */
475 475
 
476
-	/**
477
-	 * Prepares the submission's taxes.
478
-	 *
479
-	 * @since 1.0.19
480
-	 */
481
-	public function process_taxes() {
482
-
483
-		// Abort if we're not using taxes.
484
-		if ( ! $this->use_taxes() ) {
485
-			return;
486
-		}
487
-
488
-		// If a custom country && state has been passed in, use it to calculate taxes.
489
-		$country = $this->get_field( 'wpinv_country', 'billing' );
490
-		if ( ! empty( $country ) ) {
491
-			$this->country = $country;
492
-		}
493
-
494
-		$state = $this->get_field( 'wpinv_state', 'billing' );
495
-		if ( ! empty( $state ) ) {
496
-			$this->state = $state;
497
-		}
498
-
499
-		// Confirm if the provided country and the ip country are similar.
500
-		$address_confirmed = $this->get_field( 'confirm-address' );
501
-		if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
502
-			throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
503
-		}
504
-
505
-		// Abort if the country is not taxable.
506
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
507
-			return;
508
-		}
509
-
510
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
511
-
512
-		foreach ( $processor->taxes as $tax ) {
513
-			$this->add_tax( $tax );
514
-		}
515
-
516
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
517
-	}
518
-
519
-	/**
520
-	 * Adds a tax to the submission.
521
-	 *
522
-	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
523
-	 * @since 1.0.19
524
-	 */
525
-	public function add_tax( $tax ) {
526
-
527
-		if ( wpinv_round_tax_per_tax_rate() ) {
528
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
529
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
530
-		}
531
-
532
-		$this->taxes[ $tax['name'] ]         = $tax;
533
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
534
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
535
-
536
-	}
537
-
538
-	/**
539
-	 * Removes a specific tax.
540
-	 *
541
-	 * @since 1.0.19
542
-	 */
543
-	public function remove_tax( $tax_name ) {
544
-
545
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
546
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
547
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
548
-			unset( $this->taxes[ $tax_name ] );
549
-		}
550
-
551
-	}
552
-
553
-	/**
554
-	 * Whether or not we'll use taxes for the submission.
555
-	 *
556
-	 * @since 1.0.19
557
-	 */
558
-	public function use_taxes() {
559
-
560
-		$use_taxes = wpinv_use_taxes();
561
-
562
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
563
-			$use_taxes = false;
564
-		}
565
-
566
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
567
-
568
-	}
569
-
570
-	/**
571
-	 * Returns the tax.
572
-	 *
573
-	 * @since 1.0.19
574
-	 */
575
-	public function get_tax() {
576
-		return $this->totals['taxes']['initial'];
577
-	}
578
-
579
-	/**
580
-	 * Returns the recurring tax.
581
-	 *
582
-	 * @since 1.0.19
583
-	 */
584
-	public function get_recurring_tax() {
585
-		return $this->totals['taxes']['recurring'];
586
-	}
587
-
588
-	/**
589
-	 * Returns all taxes.
590
-	 *
591
-	 * @since 1.0.19
592
-	 */
593
-	public function get_taxes() {
594
-		return $this->taxes;
595
-	}
596
-
597
-	/*
476
+    /**
477
+     * Prepares the submission's taxes.
478
+     *
479
+     * @since 1.0.19
480
+     */
481
+    public function process_taxes() {
482
+
483
+        // Abort if we're not using taxes.
484
+        if ( ! $this->use_taxes() ) {
485
+            return;
486
+        }
487
+
488
+        // If a custom country && state has been passed in, use it to calculate taxes.
489
+        $country = $this->get_field( 'wpinv_country', 'billing' );
490
+        if ( ! empty( $country ) ) {
491
+            $this->country = $country;
492
+        }
493
+
494
+        $state = $this->get_field( 'wpinv_state', 'billing' );
495
+        if ( ! empty( $state ) ) {
496
+            $this->state = $state;
497
+        }
498
+
499
+        // Confirm if the provided country and the ip country are similar.
500
+        $address_confirmed = $this->get_field( 'confirm-address' );
501
+        if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
502
+            throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
503
+        }
504
+
505
+        // Abort if the country is not taxable.
506
+        if ( ! wpinv_is_country_taxable( $this->country ) ) {
507
+            return;
508
+        }
509
+
510
+        $processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
511
+
512
+        foreach ( $processor->taxes as $tax ) {
513
+            $this->add_tax( $tax );
514
+        }
515
+
516
+        do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
517
+    }
518
+
519
+    /**
520
+     * Adds a tax to the submission.
521
+     *
522
+     * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
523
+     * @since 1.0.19
524
+     */
525
+    public function add_tax( $tax ) {
526
+
527
+        if ( wpinv_round_tax_per_tax_rate() ) {
528
+            $tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
529
+            $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
530
+        }
531
+
532
+        $this->taxes[ $tax['name'] ]         = $tax;
533
+        $this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
534
+        $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
535
+
536
+    }
537
+
538
+    /**
539
+     * Removes a specific tax.
540
+     *
541
+     * @since 1.0.19
542
+     */
543
+    public function remove_tax( $tax_name ) {
544
+
545
+        if ( isset( $this->taxes[ $tax_name ] ) ) {
546
+            $this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
547
+            $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
548
+            unset( $this->taxes[ $tax_name ] );
549
+        }
550
+
551
+    }
552
+
553
+    /**
554
+     * Whether or not we'll use taxes for the submission.
555
+     *
556
+     * @since 1.0.19
557
+     */
558
+    public function use_taxes() {
559
+
560
+        $use_taxes = wpinv_use_taxes();
561
+
562
+        if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
563
+            $use_taxes = false;
564
+        }
565
+
566
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
567
+
568
+    }
569
+
570
+    /**
571
+     * Returns the tax.
572
+     *
573
+     * @since 1.0.19
574
+     */
575
+    public function get_tax() {
576
+        return $this->totals['taxes']['initial'];
577
+    }
578
+
579
+    /**
580
+     * Returns the recurring tax.
581
+     *
582
+     * @since 1.0.19
583
+     */
584
+    public function get_recurring_tax() {
585
+        return $this->totals['taxes']['recurring'];
586
+    }
587
+
588
+    /**
589
+     * Returns all taxes.
590
+     *
591
+     * @since 1.0.19
592
+     */
593
+    public function get_taxes() {
594
+        return $this->taxes;
595
+    }
596
+
597
+    /*
598 598
 	|--------------------------------------------------------------------------
599 599
 	| Discounts
600 600
 	|--------------------------------------------------------------------------
@@ -603,99 +603,99 @@  discard block
 block discarded – undo
603 603
 	| or only one-time. They also do not have to come from a discount code.
604 604
     */
605 605
 
606
-	/**
607
-	 * Prepares the submission's discount.
608
-	 *
609
-	 * @since 1.0.19
610
-	 */
611
-	public function process_discount() {
612
-
613
-		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
614
-		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
615
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
616
-
617
-		foreach ( $processor->discounts as $discount ) {
618
-			$this->add_discount( $discount );
619
-		}
620
-
621
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
622
-	}
623
-
624
-	/**
625
-	 * Adds a discount to the submission.
626
-	 *
627
-	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
628
-	 * @since 1.0.19
629
-	 */
630
-	public function add_discount( $discount ) {
631
-		$this->discounts[ $discount['name'] ]   = $discount;
632
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
633
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
634
-	}
635
-
636
-	/**
637
-	 * Removes a discount from the submission.
638
-	 *
639
-	 * @since 1.0.19
640
-	 */
641
-	public function remove_discount( $name ) {
642
-
643
-		if ( isset( $this->discounts[ $name ] ) ) {
644
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
645
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
646
-			unset( $this->discounts[ $name ] );
647
-		}
648
-
649
-	}
650
-
651
-	/**
652
-	 * Checks whether there is a discount code associated with this submission.
653
-	 *
654
-	 * @since 1.0.19
655
-	 * @return bool
656
-	 */
657
-	public function has_discount_code() {
658
-		return ! empty( $this->discounts['discount_code'] );
659
-	}
660
-
661
-	/**
662
-	 * Returns the discount code.
663
-	 *
664
-	 * @since 1.0.19
665
-	 * @return string
666
-	 */
667
-	public function get_discount_code() {
668
-		return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
669
-	}
670
-
671
-	/**
672
-	 * Returns the discount.
673
-	 *
674
-	 * @since 1.0.19
675
-	 */
676
-	public function get_discount() {
677
-		return $this->totals['discount']['initial'];
678
-	}
679
-
680
-	/**
681
-	 * Returns the recurring discount.
682
-	 *
683
-	 * @since 1.0.19
684
-	 */
685
-	public function get_recurring_discount() {
686
-		return $this->totals['discount']['recurring'];
687
-	}
688
-
689
-	/**
690
-	 * Returns all discounts.
691
-	 *
692
-	 * @since 1.0.19
693
-	 */
694
-	public function get_discounts() {
695
-		return $this->discounts;
696
-	}
697
-
698
-	/*
606
+    /**
607
+     * Prepares the submission's discount.
608
+     *
609
+     * @since 1.0.19
610
+     */
611
+    public function process_discount() {
612
+
613
+        $initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
614
+        $recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
615
+        $processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
616
+
617
+        foreach ( $processor->discounts as $discount ) {
618
+            $this->add_discount( $discount );
619
+        }
620
+
621
+        do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
622
+    }
623
+
624
+    /**
625
+     * Adds a discount to the submission.
626
+     *
627
+     * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
628
+     * @since 1.0.19
629
+     */
630
+    public function add_discount( $discount ) {
631
+        $this->discounts[ $discount['name'] ]   = $discount;
632
+        $this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
633
+        $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
634
+    }
635
+
636
+    /**
637
+     * Removes a discount from the submission.
638
+     *
639
+     * @since 1.0.19
640
+     */
641
+    public function remove_discount( $name ) {
642
+
643
+        if ( isset( $this->discounts[ $name ] ) ) {
644
+            $this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
645
+            $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
646
+            unset( $this->discounts[ $name ] );
647
+        }
648
+
649
+    }
650
+
651
+    /**
652
+     * Checks whether there is a discount code associated with this submission.
653
+     *
654
+     * @since 1.0.19
655
+     * @return bool
656
+     */
657
+    public function has_discount_code() {
658
+        return ! empty( $this->discounts['discount_code'] );
659
+    }
660
+
661
+    /**
662
+     * Returns the discount code.
663
+     *
664
+     * @since 1.0.19
665
+     * @return string
666
+     */
667
+    public function get_discount_code() {
668
+        return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
669
+    }
670
+
671
+    /**
672
+     * Returns the discount.
673
+     *
674
+     * @since 1.0.19
675
+     */
676
+    public function get_discount() {
677
+        return $this->totals['discount']['initial'];
678
+    }
679
+
680
+    /**
681
+     * Returns the recurring discount.
682
+     *
683
+     * @since 1.0.19
684
+     */
685
+    public function get_recurring_discount() {
686
+        return $this->totals['discount']['recurring'];
687
+    }
688
+
689
+    /**
690
+     * Returns all discounts.
691
+     *
692
+     * @since 1.0.19
693
+     */
694
+    public function get_discounts() {
695
+        return $this->discounts;
696
+    }
697
+
698
+    /*
699 699
 	|--------------------------------------------------------------------------
700 700
 	| Fees
701 701
 	|--------------------------------------------------------------------------
@@ -705,100 +705,100 @@  discard block
 block discarded – undo
705 705
 	| fees.
706 706
     */
707 707
 
708
-	/**
709
-	 * Prepares the submission's fees.
710
-	 *
711
-	 * @since 1.0.19
712
-	 */
713
-	public function process_fees() {
714
-
715
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
716
-
717
-		foreach ( $fees_processor->fees as $fee ) {
718
-			$this->add_fee( $fee );
719
-		}
720
-
721
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
722
-	}
723
-
724
-	/**
725
-	 * Adds a fee to the submission.
726
-	 *
727
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
728
-	 * @since 1.0.19
729
-	 */
730
-	public function add_fee( $fee ) {
731
-
732
-		if ( $fee['name'] == 'shipping' ) {
733
-			$this->totals['shipping']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
734
-			$this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
735
-			return;
736
-		}
737
-
738
-		$this->fees[ $fee['name'] ]         = $fee;
739
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
740
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
741
-
742
-	}
743
-
744
-	/**
745
-	 * Removes a fee from the submission.
746
-	 *
747
-	 * @since 1.0.19
748
-	 */
749
-	public function remove_fee( $name ) {
750
-
751
-		if ( isset( $this->fees[ $name ] ) ) {
752
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
753
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
754
-			unset( $this->fees[ $name ] );
755
-		}
756
-
757
-		if ( 'shipping' == $name ) {
758
-			$this->totals['shipping']['initial']   = 0;
759
-			$this->totals['shipping']['recurring'] = 0;
760
-		}
761
-
762
-	}
763
-
764
-	/**
765
-	 * Returns the fees.
766
-	 *
767
-	 * @since 1.0.19
768
-	 */
769
-	public function get_fee() {
770
-		return $this->totals['fees']['initial'];
771
-	}
772
-
773
-	/**
774
-	 * Returns the recurring fees.
775
-	 *
776
-	 * @since 1.0.19
777
-	 */
778
-	public function get_recurring_fee() {
779
-		return $this->totals['fees']['recurring'];
780
-	}
781
-
782
-	/**
783
-	 * Returns all fees.
784
-	 *
785
-	 * @since 1.0.19
786
-	 */
787
-	public function get_fees() {
788
-		return $this->fees;
789
-	}
790
-
791
-	/**
792
-	 * Checks if there are any fees for the form.
793
-	 *
794
-	 * @return bool
795
-	 * @since 1.0.19
796
-	 */
797
-	public function has_fees() {
798
-		return count( $this->fees ) !== 0;
799
-	}
800
-
801
-	/*
708
+    /**
709
+     * Prepares the submission's fees.
710
+     *
711
+     * @since 1.0.19
712
+     */
713
+    public function process_fees() {
714
+
715
+        $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
716
+
717
+        foreach ( $fees_processor->fees as $fee ) {
718
+            $this->add_fee( $fee );
719
+        }
720
+
721
+        do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
722
+    }
723
+
724
+    /**
725
+     * Adds a fee to the submission.
726
+     *
727
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
728
+     * @since 1.0.19
729
+     */
730
+    public function add_fee( $fee ) {
731
+
732
+        if ( $fee['name'] == 'shipping' ) {
733
+            $this->totals['shipping']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
734
+            $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
735
+            return;
736
+        }
737
+
738
+        $this->fees[ $fee['name'] ]         = $fee;
739
+        $this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
740
+        $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
741
+
742
+    }
743
+
744
+    /**
745
+     * Removes a fee from the submission.
746
+     *
747
+     * @since 1.0.19
748
+     */
749
+    public function remove_fee( $name ) {
750
+
751
+        if ( isset( $this->fees[ $name ] ) ) {
752
+            $this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
753
+            $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
754
+            unset( $this->fees[ $name ] );
755
+        }
756
+
757
+        if ( 'shipping' == $name ) {
758
+            $this->totals['shipping']['initial']   = 0;
759
+            $this->totals['shipping']['recurring'] = 0;
760
+        }
761
+
762
+    }
763
+
764
+    /**
765
+     * Returns the fees.
766
+     *
767
+     * @since 1.0.19
768
+     */
769
+    public function get_fee() {
770
+        return $this->totals['fees']['initial'];
771
+    }
772
+
773
+    /**
774
+     * Returns the recurring fees.
775
+     *
776
+     * @since 1.0.19
777
+     */
778
+    public function get_recurring_fee() {
779
+        return $this->totals['fees']['recurring'];
780
+    }
781
+
782
+    /**
783
+     * Returns all fees.
784
+     *
785
+     * @since 1.0.19
786
+     */
787
+    public function get_fees() {
788
+        return $this->fees;
789
+    }
790
+
791
+    /**
792
+     * Checks if there are any fees for the form.
793
+     *
794
+     * @return bool
795
+     * @since 1.0.19
796
+     */
797
+    public function has_fees() {
798
+        return count( $this->fees ) !== 0;
799
+    }
800
+
801
+    /*
802 802
 	|--------------------------------------------------------------------------
803 803
 	| MISC
804 804
 	|--------------------------------------------------------------------------
@@ -806,147 +806,147 @@  discard block
 block discarded – undo
806 806
 	| Extra submission functions.
807 807
     */
808 808
 
809
-	/**
810
-	 * Returns the shipping amount.
811
-	 *
812
-	 * @since 1.0.19
813
-	 */
814
-	public function get_shipping() {
815
-		return $this->totals['shipping']['initial'];
816
-	}
817
-
818
-	/**
819
-	 * Returns the recurring shipping.
820
-	 *
821
-	 * @since 1.0.19
822
-	 */
823
-	public function get_recurring_shipping() {
824
-		return $this->totals['shipping']['recurring'];
825
-	}
826
-
827
-	/**
828
-	 * Checks if there are any shipping fees for the form.
829
-	 *
830
-	 * @return bool
831
-	 * @since 1.0.19
832
-	 */
833
-	public function has_shipping() {
834
-		return apply_filters( 'getpaid_payment_form_has_shipping', false, $this );
835
-	}
836
-
837
-	/**
838
-	 * Checks if this is the initial fetch.
839
-	 *
840
-	 * @return bool
841
-	 * @since 1.0.19
842
-	 */
843
-	public function is_initial_fetch() {
844
-		return empty( $this->data['initial_state'] );
845
-	}
846
-
847
-	/**
848
-	 * Returns the total amount to collect for this submission.
849
-	 *
850
-	 * @since 1.0.19
851
-	 */
852
-	public function get_total() {
853
-		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount();
854
-		return max( $total, 0 );
855
-	}
856
-
857
-	/**
858
-	 * Returns the recurring total amount to collect for this submission.
859
-	 *
860
-	 * @since 1.0.19
861
-	 */
862
-	public function get_recurring_total() {
863
-		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount();
864
-		return max( $total, 0 );
865
-	}
866
-
867
-	/**
868
-	 * Whether payment details should be collected for this submission.
869
-	 *
870
-	 * @since 1.0.19
871
-	 */
872
-	public function should_collect_payment_details() {
873
-		$initial   = $this->get_total();
874
-		$recurring = $this->get_recurring_total();
875
-
876
-		if ( $this->has_recurring == 0 ) {
877
-			$recurring = 0;
878
-		}
879
-
880
-		$collect = $initial > 0 || $recurring > 0;
881
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
882
-	}
883
-
884
-	/**
885
-	 * Returns the billing email of the user.
886
-	 *
887
-	 * @since 1.0.19
888
-	 */
889
-	public function get_billing_email() {
890
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
891
-	}
892
-
893
-	/**
894
-	 * Checks if the submitter has a billing email.
895
-	 *
896
-	 * @since 1.0.19
897
-	 */
898
-	public function has_billing_email() {
899
-		$billing_email = $this->get_billing_email();
900
-		return ! empty( $billing_email ) && is_email( $billing_email );
901
-	}
902
-
903
-	/**
904
-	 * Returns the appropriate currency for the submission.
905
-	 *
906
-	 * @since 1.0.19
907
-	 * @return string
908
-	 */
909
-	public function get_currency() {
910
-		return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
911
-    }
912
-
913
-    /**
914
-	 * Returns the raw submission data.
915
-	 *
916
-	 * @since 1.0.19
917
-	 * @return array
918
-	 */
919
-	public function get_data() {
920
-		return $this->data;
921
-	}
922
-
923
-	/**
924
-	 * Returns a field from the submission data
925
-	 *
926
-	 * @param string $field
927
-	 * @since 1.0.19
928
-	 * @return mixed|null
929
-	 */
930
-	public function get_field( $field, $sub_array_key = null ) {
931
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
932
-	}
933
-
934
-	/**
935
-	 * Checks if a required field is set.
936
-	 *
937
-	 * @since 1.0.19
938
-	 */
939
-	public function is_required_field_set( $field ) {
940
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
941
-	}
942
-
943
-	/**
944
-	 * Formats an amount
945
-	 *
946
-	 * @since 1.0.19
947
-	 */
948
-	public function format_amount( $amount ) {
949
-		return wpinv_price( $amount, $this->get_currency() );
950
-	}
809
+    /**
810
+     * Returns the shipping amount.
811
+     *
812
+     * @since 1.0.19
813
+     */
814
+    public function get_shipping() {
815
+        return $this->totals['shipping']['initial'];
816
+    }
817
+
818
+    /**
819
+     * Returns the recurring shipping.
820
+     *
821
+     * @since 1.0.19
822
+     */
823
+    public function get_recurring_shipping() {
824
+        return $this->totals['shipping']['recurring'];
825
+    }
826
+
827
+    /**
828
+     * Checks if there are any shipping fees for the form.
829
+     *
830
+     * @return bool
831
+     * @since 1.0.19
832
+     */
833
+    public function has_shipping() {
834
+        return apply_filters( 'getpaid_payment_form_has_shipping', false, $this );
835
+    }
836
+
837
+    /**
838
+     * Checks if this is the initial fetch.
839
+     *
840
+     * @return bool
841
+     * @since 1.0.19
842
+     */
843
+    public function is_initial_fetch() {
844
+        return empty( $this->data['initial_state'] );
845
+    }
846
+
847
+    /**
848
+     * Returns the total amount to collect for this submission.
849
+     *
850
+     * @since 1.0.19
851
+     */
852
+    public function get_total() {
853
+        $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount();
854
+        return max( $total, 0 );
855
+    }
856
+
857
+    /**
858
+     * Returns the recurring total amount to collect for this submission.
859
+     *
860
+     * @since 1.0.19
861
+     */
862
+    public function get_recurring_total() {
863
+        $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount();
864
+        return max( $total, 0 );
865
+    }
866
+
867
+    /**
868
+     * Whether payment details should be collected for this submission.
869
+     *
870
+     * @since 1.0.19
871
+     */
872
+    public function should_collect_payment_details() {
873
+        $initial   = $this->get_total();
874
+        $recurring = $this->get_recurring_total();
875
+
876
+        if ( $this->has_recurring == 0 ) {
877
+            $recurring = 0;
878
+        }
879
+
880
+        $collect = $initial > 0 || $recurring > 0;
881
+        return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
882
+    }
883
+
884
+    /**
885
+     * Returns the billing email of the user.
886
+     *
887
+     * @since 1.0.19
888
+     */
889
+    public function get_billing_email() {
890
+        return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
891
+    }
892
+
893
+    /**
894
+     * Checks if the submitter has a billing email.
895
+     *
896
+     * @since 1.0.19
897
+     */
898
+    public function has_billing_email() {
899
+        $billing_email = $this->get_billing_email();
900
+        return ! empty( $billing_email ) && is_email( $billing_email );
901
+    }
902
+
903
+    /**
904
+     * Returns the appropriate currency for the submission.
905
+     *
906
+     * @since 1.0.19
907
+     * @return string
908
+     */
909
+    public function get_currency() {
910
+        return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
911
+    }
912
+
913
+    /**
914
+     * Returns the raw submission data.
915
+     *
916
+     * @since 1.0.19
917
+     * @return array
918
+     */
919
+    public function get_data() {
920
+        return $this->data;
921
+    }
922
+
923
+    /**
924
+     * Returns a field from the submission data
925
+     *
926
+     * @param string $field
927
+     * @since 1.0.19
928
+     * @return mixed|null
929
+     */
930
+    public function get_field( $field, $sub_array_key = null ) {
931
+        return getpaid_get_array_field( $this->data, $field, $sub_array_key );
932
+    }
933
+
934
+    /**
935
+     * Checks if a required field is set.
936
+     *
937
+     * @since 1.0.19
938
+     */
939
+    public function is_required_field_set( $field ) {
940
+        return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
941
+    }
942
+
943
+    /**
944
+     * Formats an amount
945
+     *
946
+     * @since 1.0.19
947
+     */
948
+    public function format_amount( $amount ) {
949
+        return wpinv_price( $amount, $this->get_currency() );
950
+    }
951 951
 
952 952
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-invoice-data-store.php 1 patch
Indentation   +479 added lines, -479 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,544 +15,544 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP {
17 17
 
18
-	/**
19
-	 * Data stored in meta keys, but not considered "meta" for a discount.
20
-	 *
21
-	 * @since 1.0.19
22
-	 * @var array
23
-	 */
24
-	protected $internal_meta_keys = array(
25
-		'_wpinv_subscr_profile_id',
26
-		'_wpinv_subscription_id',
27
-		'_wpinv_taxes',
28
-		'_wpinv_fees',
29
-		'_wpinv_discounts',
30
-		'_wpinv_submission_id',
31
-		'_wpinv_payment_form',
32
-		'_wpinv_is_viewed',
33
-		'_wpinv_phone',
34
-		'_wpinv_company_id',
35
-		'wpinv_shipping',
36
-		'wpinv_email_cc',
37
-		'wpinv_template',
38
-		'wpinv_created_via'
39
-	);
40
-
41
-	/**
42
-	 * A map of meta keys to data props.
43
-	 *
44
-	 * @since 1.0.19
45
-	 *
46
-	 * @var array
47
-	 */
48
-	protected $meta_key_to_props = array(
49
-		'_wpinv_subscr_profile_id' => 'remote_subscription_id',
50
-		'_wpinv_subscription_id'   => 'subscription_id',
51
-		'_wpinv_taxes'             => 'taxes',
52
-		'_wpinv_fees'              => 'fees',
53
-		'_wpinv_discounts'         => 'discounts',
54
-		'_wpinv_submission_id'     => 'submission_id',
55
-		'_wpinv_payment_form'      => 'payment_form',
56
-		'_wpinv_is_viewed'         => 'is_viewed',
57
-		'wpinv_email_cc'           => 'email_cc',
58
-		'wpinv_template'           => 'template',
59
-		'wpinv_created_via'        => 'created_via',
60
-		'_wpinv_phone'             => 'phone',
61
-		'_wpinv_company_id'        => 'company_id',
62
-		'wpinv_shipping'           => 'shipping',
63
-	);
64
-
65
-	/**
66
-	 * A map of database fields to data props.
67
-	 *
68
-	 * @since 1.0.19
69
-	 *
70
-	 * @var array
71
-	 */
72
-	protected $database_fields_to_props = array(
73
-		'post_id'            => 'id',
74
-		'number'             => 'number',
75
-		'currency'           => 'currency',
76
-		'key'                => 'key',
77
-		'type'               => 'type',
78
-		'mode'               => 'mode',
79
-		'user_ip'            => 'user_ip',
80
-		'first_name'         => 'first_name',
81
-		'last_name'          => 'last_name',
82
-		'address'            => 'address',
83
-		'city'               => 'city',
84
-		'state'              => 'state',
85
-		'country'            => 'country',
86
-		'zip'                => 'zip',
87
-		'zip'                => 'zip',
88
-		'adddress_confirmed' => 'address_confirmed',
89
-		'gateway'            => 'gateway',
90
-		'transaction_id'     => 'transaction_id',
91
-		'currency'           => 'currency',
92
-		'subtotal'           => 'subtotal',
93
-		'tax'                => 'total_tax',
94
-		'fees_total'         => 'total_fees',
95
-		'discount'           => 'total_discount',
96
-		'total'              => 'total',
97
-		'discount_code'      => 'discount_code',
98
-		'disable_taxes'      => 'disable_taxes',
99
-		'due_date'           => 'due_date',
100
-		'completed_date'     => 'completed_date',
101
-		'company'            => 'company',
102
-		'vat_number'         => 'vat_number',
103
-		'vat_rate'           => 'vat_rate',
104
-	);
105
-
106
-	/*
18
+    /**
19
+     * Data stored in meta keys, but not considered "meta" for a discount.
20
+     *
21
+     * @since 1.0.19
22
+     * @var array
23
+     */
24
+    protected $internal_meta_keys = array(
25
+        '_wpinv_subscr_profile_id',
26
+        '_wpinv_subscription_id',
27
+        '_wpinv_taxes',
28
+        '_wpinv_fees',
29
+        '_wpinv_discounts',
30
+        '_wpinv_submission_id',
31
+        '_wpinv_payment_form',
32
+        '_wpinv_is_viewed',
33
+        '_wpinv_phone',
34
+        '_wpinv_company_id',
35
+        'wpinv_shipping',
36
+        'wpinv_email_cc',
37
+        'wpinv_template',
38
+        'wpinv_created_via'
39
+    );
40
+
41
+    /**
42
+     * A map of meta keys to data props.
43
+     *
44
+     * @since 1.0.19
45
+     *
46
+     * @var array
47
+     */
48
+    protected $meta_key_to_props = array(
49
+        '_wpinv_subscr_profile_id' => 'remote_subscription_id',
50
+        '_wpinv_subscription_id'   => 'subscription_id',
51
+        '_wpinv_taxes'             => 'taxes',
52
+        '_wpinv_fees'              => 'fees',
53
+        '_wpinv_discounts'         => 'discounts',
54
+        '_wpinv_submission_id'     => 'submission_id',
55
+        '_wpinv_payment_form'      => 'payment_form',
56
+        '_wpinv_is_viewed'         => 'is_viewed',
57
+        'wpinv_email_cc'           => 'email_cc',
58
+        'wpinv_template'           => 'template',
59
+        'wpinv_created_via'        => 'created_via',
60
+        '_wpinv_phone'             => 'phone',
61
+        '_wpinv_company_id'        => 'company_id',
62
+        'wpinv_shipping'           => 'shipping',
63
+    );
64
+
65
+    /**
66
+     * A map of database fields to data props.
67
+     *
68
+     * @since 1.0.19
69
+     *
70
+     * @var array
71
+     */
72
+    protected $database_fields_to_props = array(
73
+        'post_id'            => 'id',
74
+        'number'             => 'number',
75
+        'currency'           => 'currency',
76
+        'key'                => 'key',
77
+        'type'               => 'type',
78
+        'mode'               => 'mode',
79
+        'user_ip'            => 'user_ip',
80
+        'first_name'         => 'first_name',
81
+        'last_name'          => 'last_name',
82
+        'address'            => 'address',
83
+        'city'               => 'city',
84
+        'state'              => 'state',
85
+        'country'            => 'country',
86
+        'zip'                => 'zip',
87
+        'zip'                => 'zip',
88
+        'adddress_confirmed' => 'address_confirmed',
89
+        'gateway'            => 'gateway',
90
+        'transaction_id'     => 'transaction_id',
91
+        'currency'           => 'currency',
92
+        'subtotal'           => 'subtotal',
93
+        'tax'                => 'total_tax',
94
+        'fees_total'         => 'total_fees',
95
+        'discount'           => 'total_discount',
96
+        'total'              => 'total',
97
+        'discount_code'      => 'discount_code',
98
+        'disable_taxes'      => 'disable_taxes',
99
+        'due_date'           => 'due_date',
100
+        'completed_date'     => 'completed_date',
101
+        'company'            => 'company',
102
+        'vat_number'         => 'vat_number',
103
+        'vat_rate'           => 'vat_rate',
104
+    );
105
+
106
+    /*
107 107
 	|--------------------------------------------------------------------------
108 108
 	| CRUD Methods
109 109
 	|--------------------------------------------------------------------------
110 110
 	*/
111 111
 
112
-	/**
113
-	 * Method to create a new invoice in the database.
114
-	 *
115
-	 * @param WPInv_Invoice $invoice Invoice object.
116
-	 */
117
-	public function create( &$invoice ) {
118
-		$invoice->set_version( WPINV_VERSION );
119
-		$invoice->set_date_created( current_time('mysql') );
120
-
121
-		// Create a new post.
122
-		$id = wp_insert_post(
123
-			apply_filters(
124
-				'getpaid_new_invoice_data',
125
-				array(
126
-					'post_date'     => $invoice->get_date_created( 'edit' ),
127
-					'post_type'     => $invoice->get_post_type( 'edit' ),
128
-					'post_status'   => $this->get_post_status( $invoice ),
129
-					'ping_status'   => 'closed',
130
-					'post_author'   => $invoice->get_user_id( 'edit' ),
131
-					'post_title'    => $invoice->get_title( 'edit' ),
132
-					'post_excerpt'  => $invoice->get_description( 'edit' ),
133
-					'post_parent'   => $invoice->get_parent_id( 'edit' ),
134
-				)
135
-			),
136
-			true
137
-		);
138
-
139
-		if ( $id && ! is_wp_error( $id ) ) {
140
-
141
-			// Update the new id and regenerate a title.
142
-			$invoice->set_id( $id );
143
-
144
-			$invoice->maybe_set_number();
145
-
146
-			wp_update_post(
147
-				array(
148
-					'ID'         => $invoice->get_id(),
149
-					'post_title' => $invoice->get_number( 'edit' ),
150
-					'post_name'  => $invoice->get_path( 'edit' )
151
-				)
152
-			);
153
-
154
-			// Save special fields and items.
155
-			$this->save_special_fields( $invoice );
156
-			$this->save_items( $invoice );
157
-
158
-			// Update meta data.
159
-			$this->update_post_meta( $invoice );
160
-			$invoice->save_meta_data();
161
-
162
-			// Apply changes.
163
-			$invoice->apply_changes();
164
-			$this->clear_caches( $invoice );
165
-
166
-			// Fires after a new invoice is created.
167
-			do_action( 'getpaid_new_invoice', $invoice );
168
-			return true;
169
-		}
170
-
171
-		if ( is_wp_error( $id ) ) {
172
-			$invoice->last_error = $id->get_error_message();
173
-		}
174
-
175
-		return false;
176
-	}
177
-
178
-	/**
179
-	 * Method to read an invoice from the database.
180
-	 *
181
-	 * @param WPInv_Invoice $invoice Invoice object.
182
-	 *
183
-	 */
184
-	public function read( &$invoice ) {
185
-
186
-		$invoice->set_defaults();
187
-		$invoice_object = get_post( $invoice->get_id() );
188
-
189
-		if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
190
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
191
-			$invoice->set_id( 0 );
192
-			return false;
193
-		}
194
-
195
-		$invoice->set_props(
196
-			array(
197
-				'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
198
-				'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
199
-				'status'        => $invoice_object->post_status,
200
-				'author'        => $invoice_object->post_author,
201
-				'description'   => $invoice_object->post_excerpt,
202
-				'parent_id'     => $invoice_object->post_parent,
203
-				'name'          => $invoice_object->post_title,
204
-				'path'          => $invoice_object->post_name,
205
-				'post_type'     => $invoice_object->post_type,
206
-			)
207
-		);
208
-
209
-		$invoice->set_type( $invoice_object->post_type );
210
-
211
-		$this->read_object_data( $invoice, $invoice_object );
212
-		$this->add_special_fields( $invoice );
213
-		$this->add_items( $invoice );
214
-		$invoice->read_meta_data();
215
-		$invoice->set_object_read( true );
216
-		do_action( 'getpaid_read_invoice', $invoice );
217
-
218
-	}
219
-
220
-	/**
221
-	 * Method to update an invoice in the database.
222
-	 *
223
-	 * @param WPInv_Invoice $invoice Invoice object.
224
-	 */
225
-	public function update( &$invoice ) {
226
-		$invoice->save_meta_data();
227
-		$invoice->set_version( WPINV_VERSION );
228
-
229
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
230
-			$invoice->set_date_created(  current_time('mysql') );
231
-		}
232
-
233
-		// Ensure both the key and number are set.
234
-		$invoice->get_path();
235
-
236
-		// Grab the current status so we can compare.
237
-		$previous_status = get_post_status( $invoice->get_id() );
238
-
239
-		$changes = $invoice->get_changes();
240
-
241
-		// Only update the post when the post data changes.
242
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
243
-			$post_data = array(
244
-				'post_date'         => $invoice->get_date_created( 'edit' ),
245
-				'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
246
-				'post_status'       => $invoice->get_status( 'edit' ),
247
-				'post_title'        => $invoice->get_name( 'edit' ),
248
-				'post_author'       => $invoice->get_user_id( 'edit' ),
249
-				'post_modified'     => $invoice->get_date_modified( 'edit' ),
250
-				'post_excerpt'      => $invoice->get_description( 'edit' ),
251
-				'post_parent'       => $invoice->get_parent_id( 'edit' ),
252
-				'post_name'         => $invoice->get_path( 'edit' ),
253
-				'post_type'         => $invoice->get_post_type( 'edit' ),
254
-			);
255
-
256
-			/**
257
-			 * When updating this object, to prevent infinite loops, use $wpdb
258
-			 * to update data, since wp_update_post spawns more calls to the
259
-			 * save_post action.
260
-			 *
261
-			 * This ensures hooks are fired by either WP itself (admin screen save),
262
-			 * or an update purely from CRUD.
263
-			 */
264
-			if ( doing_action( 'save_post' ) ) {
265
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
266
-				clean_post_cache( $invoice->get_id() );
267
-			} else {
268
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
269
-			}
270
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
271
-		}
272
-
273
-		// Update meta data.
274
-		$this->update_post_meta( $invoice );
275
-
276
-		// Save special fields and items.
277
-		$this->save_special_fields( $invoice );
278
-		$this->save_items( $invoice );
279
-
280
-		// Apply the changes.
281
-		$invoice->apply_changes();
282
-
283
-		// Clear caches.
284
-		$this->clear_caches( $invoice );
285
-
286
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
287
-		$new_status = $invoice->get_status( 'edit' );
288
-
289
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
290
-			do_action( 'getpaid_new_invoice', $invoice );
291
-		} else {
292
-			do_action( 'getpaid_update_invoice', $invoice );
293
-		}
294
-
295
-	}
296
-
297
-	/*
112
+    /**
113
+     * Method to create a new invoice in the database.
114
+     *
115
+     * @param WPInv_Invoice $invoice Invoice object.
116
+     */
117
+    public function create( &$invoice ) {
118
+        $invoice->set_version( WPINV_VERSION );
119
+        $invoice->set_date_created( current_time('mysql') );
120
+
121
+        // Create a new post.
122
+        $id = wp_insert_post(
123
+            apply_filters(
124
+                'getpaid_new_invoice_data',
125
+                array(
126
+                    'post_date'     => $invoice->get_date_created( 'edit' ),
127
+                    'post_type'     => $invoice->get_post_type( 'edit' ),
128
+                    'post_status'   => $this->get_post_status( $invoice ),
129
+                    'ping_status'   => 'closed',
130
+                    'post_author'   => $invoice->get_user_id( 'edit' ),
131
+                    'post_title'    => $invoice->get_title( 'edit' ),
132
+                    'post_excerpt'  => $invoice->get_description( 'edit' ),
133
+                    'post_parent'   => $invoice->get_parent_id( 'edit' ),
134
+                )
135
+            ),
136
+            true
137
+        );
138
+
139
+        if ( $id && ! is_wp_error( $id ) ) {
140
+
141
+            // Update the new id and regenerate a title.
142
+            $invoice->set_id( $id );
143
+
144
+            $invoice->maybe_set_number();
145
+
146
+            wp_update_post(
147
+                array(
148
+                    'ID'         => $invoice->get_id(),
149
+                    'post_title' => $invoice->get_number( 'edit' ),
150
+                    'post_name'  => $invoice->get_path( 'edit' )
151
+                )
152
+            );
153
+
154
+            // Save special fields and items.
155
+            $this->save_special_fields( $invoice );
156
+            $this->save_items( $invoice );
157
+
158
+            // Update meta data.
159
+            $this->update_post_meta( $invoice );
160
+            $invoice->save_meta_data();
161
+
162
+            // Apply changes.
163
+            $invoice->apply_changes();
164
+            $this->clear_caches( $invoice );
165
+
166
+            // Fires after a new invoice is created.
167
+            do_action( 'getpaid_new_invoice', $invoice );
168
+            return true;
169
+        }
170
+
171
+        if ( is_wp_error( $id ) ) {
172
+            $invoice->last_error = $id->get_error_message();
173
+        }
174
+
175
+        return false;
176
+    }
177
+
178
+    /**
179
+     * Method to read an invoice from the database.
180
+     *
181
+     * @param WPInv_Invoice $invoice Invoice object.
182
+     *
183
+     */
184
+    public function read( &$invoice ) {
185
+
186
+        $invoice->set_defaults();
187
+        $invoice_object = get_post( $invoice->get_id() );
188
+
189
+        if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
190
+            $invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
191
+            $invoice->set_id( 0 );
192
+            return false;
193
+        }
194
+
195
+        $invoice->set_props(
196
+            array(
197
+                'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
198
+                'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
199
+                'status'        => $invoice_object->post_status,
200
+                'author'        => $invoice_object->post_author,
201
+                'description'   => $invoice_object->post_excerpt,
202
+                'parent_id'     => $invoice_object->post_parent,
203
+                'name'          => $invoice_object->post_title,
204
+                'path'          => $invoice_object->post_name,
205
+                'post_type'     => $invoice_object->post_type,
206
+            )
207
+        );
208
+
209
+        $invoice->set_type( $invoice_object->post_type );
210
+
211
+        $this->read_object_data( $invoice, $invoice_object );
212
+        $this->add_special_fields( $invoice );
213
+        $this->add_items( $invoice );
214
+        $invoice->read_meta_data();
215
+        $invoice->set_object_read( true );
216
+        do_action( 'getpaid_read_invoice', $invoice );
217
+
218
+    }
219
+
220
+    /**
221
+     * Method to update an invoice in the database.
222
+     *
223
+     * @param WPInv_Invoice $invoice Invoice object.
224
+     */
225
+    public function update( &$invoice ) {
226
+        $invoice->save_meta_data();
227
+        $invoice->set_version( WPINV_VERSION );
228
+
229
+        if ( null === $invoice->get_date_created( 'edit' ) ) {
230
+            $invoice->set_date_created(  current_time('mysql') );
231
+        }
232
+
233
+        // Ensure both the key and number are set.
234
+        $invoice->get_path();
235
+
236
+        // Grab the current status so we can compare.
237
+        $previous_status = get_post_status( $invoice->get_id() );
238
+
239
+        $changes = $invoice->get_changes();
240
+
241
+        // Only update the post when the post data changes.
242
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
243
+            $post_data = array(
244
+                'post_date'         => $invoice->get_date_created( 'edit' ),
245
+                'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
246
+                'post_status'       => $invoice->get_status( 'edit' ),
247
+                'post_title'        => $invoice->get_name( 'edit' ),
248
+                'post_author'       => $invoice->get_user_id( 'edit' ),
249
+                'post_modified'     => $invoice->get_date_modified( 'edit' ),
250
+                'post_excerpt'      => $invoice->get_description( 'edit' ),
251
+                'post_parent'       => $invoice->get_parent_id( 'edit' ),
252
+                'post_name'         => $invoice->get_path( 'edit' ),
253
+                'post_type'         => $invoice->get_post_type( 'edit' ),
254
+            );
255
+
256
+            /**
257
+             * When updating this object, to prevent infinite loops, use $wpdb
258
+             * to update data, since wp_update_post spawns more calls to the
259
+             * save_post action.
260
+             *
261
+             * This ensures hooks are fired by either WP itself (admin screen save),
262
+             * or an update purely from CRUD.
263
+             */
264
+            if ( doing_action( 'save_post' ) ) {
265
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
266
+                clean_post_cache( $invoice->get_id() );
267
+            } else {
268
+                wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
269
+            }
270
+            $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
271
+        }
272
+
273
+        // Update meta data.
274
+        $this->update_post_meta( $invoice );
275
+
276
+        // Save special fields and items.
277
+        $this->save_special_fields( $invoice );
278
+        $this->save_items( $invoice );
279
+
280
+        // Apply the changes.
281
+        $invoice->apply_changes();
282
+
283
+        // Clear caches.
284
+        $this->clear_caches( $invoice );
285
+
286
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
287
+        $new_status = $invoice->get_status( 'edit' );
288
+
289
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
290
+            do_action( 'getpaid_new_invoice', $invoice );
291
+        } else {
292
+            do_action( 'getpaid_update_invoice', $invoice );
293
+        }
294
+
295
+    }
296
+
297
+    /*
298 298
 	|--------------------------------------------------------------------------
299 299
 	| Additional Methods
300 300
 	|--------------------------------------------------------------------------
301 301
 	*/
302 302
 
303
-	/**
303
+    /**
304 304
      * Retrieves special fields and adds to the invoice.
305
-	 *
306
-	 * @param WPInv_Invoice $invoice Invoice object.
305
+     *
306
+     * @param WPInv_Invoice $invoice Invoice object.
307 307
      */
308 308
     public function add_special_fields( &$invoice ) {
309
-		global $wpdb;
309
+        global $wpdb;
310 310
 
311
-		// Maybe retrieve from the cache.
312
-		$data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
311
+        // Maybe retrieve from the cache.
312
+        $data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
313 313
 
314
-		// If not found, retrieve from the db.
315
-		if ( false === $data ) {
316
-			$table =  $wpdb->prefix . 'getpaid_invoices';
314
+        // If not found, retrieve from the db.
315
+        if ( false === $data ) {
316
+            $table =  $wpdb->prefix . 'getpaid_invoices';
317 317
 
318
-			$data  = $wpdb->get_row(
319
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
320
-				ARRAY_A
321
-			);
318
+            $data  = $wpdb->get_row(
319
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
320
+                ARRAY_A
321
+            );
322 322
 
323
-			// Update the cache with our data
324
-			wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
323
+            // Update the cache with our data
324
+            wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
325 325
 
326
-		}
326
+        }
327 327
 
328
-		// Abort if the data does not exist.
329
-		if ( empty( $data ) ) {
330
-			$invoice->set_object_read( true );
331
-			$invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
332
-			return;
333
-		}
328
+        // Abort if the data does not exist.
329
+        if ( empty( $data ) ) {
330
+            $invoice->set_object_read( true );
331
+            $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
332
+            return;
333
+        }
334 334
 
335
-		$props = array();
335
+        $props = array();
336 336
 
337
-		foreach ( $this->database_fields_to_props as $db_field => $prop ) {
337
+        foreach ( $this->database_fields_to_props as $db_field => $prop ) {
338 338
 			
339
-			if ( $db_field == 'post_id' ) {
340
-				continue;
341
-			}
342
-
343
-			$props[ $prop ] = $data[ $db_field ];
344
-		}
345
-
346
-		$invoice->set_props( $props );
347
-
348
-	}
349
-
350
-	/**
351
-	 * Gets a list of special fields that need updated based on change state
352
-	 * or if they are present in the database or not.
353
-	 *
354
-	 * @param  WPInv_Invoice $invoice       The Invoice object.
355
-	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
356
-	 */
357
-	protected function get_special_fields_to_update( $invoice ) {
358
-		$fields_to_update = array();
359
-		$changed_props   = $invoice->get_changes();
360
-
361
-		// Props should be updated if they are a part of the $changed array or don't exist yet.
362
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
363
-			if ( array_key_exists( $prop, $changed_props ) ) {
364
-				$fields_to_update[ $database_field ] = $prop;
365
-			}
366
-		}
367
-
368
-		return $fields_to_update;
369
-	}
370
-
371
-	/**
372
-	 * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
373
-	 *
374
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
375
-	 * @since 1.0.19
376
-	 */
377
-	protected function update_special_fields( &$invoice ) {
378
-		global $wpdb;
379
-
380
-		$updated_props    = array();
381
-		$fields_to_update = $this->get_special_fields_to_update( $invoice );
382
-
383
-		foreach ( $fields_to_update as $database_field => $prop ) {
384
-			$value = $invoice->{"get_$prop"}( 'edit' );
385
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
386
-			$value = is_bool( $value ) ? ( int ) $value : $value;
387
-			$updated_props[ $database_field ] = maybe_serialize( $value );
388
-		}
389
-
390
-		if ( ! empty( $updated_props ) ) {
391
-
392
-			$table = $wpdb->prefix . 'getpaid_invoices';
393
-			$wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
394
-			wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
395
-			do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
396
-
397
-		}
398
-
399
-	}
400
-
401
-	/**
402
-	 * Helper method that inserts special fields to the database.
403
-	 *
404
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
405
-	 * @since 1.0.19
406
-	 */
407
-	protected function insert_special_fields( &$invoice ) {
408
-		global $wpdb;
409
-
410
-		$updated_props   = array();
411
-
412
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
413
-			$value = $invoice->{"get_$prop"}( 'edit' );
414
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
415
-			$value = is_bool( $value ) ? ( int ) $value : $value;
416
-			$updated_props[ $database_field ] = maybe_serialize( $value );
417
-		}
418
-
419
-		$table = $wpdb->prefix . 'getpaid_invoices';
420
-		$wpdb->insert( $table, $updated_props );
421
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
422
-		do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
423
-
424
-	}
425
-
426
-	/**
339
+            if ( $db_field == 'post_id' ) {
340
+                continue;
341
+            }
342
+
343
+            $props[ $prop ] = $data[ $db_field ];
344
+        }
345
+
346
+        $invoice->set_props( $props );
347
+
348
+    }
349
+
350
+    /**
351
+     * Gets a list of special fields that need updated based on change state
352
+     * or if they are present in the database or not.
353
+     *
354
+     * @param  WPInv_Invoice $invoice       The Invoice object.
355
+     * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
356
+     */
357
+    protected function get_special_fields_to_update( $invoice ) {
358
+        $fields_to_update = array();
359
+        $changed_props   = $invoice->get_changes();
360
+
361
+        // Props should be updated if they are a part of the $changed array or don't exist yet.
362
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
363
+            if ( array_key_exists( $prop, $changed_props ) ) {
364
+                $fields_to_update[ $database_field ] = $prop;
365
+            }
366
+        }
367
+
368
+        return $fields_to_update;
369
+    }
370
+
371
+    /**
372
+     * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
373
+     *
374
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
375
+     * @since 1.0.19
376
+     */
377
+    protected function update_special_fields( &$invoice ) {
378
+        global $wpdb;
379
+
380
+        $updated_props    = array();
381
+        $fields_to_update = $this->get_special_fields_to_update( $invoice );
382
+
383
+        foreach ( $fields_to_update as $database_field => $prop ) {
384
+            $value = $invoice->{"get_$prop"}( 'edit' );
385
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
386
+            $value = is_bool( $value ) ? ( int ) $value : $value;
387
+            $updated_props[ $database_field ] = maybe_serialize( $value );
388
+        }
389
+
390
+        if ( ! empty( $updated_props ) ) {
391
+
392
+            $table = $wpdb->prefix . 'getpaid_invoices';
393
+            $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
394
+            wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
395
+            do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
396
+
397
+        }
398
+
399
+    }
400
+
401
+    /**
402
+     * Helper method that inserts special fields to the database.
403
+     *
404
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
405
+     * @since 1.0.19
406
+     */
407
+    protected function insert_special_fields( &$invoice ) {
408
+        global $wpdb;
409
+
410
+        $updated_props   = array();
411
+
412
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
413
+            $value = $invoice->{"get_$prop"}( 'edit' );
414
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
415
+            $value = is_bool( $value ) ? ( int ) $value : $value;
416
+            $updated_props[ $database_field ] = maybe_serialize( $value );
417
+        }
418
+
419
+        $table = $wpdb->prefix . 'getpaid_invoices';
420
+        $wpdb->insert( $table, $updated_props );
421
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
422
+        do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
423
+
424
+    }
425
+
426
+    /**
427 427
      * Saves all special fields.
428
-	 *
429
-	 * @param WPInv_Invoice $invoice Invoice object.
428
+     *
429
+     * @param WPInv_Invoice $invoice Invoice object.
430 430
      */
431 431
     public function save_special_fields( & $invoice ) {
432
-		global $wpdb;
432
+        global $wpdb;
433 433
 
434
-		// The invoices table.
435
-		$table = $wpdb->prefix . 'getpaid_invoices';
436
-		$id    = (int) $invoice->get_id();
437
-		$invoice->maybe_set_key();
434
+        // The invoices table.
435
+        $table = $wpdb->prefix . 'getpaid_invoices';
436
+        $id    = (int) $invoice->get_id();
437
+        $invoice->maybe_set_key();
438 438
 
439
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
439
+        if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
440 440
 
441
-			$this->update_special_fields( $invoice );
441
+            $this->update_special_fields( $invoice );
442 442
 
443
-		} else {
443
+        } else {
444 444
 
445
-			$this->insert_special_fields( $invoice );
445
+            $this->insert_special_fields( $invoice );
446 446
 
447
-		}
447
+        }
448 448
 
449
-	}
449
+    }
450 450
 
451
-	/**
451
+    /**
452 452
      * Set's up cart details.
453
-	 *
454
-	 * @param WPInv_Invoice $invoice Invoice object.
453
+     *
454
+     * @param WPInv_Invoice $invoice Invoice object.
455 455
      */
456 456
     public function add_items( &$invoice ) {
457
-		global $wpdb;
457
+        global $wpdb;
458 458
 
459
-		// Maybe retrieve from the cache.
460
-		$items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
459
+        // Maybe retrieve from the cache.
460
+        $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
461 461
 
462
-		// If not found, retrieve from the db.
463
-		if ( false === $items ) {
464
-			$table =  $wpdb->prefix . 'getpaid_invoice_items';
462
+        // If not found, retrieve from the db.
463
+        if ( false === $items ) {
464
+            $table =  $wpdb->prefix . 'getpaid_invoice_items';
465 465
 
466
-			$items = $wpdb->get_results(
467
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
468
-			);
466
+            $items = $wpdb->get_results(
467
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
468
+            );
469 469
 
470
-			// Update the cache with our data
471
-			wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
470
+            // Update the cache with our data
471
+            wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
472 472
 
473
-		}
473
+        }
474 474
 
475
-		// Abort if no items found.
475
+        // Abort if no items found.
476 476
         if ( empty( $items ) ) {
477 477
             return;
478
-		}
479
-
480
-		$_items = array();
481
-		foreach ( $items as $item_data ) {
482
-			$item = new GetPaid_Form_Item( $item_data->item_id );
483
-
484
-			// Set item data.
485
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
486
-			$item->item_discount = wpinv_sanitize_amount( $item_data->discount );
487
-			$item->set_name( $item_data->item_name );
488
-			$item->set_description( $item_data->item_description );
489
-			$item->set_price( $item_data->item_price );
490
-			$item->set_quantity( $item_data->quantity );
491
-			$item->set_item_meta( $item_data->meta );
492
-			$_items[] = $item;
493
-		}
494
-
495
-		$invoice->set_items( $_items );
496
-	}
497
-
498
-	/**
478
+        }
479
+
480
+        $_items = array();
481
+        foreach ( $items as $item_data ) {
482
+            $item = new GetPaid_Form_Item( $item_data->item_id );
483
+
484
+            // Set item data.
485
+            $item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
486
+            $item->item_discount = wpinv_sanitize_amount( $item_data->discount );
487
+            $item->set_name( $item_data->item_name );
488
+            $item->set_description( $item_data->item_description );
489
+            $item->set_price( $item_data->item_price );
490
+            $item->set_quantity( $item_data->quantity );
491
+            $item->set_item_meta( $item_data->meta );
492
+            $_items[] = $item;
493
+        }
494
+
495
+        $invoice->set_items( $_items );
496
+    }
497
+
498
+    /**
499 499
      * Saves cart details.
500
-	 *
501
-	 * @param WPInv_Invoice $invoice Invoice object.
500
+     *
501
+     * @param WPInv_Invoice $invoice Invoice object.
502 502
      */
503 503
     public function save_items( $invoice ) {
504 504
 
505
-		// Delete previously existing items.
506
-		$this->delete_items( $invoice );
505
+        // Delete previously existing items.
506
+        $this->delete_items( $invoice );
507 507
 
508
-		$table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
508
+        $table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
509 509
 
510
-		foreach ( $invoice->get_cart_details() as $item_data ) {
511
-			$item_data = array_map( 'maybe_serialize', $item_data );
512
-			$GLOBALS['wpdb']->insert( $table, $item_data );
513
-		}
510
+        foreach ( $invoice->get_cart_details() as $item_data ) {
511
+            $item_data = array_map( 'maybe_serialize', $item_data );
512
+            $GLOBALS['wpdb']->insert( $table, $item_data );
513
+        }
514 514
 
515
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
516
-		do_action( "getpaid_invoice_save_items", $invoice );
515
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
516
+        do_action( "getpaid_invoice_save_items", $invoice );
517 517
 
518
-	}
518
+    }
519 519
 
520
-	/**
520
+    /**
521 521
      * Deletes an invoice's cart details from the database.
522
-	 *
523
-	 * @param WPInv_Invoice $invoice Invoice object.
522
+     *
523
+     * @param WPInv_Invoice $invoice Invoice object.
524 524
      */
525 525
     public function delete_items( $invoice ) {
526
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
527
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
528
-	}
526
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
527
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
528
+    }
529 529
 
530
-	/**
530
+    /**
531 531
      * Deletes an invoice's special fields from the database.
532
-	 *
533
-	 * @param WPInv_Invoice $invoice Invoice object.
532
+     *
533
+     * @param WPInv_Invoice $invoice Invoice object.
534 534
      */
535 535
     public function delete_special_fields( $invoice ) {
536
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
537
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
538
-	}
536
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
537
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
538
+    }
539 539
 	
540
-	/**
541
-	 * Get the status to save to the post object.
542
-	 *
543
-	 *
544
-	 * @since 1.0.19
545
-	 * @param  WPInv_Invoice $object GetPaid_Data object.
546
-	 * @return string
547
-	 */
548
-	protected function get_post_status( $object ) {
549
-		$object_status = $object->get_status( 'edit' );
550
-
551
-		if ( ! $object_status ) {
552
-			$object_status = $object->get_default_status();
553
-		}
554
-
555
-		return $object_status;
556
-	}
540
+    /**
541
+     * Get the status to save to the post object.
542
+     *
543
+     *
544
+     * @since 1.0.19
545
+     * @param  WPInv_Invoice $object GetPaid_Data object.
546
+     * @return string
547
+     */
548
+    protected function get_post_status( $object ) {
549
+        $object_status = $object->get_status( 'edit' );
550
+
551
+        if ( ! $object_status ) {
552
+            $object_status = $object->get_default_status();
553
+        }
554
+
555
+        return $object_status;
556
+    }
557 557
 
558 558
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 1 patch
Indentation   +301 added lines, -301 removed lines patch added patch discarded remove patch
@@ -12,184 +12,184 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Checkout {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Payment_Form_Submission
17
-	 */
18
-	protected $payment_form_submission;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 * 
23
-	 * @param GetPaid_Payment_Form_Submission $submission
24
-	 */
25
-	public function __construct( $submission ) {
26
-		$this->payment_form_submission = $submission;
27
-	}
28
-
29
-	/**
30
-	 * Processes the checkout.
31
-	 *
32
-	 */
33
-	public function process_checkout() {
34
-
35
-		// Validate the submission.
36
-		$this->validate_submission();
37
-
38
-		// Prepare the invoice.
39
-		$items      = $this->get_submission_items();
40
-		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving();
43
-
44
-		$this->prepare_billing_info( $invoice );
45
-
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
47
-
48
-		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
50
-		$invoice->recalculate_total();
15
+    /**
16
+     * @var GetPaid_Payment_Form_Submission
17
+     */
18
+    protected $payment_form_submission;
19
+
20
+    /**
21
+     * Class constructor.
22
+     * 
23
+     * @param GetPaid_Payment_Form_Submission $submission
24
+     */
25
+    public function __construct( $submission ) {
26
+        $this->payment_form_submission = $submission;
27
+    }
28
+
29
+    /**
30
+     * Processes the checkout.
31
+     *
32
+     */
33
+    public function process_checkout() {
34
+
35
+        // Validate the submission.
36
+        $this->validate_submission();
37
+
38
+        // Prepare the invoice.
39
+        $items      = $this->get_submission_items();
40
+        $invoice    = $this->get_submission_invoice();
41
+        $invoice    = $this->process_submission_invoice( $invoice, $items );
42
+        $prepared   = $this->prepare_submission_data_for_saving();
43
+
44
+        $this->prepare_billing_info( $invoice );
45
+
46
+        $shipping   = $this->prepare_shipping_info( $invoice );
47
+
48
+        // Save the invoice.
49
+        $invoice->set_is_viewed( true );
50
+        $invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+        do_action( 'getpaid_checkout_invoice_updated', $invoice );
54 54
 
55
-		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
57
-	}
55
+        // Send to the gateway.
56
+        $this->post_process_submission( $invoice, $prepared, $shipping );
57
+    }
58 58
 
59
-	/**
60
-	 * Validates the submission.
61
-	 *
62
-	 */
63
-	protected function validate_submission() {
59
+    /**
60
+     * Validates the submission.
61
+     *
62
+     */
63
+    protected function validate_submission() {
64 64
 
65
-		$submission = $this->payment_form_submission;
66
-		$data       = $submission->get_data();
65
+        $submission = $this->payment_form_submission;
66
+        $data       = $submission->get_data();
67 67
 
68
-		// Do we have an error?
68
+        // Do we have an error?
69 69
         if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
70
+            wp_send_json_error( $submission->last_error );
71 71
         }
72 72
 
73
-		// We need a billing email.
73
+        // We need a billing email.
74 74
         if ( ! $submission->has_billing_email() ) {
75 75
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
76
-		}
76
+        }
77 77
 
78
-		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
-		}
78
+        // Non-recurring gateways should not be allowed to process recurring invoices.
79
+        if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
+        }
82 82
 
83
-		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
86
-		}
83
+        // Ensure the gateway is active.
84
+        if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
+            wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
86
+        }
87 87
 
88
-		// Clear any existing errors.
89
-		wpinv_clear_errors();
88
+        // Clear any existing errors.
89
+        wpinv_clear_errors();
90 90
 
91
-		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
91
+        // Allow themes and plugins to hook to errors
92
+        do_action( 'getpaid_checkout_error_checks', $submission );
93 93
 
94
-		// Do we have any errors?
94
+        // Do we have any errors?
95 95
         if ( wpinv_get_errors() ) {
96 96
             wp_send_json_error( getpaid_get_errors_html() );
97
-		}
97
+        }
98 98
 
99
-	}
99
+    }
100 100
 
101
-	/**
102
-	 * Retrieves submission items.
103
-	 *
104
-	 * @return GetPaid_Form_Item[]
105
-	 */
106
-	protected function get_submission_items() {
101
+    /**
102
+     * Retrieves submission items.
103
+     *
104
+     * @return GetPaid_Form_Item[]
105
+     */
106
+    protected function get_submission_items() {
107 107
 
108
-		$items = $this->payment_form_submission->get_items();
108
+        $items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111 111
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112 112
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
113
-		}
114
-
115
-		return $items;
116
-	}
117
-
118
-	/**
119
-	 * Retrieves submission invoice.
120
-	 *
121
-	 * @return WPInv_Invoice
122
-	 */
123
-	protected function get_submission_invoice() {
124
-		$submission = $this->payment_form_submission;
125
-
126
-		if ( ! $submission->has_invoice() ) {
127
-			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
129
-			return $invoice;
130 113
         }
131 114
 
132
-		$invoice = $submission->get_invoice();
115
+        return $items;
116
+    }
117
+
118
+    /**
119
+     * Retrieves submission invoice.
120
+     *
121
+     * @return WPInv_Invoice
122
+     */
123
+    protected function get_submission_invoice() {
124
+        $submission = $this->payment_form_submission;
125
+
126
+        if ( ! $submission->has_invoice() ) {
127
+            $invoice = new WPInv_Invoice();
128
+            $invoice->set_created_via( 'payment_form' );
129
+            return $invoice;
130
+        }
131
+
132
+        $invoice = $submission->get_invoice();
133 133
 
134
-		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
-		}
134
+        // Make sure that it is neither paid or refunded.
135
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
+        }
138 138
 
139
-		return $invoice;
140
-	}
139
+        return $invoice;
140
+    }
141 141
 
142
-	/**
143
-	 * Processes the submission invoice.
144
-	 *
145
-	 * @param WPInv_Invoice $invoice
146
-	 * @param GetPaid_Form_Item[] $items
147
-	 * @return WPInv_Invoice
148
-	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
142
+    /**
143
+     * Processes the submission invoice.
144
+     *
145
+     * @param WPInv_Invoice $invoice
146
+     * @param GetPaid_Form_Item[] $items
147
+     * @return WPInv_Invoice
148
+     */
149
+    protected function process_submission_invoice( $invoice, $items ) {
150 150
 
151
-		$submission = $this->payment_form_submission;
151
+        $submission = $this->payment_form_submission;
152 152
 
153
-		// Set-up the invoice details.
154
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
-		$invoice->set_user_id( $this->get_submission_customer() );
156
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
153
+        // Set-up the invoice details.
154
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
+        $invoice->set_user_id( $this->get_submission_customer() );
156
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
157 157
         $invoice->set_items( $items );
158 158
         $invoice->set_fees( $submission->get_fees() );
159 159
         $invoice->set_taxes( $submission->get_taxes() );
160
-		$invoice->set_discounts( $submission->get_discounts() );
161
-		$invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
-		$invoice->set_currency( $submission->get_currency() );
160
+        $invoice->set_discounts( $submission->get_discounts() );
161
+        $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
+        $invoice->set_currency( $submission->get_currency() );
163 163
 
164
-		if ( $submission->has_shipping() ) {
165
-			$invoice->set_shipping( $submission->get_shipping() );
166
-		}
164
+        if ( $submission->has_shipping() ) {
165
+            $invoice->set_shipping( $submission->get_shipping() );
166
+        }
167 167
 
168
-		$address_confirmed = $submission->get_field( 'confirm-address' );
169
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
168
+        $address_confirmed = $submission->get_field( 'confirm-address' );
169
+        $invoice->set_address_confirmed( ! empty( $address_confirmed ) );
170 170
 
171
-		if ( $submission->has_discount_code() ) {
171
+        if ( $submission->has_discount_code() ) {
172 172
             $invoice->set_discount_code( $submission->get_discount_code() );
173
-		}
174
-
175
-		getpaid_maybe_add_default_address( $invoice );
176
-		return $invoice;
177
-	}
178
-
179
-	/**
180
-	 * Retrieves the submission's customer.
181
-	 *
182
-	 * @return int The customer id.
183
-	 */
184
-	protected function get_submission_customer() {
185
-		$submission = $this->payment_form_submission;
186
-
187
-		// If this is an existing invoice...
188
-		if ( $submission->has_invoice() ) {
189
-			return $submission->get_invoice()->get_user_id();
190
-		}
191
-
192
-		// (Maybe) create the user.
173
+        }
174
+
175
+        getpaid_maybe_add_default_address( $invoice );
176
+        return $invoice;
177
+    }
178
+
179
+    /**
180
+     * Retrieves the submission's customer.
181
+     *
182
+     * @return int The customer id.
183
+     */
184
+    protected function get_submission_customer() {
185
+        $submission = $this->payment_form_submission;
186
+
187
+        // If this is an existing invoice...
188
+        if ( $submission->has_invoice() ) {
189
+            return $submission->get_invoice()->get_user_id();
190
+        }
191
+
192
+        // (Maybe) create the user.
193 193
         $user = get_current_user_id();
194 194
 
195 195
         if ( empty( $user ) ) {
@@ -199,11 +199,11 @@  discard block
 block discarded – undo
199 199
         if ( empty( $user ) ) {
200 200
             $user = wpinv_create_user( $submission->get_billing_email() );
201 201
 
202
-			// (Maybe) send new user notification.
203
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
204
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
205
-				wp_send_new_user_notifications( $user, 'user' );
206
-			}
202
+            // (Maybe) send new user notification.
203
+            $should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
204
+            if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
205
+                wp_send_new_user_notifications( $user, 'user' );
206
+            }
207 207
 
208 208
         }
209 209
 
@@ -213,49 +213,49 @@  discard block
 block discarded – undo
213 213
 
214 214
         if ( is_numeric( $user ) ) {
215 215
             return $user;
216
-		}
216
+        }
217 217
 
218
-		return $user->ID;
218
+        return $user->ID;
219 219
 
220
-	}
220
+    }
221 221
 
222
-	/**
222
+    /**
223 223
      * Prepares submission data for saving to the database.
224 224
      *
225
-	 * @return array
225
+     * @return array
226 226
      */
227 227
     public function prepare_submission_data_for_saving() {
228 228
 
229
-		$submission = $this->payment_form_submission;
229
+        $submission = $this->payment_form_submission;
230 230
 
231
-		// Prepared submission details.
231
+        // Prepared submission details.
232 232
         $prepared = array(
233
-			'all'  => array(),
234
-			'meta' => array(),
235
-		);
233
+            'all'  => array(),
234
+            'meta' => array(),
235
+        );
236 236
 
237 237
         // Raw submission details.
238
-		$data     = $submission->get_data();
238
+        $data     = $submission->get_data();
239 239
 
240
-		// Loop through the submitted details.
240
+        // Loop through the submitted details.
241 241
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
242 242
 
243
-			// Skip premade fields.
243
+            // Skip premade fields.
244 244
             if ( ! empty( $field['premade'] ) ) {
245 245
                 continue;
246 246
             }
247 247
 
248
-			// Ensure address is provided.
249
-			if ( $field['type'] == 'address' ) {
248
+            // Ensure address is provided.
249
+            if ( $field['type'] == 'address' ) {
250 250
                 $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
251 251
 
252
-				foreach ( $field['fields'] as $address_field ) {
252
+                foreach ( $field['fields'] as $address_field ) {
253 253
 
254
-					if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) {
255
-						wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
256
-					}
254
+                    if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) {
255
+                        wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
256
+                    }
257 257
 
258
-				}
258
+                }
259 259
 
260 260
             }
261 261
 
@@ -267,31 +267,31 @@  discard block
 block discarded – undo
267 267
             // Handle misc fields.
268 268
             if ( isset( $data[ $field['id'] ] ) ) {
269 269
 
270
-				// Uploads.
271
-				if ( $field['type'] == 'file_upload' ) {
272
-					$max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
270
+                // Uploads.
271
+                if ( $field['type'] == 'file_upload' ) {
272
+                    $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
273 273
 
274
-					if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
275
-						wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
276
-					}
274
+                    if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
275
+                        wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
276
+                    }
277 277
 
278
-					$value = array();
278
+                    $value = array();
279 279
 
280
-					foreach ( $data[ $field['id'] ] as $url => $name ) {
281
-						$value[] = sprintf(
282
-							'<a href="%s" target="_blank">%s</a>',
283
-							esc_url_raw( $url ),
284
-							esc_html( $name )
285
-						);
286
-					}
280
+                    foreach ( $data[ $field['id'] ] as $url => $name ) {
281
+                        $value[] = sprintf(
282
+                            '<a href="%s" target="_blank">%s</a>',
283
+                            esc_url_raw( $url ),
284
+                            esc_html( $name )
285
+                        );
286
+                    }
287 287
 
288
-					$value = implode( ' | ', $value );
288
+                    $value = implode( ' | ', $value );
289 289
 
290
-				} else if ( $field['type'] == 'checkbox' ) {
291
-					$value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
292
-				} else {
293
-					$value = wp_kses_post( $data[ $field['id'] ] );
294
-				}
290
+                } else if ( $field['type'] == 'checkbox' ) {
291
+                    $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
292
+                } else {
293
+                    $value = wp_kses_post( $data[ $field['id'] ] );
294
+                }
295 295
 
296 296
                 $label = $field['id'];
297 297
 
@@ -299,190 +299,190 @@  discard block
 block discarded – undo
299 299
                     $label = $field['label'];
300 300
                 }
301 301
 
302
-				if ( ! empty( $field['add_meta'] ) ) {
303
-					$prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
304
-				}
305
-				$prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
302
+                if ( ! empty( $field['add_meta'] ) ) {
303
+                    $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
304
+                }
305
+                $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
306 306
 
307 307
             }
308 308
 
309
-		}
309
+        }
310 310
 
311
-		return $prepared;
311
+        return $prepared;
312 312
 
313
-	}
313
+    }
314 314
 
315
-	/**
315
+    /**
316 316
      * Retrieves address details.
317 317
      *
318
-	 * @return array
319
-	 * @param WPInv_Invoice $invoice
320
-	 * @param string $type
318
+     * @return array
319
+     * @param WPInv_Invoice $invoice
320
+     * @param string $type
321 321
      */
322 322
     public function prepare_address_details( $invoice, $type = 'billing' ) {
323 323
 
324
-		$data     = $this->payment_form_submission->get_data();
325
-		$type     = sanitize_key( $type );
326
-		$address  = array();
327
-		$prepared = array();
324
+        $data     = $this->payment_form_submission->get_data();
325
+        $type     = sanitize_key( $type );
326
+        $address  = array();
327
+        $prepared = array();
328 328
 
329
-		if ( ! empty( $data[ $type ] ) ) {
330
-			$address = $data[ $type ];
331
-		}
329
+        if ( ! empty( $data[ $type ] ) ) {
330
+            $address = $data[ $type ];
331
+        }
332 332
 
333
-		// Clean address details.
334
-		foreach ( $address as $key => $value ) {
335
-			$key             = sanitize_key( $key );
336
-			$key             = str_replace( 'wpinv_', '', $key );
337
-			$value           = wpinv_clean( $value );
338
-			$prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
339
-		}
333
+        // Clean address details.
334
+        foreach ( $address as $key => $value ) {
335
+            $key             = sanitize_key( $key );
336
+            $key             = str_replace( 'wpinv_', '', $key );
337
+            $value           = wpinv_clean( $value );
338
+            $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
339
+        }
340 340
 
341
-		// Filter address details.
342
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
341
+        // Filter address details.
342
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
343 343
 
344
-		// Remove non-whitelisted values.
345
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
344
+        // Remove non-whitelisted values.
345
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
346 346
 
347
-	}
347
+    }
348 348
 
349
-	/**
349
+    /**
350 350
      * Prepares the billing details.
351 351
      *
352
-	 * @return array
353
-	 * @param WPInv_Invoice $invoice
352
+     * @return array
353
+     * @param WPInv_Invoice $invoice
354 354
      */
355 355
     protected function prepare_billing_info( &$invoice ) {
356 356
 
357
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
357
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
358 358
 
359
-		// Update the invoice with the billing details.
360
-		$invoice->set_props( $billing_address );
359
+        // Update the invoice with the billing details.
360
+        $invoice->set_props( $billing_address );
361 361
 
362
-	}
362
+    }
363 363
 
364
-	/**
364
+    /**
365 365
      * Prepares the shipping details.
366 366
      *
367
-	 * @return array
368
-	 * @param WPInv_Invoice $invoice
367
+     * @return array
368
+     * @param WPInv_Invoice $invoice
369 369
      */
370 370
     protected function prepare_shipping_info( $invoice ) {
371 371
 
372
-		$data = $this->payment_form_submission->get_data();
372
+        $data = $this->payment_form_submission->get_data();
373 373
 
374
-		if ( empty( $data['same-shipping-address'] ) ) {
375
-			return $this->prepare_address_details( $invoice, 'shipping' );
376
-		}
374
+        if ( empty( $data['same-shipping-address'] ) ) {
375
+            return $this->prepare_address_details( $invoice, 'shipping' );
376
+        }
377 377
 
378
-		return $this->prepare_address_details( $invoice, 'billing' );
378
+        return $this->prepare_address_details( $invoice, 'billing' );
379 379
 
380
-	}
380
+    }
381 381
 
382
-	/**
383
-	 * Confirms the submission is valid and send users to the gateway.
384
-	 *
385
-	 * @param WPInv_Invoice $invoice
386
-	 * @param array $prepared_payment_form_data
387
-	 * @param array $shipping
388
-	 */
389
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
382
+    /**
383
+     * Confirms the submission is valid and send users to the gateway.
384
+     *
385
+     * @param WPInv_Invoice $invoice
386
+     * @param array $prepared_payment_form_data
387
+     * @param array $shipping
388
+     */
389
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
390 390
 
391
-		// Ensure the invoice exists.
391
+        // Ensure the invoice exists.
392 392
         if ( ! $invoice->exists() ) {
393 393
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
394 394
         }
395 395
 
396
-		// Save payment form data.
397
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
396
+        // Save payment form data.
397
+        $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
398 398
         delete_post_meta( $invoice->get_id(), 'payment_form_data' );
399
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
400
-		if ( ! empty( $prepared_payment_form_data ) ) {
399
+        delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
400
+        if ( ! empty( $prepared_payment_form_data ) ) {
401 401
 
402
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
403
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
404
-			}
402
+            if ( ! empty( $prepared_payment_form_data['all'] ) ) {
403
+                update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
404
+            }
405 405
 
406
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
407
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
408
-			}
406
+            if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
407
+                update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
408
+            }
409 409
 
410
-		}
410
+        }
411 411
 
412
-		// Save payment form data.
413
-		$shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
412
+        // Save payment form data.
413
+        $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
414 414
         if ( ! empty( $shipping ) ) {
415 415
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
416
-		}
416
+        }
417 417
 
418
-		// Backwards compatibility.
418
+        // Backwards compatibility.
419 419
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
420 420
 
421
-		$this->process_payment( $invoice );
421
+        $this->process_payment( $invoice );
422 422
 
423 423
         // If we are here, there was an error.
424
-		wpinv_send_back_to_checkout( $invoice );
424
+        wpinv_send_back_to_checkout( $invoice );
425 425
 
426
-	}
426
+    }
427 427
 
428
-	/**
429
-	 * Processes the actual payment.
430
-	 *
431
-	 * @param WPInv_Invoice $invoice
432
-	 */
433
-	protected function process_payment( $invoice ) {
428
+    /**
429
+     * Processes the actual payment.
430
+     *
431
+     * @param WPInv_Invoice $invoice
432
+     */
433
+    protected function process_payment( $invoice ) {
434 434
 
435
-		// Clear any checkout errors.
436
-		wpinv_clear_errors();
435
+        // Clear any checkout errors.
436
+        wpinv_clear_errors();
437 437
 
438
-		// No need to send free invoices to the gateway.
439
-		if ( $invoice->is_free() ) {
440
-			$this->process_free_payment( $invoice );
441
-		}
438
+        // No need to send free invoices to the gateway.
439
+        if ( $invoice->is_free() ) {
440
+            $this->process_free_payment( $invoice );
441
+        }
442 442
 
443
-		$submission = $this->payment_form_submission;
443
+        $submission = $this->payment_form_submission;
444 444
 
445
-		// Fires before sending to the gateway.
446
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
445
+        // Fires before sending to the gateway.
446
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
447 447
 
448
-		// Allow the sumission data to be modified before it is sent to the gateway.
449
-		$submission_data    = $submission->get_data();
450
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
451
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
448
+        // Allow the sumission data to be modified before it is sent to the gateway.
449
+        $submission_data    = $submission->get_data();
450
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
451
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
452 452
 
453
-		// Validate the currency.
454
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
455
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
456
-		}
453
+        // Validate the currency.
454
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
455
+            wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
456
+        }
457 457
 
458
-		// Check to see if we have any errors.
459
-		if ( wpinv_get_errors() ) {
460
-			wpinv_send_back_to_checkout( $invoice );
461
-		}
458
+        // Check to see if we have any errors.
459
+        if ( wpinv_get_errors() ) {
460
+            wpinv_send_back_to_checkout( $invoice );
461
+        }
462 462
 
463
-		// Send info to the gateway for payment processing
464
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
463
+        // Send info to the gateway for payment processing
464
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
465 465
 
466
-		// Backwards compatibility.
467
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
466
+        // Backwards compatibility.
467
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
468 468
 
469
-	}
469
+    }
470 470
 
471
-	/**
472
-	 * Marks the invoice as paid in case the checkout is free.
473
-	 *
474
-	 * @param WPInv_Invoice $invoice
475
-	 */
476
-	protected function process_free_payment( $invoice ) {
471
+    /**
472
+     * Marks the invoice as paid in case the checkout is free.
473
+     *
474
+     * @param WPInv_Invoice $invoice
475
+     */
476
+    protected function process_free_payment( $invoice ) {
477 477
 
478
-		$invoice->set_gateway( 'none' );
479
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
480
-		$invoice->mark_paid();
481
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
478
+        $invoice->set_gateway( 'none' );
479
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
480
+        $invoice->mark_paid();
481
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
482 482
 
483
-	}
483
+    }
484 484
 
485
-	/**
485
+    /**
486 486
      * Sends a redrect response to payment details.
487 487
      *
488 488
      */
Please login to merge, or discard this patch.