Passed
Push — master ( bcec86...578d12 )
by Brian
10:46
created
includes/admin/meta-boxes/class-getpaid-meta-box-payment-form.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 if ( ! defined( 'ABSPATH' ) ) {
10
-	exit; // Exit if accessed directly
10
+    exit; // Exit if accessed directly
11 11
 }
12 12
 
13 13
 /**
@@ -16,10 +16,10 @@  discard block
 block discarded – undo
16 16
 class GetPaid_Meta_Box_Payment_Form {
17 17
 
18 18
     /**
19
-	 * Output the metabox.
20
-	 *
21
-	 * @param WP_Post $post
22
-	 */
19
+     * Output the metabox.
20
+     *
21
+     * @param WP_Post $post
22
+     */
23 23
     public static function output( $post ) {
24 24
         ?>
25 25
         <div id="wpinv-form-builder" class="bsui">
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
     }
87 87
 
88 88
     /**
89
-	 * Save meta box data.
90
-	 *
91
-	 * @param int $post_id
92
-	 */
93
-	public static function save( $post_id ) {
89
+     * Save meta box data.
90
+     *
91
+     * @param int $post_id
92
+     */
93
+    public static function save( $post_id ) {
94 94
 
95 95
         // Prepare the form.
96 96
         $form = new GetPaid_Payment_Form( $post_id );
@@ -121,11 +121,11 @@  discard block
 block discarded – undo
121 121
     }
122 122
 
123 123
     /**
124
-	 * Converts an array fo form items to objects.
125
-	 *
126
-	 * @param array $items
127
-	 */
128
-	public static function item_to_objects( $items ) {
124
+     * Converts an array fo form items to objects.
125
+     *
126
+     * @param array $items
127
+     */
128
+    public static function item_to_objects( $items ) {
129 129
 
130 130
         $objects = array();
131 131
 
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-discount-details.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 if ( ! defined( 'ABSPATH' ) ) {
11
-	exit; // Exit if accessed directly
11
+    exit; // Exit if accessed directly
12 12
 }
13 13
 
14 14
 /**
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
17 17
 class GetPaid_Meta_Box_Discount_Details {
18 18
 
19 19
     /**
20
-	 * Output the metabox.
21
-	 *
22
-	 * @param WP_Post $post
23
-	 */
20
+     * Output the metabox.
21
+     *
22
+     * @param WP_Post $post
23
+     */
24 24
     public static function output( $post ) {
25 25
 
26 26
         // Prepare the discount.
@@ -368,34 +368,34 @@  discard block
 block discarded – undo
368 368
     }
369 369
 
370 370
     /**
371
-	 * Save meta box data.
372
-	 *
373
-	 * @param int $post_id
374
-	 */
375
-	public static function save( $post_id ) {
371
+     * Save meta box data.
372
+     *
373
+     * @param int $post_id
374
+     */
375
+    public static function save( $post_id ) {
376 376
 
377 377
         // Prepare the discount.
378 378
         $discount = new WPInv_Discount( $post_id );
379 379
 
380 380
         // Load new data.
381 381
         $discount->set_props(
382
-			array(
383
-				'code'                 => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null,
384
-				'amount'               => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null,
385
-				'start'                => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null,
386
-				'expiration'           => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null,
387
-				'is_single_use'        => isset( $_POST['wpinv_discount_single_use'] ),
382
+            array(
383
+                'code'                 => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null,
384
+                'amount'               => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null,
385
+                'start'                => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null,
386
+                'expiration'           => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null,
387
+                'is_single_use'        => isset( $_POST['wpinv_discount_single_use'] ),
388 388
                 'type'                 => isset( $_POST['wpinv_discount_type'] ) ? $_POST['wpinv_discount_type'] : null,
389
-				'is_recurring'         => isset( $_POST['wpinv_discount_recurring'] ),
390
-				'items'                => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(),
391
-				'excluded_items'       => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(),
392
-				'max_uses'             => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null,
393
-				'min_total'            => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null,
394
-				'max_total'            => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null,
395
-			)
389
+                'is_recurring'         => isset( $_POST['wpinv_discount_recurring'] ),
390
+                'items'                => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(),
391
+                'excluded_items'       => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(),
392
+                'max_uses'             => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null,
393
+                'min_total'            => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null,
394
+                'max_total'            => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null,
395
+            )
396 396
         );
397 397
 
398
-		$discount->save();
399
-		do_action( 'getpaid_discount_metabox_save', $post_id, $discount );
400
-	}
398
+        $discount->save();
399
+        do_action( 'getpaid_discount_metabox_save', $post_id, $discount );
400
+    }
401 401
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-fees.php 1 patch
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -12,108 +12,108 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Fees {
14 14
 
15
-	/**
16
-	 * The fee validation error.
17
-	 * @var string
18
-	 */
19
-	public $fee_error;
20
-
21
-	/**
22
-	 * Submission fees.
23
-	 * @var array
24
-	 */
25
-	public $fees = array();
15
+    /**
16
+     * The fee validation error.
17
+     * @var string
18
+     */
19
+    public $fee_error;
20
+
21
+    /**
22
+     * Submission fees.
23
+     * @var array
24
+     */
25
+    public $fees = array();
26
+
27
+    /**
28
+     * Class constructor
29
+     *
30
+     * @param GetPaid_Payment_Form_Submission $submission
31
+     */
32
+    public function __construct( $submission ) {
33
+
34
+        // Process any existing invoice fees.
35
+        if ( $submission->has_invoice() ) {
36
+            $this->fees = $submission->get_invoice()->get_fees();
37
+        }
38
+
39
+        // Process price fields.
40
+        $data         = $submission->get_data();
41
+        $payment_form = $submission->get_payment_form();
42
+
43
+        foreach ( $payment_form->get_elements() as $element ) {
44
+
45
+            if ( 'price_input' == $element['type'] ) {
46
+                $this->process_price_input( $element, $data );
47
+            }
48
+
49
+            if ( 'price_select' == $element['type'] ) {
50
+                $this->process_price_select( $element, $data );
51
+            }
52
+
53
+        }
54
+
55
+    }
56
+
57
+    /**
58
+     * Process a price input field.
59
+     *
60
+     * @param array $element
61
+     * @param array $data
62
+     */
63
+    public function process_price_input( $element, $data ) {
64
+
65
+        // Abort if not passed.
66
+        if ( empty( $data[ $element['id'] ] ) ) {
67
+            return;
68
+        }
69
+
70
+        $amount  = (float) wpinv_sanitize_amount( $data[ $element['id'] ] );
71
+        $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] );
72
+
73
+        if ( $amount < $minimum ) {
74
+            throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), $minimum ) );
75
+        }
76
+
77
+        $this->fees[ $element['label'] ] = array(
78
+            'name'          => $element['label'],
79
+            'initial_fee'   => $amount,
80
+            'recurring_fee' => 0,
81
+        );
82
+
83
+    }
26 84
 
27 85
     /**
28
-	 * Class constructor
29
-	 *
30
-	 * @param GetPaid_Payment_Form_Submission $submission
31
-	 */
32
-	public function __construct( $submission ) {
33
-
34
-		// Process any existing invoice fees.
35
-		if ( $submission->has_invoice() ) {
36
-			$this->fees = $submission->get_invoice()->get_fees();
37
-		}
38
-
39
-		// Process price fields.
40
-		$data         = $submission->get_data();
41
-		$payment_form = $submission->get_payment_form();
42
-
43
-		foreach ( $payment_form->get_elements() as $element ) {
44
-
45
-			if ( 'price_input' == $element['type'] ) {
46
-				$this->process_price_input( $element, $data );
47
-			}
48
-
49
-			if ( 'price_select' == $element['type'] ) {
50
-				$this->process_price_select( $element, $data );
51
-			}
52
-
53
-		}
54
-
55
-	}
56
-
57
-	/**
58
-	 * Process a price input field.
59
-	 *
60
-	 * @param array $element
61
-	 * @param array $data
62
-	 */
63
-	public function process_price_input( $element, $data ) {
64
-
65
-		// Abort if not passed.
66
-		if ( empty( $data[ $element['id'] ] ) ) {
67
-			return;
68
-		}
69
-
70
-		$amount  = (float) wpinv_sanitize_amount( $data[ $element['id'] ] );
71
-		$minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] );
72
-
73
-		if ( $amount < $minimum ) {
74
-			throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), $minimum ) );
75
-		}
76
-
77
-		$this->fees[ $element['label'] ] = array(
78
-			'name'          => $element['label'],
79
-			'initial_fee'   => $amount,
80
-			'recurring_fee' => 0,
81
-		);
82
-
83
-	}
84
-
85
-	/**
86
-	 * Process a price select field.
87
-	 *
88
-	 * @param array $element
89
-	 * @param array $data
90
-	 */
91
-	public function process_price_select( $element, $data ) {
92
-
93
-		// Abort if not passed.
94
-		if ( empty( $data[ $element['id'] ] ) ) {
95
-			return;
96
-		}
97
-
98
-		$options  = getpaid_convert_price_string_to_options( $element['options'] );
99
-		$selected = wpinv_parse_list( $data[ $element['id'] ] );
100
-		$total    = 0;
101
-
102
-		foreach ( $selected as $price ) {
103
-
104
-			if ( ! isset( $options[ $price ] ) ) {
105
-				throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) );
106
-			}
107
-
108
-			$total += (float) wpinv_sanitize_amount( $price );
109
-		}
110
-
111
-		$this->fees[ $element['label'] ] = array(
112
-			'name'          => $element['label'],
113
-			'initial_fee'   => $total,
114
-			'recurring_fee' => 0,
115
-		);
116
-
117
-	}
86
+     * Process a price select field.
87
+     *
88
+     * @param array $element
89
+     * @param array $data
90
+     */
91
+    public function process_price_select( $element, $data ) {
92
+
93
+        // Abort if not passed.
94
+        if ( empty( $data[ $element['id'] ] ) ) {
95
+            return;
96
+        }
97
+
98
+        $options  = getpaid_convert_price_string_to_options( $element['options'] );
99
+        $selected = wpinv_parse_list( $data[ $element['id'] ] );
100
+        $total    = 0;
101
+
102
+        foreach ( $selected as $price ) {
103
+
104
+            if ( ! isset( $options[ $price ] ) ) {
105
+                throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) );
106
+            }
107
+
108
+            $total += (float) wpinv_sanitize_amount( $price );
109
+        }
110
+
111
+        $this->fees[ $element['label'] ] = array(
112
+            'name'          => $element['label'],
113
+            'initial_fee'   => $total,
114
+            'recurring_fee' => 0,
115
+        );
116
+
117
+    }
118 118
 
119 119
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-taxes.php 1 patch
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -12,231 +12,231 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Taxes {
14 14
 
15
-	/**
16
-	 * Submission taxes.
17
-	 * @var array
18
-	 */
19
-	public $taxes = array();
20
-
21
-	/**
22
-	 * Initial tax.
23
-	 * @var float
24
-	 */
25
-	protected $initial_tax = 0;
26
-
27
-	/**
28
-	 * Recurring tax.
29
-	 * @var float
30
-	 */
31
-	protected $recurring_tax = 0;
15
+    /**
16
+     * Submission taxes.
17
+     * @var array
18
+     */
19
+    public $taxes = array();
20
+
21
+    /**
22
+     * Initial tax.
23
+     * @var float
24
+     */
25
+    protected $initial_tax = 0;
26
+
27
+    /**
28
+     * Recurring tax.
29
+     * @var float
30
+     */
31
+    protected $recurring_tax = 0;
32
+
33
+    /**
34
+     * Class constructor
35
+     *
36
+     * @param GetPaid_Payment_Form_Submission $submission
37
+     */
38
+    public function __construct( $submission ) {
39
+
40
+        // Validate VAT number.
41
+        $this->validate_vat( $submission );
42
+
43
+        foreach ( $submission->get_items() as $item ) {
44
+            $this->process_item_tax( $item, $submission );
45
+        }
46
+
47
+        // Process any existing invoice taxes.
48
+        if ( $submission->has_invoice() ) {
49
+            $this->taxes = $submission->get_invoice()->get_taxes();
50
+        }
51
+
52
+        // Add VAT.
53
+        $this->taxes['vat'] = array(
54
+            'name'          => 'vat',
55
+            'initial_tax'   => $this->initial_tax,
56
+            'recurring_tax' => $this->recurring_tax,
57
+        );
58
+
59
+    }
60
+
61
+    /**
62
+     * Maybe process tax.
63
+     *
64
+     * @since 1.0.19
65
+     * @param GetPaid_Form_Item $item
66
+     * @param GetPaid_Payment_Form_Submission $submission
67
+     */
68
+    public function process_item_tax( $item, $submission ) {
69
+
70
+        $rate     = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() );
71
+        $price    = $item->get_sub_total();
72
+        $item_tax = $price * $rate * 0.01;
73
+
74
+        if ( wpinv_prices_include_tax() ) {
75
+            $item_tax = $price - ( $price - $price * $rate * 0.01 );
76
+        }
77
+
78
+        $this->initial_tax += $item_tax;
79
+
80
+        if ( $item->is_recurring() ) {
81
+            $this->recurring_tax += $item_tax;
82
+        }
83
+
84
+    }
85
+
86
+    /**
87
+     * Checks if the submission has a digital item.
88
+     *
89
+     * @param GetPaid_Payment_Form_Submission $submission
90
+     * @since 1.0.19
91
+     * @return bool
92
+     */
93
+    public function has_digital_item( $submission ) {
94
+
95
+        foreach ( $submission->get_items() as $item ) {
96
+
97
+            if ( 'digital' == $item->get_vat_rule() ) {
98
+                return true;
99
+            }
100
+
101
+        }
102
+
103
+        return false;
104
+    }
105
+
106
+    /**
107
+     * Checks if this is an eu store.
108
+     *
109
+     * @since 1.0.19
110
+     * @return bool
111
+     */
112
+    public function is_eu_store() {
113
+        return $this->is_eu_country( wpinv_get_default_country() );
114
+    }
115
+
116
+    /**
117
+     * Checks if this is an eu country.
118
+     *
119
+     * @param string $country
120
+     * @since 1.0.19
121
+     * @return bool
122
+     */
123
+    public function is_eu_country( $country ) {
124
+        return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country );
125
+    }
126
+
127
+    /**
128
+     * Checks if this is an eu purchase.
129
+     *
130
+     * @param string $customer_country
131
+     * @since 1.0.19
132
+     * @return bool
133
+     */
134
+    public function is_eu_transaction( $customer_country ) {
135
+        return $this->is_eu_country( $customer_country ) && $this->is_eu_store();
136
+    }
137
+
138
+    /**
139
+     * Retrieves the vat number.
140
+     *
141
+     * @param GetPaid_Payment_Form_Submission $submission
142
+     * @since 1.0.19
143
+     * @return string
144
+     */
145
+    public function get_vat_number( $submission ) {
146
+
147
+        // Retrieve from the posted number.
148
+        $vat_number = $submission->get_field( 'wpinv_vat_number' );
149
+        if ( ! empty( $vat_number ) ) {
150
+            return wpinv_clean( $vat_number );
151
+        }
152
+
153
+        // Retrieve from the invoice.
154
+        return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
155
+    }
156
+
157
+    /**
158
+     * Retrieves the company.
159
+     *
160
+     * @param GetPaid_Payment_Form_Submission $submission
161
+     * @since 1.0.19
162
+     * @return string
163
+     */
164
+    public function get_company( $submission ) {
165
+
166
+        // Retrieve from the posted data.
167
+        $company = $submission->get_field( 'wpinv_company' );
168
+        if ( ! empty( $company ) ) {
169
+            return wpinv_clean( $company );
170
+        }
171
+
172
+        // Retrieve from the invoice.
173
+        return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
174
+    }
175
+
176
+    /**
177
+     * Checks if we requires a VAT number.
178
+     *
179
+     * @param bool $ip_in_eu Whether the customer IP is from the EU
180
+     * @param bool $country_in_eu Whether the customer country is from the EU
181
+     * @since 1.0.19
182
+     * @return string
183
+     */
184
+    public function requires_vat( $ip_in_eu, $country_in_eu ) {
185
+
186
+        $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
187
+        $prevent_b2c = ! empty( $prevent_b2c );
188
+        $is_eu       = $ip_in_eu || $country_in_eu;
189
+
190
+        return $prevent_b2c && $is_eu;
191
+    }
32 192
 
33 193
     /**
34
-	 * Class constructor
35
-	 *
36
-	 * @param GetPaid_Payment_Form_Submission $submission
37
-	 */
38
-	public function __construct( $submission ) {
39
-
40
-		// Validate VAT number.
41
-		$this->validate_vat( $submission );
42
-
43
-		foreach ( $submission->get_items() as $item ) {
44
-			$this->process_item_tax( $item, $submission );
45
-		}
46
-
47
-		// Process any existing invoice taxes.
48
-		if ( $submission->has_invoice() ) {
49
-			$this->taxes = $submission->get_invoice()->get_taxes();
50
-		}
51
-
52
-		// Add VAT.
53
-		$this->taxes['vat'] = array(
54
-			'name'          => 'vat',
55
-			'initial_tax'   => $this->initial_tax,
56
-			'recurring_tax' => $this->recurring_tax,
57
-		);
58
-
59
-	}
60
-
61
-	/**
62
-	 * Maybe process tax.
63
-	 *
64
-	 * @since 1.0.19
65
-	 * @param GetPaid_Form_Item $item
66
-	 * @param GetPaid_Payment_Form_Submission $submission
67
-	 */
68
-	public function process_item_tax( $item, $submission ) {
69
-
70
-		$rate     = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() );
71
-		$price    = $item->get_sub_total();
72
-		$item_tax = $price * $rate * 0.01;
73
-
74
-		if ( wpinv_prices_include_tax() ) {
75
-			$item_tax = $price - ( $price - $price * $rate * 0.01 );
76
-		}
77
-
78
-		$this->initial_tax += $item_tax;
79
-
80
-		if ( $item->is_recurring() ) {
81
-			$this->recurring_tax += $item_tax;
82
-		}
83
-
84
-	}
85
-
86
-	/**
87
-	 * Checks if the submission has a digital item.
88
-	 *
89
-	 * @param GetPaid_Payment_Form_Submission $submission
90
-	 * @since 1.0.19
91
-	 * @return bool
92
-	 */
93
-	public function has_digital_item( $submission ) {
94
-
95
-		foreach ( $submission->get_items() as $item ) {
96
-
97
-			if ( 'digital' == $item->get_vat_rule() ) {
98
-				return true;
99
-			}
100
-
101
-		}
102
-
103
-		return false;
104
-	}
105
-
106
-	/**
107
-	 * Checks if this is an eu store.
108
-	 *
109
-	 * @since 1.0.19
110
-	 * @return bool
111
-	 */
112
-	public function is_eu_store() {
113
-		return $this->is_eu_country( wpinv_get_default_country() );
114
-	}
115
-
116
-	/**
117
-	 * Checks if this is an eu country.
118
-	 *
119
-	 * @param string $country
120
-	 * @since 1.0.19
121
-	 * @return bool
122
-	 */
123
-	public function is_eu_country( $country ) {
124
-		return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country );
125
-	}
126
-
127
-	/**
128
-	 * Checks if this is an eu purchase.
129
-	 *
130
-	 * @param string $customer_country
131
-	 * @since 1.0.19
132
-	 * @return bool
133
-	 */
134
-	public function is_eu_transaction( $customer_country ) {
135
-		return $this->is_eu_country( $customer_country ) && $this->is_eu_store();
136
-	}
137
-
138
-	/**
139
-	 * Retrieves the vat number.
140
-	 *
141
-	 * @param GetPaid_Payment_Form_Submission $submission
142
-	 * @since 1.0.19
143
-	 * @return string
144
-	 */
145
-	public function get_vat_number( $submission ) {
146
-
147
-		// Retrieve from the posted number.
148
-		$vat_number = $submission->get_field( 'wpinv_vat_number' );
149
-		if ( ! empty( $vat_number ) ) {
150
-			return wpinv_clean( $vat_number );
151
-		}
152
-
153
-		// Retrieve from the invoice.
154
-		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
155
-	}
156
-
157
-	/**
158
-	 * Retrieves the company.
159
-	 *
160
-	 * @param GetPaid_Payment_Form_Submission $submission
161
-	 * @since 1.0.19
162
-	 * @return string
163
-	 */
164
-	public function get_company( $submission ) {
165
-
166
-		// Retrieve from the posted data.
167
-		$company = $submission->get_field( 'wpinv_company' );
168
-		if ( ! empty( $company ) ) {
169
-			return wpinv_clean( $company );
170
-		}
171
-
172
-		// Retrieve from the invoice.
173
-		return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
174
-	}
175
-
176
-	/**
177
-	 * Checks if we requires a VAT number.
178
-	 *
179
-	 * @param bool $ip_in_eu Whether the customer IP is from the EU
180
-	 * @param bool $country_in_eu Whether the customer country is from the EU
181
-	 * @since 1.0.19
182
-	 * @return string
183
-	 */
184
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
185
-
186
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
187
-		$prevent_b2c = ! empty( $prevent_b2c );
188
-		$is_eu       = $ip_in_eu || $country_in_eu;
189
-
190
-		return $prevent_b2c && $is_eu;
191
-	}
192
-
193
-	/**
194
-	 * Validate VAT data.
195
-	 *
196
-	 * @param GetPaid_Payment_Form_Submission $submission
197
-	 * @since 1.0.19
198
-	 */
199
-	public function validate_vat( $submission ) {
200
-
201
-		$has_digital = $this->has_digital_item( $submission );
202
-		$in_eu       = $this->is_eu_transaction( $submission->country );
203
-
204
-		// Abort if we are not validating vat numbers.
205
-		if ( ! $has_digital && ! $in_eu ) {
194
+     * Validate VAT data.
195
+     *
196
+     * @param GetPaid_Payment_Form_Submission $submission
197
+     * @since 1.0.19
198
+     */
199
+    public function validate_vat( $submission ) {
200
+
201
+        $has_digital = $this->has_digital_item( $submission );
202
+        $in_eu       = $this->is_eu_transaction( $submission->country );
203
+
204
+        // Abort if we are not validating vat numbers.
205
+        if ( ! $has_digital && ! $in_eu ) {
206 206
             return;
207
-		}
207
+        }
208 208
 
209
-		// Prepare variables.
210
-		$vat_number  = $this->get_vat_number( $submission );
211
-		$company     = $this->get_company( $submission );
212
-		$ip_country  = WPInv_EUVat::get_country_by_ip();
209
+        // Prepare variables.
210
+        $vat_number  = $this->get_vat_number( $submission );
211
+        $company     = $this->get_company( $submission );
212
+        $ip_country  = WPInv_EUVat::get_country_by_ip();
213 213
         $is_eu       = $this->is_eu_country( $submission->country );
214 214
         $is_ip_eu    = $this->is_eu_country( $ip_country );
215 215
 
216
-		// If we're preventing business to consumer purchases, ensure
217
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
216
+        // If we're preventing business to consumer purchases, ensure
217
+        if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
218 218
 
219
-			// Ensure that a vat number has been specified.
220
-			throw new Exception(
221
-				wp_sprintf(
222
-					__( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ),
223
-					getpaid_vat_name()
224
-				)
225
-			);
219
+            // Ensure that a vat number has been specified.
220
+            throw new Exception(
221
+                wp_sprintf(
222
+                    __( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ),
223
+                    getpaid_vat_name()
224
+                )
225
+            );
226 226
 
227
-		}
227
+        }
228 228
 
229
-		// Abort if we are not validating vat (vat number should exist, user should be in eu and business too).
230
-		if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) {
229
+        // Abort if we are not validating vat (vat number should exist, user should be in eu and business too).
230
+        if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) {
231 231
             return;
232
-		}
232
+        }
233 233
 
234
-		$is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country );
234
+        $is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country );
235 235
 
236
-		if ( is_string( $is_valid ) ) {
237
-			throw new Exception( $is_valid );
238
-		}
236
+        if ( is_string( $is_valid ) ) {
237
+            throw new Exception( $is_valid );
238
+        }
239 239
 
240
-	}
240
+    }
241 241
 
242 242
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 1 patch
Indentation   +736 added lines, -736 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,187 +10,187 @@  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
-	);
54
-
55
-	/**
56
-	 * Sets the associated payment form.
57
-	 *
58
-	 * @var GetPaid_Payment_Form
59
-	 */
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
+    );
54
+
55
+    /**
56
+     * Sets the associated payment form.
57
+     *
58
+     * @var GetPaid_Payment_Form
59
+     */
60 60
     protected $payment_form = null;
61 61
 
62 62
     /**
63
-	 * The country for the submission.
64
-	 *
65
-	 * @var string
66
-	 */
67
-	public $country = null;
68
-
69
-    /**
70
-	 * The state for the submission.
71
-	 *
72
-	 * @since 1.0.19
73
-	 * @var string
74
-	 */
75
-	public $state = null;
76
-
77
-	/**
78
-	 * The invoice associated with the submission.
79
-	 *
80
-	 * @var WPInv_Invoice
81
-	 */
82
-	protected $invoice = null;
83
-
84
-	/**
85
-	 * The recurring item for the submission.
86
-	 *
87
-	 * @var int
88
-	 */
89
-	public $has_recurring = 0;
90
-
91
-	/**
92
-	 * An array of fees for the submission.
93
-	 *
94
-	 * @var array
95
-	 */
96
-	protected $fees = array();
97
-
98
-	/**
99
-	 * An array of discounts for the submission.
100
-	 *
101
-	 * @var array
102
-	 */
103
-	protected $discounts = array();
104
-
105
-	/**
106
-	 * An array of taxes for the submission.
107
-	 *
108
-	 * @var array
109
-	 */
110
-	protected $taxes = array();
111
-
112
-	/**
113
-	 * An array of items for the submission.
114
-	 *
115
-	 * @var GetPaid_Form_Item[]
116
-	 */
117
-	protected $items = array();
118
-
119
-	/**
120
-	 * The last error.
121
-	 *
122
-	 * @var string
123
-	 */
124
-	public $last_error = null;
125
-
126
-    /**
127
-	 * Class constructor.
128
-	 *
129
-	 */
130
-	public function __construct() {
131
-
132
-		// Set the state and country to the default state and country.
133
-		$this->country = wpinv_default_billing_country();
134
-		$this->state   = wpinv_get_default_state();
135
-
136
-		// Do we have an actual submission?
137
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
138
-			$this->load_data( $_POST );
139
-		}
140
-
141
-	}
142
-
143
-	/**
144
-	 * Loads submission data.
145
-	 *
146
-	 * @param array $data
147
-	 */
148
-	public function load_data( $data ) {
149
-
150
-		// Remove slashes from the submitted data...
151
-		$data       = wp_unslash( $data );
152
-
153
-		// Allow plugins to filter the data.
154
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
155
-
156
-		// Cache it...
157
-		$this->data = $data;
158
-
159
-		// Then generate a unique id from the data.
160
-		$this->id   = md5( wp_json_encode( $data ) );
161
-
162
-		// Finally, process the submission.
163
-		try {
164
-
165
-			// Each process is passed an instance of the class (with reference)
166
-			// and should throw an Exception whenever it encounters one.
167
-			$processors = apply_filters(
168
-				'getpaid_payment_form_submission_processors',
169
-				array(
170
-					array( $this, 'process_payment_form' ),
171
-					array( $this, 'process_invoice' ),
172
-					array( $this, 'process_fees' ),
173
-					array( $this, 'process_items' ),
174
-					array( $this, 'process_taxes' ),
175
-					array( $this, 'process_discount' ),
176
-				),
177
-				$this		
178
-			);
179
-
180
-			foreach ( $processors as $processor ) {
181
-				call_user_func_array( $processor, array( &$this ) );
182
-			}
183
-
184
-		} catch ( Exception $e ) {
185
-			$this->last_error = $e->getMessage();
186
-		}
187
-
188
-		// Fired when we are done processing a submission.
189
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
190
-
191
-	}
192
-
193
-	/*
63
+     * The country for the submission.
64
+     *
65
+     * @var string
66
+     */
67
+    public $country = null;
68
+
69
+    /**
70
+     * The state for the submission.
71
+     *
72
+     * @since 1.0.19
73
+     * @var string
74
+     */
75
+    public $state = null;
76
+
77
+    /**
78
+     * The invoice associated with the submission.
79
+     *
80
+     * @var WPInv_Invoice
81
+     */
82
+    protected $invoice = null;
83
+
84
+    /**
85
+     * The recurring item for the submission.
86
+     *
87
+     * @var int
88
+     */
89
+    public $has_recurring = 0;
90
+
91
+    /**
92
+     * An array of fees for the submission.
93
+     *
94
+     * @var array
95
+     */
96
+    protected $fees = array();
97
+
98
+    /**
99
+     * An array of discounts for the submission.
100
+     *
101
+     * @var array
102
+     */
103
+    protected $discounts = array();
104
+
105
+    /**
106
+     * An array of taxes for the submission.
107
+     *
108
+     * @var array
109
+     */
110
+    protected $taxes = array();
111
+
112
+    /**
113
+     * An array of items for the submission.
114
+     *
115
+     * @var GetPaid_Form_Item[]
116
+     */
117
+    protected $items = array();
118
+
119
+    /**
120
+     * The last error.
121
+     *
122
+     * @var string
123
+     */
124
+    public $last_error = null;
125
+
126
+    /**
127
+     * Class constructor.
128
+     *
129
+     */
130
+    public function __construct() {
131
+
132
+        // Set the state and country to the default state and country.
133
+        $this->country = wpinv_default_billing_country();
134
+        $this->state   = wpinv_get_default_state();
135
+
136
+        // Do we have an actual submission?
137
+        if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
138
+            $this->load_data( $_POST );
139
+        }
140
+
141
+    }
142
+
143
+    /**
144
+     * Loads submission data.
145
+     *
146
+     * @param array $data
147
+     */
148
+    public function load_data( $data ) {
149
+
150
+        // Remove slashes from the submitted data...
151
+        $data       = wp_unslash( $data );
152
+
153
+        // Allow plugins to filter the data.
154
+        $data       = apply_filters( 'getpaid_submission_data', $data, $this );
155
+
156
+        // Cache it...
157
+        $this->data = $data;
158
+
159
+        // Then generate a unique id from the data.
160
+        $this->id   = md5( wp_json_encode( $data ) );
161
+
162
+        // Finally, process the submission.
163
+        try {
164
+
165
+            // Each process is passed an instance of the class (with reference)
166
+            // and should throw an Exception whenever it encounters one.
167
+            $processors = apply_filters(
168
+                'getpaid_payment_form_submission_processors',
169
+                array(
170
+                    array( $this, 'process_payment_form' ),
171
+                    array( $this, 'process_invoice' ),
172
+                    array( $this, 'process_fees' ),
173
+                    array( $this, 'process_items' ),
174
+                    array( $this, 'process_taxes' ),
175
+                    array( $this, 'process_discount' ),
176
+                ),
177
+                $this		
178
+            );
179
+
180
+            foreach ( $processors as $processor ) {
181
+                call_user_func_array( $processor, array( &$this ) );
182
+            }
183
+
184
+        } catch ( Exception $e ) {
185
+            $this->last_error = $e->getMessage();
186
+        }
187
+
188
+        // Fired when we are done processing a submission.
189
+        do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
190
+
191
+    }
192
+
193
+    /*
194 194
 	|--------------------------------------------------------------------------
195 195
 	| Payment Forms.
196 196
 	|--------------------------------------------------------------------------
@@ -199,39 +199,39 @@  discard block
 block discarded – undo
199 199
 	| submission has an active payment form etc.
200 200
     */
201 201
 
202
-	/**
203
-	 * Prepares the submission's payment form.
204
-	 *
205
-	 * @since 1.0.19
206
-	 */
207
-	public function process_payment_form() {
202
+    /**
203
+     * Prepares the submission's payment form.
204
+     *
205
+     * @since 1.0.19
206
+     */
207
+    public function process_payment_form() {
208 208
 
209
-		// Every submission needs an active payment form.
210
-		if ( empty( $this->data['form_id'] ) ) {
211
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
212
-		}
209
+        // Every submission needs an active payment form.
210
+        if ( empty( $this->data['form_id'] ) ) {
211
+            throw new Exception( __( 'Missing payment form', 'invoicing' ) );
212
+        }
213 213
 
214
-		// Fetch the payment form.
215
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
214
+        // Fetch the payment form.
215
+        $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
216 216
 
217
-		if ( ! $this->payment_form->is_active() ) {
218
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
219
-		}
217
+        if ( ! $this->payment_form->is_active() ) {
218
+            throw new Exception( __( 'Payment form not active', 'invoicing' ) );
219
+        }
220 220
 
221
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
222
-	}
221
+        do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
222
+    }
223 223
 
224 224
     /**
225
-	 * Returns the payment form.
226
-	 *
227
-	 * @since 1.0.19
228
-	 * @return GetPaid_Payment_Form
229
-	 */
230
-	public function get_payment_form() {
231
-		return $this->payment_form;
232
-	}
225
+     * Returns the payment form.
226
+     *
227
+     * @since 1.0.19
228
+     * @return GetPaid_Payment_Form
229
+     */
230
+    public function get_payment_form() {
231
+        return $this->payment_form;
232
+    }
233 233
 
234
-	/*
234
+    /*
235 235
 	|--------------------------------------------------------------------------
236 236
 	| Invoices.
237 237
 	|--------------------------------------------------------------------------
@@ -240,61 +240,61 @@  discard block
 block discarded – undo
240 240
 	| might be for an existing invoice.
241 241
 	*/
242 242
 
243
-	/**
244
-	 * Prepares the submission's invoice.
245
-	 *
246
-	 * @since 1.0.19
247
-	 */
248
-	public function process_invoice() {
243
+    /**
244
+     * Prepares the submission's invoice.
245
+     *
246
+     * @since 1.0.19
247
+     */
248
+    public function process_invoice() {
249 249
 
250
-		// Abort if there is no invoice.
251
-		if ( empty( $this->data['invoice_id'] ) ) {
252
-			return;
253
-		}
250
+        // Abort if there is no invoice.
251
+        if ( empty( $this->data['invoice_id'] ) ) {
252
+            return;
253
+        }
254 254
 
255
-		// If the submission is for an existing invoice, ensure that it exists
256
-		// and that it is not paid for.
257
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
255
+        // If the submission is for an existing invoice, ensure that it exists
256
+        // and that it is not paid for.
257
+        $invoice = wpinv_get_invoice( $this->data['invoice_id'] );
258 258
 
259 259
         if ( empty( $invoice ) ) {
260
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
261
-		}
262
-
263
-		if ( $invoice->is_paid() ) {
264
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
265
-		}
266
-
267
-		$this->payment_form->set_items( $invoice->get_items() );
268
-		$this->payment_form->invoice = $invoice;
269
-
270
-		$this->country = $invoice->get_country();
271
-		$this->state   = $invoice->get_state();
272
-		$this->invoice = $invoice;
273
-
274
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
275
-	}
276
-
277
-	/**
278
-	 * Returns the associated invoice.
279
-	 *
280
-	 * @since 1.0.19
281
-	 * @return WPInv_Invoice
282
-	 */
283
-	public function get_invoice() {
284
-		return $this->invoice;
285
-	}
286
-
287
-	/**
288
-	 * Checks whether there is an invoice associated with this submission.
289
-	 *
290
-	 * @since 1.0.19
291
-	 * @return bool
292
-	 */
293
-	public function has_invoice() {
294
-		return ! empty( $this->invoice );
295
-	}
296
-
297
-	/*
260
+            throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
261
+        }
262
+
263
+        if ( $invoice->is_paid() ) {
264
+            throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
265
+        }
266
+
267
+        $this->payment_form->set_items( $invoice->get_items() );
268
+        $this->payment_form->invoice = $invoice;
269
+
270
+        $this->country = $invoice->get_country();
271
+        $this->state   = $invoice->get_state();
272
+        $this->invoice = $invoice;
273
+
274
+        do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
275
+    }
276
+
277
+    /**
278
+     * Returns the associated invoice.
279
+     *
280
+     * @since 1.0.19
281
+     * @return WPInv_Invoice
282
+     */
283
+    public function get_invoice() {
284
+        return $this->invoice;
285
+    }
286
+
287
+    /**
288
+     * Checks whether there is an invoice associated with this submission.
289
+     *
290
+     * @since 1.0.19
291
+     * @return bool
292
+     */
293
+    public function has_invoice() {
294
+        return ! empty( $this->invoice );
295
+    }
296
+
297
+    /*
298 298
 	|--------------------------------------------------------------------------
299 299
 	| Items.
300 300
 	|--------------------------------------------------------------------------
@@ -303,105 +303,105 @@  discard block
 block discarded – undo
303 303
 	| recurring item. But can have an unlimited number of non-recurring items.
304 304
 	*/
305 305
 
306
-	/**
307
-	 * Prepares the submission's items.
308
-	 *
309
-	 * @since 1.0.19
310
-	 */
311
-	public function process_items() {
312
-
313
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
314
-
315
-		foreach ( $processor->items as $item ) {
316
-			$this->add_item( $item );
317
-		}
318
-
319
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
320
-	}
321
-
322
-	/**
323
-	 * Adds an item to the submission.
324
-	 *
325
-	 * @since 1.0.19
326
-	 * @param GetPaid_Form_Item $item
327
-	 */
328
-	public function add_item( $item ) {
329
-
330
-		// Make sure that it is available for purchase.
331
-		if ( ! $item->can_purchase() ) {
332
-			return;
333
-		}
334
-
335
-		// Each submission can only contain one recurring item.
336
-		if ( $item->is_recurring() ) {
337
-
338
-			if ( $this->has_recurring != 0 ) {
339
-				throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
340
-			}
341
-
342
-			$this->has_recurring = $item->get_id();
343
-
344
-		}
345
-
346
-		// Update the items and totals.
347
-		$this->items[ $item->get_id() ]         = $item;
348
-		$this->totals['subtotal']['initial']   += $item->get_sub_total();
349
-		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
350
-
351
-	}
352
-
353
-	/**
354
-	 * Removes a specific item.
355
-	 * 
356
-	 * You should not call this method after the discounts and taxes
357
-	 * have been calculated.
358
-	 *
359
-	 * @since 1.0.19
360
-	 */
361
-	public function remove_item( $item_id ) {
362
-
363
-		if ( isset( $this->items[ $item_id ] ) ) {
364
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
365
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
366
-
367
-			if ( $this->items[ $item_id ]->is_recurring() ) {
368
-				$this->has_recurring = 0;
369
-			}
370
-
371
-			unset( $this->items[ $item_id ] );
372
-		}
306
+    /**
307
+     * Prepares the submission's items.
308
+     *
309
+     * @since 1.0.19
310
+     */
311
+    public function process_items() {
312
+
313
+        $processor = new GetPaid_Payment_Form_Submission_Items( $this );
314
+
315
+        foreach ( $processor->items as $item ) {
316
+            $this->add_item( $item );
317
+        }
318
+
319
+        do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
320
+    }
321
+
322
+    /**
323
+     * Adds an item to the submission.
324
+     *
325
+     * @since 1.0.19
326
+     * @param GetPaid_Form_Item $item
327
+     */
328
+    public function add_item( $item ) {
329
+
330
+        // Make sure that it is available for purchase.
331
+        if ( ! $item->can_purchase() ) {
332
+            return;
333
+        }
334
+
335
+        // Each submission can only contain one recurring item.
336
+        if ( $item->is_recurring() ) {
337
+
338
+            if ( $this->has_recurring != 0 ) {
339
+                throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
340
+            }
341
+
342
+            $this->has_recurring = $item->get_id();
343
+
344
+        }
345
+
346
+        // Update the items and totals.
347
+        $this->items[ $item->get_id() ]         = $item;
348
+        $this->totals['subtotal']['initial']   += $item->get_sub_total();
349
+        $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
350
+
351
+    }
352
+
353
+    /**
354
+     * Removes a specific item.
355
+     * 
356
+     * You should not call this method after the discounts and taxes
357
+     * have been calculated.
358
+     *
359
+     * @since 1.0.19
360
+     */
361
+    public function remove_item( $item_id ) {
362
+
363
+        if ( isset( $this->items[ $item_id ] ) ) {
364
+            $this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
365
+            $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
366
+
367
+            if ( $this->items[ $item_id ]->is_recurring() ) {
368
+                $this->has_recurring = 0;
369
+            }
370
+
371
+            unset( $this->items[ $item_id ] );
372
+        }
373 373
 		
374
-	}
375
-
376
-	/**
377
-	 * Returns the subtotal.
378
-	 *
379
-	 * @since 1.0.19
380
-	 */
381
-	public function get_subtotal() {
382
-		return $this->totals['subtotal']['initial'];
383
-	}
384
-
385
-	/**
386
-	 * Returns the recurring subtotal.
387
-	 *
388
-	 * @since 1.0.19
389
-	 */
390
-	public function get_recurring_subtotal() {
391
-		return $this->totals['subtotal']['recurring'];
392
-	}
393
-
394
-	/**
395
-	 * Returns all items.
396
-	 *
397
-	 * @since 1.0.19
398
-	 * @return GetPaid_Form_Item[]
399
-	 */
400
-	public function get_items() {
401
-		return $this->items;
402
-	}
403
-
404
-	/*
374
+    }
375
+
376
+    /**
377
+     * Returns the subtotal.
378
+     *
379
+     * @since 1.0.19
380
+     */
381
+    public function get_subtotal() {
382
+        return $this->totals['subtotal']['initial'];
383
+    }
384
+
385
+    /**
386
+     * Returns the recurring subtotal.
387
+     *
388
+     * @since 1.0.19
389
+     */
390
+    public function get_recurring_subtotal() {
391
+        return $this->totals['subtotal']['recurring'];
392
+    }
393
+
394
+    /**
395
+     * Returns all items.
396
+     *
397
+     * @since 1.0.19
398
+     * @return GetPaid_Form_Item[]
399
+     */
400
+    public function get_items() {
401
+        return $this->items;
402
+    }
403
+
404
+    /*
405 405
 	|--------------------------------------------------------------------------
406 406
 	| Taxes
407 407
 	|--------------------------------------------------------------------------
@@ -410,108 +410,108 @@  discard block
 block discarded – undo
410 410
 	| or only one-time.
411 411
     */
412 412
 
413
-	/**
414
-	 * Prepares the submission's taxes.
415
-	 *
416
-	 * @since 1.0.19
417
-	 */
418
-	public function process_taxes() {
419
-
420
-		// Abort if we're not using taxes.
421
-		if ( ! $this->use_taxes() ) {
422
-			return;
423
-		}
424
-
425
-		// If a custom country && state has been passed in, use it to calculate taxes.
426
-		if ( ! empty( $this->data['wpinv_country'] ) ) {
427
-			$this->country = $this->data['wpinv_country'];
428
-		}
429
-
430
-		if ( ! empty( $this->data['wpinv_state'] ) ) {
431
-			$this->country = $this->data['wpinv_state'];
432
-		}
433
-
434
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
435
-
436
-		foreach ( $processor->taxes as $tax ) {
437
-			$this->add_tax( $tax );
438
-		}
439
-
440
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
441
-	}
442
-
443
-	/**
444
-	 * Adds a tax to the submission.
445
-	 *
446
-	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
447
-	 * @since 1.0.19
448
-	 */
449
-	public function add_tax( $tax ) {
450
-		$this->taxes[ $tax['name'] ]         = $tax;
451
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
452
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
453
-	}
454
-
455
-	/**
456
-	 * Removes a specific tax.
457
-	 *
458
-	 * @since 1.0.19
459
-	 */
460
-	public function remove_tax( $tax_name ) {
461
-
462
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
463
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
464
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
465
-			unset( $this->taxes[ $tax_name ] );
466
-		}
467
-
468
-	}
469
-
470
-	/**
471
-	 * Whether or not we'll use taxes for the submission.
472
-	 *
473
-	 * @since 1.0.19
474
-	 */
475
-	public function use_taxes() {
476
-
477
-		$use_taxes = wpinv_use_taxes();
478
-
479
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
480
-			$use_taxes = false;
481
-		}
482
-
483
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
484
-
485
-	}
486
-
487
-	/**
488
-	 * Returns the tax.
489
-	 *
490
-	 * @since 1.0.19
491
-	 */
492
-	public function get_tax() {
493
-		return $this->totals['taxes']['initial'];
494
-	}
495
-
496
-	/**
497
-	 * Returns the recurring tax.
498
-	 *
499
-	 * @since 1.0.19
500
-	 */
501
-	public function get_recurring_tax() {
502
-		return $this->totals['taxes']['recurring'];
503
-	}
504
-
505
-	/**
506
-	 * Returns all taxes.
507
-	 *
508
-	 * @since 1.0.19
509
-	 */
510
-	public function get_taxes() {
511
-		return $this->taxes;
512
-	}
513
-
514
-	/*
413
+    /**
414
+     * Prepares the submission's taxes.
415
+     *
416
+     * @since 1.0.19
417
+     */
418
+    public function process_taxes() {
419
+
420
+        // Abort if we're not using taxes.
421
+        if ( ! $this->use_taxes() ) {
422
+            return;
423
+        }
424
+
425
+        // If a custom country && state has been passed in, use it to calculate taxes.
426
+        if ( ! empty( $this->data['wpinv_country'] ) ) {
427
+            $this->country = $this->data['wpinv_country'];
428
+        }
429
+
430
+        if ( ! empty( $this->data['wpinv_state'] ) ) {
431
+            $this->country = $this->data['wpinv_state'];
432
+        }
433
+
434
+        $processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
435
+
436
+        foreach ( $processor->taxes as $tax ) {
437
+            $this->add_tax( $tax );
438
+        }
439
+
440
+        do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
441
+    }
442
+
443
+    /**
444
+     * Adds a tax to the submission.
445
+     *
446
+     * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
447
+     * @since 1.0.19
448
+     */
449
+    public function add_tax( $tax ) {
450
+        $this->taxes[ $tax['name'] ]         = $tax;
451
+        $this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
452
+        $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
453
+    }
454
+
455
+    /**
456
+     * Removes a specific tax.
457
+     *
458
+     * @since 1.0.19
459
+     */
460
+    public function remove_tax( $tax_name ) {
461
+
462
+        if ( isset( $this->taxes[ $tax_name ] ) ) {
463
+            $this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
464
+            $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
465
+            unset( $this->taxes[ $tax_name ] );
466
+        }
467
+
468
+    }
469
+
470
+    /**
471
+     * Whether or not we'll use taxes for the submission.
472
+     *
473
+     * @since 1.0.19
474
+     */
475
+    public function use_taxes() {
476
+
477
+        $use_taxes = wpinv_use_taxes();
478
+
479
+        if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
480
+            $use_taxes = false;
481
+        }
482
+
483
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
484
+
485
+    }
486
+
487
+    /**
488
+     * Returns the tax.
489
+     *
490
+     * @since 1.0.19
491
+     */
492
+    public function get_tax() {
493
+        return $this->totals['taxes']['initial'];
494
+    }
495
+
496
+    /**
497
+     * Returns the recurring tax.
498
+     *
499
+     * @since 1.0.19
500
+     */
501
+    public function get_recurring_tax() {
502
+        return $this->totals['taxes']['recurring'];
503
+    }
504
+
505
+    /**
506
+     * Returns all taxes.
507
+     *
508
+     * @since 1.0.19
509
+     */
510
+    public function get_taxes() {
511
+        return $this->taxes;
512
+    }
513
+
514
+    /*
515 515
 	|--------------------------------------------------------------------------
516 516
 	| Discounts
517 517
 	|--------------------------------------------------------------------------
@@ -520,99 +520,99 @@  discard block
 block discarded – undo
520 520
 	| or only one-time. They also do not have to come from a discount code.
521 521
     */
522 522
 
523
-	/**
524
-	 * Prepares the submission's discount.
525
-	 *
526
-	 * @since 1.0.19
527
-	 */
528
-	public function process_discount() {
529
-
530
-		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
531
-		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
532
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
533
-
534
-		foreach ( $processor->discounts as $discount ) {
535
-			$this->add_discount( $discount );
536
-		}
537
-
538
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
539
-	}
540
-
541
-	/**
542
-	 * Adds a discount to the submission.
543
-	 *
544
-	 * @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.
545
-	 * @since 1.0.19
546
-	 */
547
-	public function add_discount( $discount ) {
548
-		$this->discounts[ $discount['name'] ]   = $discount;
549
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
550
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
551
-	}
552
-
553
-	/**
554
-	 * Removes a discount from the submission.
555
-	 *
556
-	 * @since 1.0.19
557
-	 */
558
-	public function remove_discount( $name ) {
559
-
560
-		if ( isset( $this->discounts[ $name ] ) ) {
561
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
562
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
563
-			unset( $this->discounts[ $name ] );
564
-		}
565
-
566
-	}
567
-
568
-	/**
569
-	 * Checks whether there is a discount code associated with this submission.
570
-	 *
571
-	 * @since 1.0.19
572
-	 * @return bool
573
-	 */
574
-	public function has_discount_code() {
575
-		return ! empty( $this->discounts['discount_code'] );
576
-	}
577
-
578
-	/**
579
-	 * Returns the discount code.
580
-	 *
581
-	 * @since 1.0.19
582
-	 * @return string
583
-	 */
584
-	public function get_discount_code() {
585
-		return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
586
-	}
587
-
588
-	/**
589
-	 * Returns the discount.
590
-	 *
591
-	 * @since 1.0.19
592
-	 */
593
-	public function get_discount() {
594
-		return $this->totals['discount']['initial'];
595
-	}
596
-
597
-	/**
598
-	 * Returns the recurring discount.
599
-	 *
600
-	 * @since 1.0.19
601
-	 */
602
-	public function get_recurring_discount() {
603
-		return $this->totals['discount']['recurring'];
604
-	}
605
-
606
-	/**
607
-	 * Returns all discounts.
608
-	 *
609
-	 * @since 1.0.19
610
-	 */
611
-	public function get_discounts() {
612
-		return $this->discounts;
613
-	}
614
-
615
-	/*
523
+    /**
524
+     * Prepares the submission's discount.
525
+     *
526
+     * @since 1.0.19
527
+     */
528
+    public function process_discount() {
529
+
530
+        $initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
531
+        $recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
532
+        $processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
533
+
534
+        foreach ( $processor->discounts as $discount ) {
535
+            $this->add_discount( $discount );
536
+        }
537
+
538
+        do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
539
+    }
540
+
541
+    /**
542
+     * Adds a discount to the submission.
543
+     *
544
+     * @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.
545
+     * @since 1.0.19
546
+     */
547
+    public function add_discount( $discount ) {
548
+        $this->discounts[ $discount['name'] ]   = $discount;
549
+        $this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
550
+        $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
551
+    }
552
+
553
+    /**
554
+     * Removes a discount from the submission.
555
+     *
556
+     * @since 1.0.19
557
+     */
558
+    public function remove_discount( $name ) {
559
+
560
+        if ( isset( $this->discounts[ $name ] ) ) {
561
+            $this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
562
+            $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
563
+            unset( $this->discounts[ $name ] );
564
+        }
565
+
566
+    }
567
+
568
+    /**
569
+     * Checks whether there is a discount code associated with this submission.
570
+     *
571
+     * @since 1.0.19
572
+     * @return bool
573
+     */
574
+    public function has_discount_code() {
575
+        return ! empty( $this->discounts['discount_code'] );
576
+    }
577
+
578
+    /**
579
+     * Returns the discount code.
580
+     *
581
+     * @since 1.0.19
582
+     * @return string
583
+     */
584
+    public function get_discount_code() {
585
+        return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
586
+    }
587
+
588
+    /**
589
+     * Returns the discount.
590
+     *
591
+     * @since 1.0.19
592
+     */
593
+    public function get_discount() {
594
+        return $this->totals['discount']['initial'];
595
+    }
596
+
597
+    /**
598
+     * Returns the recurring discount.
599
+     *
600
+     * @since 1.0.19
601
+     */
602
+    public function get_recurring_discount() {
603
+        return $this->totals['discount']['recurring'];
604
+    }
605
+
606
+    /**
607
+     * Returns all discounts.
608
+     *
609
+     * @since 1.0.19
610
+     */
611
+    public function get_discounts() {
612
+        return $this->discounts;
613
+    }
614
+
615
+    /*
616 616
 	|--------------------------------------------------------------------------
617 617
 	| Fees
618 618
 	|--------------------------------------------------------------------------
@@ -622,89 +622,89 @@  discard block
 block discarded – undo
622 622
 	| fees.
623 623
     */
624 624
 
625
-	/**
626
-	 * Prepares the submission's fees.
627
-	 *
628
-	 * @since 1.0.19
629
-	 */
630
-	public function process_fees() {
631
-
632
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
633
-
634
-		foreach ( $fees_processor->fees as $fee ) {
635
-			$this->add_fee( $fee );
636
-		}
637
-
638
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
639
-	}
640
-
641
-	/**
642
-	 * Adds a fee to the submission.
643
-	 *
644
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
645
-	 * @since 1.0.19
646
-	 */
647
-	public function add_fee( $fee ) {
648
-
649
-		$this->fees[ $fee['name'] ]         = $fee;
650
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
651
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
652
-
653
-	}
654
-
655
-	/**
656
-	 * Removes a fee from the submission.
657
-	 *
658
-	 * @since 1.0.19
659
-	 */
660
-	public function remove_fee( $name ) {
661
-
662
-		if ( isset( $this->fees[ $name ] ) ) {
663
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
664
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
665
-			unset( $this->fees[ $name ] );
666
-		}
667
-
668
-	}
669
-
670
-	/**
671
-	 * Returns the fees.
672
-	 *
673
-	 * @since 1.0.19
674
-	 */
675
-	public function get_fee() {
676
-		return $this->totals['fees']['initial'];
677
-	}
678
-
679
-	/**
680
-	 * Returns the recurring fees.
681
-	 *
682
-	 * @since 1.0.19
683
-	 */
684
-	public function get_recurring_fee() {
685
-		return $this->totals['fees']['recurring'];
686
-	}
687
-
688
-	/**
689
-	 * Returns all fees.
690
-	 *
691
-	 * @since 1.0.19
692
-	 */
693
-	public function get_fees() {
694
-		return $this->fees;
695
-	}
696
-
697
-	/**
698
-	 * Checks if there are any fees for the form.
699
-	 *
700
-	 * @return bool
701
-	 * @since 1.0.19
702
-	 */
703
-	public function has_fees() {
704
-		return count( $this->fees ) !== 0;
705
-	}
706
-
707
-	/*
625
+    /**
626
+     * Prepares the submission's fees.
627
+     *
628
+     * @since 1.0.19
629
+     */
630
+    public function process_fees() {
631
+
632
+        $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
633
+
634
+        foreach ( $fees_processor->fees as $fee ) {
635
+            $this->add_fee( $fee );
636
+        }
637
+
638
+        do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
639
+    }
640
+
641
+    /**
642
+     * Adds a fee to the submission.
643
+     *
644
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
645
+     * @since 1.0.19
646
+     */
647
+    public function add_fee( $fee ) {
648
+
649
+        $this->fees[ $fee['name'] ]         = $fee;
650
+        $this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
651
+        $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
652
+
653
+    }
654
+
655
+    /**
656
+     * Removes a fee from the submission.
657
+     *
658
+     * @since 1.0.19
659
+     */
660
+    public function remove_fee( $name ) {
661
+
662
+        if ( isset( $this->fees[ $name ] ) ) {
663
+            $this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
664
+            $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
665
+            unset( $this->fees[ $name ] );
666
+        }
667
+
668
+    }
669
+
670
+    /**
671
+     * Returns the fees.
672
+     *
673
+     * @since 1.0.19
674
+     */
675
+    public function get_fee() {
676
+        return $this->totals['fees']['initial'];
677
+    }
678
+
679
+    /**
680
+     * Returns the recurring fees.
681
+     *
682
+     * @since 1.0.19
683
+     */
684
+    public function get_recurring_fee() {
685
+        return $this->totals['fees']['recurring'];
686
+    }
687
+
688
+    /**
689
+     * Returns all fees.
690
+     *
691
+     * @since 1.0.19
692
+     */
693
+    public function get_fees() {
694
+        return $this->fees;
695
+    }
696
+
697
+    /**
698
+     * Checks if there are any fees for the form.
699
+     *
700
+     * @return bool
701
+     * @since 1.0.19
702
+     */
703
+    public function has_fees() {
704
+        return count( $this->fees ) !== 0;
705
+    }
706
+
707
+    /*
708 708
 	|--------------------------------------------------------------------------
709 709
 	| MISC
710 710
 	|--------------------------------------------------------------------------
@@ -712,109 +712,109 @@  discard block
 block discarded – undo
712 712
 	| Extra submission functions.
713 713
     */
714 714
 
715
-	/**
716
-	 * Returns the total amount to collect for this submission.
717
-	 *
718
-	 * @since 1.0.19
719
-	 */
720
-	public function get_total() {
721
-		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
722
-		return max( $total, 0 );
723
-	}
724
-
725
-	/**
726
-	 * Returns the recurring total amount to collect for this submission.
727
-	 *
728
-	 * @since 1.0.19
729
-	 */
730
-	public function get_recurring_total() {
731
-		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
732
-		return max( $total, 0 );
733
-	}
734
-
735
-	/**
736
-	 * Whether payment details should be collected for this submission.
737
-	 *
738
-	 * @since 1.0.19
739
-	 */
740
-	public function should_collect_payment_details() {
741
-		$initial   = $this->get_total();
742
-		$recurring = $this->get_recurring_total();
743
-
744
-		if ( $this->has_recurring == 0 ) {
745
-			$recurring = 0;
746
-		}
747
-
748
-		$collect = $initial > 0 || $recurring > 0;
749
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
750
-	}
751
-
752
-	/**
753
-	 * Returns the billing email of the user.
754
-	 *
755
-	 * @since 1.0.19
756
-	 */
757
-	public function get_billing_email() {
758
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
759
-	}
760
-
761
-	/**
762
-	 * Checks if the submitter has a billing email.
763
-	 *
764
-	 * @since 1.0.19
765
-	 */
766
-	public function has_billing_email() {
767
-		$billing_email = $this->get_billing_email();
768
-		return ! empty( $billing_email );
769
-	}
770
-
771
-	/**
772
-	 * Returns the appropriate currency for the submission.
773
-	 *
774
-	 * @since 1.0.19
775
-	 * @return string
776
-	 */
777
-	public function get_currency() {
778
-		return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
779
-    }
780
-
781
-    /**
782
-	 * Returns the raw submission data.
783
-	 *
784
-	 * @since 1.0.19
785
-	 * @return array
786
-	 */
787
-	public function get_data() {
788
-		return $this->data;
789
-	}
790
-
791
-	/**
792
-	 * Returns a field from the submission data
793
-	 *
794
-	 * @param string $field
795
-	 * @since 1.0.19
796
-	 * @return mixed
797
-	 */
798
-	public function get_field( $field ) {
799
-		return isset( $this->data[ $field ] ) ? $this->data[ $field ] : '';
800
-	}
801
-
802
-	/**
803
-	 * Checks if a required field is set.
804
-	 *
805
-	 * @since 1.0.19
806
-	 */
807
-	public function is_required_field_set( $field ) {
808
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
809
-	}
810
-
811
-	/**
812
-	 * Formats an amount
813
-	 *
814
-	 * @since 1.0.19
815
-	 */
816
-	public function format_amount( $amount ) {
817
-		return wpinv_price( $amount, $this->get_currency() );
818
-	}
715
+    /**
716
+     * Returns the total amount to collect for this submission.
717
+     *
718
+     * @since 1.0.19
719
+     */
720
+    public function get_total() {
721
+        $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
722
+        return max( $total, 0 );
723
+    }
724
+
725
+    /**
726
+     * Returns the recurring total amount to collect for this submission.
727
+     *
728
+     * @since 1.0.19
729
+     */
730
+    public function get_recurring_total() {
731
+        $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
732
+        return max( $total, 0 );
733
+    }
734
+
735
+    /**
736
+     * Whether payment details should be collected for this submission.
737
+     *
738
+     * @since 1.0.19
739
+     */
740
+    public function should_collect_payment_details() {
741
+        $initial   = $this->get_total();
742
+        $recurring = $this->get_recurring_total();
743
+
744
+        if ( $this->has_recurring == 0 ) {
745
+            $recurring = 0;
746
+        }
747
+
748
+        $collect = $initial > 0 || $recurring > 0;
749
+        return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
750
+    }
751
+
752
+    /**
753
+     * Returns the billing email of the user.
754
+     *
755
+     * @since 1.0.19
756
+     */
757
+    public function get_billing_email() {
758
+        return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
759
+    }
760
+
761
+    /**
762
+     * Checks if the submitter has a billing email.
763
+     *
764
+     * @since 1.0.19
765
+     */
766
+    public function has_billing_email() {
767
+        $billing_email = $this->get_billing_email();
768
+        return ! empty( $billing_email );
769
+    }
770
+
771
+    /**
772
+     * Returns the appropriate currency for the submission.
773
+     *
774
+     * @since 1.0.19
775
+     * @return string
776
+     */
777
+    public function get_currency() {
778
+        return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
779
+    }
780
+
781
+    /**
782
+     * Returns the raw submission data.
783
+     *
784
+     * @since 1.0.19
785
+     * @return array
786
+     */
787
+    public function get_data() {
788
+        return $this->data;
789
+    }
790
+
791
+    /**
792
+     * Returns a field from the submission data
793
+     *
794
+     * @param string $field
795
+     * @since 1.0.19
796
+     * @return mixed
797
+     */
798
+    public function get_field( $field ) {
799
+        return isset( $this->data[ $field ] ) ? $this->data[ $field ] : '';
800
+    }
801
+
802
+    /**
803
+     * Checks if a required field is set.
804
+     *
805
+     * @since 1.0.19
806
+     */
807
+    public function is_required_field_set( $field ) {
808
+        return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
809
+    }
810
+
811
+    /**
812
+     * Formats an amount
813
+     *
814
+     * @since 1.0.19
815
+     */
816
+    public function format_amount( $amount ) {
817
+        return wpinv_price( $amount, $this->get_currency() );
818
+    }
819 819
 
820 820
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 1 patch
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -12,185 +12,185 @@
 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 31
             'is_free'       => $submission->should_collect_payment_details(),
32
-		);
32
+        );
33 33
 		
34
-		$this->add_totals( $submission );
35
-		$this->add_texts( $submission );
36
-		$this->add_items( $submission );
37
-		$this->add_fees( $submission );
38
-		$this->add_discounts( $submission );
39
-		$this->add_taxes( $submission );
40
-
41
-	}
42
-
43
-	/**
44
-	 * Adds totals to a response for submission refresh prices.
45
-	 *
46
-	 * @param GetPaid_Payment_Form_Submission $submission
47
-	 */
48
-	public function add_totals( $submission ) {
49
-
50
-		$this->response = array_merge(
51
-			$this->response,
52
-			array(
53
-
54
-				'totals'        => array(
55
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
56
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
57
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
58
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
59
-					'total'     => $submission->format_amount( $submission->get_total() ),
60
-				),
34
+        $this->add_totals( $submission );
35
+        $this->add_texts( $submission );
36
+        $this->add_items( $submission );
37
+        $this->add_fees( $submission );
38
+        $this->add_discounts( $submission );
39
+        $this->add_taxes( $submission );
40
+
41
+    }
42
+
43
+    /**
44
+     * Adds totals to a response for submission refresh prices.
45
+     *
46
+     * @param GetPaid_Payment_Form_Submission $submission
47
+     */
48
+    public function add_totals( $submission ) {
49
+
50
+        $this->response = array_merge(
51
+            $this->response,
52
+            array(
53
+
54
+                'totals'        => array(
55
+                    'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
56
+                    'discount'  => $submission->format_amount( $submission->get_discount() ),
57
+                    'fees'      => $submission->format_amount( $submission->get_fee() ),
58
+                    'tax'       => $submission->format_amount( $submission->get_tax() ),
59
+                    'total'     => $submission->format_amount( $submission->get_total() ),
60
+                ),
61 61
 	
62
-				'recurring'     => array(
63
-					'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
64
-					'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
65
-					'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
66
-					'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
67
-					'total'     => $submission->format_amount( $submission->get_recurring_total() ),
68
-				),
62
+                'recurring'     => array(
63
+                    'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
64
+                    'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
65
+                    'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
66
+                    'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
67
+                    'total'     => $submission->format_amount( $submission->get_recurring_total() ),
68
+                ),
69 69
 
70
-			)
71
-		);
70
+            )
71
+        );
72 72
 
73
-	}
73
+    }
74 74
 
75
-	/**
76
-	 * Adds texts to a response for submission refresh prices.
77
-	 *
78
-	 * @param GetPaid_Payment_Form_Submission $submission
79
-	 */
80
-	public function add_texts( $submission ) {
75
+    /**
76
+     * Adds texts to a response for submission refresh prices.
77
+     *
78
+     * @param GetPaid_Payment_Form_Submission $submission
79
+     */
80
+    public function add_texts( $submission ) {
81 81
 
82
-		$payable = $submission->format_amount( $submission->get_total() );
82
+        $payable = $submission->format_amount( $submission->get_total() );
83 83
 
84
-		if ( $submission->has_recurring != 0 ) {
84
+        if ( $submission->has_recurring != 0 ) {
85 85
 
86
-			$recurring = new WPInv_Item( $submission->has_recurring );
87
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
86
+            $recurring = new WPInv_Item( $submission->has_recurring );
87
+            $period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
88 88
 
89
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
90
-				$payable = "$payable / $period";
91
-			} else {
92
-				$payable = sprintf(
93
-					__( '%1$s (renews at %2$s / %3$s)'),
94
-					$submission->format_amount( $submission->get_total() ),
95
-					$submission->format_amount( $submission->get_recurring_total() ),
96
-					$period
97
-				);
98
-			}
89
+            if ( $submission->get_total() == $submission->get_recurring_total() ) {
90
+                $payable = "$payable / $period";
91
+            } else {
92
+                $payable = sprintf(
93
+                    __( '%1$s (renews at %2$s / %3$s)'),
94
+                    $submission->format_amount( $submission->get_total() ),
95
+                    $submission->format_amount( $submission->get_recurring_total() ),
96
+                    $period
97
+                );
98
+            }
99 99
 
100
-		}
100
+        }
101 101
 
102
-		$texts = array(
103
-			'.getpaid-checkout-total-payable' => $payable,
104
-		);
102
+        $texts = array(
103
+            '.getpaid-checkout-total-payable' => $payable,
104
+        );
105 105
 
106
-		foreach ( $submission->get_items() as $item_id => $item ) {
107
-			$texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
108
-			$texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
109
-		}
106
+        foreach ( $submission->get_items() as $item_id => $item ) {
107
+            $texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
108
+            $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
109
+        }
110 110
 
111
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
111
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
112 112
 
113
-	}
113
+    }
114 114
 
115
-	/**
116
-	 * Adds items to a response for submission refresh prices.
117
-	 *
118
-	 * @param GetPaid_Payment_Form_Submission $submission
119
-	 */
120
-	public function add_items( $submission ) {
115
+    /**
116
+     * Adds items to a response for submission refresh prices.
117
+     *
118
+     * @param GetPaid_Payment_Form_Submission $submission
119
+     */
120
+    public function add_items( $submission ) {
121 121
 
122
-		// Add items.
123
-		$items = array();
122
+        // Add items.
123
+        $items = array();
124 124
 
125 125
         foreach ( $submission->get_items() as $item_id => $item ) {
126
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
127
-		}
126
+            $items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
127
+        }
128 128
 
129
-		$this->response = array_merge(
130
-			$this->response,
131
-			array( 'items' => $items )
132
-		);
129
+        $this->response = array_merge(
130
+            $this->response,
131
+            array( 'items' => $items )
132
+        );
133 133
 
134
-	}
134
+    }
135 135
 
136
-	/**
137
-	 * Adds fees to a response for submission refresh prices.
138
-	 *
139
-	 * @param GetPaid_Payment_Form_Submission $submission
140
-	 */
141
-	public function add_fees( $submission ) {
136
+    /**
137
+     * Adds fees to a response for submission refresh prices.
138
+     *
139
+     * @param GetPaid_Payment_Form_Submission $submission
140
+     */
141
+    public function add_fees( $submission ) {
142 142
 
143
-		$fees = array();
143
+        $fees = array();
144 144
 
145 145
         foreach ( $submission->get_fees() as $name => $data ) {
146
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
147
-		}
146
+            $fees[$name] = $submission->format_amount( $data['initial_fee'] );
147
+        }
148 148
 
149
-		$this->response = array_merge(
150
-			$this->response,
151
-			array( 'fees' => $fees )
152
-		);
149
+        $this->response = array_merge(
150
+            $this->response,
151
+            array( 'fees' => $fees )
152
+        );
153 153
 
154
-	}
154
+    }
155 155
 
156
-	/**
157
-	 * Adds discounts to a response for submission refresh prices.
158
-	 *
159
-	 * @param GetPaid_Payment_Form_Submission $submission
160
-	 */
161
-	public function add_discounts( $submission ) {
156
+    /**
157
+     * Adds discounts to a response for submission refresh prices.
158
+     *
159
+     * @param GetPaid_Payment_Form_Submission $submission
160
+     */
161
+    public function add_discounts( $submission ) {
162 162
 
163
-		$discounts = array();
163
+        $discounts = array();
164 164
 
165 165
         foreach ( $submission->get_discounts() as $name => $data ) {
166
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
167
-		}
166
+            $discounts[$name] = $submission->format_amount( $data['initial_discount'] );
167
+        }
168 168
 
169
-		$this->response = array_merge(
170
-			$this->response,
171
-			array( 'discounts' => $discounts )
172
-		);
169
+        $this->response = array_merge(
170
+            $this->response,
171
+            array( 'discounts' => $discounts )
172
+        );
173 173
 
174
-	}
174
+    }
175 175
 
176
-	/**
177
-	 * Adds taxes to a response for submission refresh prices.
178
-	 *
179
-	 * @param GetPaid_Payment_Form_Submission $submission
180
-	 */
181
-	public function add_taxes( $submission ) {
176
+    /**
177
+     * Adds taxes to a response for submission refresh prices.
178
+     *
179
+     * @param GetPaid_Payment_Form_Submission $submission
180
+     */
181
+    public function add_taxes( $submission ) {
182 182
 
183
-		$taxes = array();
183
+        $taxes = array();
184 184
 
185 185
         foreach ( $submission->get_taxes() as $name => $data ) {
186
-			$taxes[$name] = $submission->format_amount( $data['initial_tax'] );
187
-		}
186
+            $taxes[$name] = $submission->format_amount( $data['initial_tax'] );
187
+        }
188 188
 
189
-		$this->response = array_merge(
190
-			$this->response,
191
-			array( 'taxes' => $taxes )
192
-		);
189
+        $this->response = array_merge(
190
+            $this->response,
191
+            array( 'taxes' => $taxes )
192
+        );
193 193
 
194
-	}
194
+    }
195 195
 
196 196
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-items.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -12,77 +12,77 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Items {
14 14
 
15
-	/**
16
-	 * Submission items.
17
-	 * @var GetPaid_Form_Item[]
18
-	 */
19
-	public $items = array();
15
+    /**
16
+     * Submission items.
17
+     * @var GetPaid_Form_Item[]
18
+     */
19
+    public $items = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27 27
 
28
-		$data         = $submission->get_data();
29
-		$payment_form = $submission->get_payment_form();
28
+        $data         = $submission->get_data();
29
+        $payment_form = $submission->get_payment_form();
30 30
 
31
-		// Prepare the selected items.
32
-		$selected_items = array();
33
-		if ( ! empty( $data['getpaid-items'] ) ) {
34
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
35
-		}
31
+        // Prepare the selected items.
32
+        $selected_items = array();
33
+        if ( ! empty( $data['getpaid-items'] ) ) {
34
+            $selected_items = wpinv_clean( $data['getpaid-items'] );
35
+        }
36 36
 
37
-		// For default forms, ensure that an item has been set.
38
-		if ( $payment_form->is_default() && ! $submission->has_invoice() ) {
39
-			$payment_form->set_items( $selected_items );
40
-		}
37
+        // For default forms, ensure that an item has been set.
38
+        if ( $payment_form->is_default() && ! $submission->has_invoice() ) {
39
+            $payment_form->set_items( $selected_items );
40
+        }
41 41
 
42
-		// Process each individual item.
43
-		foreach ( $payment_form->get_items() as $item ) {
44
-			$this->process_item( $item, $selected_items );
45
-		}
42
+        // Process each individual item.
43
+        foreach ( $payment_form->get_items() as $item ) {
44
+            $this->process_item( $item, $selected_items );
45
+        }
46 46
 
47
-	}
47
+    }
48 48
 
49
-	/**
50
-	 * Process a single item.
51
-	 *
52
-	 * @param GetPaid_Form_Item $item
53
-	 * @param array $selected_items
54
-	 */
55
-	public function process_item( $item, $selected_items ) {
49
+    /**
50
+     * Process a single item.
51
+     *
52
+     * @param GetPaid_Form_Item $item
53
+     * @param array $selected_items
54
+     */
55
+    public function process_item( $item, $selected_items ) {
56 56
 
57
-		// Abort if this is an optional item and it has not been selected.
58
-		if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
59
-			return;
60
-		}
57
+        // Abort if this is an optional item and it has not been selected.
58
+        if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
59
+            return;
60
+        }
61 61
 
62
-		// (maybe) let customers change the quantities and prices.
63
-		if ( isset( $selected_items[ $item->get_id() ] ) ) {
62
+        // (maybe) let customers change the quantities and prices.
63
+        if ( isset( $selected_items[ $item->get_id() ] ) ) {
64 64
 
65
-			// Maybe change the quantities.
66
-			if ( $item->allows_quantities() ) {
67
-				$item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] );
68
-			}
65
+            // Maybe change the quantities.
66
+            if ( $item->allows_quantities() ) {
67
+                $item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] );
68
+            }
69 69
 
70
-			// Maybe change the price.
71
-			if ( $item->user_can_set_their_price() ) {
72
-				$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
70
+            // Maybe change the price.
71
+            if ( $item->user_can_set_their_price() ) {
72
+                $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
73 73
 
74
-				// But don't get lower than the minimum price.
75
-				$price = max( $price, $item->get_minimum_price() );
74
+                // But don't get lower than the minimum price.
75
+                $price = max( $price, $item->get_minimum_price() );
76 76
 
77
-				$item->set_price( $price );
77
+                $item->set_price( $price );
78 78
 
79
-			}
79
+            }
80 80
 
81
-		}
81
+        }
82 82
 
83
-		// Save the item.
84
-		$this->items[] = $item;
83
+        // Save the item.
84
+        $this->items[] = $item;
85 85
 
86
-	}
86
+    }
87 87
 
88 88
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form.php 1 patch
Indentation   +520 added lines, -520 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,55 +10,55 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form extends GetPaid_Data {
11 11
 
12 12
     /**
13
-	 * Which data store to load.
14
-	 *
15
-	 * @var string
16
-	 */
13
+     * Which data store to load.
14
+     *
15
+     * @var string
16
+     */
17 17
     protected $data_store_name = 'payment_form';
18 18
 
19 19
     /**
20
-	 * This is the name of this object type.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $object_type = 'payment_form';
20
+     * This is the name of this object type.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $object_type = 'payment_form';
25 25
 
26 26
     /**
27
-	 * Form Data array. This is the core form data exposed in APIs.
28
-	 *
29
-	 * @since 1.0.19
30
-	 * @var array
31
-	 */
32
-	protected $data = array(
33
-		'status'               => 'draft',
34
-		'version'              => '',
35
-		'date_created'         => null,
27
+     * Form Data array. This is the core form data exposed in APIs.
28
+     *
29
+     * @since 1.0.19
30
+     * @var array
31
+     */
32
+    protected $data = array(
33
+        'status'               => 'draft',
34
+        'version'              => '',
35
+        'date_created'         => null,
36 36
         'date_modified'        => null,
37 37
         'name'                 => '',
38 38
         'author'               => 1,
39 39
         'elements'             => null,
40
-		'items'                => null,
41
-		'earned'               => 0,
42
-		'refunded'             => 0,
43
-		'cancelled'            => 0,
44
-		'failed'               => 0,
45
-	);
46
-
47
-    /**
48
-	 * Stores meta in cache for future reads.
49
-	 *
50
-	 * A group must be set to to enable caching.
51
-	 *
52
-	 * @var string
53
-	 */
54
-	protected $cache_group = 'getpaid_forms';
55
-
56
-	/**
57
-	 * Stores a reference to the invoice if the form is for an invoice..
58
-	 *
59
-	 * @var WPInv_Invoice
60
-	 */
61
-	public $invoice = 0;
40
+        'items'                => null,
41
+        'earned'               => 0,
42
+        'refunded'             => 0,
43
+        'cancelled'            => 0,
44
+        'failed'               => 0,
45
+    );
46
+
47
+    /**
48
+     * Stores meta in cache for future reads.
49
+     *
50
+     * A group must be set to to enable caching.
51
+     *
52
+     * @var string
53
+     */
54
+    protected $cache_group = 'getpaid_forms';
55
+
56
+    /**
57
+     * Stores a reference to the invoice if the form is for an invoice..
58
+     *
59
+     * @var WPInv_Invoice
60
+     */
61
+    public $invoice = 0;
62 62
 
63 63
     /**
64 64
      * Stores a reference to the original WP_Post object
@@ -68,35 +68,35 @@  discard block
 block discarded – undo
68 68
     protected $post = null;
69 69
 
70 70
     /**
71
-	 * Get the form if ID is passed, otherwise the form is new and empty.
72
-	 *
73
-	 * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74
-	 */
75
-	public function __construct( $form = 0 ) {
76
-		parent::__construct( $form );
71
+     * Get the form if ID is passed, otherwise the form is new and empty.
72
+     *
73
+     * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74
+     */
75
+    public function __construct( $form = 0 ) {
76
+        parent::__construct( $form );
77 77
 
78
-		if ( is_numeric( $form ) && $form > 0 ) {
79
-			$this->set_id( $form );
80
-		} elseif ( $form instanceof self ) {
78
+        if ( is_numeric( $form ) && $form > 0 ) {
79
+            $this->set_id( $form );
80
+        } elseif ( $form instanceof self ) {
81 81
 
82
-			$this->set_id( $form->get_id() );
83
-			$this->invoice = $form->invoice;
82
+            $this->set_id( $form->get_id() );
83
+            $this->invoice = $form->invoice;
84 84
 
85
-		} elseif ( ! empty( $form->ID ) ) {
86
-			$this->set_id( $form->ID );
87
-		} else {
88
-			$this->set_object_read( true );
89
-		}
85
+        } elseif ( ! empty( $form->ID ) ) {
86
+            $this->set_id( $form->ID );
87
+        } else {
88
+            $this->set_object_read( true );
89
+        }
90 90
 
91 91
         // Load the datastore.
92
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
92
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
93 93
 
94
-		if ( $this->get_id() > 0 ) {
94
+        if ( $this->get_id() > 0 ) {
95 95
             $this->post = get_post( $this->get_id() );
96
-			$this->data_store->read( $this );
96
+            $this->data_store->read( $this );
97 97
         }
98 98
 
99
-	}
99
+    }
100 100
 
101 101
     /*
102 102
 	|--------------------------------------------------------------------------
@@ -114,351 +114,351 @@  discard block
 block discarded – undo
114 114
     */
115 115
 
116 116
     /**
117
-	 * Get plugin version when the form was created.
118
-	 *
119
-	 * @since 1.0.19
120
-	 * @param  string $context View or edit context.
121
-	 * @return string
122
-	 */
123
-	public function get_version( $context = 'view' ) {
124
-		return $this->get_prop( 'version', $context );
117
+     * Get plugin version when the form was created.
118
+     *
119
+     * @since 1.0.19
120
+     * @param  string $context View or edit context.
121
+     * @return string
122
+     */
123
+    public function get_version( $context = 'view' ) {
124
+        return $this->get_prop( 'version', $context );
125 125
     }
126 126
 
127 127
     /**
128
-	 * Get date when the form was created.
129
-	 *
130
-	 * @since 1.0.19
131
-	 * @param  string $context View or edit context.
132
-	 * @return string
133
-	 */
134
-	public function get_date_created( $context = 'view' ) {
135
-		return $this->get_prop( 'date_created', $context );
128
+     * Get date when the form was created.
129
+     *
130
+     * @since 1.0.19
131
+     * @param  string $context View or edit context.
132
+     * @return string
133
+     */
134
+    public function get_date_created( $context = 'view' ) {
135
+        return $this->get_prop( 'date_created', $context );
136 136
     }
137 137
 
138 138
     /**
139
-	 * Get GMT date when the form was created.
140
-	 *
141
-	 * @since 1.0.19
142
-	 * @param  string $context View or edit context.
143
-	 * @return string
144
-	 */
145
-	public function get_date_created_gmt( $context = 'view' ) {
139
+     * Get GMT date when the form was created.
140
+     *
141
+     * @since 1.0.19
142
+     * @param  string $context View or edit context.
143
+     * @return string
144
+     */
145
+    public function get_date_created_gmt( $context = 'view' ) {
146 146
         $date = $this->get_date_created( $context );
147 147
 
148 148
         if ( $date ) {
149 149
             $date = get_gmt_from_date( $date );
150 150
         }
151
-		return $date;
151
+        return $date;
152 152
     }
153 153
 
154 154
     /**
155
-	 * Get date when the form was last modified.
156
-	 *
157
-	 * @since 1.0.19
158
-	 * @param  string $context View or edit context.
159
-	 * @return string
160
-	 */
161
-	public function get_date_modified( $context = 'view' ) {
162
-		return $this->get_prop( 'date_modified', $context );
155
+     * Get date when the form was last modified.
156
+     *
157
+     * @since 1.0.19
158
+     * @param  string $context View or edit context.
159
+     * @return string
160
+     */
161
+    public function get_date_modified( $context = 'view' ) {
162
+        return $this->get_prop( 'date_modified', $context );
163 163
     }
164 164
 
165 165
     /**
166
-	 * Get GMT date when the form was last modified.
167
-	 *
168
-	 * @since 1.0.19
169
-	 * @param  string $context View or edit context.
170
-	 * @return string
171
-	 */
172
-	public function get_date_modified_gmt( $context = 'view' ) {
166
+     * Get GMT date when the form was last modified.
167
+     *
168
+     * @since 1.0.19
169
+     * @param  string $context View or edit context.
170
+     * @return string
171
+     */
172
+    public function get_date_modified_gmt( $context = 'view' ) {
173 173
         $date = $this->get_date_modified( $context );
174 174
 
175 175
         if ( $date ) {
176 176
             $date = get_gmt_from_date( $date );
177 177
         }
178
-		return $date;
178
+        return $date;
179 179
     }
180 180
 
181 181
     /**
182
-	 * Get the form name.
183
-	 *
184
-	 * @since 1.0.19
185
-	 * @param  string $context View or edit context.
186
-	 * @return string
187
-	 */
188
-	public function get_name( $context = 'view' ) {
189
-		return $this->get_prop( 'name', $context );
182
+     * Get the form name.
183
+     *
184
+     * @since 1.0.19
185
+     * @param  string $context View or edit context.
186
+     * @return string
187
+     */
188
+    public function get_name( $context = 'view' ) {
189
+        return $this->get_prop( 'name', $context );
190 190
     }
191 191
 
192 192
     /**
193
-	 * Alias of self::get_name().
194
-	 *
195
-	 * @since 1.0.19
196
-	 * @param  string $context View or edit context.
197
-	 * @return string
198
-	 */
199
-	public function get_title( $context = 'view' ) {
200
-		return $this->get_name( $context );
201
-	}
193
+     * Alias of self::get_name().
194
+     *
195
+     * @since 1.0.19
196
+     * @param  string $context View or edit context.
197
+     * @return string
198
+     */
199
+    public function get_title( $context = 'view' ) {
200
+        return $this->get_name( $context );
201
+    }
202 202
 
203 203
     /**
204
-	 * Get the owner of the form.
205
-	 *
206
-	 * @since 1.0.19
207
-	 * @param  string $context View or edit context.
208
-	 * @return int
209
-	 */
210
-	public function get_author( $context = 'view' ) {
211
-		return (int) $this->get_prop( 'author', $context );
204
+     * Get the owner of the form.
205
+     *
206
+     * @since 1.0.19
207
+     * @param  string $context View or edit context.
208
+     * @return int
209
+     */
210
+    public function get_author( $context = 'view' ) {
211
+        return (int) $this->get_prop( 'author', $context );
212 212
     }
213 213
 
214 214
     /**
215
-	 * Get the elements that make up the form.
216
-	 *
217
-	 * @since 1.0.19
218
-	 * @param  string $context View or edit context.
219
-	 * @return array
220
-	 */
221
-	public function get_elements( $context = 'view' ) {
222
-		$elements = $this->get_prop( 'elements', $context );
215
+     * Get the elements that make up the form.
216
+     *
217
+     * @since 1.0.19
218
+     * @param  string $context View or edit context.
219
+     * @return array
220
+     */
221
+    public function get_elements( $context = 'view' ) {
222
+        $elements = $this->get_prop( 'elements', $context );
223 223
 
224
-		if ( empty( $elements ) || ! is_array( $elements ) ) {
224
+        if ( empty( $elements ) || ! is_array( $elements ) ) {
225 225
             return wpinv_get_data( 'sample-payment-form' );
226
-		}
226
+        }
227 227
 
228
-		// Ensure that all required elements exist.
229
-		$_elements = array();
230
-		foreach ( $elements as $element ) {
228
+        // Ensure that all required elements exist.
229
+        $_elements = array();
230
+        foreach ( $elements as $element ) {
231 231
 
232
-			if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
232
+            if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
233 233
 
234
-				$_elements[] = array(
235
-					'text'        => __( 'Select Payment Method', 'invoicing' ),
236
-					'id'          => 'gtscicd',
237
-					'name'        => 'gtscicd',
238
-					'type'        => 'gateway_select',
239
-					'premade'     => true
234
+                $_elements[] = array(
235
+                    'text'        => __( 'Select Payment Method', 'invoicing' ),
236
+                    'id'          => 'gtscicd',
237
+                    'name'        => 'gtscicd',
238
+                    'type'        => 'gateway_select',
239
+                    'premade'     => true
240 240
 			
241
-				);
241
+                );
242 242
 
243
-			}
243
+            }
244 244
 
245
-			$_elements[] = $element;
245
+            $_elements[] = $element;
246 246
 
247
-		}
247
+        }
248 248
 
249 249
         return $_elements;
250
-	}
251
-
252
-	/**
253
-	 * Get the items sold via the form.
254
-	 *
255
-	 * @since 1.0.19
256
-	 * @param  string $context View or edit context.
257
-	 * @param  string $return objects or arrays.
258
-	 * @return GetPaid_Form_Item[]
259
-	 */
260
-	public function get_items( $context = 'view', $return = 'objects' ) {
261
-		$items = $this->get_prop( 'items', $context );
262
-
263
-		if ( empty( $items ) || ! is_array( $items ) ) {
250
+    }
251
+
252
+    /**
253
+     * Get the items sold via the form.
254
+     *
255
+     * @since 1.0.19
256
+     * @param  string $context View or edit context.
257
+     * @param  string $return objects or arrays.
258
+     * @return GetPaid_Form_Item[]
259
+     */
260
+    public function get_items( $context = 'view', $return = 'objects' ) {
261
+        $items = $this->get_prop( 'items', $context );
262
+
263
+        if ( empty( $items ) || ! is_array( $items ) ) {
264 264
             $items = wpinv_get_data( 'sample-payment-form-items' );
265
-		}
265
+        }
266
+
267
+        // Convert the items.
268
+        $prepared = array();
266 269
 
267
-		// Convert the items.
268
-		$prepared = array();
270
+        foreach ( $items as $key => $value ) {
269 271
 
270
-		foreach ( $items as $key => $value ) {
272
+            // Form items.
273
+            if ( $value instanceof GetPaid_Form_Item ) {
271 274
 
272
-			// Form items.
273
-			if ( $value instanceof GetPaid_Form_Item ) {
275
+                if ( $value->can_purchase() ) {
276
+                    $prepared[] = $value;
277
+                }
274 278
 
275
-				if ( $value->can_purchase() ) {
276
-					$prepared[] = $value;
277
-				}
279
+                continue;
278 280
 
279
-				continue;
281
+            }
280 282
 
281
-			}
283
+            // $item_id => $quantity (buy buttons)
284
+            if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
+                $item = new GetPaid_Form_Item( $key );
282 286
 
283
-			// $item_id => $quantity (buy buttons)
284
-			if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
-				$item = new GetPaid_Form_Item( $key );
287
+                if ( $item->can_purchase() ) {
288
+                    $item->set_quantity( $value );
289
+                    $prepared[] = $item;
290
+                }
286 291
 
287
-				if ( $item->can_purchase() ) {
288
-					$item->set_quantity( $value );
289
-					$prepared[] = $item;
290
-				}
292
+                continue;
293
+            }
291 294
 
292
-				continue;
293
-			}
295
+            // Items saved via payment forms editor.
296
+            if ( is_array( $value ) && isset( $value['id'] ) ) {
294 297
 
295
-			// Items saved via payment forms editor.
296
-			if ( is_array( $value ) && isset( $value['id'] ) ) {
298
+                $item = new GetPaid_Form_Item( $value['id'] );
297 299
 
298
-				$item = new GetPaid_Form_Item( $value['id'] );
300
+                if ( ! $item->can_purchase() ) {
301
+                    continue;
302
+                }
299 303
 
300
-				if ( ! $item->can_purchase() ) {
301
-					continue;
302
-				}
304
+                // Sub-total (Cart items).
305
+                if ( isset( $value['subtotal'] ) ) {
306
+                    $item->set_price( $value['subtotal'] );
307
+                }
303 308
 
304
-				// Sub-total (Cart items).
305
-				if ( isset( $value['subtotal'] ) ) {
306
-					$item->set_price( $value['subtotal'] );
307
-				}
309
+                if ( isset( $value['quantity'] ) ) {
310
+                    $item->set_quantity( $value['quantity'] );
311
+                }
308 312
 
309
-				if ( isset( $value['quantity'] ) ) {
310
-					$item->set_quantity( $value['quantity'] );
311
-				}
313
+                if ( isset( $value['allow_quantities'] ) ) {
314
+                    $item->set_allow_quantities( $value['allow_quantities'] );
315
+                }
312 316
 
313
-				if ( isset( $value['allow_quantities'] ) ) {
314
-					$item->set_allow_quantities( $value['allow_quantities'] );
315
-				}
317
+                if ( isset( $value['required'] ) ) {
318
+                    $item->set_is_required( $value['required'] );
319
+                }
316 320
 
317
-				if ( isset( $value['required'] ) ) {
318
-					$item->set_is_required( $value['required'] );
319
-				}
321
+                if ( isset( $value['description'] ) ) {
322
+                    $item->set_custom_description( $value['description'] );
323
+                }
320 324
 
321
-				if ( isset( $value['description'] ) ) {
322
-					$item->set_custom_description( $value['description'] );
323
-				}
325
+                $prepared[] = $item;
326
+                continue;
324 327
 
325
-				$prepared[] = $item;
326
-				continue;
328
+            }
329
+
330
+            // $item_id => array( 'price' => 10 ) (item variations)
331
+            if ( is_numeric( $key ) && is_array( $value ) ) {
332
+                $item = new GetPaid_Form_Item( $key );
333
+
334
+                if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
335
+                    $item->set_price( $value['price'] );
336
+                }
337
+
338
+                if ( $item->can_purchase() ) {
339
+                    $prepared[] = $item;
340
+                }
341
+
342
+                continue;
343
+            }
344
+
345
+        }
346
+
347
+        if ( 'objects' == $return && 'view' == $context ) {
348
+            return $prepared;
349
+        }
350
+
351
+        $items = array();
352
+        foreach ( $prepared as $item ) {
353
+            $items[] = $item->prepare_data_for_use();
354
+        }
355
+
356
+        return $items;
357
+    }
358
+
359
+    /**
360
+     * Get a single item belonging to the form.
361
+     *
362
+     * @since 1.0.19
363
+     * @param  int $item_id The item id to return.
364
+     * @return GetPaid_Form_Item|bool
365
+     */
366
+    public function get_item( $item_id ) {
367
+
368
+        if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
369
+            return false;
370
+        }
371
+
372
+        foreach( $this->get_items() as $item ) {
373
+            if ( $item->get_id() == (int) $item_id ) {
374
+                return $item;
375
+            }
376
+        }
377
+
378
+        return false;
379
+
380
+    }
381
+
382
+    /**
383
+     * Gets a single element.
384
+     *
385
+     * @since 1.0.19
386
+     * @param  string $element_type The element type to return.
387
+     * @return array|bool
388
+     */
389
+    public function get_element_type( $element_type ) {
390
+
391
+        if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
392
+            return false;
393
+        }
394
+
395
+        foreach ( $this->get_prop( 'elements' ) as $element ) {
396
+
397
+            if ( $element['type'] == $element_type ) {
398
+                return $element;
399
+            }
400
+
401
+        }
402
+
403
+        return false;
404
+
405
+    }
406
+
407
+    /**
408
+     * Get the total amount earned via this form.
409
+     *
410
+     * @since 1.0.19
411
+     * @param  string $context View or edit context.
412
+     * @return array
413
+     */
414
+    public function get_earned( $context = 'view' ) {
415
+        return $this->get_prop( 'earned', $context );
416
+    }
417
+
418
+    /**
419
+     * Get the total amount refunded via this form.
420
+     *
421
+     * @since 1.0.19
422
+     * @param  string $context View or edit context.
423
+     * @return array
424
+     */
425
+    public function get_refunded( $context = 'view' ) {
426
+        return $this->get_prop( 'refunded', $context );
427
+    }
327 428
 
328
-			}
429
+    /**
430
+     * Get the total amount cancelled via this form.
431
+     *
432
+     * @since 1.0.19
433
+     * @param  string $context View or edit context.
434
+     * @return array
435
+     */
436
+    public function get_cancelled( $context = 'view' ) {
437
+        return $this->get_prop( 'cancelled', $context );
438
+    }
329 439
 
330
-			// $item_id => array( 'price' => 10 ) (item variations)
331
-			if ( is_numeric( $key ) && is_array( $value ) ) {
332
-				$item = new GetPaid_Form_Item( $key );
440
+    /**
441
+     * Get the total amount failed via this form.
442
+     *
443
+     * @since 1.0.19
444
+     * @param  string $context View or edit context.
445
+     * @return array
446
+     */
447
+    public function get_failed( $context = 'view' ) {
448
+        return $this->get_prop( 'failed', $context );
449
+    }
333 450
 
334
-				if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
335
-					$item->set_price( $value['price'] );
336
-				}
337
-
338
-				if ( $item->can_purchase() ) {
339
-					$prepared[] = $item;
340
-				}
341
-
342
-				continue;
343
-			}
344
-
345
-		}
346
-
347
-		if ( 'objects' == $return && 'view' == $context ) {
348
-			return $prepared;
349
-		}
350
-
351
-		$items = array();
352
-		foreach ( $prepared as $item ) {
353
-			$items[] = $item->prepare_data_for_use();
354
-		}
355
-
356
-		return $items;
357
-	}
358
-
359
-	/**
360
-	 * Get a single item belonging to the form.
361
-	 *
362
-	 * @since 1.0.19
363
-	 * @param  int $item_id The item id to return.
364
-	 * @return GetPaid_Form_Item|bool
365
-	 */
366
-	public function get_item( $item_id ) {
367
-
368
-		if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
369
-			return false;
370
-		}
371
-
372
-		foreach( $this->get_items() as $item ) {
373
-			if ( $item->get_id() == (int) $item_id ) {
374
-				return $item;
375
-			}
376
-		}
377
-
378
-		return false;
379
-
380
-	}
381
-
382
-	/**
383
-	 * Gets a single element.
384
-	 *
385
-	 * @since 1.0.19
386
-	 * @param  string $element_type The element type to return.
387
-	 * @return array|bool
388
-	 */
389
-	public function get_element_type( $element_type ) {
390
-
391
-		if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
392
-			return false;
393
-		}
394
-
395
-		foreach ( $this->get_prop( 'elements' ) as $element ) {
396
-
397
-			if ( $element['type'] == $element_type ) {
398
-				return $element;
399
-			}
400
-
401
-		}
402
-
403
-		return false;
404
-
405
-	}
406
-
407
-	/**
408
-	 * Get the total amount earned via this form.
409
-	 *
410
-	 * @since 1.0.19
411
-	 * @param  string $context View or edit context.
412
-	 * @return array
413
-	 */
414
-	public function get_earned( $context = 'view' ) {
415
-		return $this->get_prop( 'earned', $context );
416
-	}
417
-
418
-	/**
419
-	 * Get the total amount refunded via this form.
420
-	 *
421
-	 * @since 1.0.19
422
-	 * @param  string $context View or edit context.
423
-	 * @return array
424
-	 */
425
-	public function get_refunded( $context = 'view' ) {
426
-		return $this->get_prop( 'refunded', $context );
427
-	}
428
-
429
-	/**
430
-	 * Get the total amount cancelled via this form.
431
-	 *
432
-	 * @since 1.0.19
433
-	 * @param  string $context View or edit context.
434
-	 * @return array
435
-	 */
436
-	public function get_cancelled( $context = 'view' ) {
437
-		return $this->get_prop( 'cancelled', $context );
438
-	}
439
-
440
-	/**
441
-	 * Get the total amount failed via this form.
442
-	 *
443
-	 * @since 1.0.19
444
-	 * @param  string $context View or edit context.
445
-	 * @return array
446
-	 */
447
-	public function get_failed( $context = 'view' ) {
448
-		return $this->get_prop( 'failed', $context );
449
-	}
450
-
451
-	/**
452
-	 * Get the currency.
453
-	 *
454
-	 * @since 1.0.19
455
-	 * @param  string $context View or edit context.
456
-	 * @return string
457
-	 */
458
-	public function get_currency() {
459
-		$currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
460
-		return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
461
-	}
451
+    /**
452
+     * Get the currency.
453
+     *
454
+     * @since 1.0.19
455
+     * @param  string $context View or edit context.
456
+     * @return string
457
+     */
458
+    public function get_currency() {
459
+        $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
460
+        return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
461
+    }
462 462
 
463 463
     /*
464 464
 	|--------------------------------------------------------------------------
@@ -471,22 +471,22 @@  discard block
 block discarded – undo
471 471
     */
472 472
 
473 473
     /**
474
-	 * Set plugin version when the item was created.
475
-	 *
476
-	 * @since 1.0.19
477
-	 */
478
-	public function set_version( $value ) {
479
-		$this->set_prop( 'version', $value );
474
+     * Set plugin version when the item was created.
475
+     *
476
+     * @since 1.0.19
477
+     */
478
+    public function set_version( $value ) {
479
+        $this->set_prop( 'version', $value );
480 480
     }
481 481
 
482 482
     /**
483
-	 * Set date when the item was created.
484
-	 *
485
-	 * @since 1.0.19
486
-	 * @param string $value Value to set.
483
+     * Set date when the item was created.
484
+     *
485
+     * @since 1.0.19
486
+     * @param string $value Value to set.
487 487
      * @return bool Whether or not the date was set.
488
-	 */
489
-	public function set_date_created( $value ) {
488
+     */
489
+    public function set_date_created( $value ) {
490 490
         $date = strtotime( $value );
491 491
 
492 492
         if ( $date ) {
@@ -499,13 +499,13 @@  discard block
 block discarded – undo
499 499
     }
500 500
 
501 501
     /**
502
-	 * Set date when the item was last modified.
503
-	 *
504
-	 * @since 1.0.19
505
-	 * @param string $value Value to set.
502
+     * Set date when the item was last modified.
503
+     *
504
+     * @since 1.0.19
505
+     * @param string $value Value to set.
506 506
      * @return bool Whether or not the date was set.
507
-	 */
508
-	public function set_date_modified( $value ) {
507
+     */
508
+    public function set_date_modified( $value ) {
509 509
         $date = strtotime( $value );
510 510
 
511 511
         if ( $date ) {
@@ -518,118 +518,118 @@  discard block
 block discarded – undo
518 518
     }
519 519
 
520 520
     /**
521
-	 * Set the item name.
522
-	 *
523
-	 * @since 1.0.19
524
-	 * @param  string $value New name.
525
-	 */
526
-	public function set_name( $value ) {
527
-		$this->set_prop( 'name', sanitize_text_field( $value ) );
528
-    }
529
-
530
-    /**
531
-	 * Alias of self::set_name().
532
-	 *
533
-	 * @since 1.0.19
534
-	 * @param  string $value New name.
535
-	 */
536
-	public function set_title( $value ) {
537
-		$this->set_name( $value );
538
-    }
539
-
540
-    /**
541
-	 * Set the owner of the item.
542
-	 *
543
-	 * @since 1.0.19
544
-	 * @param  int $value New author.
545
-	 */
546
-	public function set_author( $value ) {
547
-		$this->set_prop( 'author', (int) $value );
548
-	}
549
-
550
-	/**
551
-	 * Set the form elements.
552
-	 *
553
-	 * @since 1.0.19
554
-	 * @param  array $value Form elements.
555
-	 */
556
-	public function set_elements( $value ) {
557
-		if ( is_array( $value ) ) {
558
-			$this->set_prop( 'elements', $value );
559
-		}
560
-	}
561
-
562
-	/**
563
-	 * Set the form items.
564
-	 *
565
-	 * @since 1.0.19
566
-	 * @param  array $value Form elements.
567
-	 */
568
-	public function set_items( $value ) {
569
-		if ( is_array( $value ) ) {
570
-			$this->set_prop( 'items', $value );
571
-		}
572
-	}
573
-
574
-	/**
575
-	 * Set the total amount earned via this form.
576
-	 *
577
-	 * @since 1.0.19
578
-	 * @param  float $value Amount earned.
579
-	 */
580
-	public function set_earned( $value ) {
581
-		$value = max( (float) $value, 0 );
582
-		$this->set_prop( 'earned', $value );
583
-	}
584
-
585
-	/**
586
-	 * Set the total amount refunded via this form.
587
-	 *
588
-	 * @since 1.0.19
589
-	 * @param  float $value Amount refunded.
590
-	 */
591
-	public function set_refunded( $value ) {
592
-		$value = max( (float) $value, 0 );
593
-		$this->set_prop( 'refunded', $value );
594
-	}
595
-
596
-	/**
597
-	 * Set the total amount cancelled via this form.
598
-	 *
599
-	 * @since 1.0.19
600
-	 * @param  float $value Amount cancelled.
601
-	 */
602
-	public function set_cancelled( $value ) {
603
-		$value = max( (float) $value, 0 );
604
-		$this->set_prop( 'cancelled', $value );
605
-	}
606
-
607
-	/**
608
-	 * Set the total amount failed via this form.
609
-	 *
610
-	 * @since 1.0.19
611
-	 * @param  float $value Amount cancelled.
612
-	 */
613
-	public function set_failed( $value ) {
614
-		$value = max( (float) $value, 0 );
615
-		$this->set_prop( 'failed', $value );
616
-	}
521
+     * Set the item name.
522
+     *
523
+     * @since 1.0.19
524
+     * @param  string $value New name.
525
+     */
526
+    public function set_name( $value ) {
527
+        $this->set_prop( 'name', sanitize_text_field( $value ) );
528
+    }
529
+
530
+    /**
531
+     * Alias of self::set_name().
532
+     *
533
+     * @since 1.0.19
534
+     * @param  string $value New name.
535
+     */
536
+    public function set_title( $value ) {
537
+        $this->set_name( $value );
538
+    }
539
+
540
+    /**
541
+     * Set the owner of the item.
542
+     *
543
+     * @since 1.0.19
544
+     * @param  int $value New author.
545
+     */
546
+    public function set_author( $value ) {
547
+        $this->set_prop( 'author', (int) $value );
548
+    }
549
+
550
+    /**
551
+     * Set the form elements.
552
+     *
553
+     * @since 1.0.19
554
+     * @param  array $value Form elements.
555
+     */
556
+    public function set_elements( $value ) {
557
+        if ( is_array( $value ) ) {
558
+            $this->set_prop( 'elements', $value );
559
+        }
560
+    }
561
+
562
+    /**
563
+     * Set the form items.
564
+     *
565
+     * @since 1.0.19
566
+     * @param  array $value Form elements.
567
+     */
568
+    public function set_items( $value ) {
569
+        if ( is_array( $value ) ) {
570
+            $this->set_prop( 'items', $value );
571
+        }
572
+    }
573
+
574
+    /**
575
+     * Set the total amount earned via this form.
576
+     *
577
+     * @since 1.0.19
578
+     * @param  float $value Amount earned.
579
+     */
580
+    public function set_earned( $value ) {
581
+        $value = max( (float) $value, 0 );
582
+        $this->set_prop( 'earned', $value );
583
+    }
584
+
585
+    /**
586
+     * Set the total amount refunded via this form.
587
+     *
588
+     * @since 1.0.19
589
+     * @param  float $value Amount refunded.
590
+     */
591
+    public function set_refunded( $value ) {
592
+        $value = max( (float) $value, 0 );
593
+        $this->set_prop( 'refunded', $value );
594
+    }
595
+
596
+    /**
597
+     * Set the total amount cancelled via this form.
598
+     *
599
+     * @since 1.0.19
600
+     * @param  float $value Amount cancelled.
601
+     */
602
+    public function set_cancelled( $value ) {
603
+        $value = max( (float) $value, 0 );
604
+        $this->set_prop( 'cancelled', $value );
605
+    }
606
+
607
+    /**
608
+     * Set the total amount failed via this form.
609
+     *
610
+     * @since 1.0.19
611
+     * @param  float $value Amount cancelled.
612
+     */
613
+    public function set_failed( $value ) {
614
+        $value = max( (float) $value, 0 );
615
+        $this->set_prop( 'failed', $value );
616
+    }
617 617
 
618 618
     /**
619 619
      * Create an item. For backwards compatibilty.
620 620
      *
621 621
      * @deprecated
622
-	 * @return int item id
622
+     * @return int item id
623 623
      */
624 624
     public function create( $data = array() ) {
625 625
 
626
-		// Set the properties.
627
-		if ( is_array( $data ) ) {
628
-			$this->set_props( $data );
629
-		}
626
+        // Set the properties.
627
+        if ( is_array( $data ) ) {
628
+            $this->set_props( $data );
629
+        }
630 630
 
631
-		// Save the item.
632
-		return $this->save();
631
+        // Save the item.
632
+        return $this->save();
633 633
 
634 634
     }
635 635
 
@@ -637,7 +637,7 @@  discard block
 block discarded – undo
637 637
      * Updates an item. For backwards compatibilty.
638 638
      *
639 639
      * @deprecated
640
-	 * @return int item id
640
+     * @return int item id
641 641
      */
642 642
     public function update( $data = array() ) {
643 643
         return $this->create( $data );
@@ -653,22 +653,22 @@  discard block
 block discarded – undo
653 653
 	*/
654 654
 
655 655
     /**
656
-	 * Checks whether this is the default payment form.
657
-	 *
658
-	 * @since 1.0.19
659
-	 * @return bool
660
-	 */
656
+     * Checks whether this is the default payment form.
657
+     *
658
+     * @since 1.0.19
659
+     * @return bool
660
+     */
661 661
     public function is_default() {
662 662
         $is_default = $this->get_id() == wpinv_get_default_payment_form();
663 663
         return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this );
664
-	}
664
+    }
665 665
 
666 666
     /**
667
-	 * Checks whether the form is active.
668
-	 *
669
-	 * @since 1.0.19
670
-	 * @return bool
671
-	 */
667
+     * Checks whether the form is active.
668
+     *
669
+     * @since 1.0.19
670
+     * @return bool
671
+     */
672 672
     public function is_active() {
673 673
         $is_active = 0 !== (int) $this->get_id();
674 674
 
@@ -677,70 +677,70 @@  discard block
 block discarded – undo
677 677
         }
678 678
 
679 679
         return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this );
680
-	}
681
-
682
-	/**
683
-	 * Checks whether the form has a given item.
684
-	 *
685
-	 * @since 1.0.19
686
-	 * @return bool
687
-	 */
680
+    }
681
+
682
+    /**
683
+     * Checks whether the form has a given item.
684
+     *
685
+     * @since 1.0.19
686
+     * @return bool
687
+     */
688 688
     public function has_item( $item_id ) {
689 689
         return false !== $this->get_item( $item_id );
690
-	}
691
-
692
-	/**
693
-	 * Checks whether the form has a given element.
694
-	 *
695
-	 * @since 1.0.19
696
-	 * @return bool
697
-	 */
690
+    }
691
+
692
+    /**
693
+     * Checks whether the form has a given element.
694
+     *
695
+     * @since 1.0.19
696
+     * @return bool
697
+     */
698 698
     public function has_element_type( $element_type ) {
699 699
         return false !== $this->get_element_type( $element_type );
700
-	}
701
-
702
-	/**
703
-	 * Checks whether this form is recurring or not.
704
-	 *
705
-	 * @since 1.0.19
706
-	 * @return bool
707
-	 */
700
+    }
701
+
702
+    /**
703
+     * Checks whether this form is recurring or not.
704
+     *
705
+     * @since 1.0.19
706
+     * @return bool
707
+     */
708 708
     public function is_recurring() {
709 709
 
710
-		if ( ! empty( $this->invoice ) ) {
711
-			return $this->invoice->is_recurring();
712
-		}
710
+        if ( ! empty( $this->invoice ) ) {
711
+            return $this->invoice->is_recurring();
712
+        }
713 713
 
714
-		foreach ( $this->get_items() as $item ) {
714
+        foreach ( $this->get_items() as $item ) {
715 715
 
716
-			if ( $item->is_recurring() ) {
717
-				return true;
718
-			}
716
+            if ( $item->is_recurring() ) {
717
+                return true;
718
+            }
719 719
 
720
-		}
720
+        }
721 721
 
722 722
         return false;
723
-	}
723
+    }
724 724
 
725
-	/**
726
-	 * Retrieves the form's html.
727
-	 *
728
-	 * @since 1.0.19
729
-	 */
725
+    /**
726
+     * Retrieves the form's html.
727
+     *
728
+     * @since 1.0.19
729
+     */
730 730
     public function get_html() {
731 731
 
732
-		// Return the HTML.
733
-		return wpinv_get_template_html( 'payment-forms/form.php', array( 'form' => $this ) );
732
+        // Return the HTML.
733
+        return wpinv_get_template_html( 'payment-forms/form.php', array( 'form' => $this ) );
734 734
 
735
-	}
735
+    }
736 736
 
737
-	/**
738
-	 * Displays the payment form.
739
-	 *
740
-	 * @since 1.0.19
741
-	 */
737
+    /**
738
+     * Displays the payment form.
739
+     *
740
+     * @since 1.0.19
741
+     */
742 742
     public function display() {
743
-		echo $this->get_html();
743
+        echo $this->get_html();
744 744
     }
745 745
 
746 746
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-discount.php 1 patch
Indentation   +181 added lines, -181 removed lines patch added patch discarded remove patch
@@ -12,189 +12,189 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Discount {
14 14
 
15
-	/**
16
-	 * Submission discounts.
17
-	 * @var array
18
-	 */
19
-	public $discounts = array();
15
+    /**
16
+     * Submission discounts.
17
+     * @var array
18
+     */
19
+    public $discounts = array();
20
+
21
+    /**
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     * @param float                           $initial_total
26
+     * @param float                           $recurring_total
27
+     */
28
+    public function __construct( $submission, $initial_total, $recurring_total ) {
29
+
30
+        // Process any existing invoice discounts.
31
+        if ( $submission->has_invoice() ) {
32
+            $this->discounts = $submission->get_invoice()->get_discounts();
33
+        }
34
+
35
+        // Do we have a discount?
36
+        $discount = $submission->get_field( 'discount' );
37
+
38
+        if ( empty( $discount ) ) {
39
+
40
+            if ( isset( $this->discounts['discount_code'] ) ) {
41
+                unset( $this->discounts['discount_code'] );
42
+            }
43
+
44
+            return;
45
+        }
46
+
47
+        // Processes the discount code.
48
+        $amount = max( $initial_total, $recurring_total );
49
+        $this->process_discount( $submission, $discount, $amount );
50
+
51
+    }
20 52
 
21 53
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 * @param float                           $initial_total
26
-	 * @param float                           $recurring_total
27
-	 */
28
-	public function __construct( $submission, $initial_total, $recurring_total ) {
29
-
30
-		// Process any existing invoice discounts.
31
-		if ( $submission->has_invoice() ) {
32
-			$this->discounts = $submission->get_invoice()->get_discounts();
33
-		}
34
-
35
-		// Do we have a discount?
36
-		$discount = $submission->get_field( 'discount' );
37
-
38
-		if ( empty( $discount ) ) {
39
-
40
-			if ( isset( $this->discounts['discount_code'] ) ) {
41
-				unset( $this->discounts['discount_code'] );
42
-			}
43
-
44
-			return;
45
-		}
46
-
47
-		// Processes the discount code.
48
-		$amount = max( $initial_total, $recurring_total );
49
-		$this->process_discount( $submission, $discount, $amount );
50
-
51
-	}
52
-
53
-	/**
54
-	 * Processes a submission discount.
55
-	 *
56
-	 * @param GetPaid_Payment_Form_Submission $submission
57
-	 * @param string                          $discount
58
-	 * @param float                           $amount
59
-	 */
60
-	public function process_discount( $submission, $discount, $amount ) {
61
-
62
-		// Fetch the discount.
63
-		$discount = new WPInv_Discount( $discount );
64
-
65
-		// Ensure it is active.
54
+     * Processes a submission discount.
55
+     *
56
+     * @param GetPaid_Payment_Form_Submission $submission
57
+     * @param string                          $discount
58
+     * @param float                           $amount
59
+     */
60
+    public function process_discount( $submission, $discount, $amount ) {
61
+
62
+        // Fetch the discount.
63
+        $discount = new WPInv_Discount( $discount );
64
+
65
+        // Ensure it is active.
66 66
         if ( ! $this->is_discount_active( $discount ) ) {
67
-			throw new Exception( __( 'Invalid or expired discount code', 'invoicing' ) );
68
-		}
69
-
70
-		// Exceeded limit.
71
-		if ( $discount->has_exceeded_limit() ) {
72
-			throw new Exception( __( 'This discount code has been used up', 'invoicing' ) );
73
-		}
74
-
75
-		// Validate usages.
76
-		$this->validate_single_use_discount( $submission, $discount );
77
-
78
-		// Validate amount.
79
-		$this->validate_discount_amount( $submission, $discount, $amount );
80
-
81
-		// Save the discount.
82
-		$this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount );
83
-	}
84
-
85
-	/**
86
-	 * Validates a single use discount.
87
-	 *
88
-	 * @param WPInv_Discount                  $discount
89
-	 * @return bool
90
-	 */
91
-	public function is_discount_active(  $discount ) {
92
-		return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired();
93
-	}
94
-
95
-	/**
96
-	 * Returns a user's id or email.
97
-	 *
98
-	 * @param string $email
99
-	 * @return int|string|false
100
-	 */
101
-	public function get_user_id_or_email( $email ) {
102
-
103
-		if ( is_user_logged_in() ) {
104
-			return get_current_user_id();
105
-		}
106
-
107
-		return empty( $email ) ? false : sanitize_email( $email );
108
-	}
109
-
110
-	/**
111
-	 * Validates a single use discount.
112
-	 *
113
-	 * @param GetPaid_Payment_Form_Submission $submission
114
-	 * @param WPInv_Discount                  $discount
115
-	 */
116
-	public function validate_single_use_discount( $submission, $discount ) {
117
-
118
-		// Abort if it is not a single use discount.
119
-		if ( ! $discount->is_single_use() ) {
120
-			return;
121
-		}
122
-
123
-		// Ensure there is a valid billing email.
124
-		$user = $this->get_user_id_or_email( $submission->get_billing_email() );
125
-
126
-		if ( empty( $user ) ) {
127
-			throw new Exception( __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) );
128
-		}
129
-
130
-		// Has the user used this discount code before?
131
-		if ( ! $discount->is_valid_for_user( $user ) ) {
132
-			throw new Exception( __( 'You have already used this discount', 'invoicing' ) );
133
-		}
134
-
135
-	}
136
-
137
-	/**
138
-	 * Validates the discount's amount.
139
-	 *
140
-	 * @param GetPaid_Payment_Form_Submission $submission
141
-	 * @param WPInv_Discount         $discount
142
-	 * @param float                  $amount
143
-	 */
144
-	public function validate_discount_amount( $submission, $discount, $amount ) {
145
-
146
-		// Validate minimum amount.
147
-		if ( ! $discount->is_minimum_amount_met( $amount ) ) {
148
-			$min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() );
149
-			throw new Exception( sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) );
150
-		}
151
-
152
-		// Validate the maximum amount.
153
-		if ( ! $discount->is_maximum_amount_met( $amount ) ) {
154
-			$max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() );
155
-			throw new Exception( sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) );
156
-		}
157
-
158
-	}
159
-
160
-	/**
161
-	 * Calculates the discount code's amount.
162
-	 *
163
-	 * Ensure that the discount exists and has been validated before calling this method.
164
-	 *
165
-	 * @param GetPaid_Payment_Form_Submission $submission
166
-	 * @param WPInv_Discount                  $discount
167
-	 * @return array
168
-	 */
169
-	public function calculate_discount( $submission, $discount ) {
170
-
171
-		$initial_discount   = 0;
172
-		$recurring_discount = 0;
173
-
174
-		foreach ( $submission->get_items() as $item ) {
175
-
176
-			// Abort if it is not valid for this item.
177
-			if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) {
178
-				continue;
179
-			}
180
-
181
-			// Calculate the initial amount...
182
-			$initial_discount += $discount->get_discounted_amount( $item->get_sub_total() );
183
-
184
-			// ... and maybe the recurring amount.
185
-			if ( $item->is_recurring() && $discount->is_recurring() ) {
186
-				$recurring_discount += $discount->get_discounted_amount( $item->get_recurring_sub_total() );
187
-			}
188
-
189
-		}
190
-
191
-		return array(
192
-			'name'               => 'discount_code',
193
-			'discount_code'      => $discount->get_code(),
194
-			'initial_discount'   => $initial_discount,
195
-			'recurring_discount' => $recurring_discount,
196
-		);
197
-
198
-	}
67
+            throw new Exception( __( 'Invalid or expired discount code', 'invoicing' ) );
68
+        }
69
+
70
+        // Exceeded limit.
71
+        if ( $discount->has_exceeded_limit() ) {
72
+            throw new Exception( __( 'This discount code has been used up', 'invoicing' ) );
73
+        }
74
+
75
+        // Validate usages.
76
+        $this->validate_single_use_discount( $submission, $discount );
77
+
78
+        // Validate amount.
79
+        $this->validate_discount_amount( $submission, $discount, $amount );
80
+
81
+        // Save the discount.
82
+        $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount );
83
+    }
84
+
85
+    /**
86
+     * Validates a single use discount.
87
+     *
88
+     * @param WPInv_Discount                  $discount
89
+     * @return bool
90
+     */
91
+    public function is_discount_active(  $discount ) {
92
+        return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired();
93
+    }
94
+
95
+    /**
96
+     * Returns a user's id or email.
97
+     *
98
+     * @param string $email
99
+     * @return int|string|false
100
+     */
101
+    public function get_user_id_or_email( $email ) {
102
+
103
+        if ( is_user_logged_in() ) {
104
+            return get_current_user_id();
105
+        }
106
+
107
+        return empty( $email ) ? false : sanitize_email( $email );
108
+    }
109
+
110
+    /**
111
+     * Validates a single use discount.
112
+     *
113
+     * @param GetPaid_Payment_Form_Submission $submission
114
+     * @param WPInv_Discount                  $discount
115
+     */
116
+    public function validate_single_use_discount( $submission, $discount ) {
117
+
118
+        // Abort if it is not a single use discount.
119
+        if ( ! $discount->is_single_use() ) {
120
+            return;
121
+        }
122
+
123
+        // Ensure there is a valid billing email.
124
+        $user = $this->get_user_id_or_email( $submission->get_billing_email() );
125
+
126
+        if ( empty( $user ) ) {
127
+            throw new Exception( __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) );
128
+        }
129
+
130
+        // Has the user used this discount code before?
131
+        if ( ! $discount->is_valid_for_user( $user ) ) {
132
+            throw new Exception( __( 'You have already used this discount', 'invoicing' ) );
133
+        }
134
+
135
+    }
136
+
137
+    /**
138
+     * Validates the discount's amount.
139
+     *
140
+     * @param GetPaid_Payment_Form_Submission $submission
141
+     * @param WPInv_Discount         $discount
142
+     * @param float                  $amount
143
+     */
144
+    public function validate_discount_amount( $submission, $discount, $amount ) {
145
+
146
+        // Validate minimum amount.
147
+        if ( ! $discount->is_minimum_amount_met( $amount ) ) {
148
+            $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() );
149
+            throw new Exception( sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) );
150
+        }
151
+
152
+        // Validate the maximum amount.
153
+        if ( ! $discount->is_maximum_amount_met( $amount ) ) {
154
+            $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() );
155
+            throw new Exception( sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) );
156
+        }
157
+
158
+    }
159
+
160
+    /**
161
+     * Calculates the discount code's amount.
162
+     *
163
+     * Ensure that the discount exists and has been validated before calling this method.
164
+     *
165
+     * @param GetPaid_Payment_Form_Submission $submission
166
+     * @param WPInv_Discount                  $discount
167
+     * @return array
168
+     */
169
+    public function calculate_discount( $submission, $discount ) {
170
+
171
+        $initial_discount   = 0;
172
+        $recurring_discount = 0;
173
+
174
+        foreach ( $submission->get_items() as $item ) {
175
+
176
+            // Abort if it is not valid for this item.
177
+            if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) {
178
+                continue;
179
+            }
180
+
181
+            // Calculate the initial amount...
182
+            $initial_discount += $discount->get_discounted_amount( $item->get_sub_total() );
183
+
184
+            // ... and maybe the recurring amount.
185
+            if ( $item->is_recurring() && $discount->is_recurring() ) {
186
+                $recurring_discount += $discount->get_discounted_amount( $item->get_recurring_sub_total() );
187
+            }
188
+
189
+        }
190
+
191
+        return array(
192
+            'name'               => 'discount_code',
193
+            'discount_code'      => $discount->get_code(),
194
+            'initial_discount'   => $initial_discount,
195
+            'recurring_discount' => $recurring_discount,
196
+        );
197
+
198
+    }
199 199
 
200 200
 }
Please login to merge, or discard this patch.